Skip to content

fix(react-core): honor threadId prop on useAgent - #6141

Merged
tylerslaton merged 7 commits into
mainfrom
fix/useagent-threadid
Jul 29, 2026
Merged

tylerslaton merged 7 commits into
mainfrom
fix/useagent-threadid

Conversation

@davidmckayv

Copy link
Copy Markdown
Contributor

Problem

UseAgentProps (packages/react-core/src/v2/hooks/use-agent.tsx) exposed only { agentId?, updates?, throttleMs? } — there was no threadId. Yet the shipped V2 React Native demo calls:

const { agent } = useAgent({ agentId: "default", threadId });

(examples/v2/react-native/demo/src/ChatScreen.tsx)

Because the prop didn't exist on the type, it was silently ignored. The demo's threadId state — and its "New Chat" reset (setThreadId(generateThreadId())) — never reached the agent. The demo has no <CopilotChatConfigurationProvider> in its tree (see App.tsx), which was the only source the hook read threadId from, so the agent ran under its own auto-minted UUID the whole time. A misleading API: the demo advertised a supported prop that did nothing.

Fix

Accept an optional threadId on UseAgentProps and honor it. Resolution precedence:

  1. An explicit threadId prop wins — lets headless callers (e.g. React Native) scope the run to a thread with no chat-configuration provider in the tree.
  2. Otherwise fall back to the surrounding chat configuration's threadId, gated on hasExplicitThreadId exactly as before.

The threadId still lands on agent.threadId, which ProxiedCopilotRuntimeAgent uses to address /agent/run, /agent/connect, and /agent/stop.

Backward compatibility

Fully backward compatible: threadId is optional, and when omitted the behavior is byte-for-byte unchanged (config-sourced, hasExplicitThreadId-gated). No demo change is needed — the RN demo's existing useAgent({ agentId, threadId }) call now works as it always appeared to.

Tests

Extends the existing threadId-propagation contract test (packages/react-core/src/__tests__/threadid-propagation.contract.test.tsx) with the prop path:

  • honors an explicit threadId prop with no CopilotChatConfigurationProvider (the RN demo scenario)
  • prefers the threadId prop over the chat configuration's threadId
  • re-syncs agent.threadId when the prop changes

The pre-existing config-sourced invariants remain covered and unchanged.

🤖 Generated with Claude Code

UseAgentProps had no `threadId`, yet the shipped V2 React Native demo
calls `useAgent({ agentId: "default", threadId })`. Because the prop
didn't exist, it was silently dropped: the demo's thread state (and its
"New Chat" reset) never reached the agent, which ran under its own
auto-minted UUID. threadId was only ever sourced from a surrounding
`CopilotChatConfigurationProvider`, which the headless RN demo has none.

Accept an optional `threadId` on UseAgentProps and honor it. Resolution
precedence: an explicit `threadId` prop wins; otherwise fall back to the
chat configuration's threadId (gated on hasExplicitThreadId, as before).
When the prop is omitted, behavior is unchanged — fully backward
compatible. This makes the RN demo's existing usage work and unblocks
headless callers that have no chat-configuration provider in the tree.

Extends the threadId-propagation contract test with coverage for the
prop path (no provider, prop-over-config precedence, prop re-sync).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@pkg-pr-new

pkg-pr-new Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@copilotkit/a2ui-renderer

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

@copilotkit/agentcore-runner

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/agentcore-runner@6141

@copilotkit/angular

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

@copilotkit/channels

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

@copilotkit/channels-core

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/channels-core@6141

@copilotkit/channels-discord

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/channels-discord@6141

@copilotkit/channels-intelligence

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/channels-intelligence@6141

@copilotkit/channels-slack

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/channels-slack@6141

@copilotkit/channels-teams

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/channels-teams@6141

@copilotkit/channels-telegram

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/channels-telegram@6141

@copilotkit/channels-ui

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/channels-ui@6141

@copilotkit/channels-whatsapp

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/channels-whatsapp@6141

@copilotkit/core

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

@copilotkit/react-core

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

@copilotkit/react-native

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

@copilotkit/react-textarea

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

@copilotkit/react-ui

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

@copilotkit/runtime

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

@copilotkit/runtime-client-gql

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

@copilotkit/sdk-js

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

@copilotkit/shared

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

@copilotkit/sqlite-runner

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

@copilotkit/voice

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

@copilotkit/vue

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

@copilotkit/web-components

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/web-components@6141

@copilotkit/web-inspector

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

commit: 4c2dd14

@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Size Change: +3.75 kB (+0.31%)

Total Size: 1.2 MB

