Skip to content

feat: add @copilotkit/react-native package#3633

Open
mxmzb wants to merge 17 commits intomainfrom
feat/react-native-support
Open

feat: add @copilotkit/react-native package#3633
mxmzb wants to merge 17 commits intomainfrom
feat/react-native-support

Conversation

@mxmzb
Copy link
Copy Markdown
Contributor

@mxmzb mxmzb commented Apr 6, 2026

Summary

  • Extract CopilotKitContext and useCopilotKit into standalone context.ts in react-core, enabling cross-platform reuse without web dependencies
  • Add new @copilotkit/react-native package with lightweight provider, polyfills, and streaming fetch
  • All hooks (useAgent, useFrontendTool, useHumanInTheLoop, etc.) are re-exported directly from react-core — no reimplementation

Motivation

CopilotKit's React hooks are platform-agnostic, but the barrel import in @copilotkit/react-core pulls in web-only dependencies (Radix UI, Lit, A2UI renderer, react-dom, CSS). This makes the package unusable in React Native without extensive Metro shimming.

By extracting the React context into a standalone entry point (@copilotkit/react-core/v2/context), the new @copilotkit/react-native package can provide its own lightweight provider while reusing all existing hooks.

What's in @copilotkit/react-native

Export Description
CopilotKitProvider Lightweight provider — no DOM, CSS, Radix, Lit, or A2UI deps
installStreamingFetch() XHR-based streaming fetch for response.body.getReader() support
@copilotkit/react-native/polyfills ReadableStream, TextEncoder, crypto, DOMException, window.location
useAgent, useFrontendTool, etc. Re-exported from react-core (shared context)

Usage

// index.js (entry point, before other imports)
import "@copilotkit/react-native/polyfills";
import { installStreamingFetch } from "@copilotkit/react-native";
installStreamingFetch();

// App.tsx
import { CopilotKitProvider, useAgent, useCopilotKit } from "@copilotkit/react-native";

function App() {
  return (
    <CopilotKitProvider runtimeUrl="https://your-server/api/copilotkit">
      <ChatScreen />
    </CopilotKitProvider>
  );
}

Test plan

  • nx run react-core:build passes
  • nx run @copilotkit/react-native:build passes
  • nx run react-core:test — all 952 tests pass
  • Manual test in React Native app (tested during development with bare RN 0.84 project)

🤖 Generated with Claude Code

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat-with-your-data Ready Ready Preview, Comment Apr 20, 2026 2:42pm
docs Ready Ready Preview, Comment Apr 20, 2026 2:42pm
form-filling Ready Ready Preview, Comment Apr 20, 2026 2:42pm
research-canvas Ready Ready Preview, Comment Apr 20, 2026 2:42pm
travel Ready Ready Preview, Comment Apr 20, 2026 2:42pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 6, 2026

⚠️ No Changeset found

Latest commit: c7949a1

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 6, 2026

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@vercel vercel Bot temporarily deployed to Preview – form-filling April 10, 2026 18:59 Inactive
@vercel vercel Bot temporarily deployed to Preview – chat-with-your-data April 10, 2026 18:59 Inactive
@mxmzb mxmzb force-pushed the feat/react-native-support branch from 2832421 to 66f1b95 Compare April 10, 2026 19:07
@vercel vercel Bot temporarily deployed to Preview – chat-with-your-data April 10, 2026 19:41 Inactive
@vercel vercel Bot temporarily deployed to Preview – form-filling April 10, 2026 19:41 Inactive
@vercel vercel Bot temporarily deployed to Preview – form-filling April 10, 2026 21:19 Inactive
…build

