@copilotkit/react-core 1.55.0-next.8 → 1.55.0

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.
Files changed (94) hide show
  1. package/CHANGELOG.md +48 -5
  2. package/dist/{copilotkit-DNYSFuz5.mjs → copilotkit-BY5S1-0P.mjs} +2772 -858
  3. package/dist/copilotkit-BY5S1-0P.mjs.map +1 -0
  4. package/dist/{copilotkit-Dy5w3qEV.d.mts → copilotkit-BuhSUZHb.d.mts} +230 -17
  5. package/dist/copilotkit-BuhSUZHb.d.mts.map +1 -0
  6. package/dist/{copilotkit-B3Mb1yVE.cjs → copilotkit-Bz5-ImDl.cjs} +2776 -832
  7. package/dist/copilotkit-Bz5-ImDl.cjs.map +1 -0
  8. package/dist/{copilotkit-DBzgOMby.d.cts → copilotkit-dwDWYpya.d.cts} +230 -17
  9. package/dist/copilotkit-dwDWYpya.d.cts.map +1 -0
  10. package/dist/index.cjs +9 -4
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +1 -1
  13. package/dist/index.d.mts +1 -1
  14. package/dist/index.mjs +9 -4
  15. package/dist/index.mjs.map +1 -1
  16. package/dist/index.umd.js +1624 -396
  17. package/dist/index.umd.js.map +1 -1
  18. package/dist/v2/index.cjs +13 -1
  19. package/dist/v2/index.css +1 -1
  20. package/dist/v2/index.d.cts +3 -3
  21. package/dist/v2/index.d.mts +3 -3
  22. package/dist/v2/index.mjs +3 -2
  23. package/dist/v2/index.umd.js +2746 -790
  24. package/dist/v2/index.umd.js.map +1 -1
  25. package/package.json +62 -54
  26. package/scripts/scope-preflight.mjs +1 -2
  27. package/src/components/CopilotListeners.tsx +41 -8
  28. package/src/components/copilot-provider/__tests__/copilot-messages-key.test.tsx +92 -0
  29. package/src/components/copilot-provider/copilotkit-props.tsx +4 -2
  30. package/src/components/copilot-provider/copilotkit.tsx +3 -3
  31. package/src/components/toast/toast-provider.tsx +269 -194
  32. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +27 -16
  33. package/src/hooks/use-copilot-chat_internal.ts +15 -4
  34. package/src/v2/__tests__/A2UIMessageRenderer.test.tsx +86 -22
  35. package/src/v2/__tests__/utils/test-helpers.tsx +107 -7
  36. package/src/v2/a2ui/A2UICatalogContext.tsx +79 -0
  37. package/src/v2/a2ui/A2UIMessageRenderer.tsx +125 -37
  38. package/src/v2/a2ui/A2UIToolCallRenderer.tsx +290 -0
  39. package/src/v2/components/CopilotKitInspector.tsx +2 -0
  40. package/src/v2/components/OpenGenerativeUIRenderer.tsx +598 -0
  41. package/src/v2/components/__tests__/OpenGenerativeUIRenderer.test.tsx +665 -0
  42. package/src/v2/components/chat/CopilotChat.tsx +197 -52
  43. package/src/v2/components/chat/CopilotChatAssistantMessage.tsx +17 -2
  44. package/src/v2/components/chat/CopilotChatAttachmentQueue.tsx +481 -0
  45. package/src/v2/components/chat/CopilotChatAttachmentRenderer.tsx +139 -0
  46. package/src/v2/components/chat/CopilotChatInput.tsx +146 -77
  47. package/src/v2/components/chat/CopilotChatMessageView.tsx +260 -151
  48. package/src/v2/components/chat/CopilotChatSuggestionView.tsx +1 -0
  49. package/src/v2/components/chat/CopilotChatUserMessage.tsx +54 -0
  50. package/src/v2/components/chat/CopilotChatView.tsx +179 -66
  51. package/src/v2/components/chat/__tests__/CopilotChat.attachments.test.tsx +168 -0
  52. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +63 -2
  53. package/src/v2/components/chat/__tests__/CopilotChatInput.test.tsx +544 -1
  54. package/src/v2/components/chat/__tests__/CopilotChatPerf.e2e.test.tsx +268 -0
  55. package/src/v2/components/chat/__tests__/CopilotChatPropsRerender.e2e.test.tsx +249 -0
  56. package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.tsx +5 -2
  57. package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.tsx +5 -2
  58. package/src/v2/components/chat/__tests__/MCPAppsActivityRenderer.e2e.test.tsx +60 -3
  59. package/src/v2/components/chat/__tests__/copilot-chat-throttle.test.tsx +138 -0
  60. package/src/v2/components/chat/index.ts +9 -0
  61. package/src/v2/components/chat/scroll-element-context.ts +13 -0
  62. package/src/v2/hooks/__tests__/use-agent-context-timing.e2e.test.tsx +8 -0
  63. package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +327 -0
  64. package/src/v2/hooks/__tests__/use-agent-throttle.test.tsx +1003 -0
  65. package/src/v2/hooks/__tests__/use-agent.e2e.test.tsx +13 -2
  66. package/src/v2/hooks/__tests__/use-attachments.test.tsx +169 -0
  67. package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.tsx +23 -4
  68. package/src/v2/hooks/__tests__/use-threads.test.tsx +54 -0
  69. package/src/v2/hooks/index.ts +5 -0
  70. package/src/v2/hooks/use-agent.tsx +220 -15
  71. package/src/v2/hooks/use-attachments.tsx +269 -0
  72. package/src/v2/hooks/use-frontend-tool.tsx +5 -2
  73. package/src/v2/hooks/use-render-activity-message.tsx +9 -2
  74. package/src/v2/hooks/use-render-custom-messages.tsx +6 -1
  75. package/src/v2/hooks/use-threads.tsx +35 -15
  76. package/src/v2/index.ts +5 -1
  77. package/src/v2/lib/__tests__/processPartialHtml.test.ts +112 -0
  78. package/src/v2/lib/__tests__/slots.test.ts +56 -0
  79. package/src/v2/lib/processPartialHtml.ts +45 -0
  80. package/src/v2/lib/slots.tsx +42 -1
  81. package/src/v2/providers/CopilotChatConfigurationProvider.tsx +9 -3
  82. package/src/v2/providers/CopilotKitProvider.tsx +268 -32
  83. package/src/v2/providers/SandboxFunctionsContext.ts +10 -0
  84. package/src/v2/providers/__tests__/CopilotKitProvider.sandboxFunctions.test.tsx +198 -0
  85. package/src/v2/providers/__tests__/CopilotKitProvider.test.tsx +71 -0
  86. package/src/v2/providers/index.ts +7 -0
  87. package/src/v2/styles/globals.css +2 -1
  88. package/src/v2/types/index.ts +1 -0
  89. package/src/v2/types/sandbox-function.ts +11 -0
  90. package/dist/copilotkit-B3Mb1yVE.cjs.map +0 -1
  91. package/dist/copilotkit-DBzgOMby.d.cts.map +0 -1
  92. package/dist/copilotkit-DNYSFuz5.mjs.map +0 -1
  93. package/dist/copilotkit-Dy5w3qEV.d.mts.map +0 -1
  94. package/src/v2/components/__tests__/license-warning-banner.test.tsx +0 -46