📦 View Changed
Filename Size Change
packages/react-core/dist/copilotkit-BrNiD3wI.cjs 107 kB +107 kB (new file) 🆕
packages/react-core/dist/copilotkit-BrZGzZw6.mjs 106 kB +106 kB (new file) 🆕
packages/react-core/dist/copilotkit-D_5VbHM6.mjs 0 B -105 kB (removed) 🏆
packages/react-core/dist/copilotkit-Dsbkpn7h.cjs 0 B -107 kB (removed) 🏆
packages/react-core/dist/index.cjs 16.9 kB +1 B (+0.01%)
packages/react-core/dist/index.mjs 16.8 kB -1 B (-0.01%)
packages/react-core/dist/index.umd.js 65 kB +625 B (+0.97%)
packages/react-core/dist/v2/headless.cjs 13.5 kB +606 B (+4.72%) 🔍
packages/react-core/dist/v2/headless.mjs 12.9 kB +605 B (+4.91%) 🔍
packages/react-core/dist/v2/index.umd.js 107 kB +641 B (+0.6%)
ℹ️ View Unchanged
Filename Size
packages/a2ui-renderer/dist/_virtual/_rolldown/runtime.cjs 516 B
packages/a2ui-renderer/dist/a2ui-types.cjs 172 B
packages/a2ui-renderer/dist/a2ui-types.mjs 171 B
packages/a2ui-renderer/dist/index.cjs 842 B
packages/a2ui-renderer/dist/index.mjs 563 B
packages/a2ui-renderer/dist/index.umd.js 12.2 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/A2uiSurface.cjs 1.49 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/A2uiSurface.mjs 1.43 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/adapter.cjs 1.07 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/adapter.mjs 1.01 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/AudioPlayer.cjs 904 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/AudioPlayer.mjs 492 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Button.cjs 1 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Button.mjs 596 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Card.cjs 829 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Card.mjs 419 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/CheckBox.cjs 1.1 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/CheckBox.mjs 1.02 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/ChildList.cjs 799 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/ChildList.mjs 737 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/ChoicePicker.cjs 1.63 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/ChoicePicker.mjs 1.57 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Column.cjs 856 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Column.mjs 802 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/DateTimeInput.cjs 1.12 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/DateTimeInput.mjs 1.05 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Divider.cjs 842 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Divider.mjs 432 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Icon.cjs 877 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Icon.mjs 469 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Image.cjs 995 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Image.mjs 587 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/List.cjs 920 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/List.mjs 508 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Modal.cjs 1.19 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Modal.mjs 1.13 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Row.cjs 855 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Row.mjs 801 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Slider.cjs 1.06 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Slider.mjs 984 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Tabs.cjs 1.1 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Tabs.mjs 1.04 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Text.cjs 903 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Text.mjs 489 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/TextField.cjs 1.21 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/TextField.mjs 1.14 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Video.cjs 788 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/components/Video.mjs 378 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/index.cjs 928 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/index.mjs 855 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/utils.cjs 579 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/basic/utils.mjs 556 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/Button.cjs 982 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/Button.mjs 580 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/ChildList.cjs 800 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/ChildList.mjs 735 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/Column.cjs 1.08 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/Column.mjs 1.02 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/Row.cjs 1.07 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/Row.mjs 1.01 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/Text.cjs 894 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/Text.mjs 839 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/TextField.cjs 1.21 kB
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/components/TextField.mjs 802 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/index.cjs 849 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/catalog/minimal/index.mjs 804 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/index.cjs 310 B
packages/a2ui-renderer/dist/react-renderer/a2ui-react/index.mjs 325 B
packages/a2ui-renderer/dist/react-renderer/catalog-utils.cjs 1.59 kB
packages/a2ui-renderer/dist/react-renderer/catalog-utils.mjs 1.52 kB
packages/a2ui-renderer/dist/react-renderer/core/A2UIProvider.cjs 1.5 kB
packages/a2ui-renderer/dist/react-renderer/core/A2UIProvider.mjs 1.42 kB
packages/a2ui-renderer/dist/react-renderer/core/A2UIRenderer.cjs 728 B
packages/a2ui-renderer/dist/react-renderer/core/A2UIRenderer.mjs 671 B
packages/a2ui-renderer/dist/react-renderer/create-catalog.cjs 1.35 kB
packages/a2ui-renderer/dist/react-renderer/create-catalog.mjs 1.28 kB
packages/a2ui-renderer/dist/react-renderer/hooks/useA2UI.cjs 316 B
packages/a2ui-renderer/dist/react-renderer/hooks/useA2UI.mjs 309 B
packages/a2ui-renderer/dist/react-renderer/index.cjs 399 B
packages/a2ui-renderer/dist/react-renderer/index.mjs 515 B
packages/a2ui-renderer/dist/react-renderer/lib/utils.cjs 236 B
packages/a2ui-renderer/dist/react-renderer/lib/utils.mjs 188 B
packages/a2ui-renderer/dist/react-renderer/styles/index.cjs 239 B
packages/a2ui-renderer/dist/react-renderer/styles/index.mjs 231 B
packages/a2ui-renderer/dist/react-renderer/theme/ThemeContext.cjs 436 B
packages/a2ui-renderer/dist/react-renderer/theme/ThemeContext.mjs 381 B
packages/a2ui-renderer/dist/web-components/_virtual/_rolldown/runtime.cjs 260 B
packages/a2ui-renderer/dist/web-components/_virtual/_rolldown/runtime.mjs 258 B
packages/a2ui-renderer/dist/web-components/adapter.cjs 346 B
packages/a2ui-renderer/dist/web-components/adapter.mjs 335 B
packages/a2ui-renderer/dist/web-components/bound-component.cjs 670 B
packages/a2ui-renderer/dist/web-components/bound-component.mjs 662 B
packages/a2ui-renderer/dist/web-components/catalog/basic/audio-player.cjs 536 B
packages/a2ui-renderer/dist/web-components/catalog/basic/audio-player.mjs 492 B
packages/a2ui-renderer/dist/web-components/catalog/basic/button.cjs 647 B
packages/a2ui-renderer/dist/web-components/catalog/basic/button.mjs 604 B
packages/a2ui-renderer/dist/web-components/catalog/basic/card.cjs 448 B
packages/a2ui-renderer/dist/web-components/catalog/basic/card.mjs 402 B
packages/a2ui-renderer/dist/web-components/catalog/basic/check-box.cjs 743 B
packages/a2ui-renderer/dist/web-components/catalog/basic/check-box.mjs 695 B
packages/a2ui-renderer/dist/web-components/catalog/basic/choice-picker.cjs 1.27 kB
packages/a2ui-renderer/dist/web-components/catalog/basic/choice-picker.mjs 1.24 kB
packages/a2ui-renderer/dist/web-components/catalog/basic/column.cjs 474 B
packages/a2ui-renderer/dist/web-components/catalog/basic/column.mjs 431 B
packages/a2ui-renderer/dist/web-components/catalog/basic/components.cjs 482 B
packages/a2ui-renderer/dist/web-components/catalog/basic/components.mjs 424 B
packages/a2ui-renderer/dist/web-components/catalog/basic/date-time-input.cjs 756 B
packages/a2ui-renderer/dist/web-components/catalog/basic/date-time-input.mjs 714 B
packages/a2ui-renderer/dist/web-components/catalog/basic/divider.cjs 450 B
packages/a2ui-renderer/dist/web-components/catalog/basic/divider.mjs 404 B
packages/a2ui-renderer/dist/web-components/catalog/basic/icon.cjs 504 B
packages/a2ui-renderer/dist/web-components/catalog/basic/icon.mjs 455 B
packages/a2ui-renderer/dist/web-components/catalog/basic/ids.cjs 192 B
packages/a2ui-renderer/dist/web-components/catalog/basic/ids.mjs 190 B
packages/a2ui-renderer/dist/web-components/catalog/basic/image.cjs 624 B
packages/a2ui-renderer/dist/web-components/catalog/basic/image.mjs 578 B
packages/a2ui-renderer/dist/web-components/catalog/basic/index.cjs 465 B
packages/a2ui-renderer/dist/web-components/catalog/basic/index.mjs 526 B
packages/a2ui-renderer/dist/web-components/catalog/basic/list.cjs 534 B
packages/a2ui-renderer/dist/web-components/catalog/basic/list.mjs 483 B
packages/a2ui-renderer/dist/web-components/catalog/basic/modal.cjs 842 B
packages/a2ui-renderer/dist/web-components/catalog/basic/modal.mjs 800 B
packages/a2ui-renderer/dist/web-components/catalog/basic/row.cjs 471 B
packages/a2ui-renderer/dist/web-components/catalog/basic/row.mjs 427 B
packages/a2ui-renderer/dist/web-components/catalog/basic/slider.cjs 701 B
packages/a2ui-renderer/dist/web-components/catalog/basic/slider.mjs 653 B
packages/a2ui-renderer/dist/web-components/catalog/basic/tabs.cjs 780 B
packages/a2ui-renderer/dist/web-components/catalog/basic/tabs.mjs 730 B
packages/a2ui-renderer/dist/web-components/catalog/basic/text-field.cjs 857 B
packages/a2ui-renderer/dist/web-components/catalog/basic/text-field.mjs 814 B
packages/a2ui-renderer/dist/web-components/catalog/basic/text.cjs 553 B
packages/a2ui-renderer/dist/web-components/catalog/basic/text.mjs 501 B
packages/a2ui-renderer/dist/web-components/catalog/basic/utils.cjs 484 B
packages/a2ui-renderer/dist/web-components/catalog/basic/utils.mjs 462 B
packages/a2ui-renderer/dist/web-components/catalog/basic/video.cjs 400 B
packages/a2ui-renderer/dist/web-components/catalog/basic/video.mjs 352 B
packages/a2ui-renderer/dist/web-components/catalog/children.cjs 302 B
packages/a2ui-renderer/dist/web-components/catalog/children.mjs 300 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/button.cjs 629 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/button.mjs 584 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/column.cjs 609 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/column.mjs 559 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/components.cjs 245 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/components.mjs 263 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/index.cjs 724 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/index.mjs 654 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/row.cjs 593 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/row.mjs 544 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/text-field.cjs 874 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/text-field.mjs 822 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/text.cjs 509 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/text.mjs 477 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/utils.cjs 291 B
packages/a2ui-renderer/dist/web-components/catalog/minimal/utils.mjs 287 B
packages/a2ui-renderer/dist/web-components/create-catalog.cjs 1.89 kB
packages/a2ui-renderer/dist/web-components/create-catalog.mjs 1.83 kB
packages/a2ui-renderer/dist/web-components/define.cjs 440 B
packages/a2ui-renderer/dist/web-components/define.mjs 341 B
packages/a2ui-renderer/dist/web-components/index.cjs 960 B
packages/a2ui-renderer/dist/web-components/index.mjs 655 B
packages/a2ui-renderer/dist/web-components/node.cjs 1.05 kB
packages/a2ui-renderer/dist/web-components/node.mjs 1.04 kB
packages/a2ui-renderer/dist/web-components/surface.cjs 2.83 kB
packages/a2ui-renderer/dist/web-components/surface.mjs 2.81 kB
packages/core/dist/index.cjs 48.5 kB
packages/core/dist/index.mjs 48.1 kB
packages/core/dist/index.umd.js 51.8 kB
packages/react-core/dist/v2/context.cjs 1.55 kB
packages/react-core/dist/v2/context.mjs 1.47 kB
packages/react-core/dist/v2/index.cjs 1.26 kB
packages/react-core/dist/v2/index.mjs 1.12 kB
packages/react-textarea/dist/index.cjs 18.1 kB
packages/react-textarea/dist/index.mjs 17.4 kB
packages/react-textarea/dist/index.umd.js 18.8 kB
packages/react-ui/dist/index.cjs 24.6 kB
packages/react-ui/dist/index.mjs 23.9 kB
packages/react-ui/dist/index.umd.js 25.8 kB
packages/runtime-client-gql/dist/_virtual/_rolldown/runtime.cjs 516 B
packages/runtime-client-gql/dist/client/conversion.cjs 1.52 kB
packages/runtime-client-gql/dist/client/conversion.mjs 1.45 kB
packages/runtime-client-gql/dist/client/CopilotRuntimeClient.cjs 1.58 kB
packages/runtime-client-gql/dist/client/CopilotRuntimeClient.mjs 1.54 kB
packages/runtime-client-gql/dist/client/types.cjs 701 B
packages/runtime-client-gql/dist/client/types.mjs 642 B
packages/runtime-client-gql/dist/graphql/@generated/gql.cjs 850 B
packages/runtime-client-gql/dist/graphql/@generated/gql.mjs 850 B
packages/runtime-client-gql/dist/graphql/@generated/graphql.cjs 2.4 kB
packages/runtime-client-gql/dist/graphql/@generated/graphql.mjs 2.36 kB
packages/runtime-client-gql/dist/graphql/definitions/mutations.cjs 740 B
packages/runtime-client-gql/dist/graphql/definitions/mutations.mjs 732 B
packages/runtime-client-gql/dist/graphql/definitions/queries.cjs 316 B
packages/runtime-client-gql/dist/graphql/definitions/queries.mjs 304 B
packages/runtime-client-gql/dist/index.cjs 679 B
packages/runtime-client-gql/dist/index.mjs 495 B
packages/runtime-client-gql/dist/index.umd.js 9.58 kB
packages/runtime-client-gql/dist/message-conversion/agui-to-gql.cjs 1.72 kB
packages/runtime-client-gql/dist/message-conversion/agui-to-gql.mjs 1.7 kB
packages/runtime-client-gql/dist/message-conversion/gql-to-agui.cjs 1.56 kB
packages/runtime-client-gql/dist/message-conversion/gql-to-agui.mjs 1.53 kB
packages/runtime-client-gql/dist/package.cjs 181 B
packages/runtime-client-gql/dist/package.mjs 116 B
packages/shared/dist/_virtual/_rolldown/runtime.cjs 516 B
packages/shared/dist/a2ui-prompts.cjs 2.85 kB
packages/shared/dist/a2ui-prompts.mjs 2.85 kB
packages/shared/dist/attachments/utils.cjs 1.74 kB
packages/shared/dist/attachments/utils.mjs 1.7 kB
packages/shared/dist/constants/index.cjs 362 B
packages/shared/dist/constants/index.mjs 345 B
packages/shared/dist/debug.cjs 454 B
packages/shared/dist/debug.mjs 452 B
packages/shared/dist/finalize-events.cjs 1.05 kB
packages/shared/dist/finalize-events.mjs 1 kB
packages/shared/dist/index.cjs 1.99 kB
packages/shared/dist/index.mjs 1.66 kB
packages/shared/dist/index.umd.js 20.3 kB
packages/shared/dist/logger.cjs 112 B
packages/shared/dist/logger.mjs 112 B
packages/shared/dist/package.cjs 181 B
packages/shared/dist/package.mjs 116 B
packages/shared/dist/standard-schema.cjs 740 B
packages/shared/dist/standard-schema.mjs 737 B
packages/shared/dist/telemetry/lambda-client.cjs 1.14 kB
packages/shared/dist/telemetry/lambda-client.mjs 1.13 kB
packages/shared/dist/telemetry/telemetry-client.cjs 1.33 kB
packages/shared/dist/telemetry/telemetry-client.mjs 1.27 kB
packages/shared/dist/telemetry/utils.cjs 321 B
packages/shared/dist/telemetry/utils.mjs 277 B
packages/shared/dist/transcription-errors.cjs 951 B
packages/shared/dist/transcription-errors.mjs 944 B
packages/shared/dist/utils/clipboard.cjs 407 B
packages/shared/dist/utils/clipboard.mjs 405 B
packages/shared/dist/utils/conditions.cjs 540 B
packages/shared/dist/utils/conditions.mjs 536 B
packages/shared/dist/utils/console-styling.cjs 1.24 kB
packages/shared/dist/utils/console-styling.mjs 1.22 kB
packages/shared/dist/utils/errors.cjs 4.51 kB
packages/shared/dist/utils/errors.mjs 4.41 kB
packages/shared/dist/utils/index.cjs 1.39 kB
packages/shared/dist/utils/index.mjs 1.65 kB
packages/shared/dist/utils/json-schema.cjs 1.97 kB
packages/shared/dist/utils/json-schema.mjs 1.91 kB
packages/shared/dist/utils/random-id.cjs 618 B
packages/shared/dist/utils/random-id.mjs 559 B
packages/shared/dist/utils/requests.cjs 706 B
packages/shared/dist/utils/requests.mjs 704 B
packages/shared/dist/utils/types.cjs 161 B
packages/shared/dist/utils/types.mjs 160 B
packages/voice/dist/_virtual/_rolldown/runtime.cjs 516 B
packages/voice/dist/index.cjs 175 B
packages/voice/dist/index.mjs 95 B
packages/voice/dist/index.umd.js 1.5 kB
packages/voice/dist/transcription/transcription-service-openai.cjs 495 B
packages/voice/dist/transcription/transcription-service-openai.mjs 434 B
packages/web-inspector/dist/assets/inspector-logo-icon.cjs 499 B
packages/web-inspector/dist/assets/inspector-logo-icon.mjs 434 B
packages/web-inspector/dist/assets/inspector-logo.cjs 4.32 kB
packages/web-inspector/dist/assets/inspector-logo.mjs 4.23 kB
packages/web-inspector/dist/index.cjs 59.4 kB
packages/web-inspector/dist/index.mjs 59.4 kB
packages/web-inspector/dist/index.umd.js 77.5 kB
packages/web-inspector/dist/lib/context-helpers.cjs 862 B
packages/web-inspector/dist/lib/context-helpers.mjs 830 B
packages/web-inspector/dist/lib/persistence.cjs 1.2 kB
packages/web-inspector/dist/lib/persistence.mjs 1.16 kB
packages/web-inspector/dist/lib/telemetry.cjs 2.54 kB
packages/web-inspector/dist/lib/telemetry.mjs 2.44 kB
packages/web-inspector/dist/package.cjs 181 B
packages/web-inspector/dist/package.mjs 116 B
packages/web-inspector/dist/styles/generated.cjs 6.42 kB
packages/web-inspector/dist/styles/generated.mjs 6.36 kB

