@copilotkit/vue 1.68.3 → 1.69.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.
@@ -21,5 +21,5 @@ describe("@copilotkit/vue SSR import safety", () => {
21
21
  const mod = await import("../../../../index");
22
22
  expect(mod.CopilotThreadsDrawer).toBeDefined();
23
23
  expect(evaluated.current).toBe(false);
24
- });
24
+ }, 20_000);
25
25
  });
@@ -0,0 +1,126 @@
1
+ import type { Message, ToolCall, ToolMessage } from "@ag-ui/core";
2
+ import { DEFAULT_AGENT_ID } from "@copilotkit/shared";
3
+ import { ToolCallStatus } from "@copilotkit/core";
4
+ import { partialJSONParse } from "@copilotkit/shared";
5
+ import type { CopilotChatToolCallRenderSlotProps } from "./types";
6
+ import type {
7
+ VueToolCallRenderer,
8
+ VueToolCallRendererRenderProps,
9
+ } from "../../types";
10
+
11
+ export function findToolMessage(
12
+ messages: Message[],
13
+ toolCallId: string,
14
+ ): ToolMessage | undefined {
15
+ return messages.find(
16
+ (message) =>
17
+ message.role === "tool" &&
18
+ (message as ToolMessage).toolCallId === toolCallId,
19
+ ) as ToolMessage | undefined;
20
+ }
21
+
22
+ export function getToolCallSlotName(toolName: string): `tool-call-${string}` {
23
+ return `tool-call-${toolName}`;
24
+ }
25
+
26
+ export function getCoreRenderConfig(
27
+ toolCall: ToolCall,
28
+ renderToolCalls: readonly VueToolCallRenderer<unknown>[],
29
+ agentId: string,
30
+ ): VueToolCallRenderer<unknown> | undefined {
31
+ const exactMatches = renderToolCalls.filter(
32
+ (renderConfig) => renderConfig.name === toolCall.function.name,
33
+ );
34
+
35
+ return (
36
+ exactMatches.find((renderConfig) => renderConfig.agentId === agentId) ??
37
+ exactMatches.find((renderConfig) => !renderConfig.agentId) ??
38
+ exactMatches[0] ??
39
+ renderToolCalls.find((renderConfig) => renderConfig.name === "*")
40
+ );
41
+ }
42
+
43
+ export function getToolCallRenderProps(
44
+ toolCall: ToolCall,
45
+ messages: Message[],
46
+ executingToolCallIds: ReadonlySet<string>,
47
+ ): CopilotChatToolCallRenderSlotProps {
48
+ const toolMessage = findToolMessage(messages, toolCall.id);
49
+ const parsedArgs = partialJSONParse(toolCall.function.arguments);
50
+
51
+ if (toolMessage) {
52
+ return {
53
+ name: toolCall.function.name,
54
+ args: parsedArgs,
55
+ status: ToolCallStatus.Complete,
56
+ result: toolMessage.content,
57
+ toolCall,
58
+ toolMessage,
59
+ };
60
+ }
61
+
62
+ const isExecuting = executingToolCallIds.has(toolCall.id);
63
+ return {
64
+ name: toolCall.function.name,
65
+ args: parsedArgs,
66
+ status: isExecuting ? ToolCallStatus.Executing : ToolCallStatus.InProgress,
67
+ result: undefined,
68
+ toolCall,
69
+ toolMessage: undefined,
70
+ };
71
+ }
72
+
73
+ export function getCoreRenderProps(
74
+ toolCall: ToolCall,
75
+ messages: Message[],
76
+ executingToolCallIds: ReadonlySet<string>,
77
+ ): VueToolCallRendererRenderProps<unknown> {
78
+ const toolMessage = findToolMessage(messages, toolCall.id);
79
+ const parsedArgs = partialJSONParse(toolCall.function.arguments);
80
+
81
+ if (toolMessage) {
82
+ return {
83
+ name: toolCall.function.name,
84
+ toolCallId: toolCall.id,
85
+ args: parsedArgs,
86
+ status: ToolCallStatus.Complete,
87
+ result: toolMessage.content,
88
+ };
89
+ }
90
+
91
+ const isExecuting = executingToolCallIds.has(toolCall.id);
92
+ if (isExecuting) {
93
+ return {
94
+ name: toolCall.function.name,
95
+ toolCallId: toolCall.id,
96
+ args: parsedArgs,
97
+ status: ToolCallStatus.Executing,
98
+ result: undefined,
99
+ };
100
+ }
101
+
102
+ return {
103
+ name: toolCall.function.name,
104
+ toolCallId: toolCall.id,
105
+ args: parsedArgs && typeof parsedArgs === "object" ? parsedArgs : {},
106
+ status: ToolCallStatus.InProgress,
107
+ result: undefined,
108
+ };
109
+ }
110
+
111
+ export function getToolCallMemoDeps(
112
+ toolCall: ToolCall,
113
+ messages: Message[],
114
+ executingToolCallIds: ReadonlySet<string>,
115
+ renderToolCalls: readonly VueToolCallRenderer<unknown>[],
116
+ agentId: string = DEFAULT_AGENT_ID,
117
+ ): unknown[] {
118
+ return [
119
+ toolCall.id,
120
+ toolCall.function.name,
121
+ toolCall.function.arguments,
122
+ findToolMessage(messages, toolCall.id)?.content,
123
+ executingToolCallIds.has(toolCall.id),
124
+ getCoreRenderConfig(toolCall, renderToolCalls, agentId)?.render,
125
+ ];
126
+ }