@@ -0,0 +1,290 @@
1
+ import React, { useEffect, useRef } from "react";
2
+ import { useCopilotKit } from "../providers/CopilotKitProvider";
3
+ import { defineToolCallRenderer } from "../types/defineToolCallRenderer";
4
+ import { z } from "zod";
5
+
6
+ /**
7
+ * Tool name used by the dynamic A2UI generation secondary LLM.
8
+ * This renderer is auto-registered when A2UI is enabled.
9
+ */
10
+ export const RENDER_A2UI_TOOL_NAME = "render_a2ui";
11
+
12
+ interface A2UIProgressProps {
13
+ parameters: unknown;
14
+ }
15
+
16
+ /**
17
+ * Built-in progress indicator for dynamic A2UI generation.
18
+ * Shows a skeleton wireframe that progressively reveals as tokens stream in.
19
+ *
20
+ * Registered automatically when A2UI is enabled. Users can override by
21
+ * providing their own `useRenderTool({ name: "render_a2ui", ... })`.
22
+ */
23
+ function A2UIProgressIndicator({ parameters }: A2UIProgressProps) {
24
+ const lastRef = useRef({ time: 0, tokens: 0 });
25
+ const now = Date.now();
26
+
27
+ let { tokens } = lastRef.current;
28
+ if (now - lastRef.current.time > 200) {
29
+ const chars = JSON.stringify(parameters ?? {}).length;
30
+ tokens = Math.round(chars / 4);
31
+ lastRef.current = { time: now, tokens };
32
+ }
33
+
34
+ const phase = tokens < 50 ? 0 : tokens < 200 ? 1 : tokens < 400 ? 2 : 3;
35
+
36
+ return (
37
+ <div style={{ margin: "12px 0", maxWidth: 320 }}>
38
+ <div
39
+ style={{
40
+ position: "relative",
41
+ overflow: "hidden",
42
+ borderRadius: 12,
43
+ border: "1px solid rgba(228,228,231,0.8)",
44
+ backgroundColor: "#fff",
45
+ boxShadow: "0 1px 2px rgba(0,0,0,0.04)",
46
+ padding: "16px 18px 14px",
47
+ }}
48
+ >
49
+ {/* Top bar */}
50
+ <div
51
+ style={{
52
+ display: "flex",
53
+ alignItems: "center",
54
+ gap: 8,
55
+ marginBottom: 12,
56
+ }}
57
+ >
58
+ <div style={{ display: "flex", gap: 4 }}>
59
+ <Dot />
60
+ <Dot />
61
+ <Dot />
62
+ </div>
63
+ <Bar
64
+ w={64}
65
+ h={6}
66
+ bg="#e4e4e7"
67
+ opacity={phase >= 1 ? 1 : 0.4}
68
+ transition="opacity 0.5s"
69
+ />
70
+ </div>
71
+
72
+ {/* Skeleton lines */}
73
+ <div style={{ display: "grid", gap: 7 }}>
74
+ <Row show={phase >= 0}>
75
+ <Bar w={36} h={7} bg="rgba(147,197,253,0.7)" anim={0} />
76
+ <Bar w={80} h={7} bg="rgba(219,234,254,0.8)" anim={0.2} />
77
+ </Row>
78
+ <Row show={phase >= 0} delay={0.1}>
79
+ <Spacer />
80
+ <Dot />
81
+ <Bar w={100} h={7} bg="rgba(24,24,27,0.2)" anim={0.3} />
82
+ </Row>
83
+ <Row show={phase >= 1} delay={0.15}>
84
+ <Spacer />
85
+ <Bar w={48} h={7} bg="rgba(24,24,27,0.15)" anim={0.1} />
86
+ <Bar w={40} h={7} bg="rgba(153,246,228,0.6)" anim={0.5} />
87
+ <Bar w={56} h={7} bg="rgba(147,197,253,0.6)" anim={0.3} />
88
+ </Row>
89
+ <Row show={phase >= 1} delay={0.2}>
90
+ <Spacer />
91
+ <Dot />
92
+ <Bar w={60} h={7} bg="rgba(24,24,27,0.15)" anim={0.4} />
93
+ </Row>
94
+ <Row show={phase >= 2} delay={0.25}>
95
+ <Bar w={40} h={7} bg="rgba(153,246,228,0.5)" anim={0.2} />
96
+ <Dot />
97
+ <Bar w={48} h={7} bg="rgba(24,24,27,0.15)" anim={0.6} />
98
+ <Bar w={64} h={7} bg="rgba(147,197,253,0.5)" anim={0.1} />
99
+ </Row>
100
+ <Row show={phase >= 2} delay={0.3}>
101
+ <Bar w={36} h={7} bg="rgba(147,197,253,0.6)" anim={0.5} />
102
+ <Bar w={36} h={7} bg="rgba(24,24,27,0.12)" anim={0.7} />
103
+ </Row>
104
+ <Row show={phase >= 3} delay={0.35}>
105
+ <Dot />
106
+ <Bar w={44} h={7} bg="rgba(24,24,27,0.18)" anim={0.3} />
107
+ <Dot />
108
+ <Bar w={56} h={7} bg="rgba(153,246,228,0.5)" anim={0.8} />
109
+ <Bar w={48} h={7} bg="rgba(147,197,253,0.5)" anim={0.4} />
110
+ </Row>
111
+ </div>
112
+
113
+ {/* Shimmer */}
114
+ <div
115
+ style={{
116
+ pointerEvents: "none",
117
+ position: "absolute",
118
+ inset: 0,
119
+ background:
120
+ "linear-gradient(105deg, transparent 0%, transparent 40%, rgba(255,255,255,0.6) 50%, transparent 60%, transparent 100%)",
121
+ backgroundSize: "250% 100%",
122
+ animation: "cpk-a2ui-sweep 3s ease-in-out infinite",
123
+ }}
124
+ />
125
+ </div>
126
+
127
+ {/* Label */}
128
+ <div
129
+ style={{
130
+ display: "flex",
131
+ alignItems: "center",
132
+ justifyContent: "center",
133
+ gap: 8,
134
+ marginTop: 8,
135
+ }}
136
+ >
137
+ <span
138
+ style={{
139
+ fontSize: 12,
140
+ color: "#a1a1aa",
141
+ letterSpacing: "0.025em",
142
+ }}
143
+ >
144
+ Building interface
145
+ </span>
146
+ {tokens > 0 && (
147
+ <span
148
+ style={{
149
+ fontSize: 11,
150
+ color: "#d4d4d8",
151
+ fontVariantNumeric: "tabular-nums",
152
+ }}
153
+ >
154
+ ~{tokens.toLocaleString()} tokens
155
+ </span>
156
+ )}
157
+ </div>
158
+
159
+ <style>{`
160
+ @keyframes cpk-a2ui-fade {
161
+ 0%, 100% { opacity: 1; }
162
+ 50% { opacity: 0.5; }
163
+ }
164
+ @keyframes cpk-a2ui-sweep {
165
+ 0% { background-position: 250% 0; }
166
+ 100% { background-position: -250% 0; }
167
+ }
168
+ `}</style>
169
+ </div>
170
+ );
171
+ }
172
+
173
+ // --- Primitives ---
174
+
175
+ function Dot() {
176
+ return (
177
+ <div
178
+ style={{
179
+ width: 7,
180
+ height: 7,
181
+ borderRadius: "50%",
182
+ backgroundColor: "#d4d4d8",
183
+ flexShrink: 0,
184
+ }}
185
+ />
186
+ );
187
+ }
188
+
189
+ function Spacer() {
190
+ return <div style={{ width: 12 }} />;
191
+ }
192
+
193
+ function Bar({
194
+ w,
195
+ h,
196
+ bg,
197
+ anim,
198
+ opacity,
199
+ transition,
200
+ }: {
201
+ w: number;
202
+ h: number;
203
+ bg: string;
204
+ anim?: number;
205
+ opacity?: number;
206
+ transition?: string;
207
+ }) {
208
+ return (
209
+ <div
210
+ style={{
211
+ width: w,
212
+ height: h,
213
+ borderRadius: 9999,
214
+ backgroundColor: bg,
215
+ ...(anim !== undefined
216
+ ? { animation: `cpk-a2ui-fade 2.4s ease-in-out ${anim}s infinite` }
217
+ : {}),
218
+ ...(opacity !== undefined ? { opacity } : {}),
219
+ ...(transition ? { transition } : {}),
220
+ }}
221
+ />
222
+ );
223
+ }
224
+
225
+ function Row({
226
+ children,
227
+ show,
228
+ delay = 0,
229
+ }: {
230
+ children: React.ReactNode;
231
+ show: boolean;
232
+ delay?: number;
233
+ }) {
234
+ return (
235
+ <div
236
+ style={{
237
+ display: "flex",
238
+ alignItems: "center",
239
+ gap: 6,
240
+ opacity: show ? 1 : 0,
241
+ transition: `opacity 0.4s ${delay}s`,
242
+ }}
243
+ >
244
+ {children}
245
+ </div>
246
+ );
247
+ }
248
+
249
+ // --- Hook entry point ---
250
+
251
+ /**
252
+ * Registers the built-in `render_a2ui` tool call renderer via the props-based
253
+ * `setRenderToolCalls` mechanism (not `useRenderTool`).
254
+ *
255
+ * This ensures user-registered `useRenderTool({ name: "render_a2ui", ... })`
256
+ * hooks automatically override the built-in, since the merge logic in
257
+ * react-core.ts gives hook-based entries priority over prop-based entries.
258
+ */
259
+ export function A2UIBuiltInToolCallRenderer(): null {
260
+ const { copilotkit } = useCopilotKit();
261
+
262
+ useEffect(() => {
263
+ const renderer = defineToolCallRenderer({
264
+ name: RENDER_A2UI_TOOL_NAME,
265
+ args: z.any(),
266
+ render: ({ status, args: parameters }) => {
267
+ if (status === "complete") return <></>;
268
+ const params = parameters as any;
269
+ // Hide skeleton once the A2UI surface has enough data to render.
270
+ // For data-bound surfaces: items array is populated.
271
+ // For dashboard-style surfaces: components array has multiple entries
272
+ // (meaning the streaming path is emitting activity snapshots).
273
+ const items = params?.items;
274
+ if (Array.isArray(items) && items.length > 0) return <></>;
275
+ const components = params?.components;
276
+ if (Array.isArray(components) && components.length > 2) return <></>;
277
+ return <A2UIProgressIndicator parameters={parameters} />;
278
+ },
279
+ });
280
+
281
+ // Register via props-based mechanism so useRenderTool hooks take priority
282
+ const existing = (copilotkit as any)._renderToolCalls ?? [];
283
+ copilotkit.setRenderToolCalls([
284
+ ...existing.filter((rc: any) => rc.name !== RENDER_A2UI_TOOL_NAME),
285
+ renderer,
286
+ ]);
287
+ }, [copilotkit]);
288
+
289
+ return null;
290
+ }
@@ -1,9 +1,11 @@
1
1
  import * as React from "react";
2
2
  import { createComponent } from "@lit-labs/react";
3
3
  import type { CopilotKitCore } from "@copilotkit/core";
4
+ import type { Anchor } from "@copilotkit/web-inspector";
4
5
 
5
6
  type CopilotKitInspectorBaseProps = {
6
7
  core?: CopilotKitCore | null;
8
+ defaultAnchor?: Anchor;
7
9
  [key: string]: unknown;
8
10
  };
9
11