@tanstack/ai 0.45.1 → 0.47.1

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 (82) hide show
  1. package/dist/esm/activities/chat/index.d.ts +36 -11
  2. package/dist/esm/activities/chat/index.js +462 -66
  3. package/dist/esm/activities/chat/index.js.map +1 -1
  4. package/dist/esm/activities/chat/messages.d.ts +1 -0
  5. package/dist/esm/activities/chat/messages.js +12 -7
  6. package/dist/esm/activities/chat/messages.js.map +1 -1
  7. package/dist/esm/activities/chat/middleware/builder.d.ts +7 -2
  8. package/dist/esm/activities/chat/middleware/builder.js.map +1 -1
  9. package/dist/esm/activities/chat/middleware/compose.d.ts +10 -3
  10. package/dist/esm/activities/chat/middleware/compose.js +55 -0
  11. package/dist/esm/activities/chat/middleware/compose.js.map +1 -1
  12. package/dist/esm/activities/chat/middleware/define.d.ts +6 -3
  13. package/dist/esm/activities/chat/middleware/define.js.map +1 -1
  14. package/dist/esm/activities/chat/middleware/generic-interrupts.d.ts +13 -0
  15. package/dist/esm/activities/chat/middleware/generic-interrupts.js +8 -0
  16. package/dist/esm/activities/chat/middleware/generic-interrupts.js.map +1 -0
  17. package/dist/esm/activities/chat/middleware/index.d.ts +4 -1
  18. package/dist/esm/activities/chat/middleware/types.d.ts +54 -3
  19. package/dist/esm/activities/chat/middleware/types.js +16 -0
  20. package/dist/esm/activities/chat/middleware/types.js.map +1 -0
  21. package/dist/esm/activities/chat/stream/processor.js +18 -5
  22. package/dist/esm/activities/chat/stream/processor.js.map +1 -1
  23. package/dist/esm/activities/chat/tools/unique-tool-names.d.ts +20 -0
  24. package/dist/esm/activities/chat/tools/unique-tool-names.js +57 -0
  25. package/dist/esm/activities/chat/tools/unique-tool-names.js.map +1 -0
  26. package/dist/esm/adapter-internals.d.ts +7 -0
  27. package/dist/esm/adapter-internals.js +5 -1
  28. package/dist/esm/client.d.ts +4 -0
  29. package/dist/esm/client.js +3 -1
  30. package/dist/esm/client.js.map +1 -1
  31. package/dist/esm/generic-interrupt-continuation.d.ts +45 -0
  32. package/dist/esm/generic-interrupt-continuation.js +80 -0
  33. package/dist/esm/generic-interrupt-continuation.js.map +1 -0
  34. package/dist/esm/index.d.ts +9 -1
  35. package/dist/esm/index.js +7 -2
  36. package/dist/esm/interrupt-definition.d.ts +113 -0
  37. package/dist/esm/interrupt-definition.js +169 -0
  38. package/dist/esm/interrupt-definition.js.map +1 -0
  39. package/dist/esm/interrupt-resume.d.ts +3 -0
  40. package/dist/esm/interrupt-resume.js +77 -16
  41. package/dist/esm/interrupt-resume.js.map +1 -1
  42. package/dist/esm/interrupts.d.ts +12 -3
  43. package/dist/esm/interrupts.js.map +1 -1
  44. package/dist/esm/middlewares/usage-attributes.d.ts +2 -2
  45. package/dist/esm/middlewares/usage-attributes.js +9 -2
  46. package/dist/esm/middlewares/usage-attributes.js.map +1 -1
  47. package/dist/esm/stream-to-response.d.ts +26 -0
  48. package/dist/esm/stream-to-response.js +1 -1
  49. package/dist/esm/stream-to-response.js.map +1 -1
  50. package/dist/esm/stream-to-websocket.d.ts +123 -0
  51. package/dist/esm/stream-to-websocket.js +249 -0
  52. package/dist/esm/stream-to-websocket.js.map +1 -0
  53. package/dist/esm/types.d.ts +19 -10
  54. package/dist/esm/utilities/chat-params.js +10 -1
  55. package/dist/esm/utilities/chat-params.js.map +1 -1
  56. package/package.json +2 -2
  57. package/skills/ai-core/media-generation/SKILL.md +13 -9
  58. package/skills/ai-core/middleware/SKILL.md +53 -44
  59. package/skills/ai-core/structured-outputs/SKILL.md +59 -55
  60. package/skills/ai-core/tool-calling/SKILL.md +54 -1
  61. package/src/activities/chat/index.ts +1076 -194
  62. package/src/activities/chat/messages.ts +11 -3
  63. package/src/activities/chat/middleware/builder.ts +29 -4
  64. package/src/activities/chat/middleware/compose.ts +95 -5
  65. package/src/activities/chat/middleware/define.ts +13 -3
  66. package/src/activities/chat/middleware/generic-interrupts.ts +26 -0
  67. package/src/activities/chat/middleware/index.ts +15 -0
  68. package/src/activities/chat/middleware/types.ts +127 -2
  69. package/src/activities/chat/stream/processor.ts +21 -0
  70. package/src/activities/chat/tools/unique-tool-names.ts +73 -0
  71. package/src/adapter-internals.ts +24 -0
  72. package/src/client.ts +20 -0
  73. package/src/generic-interrupt-continuation.ts +162 -0
  74. package/src/index.ts +51 -0
  75. package/src/interrupt-definition.ts +581 -0
  76. package/src/interrupt-resume.ts +156 -25
  77. package/src/interrupts.ts +13 -3
  78. package/src/middlewares/usage-attributes.ts +12 -2
  79. package/src/stream-to-response.ts +2 -2
  80. package/src/stream-to-websocket.ts +418 -0
  81. package/src/types.ts +21 -8
  82. package/src/utilities/chat-params.ts +16 -3
@@ -0,0 +1,57 @@
1
+ //#region src/activities/chat/tools/unique-tool-names.ts
2
+ /**
3
+ * Thrown when `chat({ tools })` (or a provider converter) receives two tools
4
+ * with the same public `name`.
5
+ *
6
+ * The common case is a provider-native factory (`webSearchTool()`) next to an
7
+ * ordinary function that reused the reserved name (`web_search`). Providers
8
+ * reject that pair, so we fail before the request is built.
9
+ */
10
+ var DuplicateToolNameError = class extends Error {
11
+ toolName;
12
+ constructor(toolName, message) {
13
+ super(message);
14
+ this.name = "DuplicateToolNameError";
15
+ this.toolName = toolName;
16
+ }
17
+ };
18
+ function isProviderNativeTool(tool) {
19
+ const kind = tool.metadata?.["__kind"];
20
+ return typeof kind === "string" && kind.length > 0;
21
+ }
22
+ function nativeAndCustomMessage(toolName) {
23
+ return [
24
+ `Cannot pass two tools named "${toolName}" in the same chat() call.`,
25
+ `One is the provider-native tool from a factory (for example webSearchTool()).`,
26
+ `The other is your own function with the same public name.`,
27
+ `Tool names in one tools array must be unique.`,
28
+ `Keep the factory for hosted search, or keep your function and give it a different name.`
29
+ ].join(" ");
30
+ }
31
+ function duplicateNameMessage(toolName) {
32
+ return [`Cannot pass two tools named "${toolName}" in the same chat() call.`, `Tool names in one tools array must be unique.`].join(" ");
33
+ }
34
+ /**
35
+ * Throws {@link DuplicateToolNameError} when two tools share a public name.
36
+ *
37
+ * The native-vs-custom message fires when one of the colliding tools carries
38
+ * adapter `metadata.__kind` (set by a provider factory) and another does not.
39
+ */
40
+ function assertUniqueToolNames(tools) {
41
+ const byName = /* @__PURE__ */ new Map();
42
+ for (const tool of tools) {
43
+ const group = byName.get(tool.name);
44
+ if (group) group.push(tool);
45
+ else byName.set(tool.name, [tool]);
46
+ }
47
+ for (const [name, group] of byName) {
48
+ if (group.length < 2) continue;
49
+ const hasNative = group.some(isProviderNativeTool);
50
+ const hasCustom = group.some((tool) => !isProviderNativeTool(tool));
51
+ throw new DuplicateToolNameError(name, hasNative && hasCustom ? nativeAndCustomMessage(name) : duplicateNameMessage(name));
52
+ }
53
+ }
54
+ //#endregion
55
+ export { DuplicateToolNameError, assertUniqueToolNames };
56
+
57
+ //# sourceMappingURL=unique-tool-names.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unique-tool-names.js","names":[],"sources":["../../../../../src/activities/chat/tools/unique-tool-names.ts"],"sourcesContent":["import type { Tool } from '../../../types'\n\n/**\n * Thrown when `chat({ tools })` (or a provider converter) receives two tools\n * with the same public `name`.\n *\n * The common case is a provider-native factory (`webSearchTool()`) next to an\n * ordinary function that reused the reserved name (`web_search`). Providers\n * reject that pair, so we fail before the request is built.\n */\nexport class DuplicateToolNameError extends Error {\n readonly toolName: string\n\n constructor(toolName: string, message: string) {\n super(message)\n this.name = 'DuplicateToolNameError'\n this.toolName = toolName\n }\n}\n\nfunction isProviderNativeTool(tool: Tool): boolean {\n const kind = tool.metadata?.['__kind']\n return typeof kind === 'string' && kind.length > 0\n}\n\nfunction nativeAndCustomMessage(toolName: string) {\n return [\n `Cannot pass two tools named \"${toolName}\" in the same chat() call.`,\n `One is the provider-native tool from a factory (for example webSearchTool()).`,\n `The other is your own function with the same public name.`,\n `Tool names in one tools array must be unique.`,\n `Keep the factory for hosted search, or keep your function and give it a different name.`,\n ].join(' ')\n}\n\nfunction duplicateNameMessage(toolName: string) {\n return [\n `Cannot pass two tools named \"${toolName}\" in the same chat() call.`,\n `Tool names in one tools array must be unique.`,\n ].join(' ')\n}\n\n/**\n * Throws {@link DuplicateToolNameError} when two tools share a public name.\n *\n * The native-vs-custom message fires when one of the colliding tools carries\n * adapter `metadata.__kind` (set by a provider factory) and another does not.\n */\nexport function assertUniqueToolNames(tools: ReadonlyArray<Tool>): void {\n const byName = new Map<string, Array<Tool>>()\n for (const tool of tools) {\n const group = byName.get(tool.name)\n if (group) {\n group.push(tool)\n } else {\n byName.set(tool.name, [tool])\n }\n }\n\n for (const [name, group] of byName) {\n if (group.length < 2) {\n continue\n }\n const hasNative = group.some(isProviderNativeTool)\n const hasCustom = group.some((tool) => !isProviderNativeTool(tool))\n throw new DuplicateToolNameError(\n name,\n hasNative && hasCustom\n ? nativeAndCustomMessage(name)\n : duplicateNameMessage(name),\n )\n }\n}\n"],"mappings":";;;;;;;;;AAUA,IAAa,yBAAb,cAA4C,MAAM;CAChD;CAEA,YAAY,UAAkB,SAAiB;EAC7C,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,WAAW;CAClB;AACF;AAEA,SAAS,qBAAqB,MAAqB;CACjD,MAAM,OAAO,KAAK,WAAW;CAC7B,OAAO,OAAO,SAAS,YAAY,KAAK,SAAS;AACnD;AAEA,SAAS,uBAAuB,UAAkB;CAChD,OAAO;EACL,gCAAgC,SAAS;EACzC;EACA;EACA;EACA;CACF,CAAC,CAAC,KAAK,GAAG;AACZ;AAEA,SAAS,qBAAqB,UAAkB;CAC9C,OAAO,CACL,gCAAgC,SAAS,6BACzC,+CACF,CAAC,CAAC,KAAK,GAAG;AACZ;;;;;;;AAQA,SAAgB,sBAAsB,OAAkC;CACtE,MAAM,yBAAS,IAAI,IAAyB;CAC5C,KAAK,MAAM,QAAQ,OAAO;EACxB,MAAM,QAAQ,OAAO,IAAI,KAAK,IAAI;EAClC,IAAI,OACF,MAAM,KAAK,IAAI;OAEf,OAAO,IAAI,KAAK,MAAM,CAAC,IAAI,CAAC;CAEhC;CAEA,KAAK,MAAM,CAAC,MAAM,UAAU,QAAQ;EAClC,IAAI,MAAM,SAAS,GACjB;EAEF,MAAM,YAAY,MAAM,KAAK,oBAAoB;EACjD,MAAM,YAAY,MAAM,MAAM,SAAS,CAAC,qBAAqB,IAAI,CAAC;EAClE,MAAM,IAAI,uBACR,MACA,aAAa,YACT,uBAAuB,IAAI,IAC3B,qBAAqB,IAAI,CAC/B;CACF;AACF"}
@@ -6,5 +6,12 @@ export { toRunErrorPayload, toRunErrorRawEvent, } from './activities/error-paylo
6
6
  export { getSandboxRuntime, provideSandboxRuntime, SandboxRuntimeCapability, } from './activities/chat/middleware/sandbox-runtime.js';
