Repository navigation
fix(react-core): honor threadId prop on useAgent - #6141
Merged
Merged
Conversation
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]>
davidmckayv
requested review from
jpr5,
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
July 23, 2026 21:55
@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: |
Contributor
|
Size Change: +3.75 kB (+0.31%) Total Size: 1.2 MB 📦 View Changed
ℹ️ View Unchanged
|
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]>
mme
requested changes
Jul 27, 2026
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]>
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)
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]>
mme
approved these changes
Jul 29, 2026
mme
approved these changes
Jul 29, 2026
tylerslaton
approved these changes
Jul 29, 2026
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).
This was referenced Sep 10, 2026
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 -->
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
UseAgentProps(packages/react-core/src/v2/hooks/use-agent.tsx) exposed only{ agentId?, updates?, throttleMs? }— there was nothreadId. Yet the shipped V2 React Native demo calls:(
examples/v2/react-native/demo/src/ChatScreen.tsx)Because the prop didn't exist on the type, it was silently ignored. The demo's
threadIdstate — and its "New Chat" reset (setThreadId(generateThreadId())) — never reached the agent. The demo has no<CopilotChatConfigurationProvider>in its tree (seeApp.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
threadIdonUseAgentPropsand honor it. Resolution precedence:threadIdprop wins — lets headless callers (e.g. React Native) scope the run to a thread with no chat-configuration provider in the tree.hasExplicitThreadIdexactly as before.The threadId still lands on
agent.threadId, whichProxiedCopilotRuntimeAgentuses to address/agent/run,/agent/connect, and/agent/stop.Backward compatibility
Fully backward compatible:
threadIdis optional, and when omitted the behavior is byte-for-byte unchanged (config-sourced,hasExplicitThreadId-gated). No demo change is needed — the RN demo's existinguseAgent({ 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:threadIdprop with noCopilotChatConfigurationProvider(the RN demo scenario)threadIdprop over the chat configuration's threadIdagent.threadIdwhen the prop changesThe pre-existing config-sourced invariants remain covered and unchanged.
🤖 Generated with Claude Code