@copilotkit/vue 1.75.2 → 1.76.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.
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +272 -157
- package/dist/index.mjs.map +1 -1
- package/dist/use-render-activity-message-BTKmd3f3.cjs +110 -0
- package/dist/use-render-activity-message-BTKmd3f3.cjs.map +1 -0
- package/dist/use-render-activity-message-Eu6R2vGT.js +12801 -0
- package/dist/use-render-activity-message-Eu6R2vGT.js.map +1 -0
- package/dist/v2/components/chat/CopilotChat.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts +8 -152
- package/dist/v2/components/chat/CopilotChatAssistantMessage.vue.d.ts.map +1 -1
- package/dist/v2/components/chat/copilotChatToolCallItemRender.d.ts.map +1 -1
- package/dist/v2/hooks/use-agent.d.ts.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.d.cts +2 -0
- package/dist/v2/index.d.mts +2 -0
- package/dist/v2/index.d.ts +2 -0
- package/dist/v2/index.d.ts.map +1 -1
- package/dist/v2/index.mjs +187 -72
- package/dist/v2/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/v2/__tests__/utils/test-helpers.ts +26 -6
- package/src/v2/components/chat/CopilotChat.vue +100 -20
- package/src/v2/components/chat/__tests__/CopilotChat.clearOnFresh.test.ts +130 -2
- package/src/v2/components/chat/__tests__/CopilotChat.e2e.test.ts +6 -1
- package/src/v2/components/chat/__tests__/CopilotChatToolRendering.e2e.test.ts +22 -40
- package/src/v2/components/chat/__tests__/CopilotChatToolRerenders.e2e.test.ts +12 -24
- package/src/v2/components/chat/copilotChatToolCallItemRender.ts +3 -2
- package/src/v2/hooks/__tests__/use-agent-headers.test.ts +83 -0
- package/src/v2/hooks/__tests__/use-agent-stability.test.ts +2 -0
- package/src/v2/hooks/__tests__/use-agent.e2e.test.ts +5 -3
- package/src/v2/hooks/__tests__/use-frontend-tool.e2e.test.ts +2 -2
- package/src/v2/hooks/use-agent.ts +3 -3
- package/src/v2/index.ts +5 -0
- package/src/v2/providers/__tests__/CopilotKitProvider.renderCustomMessages.e2e.test.ts +6 -4
- package/dist/use-render-activity-message-CGdS03Xj.cjs +0 -85
- package/dist/use-render-activity-message-CGdS03Xj.cjs.map +0 -1
- package/dist/use-render-activity-message-XmuT9fKy.js +0 -9799
- package/dist/use-render-activity-message-XmuT9fKy.js.map +0 -1
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
AGUIConnectNotImplementedError,
|
|
4
|
-
AbstractAgent,
|
|
5
|
-
HttpAgent,
|
|
6
|
-
} from "@ag-ui/client";
|
|
2
|
+
import { AGUIConnectNotImplementedError, AbstractAgent } from "@ag-ui/client";
|
|
7
3
|
import {
|
|
8
4
|
createAttachmentContent,
|
|
9
5
|
DEFAULT_AGENT_ID,
|
|
@@ -21,7 +17,7 @@ import {
|
|
|
21
17
|
useSlots,
|
|
22
18
|
watch,
|
|
23
19
|
} from "vue";
|
|
24
|
-
import { CopilotKitCoreErrorCode } from "@copilotkit/core";
|
|
20
|
+
import { CopilotKitCoreErrorCode, ɵisHttpAgent } from "@copilotkit/core";
|
|
25
21
|
import type { Suggestion } from "@copilotkit/core";
|
|
26
22
|
import CopilotChatConfigurationProvider from "../../providers/CopilotChatConfigurationProvider.vue";
|
|
27
23
|
import { useCopilotChatConfiguration } from "../../providers/useCopilotChatConfiguration";
|
|
@@ -111,9 +107,15 @@ type ActiveConnectCycle = {
|
|
|
111
107
|
inspectorRequestId: string | null;
|
|
112
108
|
abortController: AbortController;
|
|
113
109
|
detached: boolean;
|
|
110
|
+
clearDiscardedBaseline?: () => void;
|
|
114
111
|
};
|
|
115
112
|
|
|
116
113
|
const activeConnectCycle = shallowRef<ActiveConnectCycle | null>(null);
|
|
114
|
+
let lastConnectCycle: ActiveConnectCycle | null = null;
|
|
115
|
+
const detachPromises = new WeakMap<AbstractAgent, Promise<void>>();
|
|
116
|
+
// Agent clones can share cursors. Finish every old reset before connecting again.
|
|
117
|
+
let pendingTeardown = Promise.resolve();
|
|
118
|
+
const baselineThreadIds = new WeakMap<AbstractAgent, string>();
|
|
117
119
|
|
|
118
120
|
const resolvedAgentId = computed(
|
|
119
121
|
() => props.agentId ?? existingConfig.value?.agentId ?? DEFAULT_AGENT_ID,
|
|
@@ -379,6 +381,7 @@ watch(
|
|
|
379
381
|
// React does — makes the ordering unconditional instead of depending on
|
|
380
382
|
// watcher scheduling. Non-explicit threads skip /connect below, but the first
|
|
381
383
|
// runAgent still has to ship the thread the UI is rendering.
|
|
384
|
+
baselineThreadIds.set(currentAgent, currentAgent.threadId);
|
|
382
385
|
currentAgent.threadId = threadId;
|
|
383
386
|
|
|
384
387
|
// When the caller hasn't picked a specific thread, resolvedThreadId is
|
|
@@ -421,10 +424,6 @@ watch(
|
|
|
421
424
|
cycle = existingCycle;
|
|
422
425
|
} else {
|
|
423
426
|
const connectAbortController = new AbortController();
|
|
424
|
-
if (currentAgent instanceof HttpAgent) {
|
|
425
|
-
currentAgent.abortController = connectAbortController;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
427
|
cycle = {
|
|
429
428
|
core: core as object,
|
|
430
429
|
agent: currentAgent,
|
|
@@ -434,11 +433,18 @@ watch(
|
|
|
434
433
|
detached: false,
|
|
435
434
|
};
|
|
436
435
|
activeConnectCycle.value = cycle;
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
436
|
+
lastConnectCycle = cycle;
|
|
437
|
+
|
|
438
|
+
void pendingTeardown
|
|
439
|
+
.then(() => {
|
|
440
|
+
if (cycle.detached) return;
|
|
441
|
+
if (ɵisHttpAgent(currentAgent))
|
|
442
|
+
currentAgent.abortController = connectAbortController;
|
|
443
|
+
return core.connectAgent({ agent: currentAgent });
|
|
444
|
+
})
|
|
440
445
|
.catch((error: unknown) => {
|
|
441
446
|
if (cycle.detached) {
|
|
447
|
+
cycle.clearDiscardedBaseline?.();
|
|
442
448
|
return;
|
|
443
449
|
}
|
|
444
450
|
if (error instanceof AGUIConnectNotImplementedError) {
|
|
@@ -460,6 +466,7 @@ watch(
|
|
|
460
466
|
// can briefly render against an incompletely-laid-out message
|
|
461
467
|
// tree and visibly snap once the last text chunk lands.
|
|
462
468
|
if (cycle.detached) {
|
|
469
|
+
cycle.clearDiscardedBaseline?.();
|
|
463
470
|
return;
|
|
464
471
|
}
|
|
465
472
|
const raf =
|
|
@@ -490,7 +497,17 @@ watch(
|
|
|
490
497
|
|
|
491
498
|
activeCycle.detached = true;
|
|
492
499
|
activeCycle.abortController.abort();
|
|
493
|
-
|
|
500
|
+
const detach = activeCycle.agent
|
|
501
|
+
.detachActiveRun()
|
|
502
|
+
.catch((error: unknown) => {
|
|
503
|
+
console.error("CopilotChat: detachActiveRun failed", error);
|
|
504
|
+
});
|
|
505
|
+
detachPromises.set(activeCycle.agent, detach);
|
|
506
|
+
pendingTeardown = Promise.all([pendingTeardown, detach]).then(() => {});
|
|
507
|
+
void detach.then(() => {
|
|
508
|
+
if (detachPromises.get(activeCycle.agent) === detach)
|
|
509
|
+
detachPromises.delete(activeCycle.agent);
|
|
510
|
+
});
|
|
494
511
|
activeConnectCycle.value = null;
|
|
495
512
|
});
|
|
496
513
|
},
|
|
@@ -502,17 +519,80 @@ watch(
|
|
|
502
519
|
// replay their history via the /connect cycle above, and the very first
|
|
503
520
|
// resolution (mount) or an agent-store swap that keeps the same thread id
|
|
504
521
|
// must never clear — only a real fresh-thread transition does.
|
|
505
|
-
|
|
522
|
+
let lastFreshSelection:
|
|
523
|
+
| { threadId: string; agent: AbstractAgent | null }
|
|
524
|
+
| undefined;
|
|
506
525
|
watch(
|
|
507
526
|
[resolvedThreadId, hasExplicitThreadId, () => agent.value],
|
|
508
|
-
([threadId, isExplicit, currentAgent]) => {
|
|
509
|
-
const previous =
|
|
510
|
-
|
|
527
|
+
([threadId, isExplicit, currentAgent], _old, onCleanup) => {
|
|
528
|
+
const previous = lastFreshSelection;
|
|
529
|
+
const selection = { threadId, agent: currentAgent };
|
|
530
|
+
lastFreshSelection = selection;
|
|
511
531
|
if (!currentAgent) return;
|
|
512
532
|
if (isExplicit) return;
|
|
513
533
|
if (previous === undefined) return;
|
|
514
|
-
if (threadId === previous) return;
|
|
515
|
-
|
|
534
|
+
if (threadId === previous.threadId) return;
|
|
535
|
+
let active = true;
|
|
536
|
+
let resetPending = true;
|
|
537
|
+
onCleanup(() => {
|
|
538
|
+
active = false;
|
|
539
|
+
});
|
|
540
|
+
const discardedThreadId =
|
|
541
|
+
previous.agent === currentAgent
|
|
542
|
+
? previous.threadId
|
|
543
|
+
: baselineThreadIds.get(currentAgent);
|
|
544
|
+
const clearCursor = () => {
|
|
545
|
+
if (!discardedThreadId) return;
|
|
546
|
+
if (
|
|
547
|
+
"clearReplayCursor" in currentAgent &&
|
|
548
|
+
typeof currentAgent.clearReplayCursor === "function"
|
|
549
|
+
)
|
|
550
|
+
currentAgent.clearReplayCursor(discardedThreadId);
|
|
551
|
+
if (
|
|
552
|
+
"clearReconnectCursor" in currentAgent &&
|
|
553
|
+
typeof currentAgent.clearReconnectCursor === "function"
|
|
554
|
+
)
|
|
555
|
+
currentAgent.clearReconnectCursor(discardedThreadId);
|
|
556
|
+
};
|
|
557
|
+
const clearDiscardedBaseline = () => {
|
|
558
|
+
if (
|
|
559
|
+
!active ||
|
|
560
|
+
!resetPending ||
|
|
561
|
+
isUnmounting.value ||
|
|
562
|
+
lastFreshSelection !== selection ||
|
|
563
|
+
agent.value !== currentAgent
|
|
564
|
+
)
|
|
565
|
+
return;
|
|
566
|
+
currentAgent.setMessages([]);
|
|
567
|
+
currentAgent.setState({});
|
|
568
|
+
currentAgent.pendingInterrupts = [];
|
|
569
|
+
clearCursor();
|
|
570
|
+
};
|
|
571
|
+
if (
|
|
572
|
+
lastConnectCycle?.agent === currentAgent &&
|
|
573
|
+
lastConnectCycle.threadId === discardedThreadId
|
|
574
|
+
)
|
|
575
|
+
lastConnectCycle.clearDiscardedBaseline = clearDiscardedBaseline;
|
|
576
|
+
const detach =
|
|
577
|
+
detachPromises.get(currentAgent) ?? currentAgent.detachActiveRun();
|
|
578
|
+
detachPromises.set(currentAgent, detach);
|
|
579
|
+
const finishReset = () => {
|
|
580
|
+
if (!resetPending) return;
|
|
581
|
+
// The cursor belongs to the discarded view, even after a fast reopen.
|
|
582
|
+
clearCursor();
|
|
583
|
+
clearDiscardedBaseline();
|
|
584
|
+
resetPending = false;
|
|
585
|
+
};
|
|
586
|
+
clearDiscardedBaseline();
|
|
587
|
+
pendingTeardown = Promise.all([pendingTeardown, detach])
|
|
588
|
+
.then(finishReset)
|
|
589
|
+
.catch((error: unknown) => {
|
|
590
|
+
console.error("CopilotChat: detachActiveRun failed", error);
|
|
591
|
+
})
|
|
592
|
+
.finally(() => {
|
|
593
|
+
if (detachPromises.get(currentAgent) === detach)
|
|
594
|
+
detachPromises.delete(currentAgent);
|
|
595
|
+
});
|
|
516
596
|
},
|
|
517
597
|
{ immediate: true },
|
|
518
598
|
);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { defineComponent, h, nextTick } from "vue";
|
|
2
|
+
import { defineComponent, h, nextTick, ref } from "vue";
|
|
3
3
|
import { flushPromises, mount } from "@vue/test-utils";
|
|
4
4
|
import CopilotKitProvider from "../../../providers/CopilotKitProvider.vue";
|
|
5
5
|
import CopilotChatConfigurationProvider from "../../../providers/CopilotChatConfigurationProvider.vue";
|
|
@@ -14,6 +14,134 @@ import CopilotChat from "../CopilotChat.vue";
|
|
|
14
14
|
// configuration transitions to a fresh, non-explicit thread via
|
|
15
15
|
// startNewThread()
|
|
16
16
|
describe("CopilotChat clear-on-fresh", () => {
|
|
17
|
+
it.each(["clearReplayCursor", "clearReconnectCursor"] as const)(
|
|
18
|
+
"clears state and the captured %s cursor on a fresh selection",
|
|
19
|
+
async (method) => {
|
|
20
|
+
const agent = new StateCapturingAgent();
|
|
21
|
+
const cursors = new Map<string, string>();
|
|
22
|
+
Object.defineProperty(agent, method, {
|
|
23
|
+
value: (threadId: string) => cursors.delete(threadId),
|
|
24
|
+
});
|
|
25
|
+
const threadId = ref("saved");
|
|
26
|
+
const explicit = ref(true);
|
|
27
|
+
const wrapper = mount(CopilotKitProvider, {
|
|
28
|
+
props: { agents__unsafe_dev_only: { default: agent } },
|
|
29
|
+
slots: {
|
|
30
|
+
default: () =>
|
|
31
|
+
h(
|
|
32
|
+
CopilotChatConfigurationProvider,
|
|
33
|
+
{ threadId: threadId.value, hasExplicitThreadId: explicit.value },
|
|
34
|
+
{ default: () => h(CopilotChat, { welcomeScreen: false }) },
|
|
35
|
+
),
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
await flushPromises();
|
|
39
|
+
agent.setState({ saved: true });
|
|
40
|
+
agent.pendingInterrupts = [{ id: "approval-A", reason: "confirmation" }];
|
|
41
|
+
cursors.set("saved", "last-event");
|
|
42
|
+
cursors.set("other", "keep-other");
|
|
43
|
+
threadId.value = "fresh";
|
|
44
|
+
explicit.value = false;
|
|
45
|
+
await flushPromises();
|
|
46
|
+
expect(agent.state).toEqual({});
|
|
47
|
+
expect(agent.pendingInterrupts).toEqual([]);
|
|
48
|
+
expect(cursors.get("saved")).toBeUndefined();
|
|
49
|
+
expect(cursors.get("other")).toBe("keep-other");
|
|
50
|
+
wrapper.unmount();
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
it.each(["fresh", "saved", "other", "via-fresh", "swap"])(
|
|
54
|
+
"protects %s from an abandoned connect that completes later",
|
|
55
|
+
async (destination) => {
|
|
56
|
+
let releaseDetach = () => {};
|
|
57
|
+
let releaseConnect = () => {};
|
|
58
|
+
let pendingDetach: Promise<void> | undefined;
|
|
59
|
+
const oldConnect = new Promise<void>((resolve) => {
|
|
60
|
+
releaseConnect = resolve;
|
|
61
|
+
});
|
|
62
|
+
const cursors = new Map<string, string>();
|
|
63
|
+
const requests: (string | null)[] = [];
|
|
64
|
+
class ReplayAgent extends StateCapturingAgent {
|
|
65
|
+
clearReplayCursor(threadId: string) {
|
|
66
|
+
cursors.delete(threadId);
|
|
67
|
+
}
|
|
68
|
+
async detachActiveRun() {
|
|
69
|
+
await pendingDetach;
|
|
70
|
+
await super.detachActiveRun();
|
|
71
|
+
}
|
|
72
|
+
async connectAgent(
|
|
73
|
+
...args: Parameters<StateCapturingAgent["connectAgent"]>
|
|
74
|
+
) {
|
|
75
|
+
requests.push(cursors.get(this.threadId) ?? null);
|
|
76
|
+
const first = requests.length === 1;
|
|
77
|
+
const result = await super.connectAgent(...args);
|
|
78
|
+
if (first) await oldConnect;
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const agent = new ReplayAgent();
|
|
83
|
+
let currentAgent = agent;
|
|
84
|
+
const threadId = ref("saved");
|
|
85
|
+
const explicit = ref(true);
|
|
86
|
+
const wrapper = mount(CopilotKitProvider, {
|
|
87
|
+
props: { agents__unsafe_dev_only: { default: agent } },
|
|
88
|
+
slots: {
|
|
89
|
+
default: () =>
|
|
90
|
+
h(
|
|
91
|
+
CopilotChatConfigurationProvider,
|
|
92
|
+
{ threadId: threadId.value, hasExplicitThreadId: explicit.value },
|
|
93
|
+
{ default: () => h(CopilotChat, { welcomeScreen: false }) },
|
|
94
|
+
),
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
await flushPromises();
|
|
98
|
+
expect(requests).toEqual([null]);
|
|
99
|
+
pendingDetach = new Promise<void>((resolve) => {
|
|
100
|
+
releaseDetach = resolve;
|
|
101
|
+
});
|
|
102
|
+
cursors.set("saved", "old-event");
|
|
103
|
+
threadId.value = "fresh";
|
|
104
|
+
explicit.value = false;
|
|
105
|
+
await nextTick();
|
|
106
|
+
if (destination === "via-fresh") {
|
|
107
|
+
threadId.value = "fresh-again";
|
|
108
|
+
await nextTick();
|
|
109
|
+
}
|
|
110
|
+
if (destination === "swap") {
|
|
111
|
+
currentAgent = new ReplayAgent();
|
|
112
|
+
await wrapper.setProps({
|
|
113
|
+
agents__unsafe_dev_only: { default: currentAgent },
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const target =
|
|
117
|
+
destination === "via-fresh" || destination === "swap"
|
|
118
|
+
? "saved"
|
|
119
|
+
: destination;
|
|
120
|
+
if (target !== "fresh") {
|
|
121
|
+
threadId.value = target;
|
|
122
|
+
explicit.value = true;
|
|
123
|
+
await nextTick();
|
|
124
|
+
}
|
|
125
|
+
expect(requests).toEqual([null]);
|
|
126
|
+
cursors.set("saved", "late-event");
|
|
127
|
+
releaseDetach();
|
|
128
|
+
await flushPromises();
|
|
129
|
+
expect(requests).toEqual(target === "fresh" ? [null] : [null, null]);
|
|
130
|
+
currentAgent.setState({ current: true });
|
|
131
|
+
currentAgent.pendingInterrupts = [
|
|
132
|
+
{ id: "approval-new", reason: "confirmation" },
|
|
133
|
+
];
|
|
134
|
+
cursors.set(target, "new-event");
|
|
135
|
+
releaseConnect();
|
|
136
|
+
await flushPromises();
|
|
137
|
+
expect(currentAgent.state).toEqual({ current: true });
|
|
138
|
+
expect(currentAgent.pendingInterrupts).toEqual([
|
|
139
|
+
{ id: "approval-new", reason: "confirmation" },
|
|
140
|
+
]);
|
|
141
|
+
expect(cursors.get(target)).toBe("new-event");
|
|
142
|
+
wrapper.unmount();
|
|
143
|
+
},
|
|
144
|
+
);
|
|
17
145
|
it("does not clear messages on initial mount", async () => {
|
|
18
146
|
const agent = new StateCapturingAgent();
|
|
19
147
|
// Spy before mount: attaching afterwards can never observe a mount-time
|
|
@@ -133,7 +261,7 @@ describe("CopilotChat clear-on-fresh", () => {
|
|
|
133
261
|
await nextTick();
|
|
134
262
|
expect(currentThreadId).toBe("elsewhere");
|
|
135
263
|
|
|
136
|
-
newAgent!.setMessages([{ id: "m1", role: "user", content: "hi" }
|
|
264
|
+
newAgent!.setMessages([{ id: "m1", role: "user", content: "hi" }]);
|
|
137
265
|
expect(newAgent!.messages.length).toBe(1);
|
|
138
266
|
|
|
139
267
|
// Switch back non-explicitly. Any `setMessages([])` observed here must come
|
|
@@ -3,6 +3,7 @@ import { computed, defineComponent, onMounted } from "vue";
|
|
|
3
3
|
import type { PropType } from "vue";
|
|
4
4
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
5
|
import { EventType } from "@ag-ui/client";
|
|
6
|
+
import type { RunErrorEvent } from "@ag-ui/client";
|
|
6
7
|
import { z } from "zod";
|
|
7
8
|
import { useConfigureSuggestions } from "../../../hooks/use-configure-suggestions";
|
|
8
9
|
import {
|
|
@@ -189,7 +190,11 @@ describe("CopilotChat E2E - Chat Basics and Streaming Patterns", () => {
|
|
|
189
190
|
);
|
|
190
191
|
});
|
|
191
192
|
|
|
192
|
-
|
|
193
|
+
const errorEvent: RunErrorEvent = {
|
|
194
|
+
type: EventType.RUN_ERROR,
|
|
195
|
+
message: "Test run failed",
|
|
196
|
+
};
|
|
197
|
+
await agent.emit(errorEvent);
|
|
193
198
|
await agent.complete();
|
|
194
199
|
|
|
195
200
|
await waitFor(() => {
|
|
@@ -21,6 +21,10 @@ import CopilotChatToolCallsView from "../CopilotChatToolCallsView.vue";
|
|
|
21
21
|
import { useFrontendTool } from "../../../hooks/use-frontend-tool";
|
|
22
22
|
import type { VueFrontendTool } from "../../../types";
|
|
23
23
|
import type { VueToolCallRendererRenderProps } from "../../../types/vue-tool-call-renderer";
|
|
24
|
+
import {
|
|
25
|
+
runStartedEvent,
|
|
26
|
+
runFinishedEvent,
|
|
27
|
+
} from "../../../__tests__/utils/test-helpers";
|
|
24
28
|
|
|
25
29
|
afterEach(() => {
|
|
26
30
|
cleanup();
|
|
@@ -43,7 +47,7 @@ class MockStreamingAgent extends AbstractAgent {
|
|
|
43
47
|
const messageId = `m_${Date.now()}`;
|
|
44
48
|
const toolCallId = `tc_${Date.now()}`;
|
|
45
49
|
|
|
46
|
-
observer.next(
|
|
50
|
+
observer.next(runStartedEvent(_input));
|
|
47
51
|
observer.next({
|
|
48
52
|
type: EventType.TEXT_MESSAGE_CHUNK,
|
|
49
53
|
messageId,
|
|
@@ -68,7 +72,7 @@ class MockStreamingAgent extends AbstractAgent {
|
|
|
68
72
|
messageId: `${messageId}_result`,
|
|
69
73
|
content: JSON.stringify({ temperature: 21, unit: "celsius" }),
|
|
70
74
|
} as BaseEvent);
|
|
71
|
-
observer.next(
|
|
75
|
+
observer.next(runFinishedEvent(_input));
|
|
72
76
|
observer.complete();
|
|
73
77
|
});
|
|
74
78
|
}
|
|
@@ -492,9 +496,7 @@ describe("Streaming in-progress without timers", () => {
|
|
|
492
496
|
const messageId = "m_step";
|
|
493
497
|
const toolCallId = "tc_step";
|
|
494
498
|
|
|
495
|
-
await agent.emit(
|
|
496
|
-
type: EventType.RUN_STARTED,
|
|
497
|
-
} as BaseEvent);
|
|
499
|
+
await agent.emit(runStartedEvent());
|
|
498
500
|
await agent.emit({
|
|
499
501
|
type: EventType.TEXT_MESSAGE_CHUNK,
|
|
500
502
|
messageId,
|
|
@@ -543,9 +545,7 @@ describe("Streaming in-progress without timers", () => {
|
|
|
543
545
|
expect(el.textContent).toContain("21");
|
|
544
546
|
});
|
|
545
547
|
|
|
546
|
-
await agent.emit(
|
|
547
|
-
type: EventType.RUN_FINISHED,
|
|
548
|
-
} as BaseEvent);
|
|
548
|
+
await agent.emit(runFinishedEvent());
|
|
549
549
|
await agent.complete();
|
|
550
550
|
});
|
|
551
551
|
});
|
|
@@ -586,9 +586,7 @@ describe("Executing State Transitions", () => {
|
|
|
586
586
|
const messageId = "m_exec";
|
|
587
587
|
const toolCallId = "tc_exec";
|
|
588
588
|
|
|
589
|
-
await agent.emit(
|
|
590
|
-
type: EventType.RUN_STARTED,
|
|
591
|
-
} as BaseEvent);
|
|
589
|
+
await agent.emit(runStartedEvent());
|
|
592
590
|
await agent.emit({
|
|
593
591
|
type: EventType.TOOL_CALL_CHUNK,
|
|
594
592
|
toolCallId,
|
|
@@ -603,9 +601,7 @@ describe("Executing State Transitions", () => {
|
|
|
603
601
|
expect(status.textContent).toMatch(/Value: test/);
|
|
604
602
|
});
|
|
605
603
|
|
|
606
|
-
await agent.emit(
|
|
607
|
-
type: EventType.RUN_FINISHED,
|
|
608
|
-
} as BaseEvent);
|
|
604
|
+
await agent.emit(runFinishedEvent());
|
|
609
605
|
await agent.complete();
|
|
610
606
|
|
|
611
607
|
await waitFor(() => {
|
|
@@ -653,9 +649,7 @@ describe("Multiple Tool Calls in Same Message", () => {
|
|
|
653
649
|
const toolCallId2 = "tc_2";
|
|
654
650
|
const toolCallId3 = "tc_3";
|
|
655
651
|
|
|
656
|
-
await agent.emit(
|
|
657
|
-
type: EventType.RUN_STARTED,
|
|
658
|
-
} as BaseEvent);
|
|
652
|
+
await agent.emit(runStartedEvent());
|
|
659
653
|
await agent.emit({
|
|
660
654
|
type: EventType.TOOL_CALL_CHUNK,
|
|
661
655
|
toolCallId: toolCallId1,
|
|
@@ -714,9 +708,7 @@ describe("Multiple Tool Calls in Same Message", () => {
|
|
|
714
708
|
expect(screen.getByTestId("tool1-third").textContent).toContain("C");
|
|
715
709
|
});
|
|
716
710
|
|
|
717
|
-
await agent.emit(
|
|
718
|
-
type: EventType.RUN_FINISHED,
|
|
719
|
-
} as BaseEvent);
|
|
711
|
+
await agent.emit(runFinishedEvent());
|
|
720
712
|
await agent.complete();
|
|
721
713
|
});
|
|
722
714
|
});
|
|
@@ -747,9 +739,7 @@ describe("Partial Args Accumulation", () => {
|
|
|
747
739
|
const messageId = "m_partial";
|
|
748
740
|
const toolCallId = "tc_partial";
|
|
749
741
|
|
|
750
|
-
await agent.emit(
|
|
751
|
-
type: EventType.RUN_STARTED,
|
|
752
|
-
} as BaseEvent);
|
|
742
|
+
await agent.emit(runStartedEvent());
|
|
753
743
|
await agent.emit({
|
|
754
744
|
type: EventType.TOOL_CALL_CHUNK,
|
|
755
745
|
toolCallId,
|
|
@@ -801,9 +791,7 @@ describe("Partial Args Accumulation", () => {
|
|
|
801
791
|
expect(tool.textContent).toMatch(/Status: (complete|inProgress)/i);
|
|
802
792
|
});
|
|
803
793
|
|
|
804
|
-
await agent.emit(
|
|
805
|
-
type: EventType.RUN_FINISHED,
|
|
806
|
-
} as BaseEvent);
|
|
794
|
+
await agent.emit(runFinishedEvent());
|
|
807
795
|
await agent.complete();
|
|
808
796
|
});
|
|
809
797
|
});
|
|
@@ -885,7 +873,7 @@ describe("toolCallId parity for registered renderers", () => {
|
|
|
885
873
|
const messageId = "m_id";
|
|
886
874
|
const toolCallId = "tc_id_parity";
|
|
887
875
|
|
|
888
|
-
await agent.emit(
|
|
876
|
+
await agent.emit(runStartedEvent());
|
|
889
877
|
await agent.emit({
|
|
890
878
|
type: EventType.TOOL_CALL_CHUNK,
|
|
891
879
|
toolCallId,
|
|
@@ -900,7 +888,7 @@ describe("toolCallId parity for registered renderers", () => {
|
|
|
900
888
|
expect(el.textContent).toContain(`id:${toolCallId}`);
|
|
901
889
|
});
|
|
902
890
|
|
|
903
|
-
await agent.emit(
|
|
891
|
+
await agent.emit(runFinishedEvent());
|
|
904
892
|
await agent.complete();
|
|
905
893
|
|
|
906
894
|
await waitFor(() => {
|
|
@@ -948,6 +936,8 @@ describe("toolCallId parity for registered renderers", () => {
|
|
|
948
936
|
describe("Status Persistence After Agent Stops", () => {
|
|
949
937
|
it("should remain in InProgress status after agent stops if no result", async () => {
|
|
950
938
|
const agent = new MockStepwiseAgent();
|
|
939
|
+
const firstRun = { threadId: agent.threadId, runId: "first-run" };
|
|
940
|
+
const secondRun = { threadId: agent.threadId, runId: "second-run" };
|
|
951
941
|
renderChatHarness({
|
|
952
942
|
agent,
|
|
953
943
|
frontendTools: [
|
|
@@ -967,9 +957,7 @@ describe("Status Persistence After Agent Stops", () => {
|
|
|
967
957
|
const messageId = "msg_status";
|
|
968
958
|
const toolCallId = "tc_status";
|
|
969
959
|
|
|
970
|
-
await agent.emit(
|
|
971
|
-
type: EventType.RUN_STARTED,
|
|
972
|
-
} as BaseEvent);
|
|
960
|
+
await agent.emit(runStartedEvent(firstRun));
|
|
973
961
|
await agent.emit({
|
|
974
962
|
type: EventType.TOOL_CALL_CHUNK,
|
|
975
963
|
toolCallId,
|
|
@@ -983,9 +971,7 @@ describe("Status Persistence After Agent Stops", () => {
|
|
|
983
971
|
expect(statusElement.textContent).toBe("inProgress");
|
|
984
972
|
});
|
|
985
973
|
|
|
986
|
-
await agent.emit(
|
|
987
|
-
type: EventType.RUN_FINISHED,
|
|
988
|
-
} as BaseEvent);
|
|
974
|
+
await agent.emit(runFinishedEvent(firstRun));
|
|
989
975
|
|
|
990
976
|
await waitFor(() => {
|
|
991
977
|
const statusElement = screen.getByTestId("status");
|
|
@@ -996,9 +982,7 @@ describe("Status Persistence After Agent Stops", () => {
|
|
|
996
982
|
expect(statusElement.textContent).toBe("inProgress");
|
|
997
983
|
expect(statusElement.textContent).not.toBe("complete");
|
|
998
984
|
|
|
999
|
-
await agent.emit(
|
|
1000
|
-
type: EventType.RUN_STARTED,
|
|
1001
|
-
} as BaseEvent);
|
|
985
|
+
await agent.emit(runStartedEvent(secondRun));
|
|
1002
986
|
await agent.emit({
|
|
1003
987
|
type: EventType.TOOL_CALL_RESULT,
|
|
1004
988
|
toolCallId,
|
|
@@ -1011,9 +995,7 @@ describe("Status Persistence After Agent Stops", () => {
|
|
|
1011
995
|
expect(statusEl.textContent).toBe("complete");
|
|
1012
996
|
});
|
|
1013
997
|
|
|
1014
|
-
await agent.emit(
|
|
1015
|
-
type: EventType.RUN_FINISHED,
|
|
1016
|
-
} as BaseEvent);
|
|
998
|
+
await agent.emit(runFinishedEvent(secondRun));
|
|
1017
999
|
await agent.complete();
|
|
1018
1000
|
});
|
|
1019
1001
|
});
|
|
@@ -17,6 +17,10 @@ import CopilotKitProvider from "../../../providers/CopilotKitProvider.vue";
|
|
|
17
17
|
import CopilotChatConfigurationProvider from "../../../providers/CopilotChatConfigurationProvider.vue";
|
|
18
18
|
import CopilotChat from "../CopilotChat.vue";
|
|
19
19
|
import type { VueFrontendTool } from "../../../types";
|
|
20
|
+
import {
|
|
21
|
+
runStartedEvent,
|
|
22
|
+
runFinishedEvent,
|
|
23
|
+
} from "../../../__tests__/utils/test-helpers";
|
|
20
24
|
|
|
21
25
|
afterEach(() => {
|
|
22
26
|
cleanup();
|
|
@@ -183,9 +187,7 @@ describe("Tool Call Re-render Prevention", () => {
|
|
|
183
187
|
const messageId = "m_rerender_test";
|
|
184
188
|
const toolCallId = "tc_rerender_test";
|
|
185
189
|
|
|
186
|
-
await agent.emit(
|
|
187
|
-
type: EventType.RUN_STARTED,
|
|
188
|
-
} as BaseEvent);
|
|
190
|
+
await agent.emit(runStartedEvent());
|
|
189
191
|
await agent.emit({
|
|
190
192
|
type: EventType.TOOL_CALL_CHUNK,
|
|
191
193
|
toolCallId,
|
|
@@ -252,9 +254,7 @@ describe("Tool Call Re-render Prevention", () => {
|
|
|
252
254
|
expect(screen.getByTestId("location").textContent).toBe("Paris");
|
|
253
255
|
expect(screen.getByTestId("result").textContent).toContain("temperature");
|
|
254
256
|
|
|
255
|
-
await agent.emit(
|
|
256
|
-
type: EventType.RUN_FINISHED,
|
|
257
|
-
} as BaseEvent);
|
|
257
|
+
await agent.emit(runFinishedEvent());
|
|
258
258
|
await agent.complete();
|
|
259
259
|
});
|
|
260
260
|
|
|
@@ -302,9 +302,7 @@ describe("Tool Call Re-render Prevention", () => {
|
|
|
302
302
|
const messageId = "m_search";
|
|
303
303
|
const toolCallId = "tc_search";
|
|
304
304
|
|
|
305
|
-
await agent.emit(
|
|
306
|
-
type: EventType.RUN_STARTED,
|
|
307
|
-
} as BaseEvent);
|
|
305
|
+
await agent.emit(runStartedEvent());
|
|
308
306
|
await agent.emit({
|
|
309
307
|
type: EventType.TOOL_CALL_CHUNK,
|
|
310
308
|
toolCallId,
|
|
@@ -334,9 +332,7 @@ describe("Tool Call Re-render Prevention", () => {
|
|
|
334
332
|
const renderCountAfterText = toolRenderCount;
|
|
335
333
|
expect(renderCountAfterText).toBe(renderCountAfterToolCall);
|
|
336
334
|
|
|
337
|
-
await agent.emit(
|
|
338
|
-
type: EventType.RUN_FINISHED,
|
|
339
|
-
} as BaseEvent);
|
|
335
|
+
await agent.emit(runFinishedEvent());
|
|
340
336
|
await agent.complete();
|
|
341
337
|
});
|
|
342
338
|
|
|
@@ -384,9 +380,7 @@ describe("Tool Call Re-render Prevention", () => {
|
|
|
384
380
|
const messageId = "m_search_update";
|
|
385
381
|
const toolCallId = "tc_search_update";
|
|
386
382
|
|
|
387
|
-
await agent.emit(
|
|
388
|
-
type: EventType.RUN_STARTED,
|
|
389
|
-
} as BaseEvent);
|
|
383
|
+
await agent.emit(runStartedEvent());
|
|
390
384
|
await agent.emit({
|
|
391
385
|
type: EventType.TOOL_CALL_CHUNK,
|
|
392
386
|
toolCallId,
|
|
@@ -422,9 +416,7 @@ describe("Tool Call Re-render Prevention", () => {
|
|
|
422
416
|
expect(capturedArgs).toContain("Rea");
|
|
423
417
|
expect(capturedArgs).toContain("React hooks");
|
|
424
418
|
|
|
425
|
-
await agent.emit(
|
|
426
|
-
type: EventType.RUN_FINISHED,
|
|
427
|
-
} as BaseEvent);
|
|
419
|
+
await agent.emit(runFinishedEvent());
|
|
428
420
|
await agent.complete();
|
|
429
421
|
});
|
|
430
422
|
|
|
@@ -471,9 +463,7 @@ describe("Tool Call Re-render Prevention", () => {
|
|
|
471
463
|
const messageId = "m_data";
|
|
472
464
|
const toolCallId = "tc_data";
|
|
473
465
|
|
|
474
|
-
await agent.emit(
|
|
475
|
-
type: EventType.RUN_STARTED,
|
|
476
|
-
} as BaseEvent);
|
|
466
|
+
await agent.emit(runStartedEvent());
|
|
477
467
|
await agent.emit({
|
|
478
468
|
type: EventType.TOOL_CALL_CHUNK,
|
|
479
469
|
toolCallId,
|
|
@@ -508,9 +498,7 @@ describe("Tool Call Re-render Prevention", () => {
|
|
|
508
498
|
expect(capturedStatuses).toContain(ToolCallStatus.InProgress);
|
|
509
499
|
expect(capturedStatuses).toContain(ToolCallStatus.Complete);
|
|
510
500
|
|
|
511
|
-
await agent.emit(
|
|
512
|
-
type: EventType.RUN_FINISHED,
|
|
513
|
-
} as BaseEvent);
|
|
501
|
+
await agent.emit(runFinishedEvent());
|
|
514
502
|
await agent.complete();
|
|
515
503
|
});
|
|
516
504
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Message, ToolCall, ToolMessage } from "@ag-ui/core";
|
|
2
|
+
import { contentToText } from "@ag-ui/core";
|
|
2
3
|
import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
|
|
3
4
|
import { ToolCallStatus } from "@copilotkit/core";
|
|
4
5
|
import { partialJSONParse } from "@copilotkit/shared";
|
|
@@ -53,7 +54,7 @@ export function getToolCallRenderProps(
|
|
|
53
54
|
name: toolCall.function.name,
|
|
54
55
|
args: parsedArgs,
|
|
55
56
|
status: ToolCallStatus.Complete,
|
|
56
|
-
result: toolMessage.content,
|
|
57
|
+
result: contentToText(toolMessage.content),
|
|
57
58
|
toolCall,
|
|
58
59
|
toolMessage,
|
|
59
60
|
};
|
|
@@ -84,7 +85,7 @@ export function getCoreRenderProps(
|
|
|
84
85
|
toolCallId: toolCall.id,
|
|
85
86
|
args: parsedArgs,
|
|
86
87
|
status: ToolCallStatus.Complete,
|
|
87
|
-
result: toolMessage.content,
|
|
88
|
+
result: contentToText(toolMessage.content),
|
|
88
89
|
};
|
|
89
90
|
}
|
|
90
91
|
|