7
7
  export { getRunDisconnect, provideRunDisconnect, RunDisconnectCapability, } from './activities/chat/middleware/run-disconnect.js';
8
8
  export { getPendingTurn, PendingTurnCapability, providePendingTurn, } from './activities/chat/middleware/pending-turn.js';
9
+ export { getGenericInterruptDefinitionRegistry, GenericInterruptDefinitionRegistryCapability, provideGenericInterruptDefinitionRegistry, } from './activities/chat/middleware/generic-interrupts.js';
10
+ export type { GenericInterruptDefinitionRegistry } from './activities/chat/middleware/generic-interrupts.js';
11
+ export { createInterruptBinding, getInterruptRequestInput, rehydrateInterruptRequest, } from './interrupt-definition.js';
12
+ export type { GenericInterruptRequest, InterruptDefinition, } from './interrupt-definition.js';
13
+ export { readInterruptBinding, validateInterruptResumeBatch, } from './interrupt-resume.js';
14
+ export type { PendingInterruptResumeRecord } from './interrupt-resume.js';
15
+ export { assertUniqueToolNames, DuplicateToolNameError, } from './activities/chat/tools/unique-tool-names.js';
9
16
  export { appendOutputSchemaInstruction, parseJsonFromAssistantText, } from './utilities/structured-output-text.js';
10
17
  export { structuredOutputCompleteChunk, structuredOutputStartChunk, } from './utilities/structured-output-events.js';
@@ -1,9 +1,13 @@
1
1
  import { toRunErrorPayload, toRunErrorRawEvent } from "./activities/error-payload.js";
2
2
  import { InternalLogger } from "./logger/internal-logger.js";
3
3
  import { resolveDebugOption } from "./logger/resolve.js";
4
+ import { readInterruptBinding, validateInterruptResumeBatch } from "./interrupt-resume.js";
5
+ import { createInterruptBinding, getInterruptRequestInput, rehydrateInterruptRequest } from "./interrupt-definition.js";
6
+ import { DuplicateToolNameError, assertUniqueToolNames } from "./activities/chat/tools/unique-tool-names.js";
4
7
  import { SandboxRuntimeCapability, getSandboxRuntime, provideSandboxRuntime } from "./activities/chat/middleware/sandbox-runtime.js";
5
8
  import { RunDisconnectCapability, getRunDisconnect, provideRunDisconnect } from "./activities/chat/middleware/run-disconnect.js";
9
+ import { GenericInterruptDefinitionRegistryCapability, getGenericInterruptDefinitionRegistry, provideGenericInterruptDefinitionRegistry } from "./activities/chat/middleware/generic-interrupts.js";
6
10
  import { PendingTurnCapability, getPendingTurn, providePendingTurn } from "./activities/chat/middleware/pending-turn.js";
7
11
  import { appendOutputSchemaInstruction, parseJsonFromAssistantText } from "./utilities/structured-output-text.js";
8
12
  import { structuredOutputCompleteChunk, structuredOutputStartChunk } from "./utilities/structured-output-events.js";
9
- export { InternalLogger, PendingTurnCapability, RunDisconnectCapability, SandboxRuntimeCapability, appendOutputSchemaInstruction, getPendingTurn, getRunDisconnect, getSandboxRuntime, parseJsonFromAssistantText, providePendingTurn, provideRunDisconnect, provideSandboxRuntime, resolveDebugOption, structuredOutputCompleteChunk, structuredOutputStartChunk, toRunErrorPayload, toRunErrorRawEvent };
13
+ export { DuplicateToolNameError, GenericInterruptDefinitionRegistryCapability, InternalLogger, PendingTurnCapability, RunDisconnectCapability, SandboxRuntimeCapability, appendOutputSchemaInstruction, assertUniqueToolNames, createInterruptBinding, getGenericInterruptDefinitionRegistry, getInterruptRequestInput, getPendingTurn, getRunDisconnect, getSandboxRuntime, parseJsonFromAssistantText, provideGenericInterruptDefinitionRegistry, providePendingTurn, provideRunDisconnect, provideSandboxRuntime, readInterruptBinding, rehydrateInterruptRequest, resolveDebugOption, structuredOutputCompleteChunk, structuredOutputStartChunk, toRunErrorPayload, toRunErrorRawEvent, validateInterruptResumeBatch };
@@ -61,6 +61,10 @@ export { uiMessagesToWire } from './utilities/ag-ui-wire.js';
61
61
  export type { WireMessage } from './utilities/ag-ui-wire.js';
62
62
  export type { AudioPart, ContentPart, ContentPartDataSource, ContentPartSource, ContentPartUrlSource, CustomEvent, DocumentPart, ImagePart, MediaInputMetadata, MediaInputRole, MediaPrompt, MediaPromptPart, MessagePart, ModelMessage, PersistedArtifactActivity, PersistedArtifactRef, PersistedArtifactRole, Interrupt, RunAgentResumeItem, RunErrorEvent, RunFinishedEvent, RunFinishedOutcome, SchemaInput, StreamChunk, StructuredOutputPart, TextPart, ThinkingPart, ToolCall, ToolCallPart, ToolResultPart, UIMessage, UIResourcePart, VideoPart, InferSchemaType, } from './types.js';
63
63
  export { INTERRUPT_BINDING_VERSION, canonicalizeInterruptResolutions, } from './interrupts.js';
64
+ export { defineInterrupt, hashInterruptDefinitionSchema, INTERRUPT_PAYLOAD_METADATA_KEY, } from './interrupt-definition.js';
65
+ export { INTERRUPT_CONTINUATION_METADATA_KEY, INTERRUPT_CONTINUATION_VERSION, genericInterruptContinuationFromDescriptor, readGenericInterruptContinuation, wrapGenericInterruptContinuation, } from './generic-interrupt-continuation.js';
66
+ export type { GenericInterruptContinuation, GenericInterruptContinuationReadResult, } from './generic-interrupt-continuation.js';
67
+ export type { GenericInterruptRequest, InterruptDefinition, } from './interrupt-definition.js';
64
68
  export type { BatchInterruptError, BatchInterruptErrorCode, InterruptBinding, InterruptCorrelation, InterruptSubmissionError, ItemInterruptError, ItemInterruptErrorCode, ToolApprovalResolution, UnopenedInterruptBinding, } from './interrupts.js';
65
69
  export { INTERRUPT_BINDING_METADATA_KEY, readInterruptBinding, readUnopenedInterruptBinding, withInterruptBinding, withoutInterruptBinding, } from './interrupt-resume.js';
66
70
  export type { AudioVisualization, RealtimeAdapter, RealtimeConnection, RealtimeError, RealtimeErrorCode, RealtimeEvent, RealtimeEventHandler, RealtimeEventPayloads, RealtimeMessage, RealtimeMessagePart, RealtimeMode, RealtimeSessionConfig, RealtimeStatus, RealtimeToken, RealtimeAudioPart, RealtimeImagePart, RealtimeTextPart, RealtimeToolCallPart, RealtimeToolResultPart, VADConfig, } from './realtime/types.js';
@@ -3,6 +3,8 @@ import { INTERRUPT_BINDING_VERSION, canonicalizeInterruptResolutions } from "./i
3
3
  import { convertSchemaToJsonSchema, isStandardSchema, parseWithStandardSchema, validateWithStandardSchema } from "./activities/chat/tools/schema-converter.js";
4
4
  import { hashSchemaInput, normalizeApprovalSchema } from "./activities/chat/tools/approval-schema.js";
5
5
  import { INTERRUPT_BINDING_METADATA_KEY, readInterruptBinding, readUnopenedInterruptBinding, withInterruptBinding, withoutInterruptBinding } from "./interrupt-resume.js";
6
+ import { INTERRUPT_PAYLOAD_METADATA_KEY, defineInterrupt, hashInterruptDefinitionSchema } from "./interrupt-definition.js";
7
+ import { INTERRUPT_CONTINUATION_METADATA_KEY, INTERRUPT_CONTINUATION_VERSION, genericInterruptContinuationFromDescriptor, readGenericInterruptContinuation, wrapGenericInterruptContinuation } from "./generic-interrupt-continuation.js";
6
8
  import { convertMessagesToModelMessages, generateMessageId, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, uiMessageToModelMessages } from "./activities/chat/messages.js";
7
9
  import { toolDefinition } from "./activities/chat/tools/tool-definition.js";
8
10
  import { PartialJSONParser, defaultJSONParser, parsePartialJSON } from "./activities/chat/stream/json-parser.js";
@@ -129,6 +131,6 @@ var EventType = /* @__PURE__ */ function(EventType) {
129
131
  return EventType;
130
132
  }({});
131
133
  //#endregion
132
- export { BatchStrategy, CompositeStrategy, EventType, INTERRUPT_BINDING_METADATA_KEY, INTERRUPT_BINDING_VERSION, ImmediateStrategy, PartialJSONParser, PunctuationStrategy, StreamProcessor, WordBoundaryStrategy, canonicalInterruptJson, canonicalizeInterruptResolutions, cloneAndDeepFreezeJson, convertMessagesToModelMessages, convertSchemaToJsonSchema, defaultJSONParser, digestInterruptJson, generateMessageId, generationParamsFromBody, generationParamsFromRequest, hashSchemaInput, isStandardSchema, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeApprovalSchema, normalizeToUIMessage, parsePartialJSON, parseWithStandardSchema, readInterruptBinding, readUnopenedInterruptBinding, toolDefinition, uiMessageToModelMessages, uiMessagesToWire, validateWithStandardSchema, withInterruptBinding, withoutInterruptBinding };
134
+ export { BatchStrategy, CompositeStrategy, EventType, INTERRUPT_BINDING_METADATA_KEY, INTERRUPT_BINDING_VERSION, INTERRUPT_CONTINUATION_METADATA_KEY, INTERRUPT_CONTINUATION_VERSION, INTERRUPT_PAYLOAD_METADATA_KEY, ImmediateStrategy, PartialJSONParser, PunctuationStrategy, StreamProcessor, WordBoundaryStrategy, canonicalInterruptJson, canonicalizeInterruptResolutions, cloneAndDeepFreezeJson, convertMessagesToModelMessages, convertSchemaToJsonSchema, defaultJSONParser, defineInterrupt, digestInterruptJson, generateMessageId, generationParamsFromBody, generationParamsFromRequest, genericInterruptContinuationFromDescriptor, hashInterruptDefinitionSchema, hashSchemaInput, isStandardSchema, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeApprovalSchema, normalizeToUIMessage, parsePartialJSON, parseWithStandardSchema, readGenericInterruptContinuation, readInterruptBinding, readUnopenedInterruptBinding, toolDefinition, uiMessageToModelMessages, uiMessagesToWire, validateWithStandardSchema, withInterruptBinding, withoutInterruptBinding, wrapGenericInterruptContinuation };
133
135
 