compressed-size-action

davidmckayv added a commit that referenced this pull request Jul 24, 2026
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]>
Writing a per-hook threadId onto an agent resolved by agentId alone mutates a
shared singleton, so two useAgent calls that share an agentId clobber each
other's thread (review feedback from @mme). Require runtimeAgentId when threadId
is provided: the hook then registers a private proxied agent (agentId ->
runtimeAgentId via CopilotKitCore.registerProxiedAgent) and scopes the threadId
to that instance instead of a shared one. Register/unregister run as one
balanced, StrictMode-safe effect, exposing the proxy via state so the hook
swaps from the provisional stand-in deterministically. Passing threadId without
runtimeAgentId now throws. Updates the React Native demo to the new API.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@davidmckayv
davidmckayv requested a review from mme July 27, 2026 15:02
The harness's loosely-typed runtimeTransport string isn't assignable to
ProxiedCopilotRuntimeAgentConfig.transport (CopilotRuntimeTransport); leave it
at the "auto" default since these tests assert threadId/runtimeAgentId only.
Fixes the check-types failure.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
samjulien added a commit that referenced this pull request Jul 28, 2026
## 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
- **Headless imports** — `@copilotkit/react-native/headless` for a
custom-UI app, avoiding the chat/attachment native peer deps the default
barrel re-exports.
- **Metro configuration for release bundles** —
`unstable_enablePackageExports` + browser-first
`unstable_conditionNames` so the transitive `jose` dependency resolves
to its browser build (fails only at release-bundle time otherwise).
- **Polyfills** — documents the real auto-installed barrel + granular
subpaths, including the `crypto` polyfill (backed by `Math.random`) and
the recommendation to install a secure RNG for production.
- **Provider options** — the full `CopilotKitProvider` prop surface:
`runtimeUrl`, `headers` (auth), `credentials`, `properties`, `onError`,
`debug`, `defaultThrottleMs`, `useSingleEndpoint`.
- **Runtime and model wiring** — the string model form,
`OPENAI_BASE_URL` (and Anthropic/Google equivalents) for
OpenAI-compatible endpoints, `createCopilotNodeListener` zero-dep
serving, and `BuiltInAgent` options.
- **Connecting from a device or bench** — LAN IP, Android emulator
`10.0.2.2`, `adb reverse` for USB, and Android release cleartext HTTP
via `expo-build-properties`.
- **Frontend tools and generative UI** — `useFrontendTool` with
zod/Standard Schema, the send-a-turn recipe, `useAgent` read-only
subscribe + `threadId`, discriminated-union params, and variable-length
`ScrollView` rendering.
- **Run lifecycle and UI** — `isRunning` outliving the visible compose,
and gating overlays/reveal motion accordingly.
- **Voice and speech-to-text** — DIY STT with a graceful-fallback
warning for de-Googled/automotive hardware.
- Refreshed **What's included** and **Known limitations**, plus a **Next
steps** section.

