@copilotkit/runtime 1.61.1 → 1.62.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 (81) hide show
  1. package/dist/agent/converters/aisdk.cjs +52 -1
  2. package/dist/agent/converters/aisdk.cjs.map +1 -1
  3. package/dist/agent/converters/aisdk.d.cts +6 -2
  4. package/dist/agent/converters/aisdk.d.cts.map +1 -1
  5. package/dist/agent/converters/aisdk.d.mts +6 -2
  6. package/dist/agent/converters/aisdk.d.mts.map +1 -1
  7. package/dist/agent/converters/aisdk.mjs +52 -1
  8. package/dist/agent/converters/aisdk.mjs.map +1 -1
  9. package/dist/agent/converters/tanstack.cjs +17 -1
  10. package/dist/agent/converters/tanstack.cjs.map +1 -1
  11. package/dist/agent/converters/tanstack.d.cts +6 -2
  12. package/dist/agent/converters/tanstack.d.cts.map +1 -1
  13. package/dist/agent/converters/tanstack.d.mts +6 -2
  14. package/dist/agent/converters/tanstack.d.mts.map +1 -1
  15. package/dist/agent/converters/tanstack.mjs +17 -1
  16. package/dist/agent/converters/tanstack.mjs.map +1 -1
  17. package/dist/agent/index.cjs +165 -39
  18. package/dist/agent/index.cjs.map +1 -1
  19. package/dist/agent/index.d.cts +42 -4
  20. package/dist/agent/index.d.cts.map +1 -1
  21. package/dist/agent/index.d.mts +42 -4
  22. package/dist/agent/index.d.mts.map +1 -1
  23. package/dist/agent/index.mjs +165 -40
  24. package/dist/agent/index.mjs.map +1 -1
  25. package/dist/graphql/message-conversion/agui-to-gql.cjs +5 -3
  26. package/dist/graphql/message-conversion/agui-to-gql.cjs.map +1 -1
  27. package/dist/graphql/message-conversion/agui-to-gql.mjs +5 -3
  28. package/dist/graphql/message-conversion/agui-to-gql.mjs.map +1 -1
  29. package/dist/lib/integrations/node-http/request-handler.cjs.map +1 -1
  30. package/dist/lib/integrations/node-http/request-handler.mjs.map +1 -1
  31. package/dist/lib/runtime/copilot-runtime.cjs +1 -1
  32. package/dist/lib/runtime/copilot-runtime.cjs.map +1 -1
  33. package/dist/lib/runtime/copilot-runtime.d.cts.map +1 -1
  34. package/dist/lib/runtime/copilot-runtime.d.mts.map +1 -1
  35. package/dist/lib/runtime/copilot-runtime.mjs +1 -1
  36. package/dist/lib/runtime/copilot-runtime.mjs.map +1 -1
  37. package/dist/package.cjs +1 -1
  38. package/dist/package.mjs +1 -1
  39. package/dist/service-adapters/openai/openai-assistant-adapter.cjs.map +1 -1
  40. package/dist/service-adapters/openai/openai-assistant-adapter.d.cts.map +1 -1
  41. package/dist/service-adapters/openai/openai-assistant-adapter.d.mts.map +1 -1
  42. package/dist/service-adapters/openai/openai-assistant-adapter.mjs.map +1 -1
  43. package/dist/service-adapters/openai/utils.cjs.map +1 -1
  44. package/dist/service-adapters/openai/utils.mjs.map +1 -1
  45. package/dist/v2/index.cjs +1 -0
  46. package/dist/v2/index.d.cts +2 -2
  47. package/dist/v2/index.d.mts +2 -2
  48. package/dist/v2/index.mjs +2 -2
  49. package/dist/v2/runtime/core/runtime.cjs.map +1 -1
  50. package/dist/v2/runtime/core/runtime.d.cts +3 -3
  51. package/dist/v2/runtime/core/runtime.d.cts.map +1 -1
  52. package/dist/v2/runtime/core/runtime.d.mts +3 -3
  53. package/dist/v2/runtime/core/runtime.d.mts.map +1 -1
  54. package/dist/v2/runtime/core/runtime.mjs.map +1 -1
  55. package/dist/v2/runtime/endpoints/express-fetch-bridge.cjs.map +1 -1
  56. package/dist/v2/runtime/endpoints/express-fetch-bridge.mjs.map +1 -1
  57. package/dist/v2/runtime/endpoints/single-route-helpers.cjs +1 -1
  58. package/dist/v2/runtime/endpoints/single-route-helpers.cjs.map +1 -1
  59. package/dist/v2/runtime/endpoints/single-route-helpers.mjs +1 -1
  60. package/dist/v2/runtime/endpoints/single-route-helpers.mjs.map +1 -1
  61. package/dist/v2/runtime/handlers/handle-run.cjs +4 -3
  62. package/dist/v2/runtime/handlers/handle-run.cjs.map +1 -1
  63. package/dist/v2/runtime/handlers/handle-run.mjs +4 -3
  64. package/dist/v2/runtime/handlers/handle-run.mjs.map +1 -1
  65. package/dist/v2/runtime/handlers/intelligence/thread-names.cjs +0 -2
  66. package/dist/v2/runtime/handlers/intelligence/thread-names.cjs.map +1 -1
  67. package/dist/v2/runtime/handlers/intelligence/thread-names.mjs +0 -2
  68. package/dist/v2/runtime/handlers/intelligence/thread-names.mjs.map +1 -1
  69. package/dist/v2/runtime/handlers/shared/agent-utils.cjs +8 -4
  70. package/dist/v2/runtime/handlers/shared/agent-utils.cjs.map +1 -1
  71. package/dist/v2/runtime/handlers/shared/agent-utils.mjs +8 -4
  72. package/dist/v2/runtime/handlers/shared/agent-utils.mjs.map +1 -1
  73. package/dist/v2/runtime/runner/in-memory.cjs.map +1 -1
  74. package/dist/v2/runtime/runner/in-memory.d.cts.map +1 -1
  75. package/dist/v2/runtime/runner/in-memory.d.mts.map +1 -1
  76. package/dist/v2/runtime/runner/in-memory.mjs.map +1 -1
  77. package/dist/v2/runtime/runner/intelligence.cjs.map +1 -1
  78. package/dist/v2/runtime/runner/intelligence.d.cts.map +1 -1
  79. package/dist/v2/runtime/runner/intelligence.d.mts.map +1 -1
  80. package/dist/v2/runtime/runner/intelligence.mjs.map +1 -1
  81. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/agent/index.ts"],"mappings":";;;;;;;;;;;;;;;;;KA6DY,mBAAA;;;;KAkBA,iBAAA;AAAZ;;;AAAA,KA8BY,cAAA,YAA0B,aAAA;;AAAtC;;UAKiB,mBAAA;EALqB;EAOpC,IAAA;EAFe;EAIf,GAAA;;;;;;;EAOA,OAAA,GAAU,oCAAA;AAAA;AAMZ;;;AAAA,UAAiB,kBAAA;EAEf;EAAA,IAAA;EAIA;EAFA,GAAA;EAEgB;EAAhB,OAAA,GAAU,MAAA;AAAA;;;;KAMA,eAAA,GAAkB,mBAAA,GAAsB,kBAAA;AAUpD;;;;;;;;AAAA,UAAiB,iBAAA;EAWD;EATd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, apiKey) {
41
41
  }
