@copilotkit/react-core 1.59.5 → 1.60.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{copilotkit-CFfEVdV4.cjs → copilotkit-BTHcCAVQ.cjs} +93 -78
- package/dist/copilotkit-BTHcCAVQ.cjs.map +1 -0
- package/dist/{copilotkit-Ctvinul7.d.cts → copilotkit-C9ptuh-b.d.cts} +32 -70
- package/dist/copilotkit-C9ptuh-b.d.cts.map +1 -0
- package/dist/{copilotkit-DEGlMWM0.mjs → copilotkit-CV519nFv.mjs} +94 -79
- package/dist/copilotkit-CV519nFv.mjs.map +1 -0
- package/dist/{copilotkit-DqDT5RLa.d.mts → copilotkit-DvbI8G0d.d.mts} +32 -70
- package/dist/copilotkit-DvbI8G0d.d.mts.map +1 -0
- package/dist/index.cjs +11 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +11 -12
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +47 -54
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.css +1 -1
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +92 -77
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +8 -8
- package/skills/react-core/SKILL.md +5 -5
- package/skills/react-core/references/chat-components.md +20 -12
- package/skills/react-core/references/client-side-tools.md +1 -1
- package/skills/react-core/references/custom-message-renderers.md +8 -11
- package/skills/react-core/references/debug-mode.md +15 -15
- package/skills/react-core/references/provider-setup.md +45 -52
- package/skills/react-core/references/rendering-activity-messages.md +6 -12
- package/dist/copilotkit-CFfEVdV4.cjs.map +0 -1
- package/dist/copilotkit-Ctvinul7.d.cts.map +0 -1
- package/dist/copilotkit-DEGlMWM0.mjs.map +0 -1
- package/dist/copilotkit-DqDT5RLa.d.mts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/react-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.60.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@ag-ui/client": "0.0.
|
|
62
|
-
"@ag-ui/core": "0.0.
|
|
61
|
+
"@ag-ui/client": "0.0.57",
|
|
62
|
+
"@ag-ui/core": "0.0.57",
|
|
63
63
|
"@jetbrains/websandbox": "^1.1.3",
|
|
64
64
|
"@lit-labs/react": "^2.0.2",
|
|
65
65
|
"@radix-ui/react-dropdown-menu": "^2.1.15",
|
|
@@ -79,11 +79,11 @@
|
|
|
79
79
|
"untruncate-json": "^0.0.1",
|
|
80
80
|
"use-stick-to-bottom": "^1.1.1",
|
|
81
81
|
"zod-to-json-schema": "^3.24.5",
|
|
82
|
-
"@copilotkit/a2ui-renderer": "1.
|
|
83
|
-
"@copilotkit/runtime-client-gql": "1.
|
|
84
|
-
"@copilotkit/shared": "1.
|
|
85
|
-
"@copilotkit/core": "1.
|
|
86
|
-
"@copilotkit/web-inspector": "1.
|
|
82
|
+
"@copilotkit/a2ui-renderer": "1.60.1",
|
|
83
|
+
"@copilotkit/runtime-client-gql": "1.60.1",
|
|
84
|
+
"@copilotkit/shared": "1.60.1",
|
|
85
|
+
"@copilotkit/core": "1.60.1",
|
|
86
|
+
"@copilotkit/web-inspector": "1.60.1"
|
|
87
87
|
},
|
|
88
88
|
"devDependencies": {
|
|
89
89
|
"@tailwindcss/cli": "^4.1.11",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: react-core
|
|
3
3
|
description: >
|
|
4
|
-
@copilotkit/react-core — mount
|
|
5
|
-
v7 / TanStack Start / SPA app, drop in CopilotChat/CopilotPopup/CopilotSidebar (v2 chat
|
|
4
|
+
@copilotkit/react-core — mount the CopilotKit provider (from @copilotkit/react-core/v2)
|
|
5
|
+
in a Next.js App Router / React Router v7 / TanStack Start / SPA app, drop in CopilotChat/CopilotPopup/CopilotSidebar (v2 chat
|
|
6
6
|
components ship from react-core/v2 — NOT react-ui, which is CSS-only in v2), access and
|
|
7
7
|
subscribe to agents with useAgent / useAgentContext / useCapabilities, switch between
|
|
8
8
|
multiple agents, manage durable Intelligence threads with useThreads, register
|
|
@@ -48,7 +48,7 @@ sources:
|
|
|
48
48
|
# CopilotKit React Core
|
|
49
49
|
|
|
50
50
|
`@copilotkit/react-core` is the React frontend half of CopilotKit: it mounts a provider,
|
|
51
|
-
speaks AG-UI over SSE to a runtime (or directly to CopilotKit
|
|
51
|
+
speaks AG-UI over SSE to a runtime (or directly to CopilotKit Intelligence in SPA mode), and
|
|
52
52
|
exposes hooks for every interaction surface.
|
|
53
53
|
|
|
54
54
|
This SKILL.md is the **index**. Read the reference under `references/` that matches
|
|
@@ -56,7 +56,7 @@ your task — do not try to absorb the whole package from this file.
|
|
|
56
56
|
|
|
57
57
|
## Mental model — three shells you compose
|
|
58
58
|
|
|
59
|
-
1. **Provider shell** — `
|
|
59
|
+
1. **Provider shell** — the `CopilotKit` provider (from `@copilotkit/react-core/v2`) at or near the root (inside `"use client"` for
|
|
60
60
|
Next.js App Router). Carries `runtimeUrl` (or `publicLicenseKey` for SPA), `headers`,
|
|
61
61
|
`credentials`, `properties`, `onError`, `debug`, `showDevConsole`.
|
|
62
62
|
2. **Chat shell** — `CopilotChat` / `CopilotPopup` / `CopilotSidebar` or a composed
|
|
@@ -71,7 +71,7 @@ your task — do not try to absorb the whole package from this file.
|
|
|
71
71
|
|
|
72
72
|
| Task | Reference |
|
|
73
73
|
| --------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- |
|
|
74
|
-
| Mount `
|
|
74
|
+
| Mount the `CopilotKit` provider, pick `runtimeUrl` vs `publicLicenseKey`, RSC boundary rules | `references/provider-setup.md` |
|
|
75
75
|
| Drop in `CopilotChat` / `CopilotPopup` / `CopilotSidebar`, compose `CopilotChatView` with slot primitives | `references/chat-components.md` |
|
|
76
76
|
| File / image attachments via `useAttachments` — drag-drop, click, paste, custom upload | `references/attachments.md` |
|
|
77
77
|
| Client-side debug tooling — `showDevConsole`, `debug` prop, lazy-loaded web inspector | `references/debug-mode.md` |
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
# CopilotKit Chat Components (React)
|
|
2
2
|
|
|
3
3
|
This skill builds on `copilotkit/provider-setup`. Read it first — every
|
|
4
|
-
chat component must be inside `
|
|
4
|
+
chat component must be inside the `CopilotKit` provider (from
|
|
5
|
+
`@copilotkit/react-core/v2`).
|
|
5
6
|
|
|
6
7
|
All chat components live on `@copilotkit/react-core/v2`. The legacy
|
|
7
8
|
`@copilotkit/react-ui` package is v1-only; its `/v2` subpath is a CSS-only
|
|
@@ -30,7 +31,7 @@ suggestions internally via `useAgent`. You do not pass `messages` or
|
|
|
30
31
|
```tsx
|
|
31
32
|
import { CopilotPopup } from "@copilotkit/react-core/v2";
|
|
32
33
|
|
|
33
|
-
<CopilotPopup agentId="default"
|
|
34
|
+
<CopilotPopup agentId="default" defaultOpen={false} />;
|
|
34
35
|
```
|
|
35
36
|
|
|
36
37
|
### Persistent sidebar
|
|
@@ -52,8 +53,6 @@ want to manage `messages`/`isRunning` yourself.
|
|
|
52
53
|
```tsx
|
|
53
54
|
import {
|
|
54
55
|
CopilotChatView,
|
|
55
|
-
CopilotChatInput,
|
|
56
|
-
CopilotChatMessageView,
|
|
57
56
|
useAgent,
|
|
58
57
|
useCopilotKit,
|
|
59
58
|
} from "@copilotkit/react-core/v2";
|
|
@@ -66,7 +65,7 @@ export function HeadlessChat() {
|
|
|
66
65
|
<CopilotChatView
|
|
67
66
|
messages={agent.messages}
|
|
68
67
|
isRunning={agent.isRunning}
|
|
69
|
-
|
|
68
|
+
onSubmitMessage={async (text) => {
|
|
70
69
|
agent.addMessage({
|
|
71
70
|
id: crypto.randomUUID(),
|
|
72
71
|
role: "user",
|
|
@@ -75,8 +74,12 @@ export function HeadlessChat() {
|
|
|
75
74
|
await copilotkit.runAgent({ agent });
|
|
76
75
|
}}
|
|
77
76
|
>
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
{({ messageView, input }) => (
|
|
78
|
+
<>
|
|
79
|
+
{messageView}
|
|
80
|
+
{input}
|
|
81
|
+
</>
|
|
82
|
+
)}
|
|
80
83
|
</CopilotChatView>
|
|
81
84
|
);
|
|
82
85
|
}
|
|
@@ -89,7 +92,7 @@ export function HeadlessChat() {
|
|
|
89
92
|
agentId="default"
|
|
90
93
|
labels={{
|
|
91
94
|
chatInputPlaceholder: "Ask about the data…",
|
|
92
|
-
|
|
95
|
+
welcomeMessageText: "What would you like to analyze?",
|
|
93
96
|
}}
|
|
94
97
|
/>
|
|
95
98
|
```
|
|
@@ -157,14 +160,19 @@ Correct:
|
|
|
157
160
|
// CopilotChat manages messages and isRunning internally.
|
|
158
161
|
<CopilotChat agentId="default" />
|
|
159
162
|
|
|
160
|
-
// For manual control, drop down to headless CopilotChatView
|
|
163
|
+
// For manual control, drop down to headless CopilotChatView. Its `children`
|
|
164
|
+
// is a render prop that receives the bound slot elements:
|
|
161
165
|
<CopilotChatView
|
|
162
166
|
messages={myMessages}
|
|
163
167
|
isRunning={busy}
|
|
164
|
-
|
|
168
|
+
onSubmitMessage={handleSubmit}
|
|
165
169
|
>
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
{({ messageView, input }) => (
|
|
171
|
+
<>
|
|
172
|
+
{messageView}
|
|
173
|
+
{input}
|
|
174
|
+
</>
|
|
175
|
+
)}
|
|
168
176
|
</CopilotChatView>
|
|
169
177
|
```
|
|
170
178
|
|
|
@@ -6,7 +6,7 @@ internally by `<CopilotChat>` / `<CopilotChatView>`.
|
|
|
6
6
|
|
|
7
7
|
Key rules:
|
|
8
8
|
|
|
9
|
-
- Renderers are passed to `
|
|
9
|
+
- Renderers are passed to the `CopilotKit` provider via `renderCustomMessages`.
|
|
10
10
|
- The hook returns `null` when called outside `CopilotChatConfigurationProvider`.
|
|
11
11
|
- First non-null result wins — agent-scoped renderers evaluated first.
|
|
12
12
|
- `stateSnapshot` is `undefined` before the run's `runId` resolves.
|
|
@@ -15,7 +15,7 @@ Key rules:
|
|
|
15
15
|
|
|
16
16
|
```tsx
|
|
17
17
|
"use client";
|
|
18
|
-
import {
|
|
18
|
+
import { CopilotKit } from "@copilotkit/react-core/v2";
|
|
19
19
|
import type { ReactCustomMessageRenderer } from "@copilotkit/react-core/v2";
|
|
20
20
|
import { useMemo } from "react";
|
|
21
21
|
import { Button } from "@/components/ui/button";
|
|
@@ -41,12 +41,9 @@ const CopyButton: ReactCustomMessageRenderer = {
|
|
|
41
41
|
export function Providers({ children }: { children: React.ReactNode }) {
|
|
42
42
|
const renderers = useMemo(() => [CopyButton], []);
|
|
43
43
|
return (
|
|
44
|
-
<
|
|
45
|
-
runtimeUrl="/api/copilotkit"
|
|
46
|
-
renderCustomMessages={renderers}
|
|
47
|
-
>
|
|
44
|
+
<CopilotKit runtimeUrl="/api/copilotkit" renderCustomMessages={renderers}>
|
|
48
45
|
{children}
|
|
49
|
-
</
|
|
46
|
+
</CopilotKit>
|
|
50
47
|
);
|
|
51
48
|
}
|
|
52
49
|
```
|
|
@@ -129,9 +126,9 @@ Correct:
|
|
|
129
126
|
|
|
130
127
|
```tsx
|
|
131
128
|
// Option A — register renderers via the provider prop so <CopilotChat> picks them up:
|
|
132
|
-
<
|
|
129
|
+
<CopilotKit renderCustomMessages={renderers}>
|
|
133
130
|
<CopilotChat agentId="default" />
|
|
134
|
-
</
|
|
131
|
+
</CopilotKit>;
|
|
135
132
|
|
|
136
133
|
// Option B — call the hook only inside a chat-configured subtree:
|
|
137
134
|
import { CopilotChatConfigurationProvider } from "@copilotkit/react-core/v2";
|
|
@@ -207,7 +204,7 @@ Source: `packages/react-core/src/v2/hooks/use-render-custom-messages.tsx:73-95`
|
|
|
207
204
|
Wrong:
|
|
208
205
|
|
|
209
206
|
```tsx
|
|
210
|
-
<
|
|
207
|
+
<CopilotKit
|
|
211
208
|
renderCustomMessages={[CopyButton, DebugBefore]} // fresh array every render
|
|
212
209
|
/>
|
|
213
210
|
```
|
|
@@ -216,7 +213,7 @@ Correct:
|
|
|
216
213
|
|
|
217
214
|
```tsx
|
|
218
215
|
const renderers = useMemo(() => [CopyButton, DebugBefore], []);
|
|
219
|
-
<
|
|
216
|
+
<CopilotKit renderCustomMessages={renderers} />;
|
|
220
217
|
```
|
|
221
218
|
|
|
222
219
|
The provider's stable-array-prop diff console-errors when a new array
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# CopilotKit Debug Mode (React)
|
|
2
2
|
|
|
3
3
|
This skill builds on `copilotkit/provider-setup`. Both debug surfaces are
|
|
4
|
-
props on `
|
|
4
|
+
props on the `CopilotKit` provider (from `@copilotkit/react-core/v2`).
|
|
5
5
|
|
|
6
6
|
Two independent knobs:
|
|
7
7
|
|
|
@@ -14,17 +14,17 @@ Both should be `'auto'` / off in production.
|
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
16
|
"use client";
|
|
17
|
-
import {
|
|
17
|
+
import { CopilotKit } from "@copilotkit/react-core/v2";
|
|
18
18
|
|
|
19
19
|
export function Providers({ children }: { children: React.ReactNode }) {
|
|
20
20
|
return (
|
|
21
|
-
<
|
|
21
|
+
<CopilotKit
|
|
22
22
|
runtimeUrl="/api/copilotkit"
|
|
23
23
|
showDevConsole="auto"
|
|
24
24
|
debug={{ events: true, lifecycle: true, verbose: false }}
|
|
25
25
|
>
|
|
26
26
|
{children}
|
|
27
|
-
</
|
|
27
|
+
</CopilotKit>
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
30
|
```
|
|
@@ -41,7 +41,7 @@ leaking PII by default. For a bug repro, explicitly set `verbose: true` to
|
|
|
41
41
|
dump full message/tool-call payloads.
|
|
42
42
|
|
|
43
43
|
```tsx
|
|
44
|
-
<
|
|
44
|
+
<CopilotKit
|
|
45
45
|
runtimeUrl="/api/copilotkit"
|
|
46
46
|
debug={{ events: true, lifecycle: true, verbose: true }}
|
|
47
47
|
/>
|
|
@@ -50,7 +50,7 @@ dump full message/tool-call payloads.
|
|
|
50
50
|
### Anchor the inspector on narrow viewports
|
|
51
51
|
|
|
52
52
|
```tsx
|
|
53
|
-
<
|
|
53
|
+
<CopilotKit
|
|
54
54
|
runtimeUrl="/api/copilotkit"
|
|
55
55
|
showDevConsole="auto"
|
|
56
56
|
inspectorDefaultAnchor="bottom-left"
|
|
@@ -60,7 +60,7 @@ dump full message/tool-call payloads.
|
|
|
60
60
|
### Env-gate the inspector
|
|
61
61
|
|
|
62
62
|
```tsx
|
|
63
|
-
<
|
|
63
|
+
<CopilotKit
|
|
64
64
|
runtimeUrl="/api/copilotkit"
|
|
65
65
|
showDevConsole={process.env.NODE_ENV !== "production"}
|
|
66
66
|
/>
|
|
@@ -73,13 +73,13 @@ dump full message/tool-call payloads.
|
|
|
73
73
|
Wrong:
|
|
74
74
|
|
|
75
75
|
```tsx
|
|
76
|
-
<
|
|
76
|
+
<CopilotKit runtimeUrl="/api/copilotkit" showDevConsole={true} />
|
|
77
77
|
```
|
|
78
78
|
|
|
79
79
|
Correct:
|
|
80
80
|
|
|
81
81
|
```tsx
|
|
82
|
-
<
|
|
82
|
+
<CopilotKit runtimeUrl="/api/copilotkit" showDevConsole="auto" />
|
|
83
83
|
// "auto" enables only on localhost / 127.0.0.1
|
|
84
84
|
```
|
|
85
85
|
|
|
@@ -93,14 +93,14 @@ Source: `packages/react-core/src/v2/providers/CopilotKitProvider.tsx:301-321`
|
|
|
93
93
|
Wrong:
|
|
94
94
|
|
|
95
95
|
```tsx
|
|
96
|
-
<
|
|
96
|
+
<CopilotKit debug={true} />
|
|
97
97
|
// Then wondering why message contents aren't in the console
|
|
98
98
|
```
|
|
99
99
|
|
|
100
100
|
Correct:
|
|
101
101
|
|
|
102
102
|
```tsx
|
|
103
|
-
<
|
|
103
|
+
<CopilotKit debug={{ events: true, lifecycle: true, verbose: true }} />
|
|
104
104
|
```
|
|
105
105
|
|
|
106
106
|
`debug: true` is shorthand for `{ events: true, lifecycle: true, verbose: false }`.
|
|
@@ -114,13 +114,13 @@ Source: `docs/snippets/shared/troubleshooting/debug-mode.mdx:85-93`
|
|
|
114
114
|
Wrong:
|
|
115
115
|
|
|
116
116
|
```tsx
|
|
117
|
-
<
|
|
117
|
+
<CopilotKit debug={{ events: true, network: true, errors: true }} />
|
|
118
118
|
```
|
|
119
119
|
|
|
120
120
|
Correct:
|
|
121
121
|
|
|
122
122
|
```tsx
|
|
123
|
-
<
|
|
123
|
+
<CopilotKit debug={{ events: true, lifecycle: true, verbose: true }} />
|
|
124
124
|
```
|
|
125
125
|
|
|
126
126
|
`DebugConfig` has exactly three fields: `events`, `lifecycle`, `verbose`.
|
|
@@ -134,13 +134,13 @@ Wrong:
|
|
|
134
134
|
|
|
135
135
|
```tsx
|
|
136
136
|
// App embedded in a sandboxed iframe with showDevConsole on
|
|
137
|
-
<
|
|
137
|
+
<CopilotKit runtimeUrl="..." showDevConsole="auto" />
|
|
138
138
|
```
|
|
139
139
|
|
|
140
140
|
Correct:
|
|
141
141
|
|
|
142
142
|
```tsx
|
|
143
|
-
<
|
|
143
|
+
<CopilotKit
|
|
144
144
|
runtimeUrl="..."
|
|
145
145
|
showDevConsole={typeof window !== "undefined" && window.self === window.top}
|
|
146
146
|
/>
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
# CopilotKit Provider Setup (React)
|
|
2
2
|
|
|
3
|
-
Mount `
|
|
4
|
-
CopilotKit hook (`useAgent`,
|
|
5
|
-
|
|
6
|
-
be rendered inside
|
|
3
|
+
Mount the `CopilotKit` provider (from `@copilotkit/react-core/v2`) once
|
|
4
|
+
near the root of the React tree. Every CopilotKit hook (`useAgent`,
|
|
5
|
+
`useFrontendTool`, `useRenderTool`, etc.) and every chat component
|
|
6
|
+
(`CopilotChat`, `CopilotPopup`, `CopilotSidebar`) must be rendered inside
|
|
7
|
+
this provider.
|
|
8
|
+
|
|
9
|
+
> **Which provider component?** Always use `CopilotKit` imported from `@copilotkit/react-core/v2`. It is the compatibility bridge across v1 and v2 and a strict superset of the other provider APIs. Do **not** use `CopilotKit` from the package root (`@copilotkit/react-core`, legacy v1) or `CopilotKitProvider` from `/v2` (a subset of the functionality).
|
|
7
10
|
|
|
8
11
|
All v2 imports use the `@copilotkit/react-core/v2` subpath. Imports from the
|
|
9
12
|
package root are v1 and will not work with v2 hooks or components.
|
|
@@ -20,12 +23,12 @@ pattern is a dedicated client-only `providers.tsx`.
|
|
|
20
23
|
// app/providers.tsx
|
|
21
24
|
"use client";
|
|
22
25
|
|
|
23
|
-
import {
|
|
26
|
+
import { CopilotKit } from "@copilotkit/react-core/v2";
|
|
24
27
|
import "@copilotkit/react-core/v2/styles.css";
|
|
25
28
|
|
|
26
29
|
export function Providers({ children }: { children: React.ReactNode }) {
|
|
27
30
|
return (
|
|
28
|
-
<
|
|
31
|
+
<CopilotKit
|
|
29
32
|
runtimeUrl="/api/copilotkit"
|
|
30
33
|
credentials="include"
|
|
31
34
|
onError={({ code, error, context }) => {
|
|
@@ -33,7 +36,7 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
|
|
33
36
|
}}
|
|
34
37
|
>
|
|
35
38
|
{children}
|
|
36
|
-
</
|
|
39
|
+
</CopilotKit>
|
|
37
40
|
);
|
|
38
41
|
}
|
|
39
42
|
```
|
|
@@ -66,28 +69,24 @@ export default function RootLayout({
|
|
|
66
69
|
### Vite / React Router v7 / SPA
|
|
67
70
|
|
|
68
71
|
```tsx
|
|
69
|
-
import {
|
|
72
|
+
import { CopilotKit } from "@copilotkit/react-core/v2";
|
|
70
73
|
import "@copilotkit/react-core/v2/styles.css";
|
|
71
74
|
|
|
72
75
|
export function App({ children }: { children: React.ReactNode }) {
|
|
73
|
-
return
|
|
74
|
-
<CopilotKitProvider runtimeUrl="/api/copilotkit">
|
|
75
|
-
{children}
|
|
76
|
-
</CopilotKitProvider>
|
|
77
|
-
);
|
|
76
|
+
return <CopilotKit runtimeUrl="/api/copilotkit">{children}</CopilotKit>;
|
|
78
77
|
}
|
|
79
78
|
```
|
|
80
79
|
|
|
81
|
-
### SPA with CopilotKit
|
|
80
|
+
### SPA with CopilotKit Intelligence (no self-hosted runtime)
|
|
82
81
|
|
|
83
82
|
```tsx
|
|
84
|
-
<
|
|
83
|
+
<CopilotKit publicLicenseKey="ck_pub_..." />
|
|
85
84
|
```
|
|
86
85
|
|
|
87
|
-
`
|
|
88
|
-
client bundle. `
|
|
89
|
-
|
|
90
|
-
|
|
86
|
+
`publicLicenseKey` is the canonical prop for running CopilotKit from a
|
|
87
|
+
pure client bundle. `publicApiKey` is a deprecated alias that resolves to
|
|
88
|
+
the same value — accept it in old code, but always write
|
|
89
|
+
`publicLicenseKey` in new code.
|
|
91
90
|
|
|
92
91
|
## Core Patterns
|
|
93
92
|
|
|
@@ -117,7 +116,7 @@ UI from getting stuck in "connecting..." when the runtime URL is wrong or
|
|
|
117
116
|
CORS is misconfigured.
|
|
118
117
|
|
|
119
118
|
```tsx
|
|
120
|
-
<
|
|
119
|
+
<CopilotKit
|
|
121
120
|
runtimeUrl="/api/copilotkit"
|
|
122
121
|
onError={({ code, error, context }) => {
|
|
123
122
|
telemetry.capture({ code, message: error.message, context });
|
|
@@ -136,7 +135,7 @@ const properties = useMemo(
|
|
|
136
135
|
[user.tenantId, user.locale],
|
|
137
136
|
);
|
|
138
137
|
|
|
139
|
-
<
|
|
138
|
+
<CopilotKit runtimeUrl="/api/copilotkit" properties={properties} />;
|
|
140
139
|
```
|
|
141
140
|
|
|
142
141
|
## Common Mistakes
|
|
@@ -147,12 +146,10 @@ Wrong:
|
|
|
147
146
|
|
|
148
147
|
```tsx
|
|
149
148
|
// app/page.tsx (server component — no "use client")
|
|
150
|
-
import {
|
|
149
|
+
import { CopilotKit } from "@copilotkit/react-core/v2";
|
|
151
150
|
|
|
152
151
|
export default function Page() {
|
|
153
|
-
return
|
|
154
|
-
<CopilotKitProvider runtimeUrl="/api/copilotkit">...</CopilotKitProvider>
|
|
155
|
-
);
|
|
152
|
+
return <CopilotKit runtimeUrl="/api/copilotkit">...</CopilotKit>;
|
|
156
153
|
}
|
|
157
154
|
```
|
|
158
155
|
|
|
@@ -161,14 +158,10 @@ Correct:
|
|
|
161
158
|
```tsx
|
|
162
159
|
// app/providers.tsx
|
|
163
160
|
"use client";
|
|
164
|
-
import {
|
|
161
|
+
import { CopilotKit } from "@copilotkit/react-core/v2";
|
|
165
162
|
|
|
166
163
|
export function Providers({ children }: { children: React.ReactNode }) {
|
|
167
|
-
return
|
|
168
|
-
<CopilotKitProvider runtimeUrl="/api/copilotkit">
|
|
169
|
-
{children}
|
|
170
|
-
</CopilotKitProvider>
|
|
171
|
-
);
|
|
164
|
+
return <CopilotKit runtimeUrl="/api/copilotkit">{children}</CopilotKit>;
|
|
172
165
|
}
|
|
173
166
|
|
|
174
167
|
// app/layout.tsx imports <Providers>.
|
|
@@ -185,13 +178,13 @@ Source: `packages/react-core/src/v2/index.ts:1`
|
|
|
185
178
|
Wrong:
|
|
186
179
|
|
|
187
180
|
```tsx
|
|
188
|
-
<
|
|
181
|
+
<CopilotKit
|
|
189
182
|
agents__unsafe_dev_only={{
|
|
190
183
|
default: new BuiltInAgent({ apiKey: process.env.OPENAI_KEY! }),
|
|
191
184
|
}}
|
|
192
185
|
/>
|
|
193
186
|
// or the alias (same thing):
|
|
194
|
-
<
|
|
187
|
+
<CopilotKit
|
|
195
188
|
selfManagedAgents={{ default: new BuiltInAgent({ apiKey: "..." }) }}
|
|
196
189
|
/>
|
|
197
190
|
```
|
|
@@ -200,10 +193,10 @@ Correct:
|
|
|
200
193
|
|
|
201
194
|
```tsx
|
|
202
195
|
// Route through a runtime that keeps secrets server-side:
|
|
203
|
-
<
|
|
196
|
+
<CopilotKit runtimeUrl="/api/copilotkit" />
|
|
204
197
|
|
|
205
|
-
// Or for a pure SPA, use CopilotKit
|
|
206
|
-
<
|
|
198
|
+
// Or for a pure SPA, use CopilotKit Intelligence:
|
|
199
|
+
<CopilotKit publicLicenseKey="ck_pub_..." />
|
|
207
200
|
```
|
|
208
201
|
|
|
209
202
|
Both props are aliases for the same dev-only mechanism and ship any embedded
|
|
@@ -216,7 +209,7 @@ Source: `packages/react-core/src/v2/providers/CopilotKitProvider.tsx:136-138,393
|
|
|
216
209
|
Wrong:
|
|
217
210
|
|
|
218
211
|
```tsx
|
|
219
|
-
<
|
|
212
|
+
<CopilotKit
|
|
220
213
|
runtimeUrl="/api/copilotkit"
|
|
221
214
|
headers={{ Authorization: `Bearer ${token}` }}
|
|
222
215
|
properties={{ tenantId: user.tenantId }}
|
|
@@ -232,7 +225,7 @@ const properties = useMemo(
|
|
|
232
225
|
[user.tenantId],
|
|
233
226
|
);
|
|
234
227
|
|
|
235
|
-
<
|
|
228
|
+
<CopilotKit
|
|
236
229
|
runtimeUrl="/api/copilotkit"
|
|
237
230
|
headers={headers}
|
|
238
231
|
properties={properties}
|
|
@@ -251,13 +244,13 @@ Source: `packages/react-core/src/v2/providers/CopilotKitProvider.tsx:324-340,399
|
|
|
251
244
|
Wrong:
|
|
252
245
|
|
|
253
246
|
```tsx
|
|
254
|
-
<
|
|
247
|
+
<CopilotKit runtimeUrl="/api/copilotkit" />
|
|
255
248
|
```
|
|
256
249
|
|
|
257
250
|
Correct:
|
|
258
251
|
|
|
259
252
|
```tsx
|
|
260
|
-
<
|
|
253
|
+
<CopilotKit
|
|
261
254
|
runtimeUrl="/api/copilotkit"
|
|
262
255
|
onError={({ code, error, context }) => {
|
|
263
256
|
telemetry.capture({ code, error, context });
|
|
@@ -272,26 +265,26 @@ forever and users never see the actual error.
|
|
|
272
265
|
|
|
273
266
|
Source: `packages/react-core/src/v2/providers/CopilotKitProvider.tsx:638-660`
|
|
274
267
|
|
|
275
|
-
### HIGH — Writing `
|
|
268
|
+
### HIGH — Writing `publicApiKey` in new code
|
|
276
269
|
|
|
277
270
|
Wrong:
|
|
278
271
|
|
|
279
272
|
```tsx
|
|
280
|
-
<
|
|
273
|
+
<CopilotKit publicApiKey="ck_pub_..." />
|
|
281
274
|
```
|
|
282
275
|
|
|
283
276
|
Correct:
|
|
284
277
|
|
|
285
278
|
```tsx
|
|
286
|
-
<
|
|
279
|
+
<CopilotKit publicLicenseKey="ck_pub_..." />
|
|
287
280
|
```
|
|
288
281
|
|
|
289
|
-
`
|
|
290
|
-
canonical name
|
|
291
|
-
`
|
|
282
|
+
`publicApiKey` still works as a deprecated alias, but `publicLicenseKey`
|
|
283
|
+
is the canonical name. The `CopilotKit` provider resolves
|
|
284
|
+
`publicLicenseKey || publicApiKey`. Always write the canonical form in
|
|
292
285
|
new code.
|
|
293
286
|
|
|
294
|
-
Source: `packages/react-core/src/
|
|
287
|
+
Source: `packages/react-core/src/components/copilot-provider/copilotkit.tsx:172`
|
|
295
288
|
|
|
296
289
|
### MEDIUM — Putting the provider below a layout that uses CopilotKit
|
|
297
290
|
|
|
@@ -301,7 +294,7 @@ Wrong:
|
|
|
301
294
|
<html>
|
|
302
295
|
<body>
|
|
303
296
|
<Header>{/* Header uses useFrontendTool internally */}</Header>
|
|
304
|
-
<
|
|
297
|
+
<CopilotKit>{children}</CopilotKit>
|
|
305
298
|
</body>
|
|
306
299
|
</html>
|
|
307
300
|
```
|
|
@@ -311,16 +304,16 @@ Correct:
|
|
|
311
304
|
```tsx
|
|
312
305
|
<html>
|
|
313
306
|
<body>
|
|
314
|
-
<
|
|
307
|
+
<CopilotKit>
|
|
315
308
|
<Header />
|
|
316
309
|
{children}
|
|
317
|
-
</
|
|
310
|
+
</CopilotKit>
|
|
318
311
|
</body>
|
|
319
312
|
</html>
|
|
320
313
|
```
|
|
321
314
|
|
|
322
315
|
Any component that calls `useCopilotKit`, `useFrontendTool`, `useAgent`, or
|
|
323
|
-
any other CopilotKit hook must be a descendant of `
|
|
324
|
-
Placing the provider beside or below a consumer throws at mount.
|
|
316
|
+
any other CopilotKit hook must be a descendant of the `CopilotKit`
|
|
317
|
+
provider. Placing the provider beside or below a consumer throws at mount.
|
|
325
318
|
|
|
326
319
|
Source: `packages/react-core/src/v2/providers/CopilotKitProvider.tsx` (context)
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
This skill builds on `copilotkit/provider-setup`. Activity-message
|
|
4
4
|
renderers are registered as entries in the `renderActivityMessages` array
|
|
5
|
-
prop on `
|
|
5
|
+
prop on the `CopilotKit` provider and resolved at render time by
|
|
6
6
|
`useRenderActivityMessage` (consumed internally by chat components).
|
|
7
7
|
|
|
8
8
|
User renderers are placed first in the array so they override the built-in
|
|
@@ -20,7 +20,7 @@ Resolver order:
|
|
|
20
20
|
|
|
21
21
|
```tsx
|
|
22
22
|
"use client";
|
|
23
|
-
import {
|
|
23
|
+
import { CopilotKit } from "@copilotkit/react-core/v2";
|
|
24
24
|
import type { ReactActivityMessageRenderer } from "@copilotkit/react-core/v2";
|
|
25
25
|
import { z } from "zod";
|
|
26
26
|
import { useMemo } from "react";
|
|
@@ -46,12 +46,9 @@ const progressRenderer: ReactActivityMessageRenderer<{
|
|
|
46
46
|
export function Providers({ children }: { children: React.ReactNode }) {
|
|
47
47
|
const renderers = useMemo(() => [progressRenderer], []);
|
|
48
48
|
return (
|
|
49
|
-
<
|
|
50
|
-
runtimeUrl="/api/copilotkit"
|
|
51
|
-
renderActivityMessages={renderers}
|
|
52
|
-
>
|
|
49
|
+
<CopilotKit runtimeUrl="/api/copilotkit" renderActivityMessages={renderers}>
|
|
53
50
|
{children}
|
|
54
|
-
</
|
|
51
|
+
</CopilotKit>
|
|
55
52
|
);
|
|
56
53
|
}
|
|
57
54
|
```
|
|
@@ -184,7 +181,7 @@ Source: `packages/react-core/src/v2/hooks/use-render-activity-message.tsx`
|
|
|
184
181
|
Wrong:
|
|
185
182
|
|
|
186
183
|
```tsx
|
|
187
|
-
<
|
|
184
|
+
<CopilotKit
|
|
188
185
|
runtimeUrl="/api/copilotkit"
|
|
189
186
|
renderActivityMessages={[progressRenderer, customMcpRenderer]}
|
|
190
187
|
/>
|
|
@@ -194,10 +191,7 @@ Correct:
|
|
|
194
191
|
|
|
195
192
|
```tsx
|
|
196
193
|
const renderers = useMemo(() => [progressRenderer, customMcpRenderer], []);
|
|
197
|
-
<
|
|
198
|
-
runtimeUrl="/api/copilotkit"
|
|
199
|
-
renderActivityMessages={renderers}
|
|
200
|
-
/>;
|
|
194
|
+
<CopilotKit runtimeUrl="/api/copilotkit" renderActivityMessages={renderers} />;
|
|
201
195
|
```
|
|
202
196
|
|
|
203
197
|
The provider uses `useStableArrayProp` and console-errors when a new array
|