### 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/headless` subpath (headless provider + hooks
without chat/attachment deps) — #6142 ✅ merged
- `resolveModel` honoring `OPENAI_BASE_URL` / `ANTHROPIC_BASE_URL` /
`GOOGLE_GENERATIVE_AI_BASE_URL` for the string model form — #6140 ✅
merged
- union / `anyOf` / `oneOf` tool-param schemas surviving JSON-schema→zod
conversion — #6143 ✅ merged

The fourth — `useAgent` accepting an optional `threadId` (#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 `/headless` and the root
barrel side-effect-import the polyfill barrel —
`@copilotkit/react-native/components` does not, so the "all three
surfaces auto-install" wording was corrected.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
mme and others added 2 commits July 29, 2026 11:27
UseAgentProps left `agentId`, `runtimeAgentId`, and `threadId` independently
optional, so every unsafe or pointless combination compiled and only
`threadId`-without-`runtimeAgentId` was caught — at runtime, on render. Given
the bug this branch fixes was a silently-ignored `threadId` prop, the type is
where it should have been caught.

Split UseAgentProps into a base plus a two-branch union so exactly two shapes
are valid:

  useAgent()                                       // shared agent
  useAgent({ agentId })                            // shared agent
  useAgent({ agentId, runtimeAgentId, threadId })  // private agent, pinned thread

Every partial combination is now a compile error, each for its own reason.
`threadId` alone would scope a thread onto a shared singleton (the original
review finding). `runtimeAgentId` without `threadId` registers a private agent
that behaves like the shared one, minus nothing but a registration and a local
id to keep unique. And without an explicit `agentId`, the proxy registers under
the chat configuration's agentId or DEFAULT_AGENT_ID — ids that already belong
to real agents — which either throws `already registered` or silently shadows
one, depending on whether runtime discovery has landed.

The runtime throws stay as backstops for callers TypeScript doesn't cover (plain
JS, `as any`, props widened to `string | undefined` at a call boundary), and now
cover all three cases, each failing before any registration happens.