134
136
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","names":[],"sources":["../../src/client.ts"],"sourcesContent":["import type {\n AudioGenerationOptions,\n ImageGenerationOptions,\n TTSOptions,\n TranscriptionOptions,\n VideoGenerationOptions,\n} from './types'\n\nexport type GenerationKind =\n | 'image'\n | 'audio'\n | 'tts'\n | 'video'\n | 'transcription'\n\ntype GenerationInputByKind = {\n image: Omit<ImageGenerationOptions, 'logger' | 'model'>\n audio: Omit<AudioGenerationOptions, 'logger' | 'model'>\n tts: Omit<TTSOptions, 'logger' | 'model'>\n video: Omit<VideoGenerationOptions, 'logger' | 'model'>\n transcription: Omit<TranscriptionOptions, 'logger' | 'model'>\n}\n\nexport interface GenerationParams<TKind extends GenerationKind> {\n input: GenerationInputByKind[TKind]\n forwardedProps: Record<string, unknown>\n threadId?: string\n runId?: string\n}\n\nconst generationKinds = [\n 'image',\n 'audio',\n 'tts',\n 'video',\n 'transcription',\n] as const satisfies ReadonlyArray<GenerationKind>\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction hasOwnKey(value: Record<string, unknown>, key: string): boolean {\n return Object.prototype.hasOwnProperty.call(value, key)\n}\n\nfunction isGenerationEnvelope(body: unknown): body is Record<string, unknown> {\n return (\n isRecord(body) &&\n (hasOwnKey(body, 'data') || hasOwnKey(body, 'forwardedProps'))\n )\n}\n\nfunction assertGenerationKind(kind: unknown): asserts kind is GenerationKind {\n if (!generationKinds.includes(kind as GenerationKind)) {\n throw new Error(\n `Unsupported generation kind: ${String(\n kind,\n )}. Expected one of ${generationKinds.join(', ')}.`,\n )\n }\n}\n\nfunction assertInputForKind(\n kind: GenerationKind,\n input: unknown,\n): asserts input is GenerationInputByKind[GenerationKind] {\n if (!isRecord(input)) {\n throw new Error(`Generation ${kind} input must be an object.`)\n }\n\n const requiredKey =\n kind === 'tts' ? 'text' : kind === 'transcription' ? 'audio' : 'prompt'\n\n if (!hasOwnKey(input, requiredKey)) {\n throw new Error(`Generation ${kind} input must include ${requiredKey}.`)\n }\n}\n\nfunction isInputForKind(kind: GenerationKind, input: unknown): boolean {\n if (!isRecord(input)) return false\n\n const requiredKey =\n kind === 'tts' ? 'text' : kind === 'transcription' ? 'audio' : 'prompt'\n\n return hasOwnKey(input, requiredKey)\n}\n\nfunction forwardedPropsFromEnvelope(\n envelope: Record<string, unknown>,\n): Record<string, unknown> {\n if (!hasOwnKey(envelope, 'forwardedProps')) {\n return {}\n }\n\n if (!isRecord(envelope.forwardedProps)) {\n throw new Error('Generation envelope forwardedProps must be an object.')\n }\n\n return envelope.forwardedProps\n}\n\nfunction optionalStringField(\n envelope: Record<string, unknown>,\n key: 'threadId' | 'runId',\n): string | undefined {\n if (!hasOwnKey(envelope, key)) {\n return undefined\n }\n\n const value = envelope[key]\n if (typeof value !== 'string') {\n throw new Error(`Generation envelope ${key} must be a string.`)\n }\n\n return value\n}\n\nfunction generationIdentityFields(envelope: Record<string, unknown>): {\n threadId?: string\n runId?: string\n} {\n const identity: {\n threadId?: string\n runId?: string\n } = {}\n const threadId = optionalStringField(envelope, 'threadId')\n const runId = optionalStringField(envelope, 'runId')\n\n if (threadId !== undefined) identity.threadId = threadId\n if (runId !== undefined) identity.runId = runId\n\n return identity\n}\n\nexport function generationParamsFromBody<TKind extends GenerationKind>(\n kind: TKind,\n body: unknown,\n): GenerationParams<TKind> {\n assertGenerationKind(kind)\n\n if (isInputForKind(kind, body)) {\n assertInputForKind(kind, body)\n return {\n input: body as GenerationInputByKind[TKind],\n forwardedProps: {},\n }\n }\n\n if (!isGenerationEnvelope(body)) {\n assertInputForKind(kind, body)\n return {\n input: body as GenerationInputByKind[TKind],\n forwardedProps: {},\n }\n }\n\n if (!hasOwnKey(body, 'data')) {\n throw new Error(`Generation ${kind} envelope must include data.`)\n }\n\n const input = body.data\n assertInputForKind(kind, input)\n\n const forwardedProps = forwardedPropsFromEnvelope(body)\n\n return {\n input: input as GenerationInputByKind[TKind],\n forwardedProps,\n ...generationIdentityFields(body),\n }\n}\n\nexport async function generationParamsFromRequest<TKind extends GenerationKind>(\n kind: TKind,\n request: Request,\n): Promise<GenerationParams<TKind>> {\n let body: unknown\n try {\n body = await request.json()\n } catch (error) {\n throw new Error('Invalid JSON request body.', { cause: error })\n }\n\n if (!isRecord(body)) {\n throw new Error('Generation request body must be a JSON object.')\n }\n\n return generationParamsFromBody(kind, body)\n}\n\nexport enum EventType {\n TEXT_MESSAGE_START = 'TEXT_MESSAGE_START',\n TEXT_MESSAGE_CONTENT = 'TEXT_MESSAGE_CONTENT',\n TEXT_MESSAGE_END = 'TEXT_MESSAGE_END',\n TEXT_MESSAGE_CHUNK = 'TEXT_MESSAGE_CHUNK',\n TOOL_CALL_START = 'TOOL_CALL_START',\n TOOL_CALL_ARGS = 'TOOL_CALL_ARGS',\n TOOL_CALL_END = 'TOOL_CALL_END',\n TOOL_CALL_CHUNK = 'TOOL_CALL_CHUNK',\n TOOL_CALL_RESULT = 'TOOL_CALL_RESULT',\n THINKING_START = 'THINKING_START',\n THINKING_END = 'THINKING_END',\n THINKING_TEXT_MESSAGE_START = 'THINKING_TEXT_MESSAGE_START',\n THINKING_TEXT_MESSAGE_CONTENT = 'THINKING_TEXT_MESSAGE_CONTENT',\n THINKING_TEXT_MESSAGE_END = 'THINKING_TEXT_MESSAGE_END',\n STATE_SNAPSHOT = 'STATE_SNAPSHOT',\n STATE_DELTA = 'STATE_DELTA',\n MESSAGES_SNAPSHOT = 'MESSAGES_SNAPSHOT',\n ACTIVITY_SNAPSHOT = 'ACTIVITY_SNAPSHOT',\n ACTIVITY_DELTA = 'ACTIVITY_DELTA',\n RAW = 'RAW',\n CUSTOM = 'CUSTOM',\n RUN_STARTED = 'RUN_STARTED',\n RUN_FINISHED = 'RUN_FINISHED',\n RUN_ERROR = 'RUN_ERROR',\n STEP_STARTED = 'STEP_STARTED',\n STEP_FINISHED = 'STEP_FINISHED',\n REASONING_START = 'REASONING_START',\n REASONING_MESSAGE_START = 'REASONING_MESSAGE_START',\n REASONING_MESSAGE_CONTENT = 'REASONING_MESSAGE_CONTENT',\n REASONING_MESSAGE_END = 'REASONING_MESSAGE_END',\n REASONING_MESSAGE_CHUNK = 'REASONING_MESSAGE_CHUNK',\n REASONING_END = 'REASONING_END',\n REASONING_ENCRYPTED_VALUE = 'REASONING_ENCRYPTED_VALUE',\n}\n\nexport {\n toolDefinition,\n type AnyClientTool,\n type ClientTool,\n type InferToolInput,\n type InferToolName,\n type InferToolOutput,\n type ApprovalCapabilityOf,\n type ApprovalSchemaConfig,\n type ApprovalSchemaOf,\n type InputSchemaOf,\n type OutputSchemaOf,\n type NoSchema,\n type ToolDefinition,\n type ToolDefinitionConfig,\n type ToolDefinitionInstance,\n} from './activities/chat/tools/tool-definition'\n\nexport {\n hashSchemaInput,\n normalizeApprovalSchema,\n type NormalizedApprovalSchema,\n type NormalizedSchemaInput,\n} from './activities/chat/tools/approval-schema'\n\nexport {\n canonicalInterruptJson,\n cloneAndDeepFreezeJson,\n digestInterruptJson,\n} from './interrupt-serialization'\n\nexport {\n convertSchemaToJsonSchema,\n isStandardSchema,\n parseWithStandardSchema,\n validateWithStandardSchema,\n} from './activities/chat/tools/schema-converter'\n\nexport {\n convertMessagesToModelMessages,\n generateMessageId,\n modelMessageToUIMessage,\n modelMessagesToUIMessages,\n normalizeToUIMessage,\n uiMessageToModelMessages,\n} from './activities/chat/messages'\n\nexport {\n BatchStrategy,\n CompositeStrategy,\n defaultJSONParser,\n ImmediateStrategy,\n parsePartialJSON,\n PartialJSONParser,\n PunctuationStrategy,\n StreamProcessor,\n WordBoundaryStrategy,\n} from './activities/chat/stream/index'\nexport type {\n ChunkRecording,\n ChunkStrategy,\n InternalToolCallState,\n JSONParser,\n ProcessorResult,\n ProcessorState,\n StreamProcessorEvents,\n StreamProcessorOptions,\n ToolCallState,\n ToolResultState,\n} from './activities/chat/stream/index'\n\nexport { uiMessagesToWire } from './utilities/ag-ui-wire'\nexport type { WireMessage } from './utilities/ag-ui-wire'\n\nexport type {\n AudioPart,\n ContentPart,\n ContentPartDataSource,\n ContentPartSource,\n ContentPartUrlSource,\n CustomEvent,\n DocumentPart,\n ImagePart,\n MediaInputMetadata,\n MediaInputRole,\n MediaPrompt,\n MediaPromptPart,\n MessagePart,\n ModelMessage,\n PersistedArtifactActivity,\n PersistedArtifactRef,\n PersistedArtifactRole,\n Interrupt,\n RunAgentResumeItem,\n RunErrorEvent,\n RunFinishedEvent,\n RunFinishedOutcome,\n SchemaInput,\n StreamChunk,\n StructuredOutputPart,\n TextPart,\n ThinkingPart,\n ToolCall,\n ToolCallPart,\n ToolResultPart,\n UIMessage,\n UIResourcePart,\n VideoPart,\n InferSchemaType,\n} from './types'\n\n// Enumerated, not `export *` — see the matching note in `index.ts`. The\n// interrupt protocol surface is a commitment, so it is published field by\n// field.\nexport {\n INTERRUPT_BINDING_VERSION,\n canonicalizeInterruptResolutions,\n} from './interrupts'\nexport type {\n BatchInterruptError,\n BatchInterruptErrorCode,\n InterruptBinding,\n InterruptCorrelation,\n InterruptSubmissionError,\n ItemInterruptError,\n ItemInterruptErrorCode,\n ToolApprovalResolution,\n UnopenedInterruptBinding,\n} from './interrupts'\n\nexport {\n INTERRUPT_BINDING_METADATA_KEY,\n readInterruptBinding,\n readUnopenedInterruptBinding,\n withInterruptBinding,\n withoutInterruptBinding,\n} from './interrupt-resume'\n\nexport type {\n AudioVisualization,\n RealtimeAdapter,\n RealtimeConnection,\n RealtimeError,\n RealtimeErrorCode,\n RealtimeEvent,\n RealtimeEventHandler,\n RealtimeEventPayloads,\n RealtimeMessage,\n RealtimeMessagePart,\n RealtimeMode,\n RealtimeSessionConfig,\n RealtimeStatus,\n RealtimeToken,\n RealtimeAudioPart,\n RealtimeImagePart,\n RealtimeTextPart,\n RealtimeToolCallPart,\n RealtimeToolResultPart,\n VADConfig,\n} from './realtime/types'\n"],"mappings":"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"}
1
+ {"version":3,"file":"client.js","names":[],"sources":["../../src/client.ts"],"sourcesContent":["import type {\n AudioGenerationOptions,\n ImageGenerationOptions,\n TTSOptions,\n TranscriptionOptions,\n VideoGenerationOptions,\n} from './types'\n\nexport type GenerationKind =\n | 'image'\n | 'audio'\n | 'tts'\n | 'video'\n | 'transcription'\n\ntype GenerationInputByKind = {\n image: Omit<ImageGenerationOptions, 'logger' | 'model'>\n audio: Omit<AudioGenerationOptions, 'logger' | 'model'>\n tts: Omit<TTSOptions, 'logger' | 'model'>\n video: Omit<VideoGenerationOptions, 'logger' | 'model'>\n transcription: Omit<TranscriptionOptions, 'logger' | 'model'>\n}\n\nexport interface GenerationParams<TKind extends GenerationKind> {\n input: GenerationInputByKind[TKind]\n forwardedProps: Record<string, unknown>\n threadId?: string\n runId?: string\n}\n\nconst generationKinds = [\n 'image',\n 'audio',\n 'tts',\n 'video',\n 'transcription',\n] as const satisfies ReadonlyArray<GenerationKind>\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\nfunction hasOwnKey(value: Record<string, unknown>, key: string): boolean {\n return Object.prototype.hasOwnProperty.call(value, key)\n}\n\nfunction isGenerationEnvelope(body: unknown): body is Record<string, unknown> {\n return (\n isRecord(body) &&\n (hasOwnKey(body, 'data') || hasOwnKey(body, 'forwardedProps'))\n )\n}\n\nfunction assertGenerationKind(kind: unknown): asserts kind is GenerationKind {\n if (!generationKinds.includes(kind as GenerationKind)) {\n throw new Error(\n `Unsupported generation kind: ${String(\n kind,\n )}. Expected one of ${generationKinds.join(', ')}.`,\n )\n }\n}\n\nfunction assertInputForKind(\n kind: GenerationKind,\n input: unknown,\n): asserts input is GenerationInputByKind[GenerationKind] {\n if (!isRecord(input)) {\n throw new Error(`Generation ${kind} input must be an object.`)\n }\n\n const requiredKey =\n kind === 'tts' ? 'text' : kind === 'transcription' ? 'audio' : 'prompt'\n\n if (!hasOwnKey(input, requiredKey)) {\n throw new Error(`Generation ${kind} input must include ${requiredKey}.`)\n }\n}\n\nfunction isInputForKind(kind: GenerationKind, input: unknown): boolean {\n if (!isRecord(input)) return false\n\n const requiredKey =\n kind === 'tts' ? 'text' : kind === 'transcription' ? 'audio' : 'prompt'\n\n return hasOwnKey(input, requiredKey)\n}\n\nfunction forwardedPropsFromEnvelope(\n envelope: Record<string, unknown>,\n): Record<string, unknown> {\n if (!hasOwnKey(envelope, 'forwardedProps')) {\n return {}\n }\n\n if (!isRecord(envelope.forwardedProps)) {\n throw new Error('Generation envelope forwardedProps must be an object.')\n }\n\n return envelope.forwardedProps\n}\n\nfunction optionalStringField(\n envelope: Record<string, unknown>,\n key: 'threadId' | 'runId',\n): string | undefined {\n if (!hasOwnKey(envelope, key)) {\n return undefined\n }\n\n const value = envelope[key]\n if (typeof value !== 'string') {\n throw new Error(`Generation envelope ${key} must be a string.`)\n }\n\n return value\n}\n\nfunction generationIdentityFields(envelope: Record<string, unknown>): {\n threadId?: string\n runId?: string\n} {\n const identity: {\n threadId?: string\n runId?: string\n } = {}\n const threadId = optionalStringField(envelope, 'threadId')\n const runId = optionalStringField(envelope, 'runId')\n\n if (threadId !== undefined) identity.threadId = threadId\n if (runId !== undefined) identity.runId = runId\n\n return identity\n}\n\nexport function generationParamsFromBody<TKind extends GenerationKind>(\n kind: TKind,\n body: unknown,\n): GenerationParams<TKind> {\n assertGenerationKind(kind)\n\n if (isInputForKind(kind, body)) {\n assertInputForKind(kind, body)\n return {\n input: body as GenerationInputByKind[TKind],\n forwardedProps: {},\n }\n }\n\n if (!isGenerationEnvelope(body)) {\n assertInputForKind(kind, body)\n return {\n input: body as GenerationInputByKind[TKind],\n forwardedProps: {},\n }\n }\n\n if (!hasOwnKey(body, 'data')) {\n throw new Error(`Generation ${kind} envelope must include data.`)\n }\n\n const input = body.data\n assertInputForKind(kind, input)\n\n const forwardedProps = forwardedPropsFromEnvelope(body)\n\n return {\n input: input as GenerationInputByKind[TKind],\n forwardedProps,\n ...generationIdentityFields(body),\n }\n}\n\nexport async function generationParamsFromRequest<TKind extends GenerationKind>(\n kind: TKind,\n request: Request,\n): Promise<GenerationParams<TKind>> {\n let body: unknown\n try {\n body = await request.json()\n } catch (error) {\n throw new Error('Invalid JSON request body.', { cause: error })\n }\n\n if (!isRecord(body)) {\n throw new Error('Generation request body must be a JSON object.')\n }\n\n return generationParamsFromBody(kind, body)\n}\n\nexport enum EventType {\n TEXT_MESSAGE_START = 'TEXT_MESSAGE_START',\n TEXT_MESSAGE_CONTENT = 'TEXT_MESSAGE_CONTENT',\n TEXT_MESSAGE_END = 'TEXT_MESSAGE_END',\n TEXT_MESSAGE_CHUNK = 'TEXT_MESSAGE_CHUNK',\n TOOL_CALL_START = 'TOOL_CALL_START',\n TOOL_CALL_ARGS = 'TOOL_CALL_ARGS',\n TOOL_CALL_END = 'TOOL_CALL_END',\n TOOL_CALL_CHUNK = 'TOOL_CALL_CHUNK',\n TOOL_CALL_RESULT = 'TOOL_CALL_RESULT',\n THINKING_START = 'THINKING_START',\n THINKING_END = 'THINKING_END',\n THINKING_TEXT_MESSAGE_START = 'THINKING_TEXT_MESSAGE_START',\n THINKING_TEXT_MESSAGE_CONTENT = 'THINKING_TEXT_MESSAGE_CONTENT',\n THINKING_TEXT_MESSAGE_END = 'THINKING_TEXT_MESSAGE_END',\n STATE_SNAPSHOT = 'STATE_SNAPSHOT',\n STATE_DELTA = 'STATE_DELTA',\n MESSAGES_SNAPSHOT = 'MESSAGES_SNAPSHOT',\n ACTIVITY_SNAPSHOT = 'ACTIVITY_SNAPSHOT',\n ACTIVITY_DELTA = 'ACTIVITY_DELTA',\n RAW = 'RAW',\n CUSTOM = 'CUSTOM',\n RUN_STARTED = 'RUN_STARTED',\n RUN_FINISHED = 'RUN_FINISHED',\n RUN_ERROR = 'RUN_ERROR',\n STEP_STARTED = 'STEP_STARTED',\n STEP_FINISHED = 'STEP_FINISHED',\n REASONING_START = 'REASONING_START',\n REASONING_MESSAGE_START = 'REASONING_MESSAGE_START',\n REASONING_MESSAGE_CONTENT = 'REASONING_MESSAGE_CONTENT',\n REASONING_MESSAGE_END = 'REASONING_MESSAGE_END',\n REASONING_MESSAGE_CHUNK = 'REASONING_MESSAGE_CHUNK',\n REASONING_END = 'REASONING_END',\n REASONING_ENCRYPTED_VALUE = 'REASONING_ENCRYPTED_VALUE',\n}\n\nexport {\n toolDefinition,\n type AnyClientTool,\n type ClientTool,\n type InferToolInput,\n type InferToolName,\n type InferToolOutput,\n type ApprovalCapabilityOf,\n type ApprovalSchemaConfig,\n type ApprovalSchemaOf,\n type InputSchemaOf,\n type OutputSchemaOf,\n type NoSchema,\n type ToolDefinition,\n type ToolDefinitionConfig,\n type ToolDefinitionInstance,\n} from './activities/chat/tools/tool-definition'\n\nexport {\n hashSchemaInput,\n normalizeApprovalSchema,\n type NormalizedApprovalSchema,\n type NormalizedSchemaInput,\n} from './activities/chat/tools/approval-schema'\n\nexport {\n canonicalInterruptJson,\n cloneAndDeepFreezeJson,\n digestInterruptJson,\n} from './interrupt-serialization'\n\nexport {\n convertSchemaToJsonSchema,\n isStandardSchema,\n parseWithStandardSchema,\n validateWithStandardSchema,\n} from './activities/chat/tools/schema-converter'\n\nexport {\n convertMessagesToModelMessages,\n generateMessageId,\n modelMessageToUIMessage,\n modelMessagesToUIMessages,\n normalizeToUIMessage,\n uiMessageToModelMessages,\n} from './activities/chat/messages'\n\nexport {\n BatchStrategy,\n CompositeStrategy,\n defaultJSONParser,\n ImmediateStrategy,\n parsePartialJSON,\n PartialJSONParser,\n PunctuationStrategy,\n StreamProcessor,\n WordBoundaryStrategy,\n} from './activities/chat/stream/index'\nexport type {\n ChunkRecording,\n ChunkStrategy,\n InternalToolCallState,\n JSONParser,\n ProcessorResult,\n ProcessorState,\n StreamProcessorEvents,\n StreamProcessorOptions,\n ToolCallState,\n ToolResultState,\n} from './activities/chat/stream/index'\n\nexport { uiMessagesToWire } from './utilities/ag-ui-wire'\nexport type { WireMessage } from './utilities/ag-ui-wire'\n\nexport type {\n AudioPart,\n ContentPart,\n ContentPartDataSource,\n ContentPartSource,\n ContentPartUrlSource,\n CustomEvent,\n DocumentPart,\n ImagePart,\n MediaInputMetadata,\n MediaInputRole,\n MediaPrompt,\n MediaPromptPart,\n MessagePart,\n ModelMessage,\n PersistedArtifactActivity,\n PersistedArtifactRef,\n PersistedArtifactRole,\n Interrupt,\n RunAgentResumeItem,\n RunErrorEvent,\n RunFinishedEvent,\n RunFinishedOutcome,\n SchemaInput,\n StreamChunk,\n StructuredOutputPart,\n TextPart,\n ThinkingPart,\n ToolCall,\n ToolCallPart,\n ToolResultPart,\n UIMessage,\n UIResourcePart,\n VideoPart,\n InferSchemaType,\n} from './types'\n\n// Enumerated, not `export *` — see the matching note in `index.ts`. The\n// interrupt protocol surface is a commitment, so it is published field by\n// field.\nexport {\n INTERRUPT_BINDING_VERSION,\n canonicalizeInterruptResolutions,\n} from './interrupts'\nexport {\n defineInterrupt,\n hashInterruptDefinitionSchema,\n INTERRUPT_PAYLOAD_METADATA_KEY,\n} from './interrupt-definition'\nexport {\n INTERRUPT_CONTINUATION_METADATA_KEY,\n INTERRUPT_CONTINUATION_VERSION,\n genericInterruptContinuationFromDescriptor,\n readGenericInterruptContinuation,\n wrapGenericInterruptContinuation,\n} from './generic-interrupt-continuation'\nexport type {\n GenericInterruptContinuation,\n GenericInterruptContinuationReadResult,\n} from './generic-interrupt-continuation'\nexport type {\n GenericInterruptRequest,\n InterruptDefinition,\n} from './interrupt-definition'\nexport type {\n BatchInterruptError,\n BatchInterruptErrorCode,\n InterruptBinding,\n InterruptCorrelation,\n InterruptSubmissionError,\n ItemInterruptError,\n ItemInterruptErrorCode,\n ToolApprovalResolution,\n UnopenedInterruptBinding,\n} from './interrupts'\n\nexport {\n INTERRUPT_BINDING_METADATA_KEY,\n readInterruptBinding,\n readUnopenedInterruptBinding,\n withInterruptBinding,\n withoutInterruptBinding,\n} from './interrupt-resume'\n\nexport type {\n AudioVisualization,\n RealtimeAdapter,\n RealtimeConnection,\n RealtimeError,\n RealtimeErrorCode,\n RealtimeEvent,\n RealtimeEventHandler,\n RealtimeEventPayloads,\n RealtimeMessage,\n RealtimeMessagePart,\n RealtimeMode,\n RealtimeSessionConfig,\n RealtimeStatus,\n RealtimeToken,\n RealtimeAudioPart,\n RealtimeImagePart,\n RealtimeTextPart,\n RealtimeToolCallPart,\n RealtimeToolResultPart,\n VADConfig,\n} from './realtime/types'\n"],"mappings":"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"}
@@ -0,0 +1,45 @@
1
+ import { Interrupt } from './types.js';
2
+ /**
3
+ * `ResumeEntry.metadata` key for a first-party generic request.
4
+ *
5
+ * AG-UI `resume` only carries the answer (`interruptId`, `status`, `payload`).
6
+ * The original request rides here so an ephemeral server can rebuild it.
7
+ */
8
+ export declare const INTERRUPT_CONTINUATION_METADATA_KEY: "tanstack:interruptContinuation";
9
+ export declare const INTERRUPT_CONTINUATION_VERSION: 1;
10
+ export interface GenericInterruptContinuation {
11
+ v: typeof INTERRUPT_CONTINUATION_VERSION;
12
+ definitionId: string;
13
+ key: string;
14
+ batchIndex: number;
15
+ reason: string;
16
+ message: string;
17
+ expiresAt?: string;
18
+ responseSchemaHash?: string;
19
+ payloadSchemaHash?: string;
20
+ payload?: unknown;
21
+ }
22
+ export type GenericInterruptContinuationReadResult = {
23
+ status: 'absent';
24
+ } | {
25
+ status: 'invalid';
26
+ message: string;
27
+ } | {
28
+ status: 'ok';
29
+ value: GenericInterruptContinuation;
30
+ };
31
+ /**
32
+ * Read one generic request from `resume[].metadata`.
33
+ *
34
+ * Missing key means this resume item is not a first-party generic continuation.
35
+ * A present key that fails the shape is a protocol error.
36
+ */
37
+ export declare function readGenericInterruptContinuation(metadata: unknown): GenericInterruptContinuationReadResult;
38
+ /** Put a parsed continuation on `ResumeEntry.metadata`. */
39
+ export declare function wrapGenericInterruptContinuation(continuation: GenericInterruptContinuation): Record<string, unknown>;
40
+ /**
41
+ * Build the resume-metadata continuation from an outbound AG-UI interrupt.
42
+ *
43
+ * Returns `undefined` when the descriptor is not a first-party generic item.
44
+ */
45
+ export declare function genericInterruptContinuationFromDescriptor(interrupt: Interrupt): GenericInterruptContinuation | undefined;
@@ -0,0 +1,80 @@
1
+ import { readUnopenedInterruptBinding } from "./interrupt-resume.js";
2
+ import { INTERRUPT_PAYLOAD_METADATA_KEY } from "./interrupt-definition.js";
3
+ //#region src/generic-interrupt-continuation.ts
4
+ /**
5
+ * `ResumeEntry.metadata` key for a first-party generic request.
6
+ *
7
+ * AG-UI `resume` only carries the answer (`interruptId`, `status`, `payload`).
8
+ * The original request rides here so an ephemeral server can rebuild it.
9
+ */
10
+ var INTERRUPT_CONTINUATION_METADATA_KEY = "tanstack:interruptContinuation";
11
+ var INTERRUPT_CONTINUATION_VERSION = 1;
12
+ function isRecord(value) {
13
+ return value !== null && typeof value === "object" && !Array.isArray(value);
14
+ }
15
+ function invalid(message) {
16
+ return {
17
+ status: "invalid",
18
+ message
19
+ };
20
+ }
21
+ /**
22
+ * Read one generic request from `resume[].metadata`.
23
+ *
24
+ * Missing key means this resume item is not a first-party generic continuation.
25
+ * A present key that fails the shape is a protocol error.
26
+ */
27
+ function readGenericInterruptContinuation(metadata) {
28
+ if (metadata === void 0) return { status: "absent" };
29
+ if (!isRecord(metadata)) return invalid("Generic interrupt resume metadata must be an object.");
30
+ if (!Object.prototype.hasOwnProperty.call(metadata, "tanstack:interruptContinuation")) return { status: "absent" };
31
+ const raw = metadata[INTERRUPT_CONTINUATION_METADATA_KEY];
32
+ if (!isRecord(raw)) return invalid("Generic interrupt continuation is invalid.");
33
+ if (raw.v !== 1 || typeof raw.definitionId !== "string" || typeof raw.key !== "string" || typeof raw.reason !== "string" || typeof raw.message !== "string" || typeof raw.batchIndex !== "number" || !Number.isInteger(raw.batchIndex) || raw.batchIndex < 0 || raw.responseSchemaHash !== void 0 && typeof raw.responseSchemaHash !== "string" || raw.expiresAt !== void 0 && typeof raw.expiresAt !== "string" || raw.payloadSchemaHash !== void 0 && typeof raw.payloadSchemaHash !== "string") return invalid("Generic interrupt continuation contains invalid fields.");
34
+ return {
35
+ status: "ok",
36
+ value: {
37
+ v: 1,
38
+ definitionId: raw.definitionId,
39
+ key: raw.key,
40
+ batchIndex: raw.batchIndex,
41
+ reason: raw.reason,
42
+ message: raw.message,
43
+ ...typeof raw.expiresAt === "string" ? { expiresAt: raw.expiresAt } : {},
44
+ ...typeof raw.responseSchemaHash === "string" ? { responseSchemaHash: raw.responseSchemaHash } : {},
45
+ ...typeof raw.payloadSchemaHash === "string" ? { payloadSchemaHash: raw.payloadSchemaHash } : {},
46
+ ...Object.prototype.hasOwnProperty.call(raw, "payload") ? { payload: raw.payload } : {}
47
+ }
48
+ };
49
+ }
50
+ /** Put a parsed continuation on `ResumeEntry.metadata`. */
51
+ function wrapGenericInterruptContinuation(continuation) {
52
+ return { [INTERRUPT_CONTINUATION_METADATA_KEY]: continuation };
53
+ }
54
+ /**
55
+ * Build the resume-metadata continuation from an outbound AG-UI interrupt.
56
+ *
57
+ * Returns `undefined` when the descriptor is not a first-party generic item.
58
+ */
59
+ function genericInterruptContinuationFromDescriptor(interrupt) {
60
+ const binding = readUnopenedInterruptBinding(interrupt);
61
+ if (binding?.kind !== "generic" || binding.definitionId === void 0 || binding.key === void 0 || binding.batchIndex === void 0) return;
62
+ const metadata = isRecord(interrupt.metadata) ? interrupt.metadata : void 0;
63
+ const hasPayload = metadata !== void 0 && Object.prototype.hasOwnProperty.call(metadata, "tanstack:interruptPayload");
64
+ return {
65
+ v: 1,
66
+ definitionId: binding.definitionId,
67
+ key: binding.key,
68
+ batchIndex: binding.batchIndex,
69
+ reason: interrupt.reason,
70
+ message: interrupt.message ?? "",
71
+ ...interrupt.expiresAt !== void 0 ? { expiresAt: interrupt.expiresAt } : {},
72
+ ...binding.responseSchemaHash !== void 0 ? { responseSchemaHash: binding.responseSchemaHash } : {},
73
+ ...binding.payloadSchemaHash !== void 0 ? { payloadSchemaHash: binding.payloadSchemaHash } : {},
74
+ ...hasPayload ? { payload: metadata[INTERRUPT_PAYLOAD_METADATA_KEY] } : {}
75
+ };
76
+ }
77
+ //#endregion
78
+ export { INTERRUPT_CONTINUATION_METADATA_KEY, INTERRUPT_CONTINUATION_VERSION, genericInterruptContinuationFromDescriptor, readGenericInterruptContinuation, wrapGenericInterruptContinuation };
79
+
80
+ //# sourceMappingURL=generic-interrupt-continuation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-interrupt-continuation.js","names":[],"sources":["../../src/generic-interrupt-continuation.ts"],"sourcesContent":["import { INTERRUPT_PAYLOAD_METADATA_KEY } from './interrupt-definition'\nimport { readUnopenedInterruptBinding } from './interrupt-resume'\nimport type { Interrupt } from './types'\n\n/**\n * `ResumeEntry.metadata` key for a first-party generic request.\n *\n * AG-UI `resume` only carries the answer (`interruptId`, `status`, `payload`).\n * The original request rides here so an ephemeral server can rebuild it.\n */\nexport const INTERRUPT_CONTINUATION_METADATA_KEY =\n 'tanstack:interruptContinuation' as const\n\nexport const INTERRUPT_CONTINUATION_VERSION = 1 as const\n\nexport interface GenericInterruptContinuation {\n v: typeof INTERRUPT_CONTINUATION_VERSION\n definitionId: string\n key: string\n batchIndex: number\n reason: string\n message: string\n expiresAt?: string\n responseSchemaHash?: string\n payloadSchemaHash?: string\n payload?: unknown\n}\n\nexport type GenericInterruptContinuationReadResult =\n | { status: 'absent' }\n | { status: 'invalid'; message: string }\n | { status: 'ok'; value: GenericInterruptContinuation }\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction invalid(\n message: string,\n): Extract<GenericInterruptContinuationReadResult, { status: 'invalid' }> {\n return { status: 'invalid', message }\n}\n\n/**\n * Read one generic request from `resume[].metadata`.\n *\n * Missing key means this resume item is not a first-party generic continuation.\n * A present key that fails the shape is a protocol error.\n */\nexport function readGenericInterruptContinuation(\n metadata: unknown,\n): GenericInterruptContinuationReadResult {\n if (metadata === undefined) return { status: 'absent' }\n if (!isRecord(metadata)) {\n return invalid('Generic interrupt resume metadata must be an object.')\n }\n if (\n !Object.prototype.hasOwnProperty.call(\n metadata,\n INTERRUPT_CONTINUATION_METADATA_KEY,\n )\n ) {\n return { status: 'absent' }\n }\n const raw = metadata[INTERRUPT_CONTINUATION_METADATA_KEY]\n if (!isRecord(raw)) {\n return invalid('Generic interrupt continuation is invalid.')\n }\n if (\n raw.v !== INTERRUPT_CONTINUATION_VERSION ||\n typeof raw.definitionId !== 'string' ||\n typeof raw.key !== 'string' ||\n typeof raw.reason !== 'string' ||\n typeof raw.message !== 'string' ||\n typeof raw.batchIndex !== 'number' ||\n !Number.isInteger(raw.batchIndex) ||\n raw.batchIndex < 0 ||\n (raw.responseSchemaHash !== undefined &&\n typeof raw.responseSchemaHash !== 'string') ||\n (raw.expiresAt !== undefined && typeof raw.expiresAt !== 'string') ||\n (raw.payloadSchemaHash !== undefined &&\n typeof raw.payloadSchemaHash !== 'string')\n ) {\n return invalid('Generic interrupt continuation contains invalid fields.')\n }\n return {\n status: 'ok',\n value: {\n v: INTERRUPT_CONTINUATION_VERSION,\n definitionId: raw.definitionId,\n key: raw.key,\n batchIndex: raw.batchIndex,\n reason: raw.reason,\n message: raw.message,\n ...(typeof raw.expiresAt === 'string'\n ? { expiresAt: raw.expiresAt }\n : {}),\n ...(typeof raw.responseSchemaHash === 'string'\n ? { responseSchemaHash: raw.responseSchemaHash }\n : {}),\n ...(typeof raw.payloadSchemaHash === 'string'\n ? { payloadSchemaHash: raw.payloadSchemaHash }\n : {}),\n ...(Object.prototype.hasOwnProperty.call(raw, 'payload')\n ? { payload: raw.payload }\n : {}),\n },\n }\n}\n\n/** Put a parsed continuation on `ResumeEntry.metadata`. */\nexport function wrapGenericInterruptContinuation(\n continuation: GenericInterruptContinuation,\n): Record<string, unknown> {\n return { [INTERRUPT_CONTINUATION_METADATA_KEY]: continuation }\n}\n\n/**\n * Build the resume-metadata continuation from an outbound AG-UI interrupt.\n *\n * Returns `undefined` when the descriptor is not a first-party generic item.\n */\nexport function genericInterruptContinuationFromDescriptor(\n interrupt: Interrupt,\n): GenericInterruptContinuation | undefined {\n const binding = readUnopenedInterruptBinding(interrupt)\n if (\n binding?.kind !== 'generic' ||\n binding.definitionId === undefined ||\n binding.key === undefined ||\n binding.batchIndex === undefined\n ) {\n return undefined\n }\n const metadata = isRecord(interrupt.metadata) ? interrupt.metadata : undefined\n const hasPayload =\n metadata !== undefined &&\n Object.prototype.hasOwnProperty.call(\n metadata,\n INTERRUPT_PAYLOAD_METADATA_KEY,\n )\n return {\n v: INTERRUPT_CONTINUATION_VERSION,\n definitionId: binding.definitionId,\n key: binding.key,\n batchIndex: binding.batchIndex,\n reason: interrupt.reason,\n message: interrupt.message ?? '',\n ...(interrupt.expiresAt !== undefined\n ? { expiresAt: interrupt.expiresAt }\n : {}),\n ...(binding.responseSchemaHash !== undefined\n ? { responseSchemaHash: binding.responseSchemaHash }\n : {}),\n ...(binding.payloadSchemaHash !== undefined\n ? { payloadSchemaHash: binding.payloadSchemaHash }\n : {}),\n ...(hasPayload\n ? { payload: metadata[INTERRUPT_PAYLOAD_METADATA_KEY] }\n : {}),\n }\n}\n"],"mappings":";;;;;;;;;AAUA,IAAa,sCACX;AAEF,IAAa,iCAAiC;AAoB9C,SAAS,SAAS,OAAkD;CAClE,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,QACP,SACwE;CACxE,OAAO;EAAE,QAAQ;EAAW;CAAQ;AACtC;;;;;;;AAQA,SAAgB,iCACd,UACwC;CACxC,IAAI,aAAa,KAAA,GAAW,OAAO,EAAE,QAAQ,SAAS;CACtD,IAAI,CAAC,SAAS,QAAQ,GACpB,OAAO,QAAQ,sDAAsD;CAEvE,IACE,CAAC,OAAO,UAAU,eAAe,KAC/B,UAAA,gCAEF,GAEA,OAAO,EAAE,QAAQ,SAAS;CAE5B,MAAM,MAAM,SAAS;CACrB,IAAI,CAAC,SAAS,GAAG,GACf,OAAO,QAAQ,4CAA4C;CAE7D,IACE,IAAI,MAAA,KACJ,OAAO,IAAI,iBAAiB,YAC5B,OAAO,IAAI,QAAQ,YACnB,OAAO,IAAI,WAAW,YACtB,OAAO,IAAI,YAAY,YACvB,OAAO,IAAI,eAAe,YAC1B,CAAC,OAAO,UAAU,IAAI,UAAU,KAChC,IAAI,aAAa,KAChB,IAAI,uBAAuB,KAAA,KAC1B,OAAO,IAAI,uBAAuB,YACnC,IAAI,cAAc,KAAA,KAAa,OAAO,IAAI,cAAc,YACxD,IAAI,sBAAsB,KAAA,KACzB,OAAO,IAAI,sBAAsB,UAEnC,OAAO,QAAQ,yDAAyD;CAE1E,OAAO;EACL,QAAQ;EACR,OAAO;GACL,GAAA;GACA,cAAc,IAAI;GAClB,KAAK,IAAI;GACT,YAAY,IAAI;GAChB,QAAQ,IAAI;GACZ,SAAS,IAAI;GACb,GAAI,OAAO,IAAI,cAAc,WACzB,EAAE,WAAW,IAAI,UAAU,IAC3B,CAAC;GACL,GAAI,OAAO,IAAI,uBAAuB,WAClC,EAAE,oBAAoB,IAAI,mBAAmB,IAC7C,CAAC;GACL,GAAI,OAAO,IAAI,sBAAsB,WACjC,EAAE,mBAAmB,IAAI,kBAAkB,IAC3C,CAAC;GACL,GAAI,OAAO,UAAU,eAAe,KAAK,KAAK,SAAS,IACnD,EAAE,SAAS,IAAI,QAAQ,IACvB,CAAC;EACP;CACF;AACF;;AAGA,SAAgB,iCACd,cACyB;CACzB,OAAO,GAAG,sCAAsC,aAAa;AAC/D;;;;;;AAOA,SAAgB,2CACd,WAC0C;CAC1C,MAAM,UAAU,6BAA6B,SAAS;CACtD,IACE,SAAS,SAAS,aAClB,QAAQ,iBAAiB,KAAA,KACzB,QAAQ,QAAQ,KAAA,KAChB,QAAQ,eAAe,KAAA,GAEvB;CAEF,MAAM,WAAW,SAAS,UAAU,QAAQ,IAAI,UAAU,WAAW,KAAA;CACrE,MAAM,aACJ,aAAa,KAAA,KACb,OAAO,UAAU,eAAe,KAC9B,UAAA,2BAEF;CACF,OAAO;EACL,GAAA;EACA,cAAc,QAAQ;EACtB,KAAK,QAAQ;EACb,YAAY,QAAQ;EACpB,QAAQ,UAAU;EAClB,SAAS,UAAU,WAAW;EAC9B,GAAI,UAAU,cAAc,KAAA,IACxB,EAAE,WAAW,UAAU,UAAU,IACjC,CAAC;EACL,GAAI,QAAQ,uBAAuB,KAAA,IAC/B,EAAE,oBAAoB,QAAQ,mBAAmB,IACjD,CAAC;EACL,GAAI,QAAQ,sBAAsB,KAAA,IAC9B,EAAE,mBAAmB,QAAQ,kBAAkB,IAC/C,CAAC;EACL,GAAI,aACA,EAAE,SAAS,SAAS,gCAAgC,IACpD,CAAC;CACP;AACF"}
@@ -16,18 +16,26 @@ export { canonicalInterruptJson, cloneAndDeepFreezeJson, digestInterruptJson, }
16
16
  export { INTERRUPT_BINDING_METADATA_KEY, InterruptResumeValidationError, interruptItemError, readInterruptBinding, readUnopenedInterruptBinding, validateInterruptResumeBatch, withInterruptBinding, withoutInterruptBinding, type PendingInterruptResumeRecord, type ValidateInterruptResumeBatchInput, type ValidatedInterruptResumeBatch, } from './interrupt-resume.js';