42
42
  }
43
43
  /**
44
+ * Thrown by `AgentFactoryContext.interrupt()` on a fresh (non-resume) run to
45
+ * pause the factory. Caught in `runFactory` and translated into a RUN_FINISHED
46
+ * event carrying `outcome:{type:"interrupt",interrupts}`. Not a real error.
47
+ */
48
+ var InterruptSignal = class extends Error {
49
+ constructor(interrupts) {
50
+ super("CopilotKit interrupt: run paused awaiting human input");
51
+ this.interrupts = interrupts;
52
+ this.name = "InterruptSignal";
53
+ }
54
+ };
55
+ /**
44
56
  * Define a tool for use with BuiltInAgent
45
57
  * @param name - The name of the tool
46
58
  * @param description - Description of what the tool does
@@ -53,7 +65,10 @@ function defineTool(config) {
53
65
  name: config.name,
54
66
  description: config.description,
55
67
  parameters: config.parameters,
56
- execute: config.execute
68
+ execute: config.execute,
69
+ interrupt: config.interrupt,
70
+ interruptReason: config.interruptReason,
71
+ interruptMessage: config.interruptMessage
57
72
  };
58
73
  }
59
74
  /**
@@ -269,6 +284,19 @@ function isJsonSchema(obj) {
269
284
  "array"
270
285
  ].includes(schema.type);
271
286
  }
287
+ /**
288
+ * Type-only pass-through for handing a Zod schema to the AI SDK's `tool()`.
289
+ * The raw Zod schema is returned unchanged at runtime — the SDK's `asSchema()`
290
+ * converts and validates it internally exactly as before.
291
+ *
292
+ * The Zod type is erased through `unknown` deliberately: letting tsc relate
293
+ * Zod schema types to the AI SDK's `FlexibleSchema` union (conditional types
294
+ * spanning zod v3/v4) makes type instantiation explode (TS2589 / compiler
295
+ * OOM) under this package's `moduleResolution: node`.
296
+ */
297
+ function toLanguageModelSchema(schema) {
298
+ return schema;
299
+ }
272
300
  function convertToolsToVercelAITools(tools) {
273
301
  const result = {};
274
302
  for (const tool$1 of tools) {
@@ -276,7 +304,7 @@ function convertToolsToVercelAITools(tools) {
276
304
  const zodSchema = convertJsonSchemaToZodSchema$1(tool$1.parameters, true);
277
305
  result[tool$1.name] = tool({
278
306
  description: tool$1.description,
279
- inputSchema: zodSchema
307
+ inputSchema: toLanguageModelSchema(zodSchema)
280
308
  });
281
309
  }
282
310
  return result;
@@ -335,16 +363,19 @@ var BuiltInAgent = class BuiltInAgent extends AbstractAgent {
335
363
  supported: true,
336
364
  clientProvided: true
337
365
  },
338
- transport: { streaming: true }
366
+ transport: { streaming: true },
367
+ humanInTheLoop: { interrupts: true }
339
368
  };
340
- if (!this.config.capabilities) return inferred;
369
+ const capabilities = isFactoryConfig(this.config) ? void 0 : this.config.capabilities;
370
+ if (!capabilities) return inferred;
341
371
  return {
342
372
  ...inferred,
343
- ...this.config.capabilities
373
+ ...capabilities
344
374
  };
345
375
  }