Adds use-agent-types.test.tsx pinning the compile-time half of the contract
across the accept/reject matrix, plus contract tests for the two new throws. The
`@ts-expect-error` on each deliberately-bad call doubles as an assertion that the
type still rejects it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The reference page's Parameters section covered only `agentId` and `updates`, so
both props this branch adds were undocumented.

Adds an entry for each, and notes on `agentId` that passing `runtimeAgentId`
makes it required and turns it into a name the hook registers an agent under
rather than one it retrieves.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@linear-code

linear-code Bot commented Jul 29, 2026

Copy link
Copy Markdown

CPK-7741

@tylerslaton
tylerslaton merged commit 70d5a16 into main Jul 29, 2026
39 checks passed
@tylerslaton
tylerslaton deleted the fix/useagent-threadid branch July 29, 2026 14:24
mme added a commit that referenced this pull request Jul 29, 2026
Ports PR #6141's React contract to Vue and deletes the per-thread cloning Vue
used instead.

Cloning is gone: cloneForThread, getOrCreateThreadClone, getThreadClone and the
module-level globalThreadCloneMap. Those clones were reachable only through a
WeakMap, components had to look them up to find the agent actually in use, and
nothing tied a clone's lifetime to the scope that created it.

In its place, the same two-shape contract React now has:

  useAgent()                                       // shared registry agent
  useAgent({ agentId })                            // shared registry agent
  useAgent({ agentId, runtimeAgentId, threadId })  // private proxied agent