17
17
  export type { MCPToolSource, ChatMCPOptions, MCPConnectionPolicy, } from './activities/chat/mcp/types.js';
18
18
  export { MCPDuplicateToolNameError } from './activities/chat/mcp/manager.js';
19
+ export { DuplicateToolNameError } from './activities/chat/tools/unique-tool-names.js';
19
20
  export { convertSchemaToJsonSchema, isStandardSchema, parseWithStandardSchema, validateWithStandardSchema, StandardSchemaValidationError, } from './activities/chat/tools/schema-converter.js';
20
21
  export { streamToText, toServerSentEventsStream, toServerSentEventsResponse, resumeServerSentEventsResponse, toHttpStream, toHttpResponse, resumeHttpResponse, resolveResumeRunId, RUN_ACCEPTED_EVENT, } from './stream-to-response.js';
21
22
  export type { RunDriverOptions } from './stream-to-response.js';
22
23
  export { memoryStream, replayRunStream } from './stream-durability.js';
23
24
  export type { MemoryStreamInit, MemoryStreamOptions, StreamDurability, UpsertableStreamDurability, } from './stream-durability.js';
25
+ export { toWebSocketStream, toWebSocketResponse, resumeWebSocketStream, resumeWebSocketResponse, encodeWsFrame, decodeWsFrame, } from './stream-to-websocket.js';
26
+ export type { WebSocketLike, WsRunContext, WebSocketStreamInit, InboundFrame, } from './stream-to-websocket.js';
24
27
  export { ToolCallManager } from './activities/chat/tools/tool-calls.js';
