@copilotkit/sdk-js 1.56.1 → 1.56.2-canary.test-welcome-screen
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@copilotkit/sdk-js",
|
|
3
|
-
"version": "1.56.
|
|
3
|
+
"version": "1.56.2-canary.test-welcome-screen",
|
|
4
4
|
"private": false,
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@ag-ui/langgraph": "0.0.29",
|
|
52
|
-
"@copilotkit/shared": "1.56.
|
|
52
|
+
"@copilotkit/shared": "1.56.2-canary.test-welcome-screen"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@langchain/core": "^1.1.8",
|
|
@@ -68,7 +68,6 @@
|
|
|
68
68
|
"tsconfig": "1.4.12"
|
|
69
69
|
},
|
|
70
70
|
"peerDependencies": {
|
|
71
|
-
"@langchain/community": "^0.3.58",
|
|
72
71
|
"@langchain/core": ">=0.4.0 <2.0.0",
|
|
73
72
|
"@langchain/langgraph": ">=0.4.0 <2.0.0",
|
|
74
73
|
"langchain": ">=1.0.0",
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import {
|
|
2
|
+
copilotkitCustomizeConfig,
|
|
3
|
+
convertActionsToDynamicStructuredTools,
|
|
4
|
+
convertActionToDynamicStructuredTool,
|
|
5
|
+
} from "../utils";
|
|
6
|
+
|
|
7
|
+
describe("copilotkitCustomizeConfig", () => {
|
|
8
|
+
it("returns config unchanged when no options provided", () => {
|
|
9
|
+
const baseConfig = { metadata: { existing: true } };
|
|
10
|
+
const result = copilotkitCustomizeConfig(baseConfig);
|
|
11
|
+
expect(result.metadata).toEqual({ existing: true });
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("returns config unchanged when options is empty object", () => {
|
|
15
|
+
const baseConfig = { metadata: {} };
|
|
16
|
+
const result = copilotkitCustomizeConfig(baseConfig, {});
|
|
17
|
+
expect(result.metadata).toEqual({});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("sets emit-messages metadata flag to false", () => {
|
|
21
|
+
const result = copilotkitCustomizeConfig({}, { emitMessages: false });
|
|
22
|
+
expect(result.metadata!["copilotkit:emit-messages"]).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("sets emit-messages metadata flag to true", () => {
|
|
26
|
+
const result = copilotkitCustomizeConfig({}, { emitMessages: true });
|
|
27
|
+
expect(result.metadata!["copilotkit:emit-messages"]).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("sets emit-tool-calls metadata flag to false", () => {
|
|
31
|
+
const result = copilotkitCustomizeConfig({}, { emitToolCalls: false });
|
|
32
|
+
expect(result.metadata!["copilotkit:emit-tool-calls"]).toBe(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("sets emit-tool-calls to a specific tool name string", () => {
|
|
36
|
+
const result = copilotkitCustomizeConfig(
|
|
37
|
+
{},
|
|
38
|
+
{ emitToolCalls: "SearchTool" },
|
|
39
|
+
);
|
|
40
|
+
expect(result.metadata!["copilotkit:emit-tool-calls"]).toBe("SearchTool");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("sets emit-tool-calls to an array of tool names", () => {
|
|
44
|
+
const result = copilotkitCustomizeConfig(
|
|
45
|
+
{},
|
|
46
|
+
{ emitToolCalls: ["SearchTool", "FetchTool"] },
|
|
47
|
+
);
|
|
48
|
+
expect(result.metadata!["copilotkit:emit-tool-calls"]).toEqual([
|
|
49
|
+
"SearchTool",
|
|
50
|
+
"FetchTool",
|
|
51
|
+
]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("sets both emit flags together", () => {
|
|
55
|
+
const result = copilotkitCustomizeConfig(
|
|
56
|
+
{},
|
|
57
|
+
{
|
|
58
|
+
emitMessages: false,
|
|
59
|
+
emitToolCalls: false,
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
expect(result.metadata!["copilotkit:emit-messages"]).toBe(false);
|
|
63
|
+
expect(result.metadata!["copilotkit:emit-tool-calls"]).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("emitAll sets both messages and tool-calls to true", () => {
|
|
67
|
+
const result = copilotkitCustomizeConfig({}, { emitAll: true });
|
|
68
|
+
expect(result.metadata!["copilotkit:emit-messages"]).toBe(true);
|
|
69
|
+
expect(result.metadata!["copilotkit:emit-tool-calls"]).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("converts emitIntermediateState to snake_case in metadata", () => {
|
|
73
|
+
const result = copilotkitCustomizeConfig(
|
|
74
|
+
{},
|
|
75
|
+
{
|
|
76
|
+
emitIntermediateState: [
|
|
77
|
+
{ stateKey: "steps", tool: "SearchTool", toolArgument: "steps" },
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
const intermediateState =
|
|
82
|
+
result.metadata!["copilotkit:emit-intermediate-state"];
|
|
83
|
+
expect(intermediateState).toHaveLength(1);
|
|
84
|
+
expect(intermediateState[0]).toEqual({
|
|
85
|
+
state_key: "steps",
|
|
86
|
+
tool: "SearchTool",
|
|
87
|
+
tool_argument: "steps",
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("handles emitIntermediateState without toolArgument", () => {
|
|
92
|
+
const result = copilotkitCustomizeConfig(
|
|
93
|
+
{},
|
|
94
|
+
{
|
|
95
|
+
emitIntermediateState: [{ stateKey: "output", tool: "WriteTool" }],
|
|
96
|
+
},
|
|
97
|
+
);
|
|
98
|
+
const intermediateState =
|
|
99
|
+
result.metadata!["copilotkit:emit-intermediate-state"];
|
|
100
|
+
expect(intermediateState[0]).toEqual({
|
|
101
|
+
state_key: "output",
|
|
102
|
+
tool: "WriteTool",
|
|
103
|
+
tool_argument: undefined,
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("throws when emitIntermediateState item is missing stateKey", () => {
|
|
108
|
+
expect(() => {
|
|
109
|
+
copilotkitCustomizeConfig(
|
|
110
|
+
{},
|
|
111
|
+
{
|
|
112
|
+
emitIntermediateState: [{ tool: "SearchTool" } as any],
|
|
113
|
+
},
|
|
114
|
+
);
|
|
115
|
+
}).toThrow("stateKey");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("throws when emitIntermediateState item is missing tool", () => {
|
|
119
|
+
expect(() => {
|
|
120
|
+
copilotkitCustomizeConfig(
|
|
121
|
+
{},
|
|
122
|
+
{
|
|
123
|
+
emitIntermediateState: [{ stateKey: "steps" } as any],
|
|
124
|
+
},
|
|
125
|
+
);
|
|
126
|
+
}).toThrow("tool");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("preserves existing metadata from baseConfig", () => {
|
|
130
|
+
const result = copilotkitCustomizeConfig(
|
|
131
|
+
{ metadata: { "custom-key": "custom-value" } },
|
|
132
|
+
{ emitMessages: false },
|
|
133
|
+
);
|
|
134
|
+
expect(result.metadata!["custom-key"]).toBe("custom-value");
|
|
135
|
+
expect(result.metadata!["copilotkit:emit-messages"]).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("handles null/undefined baseConfig gracefully", () => {
|
|
139
|
+
const result = copilotkitCustomizeConfig(null as any, {
|
|
140
|
+
emitMessages: false,
|
|
141
|
+
});
|
|
142
|
+
expect(result.metadata!["copilotkit:emit-messages"]).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("convertActionToDynamicStructuredTool", () => {
|
|
147
|
+
it("converts a valid action to DynamicStructuredTool", () => {
|
|
148
|
+
const action = {
|
|
149
|
+
name: "myTool",
|
|
150
|
+
description: "A test tool",
|
|
151
|
+
parameters: {
|
|
152
|
+
type: "object",
|
|
153
|
+
properties: {
|
|
154
|
+
query: { type: "string" },
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
const tool = convertActionToDynamicStructuredTool(action);
|
|
159
|
+
expect(tool.name).toBe("myTool");
|
|
160
|
+
expect(tool.description).toBe("A test tool");
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("throws when actionInput is null", () => {
|
|
164
|
+
expect(() => convertActionToDynamicStructuredTool(null)).toThrow(
|
|
165
|
+
"Action input is required",
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("throws when name is missing", () => {
|
|
170
|
+
expect(() =>
|
|
171
|
+
convertActionToDynamicStructuredTool({
|
|
172
|
+
description: "test",
|
|
173
|
+
parameters: {},
|
|
174
|
+
}),
|
|
175
|
+
).toThrow("name");
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("throws when description is missing", () => {
|
|
179
|
+
expect(() =>
|
|
180
|
+
convertActionToDynamicStructuredTool({ name: "test", parameters: {} }),
|
|
181
|
+
).toThrow("description");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("throws when parameters is missing", () => {
|
|
185
|
+
expect(() =>
|
|
186
|
+
convertActionToDynamicStructuredTool({
|
|
187
|
+
name: "test",
|
|
188
|
+
description: "test",
|
|
189
|
+
}),
|
|
190
|
+
).toThrow("parameters");
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("convertActionsToDynamicStructuredTools", () => {
|
|
195
|
+
it("converts multiple actions", () => {
|
|
196
|
+
const actions = [
|
|
197
|
+
{
|
|
198
|
+
name: "tool1",
|
|
199
|
+
description: "First tool",
|
|
200
|
+
parameters: { type: "object", properties: {} },
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "tool2",
|
|
204
|
+
description: "Second tool",
|
|
205
|
+
parameters: { type: "object", properties: {} },
|
|
206
|
+
},
|
|
207
|
+
];
|
|
208
|
+
const tools = convertActionsToDynamicStructuredTools(actions);
|
|
209
|
+
expect(tools).toHaveLength(2);
|
|
210
|
+
expect(tools[0].name).toBe("tool1");
|
|
211
|
+
expect(tools[1].name).toBe("tool2");
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("returns empty array for empty input", () => {
|
|
215
|
+
const tools = convertActionsToDynamicStructuredTools([]);
|
|
216
|
+
expect(tools).toEqual([]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("handles { type: 'function', function: {...} } format", () => {
|
|
220
|
+
const actions = [
|
|
221
|
+
{
|
|
222
|
+
type: "function",
|
|
223
|
+
function: {
|
|
224
|
+
name: "wrappedTool",
|
|
225
|
+
description: "A wrapped tool",
|
|
226
|
+
parameters: { type: "object", properties: {} },
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
];
|
|
230
|
+
const tools = convertActionsToDynamicStructuredTools(actions);
|
|
231
|
+
expect(tools).toHaveLength(1);
|
|
232
|
+
expect(tools[0].name).toBe("wrappedTool");
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("throws when input is not an array", () => {
|
|
236
|
+
expect(() =>
|
|
237
|
+
convertActionsToDynamicStructuredTools("not-array" as any),
|
|
238
|
+
).toThrow("Actions must be an array");
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("wraps individual action errors with index info", () => {
|
|
242
|
+
const actions = [
|
|
243
|
+
{
|
|
244
|
+
name: "goodTool",
|
|
245
|
+
description: "works",
|
|
246
|
+
parameters: { type: "object", properties: {} },
|
|
247
|
+
},
|
|
248
|
+
{ name: "badTool" }, // missing description and parameters
|
|
249
|
+
];
|
|
250
|
+
expect(() => convertActionsToDynamicStructuredTools(actions)).toThrow(
|
|
251
|
+
"index 1",
|
|
252
|
+
);
|
|
253
|
+
});
|
|
254
|
+
});
|