UseAgentProps becomes a base plus a two-branch union, so every partial set —
{ agentId, threadId }, { agentId, runtimeAgentId }, { runtimeAgentId, threadId }
— is a compile error, with the same three runtime guards and the same messages as
React for callers TypeScript doesn't reach. Vue's branches take
MaybeRefOrGetter where React takes plain values; the shapes are otherwise
identical.

Thread resolution mirrors React exactly: an explicit `threadId` prop wins,
otherwise the chat configuration's thread gated on `hasExplicitThreadId`, so a
ThreadsProvider-minted placeholder UUID never overwrites the agent's own.

Two Vue-specific details, both load-bearing:

- The pin watcher's first source is `() => agent.value`, not `agent`. Vue sets
  `forceTrigger` when any array watch source is a shallow ref, which would re-run
  the pin on every `triggerRef(agent)` — i.e. every streamed message — and re-pin
  the inherited thread over one CopilotChat had deliberately set for the chat it
  renders. Two suites cover this ("uses the explicit agentId and threadId over
  inherited configuration").
- CopilotChat assigns `agent.threadId` inside its /connect watcher rather than a
  separate one, because CopilotKitCore.connectAgent reads that field
  synchronously to decide whether a restore is fresh; a later assignment would
  let /connect address the previous thread. React does the same, in the same
  place.

CopilotChatMessageView resolves the registry agent directly instead of consulting
the clone map, and reads `copilotkit.agents` so it recomputes when the registry
changes.

Tests: use-agent-thread-isolation.test.ts covered clone semantics that no longer
exist; use-agent-thread-pinning.test.ts replaces it with the new invariants —
one instance per agentId, config-thread pinning gated on explicitness, and all
three all-or-nothing guards. Four component suites used getThreadClone purely as
a lookup and now read from the registry. MockMCPProxyAgent recorded addMessage
only inside its clone() override, so those assertions passed only because
cloning existed; the recording moves onto the class. clone() itself is left
intact everywhere, since CopilotKitCore's SuggestionEngine still clones agents
(packages/core/src/core/suggestion-engine.ts).

Call-site enumeration: cloneForThread and getOrCreateThreadClone were
module-private, zero references. getThreadClone and globalThreadCloneMap were
used by CopilotChatMessageView (rewritten) and 4 test files (retargeted); zero
remain, including in prose. useAgent's other callers, use-capabilities and
use-interrupt, pass `{ agentId }` only and match the unscoped branch unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
BenTaylorDev added a commit that referenced this pull request Aug 13, 2026
…ing (#6234)

## Problem

Vue's `useAgent` implemented per-thread agent **cloning** — a mechanism
React never had. Passing a `threadId` silently handed you a copy of the
agent:

```ts
useAgent({ agentId: "assistant", threadId: "thread-1" })  // → a clone, keyed (agent, threadId)
```

The clones lived in a module-level `WeakMap` (`globalThreadCloneMap`),
so:

- Nothing tied a clone's lifetime to the scope that created it — they
were never released.
- Components had to *look up* which copy was live.
`CopilotChatMessageView` called `getThreadClone(registryAgent,
config.threadId) ?? registryAgent` just to find the agent actually being
rendered.
- `getThreadClone` / `globalThreadCloneMap` were exported from the
module purely so components could do that lookup.

Meanwhile React grew an explicit contract for the same use case in
#6141: a private *proxied* agent, registered under a local `agentId` and
routed to a `runtimeAgentId`.

## Change

Deletes cloning entirely and ports React #6141's contract to Vue.

`cloneForThread`, `getOrCreateThreadClone`, `getThreadClone` and
`globalThreadCloneMap` are gone — zero references remain, including in
prose.

`UseAgentProps` becomes a base plus a two-branch union, with the same
all-or-nothing rule React now enforces:

```ts
useAgent()                                       // shared registry agent
useAgent({ agentId })                            // shared registry agent
useAgent({ agentId, runtimeAgentId, threadId })  // private proxied agent
```

Every partial set — `{ agentId, threadId }`, `{ agentId, runtimeAgentId
}`, `{ runtimeAgentId, threadId }` — is a compile error, backed by the
same three runtime guards with the same messages for callers TypeScript
doesn't reach.

### Parity with #6141

| | React (#6141) | Vue (this PR) |
|---|---|---|
| scoped branch | `agentId` / `threadId` / `runtimeAgentId`, all
required `string` | same, as `MaybeRefOrGetter<string>` |
| unscoped branch | `agentId?: string`, `threadId?: undefined`,
`runtimeAgentId?: undefined` | identical |
| runtime guards | 3 | same 3, same messages |
| thread resolution | prop → chat config, gated on `hasExplicitThreadId`
| identical |
| proxy registration | balanced effect on core + both ids | same deps |

## Two Vue-specific details

Both are load-bearing and were found by tests failing, not by
inspection:

**The pin watcher's first source is `() => agent.value`, not `agent`.**
Vue sets `forceTrigger` when any array watch source is a shallow ref, so
passing the ref directly re-ran the pin on *every* `triggerRef(agent)` —
i.e. every streamed message — re-pinning the inherited thread over one
`CopilotChat` had deliberately set for the chat it renders. Two existing
suites cover this (`uses the explicit agentId and threadId over
inherited configuration`). React has no equivalent hazard because effect
deps compare by identity.

**`CopilotChat` assigns `agent.threadId` inside its `/connect`
watcher**, not a separate one. `CopilotKitCore.connectAgent` reads that
field *synchronously* (`run-handler.ts`) to decide whether a restore is
fresh, so a later assignment lets `/connect` address the previous thread
— skipping the messages/state reset and re-stamping its restore key with
the stale id. Same placement as React's `CopilotChat`.

`CopilotChatMessageView` now resolves the registry agent directly
instead of consulting the clone map, and reads `copilotkit.agents` so it
recomputes when the registry changes.

## What callers see

**One agent per `agentId`** — the model React has always had. Thread
isolation is now explicit instead of implicit: ask for it and you get a
real, separately-registered agent rather than a copy that appears out of
nowhere.

```ts
// before — silently produced a copy of the "assistant" agent
useAgent({ agentId: "assistant", threadId: "thread-1" })

// now — an explicit private agent of your own, routed to "assistant"
useAgent({ agentId: "chat-1", runtimeAgentId: "assistant", threadId: "thread-1" })
```

Nothing in this repo needed updating: `CopilotChat`, `use-capabilities`,
`use-interrupt` and all six example apps already used `{ agentId }`.
`<CopilotChat agentId threadId>` is unchanged for consumers.

## Tests

`use-agent-thread-isolation.test.ts` (433 lines) covered clone semantics
that no longer exist; it's replaced by
`use-agent-thread-pinning.test.ts`, which pins the new invariants — one
instance per `agentId` never a copy, config-thread pinning gated on
explicitness, and all three all-or-nothing guards.

Four component suites used `getThreadClone` purely as a lookup to find
the agent under test and now read from the registry.

`MockMCPProxyAgent` recorded `addMessage` **only inside its `clone()`
override**, so those assertions were passing only because cloning
existed. The recording moves onto the class. `clone()` itself is left
intact everywhere — `CopilotKitCore`'s `SuggestionEngine` still clones
agents (`packages/core/src/core/suggestion-engine.ts`), so removing
those overrides would have planted a latent trap.

## Deliberately not included

Found while reviewing this area, real, but out of scope — each wants its
own change:

- `useAgent`'s header watcher **replaces** `agent.headers` instead of
calling `copilotkit.applyHeadersToAgent()`, dropping per-agent
construction-time headers. Regresses #5635 in Vue; React does this
correctly.
- `credentials` never reach a provisional agent.
- No `onAgentsChanged` subscription anywhere in `packages/vue`, so `()
=> copilotkit.value.agents` as a watch source never re-evaluates on
registry change.
- `/connect` is skipped for a plain `HttpAgent` — the `hasCustomConnect`
prototype comparison matches every real agent. Vue-only, no React
equivalent.
- `CopilotThreadsDrawer.ssr.test.ts` is a latent flake (5s timeout on a
dynamic import; passes in isolation).
BenTaylorDev added a commit that referenced this pull request Sep 10, 2026
…e reference (#7025)

## Summary

The React Native `useAgent` reference page still documents the
pre-`1.64.2` hook. Parameters list only `agentId` and `updates`, and the
signature returns `{ agent: AbstractAgent }` with no `isReady`.

React Native re-exports react-core's `useAgent` verbatim
(`packages/react-native/src/headless.ts:53`, re-exporting from
`@copilotkit/react-core/v2/headless`), so it is the same hook with the
same props. The page is simply stale.

This adds:

- `threadId`, `runtimeAgentId` and `throttleMs` parameters
- the `isReady` return value, and `isReady` in the signature
- the `@copilotkit/react-native/headless` import note
- the two valid option shapes, and a thread-scoped example
- `Optional Throttling`, `Readiness` and `Thread Scoping` behavior
bullets

Content mirrors #6388, which makes the equivalent changes to the React
page, so the two pages stay consistent. No overlap in files.

Docs only. No source or public API change.

## Context

Reported by a community user in #6125 for the React page: the
thread-scoping API shipped in `v1.64.2` (#6141) and the Vue mirror in
`v1.68.0` (#6234), but the docs site was never updated. #6388 covers the
React page; this covers React Native.

## Testing

Verified against a live `next dev` render of shell-docs on `origin/main`
(`35c1e801ae`), with the edited page in place.

**1. MDX compiles with the real compiler** (`@mdx-js/mdx` from
`showcase/shell-docs/node_modules`, the untouched pages as controls):

```
OK    .../worktrees/docs-rn-useagent/.../react-native/hooks/useAgent.mdx   <- edited
OK    .../showcase/shell-docs/.../react-native/hooks/useAgent.mdx          <- control
OK    .../showcase/shell-docs/.../hooks/useAgent.mdx                       <- control
exit=0
```

**2. Component tags balance** (no unclosed `<PropertyReference>`, which
renders as silently swallowed content):

```
open: 23 close: 23 self-closing: 0
BALANCED
fences: 20 (even=ok)
```

**3. Page serves 200 and renders the new content** (`next dev`, port
3003):

```
200  /reference/react-native/hooks/useAgent

threadId: 17      runtimeAgentId: 10     throttleMs: 5      isReady: 17
Thread-scoped Agent: 2                   Thread Scoping: 2
react-native/headless: 2                 preview-: 2

error markers: (none)
```

No `Unhandled Runtime Error`, `Build Error`, `Failed to compile`, or
error overlay in the served HTML.

**4. Prop descriptions actually render**, checked against the untouched
React page as a negative control. The new text is present on the edited
page and correctly absent on the React page, which is what #6388 adds:

```
=== react-native (edited) ===
  ID of the agent to retrieve                   PRESENT
  Controls which agent changes trigger          PRESENT
  Thread ID for a private proxied agent         PRESENT
  Unique identifier for the agent instance      PRESENT
=== react (untouched control) ===
  Thread ID for a private proxied agent         absent
```

Not run: `showcase/shell-docs` `npm run dev` via its `predev` script
fails in this environment on a pre-existing missing `js-yaml` in
`showcase/harness`, unrelated to this change. I ran `next dev` directly
instead, which is why the generators (registry, search index) did not
run. Those generate demo and search content, not reference pages.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Documentation**
- Expanded `useAgent` reference documentation to cover shared and
thread-scoped agent resolution.
- Documented private proxied agents, headless imports, required option
combinations, and runtime/type validation.
- Added guidance for readiness states, provisional agents, connection
failures, and thread-scoped usage.
- Documented the `isReady` return value and `throttleMs` configuration
for controlling update frequency.
- Clarified agent ID resolution, including provider-level configuration
and default fallback behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

3 participants