@tanstack/ai-client 0.34.0 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/esm/chat-client.d.ts +18 -2
- package/dist/esm/chat-client.js +69 -16
- package/dist/esm/chat-client.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +2 -2
- package/dist/esm/interrupt-manager.d.ts +3 -0
- package/dist/esm/interrupt-manager.js +62 -5
- package/dist/esm/interrupt-manager.js.map +1 -1
- package/dist/esm/types.d.ts +3 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/web-mcp-tools.d.ts +60 -0
- package/dist/esm/web-mcp-tools.js +92 -1
- package/dist/esm/web-mcp-tools.js.map +1 -1
- package/package.json +5 -5
- package/src/chat-client.ts +134 -38
- package/src/index.ts +8 -1
- package/src/interrupt-manager.ts +91 -6
- package/src/types.ts +3 -0
- package/src/web-mcp-tools.ts +181 -0
package/dist/esm/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export { InterruptManager } from './interrupt-manager.js';
|
|
|
5
5
|
export type { InterruptManagerHydration, InterruptManagerOptions, InterruptManagerSubmission, } from './interrupt-manager.js';
|
|
6
6
|
export { createMcpAppBridge } from './mcp-app-bridge.js';
|
|
7
7
|
export type { McpAppBridge, CreateMcpAppBridgeOptions } from './mcp-app-bridge.js';
|
|
8
|
-
export { registerWebMCPTools } from './web-mcp-tools.js';
|
|
9
|
-
export type { RegisterWebMCPToolsOptions, WebMCPToolAnnotations, WebMCPToolOptions, WebMCPToolOptionsByName, } from './web-mcp-tools.js';
|
|
8
|
+
export { getWebMCPTools, registerWebMCPTools, subscribeWebMCPTools, } from './web-mcp-tools.js';
|
|
9
|
+
export type { GetWebMCPToolsOptions, RegisterWebMCPToolsOptions, SubscribeWebMCPToolsOptions, WebMCPPageTool, WebMCPToolAnnotations, WebMCPToolOptions, WebMCPToolOptionsByName, } from './web-mcp-tools.js';
|
|
10
10
|
export { RealtimeClient } from './realtime-client.js';
|
|
11
11
|
export { GenerationClient } from './generation-client.js';
|
|
12
12
|
export { VideoGenerationClient } from './video-generation-client.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { DurableStreamIncompleteError, StreamReconnectLimitError, StreamTruncate
|
|
|
4
4
|
import { InterruptManager } from "./interrupt-manager.js";
|
|
5
5
|
import { ChatClient } from "./chat-client.js";
|
|
6
6
|
import { createMcpAppBridge } from "./mcp-app-bridge.js";
|
|
7
|
-
import { registerWebMCPTools } from "./web-mcp-tools.js";
|
|
7
|
+
import { getWebMCPTools, registerWebMCPTools, subscribeWebMCPTools } from "./web-mcp-tools.js";
|
|
8
8
|
import { RealtimeClient } from "./realtime-client.js";
|
|
9
9
|
import { GENERATION_EVENTS } from "./generation-types.js";
|
|
10
10
|
import { GenerationClient } from "./generation-client.js";
|
|
@@ -14,4 +14,4 @@ import { clientTools, createChatClientOptions } from "./types.js";
|
|
|
14
14
|
import { StorageUnavailableError, indexedDBPersistence, localStoragePersistence, sessionStoragePersistence } from "./storage-adapters.js";
|
|
15
15
|
import { createAIDevtoolsGenerationPreview } from "./devtools.js";
|
|
16
16
|
import { BatchStrategy, CompositeStrategy, ImmediateStrategy, PartialJSONParser, PunctuationStrategy, StreamProcessor, WordBoundaryStrategy, convertMessagesToModelMessages, defaultJSONParser, generateMessageId, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, parsePartialJSON, uiMessageToModelMessages } from "@tanstack/ai/client";
|
|
17
|
-
export { AudioRecorder, BatchStrategy, ChatClient, CompositeStrategy, DurableStreamIncompleteError, GENERATION_EVENTS, GenerationClient, ImmediateStrategy, InterruptManager, PartialJSONParser, PunctuationStrategy, RealtimeClient, StorageUnavailableError, StreamProcessor, StreamReconnectLimitError, StreamTruncatedError, UnsupportedResponseStreamError, VideoGenerationClient, WordBoundaryStrategy, clientTools, convertMessagesToModelMessages, createAIDevtoolsGenerationPreview, createChatClientOptions, createMcpAppBridge, defaultJSONParser, fetchHttpStream, fetchServerSentEvents, generateMessageId, indexedDBPersistence, localStoragePersistence, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, parsePartialJSON, reconstructAudioResult, reconstructImageResult, reconstructSpeechResult, reconstructSummarizeResult, reconstructTranscriptionResult, registerWebMCPTools, rpcStream, sessionStoragePersistence, stream, uiMessageToModelMessages, webSocket, xhrHttpStream, xhrServerSentEvents };
|
|
17
|
+
export { AudioRecorder, BatchStrategy, ChatClient, CompositeStrategy, DurableStreamIncompleteError, GENERATION_EVENTS, GenerationClient, ImmediateStrategy, InterruptManager, PartialJSONParser, PunctuationStrategy, RealtimeClient, StorageUnavailableError, StreamProcessor, StreamReconnectLimitError, StreamTruncatedError, UnsupportedResponseStreamError, VideoGenerationClient, WordBoundaryStrategy, clientTools, convertMessagesToModelMessages, createAIDevtoolsGenerationPreview, createChatClientOptions, createMcpAppBridge, defaultJSONParser, fetchHttpStream, fetchServerSentEvents, generateMessageId, getWebMCPTools, indexedDBPersistence, localStoragePersistence, modelMessageToUIMessage, modelMessagesToUIMessages, normalizeToUIMessage, parsePartialJSON, reconstructAudioResult, reconstructImageResult, reconstructSpeechResult, reconstructSummarizeResult, reconstructTranscriptionResult, registerWebMCPTools, rpcStream, sessionStoragePersistence, stream, subscribeWebMCPTools, uiMessageToModelMessages, webSocket, xhrHttpStream, xhrServerSentEvents };
|
|
@@ -53,6 +53,9 @@ export declare class InterruptManager<TTools extends ReadonlyArray<AnyClientTool
|
|
|
53
53
|
cancel(): void;
|
|
54
54
|
retry(): void;
|
|
55
55
|
resolveClientToolOutput(toolCallId: string, output: unknown): boolean;
|
|
56
|
+
resolveClientToolError(toolCallId: string, errorText: string): boolean;
|
|
57
|
+
private resolveClientToolResult;
|
|
58
|
+
private stageClientToolError;
|
|
56
59
|
resolveToolApprovalDecision(interruptId: string, approved: boolean): boolean;
|
|
57
60
|
private hydrateInterrupt;
|
|
58
61
|
private buildSnapshot;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { INTERRUPT_BINDING_METADATA_KEY, INTERRUPT_BINDING_VERSION, canonicalInterruptJson, canonicalizeInterruptResolutions, cloneAndDeepFreezeJson, digestInterruptJson, genericInterruptContinuationFromDescriptor, hashInterruptDefinitionSchema, hashSchemaInput, isStandardSchema, normalizeApprovalSchema, readInterruptBinding, wrapGenericInterruptContinuation } from "@tanstack/ai/client";
|
|
1
|
+
import { INTERRUPT_BINDING_METADATA_KEY, INTERRUPT_BINDING_VERSION, canonicalInterruptJson, canonicalizeInterruptResolutions, cloneAndDeepFreezeJson, digestInterruptJson, genericInterruptContinuationFromDescriptor, hashInterruptDefinitionSchema, hashSchemaInput, isStandardSchema, normalizeApprovalSchema, readInterruptBinding, withTanstackMetadata, wrapGenericInterruptContinuation } from "@tanstack/ai/client";
|
|
2
2
|
//#region src/interrupt-manager.ts
|
|
3
3
|
function isClientOwnedInterrupt(item) {
|
|
4
4
|
return item.resumable;
|
|
5
5
|
}
|
|
6
6
|
function resolutionWithContinuation(item, resolution) {
|
|
7
7
|
const continuation = genericInterruptContinuationFromDescriptor(item.descriptor);
|
|
8
|
-
if (
|
|
9
|
-
return {
|
|
8
|
+
if (continuation) return {
|
|
10
9
|
...resolution,
|
|
11
10
|
metadata: wrapGenericInterruptContinuation(continuation)
|
|
12
11
|
};
|
|
12
|
+
return resolution;
|
|
13
13
|
}
|
|
14
14
|
function isRootResolvableInterrupt(interrupt) {
|
|
15
15
|
return "cancel" in interrupt && "clearResolution" in interrupt;
|
|
@@ -329,11 +329,51 @@ var InterruptManager = class {
|
|
|
329
329
|
this.submitBatch(submission);
|
|
330
330
|
}
|
|
331
331
|
resolveClientToolOutput(toolCallId, output) {
|
|
332
|
+
return this.resolveClientToolResult(toolCallId, {
|
|
333
|
+
state: "output-available",
|
|
334
|
+
output
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
resolveClientToolError(toolCallId, errorText) {
|
|
338
|
+
return this.resolveClientToolResult(toolCallId, {
|
|
339
|
+
state: "output-error",
|
|
340
|
+
errorText
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
resolveClientToolResult(toolCallId, result) {
|
|
332
344
|
const item = this.items.find((candidate) => candidate.kind === "client-tool-execution" && candidate.binding?.kind === "client-tool-execution" && candidate.binding.toolCallId === toolCallId || candidate.kind === "generic" && isClientToolExecutionReason(candidate.descriptor.reason) && candidate.descriptor.toolCallId === toolCallId && isLegacyClientToolMetadata(candidate.descriptor.metadata));
|
|
333
345
|
if (!item) return false;
|
|
334
|
-
|
|
346
|
+
if (item.kind !== "client-tool-execution") {
|
|
347
|
+
this.resolveItem(item.descriptor.id, result.state === "output-error" ? { error: result.errorText } : result.output);
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
if (result.state === "output-available") {
|
|
351
|
+
this.resolveItem(item.descriptor.id, result.output);
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
this.stageClientToolError(item, result.errorText);
|
|
335
355
|
return true;
|
|
336
356
|
}
|
|
357
|
+
stageClientToolError(item, errorText) {
|
|
358
|
+
this.assertItemMutable();
|
|
359
|
+
this.invalidateRetry();
|
|
360
|
+
if (!item.canResolve) {
|
|
361
|
+
item.status = "error";
|
|
362
|
+
item.error = this.itemError(item.descriptor.id, "invalid-response-schema", "The interrupt response schema is invalid and cannot be resolved.");
|
|
363
|
+
this.publish();
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
item.validationGeneration++;
|
|
367
|
+
item.resolution = cloneAndDeepFreezeJson(withTanstackMetadata(resolutionWithContinuation(item, {
|
|
368
|
+
interruptId: item.descriptor.id,
|
|
369
|
+
status: "resolved",
|
|
370
|
+
payload: { error: errorText }
|
|
371
|
+
}), { state: "output-error" }));
|
|
372
|
+
item.status = "staged";
|
|
373
|
+
item.error = void 0;
|
|
374
|
+
this.publish();
|
|
375
|
+
this.maybeSubmit();
|
|
376
|
+
}
|
|
337
377
|
resolveToolApprovalDecision(interruptId, approved) {
|
|
338
378
|
const item = this.items.find((candidate) => candidate.descriptor.id === interruptId && (candidate.kind === "tool-approval" || candidate.kind === "generic" && candidate.descriptor.reason === "approval_required" && isLegacyApprovalMetadata(candidate.descriptor.metadata)));
|
|
339
379
|
if (!item) return false;
|
|
@@ -646,7 +686,24 @@ var InterruptManager = class {
|
|
|
646
686
|
} : result;
|
|
647
687
|
return isPromiseLike(validation) ? Promise.resolve(validation).then(preserveInput) : preserveInput(validation);
|
|
648
688
|
}
|
|
649
|
-
if (item.kind === "client-tool-execution")
|
|
689
|
+
if (item.kind === "client-tool-execution") {
|
|
690
|
+
const validation = validateWithSchema(item.tool?.outputSchema, payload, "invalid-tool-output");
|
|
691
|
+
const canonicalize = (result) => {
|
|
692
|
+
if (!("valid" in result)) return result;
|
|
693
|
+
try {
|
|
694
|
+
return {
|
|
695
|
+
valid: true,
|
|
696
|
+
payload: cloneAndDeepFreezeJson(result.payload)
|
|
697
|
+
};
|
|
698
|
+
} catch (error) {
|
|
699
|
+
return {
|
|
700
|
+
code: "invalid-tool-output",
|
|
701
|
+
message: error instanceof Error ? error.message : String(error)
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
return isPromiseLike(validation) ? Promise.resolve(validation).then(canonicalize) : canonicalize(validation);
|
|
706
|
+
}
|
|
650
707
|
return this.validateApprovalCandidate(item, payload);
|
|
651
708
|
}
|
|
652
709
|
validateApprovalCandidate(item, payload) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interrupt-manager.js","names":[],"sources":["../../src/interrupt-manager.ts"],"sourcesContent":["import {\n INTERRUPT_BINDING_METADATA_KEY,\n INTERRUPT_BINDING_VERSION,\n canonicalInterruptJson,\n canonicalizeInterruptResolutions,\n cloneAndDeepFreezeJson,\n digestInterruptJson,\n genericInterruptContinuationFromDescriptor,\n hashInterruptDefinitionSchema,\n hashSchemaInput,\n isStandardSchema,\n normalizeApprovalSchema,\n readInterruptBinding,\n wrapGenericInterruptContinuation,\n} from '@tanstack/ai/client'\nimport type {\n AnyClientTool,\n BatchInterruptError,\n Interrupt,\n InterruptBinding,\n InterruptDefinition,\n InterruptSubmissionError,\n ItemInterruptError,\n RunAgentResumeItem,\n} from '@tanstack/ai/client'\nimport type {\n BoundInterruptBase,\n BoundInterrupts,\n ChatInterrupt,\n ChatInterruptState,\n GenericAGUIInterrupt,\n InterruptItemStatus,\n ResolvableChatInterrupt,\n UnboundInterrupt,\n} from './types'\n\nexport interface InterruptManagerHydration {\n threadId: string\n interruptedRunId: string\n generation: number\n interrupts: ReadonlyArray<Interrupt>\n}\n\nexport interface InterruptManagerSubmission {\n threadId: string\n interruptedRunId: string\n generation: number\n resolutions: ReadonlyArray<RunAgentResumeItem>\n canonicalResolutions: string\n fingerprint: string\n}\n\nexport type InterruptManagerChangeSource = 'hydrate' | 'live'\n\nexport interface InterruptManagerOptions<\n TTools extends ReadonlyArray<AnyClientTool>,\n TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>> =\n readonly [],\n> {\n tools?: TTools\n interrupts?: TInterrupts\n submit: (submission: InterruptManagerSubmission) => Promise<void>\n onChange?: (source: InterruptManagerChangeSource) => void\n}\n\ntype UnknownObject = { [key: string]: unknown }\n\ntype RuntimeKind =\n | 'generic'\n | 'tool-approval'\n | 'client-tool-execution'\n /** Carries no binding we understand — not ours to resume. */\n | 'unbound'\n\ninterface RuntimeInterrupt {\n descriptor: Interrupt\n /** `undefined` only for `unbound` items. */\n binding: InterruptBinding | undefined\n kind: RuntimeKind\n status: InterruptItemStatus\n canResolve: boolean\n error?: ItemInterruptError\n resolution?: RunAgentResumeItem\n tool?: AnyClientTool\n definition?: InterruptDefinition<any, any, any, any>\n /** Validated display payload for a registered first-party generic item. */\n payload?: unknown\n /** This binding is valid and can participate in this chat resume batch. */\n resumable: boolean\n validationGeneration: number\n}\n\ninterface ValidationFailure {\n code: ItemInterruptError['code']\n message: string\n path?: ReadonlyArray<string | number>\n}\n\ntype ValidationResult = { valid: true; payload: unknown } | ValidationFailure\n\ninterface TransactionToken {\n active: boolean\n}\n\ninterface SubmissionOperation {\n submission: InterruptManagerSubmission\n}\n\ninterface RuntimeInterruptCheckpoint {\n status: InterruptItemStatus\n resolution?: RunAgentResumeItem\n error?: ItemInterruptError\n validationGeneration: number\n}\n\nfunction isClientOwnedInterrupt(item: RuntimeInterrupt): boolean {\n return item.resumable\n}\n\nfunction resolutionWithContinuation(\n item: RuntimeInterrupt,\n resolution: RunAgentResumeItem,\n): RunAgentResumeItem {\n const continuation = genericInterruptContinuationFromDescriptor(\n item.descriptor,\n )\n if (!continuation) return resolution\n return {\n ...resolution,\n metadata: wrapGenericInterruptContinuation(continuation),\n }\n}\n\nfunction isRootResolvableInterrupt<\n TTools extends ReadonlyArray<AnyClientTool>,\n TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>>,\n>(\n interrupt: ChatInterrupt<TTools, TInterrupts>,\n): interrupt is ResolvableChatInterrupt<TTools, TInterrupts> {\n return 'cancel' in interrupt && 'clearResolution' in interrupt\n}\n\nconst itemErrorCodes = new Set<ItemInterruptError['code']>([\n 'invalid-payload',\n 'invalid-edited-args',\n 'invalid-tool-output',\n 'invalid-response-schema',\n 'unknown-interrupt',\n 'expired',\n 'stale',\n 'conflict',\n 'legacy-unsupported',\n])\n\nconst batchErrorCodes = new Set<BatchInterruptError['code']>([\n 'incomplete-batch',\n 'item-validation-failed',\n 'unsupported-bulk-operation',\n 'async-resolver',\n 'inactive-transaction',\n 'mixed-provenance',\n 'transport',\n 'server',\n 'protocol',\n 'invalid-response-schema',\n 'expired',\n 'stale',\n 'conflict',\n 'legacy-submit-failed',\n])\n\nfunction isUnknownObject(value: unknown): value is UnknownObject {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction isLegacyApprovalMetadata(value: unknown): boolean {\n return (\n isUnknownObject(value) &&\n value['kind'] === 'approval' &&\n typeof value['toolName'] === 'string' &&\n 'input' in value\n )\n}\n\nfunction isLegacyClientToolMetadata(value: unknown): boolean {\n return (\n isUnknownObject(value) &&\n value['kind'] === 'client_tool' &&\n typeof value['toolName'] === 'string' &&\n 'input' in value\n )\n}\n\n/**\n * Does this descriptor carry the pre-binding TanStack metadata marker?\n *\n * Descriptors emitted before the resume binding existed are still ours to\n * resume, so they must not be mistaken for another producer's interrupt.\n */\nfunction isLegacyInterruptMetadata(interrupt: Interrupt): boolean {\n return (\n isLegacyApprovalMetadata(interrupt.metadata) ||\n isLegacyClientToolMetadata(interrupt.metadata)\n )\n}\n\nfunction getDescriptorBinding(\n interrupt: Interrupt,\n): InterruptBinding | undefined {\n return readInterruptBinding(interrupt)\n}\n\nfunction hasReservedFirstPartyBindingMarker(interrupt: Interrupt): boolean {\n if (!isUnknownObject(interrupt.metadata)) return false\n const binding = interrupt.metadata[INTERRUPT_BINDING_METADATA_KEY]\n if (!isUnknownObject(binding)) return false\n if (\n binding['v'] !== undefined &&\n binding['v'] !== INTERRUPT_BINDING_VERSION\n ) {\n return false\n }\n return (\n binding['kind'] === 'generic' ||\n binding['kind'] === 'tool-approval' ||\n binding['kind'] === 'client-tool-execution' ||\n 'definitionId' in binding ||\n 'key' in binding ||\n 'batchIndex' in binding ||\n 'payloadSchemaHash' in binding\n )\n}\n\nfunction hasFirstPartyGenericMarker(interrupt: Interrupt): boolean {\n if (!isUnknownObject(interrupt.metadata)) return false\n const binding = interrupt.metadata[INTERRUPT_BINDING_METADATA_KEY]\n if (!isUnknownObject(binding) || binding['kind'] !== 'generic') return false\n return (\n 'definitionId' in binding ||\n 'key' in binding ||\n 'batchIndex' in binding ||\n 'payloadSchemaHash' in binding\n )\n}\n\nfunction getInterruptPayload(interrupt: Interrupt): unknown {\n return interrupt.metadata?.['tanstack:interruptPayload']\n}\n\n/**\n * Only used to route *legacy* (pre-binding) descriptors, which have no binding\n * to classify off. Current descriptors are classified by their binding alone.\n */\nfunction isClientToolExecutionReason(reason: string): boolean {\n return (\n reason === 'tanstack:client_tool_execution' ||\n reason === 'client_tool_input'\n )\n}\n\nfunction responseSchemaHash(interrupt: Interrupt): string | undefined {\n if (interrupt.responseSchema === undefined) return undefined\n try {\n return digestInterruptJson(canonicalInterruptJson(interrupt.responseSchema))\n } catch {\n return undefined\n }\n}\n\nfunction definitionSchemaHash(\n schema: InterruptDefinition<any, any, any, any>['responseSchema'] | undefined,\n): string | undefined {\n if (schema === undefined) return undefined\n try {\n return hashInterruptDefinitionSchema(schema)\n } catch {\n return undefined\n }\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 validateWithSchema(\n schema: unknown,\n value: unknown,\n code: ItemInterruptError['code'],\n): ValidationResult | Promise<ValidationResult> {\n if (schema === undefined) return { valid: true, payload: value }\n if (isStandardSchema(schema)) {\n const result = schema['~standard'].validate(value)\n const normalize = (\n validation: Awaited<typeof result>,\n ): ValidationResult => {\n if (!validation.issues) {\n return { valid: true, payload: validation.value }\n }\n return {\n code,\n message: validation.issues[0]?.message ?? 'Schema validation failed.',\n }\n }\n return isPromiseLike(result)\n ? Promise.resolve(result).then(normalize)\n : normalize(result)\n }\n // A non-Standard-Schema value (a raw JSON Schema arriving over the wire) is\n // not validated by the library. The application transforms the schema and\n // validates the value itself before resolving; whatever it passes flows\n // through as-is.\n return { valid: true, payload: value }\n}\n\nfunction isItemErrorCode(value: string): value is ItemInterruptError['code'] {\n for (const code of itemErrorCodes) if (code === value) return true\n return false\n}\n\nfunction isBatchErrorCode(value: string): value is BatchInterruptError['code'] {\n for (const code of batchErrorCodes) if (code === value) return true\n return false\n}\n\nfunction isSubmissionError(value: unknown): value is InterruptSubmissionError {\n if (!isUnknownObject(value)) return false\n const scope = value['scope']\n const code = value['code']\n const base =\n typeof code === 'string' &&\n typeof value['message'] === 'string' &&\n typeof value['retryable'] === 'boolean' &&\n typeof value['threadId'] === 'string' &&\n typeof value['interruptedRunId'] === 'string' &&\n typeof value['generation'] === 'number'\n if (!base) return false\n if (scope === 'item') {\n return (\n isItemErrorCode(code) &&\n typeof value['interruptId'] === 'string' &&\n (value['source'] === 'client' || value['source'] === 'server')\n )\n }\n return (\n scope === 'batch' &&\n isBatchErrorCode(code) &&\n Array.isArray(value['interruptIds']) &&\n value['interruptIds'].every((id) => typeof id === 'string') &&\n (value['source'] === 'client' ||\n value['source'] === 'server' ||\n value['source'] === 'transport')\n )\n}\n\nfunction readSubmissionErrors(\n error: unknown,\n): ReadonlyArray<InterruptSubmissionError> {\n if (isSubmissionError(error)) return [error]\n if (!isUnknownObject(error) || !Array.isArray(error['errors'])) return []\n return error['errors'].every(isSubmissionError) ? error['errors'] : []\n}\n\nfunction haveSameInterruptIds(\n left: ReadonlyArray<string>,\n right: ReadonlyArray<string>,\n): boolean {\n if (left.length !== right.length) return false\n const sortedLeft = [...left].sort()\n const sortedRight = [...right].sort()\n return sortedLeft.every((id, index) => id === sortedRight[index])\n}\n\nfunction haveSameBatchCorrelation(\n left: BatchInterruptError,\n right: BatchInterruptError,\n): boolean {\n return (\n left.threadId === right.threadId &&\n left.interruptedRunId === right.interruptedRunId &&\n left.generation === right.generation &&\n haveSameInterruptIds(left.interruptIds, right.interruptIds)\n )\n}\n\nfunction mergeSubmissionBatchErrors(\n current: ReadonlyArray<BatchInterruptError>,\n previousSubmission: ReadonlyArray<BatchInterruptError>,\n incoming: ReadonlyArray<BatchInterruptError>,\n): {\n rootErrors: ReadonlyArray<BatchInterruptError>\n submissionRootErrors: ReadonlyArray<BatchInterruptError>\n} {\n const replaceableIncoming = incoming.filter(\n (error) => error.source !== 'transport',\n )\n const isSuperseded = (candidate: BatchInterruptError): boolean =>\n previousSubmission.includes(candidate) &&\n replaceableIncoming.some((error) =>\n haveSameBatchCorrelation(candidate, error),\n )\n const retainedRootErrors = current.filter(\n (candidate) => !isSuperseded(candidate),\n )\n const retainedSubmissionRootErrors = previousSubmission.filter(\n (candidate) =>\n !replaceableIncoming.some((error) =>\n haveSameBatchCorrelation(candidate, error),\n ),\n )\n return Object.freeze({\n rootErrors: Object.freeze([...retainedRootErrors, ...incoming]),\n submissionRootErrors: Object.freeze([\n ...retainedSubmissionRootErrors,\n ...replaceableIncoming,\n ]),\n })\n}\n\nfunction submissionErrorMatchesActiveBatch(\n error: InterruptSubmissionError,\n submission: InterruptManagerSubmission,\n): boolean {\n if (\n error.threadId !== submission.threadId ||\n error.interruptedRunId !== submission.interruptedRunId ||\n error.generation !== submission.generation\n ) {\n return false\n }\n const interruptIds = submission.resolutions.map(\n (resolution) => resolution.interruptId,\n )\n return error.scope === 'item'\n ? interruptIds.includes(error.interruptId)\n : haveSameInterruptIds(error.interruptIds, interruptIds)\n}\n\nfunction genericBinding(\n interrupt: Interrupt,\n hydration: InterruptManagerHydration,\n candidate: InterruptBinding | undefined,\n): InterruptBinding {\n const schemaHash =\n responseSchemaHash(interrupt) ?? candidate?.responseSchemaHash\n return cloneAndDeepFreezeJson({\n v: INTERRUPT_BINDING_VERSION,\n kind: 'generic',\n interruptId: interrupt.id,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n ...(schemaHash !== undefined ? { responseSchemaHash: schemaHash } : {}),\n ...(interrupt.expiresAt !== undefined\n ? { expiresAt: interrupt.expiresAt }\n : {}),\n })\n}\n\nfunction baseSnapshot(\n item: RuntimeInterrupt,\n hydration: InterruptManagerHydration,\n): Omit<BoundInterruptBase, 'cancel' | 'clearResolution'> {\n const descriptor = cloneAndDeepFreezeJson(item.descriptor)\n const errors: ReadonlyArray<ItemInterruptError> =\n item.error === undefined\n ? Object.freeze([])\n : Object.freeze([cloneAndDeepFreezeJson(item.error)])\n const error = errors[0]\n return {\n id: descriptor.id,\n interruptId: descriptor.id,\n reason: descriptor.reason,\n ...(descriptor.message !== undefined\n ? { message: descriptor.message }\n : {}),\n ...(descriptor.responseSchema !== undefined\n ? { responseSchema: descriptor.responseSchema }\n : {}),\n ...(descriptor.expiresAt !== undefined\n ? { expiresAt: descriptor.expiresAt }\n : {}),\n ...(descriptor.metadata !== undefined\n ? { metadata: descriptor.metadata }\n : {}),\n threadId: hydration.threadId,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n status: item.status,\n errors,\n ...(error !== undefined ? { error } : {}),\n canResolve: item.canResolve,\n }\n}\n\nexport class InterruptManager<\n TTools extends ReadonlyArray<AnyClientTool> = ReadonlyArray<AnyClientTool>,\n TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>> =\n readonly [],\n> {\n private hydration: InterruptManagerHydration | undefined\n private items: Array<RuntimeInterrupt> = []\n private snapshot: ReadonlyArray<ChatInterrupt<TTools, TInterrupts>> =\n Object.freeze([])\n private rootErrors: ReadonlyArray<BatchInterruptError> = Object.freeze([])\n private submissionRootErrors: ReadonlyArray<BatchInterruptError> =\n Object.freeze([])\n private state: ChatInterruptState<TTools, TInterrupts> = Object.freeze({\n interrupts: this.snapshot,\n pendingInterrupts: this.snapshot,\n interruptErrors: this.rootErrors,\n resuming: false,\n })\n private activeTransaction: TransactionToken | undefined\n private activeSubmissionOperation: SubmissionOperation | undefined\n private retrySubmission: InterruptManagerSubmission | undefined\n private resuming = false\n private tools: TTools | undefined\n private readonly interruptDefinitions: ReadonlyMap<\n string,\n InterruptDefinition<any, any, any, any>\n >\n\n constructor(\n private readonly options: InterruptManagerOptions<TTools, TInterrupts>,\n ) {\n this.tools = options.tools\n const definitions = new Map<\n string,\n InterruptDefinition<any, any, any, any>\n >()\n for (const definition of options.interrupts ?? []) {\n if (definitions.has(definition.id)) {\n throw new Error(`Duplicate interrupt definition id: ${definition.id}`)\n }\n definitions.set(definition.id, definition)\n }\n this.interruptDefinitions = definitions\n }\n\n updateTools(tools: TTools): void {\n this.tools = tools\n }\n\n hydrate(\n hydration: InterruptManagerHydration,\n source: InterruptManagerChangeSource = 'live',\n ): void {\n this.activeSubmissionOperation = undefined\n this.hydration = {\n threadId: hydration.threadId,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n interrupts: cloneAndDeepFreezeJson(hydration.interrupts),\n }\n const firstPartyIndexes = new Map<number, number>()\n for (const interrupt of hydration.interrupts) {\n const binding = getDescriptorBinding(interrupt)\n if (\n binding?.kind === 'generic' &&\n binding.definitionId !== undefined &&\n binding.key !== undefined &&\n binding.batchIndex !== undefined\n ) {\n firstPartyIndexes.set(\n binding.batchIndex,\n (firstPartyIndexes.get(binding.batchIndex) ?? 0) + 1,\n )\n }\n }\n this.items = hydration.interrupts.map((interrupt) =>\n this.hydrateInterrupt(interrupt, hydration, firstPartyIndexes),\n )\n this.rootErrors = Object.freeze([])\n this.submissionRootErrors = Object.freeze([])\n this.retrySubmission = undefined\n this.resuming = false\n this.publish(source)\n }\n\n getInterrupts(): BoundInterrupts<TTools, TInterrupts> {\n return this.snapshot\n }\n\n getState(): ChatInterruptState<TTools, TInterrupts> {\n return this.state\n }\n\n getDescriptors(): ReadonlyArray<Interrupt> {\n return this.hydration?.interrupts ?? Object.freeze([])\n }\n\n hasValidatedFirstPartyGenericBatch(): boolean {\n return this.items.some(\n (item) => item.kind === 'generic' && item.definition !== undefined,\n )\n }\n\n reset(options?: {\n preserveRootErrors?: boolean\n source?: InterruptManagerChangeSource\n }): void {\n this.activeSubmissionOperation = undefined\n this.hydration = undefined\n this.items = []\n this.snapshot = Object.freeze([])\n if (options?.preserveRootErrors !== true) {\n this.rootErrors = Object.freeze([])\n this.submissionRootErrors = Object.freeze([])\n }\n this.retrySubmission = undefined\n this.resuming = false\n this.state = Object.freeze({\n interrupts: this.snapshot,\n pendingInterrupts: this.snapshot,\n interruptErrors: this.rootErrors,\n resuming: false,\n })\n this.options.onChange?.(options?.source ?? 'live')\n }\n\n getInterruptErrors(): ReadonlyArray<BatchInterruptError> {\n return this.rootErrors\n }\n\n getResuming(): boolean {\n return this.resuming\n }\n\n resolve(approved: boolean): void\n resolve(\n resolver: (\n interrupt: ResolvableChatInterrupt<TTools, TInterrupts>,\n ) => undefined,\n ): void\n resolve(\n resolution:\n | boolean\n | ((interrupt: ResolvableChatInterrupt<TTools, TInterrupts>) => unknown),\n ): void {\n this.assertRootMutable()\n if (typeof resolution === 'boolean') {\n this.resolveBooleanBulk(resolution)\n return\n }\n this.resolveTransaction(resolution)\n }\n\n cancel(): void {\n this.assertRootMutable()\n this.invalidateRetry()\n for (const item of this.items) {\n if (!isClientOwnedInterrupt(item)) continue\n item.validationGeneration++\n item.resolution = Object.freeze(\n resolutionWithContinuation(item, {\n interruptId: item.descriptor.id,\n status: 'cancelled',\n }),\n )\n item.status = 'staged'\n item.error = undefined\n }\n this.publish()\n this.maybeSubmit()\n }\n\n retry(): void {\n if (this.resuming)\n throw new Error('Interrupt submission is already active.')\n const submission = this.retrySubmission\n if (!submission) {\n this.addRootError(\n 'transport',\n 'There is no retryable interrupt submission.',\n false,\n )\n return\n }\n this.submitBatch(submission)\n }\n\n resolveClientToolOutput(toolCallId: string, output: unknown): boolean {\n const item = this.items.find(\n (candidate) =>\n (candidate.kind === 'client-tool-execution' &&\n candidate.binding?.kind === 'client-tool-execution' &&\n candidate.binding.toolCallId === toolCallId) ||\n (candidate.kind === 'generic' &&\n isClientToolExecutionReason(candidate.descriptor.reason) &&\n candidate.descriptor.toolCallId === toolCallId &&\n isLegacyClientToolMetadata(candidate.descriptor.metadata)),\n )\n if (!item) return false\n this.resolveItem(item.descriptor.id, output)\n return true\n }\n\n resolveToolApprovalDecision(interruptId: string, approved: boolean): boolean {\n const item = this.items.find(\n (candidate) =>\n candidate.descriptor.id === interruptId &&\n (candidate.kind === 'tool-approval' ||\n (candidate.kind === 'generic' &&\n candidate.descriptor.reason === 'approval_required' &&\n isLegacyApprovalMetadata(candidate.descriptor.metadata))),\n )\n if (!item) return false\n this.resolveItem(item.descriptor.id, { approved })\n return true\n }\n\n private hydrateInterrupt(\n descriptor: Interrupt,\n hydration: InterruptManagerHydration,\n firstPartyIndexes: ReadonlyMap<number, number>,\n ): RuntimeInterrupt {\n const interrupt = cloneAndDeepFreezeJson(descriptor)\n const candidate = getDescriptorBinding(interrupt)\n const legacyResumable =\n candidate === undefined && isLegacyInterruptMetadata(interrupt)\n\n // No binding we understand, and nothing else identifying the descriptor as\n // ours, means this interrupt was not produced by this package's resume\n // path — a workflow engine's durable approval projected onto the same\n // AG-UI stream, a third-party agent's pause, or a binding written at a\n // protocol version we don't know.\n //\n // Do not invent a binding for it. Synthesising one would render a\n // resolvable form whose answer is submitted against a run that has no\n // matching pending descriptor, failing late as `unknown-interrupt` after\n // the user has already filled it in. Surface it as unresolvable instead,\n // so \"someone else owns this pause\" is visible rather than silently\n // translated into an AI-domain interrupt.\n //\n // Pre-binding TanStack descriptors are still ours: they carry the legacy\n // `metadata.kind` marker, so they keep hydrating through the generic path\n // below.\n if (candidate === undefined && !legacyResumable) {\n if (hasReservedFirstPartyBindingMarker(interrupt)) {\n return {\n descriptor: interrupt,\n binding: genericBinding(interrupt, hydration, undefined),\n kind: 'generic',\n status: 'error',\n canResolve: false,\n resumable: false,\n error: this.itemError(\n interrupt.id,\n 'stale',\n 'The interrupt binding is invalid or incomplete.',\n ),\n validationGeneration: 0,\n }\n }\n return {\n descriptor: interrupt,\n binding: undefined,\n kind: 'unbound',\n status: 'pending',\n canResolve: false,\n resumable: false,\n validationGeneration: 0,\n }\n }\n\n const correlated =\n candidate !== undefined &&\n candidate.interruptId === interrupt.id &&\n candidate.interruptedRunId === hydration.interruptedRunId &&\n candidate.generation === hydration.generation &&\n responseSchemaHash(interrupt) === candidate.responseSchemaHash\n\n const structurallyCorrelated =\n candidate !== undefined &&\n candidate.interruptId === interrupt.id &&\n candidate.interruptedRunId === hydration.interruptedRunId &&\n candidate.generation === hydration.generation &&\n candidate.responseSchemaHash ===\n (responseSchemaHash(interrupt) ?? candidate.responseSchemaHash)\n\n if (\n candidate !== undefined &&\n hasFirstPartyGenericMarker(interrupt) &&\n (!structurallyCorrelated ||\n candidate.kind !== 'generic' ||\n candidate.definitionId === undefined ||\n candidate.key === undefined ||\n candidate.batchIndex === undefined)\n ) {\n return {\n descriptor: interrupt,\n binding: genericBinding(interrupt, hydration, candidate),\n kind: 'generic',\n status: 'error',\n canResolve: false,\n resumable: false,\n error: this.itemError(\n interrupt.id,\n 'stale',\n 'The interrupt binding does not match this interrupted run.',\n ),\n validationGeneration: 0,\n }\n }\n\n if (structurallyCorrelated && candidate.kind === 'tool-approval') {\n const tool = this.tools?.find(\n (configured) => configured.name === candidate.toolName,\n )\n // Gated on the binding and the schema hashes below, not on\n // `interrupt.reason` — that string is free-form AG-UI text another\n // producer can also use, so it cannot be what decides ownership.\n if (\n tool?.needsApproval === true &&\n interrupt.toolCallId === candidate.toolCallId\n ) {\n try {\n const approval = normalizeApprovalSchema(\n tool.approvalSchema,\n tool.inputSchema,\n )\n if (\n hashSchemaInput(tool.inputSchema) === candidate.inputSchemaHash &&\n approval.approvalSchemaHash === candidate.approvalSchemaHash &&\n approval.responseSchemaHash === candidate.responseSchemaHash\n ) {\n return {\n descriptor: interrupt,\n binding: cloneAndDeepFreezeJson(candidate),\n kind: 'tool-approval',\n status: 'pending',\n canResolve: true,\n resumable: true,\n tool,\n validationGeneration: 0,\n }\n }\n } catch {\n // Invalid configured schemas cannot safely grant typed hydration.\n }\n }\n }\n\n if (structurallyCorrelated && candidate.kind === 'client-tool-execution') {\n const tool = this.tools?.find(\n (configured) => configured.name === candidate.toolName,\n )\n // Binding-gated, for the same reason as tool approvals above.\n if (\n tool !== undefined &&\n interrupt.toolCallId === candidate.toolCallId &&\n hashSchemaInput(tool.outputSchema) === candidate.outputSchemaHash\n ) {\n return {\n descriptor: interrupt,\n binding: cloneAndDeepFreezeJson(candidate),\n kind: 'client-tool-execution',\n status: 'pending',\n canResolve: true,\n resumable: true,\n tool,\n validationGeneration: 0,\n }\n }\n }\n\n if (\n candidate !== undefined &&\n candidate.kind === 'generic' &&\n candidate.definitionId !== undefined &&\n candidate.key !== undefined &&\n candidate.batchIndex !== undefined &&\n candidate.key.length > 0 &&\n firstPartyIndexes.get(candidate.batchIndex) !== 1\n ) {\n return {\n descriptor: interrupt,\n binding: cloneAndDeepFreezeJson(candidate),\n kind: 'generic',\n status: 'error',\n canResolve: false,\n resumable: false,\n error: this.itemError(\n interrupt.id,\n 'stale',\n 'Generic interrupt batch contains a duplicate batchIndex.',\n ),\n validationGeneration: 0,\n }\n }\n\n if (\n correlated &&\n candidate.kind === 'generic' &&\n candidate.definitionId !== undefined &&\n candidate.key !== undefined &&\n candidate.batchIndex !== undefined &&\n candidate.key.length > 0 &&\n firstPartyIndexes.get(candidate.batchIndex) === 1\n ) {\n const definition = this.interruptDefinitions.get(candidate.definitionId)\n if (\n definition !== undefined &&\n definitionSchemaHash(definition.responseSchema) ===\n candidate.responseSchemaHash &&\n (definition.payloadSchema === undefined\n ? candidate.payloadSchemaHash === undefined\n : candidate.payloadSchemaHash ===\n definitionSchemaHash(definition.payloadSchema))\n ) {\n const rawPayload = getInterruptPayload(interrupt)\n // First-party display payloads are parsed by definition.interrupt()\n // before the server emits them. Re-validating here would feed schema\n // output back through an input schema and reject transforms such as\n // z.string().transform(Number). The checks above still bind this value\n // to the exact descriptor, run, generation, definition, and schemas.\n return {\n descriptor: interrupt,\n binding: cloneAndDeepFreezeJson(candidate),\n definition,\n kind: 'generic',\n status: 'pending',\n canResolve: true,\n resumable: true,\n ...(rawPayload === undefined\n ? {}\n : { payload: cloneAndDeepFreezeJson(rawPayload) }),\n validationGeneration: 0,\n }\n }\n }\n\n const resumable =\n legacyResumable ||\n (candidate !== undefined &&\n candidate.interruptId === interrupt.id &&\n candidate.interruptedRunId === hydration.interruptedRunId &&\n candidate.generation === hydration.generation &&\n (candidate.kind !== 'generic' ||\n responseSchemaHash(interrupt) === undefined ||\n candidate.responseSchemaHash === responseSchemaHash(interrupt)))\n return {\n descriptor: interrupt,\n binding: genericBinding(interrupt, hydration, candidate),\n kind: 'generic',\n status: 'pending',\n // A valid raw binding is an explicit request to use this resume path,\n // even when this client has no registered first-party definition. Keep\n // it untyped, but preserve its existing generic controls. Missing,\n // malformed, and unsupported bindings remain display-only.\n canResolve: resumable,\n resumable,\n validationGeneration: 0,\n }\n }\n\n private buildSnapshot(\n transaction?: TransactionToken,\n ): BoundInterrupts<TTools, TInterrupts> {\n const hydration = this.requireHydration()\n // `client-tool-execution` items stay in `this.items` (they usually gate\n // batch submission and are resolved internally via auto-execution /\n // addToolResult), but they are never surfaced as public bound interrupts.\n // A mixed generic batch is the exception: those client tools wait for\n // `toolResume` and must not block submit.\n //\n // Items with status `submitting` are also omitted: the resume stream is\n // already in flight, so Approve/Deny is not actionable. Keeping them in\n // the public list made UIs look stuck after a successful approve and\n // blocked follow-up turns that key off `interrupts.length`.\n const next = this.items\n .filter(\n (item) =>\n item.kind !== 'client-tool-execution' && item.status !== 'submitting',\n )\n .map((item) => {\n const base = baseSnapshot(item, hydration)\n // Not ours to resume: expose the descriptor so a UI can show the run\n // is paused, with no `resolveInterrupt` to call.\n if (item.kind === 'unbound' || item.binding === undefined) {\n const snapshot: UnboundInterrupt = {\n ...base,\n kind: 'unbound',\n canResolve: false,\n }\n return Object.freeze(snapshot)\n }\n if (\n item.kind === 'tool-approval' &&\n item.binding.kind === 'tool-approval'\n ) {\n const binding = cloneAndDeepFreezeJson(item.binding)\n const snapshot = {\n ...base,\n kind: 'tool-approval' as const,\n binding,\n toolName: item.binding.toolName,\n toolCallId: item.binding.toolCallId,\n originalArgs: cloneAndDeepFreezeJson(item.binding.originalArgs),\n cancel: () => this.cancelItem(item.descriptor.id, transaction),\n clearResolution: () =>\n this.clearItem(item.descriptor.id, transaction),\n resolveInterrupt: (approved: boolean, options?: unknown) => {\n const details = isUnknownObject(options) ? options : undefined\n this.resolveItem(\n item.descriptor.id,\n {\n approved,\n ...(approved && details?.['editedArgs'] !== undefined\n ? { editedArgs: details['editedArgs'] }\n : {}),\n ...(details?.['payload'] !== undefined\n ? { payload: details['payload'] }\n : {}),\n },\n transaction,\n )\n },\n }\n return Object.freeze(snapshot)\n }\n const boundGeneric =\n item.binding.kind === 'generic'\n ? cloneAndDeepFreezeJson(item.binding)\n : cloneAndDeepFreezeJson({\n v: INTERRUPT_BINDING_VERSION,\n kind: 'generic' as const,\n interruptId: item.descriptor.id,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n ...(typeof item.binding.responseSchemaHash === 'string'\n ? { responseSchemaHash: item.binding.responseSchemaHash }\n : {}),\n })\n if (item.definition !== undefined && item.binding.kind === 'generic') {\n const snapshot = {\n ...base,\n kind: 'generic',\n definitionId: item.definition.id,\n key: item.binding.key ?? '',\n payload: item.payload,\n binding: boundGeneric,\n cancel: () => this.cancelItem(item.descriptor.id, transaction),\n clearResolution: () =>\n this.clearItem(item.descriptor.id, transaction),\n resolveInterrupt: (response: unknown) =>\n this.resolveItem(item.descriptor.id, response, transaction),\n }\n return Object.freeze(snapshot)\n }\n const snapshot: GenericAGUIInterrupt = {\n ...base,\n kind: 'generic',\n binding: boundGeneric,\n cancel: () => this.cancelItem(item.descriptor.id, transaction),\n clearResolution: () =>\n this.clearItem(item.descriptor.id, transaction),\n resolveInterrupt: (payload) =>\n this.resolveItem(item.descriptor.id, payload, transaction),\n }\n return Object.freeze(snapshot)\n })\n\n // The runtime items are created only from the exact configured TTools entry\n // selected by name. TypeScript cannot preserve that per-element lookup\n // through Array.map, so this generic return boundary restores the proven\n // distributive public union.\n return Object.freeze(next) as BoundInterrupts<TTools, TInterrupts>\n }\n\n // Provenance belongs to each publication because `onChange` may synchronously\n // mutate the manager and publish again before an outer callback returns.\n private publish(source: InterruptManagerChangeSource = 'live'): void {\n if (!this.hydration) {\n this.snapshot = Object.freeze([])\n this.state = Object.freeze({\n interrupts: this.snapshot,\n pendingInterrupts: this.snapshot,\n interruptErrors: this.rootErrors,\n resuming: this.resuming,\n })\n this.options.onChange?.(source)\n return\n }\n this.snapshot = this.buildSnapshot()\n this.state = Object.freeze({\n interrupts: this.snapshot,\n pendingInterrupts: this.snapshot,\n interruptErrors: this.rootErrors,\n resuming: this.resuming,\n })\n this.options.onChange?.(source)\n }\n\n private resolveItem(\n interruptId: string,\n payload: unknown,\n transaction?: TransactionToken,\n ): void {\n this.assertItemMutable(transaction)\n const item = this.findItem(interruptId)\n this.invalidateRetry()\n if (!item.canResolve) {\n item.status = 'error'\n item.error = this.itemError(\n interruptId,\n 'invalid-response-schema',\n 'The interrupt response schema is invalid and cannot be resolved.',\n )\n if (!transaction) this.publish()\n return\n }\n const validationGeneration = ++item.validationGeneration\n const validation = this.validateCandidate(item, payload)\n if (isPromiseLike(validation)) {\n item.status = 'validating'\n item.error = undefined\n if (!transaction) this.publish()\n void Promise.resolve(validation)\n .then((result) => {\n if (validationGeneration !== item.validationGeneration) return\n this.applyValidation(item, result, transaction)\n })\n .catch((error: unknown) => {\n if (validationGeneration !== item.validationGeneration) return\n this.applyValidation(\n item,\n {\n code: this.validationCode(item),\n message: error instanceof Error ? error.message : String(error),\n },\n transaction,\n )\n })\n return\n }\n this.applyValidation(item, validation, transaction)\n }\n\n private cancelItem(\n interruptId: string,\n transaction?: TransactionToken,\n ): void {\n this.assertItemMutable(transaction)\n const item = this.findItem(interruptId)\n this.invalidateRetry()\n item.validationGeneration++\n item.resolution = Object.freeze(\n resolutionWithContinuation(item, { interruptId, status: 'cancelled' }),\n )\n item.status = 'staged'\n item.error = undefined\n if (!transaction) {\n this.publish()\n this.maybeSubmit()\n }\n }\n\n private clearItem(interruptId: string, transaction?: TransactionToken): void {\n this.assertItemMutable(transaction)\n const item = this.findItem(interruptId)\n this.invalidateRetry()\n item.validationGeneration++\n item.resolution = undefined\n item.error = undefined\n item.status = 'pending'\n if (!transaction) this.publish()\n }\n\n private maybeSubmit(): void {\n // Unbound items can never be resolved through this path — something else\n // owns them. Including them in the completeness gate would deadlock the\n // batch, so the run's own interrupts could never be answered once a\n // foreign one shared the stream.\n const hasGeneric = this.items.some((item) => item.kind === 'generic')\n const ours = this.items.filter(\n (item) =>\n isClientOwnedInterrupt(item) &&\n !(hasGeneric && item.kind === 'client-tool-execution'),\n )\n if (\n ours.length === 0 ||\n ours.some(\n (item) => item.resolution === undefined || item.status !== 'staged',\n )\n ) {\n return\n }\n const hydration = this.requireHydration()\n const canonical = canonicalizeInterruptResolutions(\n ours.map((item) => item.resolution).filter((item) => item !== undefined),\n )\n const submission = Object.freeze({\n threadId: hydration.threadId,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n resolutions: canonical.resolutions,\n canonicalResolutions: canonical.canonicalResolutions,\n fingerprint: canonical.fingerprint,\n })\n this.submitBatch(submission)\n }\n\n private applyValidation(\n item: RuntimeInterrupt,\n result: ValidationResult,\n transaction?: TransactionToken,\n ): void {\n if (!('valid' in result)) {\n item.status = 'error'\n const itemError = this.itemError(\n item.descriptor.id,\n result.code,\n result.message,\n result.path,\n )\n item.error = itemError\n // Client-tool-execution items are hidden from the public interrupt list,\n // so promote their validation failures onto interruptErrors for the UI.\n if (item.kind === 'client-tool-execution') {\n this.rootErrors = Object.freeze([\n ...this.rootErrors.filter(\n (error) =>\n !(\n error.code === 'item-validation-failed' &&\n error.interruptIds.includes(item.descriptor.id)\n ),\n ),\n Object.freeze({\n scope: 'batch' as const,\n code: 'item-validation-failed' as const,\n message: itemError.message,\n source: 'client' as const,\n retryable: false,\n interruptIds: Object.freeze([item.descriptor.id]),\n threadId: itemError.threadId,\n interruptedRunId: itemError.interruptedRunId,\n generation: itemError.generation,\n }),\n ])\n }\n if (!transaction) this.publish()\n return\n }\n item.resolution = cloneAndDeepFreezeJson(\n resolutionWithContinuation(item, {\n interruptId: item.descriptor.id,\n status: 'resolved',\n payload: result.payload,\n }),\n )\n item.status = 'staged'\n item.error = undefined\n if (!transaction) {\n this.publish()\n this.maybeSubmit()\n }\n }\n\n private validateCandidate(\n item: RuntimeInterrupt,\n payload: unknown,\n ): ValidationResult | Promise<ValidationResult> {\n if (item.kind === 'generic') {\n const validation = validateWithSchema(\n item.definition?.responseSchema ?? item.descriptor.responseSchema,\n payload,\n 'invalid-payload',\n )\n if (item.definition === undefined) return validation\n const preserveInput = (result: ValidationResult): ValidationResult =>\n 'valid' in result ? { valid: true, payload } : result\n return isPromiseLike(validation)\n ? Promise.resolve(validation).then(preserveInput)\n : preserveInput(validation)\n }\n if (item.kind === 'client-tool-execution') {\n return validateWithSchema(\n item.tool?.outputSchema,\n payload,\n 'invalid-tool-output',\n )\n }\n return this.validateApprovalCandidate(item, payload)\n }\n\n private validateApprovalCandidate(\n item: RuntimeInterrupt,\n payload: unknown,\n ): ValidationResult | Promise<ValidationResult> {\n if (!isUnknownObject(payload) || typeof payload['approved'] !== 'boolean') {\n return {\n code: 'invalid-payload',\n message: 'Tool approval resolutions require an approved boolean.',\n }\n }\n const approved = payload['approved']\n const editedArgs = payload['editedArgs']\n if (!approved && editedArgs !== undefined) {\n return {\n code: 'invalid-edited-args',\n message: 'Rejected tool approvals cannot edit tool arguments.',\n }\n }\n if (approved && editedArgs !== undefined) {\n const editedValidation = validateWithSchema(\n item.tool?.inputSchema,\n editedArgs,\n 'invalid-edited-args',\n )\n if (isPromiseLike(editedValidation)) {\n return Promise.resolve(editedValidation).then((result) =>\n 'valid' in result\n ? this.validateApprovalPayload(item, payload, result.payload)\n : result,\n )\n }\n if (!('valid' in editedValidation)) return editedValidation\n return this.validateApprovalPayload(\n item,\n payload,\n editedValidation.payload,\n )\n }\n return this.validateApprovalPayload(item, payload, undefined)\n }\n\n private validateApprovalPayload(\n item: RuntimeInterrupt,\n envelope: UnknownObject,\n validatedEditedArgs: unknown,\n ): ValidationResult | Promise<ValidationResult> {\n const approved = envelope['approved'] === true\n const schema = this.approvalBranchSchema(item.tool, approved)\n const branchPayload = envelope['payload']\n if (schema === undefined && branchPayload !== undefined) {\n return {\n code: 'invalid-payload',\n message: 'This approval branch does not accept a payload.',\n }\n }\n if (schema !== undefined && branchPayload === undefined) {\n return {\n code: 'invalid-payload',\n message: 'This approval branch requires a payload.',\n }\n }\n const validation = validateWithSchema(\n schema,\n branchPayload,\n 'invalid-payload',\n )\n const buildEnvelope = (result: ValidationResult): ValidationResult => {\n if (!('valid' in result)) return result\n return {\n valid: true,\n payload: {\n approved,\n ...(validatedEditedArgs !== undefined\n ? { editedArgs: validatedEditedArgs }\n : {}),\n ...(schema !== undefined ? { payload: result.payload } : {}),\n },\n }\n }\n return isPromiseLike(validation)\n ? Promise.resolve(validation).then(buildEnvelope)\n : buildEnvelope(validation)\n }\n\n private approvalBranchSchema(\n tool: AnyClientTool | undefined,\n approved: boolean,\n ): unknown {\n const approvalSchema: unknown = tool?.approvalSchema\n if (!isUnknownObject(approvalSchema)) return approvalSchema\n const hasBranches =\n 'approve' in approvalSchema || 'reject' in approvalSchema\n if (!hasBranches) return approvalSchema\n return approved ? approvalSchema['approve'] : approvalSchema['reject']\n }\n\n private validationCode(item: RuntimeInterrupt): ItemInterruptError['code'] {\n return item.kind === 'client-tool-execution'\n ? 'invalid-tool-output'\n : 'invalid-payload'\n }\n\n private resolveBooleanBulk(approved: boolean): void {\n // `client-tool-execution` items resolve out-of-band (auto execution /\n // addToolResult); they are transparent to the boolean shorthand. Eligibility\n // and resolution consider only the publicly resolvable items.\n const resolvable = this.items.filter(\n (item) =>\n isClientOwnedInterrupt(item) && item.kind !== 'client-tool-execution',\n )\n const eligible = resolvable.every(\n (item) =>\n item.kind === 'tool-approval' &&\n this.approvalBranchSchema(item.tool, approved) === undefined,\n )\n if (!eligible || resolvable.length === 0) {\n this.addRootError(\n 'unsupported-bulk-operation',\n 'Boolean bulk resolution requires payloadless tool approvals.',\n false,\n )\n return\n }\n this.invalidateRetry()\n for (const item of resolvable) {\n item.validationGeneration++\n item.resolution = cloneAndDeepFreezeJson({\n interruptId: item.descriptor.id,\n status: 'resolved',\n payload: { approved },\n })\n item.status = 'staged'\n item.error = undefined\n }\n this.publish()\n this.maybeSubmit()\n }\n\n private resolveTransaction(\n resolver: (\n interrupt: ResolvableChatInterrupt<TTools, TInterrupts>,\n ) => unknown,\n ): void {\n const checkpoints = this.items.map<RuntimeInterruptCheckpoint>((item) => ({\n status: item.status,\n ...(item.resolution !== undefined ? { resolution: item.resolution } : {}),\n ...(item.error !== undefined ? { error: item.error } : {}),\n validationGeneration: item.validationGeneration,\n }))\n const token: TransactionToken = { active: true }\n this.activeTransaction = token\n const stable = this.buildSnapshot(token).filter(isRootResolvableInterrupt)\n let failure:\n | { code: BatchInterruptError['code']; message: string }\n | undefined\n try {\n for (const interrupt of stable) {\n const result = resolver(interrupt)\n if (result !== undefined) {\n failure = {\n code: isPromiseLike(result)\n ? 'async-resolver'\n : 'inactive-transaction',\n message: isPromiseLike(result)\n ? 'Interrupt transaction resolvers must be synchronous.'\n : 'Interrupt transaction resolvers must return literal undefined.',\n }\n break\n }\n }\n if (\n failure === undefined &&\n this.items.some(\n (item) =>\n // `client-tool-execution` items are resolved out-of-band (auto\n // execution / addToolResult), not by this synchronous resolver, so\n // they don't count against transaction completeness. `maybeSubmit`\n // still waits for them unless a generic interrupt shares the batch.\n isClientOwnedInterrupt(item) &&\n item.kind !== 'client-tool-execution' &&\n (item.resolution === undefined || item.status !== 'staged'),\n )\n ) {\n failure = {\n code: 'incomplete-batch',\n message: 'Interrupt transaction did not resolve every item.',\n }\n }\n } catch (error) {\n failure = {\n code: 'item-validation-failed',\n message: error instanceof Error ? error.message : String(error),\n }\n } finally {\n token.active = false\n this.activeTransaction = undefined\n }\n\n if (failure) {\n this.restoreCheckpoints(checkpoints)\n this.addRootError(failure.code, failure.message, false)\n return\n }\n this.publish()\n this.maybeSubmit()\n }\n\n private restoreCheckpoints(\n checkpoints: ReadonlyArray<RuntimeInterruptCheckpoint>,\n ): void {\n this.items.forEach((item, index) => {\n const checkpoint = checkpoints[index]\n if (!checkpoint) return\n item.status = checkpoint.status\n item.resolution = checkpoint.resolution\n item.error = checkpoint.error\n item.validationGeneration = checkpoint.validationGeneration + 1\n })\n this.publish()\n }\n\n private assertItemMutable(transaction?: TransactionToken): void {\n if (transaction && !transaction.active) {\n throw new Error('Interrupt transaction is inactive.')\n }\n if (this.activeTransaction && transaction !== this.activeTransaction) {\n throw new Error('Interrupt transaction is inactive.')\n }\n if (this.resuming) {\n throw new Error('Interrupts cannot be mutated while submitting.')\n }\n }\n\n private assertRootMutable(): void {\n if (this.activeTransaction) {\n throw new Error('Interrupt transaction is already active.')\n }\n if (this.resuming) {\n throw new Error('Interrupts cannot be mutated while submitting.')\n }\n }\n\n private invalidateRetry(): void {\n this.retrySubmission = undefined\n }\n\n private submitBatch(submission: InterruptManagerSubmission): void {\n // Track ownership so a superseded submission cannot mutate current state.\n const operation = { submission }\n this.activeSubmissionOperation = operation\n this.resuming = true\n this.retrySubmission = undefined\n for (const item of this.items) {\n if (isClientOwnedInterrupt(item)) item.status = 'submitting'\n }\n this.publish()\n void this.performSubmission(operation)\n }\n\n private async performSubmission(\n operation: SubmissionOperation,\n ): Promise<void> {\n try {\n await this.options.submit(operation.submission)\n } catch (error) {\n if (this.activeSubmissionOperation !== operation) return\n this.handleSubmissionFailure(error, operation.submission)\n } finally {\n if (this.activeSubmissionOperation === operation) {\n this.activeSubmissionOperation = undefined\n this.resuming = false\n this.publish()\n }\n }\n }\n\n private handleSubmissionFailure(\n error: unknown,\n submission: InterruptManagerSubmission,\n ): void {\n const errors = readSubmissionErrors(error)\n if (errors.length === 0) {\n const message = error instanceof Error ? error.message : String(error)\n this.addRootError('transport', message, true, 'transport')\n this.retrySubmission = submission\n for (const item of this.items) {\n if (isClientOwnedInterrupt(item)) item.status = 'error'\n }\n return\n }\n\n const correlatedErrors = errors.filter((submissionError) =>\n submissionErrorMatchesActiveBatch(submissionError, submission),\n )\n if (correlatedErrors.length !== errors.length) {\n this.addRootError(\n 'protocol',\n 'Interrupt submission errors did not match the active batch.',\n false,\n )\n }\n\n let nonRetryable = false\n let retryable = false\n const batchErrors: Array<BatchInterruptError> = []\n for (const submissionError of correlatedErrors) {\n if (\n submissionError.code === 'stale' ||\n submissionError.code === 'expired' ||\n submissionError.code === 'conflict'\n ) {\n nonRetryable = true\n }\n retryable ||= submissionError.retryable\n if (submissionError.scope === 'item') {\n const item = this.items.find(\n (candidate) =>\n isClientOwnedInterrupt(candidate) &&\n candidate.descriptor.id === submissionError.interruptId,\n )\n if (item) {\n item.status = 'error'\n item.error = cloneAndDeepFreezeJson(submissionError)\n }\n } else {\n batchErrors.push(cloneAndDeepFreezeJson(submissionError))\n }\n }\n const mergedBatchErrors = mergeSubmissionBatchErrors(\n this.rootErrors,\n this.submissionRootErrors,\n batchErrors,\n )\n this.rootErrors = mergedBatchErrors.rootErrors\n this.submissionRootErrors = mergedBatchErrors.submissionRootErrors\n for (const item of this.items) {\n if (isClientOwnedInterrupt(item) && item.status === 'submitting') {\n item.status = 'error'\n }\n }\n this.retrySubmission = retryable && !nonRetryable ? submission : undefined\n }\n\n private addRootError(\n code: BatchInterruptError['code'],\n message: string,\n retryable: boolean,\n source: BatchInterruptError['source'] = 'client',\n ): void {\n const hydration = this.requireHydration()\n this.rootErrors = Object.freeze([\n ...this.rootErrors,\n Object.freeze({\n scope: 'batch' as const,\n code,\n message,\n source,\n retryable,\n interruptIds: Object.freeze(\n this.items\n .filter(isClientOwnedInterrupt)\n .map((item) => item.descriptor.id),\n ),\n threadId: hydration.threadId,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n }),\n ])\n this.publish()\n }\n\n private findItem(interruptId: string): RuntimeInterrupt {\n const item = this.items.find(\n (candidate) => candidate.descriptor.id === interruptId,\n )\n if (!item) throw new Error(`Unknown interrupt: ${interruptId}`)\n return item\n }\n\n private requireHydration(): InterruptManagerHydration {\n if (!this.hydration) throw new Error('InterruptManager is not hydrated.')\n return this.hydration\n }\n\n private itemError(\n interruptId: string,\n code: ItemInterruptError['code'],\n message: string,\n path?: ReadonlyArray<string | number>,\n ): ItemInterruptError {\n const hydration = this.requireHydration()\n return Object.freeze({\n scope: 'item',\n interruptId,\n code,\n message,\n ...(path !== undefined ? { path: Object.freeze([...path]) } : {}),\n source: 'client',\n retryable: false,\n threadId: hydration.threadId,\n interruptedRun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interrupt-manager.ts"],"sourcesContent":["import {\n INTERRUPT_BINDING_METADATA_KEY,\n INTERRUPT_BINDING_VERSION,\n canonicalInterruptJson,\n canonicalizeInterruptResolutions,\n cloneAndDeepFreezeJson,\n digestInterruptJson,\n genericInterruptContinuationFromDescriptor,\n hashInterruptDefinitionSchema,\n hashSchemaInput,\n isStandardSchema,\n normalizeApprovalSchema,\n readInterruptBinding,\n withTanstackMetadata,\n wrapGenericInterruptContinuation,\n} from '@tanstack/ai/client'\nimport type {\n AnyClientTool,\n BatchInterruptError,\n Interrupt,\n InterruptBinding,\n InterruptDefinition,\n InterruptSubmissionError,\n ItemInterruptError,\n RunAgentResumeItem,\n} from '@tanstack/ai/client'\nimport type {\n BoundInterruptBase,\n BoundInterrupts,\n ChatInterrupt,\n ChatInterruptState,\n GenericAGUIInterrupt,\n InterruptItemStatus,\n ResolvableChatInterrupt,\n UnboundInterrupt,\n} from './types'\n\nexport interface InterruptManagerHydration {\n threadId: string\n interruptedRunId: string\n generation: number\n interrupts: ReadonlyArray<Interrupt>\n}\n\nexport interface InterruptManagerSubmission {\n threadId: string\n interruptedRunId: string\n generation: number\n resolutions: ReadonlyArray<RunAgentResumeItem>\n canonicalResolutions: string\n fingerprint: string\n}\n\nexport type InterruptManagerChangeSource = 'hydrate' | 'live'\n\nexport interface InterruptManagerOptions<\n TTools extends ReadonlyArray<AnyClientTool>,\n TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>> =\n readonly [],\n> {\n tools?: TTools\n interrupts?: TInterrupts\n submit: (submission: InterruptManagerSubmission) => Promise<void>\n onChange?: (source: InterruptManagerChangeSource) => void\n}\n\ntype UnknownObject = { [key: string]: unknown }\n\ntype RuntimeKind =\n | 'generic'\n | 'tool-approval'\n | 'client-tool-execution'\n /** Carries no binding we understand — not ours to resume. */\n | 'unbound'\n\ninterface RuntimeInterrupt {\n descriptor: Interrupt\n /** `undefined` only for `unbound` items. */\n binding: InterruptBinding | undefined\n kind: RuntimeKind\n status: InterruptItemStatus\n canResolve: boolean\n error?: ItemInterruptError\n resolution?: RunAgentResumeItem\n tool?: AnyClientTool\n definition?: InterruptDefinition<any, any, any, any>\n /** Validated display payload for a registered first-party generic item. */\n payload?: unknown\n /** This binding is valid and can participate in this chat resume batch. */\n resumable: boolean\n validationGeneration: number\n}\n\ninterface ValidationFailure {\n code: ItemInterruptError['code']\n message: string\n path?: ReadonlyArray<string | number>\n}\n\ntype ValidationResult = { valid: true; payload: unknown } | ValidationFailure\n\ninterface TransactionToken {\n active: boolean\n}\n\ninterface SubmissionOperation {\n submission: InterruptManagerSubmission\n}\n\ninterface RuntimeInterruptCheckpoint {\n status: InterruptItemStatus\n resolution?: RunAgentResumeItem\n error?: ItemInterruptError\n validationGeneration: number\n}\n\nfunction isClientOwnedInterrupt(item: RuntimeInterrupt): boolean {\n return item.resumable\n}\n\nfunction resolutionWithContinuation(\n item: RuntimeInterrupt,\n resolution: RunAgentResumeItem,\n): RunAgentResumeItem {\n const continuation = genericInterruptContinuationFromDescriptor(\n item.descriptor,\n )\n if (continuation) {\n return {\n ...resolution,\n metadata: wrapGenericInterruptContinuation(continuation),\n }\n }\n return resolution\n}\n\nfunction isRootResolvableInterrupt<\n TTools extends ReadonlyArray<AnyClientTool>,\n TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>>,\n>(\n interrupt: ChatInterrupt<TTools, TInterrupts>,\n): interrupt is ResolvableChatInterrupt<TTools, TInterrupts> {\n return 'cancel' in interrupt && 'clearResolution' in interrupt\n}\n\nconst itemErrorCodes = new Set<ItemInterruptError['code']>([\n 'invalid-payload',\n 'invalid-edited-args',\n 'invalid-tool-output',\n 'invalid-response-schema',\n 'unknown-interrupt',\n 'expired',\n 'stale',\n 'conflict',\n 'legacy-unsupported',\n])\n\nconst batchErrorCodes = new Set<BatchInterruptError['code']>([\n 'incomplete-batch',\n 'item-validation-failed',\n 'unsupported-bulk-operation',\n 'async-resolver',\n 'inactive-transaction',\n 'mixed-provenance',\n 'transport',\n 'server',\n 'protocol',\n 'invalid-response-schema',\n 'expired',\n 'stale',\n 'conflict',\n 'legacy-submit-failed',\n])\n\nfunction isUnknownObject(value: unknown): value is UnknownObject {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction isLegacyApprovalMetadata(value: unknown): boolean {\n return (\n isUnknownObject(value) &&\n value['kind'] === 'approval' &&\n typeof value['toolName'] === 'string' &&\n 'input' in value\n )\n}\n\nfunction isLegacyClientToolMetadata(value: unknown): boolean {\n return (\n isUnknownObject(value) &&\n value['kind'] === 'client_tool' &&\n typeof value['toolName'] === 'string' &&\n 'input' in value\n )\n}\n\n/**\n * Does this descriptor carry the pre-binding TanStack metadata marker?\n *\n * Descriptors emitted before the resume binding existed are still ours to\n * resume, so they must not be mistaken for another producer's interrupt.\n */\nfunction isLegacyInterruptMetadata(interrupt: Interrupt): boolean {\n return (\n isLegacyApprovalMetadata(interrupt.metadata) ||\n isLegacyClientToolMetadata(interrupt.metadata)\n )\n}\n\nfunction getDescriptorBinding(\n interrupt: Interrupt,\n): InterruptBinding | undefined {\n return readInterruptBinding(interrupt)\n}\n\nfunction hasReservedFirstPartyBindingMarker(interrupt: Interrupt): boolean {\n if (!isUnknownObject(interrupt.metadata)) return false\n const binding = interrupt.metadata[INTERRUPT_BINDING_METADATA_KEY]\n if (!isUnknownObject(binding)) return false\n if (\n binding['v'] !== undefined &&\n binding['v'] !== INTERRUPT_BINDING_VERSION\n ) {\n return false\n }\n return (\n binding['kind'] === 'generic' ||\n binding['kind'] === 'tool-approval' ||\n binding['kind'] === 'client-tool-execution' ||\n 'definitionId' in binding ||\n 'key' in binding ||\n 'batchIndex' in binding ||\n 'payloadSchemaHash' in binding\n )\n}\n\nfunction hasFirstPartyGenericMarker(interrupt: Interrupt): boolean {\n if (!isUnknownObject(interrupt.metadata)) return false\n const binding = interrupt.metadata[INTERRUPT_BINDING_METADATA_KEY]\n if (!isUnknownObject(binding) || binding['kind'] !== 'generic') return false\n return (\n 'definitionId' in binding ||\n 'key' in binding ||\n 'batchIndex' in binding ||\n 'payloadSchemaHash' in binding\n )\n}\n\nfunction getInterruptPayload(interrupt: Interrupt): unknown {\n return interrupt.metadata?.['tanstack:interruptPayload']\n}\n\n/**\n * Only used to route *legacy* (pre-binding) descriptors, which have no binding\n * to classify off. Current descriptors are classified by their binding alone.\n */\nfunction isClientToolExecutionReason(reason: string): boolean {\n return (\n reason === 'tanstack:client_tool_execution' ||\n reason === 'client_tool_input'\n )\n}\n\nfunction responseSchemaHash(interrupt: Interrupt): string | undefined {\n if (interrupt.responseSchema === undefined) return undefined\n try {\n return digestInterruptJson(canonicalInterruptJson(interrupt.responseSchema))\n } catch {\n return undefined\n }\n}\n\nfunction definitionSchemaHash(\n schema: InterruptDefinition<any, any, any, any>['responseSchema'] | undefined,\n): string | undefined {\n if (schema === undefined) return undefined\n try {\n return hashInterruptDefinitionSchema(schema)\n } catch {\n return undefined\n }\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 validateWithSchema(\n schema: unknown,\n value: unknown,\n code: ItemInterruptError['code'],\n): ValidationResult | Promise<ValidationResult> {\n if (schema === undefined) return { valid: true, payload: value }\n if (isStandardSchema(schema)) {\n const result = schema['~standard'].validate(value)\n const normalize = (\n validation: Awaited<typeof result>,\n ): ValidationResult => {\n if (!validation.issues) {\n return { valid: true, payload: validation.value }\n }\n return {\n code,\n message: validation.issues[0]?.message ?? 'Schema validation failed.',\n }\n }\n return isPromiseLike(result)\n ? Promise.resolve(result).then(normalize)\n : normalize(result)\n }\n // A non-Standard-Schema value (a raw JSON Schema arriving over the wire) is\n // not validated by the library. The application transforms the schema and\n // validates the value itself before resolving; whatever it passes flows\n // through as-is.\n return { valid: true, payload: value }\n}\n\nfunction isItemErrorCode(value: string): value is ItemInterruptError['code'] {\n for (const code of itemErrorCodes) if (code === value) return true\n return false\n}\n\nfunction isBatchErrorCode(value: string): value is BatchInterruptError['code'] {\n for (const code of batchErrorCodes) if (code === value) return true\n return false\n}\n\nfunction isSubmissionError(value: unknown): value is InterruptSubmissionError {\n if (!isUnknownObject(value)) return false\n const scope = value['scope']\n const code = value['code']\n const base =\n typeof code === 'string' &&\n typeof value['message'] === 'string' &&\n typeof value['retryable'] === 'boolean' &&\n typeof value['threadId'] === 'string' &&\n typeof value['interruptedRunId'] === 'string' &&\n typeof value['generation'] === 'number'\n if (!base) return false\n if (scope === 'item') {\n return (\n isItemErrorCode(code) &&\n typeof value['interruptId'] === 'string' &&\n (value['source'] === 'client' || value['source'] === 'server')\n )\n }\n return (\n scope === 'batch' &&\n isBatchErrorCode(code) &&\n Array.isArray(value['interruptIds']) &&\n value['interruptIds'].every((id) => typeof id === 'string') &&\n (value['source'] === 'client' ||\n value['source'] === 'server' ||\n value['source'] === 'transport')\n )\n}\n\nfunction readSubmissionErrors(\n error: unknown,\n): ReadonlyArray<InterruptSubmissionError> {\n if (isSubmissionError(error)) return [error]\n if (!isUnknownObject(error) || !Array.isArray(error['errors'])) return []\n return error['errors'].every(isSubmissionError) ? error['errors'] : []\n}\n\nfunction haveSameInterruptIds(\n left: ReadonlyArray<string>,\n right: ReadonlyArray<string>,\n): boolean {\n if (left.length !== right.length) return false\n const sortedLeft = [...left].sort()\n const sortedRight = [...right].sort()\n return sortedLeft.every((id, index) => id === sortedRight[index])\n}\n\nfunction haveSameBatchCorrelation(\n left: BatchInterruptError,\n right: BatchInterruptError,\n): boolean {\n return (\n left.threadId === right.threadId &&\n left.interruptedRunId === right.interruptedRunId &&\n left.generation === right.generation &&\n haveSameInterruptIds(left.interruptIds, right.interruptIds)\n )\n}\n\nfunction mergeSubmissionBatchErrors(\n current: ReadonlyArray<BatchInterruptError>,\n previousSubmission: ReadonlyArray<BatchInterruptError>,\n incoming: ReadonlyArray<BatchInterruptError>,\n): {\n rootErrors: ReadonlyArray<BatchInterruptError>\n submissionRootErrors: ReadonlyArray<BatchInterruptError>\n} {\n const replaceableIncoming = incoming.filter(\n (error) => error.source !== 'transport',\n )\n const isSuperseded = (candidate: BatchInterruptError): boolean =>\n previousSubmission.includes(candidate) &&\n replaceableIncoming.some((error) =>\n haveSameBatchCorrelation(candidate, error),\n )\n const retainedRootErrors = current.filter(\n (candidate) => !isSuperseded(candidate),\n )\n const retainedSubmissionRootErrors = previousSubmission.filter(\n (candidate) =>\n !replaceableIncoming.some((error) =>\n haveSameBatchCorrelation(candidate, error),\n ),\n )\n return Object.freeze({\n rootErrors: Object.freeze([...retainedRootErrors, ...incoming]),\n submissionRootErrors: Object.freeze([\n ...retainedSubmissionRootErrors,\n ...replaceableIncoming,\n ]),\n })\n}\n\nfunction submissionErrorMatchesActiveBatch(\n error: InterruptSubmissionError,\n submission: InterruptManagerSubmission,\n): boolean {\n if (\n error.threadId !== submission.threadId ||\n error.interruptedRunId !== submission.interruptedRunId ||\n error.generation !== submission.generation\n ) {\n return false\n }\n const interruptIds = submission.resolutions.map(\n (resolution) => resolution.interruptId,\n )\n return error.scope === 'item'\n ? interruptIds.includes(error.interruptId)\n : haveSameInterruptIds(error.interruptIds, interruptIds)\n}\n\nfunction genericBinding(\n interrupt: Interrupt,\n hydration: InterruptManagerHydration,\n candidate: InterruptBinding | undefined,\n): InterruptBinding {\n const schemaHash =\n responseSchemaHash(interrupt) ?? candidate?.responseSchemaHash\n return cloneAndDeepFreezeJson({\n v: INTERRUPT_BINDING_VERSION,\n kind: 'generic',\n interruptId: interrupt.id,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n ...(schemaHash !== undefined ? { responseSchemaHash: schemaHash } : {}),\n ...(interrupt.expiresAt !== undefined\n ? { expiresAt: interrupt.expiresAt }\n : {}),\n })\n}\n\nfunction baseSnapshot(\n item: RuntimeInterrupt,\n hydration: InterruptManagerHydration,\n): Omit<BoundInterruptBase, 'cancel' | 'clearResolution'> {\n const descriptor = cloneAndDeepFreezeJson(item.descriptor)\n const errors: ReadonlyArray<ItemInterruptError> =\n item.error === undefined\n ? Object.freeze([])\n : Object.freeze([cloneAndDeepFreezeJson(item.error)])\n const error = errors[0]\n return {\n id: descriptor.id,\n interruptId: descriptor.id,\n reason: descriptor.reason,\n ...(descriptor.message !== undefined\n ? { message: descriptor.message }\n : {}),\n ...(descriptor.responseSchema !== undefined\n ? { responseSchema: descriptor.responseSchema }\n : {}),\n ...(descriptor.expiresAt !== undefined\n ? { expiresAt: descriptor.expiresAt }\n : {}),\n ...(descriptor.metadata !== undefined\n ? { metadata: descriptor.metadata }\n : {}),\n threadId: hydration.threadId,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n status: item.status,\n errors,\n ...(error !== undefined ? { error } : {}),\n canResolve: item.canResolve,\n }\n}\n\nexport class InterruptManager<\n TTools extends ReadonlyArray<AnyClientTool> = ReadonlyArray<AnyClientTool>,\n TInterrupts extends ReadonlyArray<InterruptDefinition<any, any, any, any>> =\n readonly [],\n> {\n private hydration: InterruptManagerHydration | undefined\n private items: Array<RuntimeInterrupt> = []\n private snapshot: ReadonlyArray<ChatInterrupt<TTools, TInterrupts>> =\n Object.freeze([])\n private rootErrors: ReadonlyArray<BatchInterruptError> = Object.freeze([])\n private submissionRootErrors: ReadonlyArray<BatchInterruptError> =\n Object.freeze([])\n private state: ChatInterruptState<TTools, TInterrupts> = Object.freeze({\n interrupts: this.snapshot,\n pendingInterrupts: this.snapshot,\n interruptErrors: this.rootErrors,\n resuming: false,\n })\n private activeTransaction: TransactionToken | undefined\n private activeSubmissionOperation: SubmissionOperation | undefined\n private retrySubmission: InterruptManagerSubmission | undefined\n private resuming = false\n private tools: TTools | undefined\n private readonly interruptDefinitions: ReadonlyMap<\n string,\n InterruptDefinition<any, any, any, any>\n >\n\n constructor(\n private readonly options: InterruptManagerOptions<TTools, TInterrupts>,\n ) {\n this.tools = options.tools\n const definitions = new Map<\n string,\n InterruptDefinition<any, any, any, any>\n >()\n for (const definition of options.interrupts ?? []) {\n if (definitions.has(definition.id)) {\n throw new Error(`Duplicate interrupt definition id: ${definition.id}`)\n }\n definitions.set(definition.id, definition)\n }\n this.interruptDefinitions = definitions\n }\n\n updateTools(tools: TTools): void {\n this.tools = tools\n }\n\n hydrate(\n hydration: InterruptManagerHydration,\n source: InterruptManagerChangeSource = 'live',\n ): void {\n this.activeSubmissionOperation = undefined\n this.hydration = {\n threadId: hydration.threadId,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n interrupts: cloneAndDeepFreezeJson(hydration.interrupts),\n }\n const firstPartyIndexes = new Map<number, number>()\n for (const interrupt of hydration.interrupts) {\n const binding = getDescriptorBinding(interrupt)\n if (\n binding?.kind === 'generic' &&\n binding.definitionId !== undefined &&\n binding.key !== undefined &&\n binding.batchIndex !== undefined\n ) {\n firstPartyIndexes.set(\n binding.batchIndex,\n (firstPartyIndexes.get(binding.batchIndex) ?? 0) + 1,\n )\n }\n }\n this.items = hydration.interrupts.map((interrupt) =>\n this.hydrateInterrupt(interrupt, hydration, firstPartyIndexes),\n )\n this.rootErrors = Object.freeze([])\n this.submissionRootErrors = Object.freeze([])\n this.retrySubmission = undefined\n this.resuming = false\n this.publish(source)\n }\n\n getInterrupts(): BoundInterrupts<TTools, TInterrupts> {\n return this.snapshot\n }\n\n getState(): ChatInterruptState<TTools, TInterrupts> {\n return this.state\n }\n\n getDescriptors(): ReadonlyArray<Interrupt> {\n return this.hydration?.interrupts ?? Object.freeze([])\n }\n\n hasValidatedFirstPartyGenericBatch(): boolean {\n return this.items.some(\n (item) => item.kind === 'generic' && item.definition !== undefined,\n )\n }\n\n reset(options?: {\n preserveRootErrors?: boolean\n source?: InterruptManagerChangeSource\n }): void {\n this.activeSubmissionOperation = undefined\n this.hydration = undefined\n this.items = []\n this.snapshot = Object.freeze([])\n if (options?.preserveRootErrors !== true) {\n this.rootErrors = Object.freeze([])\n this.submissionRootErrors = Object.freeze([])\n }\n this.retrySubmission = undefined\n this.resuming = false\n this.state = Object.freeze({\n interrupts: this.snapshot,\n pendingInterrupts: this.snapshot,\n interruptErrors: this.rootErrors,\n resuming: false,\n })\n this.options.onChange?.(options?.source ?? 'live')\n }\n\n getInterruptErrors(): ReadonlyArray<BatchInterruptError> {\n return this.rootErrors\n }\n\n getResuming(): boolean {\n return this.resuming\n }\n\n resolve(approved: boolean): void\n resolve(\n resolver: (\n interrupt: ResolvableChatInterrupt<TTools, TInterrupts>,\n ) => undefined,\n ): void\n resolve(\n resolution:\n | boolean\n | ((interrupt: ResolvableChatInterrupt<TTools, TInterrupts>) => unknown),\n ): void {\n this.assertRootMutable()\n if (typeof resolution === 'boolean') {\n this.resolveBooleanBulk(resolution)\n return\n }\n this.resolveTransaction(resolution)\n }\n\n cancel(): void {\n this.assertRootMutable()\n this.invalidateRetry()\n for (const item of this.items) {\n if (!isClientOwnedInterrupt(item)) continue\n item.validationGeneration++\n item.resolution = Object.freeze(\n resolutionWithContinuation(item, {\n interruptId: item.descriptor.id,\n status: 'cancelled',\n }),\n )\n item.status = 'staged'\n item.error = undefined\n }\n this.publish()\n this.maybeSubmit()\n }\n\n retry(): void {\n if (this.resuming)\n throw new Error('Interrupt submission is already active.')\n const submission = this.retrySubmission\n if (!submission) {\n this.addRootError(\n 'transport',\n 'There is no retryable interrupt submission.',\n false,\n )\n return\n }\n this.submitBatch(submission)\n }\n\n resolveClientToolOutput(toolCallId: string, output: unknown): boolean {\n return this.resolveClientToolResult(toolCallId, {\n state: 'output-available',\n output,\n })\n }\n\n resolveClientToolError(toolCallId: string, errorText: string): boolean {\n return this.resolveClientToolResult(toolCallId, {\n state: 'output-error',\n errorText,\n })\n }\n\n private resolveClientToolResult(\n toolCallId: string,\n result:\n | { state: 'output-available'; output: unknown }\n | { state: 'output-error'; errorText: string },\n ): boolean {\n const item = this.items.find(\n (candidate) =>\n (candidate.kind === 'client-tool-execution' &&\n candidate.binding?.kind === 'client-tool-execution' &&\n candidate.binding.toolCallId === toolCallId) ||\n (candidate.kind === 'generic' &&\n isClientToolExecutionReason(candidate.descriptor.reason) &&\n candidate.descriptor.toolCallId === toolCallId &&\n isLegacyClientToolMetadata(candidate.descriptor.metadata)),\n )\n if (!item) return false\n if (item.kind !== 'client-tool-execution') {\n this.resolveItem(\n item.descriptor.id,\n result.state === 'output-error'\n ? { error: result.errorText }\n : result.output,\n )\n return true\n }\n if (result.state === 'output-available') {\n this.resolveItem(item.descriptor.id, result.output)\n return true\n }\n this.stageClientToolError(item, result.errorText)\n return true\n }\n\n private stageClientToolError(\n item: RuntimeInterrupt,\n errorText: string,\n ): void {\n this.assertItemMutable()\n this.invalidateRetry()\n if (!item.canResolve) {\n item.status = 'error'\n item.error = this.itemError(\n item.descriptor.id,\n 'invalid-response-schema',\n 'The interrupt response schema is invalid and cannot be resolved.',\n )\n this.publish()\n return\n }\n item.validationGeneration++\n item.resolution = cloneAndDeepFreezeJson(\n withTanstackMetadata(\n resolutionWithContinuation(item, {\n interruptId: item.descriptor.id,\n status: 'resolved',\n payload: { error: errorText },\n }),\n { state: 'output-error' },\n ),\n )\n item.status = 'staged'\n item.error = undefined\n this.publish()\n this.maybeSubmit()\n }\n\n resolveToolApprovalDecision(interruptId: string, approved: boolean): boolean {\n const item = this.items.find(\n (candidate) =>\n candidate.descriptor.id === interruptId &&\n (candidate.kind === 'tool-approval' ||\n (candidate.kind === 'generic' &&\n candidate.descriptor.reason === 'approval_required' &&\n isLegacyApprovalMetadata(candidate.descriptor.metadata))),\n )\n if (!item) return false\n this.resolveItem(item.descriptor.id, { approved })\n return true\n }\n\n private hydrateInterrupt(\n descriptor: Interrupt,\n hydration: InterruptManagerHydration,\n firstPartyIndexes: ReadonlyMap<number, number>,\n ): RuntimeInterrupt {\n const interrupt = cloneAndDeepFreezeJson(descriptor)\n const candidate = getDescriptorBinding(interrupt)\n const legacyResumable =\n candidate === undefined && isLegacyInterruptMetadata(interrupt)\n\n // No binding we understand, and nothing else identifying the descriptor as\n // ours, means this interrupt was not produced by this package's resume\n // path — a workflow engine's durable approval projected onto the same\n // AG-UI stream, a third-party agent's pause, or a binding written at a\n // protocol version we don't know.\n //\n // Do not invent a binding for it. Synthesising one would render a\n // resolvable form whose answer is submitted against a run that has no\n // matching pending descriptor, failing late as `unknown-interrupt` after\n // the user has already filled it in. Surface it as unresolvable instead,\n // so \"someone else owns this pause\" is visible rather than silently\n // translated into an AI-domain interrupt.\n //\n // Pre-binding TanStack descriptors are still ours: they carry the legacy\n // `metadata.kind` marker, so they keep hydrating through the generic path\n // below.\n if (candidate === undefined && !legacyResumable) {\n if (hasReservedFirstPartyBindingMarker(interrupt)) {\n return {\n descriptor: interrupt,\n binding: genericBinding(interrupt, hydration, undefined),\n kind: 'generic',\n status: 'error',\n canResolve: false,\n resumable: false,\n error: this.itemError(\n interrupt.id,\n 'stale',\n 'The interrupt binding is invalid or incomplete.',\n ),\n validationGeneration: 0,\n }\n }\n return {\n descriptor: interrupt,\n binding: undefined,\n kind: 'unbound',\n status: 'pending',\n canResolve: false,\n resumable: false,\n validationGeneration: 0,\n }\n }\n\n const correlated =\n candidate !== undefined &&\n candidate.interruptId === interrupt.id &&\n candidate.interruptedRunId === hydration.interruptedRunId &&\n candidate.generation === hydration.generation &&\n responseSchemaHash(interrupt) === candidate.responseSchemaHash\n\n const structurallyCorrelated =\n candidate !== undefined &&\n candidate.interruptId === interrupt.id &&\n candidate.interruptedRunId === hydration.interruptedRunId &&\n candidate.generation === hydration.generation &&\n candidate.responseSchemaHash ===\n (responseSchemaHash(interrupt) ?? candidate.responseSchemaHash)\n\n if (\n candidate !== undefined &&\n hasFirstPartyGenericMarker(interrupt) &&\n (!structurallyCorrelated ||\n candidate.kind !== 'generic' ||\n candidate.definitionId === undefined ||\n candidate.key === undefined ||\n candidate.batchIndex === undefined)\n ) {\n return {\n descriptor: interrupt,\n binding: genericBinding(interrupt, hydration, candidate),\n kind: 'generic',\n status: 'error',\n canResolve: false,\n resumable: false,\n error: this.itemError(\n interrupt.id,\n 'stale',\n 'The interrupt binding does not match this interrupted run.',\n ),\n validationGeneration: 0,\n }\n }\n\n if (structurallyCorrelated && candidate.kind === 'tool-approval') {\n const tool = this.tools?.find(\n (configured) => configured.name === candidate.toolName,\n )\n // Gated on the binding and the schema hashes below, not on\n // `interrupt.reason` — that string is free-form AG-UI text another\n // producer can also use, so it cannot be what decides ownership.\n if (\n tool?.needsApproval === true &&\n interrupt.toolCallId === candidate.toolCallId\n ) {\n try {\n const approval = normalizeApprovalSchema(\n tool.approvalSchema,\n tool.inputSchema,\n )\n if (\n hashSchemaInput(tool.inputSchema) === candidate.inputSchemaHash &&\n approval.approvalSchemaHash === candidate.approvalSchemaHash &&\n approval.responseSchemaHash === candidate.responseSchemaHash\n ) {\n return {\n descriptor: interrupt,\n binding: cloneAndDeepFreezeJson(candidate),\n kind: 'tool-approval',\n status: 'pending',\n canResolve: true,\n resumable: true,\n tool,\n validationGeneration: 0,\n }\n }\n } catch {\n // Invalid configured schemas cannot safely grant typed hydration.\n }\n }\n }\n\n if (structurallyCorrelated && candidate.kind === 'client-tool-execution') {\n const tool = this.tools?.find(\n (configured) => configured.name === candidate.toolName,\n )\n // Binding-gated, for the same reason as tool approvals above.\n if (\n tool !== undefined &&\n interrupt.toolCallId === candidate.toolCallId &&\n hashSchemaInput(tool.outputSchema) === candidate.outputSchemaHash\n ) {\n return {\n descriptor: interrupt,\n binding: cloneAndDeepFreezeJson(candidate),\n kind: 'client-tool-execution',\n status: 'pending',\n canResolve: true,\n resumable: true,\n tool,\n validationGeneration: 0,\n }\n }\n }\n\n if (\n candidate !== undefined &&\n candidate.kind === 'generic' &&\n candidate.definitionId !== undefined &&\n candidate.key !== undefined &&\n candidate.batchIndex !== undefined &&\n candidate.key.length > 0 &&\n firstPartyIndexes.get(candidate.batchIndex) !== 1\n ) {\n return {\n descriptor: interrupt,\n binding: cloneAndDeepFreezeJson(candidate),\n kind: 'generic',\n status: 'error',\n canResolve: false,\n resumable: false,\n error: this.itemError(\n interrupt.id,\n 'stale',\n 'Generic interrupt batch contains a duplicate batchIndex.',\n ),\n validationGeneration: 0,\n }\n }\n\n if (\n correlated &&\n candidate.kind === 'generic' &&\n candidate.definitionId !== undefined &&\n candidate.key !== undefined &&\n candidate.batchIndex !== undefined &&\n candidate.key.length > 0 &&\n firstPartyIndexes.get(candidate.batchIndex) === 1\n ) {\n const definition = this.interruptDefinitions.get(candidate.definitionId)\n if (\n definition !== undefined &&\n definitionSchemaHash(definition.responseSchema) ===\n candidate.responseSchemaHash &&\n (definition.payloadSchema === undefined\n ? candidate.payloadSchemaHash === undefined\n : candidate.payloadSchemaHash ===\n definitionSchemaHash(definition.payloadSchema))\n ) {\n const rawPayload = getInterruptPayload(interrupt)\n // First-party display payloads are parsed by definition.interrupt()\n // before the server emits them. Re-validating here would feed schema\n // output back through an input schema and reject transforms such as\n // z.string().transform(Number). The checks above still bind this value\n // to the exact descriptor, run, generation, definition, and schemas.\n return {\n descriptor: interrupt,\n binding: cloneAndDeepFreezeJson(candidate),\n definition,\n kind: 'generic',\n status: 'pending',\n canResolve: true,\n resumable: true,\n ...(rawPayload === undefined\n ? {}\n : { payload: cloneAndDeepFreezeJson(rawPayload) }),\n validationGeneration: 0,\n }\n }\n }\n\n const resumable =\n legacyResumable ||\n (candidate !== undefined &&\n candidate.interruptId === interrupt.id &&\n candidate.interruptedRunId === hydration.interruptedRunId &&\n candidate.generation === hydration.generation &&\n (candidate.kind !== 'generic' ||\n responseSchemaHash(interrupt) === undefined ||\n candidate.responseSchemaHash === responseSchemaHash(interrupt)))\n return {\n descriptor: interrupt,\n binding: genericBinding(interrupt, hydration, candidate),\n kind: 'generic',\n status: 'pending',\n // A valid raw binding is an explicit request to use this resume path,\n // even when this client has no registered first-party definition. Keep\n // it untyped, but preserve its existing generic controls. Missing,\n // malformed, and unsupported bindings remain display-only.\n canResolve: resumable,\n resumable,\n validationGeneration: 0,\n }\n }\n\n private buildSnapshot(\n transaction?: TransactionToken,\n ): BoundInterrupts<TTools, TInterrupts> {\n const hydration = this.requireHydration()\n // `client-tool-execution` items stay in `this.items` (they usually gate\n // batch submission and are resolved internally via auto-execution /\n // addToolResult), but they are never surfaced as public bound interrupts.\n // A mixed generic batch is the exception: those client tools wait for\n // `toolResume` and must not block submit.\n //\n // Items with status `submitting` are also omitted: the resume stream is\n // already in flight, so Approve/Deny is not actionable. Keeping them in\n // the public list made UIs look stuck after a successful approve and\n // blocked follow-up turns that key off `interrupts.length`.\n const next = this.items\n .filter(\n (item) =>\n item.kind !== 'client-tool-execution' && item.status !== 'submitting',\n )\n .map((item) => {\n const base = baseSnapshot(item, hydration)\n // Not ours to resume: expose the descriptor so a UI can show the run\n // is paused, with no `resolveInterrupt` to call.\n if (item.kind === 'unbound' || item.binding === undefined) {\n const snapshot: UnboundInterrupt = {\n ...base,\n kind: 'unbound',\n canResolve: false,\n }\n return Object.freeze(snapshot)\n }\n if (\n item.kind === 'tool-approval' &&\n item.binding.kind === 'tool-approval'\n ) {\n const binding = cloneAndDeepFreezeJson(item.binding)\n const snapshot = {\n ...base,\n kind: 'tool-approval' as const,\n binding,\n toolName: item.binding.toolName,\n toolCallId: item.binding.toolCallId,\n originalArgs: cloneAndDeepFreezeJson(item.binding.originalArgs),\n cancel: () => this.cancelItem(item.descriptor.id, transaction),\n clearResolution: () =>\n this.clearItem(item.descriptor.id, transaction),\n resolveInterrupt: (approved: boolean, options?: unknown) => {\n const details = isUnknownObject(options) ? options : undefined\n this.resolveItem(\n item.descriptor.id,\n {\n approved,\n ...(approved && details?.['editedArgs'] !== undefined\n ? { editedArgs: details['editedArgs'] }\n : {}),\n ...(details?.['payload'] !== undefined\n ? { payload: details['payload'] }\n : {}),\n },\n transaction,\n )\n },\n }\n return Object.freeze(snapshot)\n }\n const boundGeneric =\n item.binding.kind === 'generic'\n ? cloneAndDeepFreezeJson(item.binding)\n : cloneAndDeepFreezeJson({\n v: INTERRUPT_BINDING_VERSION,\n kind: 'generic' as const,\n interruptId: item.descriptor.id,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n ...(typeof item.binding.responseSchemaHash === 'string'\n ? { responseSchemaHash: item.binding.responseSchemaHash }\n : {}),\n })\n if (item.definition !== undefined && item.binding.kind === 'generic') {\n const snapshot = {\n ...base,\n kind: 'generic',\n definitionId: item.definition.id,\n key: item.binding.key ?? '',\n payload: item.payload,\n binding: boundGeneric,\n cancel: () => this.cancelItem(item.descriptor.id, transaction),\n clearResolution: () =>\n this.clearItem(item.descriptor.id, transaction),\n resolveInterrupt: (response: unknown) =>\n this.resolveItem(item.descriptor.id, response, transaction),\n }\n return Object.freeze(snapshot)\n }\n const snapshot: GenericAGUIInterrupt = {\n ...base,\n kind: 'generic',\n binding: boundGeneric,\n cancel: () => this.cancelItem(item.descriptor.id, transaction),\n clearResolution: () =>\n this.clearItem(item.descriptor.id, transaction),\n resolveInterrupt: (payload) =>\n this.resolveItem(item.descriptor.id, payload, transaction),\n }\n return Object.freeze(snapshot)\n })\n\n // The runtime items are created only from the exact configured TTools entry\n // selected by name. TypeScript cannot preserve that per-element lookup\n // through Array.map, so this generic return boundary restores the proven\n // distributive public union.\n return Object.freeze(next) as BoundInterrupts<TTools, TInterrupts>\n }\n\n // Provenance belongs to each publication because `onChange` may synchronously\n // mutate the manager and publish again before an outer callback returns.\n private publish(source: InterruptManagerChangeSource = 'live'): void {\n if (!this.hydration) {\n this.snapshot = Object.freeze([])\n this.state = Object.freeze({\n interrupts: this.snapshot,\n pendingInterrupts: this.snapshot,\n interruptErrors: this.rootErrors,\n resuming: this.resuming,\n })\n this.options.onChange?.(source)\n return\n }\n this.snapshot = this.buildSnapshot()\n this.state = Object.freeze({\n interrupts: this.snapshot,\n pendingInterrupts: this.snapshot,\n interruptErrors: this.rootErrors,\n resuming: this.resuming,\n })\n this.options.onChange?.(source)\n }\n\n private resolveItem(\n interruptId: string,\n payload: unknown,\n transaction?: TransactionToken,\n ): void {\n this.assertItemMutable(transaction)\n const item = this.findItem(interruptId)\n this.invalidateRetry()\n if (!item.canResolve) {\n item.status = 'error'\n item.error = this.itemError(\n interruptId,\n 'invalid-response-schema',\n 'The interrupt response schema is invalid and cannot be resolved.',\n )\n if (!transaction) this.publish()\n return\n }\n const validationGeneration = ++item.validationGeneration\n const validation = this.validateCandidate(item, payload)\n if (isPromiseLike(validation)) {\n item.status = 'validating'\n item.error = undefined\n if (!transaction) this.publish()\n void Promise.resolve(validation)\n .then((result) => {\n if (validationGeneration !== item.validationGeneration) return\n this.applyValidation(item, result, transaction)\n })\n .catch((error: unknown) => {\n if (validationGeneration !== item.validationGeneration) return\n this.applyValidation(\n item,\n {\n code: this.validationCode(item),\n message: error instanceof Error ? error.message : String(error),\n },\n transaction,\n )\n })\n return\n }\n this.applyValidation(item, validation, transaction)\n }\n\n private cancelItem(\n interruptId: string,\n transaction?: TransactionToken,\n ): void {\n this.assertItemMutable(transaction)\n const item = this.findItem(interruptId)\n this.invalidateRetry()\n item.validationGeneration++\n item.resolution = Object.freeze(\n resolutionWithContinuation(item, { interruptId, status: 'cancelled' }),\n )\n item.status = 'staged'\n item.error = undefined\n if (!transaction) {\n this.publish()\n this.maybeSubmit()\n }\n }\n\n private clearItem(interruptId: string, transaction?: TransactionToken): void {\n this.assertItemMutable(transaction)\n const item = this.findItem(interruptId)\n this.invalidateRetry()\n item.validationGeneration++\n item.resolution = undefined\n item.error = undefined\n item.status = 'pending'\n if (!transaction) this.publish()\n }\n\n private maybeSubmit(): void {\n // Unbound items can never be resolved through this path — something else\n // owns them. Including them in the completeness gate would deadlock the\n // batch, so the run's own interrupts could never be answered once a\n // foreign one shared the stream.\n const hasGeneric = this.items.some((item) => item.kind === 'generic')\n const ours = this.items.filter(\n (item) =>\n isClientOwnedInterrupt(item) &&\n !(hasGeneric && item.kind === 'client-tool-execution'),\n )\n if (\n ours.length === 0 ||\n ours.some(\n (item) => item.resolution === undefined || item.status !== 'staged',\n )\n ) {\n return\n }\n const hydration = this.requireHydration()\n const canonical = canonicalizeInterruptResolutions(\n ours.map((item) => item.resolution).filter((item) => item !== undefined),\n )\n const submission = Object.freeze({\n threadId: hydration.threadId,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n resolutions: canonical.resolutions,\n canonicalResolutions: canonical.canonicalResolutions,\n fingerprint: canonical.fingerprint,\n })\n this.submitBatch(submission)\n }\n\n private applyValidation(\n item: RuntimeInterrupt,\n result: ValidationResult,\n transaction?: TransactionToken,\n ): void {\n if (!('valid' in result)) {\n item.status = 'error'\n const itemError = this.itemError(\n item.descriptor.id,\n result.code,\n result.message,\n result.path,\n )\n item.error = itemError\n // Client-tool-execution items are hidden from the public interrupt list,\n // so promote their validation failures onto interruptErrors for the UI.\n if (item.kind === 'client-tool-execution') {\n this.rootErrors = Object.freeze([\n ...this.rootErrors.filter(\n (error) =>\n !(\n error.code === 'item-validation-failed' &&\n error.interruptIds.includes(item.descriptor.id)\n ),\n ),\n Object.freeze({\n scope: 'batch' as const,\n code: 'item-validation-failed' as const,\n message: itemError.message,\n source: 'client' as const,\n retryable: false,\n interruptIds: Object.freeze([item.descriptor.id]),\n threadId: itemError.threadId,\n interruptedRunId: itemError.interruptedRunId,\n generation: itemError.generation,\n }),\n ])\n }\n if (!transaction) this.publish()\n return\n }\n item.resolution = cloneAndDeepFreezeJson(\n resolutionWithContinuation(item, {\n interruptId: item.descriptor.id,\n status: 'resolved',\n payload: result.payload,\n }),\n )\n item.status = 'staged'\n item.error = undefined\n if (!transaction) {\n this.publish()\n this.maybeSubmit()\n }\n }\n\n private validateCandidate(\n item: RuntimeInterrupt,\n payload: unknown,\n ): ValidationResult | Promise<ValidationResult> {\n if (item.kind === 'generic') {\n const validation = validateWithSchema(\n item.definition?.responseSchema ?? item.descriptor.responseSchema,\n payload,\n 'invalid-payload',\n )\n if (item.definition === undefined) return validation\n const preserveInput = (result: ValidationResult): ValidationResult =>\n 'valid' in result ? { valid: true, payload } : result\n return isPromiseLike(validation)\n ? Promise.resolve(validation).then(preserveInput)\n : preserveInput(validation)\n }\n if (item.kind === 'client-tool-execution') {\n const validation = validateWithSchema(\n item.tool?.outputSchema,\n payload,\n 'invalid-tool-output',\n )\n const canonicalize = (result: ValidationResult): ValidationResult => {\n if (!('valid' in result)) return result\n try {\n return {\n valid: true,\n payload: cloneAndDeepFreezeJson(result.payload),\n }\n } catch (error) {\n return {\n code: 'invalid-tool-output',\n message: error instanceof Error ? error.message : String(error),\n }\n }\n }\n return isPromiseLike(validation)\n ? Promise.resolve(validation).then(canonicalize)\n : canonicalize(validation)\n }\n return this.validateApprovalCandidate(item, payload)\n }\n\n private validateApprovalCandidate(\n item: RuntimeInterrupt,\n payload: unknown,\n ): ValidationResult | Promise<ValidationResult> {\n if (!isUnknownObject(payload) || typeof payload['approved'] !== 'boolean') {\n return {\n code: 'invalid-payload',\n message: 'Tool approval resolutions require an approved boolean.',\n }\n }\n const approved = payload['approved']\n const editedArgs = payload['editedArgs']\n if (!approved && editedArgs !== undefined) {\n return {\n code: 'invalid-edited-args',\n message: 'Rejected tool approvals cannot edit tool arguments.',\n }\n }\n if (approved && editedArgs !== undefined) {\n const editedValidation = validateWithSchema(\n item.tool?.inputSchema,\n editedArgs,\n 'invalid-edited-args',\n )\n if (isPromiseLike(editedValidation)) {\n return Promise.resolve(editedValidation).then((result) =>\n 'valid' in result\n ? this.validateApprovalPayload(item, payload, result.payload)\n : result,\n )\n }\n if (!('valid' in editedValidation)) return editedValidation\n return this.validateApprovalPayload(\n item,\n payload,\n editedValidation.payload,\n )\n }\n return this.validateApprovalPayload(item, payload, undefined)\n }\n\n private validateApprovalPayload(\n item: RuntimeInterrupt,\n envelope: UnknownObject,\n validatedEditedArgs: unknown,\n ): ValidationResult | Promise<ValidationResult> {\n const approved = envelope['approved'] === true\n const schema = this.approvalBranchSchema(item.tool, approved)\n const branchPayload = envelope['payload']\n if (schema === undefined && branchPayload !== undefined) {\n return {\n code: 'invalid-payload',\n message: 'This approval branch does not accept a payload.',\n }\n }\n if (schema !== undefined && branchPayload === undefined) {\n return {\n code: 'invalid-payload',\n message: 'This approval branch requires a payload.',\n }\n }\n const validation = validateWithSchema(\n schema,\n branchPayload,\n 'invalid-payload',\n )\n const buildEnvelope = (result: ValidationResult): ValidationResult => {\n if (!('valid' in result)) return result\n return {\n valid: true,\n payload: {\n approved,\n ...(validatedEditedArgs !== undefined\n ? { editedArgs: validatedEditedArgs }\n : {}),\n ...(schema !== undefined ? { payload: result.payload } : {}),\n },\n }\n }\n return isPromiseLike(validation)\n ? Promise.resolve(validation).then(buildEnvelope)\n : buildEnvelope(validation)\n }\n\n private approvalBranchSchema(\n tool: AnyClientTool | undefined,\n approved: boolean,\n ): unknown {\n const approvalSchema: unknown = tool?.approvalSchema\n if (!isUnknownObject(approvalSchema)) return approvalSchema\n const hasBranches =\n 'approve' in approvalSchema || 'reject' in approvalSchema\n if (!hasBranches) return approvalSchema\n return approved ? approvalSchema['approve'] : approvalSchema['reject']\n }\n\n private validationCode(item: RuntimeInterrupt): ItemInterruptError['code'] {\n return item.kind === 'client-tool-execution'\n ? 'invalid-tool-output'\n : 'invalid-payload'\n }\n\n private resolveBooleanBulk(approved: boolean): void {\n // `client-tool-execution` items resolve out-of-band (auto execution /\n // addToolResult); they are transparent to the boolean shorthand. Eligibility\n // and resolution consider only the publicly resolvable items.\n const resolvable = this.items.filter(\n (item) =>\n isClientOwnedInterrupt(item) && item.kind !== 'client-tool-execution',\n )\n const eligible = resolvable.every(\n (item) =>\n item.kind === 'tool-approval' &&\n this.approvalBranchSchema(item.tool, approved) === undefined,\n )\n if (!eligible || resolvable.length === 0) {\n this.addRootError(\n 'unsupported-bulk-operation',\n 'Boolean bulk resolution requires payloadless tool approvals.',\n false,\n )\n return\n }\n this.invalidateRetry()\n for (const item of resolvable) {\n item.validationGeneration++\n item.resolution = cloneAndDeepFreezeJson({\n interruptId: item.descriptor.id,\n status: 'resolved',\n payload: { approved },\n })\n item.status = 'staged'\n item.error = undefined\n }\n this.publish()\n this.maybeSubmit()\n }\n\n private resolveTransaction(\n resolver: (\n interrupt: ResolvableChatInterrupt<TTools, TInterrupts>,\n ) => unknown,\n ): void {\n const checkpoints = this.items.map<RuntimeInterruptCheckpoint>((item) => ({\n status: item.status,\n ...(item.resolution !== undefined ? { resolution: item.resolution } : {}),\n ...(item.error !== undefined ? { error: item.error } : {}),\n validationGeneration: item.validationGeneration,\n }))\n const token: TransactionToken = { active: true }\n this.activeTransaction = token\n const stable = this.buildSnapshot(token).filter(isRootResolvableInterrupt)\n let failure:\n | { code: BatchInterruptError['code']; message: string }\n | undefined\n try {\n for (const interrupt of stable) {\n const result = resolver(interrupt)\n if (result !== undefined) {\n failure = {\n code: isPromiseLike(result)\n ? 'async-resolver'\n : 'inactive-transaction',\n message: isPromiseLike(result)\n ? 'Interrupt transaction resolvers must be synchronous.'\n : 'Interrupt transaction resolvers must return literal undefined.',\n }\n break\n }\n }\n if (\n failure === undefined &&\n this.items.some(\n (item) =>\n // `client-tool-execution` items are resolved out-of-band (auto\n // execution / addToolResult), not by this synchronous resolver, so\n // they don't count against transaction completeness. `maybeSubmit`\n // still waits for them unless a generic interrupt shares the batch.\n isClientOwnedInterrupt(item) &&\n item.kind !== 'client-tool-execution' &&\n (item.resolution === undefined || item.status !== 'staged'),\n )\n ) {\n failure = {\n code: 'incomplete-batch',\n message: 'Interrupt transaction did not resolve every item.',\n }\n }\n } catch (error) {\n failure = {\n code: 'item-validation-failed',\n message: error instanceof Error ? error.message : String(error),\n }\n } finally {\n token.active = false\n this.activeTransaction = undefined\n }\n\n if (failure) {\n this.restoreCheckpoints(checkpoints)\n this.addRootError(failure.code, failure.message, false)\n return\n }\n this.publish()\n this.maybeSubmit()\n }\n\n private restoreCheckpoints(\n checkpoints: ReadonlyArray<RuntimeInterruptCheckpoint>,\n ): void {\n this.items.forEach((item, index) => {\n const checkpoint = checkpoints[index]\n if (!checkpoint) return\n item.status = checkpoint.status\n item.resolution = checkpoint.resolution\n item.error = checkpoint.error\n item.validationGeneration = checkpoint.validationGeneration + 1\n })\n this.publish()\n }\n\n private assertItemMutable(transaction?: TransactionToken): void {\n if (transaction && !transaction.active) {\n throw new Error('Interrupt transaction is inactive.')\n }\n if (this.activeTransaction && transaction !== this.activeTransaction) {\n throw new Error('Interrupt transaction is inactive.')\n }\n if (this.resuming) {\n throw new Error('Interrupts cannot be mutated while submitting.')\n }\n }\n\n private assertRootMutable(): void {\n if (this.activeTransaction) {\n throw new Error('Interrupt transaction is already active.')\n }\n if (this.resuming) {\n throw new Error('Interrupts cannot be mutated while submitting.')\n }\n }\n\n private invalidateRetry(): void {\n this.retrySubmission = undefined\n }\n\n private submitBatch(submission: InterruptManagerSubmission): void {\n // Track ownership so a superseded submission cannot mutate current state.\n const operation = { submission }\n this.activeSubmissionOperation = operation\n this.resuming = true\n this.retrySubmission = undefined\n for (const item of this.items) {\n if (isClientOwnedInterrupt(item)) item.status = 'submitting'\n }\n this.publish()\n void this.performSubmission(operation)\n }\n\n private async performSubmission(\n operation: SubmissionOperation,\n ): Promise<void> {\n try {\n await this.options.submit(operation.submission)\n } catch (error) {\n if (this.activeSubmissionOperation !== operation) return\n this.handleSubmissionFailure(error, operation.submission)\n } finally {\n if (this.activeSubmissionOperation === operation) {\n this.activeSubmissionOperation = undefined\n this.resuming = false\n this.publish()\n }\n }\n }\n\n private handleSubmissionFailure(\n error: unknown,\n submission: InterruptManagerSubmission,\n ): void {\n const errors = readSubmissionErrors(error)\n if (errors.length === 0) {\n const message = error instanceof Error ? error.message : String(error)\n this.addRootError('transport', message, true, 'transport')\n this.retrySubmission = submission\n for (const item of this.items) {\n if (isClientOwnedInterrupt(item)) item.status = 'error'\n }\n return\n }\n\n const correlatedErrors = errors.filter((submissionError) =>\n submissionErrorMatchesActiveBatch(submissionError, submission),\n )\n if (correlatedErrors.length !== errors.length) {\n this.addRootError(\n 'protocol',\n 'Interrupt submission errors did not match the active batch.',\n false,\n )\n }\n\n let nonRetryable = false\n let retryable = false\n const batchErrors: Array<BatchInterruptError> = []\n for (const submissionError of correlatedErrors) {\n if (\n submissionError.code === 'stale' ||\n submissionError.code === 'expired' ||\n submissionError.code === 'conflict'\n ) {\n nonRetryable = true\n }\n retryable ||= submissionError.retryable\n if (submissionError.scope === 'item') {\n const item = this.items.find(\n (candidate) =>\n isClientOwnedInterrupt(candidate) &&\n candidate.descriptor.id === submissionError.interruptId,\n )\n if (item) {\n item.status = 'error'\n item.error = cloneAndDeepFreezeJson(submissionError)\n }\n } else {\n batchErrors.push(cloneAndDeepFreezeJson(submissionError))\n }\n }\n const mergedBatchErrors = mergeSubmissionBatchErrors(\n this.rootErrors,\n this.submissionRootErrors,\n batchErrors,\n )\n this.rootErrors = mergedBatchErrors.rootErrors\n this.submissionRootErrors = mergedBatchErrors.submissionRootErrors\n for (const item of this.items) {\n if (isClientOwnedInterrupt(item) && item.status === 'submitting') {\n item.status = 'error'\n }\n }\n this.retrySubmission = retryable && !nonRetryable ? submission : undefined\n }\n\n private addRootError(\n code: BatchInterruptError['code'],\n message: string,\n retryable: boolean,\n source: BatchInterruptError['source'] = 'client',\n ): void {\n const hydration = this.requireHydration()\n this.rootErrors = Object.freeze([\n ...this.rootErrors,\n Object.freeze({\n scope: 'batch' as const,\n code,\n message,\n source,\n retryable,\n interruptIds: Object.freeze(\n this.items\n .filter(isClientOwnedInterrupt)\n .map((item) => item.descriptor.id),\n ),\n threadId: hydration.threadId,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n }),\n ])\n this.publish()\n }\n\n private findItem(interruptId: string): RuntimeInterrupt {\n const item = this.items.find(\n (candidate) => candidate.descriptor.id === interruptId,\n )\n if (!item) throw new Error(`Unknown interrupt: ${interruptId}`)\n return item\n }\n\n private requireHydration(): InterruptManagerHydration {\n if (!this.hydration) throw new Error('InterruptManager is not hydrated.')\n return this.hydration\n }\n\n private itemError(\n interruptId: string,\n code: ItemInterruptError['code'],\n message: string,\n path?: ReadonlyArray<string | number>,\n ): ItemInterruptError {\n const hydration = this.requireHydration()\n return Object.freeze({\n scope: 'item',\n interruptId,\n code,\n message,\n ...(path !== undefined ? { path: Object.freeze([...path]) } : {}),\n source: 'client',\n retryable: false,\n threadId: hydration.threadId,\n interruptedRunId: hydration.interruptedRunId,\n generation: hydration.generation,\n })\n }\n}\n"],"mappings":";;AAoHA,SAAS,uBAAuB,MAAiC;CAC/D,OAAO,KAAK;AACd;AAEA,SAAS,2BACP,MACA,YACoB;CACpB,MAAM,eAAe,2CACnB,KAAK,UACP;CACA,IAAI,cACF,OAAO;EACL,GAAG;EACH,UAAU,iCAAiC,YAAY;CACzD;CAEF,OAAO;AACT;AAEA,SAAS,0BAIP,WAC2D;CAC3D,OAAO,YAAY,aAAa,qBAAqB;AACvD;AAEA,IAAM,iCAAiB,IAAI,IAAgC;CACzD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,IAAM,kCAAkB,IAAI,IAAiC;CAC3D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAS,gBAAgB,OAAwC;CAC/D,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AAC5E;AAEA,SAAS,yBAAyB,OAAyB;CACzD,OACE,gBAAgB,KAAK,KACrB,MAAM,YAAY,cAClB,OAAO,MAAM,gBAAgB,YAC7B,WAAW;AAEf;AAEA,SAAS,2BAA2B,OAAyB;CAC3D,OACE,gBAAgB,KAAK,KACrB,MAAM,YAAY,iBAClB,OAAO,MAAM,gBAAgB,YAC7B,WAAW;AAEf;;;;;;;AAQA,SAAS,0BAA0B,WAA+B;CAChE,OACE,yBAAyB,UAAU,QAAQ,KAC3C,2BAA2B,UAAU,QAAQ;AAEjD;AAEA,SAAS,qBACP,WAC8B;CAC9B,OAAO,qBAAqB,SAAS;AACvC;AAEA,SAAS,mCAAmC,WAA+B;CACzE,IAAI,CAAC,gBAAgB,UAAU,QAAQ,GAAG,OAAO;CACjD,MAAM,UAAU,UAAU,SAAS;CACnC,IAAI,CAAC,gBAAgB,OAAO,GAAG,OAAO;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ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyClientTool, ApprovalCapabilityOf, ApprovalSchemaOf, AudioPart, BatchInterruptError, ChunkStrategy, ContentPart, DocumentPart, ImagePart, InferSchemaType, InterruptDefinition, InferToolInput, InferToolOutput, InputSchemaOf, Interrupt, InterruptBinding, ItemInterruptError, ModelMessage, NoSchema, RunAgentResumeItem, SchemaInput, StreamChunk, StructuredOutputPart, SubagentHandleData, SubagentStatus, UIResourcePart, VideoPart } from '@tanstack/ai/client';
|
|
1
|
+
import { AnyClientTool, ApprovalCapabilityOf, ApprovalSchemaOf, AudioPart, BatchInterruptError, ChunkStrategy, ContentPart, DocumentPart, ImagePart, InferSchemaType, InterruptDefinition, InferToolInput, InferToolOutput, InputSchemaOf, Interrupt, InterruptBinding, ItemInterruptError, ModelMessage, NoSchema, RunAgentResumeItem, SchemaInput, StreamChunk, StructuredOutputPart, SubagentHandleData, SubagentStatus, ToolResultOutcome, UIResourcePart, VideoPart } from '@tanstack/ai/client';
|
|
2
2
|
import { ByokClient } from './byok.js';
|
|
3
3
|
import { ConnectionAdapter } from './connection-adapters.js';
|
|
4
4
|
import { AIDevtoolsClientMetadata } from './devtools.js';
|
|
@@ -433,6 +433,8 @@ export interface ToolResultPart {
|
|
|
433
433
|
toolCallId: string;
|
|
434
434
|
content: string | Array<ContentPart>;
|
|
435
435
|
state: ToolResultState;
|
|
436
|
+
/** Set when the user or middleware cancelled or denied the tool call; state remains `error`. */
|
|
437
|
+
outcome?: ToolResultOutcome;
|
|
436
438
|
error?: string;
|
|
437
439
|
metadata?: Record<string, unknown>;
|
|
438
440
|
createdAt?: Date;
|