25
28
  export { DISCOVERY_TOOL_NAME } from './activities/chat/tools/lazy-tool-manager.js';
26
29
  export type { ProviderTool } from './tools/provider-tool.js';
27
30
  export { brandProviderTool } from './tools/provider-tool.js';
28
31
  export { maxIterations, untilFinishReason, combineStrategies, } from './activities/chat/agent-loop-strategies.js';
29
32
  export { createToolRegistry, createFrozenRegistry, type ToolRegistry, } from './tool-registry.js';
30
- export type { ChatMiddleware, ChatMiddlewareContext, ChatMiddlewarePhase, ChatMiddlewareConfig, ChatResumeToolState, ChatResumeGenericResolution, StructuredOutputMiddlewareConfig, ToolCallHookContext, BeforeToolCallDecision, AfterToolCallInfo, IterationInfo, ToolPhaseCompleteInfo, UsageInfo, FinishInfo, AbortInfo, ErrorInfo, SandboxFileEvent, SandboxFileHookEvent, ChatSandboxHooks, } from './activities/chat/middleware/index.js';
33
+ export type { ChatMiddleware, ChatMiddlewareContext, ChatMiddlewarePhase, ChatMiddlewareConfig, ChatResumeToolState, ChatResumeGenericResolution, StructuredOutputMiddlewareConfig, ToolCallHookContext, BeforeToolCallDecision, AfterToolCallInfo, IterationInfo, ToolPhaseCompleteInfo, UsageInfo, FinishInfo, AbortInfo, ErrorInfo, SandboxFileEvent, SandboxFileHookEvent, ChatSandboxHooks, InterruptBoundaryPhase, InterruptToolResume, InterruptResolutionCollection, GenericInterruptResolution, InterruptBoundaryResult, InterruptResolutionResult, } from './activities/chat/middleware/index.js';
34
+ export { INTERRUPT_BOUNDARY_PHASES, INTERRUPT_TOOL_RESUMES, } from './activities/chat/middleware/index.js';
35
+ export { defineInterrupt, createInterruptBinding, INTERRUPT_PAYLOAD_METADATA_KEY, } from './interrupt-definition.js';
36
+ export { INTERRUPT_CONTINUATION_METADATA_KEY, INTERRUPT_CONTINUATION_VERSION, genericInterruptContinuationFromDescriptor, readGenericInterruptContinuation, wrapGenericInterruptContinuation, } from './generic-interrupt-continuation.js';
37
+ export type { GenericInterruptContinuation, GenericInterruptContinuationReadResult, } from './generic-interrupt-continuation.js';
38
+ export type { InterruptDefinition, GenericInterruptRequest, InterruptDefinitionOptions, InterruptBindingDescriptor, } from './interrupt-definition.js';
31
39
  export { INTERRUPT_BINDING_VERSION, canonicalizeInterruptResolutions, } from './interrupts.js';
