@copilotkit/react-core 1.56.5-canary.1777972218 → 1.57.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 (45) hide show
  1. package/dist/{copilotkit-BVK_b6St.mjs → copilotkit-CPe2-340.mjs} +177 -330
  2. package/dist/copilotkit-CPe2-340.mjs.map +1 -0
  3. package/dist/{copilotkit-DV9LwRgi.d.mts → copilotkit-DFaI4j2r.d.mts} +6 -52
  4. package/dist/copilotkit-DFaI4j2r.d.mts.map +1 -0
  5. package/dist/{copilotkit-BGIsblrk.cjs → copilotkit-DGbvw8n2.cjs} +176 -335
  6. package/dist/copilotkit-DGbvw8n2.cjs.map +1 -0
  7. package/dist/{copilotkit-Bc7kZ72T.d.cts → copilotkit-Dg4r4Gi_.d.cts} +6 -52
  8. package/dist/copilotkit-Dg4r4Gi_.d.cts.map +1 -0
  9. package/dist/index.cjs +5 -2
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.mjs +5 -2
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/index.umd.js +172 -117
  16. package/dist/index.umd.js.map +1 -1
  17. package/dist/v2/index.cjs +1 -2
  18. package/dist/v2/index.css +1 -1
  19. package/dist/v2/index.d.cts +2 -2
  20. package/dist/v2/index.d.mts +2 -2
  21. package/dist/v2/index.mjs +2 -2
  22. package/dist/v2/index.umd.js +182 -340
  23. package/dist/v2/index.umd.js.map +1 -1
  24. package/package.json +6 -6
  25. package/src/hooks/__tests__/use-copilot-chat-internal-connect.test.tsx +6 -5
  26. package/src/hooks/use-copilot-chat_internal.ts +1 -0
  27. package/src/v2/components/chat/CopilotChat.tsx +1 -2
  28. package/src/v2/components/chat/CopilotChatMessageView.tsx +13 -124
  29. package/src/v2/components/chat/CopilotChatView.tsx +2 -2
  30. package/src/v2/components/chat/__tests__/CopilotChat.welcomeGate.test.tsx +3 -1
  31. package/src/v2/components/chat/__tests__/CopilotChatActivityRendering.e2e.test.tsx +25 -29
  32. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +60 -5
  33. package/src/v2/components/index.ts +0 -1
  34. package/src/v2/hooks/__tests__/use-agent-thread-isolation.test.tsx +333 -0
  35. package/src/v2/hooks/use-agent.tsx +116 -7
  36. package/src/v2/hooks/use-render-activity-message.tsx +11 -3
  37. package/src/v2/hooks/use-render-custom-messages.tsx +6 -1
  38. package/src/v2/styles/globals.css +0 -112
  39. package/dist/copilotkit-BGIsblrk.cjs.map +0 -1
  40. package/dist/copilotkit-BVK_b6St.mjs.map +0 -1
  41. package/dist/copilotkit-Bc7kZ72T.d.cts.map +0 -1
  42. package/dist/copilotkit-DV9LwRgi.d.mts.map +0 -1
  43. package/src/v2/components/intelligence-indicator/IntelligenceIndicator.tsx +0 -265
  44. package/src/v2/components/intelligence-indicator/__tests__/IntelligenceIndicator.e2e.test.tsx +0 -362
  45. package/src/v2/components/intelligence-indicator/index.ts +0 -2