346
376
  run(input) {
347
377
  if (isFactoryConfig(this.config)) return this.runFactory(input, this.config);
378
+ const config = this.config;
348
379
  if (this.abortController) throw new Error("Agent is already running. Call abortRun() first or create a new instance.");
349
380
  this.abortController = new AbortController();
350
381
  const abortController = this.abortController;
@@ -355,14 +386,14 @@ var BuiltInAgent = class BuiltInAgent extends AbstractAgent {
355
386
  runId: input.runId
356
387
  };
357
388
  subscriber.next(startEvent);
358
- const model = resolveModel(this.config.model, this.config.apiKey);
389
+ const model = resolveModel(config.model, config.apiKey);
359
390
  let systemPrompt = void 0;
360
- const hasPrompt = !!this.config.prompt;
391
+ const hasPrompt = !!config.prompt;
361
392
  const hasContext = input.context && input.context.length > 0;
362
393
  const hasState = input.state !== void 0 && input.state !== null && !(typeof input.state === "object" && Object.keys(input.state).length === 0);
363
394
  if (hasPrompt || hasContext || hasState) {
364
395
  const parts = [];
365
- if (hasPrompt) parts.push(this.config.prompt);
396
+ if (hasPrompt) parts.push(config.prompt);
366
397
  if (hasContext) {
367
398
  parts.push("\n## Context from the application\n");
368
399
  for (const ctx of input.context) parts.push(`${ctx.description}:\n${ctx.value}\n`);
@@ -374,16 +405,46 @@ This is state from the application that you can edit by calling AGUISendStateSna
374
405
  systemPrompt = parts.join("");
375
406
  }
376
407
  const messages = convertMessagesToVercelAISDKMessages(input.messages, {
377
- forwardSystemMessages: this.config.forwardSystemMessages,
378
- forwardDeveloperMessages: this.config.forwardDeveloperMessages
408
+ forwardSystemMessages: config.forwardSystemMessages,
409
+ forwardDeveloperMessages: config.forwardDeveloperMessages
379
410
  });
380
411
  if (systemPrompt) messages.unshift({
381
412
  role: "system",
382
413
  content: systemPrompt
383
414
  });
415
+ const resumeEntries = input.resume ?? [];
416
+ if (resumeEntries.length > 0) {
417
+ const toolNameById = /* @__PURE__ */ new Map();
418
+ for (const m of input.messages) {
419
+ if (m.role !== "assistant") continue;
420
+ for (const tc of m.toolCalls ?? []) if (tc.id && tc.function?.name) toolNameById.set(tc.id, tc.function.name);
421
+ }
422
+ const alreadyAnswered = /* @__PURE__ */ new Set();
423
+ for (const m of messages) {
424
+ if (m.role !== "tool" || !Array.isArray(m.content)) continue;
425
+ for (const part of m.content) if (part && typeof part === "object" && "toolCallId" in part) alreadyAnswered.add(part.toolCallId);
426
+ }
427
+ for (const entry of resumeEntries) {
428
+ if (alreadyAnswered.has(entry.interruptId)) continue;
429
+ const value = entry.status === "cancelled" ? { status: "cancelled" } : entry.payload ?? { status: "resolved" };
430
+ const toolResultMessage = {
431
+ role: "tool",
432
+ content: [{
433
+ type: "tool-result",
434
+ toolCallId: entry.interruptId,
435
+ toolName: toolNameById.get(entry.interruptId) ?? "",
436
+ output: {
437
+ type: "json",
438
+ value
439
+ }
440
+ }]
441
+ };
442
+ messages.push(toolResultMessage);
443
+ }
444
+ }
384
445
  let allTools = convertToolsToVercelAITools(input.tools);
385
- if (this.config.tools && this.config.tools.length > 0) {
386
- const configTools = convertToolDefinitionsToVercelAITools(this.config.tools);
446
+ if (config.tools && config.tools.length > 0) {
447
+ const configTools = convertToolDefinitionsToVercelAITools(config.tools);
387
448
  allTools = {
388
449
  ...allTools,
389
450
  ...configTools
@@ -393,23 +454,23 @@ This is state from the application that you can edit by calling AGUISendStateSna
393
454
  model,
394
455
  messages,
395
456
  tools: allTools,
396
- toolChoice: this.config.toolChoice,
397
- stopWhen: this.config.maxSteps ? stepCountIs(this.config.maxSteps) : void 0,
398
- maxOutputTokens: this.config.maxOutputTokens,
399
- temperature: this.config.temperature,
400
- topP: this.config.topP,
401
- topK: this.config.topK,
402
- presencePenalty: this.config.presencePenalty,
403
- frequencyPenalty: this.config.frequencyPenalty,
404
- stopSequences: this.config.stopSequences,
405
- seed: this.config.seed,
406
- providerOptions: this.config.providerOptions,
407
- maxRetries: this.config.maxRetries
457
+ toolChoice: config.toolChoice,
458
+ stopWhen: config.maxSteps ? stepCountIs(config.maxSteps) : void 0,
459
+ maxOutputTokens: config.maxOutputTokens,
460
+ temperature: config.temperature,
461
+ topP: config.topP,
462
+ topK: config.topK,
463
+ presencePenalty: config.presencePenalty,
464
+ frequencyPenalty: config.frequencyPenalty,
465
+ stopSequences: config.stopSequences,
466
+ seed: config.seed,
467
+ providerOptions: config.providerOptions,
468
+ maxRetries: config.maxRetries
408
469
  };
409
470
  if (input.forwardedProps && typeof input.forwardedProps === "object") {
410
471
  const props = input.forwardedProps;
411
472
  if (props.model !== void 0 && this.canOverride("model")) {
412
- if (typeof props.model === "string" || typeof props.model === "object") streamTextParams.model = resolveModel(props.model, this.config.apiKey);
473
+ if (typeof props.model === "string" || typeof props.model === "object") streamTextParams.model = resolveModel(props.model, config.apiKey);
413
474
  }
414
475
  if (props.toolChoice !== void 0 && this.canOverride("toolChoice")) {
415
476
  const toolChoice = props.toolChoice;
@@ -455,7 +516,7 @@ This is state from the application that you can edit by calling AGUISendStateSna
455
516
  ...streamTextParams.tools,
456
517
  AGUISendStateSnapshot: tool({
457
518
  description: "Replace the entire application state with a new snapshot",
458
- inputSchema: z.object({ snapshot: z.any().describe("The complete new state object") }),
519
+ inputSchema: toLanguageModelSchema(z.object({ snapshot: z.any().describe("The complete new state object") })),
459
520
  execute: async ({ snapshot }) => {
460
521
  return {
461
522
  success: true,
@@ -465,7 +526,7 @@ This is state from the application that you can edit by calling AGUISendStateSna
465
526
  }),
466
527
  AGUISendStateDelta: tool({
467
528
  description: "Apply incremental updates to application state using JSON Patch operations",
468
- inputSchema: z.object({ delta: z.array(z.object({
529
+ inputSchema: toLanguageModelSchema(z.object({ delta: z.array(z.object({
469
530
  op: z.enum([
470
531
  "add",
471
532
  "replace",
@@ -473,7 +534,7 @@ This is state from the application that you can edit by calling AGUISendStateSna
473
534
  ]).describe("The operation to perform"),
474
535
  path: z.string().describe("JSON Pointer path (e.g., '/foo/bar')"),
475
536
  value: z.any().optional().describe("The value to set. Required for 'add' and 'replace' operations, ignored for 'remove'.")
476
- })).describe("Array of JSON Patch operations") }),
537
+ })).describe("Array of JSON Patch operations") })),
477
538
  execute: async ({ delta }) => {
478
539
  return {
479
540
  success: true,
@@ -482,14 +543,14 @@ This is state from the application that you can edit by calling AGUISendStateSna
482
543
  }
483
544
  })
484
545
  };
485
- if (this.config.mcpClients && this.config.mcpClients.length > 0) for (const client of this.config.mcpClients) {
546
+ if (config.mcpClients && config.mcpClients.length > 0) for (const client of config.mcpClients) {
486
547
  const mcpTools = await client.tools();
487
548
  streamTextParams.tools = {
488
549
  ...streamTextParams.tools,
489
550
  ...mcpTools
490
551
  };
491
552
  }
492
- const allMcpServers = [...this.config.mcpServers ?? []];
553
+ const allMcpServers = [...config.mcpServers ?? []];
493
554
  if (allMcpServers.length > 0) for (const serverConfig of allMcpServers) {
494
555
  let transport;
495
556
  if (serverConfig.type === "http") transport = new StreamableHTTPClientTransport(new URL(serverConfig.url), serverConfig.options);
@@ -518,6 +579,12 @@ This is state from the application that you can edit by calling AGUISendStateSna
518
579
  ...streamTextParams,
519
580
  abortSignal: abortController.signal
520
581
  });
582
+ const interruptToolNames = new Set((isFactoryConfig(this.config) ? [] : this.config.tools ?? []).filter((t) => t.interrupt).map((t) => t.name));
583
+ const interruptToolMeta = new Map((isFactoryConfig(this.config) ? [] : this.config.tools ?? []).filter((t) => t.interrupt).map((t) => [t.name, {
584
+ reason: t.interruptReason ?? "tool_call",
585
+ message: t.interruptMessage
586
+ }]));
587
+ const pendingInterrupts = [];
521
588
  const toolCallStates = /* @__PURE__ */ new Map();
522
589
  const ensureToolCallState = (toolCallId) => {
523
590
  let state = toolCallStates.get(toolCallId);
@@ -659,11 +726,25 @@ This is state from the application that you can edit by calling AGUISendStateSna
659
726
  };
660
727
  subscriber.next(endEvent);
661
728
  }
729
+ if (state.toolName && interruptToolNames.has(state.toolName)) {
730
+ const meta = interruptToolMeta.get(state.toolName);
731
+ pendingInterrupts.push({
732
+ id: toolCallId,
733
+ toolCallId,
734
+ reason: meta?.reason ?? "tool_call",
735
+ ...meta?.message ? { message: meta.message } : {}
736
+ });
737
+ }
662
738
  break;
663
739
  }
664
740
  case "tool-result": {
665
- const toolResult = "output" in part ? part.output : "result" in part ? part.result : null;
666
- const toolName = "toolName" in part ? part.toolName : "";
741
+ const toolName = "toolName" in part && part.toolName || toolCallStates.get(part.toolCallId)?.toolName || "";
742
+ if (toolName && interruptToolNames.has(toolName)) {
743
+ toolCallStates.delete(part.toolCallId);
744
+ break;
745
+ }
746
+ const legacyPart = part;
747
+ const toolResult = "output" in part ? part.output : "result" in legacyPart ? legacyPart.result : null;
667
748
  toolCallStates.delete(part.toolCallId);
668
749
  if (toolName === "AGUISendStateSnapshot" && toolResult && typeof toolResult === "object") {
669
750
  const snapshot = toolResult.snapshot;
@@ -704,7 +785,11 @@ This is state from the application that you can edit by calling AGUISendStateSna
704
785
  const finishedEvent = {
705
786
  type: EventType.RUN_FINISHED,
706
787
  threadId: input.threadId,
707
- runId: input.runId
788
+ runId: input.runId,
789
+ ...pendingInterrupts.length > 0 ? { outcome: {
790
+ type: "interrupt",
791
+ interrupts: pendingInterrupts
792
+ } } : {}
708
793
  };
709
794
  subscriber.next(finishedEvent);
710
795
  terminalEventEmitted = true;
@@ -713,7 +798,7 @@ This is state from the application that you can edit by calling AGUISendStateSna
713
798
  }
714
799
  case "error": {
715
800
  if (abortController.signal.aborted) break;
716
- const err = part.error ?? part.message ?? part.cause;
801
+ const err = part.error ?? ("message" in part ? part.message : void 0) ?? ("cause" in part ? part.cause : void 0);
717
802
  const runErrorEvent = {
718
803
  type: EventType.RUN_ERROR,
719
804
  message: err instanceof Error ? err.message : typeof err === "string" ? err : `AI SDK stream error: ${JSON.stringify(part)}`,
@@ -734,7 +819,11 @@ This is state from the application that you can edit by calling AGUISendStateSna
734
819
  const finishedEvent = {
735
820
  type: EventType.RUN_FINISHED,
736
821
  threadId: input.threadId,
737
- runId: input.runId
822
+ runId: input.runId,
823
+ ...pendingInterrupts.length > 0 ? { outcome: {
824
+ type: "interrupt",
825
+ interrupts: pendingInterrupts
826
+ } } : {}
738
827
  };
739
828
  subscriber.next(finishedEvent);
740
829
  }
@@ -779,17 +868,40 @@ This is state from the application that you can edit by calling AGUISendStateSna
779
868
  const ctx = {
780
869
  input,
781
870
  abortController: controller,
782
- abortSignal: controller.signal
871
+ abortSignal: controller.signal,
872
+ interrupt: async (interrupts) => {
873
+ const resume = input.resume ?? [];
874
+ const ids = new Set(interrupts.map((i) => i.id));
875
+ const matching = resume.filter((r) => ids.has(r.interruptId));
876
+ if (interrupts.length > 0 && matching.length === interrupts.length) return matching;
877
+ throw new InterruptSignal(interrupts);
878
+ }
879
+ };
880
+ const answeredToolCallIds = new Set(input.messages.filter((m) => m.role === "tool").map((m) => m.toolCallId).filter((id) => typeof id === "string"));
881
+ const resumeToolMessages = (input.resume ?? []).filter((entry) => !answeredToolCallIds.has(entry.interruptId)).map((entry) => ({
882
+ id: randomUUID(),
883
+ role: "tool",
884
+ toolCallId: entry.interruptId,
885
+ content: JSON.stringify(entry.status === "cancelled" ? { status: "cancelled" } : entry.payload ?? { status: "resolved" })
886
+ }));
887
+ const factoryInput = resumeToolMessages.length > 0 && config.type !== "custom" ? {
888
+ ...input,
889
+ messages: [...input.messages, ...resumeToolMessages]
890
+ } : input;
891
+ const factoryCtx = {
892
+ ...ctx,
893
+ input: factoryInput
783
894
  };
784
895
  (async () => {
785
896
  try {
786
897
  let events;
898
+ const pendingInterrupts = [];
787
899
  switch (config.type) {
788
900
  case "aisdk":
789
- events = convertAISDKStream((await config.factory(ctx)).fullStream, controller.signal);
901
+ events = convertAISDKStream((await config.factory(factoryCtx)).fullStream, controller.signal, pendingInterrupts);
790
902
  break;
791
903
  case "tanstack":
792
- events = convertTanStackStream(await config.factory(ctx), controller.signal);
904
+ events = convertTanStackStream(await config.factory(factoryCtx), controller.signal, pendingInterrupts);
793
905
  break;
794
906
  case "custom":
795
907
  events = await config.factory(ctx);
@@ -800,6 +912,7 @@ This is state from the application that you can edit by calling AGUISendStateSna
800
912
  }
801
913
  }
802
914
  for await (const event of events) subscriber.next(event);
915
+ if (pendingInterrupts.length > 0 && !controller.signal.aborted) throw new InterruptSignal(pendingInterrupts);
803
916
  if (!controller.signal.aborted) {
804
917
  const finishedEvent = {
805
918
  type: EventType.RUN_FINISHED,
@@ -810,7 +923,19 @@ This is state from the application that you can edit by calling AGUISendStateSna
810
923
  }
811
924
  subscriber.complete();
812
925
  } catch (error) {
813
- if (controller.signal.aborted) subscriber.complete();
926
+ if (error instanceof InterruptSignal) {
927
+ const finishedEvent = {
928
+ type: EventType.RUN_FINISHED,
929
+ threadId: input.threadId,
930
+ runId: input.runId,
931
+ outcome: {
932
+ type: "interrupt",
933
+ interrupts: error.interrupts
934
+ }
935
+ };
936
+ subscriber.next(finishedEvent);
937
+ subscriber.complete();
938
+ } else if (controller.signal.aborted) subscriber.complete();
814
939
  else {
815
940
  const runErrorEvent = {
816
941
  type: EventType.RUN_ERROR,
@@ -850,5 +975,5 @@ var BasicAgent = class extends BuiltInAgent {
850
975
  };
851
976
 
852
977
  //#endregion
853
- export { BasicAgent, BuiltInAgent, convertJsonSchemaToZodSchema$1 as convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, defineTool, resolveModel };
978
+ export { BasicAgent, BuiltInAgent, InterruptSignal, convertJsonSchemaToZodSchema$1 as convertJsonSchemaToZodSchema, convertMessagesToVercelAISDKMessages, convertToolDefinitionsToVercelAITools, convertToolsToVercelAITools, defineTool, resolveModel };
854
979
  //# sourceMappingURL=index.mjs.map