@agent-native/core 0.66.6 → 0.66.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/agent/run-manager.d.ts.map +1 -1
  2. package/dist/agent/run-manager.js +29 -4
  3. package/dist/agent/run-manager.js.map +1 -1
  4. package/dist/cli/code-agent-executor.js +2 -2
  5. package/dist/cli/code-agent-executor.js.map +1 -1
  6. package/dist/cli/index.js +2 -2
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/cli/skills.d.ts +9 -3
  9. package/dist/cli/skills.d.ts.map +1 -1
  10. package/dist/cli/skills.js +393 -45
  11. package/dist/cli/skills.js.map +1 -1
  12. package/dist/client/AgentPanel.d.ts.map +1 -1
  13. package/dist/client/AgentPanel.js +5 -6
  14. package/dist/client/AgentPanel.js.map +1 -1
  15. package/dist/client/blocks/library/AnnotatedCodeBlock.js +2 -2
  16. package/dist/client/blocks/library/AnnotatedCodeBlock.js.map +1 -1
  17. package/dist/client/blocks/library/DiffBlock.d.ts.map +1 -1
  18. package/dist/client/blocks/library/DiffBlock.js +1 -1
  19. package/dist/client/blocks/library/DiffBlock.js.map +1 -1
  20. package/dist/client/blocks/library/annotation-rail.d.ts +3 -1
  21. package/dist/client/blocks/library/annotation-rail.d.ts.map +1 -1
  22. package/dist/client/blocks/library/annotation-rail.js +32 -4
  23. package/dist/client/blocks/library/annotation-rail.js.map +1 -1
  24. package/dist/client/chat/runtime.d.ts.map +1 -1
  25. package/dist/client/chat/runtime.js +5 -2
  26. package/dist/client/chat/runtime.js.map +1 -1
  27. package/dist/client/error-format.d.ts +1 -1
  28. package/dist/client/error-format.d.ts.map +1 -1
  29. package/dist/client/error-format.js +23 -2
  30. package/dist/client/error-format.js.map +1 -1
  31. package/dist/client/sse-event-processor.d.ts.map +1 -1
  32. package/dist/client/sse-event-processor.js +3 -2
  33. package/dist/client/sse-event-processor.js.map +1 -1
  34. package/dist/file-upload/pre-upload-attachments.js +1 -1
  35. package/dist/file-upload/pre-upload-attachments.js.map +1 -1
  36. package/dist/scripts/runner.d.ts +1 -1
  37. package/dist/scripts/runner.d.ts.map +1 -1
  38. package/dist/scripts/runner.js +40 -6
  39. package/dist/scripts/runner.js.map +1 -1
  40. package/dist/templates/headless/AGENTS.md +1 -1
  41. package/dist/templates/headless/DEVELOPING.md +1 -1
  42. package/dist/templates/workspace-core/.agents/skills/integration-webhooks/SKILL.md +11 -0
  43. package/docs/content/actions.md +11 -2
  44. package/docs/content/local-file-mode.md +25 -0
  45. package/docs/content/messaging.md +24 -0
  46. package/docs/content/skills-guide.md +3 -0
  47. package/docs/content/template-clips.md +60 -0
  48. package/docs/content/template-content.md +15 -0
  49. package/package.json +1 -1
  50. package/src/templates/headless/AGENTS.md +1 -1
  51. package/src/templates/headless/DEVELOPING.md +1 -1
  52. package/src/templates/workspace-core/.agents/skills/integration-webhooks/SKILL.md +11 -0
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/client/chat/runtime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EACL,0BAA0B,GAG3B,MAAM,2BAA2B,CAAC;AA8lBnC,MAAM,4BAA4B,GAAiC;IACjE,QAAQ,EAAE;QACR,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,IAAI;QACb,iBAAiB,EAAE,IAAI;QACvB,WAAW,EAAE,IAAI;KAClB;IACD,KAAK,EAAE;QACL,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,IAAI;QACf,eAAe,EAAE,IAAI;QACrB,OAAO,EAAE,IAAI;KACd;IACD,QAAQ,EAAE;QACR,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,IAAI;KACjB;IACD,YAAY,EAAE;QACZ,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,IAAI;KACrB;IACD,MAAM,EAAE;QACN,UAAU,EA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AE,CAAC;wBACX,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAA4B,CAAC;wBACpE,MAAM,MAAM,GACV,QAAQ,CAAC,MAAM,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ;4BACpD,CAAC,CAAE,QAAQ,CAAC,MAAkC;4BAC9C,CAAC,CAAC,EAAE,CAAC;wBACT,MAAM;4BACJ,GAAG,MAAM;4BACT,QAAQ,EAAE;gCACR,GAAG,QAAQ;gCACX,MAAM,EAAE;oCACN,GAAG,MAAM;oCACT,SAAS,EAAE,OAAO,CAAC,EAAE;oCACrB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iCAC7C;6BACF;yBACoB,CAAC;oBAC1B,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAC1D,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;oBACzC,OAAO;gBACT,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ChatModelAdapter, ChatModelRunResult } from \"@assistant-ui/react\";\nimport type { AgentMcpAppPayload } from \"../../mcp-client/app-result.js\";\nimport type { ActionChatUIConfig } from \"../../action-ui.js\";\nimport type { ReasoningEffort } from \"../../shared/reasoning-effort.js\";\nimport { agentNativePath } from \"../api-path.js\";\nimport {\n settleInterruptedToolCalls,\n type ContentPart,\n type SSEEvent,\n} from \"../sse-event-processor.js\";\n\nexport type AgentChatRuntimeId = string;\nexport type AgentChatRuntimeSessionId = string;\nexport type AgentChatRuntimeTurnId = string;\nexport type AgentChatRuntimeMessageId = string;\nexport type AgentChatRuntimeToolCallId = string;\nexport type AgentChatRuntimeMetadata = Record<string, unknown>;\nexport type AgentChatRuntimeAwaitable<T> = T | Promise<T>;\n\nexport type AgentChatRuntimeKind =\n | \"agent-native\"\n | \"external-agent\"\n | \"code-agent\"\n | (string & {});\n\nexport type AgentChatRuntimeRole = \"system\" | \"user\" | \"assistant\" | \"tool\";\n\nexport interface AgentChatRuntimeContentPartBase<\n TType extends string = string,\n> {\n readonly type: TType;\n readonly id?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeTextPart extends AgentChatRuntimeContentPartBase<\"text\"> {\n readonly text: string;\n}\n\nexport interface AgentChatRuntimeReasoningPart extends AgentChatRuntimeContentPartBase<\"reasoning\"> {\n readonly text: string;\n readonly signature?: string;\n}\n\nexport interface AgentChatRuntimeImagePart extends AgentChatRuntimeContentPartBase<\"image\"> {\n readonly data?: string;\n readonly url?: string;\n readonly mediaType?: string;\n readonly alt?: string;\n}\n\nexport interface AgentChatRuntimeFilePart extends AgentChatRuntimeContentPartBase<\"file\"> {\n readonly data?: string;\n readonly url?: string;\n readonly mediaType?: string;\n readonly filename?: string;\n}\n\nexport interface AgentChatRuntimeToolCallPart extends AgentChatRuntimeContentPartBase<\"tool-call\"> {\n readonly toolCallId: AgentChatRuntimeToolCallId;\n readonly toolName: string;\n readonly input?: unknown;\n readonly inputText?: string;\n}\n\nexport interface AgentChatRuntimeToolResultPart extends AgentChatRuntimeContentPartBase<\"tool-result\"> {\n readonly toolCallId: AgentChatRuntimeToolCallId;\n readonly toolName?: string;\n readonly result?: unknown;\n readonly resultText?: string;\n readonly isError?: boolean;\n readonly mcpApp?: AgentMcpAppPayload;\n readonly chatUI?: ActionChatUIConfig;\n}\n\nexport interface AgentChatRuntimeDataPart extends AgentChatRuntimeContentPartBase<\"data\"> {\n readonly data: unknown;\n readonly mediaType?: string;\n readonly title?: string;\n}\n\nexport interface AgentChatRuntimeCustomContentPart extends AgentChatRuntimeContentPartBase {\n readonly [key: string]: unknown;\n}\n\nexport type AgentChatRuntimeKnownContentPart =\n | AgentChatRuntimeTextPart\n | AgentChatRuntimeReasoningPart\n | AgentChatRuntimeImagePart\n | AgentChatRuntimeFilePart\n | AgentChatRuntimeToolCallPart\n | AgentChatRuntimeToolResultPart\n | AgentChatRuntimeDataPart;\n\nexport type AgentChatRuntimeContentPart<\n TCustomPart extends AgentChatRuntimeCustomContentPart = never,\n> = AgentChatRuntimeKnownContentPart | TCustomPart;\n\nexport interface AgentChatRuntimeMessage<\n TContentPart extends AgentChatRuntimeContentPartBase =\n AgentChatRuntimeKnownContentPart,\n> {\n readonly id: AgentChatRuntimeMessageId;\n readonly role: AgentChatRuntimeRole;\n readonly content: readonly TContentPart[];\n readonly createdAt?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeAttachment {\n readonly id?: string;\n readonly name: string;\n readonly mediaType?: string;\n readonly data?: string;\n readonly url?: string;\n readonly text?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeToolDefinition {\n readonly name: string;\n readonly description?: string;\n readonly inputSchema?: Record<string, unknown>;\n readonly readOnly?: boolean;\n readonly destructive?: boolean;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeToolCall {\n readonly id: AgentChatRuntimeToolCallId;\n readonly name: string;\n readonly input?: unknown;\n readonly inputText?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport type AgentChatRuntimeToolStatus =\n | \"pending\"\n | \"running\"\n | \"completed\"\n | \"failed\"\n | \"cancelled\";\n\nexport interface AgentChatRuntimeUsage {\n readonly inputTokens?: number;\n readonly outputTokens?: number;\n readonly totalTokens?: number;\n readonly reasoningTokens?: number;\n readonly cacheReadTokens?: number;\n readonly cacheWriteTokens?: number;\n readonly costCents?: number;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeMessageCapabilities {\n readonly streaming: boolean;\n readonly history?: boolean;\n readonly structuredContent?: boolean;\n readonly multimodal?: boolean;\n readonly attachments?: boolean;\n}\n\nexport interface AgentChatRuntimeToolCapabilities {\n readonly events: boolean;\n readonly hostTools?: boolean;\n readonly inputStreaming?: boolean;\n readonly resultStreaming?: boolean;\n readonly approvals?: boolean;\n readonly mcpApps?: boolean;\n}\n\nexport interface AgentChatRuntimeSessionCapabilities {\n readonly create: boolean;\n readonly restore?: boolean;\n readonly list?: boolean;\n readonly fork?: boolean;\n readonly detach?: boolean;\n readonly persistent?: boolean;\n}\n\nexport interface AgentChatRuntimeCancellationCapabilities {\n readonly abortSignal?: boolean;\n readonly explicitCancel?: boolean;\n readonly interrupt?: boolean;\n}\n\nexport interface AgentChatRuntimeModelCapabilities {\n readonly selectable?: boolean;\n readonly reasoningEffort?: boolean;\n readonly temperature?: boolean;\n readonly providerOptions?: boolean;\n}\n\nexport interface AgentChatRuntimeArtifactCapabilities {\n readonly files?: boolean;\n readonly links?: boolean;\n readonly patches?: boolean;\n readonly progress?: boolean;\n}\n\nexport interface AgentChatRuntimeCapabilities {\n readonly messages: AgentChatRuntimeMessageCapabilities;\n readonly tools?: AgentChatRuntimeToolCapabilities;\n readonly sessions?: AgentChatRuntimeSessionCapabilities;\n readonly cancellation?: AgentChatRuntimeCancellationCapabilities;\n readonly models?: AgentChatRuntimeModelCapabilities;\n readonly artifacts?: AgentChatRuntimeArtifactCapabilities;\n readonly custom?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeCreateSessionInput {\n readonly id?: AgentChatRuntimeSessionId;\n readonly threadId?: string;\n readonly title?: string;\n readonly messages?: readonly AgentChatRuntimeMessage[];\n readonly resumeState?: unknown;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport interface AgentChatRuntimeListSessionsInput {\n readonly threadId?: string;\n readonly limit?: number;\n readonly cursor?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport type AgentChatRuntimeSessionStatus =\n | \"idle\"\n | \"running\"\n | \"waiting\"\n | \"cancelled\"\n | \"completed\"\n | \"error\";\n\nexport interface AgentChatRuntimeSessionSummary {\n readonly id: AgentChatRuntimeSessionId;\n readonly runtimeId: AgentChatRuntimeId;\n readonly threadId?: string;\n readonly title?: string;\n readonly status?: AgentChatRuntimeSessionStatus;\n readonly createdAt?: string;\n readonly updatedAt?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeSessionSnapshot extends AgentChatRuntimeSessionSummary {\n readonly messages?: readonly AgentChatRuntimeMessage[];\n readonly resumeState?: unknown;\n}\n\nexport interface AgentChatRuntimeTurnInput {\n readonly prompt?: string;\n readonly messages?: readonly AgentChatRuntimeMessage[];\n readonly attachments?: readonly AgentChatRuntimeAttachment[];\n readonly tools?: readonly AgentChatRuntimeToolDefinition[];\n readonly model?: string;\n readonly reasoningEffort?: ReasoningEffort;\n readonly temperature?: number;\n readonly providerOptions?: Record<string, unknown>;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport interface AgentChatRuntimeApprovalResponse {\n readonly id: string;\n readonly approved: boolean;\n readonly message?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeContinueInput {\n readonly turnId?: AgentChatRuntimeTurnId;\n readonly prompt?: string;\n readonly approval?: AgentChatRuntimeApprovalResponse;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport interface AgentChatRuntimeCancelInput {\n readonly sessionId?: AgentChatRuntimeSessionId;\n readonly turnId?: AgentChatRuntimeTurnId;\n readonly runId?: string;\n readonly reason?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport type AgentChatRuntimeCancelStatus =\n | \"cancelled\"\n | \"not-found\"\n | \"already-finished\"\n | \"unsupported\";\n\nexport interface AgentChatRuntimeCancelResult {\n readonly status: AgentChatRuntimeCancelStatus;\n readonly message?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeEventBase<TType extends string = string> {\n readonly type: TType;\n readonly id?: string;\n readonly sessionId?: AgentChatRuntimeSessionId;\n readonly turnId?: AgentChatRuntimeTurnId;\n readonly timestamp?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeMessageStartEvent extends AgentChatRuntimeEventBase<\"message-start\"> {\n readonly message: AgentChatRuntimeMessage;\n}\n\nexport type AgentChatRuntimeMessageDelta =\n | {\n readonly type: \"text\";\n readonly text: string;\n readonly partId?: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly partId?: string;\n readonly signature?: string;\n }\n | {\n readonly type: \"data\";\n readonly data: unknown;\n readonly partId?: string;\n readonly mediaType?: string;\n };\n\nexport interface AgentChatRuntimeMessageDeltaEvent extends AgentChatRuntimeEventBase<\"message-delta\"> {\n readonly messageId: AgentChatRuntimeMessageId;\n readonly delta: AgentChatRuntimeMessageDelta;\n}\n\nexport interface AgentChatRuntimeMessageDoneEvent extends AgentChatRuntimeEventBase<\"message-done\"> {\n readonly message: AgentChatRuntimeMessage;\n}\n\nexport interface AgentChatRuntimeToolStartEvent extends AgentChatRuntimeEventBase<\"tool-start\"> {\n readonly toolCall: AgentChatRuntimeToolCall;\n}\n\nexport interface AgentChatRuntimeToolDeltaEvent extends AgentChatRuntimeEventBase<\"tool-delta\"> {\n readonly toolCallId: AgentChatRuntimeToolCallId;\n readonly toolName?: string;\n readonly inputTextDelta?: string;\n readonly resultTextDelta?: string;\n}\n\nexport interface AgentChatRuntimeToolDoneEvent extends AgentChatRuntimeEventBase<\"tool-done\"> {\n readonly toolCallId: AgentChatRuntimeToolCallId;\n readonly toolName: string;\n readonly status: AgentChatRuntimeToolStatus;\n readonly result?: unknown;\n readonly resultText?: string;\n readonly error?: string;\n readonly mcpApp?: AgentMcpAppPayload;\n readonly chatUI?: ActionChatUIConfig;\n}\n\nexport interface AgentChatRuntimeApprovalRequestEvent extends AgentChatRuntimeEventBase<\"approval-request\"> {\n readonly approvalId: string;\n readonly toolCallId?: AgentChatRuntimeToolCallId;\n readonly toolName?: string;\n readonly message: string;\n readonly input?: unknown;\n}\n\nexport interface AgentChatRuntimeApprovalResolvedEvent extends AgentChatRuntimeEventBase<\"approval-resolved\"> {\n readonly approvalId: string;\n readonly approved: boolean;\n readonly message?: string;\n}\n\nexport interface AgentChatRuntimeStatusEvent extends AgentChatRuntimeEventBase<\"status\"> {\n readonly level?: \"info\" | \"warning\" | \"error\";\n readonly message: string;\n readonly code?: string;\n}\n\nexport interface AgentChatRuntimeArtifactEvent extends AgentChatRuntimeEventBase<\"artifact\"> {\n readonly artifact: {\n readonly id?: string;\n readonly kind: string;\n readonly title?: string;\n readonly url?: string;\n readonly path?: string;\n readonly data?: unknown;\n readonly metadata?: AgentChatRuntimeMetadata;\n };\n}\n\nexport interface AgentChatRuntimeFileEvent extends AgentChatRuntimeEventBase<\"file\"> {\n readonly path: string;\n readonly operation?: \"create\" | \"update\" | \"delete\" | \"rename\" | \"unknown\";\n readonly summary?: string;\n}\n\nexport interface AgentChatRuntimeUsageEvent extends AgentChatRuntimeEventBase<\"usage\"> {\n readonly usage: AgentChatRuntimeUsage;\n}\n\nexport interface AgentChatRuntimeErrorEvent extends AgentChatRuntimeEventBase<\"error\"> {\n readonly error: string;\n readonly code?: string;\n readonly recoverable?: boolean;\n readonly cause?: unknown;\n}\n\nexport type AgentChatRuntimeDoneReason =\n | \"complete\"\n | \"cancelled\"\n | \"error\"\n | \"interrupted\"\n | \"length\"\n | \"tool-use\"\n | (string & {});\n\nexport interface AgentChatRuntimeDoneEvent extends AgentChatRuntimeEventBase<\"done\"> {\n readonly reason?: AgentChatRuntimeDoneReason;\n}\n\nexport interface AgentChatRuntimeCustomEvent extends AgentChatRuntimeEventBase {\n readonly [key: string]: unknown;\n}\n\nexport type AgentChatRuntimeKnownEvent =\n | AgentChatRuntimeMessageStartEvent\n | AgentChatRuntimeMessageDeltaEvent\n | AgentChatRuntimeMessageDoneEvent\n | AgentChatRuntimeToolStartEvent\n | AgentChatRuntimeToolDeltaEvent\n | AgentChatRuntimeToolDoneEvent\n | AgentChatRuntimeApprovalRequestEvent\n | AgentChatRuntimeApprovalResolvedEvent\n | AgentChatRuntimeStatusEvent\n | AgentChatRuntimeArtifactEvent\n | AgentChatRuntimeFileEvent\n | AgentChatRuntimeUsageEvent\n | AgentChatRuntimeErrorEvent\n | AgentChatRuntimeDoneEvent;\n\nexport type AgentChatRuntimeEvent<\n TCustomEvent extends AgentChatRuntimeCustomEvent = never,\n> = AgentChatRuntimeKnownEvent | TCustomEvent;\n\nexport interface AgentChatRuntimeTurn<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n> {\n readonly id?: AgentChatRuntimeTurnId;\n readonly sessionId: AgentChatRuntimeSessionId;\n readonly runId?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly events: AsyncIterable<TEvent>;\n cancel?(\n input?: AgentChatRuntimeCancelInput,\n ): Promise<AgentChatRuntimeCancelResult>;\n}\n\nexport interface AgentChatRuntimeSendMessageInput extends AgentChatRuntimeTurnInput {\n readonly sessionId?: AgentChatRuntimeSessionId;\n}\n\nexport interface AgentChatRuntimeSubscribeInput {\n readonly sessionId?: AgentChatRuntimeSessionId;\n readonly turnId?: AgentChatRuntimeTurnId;\n readonly runId?: string;\n readonly after?: number;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport interface AgentChatRuntimeResumeInput extends AgentChatRuntimeSubscribeInput {\n readonly prompt?: string;\n}\n\nexport interface AgentChatRuntimeSession<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n> {\n readonly id: AgentChatRuntimeSessionId;\n readonly runtimeId: AgentChatRuntimeId;\n readonly threadId?: string;\n readonly capabilities?: Partial<AgentChatRuntimeCapabilities>;\n sendMessage?(\n input: AgentChatRuntimeTurnInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n startTurn(\n input: AgentChatRuntimeTurnInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n continueTurn?(\n input?: AgentChatRuntimeContinueInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n cancelTurn?(\n input?: AgentChatRuntimeCancelInput,\n ): Promise<AgentChatRuntimeCancelResult>;\n snapshot?(): AgentChatRuntimeAwaitable<AgentChatRuntimeSessionSnapshot>;\n dispose?(): AgentChatRuntimeAwaitable<void>;\n}\n\nexport interface AgentChatRuntime<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n> {\n readonly id: AgentChatRuntimeId;\n readonly kind: AgentChatRuntimeKind;\n readonly label: string;\n readonly description?: string;\n readonly capabilities: AgentChatRuntimeCapabilities;\n createSession(\n input?: AgentChatRuntimeCreateSessionInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeSession<TEvent>>;\n restoreSession?(\n snapshot: AgentChatRuntimeSessionSnapshot,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeSession<TEvent>>;\n getSession?(input: {\n readonly sessionId: AgentChatRuntimeSessionId;\n readonly abortSignal?: AbortSignal;\n }): AgentChatRuntimeAwaitable<AgentChatRuntimeSession<TEvent> | null>;\n listSessions?(\n input?: AgentChatRuntimeListSessionsInput,\n ): AgentChatRuntimeAwaitable<readonly AgentChatRuntimeSessionSummary[]>;\n sendMessage?(\n input: AgentChatRuntimeSendMessageInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n subscribe?(\n input: AgentChatRuntimeSubscribeInput,\n ): AgentChatRuntimeAwaitable<AsyncIterable<TEvent>>;\n resume?(\n input: AgentChatRuntimeResumeInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n cancel?(\n input: AgentChatRuntimeCancelInput,\n ): Promise<AgentChatRuntimeCancelResult>;\n}\n\ntype FetchLike = typeof fetch;\ntype HeadersFactory =\n | HeadersInit\n | ((input: {\n sessionId?: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n }) => HeadersInit | Promise<HeadersInit>);\n\nexport interface CreateHttpAgentChatRuntimeOptions<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n> {\n readonly id?: AgentChatRuntimeId;\n readonly kind?: AgentChatRuntimeKind;\n readonly label?: string;\n readonly description?: string;\n readonly endpoint:\n | string\n | ((input: {\n session: AgentChatRuntimeSessionSummary;\n turn: AgentChatRuntimeTurnInput;\n }) => string | URL);\n readonly method?: \"POST\" | \"PUT\";\n readonly headers?: HeadersFactory;\n readonly credentials?: RequestCredentials;\n readonly fetch?: FetchLike;\n readonly capabilities?: Partial<AgentChatRuntimeCapabilities>;\n readonly mapRequest?: (input: {\n session: AgentChatRuntimeSessionSummary;\n turn: AgentChatRuntimeTurnInput;\n turnId: AgentChatRuntimeTurnId;\n }) => unknown;\n readonly mapEvent?: (\n event: unknown,\n context: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n ) => TEvent | readonly TEvent[] | null;\n readonly cancelEndpoint?:\n | string\n | ((input: AgentChatRuntimeCancelInput) => string | URL | null);\n readonly resumeEndpoint?:\n | string\n | ((input: AgentChatRuntimeSubscribeInput) => string | URL | null);\n readonly listSessionsEndpoint?: string | URL;\n readonly getSessionEndpoint?:\n | string\n | ((input: { sessionId: AgentChatRuntimeSessionId }) => string | URL);\n}\n\nexport interface CreateAgentNativeChatRuntimeOptions {\n readonly id?: AgentChatRuntimeId;\n readonly label?: string;\n readonly description?: string;\n readonly apiUrl?: string;\n readonly headers?: HeadersFactory;\n readonly fetch?: FetchLike;\n readonly threadId?: string;\n readonly browserTabId?: string;\n readonly surface?: \"app\" | \"dev-frame\";\n readonly mode?: \"act\" | \"plan\";\n readonly model?: string;\n readonly engine?: string;\n readonly effort?: ReasoningEffort;\n readonly scope?: unknown;\n}\n\nexport interface CreateAgentChatRuntimeAdapterOptions {\n readonly sessionId?: AgentChatRuntimeSessionId;\n readonly threadId?: string;\n readonly modelRef?: { current: string | undefined };\n readonly effortRef?: { current: ReasoningEffort | undefined };\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nconst DEFAULT_RUNTIME_CAPABILITIES: AgentChatRuntimeCapabilities = {\n messages: {\n streaming: true,\n history: true,\n structuredContent: true,\n attachments: true,\n },\n tools: {\n events: true,\n hostTools: true,\n resultStreaming: true,\n mcpApps: true,\n },\n sessions: {\n create: true,\n restore: true,\n persistent: true,\n },\n cancellation: {\n abortSignal: true,\n explicitCancel: true,\n },\n models: {\n selectable: true,\n reasoningEffort: true,\n },\n artifacts: {\n files: true,\n links: true,\n progress: true,\n },\n};\n\nfunction mergeCapabilities(\n overrides?: Partial<AgentChatRuntimeCapabilities>,\n): AgentChatRuntimeCapabilities {\n return {\n ...DEFAULT_RUNTIME_CAPABILITIES,\n ...overrides,\n messages: {\n ...DEFAULT_RUNTIME_CAPABILITIES.messages,\n ...overrides?.messages,\n },\n tools: {\n ...DEFAULT_RUNTIME_CAPABILITIES.tools,\n ...overrides?.tools,\n events:\n overrides?.tools?.events ?? DEFAULT_RUNTIME_CAPABILITIES.tools!.events,\n },\n sessions: {\n ...DEFAULT_RUNTIME_CAPABILITIES.sessions,\n ...overrides?.sessions,\n create:\n overrides?.sessions?.create ??\n DEFAULT_RUNTIME_CAPABILITIES.sessions!.create,\n },\n cancellation: {\n ...DEFAULT_RUNTIME_CAPABILITIES.cancellation,\n ...overrides?.cancellation,\n },\n models: { ...DEFAULT_RUNTIME_CAPABILITIES.models, ...overrides?.models },\n artifacts: {\n ...DEFAULT_RUNTIME_CAPABILITIES.artifacts,\n ...overrides?.artifacts,\n },\n };\n}\n\nfunction createRuntimeId(prefix: string): string {\n if (\n typeof crypto !== \"undefined\" &&\n typeof crypto.randomUUID === \"function\"\n ) {\n return `${prefix}-${crypto.randomUUID()}`;\n }\n return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;\n}\n\nfunction createAbortController(signal?: AbortSignal): {\n controller: AbortController;\n cleanup: () => void;\n} {\n const controller = new AbortController();\n if (!signal) return { controller, cleanup: () => {} };\n if (signal.aborted) controller.abort();\n const abort = () => controller.abort();\n signal.addEventListener(\"abort\", abort, { once: true });\n return {\n controller,\n cleanup: () => signal.removeEventListener(\"abort\", abort),\n };\n}\n\nasync function resolveHeaders(\n headers: HeadersFactory | undefined,\n input: {\n sessionId?: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n): Promise<Headers> {\n const resolved =\n typeof headers === \"function\" ? await headers(input) : headers;\n return new Headers(resolved);\n}\n\nfunction normalizeEndpoint(value: string | URL): string {\n return typeof value === \"string\" ? value : value.toString();\n}\n\nfunction isRuntimeEvent(value: unknown): value is AgentChatRuntimeEventBase {\n return (\n !!value &&\n typeof value === \"object\" &&\n typeof (value as { type?: unknown }).type === \"string\"\n );\n}\n\nfunction parseJsonEvent(raw: string): unknown | null {\n const trimmed = raw.trim();\n if (!trimmed || trimmed === \"[DONE]\") return null;\n try {\n return JSON.parse(trimmed);\n } catch {\n return null;\n }\n}\n\nasync function* readJsonEventStream(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<unknown> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n let pendingSseData: string[] = [];\n\n const flushSseData = function* (): Generator<unknown> {\n if (pendingSseData.length === 0) return;\n const parsed = parseJsonEvent(pendingSseData.join(\"\\n\"));\n pendingSseData = [];\n if (parsed) yield parsed;\n };\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(/\\r?\\n/);\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data:\")) {\n pendingSseData.push(line.slice(5).trimStart());\n continue;\n }\n if (line.trim() === \"\") {\n yield* flushSseData();\n continue;\n }\n const parsed = parseJsonEvent(line);\n if (parsed) yield parsed;\n }\n }\n\n if (buffer.trim()) {\n const parsed = parseJsonEvent(buffer);\n if (parsed) yield parsed;\n }\n yield* flushSseData();\n } finally {\n try {\n reader.releaseLock();\n } catch {\n // Some browser runtimes consider a cancelled stream locked for a tick.\n }\n }\n}\n\nfunction textResponseEvents(\n text: string,\n sessionId: AgentChatRuntimeSessionId,\n turnId?: AgentChatRuntimeTurnId,\n): AgentChatRuntimeKnownEvent[] {\n const message: AgentChatRuntimeMessage = {\n id: createRuntimeId(\"message\"),\n role: \"assistant\",\n content: [],\n };\n return [\n { type: \"message-start\", sessionId, turnId, message },\n ...(text\n ? [\n {\n type: \"message-delta\" as const,\n sessionId,\n turnId,\n messageId: message.id,\n delta: { type: \"text\" as const, text },\n },\n ]\n : []),\n { type: \"message-done\", sessionId, turnId, message },\n { type: \"done\", sessionId, turnId, reason: \"complete\" },\n ];\n}\n\nasync function* eventsFromJsonResponse(\n value: unknown,\n sessionId: AgentChatRuntimeSessionId,\n turnId?: AgentChatRuntimeTurnId,\n): AsyncGenerator<AgentChatRuntimeEvent> {\n if (Array.isArray(value)) {\n for (const item of value) {\n if (isRuntimeEvent(item)) yield item as AgentChatRuntimeEvent;\n }\n return;\n }\n if (!value || typeof value !== \"object\") return;\n const record = value as Record<string, unknown>;\n if (Array.isArray(record.events)) {\n for (const item of record.events) {\n if (isRuntimeEvent(item)) yield item as AgentChatRuntimeEvent;\n }\n return;\n }\n const text =\n typeof record.message === \"string\"\n ? record.message\n : typeof record.text === \"string\"\n ? record.text\n : \"\";\n if (text) {\n for (const event of textResponseEvents(text, sessionId, turnId)) {\n yield event;\n }\n }\n}\n\nfunction defaultMapHttpRuntimeEvent(\n event: unknown,\n _context?: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n): AgentChatRuntimeEvent | readonly AgentChatRuntimeEvent[] | null {\n if (!isRuntimeEvent(event)) return null;\n return event as AgentChatRuntimeEvent;\n}\n\nfunction normalizeMappedEvents<TEvent extends AgentChatRuntimeEventBase>(\n mapped: TEvent | readonly TEvent[] | null,\n): readonly TEvent[] {\n if (!mapped) return [];\n return Array.isArray(mapped)\n ? (mapped as readonly TEvent[])\n : [mapped as TEvent];\n}\n\nasync function* streamResponseEvents<TEvent extends AgentChatRuntimeEventBase>(\n response: Response,\n input: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n mapEvent: (\n event: unknown,\n context: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n ) => TEvent | readonly TEvent[] | null;\n },\n): AsyncGenerator<TEvent> {\n const context = {\n sessionId: input.sessionId,\n turnId: input.turnId,\n runId: input.runId,\n };\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (response.body && !contentType.includes(\"application/json\")) {\n for await (const raw of readJsonEventStream(response.body)) {\n for (const event of normalizeMappedEvents(input.mapEvent(raw, context))) {\n yield event;\n }\n }\n return;\n }\n\n const json = await response.json().catch(() => null);\n for await (const event of eventsFromJsonResponse(\n json,\n input.sessionId,\n input.turnId,\n )) {\n for (const mapped of normalizeMappedEvents(\n input.mapEvent(event, context),\n )) {\n yield mapped;\n }\n }\n}\n\nfunction defaultHttpRuntimeRequest(input: {\n session: AgentChatRuntimeSessionSummary;\n turn: AgentChatRuntimeTurnInput;\n turnId: AgentChatRuntimeTurnId;\n}) {\n return {\n sessionId: input.session.id,\n threadId: input.session.threadId,\n turnId: input.turnId,\n prompt: input.turn.prompt,\n messages: input.turn.messages,\n attachments: input.turn.attachments,\n tools: input.turn.tools,\n model: input.turn.model,\n reasoningEffort: input.turn.reasoningEffort,\n temperature: input.turn.temperature,\n providerOptions: input.turn.providerOptions,\n metadata: input.turn.metadata,\n };\n}\n\nasync function readErrorText(response: Response): Promise<string> {\n const text = await response.text().catch(() => \"\");\n if (!text) return `HTTP ${response.status}`;\n try {\n const parsed = JSON.parse(text) as { error?: unknown; message?: unknown };\n if (typeof parsed.error === \"string\") return parsed.error;\n if (typeof parsed.message === \"string\") return parsed.message;\n } catch {\n // Keep raw text.\n }\n return text.slice(0, 500);\n}\n\nexport function createHttpAgentChatRuntime<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n>(\n options: CreateHttpAgentChatRuntimeOptions<TEvent>,\n): AgentChatRuntime<TEvent> {\n const fetchImpl = options.fetch ?? fetch;\n const capabilities = mergeCapabilities(options.capabilities);\n const runtimeId = options.id ?? \"external:http\";\n const mapEvent =\n options.mapEvent ??\n (defaultMapHttpRuntimeEvent as (\n event: unknown,\n context: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n ) => TEvent | readonly TEvent[] | null);\n\n const createSessionObject = (\n input?: AgentChatRuntimeCreateSessionInput,\n ): AgentChatRuntimeSession<TEvent> => {\n const sessionId =\n input?.id ?? input?.threadId ?? createRuntimeId(\"session\");\n const summary: AgentChatRuntimeSessionSummary = {\n id: sessionId,\n runtimeId,\n threadId: input?.threadId,\n title: input?.title,\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n metadata: input?.metadata,\n };\n\n const startTurn = async (\n turn: AgentChatRuntimeTurnInput,\n ): Promise<AgentChatRuntimeTurn<TEvent>> => {\n const turnId = createRuntimeId(\"turn\");\n const { controller, cleanup } = createAbortController(turn.abortSignal);\n const endpoint =\n typeof options.endpoint === \"function\"\n ? options.endpoint({ session: summary, turn })\n : options.endpoint;\n const headers = await resolveHeaders(options.headers, {\n sessionId,\n turnId,\n });\n if (!headers.has(\"Content-Type\"))\n headers.set(\"Content-Type\", \"application/json\");\n const response = await fetchImpl(normalizeEndpoint(endpoint), {\n method: options.method ?? \"POST\",\n headers,\n credentials: options.credentials,\n body: JSON.stringify(\n options.mapRequest\n ? options.mapRequest({ session: summary, turn, turnId })\n : defaultHttpRuntimeRequest({ session: summary, turn, turnId }),\n ),\n signal: controller.signal,\n });\n if (!response.ok) {\n cleanup();\n throw new Error(await readErrorText(response));\n }\n\n const runId = response.headers.get(\"X-Run-Id\") ?? undefined;\n const events = (async function* () {\n try {\n yield* streamResponseEvents(response, {\n sessionId,\n turnId,\n runId,\n mapEvent,\n });\n } finally {\n cleanup();\n }\n })();\n\n return {\n id: turnId,\n sessionId,\n runId,\n events,\n cancel: async (cancelInput) => {\n controller.abort();\n if (!options.cancelEndpoint) return { status: \"cancelled\" };\n const endpoint =\n typeof options.cancelEndpoint === \"function\"\n ? options.cancelEndpoint({\n ...cancelInput,\n sessionId,\n turnId,\n runId,\n })\n : options.cancelEndpoint;\n if (!endpoint) return { status: \"unsupported\" };\n const cancelHeaders = await resolveHeaders(options.headers, {\n sessionId,\n turnId,\n });\n if (!cancelHeaders.has(\"Content-Type\")) {\n cancelHeaders.set(\"Content-Type\", \"application/json\");\n }\n const cancelResponse = await fetchImpl(normalizeEndpoint(endpoint), {\n method: \"POST\",\n headers: cancelHeaders,\n credentials: options.credentials,\n body: JSON.stringify({\n sessionId,\n turnId,\n runId,\n reason: cancelInput?.reason ?? \"user\",\n metadata: cancelInput?.metadata,\n }),\n signal: cancelInput?.abortSignal,\n });\n return cancelResponse.ok\n ? { status: \"cancelled\" }\n : {\n status: \"unsupported\",\n message: await readErrorText(cancelResponse),\n };\n },\n };\n };\n\n return {\n id: sessionId,\n runtimeId,\n threadId: input?.threadId,\n capabilities,\n sendMessage: startTurn,\n startTurn,\n snapshot: () => ({\n ...summary,\n status: \"idle\",\n updatedAt: new Date().toISOString(),\n messages: input?.messages,\n resumeState: input?.resumeState,\n }),\n dispose: () => undefined,\n };\n };\n\n const runtime: AgentChatRuntime<TEvent> = {\n id: runtimeId,\n kind: options.kind ?? \"external-agent\",\n label: options.label ?? \"External agent\",\n description: options.description,\n capabilities,\n createSession: createSessionObject,\n restoreSession: (snapshot) =>\n createSessionObject({\n id: snapshot.id,\n threadId: snapshot.threadId,\n title: snapshot.title,\n messages: snapshot.messages,\n resumeState: snapshot.resumeState,\n metadata: snapshot.metadata,\n }),\n sendMessage: async (input) => {\n const session = createSessionObject({\n id: input.sessionId,\n threadId: input.sessionId,\n metadata: input.metadata,\n });\n return session.startTurn(input);\n },\n subscribe: async (input) => {\n if (!options.resumeEndpoint) return (async function* () {})();\n const endpoint =\n typeof options.resumeEndpoint === \"function\"\n ? options.resumeEndpoint(input)\n : options.resumeEndpoint;\n if (!endpoint) return (async function* () {})();\n const headers = await resolveHeaders(options.headers, input);\n const response = await fetchImpl(normalizeEndpoint(endpoint), {\n headers,\n credentials: options.credentials,\n signal: input.abortSignal,\n });\n if (!response.ok) throw new Error(await readErrorText(response));\n return streamResponseEvents(response, {\n sessionId: input.sessionId ?? \"session\",\n turnId: input.turnId,\n runId: input.runId,\n mapEvent,\n });\n },\n resume: async (input) => {\n const sessionId = input.sessionId ?? createRuntimeId(\"session\");\n const events = runtime.subscribe\n ? await runtime.subscribe(input)\n : (async function* () {})();\n return {\n id: input.turnId,\n sessionId,\n runId: input.runId,\n events,\n };\n },\n cancel: async (input) => {\n if (!options.cancelEndpoint) return { status: \"unsupported\" };\n const endpoint =\n typeof options.cancelEndpoint === \"function\"\n ? options.cancelEndpoint(input)\n : options.cancelEndpoint;\n if (!endpoint) return { status: \"unsupported\" };\n const headers = await resolveHeaders(options.headers, input);\n if (!headers.has(\"Content-Type\"))\n headers.set(\"Content-Type\", \"application/json\");\n const response = await fetchImpl(normalizeEndpoint(endpoint), {\n method: \"POST\",\n headers,\n credentials: options.credentials,\n body: JSON.stringify(input),\n signal: input.abortSignal,\n });\n return response.ok\n ? { status: \"cancelled\" }\n : { status: \"unsupported\", message: await readErrorText(response) };\n },\n };\n\n return runtime;\n}\n\nfunction runtimeMessageText(message: AgentChatRuntimeMessage): string {\n return message.content\n .map((part) =>\n part.type === \"text\" || part.type === \"reasoning\" ? part.text : \"\",\n )\n .filter(Boolean)\n .join(\"\\n\");\n}\n\nfunction nativeHistoryFromMessages(\n messages: readonly AgentChatRuntimeMessage[] | undefined,\n currentPrompt: string,\n) {\n const history = (messages ?? [])\n .filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n )\n .map((message) => ({\n role: message.role as \"user\" | \"assistant\",\n content: runtimeMessageText(message),\n }))\n .filter((message) => message.content.trim());\n if (!currentPrompt.trim()) return history;\n const last = history[history.length - 1];\n return last?.role === \"user\" && last.content === currentPrompt\n ? history.slice(0, -1)\n : history;\n}\n\nfunction mapAgentNativeEvent(\n raw: unknown,\n input: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n messageId: string;\n text: { value: string; started: boolean };\n },\n): AgentChatRuntimeKnownEvent[] {\n if (!raw || typeof raw !== \"object\") return [];\n const ev = raw as SSEEvent;\n const base = {\n sessionId: input.sessionId,\n turnId: input.turnId,\n };\n if (ev.seq !== undefined) {\n (base as { metadata?: AgentChatRuntimeMetadata }).metadata = {\n seq: ev.seq,\n };\n }\n if (ev.type === \"text\") {\n const text = ev.text ?? \"\";\n const events: AgentChatRuntimeKnownEvent[] = [];\n if (!input.text.started) {\n input.text.started = true;\n events.push({\n type: \"message-start\",\n ...base,\n message: {\n id: input.messageId,\n role: \"assistant\",\n content: [],\n },\n });\n }\n input.text.value += text;\n events.push({\n type: \"message-delta\",\n ...base,\n messageId: input.messageId,\n delta: { type: \"text\", text },\n });\n return events;\n }\n if (ev.type === \"activity\") {\n return [\n {\n type: \"status\",\n ...base,\n message: ev.label ?? ev.tool ?? \"Working\",\n metadata: ev.tool ? { tool: ev.tool } : undefined,\n },\n ];\n }\n if (ev.type === \"tool_start\") {\n return [\n {\n type: \"tool-start\",\n ...base,\n toolCall: {\n id: ev.id ?? createRuntimeId(\"tool\"),\n name: ev.tool ?? \"unknown\",\n input: ev.input,\n inputText: ev.input ? JSON.stringify(ev.input) : undefined,\n },\n },\n ];\n }\n if (ev.type === \"tool_done\") {\n return [\n {\n type: \"tool-done\",\n ...base,\n toolCallId: ev.id ?? \"\",\n toolName: ev.tool ?? \"unknown\",\n status: ev.error ? \"failed\" : \"completed\",\n result: ev.result,\n resultText:\n typeof ev.result === \"string\"\n ? ev.result\n : ev.result !== undefined\n ? JSON.stringify(ev.result)\n : undefined,\n error: ev.error,\n mcpApp: ev.mcpApp,\n chatUI: ev.chatUI,\n },\n ];\n }\n if (ev.type === \"approval_required\") {\n return [\n {\n type: \"approval-request\",\n ...base,\n approvalId: ev.approvalKey ?? ev.id ?? createRuntimeId(\"approval\"),\n toolCallId: ev.id,\n toolName: ev.tool,\n message: ev.label ?? \"Approve this tool call?\",\n input: ev.input,\n },\n ];\n }\n if (ev.type === \"error\" || ev.type === \"missing_api_key\") {\n return [\n {\n type: \"error\",\n ...base,\n error: ev.error ?? \"Agent chat failed.\",\n code: ev.errorCode,\n recoverable: ev.recoverable,\n },\n { type: \"done\", ...base, reason: \"error\" },\n ];\n }\n if (ev.type === \"done\") {\n const message: AgentChatRuntimeMessage = {\n id: input.messageId,\n role: \"assistant\",\n content: input.text.value\n ? [{ type: \"text\", text: input.text.value }]\n : [],\n };\n return [\n ...(input.text.started\n ? [{ type: \"message-done\" as const, ...base, message }]\n : []),\n { type: \"done\", ...base, reason: \"complete\" },\n ];\n }\n return [];\n}\n\nexport function createAgentNativeChatRuntime(\n options: CreateAgentNativeChatRuntimeOptions = {},\n): AgentChatRuntime<AgentChatRuntimeKnownEvent> {\n const apiUrl = options.apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n const runtimeId = options.id ?? \"agent-native\";\n const fetchImpl = options.fetch ?? fetch;\n\n return createHttpAgentChatRuntime({\n id: runtimeId,\n kind: \"agent-native\",\n label: options.label ?? \"Agent Native\",\n description:\n options.description ?? \"Agent-Native's built-in chat transport.\",\n endpoint: apiUrl,\n fetch: fetchImpl,\n headers: async (input) => {\n const headers = await resolveHeaders(options.headers, input);\n headers.set(\"x-agent-native-surface\", options.surface ?? \"app\");\n return headers;\n },\n capabilities: DEFAULT_RUNTIME_CAPABILITIES,\n mapRequest: ({ session, turn, turnId }) => {\n const prompt =\n turn.prompt ??\n [...(turn.messages ?? [])]\n .reverse()\n .find((message) => message.role === \"user\")\n ?.content.map((part) => (part.type === \"text\" ? part.text : \"\"))\n .join(\"\\n\") ??\n \"\";\n return {\n message: prompt,\n displayMessage: prompt,\n history: nativeHistoryFromMessages(turn.messages, prompt),\n turnId,\n threadId: session.threadId ?? options.threadId,\n ...(options.mode ? { mode: options.mode } : {}),\n ...((turn.model ?? options.model)\n ? { model: turn.model ?? options.model }\n : {}),\n ...(options.engine ? { engine: options.engine } : {}),\n ...((turn.reasoningEffort ?? options.effort)\n ? { effort: turn.reasoningEffort ?? options.effort }\n : {}),\n ...(options.browserTabId ? { browserTabId: options.browserTabId } : {}),\n ...(options.scope ? { scope: options.scope } : {}),\n ...(turn.attachments?.length ? { attachments: turn.attachments } : {}),\n ...(turn.metadata ? { metadata: turn.metadata } : {}),\n };\n },\n mapEvent: (() => {\n const states = new Map<\n string,\n { messageId: string; text: { value: string; started: boolean } }\n >();\n return (\n event: unknown,\n context: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n },\n ) => {\n const stateKey = context.turnId ?? context.sessionId;\n let state = states.get(stateKey);\n if (!state) {\n state = {\n messageId: createRuntimeId(\"message\"),\n text: { value: \"\", started: false },\n };\n states.set(stateKey, state);\n }\n const mapped = mapAgentNativeEvent(event, {\n sessionId: context.sessionId,\n turnId: context.turnId,\n messageId: state.messageId,\n text: state.text,\n });\n const type =\n event && typeof event === \"object\"\n ? (event as { type?: unknown }).type\n : undefined;\n if (type === \"done\" || type === \"error\" || type === \"missing_api_key\") {\n states.delete(stateKey);\n }\n return mapped;\n };\n })(),\n cancelEndpoint: (input) =>\n input.runId\n ? `${apiUrl}/runs/${encodeURIComponent(input.runId)}/abort`\n : null,\n resumeEndpoint: (input) =>\n input.runId\n ? `${apiUrl}/runs/${encodeURIComponent(input.runId)}/events?after=${input.after ?? 0}`\n : null,\n });\n}\n\nfunction toContentPartInput(value: unknown): Record<string, string> {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return {};\n const out: Record<string, string> = {};\n for (const [key, item] of Object.entries(value)) {\n out[key] = typeof item === \"string\" ? item : JSON.stringify(item);\n }\n return out;\n}\n\nfunction toolResultText(value: unknown): string {\n if (typeof value === \"string\") return value;\n if (value === undefined) return \"\";\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction applyRuntimeEventToContent(\n event: AgentChatRuntimeEventBase,\n content: ContentPart[],\n): ChatModelRunResult | null {\n const typed = event as AgentChatRuntimeKnownEvent;\n if (typed.type === \"message-start\") {\n for (const part of typed.message.content) {\n if (part.type === \"text\" && part.text) {\n content.push({ type: \"text\", text: part.text });\n }\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"message-delta\") {\n if (typed.delta.type === \"text\") {\n const last = content[content.length - 1];\n if (last?.type === \"text\") {\n last.text += typed.delta.text;\n } else {\n content.push({ type: \"text\", text: typed.delta.text });\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n return null;\n }\n if (typed.type === \"message-done\") {\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"tool-start\") {\n content.push({\n type: \"tool-call\",\n toolCallId: typed.toolCall.id,\n toolName: typed.toolCall.name,\n argsText:\n typed.toolCall.inputText ?? JSON.stringify(typed.toolCall.input ?? {}),\n args: toContentPartInput(typed.toolCall.input),\n });\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"tool-delta\") {\n const part = [...content]\n .reverse()\n .find(\n (candidate): candidate is Extract<ContentPart, { type: \"tool-call\" }> =>\n candidate.type === \"tool-call\" &&\n candidate.toolCallId === typed.toolCallId,\n );\n if (!part) return null;\n if (typed.inputTextDelta) {\n part.argsText += typed.inputTextDelta;\n }\n if (typed.resultTextDelta) {\n part.result = `${part.result ?? \"\"}${typed.resultTextDelta}`;\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"tool-done\") {\n const part = [...content]\n .reverse()\n .find(\n (candidate): candidate is Extract<ContentPart, { type: \"tool-call\" }> =>\n candidate.type === \"tool-call\" &&\n candidate.toolCallId === typed.toolCallId,\n );\n if (part) {\n part.result =\n typed.error ?? typed.resultText ?? toolResultText(typed.result);\n if (typed.mcpApp) part.mcpApp = typed.mcpApp;\n if (typed.chatUI) part.chatUI = typed.chatUI;\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"approval-request\") {\n const part = [...content]\n .reverse()\n .find(\n (candidate): candidate is Extract<ContentPart, { type: \"tool-call\" }> =>\n candidate.type === \"tool-call\" &&\n (candidate.toolCallId === typed.toolCallId ||\n candidate.toolName === typed.toolName),\n );\n if (part) {\n part.approval = { approvalKey: typed.approvalId };\n } else {\n content.push({\n type: \"tool-call\",\n toolCallId: typed.toolCallId ?? typed.approvalId,\n toolName: typed.toolName ?? \"approval\",\n argsText: typed.input ? JSON.stringify(typed.input) : \"\",\n args: toContentPartInput(typed.input),\n approval: { approvalKey: typed.approvalId },\n });\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"error\") {\n settleInterruptedToolCalls(content);\n content.push({\n type: \"text\",\n text: `Something went wrong: ${typed.error}`,\n });\n return {\n content: [...content],\n status: { type: \"incomplete\", reason: \"error\" },\n metadata: {\n custom: {\n runError: {\n message: typed.error,\n ...(typed.code ? { errorCode: typed.code } : {}),\n ...(typed.recoverable ? { recoverable: typed.recoverable } : {}),\n },\n },\n },\n } as ChatModelRunResult;\n }\n if (typed.type === \"done\") {\n return {\n content: [...content],\n status:\n typed.reason === \"error\"\n ? { type: \"incomplete\", reason: \"error\" }\n : { type: \"complete\", reason: \"stop\" },\n } as ChatModelRunResult;\n }\n return null;\n}\n\nfunction assistantMessageText(message: {\n content?: readonly { type: string; text?: string }[];\n}): string {\n return (message.content ?? [])\n .filter(\n (part): part is { type: string; text: string } => part.type === \"text\",\n )\n .map((part) => part.text)\n .join(\"\\n\");\n}\n\nfunction assistantMessagesToRuntimeMessages(\n messages: readonly {\n role: string;\n content?: readonly { type: string; text?: string; image?: string }[];\n }[],\n): AgentChatRuntimeMessage[] {\n return messages\n .filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n )\n .map((message, index) => {\n const content: AgentChatRuntimeKnownContentPart[] = [];\n for (const part of message.content ?? []) {\n if (part.type === \"text\" && typeof part.text === \"string\") {\n content.push({ type: \"text\", text: part.text });\n } else if (part.type === \"image\" && typeof part.image === \"string\") {\n content.push({ type: \"image\", data: part.image });\n }\n }\n return {\n id: `assistant-ui-${index}`,\n role: message.role as \"user\" | \"assistant\",\n content,\n };\n });\n}\n\nfunction latestUserPrompt(\n messages: readonly {\n role: string;\n content?: readonly { type: string; text?: string }[];\n }[],\n): string {\n for (let i = messages.length - 1; i >= 0; i--) {\n const message = messages[i];\n if (message.role !== \"user\") continue;\n return assistantMessageText(message);\n }\n return \"\";\n}\n\nexport function createAgentChatRuntimeAdapter(\n runtime: AgentChatRuntime,\n options: CreateAgentChatRuntimeAdapterOptions = {},\n): ChatModelAdapter {\n let sessionPromise: Promise<AgentChatRuntimeSession> | null = null;\n const getSession = () => {\n sessionPromise ??= Promise.resolve(\n runtime.createSession({\n id: options.sessionId ?? options.threadId,\n threadId: options.threadId,\n metadata: options.metadata,\n }),\n );\n return sessionPromise;\n };\n\n return {\n async *run({ messages, abortSignal }) {\n const adapterMessages = messages as readonly {\n role: string;\n content?: readonly { type: string; text?: string; image?: string }[];\n }[];\n const session = await getSession();\n const prompt = latestUserPrompt(adapterMessages);\n const turn = await session.startTurn({\n prompt,\n messages: assistantMessagesToRuntimeMessages(adapterMessages),\n model: options.modelRef?.current,\n reasoningEffort: options.effortRef?.current,\n abortSignal,\n metadata: options.metadata,\n });\n const content: ContentPart[] = [];\n try {\n for await (const event of turn.events) {\n const result = applyRuntimeEventToContent(event, content);\n if (result) {\n const metadata = (result.metadata ?? {}) as Record<string, unknown>;\n const custom =\n metadata.custom && typeof metadata.custom === \"object\"\n ? (metadata.custom as Record<string, unknown>)\n : {};\n yield {\n ...result,\n metadata: {\n ...metadata,\n custom: {\n ...custom,\n runtimeId: runtime.id,\n ...(turn.runId ? { runId: turn.runId } : {}),\n },\n },\n } as ChatModelRunResult;\n }\n }\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n await turn.cancel?.({ reason: \"abort\" });\n return;\n }\n throw error;\n }\n },\n };\n}\n"]}
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/client/chat/runtime.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EACL,0BAA0B,GAG3B,MAAM,2BAA2B,CAAC;AA8lBnC,MAAM,4BAA4B,GAAiC;IACjE,QAAQ,EAAE;QACR,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,IAAI;QACb,iBAAiB,EAAE,IAAI;QACvB,WAAW,EAAE,IAAI;KAClB;IACD,KAAK,EAAE;QACL,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,IAAI;QACf,eAAe,EAAE,IAAI;QACrB,OAAO,EAAE,IAAI;KACd;IACD,QAAQ,EAAE;QACR,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,IAAI;QACb,UAAU,EAAE,IAAI;KACjB;IACD,YAAY,EAAE;QACZ,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,IAAI;KACrB;IACD,MAAM,EAAE;QACN,UAAU,EAAE,IAAI;QAChB,eAAe,EAAE,IAAI;KACtB;IACD,SAAS,EAAE;QACT,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,IAA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,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;oBACtC,MAAM,MAAM,GAAG,0BAA0B,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;oBAC1D,IAAI,MAAM,EAAE,CAAC;wBACX,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE,CAA4B,CAAC;wBACpE,MAAM,MAAM,GACV,QAAQ,CAAC,MAAM,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,QAAQ;4BACpD,CAAC,CAAE,QAAQ,CAAC,MAAkC;4BAC9C,CAAC,CAAC,EAAE,CAAC;wBACT,MAAM;4BACJ,GAAG,MAAM;4BACT,QAAQ,EAAE;gCACR,GAAG,QAAQ;gCACX,MAAM,EAAE;oCACN,GAAG,MAAM;oCACT,SAAS,EAAE,OAAO,CAAC,EAAE;oCACrB,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iCAC7C;6BACF;yBACoB,CAAC;oBAC1B,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;oBAC1D,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;oBACzC,OAAO;gBACT,CAAC;gBACD,MAAM,KAAK,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import type { ChatModelAdapter, ChatModelRunResult } from \"@assistant-ui/react\";\nimport type { AgentMcpAppPayload } from \"../../mcp-client/app-result.js\";\nimport type { ActionChatUIConfig } from \"../../action-ui.js\";\nimport type { ReasoningEffort } from \"../../shared/reasoning-effort.js\";\nimport { agentNativePath } from \"../api-path.js\";\nimport { formatChatErrorText, normalizeChatError } from \"../error-format.js\";\nimport {\n settleInterruptedToolCalls,\n type ContentPart,\n type SSEEvent,\n} from \"../sse-event-processor.js\";\n\nexport type AgentChatRuntimeId = string;\nexport type AgentChatRuntimeSessionId = string;\nexport type AgentChatRuntimeTurnId = string;\nexport type AgentChatRuntimeMessageId = string;\nexport type AgentChatRuntimeToolCallId = string;\nexport type AgentChatRuntimeMetadata = Record<string, unknown>;\nexport type AgentChatRuntimeAwaitable<T> = T | Promise<T>;\n\nexport type AgentChatRuntimeKind =\n | \"agent-native\"\n | \"external-agent\"\n | \"code-agent\"\n | (string & {});\n\nexport type AgentChatRuntimeRole = \"system\" | \"user\" | \"assistant\" | \"tool\";\n\nexport interface AgentChatRuntimeContentPartBase<\n TType extends string = string,\n> {\n readonly type: TType;\n readonly id?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeTextPart extends AgentChatRuntimeContentPartBase<\"text\"> {\n readonly text: string;\n}\n\nexport interface AgentChatRuntimeReasoningPart extends AgentChatRuntimeContentPartBase<\"reasoning\"> {\n readonly text: string;\n readonly signature?: string;\n}\n\nexport interface AgentChatRuntimeImagePart extends AgentChatRuntimeContentPartBase<\"image\"> {\n readonly data?: string;\n readonly url?: string;\n readonly mediaType?: string;\n readonly alt?: string;\n}\n\nexport interface AgentChatRuntimeFilePart extends AgentChatRuntimeContentPartBase<\"file\"> {\n readonly data?: string;\n readonly url?: string;\n readonly mediaType?: string;\n readonly filename?: string;\n}\n\nexport interface AgentChatRuntimeToolCallPart extends AgentChatRuntimeContentPartBase<\"tool-call\"> {\n readonly toolCallId: AgentChatRuntimeToolCallId;\n readonly toolName: string;\n readonly input?: unknown;\n readonly inputText?: string;\n}\n\nexport interface AgentChatRuntimeToolResultPart extends AgentChatRuntimeContentPartBase<\"tool-result\"> {\n readonly toolCallId: AgentChatRuntimeToolCallId;\n readonly toolName?: string;\n readonly result?: unknown;\n readonly resultText?: string;\n readonly isError?: boolean;\n readonly mcpApp?: AgentMcpAppPayload;\n readonly chatUI?: ActionChatUIConfig;\n}\n\nexport interface AgentChatRuntimeDataPart extends AgentChatRuntimeContentPartBase<\"data\"> {\n readonly data: unknown;\n readonly mediaType?: string;\n readonly title?: string;\n}\n\nexport interface AgentChatRuntimeCustomContentPart extends AgentChatRuntimeContentPartBase {\n readonly [key: string]: unknown;\n}\n\nexport type AgentChatRuntimeKnownContentPart =\n | AgentChatRuntimeTextPart\n | AgentChatRuntimeReasoningPart\n | AgentChatRuntimeImagePart\n | AgentChatRuntimeFilePart\n | AgentChatRuntimeToolCallPart\n | AgentChatRuntimeToolResultPart\n | AgentChatRuntimeDataPart;\n\nexport type AgentChatRuntimeContentPart<\n TCustomPart extends AgentChatRuntimeCustomContentPart = never,\n> = AgentChatRuntimeKnownContentPart | TCustomPart;\n\nexport interface AgentChatRuntimeMessage<\n TContentPart extends AgentChatRuntimeContentPartBase =\n AgentChatRuntimeKnownContentPart,\n> {\n readonly id: AgentChatRuntimeMessageId;\n readonly role: AgentChatRuntimeRole;\n readonly content: readonly TContentPart[];\n readonly createdAt?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeAttachment {\n readonly id?: string;\n readonly name: string;\n readonly mediaType?: string;\n readonly data?: string;\n readonly url?: string;\n readonly text?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeToolDefinition {\n readonly name: string;\n readonly description?: string;\n readonly inputSchema?: Record<string, unknown>;\n readonly readOnly?: boolean;\n readonly destructive?: boolean;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeToolCall {\n readonly id: AgentChatRuntimeToolCallId;\n readonly name: string;\n readonly input?: unknown;\n readonly inputText?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport type AgentChatRuntimeToolStatus =\n | \"pending\"\n | \"running\"\n | \"completed\"\n | \"failed\"\n | \"cancelled\";\n\nexport interface AgentChatRuntimeUsage {\n readonly inputTokens?: number;\n readonly outputTokens?: number;\n readonly totalTokens?: number;\n readonly reasoningTokens?: number;\n readonly cacheReadTokens?: number;\n readonly cacheWriteTokens?: number;\n readonly costCents?: number;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeMessageCapabilities {\n readonly streaming: boolean;\n readonly history?: boolean;\n readonly structuredContent?: boolean;\n readonly multimodal?: boolean;\n readonly attachments?: boolean;\n}\n\nexport interface AgentChatRuntimeToolCapabilities {\n readonly events: boolean;\n readonly hostTools?: boolean;\n readonly inputStreaming?: boolean;\n readonly resultStreaming?: boolean;\n readonly approvals?: boolean;\n readonly mcpApps?: boolean;\n}\n\nexport interface AgentChatRuntimeSessionCapabilities {\n readonly create: boolean;\n readonly restore?: boolean;\n readonly list?: boolean;\n readonly fork?: boolean;\n readonly detach?: boolean;\n readonly persistent?: boolean;\n}\n\nexport interface AgentChatRuntimeCancellationCapabilities {\n readonly abortSignal?: boolean;\n readonly explicitCancel?: boolean;\n readonly interrupt?: boolean;\n}\n\nexport interface AgentChatRuntimeModelCapabilities {\n readonly selectable?: boolean;\n readonly reasoningEffort?: boolean;\n readonly temperature?: boolean;\n readonly providerOptions?: boolean;\n}\n\nexport interface AgentChatRuntimeArtifactCapabilities {\n readonly files?: boolean;\n readonly links?: boolean;\n readonly patches?: boolean;\n readonly progress?: boolean;\n}\n\nexport interface AgentChatRuntimeCapabilities {\n readonly messages: AgentChatRuntimeMessageCapabilities;\n readonly tools?: AgentChatRuntimeToolCapabilities;\n readonly sessions?: AgentChatRuntimeSessionCapabilities;\n readonly cancellation?: AgentChatRuntimeCancellationCapabilities;\n readonly models?: AgentChatRuntimeModelCapabilities;\n readonly artifacts?: AgentChatRuntimeArtifactCapabilities;\n readonly custom?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeCreateSessionInput {\n readonly id?: AgentChatRuntimeSessionId;\n readonly threadId?: string;\n readonly title?: string;\n readonly messages?: readonly AgentChatRuntimeMessage[];\n readonly resumeState?: unknown;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport interface AgentChatRuntimeListSessionsInput {\n readonly threadId?: string;\n readonly limit?: number;\n readonly cursor?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport type AgentChatRuntimeSessionStatus =\n | \"idle\"\n | \"running\"\n | \"waiting\"\n | \"cancelled\"\n | \"completed\"\n | \"error\";\n\nexport interface AgentChatRuntimeSessionSummary {\n readonly id: AgentChatRuntimeSessionId;\n readonly runtimeId: AgentChatRuntimeId;\n readonly threadId?: string;\n readonly title?: string;\n readonly status?: AgentChatRuntimeSessionStatus;\n readonly createdAt?: string;\n readonly updatedAt?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeSessionSnapshot extends AgentChatRuntimeSessionSummary {\n readonly messages?: readonly AgentChatRuntimeMessage[];\n readonly resumeState?: unknown;\n}\n\nexport interface AgentChatRuntimeTurnInput {\n readonly prompt?: string;\n readonly messages?: readonly AgentChatRuntimeMessage[];\n readonly attachments?: readonly AgentChatRuntimeAttachment[];\n readonly tools?: readonly AgentChatRuntimeToolDefinition[];\n readonly model?: string;\n readonly reasoningEffort?: ReasoningEffort;\n readonly temperature?: number;\n readonly providerOptions?: Record<string, unknown>;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport interface AgentChatRuntimeApprovalResponse {\n readonly id: string;\n readonly approved: boolean;\n readonly message?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeContinueInput {\n readonly turnId?: AgentChatRuntimeTurnId;\n readonly prompt?: string;\n readonly approval?: AgentChatRuntimeApprovalResponse;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport interface AgentChatRuntimeCancelInput {\n readonly sessionId?: AgentChatRuntimeSessionId;\n readonly turnId?: AgentChatRuntimeTurnId;\n readonly runId?: string;\n readonly reason?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport type AgentChatRuntimeCancelStatus =\n | \"cancelled\"\n | \"not-found\"\n | \"already-finished\"\n | \"unsupported\";\n\nexport interface AgentChatRuntimeCancelResult {\n readonly status: AgentChatRuntimeCancelStatus;\n readonly message?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeEventBase<TType extends string = string> {\n readonly type: TType;\n readonly id?: string;\n readonly sessionId?: AgentChatRuntimeSessionId;\n readonly turnId?: AgentChatRuntimeTurnId;\n readonly timestamp?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nexport interface AgentChatRuntimeMessageStartEvent extends AgentChatRuntimeEventBase<\"message-start\"> {\n readonly message: AgentChatRuntimeMessage;\n}\n\nexport type AgentChatRuntimeMessageDelta =\n | {\n readonly type: \"text\";\n readonly text: string;\n readonly partId?: string;\n }\n | {\n readonly type: \"reasoning\";\n readonly text: string;\n readonly partId?: string;\n readonly signature?: string;\n }\n | {\n readonly type: \"data\";\n readonly data: unknown;\n readonly partId?: string;\n readonly mediaType?: string;\n };\n\nexport interface AgentChatRuntimeMessageDeltaEvent extends AgentChatRuntimeEventBase<\"message-delta\"> {\n readonly messageId: AgentChatRuntimeMessageId;\n readonly delta: AgentChatRuntimeMessageDelta;\n}\n\nexport interface AgentChatRuntimeMessageDoneEvent extends AgentChatRuntimeEventBase<\"message-done\"> {\n readonly message: AgentChatRuntimeMessage;\n}\n\nexport interface AgentChatRuntimeToolStartEvent extends AgentChatRuntimeEventBase<\"tool-start\"> {\n readonly toolCall: AgentChatRuntimeToolCall;\n}\n\nexport interface AgentChatRuntimeToolDeltaEvent extends AgentChatRuntimeEventBase<\"tool-delta\"> {\n readonly toolCallId: AgentChatRuntimeToolCallId;\n readonly toolName?: string;\n readonly inputTextDelta?: string;\n readonly resultTextDelta?: string;\n}\n\nexport interface AgentChatRuntimeToolDoneEvent extends AgentChatRuntimeEventBase<\"tool-done\"> {\n readonly toolCallId: AgentChatRuntimeToolCallId;\n readonly toolName: string;\n readonly status: AgentChatRuntimeToolStatus;\n readonly result?: unknown;\n readonly resultText?: string;\n readonly error?: string;\n readonly mcpApp?: AgentMcpAppPayload;\n readonly chatUI?: ActionChatUIConfig;\n}\n\nexport interface AgentChatRuntimeApprovalRequestEvent extends AgentChatRuntimeEventBase<\"approval-request\"> {\n readonly approvalId: string;\n readonly toolCallId?: AgentChatRuntimeToolCallId;\n readonly toolName?: string;\n readonly message: string;\n readonly input?: unknown;\n}\n\nexport interface AgentChatRuntimeApprovalResolvedEvent extends AgentChatRuntimeEventBase<\"approval-resolved\"> {\n readonly approvalId: string;\n readonly approved: boolean;\n readonly message?: string;\n}\n\nexport interface AgentChatRuntimeStatusEvent extends AgentChatRuntimeEventBase<\"status\"> {\n readonly level?: \"info\" | \"warning\" | \"error\";\n readonly message: string;\n readonly code?: string;\n}\n\nexport interface AgentChatRuntimeArtifactEvent extends AgentChatRuntimeEventBase<\"artifact\"> {\n readonly artifact: {\n readonly id?: string;\n readonly kind: string;\n readonly title?: string;\n readonly url?: string;\n readonly path?: string;\n readonly data?: unknown;\n readonly metadata?: AgentChatRuntimeMetadata;\n };\n}\n\nexport interface AgentChatRuntimeFileEvent extends AgentChatRuntimeEventBase<\"file\"> {\n readonly path: string;\n readonly operation?: \"create\" | \"update\" | \"delete\" | \"rename\" | \"unknown\";\n readonly summary?: string;\n}\n\nexport interface AgentChatRuntimeUsageEvent extends AgentChatRuntimeEventBase<\"usage\"> {\n readonly usage: AgentChatRuntimeUsage;\n}\n\nexport interface AgentChatRuntimeErrorEvent extends AgentChatRuntimeEventBase<\"error\"> {\n readonly error: string;\n readonly code?: string;\n readonly recoverable?: boolean;\n readonly cause?: unknown;\n}\n\nexport type AgentChatRuntimeDoneReason =\n | \"complete\"\n | \"cancelled\"\n | \"error\"\n | \"interrupted\"\n | \"length\"\n | \"tool-use\"\n | (string & {});\n\nexport interface AgentChatRuntimeDoneEvent extends AgentChatRuntimeEventBase<\"done\"> {\n readonly reason?: AgentChatRuntimeDoneReason;\n}\n\nexport interface AgentChatRuntimeCustomEvent extends AgentChatRuntimeEventBase {\n readonly [key: string]: unknown;\n}\n\nexport type AgentChatRuntimeKnownEvent =\n | AgentChatRuntimeMessageStartEvent\n | AgentChatRuntimeMessageDeltaEvent\n | AgentChatRuntimeMessageDoneEvent\n | AgentChatRuntimeToolStartEvent\n | AgentChatRuntimeToolDeltaEvent\n | AgentChatRuntimeToolDoneEvent\n | AgentChatRuntimeApprovalRequestEvent\n | AgentChatRuntimeApprovalResolvedEvent\n | AgentChatRuntimeStatusEvent\n | AgentChatRuntimeArtifactEvent\n | AgentChatRuntimeFileEvent\n | AgentChatRuntimeUsageEvent\n | AgentChatRuntimeErrorEvent\n | AgentChatRuntimeDoneEvent;\n\nexport type AgentChatRuntimeEvent<\n TCustomEvent extends AgentChatRuntimeCustomEvent = never,\n> = AgentChatRuntimeKnownEvent | TCustomEvent;\n\nexport interface AgentChatRuntimeTurn<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n> {\n readonly id?: AgentChatRuntimeTurnId;\n readonly sessionId: AgentChatRuntimeSessionId;\n readonly runId?: string;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly events: AsyncIterable<TEvent>;\n cancel?(\n input?: AgentChatRuntimeCancelInput,\n ): Promise<AgentChatRuntimeCancelResult>;\n}\n\nexport interface AgentChatRuntimeSendMessageInput extends AgentChatRuntimeTurnInput {\n readonly sessionId?: AgentChatRuntimeSessionId;\n}\n\nexport interface AgentChatRuntimeSubscribeInput {\n readonly sessionId?: AgentChatRuntimeSessionId;\n readonly turnId?: AgentChatRuntimeTurnId;\n readonly runId?: string;\n readonly after?: number;\n readonly metadata?: AgentChatRuntimeMetadata;\n readonly abortSignal?: AbortSignal;\n}\n\nexport interface AgentChatRuntimeResumeInput extends AgentChatRuntimeSubscribeInput {\n readonly prompt?: string;\n}\n\nexport interface AgentChatRuntimeSession<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n> {\n readonly id: AgentChatRuntimeSessionId;\n readonly runtimeId: AgentChatRuntimeId;\n readonly threadId?: string;\n readonly capabilities?: Partial<AgentChatRuntimeCapabilities>;\n sendMessage?(\n input: AgentChatRuntimeTurnInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n startTurn(\n input: AgentChatRuntimeTurnInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n continueTurn?(\n input?: AgentChatRuntimeContinueInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n cancelTurn?(\n input?: AgentChatRuntimeCancelInput,\n ): Promise<AgentChatRuntimeCancelResult>;\n snapshot?(): AgentChatRuntimeAwaitable<AgentChatRuntimeSessionSnapshot>;\n dispose?(): AgentChatRuntimeAwaitable<void>;\n}\n\nexport interface AgentChatRuntime<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n> {\n readonly id: AgentChatRuntimeId;\n readonly kind: AgentChatRuntimeKind;\n readonly label: string;\n readonly description?: string;\n readonly capabilities: AgentChatRuntimeCapabilities;\n createSession(\n input?: AgentChatRuntimeCreateSessionInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeSession<TEvent>>;\n restoreSession?(\n snapshot: AgentChatRuntimeSessionSnapshot,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeSession<TEvent>>;\n getSession?(input: {\n readonly sessionId: AgentChatRuntimeSessionId;\n readonly abortSignal?: AbortSignal;\n }): AgentChatRuntimeAwaitable<AgentChatRuntimeSession<TEvent> | null>;\n listSessions?(\n input?: AgentChatRuntimeListSessionsInput,\n ): AgentChatRuntimeAwaitable<readonly AgentChatRuntimeSessionSummary[]>;\n sendMessage?(\n input: AgentChatRuntimeSendMessageInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n subscribe?(\n input: AgentChatRuntimeSubscribeInput,\n ): AgentChatRuntimeAwaitable<AsyncIterable<TEvent>>;\n resume?(\n input: AgentChatRuntimeResumeInput,\n ): AgentChatRuntimeAwaitable<AgentChatRuntimeTurn<TEvent>>;\n cancel?(\n input: AgentChatRuntimeCancelInput,\n ): Promise<AgentChatRuntimeCancelResult>;\n}\n\ntype FetchLike = typeof fetch;\ntype HeadersFactory =\n | HeadersInit\n | ((input: {\n sessionId?: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n }) => HeadersInit | Promise<HeadersInit>);\n\nexport interface CreateHttpAgentChatRuntimeOptions<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n> {\n readonly id?: AgentChatRuntimeId;\n readonly kind?: AgentChatRuntimeKind;\n readonly label?: string;\n readonly description?: string;\n readonly endpoint:\n | string\n | ((input: {\n session: AgentChatRuntimeSessionSummary;\n turn: AgentChatRuntimeTurnInput;\n }) => string | URL);\n readonly method?: \"POST\" | \"PUT\";\n readonly headers?: HeadersFactory;\n readonly credentials?: RequestCredentials;\n readonly fetch?: FetchLike;\n readonly capabilities?: Partial<AgentChatRuntimeCapabilities>;\n readonly mapRequest?: (input: {\n session: AgentChatRuntimeSessionSummary;\n turn: AgentChatRuntimeTurnInput;\n turnId: AgentChatRuntimeTurnId;\n }) => unknown;\n readonly mapEvent?: (\n event: unknown,\n context: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n ) => TEvent | readonly TEvent[] | null;\n readonly cancelEndpoint?:\n | string\n | ((input: AgentChatRuntimeCancelInput) => string | URL | null);\n readonly resumeEndpoint?:\n | string\n | ((input: AgentChatRuntimeSubscribeInput) => string | URL | null);\n readonly listSessionsEndpoint?: string | URL;\n readonly getSessionEndpoint?:\n | string\n | ((input: { sessionId: AgentChatRuntimeSessionId }) => string | URL);\n}\n\nexport interface CreateAgentNativeChatRuntimeOptions {\n readonly id?: AgentChatRuntimeId;\n readonly label?: string;\n readonly description?: string;\n readonly apiUrl?: string;\n readonly headers?: HeadersFactory;\n readonly fetch?: FetchLike;\n readonly threadId?: string;\n readonly browserTabId?: string;\n readonly surface?: \"app\" | \"dev-frame\";\n readonly mode?: \"act\" | \"plan\";\n readonly model?: string;\n readonly engine?: string;\n readonly effort?: ReasoningEffort;\n readonly scope?: unknown;\n}\n\nexport interface CreateAgentChatRuntimeAdapterOptions {\n readonly sessionId?: AgentChatRuntimeSessionId;\n readonly threadId?: string;\n readonly modelRef?: { current: string | undefined };\n readonly effortRef?: { current: ReasoningEffort | undefined };\n readonly metadata?: AgentChatRuntimeMetadata;\n}\n\nconst DEFAULT_RUNTIME_CAPABILITIES: AgentChatRuntimeCapabilities = {\n messages: {\n streaming: true,\n history: true,\n structuredContent: true,\n attachments: true,\n },\n tools: {\n events: true,\n hostTools: true,\n resultStreaming: true,\n mcpApps: true,\n },\n sessions: {\n create: true,\n restore: true,\n persistent: true,\n },\n cancellation: {\n abortSignal: true,\n explicitCancel: true,\n },\n models: {\n selectable: true,\n reasoningEffort: true,\n },\n artifacts: {\n files: true,\n links: true,\n progress: true,\n },\n};\n\nfunction mergeCapabilities(\n overrides?: Partial<AgentChatRuntimeCapabilities>,\n): AgentChatRuntimeCapabilities {\n return {\n ...DEFAULT_RUNTIME_CAPABILITIES,\n ...overrides,\n messages: {\n ...DEFAULT_RUNTIME_CAPABILITIES.messages,\n ...overrides?.messages,\n },\n tools: {\n ...DEFAULT_RUNTIME_CAPABILITIES.tools,\n ...overrides?.tools,\n events:\n overrides?.tools?.events ?? DEFAULT_RUNTIME_CAPABILITIES.tools!.events,\n },\n sessions: {\n ...DEFAULT_RUNTIME_CAPABILITIES.sessions,\n ...overrides?.sessions,\n create:\n overrides?.sessions?.create ??\n DEFAULT_RUNTIME_CAPABILITIES.sessions!.create,\n },\n cancellation: {\n ...DEFAULT_RUNTIME_CAPABILITIES.cancellation,\n ...overrides?.cancellation,\n },\n models: { ...DEFAULT_RUNTIME_CAPABILITIES.models, ...overrides?.models },\n artifacts: {\n ...DEFAULT_RUNTIME_CAPABILITIES.artifacts,\n ...overrides?.artifacts,\n },\n };\n}\n\nfunction createRuntimeId(prefix: string): string {\n if (\n typeof crypto !== \"undefined\" &&\n typeof crypto.randomUUID === \"function\"\n ) {\n return `${prefix}-${crypto.randomUUID()}`;\n }\n return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`;\n}\n\nfunction createAbortController(signal?: AbortSignal): {\n controller: AbortController;\n cleanup: () => void;\n} {\n const controller = new AbortController();\n if (!signal) return { controller, cleanup: () => {} };\n if (signal.aborted) controller.abort();\n const abort = () => controller.abort();\n signal.addEventListener(\"abort\", abort, { once: true });\n return {\n controller,\n cleanup: () => signal.removeEventListener(\"abort\", abort),\n };\n}\n\nasync function resolveHeaders(\n headers: HeadersFactory | undefined,\n input: {\n sessionId?: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n): Promise<Headers> {\n const resolved =\n typeof headers === \"function\" ? await headers(input) : headers;\n return new Headers(resolved);\n}\n\nfunction normalizeEndpoint(value: string | URL): string {\n return typeof value === \"string\" ? value : value.toString();\n}\n\nfunction isRuntimeEvent(value: unknown): value is AgentChatRuntimeEventBase {\n return (\n !!value &&\n typeof value === \"object\" &&\n typeof (value as { type?: unknown }).type === \"string\"\n );\n}\n\nfunction parseJsonEvent(raw: string): unknown | null {\n const trimmed = raw.trim();\n if (!trimmed || trimmed === \"[DONE]\") return null;\n try {\n return JSON.parse(trimmed);\n } catch {\n return null;\n }\n}\n\nasync function* readJsonEventStream(\n body: ReadableStream<Uint8Array>,\n): AsyncGenerator<unknown> {\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n let pendingSseData: string[] = [];\n\n const flushSseData = function* (): Generator<unknown> {\n if (pendingSseData.length === 0) return;\n const parsed = parseJsonEvent(pendingSseData.join(\"\\n\"));\n pendingSseData = [];\n if (parsed) yield parsed;\n };\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(/\\r?\\n/);\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (line.startsWith(\"data:\")) {\n pendingSseData.push(line.slice(5).trimStart());\n continue;\n }\n if (line.trim() === \"\") {\n yield* flushSseData();\n continue;\n }\n const parsed = parseJsonEvent(line);\n if (parsed) yield parsed;\n }\n }\n\n if (buffer.trim()) {\n const parsed = parseJsonEvent(buffer);\n if (parsed) yield parsed;\n }\n yield* flushSseData();\n } finally {\n try {\n reader.releaseLock();\n } catch {\n // Some browser runtimes consider a cancelled stream locked for a tick.\n }\n }\n}\n\nfunction textResponseEvents(\n text: string,\n sessionId: AgentChatRuntimeSessionId,\n turnId?: AgentChatRuntimeTurnId,\n): AgentChatRuntimeKnownEvent[] {\n const message: AgentChatRuntimeMessage = {\n id: createRuntimeId(\"message\"),\n role: \"assistant\",\n content: [],\n };\n return [\n { type: \"message-start\", sessionId, turnId, message },\n ...(text\n ? [\n {\n type: \"message-delta\" as const,\n sessionId,\n turnId,\n messageId: message.id,\n delta: { type: \"text\" as const, text },\n },\n ]\n : []),\n { type: \"message-done\", sessionId, turnId, message },\n { type: \"done\", sessionId, turnId, reason: \"complete\" },\n ];\n}\n\nasync function* eventsFromJsonResponse(\n value: unknown,\n sessionId: AgentChatRuntimeSessionId,\n turnId?: AgentChatRuntimeTurnId,\n): AsyncGenerator<AgentChatRuntimeEvent> {\n if (Array.isArray(value)) {\n for (const item of value) {\n if (isRuntimeEvent(item)) yield item as AgentChatRuntimeEvent;\n }\n return;\n }\n if (!value || typeof value !== \"object\") return;\n const record = value as Record<string, unknown>;\n if (Array.isArray(record.events)) {\n for (const item of record.events) {\n if (isRuntimeEvent(item)) yield item as AgentChatRuntimeEvent;\n }\n return;\n }\n const text =\n typeof record.message === \"string\"\n ? record.message\n : typeof record.text === \"string\"\n ? record.text\n : \"\";\n if (text) {\n for (const event of textResponseEvents(text, sessionId, turnId)) {\n yield event;\n }\n }\n}\n\nfunction defaultMapHttpRuntimeEvent(\n event: unknown,\n _context?: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n): AgentChatRuntimeEvent | readonly AgentChatRuntimeEvent[] | null {\n if (!isRuntimeEvent(event)) return null;\n return event as AgentChatRuntimeEvent;\n}\n\nfunction normalizeMappedEvents<TEvent extends AgentChatRuntimeEventBase>(\n mapped: TEvent | readonly TEvent[] | null,\n): readonly TEvent[] {\n if (!mapped) return [];\n return Array.isArray(mapped)\n ? (mapped as readonly TEvent[])\n : [mapped as TEvent];\n}\n\nasync function* streamResponseEvents<TEvent extends AgentChatRuntimeEventBase>(\n response: Response,\n input: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n mapEvent: (\n event: unknown,\n context: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n ) => TEvent | readonly TEvent[] | null;\n },\n): AsyncGenerator<TEvent> {\n const context = {\n sessionId: input.sessionId,\n turnId: input.turnId,\n runId: input.runId,\n };\n const contentType = response.headers.get(\"content-type\") ?? \"\";\n if (response.body && !contentType.includes(\"application/json\")) {\n for await (const raw of readJsonEventStream(response.body)) {\n for (const event of normalizeMappedEvents(input.mapEvent(raw, context))) {\n yield event;\n }\n }\n return;\n }\n\n const json = await response.json().catch(() => null);\n for await (const event of eventsFromJsonResponse(\n json,\n input.sessionId,\n input.turnId,\n )) {\n for (const mapped of normalizeMappedEvents(\n input.mapEvent(event, context),\n )) {\n yield mapped;\n }\n }\n}\n\nfunction defaultHttpRuntimeRequest(input: {\n session: AgentChatRuntimeSessionSummary;\n turn: AgentChatRuntimeTurnInput;\n turnId: AgentChatRuntimeTurnId;\n}) {\n return {\n sessionId: input.session.id,\n threadId: input.session.threadId,\n turnId: input.turnId,\n prompt: input.turn.prompt,\n messages: input.turn.messages,\n attachments: input.turn.attachments,\n tools: input.turn.tools,\n model: input.turn.model,\n reasoningEffort: input.turn.reasoningEffort,\n temperature: input.turn.temperature,\n providerOptions: input.turn.providerOptions,\n metadata: input.turn.metadata,\n };\n}\n\nasync function readErrorText(response: Response): Promise<string> {\n const text = await response.text().catch(() => \"\");\n if (!text) return `HTTP ${response.status}`;\n try {\n const parsed = JSON.parse(text) as { error?: unknown; message?: unknown };\n if (typeof parsed.error === \"string\") return parsed.error;\n if (typeof parsed.message === \"string\") return parsed.message;\n } catch {\n // Keep raw text.\n }\n return text.slice(0, 500);\n}\n\nexport function createHttpAgentChatRuntime<\n TEvent extends AgentChatRuntimeEventBase = AgentChatRuntimeKnownEvent,\n>(\n options: CreateHttpAgentChatRuntimeOptions<TEvent>,\n): AgentChatRuntime<TEvent> {\n const fetchImpl = options.fetch ?? fetch;\n const capabilities = mergeCapabilities(options.capabilities);\n const runtimeId = options.id ?? \"external:http\";\n const mapEvent =\n options.mapEvent ??\n (defaultMapHttpRuntimeEvent as (\n event: unknown,\n context: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n runId?: string;\n },\n ) => TEvent | readonly TEvent[] | null);\n\n const createSessionObject = (\n input?: AgentChatRuntimeCreateSessionInput,\n ): AgentChatRuntimeSession<TEvent> => {\n const sessionId =\n input?.id ?? input?.threadId ?? createRuntimeId(\"session\");\n const summary: AgentChatRuntimeSessionSummary = {\n id: sessionId,\n runtimeId,\n threadId: input?.threadId,\n title: input?.title,\n status: \"idle\",\n createdAt: new Date().toISOString(),\n updatedAt: new Date().toISOString(),\n metadata: input?.metadata,\n };\n\n const startTurn = async (\n turn: AgentChatRuntimeTurnInput,\n ): Promise<AgentChatRuntimeTurn<TEvent>> => {\n const turnId = createRuntimeId(\"turn\");\n const { controller, cleanup } = createAbortController(turn.abortSignal);\n const endpoint =\n typeof options.endpoint === \"function\"\n ? options.endpoint({ session: summary, turn })\n : options.endpoint;\n const headers = await resolveHeaders(options.headers, {\n sessionId,\n turnId,\n });\n if (!headers.has(\"Content-Type\"))\n headers.set(\"Content-Type\", \"application/json\");\n const response = await fetchImpl(normalizeEndpoint(endpoint), {\n method: options.method ?? \"POST\",\n headers,\n credentials: options.credentials,\n body: JSON.stringify(\n options.mapRequest\n ? options.mapRequest({ session: summary, turn, turnId })\n : defaultHttpRuntimeRequest({ session: summary, turn, turnId }),\n ),\n signal: controller.signal,\n });\n if (!response.ok) {\n cleanup();\n throw new Error(await readErrorText(response));\n }\n\n const runId = response.headers.get(\"X-Run-Id\") ?? undefined;\n const events = (async function* () {\n try {\n yield* streamResponseEvents(response, {\n sessionId,\n turnId,\n runId,\n mapEvent,\n });\n } finally {\n cleanup();\n }\n })();\n\n return {\n id: turnId,\n sessionId,\n runId,\n events,\n cancel: async (cancelInput) => {\n controller.abort();\n if (!options.cancelEndpoint) return { status: \"cancelled\" };\n const endpoint =\n typeof options.cancelEndpoint === \"function\"\n ? options.cancelEndpoint({\n ...cancelInput,\n sessionId,\n turnId,\n runId,\n })\n : options.cancelEndpoint;\n if (!endpoint) return { status: \"unsupported\" };\n const cancelHeaders = await resolveHeaders(options.headers, {\n sessionId,\n turnId,\n });\n if (!cancelHeaders.has(\"Content-Type\")) {\n cancelHeaders.set(\"Content-Type\", \"application/json\");\n }\n const cancelResponse = await fetchImpl(normalizeEndpoint(endpoint), {\n method: \"POST\",\n headers: cancelHeaders,\n credentials: options.credentials,\n body: JSON.stringify({\n sessionId,\n turnId,\n runId,\n reason: cancelInput?.reason ?? \"user\",\n metadata: cancelInput?.metadata,\n }),\n signal: cancelInput?.abortSignal,\n });\n return cancelResponse.ok\n ? { status: \"cancelled\" }\n : {\n status: \"unsupported\",\n message: await readErrorText(cancelResponse),\n };\n },\n };\n };\n\n return {\n id: sessionId,\n runtimeId,\n threadId: input?.threadId,\n capabilities,\n sendMessage: startTurn,\n startTurn,\n snapshot: () => ({\n ...summary,\n status: \"idle\",\n updatedAt: new Date().toISOString(),\n messages: input?.messages,\n resumeState: input?.resumeState,\n }),\n dispose: () => undefined,\n };\n };\n\n const runtime: AgentChatRuntime<TEvent> = {\n id: runtimeId,\n kind: options.kind ?? \"external-agent\",\n label: options.label ?? \"External agent\",\n description: options.description,\n capabilities,\n createSession: createSessionObject,\n restoreSession: (snapshot) =>\n createSessionObject({\n id: snapshot.id,\n threadId: snapshot.threadId,\n title: snapshot.title,\n messages: snapshot.messages,\n resumeState: snapshot.resumeState,\n metadata: snapshot.metadata,\n }),\n sendMessage: async (input) => {\n const session = createSessionObject({\n id: input.sessionId,\n threadId: input.sessionId,\n metadata: input.metadata,\n });\n return session.startTurn(input);\n },\n subscribe: async (input) => {\n if (!options.resumeEndpoint) return (async function* () {})();\n const endpoint =\n typeof options.resumeEndpoint === \"function\"\n ? options.resumeEndpoint(input)\n : options.resumeEndpoint;\n if (!endpoint) return (async function* () {})();\n const headers = await resolveHeaders(options.headers, input);\n const response = await fetchImpl(normalizeEndpoint(endpoint), {\n headers,\n credentials: options.credentials,\n signal: input.abortSignal,\n });\n if (!response.ok) throw new Error(await readErrorText(response));\n return streamResponseEvents(response, {\n sessionId: input.sessionId ?? \"session\",\n turnId: input.turnId,\n runId: input.runId,\n mapEvent,\n });\n },\n resume: async (input) => {\n const sessionId = input.sessionId ?? createRuntimeId(\"session\");\n const events = runtime.subscribe\n ? await runtime.subscribe(input)\n : (async function* () {})();\n return {\n id: input.turnId,\n sessionId,\n runId: input.runId,\n events,\n };\n },\n cancel: async (input) => {\n if (!options.cancelEndpoint) return { status: \"unsupported\" };\n const endpoint =\n typeof options.cancelEndpoint === \"function\"\n ? options.cancelEndpoint(input)\n : options.cancelEndpoint;\n if (!endpoint) return { status: \"unsupported\" };\n const headers = await resolveHeaders(options.headers, input);\n if (!headers.has(\"Content-Type\"))\n headers.set(\"Content-Type\", \"application/json\");\n const response = await fetchImpl(normalizeEndpoint(endpoint), {\n method: \"POST\",\n headers,\n credentials: options.credentials,\n body: JSON.stringify(input),\n signal: input.abortSignal,\n });\n return response.ok\n ? { status: \"cancelled\" }\n : { status: \"unsupported\", message: await readErrorText(response) };\n },\n };\n\n return runtime;\n}\n\nfunction runtimeMessageText(message: AgentChatRuntimeMessage): string {\n return message.content\n .map((part) =>\n part.type === \"text\" || part.type === \"reasoning\" ? part.text : \"\",\n )\n .filter(Boolean)\n .join(\"\\n\");\n}\n\nfunction nativeHistoryFromMessages(\n messages: readonly AgentChatRuntimeMessage[] | undefined,\n currentPrompt: string,\n) {\n const history = (messages ?? [])\n .filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n )\n .map((message) => ({\n role: message.role as \"user\" | \"assistant\",\n content: runtimeMessageText(message),\n }))\n .filter((message) => message.content.trim());\n if (!currentPrompt.trim()) return history;\n const last = history[history.length - 1];\n return last?.role === \"user\" && last.content === currentPrompt\n ? history.slice(0, -1)\n : history;\n}\n\nfunction mapAgentNativeEvent(\n raw: unknown,\n input: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n messageId: string;\n text: { value: string; started: boolean };\n },\n): AgentChatRuntimeKnownEvent[] {\n if (!raw || typeof raw !== \"object\") return [];\n const ev = raw as SSEEvent;\n const base = {\n sessionId: input.sessionId,\n turnId: input.turnId,\n };\n if (ev.seq !== undefined) {\n (base as { metadata?: AgentChatRuntimeMetadata }).metadata = {\n seq: ev.seq,\n };\n }\n if (ev.type === \"text\") {\n const text = ev.text ?? \"\";\n const events: AgentChatRuntimeKnownEvent[] = [];\n if (!input.text.started) {\n input.text.started = true;\n events.push({\n type: \"message-start\",\n ...base,\n message: {\n id: input.messageId,\n role: \"assistant\",\n content: [],\n },\n });\n }\n input.text.value += text;\n events.push({\n type: \"message-delta\",\n ...base,\n messageId: input.messageId,\n delta: { type: \"text\", text },\n });\n return events;\n }\n if (ev.type === \"activity\") {\n return [\n {\n type: \"status\",\n ...base,\n message: ev.label ?? ev.tool ?? \"Working\",\n metadata: ev.tool ? { tool: ev.tool } : undefined,\n },\n ];\n }\n if (ev.type === \"tool_start\") {\n return [\n {\n type: \"tool-start\",\n ...base,\n toolCall: {\n id: ev.id ?? createRuntimeId(\"tool\"),\n name: ev.tool ?? \"unknown\",\n input: ev.input,\n inputText: ev.input ? JSON.stringify(ev.input) : undefined,\n },\n },\n ];\n }\n if (ev.type === \"tool_done\") {\n return [\n {\n type: \"tool-done\",\n ...base,\n toolCallId: ev.id ?? \"\",\n toolName: ev.tool ?? \"unknown\",\n status: ev.error ? \"failed\" : \"completed\",\n result: ev.result,\n resultText:\n typeof ev.result === \"string\"\n ? ev.result\n : ev.result !== undefined\n ? JSON.stringify(ev.result)\n : undefined,\n error: ev.error,\n mcpApp: ev.mcpApp,\n chatUI: ev.chatUI,\n },\n ];\n }\n if (ev.type === \"approval_required\") {\n return [\n {\n type: \"approval-request\",\n ...base,\n approvalId: ev.approvalKey ?? ev.id ?? createRuntimeId(\"approval\"),\n toolCallId: ev.id,\n toolName: ev.tool,\n message: ev.label ?? \"Approve this tool call?\",\n input: ev.input,\n },\n ];\n }\n if (ev.type === \"error\" || ev.type === \"missing_api_key\") {\n return [\n {\n type: \"error\",\n ...base,\n error: ev.error ?? \"Agent chat failed.\",\n code: ev.errorCode,\n recoverable: ev.recoverable,\n },\n { type: \"done\", ...base, reason: \"error\" },\n ];\n }\n if (ev.type === \"done\") {\n const message: AgentChatRuntimeMessage = {\n id: input.messageId,\n role: \"assistant\",\n content: input.text.value\n ? [{ type: \"text\", text: input.text.value }]\n : [],\n };\n return [\n ...(input.text.started\n ? [{ type: \"message-done\" as const, ...base, message }]\n : []),\n { type: \"done\", ...base, reason: \"complete\" },\n ];\n }\n return [];\n}\n\nexport function createAgentNativeChatRuntime(\n options: CreateAgentNativeChatRuntimeOptions = {},\n): AgentChatRuntime<AgentChatRuntimeKnownEvent> {\n const apiUrl = options.apiUrl ?? agentNativePath(\"/_agent-native/agent-chat\");\n const runtimeId = options.id ?? \"agent-native\";\n const fetchImpl = options.fetch ?? fetch;\n\n return createHttpAgentChatRuntime({\n id: runtimeId,\n kind: \"agent-native\",\n label: options.label ?? \"Agent Native\",\n description:\n options.description ?? \"Agent-Native's built-in chat transport.\",\n endpoint: apiUrl,\n fetch: fetchImpl,\n headers: async (input) => {\n const headers = await resolveHeaders(options.headers, input);\n headers.set(\"x-agent-native-surface\", options.surface ?? \"app\");\n return headers;\n },\n capabilities: DEFAULT_RUNTIME_CAPABILITIES,\n mapRequest: ({ session, turn, turnId }) => {\n const prompt =\n turn.prompt ??\n [...(turn.messages ?? [])]\n .reverse()\n .find((message) => message.role === \"user\")\n ?.content.map((part) => (part.type === \"text\" ? part.text : \"\"))\n .join(\"\\n\") ??\n \"\";\n return {\n message: prompt,\n displayMessage: prompt,\n history: nativeHistoryFromMessages(turn.messages, prompt),\n turnId,\n threadId: session.threadId ?? options.threadId,\n ...(options.mode ? { mode: options.mode } : {}),\n ...((turn.model ?? options.model)\n ? { model: turn.model ?? options.model }\n : {}),\n ...(options.engine ? { engine: options.engine } : {}),\n ...((turn.reasoningEffort ?? options.effort)\n ? { effort: turn.reasoningEffort ?? options.effort }\n : {}),\n ...(options.browserTabId ? { browserTabId: options.browserTabId } : {}),\n ...(options.scope ? { scope: options.scope } : {}),\n ...(turn.attachments?.length ? { attachments: turn.attachments } : {}),\n ...(turn.metadata ? { metadata: turn.metadata } : {}),\n };\n },\n mapEvent: (() => {\n const states = new Map<\n string,\n { messageId: string; text: { value: string; started: boolean } }\n >();\n return (\n event: unknown,\n context: {\n sessionId: AgentChatRuntimeSessionId;\n turnId?: AgentChatRuntimeTurnId;\n },\n ) => {\n const stateKey = context.turnId ?? context.sessionId;\n let state = states.get(stateKey);\n if (!state) {\n state = {\n messageId: createRuntimeId(\"message\"),\n text: { value: \"\", started: false },\n };\n states.set(stateKey, state);\n }\n const mapped = mapAgentNativeEvent(event, {\n sessionId: context.sessionId,\n turnId: context.turnId,\n messageId: state.messageId,\n text: state.text,\n });\n const type =\n event && typeof event === \"object\"\n ? (event as { type?: unknown }).type\n : undefined;\n if (type === \"done\" || type === \"error\" || type === \"missing_api_key\") {\n states.delete(stateKey);\n }\n return mapped;\n };\n })(),\n cancelEndpoint: (input) =>\n input.runId\n ? `${apiUrl}/runs/${encodeURIComponent(input.runId)}/abort`\n : null,\n resumeEndpoint: (input) =>\n input.runId\n ? `${apiUrl}/runs/${encodeURIComponent(input.runId)}/events?after=${input.after ?? 0}`\n : null,\n });\n}\n\nfunction toContentPartInput(value: unknown): Record<string, string> {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return {};\n const out: Record<string, string> = {};\n for (const [key, item] of Object.entries(value)) {\n out[key] = typeof item === \"string\" ? item : JSON.stringify(item);\n }\n return out;\n}\n\nfunction toolResultText(value: unknown): string {\n if (typeof value === \"string\") return value;\n if (value === undefined) return \"\";\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction applyRuntimeEventToContent(\n event: AgentChatRuntimeEventBase,\n content: ContentPart[],\n): ChatModelRunResult | null {\n const typed = event as AgentChatRuntimeKnownEvent;\n if (typed.type === \"message-start\") {\n for (const part of typed.message.content) {\n if (part.type === \"text\" && part.text) {\n content.push({ type: \"text\", text: part.text });\n }\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"message-delta\") {\n if (typed.delta.type === \"text\") {\n const last = content[content.length - 1];\n if (last?.type === \"text\") {\n last.text += typed.delta.text;\n } else {\n content.push({ type: \"text\", text: typed.delta.text });\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n return null;\n }\n if (typed.type === \"message-done\") {\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"tool-start\") {\n content.push({\n type: \"tool-call\",\n toolCallId: typed.toolCall.id,\n toolName: typed.toolCall.name,\n argsText:\n typed.toolCall.inputText ?? JSON.stringify(typed.toolCall.input ?? {}),\n args: toContentPartInput(typed.toolCall.input),\n });\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"tool-delta\") {\n const part = [...content]\n .reverse()\n .find(\n (candidate): candidate is Extract<ContentPart, { type: \"tool-call\" }> =>\n candidate.type === \"tool-call\" &&\n candidate.toolCallId === typed.toolCallId,\n );\n if (!part) return null;\n if (typed.inputTextDelta) {\n part.argsText += typed.inputTextDelta;\n }\n if (typed.resultTextDelta) {\n part.result = `${part.result ?? \"\"}${typed.resultTextDelta}`;\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"tool-done\") {\n const part = [...content]\n .reverse()\n .find(\n (candidate): candidate is Extract<ContentPart, { type: \"tool-call\" }> =>\n candidate.type === \"tool-call\" &&\n candidate.toolCallId === typed.toolCallId,\n );\n if (part) {\n part.result =\n typed.error ?? typed.resultText ?? toolResultText(typed.result);\n if (typed.mcpApp) part.mcpApp = typed.mcpApp;\n if (typed.chatUI) part.chatUI = typed.chatUI;\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"approval-request\") {\n const part = [...content]\n .reverse()\n .find(\n (candidate): candidate is Extract<ContentPart, { type: \"tool-call\" }> =>\n candidate.type === \"tool-call\" &&\n (candidate.toolCallId === typed.toolCallId ||\n candidate.toolName === typed.toolName),\n );\n if (part) {\n part.approval = { approvalKey: typed.approvalId };\n } else {\n content.push({\n type: \"tool-call\",\n toolCallId: typed.toolCallId ?? typed.approvalId,\n toolName: typed.toolName ?? \"approval\",\n argsText: typed.input ? JSON.stringify(typed.input) : \"\",\n args: toContentPartInput(typed.input),\n approval: { approvalKey: typed.approvalId },\n });\n }\n return { content: [...content] } as ChatModelRunResult;\n }\n if (typed.type === \"error\") {\n const normalized = normalizeChatError(typed.error, typed.code);\n settleInterruptedToolCalls(content);\n content.push({\n type: \"text\",\n text: formatChatErrorText(typed.error, undefined, typed.code),\n });\n return {\n content: [...content],\n status: { type: \"incomplete\", reason: \"error\" },\n metadata: {\n custom: {\n runError: {\n message: normalized.message,\n ...(normalized.details ? { details: normalized.details } : {}),\n ...(typed.code ? { errorCode: typed.code } : {}),\n ...(typed.recoverable ? { recoverable: typed.recoverable } : {}),\n },\n },\n },\n } as ChatModelRunResult;\n }\n if (typed.type === \"done\") {\n return {\n content: [...content],\n status:\n typed.reason === \"error\"\n ? { type: \"incomplete\", reason: \"error\" }\n : { type: \"complete\", reason: \"stop\" },\n } as ChatModelRunResult;\n }\n return null;\n}\n\nfunction assistantMessageText(message: {\n content?: readonly { type: string; text?: string }[];\n}): string {\n return (message.content ?? [])\n .filter(\n (part): part is { type: string; text: string } => part.type === \"text\",\n )\n .map((part) => part.text)\n .join(\"\\n\");\n}\n\nfunction assistantMessagesToRuntimeMessages(\n messages: readonly {\n role: string;\n content?: readonly { type: string; text?: string; image?: string }[];\n }[],\n): AgentChatRuntimeMessage[] {\n return messages\n .filter(\n (message) => message.role === \"user\" || message.role === \"assistant\",\n )\n .map((message, index) => {\n const content: AgentChatRuntimeKnownContentPart[] = [];\n for (const part of message.content ?? []) {\n if (part.type === \"text\" && typeof part.text === \"string\") {\n content.push({ type: \"text\", text: part.text });\n } else if (part.type === \"image\" && typeof part.image === \"string\") {\n content.push({ type: \"image\", data: part.image });\n }\n }\n return {\n id: `assistant-ui-${index}`,\n role: message.role as \"user\" | \"assistant\",\n content,\n };\n });\n}\n\nfunction latestUserPrompt(\n messages: readonly {\n role: string;\n content?: readonly { type: string; text?: string }[];\n }[],\n): string {\n for (let i = messages.length - 1; i >= 0; i--) {\n const message = messages[i];\n if (message.role !== \"user\") continue;\n return assistantMessageText(message);\n }\n return \"\";\n}\n\nexport function createAgentChatRuntimeAdapter(\n runtime: AgentChatRuntime,\n options: CreateAgentChatRuntimeAdapterOptions = {},\n): ChatModelAdapter {\n let sessionPromise: Promise<AgentChatRuntimeSession> | null = null;\n const getSession = () => {\n sessionPromise ??= Promise.resolve(\n runtime.createSession({\n id: options.sessionId ?? options.threadId,\n threadId: options.threadId,\n metadata: options.metadata,\n }),\n );\n return sessionPromise;\n };\n\n return {\n async *run({ messages, abortSignal }) {\n const adapterMessages = messages as readonly {\n role: string;\n content?: readonly { type: string; text?: string; image?: string }[];\n }[];\n const session = await getSession();\n const prompt = latestUserPrompt(adapterMessages);\n const turn = await session.startTurn({\n prompt,\n messages: assistantMessagesToRuntimeMessages(adapterMessages),\n model: options.modelRef?.current,\n reasoningEffort: options.effortRef?.current,\n abortSignal,\n metadata: options.metadata,\n });\n const content: ContentPart[] = [];\n try {\n for await (const event of turn.events) {\n const result = applyRuntimeEventToContent(event, content);\n if (result) {\n const metadata = (result.metadata ?? {}) as Record<string, unknown>;\n const custom =\n metadata.custom && typeof metadata.custom === \"object\"\n ? (metadata.custom as Record<string, unknown>)\n : {};\n yield {\n ...result,\n metadata: {\n ...metadata,\n custom: {\n ...custom,\n runtimeId: runtime.id,\n ...(turn.runId ? { runId: turn.runId } : {}),\n },\n },\n } as ChatModelRunResult;\n }\n }\n } catch (error) {\n if (error instanceof Error && error.name === \"AbortError\") {\n await turn.cancel?.({ reason: \"abort\" });\n return;\n }\n throw error;\n }\n },\n };\n}\n"]}
@@ -18,5 +18,5 @@ export interface NormalizedChatError {
18
18
  message: string;
19
19
  details?: string;
20
20
  }