@@ -1,362 +0,0 @@
1
- import React from "react";
2
- import { afterEach, describe, expect, it } from "vitest";
3
- import { fireEvent, render, screen, waitFor } from "@testing-library/react";
4
- import { EventType, type BaseEvent, type RunAgentInput } from "@ag-ui/client";
5
- import { Observable, type Subject } from "rxjs";
6
- import { takeWhile } from "rxjs/operators";
7
- import {
8
- MockStepwiseAgent,
9
- runStartedEvent,
10
- runFinishedEvent,
11
- textMessageStartEvent,
12
- textMessageEndEvent,
13
- toolCallChunkEvent,
14
- } from "../../../__tests__/utils/test-helpers";
15
- import { CopilotChat } from "../../chat/CopilotChat";
16
- import { CopilotKitProvider } from "../../../providers/CopilotKitProvider";
17
- import { CopilotChatConfigurationProvider } from "../../../providers/CopilotChatConfigurationProvider";
18
- import { useCopilotKit } from "../../../providers/CopilotKitProvider";
19
- import { useAgent } from "../../../hooks/use-agent";
20
-
21
- /**
22
- * Mock agent with accurate per-run `isRunning` lifecycle. The shared
23
- * `MockStepwiseAgent` returns the un-terminating `subject.asObservable()`
24
- * for backward compatibility, so emitting `RUN_FINISHED` on it doesn't
25
- * complete the rxjs pipeline → `isRunning` never flips back. The
26
- * `takeWhile(..., true)` here makes the per-run observable terminate on
27
- * RUN_FINISHED / RUN_ERROR (the `true` is "inclusive" — emit the
28
- * terminal event before completing). That terminates AG-UI's run
29
- * pipeline like a real agent so the indicator sees the falling edge.
30
- */
31
- class IsRunningAccurateMockAgent extends MockStepwiseAgent {
32
- override run(_input: RunAgentInput): Observable<BaseEvent> {
33
- return (this as unknown as { subject: Subject<BaseEvent> }).subject.pipe(
34
- takeWhile(
35
- (event) =>
36
- event.type !== EventType.RUN_FINISHED &&
37
- event.type !== EventType.RUN_ERROR,
38
- true,
39
- ),
40
- );
41
- }
42
- }
43
-
44
- const PILL_TESTID_RE = /^cpk-intelligence-pill-/;
45
-
46
- const expectPillCount = (n: number): void => {
47
- expect(screen.queryAllByTestId(PILL_TESTID_RE).length).toBe(n);
48
- };
49
-
50
- const expectPillOn = (messageId: string): void => {
51
- expect(
52
- screen.getByTestId(`cpk-intelligence-pill-${messageId}`).textContent,
53
- ).toContain("Using CopilotKit Intelligence");
54
- };
55
-
56
- const expectNoPillOn = (messageId: string): void => {
57
- expect(
58
- screen.queryByTestId(`cpk-intelligence-pill-${messageId}`),
59
- ).toBeNull();
60
- };
61
-
62
- const expectNoPillAnywhere = (): void => {
63
- expect(screen.queryAllByTestId(PILL_TESTID_RE).length).toBe(0);
64
- };
65
-
66
- const emitAssistantMessageWithToolCalls = (
67
- agent: MockStepwiseAgent,
68
- messageId: string,
69
- toolCalls: Array<{ id: string; name?: string; arg: string }>,
70
- ): void => {
71
- agent.emit(textMessageStartEvent(messageId));
72
- agent.emit(textMessageEndEvent(messageId));
73
- for (const tc of toolCalls) {
74
- agent.emit(
75
- toolCallChunkEvent({
76
- toolCallId: tc.id,
77
- toolCallName: tc.name ?? "bash",
78
- parentMessageId: messageId,
79
- delta: tc.arg,
80
- }),
81
- );
82
- }
83
- };
84
-
85
- const startRun = (agent: MockStepwiseAgent): void => {
86
- agent.emit(runStartedEvent());
87
- };
88
-
89
- /**
90
- * Test harness: drives `copilotkit.runAgent` from a click and force-sets
91
- * `copilotkit.intelligence` on the live core. Apps observe the
92
- * intelligence-set-up state via a real `/info` round trip; tests bypass
93
- * that plumbing by writing directly into the registry's private slot.
94
- */
95
- const RunAgentHarness: React.FC<{ withIntelligence: boolean }> = ({
96
- withIntelligence,
97
- }) => {
98
- const { copilotkit } = useCopilotKit();
99
- const { agent } = useAgent();
100
-
101
- React.useEffect(() => {
102
- const reg = (
103
- copilotkit as unknown as {
104
- agentRegistry: { _intelligence?: { wsUrl: string } };
105
- }
106
- ).agentRegistry;
107
- if (withIntelligence) {
108
- reg._intelligence = { wsUrl: "wss://test/intelligence" };
109
- } else {
110
- reg._intelligence = undefined;
111
- }
112
- }, [copilotkit, withIntelligence]);
113
-
114
- const handleClick = React.useCallback(() => {
115
- if (!agent) return;
116
- copilotkit.runAgent({ agent }).catch((err: unknown) => {
117
- console.error("[test] copilotkit.runAgent rejected:", err);
118
- throw err;
119
- });
120
- }, [copilotkit, agent]);
121
-
122
- return (
123
- <button data-testid="trigger-run" onClick={handleClick}>
124
- run
125
- </button>
126
- );
127
- };
128
-
129
- interface RenderOptions {
130
- withIntelligence?: boolean;
131
- }
132
-
133
- const renderForIndicator = (
134
- agent: MockStepwiseAgent,
135
- options: RenderOptions = {},
136
- ): void => {
137
- const { withIntelligence = true } = options;
138
-
139
- // No `renderCustomMessages` prop is passed — the indicator
140
- // auto-mounts when intelligence is configured.
141
- render(
142
- <CopilotKitProvider agents__unsafe_dev_only={{ default: agent }}>
143
- <CopilotChatConfigurationProvider agentId="default" threadId="t">
144
- <RunAgentHarness withIntelligence={withIntelligence} />
145
- <div style={{ height: 400 }}>
146
- <CopilotChat welcomeScreen={false} />
147
- </div>
148
- </CopilotChatConfigurationProvider>
149
- </CopilotKitProvider>,
150
- );
151
- };
152
-
153
- const triggerRun = async (agent: MockStepwiseAgent): Promise<void> => {
154
- await waitFor(() => expect(agent.isRunning).toBe(false));
155
- fireEvent.click(screen.getByTestId("trigger-run"));
156
- await waitFor(() => expect(agent.isRunning).toBe(true));
157
- };
158
-
159
- /** Phase machine fades over up to ~1780 ms (500 + 800 + 480). */
160
- const FADE_OUT_TIMEOUT_MS = 2500;
161
-
162
- describe('IntelligenceIndicator — "Using CopilotKit Intelligence" (auto-mounted)', () => {
163
- const activeAgents: IsRunningAccurateMockAgent[] = [];
164
- const makeAgent = (): IsRunningAccurateMockAgent => {
165
- const agent = new IsRunningAccurateMockAgent();
166
- activeAgents.push(agent);
167
- return agent;
168
- };
169
- afterEach(() => {
170
- while (activeAgents.length) {
171
- const agent = activeAgents.pop()!;
172
- try {
173
- agent.complete();
174
- } catch (err) {
175
- console.error("[test] agent.complete() threw during cleanup:", err);
176
- }
177
- }
178
- });
179
-
180
- /**
181
- * Walks through the canonical scenario:
182
- *
183
- * RUN A
184
- * m_a1 (assistant) → toolCall bash#1, bash#2
185
- * RUN B
186
- * m_b1 (assistant) → toolCall bash
187
- * m_b2 (assistant) → toolCall bash#1, bash#2
188
- *
189
- * The pill must render only on the last message of the latest
190
- * in-flight run — never on multiple messages, never on stale runs,
191
- * never on a non-last message of the current run.
192
- */
193
- it("renders only on the last message of the latest in-flight run", async () => {
194
- const agent = makeAgent();
195
- renderForIndicator(agent);
196
- await screen.findByTestId("trigger-run");
197
-
198
- expectNoPillAnywhere();
199
-
200
- // ─── Run A: m_a1 with two tool calls → pill on m_a1 ───────────────
201
- await triggerRun(agent);
202
- startRun(agent);
203
- emitAssistantMessageWithToolCalls(agent, "m_a1", [
204
- { id: "tc_a1_1", arg: '{"cmd":"ls"}' },
205
- { id: "tc_a1_2", arg: '{"cmd":"pwd"}' },
206
- ]);
207
- await waitFor(() => expectPillOn("m_a1"));
208
- expectPillCount(1);
209
-
210
- agent.emit(runFinishedEvent());
211
-
212
- // ─── Run B: m_b1 (one bash) ──────────────────────────────────────
213
- await triggerRun(agent);
214
- startRun(agent);
215
- emitAssistantMessageWithToolCalls(agent, "m_b1", [
216
- { id: "tc_b1", arg: '{"cmd":"echo b1"}' },
217
- ]);
218
- await waitFor(() => expectPillOn("m_b1"));
219
- // m_a1's pill may briefly remain in fade-out; lock the post-debounce
220
- // state.
221
- await waitFor(() => expectNoPillOn("m_a1"), {
222
- timeout: FADE_OUT_TIMEOUT_MS,
223
- });
224
- expectPillCount(1);
225
-
226
- // ─── m_b2 streams in — pill moves to m_b2, m_b1 loses pill ────────
227
- emitAssistantMessageWithToolCalls(agent, "m_b2", [
228
- { id: "tc_b2_1", arg: '{"cmd":"echo b2-1"}' },
229
- { id: "tc_b2_2", arg: '{"cmd":"echo b2-2"}' },
230
- ]);
231
- await waitFor(() => expectPillOn("m_b2"));
232
- expectNoPillOn("m_b1");
233
- expectNoPillOn("m_a1");
234
- expectPillCount(1);
235
-
236
- // ─── Run B finishes — pill fades, eventually no pill anywhere ─────
237
- agent.emit(runFinishedEvent());
238
- await waitFor(() => expectNoPillAnywhere(), {
239
- timeout: FADE_OUT_TIMEOUT_MS,
240
- });
241
- });
242
-
243
- // ─── Per-condition focused tests ────────────────────────────────────
244
-
245
- it("condition (last-in-run): never renders on a non-last message of the run", async () => {
246
- const agent = makeAgent();
247
- renderForIndicator(agent);
248
- await screen.findByTestId("trigger-run");
249
-
250
- await triggerRun(agent);
251
- startRun(agent);
252
- emitAssistantMessageWithToolCalls(agent, "m_first", [
253
- { id: "tc_first", arg: "{}" },
254
- ]);
255
- // Wait for m_first to render the pill while it is still the last
256
- // message in the run. Without this gate, both messages would land
257
- // synchronously and m_first's renderer would never have been
258
- // invoked while it was the last — turning a reactive assertion
259
- // into a first-render correctness test by accident.
260
- await waitFor(() => expectPillOn("m_first"));
261
-
262
- emitAssistantMessageWithToolCalls(agent, "m_second", [
263
- { id: "tc_second", arg: "{}" },
264
- ]);
265
-
266
- await waitFor(() => expectPillOn("m_second"));
267
- expectNoPillOn("m_first");
268
- expectPillCount(1);
269
- });
270
-
271
- it("condition (in-flight): pill clears after the run finishes", async () => {
272
- const agent = makeAgent();
273
- renderForIndicator(agent);
274
- await screen.findByTestId("trigger-run");
275
-
276
- await triggerRun(agent);
277
- startRun(agent);
278
- emitAssistantMessageWithToolCalls(agent, "m_only", [
279
- { id: "tc", arg: "{}" },
280
- ]);
281
- await waitFor(() => expectPillOn("m_only"));
282
-
283
- agent.emit(runFinishedEvent());
284
- await waitFor(() => expectNoPillOn("m_only"), {
285
- timeout: FADE_OUT_TIMEOUT_MS,
286
- });
287
- });
288
-
289
- it("condition (latest-run): never renders on a stale run after a newer run starts", async () => {
290
- const agent = makeAgent();
291
- renderForIndicator(agent);
292
- await screen.findByTestId("trigger-run");
293
-
294
- await triggerRun(agent);
295
- startRun(agent);
296
- emitAssistantMessageWithToolCalls(agent, "m_run1", [
297
- { id: "tc_run1", arg: "{}" },
298
- ]);
299
- await waitFor(() => expectPillOn("m_run1"));
300
- agent.emit(runFinishedEvent());
301
-
302
- await triggerRun(agent);
303
- startRun(agent);
304
- emitAssistantMessageWithToolCalls(agent, "m_run2", [
305
- { id: "tc_run2", arg: "{}" },
306
- ]);
307
- await waitFor(() => expectPillOn("m_run2"));
308
- expectNoPillOn("m_run1");
309
- });
310
-
311
- it("condition (tool-match): only renders when a configured tool name matches", async () => {
312
- const agent = makeAgent();
313
- renderForIndicator(agent);
314
- await screen.findByTestId("trigger-run");
315
-
316
- await triggerRun(agent);
317
- startRun(agent);
318
- // First message has only a non-matching tool call; no pill.
319
- emitAssistantMessageWithToolCalls(agent, "m_no_match", [
320
- { id: "tc_no_match", name: "fetch", arg: "{}" },
321
- ]);
322
- await new Promise((r) => setTimeout(r, 80));
323
- expectNoPillOn("m_no_match");
324
-
325
- // Second message has a bash call — pill should appear on it.
326
- emitAssistantMessageWithToolCalls(agent, "m_match", [
327
- { id: "tc_match", name: "bash", arg: "{}" },
328
- ]);
329
- await waitFor(() => expectPillOn("m_match"));
330
- expectPillCount(1);
331
- });
332
-
333
- it("intelligence gate: does not render when copilotkit.intelligence is undefined", async () => {
334
- const agent = makeAgent();
335
- renderForIndicator(agent, { withIntelligence: false });
336
- await screen.findByTestId("trigger-run");
337
-
338
- await triggerRun(agent);
339
- startRun(agent);
340
- emitAssistantMessageWithToolCalls(agent, "m1", [{ id: "tc1", arg: "{}" }]);
341
-
342
- // Without the gate, the pill would be visible by now.
343
- await new Promise((r) => setTimeout(r, 80));
344
- expectNoPillAnywhere();
345
- });
346
-
347
- it("auto-registration: no renderCustomMessages prop is required", async () => {
348
- // This is the explicit assertion that the indicator auto-mounts.
349
- // `renderForIndicator` does not pass `renderCustomMessages`, yet
350
- // the pill renders solely because intelligence is configured.
351
- const agent = makeAgent();
352
- renderForIndicator(agent);
353
- await screen.findByTestId("trigger-run");
354
-
355
- await triggerRun(agent);
356
- startRun(agent);
357
- emitAssistantMessageWithToolCalls(agent, "m1", [{ id: "tc1", arg: "{}" }]);
358
-
359
- await waitFor(() => expectPillOn("m1"));
360
- expectPillCount(1);
361
- });
362
- });
@@ -1,2 +0,0 @@
1
- export { IntelligenceIndicator } from "./IntelligenceIndicator";
2
- export type { IntelligenceIndicatorProps } from "./IntelligenceIndicator";