@tanstack/ai 0.46.0 → 0.47.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/activities/chat/index.d.ts +36 -11
- package/dist/esm/activities/chat/index.js +440 -79
- package/dist/esm/activities/chat/index.js.map +1 -1
- package/dist/esm/activities/chat/messages.d.ts +1 -0
- package/dist/esm/activities/chat/messages.js +12 -7
- package/dist/esm/activities/chat/messages.js.map +1 -1
- package/dist/esm/activities/chat/middleware/builder.d.ts +7 -2
- package/dist/esm/activities/chat/middleware/builder.js.map +1 -1
- package/dist/esm/activities/chat/middleware/compose.d.ts +10 -3
- package/dist/esm/activities/chat/middleware/compose.js +55 -0
- package/dist/esm/activities/chat/middleware/compose.js.map +1 -1
- package/dist/esm/activities/chat/middleware/define.d.ts +6 -3
- package/dist/esm/activities/chat/middleware/define.js.map +1 -1
- package/dist/esm/activities/chat/middleware/generic-interrupts.d.ts +13 -0
- package/dist/esm/activities/chat/middleware/generic-interrupts.js +8 -0
- package/dist/esm/activities/chat/middleware/generic-interrupts.js.map +1 -0
- package/dist/esm/activities/chat/middleware/index.d.ts +4 -1
- package/dist/esm/activities/chat/middleware/types.d.ts +54 -3
- package/dist/esm/activities/chat/middleware/types.js +16 -0
- package/dist/esm/activities/chat/middleware/types.js.map +1 -0
- package/dist/esm/activities/chat/stream/processor.js +18 -5
- package/dist/esm/activities/chat/stream/processor.js.map +1 -1
- package/dist/esm/adapter-internals.d.ts +6 -0
- package/dist/esm/adapter-internals.js +4 -1
- package/dist/esm/client.d.ts +4 -0
- package/dist/esm/client.js +3 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/generic-interrupt-continuation.d.ts +45 -0
- package/dist/esm/generic-interrupt-continuation.js +80 -0
- package/dist/esm/generic-interrupt-continuation.js.map +1 -0
- package/dist/esm/index.d.ts +6 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/interrupt-definition.d.ts +113 -0
- package/dist/esm/interrupt-definition.js +169 -0
- package/dist/esm/interrupt-definition.js.map +1 -0
- package/dist/esm/interrupt-resume.d.ts +3 -0
- package/dist/esm/interrupt-resume.js +77 -16
- package/dist/esm/interrupt-resume.js.map +1 -1
- package/dist/esm/interrupts.d.ts +12 -3
- package/dist/esm/interrupts.js.map +1 -1
- package/dist/esm/types.d.ts +11 -3
- package/dist/esm/utilities/chat-params.js +10 -1
- package/dist/esm/utilities/chat-params.js.map +1 -1
- package/package.json +3 -3
- package/skills/ai-core/media-generation/SKILL.md +4 -1
- package/skills/ai-core/middleware/SKILL.md +53 -44
- package/skills/ai-core/structured-outputs/SKILL.md +59 -55
- package/skills/ai-core/tool-calling/SKILL.md +54 -1
- package/src/activities/chat/index.ts +1030 -211
- package/src/activities/chat/messages.ts +11 -3
- package/src/activities/chat/middleware/builder.ts +29 -4
- package/src/activities/chat/middleware/compose.ts +95 -5
- package/src/activities/chat/middleware/define.ts +13 -3
- package/src/activities/chat/middleware/generic-interrupts.ts +26 -0
- package/src/activities/chat/middleware/index.ts +15 -0
- package/src/activities/chat/middleware/types.ts +127 -2
- package/src/activities/chat/stream/processor.ts +21 -0
- package/src/adapter-internals.ts +20 -0
- package/src/client.ts +20 -0
- package/src/generic-interrupt-continuation.ts +162 -0
- package/src/index.ts +34 -0
- package/src/interrupt-definition.ts +581 -0
- package/src/interrupt-resume.ts +156 -25
- package/src/interrupts.ts +13 -3
- package/src/types.ts +11 -3
- package/src/utilities/chat-params.ts +16 -3
package/dist/esm/client.js
CHANGED
|
@@ -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
|
package/dist/esm/client.js.map
CHANGED
|
@@ -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":";;;;;;;;;;;;AA8BA,IAAM,kBAAkB;CACtB;CACA;CACA;CACA;CACA;AACF;AAEA,SAAS,SAAS,OAAkD;CAClE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,UAAU,OAAgC,KAAsB;CACvE,OAAO,OAAO,UAAU,eAAe,KAAK,OAAO,GAAG;AACxD;AAEA,SAAS,qBAAqB,MAAgD;CAC5E,OACE,SAAS,IAAI,MACZ,UAAU,MAAM,MAAM,KAAK,UAAU,MAAM,gBAAgB;AAEhE;AAEA,SAAS,qBAAqB,MAA+C;CAC3E,IAAI,CAAC,gBAAgB,SAAS,IAAsB,GAClD,MAAM,IAAI,MACR,gCAAgC,OAC9B,IACF,EAAE,oBAAoB,gBAAgB,KAAK,IAAI,EAAE,EACnD;AAEJ;AAEA,SAAS,mBACP,MACA,OACwD;CACxD,IAAI,CAAC,SAAS,KAAK,GACjB,MAAM,IAAI,MAAM,cAAc,KAAK,0BAA0B;CAG/D,MAAM,cACJ,SAAS,QAAQ,SAAS,SAAS,k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CAGlE,MAAM,QAAQ,KAAK;CACnB,mBAAmB,MAAM,KAAK;CAI9B,OAAO;EACE;EACP,gBAJqB,2BAA2B,IAIhD;EACA,GAAG,yBAAyB,IAAI;CAClC;AACF;AAEA,eAAsB,4BACpB,MACA,SACkC;CAClC,IAAI;CACJ,IAAI;EACF,OAAO,MAAM,QAAQ,KAAK;CAC5B,SAAS,OAAO;EACd,MAAM,IAAI,MAAM,8BAA8B,EAAE,OAAO,MAAM,CAAC;CAChE;CAEA,IAAI,CAAC,SAAS,IAAI,GAChB,MAAM,IAAI,MAAM,gDAAgD;CAGlE,OAAO,yBAAyB,MAAM,IAAI;AAC5C;AAEA,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,wBAAA;CACA,UAAA,0BAAA;CACA,UAAA,sBAAA;CACA,UAAA,wBAAA;CACA,UAAA,qBAAA;CACA,UAAA,oBAAA;CACA,UAAA,mBAAA;CACA,UAAA,qBAAA;CACA,UAAA,sBAAA;CACA,UAAA,oBAAA;CACA,UAAA,kBAAA;CACA,UAAA,iCAAA;CACA,UAAA,mCAAA;CACA,UAAA,+BAAA;CACA,UAAA,oBAAA;CACA,UAAA,iBAAA;CACA,UAAA,uBAAA;CACA,UAAA,uBAAA;CACA,UAAA,oBAAA;CACA,UAAA,SAAA;CACA,UAAA,YAAA;CACA,UAAA,iBAAA;CACA,UAAA,kBAAA;CACA,UAAA,eAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,qBAAA;CACA,UAAA,6BAAA;CACA,UAAA,+BAAA;CACA,UAAA,2BAAA;CACA,UAAA,6BAAA;CACA,UAAA,mBAAA;CACA,UAAA,+BAAA;;AACF,EAAA,CAAA,CAAA"}
|
|
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 Realtim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,wBAAA;CACA,UAAA,0BAAA;CACA,UAAA,sBAAA;CACA,UAAA,wBAAA;CACA,UAAA,qBAAA;CACA,UAAA,oBAAA;CACA,UAAA,mBAAA;CACA,UAAA,qBAAA;CACA,UAAA,sBAAA;CACA,UAAA,oBAAA;CACA,UAAA,kBAAA;CACA,UAAA,iCAAA;CACA,UAAA,mCAAA;CACA,UAAA,+BAAA;CACA,UAAA,oBAAA;CACA,UAAA,iBAAA;CACA,UAAA,uBAAA;CACA,UAAA,uBAAA;CACA,UAAA,oBAAA;CACA,UAAA,SAAA;CACA,UAAA,YAAA;CACA,UAAA,iBAAA;CACA,UAAA,kBAAA;CACA,UAAA,eAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,qBAAA;CACA,UAAA,6BAAA;CACA,UAAA,+BAAA;CACA,UAAA,2BAAA;CACA,UAAA,6BAAA;CACA,UAAA,mBAAA;CACA,UAAA,+BAAA;;AACF,EAAA,CAAA,CAAA"}
|
|
@@ -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,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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"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -30,7 +30,12 @@ export type { ProviderTool } from './tools/provider-tool.js';
|
|
|
30
30
|
export { brandProviderTool } from './tools/provider-tool.js';
|
|
31
31
|
export { maxIterations, untilFinishReason, combineStrategies, } from './activities/chat/agent-loop-strategies.js';
|
|
32
32
|
export { createToolRegistry, createFrozenRegistry, type ToolRegistry, } from './tool-registry.js';
|
|
33
|
-
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';
|
|
34
39
|
export { INTERRUPT_BINDING_VERSION, canonicalizeInterruptResolutions, } from './interrupts.js';
|
|
35
40
|
export type { BatchInterruptError, BatchInterruptErrorCode, InterruptBinding, InterruptCorrelation, InterruptSubmissionError, ItemInterruptError, ItemInterruptErrorCode, ToolApprovalResolution, UnopenedInterruptBinding, } from './interrupts.js';
|
|
36
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,6 +10,8 @@ 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";
|
|
@@ -36,6 +38,7 @@ import { chatParamsFromRequest, chatParamsFromRequestBody, mergeAgentTools } fro
|
|
|
36
38
|
import { decodeWsFrame, encodeWsFrame, resumeWebSocketResponse, resumeWebSocketStream, toWebSocketResponse, toWebSocketStream } from "./stream-to-websocket.js";
|
|
37
39
|
import { brandProviderTool } from "./tools/provider-tool.js";
|
|
38
40
|
import { createFrozenRegistry, createToolRegistry } from "./tool-registry.js";
|
|
41
|
+
import { INTERRUPT_BOUNDARY_PHASES, INTERRUPT_TOOL_RESUMES } from "./activities/chat/middleware/types.js";
|
|
39
42
|
import { defineChatMiddleware } from "./activities/chat/middleware/define.js";
|
|
40
43
|
import { createChatMiddleware } from "./activities/chat/middleware/builder.js";
|
|
41
44
|
import { CUSTOM_EVENT, isCustomEvent } from "./custom-events.js";
|
|
@@ -50,4 +53,4 @@ import { StreamProcessor, createReplayStream } from "./activities/chat/stream/pr
|
|
|
50
53
|
import { uiMessagesToWire } from "./utilities/ag-ui-wire.js";
|
|
51
54
|
import { generationParamsFromBody, generationParamsFromRequest } from "./client.js";
|
|
52
55
|
import { createModel, extendAdapter } from "./extend-adapter.js";
|
|
53
|
-
export { BaseRerankAdapter, BatchStrategy, CUSTOM_EVENT, CompositeStrategy, ConsoleLogger, DISCOVERY_TOOL_NAME, DetachableRunCapability, DuplicateToolNameError, 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, decodeWsFrame, defaultJSONParser, defineChatMiddleware, defineRunStore, detectImageMimeType, digestInterruptJson, embed, encodeWsFrame, 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, resumeWebSocketResponse, resumeWebSocketStream, streamToText, summarize, toHttpResponse, toHttpStream, toServerSentEventsResponse, toServerSentEventsStream, toWebSocketResponse, toWebSocketStream, 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 {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { canonicalInterruptJson, cloneAndDeepFreezeJson, digestInterruptJson } from "./interrupt-serialization.js";
|
|
2
|
+
import "./interrupts.js";
|
|
3
|
+
import { isStandardJSONSchema, isStandardSchema } from "./activities/chat/tools/schema-converter.js";
|
|
4
|
+
//#region src/interrupt-definition.ts
|
|
5
|
+
var INTERRUPT_PAYLOAD_METADATA_KEY = "tanstack:interruptPayload";
|
|
6
|
+
var INTERRUPT_BINDING_KIND = "generic";
|
|
7
|
+
var definitionSchemaState = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function createInterruptBinding(request, fields = {}) {
|
|
9
|
+
const schemaState = definitionSchemaState.get(request.definition);
|
|
10
|
+
if (!schemaState) throw new TypeError("Interrupt definition schema state is unavailable.");
|
|
11
|
+
const { threadId, interruptedRunId, generation, batchIndex } = fields;
|
|
12
|
+
return {
|
|
13
|
+
descriptor: {
|
|
14
|
+
v: 1,
|
|
15
|
+
kind: INTERRUPT_BINDING_KIND,
|
|
16
|
+
definitionId: request.definition.id,
|
|
17
|
+
key: request.key,
|
|
18
|
+
...threadId !== void 0 ? { threadId } : {},
|
|
19
|
+
...interruptedRunId !== void 0 ? { interruptedRunId } : {},
|
|
20
|
+
...generation !== void 0 ? { generation } : {},
|
|
21
|
+
...batchIndex !== void 0 ? { batchIndex } : {},
|
|
22
|
+
...schemaState.responseSchemaCanonicalJson ? { responseSchemaCanonicalJson: schemaState.responseSchemaCanonicalJson } : {},
|
|
23
|
+
...schemaState.payloadSchemaCanonicalJson ? { payloadSchemaCanonicalJson: schemaState.payloadSchemaCanonicalJson } : {},
|
|
24
|
+
...schemaState.payloadSchemaHash ? { payloadSchemaHash: schemaState.payloadSchemaHash } : {},
|
|
25
|
+
...schemaState.responseSchemaHash ? { responseSchemaHash: schemaState.responseSchemaHash } : {}
|
|
26
|
+
},
|
|
27
|
+
..."payload" in request && request.payload !== void 0 ? { payload: request.payload } : {}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var interruptRequestFactories = /* @__PURE__ */ new WeakMap();
|
|
31
|
+
var interruptRequestInputs = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
/**
|
|
33
|
+
* Returns the schema input captured for a newly emitted request. This is
|
|
34
|
+
* internal because continuation state can cross a client boundary and must be
|
|
35
|
+
* parsed again when it returns to the server.
|
|
36
|
+
*/
|
|
37
|
+
function getInterruptRequestInput(request) {
|
|
38
|
+
const input = interruptRequestInputs.get(request);
|
|
39
|
+
if (!input) throw new TypeError("Interrupt request input is unavailable.");
|
|
40
|
+
return input;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Rebuild a request from a persisted display payload that has already passed
|
|
44
|
+
* the definition's payload schema. This is internal because callers must not
|
|
45
|
+
* bypass public input validation for new requests.
|
|
46
|
+
*/
|
|
47
|
+
function rehydrateInterruptRequest(definition, input) {
|
|
48
|
+
const factory = interruptRequestFactories.get(definition);
|
|
49
|
+
if (!factory) throw new TypeError("Interrupt definition request factory is unavailable.");
|
|
50
|
+
return factory(input, true);
|
|
51
|
+
}
|
|
52
|
+
function schemaJson(schema, name) {
|
|
53
|
+
if (!isStandardJSONSchema(schema)) throw new TypeError(`${name} must be a Standard Schema with a JSON Schema converter.`);
|
|
54
|
+
try {
|
|
55
|
+
const exported = schema["~standard"].jsonSchema.input({ target: "draft-07" });
|
|
56
|
+
if (exported === void 0) throw new TypeError("The exported schema is undefined.");
|
|
57
|
+
if (typeof exported === "function") throw new TypeError("The exported schema must not be a function.");
|
|
58
|
+
if (Array.isArray(exported)) throw new TypeError("The exported schema must be a plain JSON object.");
|
|
59
|
+
if (!exported || typeof exported !== "object" || ![Object.prototype, null].includes(Object.getPrototypeOf(exported))) throw new TypeError("The exported schema must be a plain JSON object.");
|
|
60
|
+
const converted = {};
|
|
61
|
+
for (const [key, value] of Object.entries(exported)) if (key !== "$schema") converted[key] = value;
|
|
62
|
+
return {
|
|
63
|
+
json: converted,
|
|
64
|
+
canonicalJson: canonicalInterruptJson(converted)
|
|
65
|
+
};
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new TypeError(`${name} could not export compatible JSON Schema: ${error instanceof Error ? error.message : String(error)}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/** Same hash the producer stamps on a first-party generic binding. */
|
|
71
|
+
function hashInterruptDefinitionSchema(schema) {
|
|
72
|
+
return digestInterruptJson(schemaJson(schema, "Interrupt schema").canonicalJson);
|
|
73
|
+
}
|
|
74
|
+
function validateJson(value, label) {
|
|
75
|
+
try {
|
|
76
|
+
canonicalInterruptJson(value);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
throw new TypeError(`${label} must be JSON-compatible: ${error instanceof Error ? error.message : String(error)}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function validateNonEmptyString(value, label) {
|
|
82
|
+
if (typeof value !== "string" || value.trim() === "") throw new TypeError(`${label} must be a non-empty string.`);
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
function validateExpiresAt(value) {
|
|
86
|
+
if (typeof value !== "string" || !Number.isFinite(Date.parse(value))) throw new TypeError("Interrupt expiresAt must be a valid date string.");
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
function isPromiseLike(value) {
|
|
90
|
+
return value !== null && (typeof value === "object" || typeof value === "function") && "then" in value && typeof value.then === "function";
|
|
91
|
+
}
|
|
92
|
+
function parseInterruptPayload(schema, value) {
|
|
93
|
+
if (!isStandardSchema(schema)) return value;
|
|
94
|
+
const result = schema["~standard"].validate(value);
|
|
95
|
+
if (isPromiseLike(result)) throw new TypeError("Interrupt payloadSchema validation must be synchronous.");
|
|
96
|
+
if (result.issues !== void 0) throw new TypeError(`Interrupt payload is invalid: ${result.issues.map((issue) => issue.message).join(" ")}`);
|
|
97
|
+
return result.value;
|
|
98
|
+
}
|
|
99
|
+
function defineInterrupt(options) {
|
|
100
|
+
validateNonEmptyString(options.id, "Interrupt definition id");
|
|
101
|
+
const responseJson = options.responseSchema !== void 0 ? schemaJson(options.responseSchema, "responseSchema") : void 0;
|
|
102
|
+
const hasPayloadSchema = Object.prototype.hasOwnProperty.call(options, "payloadSchema");
|
|
103
|
+
const payloadJson = hasPayloadSchema ? schemaJson(options.payloadSchema, "payloadSchema") : void 0;
|
|
104
|
+
const schemaState = {
|
|
105
|
+
...responseJson ? {
|
|
106
|
+
responseSchemaCanonicalJson: responseJson.canonicalJson,
|
|
107
|
+
responseSchemaHash: digestInterruptJson(responseJson.canonicalJson)
|
|
108
|
+
} : {},
|
|
109
|
+
...payloadJson ? {
|
|
110
|
+
payloadSchemaCanonicalJson: payloadJson.canonicalJson,
|
|
111
|
+
payloadSchemaHash: digestInterruptJson(payloadJson.canonicalJson)
|
|
112
|
+
} : {}
|
|
113
|
+
};
|
|
114
|
+
const definition = {
|
|
115
|
+
id: options.id,
|
|
116
|
+
payloadSchema: options.payloadSchema,
|
|
117
|
+
responseSchema: options.responseSchema,
|
|
118
|
+
interrupt(input) {
|
|
119
|
+
return createRequest(input, false);
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const parsePayload = (payload) => {
|
|
123
|
+
const payloadSchema = options.payloadSchema;
|
|
124
|
+
if (payloadSchema === void 0) throw new TypeError("This interrupt definition does not accept a payload.");
|
|
125
|
+
return parseInterruptPayload(payloadSchema, payload);
|
|
126
|
+
};
|
|
127
|
+
const createRequest = (input, payloadIsParsed) => {
|
|
128
|
+
for (const key of Object.keys(input)) if (![
|
|
129
|
+
"key",
|
|
130
|
+
"payload",
|
|
131
|
+
"reason",
|
|
132
|
+
"message",
|
|
133
|
+
"expiresAt"
|
|
134
|
+
].includes(key)) throw new TypeError(`Interrupt input field ${key} is not allowed.`);
|
|
135
|
+
const key = validateNonEmptyString(input.key, "Interrupt key");
|
|
136
|
+
const reason = validateNonEmptyString(input.reason, "Interrupt reason");
|
|
137
|
+
const message = validateNonEmptyString(input.message, "Interrupt message");
|
|
138
|
+
if ("payload" in input) {
|
|
139
|
+
if (!hasPayloadSchema) throw new TypeError("This interrupt definition does not accept a payload.");
|
|
140
|
+
if (input.payload !== void 0) validateJson(input.payload, "Interrupt payload");
|
|
141
|
+
}
|
|
142
|
+
const parsedPayload = "payload" in input ? payloadIsParsed ? input.payload : parsePayload(input.payload) : void 0;
|
|
143
|
+
const payload = parsedPayload === void 0 ? void 0 : cloneAndDeepFreezeJson(parsedPayload);
|
|
144
|
+
const expiresAt = input.expiresAt === void 0 ? void 0 : validateExpiresAt(input.expiresAt);
|
|
145
|
+
const request = Object.freeze({
|
|
146
|
+
definition,
|
|
147
|
+
key,
|
|
148
|
+
...hasPayloadSchema && payload !== void 0 ? { payload } : {},
|
|
149
|
+
reason,
|
|
150
|
+
message,
|
|
151
|
+
...expiresAt !== void 0 ? { expiresAt } : {}
|
|
152
|
+
});
|
|
153
|
+
if (!payloadIsParsed) interruptRequestInputs.set(request, cloneAndDeepFreezeJson({
|
|
154
|
+
key,
|
|
155
|
+
reason,
|
|
156
|
+
message,
|
|
157
|
+
...expiresAt !== void 0 ? { expiresAt } : {},
|
|
158
|
+
...parsedPayload !== void 0 ? { payload: parsedPayload } : {}
|
|
159
|
+
}));
|
|
160
|
+
return request;
|
|
161
|
+
};
|
|
162
|
+
definitionSchemaState.set(definition, schemaState);
|
|
163
|
+
interruptRequestFactories.set(definition, createRequest);
|
|
164
|
+
return Object.freeze(definition);
|
|
165
|
+
}
|
|
166
|
+
//#endregion
|
|
167
|
+
export { INTERRUPT_BINDING_KIND, INTERRUPT_PAYLOAD_METADATA_KEY, createInterruptBinding, defineInterrupt, getInterruptRequestInput, hashInterruptDefinitionSchema, rehydrateInterruptRequest };
|
|
168
|
+
|
|
169
|
+
//# sourceMappingURL=interrupt-definition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interrupt-definition.js","names":[],"sources":["../../src/interrupt-definition.ts"],"sourcesContent":["import type {\n StandardJSONSchemaV1,\n StandardSchemaV1,\n} from '@standard-schema/spec'\nimport {\n canonicalInterruptJson,\n cloneAndDeepFreezeJson,\n digestInterruptJson,\n} from './interrupt-serialization'\nimport {\n isStandardSchema,\n isStandardJSONSchema,\n} from './activities/chat/tools/schema-converter'\nimport { INTERRUPT_BINDING_VERSION } from './interrupts'\n\nexport const INTERRUPT_PAYLOAD_METADATA_KEY =\n 'tanstack:interruptPayload' as const\nexport const INTERRUPT_BINDING_KIND = 'generic' as const\n\ntype PortableSchema =\n | StandardJSONSchemaV1<any, any>\n | StandardSchemaV1<any, any>\n\ntype InferSchemaOutput<TSchema> =\n TSchema extends StandardSchemaV1<any, infer TOutput>\n ? TOutput\n : TSchema extends StandardJSONSchemaV1<any, infer TOutput>\n ? TOutput\n : never\ntype InferSchemaInput<TSchema> =\n TSchema extends StandardSchemaV1<infer TInput, any>\n ? TInput\n : TSchema extends StandardJSONSchemaV1<infer TInput, any>\n ? TInput\n : never\ntype DefinitionSchemaState = {\n responseSchemaCanonicalJson?: string\n responseSchemaHash?: string\n payloadSchemaCanonicalJson?: string\n payloadSchemaHash?: string\n}\nconst definitionSchemaState = new WeakMap<object, DefinitionSchemaState>()\n\nexport interface InterruptDefinitionOptions<\n TId extends string,\n TPayloadSchema extends PortableSchema | undefined,\n TResponseSchema extends PortableSchema | undefined,\n> {\n id: TId\n payloadSchema?: TPayloadSchema\n responseSchema?: TResponseSchema\n}\n\nexport interface InterruptBindingDescriptor {\n v: typeof INTERRUPT_BINDING_VERSION\n kind: typeof INTERRUPT_BINDING_KIND\n definitionId: string\n key: string\n threadId?: string\n interruptedRunId?: string\n generation?: number\n batchIndex?: number\n responseSchemaCanonicalJson?: string\n payloadSchemaCanonicalJson?: string\n payloadSchemaHash?: string\n responseSchemaHash?: string\n}\n\nexport interface InterruptPreEmissionData {\n descriptor: InterruptBindingDescriptor\n payload?: unknown\n}\n\ntype InterruptInput<\n TPayloadSchema extends PortableSchema | undefined,\n TPayload = unknown,\n> = {\n key: string\n reason: string\n message: string\n expiresAt?: string\n} & ([TPayloadSchema] extends [undefined] ? {} : { payload?: TPayload })\n\ntype GenericInterruptRequestBase<\n TDefinition extends InterruptDefinition<any, any, any, any>,\n> = {\n readonly definition: TDefinition\n readonly key: string\n readonly reason: string\n readonly message: string\n readonly expiresAt?: string\n}\n\ntype GenericInterruptRequestFor<\n TDefinition extends InterruptDefinition<any, any, any, any>,\n TPayloadSchema extends PortableSchema | undefined,\n TPayload,\n> = GenericInterruptRequestBase<TDefinition> &\n ([TPayloadSchema] extends [undefined]\n ? {}\n : { readonly payload: TPayload | undefined })\n\nexport type GenericInterruptRequest<\n TDefinition extends InterruptDefinition<any, any, any, any>,\n> = [TDefinition] extends [never]\n ? never\n : TDefinition extends InterruptDefinition<\n any,\n infer TPayloadSchema,\n any,\n infer TPayload\n >\n ? GenericInterruptRequestFor<TDefinition, TPayloadSchema, TPayload>\n : GenericInterruptRequestBase<TDefinition>\n\ntype InterruptInputKey = 'key' | 'reason' | 'message' | 'expiresAt' | 'payload'\ntype RejectUnexpectedInputKeys<TInput> =\n Exclude<keyof TInput, InterruptInputKey> extends never\n ? unknown\n : { [K in Exclude<keyof TInput, InterruptInputKey>]: never }\ntype RejectUnexpectedPayload<TInput> = 'payload' extends keyof TInput\n ? { payload: never }\n : unknown\ntype ValidInterruptInput<\n TInput,\n TPayloadSchema extends PortableSchema | undefined,\n TPayload = unknown,\n> =\n TInput extends InterruptInput<TPayloadSchema, TPayload>\n ? RejectUnexpectedInputKeys<TInput> &\n ([TPayloadSchema] extends [undefined]\n ? RejectUnexpectedPayload<TInput>\n : unknown)\n : never\n\n/**\n * Extracting a class method preserves the intentional bivariant assignment\n * behavior of the public `interrupt` callback without exposing a method\n * signature in an interface.\n */\ndeclare abstract class InterruptRequestMethodSignature<\n TId extends string,\n TPayloadSchema extends PortableSchema | undefined,\n TResponseSchema extends PortableSchema | undefined,\n TPayload,\n TPayloadInput,\n> {\n abstract call<TInput>(\n input: TInput & ValidInterruptInput<TInput, TPayloadSchema, TPayloadInput>,\n ): GenericInterruptRequestFor<\n InterruptDefinition<\n TId,\n TPayloadSchema,\n TResponseSchema,\n TPayload,\n TPayloadInput\n >,\n TPayloadSchema,\n TPayload\n >\n}\n\ntype InterruptRequestMethod<\n TId extends string,\n TPayloadSchema extends PortableSchema | undefined,\n TResponseSchema extends PortableSchema | undefined,\n TPayload,\n TPayloadInput,\n> = InterruptRequestMethodSignature<\n TId,\n TPayloadSchema,\n TResponseSchema,\n TPayload,\n TPayloadInput\n>['call']\n\ntype DefinedInterruptDefinition<\n TId extends string,\n TPayloadSchema extends PortableSchema | undefined,\n TResponseSchema extends PortableSchema | undefined,\n TPayload = unknown,\n TPayloadInput = TPayload,\n> = Omit<\n InterruptDefinition<\n TId,\n TPayloadSchema,\n TResponseSchema,\n TPayload,\n TPayloadInput\n >,\n 'interrupt'\n> & {\n interrupt: InterruptRequestMethod<\n TId,\n TPayloadSchema,\n TResponseSchema,\n TPayload,\n TPayloadInput\n >\n}\n\nexport interface InterruptDefinition<\n TId extends string,\n TPayloadSchema extends PortableSchema | undefined,\n TResponseSchema extends PortableSchema | undefined,\n TPayload = unknown,\n TPayloadInput = TPayload,\n> {\n readonly id: TId\n readonly payloadSchema: TPayloadSchema\n readonly responseSchema: TResponseSchema\n interrupt: InterruptRequestMethod<\n TId,\n TPayloadSchema,\n TResponseSchema,\n TPayload,\n TPayloadInput\n >\n}\n\nexport function createInterruptBinding(\n request: GenericInterruptRequest<InterruptDefinition<any, any, any, any>>,\n fields: Pick<\n InterruptBindingDescriptor,\n 'threadId' | 'interruptedRunId' | 'generation' | 'batchIndex'\n > = {},\n): InterruptPreEmissionData {\n const schemaState = definitionSchemaState.get(request.definition)\n if (!schemaState) {\n throw new TypeError('Interrupt definition schema state is unavailable.')\n }\n const { threadId, interruptedRunId, generation, batchIndex } = fields\n return {\n descriptor: {\n v: INTERRUPT_BINDING_VERSION,\n kind: INTERRUPT_BINDING_KIND,\n definitionId: request.definition.id,\n key: request.key,\n ...(threadId !== undefined ? { threadId } : {}),\n ...(interruptedRunId !== undefined ? { interruptedRunId } : {}),\n ...(generation !== undefined ? { generation } : {}),\n ...(batchIndex !== undefined ? { batchIndex } : {}),\n ...(schemaState.responseSchemaCanonicalJson\n ? {\n responseSchemaCanonicalJson:\n schemaState.responseSchemaCanonicalJson,\n }\n : {}),\n ...(schemaState.payloadSchemaCanonicalJson\n ? { payloadSchemaCanonicalJson: schemaState.payloadSchemaCanonicalJson }\n : {}),\n ...(schemaState.payloadSchemaHash\n ? { payloadSchemaHash: schemaState.payloadSchemaHash }\n : {}),\n ...(schemaState.responseSchemaHash\n ? { responseSchemaHash: schemaState.responseSchemaHash }\n : {}),\n },\n ...('payload' in request && request.payload !== undefined\n ? { payload: request.payload }\n : {}),\n }\n}\n\ntype ParsedInterruptInput = {\n key: string\n reason: string\n message: string\n expiresAt?: string\n payload?: unknown\n}\n\ntype InterruptRequestFactory = (\n input: ParsedInterruptInput,\n payloadIsParsed: boolean,\n) => GenericInterruptRequest<InterruptDefinition<any, any, any, any>>\n\nconst interruptRequestFactories = new WeakMap<object, InterruptRequestFactory>()\nconst interruptRequestInputs = new WeakMap<\n object,\n Readonly<ParsedInterruptInput>\n>()\n\n/**\n * Returns the schema input captured for a newly emitted request. This is\n * internal because continuation state can cross a client boundary and must be\n * parsed again when it returns to the server.\n */\nexport function getInterruptRequestInput(\n request: GenericInterruptRequest<InterruptDefinition<any, any, any, any>>,\n): Readonly<ParsedInterruptInput> {\n const input = interruptRequestInputs.get(request)\n if (!input) {\n throw new TypeError('Interrupt request input is unavailable.')\n }\n return input\n}\n\n/**\n * Rebuild a request from a persisted display payload that has already passed\n * the definition's payload schema. This is internal because callers must not\n * bypass public input validation for new requests.\n */\nexport function rehydrateInterruptRequest(\n definition: InterruptDefinition<any, any, any, any>,\n input: ParsedInterruptInput,\n): GenericInterruptRequest<InterruptDefinition<any, any, any, any>> {\n const factory = interruptRequestFactories.get(definition)\n if (!factory) {\n throw new TypeError('Interrupt definition request factory is unavailable.')\n }\n return factory(input, true)\n}\n\ninterface CanonicalSchemaJson {\n json: Record<string, unknown>\n canonicalJson: string\n}\n\nfunction schemaJson(schema: unknown, name: string): CanonicalSchemaJson {\n if (!isStandardJSONSchema(schema)) {\n throw new TypeError(\n `${name} must be a Standard Schema with a JSON Schema converter.`,\n )\n }\n try {\n const exported = schema['~standard'].jsonSchema.input({\n target: 'draft-07',\n })\n if (exported === undefined) {\n throw new TypeError('The exported schema is undefined.')\n }\n if (typeof exported === 'function') {\n throw new TypeError('The exported schema must not be a function.')\n }\n if (Array.isArray(exported)) {\n throw new TypeError('The exported schema must be a plain JSON object.')\n }\n if (\n !exported ||\n typeof exported !== 'object' ||\n ![Object.prototype, null].includes(Object.getPrototypeOf(exported))\n ) {\n throw new TypeError('The exported schema must be a plain JSON object.')\n }\n const converted: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(exported)) {\n if (key !== '$schema') converted[key] = value\n }\n const canonicalJson = canonicalInterruptJson(converted)\n return { json: converted, canonicalJson }\n } catch (error) {\n throw new TypeError(\n `${name} could not export compatible JSON Schema: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n\n/** Same hash the producer stamps on a first-party generic binding. */\nexport function hashInterruptDefinitionSchema(schema: unknown): string {\n return digestInterruptJson(\n schemaJson(schema, 'Interrupt schema').canonicalJson,\n )\n}\n\nfunction validateJson(value: unknown, label: string): void {\n try {\n canonicalInterruptJson(value)\n } catch (error) {\n throw new TypeError(\n `${label} must be JSON-compatible: ${error instanceof Error ? error.message : String(error)}`,\n )\n }\n}\n\nfunction validateNonEmptyString(value: unknown, label: string): string {\n if (typeof value !== 'string' || value.trim() === '') {\n throw new TypeError(`${label} must be a non-empty string.`)\n }\n return value\n}\n\nfunction validateExpiresAt(value: unknown): string {\n if (typeof value !== 'string' || !Number.isFinite(Date.parse(value))) {\n throw new TypeError('Interrupt expiresAt must be a valid date string.')\n }\n return value\n}\n\nfunction isPromiseLike(value: unknown): value is PromiseLike<unknown> {\n return (\n value !== null &&\n (typeof value === 'object' || typeof value === 'function') &&\n 'then' in value &&\n typeof value.then === 'function'\n )\n}\n\nfunction parseInterruptPayload(\n schema: PortableSchema,\n value: unknown,\n): unknown {\n if (!isStandardSchema(schema)) return value\n const result = schema['~standard'].validate(value)\n if (isPromiseLike(result)) {\n throw new TypeError(\n 'Interrupt payloadSchema validation must be synchronous.',\n )\n }\n if (result.issues !== undefined) {\n throw new TypeError(\n `Interrupt payload is invalid: ${result.issues.map((issue) => issue.message).join(' ')}`,\n )\n }\n return result.value\n}\n\nexport function defineInterrupt<\n const TId extends string,\n const TPayloadSchema extends PortableSchema,\n const TResponseSchema extends PortableSchema,\n>(options: {\n id: TId\n payloadSchema: TPayloadSchema\n responseSchema: TResponseSchema\n}): DefinedInterruptDefinition<\n TId,\n TPayloadSchema,\n TResponseSchema,\n InferSchemaOutput<TPayloadSchema>,\n InferSchemaInput<TPayloadSchema>\n>\nexport function defineInterrupt<\n const TId extends string,\n const TPayloadSchema extends PortableSchema,\n>(options: {\n id: TId\n payloadSchema: TPayloadSchema\n responseSchema?: never\n}): DefinedInterruptDefinition<\n TId,\n TPayloadSchema,\n undefined,\n InferSchemaOutput<TPayloadSchema>,\n InferSchemaInput<TPayloadSchema>\n>\nexport function defineInterrupt<\n const TId extends string,\n const TResponseSchema extends PortableSchema,\n>(options: {\n id: TId\n responseSchema: TResponseSchema\n payloadSchema?: never\n}): DefinedInterruptDefinition<\n TId,\n undefined,\n TResponseSchema,\n undefined,\n undefined\n>\nexport function defineInterrupt<\n const TId extends string,\n const TPayloadSchema extends PortableSchema | undefined,\n const TResponseSchema extends PortableSchema | undefined,\n>(\n options: InterruptDefinitionOptions<TId, TPayloadSchema, TResponseSchema>,\n): InterruptDefinition<\n TId,\n TPayloadSchema,\n TResponseSchema,\n InferSchemaOutput<TPayloadSchema>,\n InferSchemaInput<TPayloadSchema>\n> {\n validateNonEmptyString(options.id, 'Interrupt definition id')\n const hasResponseSchema = options.responseSchema !== undefined\n const responseJson = hasResponseSchema\n ? schemaJson(options.responseSchema, 'responseSchema')\n : undefined\n const hasPayloadSchema = Object.prototype.hasOwnProperty.call(\n options,\n 'payloadSchema',\n )\n const payloadJson = hasPayloadSchema\n ? schemaJson(options.payloadSchema, 'payloadSchema')\n : undefined\n const schemaState: DefinitionSchemaState = {\n ...(responseJson\n ? {\n responseSchemaCanonicalJson: responseJson.canonicalJson,\n responseSchemaHash: digestInterruptJson(responseJson.canonicalJson),\n }\n : {}),\n ...(payloadJson\n ? {\n payloadSchemaCanonicalJson: payloadJson.canonicalJson,\n payloadSchemaHash: digestInterruptJson(payloadJson.canonicalJson),\n }\n : {}),\n }\n const definition = {\n id: options.id,\n payloadSchema: options.payloadSchema,\n responseSchema: options.responseSchema,\n interrupt(input: InterruptInput<TPayloadSchema>) {\n return createRequest(input, false)\n },\n } as InterruptDefinition<\n TId,\n TPayloadSchema,\n TResponseSchema,\n InferSchemaOutput<TPayloadSchema>,\n InferSchemaInput<TPayloadSchema>\n >\n const parsePayload = (payload: unknown): unknown => {\n const payloadSchema = options.payloadSchema\n if (payloadSchema === undefined) {\n throw new TypeError(\n 'This interrupt definition does not accept a payload.',\n )\n }\n return parseInterruptPayload(payloadSchema, payload)\n }\n const createRequest: InterruptRequestFactory = (input, payloadIsParsed) => {\n for (const key of Object.keys(input)) {\n if (!['key', 'payload', 'reason', 'message', 'expiresAt'].includes(key)) {\n throw new TypeError(`Interrupt input field ${key} is not allowed.`)\n }\n }\n const key = validateNonEmptyString(input.key, 'Interrupt key')\n const reason = validateNonEmptyString(input.reason, 'Interrupt reason')\n const message = validateNonEmptyString(input.message, 'Interrupt message')\n if ('payload' in input) {\n if (!hasPayloadSchema) {\n throw new TypeError(\n 'This interrupt definition does not accept a payload.',\n )\n }\n if (input.payload !== undefined) {\n validateJson(input.payload, 'Interrupt payload')\n }\n }\n const parsedPayload =\n 'payload' in input\n ? payloadIsParsed\n ? input.payload\n : parsePayload(input.payload)\n : undefined\n const payload =\n parsedPayload === undefined\n ? undefined\n : cloneAndDeepFreezeJson(parsedPayload)\n const expiresAt =\n input.expiresAt === undefined\n ? undefined\n : validateExpiresAt(input.expiresAt)\n const request = Object.freeze({\n definition,\n key,\n ...(hasPayloadSchema && payload !== undefined ? { payload } : {}),\n reason,\n message,\n ...(expiresAt !== undefined ? { expiresAt } : {}),\n })\n if (!payloadIsParsed) {\n interruptRequestInputs.set(\n request,\n cloneAndDeepFreezeJson({\n key,\n reason,\n message,\n ...(expiresAt !== undefined ? { expiresAt } : {}),\n ...(parsedPayload !== undefined ? { payload: parsedPayload } : {}),\n }),\n )\n }\n return request\n }\n definitionSchemaState.set(definition, schemaState)\n interruptRequestFactories.set(definition, createRequest)\n return Object.freeze(definition)\n}\n"],"mappings":";;;;AAeA,IAAa,iCACX;AACF,IAAa,yBAAyB;AAwBtC,IAAM,wCAAwB,IAAI,QAAuC;AAmLzE,SAAgB,uBACd,SACA,SAGI,CAAC,GACqB;CAC1B,MAAM,cAAc,sBAAsB,IAAI,QAAQ,UAAU;CAChE,IAAI,CAAC,aACH,MAAM,IAAI,UAAU,mDAAmD;CAEzE,MAAM,EAAE,UAAU,kBAAkB,YAAY,eAAe;CAC/D,OAAO;EACL,YAAY;GACV,GAAA;GACA,MAAM;GACN,cAAc,QAAQ,WAAW;GACjC,KAAK,QAAQ;GACb,GAAI,aAAa,KAAA,IAAY,EAAE,SAAS,IAAI,CAAC;GAC7C,GAAI,qBAAqB,KAAA,IAAY,EAAE,iBAAiB,IAAI,CAAC;GAC7D,GAAI,eAAe,KAAA,IAAY,EAAE,WAAW,IAAI,CAAC;GACjD,GAAI,eAAe,KAAA,IAAY,EAAE,WAAW,IAAI,CAAC;GACjD,GAAI,YAAY,8BACZ,EACE,6BACE,YAAY,4BAChB,IACA,CAAC;GACL,GAAI,YAAY,6BACZ,EAAE,4BAA4B,YAAY,2BAA2B,IACrE,CAAC;GACL,GAAI,YAAY,oBACZ,EAAE,mBAAmB,YAAY,kBAAkB,IACnD,CAAC;GACL,GAAI,YAAY,qBACZ,EAAE,oBAAoB,YAAY,mBAAmB,IACrD,CAAC;EACP;EACA,GAAI,aAAa,WAAW,QAAQ,YAAY,KAAA,IAC5C,EAAE,SAAS,QAAQ,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