21
- export declare function normalizeChatError(errorMessage: string): NormalizedChatError;
21
+ export declare function normalizeChatError(errorMessage: string, errorCode?: string): NormalizedChatError;
22
22
  //# sourceMappingURL=error-format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error-format.d.ts","sourceRoot":"","sources":["../../src/client/error-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,qCAAqC,CAAC;AAK7E,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAY5D,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAqBR;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,mBAAmB,CA4C5E"}
1
+ {"version":3,"file":"error-format.d.ts","sourceRoot":"","sources":["../../src/client/error-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,qCAAqC,CAAC;AAK7E,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAY5D,wBAAgB,mBAAmB,CACjC,YAAY,EAAE,MAAM,EACpB,UAAU,CAAC,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAqBR;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAuBD,wBAAgB,kBAAkB,CAChC,YAAY,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,MAAM,GACjB,mBAAmB,CAoDrB"}
@@ -28,7 +28,7 @@ function isSafeUpgradeUrl(url) {
28
28
  }
29
29
  }
30
30
  export function formatChatErrorText(errorMessage, upgradeUrl, errorCode) {
31
- const normalized = normalizeChatError(errorMessage);
31
+ const normalized = normalizeChatError(errorMessage, errorCode);
32
32
  if (errorCode === "gateway_not_enabled" ||
33
33
  /space has not enabled the LLM gateway/i.test(normalized.message)) {
34
34
  return `Error: ${normalized.message}\n\n[Open Builder space settings](${BUILDER_SPACE_SETTINGS_URL})`;
@@ -45,10 +45,31 @@ export function formatChatErrorText(errorMessage, upgradeUrl, errorCode) {
45
45
  }
46
46
  return `Error: ${normalized.message}\n\n[Upgrade at builder.io](${upgradeUrl})`;
47
47
  }
48
- export function normalizeChatError(errorMessage) {
48
+ function normalizeErrorCode(errorCode) {
49
+ return String(errorCode ?? "")
50
+ .trim()
51
+ .toLowerCase();
52
+ }
53
+ function isProviderRateLimit(text, errorCode) {
54
+ const code = normalizeErrorCode(errorCode);
55
+ return (code === "provider_rate_limited" ||
56
+ code === "http_429" ||
57
+ code === "rate_limited" ||
58
+ code === "rate_limit_exceeded" ||
59
+ /^429 status code(?:\s*\(no body\))?$/i.test(text) ||
60
+ /\b(?:http\s*)?429\b.*\b(?:status|too many requests|rate[-_\s]?limit|no body)\b/i.test(text) ||
61
+ /\b(?:too many requests|rate[-_\s]?limit(?:ed| exceeded)?)\b/i.test(text));
62
+ }
63
+ export function normalizeChatError(errorMessage, errorCode) {
49
64
  const raw = String(errorMessage || "Unknown error");
50
65
  const looksHtml = /<html[\s>]|<body[\s>]|<head[\s>]/i.test(raw);
51
66
  const text = looksHtml ? htmlToText(raw) : raw.trim();
67
+ if (isProviderRateLimit(text, errorCode)) {
68
+ return {
69
+ message: "The model provider is rate-limiting this chat right now. Wait a moment, then retry.",
70
+ details: text,
71
+ };
72
+ }
52
73
  if (/^Gateway error \(no detail; raw event:/i.test(text)) {
53
74
  // The previous copy promised auto-recovery and suggested switching models,
54
75
  // but neither helps for this code: the server already retried once and
@@ -1 +1 @@
1
- {"version":3,"file":"error-format.js","sourceRoot":"","sources":["../../src/client/error-format.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,kCAAkC,CAAC;AAE7E,8EAA8E;AAC9E,6EAA6E;AAC7E,iFAAiF;AACjF,MAAM,CAAC,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAE5D,SAAS,gBAAgB,CAAC,GAAW;IACnC,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,MAAM,CAAC,QAAQ,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAC/C,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CACjC,YAAoB,EACpB,UAAm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Content":["/**\n * Append a Builder CTA markdown link to gateway errors that users can fix\n * outside the app. Used by both\n * chat SSE consumers (`sse-event-processor.ts` and `useProductionAgent.ts`)\n * to keep the copy in lockstep.\n *\n * `upgradeUrl` comes from the gateway response body and ends up interpolated\n * into markdown, so we validate it's a plain https URL with no characters\n * that would escape the `[...](url)` link target. Only `)` and whitespace\n * terminate the link target — `(`, `<`, `>` are fine inside it — so the\n * regex stays narrow; the gateway may emit URLs containing `(`\n * (e.g. `?ref=Acme%20(staging)`) and we don't want to reject them.\n */\nexport const BUILDER_SPACE_SETTINGS_URL = \"https://builder.io/account/space\";\n\n// Pseudo-href used to mark an in-app \"Start new chat\" CTA inside the markdown\n// error message. The chat renderer intercepts this href and renders a button\n// that dispatches the `agent-native:new-chat` CustomEvent instead of navigating.\nexport const NEW_CHAT_ACTION_HREF = \"agent-native:new-chat\";\n\nfunction isSafeUpgradeUrl(url: string): boolean {\n try {\n const parsed = new URL(url);\n if (parsed.protocol !== \"https:\") return false;\n return !/[\\s)]/.test(url);\n } catch {\n return false;\n }\n}\n\nexport function formatChatErrorText(\n errorMessage: string,\n upgradeUrl?: string,\n errorCode?: string,\n): string {\n const normalized = normalizeChatError(errorMessage);\n if (\n errorCode === \"gateway_not_enabled\" ||\n /space has not enabled the LLM gateway/i.test(normalized.message)\n ) {\n return `Error: ${normalized.message}\\n\\n[Open Builder space settings](${BUILDER_SPACE_SETTINGS_URL})`;\n }\n if (errorCode === \"builder_gateway_error\") {\n return `Error: ${normalized.message}\\n\\n[Start new chat](${NEW_CHAT_ACTION_HREF})`;\n }\n if (\n errorCode === \"context_length_exceeded\" ||\n errorCode === \"input_too_long\"\n ) {\n return `Error: ${normalized.message}\\n\\n[Start new chat](${NEW_CHAT_ACTION_HREF})`;\n }\n if (!upgradeUrl || !isSafeUpgradeUrl(upgradeUrl)) {\n return `Error: ${normalized.message}`;\n }\n return `Error: ${normalized.message}\\n\\n[Upgrade at builder.io](${upgradeUrl})`;\n}\n\nexport interface NormalizedChatError {\n message: string;\n details?: string;\n}\n\nexport function normalizeChatError(errorMessage: string): NormalizedChatError {\n const raw = String(errorMessage || \"Unknown error\");\n const looksHtml = /<html[\\s>]|<body[\\s>]|<head[\\s>]/i.test(raw);\n const text = looksHtml ? htmlToText(raw) : raw.trim();\n\n if (/^Gateway error \\(no detail; raw event:/i.test(text)) {\n // The previous copy promised auto-recovery and suggested switching models,\n // but neither helps for this code: the server already retried once and\n // the client deliberately skips auto-continuation\n // (see `builder_gateway_error` in sse-event-processor.ts). The error is\n // almost always upstream, so retrying the same conversation with a\n // different model lands on the same wall.\n return {\n message:\n \"The model gateway returned no error details and the chat couldn't recover. Wait a moment and retry, or start a new chat if it keeps happening.\",\n details: text,\n };\n }\n\n if (/inactivity timeout/i.test(text)) {\n return {\n message:\n \"The agent connection timed out before it could finish. You can continue from the partial work or retry.\",\n details: text,\n };\n }\n\n if (/Invalid request body:\\s*tools\\.\\d+\\.input_schema\\.type/i.test(text)) {\n return {\n message:\n \"A tool schema was invalid, so the model rejected the request before it started. The invalid tool can be skipped and the request retried.\",\n details: text,\n };\n }\n\n if (looksHtml) {\n return {\n message:\n text.slice(0, 240) || \"The provider returned an HTML error page.\",\n details: text,\n };\n }\n\n return { message: text };\n}\n\nfunction htmlToText(html: string): string {\n return html\n .replace(/<script[\\s\\S]*?<\\/script>/gi, \" \")\n .replace(/<style[\\s\\S]*?<\\/style>/gi, \" \")\n .replace(/<br\\s*\\/?>/gi, \"\\n\")\n .replace(/<\\/(p|div|h1|h2|h3|li|tr)>/gi, \"\\n\")\n .replace(/<[^>]+>/g, \" \")\n .replace(/&nbsp;/gi, \" \")\n .replace(/&lt;/gi, \"<\")\n .replace(/&gt;/gi, \">\")\n .replace(/&amp;/gi, \"&\")\n .replace(/&quot;/gi, '\"')\n .replace(/&#39;/gi, \"'\")\n .replace(/[ \\t]+/g, \" \")\n .replace(/\\n\\s+/g, \"\\n\")\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim();\n}\n"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AAS,EAAE,MAAM,CAAC;SAC1B,IAAI,EAAE,CAAC;AACZ,CAAC","sourcesContent":["/**\n * Append a Builder CTA markdown link to gateway errors that users can fix\n * outside the app. Used by both\n * chat SSE consumers (`sse-event-processor.ts` and `useProductionAgent.ts`)\n * to keep the copy in lockstep.\n *\n * `upgradeUrl` comes from the gateway response body and ends up interpolated\n * into markdown, so we validate it's a plain https URL with no characters\n * that would escape the `[...](url)` link target. Only `)` and whitespace\n * terminate the link target — `(`, `<`, `>` are fine inside it — so the\n * regex stays narrow; the gateway may emit URLs containing `(`\n * (e.g. `?ref=Acme%20(staging)`) and we don't want to reject them.\n */\nexport const BUILDER_SPACE_SETTINGS_URL = \"https://builder.io/account/space\";\n\n// Pseudo-href used to mark an in-app \"Start new chat\" CTA inside the markdown\n// error message. The chat renderer intercepts this href and renders a button\n// that dispatches the `agent-native:new-chat` CustomEvent instead of navigating.\nexport const NEW_CHAT_ACTION_HREF = \"agent-native:new-chat\";\n\nfunction isSafeUpgradeUrl(url: string): boolean {\n try {\n const parsed = new URL(url);\n if (parsed.protocol !== \"https:\") return false;\n return !/[\\s)]/.test(url);\n } catch {\n return false;\n }\n}\n\nexport function formatChatErrorText(\n errorMessage: string,\n upgradeUrl?: string,\n errorCode?: string,\n): string {\n const normalized = normalizeChatError(errorMessage, errorCode);\n if (\n errorCode === \"gateway_not_enabled\" ||\n /space has not enabled the LLM gateway/i.test(normalized.message)\n ) {\n return `Error: ${normalized.message}\\n\\n[Open Builder space settings](${BUILDER_SPACE_SETTINGS_URL})`;\n }\n if (errorCode === \"builder_gateway_error\") {\n return `Error: ${normalized.message}\\n\\n[Start new chat](${NEW_CHAT_ACTION_HREF})`;\n }\n if (\n errorCode === \"context_length_exceeded\" ||\n errorCode === \"input_too_long\"\n ) {\n return `Error: ${normalized.message}\\n\\n[Start new chat](${NEW_CHAT_ACTION_HREF})`;\n }\n if (!upgradeUrl || !isSafeUpgradeUrl(upgradeUrl)) {\n return `Error: ${normalized.message}`;\n }\n return `Error: ${normalized.message}\\n\\n[Upgrade at builder.io](${upgradeUrl})`;\n}\n\nexport interface NormalizedChatError {\n message: string;\n details?: string;\n}\n\nfunction normalizeErrorCode(errorCode?: string): string {\n return String(errorCode ?? \"\")\n .trim()\n .toLowerCase();\n}\n\nfunction isProviderRateLimit(text: string, errorCode?: string): boolean {\n const code = normalizeErrorCode(errorCode);\n return (\n code === \"provider_rate_limited\" ||\n code === \"http_429\" ||\n code === \"rate_limited\" ||\n code === \"rate_limit_exceeded\" ||\n /^429 status code(?:\\s*\\(no body\\))?$/i.test(text) ||\n /\\b(?:http\\s*)?429\\b.*\\b(?:status|too many requests|rate[-_\\s]?limit|no body)\\b/i.test(\n text,\n ) ||\n /\\b(?:too many requests|rate[-_\\s]?limit(?:ed| exceeded)?)\\b/i.test(text)\n );\n}\n\nexport function normalizeChatError(\n errorMessage: string,\n errorCode?: string,\n): NormalizedChatError {\n const raw = String(errorMessage || \"Unknown error\");\n const looksHtml = /<html[\\s>]|<body[\\s>]|<head[\\s>]/i.test(raw);\n const text = looksHtml ? htmlToText(raw) : raw.trim();\n\n if (isProviderRateLimit(text, errorCode)) {\n return {\n message:\n \"The model provider is rate-limiting this chat right now. Wait a moment, then retry.\",\n details: text,\n };\n }\n\n if (/^Gateway error \\(no detail; raw event:/i.test(text)) {\n // The previous copy promised auto-recovery and suggested switching models,\n // but neither helps for this code: the server already retried once and\n // the client deliberately skips auto-continuation\n // (see `builder_gateway_error` in sse-event-processor.ts). The error is\n // almost always upstream, so retrying the same conversation with a\n // different model lands on the same wall.\n return {\n message:\n \"The model gateway returned no error details and the chat couldn't recover. Wait a moment and retry, or start a new chat if it keeps happening.\",\n details: text,\n };\n }\n\n if (/inactivity timeout/i.test(text)) {\n return {\n message:\n \"The agent connection timed out before it could finish. You can continue from the partial work or retry.\",\n details: text,\n };\n }\n\n if (/Invalid request body:\\s*tools\\.\\d+\\.input_schema\\.type/i.test(text)) {\n return {\n message:\n \"A tool schema was invalid, so the model rejected the request before it started. The invalid tool can be skipped and the request retried.\",\n details: text,\n };\n }\n\n if (looksHtml) {\n return {\n message:\n text.slice(0, 240) || \"The provider returned an HTML error page.\",\n details: text,\n };\n }\n\n return { message: text };\n}\n\nfunction htmlToText(html: string): string {\n return html\n .replace(/<script[\\s\\S]*?<\\/script>/gi, \" \")\n .replace(/<style[\\s\\S]*?<\\/style>/gi, \" \")\n .replace(/<br\\s*\\/?>/gi, \"\\n\")\n .replace(/<\\/(p|div|h1|h2|h3|li|tr)>/gi, \"\\n\")\n .replace(/<[^>]+>/g, \" \")\n .replace(/&nbsp;/gi, \" \")\n .replace(/&lt;/gi, \"<\")\n .replace(/&gt;/gi, \">\")\n .replace(/&amp;/gi, \"&\")\n .replace(/&quot;/gi, '\"')\n .replace(/&#39;/gi, \"'\")\n .replace(/[ \\t]+/g, \" \")\n .replace(/\\n\\s+/g, \"\\n\")\n .replace(/\\n{3,}/g, \"\\n\\n\")\n .trim();\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"sse-event-processor.d.ts","sourceRoot":"","sources":["../../src/client/sse-event-processor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAK1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAItE,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,kBAAkB,C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U,CAAC,EAChC,OAAO,EAAE,WAAW,EAAE,EACtB,eAAe,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAClC,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,EAC7B,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GACpB,cAAc,CAAC,kBAAkB,CAAC,CAqIpC;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,OAAO,EAAE,WAAW,EAAE,EACtB,eAAe,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,EAClC,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,IAAI,GACzC,OAAO,CAAC,IAAI,CAAC,CA0Ff"}
@@ -109,6 +109,7 @@ function isAutoRecoverableError(ev, errMsg) {
109
109
  code === "request_too_large" ||
110
110
  code === "not_found_error" ||
111
111
  code === "model_not_found" ||
112
+ code === "provider_rate_limited" ||
112
113
  // `builder_gateway_error` is the no-detail fallback the Builder engine
113
114
  // emits when the gateway returns `{type:"stop",reason:"error"}` with no
114
115
  // explanation — almost always the upstream provider giving up (model
@@ -401,7 +402,7 @@ export function processEvent(ev, content, toolCallCounter, tabId) {
401
402
  const errMsg = LLM_MISSING_CREDENTIALS_MESSAGE;
402
403
  const errorCode = LLM_MISSING_CREDENTIALS_ERROR_CODE;
403
404
  const runError = {
404
- message: normalizeChatError(errMsg).message,
405
+ message: normalizeChatError(errMsg, errorCode).message,
405
406
  errorCode,
406
407
  };
407
408
  if (typeof window !== "undefined") {
@@ -483,7 +484,7 @@ export function processEvent(ev, content, toolCallCounter, tabId) {
483
484
  },
484
485
  };
485
486
  }
486
- const normalized = normalizeChatError(errMsg);
487
+ const normalized = normalizeChatError(errMsg, ev.errorCode);
487
488
  if (isMissingCredentialText(errMsg, ev.errorCode)) {
488
489
  if (typeof window !== "undefined") {
489
490
  window.dispatchEvent(new Event("agent-chat:missing-api-key"));