32
40
  export type { BatchInterruptError, BatchInterruptErrorCode, InterruptBinding, InterruptCorrelation, InterruptSubmissionError, ItemInterruptError, ItemInterruptErrorCode, ToolApprovalResolution, UnopenedInterruptBinding, } from './interrupts.js';
33
41
  export type { GenerationMiddleware, GenerationMiddlewareContext, GenerationActivity, GenerationUsageInfo, GenerationFinishInfo, GenerationAbortInfo, GenerationErrorInfo, AnyGenerationMiddleware, GenerationResultTransform, GenerationResultTransformContext, } from './activities/middleware/index.js';
package/dist/esm/index.js CHANGED
@@ -10,10 +10,13 @@ import { INTERRUPT_BINDING_VERSION, canonicalizeInterruptResolutions } from "./i
10
10
  import { StandardSchemaValidationError, convertSchemaToJsonSchema, isStandardSchema, parseWithStandardSchema, validateWithStandardSchema } from "./activities/chat/tools/schema-converter.js";
11
11
  import { hashSchemaInput, normalizeApprovalSchema } from "./activities/chat/tools/approval-schema.js";
12
12
  import { INTERRUPT_BINDING_METADATA_KEY, InterruptResumeValidationError, interruptItemError, readInterruptBinding, readUnopenedInterruptBinding, validateInterruptResumeBatch, withInterruptBinding, withoutInterruptBinding } from "./interrupt-resume.js";
