acpx 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{cli-DZjj5kij.js → cli-ChWsO-bb.js} +4 -4
- package/dist/{cli-DZjj5kij.js.map → cli-ChWsO-bb.js.map} +1 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +5 -5
- package/dist/{client-S8QicFBT.d.ts → client-D-4_aZf2.d.ts} +4 -2
- package/dist/client-D-4_aZf2.d.ts.map +1 -0
- package/dist/{flags-W3vEVSiS.js → flags-ceSqz2T6.js} +3 -3
- package/dist/{flags-W3vEVSiS.js.map → flags-ceSqz2T6.js.map} +1 -1
- package/dist/{flows-CLQYpPh7.js → flows-_KmnuUXd.js} +3 -3
- package/dist/{flows-CLQYpPh7.js.map → flows-_KmnuUXd.js.map} +1 -1
- package/dist/flows.d.ts +1 -1
- package/dist/flows.js +1 -1
- package/dist/perf-metrics-D0um6IR6.js.map +1 -1
- package/dist/{prompt-turn-CbSSNHjk.js → prompt-turn-CXMtXBl-.js} +10 -1
- package/dist/prompt-turn-CXMtXBl-.js.map +1 -0
- package/dist/runtime.d.ts +8 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +45 -4
- package/dist/runtime.js.map +1 -1
- package/dist/{session-BiBN0BvM.js → session-BtwAKtJ3.js} +2 -2
- package/dist/{session-BiBN0BvM.js.map → session-BtwAKtJ3.js.map} +1 -1
- package/dist/{types-Cgigsj1X.d.ts → types-yxf-gcOE.d.ts} +2 -1
- package/dist/{types-Cgigsj1X.d.ts.map → types-yxf-gcOE.d.ts.map} +1 -1
- package/package.json +2 -2
- package/dist/client-S8QicFBT.d.ts.map +0 -1
- package/dist/prompt-turn-CbSSNHjk.js.map +0 -1
package/dist/flows.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as PermissionMode, c as PromptInput, i as NonInteractivePermissionPolicy, n as AuthPolicy, r as McpServer$1 } from "./types-
|
|
1
|
+
import { a as PermissionMode, c as PromptInput, i as NonInteractivePermissionPolicy, n as AuthPolicy, r as McpServer$1 } from "./types-yxf-gcOE.js";
|
|
2
2
|
import { SetSessionConfigOptionResponse } from "@agentclientprotocol/sdk";
|
|
3
3
|
|
|
4
4
|
//#region src/runtime/engine/session-options.d.ts
|
package/dist/flows.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as flowRunsBaseDir, c as action, d as defineFlow, f as shell, i as FlowRunner, l as checkpoint, n as parseJsonObject, r as parseStrictJsonObject, s as acp, t as extractJsonObject, u as compute } from "./flows-
|
|
1
|
+
import { a as flowRunsBaseDir, c as action, d as defineFlow, f as shell, i as FlowRunner, l as checkpoint, n as parseJsonObject, r as parseStrictJsonObject, s as acp, t as extractJsonObject, u as compute } from "./flows-_KmnuUXd.js";
|
|
2
2
|
export { FlowRunner, acp, action, checkpoint, compute, defineFlow, extractJsonObject, flowRunsBaseDir, parseJsonObject, parseStrictJsonObject, shell };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perf-metrics-D0um6IR6.js","names":["asRecord","asRecord"],"sources":["../src/errors.ts","../src/types.ts","../src/acp/error-shapes.ts","../src/acp/error-normalization.ts","../src/prompt-content.ts","../src/acp/agent-session-id.ts","../src/session/runtime-session-id.ts","../src/perf-metrics.ts"],"sourcesContent":["import type { OutputErrorAcpPayload, OutputErrorCode, OutputErrorOrigin } from \"./types.js\";\n\ntype AcpxErrorOptions = ErrorOptions & {\n outputCode?: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n outputAlreadyEmitted?: boolean;\n};\n\nexport class AcpxOperationalError extends Error {\n readonly outputCode?: OutputErrorCode;\n readonly detailCode?: string;\n readonly origin?: OutputErrorOrigin;\n readonly retryable?: boolean;\n readonly acp?: OutputErrorAcpPayload;\n readonly outputAlreadyEmitted?: boolean;\n\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n this.outputCode = options?.outputCode;\n this.detailCode = options?.detailCode;\n this.origin = options?.origin;\n this.retryable = options?.retryable;\n this.acp = options?.acp;\n this.outputAlreadyEmitted = options?.outputAlreadyEmitted;\n }\n}\n\nexport class SessionNotFoundError extends AcpxOperationalError {\n readonly sessionId: string;\n\n constructor(sessionId: string) {\n super(`Session not found: ${sessionId}`);\n this.sessionId = sessionId;\n }\n}\n\nexport class SessionResolutionError extends AcpxOperationalError {}\n\nexport class AgentSpawnError extends AcpxOperationalError {\n readonly agentCommand: string;\n\n constructor(agentCommand: string, cause?: unknown) {\n super(`Failed to spawn agent command: ${agentCommand}`, {\n cause: cause instanceof Error ? cause : undefined,\n });\n this.agentCommand = agentCommand;\n }\n}\n\nexport class AgentStartupError extends AcpxOperationalError {\n readonly agentCommand: string;\n readonly exitCode: number | null;\n readonly signal: NodeJS.Signals | null;\n readonly stderrSummary?: string;\n\n constructor(params: {\n agentCommand: string;\n exitCode: number | null;\n signal: NodeJS.Signals | null;\n stderrSummary?: string;\n cause?: unknown;\n }) {\n const exitSummary = `exit=${params.exitCode ?? \"null\"}, signal=${params.signal ?? \"null\"}`;\n const stderrSuffix =\n typeof params.stderrSummary === \"string\" && params.stderrSummary.trim().length > 0\n ? `: ${params.stderrSummary.trim()}`\n : \"\";\n super(`ACP agent exited before initialize completed (${exitSummary})${stderrSuffix}`, {\n cause: params.cause instanceof Error ? params.cause : undefined,\n outputCode: \"RUNTIME\",\n detailCode: \"AGENT_STARTUP_FAILED\",\n origin: \"acp\",\n });\n this.agentCommand = params.agentCommand;\n this.exitCode = params.exitCode;\n this.signal = params.signal;\n this.stderrSummary = params.stderrSummary?.trim() || undefined;\n }\n}\n\nexport class AgentDisconnectedError extends AcpxOperationalError {\n readonly reason: string;\n readonly exitCode: number | null;\n readonly signal: NodeJS.Signals | null;\n\n constructor(\n reason: string,\n exitCode: number | null,\n signal: NodeJS.Signals | null,\n options?: AcpxErrorOptions,\n ) {\n super(\n `ACP agent disconnected during request (${reason}, exit=${exitCode ?? \"null\"}, signal=${signal ?? \"null\"})`,\n {\n outputCode: \"RUNTIME\",\n detailCode: \"AGENT_DISCONNECTED\",\n origin: \"acp\",\n ...options,\n },\n );\n this.reason = reason;\n this.exitCode = exitCode;\n this.signal = signal;\n }\n}\n\nexport class SessionResumeRequiredError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"SESSION_RESUME_REQUIRED\",\n origin: \"acp\",\n retryable: true,\n ...options,\n });\n }\n}\n\nexport class GeminiAcpStartupTimeoutError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"TIMEOUT\",\n detailCode: \"GEMINI_ACP_STARTUP_TIMEOUT\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class SessionModeReplayError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"SESSION_MODE_REPLAY_FAILED\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class SessionModelReplayError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"SESSION_MODEL_REPLAY_FAILED\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class ClaudeAcpSessionCreateTimeoutError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"TIMEOUT\",\n detailCode: \"CLAUDE_ACP_SESSION_CREATE_TIMEOUT\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class CopilotAcpUnsupportedError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"COPILOT_ACP_UNSUPPORTED\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class AuthPolicyError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"AUTH_REQUIRED\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class QueueConnectionError extends AcpxOperationalError {}\n\nexport class QueueProtocolError extends AcpxOperationalError {}\n\nexport class PermissionDeniedError extends AcpxOperationalError {}\n\nexport class PermissionPromptUnavailableError extends AcpxOperationalError {\n constructor() {\n super(\"Permission prompt unavailable in non-interactive mode\");\n }\n}\n","import type {\n AgentCapabilities,\n AnyMessage,\n McpServer,\n SessionNotification,\n SessionConfigOption,\n SetSessionConfigOptionResponse,\n StopReason,\n} from \"@agentclientprotocol/sdk\";\nexport type { McpServer, SessionNotification } from \"@agentclientprotocol/sdk\";\nimport type { PromptInput } from \"./prompt-content.js\";\n\nexport const EXIT_CODES = {\n SUCCESS: 0,\n ERROR: 1,\n USAGE: 2,\n TIMEOUT: 3,\n NO_SESSION: 4,\n PERMISSION_DENIED: 5,\n INTERRUPTED: 130,\n} as const;\n\nexport type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];\n\nexport const OUTPUT_FORMATS = [\"text\", \"json\", \"quiet\"] as const;\nexport type OutputFormat = (typeof OUTPUT_FORMATS)[number];\n\nexport const PERMISSION_MODES = [\"approve-all\", \"approve-reads\", \"deny-all\"] as const;\nexport type PermissionMode = (typeof PERMISSION_MODES)[number];\n\nexport const AUTH_POLICIES = [\"skip\", \"fail\"] as const;\nexport type AuthPolicy = (typeof AUTH_POLICIES)[number];\n\nexport const NON_INTERACTIVE_PERMISSION_POLICIES = [\"deny\", \"fail\"] as const;\nexport type NonInteractivePermissionPolicy = (typeof NON_INTERACTIVE_PERMISSION_POLICIES)[number];\n\nexport const SESSION_RESUME_POLICIES = [\"allow-new\", \"same-session-only\"] as const;\nexport type SessionResumePolicy = (typeof SESSION_RESUME_POLICIES)[number];\n\nexport const OUTPUT_STREAMS = [\"prompt\", \"control\"] as const;\nexport type OutputStream = (typeof OUTPUT_STREAMS)[number];\nexport type AcpJsonRpcMessage = AnyMessage;\nexport type AcpMessageDirection = \"outbound\" | \"inbound\";\n\nexport const OUTPUT_ERROR_CODES = [\n \"NO_SESSION\",\n \"TIMEOUT\",\n \"PERMISSION_DENIED\",\n \"PERMISSION_PROMPT_UNAVAILABLE\",\n \"RUNTIME\",\n \"USAGE\",\n] as const;\nexport type OutputErrorCode = (typeof OUTPUT_ERROR_CODES)[number];\n\nexport const OUTPUT_ERROR_ORIGINS = [\"cli\", \"runtime\", \"queue\", \"acp\"] as const;\nexport type OutputErrorOrigin = (typeof OUTPUT_ERROR_ORIGINS)[number];\n\nexport const QUEUE_ERROR_DETAIL_CODES = [\n \"QUEUE_OWNER_CLOSED\",\n \"QUEUE_OWNER_SHUTTING_DOWN\",\n \"QUEUE_OWNER_OVERLOADED\",\n \"QUEUE_OWNER_GENERATION_MISMATCH\",\n \"QUEUE_REQUEST_INVALID\",\n \"QUEUE_REQUEST_PAYLOAD_INVALID_JSON\",\n \"QUEUE_ACK_MISSING\",\n \"QUEUE_DISCONNECTED_BEFORE_ACK\",\n \"QUEUE_DISCONNECTED_BEFORE_COMPLETION\",\n \"QUEUE_PROTOCOL_INVALID_JSON\",\n \"QUEUE_PROTOCOL_MALFORMED_MESSAGE\",\n \"QUEUE_PROTOCOL_UNEXPECTED_RESPONSE\",\n \"QUEUE_NOT_ACCEPTING_REQUESTS\",\n \"QUEUE_CONTROL_REQUEST_FAILED\",\n \"QUEUE_RUNTIME_PROMPT_FAILED\",\n] as const;\nexport type QueueErrorDetailCode = (typeof QUEUE_ERROR_DETAIL_CODES)[number];\n\nexport type OutputErrorAcpPayload = {\n code: number;\n message: string;\n data?: unknown;\n};\n\nexport type PermissionStats = {\n requested: number;\n approved: number;\n denied: number;\n cancelled: number;\n};\n\nexport type ClientOperationMethod =\n | \"fs/read_text_file\"\n | \"fs/write_text_file\"\n | \"terminal/create\"\n | \"terminal/output\"\n | \"terminal/wait_for_exit\"\n | \"terminal/kill\"\n | \"terminal/release\";\n\nexport type ClientOperationStatus = \"running\" | \"completed\" | \"failed\";\n\nexport type ClientOperation = {\n method: ClientOperationMethod;\n status: ClientOperationStatus;\n summary: string;\n details?: string;\n timestamp: string;\n};\n\nexport type SessionEventLog = {\n active_path: string;\n segment_count: number;\n max_segment_bytes: number;\n max_segments: number;\n last_write_at?: string;\n last_write_error?: string | null;\n};\n\nexport type PerfMetricSummary = {\n count: number;\n totalMs: number;\n maxMs: number;\n};\n\nexport type PerfMetricsSnapshot = {\n counters: Record<string, number>;\n timings: Record<string, PerfMetricSummary>;\n gauges: Record<string, number>;\n};\n\nexport type OutputFormatterContext = {\n sessionId: string;\n};\n\nexport type OutputPolicy = {\n format: OutputFormat;\n jsonStrict: boolean;\n suppressReads: boolean;\n suppressNonJsonStderr: boolean;\n queueErrorAlreadyEmitted: boolean;\n suppressSdkConsoleErrors: boolean;\n};\n\nexport type OutputErrorEmissionPolicy = {\n queueErrorAlreadyEmitted: boolean;\n};\n\nexport interface OutputFormatter {\n setContext(context: OutputFormatterContext): void;\n onAcpMessage(message: AcpJsonRpcMessage): void;\n onError(params: {\n code: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n message: string;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n timestamp?: string;\n }): void;\n flush(): void;\n}\n\nexport type AcpClientOptions = {\n agentCommand: string;\n cwd: string;\n mcpServers?: McpServer[];\n permissionMode: PermissionMode;\n nonInteractivePermissions?: NonInteractivePermissionPolicy;\n authCredentials?: Record<string, string>;\n authPolicy?: AuthPolicy;\n suppressSdkConsoleErrors?: boolean;\n verbose?: boolean;\n sessionOptions?: {\n model?: string;\n allowedTools?: string[];\n maxTurns?: number;\n };\n onAcpMessage?: (direction: AcpMessageDirection, message: AcpJsonRpcMessage) => void;\n onAcpOutputMessage?: (direction: AcpMessageDirection, message: AcpJsonRpcMessage) => void;\n onSessionUpdate?: (notification: SessionNotification) => void;\n onClientOperation?: (operation: ClientOperation) => void;\n};\n\nexport const SESSION_RECORD_SCHEMA = \"acpx.session.v1\" as const;\nexport type SessionMessageImage = {\n source: string;\n size?: {\n width: number;\n height: number;\n } | null;\n};\n\nexport type SessionUserContent =\n | {\n Text: string;\n }\n | {\n Mention: {\n uri: string;\n content: string;\n };\n }\n | {\n Image: SessionMessageImage;\n };\n\nexport type SessionToolUse = {\n id: string;\n name: string;\n raw_input: string;\n input: unknown;\n is_input_complete: boolean;\n thought_signature?: string | null;\n};\n\nexport type SessionToolResultContent =\n | {\n Text: string;\n }\n | {\n Image: SessionMessageImage;\n };\n\nexport type SessionToolResult = {\n tool_use_id: string;\n tool_name: string;\n is_error: boolean;\n content: SessionToolResultContent;\n output?: unknown;\n};\n\nexport type SessionAgentContent =\n | {\n Text: string;\n }\n | {\n Thinking: {\n text: string;\n signature?: string | null;\n };\n }\n | {\n RedactedThinking: string;\n }\n | {\n ToolUse: SessionToolUse;\n };\n\nexport type SessionUserMessage = {\n id: string;\n content: SessionUserContent[];\n};\n\nexport type SessionAgentMessage = {\n content: SessionAgentContent[];\n tool_results: Record<string, SessionToolResult>;\n reasoning_details?: unknown;\n};\n\nexport type SessionMessage =\n | {\n User: SessionUserMessage;\n }\n | {\n Agent: SessionAgentMessage;\n }\n | \"Resume\";\n\nexport type SessionTokenUsage = {\n input_tokens?: number;\n output_tokens?: number;\n cache_creation_input_tokens?: number;\n cache_read_input_tokens?: number;\n};\n\nexport type SessionConversation = {\n title?: string | null;\n messages: SessionMessage[];\n updated_at: string;\n cumulative_token_usage: SessionTokenUsage;\n request_token_usage: Record<string, SessionTokenUsage>;\n};\n\nexport type SessionAcpxState = {\n current_mode_id?: string;\n desired_mode_id?: string;\n current_model_id?: string;\n available_models?: string[];\n available_commands?: string[];\n config_options?: SessionConfigOption[];\n session_options?: {\n model?: string;\n allowed_tools?: string[];\n max_turns?: number;\n };\n};\n\nexport type SessionRecord = {\n schema: typeof SESSION_RECORD_SCHEMA;\n acpxRecordId: string;\n acpSessionId: string;\n agentSessionId?: string;\n agentCommand: string;\n cwd: string;\n name?: string;\n createdAt: string;\n lastUsedAt: string;\n lastSeq: number;\n lastRequestId?: string;\n eventLog: SessionEventLog;\n closed?: boolean;\n closedAt?: string;\n pid?: number;\n agentStartedAt?: string;\n lastPromptAt?: string;\n lastAgentExitCode?: number | null;\n lastAgentExitSignal?: NodeJS.Signals | null;\n lastAgentExitAt?: string;\n lastAgentDisconnectReason?: string;\n protocolVersion?: number;\n agentCapabilities?: AgentCapabilities;\n title?: string | null;\n messages: SessionMessage[];\n updated_at: string;\n cumulative_token_usage: SessionTokenUsage;\n request_token_usage: Record<string, SessionTokenUsage>;\n acpx?: SessionAcpxState;\n};\n\nexport type RunPromptResult = {\n stopReason: StopReason;\n permissionStats: PermissionStats;\n sessionId: string;\n};\n\nexport type SessionSendResult = RunPromptResult & {\n record: SessionRecord;\n resumed: boolean;\n loadError?: string;\n};\n\nexport type SessionSetModeResult = {\n record: SessionRecord;\n resumed: boolean;\n loadError?: string;\n};\n\nexport type SessionSetConfigOptionResult = {\n record: SessionRecord;\n response: SetSessionConfigOptionResponse;\n resumed: boolean;\n loadError?: string;\n};\n\nexport type SessionSetModelResult = {\n record: SessionRecord;\n resumed: boolean;\n loadError?: string;\n};\n\nexport type SessionEnsureResult = {\n record: SessionRecord;\n created: boolean;\n};\n\nexport type SessionEnqueueResult = {\n queued: true;\n sessionId: string;\n requestId: string;\n};\n\nexport type SessionSendOutcome = SessionSendResult | SessionEnqueueResult;\nexport type { PromptInput };\n","import type { OutputErrorAcpPayload } from \"../types.js\";\n\nconst RESOURCE_NOT_FOUND_ACP_CODES = new Set([-32001, -32002]);\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction toAcpErrorPayload(value: unknown): OutputErrorAcpPayload | undefined {\n const record = asRecord(value);\n if (!record) {\n return undefined;\n }\n\n if (typeof record.code !== \"number\" || !Number.isFinite(record.code)) {\n return undefined;\n }\n if (typeof record.message !== \"string\" || record.message.length === 0) {\n return undefined;\n }\n\n return {\n code: record.code,\n message: record.message,\n data: record.data,\n };\n}\n\nfunction extractAcpErrorInternal(value: unknown, depth: number): OutputErrorAcpPayload | undefined {\n if (depth > 5) {\n return undefined;\n }\n\n const direct = toAcpErrorPayload(value);\n if (direct) {\n return direct;\n }\n\n const record = asRecord(value);\n if (!record) {\n return undefined;\n }\n\n if (\"error\" in record) {\n const nested = extractAcpErrorInternal(record.error, depth + 1);\n if (nested) {\n return nested;\n }\n }\n\n if (\"acp\" in record) {\n const nested = extractAcpErrorInternal(record.acp, depth + 1);\n if (nested) {\n return nested;\n }\n }\n\n if (\"cause\" in record) {\n const nested = extractAcpErrorInternal(record.cause, depth + 1);\n if (nested) {\n return nested;\n }\n }\n\n return undefined;\n}\n\nexport function formatUnknownErrorMessage(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n\n if (error && typeof error === \"object\") {\n const maybeMessage = (error as { message?: unknown }).message;\n if (typeof maybeMessage === \"string\" && maybeMessage.length > 0) {\n return maybeMessage;\n }\n\n try {\n return JSON.stringify(error);\n } catch {\n // fall through\n }\n }\n\n return String(error);\n}\n\n// Matches \"session\" followed by optional ID (quoted or unquoted) followed by \"not found\"\n// Examples: \"Session \\\"abc\\\" not found\", \"Session abc-123 not found\"\nconst SESSION_NOT_FOUND_PATTERN = /session\\s+[\"'\\w-]+\\s+not found/i;\n\nfunction isSessionNotFoundText(value: unknown): boolean {\n if (typeof value !== \"string\") {\n return false;\n }\n\n const normalized = value.toLowerCase();\n return (\n normalized.includes(\"resource_not_found\") ||\n normalized.includes(\"resource not found\") ||\n normalized.includes(\"session not found\") ||\n normalized.includes(\"unknown session\") ||\n normalized.includes(\"invalid session identifier\") ||\n SESSION_NOT_FOUND_PATTERN.test(value)\n );\n}\n\nfunction hasSessionNotFoundHint(value: unknown, depth = 0): boolean {\n if (depth > 4) {\n return false;\n }\n\n if (isSessionNotFoundText(value)) {\n return true;\n }\n\n if (Array.isArray(value)) {\n return value.some((entry) => hasSessionNotFoundHint(entry, depth + 1));\n }\n\n const record = asRecord(value);\n if (!record) {\n return false;\n }\n\n return Object.values(record).some((entry) => hasSessionNotFoundHint(entry, depth + 1));\n}\n\nexport function extractAcpError(error: unknown): OutputErrorAcpPayload | undefined {\n return extractAcpErrorInternal(error, 0);\n}\n\nexport function isAcpResourceNotFoundError(error: unknown): boolean {\n const acp = extractAcpError(error);\n if (acp && RESOURCE_NOT_FOUND_ACP_CODES.has(acp.code)) {\n return true;\n }\n\n if (acp) {\n if (isSessionNotFoundText(acp.message)) {\n return true;\n }\n if (hasSessionNotFoundHint(acp.data)) {\n return true;\n }\n }\n\n return isSessionNotFoundText(formatUnknownErrorMessage(error));\n}\n","import {\n AuthPolicyError,\n PermissionDeniedError,\n PermissionPromptUnavailableError,\n} from \"../errors.js\";\nimport {\n EXIT_CODES,\n OUTPUT_ERROR_CODES,\n OUTPUT_ERROR_ORIGINS,\n type ExitCode,\n type OutputErrorAcpPayload,\n type OutputErrorCode,\n type OutputErrorOrigin,\n} from \"../types.js\";\nimport {\n extractAcpError,\n formatUnknownErrorMessage,\n isAcpResourceNotFoundError,\n} from \"./error-shapes.js\";\n\nconst AUTH_REQUIRED_ACP_CODES = new Set([-32000]);\nconst QUERY_CLOSED_BEFORE_RESPONSE_DETAIL = \"query closed before response received\";\n\ntype ErrorMeta = {\n outputCode?: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n};\n\nexport type NormalizedOutputError = {\n code: OutputErrorCode;\n message: string;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n};\n\nexport type NormalizeOutputErrorOptions = {\n defaultCode?: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n};\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction isAuthRequiredMessage(value: string | undefined): boolean {\n if (!value) {\n return false;\n }\n const normalized = value.toLowerCase();\n return (\n normalized.includes(\"auth required\") ||\n normalized.includes(\"authentication required\") ||\n normalized.includes(\"authorization required\") ||\n normalized.includes(\"credential required\") ||\n normalized.includes(\"credentials required\") ||\n normalized.includes(\"token required\") ||\n normalized.includes(\"login required\")\n );\n}\n\nfunction isAcpAuthRequiredPayload(acp: OutputErrorAcpPayload | undefined): boolean {\n if (!acp) {\n return false;\n }\n if (!AUTH_REQUIRED_ACP_CODES.has(acp.code)) {\n return false;\n }\n if (isAuthRequiredMessage(acp.message)) {\n return true;\n }\n\n const data = asRecord(acp.data);\n if (!data) {\n return false;\n }\n\n if (data.authRequired === true) {\n return true;\n }\n\n const methodId = data.methodId;\n if (typeof methodId === \"string\" && methodId.trim().length > 0) {\n return true;\n }\n\n const methods = data.methods;\n if (Array.isArray(methods) && methods.length > 0) {\n return true;\n }\n\n return false;\n}\n\nfunction isOutputErrorCode(value: unknown): value is OutputErrorCode {\n return typeof value === \"string\" && OUTPUT_ERROR_CODES.includes(value as OutputErrorCode);\n}\n\nfunction isOutputErrorOrigin(value: unknown): value is OutputErrorOrigin {\n return typeof value === \"string\" && OUTPUT_ERROR_ORIGINS.includes(value as OutputErrorOrigin);\n}\n\nfunction readOutputErrorMeta(error: unknown): ErrorMeta {\n const record = asRecord(error);\n if (!record) {\n return {};\n }\n\n const outputCode = isOutputErrorCode(record.outputCode) ? record.outputCode : undefined;\n const detailCode =\n typeof record.detailCode === \"string\" && record.detailCode.trim().length > 0\n ? record.detailCode\n : undefined;\n const origin = isOutputErrorOrigin(record.origin) ? record.origin : undefined;\n const retryable = typeof record.retryable === \"boolean\" ? record.retryable : undefined;\n\n const acp = extractAcpError(record.acp);\n return {\n outputCode,\n detailCode,\n origin,\n retryable,\n acp,\n };\n}\n\nfunction isTimeoutLike(error: unknown): boolean {\n return error instanceof Error && error.name === \"TimeoutError\";\n}\n\nfunction isNoSessionLike(error: unknown): boolean {\n return error instanceof Error && error.name === \"NoSessionError\";\n}\n\nfunction isUsageLike(error: unknown): boolean {\n if (!(error instanceof Error)) {\n return false;\n }\n return (\n error.name === \"CommanderError\" ||\n error.name === \"InvalidArgumentError\" ||\n asRecord(error)?.code === \"commander.invalidArgument\"\n );\n}\n\nexport function formatErrorMessage(error: unknown): string {\n return formatUnknownErrorMessage(error);\n}\n\nexport { extractAcpError, isAcpResourceNotFoundError };\n\nexport function isAcpQueryClosedBeforeResponseError(error: unknown): boolean {\n const acp = extractAcpError(error);\n if (!acp || acp.code !== -32603) {\n return false;\n }\n\n const data = asRecord(acp.data);\n const details = data?.details;\n if (typeof details !== \"string\") {\n return false;\n }\n\n return details.toLowerCase().includes(QUERY_CLOSED_BEFORE_RESPONSE_DETAIL);\n}\n\nfunction mapErrorCode(error: unknown): OutputErrorCode | undefined {\n if (error instanceof PermissionPromptUnavailableError) {\n return \"PERMISSION_PROMPT_UNAVAILABLE\";\n }\n if (error instanceof PermissionDeniedError) {\n return \"PERMISSION_DENIED\";\n }\n if (isTimeoutLike(error)) {\n return \"TIMEOUT\";\n }\n if (isNoSessionLike(error) || isAcpResourceNotFoundError(error)) {\n return \"NO_SESSION\";\n }\n if (isUsageLike(error)) {\n return \"USAGE\";\n }\n return undefined;\n}\n\nexport function normalizeOutputError(\n error: unknown,\n options: NormalizeOutputErrorOptions = {},\n): NormalizedOutputError {\n const meta = readOutputErrorMeta(error);\n const mapped = mapErrorCode(error);\n let code = mapped ?? options.defaultCode ?? \"RUNTIME\";\n\n if (meta.outputCode) {\n code = meta.outputCode;\n }\n\n if (code === \"RUNTIME\" && isAcpResourceNotFoundError(error)) {\n code = \"NO_SESSION\";\n }\n\n const acp = options.acp ?? meta.acp ?? extractAcpError(error);\n const detailCode =\n meta.detailCode ??\n options.detailCode ??\n (error instanceof AuthPolicyError || isAcpAuthRequiredPayload(acp)\n ? \"AUTH_REQUIRED\"\n : undefined);\n return {\n code,\n message: formatErrorMessage(error),\n detailCode,\n origin: meta.origin ?? options.origin,\n retryable: meta.retryable ?? options.retryable,\n acp,\n };\n}\n\n/**\n * Returns true when an error from `client.prompt()` looks transient and\n * can reasonably be retried (e.g. model-API 400/500, network hiccups that\n * surface as ACP internal errors).\n *\n * Errors that are definitively non-recoverable (auth, missing session,\n * invalid params, timeout, permission) return false.\n */\nexport function isRetryablePromptError(error: unknown): boolean {\n if (error instanceof PermissionDeniedError || error instanceof PermissionPromptUnavailableError) {\n return false;\n }\n if (isTimeoutLike(error) || isNoSessionLike(error) || isUsageLike(error)) {\n return false;\n }\n\n // Extract ACP payload once and reuse for all subsequent checks.\n const acp = extractAcpError(error);\n if (!acp) {\n // Non-ACP errors (e.g. process crash) are not retried at the prompt level.\n return false;\n }\n\n // Resource-not-found (session gone) — check using the already-extracted payload.\n if (acp.code === -32001 || acp.code === -32002) {\n return false;\n }\n\n // Auth-required errors are never retryable. Use the same thorough check as normalizeOutputError.\n if (isAcpAuthRequiredPayload(acp)) {\n return false;\n }\n\n // Method-not-found or invalid-params are permanent protocol errors.\n if (acp.code === -32601 || acp.code === -32602) {\n return false;\n }\n\n // ACP internal errors (-32603) typically wrap model-API failures → retryable.\n // Parse errors (-32700) can also be transient.\n return acp.code === -32603 || acp.code === -32700;\n}\n\nexport function exitCodeForOutputErrorCode(code: OutputErrorCode): ExitCode {\n switch (code) {\n case \"USAGE\":\n return EXIT_CODES.USAGE;\n case \"TIMEOUT\":\n return EXIT_CODES.TIMEOUT;\n case \"NO_SESSION\":\n return EXIT_CODES.NO_SESSION;\n case \"PERMISSION_DENIED\":\n case \"PERMISSION_PROMPT_UNAVAILABLE\":\n return EXIT_CODES.PERMISSION_DENIED;\n case \"RUNTIME\":\n default:\n return EXIT_CODES.ERROR;\n }\n}\n","import type { ContentBlock } from \"@agentclientprotocol/sdk\";\n\nexport type PromptInput = ContentBlock[];\n\nexport class PromptInputValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PromptInputValidationError\";\n }\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\nfunction isBase64Data(value: string): boolean {\n if (value.length === 0 || value.length % 4 !== 0) {\n return false;\n }\n return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);\n}\n\nfunction isImageMimeType(value: string): boolean {\n return /^image\\/[A-Za-z0-9.+-]+$/i.test(value);\n}\n\nfunction isTextBlock(value: unknown): value is Extract<ContentBlock, { type: \"text\" }> {\n const record = asRecord(value);\n return record?.type === \"text\" && typeof record.text === \"string\";\n}\n\nfunction isImageBlock(value: unknown): value is Extract<ContentBlock, { type: \"image\" }> {\n const record = asRecord(value);\n return (\n record?.type === \"image\" &&\n isNonEmptyString(record.mimeType) &&\n isImageMimeType(record.mimeType) &&\n typeof record.data === \"string\" &&\n isBase64Data(record.data)\n );\n}\n\nfunction isResourceLinkBlock(\n value: unknown,\n): value is Extract<ContentBlock, { type: \"resource_link\" }> {\n const record = asRecord(value);\n return (\n record?.type === \"resource_link\" &&\n isNonEmptyString(record.uri) &&\n (record.title === undefined || typeof record.title === \"string\") &&\n (record.name === undefined || typeof record.name === \"string\")\n );\n}\n\nfunction isResourcePayload(value: unknown): boolean {\n const record = asRecord(value);\n if (!record || !isNonEmptyString(record.uri)) {\n return false;\n }\n return record.text === undefined || typeof record.text === \"string\";\n}\n\nfunction isResourceBlock(value: unknown): value is Extract<ContentBlock, { type: \"resource\" }> {\n const record = asRecord(value);\n return record?.type === \"resource\" && isResourcePayload(record.resource);\n}\n\nfunction isContentBlock(value: unknown): value is ContentBlock {\n return (\n isTextBlock(value) ||\n isImageBlock(value) ||\n isResourceLinkBlock(value) ||\n isResourceBlock(value)\n );\n}\n\nfunction getContentBlockValidationError(value: unknown, index: number): string | undefined {\n const record = asRecord(value);\n if (!record || typeof record.type !== \"string\") {\n return `prompt[${index}] must be an ACP content block object`;\n }\n\n switch (record.type) {\n case \"text\":\n return typeof record.text === \"string\"\n ? undefined\n : `prompt[${index}] text block must include a string text field`;\n case \"image\":\n if (!isNonEmptyString(record.mimeType)) {\n return `prompt[${index}] image block must include a non-empty mimeType`;\n }\n if (!isImageMimeType(record.mimeType)) {\n return `prompt[${index}] image block mimeType must start with image/`;\n }\n if (typeof record.data !== \"string\" || record.data.length === 0) {\n return `prompt[${index}] image block must include non-empty base64 data`;\n }\n if (!isBase64Data(record.data)) {\n return `prompt[${index}] image block data must be valid base64`;\n }\n return undefined;\n case \"resource_link\":\n if (!isNonEmptyString(record.uri)) {\n return `prompt[${index}] resource_link block must include a non-empty uri`;\n }\n if (record.title !== undefined && typeof record.title !== \"string\") {\n return `prompt[${index}] resource_link block title must be a string when present`;\n }\n if (record.name !== undefined && typeof record.name !== \"string\") {\n return `prompt[${index}] resource_link block name must be a string when present`;\n }\n return undefined;\n case \"resource\":\n if (!asRecord(record.resource)) {\n return `prompt[${index}] resource block must include a resource object`;\n }\n if (!isResourcePayload(record.resource)) {\n return `prompt[${index}] resource block resource must include a non-empty uri and optional text`;\n }\n return undefined;\n default:\n return `prompt[${index}] has unsupported content block type ${JSON.stringify(record.type)}`;\n }\n}\n\nexport function isPromptInput(value: unknown): value is PromptInput {\n return Array.isArray(value) && value.every((entry) => isContentBlock(entry));\n}\n\nexport function textPrompt(text: string): PromptInput {\n return [\n {\n type: \"text\",\n text,\n },\n ];\n}\n\nfunction parseStructuredPrompt(source: string): PromptInput | undefined {\n if (!source.startsWith(\"[\")) {\n return undefined;\n }\n try {\n const parsed = JSON.parse(source) as unknown;\n if (isPromptInput(parsed)) {\n return parsed;\n }\n if (Array.isArray(parsed)) {\n const detail =\n parsed\n .map((entry, index) => getContentBlockValidationError(entry, index))\n .find((message) => message !== undefined) ??\n \"Structured prompt JSON must be an array of valid ACP content blocks\";\n throw new PromptInputValidationError(detail);\n }\n return undefined;\n } catch (error) {\n if (error instanceof PromptInputValidationError) {\n throw error;\n }\n return undefined;\n }\n}\n\nexport function parsePromptSource(source: string): PromptInput {\n const trimmed = source.trim();\n const structured = parseStructuredPrompt(trimmed);\n if (structured) {\n return structured;\n }\n if (!trimmed) {\n return [];\n }\n return textPrompt(trimmed);\n}\n\nexport function mergePromptSourceWithText(source: string, suffixText: string): PromptInput {\n const prompt = parsePromptSource(source);\n const appended = suffixText.trim();\n if (!appended) {\n return prompt;\n }\n if (prompt.length === 0) {\n return textPrompt(appended);\n }\n return [...prompt, ...textPrompt(appended)];\n}\n\nexport function promptToDisplayText(prompt: PromptInput): string {\n return prompt\n .map((block) => {\n switch (block.type) {\n case \"text\":\n return block.text;\n case \"resource_link\":\n return block.title ?? block.name ?? block.uri;\n case \"resource\":\n return \"text\" in block.resource && typeof block.resource.text === \"string\"\n ? block.resource.text\n : block.resource.uri;\n case \"image\":\n return `[image] ${block.mimeType}`;\n default:\n return \"\";\n }\n })\n .filter((entry) => entry.trim().length > 0)\n .join(\"\\n\\n\")\n .trim();\n}\n","const AGENT_SESSION_ID_META_KEYS = [\"agentSessionId\", \"sessionId\"] as const;\n\nexport function normalizeAgentSessionId(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return undefined;\n }\n\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction asMetaRecord(meta: unknown): Record<string, unknown> | undefined {\n if (!meta || typeof meta !== \"object\" || Array.isArray(meta)) {\n return undefined;\n }\n return meta as Record<string, unknown>;\n}\n\nexport function extractAgentSessionId(meta: unknown): string | undefined {\n const record = asMetaRecord(meta);\n if (!record) {\n return undefined;\n }\n\n for (const key of AGENT_SESSION_ID_META_KEYS) {\n const normalized = normalizeAgentSessionId(record[key]);\n if (normalized) {\n return normalized;\n }\n }\n\n return undefined;\n}\n\nexport { AGENT_SESSION_ID_META_KEYS };\n","import {\n AGENT_SESSION_ID_META_KEYS,\n extractAgentSessionId,\n normalizeAgentSessionId,\n} from \"../acp/agent-session-id.js\";\n\nexport const RUNTIME_SESSION_ID_META_KEYS = AGENT_SESSION_ID_META_KEYS;\n\nexport function normalizeRuntimeSessionId(value: unknown): string | undefined {\n return normalizeAgentSessionId(value);\n}\n\nexport function extractRuntimeSessionId(meta: unknown): string | undefined {\n return extractAgentSessionId(meta);\n}\n","import type { PerfMetricsSnapshot } from \"./types.js\";\n\ntype TimingBucket = {\n count: number;\n totalMs: number;\n maxMs: number;\n};\n\nconst counters = new Map<string, number>();\nconst gauges = new Map<string, number>();\nconst timings = new Map<string, TimingBucket>();\n\nfunction hrNow(): bigint {\n return process.hrtime.bigint();\n}\n\nfunction durationMs(start: bigint): number {\n return Number(process.hrtime.bigint() - start) / 1_000_000;\n}\n\nfunction roundMetric(value: number): number {\n return Number(value.toFixed(3));\n}\n\nexport function incrementPerfCounter(name: string, delta = 1): void {\n counters.set(name, (counters.get(name) ?? 0) + delta);\n}\n\nexport function setPerfGauge(name: string, value: number): void {\n gauges.set(name, value);\n}\n\nexport function recordPerfDuration(name: string, durationMsValue: number): void {\n const next = timings.get(name) ?? {\n count: 0,\n totalMs: 0,\n maxMs: 0,\n };\n next.count += 1;\n next.totalMs += durationMsValue;\n next.maxMs = Math.max(next.maxMs, durationMsValue);\n timings.set(name, next);\n}\n\nexport async function measurePerf<T>(name: string, run: () => Promise<T>): Promise<T> {\n const startedAt = hrNow();\n try {\n return await run();\n } finally {\n recordPerfDuration(name, durationMs(startedAt));\n }\n}\n\nexport function startPerfTimer(name: string): () => number {\n const startedAt = hrNow();\n return () => {\n const elapsedMs = durationMs(startedAt);\n recordPerfDuration(name, elapsedMs);\n return elapsedMs;\n };\n}\n\nexport function getPerfMetricsSnapshot(): PerfMetricsSnapshot {\n return {\n counters: Object.fromEntries(counters.entries()),\n gauges: Object.fromEntries(gauges.entries()),\n timings: Object.fromEntries(\n [...timings.entries()].map(([name, bucket]) => [\n name,\n {\n count: bucket.count,\n totalMs: roundMetric(bucket.totalMs),\n maxMs: roundMetric(bucket.maxMs),\n },\n ]),\n ),\n };\n}\n\nexport function resetPerfMetrics(): void {\n counters.clear();\n gauges.clear();\n timings.clear();\n}\n\nexport function formatPerfMetric(name: string, durationMsValue: number): string {\n return `${name}=${roundMetric(durationMsValue)}ms`;\n}\n"],"mappings":";AAWA,IAAa,uBAAb,cAA0C,MAAM;CAC9C;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAAiB,SAA4B;AACvD,QAAM,SAAS,QAAQ;AACvB,OAAK,OAAO,IAAI,OAAO;AACvB,OAAK,aAAa,SAAS;AAC3B,OAAK,aAAa,SAAS;AAC3B,OAAK,SAAS,SAAS;AACvB,OAAK,YAAY,SAAS;AAC1B,OAAK,MAAM,SAAS;AACpB,OAAK,uBAAuB,SAAS;;;AAIzC,IAAa,uBAAb,cAA0C,qBAAqB;CAC7D;CAEA,YAAY,WAAmB;AAC7B,QAAM,sBAAsB,YAAY;AACxC,OAAK,YAAY;;;AAIrB,IAAa,yBAAb,cAA4C,qBAAqB;AAEjE,IAAa,kBAAb,cAAqC,qBAAqB;CACxD;CAEA,YAAY,cAAsB,OAAiB;AACjD,QAAM,kCAAkC,gBAAgB,EACtD,OAAO,iBAAiB,QAAQ,QAAQ,KAAA,GACzC,CAAC;AACF,OAAK,eAAe;;;AAIxB,IAAa,oBAAb,cAAuC,qBAAqB;CAC1D;CACA;CACA;CACA;CAEA,YAAY,QAMT;EACD,MAAM,cAAc,QAAQ,OAAO,YAAY,OAAO,WAAW,OAAO,UAAU;EAClF,MAAM,eACJ,OAAO,OAAO,kBAAkB,YAAY,OAAO,cAAc,MAAM,CAAC,SAAS,IAC7E,KAAK,OAAO,cAAc,MAAM,KAChC;AACN,QAAM,iDAAiD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SAAS,IAAI,KAAK,IAAI,KAAK,MAAM;;AAGvD,SAAgB,aAAa,MAAc,OAAqB;AAC9D,QAAO,IAAI,MAAM,MAAM;;AAGzB,SAAgB,mBAAmB,MAAc,iBAA+B;CAC9E,MAAM,OAAO,QAAQ,IAAI,KAAK,IAAI;EAChC,OAAO;EACP,SAAS;EACT,OAAO;EACR;AACD,MAAK,SAAS;AACd,MAAK,WAAW;AAChB,MAAK,QAAQ,KAAK,IAAI,KAAK,OAAO,gBAAgB;AAClD,SAAQ,IAAI,MAAM,KAAK;;AAGzB,eAAsB,YAAe,MAAc,KAAmC;CACpF,MAAM,YAAY,OAAO;AACzB,KAAI;AACF,SAAO,MAAM,KAAK;WACV;AACR,qBAAmB,MAAM,WAAW,UAAU,CAAC;;;AAInD,SAAgB,eAAe,MAA4B;CACzD,MAAM,YAAY,OAAO;AACzB,cAAa;EACX,MAAM,YAAY,WAAW,UAAU;AACvC,qBAAmB,MAAM,UAAU;AACnC,SAAO;;;AAIX,SAAgB,yBAA8C;AAC5D,QAAO;EACL,UAAU,OAAO,YAAY,SAAS,SAAS,CAAC;EAChD,QAAQ,OAAO,YAAY,OAAO,SAAS,CAAC;EAC5C,SAAS,OAAO,YACd,CAAC,GAAG,QAAQ,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,CAC7C,MACA;GACE,OAAO,OAAO;GACd,SAAS,YAAY,OAAO,QAAQ;GACpC,OAAO,YAAY,OAAO,MAAM;GACjC,CACF,CAAC,CACH;EACF;;AAGH,SAAgB,mBAAyB;AACvC,UAAS,OAAO;AAChB,QAAO,OAAO;AACd,SAAQ,OAAO;;AAGjB,SAAgB,iBAAiB,MAAc,iBAAiC;AAC9E,QAAO,GAAG,KAAK,GAAG,YAAY,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"perf-metrics-D0um6IR6.js","names":["asRecord","asRecord"],"sources":["../src/errors.ts","../src/types.ts","../src/acp/error-shapes.ts","../src/acp/error-normalization.ts","../src/prompt-content.ts","../src/acp/agent-session-id.ts","../src/session/runtime-session-id.ts","../src/perf-metrics.ts"],"sourcesContent":["import type { OutputErrorAcpPayload, OutputErrorCode, OutputErrorOrigin } from \"./types.js\";\n\ntype AcpxErrorOptions = ErrorOptions & {\n outputCode?: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n outputAlreadyEmitted?: boolean;\n};\n\nexport class AcpxOperationalError extends Error {\n readonly outputCode?: OutputErrorCode;\n readonly detailCode?: string;\n readonly origin?: OutputErrorOrigin;\n readonly retryable?: boolean;\n readonly acp?: OutputErrorAcpPayload;\n readonly outputAlreadyEmitted?: boolean;\n\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, options);\n this.name = new.target.name;\n this.outputCode = options?.outputCode;\n this.detailCode = options?.detailCode;\n this.origin = options?.origin;\n this.retryable = options?.retryable;\n this.acp = options?.acp;\n this.outputAlreadyEmitted = options?.outputAlreadyEmitted;\n }\n}\n\nexport class SessionNotFoundError extends AcpxOperationalError {\n readonly sessionId: string;\n\n constructor(sessionId: string) {\n super(`Session not found: ${sessionId}`);\n this.sessionId = sessionId;\n }\n}\n\nexport class SessionResolutionError extends AcpxOperationalError {}\n\nexport class AgentSpawnError extends AcpxOperationalError {\n readonly agentCommand: string;\n\n constructor(agentCommand: string, cause?: unknown) {\n super(`Failed to spawn agent command: ${agentCommand}`, {\n cause: cause instanceof Error ? cause : undefined,\n });\n this.agentCommand = agentCommand;\n }\n}\n\nexport class AgentStartupError extends AcpxOperationalError {\n readonly agentCommand: string;\n readonly exitCode: number | null;\n readonly signal: NodeJS.Signals | null;\n readonly stderrSummary?: string;\n\n constructor(params: {\n agentCommand: string;\n exitCode: number | null;\n signal: NodeJS.Signals | null;\n stderrSummary?: string;\n cause?: unknown;\n }) {\n const exitSummary = `exit=${params.exitCode ?? \"null\"}, signal=${params.signal ?? \"null\"}`;\n const stderrSuffix =\n typeof params.stderrSummary === \"string\" && params.stderrSummary.trim().length > 0\n ? `: ${params.stderrSummary.trim()}`\n : \"\";\n super(`ACP agent exited before initialize completed (${exitSummary})${stderrSuffix}`, {\n cause: params.cause instanceof Error ? params.cause : undefined,\n outputCode: \"RUNTIME\",\n detailCode: \"AGENT_STARTUP_FAILED\",\n origin: \"acp\",\n });\n this.agentCommand = params.agentCommand;\n this.exitCode = params.exitCode;\n this.signal = params.signal;\n this.stderrSummary = params.stderrSummary?.trim() || undefined;\n }\n}\n\nexport class AgentDisconnectedError extends AcpxOperationalError {\n readonly reason: string;\n readonly exitCode: number | null;\n readonly signal: NodeJS.Signals | null;\n\n constructor(\n reason: string,\n exitCode: number | null,\n signal: NodeJS.Signals | null,\n options?: AcpxErrorOptions,\n ) {\n super(\n `ACP agent disconnected during request (${reason}, exit=${exitCode ?? \"null\"}, signal=${signal ?? \"null\"})`,\n {\n outputCode: \"RUNTIME\",\n detailCode: \"AGENT_DISCONNECTED\",\n origin: \"acp\",\n ...options,\n },\n );\n this.reason = reason;\n this.exitCode = exitCode;\n this.signal = signal;\n }\n}\n\nexport class SessionResumeRequiredError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"SESSION_RESUME_REQUIRED\",\n origin: \"acp\",\n retryable: true,\n ...options,\n });\n }\n}\n\nexport class GeminiAcpStartupTimeoutError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"TIMEOUT\",\n detailCode: \"GEMINI_ACP_STARTUP_TIMEOUT\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class SessionModeReplayError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"SESSION_MODE_REPLAY_FAILED\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class SessionModelReplayError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"SESSION_MODEL_REPLAY_FAILED\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class ClaudeAcpSessionCreateTimeoutError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"TIMEOUT\",\n detailCode: \"CLAUDE_ACP_SESSION_CREATE_TIMEOUT\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class CopilotAcpUnsupportedError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"COPILOT_ACP_UNSUPPORTED\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class AuthPolicyError extends AcpxOperationalError {\n constructor(message: string, options?: AcpxErrorOptions) {\n super(message, {\n outputCode: \"RUNTIME\",\n detailCode: \"AUTH_REQUIRED\",\n origin: \"acp\",\n ...options,\n });\n }\n}\n\nexport class QueueConnectionError extends AcpxOperationalError {}\n\nexport class QueueProtocolError extends AcpxOperationalError {}\n\nexport class PermissionDeniedError extends AcpxOperationalError {}\n\nexport class PermissionPromptUnavailableError extends AcpxOperationalError {\n constructor() {\n super(\"Permission prompt unavailable in non-interactive mode\");\n }\n}\n","import type {\n AgentCapabilities,\n AnyMessage,\n McpServer,\n SessionNotification,\n SessionConfigOption,\n SetSessionConfigOptionResponse,\n StopReason,\n} from \"@agentclientprotocol/sdk\";\nexport type { McpServer, SessionNotification } from \"@agentclientprotocol/sdk\";\nimport type { PromptInput } from \"./prompt-content.js\";\n\nexport const EXIT_CODES = {\n SUCCESS: 0,\n ERROR: 1,\n USAGE: 2,\n TIMEOUT: 3,\n NO_SESSION: 4,\n PERMISSION_DENIED: 5,\n INTERRUPTED: 130,\n} as const;\n\nexport type ExitCode = (typeof EXIT_CODES)[keyof typeof EXIT_CODES];\n\nexport const OUTPUT_FORMATS = [\"text\", \"json\", \"quiet\"] as const;\nexport type OutputFormat = (typeof OUTPUT_FORMATS)[number];\n\nexport const PERMISSION_MODES = [\"approve-all\", \"approve-reads\", \"deny-all\"] as const;\nexport type PermissionMode = (typeof PERMISSION_MODES)[number];\n\nexport const AUTH_POLICIES = [\"skip\", \"fail\"] as const;\nexport type AuthPolicy = (typeof AUTH_POLICIES)[number];\n\nexport const NON_INTERACTIVE_PERMISSION_POLICIES = [\"deny\", \"fail\"] as const;\nexport type NonInteractivePermissionPolicy = (typeof NON_INTERACTIVE_PERMISSION_POLICIES)[number];\n\nexport const SESSION_RESUME_POLICIES = [\"allow-new\", \"same-session-only\"] as const;\nexport type SessionResumePolicy = (typeof SESSION_RESUME_POLICIES)[number];\n\nexport const OUTPUT_STREAMS = [\"prompt\", \"control\"] as const;\nexport type OutputStream = (typeof OUTPUT_STREAMS)[number];\nexport type AcpJsonRpcMessage = AnyMessage;\nexport type AcpMessageDirection = \"outbound\" | \"inbound\";\n\nexport const OUTPUT_ERROR_CODES = [\n \"NO_SESSION\",\n \"TIMEOUT\",\n \"PERMISSION_DENIED\",\n \"PERMISSION_PROMPT_UNAVAILABLE\",\n \"RUNTIME\",\n \"USAGE\",\n] as const;\nexport type OutputErrorCode = (typeof OUTPUT_ERROR_CODES)[number];\n\nexport const OUTPUT_ERROR_ORIGINS = [\"cli\", \"runtime\", \"queue\", \"acp\"] as const;\nexport type OutputErrorOrigin = (typeof OUTPUT_ERROR_ORIGINS)[number];\n\nexport const QUEUE_ERROR_DETAIL_CODES = [\n \"QUEUE_OWNER_CLOSED\",\n \"QUEUE_OWNER_SHUTTING_DOWN\",\n \"QUEUE_OWNER_OVERLOADED\",\n \"QUEUE_OWNER_GENERATION_MISMATCH\",\n \"QUEUE_REQUEST_INVALID\",\n \"QUEUE_REQUEST_PAYLOAD_INVALID_JSON\",\n \"QUEUE_ACK_MISSING\",\n \"QUEUE_DISCONNECTED_BEFORE_ACK\",\n \"QUEUE_DISCONNECTED_BEFORE_COMPLETION\",\n \"QUEUE_PROTOCOL_INVALID_JSON\",\n \"QUEUE_PROTOCOL_MALFORMED_MESSAGE\",\n \"QUEUE_PROTOCOL_UNEXPECTED_RESPONSE\",\n \"QUEUE_NOT_ACCEPTING_REQUESTS\",\n \"QUEUE_CONTROL_REQUEST_FAILED\",\n \"QUEUE_RUNTIME_PROMPT_FAILED\",\n] as const;\nexport type QueueErrorDetailCode = (typeof QUEUE_ERROR_DETAIL_CODES)[number];\n\nexport type OutputErrorAcpPayload = {\n code: number;\n message: string;\n data?: unknown;\n};\n\nexport type PermissionStats = {\n requested: number;\n approved: number;\n denied: number;\n cancelled: number;\n};\n\nexport type ClientOperationMethod =\n | \"fs/read_text_file\"\n | \"fs/write_text_file\"\n | \"terminal/create\"\n | \"terminal/output\"\n | \"terminal/wait_for_exit\"\n | \"terminal/kill\"\n | \"terminal/release\";\n\nexport type ClientOperationStatus = \"running\" | \"completed\" | \"failed\";\n\nexport type ClientOperation = {\n method: ClientOperationMethod;\n status: ClientOperationStatus;\n summary: string;\n details?: string;\n timestamp: string;\n};\n\nexport type SessionEventLog = {\n active_path: string;\n segment_count: number;\n max_segment_bytes: number;\n max_segments: number;\n last_write_at?: string;\n last_write_error?: string | null;\n};\n\nexport type PerfMetricSummary = {\n count: number;\n totalMs: number;\n maxMs: number;\n};\n\nexport type PerfMetricsSnapshot = {\n counters: Record<string, number>;\n timings: Record<string, PerfMetricSummary>;\n gauges: Record<string, number>;\n};\n\nexport type OutputFormatterContext = {\n sessionId: string;\n};\n\nexport type OutputPolicy = {\n format: OutputFormat;\n jsonStrict: boolean;\n suppressReads: boolean;\n suppressNonJsonStderr: boolean;\n queueErrorAlreadyEmitted: boolean;\n suppressSdkConsoleErrors: boolean;\n};\n\nexport type OutputErrorEmissionPolicy = {\n queueErrorAlreadyEmitted: boolean;\n};\n\nexport interface OutputFormatter {\n setContext(context: OutputFormatterContext): void;\n onAcpMessage(message: AcpJsonRpcMessage): void;\n onError(params: {\n code: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n message: string;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n timestamp?: string;\n }): void;\n flush(): void;\n}\n\nexport type AcpClientOptions = {\n agentCommand: string;\n cwd: string;\n mcpServers?: McpServer[];\n permissionMode: PermissionMode;\n nonInteractivePermissions?: NonInteractivePermissionPolicy;\n authCredentials?: Record<string, string>;\n authPolicy?: AuthPolicy;\n suppressSdkConsoleErrors?: boolean;\n verbose?: boolean;\n sessionOptions?: {\n model?: string;\n allowedTools?: string[];\n maxTurns?: number;\n };\n onAcpMessage?: (direction: AcpMessageDirection, message: AcpJsonRpcMessage) => void;\n onAcpOutputMessage?: (direction: AcpMessageDirection, message: AcpJsonRpcMessage) => void;\n onSessionUpdate?: (notification: SessionNotification) => void;\n onClientOperation?: (operation: ClientOperation) => void;\n};\n\nexport const SESSION_RECORD_SCHEMA = \"acpx.session.v1\" as const;\nexport type SessionMessageImage = {\n source: string;\n size?: {\n width: number;\n height: number;\n } | null;\n};\n\nexport type SessionUserContent =\n | {\n Text: string;\n }\n | {\n Mention: {\n uri: string;\n content: string;\n };\n }\n | {\n Image: SessionMessageImage;\n };\n\nexport type SessionToolUse = {\n id: string;\n name: string;\n raw_input: string;\n input: unknown;\n is_input_complete: boolean;\n thought_signature?: string | null;\n};\n\nexport type SessionToolResultContent =\n | {\n Text: string;\n }\n | {\n Image: SessionMessageImage;\n };\n\nexport type SessionToolResult = {\n tool_use_id: string;\n tool_name: string;\n is_error: boolean;\n content: SessionToolResultContent;\n output?: unknown;\n};\n\nexport type SessionAgentContent =\n | {\n Text: string;\n }\n | {\n Thinking: {\n text: string;\n signature?: string | null;\n };\n }\n | {\n RedactedThinking: string;\n }\n | {\n ToolUse: SessionToolUse;\n };\n\nexport type SessionUserMessage = {\n id: string;\n content: SessionUserContent[];\n};\n\nexport type SessionAgentMessage = {\n content: SessionAgentContent[];\n tool_results: Record<string, SessionToolResult>;\n reasoning_details?: unknown;\n};\n\nexport type SessionMessage =\n | {\n User: SessionUserMessage;\n }\n | {\n Agent: SessionAgentMessage;\n }\n | \"Resume\";\n\nexport type SessionTokenUsage = {\n input_tokens?: number;\n output_tokens?: number;\n cache_creation_input_tokens?: number;\n cache_read_input_tokens?: number;\n};\n\nexport type SessionConversation = {\n title?: string | null;\n messages: SessionMessage[];\n updated_at: string;\n cumulative_token_usage: SessionTokenUsage;\n request_token_usage: Record<string, SessionTokenUsage>;\n};\n\nexport type SessionAcpxState = {\n reset_on_next_ensure?: boolean;\n current_mode_id?: string;\n desired_mode_id?: string;\n current_model_id?: string;\n available_models?: string[];\n available_commands?: string[];\n config_options?: SessionConfigOption[];\n session_options?: {\n model?: string;\n allowed_tools?: string[];\n max_turns?: number;\n };\n};\n\nexport type SessionRecord = {\n schema: typeof SESSION_RECORD_SCHEMA;\n acpxRecordId: string;\n acpSessionId: string;\n agentSessionId?: string;\n agentCommand: string;\n cwd: string;\n name?: string;\n createdAt: string;\n lastUsedAt: string;\n lastSeq: number;\n lastRequestId?: string;\n eventLog: SessionEventLog;\n closed?: boolean;\n closedAt?: string;\n pid?: number;\n agentStartedAt?: string;\n lastPromptAt?: string;\n lastAgentExitCode?: number | null;\n lastAgentExitSignal?: NodeJS.Signals | null;\n lastAgentExitAt?: string;\n lastAgentDisconnectReason?: string;\n protocolVersion?: number;\n agentCapabilities?: AgentCapabilities;\n title?: string | null;\n messages: SessionMessage[];\n updated_at: string;\n cumulative_token_usage: SessionTokenUsage;\n request_token_usage: Record<string, SessionTokenUsage>;\n acpx?: SessionAcpxState;\n};\n\nexport type RunPromptResult = {\n stopReason: StopReason;\n permissionStats: PermissionStats;\n sessionId: string;\n};\n\nexport type SessionSendResult = RunPromptResult & {\n record: SessionRecord;\n resumed: boolean;\n loadError?: string;\n};\n\nexport type SessionSetModeResult = {\n record: SessionRecord;\n resumed: boolean;\n loadError?: string;\n};\n\nexport type SessionSetConfigOptionResult = {\n record: SessionRecord;\n response: SetSessionConfigOptionResponse;\n resumed: boolean;\n loadError?: string;\n};\n\nexport type SessionSetModelResult = {\n record: SessionRecord;\n resumed: boolean;\n loadError?: string;\n};\n\nexport type SessionEnsureResult = {\n record: SessionRecord;\n created: boolean;\n};\n\nexport type SessionEnqueueResult = {\n queued: true;\n sessionId: string;\n requestId: string;\n};\n\nexport type SessionSendOutcome = SessionSendResult | SessionEnqueueResult;\nexport type { PromptInput };\n","import type { OutputErrorAcpPayload } from \"../types.js\";\n\nconst RESOURCE_NOT_FOUND_ACP_CODES = new Set([-32001, -32002]);\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction toAcpErrorPayload(value: unknown): OutputErrorAcpPayload | undefined {\n const record = asRecord(value);\n if (!record) {\n return undefined;\n }\n\n if (typeof record.code !== \"number\" || !Number.isFinite(record.code)) {\n return undefined;\n }\n if (typeof record.message !== \"string\" || record.message.length === 0) {\n return undefined;\n }\n\n return {\n code: record.code,\n message: record.message,\n data: record.data,\n };\n}\n\nfunction extractAcpErrorInternal(value: unknown, depth: number): OutputErrorAcpPayload | undefined {\n if (depth > 5) {\n return undefined;\n }\n\n const direct = toAcpErrorPayload(value);\n if (direct) {\n return direct;\n }\n\n const record = asRecord(value);\n if (!record) {\n return undefined;\n }\n\n if (\"error\" in record) {\n const nested = extractAcpErrorInternal(record.error, depth + 1);\n if (nested) {\n return nested;\n }\n }\n\n if (\"acp\" in record) {\n const nested = extractAcpErrorInternal(record.acp, depth + 1);\n if (nested) {\n return nested;\n }\n }\n\n if (\"cause\" in record) {\n const nested = extractAcpErrorInternal(record.cause, depth + 1);\n if (nested) {\n return nested;\n }\n }\n\n return undefined;\n}\n\nexport function formatUnknownErrorMessage(error: unknown): string {\n if (error instanceof Error) {\n return error.message;\n }\n\n if (error && typeof error === \"object\") {\n const maybeMessage = (error as { message?: unknown }).message;\n if (typeof maybeMessage === \"string\" && maybeMessage.length > 0) {\n return maybeMessage;\n }\n\n try {\n return JSON.stringify(error);\n } catch {\n // fall through\n }\n }\n\n return String(error);\n}\n\n// Matches \"session\" followed by optional ID (quoted or unquoted) followed by \"not found\"\n// Examples: \"Session \\\"abc\\\" not found\", \"Session abc-123 not found\"\nconst SESSION_NOT_FOUND_PATTERN = /session\\s+[\"'\\w-]+\\s+not found/i;\n\nfunction isSessionNotFoundText(value: unknown): boolean {\n if (typeof value !== \"string\") {\n return false;\n }\n\n const normalized = value.toLowerCase();\n return (\n normalized.includes(\"resource_not_found\") ||\n normalized.includes(\"resource not found\") ||\n normalized.includes(\"session not found\") ||\n normalized.includes(\"unknown session\") ||\n normalized.includes(\"invalid session identifier\") ||\n SESSION_NOT_FOUND_PATTERN.test(value)\n );\n}\n\nfunction hasSessionNotFoundHint(value: unknown, depth = 0): boolean {\n if (depth > 4) {\n return false;\n }\n\n if (isSessionNotFoundText(value)) {\n return true;\n }\n\n if (Array.isArray(value)) {\n return value.some((entry) => hasSessionNotFoundHint(entry, depth + 1));\n }\n\n const record = asRecord(value);\n if (!record) {\n return false;\n }\n\n return Object.values(record).some((entry) => hasSessionNotFoundHint(entry, depth + 1));\n}\n\nexport function extractAcpError(error: unknown): OutputErrorAcpPayload | undefined {\n return extractAcpErrorInternal(error, 0);\n}\n\nexport function isAcpResourceNotFoundError(error: unknown): boolean {\n const acp = extractAcpError(error);\n if (acp && RESOURCE_NOT_FOUND_ACP_CODES.has(acp.code)) {\n return true;\n }\n\n if (acp) {\n if (isSessionNotFoundText(acp.message)) {\n return true;\n }\n if (hasSessionNotFoundHint(acp.data)) {\n return true;\n }\n }\n\n return isSessionNotFoundText(formatUnknownErrorMessage(error));\n}\n","import {\n AuthPolicyError,\n PermissionDeniedError,\n PermissionPromptUnavailableError,\n} from \"../errors.js\";\nimport {\n EXIT_CODES,\n OUTPUT_ERROR_CODES,\n OUTPUT_ERROR_ORIGINS,\n type ExitCode,\n type OutputErrorAcpPayload,\n type OutputErrorCode,\n type OutputErrorOrigin,\n} from \"../types.js\";\nimport {\n extractAcpError,\n formatUnknownErrorMessage,\n isAcpResourceNotFoundError,\n} from \"./error-shapes.js\";\n\nconst AUTH_REQUIRED_ACP_CODES = new Set([-32000]);\nconst QUERY_CLOSED_BEFORE_RESPONSE_DETAIL = \"query closed before response received\";\n\ntype ErrorMeta = {\n outputCode?: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n};\n\nexport type NormalizedOutputError = {\n code: OutputErrorCode;\n message: string;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n};\n\nexport type NormalizeOutputErrorOptions = {\n defaultCode?: OutputErrorCode;\n detailCode?: string;\n origin?: OutputErrorOrigin;\n retryable?: boolean;\n acp?: OutputErrorAcpPayload;\n};\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction isAuthRequiredMessage(value: string | undefined): boolean {\n if (!value) {\n return false;\n }\n const normalized = value.toLowerCase();\n return (\n normalized.includes(\"auth required\") ||\n normalized.includes(\"authentication required\") ||\n normalized.includes(\"authorization required\") ||\n normalized.includes(\"credential required\") ||\n normalized.includes(\"credentials required\") ||\n normalized.includes(\"token required\") ||\n normalized.includes(\"login required\")\n );\n}\n\nfunction isAcpAuthRequiredPayload(acp: OutputErrorAcpPayload | undefined): boolean {\n if (!acp) {\n return false;\n }\n if (!AUTH_REQUIRED_ACP_CODES.has(acp.code)) {\n return false;\n }\n if (isAuthRequiredMessage(acp.message)) {\n return true;\n }\n\n const data = asRecord(acp.data);\n if (!data) {\n return false;\n }\n\n if (data.authRequired === true) {\n return true;\n }\n\n const methodId = data.methodId;\n if (typeof methodId === \"string\" && methodId.trim().length > 0) {\n return true;\n }\n\n const methods = data.methods;\n if (Array.isArray(methods) && methods.length > 0) {\n return true;\n }\n\n return false;\n}\n\nfunction isOutputErrorCode(value: unknown): value is OutputErrorCode {\n return typeof value === \"string\" && OUTPUT_ERROR_CODES.includes(value as OutputErrorCode);\n}\n\nfunction isOutputErrorOrigin(value: unknown): value is OutputErrorOrigin {\n return typeof value === \"string\" && OUTPUT_ERROR_ORIGINS.includes(value as OutputErrorOrigin);\n}\n\nfunction readOutputErrorMeta(error: unknown): ErrorMeta {\n const record = asRecord(error);\n if (!record) {\n return {};\n }\n\n const outputCode = isOutputErrorCode(record.outputCode) ? record.outputCode : undefined;\n const detailCode =\n typeof record.detailCode === \"string\" && record.detailCode.trim().length > 0\n ? record.detailCode\n : undefined;\n const origin = isOutputErrorOrigin(record.origin) ? record.origin : undefined;\n const retryable = typeof record.retryable === \"boolean\" ? record.retryable : undefined;\n\n const acp = extractAcpError(record.acp);\n return {\n outputCode,\n detailCode,\n origin,\n retryable,\n acp,\n };\n}\n\nfunction isTimeoutLike(error: unknown): boolean {\n return error instanceof Error && error.name === \"TimeoutError\";\n}\n\nfunction isNoSessionLike(error: unknown): boolean {\n return error instanceof Error && error.name === \"NoSessionError\";\n}\n\nfunction isUsageLike(error: unknown): boolean {\n if (!(error instanceof Error)) {\n return false;\n }\n return (\n error.name === \"CommanderError\" ||\n error.name === \"InvalidArgumentError\" ||\n asRecord(error)?.code === \"commander.invalidArgument\"\n );\n}\n\nexport function formatErrorMessage(error: unknown): string {\n return formatUnknownErrorMessage(error);\n}\n\nexport { extractAcpError, isAcpResourceNotFoundError };\n\nexport function isAcpQueryClosedBeforeResponseError(error: unknown): boolean {\n const acp = extractAcpError(error);\n if (!acp || acp.code !== -32603) {\n return false;\n }\n\n const data = asRecord(acp.data);\n const details = data?.details;\n if (typeof details !== \"string\") {\n return false;\n }\n\n return details.toLowerCase().includes(QUERY_CLOSED_BEFORE_RESPONSE_DETAIL);\n}\n\nfunction mapErrorCode(error: unknown): OutputErrorCode | undefined {\n if (error instanceof PermissionPromptUnavailableError) {\n return \"PERMISSION_PROMPT_UNAVAILABLE\";\n }\n if (error instanceof PermissionDeniedError) {\n return \"PERMISSION_DENIED\";\n }\n if (isTimeoutLike(error)) {\n return \"TIMEOUT\";\n }\n if (isNoSessionLike(error) || isAcpResourceNotFoundError(error)) {\n return \"NO_SESSION\";\n }\n if (isUsageLike(error)) {\n return \"USAGE\";\n }\n return undefined;\n}\n\nexport function normalizeOutputError(\n error: unknown,\n options: NormalizeOutputErrorOptions = {},\n): NormalizedOutputError {\n const meta = readOutputErrorMeta(error);\n const mapped = mapErrorCode(error);\n let code = mapped ?? options.defaultCode ?? \"RUNTIME\";\n\n if (meta.outputCode) {\n code = meta.outputCode;\n }\n\n if (code === \"RUNTIME\" && isAcpResourceNotFoundError(error)) {\n code = \"NO_SESSION\";\n }\n\n const acp = options.acp ?? meta.acp ?? extractAcpError(error);\n const detailCode =\n meta.detailCode ??\n options.detailCode ??\n (error instanceof AuthPolicyError || isAcpAuthRequiredPayload(acp)\n ? \"AUTH_REQUIRED\"\n : undefined);\n return {\n code,\n message: formatErrorMessage(error),\n detailCode,\n origin: meta.origin ?? options.origin,\n retryable: meta.retryable ?? options.retryable,\n acp,\n };\n}\n\n/**\n * Returns true when an error from `client.prompt()` looks transient and\n * can reasonably be retried (e.g. model-API 400/500, network hiccups that\n * surface as ACP internal errors).\n *\n * Errors that are definitively non-recoverable (auth, missing session,\n * invalid params, timeout, permission) return false.\n */\nexport function isRetryablePromptError(error: unknown): boolean {\n if (error instanceof PermissionDeniedError || error instanceof PermissionPromptUnavailableError) {\n return false;\n }\n if (isTimeoutLike(error) || isNoSessionLike(error) || isUsageLike(error)) {\n return false;\n }\n\n // Extract ACP payload once and reuse for all subsequent checks.\n const acp = extractAcpError(error);\n if (!acp) {\n // Non-ACP errors (e.g. process crash) are not retried at the prompt level.\n return false;\n }\n\n // Resource-not-found (session gone) — check using the already-extracted payload.\n if (acp.code === -32001 || acp.code === -32002) {\n return false;\n }\n\n // Auth-required errors are never retryable. Use the same thorough check as normalizeOutputError.\n if (isAcpAuthRequiredPayload(acp)) {\n return false;\n }\n\n // Method-not-found or invalid-params are permanent protocol errors.\n if (acp.code === -32601 || acp.code === -32602) {\n return false;\n }\n\n // ACP internal errors (-32603) typically wrap model-API failures → retryable.\n // Parse errors (-32700) can also be transient.\n return acp.code === -32603 || acp.code === -32700;\n}\n\nexport function exitCodeForOutputErrorCode(code: OutputErrorCode): ExitCode {\n switch (code) {\n case \"USAGE\":\n return EXIT_CODES.USAGE;\n case \"TIMEOUT\":\n return EXIT_CODES.TIMEOUT;\n case \"NO_SESSION\":\n return EXIT_CODES.NO_SESSION;\n case \"PERMISSION_DENIED\":\n case \"PERMISSION_PROMPT_UNAVAILABLE\":\n return EXIT_CODES.PERMISSION_DENIED;\n case \"RUNTIME\":\n default:\n return EXIT_CODES.ERROR;\n }\n}\n","import type { ContentBlock } from \"@agentclientprotocol/sdk\";\n\nexport type PromptInput = ContentBlock[];\n\nexport class PromptInputValidationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PromptInputValidationError\";\n }\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) {\n return undefined;\n }\n return value as Record<string, unknown>;\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\nfunction isBase64Data(value: string): boolean {\n if (value.length === 0 || value.length % 4 !== 0) {\n return false;\n }\n return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(value);\n}\n\nfunction isImageMimeType(value: string): boolean {\n return /^image\\/[A-Za-z0-9.+-]+$/i.test(value);\n}\n\nfunction isTextBlock(value: unknown): value is Extract<ContentBlock, { type: \"text\" }> {\n const record = asRecord(value);\n return record?.type === \"text\" && typeof record.text === \"string\";\n}\n\nfunction isImageBlock(value: unknown): value is Extract<ContentBlock, { type: \"image\" }> {\n const record = asRecord(value);\n return (\n record?.type === \"image\" &&\n isNonEmptyString(record.mimeType) &&\n isImageMimeType(record.mimeType) &&\n typeof record.data === \"string\" &&\n isBase64Data(record.data)\n );\n}\n\nfunction isResourceLinkBlock(\n value: unknown,\n): value is Extract<ContentBlock, { type: \"resource_link\" }> {\n const record = asRecord(value);\n return (\n record?.type === \"resource_link\" &&\n isNonEmptyString(record.uri) &&\n (record.title === undefined || typeof record.title === \"string\") &&\n (record.name === undefined || typeof record.name === \"string\")\n );\n}\n\nfunction isResourcePayload(value: unknown): boolean {\n const record = asRecord(value);\n if (!record || !isNonEmptyString(record.uri)) {\n return false;\n }\n return record.text === undefined || typeof record.text === \"string\";\n}\n\nfunction isResourceBlock(value: unknown): value is Extract<ContentBlock, { type: \"resource\" }> {\n const record = asRecord(value);\n return record?.type === \"resource\" && isResourcePayload(record.resource);\n}\n\nfunction isContentBlock(value: unknown): value is ContentBlock {\n return (\n isTextBlock(value) ||\n isImageBlock(value) ||\n isResourceLinkBlock(value) ||\n isResourceBlock(value)\n );\n}\n\nfunction getContentBlockValidationError(value: unknown, index: number): string | undefined {\n const record = asRecord(value);\n if (!record || typeof record.type !== \"string\") {\n return `prompt[${index}] must be an ACP content block object`;\n }\n\n switch (record.type) {\n case \"text\":\n return typeof record.text === \"string\"\n ? undefined\n : `prompt[${index}] text block must include a string text field`;\n case \"image\":\n if (!isNonEmptyString(record.mimeType)) {\n return `prompt[${index}] image block must include a non-empty mimeType`;\n }\n if (!isImageMimeType(record.mimeType)) {\n return `prompt[${index}] image block mimeType must start with image/`;\n }\n if (typeof record.data !== \"string\" || record.data.length === 0) {\n return `prompt[${index}] image block must include non-empty base64 data`;\n }\n if (!isBase64Data(record.data)) {\n return `prompt[${index}] image block data must be valid base64`;\n }\n return undefined;\n case \"resource_link\":\n if (!isNonEmptyString(record.uri)) {\n return `prompt[${index}] resource_link block must include a non-empty uri`;\n }\n if (record.title !== undefined && typeof record.title !== \"string\") {\n return `prompt[${index}] resource_link block title must be a string when present`;\n }\n if (record.name !== undefined && typeof record.name !== \"string\") {\n return `prompt[${index}] resource_link block name must be a string when present`;\n }\n return undefined;\n case \"resource\":\n if (!asRecord(record.resource)) {\n return `prompt[${index}] resource block must include a resource object`;\n }\n if (!isResourcePayload(record.resource)) {\n return `prompt[${index}] resource block resource must include a non-empty uri and optional text`;\n }\n return undefined;\n default:\n return `prompt[${index}] has unsupported content block type ${JSON.stringify(record.type)}`;\n }\n}\n\nexport function isPromptInput(value: unknown): value is PromptInput {\n return Array.isArray(value) && value.every((entry) => isContentBlock(entry));\n}\n\nexport function textPrompt(text: string): PromptInput {\n return [\n {\n type: \"text\",\n text,\n },\n ];\n}\n\nfunction parseStructuredPrompt(source: string): PromptInput | undefined {\n if (!source.startsWith(\"[\")) {\n return undefined;\n }\n try {\n const parsed = JSON.parse(source) as unknown;\n if (isPromptInput(parsed)) {\n return parsed;\n }\n if (Array.isArray(parsed)) {\n const detail =\n parsed\n .map((entry, index) => getContentBlockValidationError(entry, index))\n .find((message) => message !== undefined) ??\n \"Structured prompt JSON must be an array of valid ACP content blocks\";\n throw new PromptInputValidationError(detail);\n }\n return undefined;\n } catch (error) {\n if (error instanceof PromptInputValidationError) {\n throw error;\n }\n return undefined;\n }\n}\n\nexport function parsePromptSource(source: string): PromptInput {\n const trimmed = source.trim();\n const structured = parseStructuredPrompt(trimmed);\n if (structured) {\n return structured;\n }\n if (!trimmed) {\n return [];\n }\n return textPrompt(trimmed);\n}\n\nexport function mergePromptSourceWithText(source: string, suffixText: string): PromptInput {\n const prompt = parsePromptSource(source);\n const appended = suffixText.trim();\n if (!appended) {\n return prompt;\n }\n if (prompt.length === 0) {\n return textPrompt(appended);\n }\n return [...prompt, ...textPrompt(appended)];\n}\n\nexport function promptToDisplayText(prompt: PromptInput): string {\n return prompt\n .map((block) => {\n switch (block.type) {\n case \"text\":\n return block.text;\n case \"resource_link\":\n return block.title ?? block.name ?? block.uri;\n case \"resource\":\n return \"text\" in block.resource && typeof block.resource.text === \"string\"\n ? block.resource.text\n : block.resource.uri;\n case \"image\":\n return `[image] ${block.mimeType}`;\n default:\n return \"\";\n }\n })\n .filter((entry) => entry.trim().length > 0)\n .join(\"\\n\\n\")\n .trim();\n}\n","const AGENT_SESSION_ID_META_KEYS = [\"agentSessionId\", \"sessionId\"] as const;\n\nexport function normalizeAgentSessionId(value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return undefined;\n }\n\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction asMetaRecord(meta: unknown): Record<string, unknown> | undefined {\n if (!meta || typeof meta !== \"object\" || Array.isArray(meta)) {\n return undefined;\n }\n return meta as Record<string, unknown>;\n}\n\nexport function extractAgentSessionId(meta: unknown): string | undefined {\n const record = asMetaRecord(meta);\n if (!record) {\n return undefined;\n }\n\n for (const key of AGENT_SESSION_ID_META_KEYS) {\n const normalized = normalizeAgentSessionId(record[key]);\n if (normalized) {\n return normalized;\n }\n }\n\n return undefined;\n}\n\nexport { AGENT_SESSION_ID_META_KEYS };\n","import {\n AGENT_SESSION_ID_META_KEYS,\n extractAgentSessionId,\n normalizeAgentSessionId,\n} from \"../acp/agent-session-id.js\";\n\nexport const RUNTIME_SESSION_ID_META_KEYS = AGENT_SESSION_ID_META_KEYS;\n\nexport function normalizeRuntimeSessionId(value: unknown): string | undefined {\n return normalizeAgentSessionId(value);\n}\n\nexport function extractRuntimeSessionId(meta: unknown): string | undefined {\n return extractAgentSessionId(meta);\n}\n","import type { PerfMetricsSnapshot } from \"./types.js\";\n\ntype TimingBucket = {\n count: number;\n totalMs: number;\n maxMs: number;\n};\n\nconst counters = new Map<string, number>();\nconst gauges = new Map<string, number>();\nconst timings = new Map<string, TimingBucket>();\n\nfunction hrNow(): bigint {\n return process.hrtime.bigint();\n}\n\nfunction durationMs(start: bigint): number {\n return Number(process.hrtime.bigint() - start) / 1_000_000;\n}\n\nfunction roundMetric(value: number): number {\n return Number(value.toFixed(3));\n}\n\nexport function incrementPerfCounter(name: string, delta = 1): void {\n counters.set(name, (counters.get(name) ?? 0) + delta);\n}\n\nexport function setPerfGauge(name: string, value: number): void {\n gauges.set(name, value);\n}\n\nexport function recordPerfDuration(name: string, durationMsValue: number): void {\n const next = timings.get(name) ?? {\n count: 0,\n totalMs: 0,\n maxMs: 0,\n };\n next.count += 1;\n next.totalMs += durationMsValue;\n next.maxMs = Math.max(next.maxMs, durationMsValue);\n timings.set(name, next);\n}\n\nexport async function measurePerf<T>(name: string, run: () => Promise<T>): Promise<T> {\n const startedAt = hrNow();\n try {\n return await run();\n } finally {\n recordPerfDuration(name, durationMs(startedAt));\n }\n}\n\nexport function startPerfTimer(name: string): () => number {\n const startedAt = hrNow();\n return () => {\n const elapsedMs = durationMs(startedAt);\n recordPerfDuration(name, elapsedMs);\n return elapsedMs;\n };\n}\n\nexport function getPerfMetricsSnapshot(): PerfMetricsSnapshot {\n return {\n counters: Object.fromEntries(counters.entries()),\n gauges: Object.fromEntries(gauges.entries()),\n timings: Object.fromEntries(\n [...timings.entries()].map(([name, bucket]) => [\n name,\n {\n count: bucket.count,\n totalMs: roundMetric(bucket.totalMs),\n maxMs: roundMetric(bucket.maxMs),\n },\n ]),\n ),\n };\n}\n\nexport function resetPerfMetrics(): void {\n counters.clear();\n gauges.clear();\n timings.clear();\n}\n\nexport function formatPerfMetric(name: string, durationMsValue: number): string {\n return `${name}=${roundMetric(durationMsValue)}ms`;\n}\n"],"mappings":";AAWA,IAAa,uBAAb,cAA0C,MAAM;CAC9C;CACA;CACA;CACA;CACA;CACA;CAEA,YAAY,SAAiB,SAA4B;AACvD,QAAM,SAAS,QAAQ;AACvB,OAAK,OAAO,IAAI,OAAO;AACvB,OAAK,aAAa,SAAS;AAC3B,OAAK,aAAa,SAAS;AAC3B,OAAK,SAAS,SAAS;AACvB,OAAK,YAAY,SAAS;AAC1B,OAAK,MAAM,SAAS;AACpB,OAAK,uBAAuB,SAAS;;;AAIzC,IAAa,uBAAb,cAA0C,qBAAqB;CAC7D;CAEA,YAAY,WAAmB;AAC7B,QAAM,sBAAsB,YAAY;AACxC,OAAK,YAAY;;;AAI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G,QAAQ,SAAS,CAAC,CAAC,KAAK,CAAC,MAAM,YAAY,CAC7C,MACA;GACE,OAAO,OAAO;GACd,SAAS,YAAY,OAAO,QAAQ;GACpC,OAAO,YAAY,OAAO,MAAM;GACjC,CACF,CAAC,CACH;EACF;;AAGH,SAAgB,mBAAyB;AACvC,UAAS,OAAO;AAChB,QAAO,OAAO;AACd,SAAQ,OAAO;;AAGjB,SAAgB,iBAAiB,MAAc,iBAAiC;AAC9E,QAAO,GAAG,KAAK,GAAG,YAAY,gBAAgB,CAAC"}
|
|
@@ -477,6 +477,7 @@ function parseAcpxState(raw) {
|
|
|
477
477
|
const record = asRecord$3(raw);
|
|
478
478
|
if (!record) return;
|
|
479
479
|
const state = {};
|
|
480
|
+
if (record.reset_on_next_ensure === true) state.reset_on_next_ensure = true;
|
|
480
481
|
if (typeof record.current_mode_id === "string") state.current_mode_id = record.current_mode_id;
|
|
481
482
|
if (typeof record.desired_mode_id === "string") state.desired_mode_id = record.desired_mode_id;
|
|
482
483
|
if (typeof record.current_model_id === "string") state.current_model_id = record.current_model_id;
|
|
@@ -1953,6 +1954,9 @@ var AcpClient = class {
|
|
|
1953
1954
|
supportsLoadSession() {
|
|
1954
1955
|
return Boolean(this.initResult?.agentCapabilities?.loadSession);
|
|
1955
1956
|
}
|
|
1957
|
+
supportsCloseSession() {
|
|
1958
|
+
return Boolean(this.initResult?.agentCapabilities?.sessionCapabilities?.close);
|
|
1959
|
+
}
|
|
1956
1960
|
setEventHandlers(handlers) {
|
|
1957
1961
|
this.eventHandlers = { ...handlers };
|
|
1958
1962
|
}
|
|
@@ -2249,6 +2253,11 @@ var AcpClient = class {
|
|
|
2249
2253
|
this.cancellingSessionIds.add(sessionId);
|
|
2250
2254
|
await this.runConnectionRequest(() => connection.cancel({ sessionId }));
|
|
2251
2255
|
}
|
|
2256
|
+
async closeSession(sessionId) {
|
|
2257
|
+
const connection = this.getConnection();
|
|
2258
|
+
await this.runConnectionRequest(() => connection.unstable_closeSession({ sessionId }));
|
|
2259
|
+
if (this.loadedSessionId === sessionId) this.loadedSessionId = void 0;
|
|
2260
|
+
}
|
|
2252
2261
|
async requestCancelActivePrompt() {
|
|
2253
2262
|
const active = this.activePrompt;
|
|
2254
2263
|
if (!active) return false;
|
|
@@ -3349,4 +3358,4 @@ async function runPromptTurn(params) {
|
|
|
3349
3358
|
//#endregion
|
|
3350
3359
|
export { resolveSessionRecord as A, serializeSessionRecordForDisk as B, findGitRepositoryRoot as C, listSessions as D, isoNow$2 as E, sessionBaseDir$1 as F, DEFAULT_AGENT_NAME as G, TimeoutError as H, sessionEventActivePath as I, resolveAgentCommand as J, listBuiltInAgents as K, sessionEventLockPath as L, parseSessionRecord as M, DEFAULT_EVENT_SEGMENT_MAX_BYTES as N, listSessionsForAgent as O, defaultSessionEventLog as P, sessionEventSegmentPath as R, absolutePath as S, findSessionByDirectoryWalk as T, withInterrupt as U, InterruptedError as V, withTimeout as W, recordSessionUpdate as _, applyConversation as a, permissionModeSatisfies as b, setCurrentModelId as c, syncAdvertisedModelState as d, cloneSessionAcpxState as f, recordPromptSubmission as g, recordClientOperation as h, connectAndLoadSession as i, writeSessionRecord as j, normalizeName as k, setDesiredModeId as l, createSessionConversation as m, withConnectedSession as n, applyLifecycleSnapshotToRecord as o, cloneSessionConversation as p, normalizeAgentName$1 as q, sessionOptionsFromRecord as r, reconcileAgentSessionId as s, runPromptTurn as t, setDesiredModelId as u, trimConversationForRuntime as v, findSession as w, DEFAULT_HISTORY_LIMIT as x, AcpClient as y, assertPersistedKeyPolicy as z };
|
|
3351
3360
|
|
|
3352
|
-
//# sourceMappingURL=prompt-turn-
|
|
3361
|
+
//# sourceMappingURL=prompt-turn-CXMtXBl-.js.map
|