@copilotkitnext/agent 1.51.4-next.7 → 1.51.4

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.
@@ -46,7 +46,9 @@ describe("Property Overrides - Edge Cases", () => {
46
46
  overridableProperties: ["model"],
47
47
  });
48
48
 
49
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
49
+ vi.mocked(streamText).mockReturnValue(
50
+ mockStreamTextResponse([finish()]) as any,
51
+ );
50
52
 
51
53
  const input: RunAgentInput = {
52
54
  threadId: "thread1",
@@ -71,7 +73,9 @@ describe("Property Overrides - Edge Cases", () => {
71
73
  overridableProperties: ["model"],
72
74
  });
73
75
 
74
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
76
+ vi.mocked(streamText).mockReturnValue(
77
+ mockStreamTextResponse([finish()]) as any,
78
+ );
75
79
 
76
80
  const customModel = {
77
81
  modelId: "custom-model",
@@ -100,7 +104,9 @@ describe("Property Overrides - Edge Cases", () => {
100
104
  overridableProperties: ["model"],
101
105
  });
102
106
 
103
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
107
+ vi.mocked(streamText).mockReturnValue(
108
+ mockStreamTextResponse([finish()]) as any,
109
+ );
104
110
 
105
111
  const input: RunAgentInput = {
106
112
  threadId: "thread1",
@@ -127,7 +133,9 @@ describe("Property Overrides - Edge Cases", () => {
127
133
  overridableProperties: ["toolChoice"],
128
134
  });
129
135
 
130
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
136
+ vi.mocked(streamText).mockReturnValue(
137
+ mockStreamTextResponse([finish()]) as any,
138
+ );
131
139
 
132
140
  const input: RunAgentInput = {
133
141
  threadId: "thread1",
@@ -152,7 +160,9 @@ describe("Property Overrides - Edge Cases", () => {
152
160
  overridableProperties: ["toolChoice"],
153
161
  });
154
162
 
155
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
163
+ vi.mocked(streamText).mockReturnValue(
164
+ mockStreamTextResponse([finish()]) as any,
165
+ );
156
166
 
157
167
  const input: RunAgentInput = {
158
168
  threadId: "thread1",
@@ -177,7 +187,9 @@ describe("Property Overrides - Edge Cases", () => {
177
187
  overridableProperties: ["toolChoice"],
178
188
  });
179
189
 
180
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
190
+ vi.mocked(streamText).mockReturnValue(
191
+ mockStreamTextResponse([finish()]) as any,
192
+ );
181
193
 
182
194
  const input: RunAgentInput = {
183
195
  threadId: "thread1",
@@ -202,7 +214,9 @@ describe("Property Overrides - Edge Cases", () => {
202
214
  overridableProperties: ["toolChoice"],
203
215
  });
204
216
 
205
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
217
+ vi.mocked(streamText).mockReturnValue(
218
+ mockStreamTextResponse([finish()]) as any,
219
+ );
206
220
 
207
221
  const input: RunAgentInput = {
208
222
  threadId: "thread1",
@@ -211,13 +225,18 @@ describe("Property Overrides - Edge Cases", () => {
211
225
  tools: [],
212
226
  context: [],
213
227
  state: {},
214
- forwardedProps: { toolChoice: { type: "tool", toolName: "specificTool" } },
228
+ forwardedProps: {
229
+ toolChoice: { type: "tool", toolName: "specificTool" },
230
+ },
215
231
  };
216
232
 
217
233
  await collectEvents(agent["run"](input));
218
234
 
219
235
  const callArgs = vi.mocked(streamText).mock.calls[0][0];
220
- expect(callArgs.toolChoice).toEqual({ type: "tool", toolName: "specificTool" });
236
+ expect(callArgs.toolChoice).toEqual({
237
+ type: "tool",
238
+ toolName: "specificTool",
239
+ });
221
240
  });
222
241
 
223
242
  it("should ignore invalid toolChoice values", async () => {
@@ -227,7 +246,9 @@ describe("Property Overrides - Edge Cases", () => {
227
246
  overridableProperties: ["toolChoice"],
228
247
  });
229
248
 
230
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
249
+ vi.mocked(streamText).mockReturnValue(
250
+ mockStreamTextResponse([finish()]) as any,
251
+ );
231
252
 
232
253
  const input: RunAgentInput = {
233
254
  threadId: "thread1",
@@ -254,7 +275,9 @@ describe("Property Overrides - Edge Cases", () => {
254
275
  overridableProperties: ["stopSequences"],
255
276
  });
256
277
 
257
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
278
+ vi.mocked(streamText).mockReturnValue(
279
+ mockStreamTextResponse([finish()]) as any,
280
+ );
258
281
 
259
282
  const input: RunAgentInput = {
260
283
  threadId: "thread1",
@@ -279,7 +302,9 @@ describe("Property Overrides - Edge Cases", () => {
279
302
  overridableProperties: ["stopSequences"],
280
303
  });
281
304
 
282
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
305
+ vi.mocked(streamText).mockReturnValue(
306
+ mockStreamTextResponse([finish()]) as any,
307
+ );
283
308
 
284
309
  const input: RunAgentInput = {
285
310
  threadId: "thread1",
@@ -304,7 +329,9 @@ describe("Property Overrides - Edge Cases", () => {
304
329
  overridableProperties: ["stopSequences"],
305
330
  });
306
331
 
307
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
332
+ vi.mocked(streamText).mockReturnValue(
333
+ mockStreamTextResponse([finish()]) as any,
334
+ );
308
335
 
309
336
  const input: RunAgentInput = {
310
337
  threadId: "thread1",
@@ -347,7 +374,9 @@ describe("Property Overrides - Edge Cases", () => {
347
374
  ],
348
375
  });
349
376
 
350
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
377
+ vi.mocked(streamText).mockReturnValue(
378
+ mockStreamTextResponse([finish()]) as any,
379
+ );
351
380
 
352
381
  const input: RunAgentInput = {
353
382
  threadId: "thread1",
@@ -388,7 +417,9 @@ describe("Property Overrides - Edge Cases", () => {
388
417
  overridableProperties: ["temperature"],
389
418
  });
390
419
 
391
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
420
+ vi.mocked(streamText).mockReturnValue(
421
+ mockStreamTextResponse([finish()]) as any,
422
+ );
392
423
 
393
424
  const input: RunAgentInput = {
394
425
  threadId: "thread1",
@@ -417,7 +448,9 @@ describe("Property Overrides - Edge Cases", () => {
417
448
  overridableProperties: ["temperature"], // Only temperature is overridable
418
449
  });
419
450
 
420
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
451
+ vi.mocked(streamText).mockReturnValue(
452
+ mockStreamTextResponse([finish()]) as any,
453
+ );
421
454
 
422
455
  const input: RunAgentInput = {
423
456
  threadId: "thread1",
@@ -448,7 +481,9 @@ describe("Property Overrides - Edge Cases", () => {
448
481
  overridableProperties: ["temperature"],
449
482
  });
450
483
 
451
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
484
+ vi.mocked(streamText).mockReturnValue(
485
+ mockStreamTextResponse([finish()]) as any,
486
+ );
452
487
 
453
488
  const input: RunAgentInput = {
454
489
  threadId: "thread1",
@@ -473,7 +508,9 @@ describe("Property Overrides - Edge Cases", () => {
473
508
  overridableProperties: ["temperature"],
474
509
  });
475
510
 
476
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
511
+ vi.mocked(streamText).mockReturnValue(
512
+ mockStreamTextResponse([finish()]) as any,
513
+ );
477
514
 
478
515
  const input: RunAgentInput = {
479
516
  threadId: "thread1",
@@ -498,7 +535,9 @@ describe("Property Overrides - Edge Cases", () => {
498
535
  overridableProperties: ["temperature"],
499
536
  });
500
537
 
501
- vi.mocked(streamText).mockReturnValue(mockStreamTextResponse([finish()]) as any);
538
+ vi.mocked(streamText).mockReturnValue(
539
+ mockStreamTextResponse([finish()]) as any,
540
+ );
502
541
 
503
542
  const input: RunAgentInput = {
504
543
  threadId: "thread1",
@@ -2,7 +2,14 @@ import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
2
2
  import { BasicAgent } from "../index";
3
3
  import { EventType, type RunAgentInput } from "@ag-ui/client";
4
4
  import { streamText } from "ai";
5
- import { mockStreamTextResponse, toolCallStreamingStart, toolCall, toolResult, finish, collectEvents } from "./test-helpers";
5
+ import {
6
+ mockStreamTextResponse,
7
+ toolCallStreamingStart,
8
+ toolCall,
9
+ toolResult,
10
+ finish,
11
+ collectEvents,
12
+ } from "./test-helpers";
6
13
 
7
14
  // Mock the ai module
8
15
  vi.mock("ai", () => ({
@@ -43,7 +50,10 @@ describe("State Update Tools", () => {
43
50
  mockStreamTextResponse([
44
51
  toolCallStreamingStart("call1", "AGUISendStateSnapshot"),
45
52
  toolCall("call1", "AGUISendStateSnapshot"),
46
- toolResult("call1", "AGUISendStateSnapshot", { success: true, snapshot: newState }),
53
+ toolResult("call1", "AGUISendStateSnapshot", {
54
+ success: true,
55
+ snapshot: newState,
56
+ }),
47
57
  finish(),
48
58
  ]) as any,
49
59
  );
@@ -60,7 +70,9 @@ describe("State Update Tools", () => {
60
70
  const events = await collectEvents(agent["run"](input));
61
71
 
62
72
  // Find STATE_SNAPSHOT event
63
- const snapshotEvent = events.find((e: any) => e.type === EventType.STATE_SNAPSHOT);
73
+ const snapshotEvent = events.find(
74
+ (e: any) => e.type === EventType.STATE_SNAPSHOT,
75
+ );
64
76
  expect(snapshotEvent).toBeDefined();
65
77
  expect(snapshotEvent).toMatchObject({
66
78
  type: EventType.STATE_SNAPSHOT,
@@ -77,7 +89,10 @@ describe("State Update Tools", () => {
77
89
  mockStreamTextResponse([
78
90
  toolCallStreamingStart("call1", "AGUISendStateSnapshot"),
79
91
  toolCall("call1", "AGUISendStateSnapshot"),
80
- toolResult("call1", "AGUISendStateSnapshot", { success: true, snapshot: { value: 1 } }),
92
+ toolResult("call1", "AGUISendStateSnapshot", {
93
+ success: true,
94
+ snapshot: { value: 1 },
95
+ }),
81
96
  finish(),
82
97
  ]) as any,
83
98
  );
@@ -94,8 +109,12 @@ describe("State Update Tools", () => {
94
109
  const events = await collectEvents(agent["run"](input));
95
110
 
96
111
  // Should have both STATE_SNAPSHOT and TOOL_CALL_RESULT
97
- const snapshotEvent = events.find((e: any) => e.type === EventType.STATE_SNAPSHOT);
98
- const toolResultEvent = events.find((e: any) => e.type === EventType.TOOL_CALL_RESULT);
112
+ const snapshotEvent = events.find(
113
+ (e: any) => e.type === EventType.STATE_SNAPSHOT,
114
+ );
115
+ const toolResultEvent = events.find(
116
+ (e: any) => e.type === EventType.TOOL_CALL_RESULT,
117
+ );
99
118
 
100
119
  expect(snapshotEvent).toBeDefined();
101
120
  expect(toolResultEvent).toBeDefined();
@@ -138,7 +157,9 @@ describe("State Update Tools", () => {
138
157
  const events = await collectEvents(agent["run"](input));
139
158
 
140
159
  // Find STATE_DELTA event
141
- const deltaEvent = events.find((e: any) => e.type === EventType.STATE_DELTA);
160
+ const deltaEvent = events.find(
161
+ (e: any) => e.type === EventType.STATE_DELTA,
162
+ );
142
163
  expect(deltaEvent).toBeDefined();
143
164
  expect(deltaEvent).toMatchObject({
144
165
  type: EventType.STATE_DELTA,
@@ -173,7 +194,9 @@ describe("State Update Tools", () => {
173
194
 
174
195
  const events = await collectEvents(agent["run"](input));
175
196
 
176
- const deltaEvent = events.find((e: any) => e.type === EventType.STATE_DELTA);
197
+ const deltaEvent = events.find(
198
+ (e: any) => e.type === EventType.STATE_DELTA,
199
+ );
177
200
  expect(deltaEvent?.delta).toEqual(delta);
178
201
  });
179
202
 
@@ -204,7 +227,9 @@ describe("State Update Tools", () => {
204
227
 
205
228
  const events = await collectEvents(agent["run"](input));
206
229
 
207
- const deltaEvent = events.find((e: any) => e.type === EventType.STATE_DELTA);
230
+ const deltaEvent = events.find(
231
+ (e: any) => e.type === EventType.STATE_DELTA,
232
+ );
208
233
  expect(deltaEvent?.delta).toEqual(delta);
209
234
  });
210
235
 
@@ -235,7 +260,9 @@ describe("State Update Tools", () => {
235
260
 
236
261
  const events = await collectEvents(agent["run"](input));
237
262
 
238
- const deltaEvent = events.find((e: any) => e.type === EventType.STATE_DELTA);
263
+ const deltaEvent = events.find(
264
+ (e: any) => e.type === EventType.STATE_DELTA,
265
+ );
239
266
  expect(deltaEvent?.delta).toEqual(delta);
240
267
  });
241
268
 
@@ -270,7 +297,9 @@ describe("State Update Tools", () => {
270
297
 
271
298
  const events = await collectEvents(agent["run"](input));
272
299
 
273
- const deltaEvent = events.find((e: any) => e.type === EventType.STATE_DELTA);
300
+ const deltaEvent = events.find(
301
+ (e: any) => e.type === EventType.STATE_DELTA,
302
+ );
274
303
  expect(deltaEvent?.delta).toEqual(delta);
275
304
  });
276
305
 
@@ -302,8 +331,12 @@ describe("State Update Tools", () => {
302
331
  const events = await collectEvents(agent["run"](input));
303
332
 
304
333
  // Should have both STATE_DELTA and TOOL_CALL_RESULT
305
- const deltaEvent = events.find((e: any) => e.type === EventType.STATE_DELTA);
306
- const toolResultEvent = events.find((e: any) => e.type === EventType.TOOL_CALL_RESULT);
334
+ const deltaEvent = events.find(
335
+ (e: any) => e.type === EventType.STATE_DELTA,
336
+ );
337
+ const toolResultEvent = events.find(
338
+ (e: any) => e.type === EventType.TOOL_CALL_RESULT,
339
+ );
307
340
 
308
341
  expect(deltaEvent).toBeDefined();
309
342
  expect(toolResultEvent).toBeDefined();
@@ -324,10 +357,16 @@ describe("State Update Tools", () => {
324
357
  mockStreamTextResponse([
325
358
  toolCallStreamingStart("call1", "AGUISendStateSnapshot"),
326
359
  toolCall("call1", "AGUISendStateSnapshot"),
327
- toolResult("call1", "AGUISendStateSnapshot", { success: true, snapshot: { value: 1 } }),
360
+ toolResult("call1", "AGUISendStateSnapshot", {
361
+ success: true,
362
+ snapshot: { value: 1 },
363
+ }),
328
364
  toolCallStreamingStart("call2", "AGUISendStateDelta"),
329
365
  toolCall("call2", "AGUISendStateDelta"),
330
- toolResult("call2", "AGUISendStateDelta", { success: true, delta: [{ op: "replace", path: "/value", value: 2 }] }),
366
+ toolResult("call2", "AGUISendStateDelta", {
367
+ success: true,
368
+ delta: [{ op: "replace", path: "/value", value: 2 }],
369
+ }),
331
370
  finish(),
332
371
  ]) as any,
333
372
  );
@@ -343,8 +382,12 @@ describe("State Update Tools", () => {
343
382
 
344
383
  const events = await collectEvents(agent["run"](input));
345
384
 
346
- const snapshotEvents = events.filter((e: any) => e.type === EventType.STATE_SNAPSHOT);
347
- const deltaEvents = events.filter((e: any) => e.type === EventType.STATE_DELTA);
385
+ const snapshotEvents = events.filter(
386
+ (e: any) => e.type === EventType.STATE_SNAPSHOT,
387
+ );
388
+ const deltaEvents = events.filter(
389
+ (e: any) => e.type === EventType.STATE_DELTA,
390
+ );
348
391
 
349
392
  expect(snapshotEvents).toHaveLength(1);
350
393
  expect(deltaEvents).toHaveLength(1);
@@ -382,7 +425,9 @@ describe("State Update Tools", () => {
382
425
  const events = await collectEvents(agent["run"](input));
383
426
 
384
427
  const stateEvents = events.filter(
385
- (e: any) => e.type === EventType.STATE_SNAPSHOT || e.type === EventType.STATE_DELTA,
428
+ (e: any) =>
429
+ e.type === EventType.STATE_SNAPSHOT ||
430
+ e.type === EventType.STATE_DELTA,
386
431
  );
387
432
 
388
433
  expect(stateEvents).toHaveLength(0);
@@ -46,7 +46,10 @@ export function textDelta(text: string): MockStreamEvent {
46
46
  /**
47
47
  * Helper to create a tool call streaming start event
48
48
  */
49
- export function toolCallStreamingStart(toolCallId: string, toolName: string): MockStreamEvent {
49
+ export function toolCallStreamingStart(
50
+ toolCallId: string,
51
+ toolName: string,
52
+ ): MockStreamEvent {
50
53
  return {
51
54
  type: "tool-input-start",
52
55
  id: toolCallId,
@@ -57,7 +60,10 @@ export function toolCallStreamingStart(toolCallId: string, toolName: string): Mo
57
60
  /**
58
61
  * Helper to create a tool call delta event
59
62
  */
60
- export function toolCallDelta(toolCallId: string, argsTextDelta: string): MockStreamEvent {
63
+ export function toolCallDelta(
64
+ toolCallId: string,
65
+ argsTextDelta: string,
66
+ ): MockStreamEvent {
61
67
  return {
62
68
  type: "tool-input-delta",
63
69
  id: toolCallId,
@@ -68,7 +74,11 @@ export function toolCallDelta(toolCallId: string, argsTextDelta: string): MockSt
68
74
  /**
69
75
  * Helper to create a tool call event
70
76
  */
71
- export function toolCall(toolCallId: string, toolName: string, input: unknown = {}): MockStreamEvent {
77
+ export function toolCall(
78
+ toolCallId: string,
79
+ toolName: string,
80
+ input: unknown = {},
81
+ ): MockStreamEvent {
72
82
  return {
73
83
  type: "tool-call",
74
84
  toolCallId,
@@ -80,7 +90,11 @@ export function toolCall(toolCallId: string, toolName: string, input: unknown =
80
90
  /**
81
91
  * Helper to create a tool result event
82
92
  */
83
- export function toolResult(toolCallId: string, toolName: string, output: any): MockStreamEvent {
93
+ export function toolResult(
94
+ toolCallId: string,
95
+ toolName: string,
96
+ output: any,
97
+ ): MockStreamEvent {
84
98
  return {
85
99
  type: "tool-result",
86
100
  toolCallId,
@@ -112,7 +126,9 @@ export function error(errorMessage: string): MockStreamEvent {
112
126
  /**
113
127
  * Collects all events from an Observable into an array
114
128
  */
115
- export async function collectEvents<T>(observable: { subscribe: (observer: any) => any }): Promise<T[]> {
129
+ export async function collectEvents<T>(observable: {
130
+ subscribe: (observer: any) => any;
131
+ }): Promise<T[]> {
116
132
  return new Promise((resolve, reject) => {
117
133
  const events: T[] = [];
118
134
  const subscription = observable.subscribe({
@@ -155,7 +155,7 @@ describe("convertMessagesToVercelAISDKMessages", () => {
155
155
  type: "function",
156
156
  function: {
157
157
  name: "getTool",
158
- arguments: '{}',
158
+ arguments: "{}",
159
159
  },
160
160
  },
161
161
  ],
@@ -331,7 +331,9 @@ describe("convertToolsToVercelAITools", () => {
331
331
  },
332
332
  ];
333
333
 
334
- expect(() => convertToolsToVercelAITools(tools)).toThrow("Invalid JSON schema");
334
+ expect(() => convertToolsToVercelAITools(tools)).toThrow(
335
+ "Invalid JSON schema",
336
+ );
335
337
  });
336
338
 
337
339
  it("should handle multiple tools", () => {