13
+ import { INTERRUPT_PAYLOAD_METADATA_KEY, createInterruptBinding, defineInterrupt } from "./interrupt-definition.js";
14
+ import { INTERRUPT_CONTINUATION_METADATA_KEY, INTERRUPT_CONTINUATION_VERSION, genericInterruptContinuationFromDescriptor, readGenericInterruptContinuation, wrapGenericInterruptContinuation } from "./generic-interrupt-continuation.js";
13
15
  import { isContentPart, isContentPartArray, normalizeToolResult } from "./utilities/tool-result.js";
14
16
  import { getProviderExecutedMetadata, isProviderExecutedToolCall } from "./utilities/provider-executed.js";
15
17
  import { firstSentence, renderLazyCatalogEntry } from "./activities/chat/tools/lazy-tools.js";
16
18
  import { DISCOVERY_TOOL_NAME } from "./activities/chat/tools/lazy-tool-manager.js";
19
+ import { DuplicateToolNameError } from "./activities/chat/tools/unique-tool-names.js";
17
20
  import { ToolCallManager } from "./activities/chat/tools/tool-calls.js";
18
21
  import { combineStrategies, maxIterations, untilFinishReason } from "./activities/chat/agent-loop-strategies.js";
19
22
  import { convertMessagesToModelMessages, generateMessageId, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, uiMessageToModelMessages } from "./activities/chat/messages.js";
@@ -31,8 +34,11 @@ import { createTranscriptionOptions, generateTranscription } from "./activities/
31
34
  import { countEmbeddingInputModalities, requireTextOnlyEmbeddingInput, resolveEmbeddingInput } from "./utilities/embedding-input.js";
32
35
  import { createEmbedOptions, embed } from "./activities/embed/index.js";
33
36
  import { toolDefinition } from "./activities/chat/tools/tool-definition.js";
37
+ import { chatParamsFromRequest, chatParamsFromRequestBody, mergeAgentTools } from "./utilities/chat-params.js";
38
+ import { decodeWsFrame, encodeWsFrame, resumeWebSocketResponse, resumeWebSocketStream, toWebSocketResponse, toWebSocketStream } from "./stream-to-websocket.js";
34
39
  import { brandProviderTool } from "./tools/provider-tool.js";
35
40
  import { createFrozenRegistry, createToolRegistry } from "./tool-registry.js";
41
+ import { INTERRUPT_BOUNDARY_PHASES, INTERRUPT_TOOL_RESUMES } from "./activities/chat/middleware/types.js";
36
42
  import { defineChatMiddleware } from "./activities/chat/middleware/define.js";
37
43
  import { createChatMiddleware } from "./activities/chat/middleware/builder.js";
38
44
  import { CUSTOM_EVENT, isCustomEvent } from "./custom-events.js";
@@ -44,8 +50,7 @@ import { realtimeToken } from "./realtime/index.js";
44
50
  import { PartialJSONParser, defaultJSONParser, parsePartialJSON } from "./activities/chat/stream/json-parser.js";
45
51
  import { BatchStrategy, CompositeStrategy, ImmediateStrategy, PunctuationStrategy, WordBoundaryStrategy } from "./activities/chat/stream/strategies.js";
46
52
  import { StreamProcessor, createReplayStream } from "./activities/chat/stream/processor.js";
47
- import { chatParamsFromRequest, chatParamsFromRequestBody, mergeAgentTools } from "./utilities/chat-params.js";
48
53
  import { uiMessagesToWire } from "./utilities/ag-ui-wire.js";
49
54
  import { generationParamsFromBody, generationParamsFromRequest } from "./client.js";
50
55
  import { createModel, extendAdapter } from "./extend-adapter.js";
