Repository navigation
docs: move the v1 CopilotKit headers notes into the JSDoc and drop a dead snippet - #7515
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Production Digest-Pinning AuditAll 43 services digest-pinned. Run 2026-10-07 06:52:44 PDT — 0 finding(s). |
@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/intelligence-langgraph
@copilotkit/intelligence-mastra
@copilotkit/mcp-apps-renderer
@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: |
|
Size Change: 0 B Total Size: 1.74 MB ℹ️ View Unchanged
|
…dead snippet reference/v1/components/CopilotKit.mdx is generated by scripts/docs/gen.ts from the CopilotKitProps JSDoc. #7510 hand-edited the page, so a regen would have dropped the caching, header_resolution_failed, user-switch and cross-origin notes. Move them into the JSDoc and regenerate the page. Delete snippets/shared/reference/copilotkit-component.mdx: an auto-generated snippet that no SNIPPET_MAP entry, import or route uses. Co-Authored-By: Claude Opus 5.5 <[email protected]>
4d724a7 to
5732e4b
Compare
…ync builders) (#7510) ## What does this PR do? The `headers` option now accepts a record, a sync builder, or an async builder. A builder runs **when each request is sent**, not when the provider renders. **The bug on `main`:** a sync builder ran during the provider's render. So if a token rotated without a provider re-render, CopilotKit kept sending the old token. For example, Clerk tokens live for 60 seconds, and typing in the chat input doesn't re-render the provider. After about a minute idle, the next run got a 401. Intelligence makes this worse, because thread refetches and realtime reconnects run without any user action, including in background tabs. There was also no way to pass an async `getToken()` at all (#1937, #2159). Measured with the real `@copilotkit/react-core` v2 build in jsdom, sending real HTTP requests to a local runtime that rejects tokens older than 60 s, after a real 65 s idle with no provider re-render: | Request after 65 s idle | `main` | this branch | |---|---|---| | Send a message (run) | **401**, token 65,053 ms old | 200, token 3–4 ms old | | `useThreads().renameThread()` (via `ɵruntimeFetch`) | **401**, token 65,051 ms old | 200, token 4–6 ms old | ### How it works - **Core** (`@copilotkit/core`): a `HeaderSourceResolver` owns the headers source. - It resolves synchronously for a record or a sync builder, so static and sync users gain no extra `await`. - For an async builder, concurrent requests share one in-flight call. A generation counter makes sure a call started before `setHeaders()` is never reused after it. - New public API: `resolveHeaders()`, `CopilotKitHeadersSource`, `CopilotKitHeaderResolutionError`, and the error code `HEADER_RESOLUTION_FAILED`. - `ɵruntimeFetch` adds the current headers when each request is sent, before the runtime watchdog is armed and before the single-route rewrite. The request's own `Content-Type`/`Accept` still win, and core headers still beat an agent's own headers (#5635 precedence). - `/info`, inspector metadata, runs, connects, stop requests and `/suggest` all resolve current headers. - **React v2** `CopilotKitProvider` and **`<CopilotKit>`** (also the main v2 export): the provider hands core one stable builder and never calls it during render. `<CopilotKit>` accepts async builders too. The one exception is the legacy v1 GraphQL `CopilotTask` path: it doesn't await an async builder, and it logs a one-time dev warning. - **Vue** and **Angular** (Angular accepts a builder for the first time), **web-inspector**, **react-textarea** (a dead render-time headers read was removed), and the **docs**. - **Out of scope:** React Native is unchanged (sync builder, evaluated at render); a follow-up issue will cover it. Cross-origin agent headers (#5635) are unchanged, and the docs now warn about them. ### Behavior changes 1. **A sync builder now runs once per request**, not once per provider render. 2. **A new token from a builder doesn't fire `onHeadersChanged`** and doesn't refetch threads or inspector metadata. Only `setHeaders()` or a new source does. 3. **`setHeaders()` with an equal record is a no-op**, and so is passing the same builder function again. 4. **User switch with a builder:** re-rendering the provider no longer reloads the thread list or re-subscribes realtime, because the builder's identity is stable. On a user switch, remount the provider (for example `key={userId}`), or call `setHeaders` with a new function or a record. The docs say this. Commit 9a69623 carries a `BREAKING CHANGE:` footer, so this lands under Breaking Changes in the release notes. 5. **Fail closed:** if a builder throws or rejects, or returns something that isn't an object (for example `() => token && {...}` before sign-in), the request is not sent. `onError` receives `header_resolution_failed` once per failed call. A header failure replaces the `AGENT_RUN_FAILED`/`AGENT_CONNECT_FAILED` that used to follow. A sync builder that threw used to crash render; now it fails closed. A header failure on `/info` sets the runtime status to Error and logs a warning that names headers. 6. **`copilotkit.headers`** is the last resolved value. With a builder it is `{}` until the first request. Angular's `headers()` signal follows source changes only (`{}` for a builder); use `core.resolveHeaders()` instead. 7. **A proxied runtime agent's `agent.headers` no longer contains core headers.** They are added at send time. Three existing tests (two #5635 remote-agent tests and one registered-proxy test) now assert on the request instead of on the field. 8. **Stop requests** and provisional proxies (React, Vue, Angular) now go through `ɵruntimeFetch` (stop requests are marked non-critical). 9. **v1 `copilotApiConfig.headers`** is a lazy getter, so a sync builder runs when `CopilotTask.run` reads it. 10. **`CpkThreadInspector.headers`** is deprecated in favor of `resolveHeaders`, and still works as a fallback. 11. **Angular `updateRuntime({ headers })`** now applies the license-key default to the new headers, as construction always did. Passing the same builder again is a no-op. 12. **Type widenings:** `CopilotKitCoreConfig.headers`, Angular `CopilotKitConfig.headers`, and the `headers` prop on `CopilotKitProvider`, Vue and `<CopilotKit>`. `resolveHeaders()` returns a read-only record. ### Follow-ups - #7511: `HEADER_RESOLUTION_FAILED` has no agent or thread context. - #7512: React `use-agent` re-applies headers on value changes instead of the generation. - #7513: React Native parity. - #7514: core headers reach user-supplied agents on other origins (#5635 behavior, documented here). - #7515 (stacked on this PR): moves the hand-written v1 `CopilotKit` docs notes into the JSDoc they're generated from, and deletes an orphaned auto-generated snippet. ## Related PRs and Issues - Closes #1937 - Supersedes #6291. Thanks to @rodboev: that PR's review is where the StrictMode, identity-churn and sync-timing traps in this design were found. - Related: #2159 (closed as a duplicate of #1937), #3401 / OSS-551 ## Testing Everything below ran on this branch, rebased onto `origin/main` at `b3d1aad2e3`. Each suite also ran on a clean `origin/main` worktree in the same environment. **Unit and integration suites (branch):** | Package | Result | |---|---| | `@copilotkit/core` | 1007 / 1007 pass; `check-types` clean | | `@copilotkit/react-core` | 1771 vitest + 54 node:test pass; `check-types` clean | | `@copilotkit/vue` | 1160 / 1160 pass; `vue-tsc` clean | | `@copilotkit/angular` | 452 pass, 1 skipped (already skipped on main); `check-types` clean | | `@copilotkit/web-inspector` | 794 / 794 pass; `check-types` clean | | `@copilotkit/react-textarea` | 3 / 3 pass; `check-types` clean | - **Compared with `origin/main`:** no failures appear on the branch only. `use-agent-context-timing.e2e` failed once, during a run that overlapped a parallel `pnpm install`. It didn't recur in 2 full runs, 3 isolated runs or 10 runs under load. Its agent isn't an `HttpAgent`, so this change adds no await on its path. - **Mutation checks:** every new test was checked by breaking the mechanism it guards, confirming the test fails, and restoring. Examples: - render-time builder evaluation → the stale-token tests fail; - dropping the generation guard → the in-flight reuse tests fail; - keying on header values → the no-reload tests fail; - a snapshot spread on a `ɵruntimeFetch` site → the removed-key tests fail; - awaiting unconditionally → the sync-timing tests fail. - **Other gates:** - oxlint: 0 errors. On the 49 modified files, warnings go from 58 on `main` to 49. The 12 new files add 4, for 53 in total. - Public API manifest: unchanged. - Release, config-allowlist and static-quality script tests: pass. - shell-docs search index and typecheck: pass. Its suite passes except 3 PNG checks, which fail only because the worktree has LFS pointer files instead of images. - Size: core is 1.19 kB larger minified. The size job is informational. - Angular showcase initial-bundle budget: 1,479,169 raw bytes on the branch vs 1,479,152 on `main` (cap 1,551,287). An earlier push failed this check because `config.ts` imported a value from `@copilotkit/core`, which pulled all of core into the initial bundle. `config.ts` now imports types only, and a test guards it. - **Not run locally:** `check:packages`, `verify:angular-package`, `verify:runtime-package`, `verify:channels-umbrella`, and the web-inspector browser tests. CI covers them. - **Docs:** every edited `.mdx` parses with the repo's `@mdx-js/mdx`. - **Live check:** the table at the top. I re-ran both scenarios on the final head (`71368fea1e`) with the same results: after a 65 s idle with 0 provider re-renders, the run sent a 2 ms-old token (200) and the rename a 5 ms-old token (200). **Review round (9a69623), after merging `origin/main` at `07d4830ade`:** - Trajectory connect and suggestions from a cloned `HttpAgent` now resolve headers at send time. There are two new rows in `core-headers-request-table.test.ts`. - Mutation check: with both source fixes reverted, the two new rows fail (`Expected: "fresh"`, `Received: "stale"`). With the fixes, the table and trajectory files pass: ``` Test Files 3 passed (3) Tests 85 passed (85) ``` - The React thread-context test now sends a request and re-renders after the token change. Mutation check: with `use-threads.tsx` keyed on `JSON.stringify(copilotkit.headers)`, the test fails (`1 failed`). On the PR code, the file passes (`13 passed`). - `nx run-many -t test check-types lint` for core, react-core, react-textarea, vue, angular and web-inspector: `check-types` passes for all six. Two tests timed out under the parallel load (`CopilotThreadsDrawer.ssr`, `MCPAppsUiMessage.e2e`). Both pass when run alone. `vue:lint` reports 166 errors, which also exist on `main`. None of them is on a line this PR adds. ## Checklist - [x] I have read the [Contribution Guide](https://github.com/copilotkit/copilotkit/blob/master/CONTRIBUTING.md) - [x] If the PR changes or adds functionality, I have updated the relevant documentation - [ ] "Allow edits by maintainers" is checked (not applicable: this branch is in this repo) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Web providers now accept synchronous and asynchronous header builders, resolving the current headers when requests are sent across runtime requests, agents, threads, transcription, and the Inspector. * Valid public API keys are included by default in request headers. * Changing the header source refreshes relevant thread and Inspector data; token updates from a builder alone do not trigger those refreshes. * Header resolution failures prevent the affected request and report `header_resolution_failed`. * **Documentation** * Updated guidance on header builders and request timing, including React Native’s synchronous-only behavior and the legacy v1 async-builder limitation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
What does this PR do?
This is a docs cleanup that follows #7510. It is stacked on #7510's branch, so the diff shows only this change. Once #7510 merges, I'll retarget it to
main.reference/v1/components/CopilotKit.mdxis generated byscripts/docs/gen.tsfrom theCopilotKitPropsJSDoc. feat: evaluate request headers when each request is sent (sync and async builders) #7510 edited the page by hand, so the next regeneration would have dropped its notes: caching in the builder,header_resolution_failed, the user-switch rule, and the cross-origin agents warning. This PR moves those notes into theheadersJSDoc and regenerates the page from it.snippets/shared/reference/copilotkit-component.mdxis auto-generated, and nothing uses it: noSNIPPET_MAPentry, import or route. It isn't a generator destination either, and it still documentedheadersasRecord<string, string>.One visible difference on the regenerated page: the
headerstype readsCopilotKitHeadersSource, which is what the generator emits, instead of the hand-expanded union. The text below it still lists the three forms (record, sync builder, async builder).Related PRs and Issues
Testing
ReferenceDocfor this one entry. The committed page is exactly the generator's output. Only theheaderssection changed; the rest of the page is identical.git grep copilotkit-componentreturns no hits outside the deleted file.scripts/docs/lib/files.tsdoesn't list it.pnpm exec vitest run scripts/__tests__/docs-reference-generator.test.ts, the same command CI runs instatic_quality.yml: 31/31 pass.@mdx-js/mdx.oxfmtandoxlinton the edited.tsx: clean. The change is a comment only.Checklist
🤖 Generated with Claude Code