The headless build entry intentionally inlines @copilotkit/* packages via
noExternal. tsdown detects their transitive deps (partial-json, phoenix,
@standard-schema/spec) in the bundle and escalates the warning to an error
when CI=true, failing the build. Setting inlineOnly: false acknowledges
this is intentional.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 13, 2026

Open in StackBlitz

@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/a2ui-renderer@3633

@copilotkitnext/angular

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/angular@3633

copilotkit

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/copilotkit@3633

@copilotkit/core

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/core@3633

@copilotkit/react-core

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-core@3633

@copilotkit/react-native

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-native@3633

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-textarea@3633

@copilotkit/react-ui

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-ui@3633

@copilotkit/runtime

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/runtime@3633

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/runtime-client-gql@3633

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/sdk-js@3633

@copilotkit/shared

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/shared@3633

@copilotkit/sqlite-runner

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/sqlite-runner@3633

@copilotkit/voice

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/voice@3633

@copilotkit/web-inspector

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/web-inspector@3633

commit: 8d736e4

…, merge subscriptions

- Keep abort signal listener active after headers arrive so mid-stream
  abort works correctly (previously disconnected too early, breaking
  agent cancellation)
- Reject fullTextPromise in ReadableStream cancel() to prevent hanging
  .text()/.json() calls after stream cancellation
- Add cleanupAbortListener() call in onAbort to prevent memory leaks
- Extract fail() helper and createAbortError() to deduplicate 5 identical
  error-handling sequences across XHR event handlers
- Add StreamingFetchResponse interface to replace `any`-typed response
- Remove __DEV__ guard from insecure crypto polyfill warning so it appears
  in production logs
- Merge two useEffect subscriptions (tool execution + error) into one

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…olyfills

Add comprehensive test suite for @copilotkit/react-native covering:

- streaming-fetch.ts (36 tests): feature detection, request lifecycle,
  streaming chunks, convenience methods, abort handling, error paths
- CopilotKitProvider.tsx (18 tests): initialization, prop sync, context
  provision, tool execution tracking, error forwarding, shape validation
- polyfills.ts (20 tests): conditional installation, preservation of
  existing globals, crypto warning, streaming-fetch integration

Also adds test infrastructure (vitest.config.mjs, setup.ts, devDependencies)
and fixes an unhandled rejection bug in streaming-fetch where fullTextPromise
could reject without a listener.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Comment thread packages/react-core/src/v2/providers/CopilotKitProvider.tsx Outdated
Comment thread packages/react-core/src/v2/headless.ts Outdated
Comment thread packages/react-native/src/polyfills.ts Outdated
Comment thread packages/react-native/package.json
mxmzb and others added 4 commits April 20, 2026 15:38
…, clean up headless exports

Move LicenseContext and useLicenseContext from CopilotKitProvider.tsx into
context.ts so both web and RN providers share the same context singleton.
Use import type for LicenseContextValue to avoid pulling @copilotkit/shared
(and its Node-only jose dep) into the RN bundle at runtime.

Also remove unused CopilotKitContext/useCopilotKit re-exports from headless.ts —
the externalize-context tsdown plugin already handles these via relative imports.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…enseContext

Address PR feedback from @AlemTuzlak:

- Split monolithic polyfills.ts into individual imports (streams, encoding,
  crypto, dom, location) so users control what gets polyfilled
- Remove auto-polyfill from index.ts — users explicitly import what they need
- Add sideEffects array to package.json for bundler correctness
- Wire LicenseContext.Provider into the RN CopilotKitProvider
- Add new polyfill entry points to tsdown config and package.json exports
- Use globalThis consistently (no more declare const global conflicts)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…alias, simplify provider

- Use `const g = globalThis as Record<string, unknown>` in polyfill files
  instead of repeating `(globalThis as any)` on every assignment line
- Add `export {}` to polyfill files without imports so TS treats them as
  modules with isolated scope (prevents top-level variable collisions)
- Document the pattern rationale in types.d.ts for future reference
- Move shape validation from contextValue useMemo to one-time construction
- Consolidate onAbort handler with centralized fail() function
- Simplify onError event forwarding (pass event directly)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…d, eliminate unsafe cast

The headless build previously inlined @copilotkit/core via noExternal,
creating a duplicate CopilotKitCoreReact class declaration in the .d.ts.
Since the class has private members, TypeScript treated the two declarations
as nominally distinct, forcing an `as unknown as CopilotKitContextValue`
cast in the RN provider with runtime shape validation.

@copilotkit/core has zero Node-only dependencies — the inlining was
unnecessary. By keeping it external:

- context.ts now value-exports CopilotKitCoreReact (was type-only import)
- headless.ts re-exports from ./context (externalized to package path)
- headless .d.ts references context's type → single declaration → no cast
- RN provider uses plain typed code, no as-unknown-as, no shape validation
- headless bundle is significantly smaller

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants