mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
47ad5e34a3
## What does this PR do?
`@copilotkit/react-native` maintained a **private tool-call render
registry** (`hooks/RenderToolContext.tsx`) alongside the canonical one
that `CopilotKitCoreReact` already provides — and which every React
Native app already ships, unused. This PR deletes the fork and points
React Native at the shared registry.
That fork caused three bugs:
| Bug | Symptom | Cause |
|---|---|---|
| **Tool renders never streamed** | A component registered with
`useRenderTool` / `useComponent` painted nothing until the tool call
completed | `CopilotChat` used `JSON.parse` on the argument buffer.
While a model writes a tool call that buffer is *invalid JSON by design*
— AG-UI delivers `TOOL_CALL_ARGS` deltas that are concatenated
client-side — so the parse threw on every delta, warned, and fell back
to `{}` |
| **`useComponent` rendered nowhere** | Silently, with no error | It
writes to core's registry; React Native's chat read React Native's
private `Map` |
| **Chat history degraded** | Navigating away from the registering
screen turned earlier tool calls into a `Called: <name>` placeholder |
The private `Map` deleted renderers on unmount; core deliberately keeps
them |
`@copilotkit/react-core` has used `partialJSONParse` on this path since
v2 shipped. React Native diverged because `useRenderToolCall` was
excluded from its re-exports on the stated grounds that it "depends on
DOM elements via `DefaultToolCallRenderer`" — a claim that was never
true of the hook itself. It was only ever reachable through the fat
`/v2` entry, whose weight is the real hazard (#4893). #5883 moved it
into `/v2/headless` on 2026-07-23; the exclusion comment was rewritten
the next day without revisiting the reason.
### What changed
- **One registry.** `useRenderTool` registers through `useFrontendTool`
into `CopilotKitCoreReact.renderToolCalls`. `CopilotChat` and any custom
surface consume react-core's `useRenderToolCall`.
- **Types are derived, not declared.** `RenderToolProps` is now
`React.ComponentProps<ReactToolCallRenderer<T>["render"]>`, so React
Native cannot drift from `ReactToolCallRenderer` — the contract every
registered renderer is actually invoked against. Change that contract
and `check-types` names every React Native renderer the change breaks.
React Native narrows only the *return* type to `ReactElement | null`,
which `FlatList`'s `renderItem` genuinely requires.
_Scope of that guarantee (corrected during review):_ it does **not**
extend to the type react-core publicly exports under the same name.
Web's `RenderToolProps<S>`
(`react-core/src/v2/hooks/use-render-tool.tsx`) is a separate
hand-declared union, generic over a schema, carrying arguments under
`parameters` (not `args`) and declaring `status` as string literals
rather than `ToolCallStatus` members. Both divergences are live today
and nothing type-checks them shut — the one place the shapes meet,
react-core's own bridge, compiles because a string-enum member is
assignable to its own literal type but not the reverse. Aligning web's
alias is a breaking web API change, filed separately.
- **`RenderToolContext.tsx` deleted** (−150 lines), along with 15 tests
that described the removed subsystem. One of them — `unregisters the
render function on unmount` — asserted the chat-history bug as a
requirement.
- **Two structural CI guards for #4893**, in opposite directions: a test
failing if any React Native source imports the fat `/v2` entry, and a
script failing if react-core's `/v2/headless` or `/v2/context` chunks
ever link shiki/mermaid/cytoscape/katex/streamdown. Both were verified
able to fail by deliberately introducing the regression. These are
*structural* assertions, not size budgets — `dev-docs/bundle-size.md`
freezes `limit` fields until OSS-122.
- **`react-native` added to the bundle-size glob**, which it had never
been in, plus a `size:headless` measurement.
React Native also gains capabilities it lacked: render props inferred
from your schema, `name`/`toolCallId` on render props, and `result` on
completed calls.
**Corrected during review — two capabilities this originally claimed are
not delivered:**
- **Wildcard (`"*"`) renderers do not work on React Native.** Because
`useRenderTool` routes through `useFrontendTool` (which calls
`addTool`), `name: "*"` registers a frontend tool literally named `*` —
advertised to the model, and colliding with core's separate
wildcard-executable-tool path. react-core's `useRenderTool` is
renderer-only and special-cases the wildcard; React Native's is not. The
guide now advises against it.
- **`followUp` (and `available`) are not forwarded**, and the handler's
`context` argument is dropped, so `stopAgent()`'s abort signal is
unreachable from an RN handler.
Both are tracked in § Known limitations for the follow-up that converges
React Native onto react-core's hooks — deleting RN's `useRenderTool` in
favour of re-exporting `useFrontendTool` (tool + renderer) and
react-core's `useRenderTool` (renderer-only, wildcard-capable). That is
an API change with its own migration note, so it is not in this PR.
### ⚠️ Breaking (in a minor)
`useRenderToolRegistry` and `RenderToolProvider` are **removed**. Both
are documented on the docs site, so this is a real break — see the
`BREAKING CHANGE:` footer on `db67ccf`, which is what the release notes
derive from, plus the rewritten reference pages.
```diff
- const registry = useRenderToolRegistry();
- const renderer = registry.get(toolCall.function.name);
- return renderer ? renderer({ args, status }) : null;
+ const renderToolCall = useRenderToolCall();
+ return renderToolCall({ toolCall });
```
Also note two semantic changes: `args` is `Partial<T>` **only** while
`status` is `"inProgress"`, and a render function is now captured at
registration — if it closes over changing values you must declare them
in `deps` (React Native previously refreshed the closure on every
render).
**Known limitation:** agent-scoped renderer resolution does not take
effect on React Native. `CopilotChatConfigurationProvider` is not in
RN's provider tree, so `agentId` always resolves to the default.
Renderers still resolve by name; two agents registering the same tool
name resolve arbitrarily. Filed separately.
### A data point worth recording
Adding `useRenderToolCall` to the measured headless entry moved the
bundle **92.8 kB → 92.7 kB**. Flat. The hook React Native spent months
not using was already inside the chunk every RN app resolves whole —
Metro doesn't tree-shake, so the fork never saved a byte. It cost them.
### Testing
- `@copilotkit/react-native`: **253 passing / 22 files** ·
`@copilotkit/react-core`: **1480 passing / 123 files** · `check-types`
and `build` green for both.
- Each of the three bugs has a deterministic test driving a real
`CopilotKitCoreReact` — no mocking of the code under test.
- Both #4893 guards carry mutation evidence: introduce the regression,
watch them fail, revert, watch them pass.
### Follow-up
`useRenderTool`'s JSDoc is split across two blocks, which orphans the
primary description from IDE hover (the `@param deps` warning still
surfaces). One-line fix, deliberately left out of the final fix wave.
## Related PRs and Issues
- **Supersedes #6346** (@davidmckayv) — its diagnoses were correct and
its test assertions are ported here, re-driven through the real registry
rather than a mocked local one. Credited via `Co-Authored-By` on
`4104bd1`.
- Addresses the React Native half of **#4893**.
- Builds on **#5883**, which created the lean `/v2/headless` entry this
PR consumes.
## Checklist
- [x] I have read the Contribution Guide
- [x] If the PR changes or adds functionality, I have updated the
relevant documentation
- [x] "Allow edits by maintainers" is checked
🤖 Generated with [Claude Code](https://claude.com/claude-code)
143 lines
4.2 KiB
JSON
143 lines
4.2 KiB
JSON
{
|
|
"name": "@copilotkit/react-core",
|
|
"version": "1.67.1",
|
|
"private": false,
|
|
"keywords": [
|
|
"ai",
|
|
"assistant",
|
|
"automation",
|
|
"copilot",
|
|
"copilotkit",
|
|
"javascript",
|
|
"nextjs",
|
|
"nodejs",
|
|
"react",
|
|
"tanstack-intent",
|
|
"textarea"
|
|
],
|
|
"homepage": "https://github.com/CopilotKit/CopilotKit",
|
|
"license": "MIT",
|
|
"repository": {
|
|
"type": "git",
|
|
"url": "https://github.com/CopilotKit/CopilotKit.git"
|
|
},
|
|
"files": [
|
|
"dist",
|
|
"skills"
|
|
],
|
|
"type": "module",
|
|
"sideEffects": [
|
|
"**/*.css"
|
|
],
|
|
"main": "./dist/index.cjs",
|
|
"module": "./dist/index.mjs",
|
|
"types": "./dist/index.d.cts",
|
|
"unpkg": "./dist/index.umd.js",
|
|
"jsdelivr": "./dist/index.umd.js",
|
|
"exports": {
|
|
".": {
|
|
"import": "./dist/index.mjs",
|
|
"require": "./dist/index.cjs"
|
|
},
|
|
"./v2": {
|
|
"import": "./dist/v2/index.mjs",
|
|
"require": "./dist/v2/index.cjs"
|
|
},
|
|
"./package.json": "./package.json",
|
|
"./v2/context": {
|
|
"import": "./dist/v2/context.mjs",
|
|
"require": "./dist/v2/context.cjs"
|
|
},
|
|
"./v2/headless": {
|
|
"import": "./dist/v2/headless.mjs",
|
|
"require": "./dist/v2/headless.cjs"
|
|
},
|
|
"./v2/styles.css": "./dist/v2/index.css"
|
|
},
|
|
"publishConfig": {
|
|
"access": "public"
|
|
},
|
|
"scripts": {
|
|
"build:css": "tailwindcss -i ./src/v2/styles/globals.css -o ./dist/v2/index.css -m && node scripts/scope-preflight.mjs ./dist/v2/index.css",
|
|
"build": "tsdown && pnpm run build:css && node scripts/context-singleton-preflight.mjs",
|
|
"size": "size-limit",
|
|
"size:headline": "node scripts/measure-copilotchat.mjs",
|
|
"size:assert-headless": "node scripts/assert-headless-purity.mjs",
|
|
"compat-check": "es-check es2022 --module 'dist/**/!(*.umd).{mjs,cjs,js}' && es-check es2020 'dist/**/*.umd.js'",
|
|
"dev": "tsdown --watch",
|
|
"test": "vitest run && pnpm run test:scripts",
|
|
"test:scripts": "node --test scripts/__tests__/measure-copilotchat.test.mjs scripts/__tests__/assert-headless-purity.test.mjs",
|
|
"test:watch": "vitest",
|
|
"check-types": "tsc --noEmit",
|
|
"link:global": "pnpm link --global",
|
|
"unlink:global": "pnpm unlink --global",
|
|
"publint": "publint .",
|
|
"attw": "attw --pack . --profile node16"
|
|
},
|
|
"dependencies": {
|
|
"@ag-ui/client": "0.0.57",
|
|
"@ag-ui/core": "0.0.57",
|
|
"@copilotkit/a2ui-renderer": "workspace:*",
|
|
"@copilotkit/core": "workspace:*",
|
|
"@copilotkit/runtime-client-gql": "workspace:*",
|
|
"@copilotkit/shared": "workspace:*",
|
|
"@copilotkit/web-components": "workspace:*",
|
|
"@copilotkit/web-inspector": "workspace:*",
|
|
"@jetbrains/websandbox": "^1.1.3",
|
|
"@lit-labs/react": "^2.0.2",
|
|
"@radix-ui/react-dropdown-menu": "^2.1.15",
|
|
"@radix-ui/react-slot": "^1.2.3",
|
|
"@radix-ui/react-tooltip": "^1.2.7",
|
|
"@scarf/scarf": "^1.3.0",
|
|
"@tanstack/react-virtual": "^3.13.0",
|
|
"class-variance-authority": "^0.7.1",
|
|
"clsx": "^2.1.1",
|
|
"katex": "^0.16.22",
|
|
"lit": "^3.3.2",
|
|
"lucide-react": "^0.525.0",
|
|
"react-markdown": "^8.0.7",
|
|
"rxjs": "7.8.1",
|
|
"streamdown": "^1.3.0",
|
|
"tailwind-merge": "^3.3.1",
|
|
"tw-animate-css": "^1.3.5",
|
|
"untruncate-json": "^0.0.1",
|
|
"use-stick-to-bottom": "^1.1.1",
|
|
"zod-to-json-schema": "^3.24.5"
|
|
},
|
|
"devDependencies": {
|
|
"@tailwindcss/cli": "^4.1.11",
|
|
"esbuild": "^0.27.0",
|
|
"@tailwindcss/postcss": "^4.1.11",
|
|
"@tailwindcss/typography": "^0.5.16",
|
|
"@tanstack/intent": "^0.0.29",
|
|
"@testing-library/jest-dom": "^6.0.0",
|
|
"@testing-library/react": "^16.3.0",
|
|
"@testing-library/react-hooks": "^8.0.1",
|
|
"@testing-library/user-event": "^14.0.0",
|
|
"@types/react": "^19.1.0",
|
|
"@types/react-dom": "^19.0.2",
|
|
"@valibot/to-json-schema": "^1.5.0",
|
|
"arktype": "^2.1.29",
|
|
"autoprefixer": "^10.4.20",
|
|
"concurrently": "^9.1.0",
|
|
"eslint": "^8.56.0",
|
|
"jsdom": "^26.1.0",
|
|
"phoenix": "^1.8.4",
|
|
"postcss": "^8.5.6",
|
|
"react": "^19.1.0",
|
|
"react-dom": "^19.2.0",
|
|
"tailwindcss": "^4.0.8",
|
|
"tsconfig": "workspace:*",
|
|
"tsdown": "^0.20.3",
|
|
"typescript": "^5.2.3",
|
|
"valibot": "^1.2.0",
|
|
"vitest": "^3.2.4",
|
|
"zod": ">=3.0.0"
|
|
},
|
|
"peerDependencies": {
|
|
"react": "^18 || ^19 || ^19.0.0-rc",
|
|
"react-dom": "^18 || ^19 || ^19.0.0-rc",
|
|
"zod": ">=3.0.0"
|
|
}
|
|
}
|