Repository navigation
docs(react-native): expand into a production guide - #6144
Conversation
Production Digest-Pinning AuditAll 41 services digest-pinned. Run 2026-07-27 15:20:57 PDT — 0 finding(s). |
samjulien
left a comment
There was a problem hiding this comment.
Thanks for expanding this material—there is a lot of useful production context here. I’m requesting changes because several copy-paste paths conflict with the current React Native export/runtime behavior and could leave readers with missing UI, stale auth headers, or platform-specific connection failures.
The inline comments cover the source-backed accuracy issues. At the page level, please also revisit the information architecture: this grows the page to 535 lines while retaining hideTOC: true and the description “Get started with CopilotKit in React Native.” Please either enable the TOC and update the frontmatter or split the quickstart from the production guide. The production material also needs to be integrated into the existing steps rather than appended as later corrections—most notably the /headless imports and polyfill setup.
Current CI is green, but these are semantic and reader-UX issues that the existing docs checks do not catch.
| | `useAgent`, `useFrontendTool`, etc. | Re-exported hooks from `@copilotkit/react-core` | | ||
| | `@copilotkit/react-native/polyfills` | ReadableStream, TextEncoder, crypto, DOMException, location | | ||
| | `@copilotkit/runtime` | Server-side runtime used to host your `default` agent | | ||
| | `@copilotkit/react-native` | The full barrel: `CopilotKitProvider`, the re-exported hooks, and the pre-built chat components (`CopilotChat`, `CopilotModal`, `CopilotSidebar`, `CopilotPopup`) plus `useAttachments` | |
There was a problem hiding this comment.
The package surface is not accurate here. The default barrel’s CopilotChat and CopilotModal are the headless wrappers from src/CopilotChat.tsx and src/CopilotModal.tsx; the fully rendered chat and bottom-sheet modal are exported from @copilotkit/react-native/components. The root barrel also does not pull @gorhom/bottom-sheet through those headless exports. Please document the root, /headless, and /components surfaces separately so readers import the UI they expect.
| | `@copilotkit/react-native/polyfills/{streams,encoding,crypto,dom,location}` | Granular subpaths for installing a single polyfill | | ||
| | `@copilotkit/runtime` | Server-side runtime (`CopilotRuntime` / `BuiltInAgent` / `createCopilotNodeListener`) used to host your agent | | ||
|
|
||
| The provider re-exports the platform-agnostic hooks from `@copilotkit/react-core` — `useAgent`, `useFrontendTool`, `useHumanInTheLoop`, `useCopilotKit`, `useSuggestions`, `useInterrupt`, `useRenderTool`, and more. They behave identically to the web SDK. |
There was a problem hiding this comment.
The provider does not re-export hooks; the package does. “They behave identically to the web SDK” is also too broad: React Native substitutes its own useRenderTool path and deliberately excludes web-only rendering hooks. Please enumerate the supported shared hooks or link the React Native API reference instead of promising full behavioral identity.
| The `headless` entry exports the provider and every platform-agnostic hook — everything in this guide except the pre-built chat components. Polyfills are still auto-installed. The default barrel re-exports everything from `headless` plus the chat UI, so existing `@copilotkit/react-native` imports keep working unchanged. | ||
|
|
||
| <Callout type="info" title="Use headless for custom UIs"> | ||
| If you build your own chat interface (as the quickstart does), prefer `@copilotkit/react-native/headless`. You only need the default barrel when you actually render `CopilotChat` / `CopilotSidebar` / `CopilotPopup` or use `useAttachments`. |
There was a problem hiding this comment.
The quickstart above imports the provider and hooks from the default barrel for a fully custom UI, but this callout says that exact reader should use /headless to avoid native peer dependencies. Please update the quickstart imports (currently lines 122 and 160) to /headless and reconcile the opening “headless” description with the package-surface section.
|
|
||
| ## Metro configuration for release bundles | ||
|
|
||
| CopilotKit's dependency graph reaches `jose` (a JWT/license dependency, pulled in transitively through `@copilotkit/shared`). `jose` ships separate Node and browser builds behind a package `exports` map, and Metro's default resolution selects the Node build, which imports `node:`-prefixed modules that can't be bundled for Hermes. This surfaces **only at release-bundle time** (`Unable to resolve module node:...`), never at typecheck. Enable package exports and put `browser` ahead of the Node conditions so `jose` (and any similar dual-build dependency) resolves to its browser build: |
There was a problem hiding this comment.
This explanation of Metro condition resolution is inaccurate and the global configuration is risky. unstable_conditionNames asserts conditions; array order does not establish package-export priority, and globally asserting browser can change resolution for unrelated dependencies. The page also claims React Native 0.70+, although package exports arrived in 0.72 and are enabled by default in Metro 0.82 / React Native 0.79. Please document the tested version bounds and scope the browser override to jose with resolveRequest while preserving Metro’s defaults.
|
|
||
| Hermes lacks several Web APIs CopilotKit relies on: `ReadableStream` / `WritableStream` / `TransformStream`, `TextEncoder` / `TextDecoder`, `DOMException` and `Headers`, `crypto.getRandomValues`, and `window.location`. It also lacks streaming `fetch` bodies (`response.body.getReader()`), which AG-UI's SSE transport needs. | ||
|
|
||
| **These are installed automatically the moment `@copilotkit/react-native` (or its `headless` entry) is imported** — the package runs its polyfill barrel and installs an XHR-based streaming-fetch shim on load. The manual `import "@copilotkit/react-native/polyfills"` shown in the quickstart is optional belt-and-suspenders: it's useful when you want the polyfills to run before other imports at your entry point, or when you're installing a secure crypto source first (below). Each polyfill is a no-op if the global it defines already exists, so importing more than once is safe. |
There was a problem hiding this comment.
This contradicts the quickstart, which says the manual polyfill barrel import is required before any other code. The production secure-RNG path also needs react-native-get-random-values to load before any CopilotKit import, while the quickstart currently installs CopilotKit’s insecure fallback first. Please make the quickstart canonical and avoid appending a later correction.
|
|
||
| ## Runtime and model wiring | ||
|
|
||
| The runtime from the quickstart hosts a `BuiltInAgent` and serves it with `createCopilotNodeListener`, which plugs straight into Node's built-in `node:http` `createServer` — no Hono or Express dependency required. `createCopilotNodeListener({ runtime, basePath, cors })` returns a request listener; `cors: true` is what lets the app reach it cross-origin from a device. |
There was a problem hiding this comment.
Native React Native networking has no browser CORS model, so cors: true is not what lets a physical device reach this server. It can matter for Expo Web/browser clients; native reachability depends on the server bind address, routing/firewall, and platform transport security. Please correct this causal explanation.
| |-------|-------------------| | ||
| | iOS simulator | `localhost` reaches the host machine | | ||
| | Android emulator | `10.0.2.2` is the emulator's alias for the host's `localhost` | | ||
| | USB-attached device | run `adb reverse tcp:8200 tcp:8200`, then use `localhost` on the device | |
There was a problem hiding this comment.
adb reverse applies only to Android USB devices, so this generic row is misleading for iOS. The LAN http:// recommendation also needs iOS App Transport Security guidance; the section currently covers only Android cleartext. Please add an iOS physical-device/ATS path, label this row Android, and include the expo-build-properties installation step before its plugin configuration.
| Because the tool is registered on the device, the model's call reaches your `handler` on the client — the ideal place to drive a state reducer that your React Native views render declaratively (the agent sends *state*, the client owns rendering). Discriminated-union / `oneOf` / `anyOf` param schemas are preserved through the runtime's schema conversion, so `z.discriminatedUnion(...)` params work. It's still good practice to normalize defensively in the handler — coerce a partially populated tool call into valid state rather than letting a malformed one render broken UI. | ||
|
|
||
| <Callout type="info" title="Rendering tool UI"> | ||
| A frontend tool can also carry a `render` function that returns React Native components, drawn as the tool runs. For arbitrary, agent-authored content whose length you can't predict, render it in a `ScrollView` with a `maxHeight` set to the available band — it sizes to content when short and scrolls when long, so it never hard-clips. |
There was a problem hiding this comment.
For inline UI rendered by React Native’s chat component, the documented hook should be the React Native useRenderTool. useFrontendTool({ render }) registers with react-core’s renderer collection, while the prebuilt React Native CopilotChat reads the separate RenderToolContext registry populated by useRenderTool. Please separate handler-driven state for a custom UI from inline chat rendering; the latter is not drawn automatically by this useFrontendTool path.
| Running a user turn is the two-step the quickstart shows: `agent.addMessage(...)` then `copilotkit.runAgent({ agent })` (the runner lives on the core, not the agent). To cancel an in-flight run, call `copilotkit.stopAgent({ agent })`. To scope a run to a specific conversation without a chat-configuration provider in the tree, pass `threadId` to `useAgent`: | ||
|
|
||
| ```tsx | ||
| const { agent } = useAgent({ agentId: "default", threadId }); // [!code highlight] |
| - **No pre-built UI components** - you build the chat interface with React Native components | ||
| - **Markdown rendering** - assistant messages with markdown render as plain text; bring your own renderer (e.g. `react-native-markdown-display`) | ||
| - **Voice** - `@copilotkit/voice` has not been adapted for React Native yet | ||
| - **No pre-built UI is required** — the package is headless by design; you build the chat interface with React Native components (the pre-built `CopilotChat` / `CopilotSidebar` / `CopilotPopup` are opt-in via the default barrel). |
There was a problem hiding this comment.
“No pre-built UI is required” is product positioning, not a limitation, and it repeats the incorrect export-surface description above. Please reserve this section for actual unsupported or constrained behavior and point readers to the exact /components surface when discussing the rendered chat UI.
Rewrites the React Native page into a production guide (Metro, polyfills,
provider options, runtime/model wiring, device + bench connectivity, frontend
tools, run lifecycle, voice), and corrects the source-backed inaccuracies found
in review. Every claim below was re-verified against the package source on main
(@copilotkit/react-native 1.63.2), not inferred.
Import surfaces (was "What's included" + "Headless imports")
- Documents all THREE entry points separately with the native peers each forces
Metro to resolve: /headless (none), root (expo-document-picker,
expo-file-system via useAttachments), /components (@gorhom/bottom-sheet,
react-native-streamdown).
- Removes the claim that the root barrel pulls @gorhom/bottom-sheet. It does
not -- the only import is src/components/CopilotModal.tsx, reachable solely
from /components. (The package's own source comments state this incorrectly;
that is what the previous draft was written from.)
- Warns that root's CopilotChat/CopilotModal are HEADLESS wrappers rendering
only children, while the same-named /components exports are the rendered
chat -- a silent blank-screen trap.
- The quickstart now imports from /headless throughout, matching its own advice
and keeping readers out of the release-bundle failure the page warns about.
- Corrects "the provider re-exports hooks" to the package, enumerates the
shared hooks, and drops "behave identically to the web SDK": React Native
ships its OWN useRenderTool (requires parameters, accepts handler, returns
ReactElement | null, no wildcard) and omits the web-only rendering hooks.
Metro
- Corrects the cause: jose is not a JWT/license dependency. It arrives via
telemetry (@copilotkit/shared -> @segment/analytics-node -> jose).
- Replaces the global unstable_conditionNames array with resolveRequest scoped
to jose (Metro's own documented recipe). unstable_conditionNames is an
UNORDERED SET of asserted conditions -- target priority comes from each
package's own exports key order, so reordering that array does nothing. The
previous config also applied browser globally and dropped Metro's default
react-native condition.
- Fixes version bounds: package exports arrived opt-in in RN 0.72 / Metro
0.76.1 and is default-on from Metro 0.82 / RN 0.79 (not "0.70+").
Polyfills
- Makes the quickstart canonical instead of correcting it later. Drops
"optional belt-and-suspenders".
- Documents the crypto ordering as a HARD requirement: CopilotKit's polyfill
and react-native-get-random-values are both first-writer-wins, so any
CopilotKit import evaluated first permanently locks in the non-cryptographic
Math.random fallback and silently no-ops the secure library.
Provider / runtime
- headers: a function form is evaluated when the PROVIDER RENDERS, memoized,
and pushed to the core -- never per request. Adds rotating-token guidance
(drive from state, or call copilotkit.setHeaders on refresh).
- cors: corrects the causal claim. CORS is browser-enforced; React Native's
native stack sends no Origin and never consults Access-Control-Allow-Origin,
so cors:true is irrelevant to native reachability (it matters for Expo Web).
Device connectivity
- Labels the adb reverse row Android-only and adds an iOS device row.
- Adds the missing `npx expo install expo-build-properties` step.
- Adds the iOS path, which was absent: ATS applies to debug and release alike,
expo-build-properties has no iOS ATS option, and since iOS 17 ATS rejects
raw IPs unless listed in NSExceptionDomains -- plus
NSLocalNetworkUsageDescription for the local-network permission gate. Notes
why NSAllowsLocalNetworking alone is insufficient.
Frontend tools
- Replaces the incorrect "useFrontendTool can carry a render function drawn as
the tool runs". The rendered RN chat reads a registry populated only by RN's
useRenderTool; a render passed to useFrontendTool is never drawn there and
yields the fallback "Called: <toolName>" stub.
Other
- Removes the useAgent({ threadId }) example: unsupported on main, does not
typecheck (TS2353), silently ignored. Recorded as a known limitation
pointing at #6141 instead, so this page no longer depends on that PR.
- Known limitations: drops the "No pre-built UI is required" positioning line;
corrects the markdown entry (the rendered chat DOES render markdown via
CopilotMarkdown/react-native-streamdown -- the old entry recommended the
wrong library); adds the threadId and web-only-hooks entries.
- Broadens the frontmatter description, which still promised only "get started".
Co-Authored-By: Claude Opus 4.8 <[email protected]>
1d31d95 to
188bc6c
Compare
|
Thanks — this was a genuinely useful review. I re-verified every point against the package source on Rebased onto current Sustained and fixed
One partial
One push-back: the TOC / page splitI'd like to keep
So a long page with Separate issues found while verifying (not fixed here)Three package-level bugs, which I'll file separately rather than smuggle into a docs PR:
Also worth noting for a future cleanup: |
@copilotkit/a2ui-renderer
@copilotkit/agentcore-runner
@copilotkit/angular
@copilotkit/channels
@copilotkit/channels-core
@copilotkit/channels-discord
@copilotkit/channels-intelligence
@copilotkit/channels-slack
@copilotkit/channels-teams
@copilotkit/channels-telegram
@copilotkit/channels-ui
@copilotkit/channels-whatsapp
@copilotkit/core
@copilotkit/react-core
@copilotkit/react-native
@copilotkit/react-textarea
@copilotkit/react-ui
@copilotkit/runtime
@copilotkit/runtime-client-gql
@copilotkit/sdk-js
@copilotkit/shared
@copilotkit/sqlite-runner
@copilotkit/voice
@copilotkit/vue
@copilotkit/web-components
@copilotkit/web-inspector
commit: |
samjulien
left a comment
There was a problem hiding this comment.
Thanks for the thorough revision—most of the original accuracy issues are now addressed. I found three remaining blockers around release availability, the supported React Native floor, and which entry points install polyfills; details inline.
Two non-blocking UX improvements would also make the guide easier to follow:
- The frontend-tool section says to add Zod but does not provide an installation command.
- The prerequisites promise both bare React Native and Expo, but app creation/run commands cover only bare CLI while the physical-device configuration covers only Expo. Consider adding framework-specific tabs or explicitly scoping each path.
I’m treating the no-TOC concern as section-wide docs UX debt rather than blocking this PR, given the established convention you documented.
|
|
||
| ```tsx title="App.tsx" | ||
| import { CopilotKitProvider } from "@copilotkit/react-native"; // [!code highlight] | ||
| import { CopilotKitProvider } from "@copilotkit/react-native/headless"; // [!code highlight] |
There was a problem hiding this comment.
[P1] The unversioned install step currently resolves to stable @copilotkit/[email protected], but that release does not export @copilotkit/react-native/headless; the subpath exists only in the current canary. The documented runtime base-URL and union-schema fixes also landed after 1.63.2. As written, a reader following the quickstart gets an unresolved import here. Please gate the docs deployment on a stable release containing these APIs, or explicitly install/document a version that contains them.
| </Callout> | ||
|
|
||
| <Callout type="info" title="Do you need `unstable_enablePackageExports`?"> | ||
| Package `exports` resolution is **enabled by default from Metro 0.82 / React Native 0.79**, so no flag is needed there. It arrived opt-in in React Native 0.72 (Metro 0.76.1) — on React Native 0.72–0.78 set `resolver.unstable_enablePackageExports = true`, which is also what lets Metro resolve this package's `/headless`, `/components`, and `/polyfills` subpaths. React Native below 0.72 has no package-exports support. |
There was a problem hiding this comment.
[P1] This correctly says React Native below 0.72 has no package-exports support, but the prerequisite still advertises React Native 0.70+ and every frontend example uses /headless. Please make 0.72 the guide minimum—ideally recommending RN 0.79 / Metro 0.82.3+—or provide a separate 0.70–0.71 path using the root export and its required peers.
| } from "@copilotkit/react-native/headless"; // [!code highlight] | ||
| ``` | ||
|
|
||
| All three surfaces auto-install the polyfills, and the root barrel re-exports everything from `/headless`, so existing `@copilotkit/react-native` imports keep working unchanged. |
There was a problem hiding this comment.
[P2] /components does not import the polyfill barrel: the root and /headless entries do, but src/components/index.ts only re-exports components. Please say that the two provider surfaces auto-install polyfills. An app pairing /components with CopilotKitProvider gets them through the provider import; importing /components alone does not.
Independent re-verification against packages/react-native source found the page overstated polyfill auto-install: only /headless (and the root barrel, via its /headless re-export) side-effect-imports the polyfill barrel. src/components/index.ts imports no polyfills, so a consumer importing only from @copilotkit/react-native/components does not get them auto-installed; it relies on the provider imported alongside it. Corrects the 'all three surfaces auto-install' and 'every entry point installs these automatically' statements accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
What
Expands the React Native docs page from a "get to first chat" quickstart into a full production guide, matching the depth of the Slack/Teams frontend pages. The existing quickstart Steps are unchanged; the new material is added after them.
Production sections added
@copilotkit/react-native/headlessfor a custom-UI app, avoiding the chat/attachment native peer deps the default barrel re-exports.unstable_enablePackageExports+ browser-firstunstable_conditionNamesso the transitivejosedependency resolves to its browser build (fails only at release-bundle time otherwise).cryptopolyfill (backed byMath.random) and the recommendation to install a secure RNG for production.CopilotKitProviderprop surface:runtimeUrl,headers(auth),credentials,properties,onError,debug,defaultThrottleMs,useSingleEndpoint.OPENAI_BASE_URL(and Anthropic/Google equivalents) for OpenAI-compatible endpoints,createCopilotNodeListenerzero-dep serving, andBuiltInAgentoptions.10.0.2.2,adb reversefor USB, and Android release cleartext HTTP viaexpo-build-properties.useFrontendToolwith zod/Standard Schema, the send-a-turn recipe,useAgentread-only subscribe +threadId, discriminated-union params, and variable-lengthScrollViewrendering.isRunningoutliving the visible compose, and gating overlays/reveal motion accordingly.Dependency on runtime / react-native fixes
Three of the four fixes this guide relies on are now merged to
main, so it documents them as current behavior:@copilotkit/react-native/headlesssubpath (headless provider + hooks without chat/attachment deps) — fix(react-native): add /headless subpath so custom-UI consumers skip chat/attachment native deps #6142 ✅ mergedresolveModelhonoringOPENAI_BASE_URL/ANTHROPIC_BASE_URL/GOOGLE_GENERATIVE_AI_BASE_URLfor the string model form — fix(runtime): honor *_BASE_URL env vars in resolveModel for OpenAI-compatible endpoints #6140 ✅ mergedanyOf/oneOftool-param schemas surviving JSON-schema→zod conversion — fix(runtime): preserve anyOf/oneOf unions in frontend tool schemas #6143 ✅ mergedThe fourth —
useAgentaccepting an optionalthreadId(#6141) — is still open. The guide therefore does not document it as working; it is listed under Known limitations instead, and will be promoted once #6141 lands.Every API, export, env var, and behavior in the page was independently re-verified against the package source (three parallel source audits over
packages/{react-native,react-core,runtime}). That pass turned up one overstatement, fixed in 6eefe2b: only/headlessand the root barrel side-effect-import the polyfill barrel —@copilotkit/react-native/componentsdoes not, so the "all three surfaces auto-install" wording was corrected.🤖 Generated with Claude Code