51
- export { BaseRerankAdapter, BatchStrategy, CUSTOM_EVENT, CompositeStrategy, ConsoleLogger, DISCOVERY_TOOL_NAME, DetachableRunCapability, EventType, INTERRUPT_BINDING_METADATA_KEY, INTERRUPT_BINDING_VERSION, ImmediateStrategy, InMemoryRunStore, InterruptResumeValidationError, MCPDuplicateToolNameError, PartialJSONParser, PunctuationStrategy, RUN_ACCEPTED_EVENT, RUN_CANCEL_REASON, RunDetachedCapability, StandardSchemaValidationError, StreamProcessor, ToolCallManager, WordBoundaryStrategy, brandProviderTool, buildBaseUsage, canonicalInterruptJson, canonicalizeInterruptResolutions, chat, chatParamsFromRequest, chatParamsFromRequestBody, cloneAndDeepFreezeJson, combineStrategies, convertMessagesToModelMessages, convertSchemaToJsonSchema, countEmbeddingInputModalities, createAudioOptions, createCapability, createChatMiddleware, createChatOptions, createEmbedOptions, createFrozenRegistry, createImageOptions, createModel, createRealtimeEventEmitter, createReplayStream, createRerankOptions, createSpeechOptions, createSummarizeOptions, createToolRegistry, createTranscriptionOptions, createVideoOptions, defaultJSONParser, defineChatMiddleware, defineRunStore, detectImageMimeType, digestInterruptJson, embed, extendAdapter, firstSentence, generateAudio, generateImage, generateMessageId, generateSpeech, generateTranscription, generateVideo, generationParamsFromBody, generationParamsFromRequest, getDetachableRun, getProviderExecutedMetadata, getRunDetached, getVideoJobStatus, hashSchemaInput, interruptItemError, isCancelRequestedReason, isContentPart, isContentPartArray, isCustomEvent, isProviderExecutedToolCall, isRunStatus, isStandardSchema, isTerminalRunStatus, maxIterations, memoryStream, mergeAgentTools, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeApprovalSchema, normalizeSystemPrompts, normalizeToUIMessage, normalizeToolResult, parsePartialJSON, parseWithStandardSchema, provideDetachableRun, provideRunDetached, readInterruptBinding, readUnopenedInterruptBinding, realtimeToken, renderLazyCatalogEntry, replayRunStream, requestRunCancel, requireTextOnlyEmbeddingInput, rerank, resolveEmbeddingInput, resolveMediaPrompt, resolveResumeRunId, resumeHttpResponse, resumeServerSentEventsResponse, streamToText, summarize, toHttpResponse, toHttpStream, toServerSentEventsResponse, toServerSentEventsStream, toolDefinition, uiMessageToModelMessages, uiMessagesToWire, untilFinishReason, validateInterruptResumeBatch, validateWithStandardSchema, wasCancelRequested, withInterruptBinding, withoutInterruptBinding };
56
+ export { BaseRerankAdapter, BatchStrategy, CUSTOM_EVENT, CompositeStrategy, ConsoleLogger, DISCOVERY_TOOL_NAME, DetachableRunCapability, DuplicateToolNameError, EventType, INTERRUPT_BINDING_METADATA_KEY, INTERRUPT_BINDING_VERSION, INTERRUPT_BOUNDARY_PHASES, INTERRUPT_CONTINUATION_METADATA_KEY, INTERRUPT_CONTINUATION_VERSION, INTERRUPT_PAYLOAD_METADATA_KEY, INTERRUPT_TOOL_RESUMES, ImmediateStrategy, InMemoryRunStore, InterruptResumeValidationError, MCPDuplicateToolNameError, PartialJSONParser, PunctuationStrategy, RUN_ACCEPTED_EVENT, RUN_CANCEL_REASON, RunDetachedCapability, StandardSchemaValidationError, StreamProcessor, ToolCallManager, WordBoundaryStrategy, brandProviderTool, buildBaseUsage, canonicalInterruptJson, canonicalizeInterruptResolutions, chat, chatParamsFromRequest, chatParamsFromRequestBody, cloneAndDeepFreezeJson, combineStrategies, convertMessagesToModelMessages, convertSchemaToJsonSchema, countEmbeddingInputModalities, createAudioOptions, createCapability, createChatMiddleware, createChatOptions, createEmbedOptions, createFrozenRegistry, createImageOptions, createInterruptBinding, createModel, createRealtimeEventEmitter, createReplayStream, createRerankOptions, createSpeechOptions, createSummarizeOptions, createToolRegistry, createTranscriptionOptions, createVideoOptions, decodeWsFrame, defaultJSONParser, defineChatMiddleware, defineInterrupt, defineRunStore, detectImageMimeType, digestInterruptJson, embed, encodeWsFrame, extendAdapter, firstSentence, generateAudio, generateImage, generateMessageId, generateSpeech, generateTranscription, generateVideo, generationParamsFromBody, generationParamsFromRequest, genericInterruptContinuationFromDescriptor, getDetachableRun, getProviderExecutedMetadata, getRunDetached, getVideoJobStatus, hashSchemaInput, interruptItemError, isCancelRequestedReason, isContentPart, isContentPartArray, isCustomEvent, isProviderExecutedToolCall, isRunStatus, isStandardSchema, isTerminalRunStatus, maxIterations, memoryStream, mergeAgentTools, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeApprovalSchema, normalizeSystemPrompts, normalizeToUIMessage, normalizeToolResult, parsePartialJSON, parseWithStandardSchema, provideDetachableRun, provideRunDetached, readGenericInterruptContinuation, readInterruptBinding, readUnopenedInterruptBinding, realtimeToken, renderLazyCatalogEntry, replayRunStream, requestRunCancel, requireTextOnlyEmbeddingInput, rerank, resolveEmbeddingInput, resolveMediaPrompt, resolveResumeRunId, resumeHttpResponse, resumeServerSentEventsResponse, resumeWebSocketResponse, resumeWebSocketStream, streamToText, summarize, toHttpResponse, toHttpStream, toServerSentEventsResponse, toServerSentEventsStream, toWebSocketResponse, toWebSocketStream, toolDefinition, uiMessageToModelMessages, uiMessagesToWire, untilFinishReason, validateInterruptResumeBatch, validateWithStandardSchema, wasCancelRequested, withInterruptBinding, withoutInterruptBinding, wrapGenericInterruptContinuation };
@@ -0,0 +1,113 @@
1
+ import { StandardJSONSchemaV1, StandardSchemaV1 } from '@standard-schema/spec';
2
+ import { INTERRUPT_BINDING_VERSION } from './interrupts.js';
3
+ export declare const INTERRUPT_PAYLOAD_METADATA_KEY: "tanstack:interruptPayload";
4
+ export declare const INTERRUPT_BINDING_KIND: "generic";
5
+ type PortableSchema = StandardJSONSchemaV1<any, any> | StandardSchemaV1<any, any>;
6
+ type InferSchemaOutput<TSchema> = TSchema extends StandardSchemaV1<any, infer TOutput> ? TOutput : TSchema extends StandardJSONSchemaV1<any, infer TOutput> ? TOutput : never;
7
+ type InferSchemaInput<TSchema> = TSchema extends StandardSchemaV1<infer TInput, any> ? TInput : TSchema extends StandardJSONSchemaV1<infer TInput, any> ? TInput : never;
8
+ export interface InterruptDefinitionOptions<TId extends string, TPayloadSchema extends PortableSchema | undefined, TResponseSchema extends PortableSchema | undefined> {
9
+ id: TId;
10
+ payloadSchema?: TPayloadSchema;
11
+ responseSchema?: TResponseSchema;
12
+ }
13
+ export interface InterruptBindingDescriptor {
14
+ v: typeof INTERRUPT_BINDING_VERSION;
15
+ kind: typeof INTERRUPT_BINDING_KIND;
16
+ definitionId: string;
17
+ key: string;
18
+ threadId?: string;
19
+ interruptedRunId?: string;
20
+ generation?: number;
21
+ batchIndex?: number;
22
+ responseSchemaCanonicalJson?: string;
23
+ payloadSchemaCanonicalJson?: string;
24
+ payloadSchemaHash?: string;
25
+ responseSchemaHash?: string;
26
+ }
27
+ export interface InterruptPreEmissionData {
28
+ descriptor: InterruptBindingDescriptor;
29
+ payload?: unknown;
30
+ }
31
+ type InterruptInput<TPayloadSchema extends PortableSchema | undefined, TPayload = unknown> = {
32
+ key: string;
33
+ reason: string;
34
+ message: string;
35
+ expiresAt?: string;
36
+ } & ([TPayloadSchema] extends [undefined] ? {} : {
37
+ payload?: TPayload;
38
+ });
39
+ type GenericInterruptRequestBase<TDefinition extends InterruptDefinition<any, any, any, any>> = {
40
+ readonly definition: TDefinition;
41
+ readonly key: string;
42
+ readonly reason: string;
43
+ readonly message: string;
44
+ readonly expiresAt?: string;
45
+ };
46
+ type GenericInterruptRequestFor<TDefinition extends InterruptDefinition<any, any, any, any>, TPayloadSchema extends PortableSchema | undefined, TPayload> = GenericInterruptRequestBase<TDefinition> & ([TPayloadSchema] extends [undefined] ? {} : {
47
+ readonly payload: TPayload | undefined;
48
+ });
49
+ export type GenericInterruptRequest<TDefinition extends InterruptDefinition<any, any, any, any>> = [TDefinition] extends [never] ? never : TDefinition extends InterruptDefinition<any, infer TPayloadSchema, any, infer TPayload> ? GenericInterruptRequestFor<TDefinition, TPayloadSchema, TPayload> : GenericInterruptRequestBase<TDefinition>;
50
+ type InterruptInputKey = 'key' | 'reason' | 'message' | 'expiresAt' | 'payload';
51
+ type RejectUnexpectedInputKeys<TInput> = Exclude<keyof TInput, InterruptInputKey> extends never ? unknown : {
52
+ [K in Exclude<keyof TInput, InterruptInputKey>]: never;
53
+ };
54
+ type RejectUnexpectedPayload<TInput> = 'payload' extends keyof TInput ? {
55
+ payload: never;
56
+ } : unknown;
57
+ type ValidInterruptInput<TInput, TPayloadSchema extends PortableSchema | undefined, TPayload = unknown> = TInput extends InterruptInput<TPayloadSchema, TPayload> ? RejectUnexpectedInputKeys<TInput> & ([TPayloadSchema] extends [undefined] ? RejectUnexpectedPayload<TInput> : unknown) : never;
58
+ /**
59
+ * Extracting a class method preserves the intentional bivariant assignment
60
+ * behavior of the public `interrupt` callback without exposing a method
61
+ * signature in an interface.
62
+ */
63
+ declare abstract class InterruptRequestMethodSignature<TId extends string, TPayloadSchema extends PortableSchema | undefined, TResponseSchema extends PortableSchema | undefined, TPayload, TPayloadInput> {
64
+ abstract call<TInput>(input: TInput & ValidInterruptInput<TInput, TPayloadSchema, TPayloadInput>): GenericInterruptRequestFor<InterruptDefinition<TId, TPayloadSchema, TResponseSchema, TPayload, TPayloadInput>, TPayloadSchema, TPayload>;
65
+ }
66
+ type InterruptRequestMethod<TId extends string, TPayloadSchema extends PortableSchema | undefined, TResponseSchema extends PortableSchema | undefined, TPayload, TPayloadInput> = InterruptRequestMethodSignature<TId, TPayloadSchema, TResponseSchema, TPayload, TPayloadInput>['call'];
67
+ type DefinedInterruptDefinition<TId extends string, TPayloadSchema extends PortableSchema | undefined, TResponseSchema extends PortableSchema | undefined, TPayload = unknown, TPayloadInput = TPayload> = Omit<InterruptDefinition<TId, TPayloadSchema, TResponseSchema, TPayload, TPayloadInput>, 'interrupt'> & {
68
+ interrupt: InterruptRequestMethod<TId, TPayloadSchema, TResponseSchema, TPayload, TPayloadInput>;
69
+ };
70
+ export interface InterruptDefinition<TId extends string, TPayloadSchema extends PortableSchema | undefined, TResponseSchema extends PortableSchema | undefined, TPayload = unknown, TPayloadInput = TPayload> {
71
+ readonly id: TId;
72
+ readonly payloadSchema: TPayloadSchema;
73
+ readonly responseSchema: TResponseSchema;
74
+ interrupt: InterruptRequestMethod<TId, TPayloadSchema, TResponseSchema, TPayload, TPayloadInput>;
75
+ }
76
+ export declare function createInterruptBinding(request: GenericInterruptRequest<InterruptDefinition<any, any, any, any>>, fields?: Pick<InterruptBindingDescriptor, 'threadId' | 'interruptedRunId' | 'generation' | 'batchIndex'>): InterruptPreEmissionData;
77
+ type ParsedInterruptInput = {
78
+ key: string;
79
+ reason: string;
80
+ message: string;
81
+ expiresAt?: string;
82
+ payload?: unknown;
83
+ };
84
+ /**
85
+ * Returns the schema input captured for a newly emitted request. This is
86
+ * internal because continuation state can cross a client boundary and must be
87
+ * parsed again when it returns to the server.
88
+ */
89
+ export declare function getInterruptRequestInput(request: GenericInterruptRequest<InterruptDefinition<any, any, any, any>>): Readonly<ParsedInterruptInput>;
90
+ /**
91
+ * Rebuild a request from a persisted display payload that has already passed
92
+ * the definition's payload schema. This is internal because callers must not
93
+ * bypass public input validation for new requests.
94
+ */
95
+ export declare function rehydrateInterruptRequest(definition: InterruptDefinition<any, any, any, any>, input: ParsedInterruptInput): GenericInterruptRequest<InterruptDefinition<any, any, any, any>>;
96
+ /** Same hash the producer stamps on a first-party generic binding. */
97
+ export declare function hashInterruptDefinitionSchema(schema: unknown): string;
98
+ export declare function defineInterrupt<const TId extends string, const TPayloadSchema extends PortableSchema, const TResponseSchema extends PortableSchema>(options: {
99
+ id: TId;
100
+ payloadSchema: TPayloadSchema;
101
+ responseSchema: TResponseSchema;
102
+ }): DefinedInterruptDefinition<TId, TPayloadSchema, TResponseSchema, InferSchemaOutput<TPayloadSchema>, InferSchemaInput<TPayloadSchema>>;
103
+ export declare function defineInterrupt<const TId extends string, const TPayloadSchema extends PortableSchema>(options: {
104
+ id: TId;
105
+ payloadSchema: TPayloadSchema;
106
+ responseSchema?: never;
107
+ }): DefinedInterruptDefinition<TId, TPayloadSchema, undefined, InferSchemaOutput<TPayloadSchema>, InferSchemaInput<TPayloadSchema>>;
108
+ export declare function defineInterrupt<const TId extends string, const TResponseSchema extends PortableSchema>(options: {
109
+ id: TId;
110
+ responseSchema: TResponseSchema;
111
+ payloadSchema?: never;
112
+ }): DefinedInterruptDefinition<TId, undefined, TResponseSchema, undefined, undefined>;
113
+ export {};