@andorra-labs/code 0.1.12 → 0.1.14
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/src/account-presentation.d.ts +1 -37
- package/dist/src/account-presentation.js +6 -43
- package/dist/src/activity.d.ts +0 -25
- package/dist/src/activity.js +1 -23
- package/dist/src/agent-definitions.d.ts +0 -26
- package/dist/src/agent-definitions.js +0 -43
- package/dist/src/agent-execution.d.ts +0 -2
- package/dist/src/agent-execution.js +347 -554
- package/dist/src/agent-mcp-catalog.d.ts +0 -8
- package/dist/src/agent-mcp-catalog.js +0 -2
- package/dist/src/agent-mcp.d.ts +0 -56
- package/dist/src/agent-mcp.js +11 -155
- package/dist/src/agent-modifiers.d.ts +0 -1
- package/dist/src/agent-modifiers.js +25 -68
- package/dist/src/analytics.d.ts +0 -66
- package/dist/src/analytics.js +0 -45
- package/dist/src/andorra/endpoint.d.ts +7 -0
- package/dist/src/andorra/endpoint.js +46 -0
- package/dist/src/andorra/entry.d.ts +21 -0
- package/dist/src/andorra/entry.js +100 -0
- package/dist/src/andorra/errors.d.ts +2 -0
- package/dist/src/andorra/errors.js +39 -0
- package/dist/src/andorra/hosted.d.ts +52 -0
- package/dist/src/andorra/hosted.js +126 -0
- package/dist/src/andorra/monitor.d.ts +151 -0
- package/dist/src/andorra/monitor.js +393 -0
- package/dist/src/andorra/notices.d.ts +7 -0
- package/dist/src/andorra/notices.js +15 -0
- package/dist/src/andorra/opt-in.d.ts +58 -0
- package/dist/src/andorra/opt-in.js +112 -0
- package/dist/src/andorra/request-watch.d.ts +6 -0
- package/dist/src/andorra/request-watch.js +10 -0
- package/dist/src/andorra/state.d.ts +86 -0
- package/dist/src/andorra/state.js +238 -0
- package/dist/src/andorra/terminal.d.ts +68 -0
- package/dist/src/andorra/terminal.js +125 -0
- package/dist/src/andorra/usage-format.d.ts +9 -0
- package/dist/src/andorra/usage-format.js +19 -0
- package/dist/src/anthropic-console-auth.d.ts +0 -24
- package/dist/src/anthropic-console-auth.js +0 -37
- package/dist/src/anthropic-credentials.d.ts +0 -25
- package/dist/src/anthropic-credentials.js +9 -29
- package/dist/src/app-server/protocol.d.ts +18 -246
- package/dist/src/app-server/protocol.js +1 -132
- package/dist/src/app-server/reasoning.d.ts +0 -31
- package/dist/src/app-server/reasoning.js +0 -54
- package/dist/src/app-server/terminal.d.ts +0 -36
- package/dist/src/app-server/terminal.js +3 -39
- package/dist/src/app-server/workspace.d.ts +0 -167
- package/dist/src/app-server/workspace.js +4 -406
- package/dist/src/app-server.d.ts +52 -925
- package/dist/src/app-server.js +828 -3076
- package/dist/src/artifacts.d.ts +0 -10
- package/dist/src/artifacts.js +1 -11
- package/dist/src/attachments.d.ts +4 -98
- package/dist/src/attachments.js +10 -130
- package/dist/src/auth/AuthManager.d.ts +9 -93
- package/dist/src/auth/AuthManager.js +164 -186
- package/dist/src/auth/callback-page.d.ts +0 -1
- package/dist/src/auth/callback-page.js +0 -4
- package/dist/src/auth/callback.d.ts +0 -25
- package/dist/src/auth/callback.js +1 -29
- package/dist/src/auth/deployment.d.ts +1 -16
- package/dist/src/auth/deployment.js +1 -16
- package/dist/src/auth/index.d.ts +1 -12
- package/dist/src/auth/index.js +1 -12
- package/dist/src/auth/lock.d.ts +0 -1
- package/dist/src/auth/lock.js +0 -1
- package/dist/src/auth/store.d.ts +33 -108
- package/dist/src/auth/store.js +55 -130
- package/dist/src/auth/types.d.ts +0 -8
- package/dist/src/auth-commands.d.ts +0 -5
- package/dist/src/auth-commands.js +0 -1
- package/dist/src/automation-runner.d.ts +0 -9
- package/dist/src/automation-runner.js +0 -11
- package/dist/src/automation-service.d.ts +0 -10
- package/dist/src/automation-service.js +3 -17
- package/dist/src/automation-tool.js +0 -5
- package/dist/src/automation-worker-shutdown.d.ts +0 -1
- package/dist/src/automation-worker-shutdown.js +0 -3
- package/dist/src/automations.d.ts +23 -2
- package/dist/src/automations.js +91 -12
- package/dist/src/background-tasks.d.ts +0 -23
- package/dist/src/background-tasks.js +0 -11
- package/dist/src/boot-trace.d.ts +0 -13
- package/dist/src/boot-trace.js +1 -14
- package/dist/src/browser-activity.js +0 -2
- package/dist/src/browser-bridge.d.ts +0 -2
- package/dist/src/browser-bridge.js +0 -27
- package/dist/src/browser-captcha-tool.d.ts +0 -13
- package/dist/src/browser-captcha-tool.js +3 -35
- package/dist/src/browser-extensions-tool.d.ts +24 -0
- package/dist/src/browser-extensions-tool.js +137 -0
- package/dist/src/browser-extensions.d.ts +127 -0
- package/dist/src/browser-extensions.js +729 -0
- package/dist/src/browser-observation.d.ts +0 -15
- package/dist/src/browser-observation.js +1 -22
- package/dist/src/browser-panel-tool.d.ts +1 -37
- package/dist/src/browser-panel-tool.js +3 -73
- package/dist/src/browser-runner.d.ts +0 -1
- package/dist/src/browser-runner.js +5 -46
- package/dist/src/browser-server.d.ts +0 -6
- package/dist/src/browser-server.js +6 -229
- package/dist/src/browser-session.d.ts +0 -25
- package/dist/src/browser-session.js +1 -71
- package/dist/src/browser-stealth.d.ts +19 -13
- package/dist/src/browser-stealth.js +22 -38
- package/dist/src/browser-ui/app.js +7 -174
- package/dist/src/browser-ui/style.css +0 -68
- package/dist/src/browser-ui/tokens.css +15 -97
- package/dist/src/browser-view.d.ts +106 -295
- package/dist/src/browser-view.js +551 -587
- package/dist/src/capabilities.d.ts +0 -8
- package/dist/src/capabilities.js +0 -29
- package/dist/src/capsolver.d.ts +0 -13
- package/dist/src/capsolver.js +0 -15
- package/dist/src/clarification-ui.d.ts +0 -7
- package/dist/src/clarification-ui.js +0 -8
- package/dist/src/claude-executable.d.ts +0 -1
- package/dist/src/claude-executable.js +1 -2
- package/dist/src/claude-provider.d.ts +6 -19
- package/dist/src/claude-provider.js +155 -63
- package/dist/src/cli-executable.d.ts +0 -16
- package/dist/src/cli-executable.js +0 -7
- package/dist/src/cli-process.d.ts +0 -26
- package/dist/src/cli-process.js +0 -18
- package/dist/src/cli-sign-in.d.ts +0 -20
- package/dist/src/cli-sign-in.js +1 -17
- package/dist/src/cli.d.ts +1 -55
- package/dist/src/cli.js +118 -742
- package/dist/src/code-intelligence/CodeIntelligenceManager.d.ts +4 -59
- package/dist/src/code-intelligence/CodeIntelligenceManager.js +26 -99
- package/dist/src/code-intelligence/ContextLedger.d.ts +0 -4
- package/dist/src/code-intelligence/ContextLedger.js +0 -10
- package/dist/src/code-intelligence/ContextRouter.d.ts +0 -6
- package/dist/src/code-intelligence/ContextRouter.js +0 -8
- package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.d.ts +0 -2
- package/dist/src/code-intelligence/codegraph/CodeGraphProjectSession.js +5 -12
- package/dist/src/code-intelligence/codegraph/CodeGraphProvider.d.ts +0 -6
- package/dist/src/code-intelligence/codegraph/CodeGraphProvider.js +0 -6
- package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.d.ts +0 -5
- package/dist/src/code-intelligence/codegraph/CodeGraphSyncBarrier.js +1 -17
- package/dist/src/code-intelligence/codegraph/repoExploreTool.d.ts +0 -5
- package/dist/src/code-intelligence/codegraph/repoExploreTool.js +0 -5
- package/dist/src/code-intelligence/repository.d.ts +0 -9
- package/dist/src/code-intelligence/repository.js +1 -11
- package/dist/src/code-intelligence/types.d.ts +0 -8
- package/dist/src/codex-auth.d.ts +0 -44
- package/dist/src/codex-auth.js +0 -45
- package/dist/src/codex-browser-auth.d.ts +0 -13
- package/dist/src/codex-browser-auth.js +3 -20
- package/dist/src/codex-errors.js +0 -2
- package/dist/src/codex-executable.d.ts +0 -2
- package/dist/src/codex-executable.js +1 -7
- package/dist/src/codex-provider.d.ts +0 -13
- package/dist/src/codex-provider.js +0 -28
- package/dist/src/codex-rpc.d.ts +0 -10
- package/dist/src/codex-rpc.js +0 -12
- package/dist/src/coding-tools.d.ts +4 -26
- package/dist/src/coding-tools.js +161 -181
- package/dist/src/command-metrics.d.ts +0 -4
- package/dist/src/command-output-tap.d.ts +0 -11
- package/dist/src/command-output-tap.js +0 -3
- package/dist/src/command-screens.d.ts +41 -1
- package/dist/src/command-screens.js +316 -113
- package/dist/src/commands.d.ts +12 -63
- package/dist/src/commands.js +98 -127
- package/dist/src/completion-gates.d.ts +0 -47
- package/dist/src/completion-gates.js +0 -14
- package/dist/src/completion.d.ts +0 -98
- package/dist/src/completion.js +2 -239
- package/dist/src/config.d.ts +15 -115
- package/dist/src/config.js +123 -172
- package/dist/src/context-budget.d.ts +0 -22
- package/dist/src/context-budget.js +0 -44
- package/dist/src/context-compaction.d.ts +29 -6
- package/dist/src/context-compaction.js +94 -25
- package/dist/src/context-selection.d.ts +0 -24
- package/dist/src/context-selection.js +0 -34
- package/dist/src/dashboard-view.d.ts +2 -2
- package/dist/src/dashboard-view.js +11 -37
- package/dist/src/dashboard.d.ts +0 -2
- package/dist/src/dashboard.js +0 -9
- package/dist/src/deadline.d.ts +0 -45
- package/dist/src/deadline.js +0 -54
- package/dist/src/decision/ContinuationAdapter.d.ts +0 -5
- package/dist/src/decision/ContinuationAdapter.js +0 -5
- package/dist/src/decision/DecisionEngine.d.ts +0 -4
- package/dist/src/decision/DecisionManager.d.ts +0 -1
- package/dist/src/decision/DecisionManager.js +2 -7
- package/dist/src/decision/DecisionPolicy.d.ts +0 -1
- package/dist/src/decision/DecisionPolicy.js +0 -1
- package/dist/src/decision/FactContinuations.d.ts +11 -43
- package/dist/src/decision/FactContinuations.js +126 -95
- package/dist/src/decision/FactServiceGate.d.ts +0 -1
- package/dist/src/decision/FactServiceGate.js +0 -4
- package/dist/src/decision/PreparedSteps.d.ts +0 -15
- package/dist/src/decision/PreparedSteps.js +1 -11
- package/dist/src/decision/applyToolMenu.d.ts +0 -1
- package/dist/src/decision/applyToolMenu.js +2 -6
- package/dist/src/decision/checks.d.ts +15 -28
- package/dist/src/decision/checks.js +118 -49
- package/dist/src/decision/facts.d.ts +0 -16
- package/dist/src/decision/facts.js +0 -30
- package/dist/src/decision/guidancePolicy.js +0 -1
- package/dist/src/decision/hostedPolicy.d.ts +0 -6
- package/dist/src/decision/hostedPolicy.js +0 -7
- package/dist/src/decision/hostedSkills.d.ts +0 -19
- package/dist/src/decision/hostedSkills.js +0 -19
- package/dist/src/decision/optimizationPolicy.d.ts +0 -3
- package/dist/src/decision/optimizationPolicy.js +1 -4
- package/dist/src/decision/providers/AndorraDecisionProvider.d.ts +0 -7
- package/dist/src/decision/providers/AndorraDecisionProvider.js +4 -27
- package/dist/src/decision/providers/HttpDecisionProvider.d.ts +0 -2
- package/dist/src/decision/providers/HttpDecisionProvider.js +0 -6
- package/dist/src/decision/routeTools.d.ts +0 -8
- package/dist/src/decision/routeTools.js +1 -8
- package/dist/src/decision/toolFamilies.d.ts +0 -1
- package/dist/src/decision/toolFamilies.js +1 -2
- package/dist/src/decision/toolMenu.d.ts +0 -3
- package/dist/src/decision/toolMenu.js +0 -4
- package/dist/src/decision/types.d.ts +1 -6
- package/dist/src/default-graph.d.ts +0 -9
- package/dist/src/default-graph.js +0 -9
- package/dist/src/delegation-changes.d.ts +0 -56
- package/dist/src/delegation-changes.js +4 -130
- package/dist/src/diff-preview.d.ts +0 -1
- package/dist/src/diff-preview.js +0 -17
- package/dist/src/duration.d.ts +0 -50
- package/dist/src/duration.js +0 -50
- package/dist/src/efficiency.d.ts +0 -39
- package/dist/src/efficiency.js +0 -16
- package/dist/src/engine/protocol.d.ts +0 -2
- package/dist/src/engine/protocol.js +0 -2
- package/dist/src/engine-streams.d.ts +0 -9
- package/dist/src/extensions.d.ts +3 -2
- package/dist/src/extensions.js +63 -35
- package/dist/src/favicons.d.ts +0 -26
- package/dist/src/favicons.js +0 -34
- package/dist/src/file-diff.d.ts +2 -58
- package/dist/src/file-diff.js +0 -32
- package/dist/src/file-read-key.d.ts +0 -7
- package/dist/src/file-read-key.js +0 -7
- package/dist/src/file-read-state.d.ts +0 -1
- package/dist/src/file-read-state.js +0 -4
- package/dist/src/firefox-cookies.d.ts +0 -34
- package/dist/src/firefox-cookies.js +1 -55
- package/dist/src/git-identity-audit.d.ts +27 -0
- package/dist/src/git-identity-audit.js +286 -0
- package/dist/src/git-identity-guard.d.ts +4 -0
- package/dist/src/git-identity-guard.js +998 -0
- package/dist/src/git-identity-hold.d.ts +12 -0
- package/dist/src/git-identity-hold.js +81 -0
- package/dist/src/git-summary.d.ts +0 -58
- package/dist/src/git-summary.js +2 -212
- package/dist/src/goal-completion-verification.d.ts +2 -2
- package/dist/src/goal-completion-verification.js +3 -6
- package/dist/src/graph-account.d.ts +0 -21
- package/dist/src/graph-account.js +0 -17
- package/dist/src/graph-editor-session.d.ts +0 -1
- package/dist/src/graph-editor-session.js +0 -3
- package/dist/src/graph-health.d.ts +9 -61
- package/dist/src/graph-health.js +34 -59
- package/dist/src/graph-manager-chat.d.ts +36 -153
- package/dist/src/graph-manager-chat.js +161 -182
- package/dist/src/graph-provider-portability.d.ts +1 -21
- package/dist/src/graph-provider-portability.js +6 -45
- package/dist/src/graph-quota.d.ts +0 -33
- package/dist/src/graph-quota.js +1 -44
- package/dist/src/graph-runner.d.ts +0 -1
- package/dist/src/graph-runner.js +58 -391
- package/dist/src/graph-selection.d.ts +0 -14
- package/dist/src/graph-selection.js +2 -15
- package/dist/src/graph-server.d.ts +2 -10
- package/dist/src/graph-server.js +39 -101
- package/dist/src/graph-studio-features.d.ts +0 -5
- package/dist/src/graph-studio-features.js +2 -42
- package/dist/src/graph-sync.d.ts +0 -78
- package/dist/src/graph-sync.js +5 -201
- package/dist/src/graph-tool.d.ts +0 -18
- package/dist/src/graph-tool.js +0 -27
- package/dist/src/graph-ui/app.js +176 -492
- package/dist/src/graph-ui/compat.js +0 -7
- package/dist/src/graph-ui/controls.css +0 -48
- package/dist/src/graph-ui/controls.js +0 -88
- package/dist/src/graph-ui/drafts.js +0 -12
- package/dist/src/graph-ui/edge-router.js +0 -62
- package/dist/src/graph-ui/embed.js +0 -59
- package/dist/src/graph-ui/icons.js +0 -8
- package/dist/src/graph-ui/library.css +0 -5
- package/dist/src/graph-ui/manager-markdown.js +0 -11
- package/dist/src/graph-ui/manager-state.js +1 -78
- package/dist/src/graph-ui/manager.css +0 -18
- package/dist/src/graph-ui/manager.js +43 -185
- package/dist/src/graph-ui/model-picker.js +0 -29
- package/dist/src/graph-ui/sidebar.js +2 -3
- package/dist/src/graph-ui/skill-picker.js +373 -39
- package/dist/src/graph-ui/studio-canvas.js +3 -38
- package/dist/src/graph-ui/studio.css +0 -18
- package/dist/src/graph-ui/studio.js +3 -71
- package/dist/src/graph-ui/style.css +16 -136
- package/dist/src/graph-ui/theme.js +1 -26
- package/dist/src/graph-ui/tokens.css +19 -118
- package/dist/src/graphs.d.ts +6 -157
- package/dist/src/graphs.js +66 -269
- package/dist/src/grep-regex-worker.js +0 -2
- package/dist/src/grep-regex.d.ts +1 -5
- package/dist/src/grep-regex.js +6 -8
- package/dist/src/grok-provider.d.ts +0 -17
- package/dist/src/grok-provider.js +1 -26
- package/dist/src/handoffs.d.ts +0 -11
- package/dist/src/handoffs.js +0 -13
- package/dist/src/hardened-runtime.d.ts +0 -10
- package/dist/src/hardened-runtime.js +9 -47
- package/dist/src/harness-home.d.ts +21 -0
- package/dist/src/harness-home.js +87 -0
- package/dist/src/host-process-guard.d.ts +0 -50
- package/dist/src/host-process-guard.js +0 -641
- package/dist/src/limits.d.ts +0 -64
- package/dist/src/limits.js +0 -62
- package/dist/src/managed-sign-in.d.ts +0 -12
- package/dist/src/managed-sign-in.js +0 -16
- package/dist/src/markdown.d.ts +0 -28
- package/dist/src/markdown.js +1 -175
- package/dist/src/mcp.d.ts +0 -99
- package/dist/src/mcp.js +4 -170
- package/dist/src/membership-errors.d.ts +0 -14
- package/dist/src/membership-errors.js +1 -14
- package/dist/src/membership.d.ts +9 -59
- package/dist/src/membership.js +20 -91
- package/dist/src/memory/LocalToolMemory.d.ts +0 -1
- package/dist/src/memory/LocalToolMemory.js +2 -7
- package/dist/src/memory/MemoryDistiller.js +0 -15
- package/dist/src/memory/MemoryManager.d.ts +0 -3
- package/dist/src/memory/MemoryManager.js +6 -18
- package/dist/src/memory/MemoryPolicy.d.ts +0 -2
- package/dist/src/memory/MemoryPolicy.js +0 -2
- package/dist/src/memory/MemoryProvider.d.ts +0 -6
- package/dist/src/memory/MemoryRetriever.js +0 -7
- package/dist/src/memory/PermissionMemoryProvider.d.ts +0 -1
- package/dist/src/memory/PermissionMemoryProvider.js +0 -1
- package/dist/src/memory/ProjectMemory.d.ts +5 -40
- package/dist/src/memory/ProjectMemory.js +22 -47
- package/dist/src/memory/ToolFailureLessons.d.ts +0 -3
- package/dist/src/memory/ToolFailureLessons.js +0 -6
- package/dist/src/memory/providers/NoOpMemoryProvider.d.ts +0 -1
- package/dist/src/memory/providers/NoOpMemoryProvider.js +0 -1
- package/dist/src/memory/redaction.d.ts +0 -5
- package/dist/src/memory/redaction.js +0 -11
- package/dist/src/memory/repository.d.ts +0 -6
- package/dist/src/memory/repository.js +2 -12
- package/dist/src/memory/types.d.ts +0 -1
- package/dist/src/model-context-windows.d.ts +2 -0
- package/dist/src/model-context-windows.js +24 -0
- package/dist/src/model-health-cache.d.ts +0 -38
- package/dist/src/model-health-cache.js +2 -50
- package/dist/src/model-metadata.d.ts +1 -18
- package/dist/src/model-metadata.js +42 -45
- package/dist/src/model-override.d.ts +0 -36
- package/dist/src/model-override.js +0 -43
- package/dist/src/model-tiers.d.ts +0 -13
- package/dist/src/model-tiers.js +0 -23
- package/dist/src/opencode-catalog.d.ts +0 -2
- package/dist/src/opencode-catalog.js +0 -11
- package/dist/src/opencode-cli-provider.d.ts +0 -35
- package/dist/src/opencode-cli-provider.js +1 -44
- package/dist/src/opencode-provider.d.ts +0 -2
- package/dist/src/opencode-provider.js +1 -16
- package/dist/src/package-name.d.ts +0 -2
- package/dist/src/package-name.js +0 -2
- package/dist/src/paged-transcript.d.ts +0 -11
- package/dist/src/paged-transcript.js +2 -20
- package/dist/src/palette.d.ts +1 -63
- package/dist/src/palette.js +1 -64
- package/dist/src/permissions.d.ts +0 -15
- package/dist/src/permissions.js +17 -21
- package/dist/src/powershell-pool.d.ts +0 -9
- package/dist/src/powershell-pool.js +3 -26
- package/dist/src/process-warnings.d.ts +4 -0
- package/dist/src/process-warnings.js +103 -0
- package/dist/src/profile.d.ts +0 -43
- package/dist/src/profile.js +0 -43
- package/dist/src/project-reservation.d.ts +11 -0
- package/dist/src/project-reservation.js +143 -0
- package/dist/src/provider-connection.d.ts +0 -18
- package/dist/src/provider-connection.js +15 -39
- package/dist/src/provider-engine.d.ts +0 -21
- package/dist/src/provider-engine.js +1 -96
- package/dist/src/provider-import.d.ts +0 -49
- package/dist/src/provider-import.js +0 -60
- package/dist/src/provider-keys.d.ts +1 -36
- package/dist/src/provider-keys.js +5 -48
- package/dist/src/provider-settings.d.ts +16 -3
- package/dist/src/provider-settings.js +36 -52
- package/dist/src/providers.d.ts +14 -219
- package/dist/src/providers.js +69 -326
- package/dist/src/pull-requests.d.ts +0 -173
- package/dist/src/pull-requests.js +5 -195
- package/dist/src/qa/browser/PlaywrightRunner.d.ts +0 -7
- package/dist/src/qa/browser/PlaywrightRunner.js +2 -16
- package/dist/src/qa/command-policy.d.ts +0 -23
- package/dist/src/qa/command-policy.js +0 -30
- package/dist/src/qa/guidance.d.ts +0 -21
- package/dist/src/qa/guidance.js +0 -20
- package/dist/src/qa/profile/ProjectInspector.d.ts +0 -4
- package/dist/src/qa/profile/ProjectInspector.js +0 -6
- package/dist/src/qa/profile/QaConfigLoader.d.ts +0 -7
- package/dist/src/qa/profile/QaConfigLoader.js +0 -6
- package/dist/src/qa/profile/QaProfile.d.ts +0 -7
- package/dist/src/qa/profile/QaProfile.js +0 -7
- package/dist/src/qa/profile/yaml.d.ts +0 -9
- package/dist/src/qa/profile/yaml.js +0 -13
- package/dist/src/qa/qa-authorize.d.ts +0 -19
- package/dist/src/qa/qa-authorize.js +4 -11
- package/dist/src/qa/runtime/ProcessManager.d.ts +0 -31
- package/dist/src/qa/runtime/ProcessManager.js +4 -41
- package/dist/src/qa/runtime/PtyManager.d.ts +0 -4
- package/dist/src/qa/runtime/PtyManager.js +1 -7
- package/dist/src/qa/runtime/changes.d.ts +0 -11
- package/dist/src/qa/runtime/changes.js +1 -3
- package/dist/src/qa/tools.d.ts +0 -10
- package/dist/src/qa/tools.js +0 -12
- package/dist/src/qa/types.d.ts +0 -13
- package/dist/src/react-runtime.d.ts +2 -21
- package/dist/src/react-runtime.js +107 -422
- package/dist/src/read-document-doc.d.ts +0 -6
- package/dist/src/read-document-doc.js +0 -55
- package/dist/src/read-document-docx.d.ts +0 -16
- package/dist/src/read-document-docx.js +2 -69
- package/dist/src/read-document-text.d.ts +0 -17
- package/dist/src/read-document-text.js +0 -22
- package/dist/src/read-document-tool.d.ts +0 -31
- package/dist/src/read-document-tool.js +0 -30
- package/dist/src/read-document.d.ts +0 -49
- package/dist/src/read-document.js +1 -67
- package/dist/src/read-image.d.ts +0 -32
- package/dist/src/read-image.js +0 -33
- package/dist/src/remote/cert.d.ts +0 -18
- package/dist/src/remote/cert.js +0 -44
- package/dist/src/remote/client.d.ts +0 -70
- package/dist/src/remote/client.js +1 -116
- package/dist/src/remote/command.js +0 -17
- package/dist/src/remote/engine-pool.d.ts +0 -152
- package/dist/src/remote/engine-pool.js +22 -339
- package/dist/src/remote/errors.d.ts +0 -15
- package/dist/src/remote/errors.js +0 -7
- package/dist/src/remote/network.d.ts +0 -26
- package/dist/src/remote/network.js +1 -34
- package/dist/src/remote/pairing.d.ts +16 -51
- package/dist/src/remote/pairing.js +50 -57
- package/dist/src/remote/pem.d.ts +0 -4
- package/dist/src/remote/pem.js +0 -4
- package/dist/src/remote/roots.d.ts +0 -20
- package/dist/src/remote/roots.js +0 -8
- package/dist/src/remote/serve.d.ts +0 -47
- package/dist/src/remote/serve.js +0 -30
- package/dist/src/remote/server.d.ts +0 -14
- package/dist/src/remote/server.js +1 -79
- package/dist/src/remote/types.d.ts +1 -32
- package/dist/src/remote/types.js +0 -10
- package/dist/src/run-control.d.ts +2 -9
- package/dist/src/run-control.js +9 -13
- package/dist/src/run-progress.d.ts +0 -170
- package/dist/src/run-progress.js +0 -285
- package/dist/src/run-records.d.ts +0 -443
- package/dist/src/run-records.js +14 -687
- package/dist/src/run-temp.d.ts +12 -0
- package/dist/src/run-temp.js +50 -0
- package/dist/src/runtime.d.ts +12 -228
- package/dist/src/runtime.js +2 -128
- package/dist/src/sandbox-child.js +0 -1
- package/dist/src/save-lock.d.ts +0 -12
- package/dist/src/save-lock.js +0 -28
- package/dist/src/screen-selection.d.ts +0 -23
- package/dist/src/screen-selection.js +0 -22
- package/dist/src/secret-redaction.d.ts +0 -12
- package/dist/src/secret-redaction.js +0 -45
- package/dist/src/session-changes.d.ts +4 -80
- package/dist/src/session-changes.js +25 -130
- package/dist/src/session-goal.d.ts +129 -0
- package/dist/src/session-goal.js +230 -0
- package/dist/src/session-monitor.d.ts +1 -10
- package/dist/src/session-monitor.js +2 -39
- package/dist/src/session-reaper.d.ts +0 -15
- package/dist/src/session-reaper.js +0 -14
- package/dist/src/session-skills.d.ts +15 -44
- package/dist/src/session-skills.js +75 -60
- package/dist/src/session-summary.d.ts +0 -26
- package/dist/src/session-summary.js +0 -32
- package/dist/src/session-title.d.ts +0 -1
- package/dist/src/session-title.js +0 -2
- package/dist/src/sessions.d.ts +3 -122
- package/dist/src/sessions.js +9 -178
- package/dist/src/shell.d.ts +3 -20
- package/dist/src/shell.js +8 -72
- package/dist/src/side-panel.d.ts +5 -99
- package/dist/src/side-panel.js +76 -133
- package/dist/src/sign-in-detection.d.ts +0 -39
- package/dist/src/sign-in-detection.js +0 -43
- package/dist/src/sign-in-offer.d.ts +1 -19
- package/dist/src/sign-in-offer.js +0 -13
- package/dist/src/skill-commands.d.ts +0 -1
- package/dist/src/skill-commands.js +1 -4
- package/dist/src/skills/bundled/control-browser/SKILL.md +1 -1
- package/dist/src/skills/bundled/graph-manager/errors.md +1 -1
- package/dist/src/skills/bundled/provenance.json +738 -738
- package/dist/src/skills/invocable-skills.d.ts +0 -18
- package/dist/src/skills/invocable-skills.js +0 -17
- package/dist/src/skills/project-skills.d.ts +0 -1
- package/dist/src/skills/project-skills.js +0 -3
- package/dist/src/skills/prompt-skills.js +0 -14
- package/dist/src/skills/runtime-skills.d.ts +0 -13
- package/dist/src/skills/runtime-skills.js +0 -37
- package/dist/src/stall-recovery.d.ts +0 -25
- package/dist/src/stall-recovery.js +0 -38
- package/dist/src/stray-files.d.ts +0 -9
- package/dist/src/stray-files.js +0 -16
- package/dist/src/structured-step.d.ts +0 -22
- package/dist/src/structured-step.js +0 -22
- package/dist/src/subagent-run.d.ts +2 -163
- package/dist/src/subagent-run.js +18 -376
- package/dist/src/subagent-tree.d.ts +32 -0
- package/dist/src/subagent-tree.js +128 -0
- package/dist/src/telemetry/aggregate.d.ts +0 -37
- package/dist/src/telemetry/aggregate.js +0 -40
- package/dist/src/telemetry/capture-core.d.ts +0 -87
- package/dist/src/telemetry/capture-core.js +0 -67
- package/dist/src/telemetry/capture.d.ts +0 -1
- package/dist/src/telemetry/capture.js +0 -3
- package/dist/src/telemetry/classify.d.ts +0 -58
- package/dist/src/telemetry/classify.js +0 -60
- package/dist/src/telemetry/decision-capture.d.ts +0 -1
- package/dist/src/telemetry/emitter.d.ts +0 -30
- package/dist/src/telemetry/emitter.js +1 -62
- package/dist/src/telemetry/gate.d.ts +0 -29
- package/dist/src/telemetry/gate.js +0 -22
- package/dist/src/telemetry/identity.d.ts +0 -13
- package/dist/src/telemetry/identity.js +0 -29
- package/dist/src/telemetry/outbox.d.ts +0 -64
- package/dist/src/telemetry/outbox.js +1 -108
- package/dist/src/telemetry/schema.d.ts +1 -49
- package/dist/src/telemetry/schema.js +3 -84
- package/dist/src/telemetry/state.d.ts +0 -53
- package/dist/src/telemetry/state.js +0 -64
- package/dist/src/telemetry/surface.d.ts +0 -31
- package/dist/src/telemetry/surface.js +1 -39
- package/dist/src/telemetry/uploader.d.ts +0 -11
- package/dist/src/telemetry/uploader.js +0 -46
- package/dist/src/telemetry/uploads.d.ts +0 -11
- package/dist/src/telemetry/uploads.js +0 -11
- package/dist/src/telemetry/version.d.ts +0 -4
- package/dist/src/telemetry/version.js +0 -14
- package/dist/src/telemetry/workspace.d.ts +0 -7
- package/dist/src/telemetry/workspace.js +1 -22
- package/dist/src/terminal-ui.d.ts +33 -521
- package/dist/src/terminal-ui.js +145 -884
- package/dist/src/test-edit-guard.d.ts +74 -0
- package/dist/src/test-edit-guard.js +269 -0
- package/dist/src/text.d.ts +0 -1
- package/dist/src/text.js +0 -1
- package/dist/src/time-limit.d.ts +0 -36
- package/dist/src/time-limit.js +0 -37
- package/dist/src/timers.d.ts +0 -161
- package/dist/src/timers.js +0 -126
- package/dist/src/todos.d.ts +0 -1
- package/dist/src/todos.js +0 -3
- package/dist/src/token-rate.d.ts +0 -94
- package/dist/src/token-rate.js +0 -154
- package/dist/src/tool-activity.d.ts +0 -6
- package/dist/src/tool-activity.js +0 -7
- package/dist/src/tool-availability.d.ts +0 -13
- package/dist/src/tool-availability.js +1 -14
- package/dist/src/tool-call-clock.d.ts +1 -4
- package/dist/src/tool-call-clock.js +0 -13
- package/dist/src/tool-catalog.d.ts +0 -11
- package/dist/src/tool-catalog.js +0 -23
- package/dist/src/tool-dependencies.d.ts +0 -5
- package/dist/src/tool-dependencies.js +0 -4
- package/dist/src/tool-diff-stats.d.ts +0 -23
- package/dist/src/tool-diff-stats.js +0 -49
- package/dist/src/tool-errors.d.ts +9 -7
- package/dist/src/tool-errors.js +13 -6
- package/dist/src/tool-failure-tracker.d.ts +3 -11
- package/dist/src/tool-failure-tracker.js +19 -27
- package/dist/src/tool-names.d.ts +0 -16
- package/dist/src/tool-names.js +0 -12
- package/dist/src/tool-profile.d.ts +6 -0
- package/dist/src/tool-profile.js +23 -0
- package/dist/src/tool-result-filter.d.ts +0 -19
- package/dist/src/tool-result-filter.js +1 -66
- package/dist/src/tool-schema-compatibility.d.ts +0 -6
- package/dist/src/tool-schema-compatibility.js +0 -9
- package/dist/src/tools.d.ts +0 -4
- package/dist/src/tools.js +11 -114
- package/dist/src/trajectory.d.ts +0 -13
- package/dist/src/trajectory.js +23 -79
- package/dist/src/transcript.d.ts +0 -41
- package/dist/src/transcript.js +5 -60
- package/dist/src/types.d.ts +4 -168
- package/dist/src/untracked-file-removal.js +0 -20
- package/dist/src/update-check.d.ts +0 -14
- package/dist/src/update-check.js +1 -15
- package/dist/src/update.d.ts +0 -35
- package/dist/src/update.js +0 -100
- package/dist/src/usage-analytics.d.ts +17 -17
- package/dist/src/usage-analytics.js +168 -209
- package/dist/src/web-search.d.ts +0 -23
- package/dist/src/web-search.js +1 -27
- package/dist/src/widgets.d.ts +0 -25
- package/dist/src/widgets.js +0 -24
- package/dist/src/workspace-facts.d.ts +0 -12
- package/dist/src/workspace-facts.js +1 -18
- package/dist/src/workspace-git-metadata.d.ts +0 -16
- package/dist/src/workspace-git-metadata.js +0 -21
- package/dist/src/workspace-instructions.d.ts +3 -15
- package/dist/src/workspace-instructions.js +6 -19
- package/package.json +13 -2
package/dist/src/providers.js
CHANGED
|
@@ -6,55 +6,19 @@ import { createOpenCodeAdapter } from './opencode-provider.js';
|
|
|
6
6
|
import { createGrokAdapter } from './grok-provider.js';
|
|
7
7
|
import { createOpenCodeCliAdapter } from './opencode-cli-provider.js';
|
|
8
8
|
import { providerAuthHeaders } from './anthropic-credentials.js';
|
|
9
|
+
import { ANDORRA_UNAVAILABLE_MESSAGE, andorraBaseUrl } from './andorra/endpoint.js';
|
|
10
|
+
import { andorraRefusal } from './andorra/errors.js';
|
|
9
11
|
import { generateEngineResponse, isEngineContextOverflow } from './provider-engine.js';
|
|
10
12
|
import { estimateStreamedTokens } from './token-rate.js';
|
|
11
13
|
export const REASONING_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
12
|
-
|
|
13
|
-
export const PROVIDER_TYPES = ['openai-compatible', 'anthropic', 'codex', 'claude', 'opencode-go', 'grok', 'opencode'];
|
|
14
|
-
/**
|
|
15
|
-
* Types that run through a vendor CLI's own sign-in on this machine instead of a key Andorra holds.
|
|
16
|
-
*
|
|
17
|
-
* They carry no credential fields, use a fixed marker base URL, and bound each request themselves,
|
|
18
|
-
* so configuration rejects key and timeout overrides on them rather than silently ignoring them.
|
|
19
|
-
*/
|
|
14
|
+
export const PROVIDER_TYPES = ['openai-compatible', 'anthropic', 'codex', 'claude', 'opencode-go', 'grok', 'opencode', 'andorra'];
|
|
20
15
|
export const SIGN_IN_PROVIDER_TYPES = ['codex', 'claude', 'grok', 'opencode'];
|
|
21
16
|
export function isSignInProviderType(type) {
|
|
22
17
|
return SIGN_IN_PROVIDER_TYPES.includes(type);
|
|
23
18
|
}
|
|
24
|
-
/** The product name messages use for a sign-in type. */
|
|
25
19
|
const SIGN_IN_PRODUCT = { codex: 'Codex', claude: 'Claude', grok: 'Grok', opencode: 'OpenCode' };
|
|
26
|
-
/**
|
|
27
|
-
* Inactivity bound for inference, and wall-clock bound for other HTTP requests,
|
|
28
|
-
* in milliseconds, when a provider does not configure its own.
|
|
29
|
-
*
|
|
30
|
-
* Its job is to end a request that will never be answered — a wedged server, a black-holed
|
|
31
|
-
* connection — never to cap a slow model. One inference call is bounded by the tokens it must
|
|
32
|
-
* decode, and the request asks for thousands of them, so a bound short enough to fire on a
|
|
33
|
-
* healthy self-hosted endpoint converts completed work into `infrastructure_error`. Inference
|
|
34
|
-
* refreshes this timer whenever response bytes arrive; active decoding may run longer. A
|
|
35
|
-
* provider that needs longer silent intervals raises it, and
|
|
36
|
-
* `0` removes it entirely for a caller that is bounded some other way.
|
|
37
|
-
*/
|
|
38
20
|
export const DEFAULT_REQUEST_TIMEOUT_MS = 10 * 60_000;
|
|
39
|
-
/**
|
|
40
|
-
* The largest per-request bound a provider may configure: one day.
|
|
41
|
-
*
|
|
42
|
-
* Node's timers accept only a signed 32-bit millisecond delay. A larger value is reduced to a
|
|
43
|
-
* 1 ms timer with a `TimeoutOverflowWarning` — and above `2 ** 32 - 1` `AbortSignal.timeout`
|
|
44
|
-
* throws — so a bound meant to be generous would instead fail every request almost immediately.
|
|
45
|
-
* Configuration and the exported adapter constructor enforce this same ceiling: a consumer that
|
|
46
|
-
* builds an adapter directly must not be able to arm that timer.
|
|
47
|
-
*/
|
|
48
21
|
export const MAX_REQUEST_TIMEOUT_MS = 86_400_000;
|
|
49
|
-
/**
|
|
50
|
-
* The single validation of a configured request bound, shared by the configuration loader and
|
|
51
|
-
* {@link createAdapter} so the two can never disagree about what a provider will honour.
|
|
52
|
-
*
|
|
53
|
-
* It rejects the whole override, not just an out-of-range value: a Codex provider applies its own
|
|
54
|
-
* fixed bound, so accepting `requestTimeoutMs` here would silently ignore what the caller asked
|
|
55
|
-
* for.
|
|
56
|
-
* @param provider - the provider whose bound is being checked.
|
|
57
|
-
*/
|
|
58
22
|
export function assertRequestTimeout(provider) {
|
|
59
23
|
const value = provider.requestTimeoutMs;
|
|
60
24
|
if (value === undefined)
|
|
@@ -65,16 +29,6 @@ export function assertRequestTimeout(provider) {
|
|
|
65
29
|
throw new Error(`Provider requestTimeoutMs must be 0 (no timeout) or an integer of milliseconds up to ${MAX_REQUEST_TIMEOUT_MS}`);
|
|
66
30
|
}
|
|
67
31
|
}
|
|
68
|
-
/**
|
|
69
|
-
* The single validation of a configured inference inactivity bound, shared by the configuration
|
|
70
|
-
* loader and {@link createAdapter} so the two can never disagree about what a provider honours.
|
|
71
|
-
*
|
|
72
|
-
* `streamIdleTimeoutMs` separates the bound on a silent inference exchange from
|
|
73
|
-
* `requestTimeoutMs`: a provider that removed the request bound to tolerate a slow prefill can
|
|
74
|
-
* still end a stream that stopped delivering bytes. Like the request bound it accepts `0` to
|
|
75
|
-
* remove the bound; Codex owns its fixed bound, so the override is rejected rather than ignored.
|
|
76
|
-
* @param provider - the provider whose inactivity bound is being checked.
|
|
77
|
-
*/
|
|
78
32
|
export function assertStreamIdleTimeout(provider) {
|
|
79
33
|
const value = provider.streamIdleTimeoutMs;
|
|
80
34
|
if (value === undefined)
|
|
@@ -85,38 +39,13 @@ export function assertStreamIdleTimeout(provider) {
|
|
|
85
39
|
throw new Error(`Provider streamIdleTimeoutMs must be 0 (no bound) or an integer of milliseconds up to ${MAX_REQUEST_TIMEOUT_MS}`);
|
|
86
40
|
}
|
|
87
41
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Bound for model listing, which is a discovery GET rather than inference.
|
|
90
|
-
*
|
|
91
|
-
* A listing is never worth the inference bound: an endpoint that accepts the connection and never
|
|
92
|
-
* answers must not leave the model screen loading for minutes, and a provider that removed its
|
|
93
|
-
* inference bound with `requestTimeoutMs: 0` must still not make discovery unbounded. A caller
|
|
94
|
-
* may pass a shorter bound of its own; this is a ceiling, not a floor.
|
|
95
|
-
*
|
|
96
|
-
* Callers pass their *cancellation* signal only. A deadline the caller arms here would fire before
|
|
97
|
-
* this one, and a caller's signal aborting is reported as a cancellation — so wrapping this call
|
|
98
|
-
* in `AbortSignal.timeout` would report a stalled endpoint as something the user did.
|
|
99
|
-
*/
|
|
100
42
|
export const MODEL_LISTING_TIMEOUT_MS = 30_000;
|
|
101
|
-
/** How a deadline reads in the phrase that reports it hitting: "15 seconds", "1 second", "40 milliseconds". */
|
|
102
43
|
export function deadlinePhrase(ms) {
|
|
103
44
|
if (ms % 1000 !== 0)
|
|
104
45
|
return `${ms} milliseconds`;
|
|
105
46
|
const seconds = ms / 1000;
|
|
106
47
|
return `${seconds} second${seconds === 1 ? '' : 's'}`;
|
|
107
48
|
}
|
|
108
|
-
/**
|
|
109
|
-
* The name a person reads for a provider in a list or picker.
|
|
110
|
-
*
|
|
111
|
-
* An explicit {@link ProviderConfig.name} wins everywhere: the id is an immutable identity, so the
|
|
112
|
-
* editable name is the only way a provider can be renamed, and preferring it here is what makes a
|
|
113
|
-
* rename reach records that still carry the old identity. Codex entries are otherwise the one case
|
|
114
|
-
* where the id is not the name: several ChatGPT accounts can be configured at once, and the label
|
|
115
|
-
* carries the account's email localpart so the rows are told apart. A configuration holding a
|
|
116
|
-
* single Codex provider keeps the plain `codex` name, and a provider whose sign-in never reported
|
|
117
|
-
* an email falls back to its id. The selection value stays the provider id everywhere; only the
|
|
118
|
-
* text changes.
|
|
119
|
-
*/
|
|
120
49
|
export function providerLabel(provider, providers) {
|
|
121
50
|
if (provider.name?.trim())
|
|
122
51
|
return provider.name.trim();
|
|
@@ -127,21 +56,31 @@ export function providerLabel(provider, providers) {
|
|
|
127
56
|
const local = provider.codexEmail?.split('@')[0] || provider.id;
|
|
128
57
|
return `codex - ${local.length > 32 ? `${local.slice(0, 31)}…` : local}`;
|
|
129
58
|
}
|
|
130
|
-
/**
|
|
59
|
+
/** What a person reads for `model`: an Andorra entry's stored display name, otherwise the id itself. */
|
|
60
|
+
export function modelDisplayName(provider, model) {
|
|
61
|
+
const names = provider?.type === 'andorra' ? provider.modelNames : undefined;
|
|
62
|
+
const name = names && Object.hasOwn(names, model) ? names[model] : undefined;
|
|
63
|
+
return typeof name === 'string' && name ? name : model;
|
|
64
|
+
}
|
|
65
|
+
/** The model id an exact display name (any case) names on an Andorra entry; undefined for an id, another provider, or a name two models share. */
|
|
66
|
+
export function modelIdForDisplayName(provider, text) {
|
|
67
|
+
if (provider.type !== 'andorra' || !provider.modelNames)
|
|
68
|
+
return undefined;
|
|
69
|
+
const ids = providerModels(provider);
|
|
70
|
+
if (ids.includes(text))
|
|
71
|
+
return undefined;
|
|
72
|
+
const wanted = text.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
73
|
+
const matches = ids.filter(id => modelDisplayName(provider, id) !== id && modelDisplayName(provider, id).toLowerCase() === wanted);
|
|
74
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
75
|
+
}
|
|
76
|
+
/** Provider id → model id → display name, for the providers that have names (Andorra). */
|
|
77
|
+
export function providerModelNames(providers) {
|
|
78
|
+
return Object.fromEntries(providers.flatMap(provider => provider.type === 'andorra' && provider.modelNames && Object.keys(provider.modelNames).length
|
|
79
|
+
? [[provider.id, { ...provider.modelNames }]] : []));
|
|
80
|
+
}
|
|
131
81
|
export const MAX_CODEX_ACCOUNT_KEY_LENGTH = 100;
|
|
132
|
-
/** The longest display name validation accepts; the name is text a list row or picker renders. */
|
|
133
82
|
export const MAX_PROVIDER_NAME_LENGTH = 64;
|
|
134
|
-
|
|
135
|
-
* An account-slot key no configured provider binds yet, based on the entry's identifier.
|
|
136
|
-
*
|
|
137
|
-
* The key becomes a directory name, so it is compared case-insensitively, exactly as validation
|
|
138
|
-
* compares it: `work-fast` may already be bound to the key `work`, and a new provider whose own id
|
|
139
|
-
* is `work` must not take that account over. The first free `id`, `id-2`, `id-3`… is returned.
|
|
140
|
-
*
|
|
141
|
-
* A provider id may be longer than a slot key validation accepts, and appending a collision suffix
|
|
142
|
-
* to a key already at the limit would overrun it, so the base is trimmed to leave the suffix room:
|
|
143
|
-
* allocating an account must never produce a key the configuration it is written into rejects.
|
|
144
|
-
*/
|
|
83
|
+
export const MAX_MODEL_DISPLAY_NAME_LENGTH = 80;
|
|
145
84
|
export function freeCodexAccountSlot(base, providers) {
|
|
146
85
|
const taken = new Set(providers.flatMap(provider => provider.codexAccount === undefined ? [] : [provider.codexAccount.toLowerCase()]));
|
|
147
86
|
const key = (suffix) => `${base.slice(0, MAX_CODEX_ACCOUNT_KEY_LENGTH - suffix.length)}${suffix}`;
|
|
@@ -150,28 +89,9 @@ export function freeCodexAccountSlot(base, providers) {
|
|
|
150
89
|
slot = key(`-${suffix}`);
|
|
151
90
|
return slot;
|
|
152
91
|
}
|
|
153
|
-
/**
|
|
154
|
-
* A free slot key for an entry a draft is adding, reserving the saved configuration as well.
|
|
155
|
-
*
|
|
156
|
-
* A draft may remove a slot-bearing entry and add a new Codex provider in the same save. The
|
|
157
|
-
* removed home outlives the draft until its retirement completes, so a key computed against the
|
|
158
|
-
* draft alone can be handed to the newcomer: that entry would sign in as the removed account, and
|
|
159
|
-
* the retirement would find the key bound and skip it. Reserving both sets closes that path for
|
|
160
|
-
* every draft editor, since the engine only allocates for writes that arrive without a key.
|
|
161
|
-
*/
|
|
162
92
|
export function freeDraftCodexAccountSlot(base, draft, saved) {
|
|
163
93
|
return freeCodexAccountSlot(base, [...draft, ...saved]);
|
|
164
94
|
}
|
|
165
|
-
/**
|
|
166
|
-
* Give every Codex entry that is a later account binding its own slot key.
|
|
167
|
-
*
|
|
168
|
-
* An entry binds an account when it is Codex now but was not Codex before — a new entry, or another
|
|
169
|
-
* type converted. A configuration that held no Codex provider keeps its inherited sign-in on the
|
|
170
|
-
* first Codex entry this write leaves; every other new binding gets a free key. An entry that was
|
|
171
|
-
* already Codex keeps whatever binding (or lack of one) it had: a save is not a migration. Allocation
|
|
172
|
-
* happens here rather than in each client so no two clients can disagree about which keys are taken,
|
|
173
|
-
* and a bulk write orders the entries exactly as adding them one at a time would.
|
|
174
|
-
*/
|
|
175
95
|
export function allocateCodexAccountSlots(stored, next) {
|
|
176
96
|
const storedHadCodex = stored.some(item => item.type === 'codex');
|
|
177
97
|
const firstCodexId = next.find(item => item.type === 'codex')?.id;
|
|
@@ -186,29 +106,15 @@ export function allocateCodexAccountSlots(stored, next) {
|
|
|
186
106
|
result.push(provider);
|
|
187
107
|
continue;
|
|
188
108
|
}
|
|
189
|
-
// The key is chosen against everything this write leaves configured: entries already placed and
|
|
190
|
-
// entries still to come, and `freeCodexAccountSlot` reads every binding among them. Bindings the
|
|
191
|
-
// write removes are reserved too, because their homes outlive the write until retirement
|
|
192
|
-
// completes: reusing a removed key here would hand the new entry an account it never signed in
|
|
193
|
-
// to, and the retirement would then find the key bound and skip it.
|
|
194
109
|
result.push({ ...provider, codexAccount: freeCodexAccountSlot(provider.id, [...result, ...next.slice(index + 1), ...stored]) });
|
|
195
110
|
}
|
|
196
111
|
return result;
|
|
197
112
|
}
|
|
198
|
-
/** The models a provider is configured to offer: the saved list, or the active model alone. */
|
|
199
113
|
export function providerModels(provider) {
|
|
200
114
|
if (provider.models !== undefined)
|
|
201
115
|
return provider.models.filter(model => model.trim());
|
|
202
116
|
return provider.model.trim() ? [provider.model] : [];
|
|
203
117
|
}
|
|
204
|
-
/**
|
|
205
|
-
* The context window saved for one model, if the provider has one.
|
|
206
|
-
*
|
|
207
|
-
* `Object.hasOwn` rather than a plain lookup: a model id is user input, so `constructor` or
|
|
208
|
-
* `toString` must read as "no saved window" instead of an inherited member. Values are required to
|
|
209
|
-
* be positive safe integers because a hand-edited configuration can reach this before validation
|
|
210
|
-
* runs in an adapter built directly.
|
|
211
|
-
*/
|
|
212
118
|
export function configuredContextWindow(provider, model) {
|
|
213
119
|
const id = model ?? provider.model;
|
|
214
120
|
if (!provider.modelContextWindows || !Object.hasOwn(provider.modelContextWindows, id))
|
|
@@ -216,15 +122,6 @@ export function configuredContextWindow(provider, model) {
|
|
|
216
122
|
const window = provider.modelContextWindows[id];
|
|
217
123
|
return Number.isSafeInteger(window) && window > 0 ? window : undefined;
|
|
218
124
|
}
|
|
219
|
-
/**
|
|
220
|
-
* Point a provider's own window at one model's saved limit.
|
|
221
|
-
*
|
|
222
|
-
* A model switch must not keep the previous model's limit, and a model with no saved entry must
|
|
223
|
-
* not inherit one: the saved window for the target model is applied when the map holds it, and the
|
|
224
|
-
* provider-level value is dropped when it does not. `/status` and the run budget read
|
|
225
|
-
* `contextWindow` directly, so a switch that only deleted it would report an unknown limit for a
|
|
226
|
-
* model whose limit the provider already knows.
|
|
227
|
-
*/
|
|
228
125
|
export function applyModelContextWindow(provider, model) {
|
|
229
126
|
const saved = configuredContextWindow(provider, model);
|
|
230
127
|
if (saved !== undefined)
|
|
@@ -232,21 +129,9 @@ export function applyModelContextWindow(provider, model) {
|
|
|
232
129
|
else
|
|
233
130
|
delete provider.contextWindow;
|
|
234
131
|
}
|
|
235
|
-
/**
|
|
236
|
-
* Raw provider secrets: stored API keys plus the current values of their named environment
|
|
237
|
-
* variables. The trajectory's own credential-name heuristic cannot know an arbitrary
|
|
238
|
-
* `apiKeyEnv` name, so every place providers (re)register secrets uses this helper — initial
|
|
239
|
-
* config load and mid-session provider edits alike.
|
|
240
|
-
*/
|
|
241
132
|
export function providerSecrets(providers, env = process.env) {
|
|
242
133
|
return providers.flatMap(provider => [provider.apiKey, provider.apiKeyEnv ? env[provider.apiKeyEnv] : undefined].filter((key) => !!key));
|
|
243
134
|
}
|
|
244
|
-
/**
|
|
245
|
-
* Record one model as configured for the provider, keeping the saved list consistent with it.
|
|
246
|
-
*
|
|
247
|
-
* The list is materialized only once it holds more than the active model, or once it exists at all:
|
|
248
|
-
* a provider edited without ever touching its model list keeps the configuration shape it had.
|
|
249
|
-
*/
|
|
250
135
|
export function recordProviderModel(provider, model) {
|
|
251
136
|
const list = providerModels(provider);
|
|
252
137
|
if (!list.includes(model))
|
|
@@ -254,7 +139,6 @@ export function recordProviderModel(provider, model) {
|
|
|
254
139
|
if (list.length > 1 || provider.models !== undefined)
|
|
255
140
|
provider.models = list;
|
|
256
141
|
}
|
|
257
|
-
/** Validate credentials without including their contents in errors. */
|
|
258
142
|
export function assertProviderCredentials(provider) {
|
|
259
143
|
if (provider.anthropicAuth !== undefined && (provider.type !== 'anthropic' || provider.anthropicAuth !== 'console')) {
|
|
260
144
|
throw new Error('anthropicAuth is an Anthropic-only setting whose only value is console.');
|
|
@@ -271,6 +155,9 @@ export function assertProviderCredentials(provider) {
|
|
|
271
155
|
if ((provider.type === 'grok' || provider.type === 'opencode') && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
272
156
|
throw new Error(`${SIGN_IN_PRODUCT[provider.type]} providers use their CLI sign-in; API key overrides are not supported.`);
|
|
273
157
|
}
|
|
158
|
+
if (provider.type === 'andorra' && (provider.apiKey !== undefined || provider.apiKeyEnv !== undefined)) {
|
|
159
|
+
throw new Error('Andorra providers use your Andorra account sign-in; API keys are not supported.');
|
|
160
|
+
}
|
|
274
161
|
if (provider.apiKey !== undefined && (typeof provider.apiKey !== 'string' || !/^[\x21-\x7e]+$/.test(provider.apiKey))) {
|
|
275
162
|
throw new Error('API key must be nonempty and contain no whitespace or control characters.');
|
|
276
163
|
}
|
|
@@ -278,7 +165,6 @@ export function assertProviderCredentials(provider) {
|
|
|
278
165
|
throw new Error('Invalid API key environment variable name.');
|
|
279
166
|
}
|
|
280
167
|
}
|
|
281
|
-
/** Shared credential precedence for inference and model discovery. */
|
|
282
168
|
export function resolveProviderApiKey(provider) {
|
|
283
169
|
assertProviderCredentials(provider);
|
|
284
170
|
if (provider.apiKey !== undefined)
|
|
@@ -302,14 +188,14 @@ export function defaultProviders() {
|
|
|
302
188
|
const MAX_REQUEST_RETRIES = 3;
|
|
303
189
|
const REQUEST_RETRY_DELAYS_MS = [1_000, 30_000, 120_000];
|
|
304
190
|
const MALFORMED_STREAM_RETRY_DELAYS_MS = [1_000, 3_000, 10_000];
|
|
191
|
+
// A malformed response is usually the model's own slip (tool-call arguments that are not valid JSON), so asking
|
|
192
|
+
// again gets a fresh sample. It needs no long backoff and is retried quietly, more often than a transport fault.
|
|
193
|
+
export const MALFORMED_RESPONSE_RETRIES = 5;
|
|
194
|
+
const MALFORMED_RESPONSE_RETRY_DELAYS_MS = [250, 250, 500, 1_000, 2_000];
|
|
195
|
+
const MALFORMED_RESPONSE_MESSAGE = 'Provider returned a malformed response.';
|
|
305
196
|
const MAX_AUTOMATIC_RETRY_AFTER_MS = REQUEST_RETRY_DELAYS_MS.at(-1);
|
|
306
197
|
export class ProviderRequestError extends Error {
|
|
307
198
|
contextOverflow;
|
|
308
|
-
/**
|
|
309
|
-
* Set when this request was classified as exceeding the context window. It travels structured so
|
|
310
|
-
* telemetry reports a limit without re-deriving one from an error message, and so a provider
|
|
311
|
-
* failure rate never absorbs an input that was simply too large.
|
|
312
|
-
*/
|
|
313
199
|
constructor(message, contextOverflow = false) {
|
|
314
200
|
super(message);
|
|
315
201
|
this.contextOverflow = contextOverflow;
|
|
@@ -319,43 +205,29 @@ export class ProviderRequestError extends Error {
|
|
|
319
205
|
class RetryableProviderError extends ProviderRequestError {
|
|
320
206
|
retryAfterMs;
|
|
321
207
|
retryDelaysMs;
|
|
322
|
-
|
|
208
|
+
maxRetries;
|
|
209
|
+
quiet;
|
|
210
|
+
constructor(message, retryAfterMs = 0, retryDelaysMs = REQUEST_RETRY_DELAYS_MS, maxRetries = MAX_REQUEST_RETRIES, quiet = false) {
|
|
323
211
|
super(message);
|
|
324
212
|
this.retryAfterMs = retryAfterMs;
|
|
325
213
|
this.retryDelaysMs = retryDelaysMs;
|
|
214
|
+
this.maxRetries = maxRetries;
|
|
215
|
+
this.quiet = quiet;
|
|
326
216
|
this.name = 'Error';
|
|
327
217
|
}
|
|
328
218
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
219
|
+
class MalformedResponseProviderError extends RetryableProviderError {
|
|
220
|
+
constructor() { super(MALFORMED_RESPONSE_MESSAGE, 0, MALFORMED_RESPONSE_RETRY_DELAYS_MS, MALFORMED_RESPONSE_RETRIES, true); }
|
|
221
|
+
}
|
|
222
|
+
class MalformedStreamProviderError extends MalformedResponseProviderError {
|
|
332
223
|
}
|
|
333
|
-
/**
|
|
334
|
-
* How much blank tool-call output a stream may carry in a row before it is abandoned: whitespace
|
|
335
|
-
* characters in a call's arguments, plus one for every tool-call fragment that adds nothing.
|
|
336
|
-
*
|
|
337
|
-
* A model sometimes opens a tool call and then generates whitespace until the provider's output
|
|
338
|
-
* cap stops it. On DeepSeek V4.1 Flash that was 131,072 completion tokens over eight minutes for a
|
|
339
|
-
* call whose arguments arrived empty, about once in three thousand requests, and it was 16% of
|
|
340
|
-
* all output in a 90-task SWE-bench run. Real arguments never hold this much consecutive
|
|
341
|
-
* whitespace: line breaks inside a JSON string are escaped, and indentation between tokens is a
|
|
342
|
-
* few characters. The stream is cut here and the request replayed, which is safe because no tool
|
|
343
|
-
* from the abandoned response ran.
|
|
344
|
-
*/
|
|
345
224
|
export const BLANK_TOOL_CALL_LIMIT = 4096;
|
|
346
|
-
/** A stream abandoned because a tool call kept generating blank output; replayed like a malformed one. */
|
|
347
225
|
class BlankToolCallProviderError extends RetryableProviderError {
|
|
348
226
|
constructor() { super('Provider streamed a tool call that kept generating blank output.', 0, MALFORMED_STREAM_RETRY_DELAYS_MS); }
|
|
349
227
|
}
|
|
350
|
-
/**
|
|
351
|
-
* Counts consecutive blank tool-call output across a stream and throws once it passes
|
|
352
|
-
* {@link BLANK_TOOL_CALL_LIMIT}. Anything the model visibly produces (argument text, a tool
|
|
353
|
-
* name, answer text, reasoning) ends the run of blanks.
|
|
354
|
-
*/
|
|
355
228
|
export function createBlankToolCallGuard(limit = BLANK_TOOL_CALL_LIMIT) {
|
|
356
229
|
let blank = 0;
|
|
357
230
|
return {
|
|
358
|
-
/** One tool-call fragment's text: its name and argument pieces joined. */
|
|
359
231
|
fragment(text) {
|
|
360
232
|
if (/\S/.test(text)) {
|
|
361
233
|
blank = 0;
|
|
@@ -365,11 +237,9 @@ export function createBlankToolCallGuard(limit = BLANK_TOOL_CALL_LIMIT) {
|
|
|
365
237
|
if (blank > limit)
|
|
366
238
|
throw new BlankToolCallProviderError();
|
|
367
239
|
},
|
|
368
|
-
/** The model produced something other than a tool-call fragment. */
|
|
369
240
|
progress() { blank = 0; },
|
|
370
241
|
};
|
|
371
242
|
}
|
|
372
|
-
/** A completed HTTP exchange the provider refused outright; `status` drives compatibility fallbacks. */
|
|
373
243
|
class HttpProviderError extends ProviderRequestError {
|
|
374
244
|
status;
|
|
375
245
|
constructor(message, status) {
|
|
@@ -393,25 +263,16 @@ function permanentConnectionFailure(error) {
|
|
|
393
263
|
|| /^(?:unexpected redirect|redirect count exceeded|bad port|unknown scheme|invalid redirect|URL scheme must be)/i.test(failure.message ?? '')
|
|
394
264
|
|| (failure.cause !== error && permanentConnectionFailure(failure.cause));
|
|
395
265
|
}
|
|
396
|
-
/**
|
|
397
|
-
* The transport code behind a failed fetch, preferring the cause's over the wrapper's.
|
|
398
|
-
*
|
|
399
|
-
* Only the code is surfaced. An exception's message is free text that has been seen to embed
|
|
400
|
-
* credentials, while the code is the part that tells an operator whether this is DNS, TLS, a
|
|
401
|
-
* refused port or a bad certificate anyway.
|
|
402
|
-
*/
|
|
403
266
|
function connectionFailureDetail(error) {
|
|
404
267
|
if (!error || typeof error !== 'object')
|
|
405
268
|
return undefined;
|
|
406
269
|
const failure = error;
|
|
407
270
|
const cause = failure.cause && typeof failure.cause === 'object' ? failure.cause : undefined;
|
|
408
271
|
const code = typeof cause?.code === 'string' && cause.code ? cause.code : typeof failure.code === 'string' && failure.code ? failure.code : undefined;
|
|
409
|
-
// Transport codes are errno-style (ENOTFOUND, ECONNRESET, ERR_TLS_...). Anything else is an
|
|
410
|
-
// arbitrary string some library attached, and echoing it would expose whatever it put there.
|
|
411
272
|
return code && /^[A-Z][A-Z0-9_]*$/.test(code) ? code : undefined;
|
|
412
273
|
}
|
|
413
274
|
function cancelled() { throw new Error('Provider request cancelled.'); }
|
|
414
|
-
function malformed() { throw new Error(
|
|
275
|
+
function malformed() { throw new Error(MALFORMED_RESPONSE_MESSAGE); }
|
|
415
276
|
class ResponseTooLargeError extends Error {
|
|
416
277
|
constructor() { super('Provider response exceeds the 4 MiB limit.'); }
|
|
417
278
|
}
|
|
@@ -444,14 +305,6 @@ function record(value) {
|
|
|
444
305
|
return malformed();
|
|
445
306
|
return value;
|
|
446
307
|
}
|
|
447
|
-
/**
|
|
448
|
-
* The provider's own explanation of a rejected request, from its bounded error body.
|
|
449
|
-
*
|
|
450
|
-
* Envelopes differ: OpenAI and DeepSeek nest `{error:{message}}`, Anthropic adds its own
|
|
451
|
-
* `{type,error}`, and vLLM's proxy puts a JSON string in `detail`. Only message-bearing fields
|
|
452
|
-
* are read, because the rest of an error body can echo request content or credentials and belongs
|
|
453
|
-
* in the provider's logs, not in the run record the person keeps.
|
|
454
|
-
*/
|
|
455
308
|
function providerErrorDetail(value, depth = 0) {
|
|
456
309
|
if (!value || typeof value !== 'object' || Array.isArray(value) || depth > 2)
|
|
457
310
|
return undefined;
|
|
@@ -472,8 +325,6 @@ function providerErrorDetail(value, depth = 0) {
|
|
|
472
325
|
const detail = providerErrorDetail(safeJson(trimmed), depth + 1);
|
|
473
326
|
if (detail)
|
|
474
327
|
return detail;
|
|
475
|
-
// A structured payload is subject to the same allowlist as a structured body: without an
|
|
476
|
-
// approved message field inside it, the serialized text stays in the provider's logs.
|
|
477
328
|
continue;
|
|
478
329
|
}
|
|
479
330
|
return boundedProviderDetail(trimmed);
|
|
@@ -494,7 +345,6 @@ function boundedProviderDetail(text) {
|
|
|
494
345
|
return undefined;
|
|
495
346
|
return collapsed.length > 400 ? `${collapsed.slice(0, 397)}...` : collapsed;
|
|
496
347
|
}
|
|
497
|
-
/** Masks the configured credential, which providers have been seen to echo back in error bodies. */
|
|
498
348
|
function redactCredential(text, key) {
|
|
499
349
|
return key ? text.split(key).join('[redacted]') : text;
|
|
500
350
|
}
|
|
@@ -511,15 +361,6 @@ function usage(value, anthropic) {
|
|
|
511
361
|
const details = data.prompt_tokens_details && typeof data.prompt_tokens_details === 'object' && !Array.isArray(data.prompt_tokens_details)
|
|
512
362
|
? data.prompt_tokens_details : {};
|
|
513
363
|
const input = tokenCount(anthropic ? data.input_tokens : data.prompt_tokens);
|
|
514
|
-
// Anthropic omits cache counts when caching is unused. Missing base usage is
|
|
515
|
-
// unavailable, whereas an explicitly reported zero is a valid measurement.
|
|
516
|
-
// OpenAI-compatible cache reads follow the vendored parser's precedence:
|
|
517
|
-
// prompt_tokens_details.cached_tokens (OpenAI/vLLM), prompt_cache_hit_tokens
|
|
518
|
-
// (DeepSeek) or top-level cached_tokens (Kimi). prompt_tokens is already
|
|
519
|
-
// inclusive of cache traffic, so inputTokens needs no adjustment.
|
|
520
|
-
// Reported means the field was there: an explicit zero is a measurement, and dropping it would make
|
|
521
|
-
// "we measured nothing cached" indistinguishable from "caching was never mentioned". Surfaces that
|
|
522
|
-
// show cache figures key on that presence, so it has to survive this mapping.
|
|
523
364
|
const created = anthropic ? tokenCount(data.cache_creation_input_tokens) : tokenCount(details.cache_write_tokens);
|
|
524
365
|
const read = anthropic ? tokenCount(data.cache_read_input_tokens) : tokenCount(details.cached_tokens ?? data.prompt_cache_hit_tokens ?? data.cached_tokens);
|
|
525
366
|
const inputTokens = anthropic
|
|
@@ -544,26 +385,16 @@ function argumentsObject(value) {
|
|
|
544
385
|
}
|
|
545
386
|
}
|
|
546
387
|
function checkCalls(calls, completionAdvertised) {
|
|
547
|
-
// Names are authorized by the executor so unadvertised calls become repairable observations.
|
|
548
388
|
const ids = new Set();
|
|
549
389
|
for (const call of calls) {
|
|
550
390
|
if (ids.has(call.id))
|
|
551
391
|
malformed();
|
|
552
392
|
ids.add(call.id);
|
|
553
|
-
// Completion is control data validated by the bounded runtime repair loop.
|
|
554
|
-
// Executable tools retain strict adapter validation before any side effects.
|
|
555
393
|
if (call.name !== COMPLETION_TOOL || !completionAdvertised)
|
|
556
394
|
argumentsObject(call.arguments);
|
|
557
395
|
}
|
|
558
396
|
return calls;
|
|
559
397
|
}
|
|
560
|
-
/**
|
|
561
|
-
* Validate one whole-body chat completion into a {@link ModelResponse}.
|
|
562
|
-
*
|
|
563
|
-
* Shared by the unstreamed request path and by the streaming path's whole-body fallback,
|
|
564
|
-
* so a server that answers `stream: true` with plain JSON is held to exactly the checks a
|
|
565
|
-
* server that never streamed must pass.
|
|
566
|
-
*/
|
|
567
398
|
function wholeBodyCompletion(data, requests, completionAdvertised) {
|
|
568
399
|
if (!Array.isArray(data.choices) || data.choices.length !== 1)
|
|
569
400
|
return malformed();
|
|
@@ -580,13 +411,9 @@ function wholeBodyCompletion(data, requests, completionAdvertised) {
|
|
|
580
411
|
.find((value) => typeof value === 'string' && value.length > 0)
|
|
581
412
|
?? (typeof message.reasoning_content === 'string' ? message.reasoning_content : undefined);
|
|
582
413
|
const reasoning = reasoningText !== undefined ? { reasoningContent: reasoningText } : {};
|
|
583
|
-
// Refusals are valid model output, even when content is null. Preserve the
|
|
584
|
-
// text for normal bounded completion handling instead of a transport error.
|
|
585
414
|
const text = [message.content, message.refusal].filter((value) => typeof value === 'string' && value.length > 0).join('\n');
|
|
586
415
|
if (message.tool_calls != null && !Array.isArray(message.tool_calls))
|
|
587
416
|
return malformed();
|
|
588
|
-
// Truncated function arguments may not be JSON (or even contain a name yet).
|
|
589
|
-
// Discard the entire batch and let the runtime apply its bounded repair policy.
|
|
590
417
|
if (choice.finish_reason === 'length' || choice.finish_reason === 'content_filter') {
|
|
591
418
|
return { text, toolCalls: [], usage: { ...usage(data.usage, false), requests }, stopReason: choice.finish_reason };
|
|
592
419
|
}
|
|
@@ -604,33 +431,10 @@ function wholeBodyCompletion(data, requests, completionAdvertised) {
|
|
|
604
431
|
return malformed();
|
|
605
432
|
return { text, toolCalls: checkCalls(calls, completionAdvertised), usage: { ...usage(data.usage, false), requests }, stopReason: nonempty(choice.finish_reason), ...reasoning };
|
|
606
433
|
}
|
|
607
|
-
/**
|
|
608
|
-
* How long after the first generated fragment later fragments still belong to the opening burst.
|
|
609
|
-
*
|
|
610
|
-
* A server that streams token by token puts a few tokens inside this span; a relay or tool-call
|
|
611
|
-
* parser that holds output back and releases it at once puts hundreds there.
|
|
612
|
-
*/
|
|
613
434
|
const DECODE_HEAD_BURST_MS = 50;
|
|
614
|
-
/**
|
|
615
|
-
* Measure a streamed response's decode time from when its fragments arrive.
|
|
616
|
-
*
|
|
617
|
-
* Whatever arrives in the opening burst was generated before the first fragment was seen, so the
|
|
618
|
-
* time it took is not observable: it is hidden in the wait that also holds prompt processing.
|
|
619
|
-
* Only output that arrives after the burst has a measured pace - its share of the stream over the
|
|
620
|
-
* span from the end of the burst to the last fragment. The reading is that pace applied to the
|
|
621
|
-
* whole response: the span scaled up by the share of the output that arrived inside it. A stream
|
|
622
|
-
* delivered fragment by fragment loses one fragment and scales by almost nothing. A stream whose
|
|
623
|
-
* output mostly landed in the opening burst - a short answer released in one or two clumps by a
|
|
624
|
-
* buffering proxy - has no pace worth extrapolating, and claims no window rather than dividing
|
|
625
|
-
* every token by the few milliseconds the clump took to arrive.
|
|
626
|
-
*
|
|
627
|
-
* Fragments are weighed by {@link estimateStreamedTokens}; only the proportions matter, since
|
|
628
|
-
* the provider's own token count is what gets divided by the result.
|
|
629
|
-
*/
|
|
630
435
|
export function createDecodeWindow(now = Date.now) {
|
|
631
436
|
let firstAt, headEndAt = 0, lastAt = 0, head = 0, paced = 0;
|
|
632
437
|
return {
|
|
633
|
-
/** Record a generated fragment's arrival; `text` is what it carried. */
|
|
634
438
|
stamp(text) {
|
|
635
439
|
const at = now(), weight = estimateStreamedTokens(text);
|
|
636
440
|
if (firstAt === undefined) {
|
|
@@ -645,7 +449,6 @@ export function createDecodeWindow(now = Date.now) {
|
|
|
645
449
|
paced += weight;
|
|
646
450
|
lastAt = at;
|
|
647
451
|
},
|
|
648
|
-
/** Decode time attributable to the whole response, or undefined when it was not observable. */
|
|
649
452
|
measure() {
|
|
650
453
|
if (firstAt === undefined || lastAt <= headEndAt || paced <= 0 || paced < head)
|
|
651
454
|
return undefined;
|
|
@@ -653,14 +456,6 @@ export function createDecodeWindow(now = Date.now) {
|
|
|
653
456
|
},
|
|
654
457
|
};
|
|
655
458
|
}
|
|
656
|
-
/**
|
|
657
|
-
* Assemble a streamed chat completion, validating it to the same rules as the whole-body path.
|
|
658
|
-
*
|
|
659
|
-
* Every streamed fragment type is checked as it arrives, so a malformed stream fails at the
|
|
660
|
-
* offending chunk rather than after silently accumulating garbage. Tool-call fragments are
|
|
661
|
-
* keyed by their `index` and concatenated in arrival order, which is how every
|
|
662
|
-
* OpenAI-compatible server splits them.
|
|
663
|
-
*/
|
|
664
459
|
function createStreamAccumulator(onReasoning, now = Date.now) {
|
|
665
460
|
let content = '', refusal, reasoning = '', finishReason, chunkUsage;
|
|
666
461
|
let sawChoice = false, sawText = false;
|
|
@@ -674,16 +469,10 @@ function createStreamAccumulator(onReasoning, now = Date.now) {
|
|
|
674
469
|
return malformed();
|
|
675
470
|
return value;
|
|
676
471
|
};
|
|
677
|
-
// The decode window opens at the first generated fragment and closes at the last: prompt
|
|
678
|
-
// processing ends where the first stamp falls, and everything between requests (tool runs,
|
|
679
|
-
// retries, the usage tail) is outside the pair. A stream that answers in a single fragment or
|
|
680
|
-
// a single burst gives no pace, and no window is claimed (see createDecodeWindow).
|
|
681
472
|
const stampOutput = (text) => decode.stamp(text);
|
|
682
473
|
const decodeWindow = () => decode.measure();
|
|
683
474
|
return {
|
|
684
|
-
/** Whether the stream delivered a choice with a finish reason, i.e. truly completed. */
|
|
685
475
|
get completed() { return sawChoice && finishReason !== undefined; },
|
|
686
|
-
/** The measured decode window, or undefined when the stream never gave one. */
|
|
687
476
|
get decodeMs() { return decodeWindow(); },
|
|
688
477
|
event(data) {
|
|
689
478
|
if (data === '[DONE]')
|
|
@@ -703,7 +492,6 @@ function createStreamAccumulator(onReasoning, now = Date.now) {
|
|
|
703
492
|
}
|
|
704
493
|
const choices = chunk.choices;
|
|
705
494
|
if (choices === undefined) {
|
|
706
|
-
// The usage-only final chunk carries no choices; a chunk without either is malformed.
|
|
707
495
|
if (chunkUsage === undefined)
|
|
708
496
|
return malformed();
|
|
709
497
|
return;
|
|
@@ -724,20 +512,12 @@ function createStreamAccumulator(onReasoning, now = Date.now) {
|
|
|
724
512
|
reasoning += reasoningDelta;
|
|
725
513
|
onReasoning(reasoningDelta);
|
|
726
514
|
}
|
|
727
|
-
// The decode window counts every representation the production parser streams as thinking:
|
|
728
|
-
// openai-completions.ts takes the first non-empty of reasoning_content, reasoning, and
|
|
729
|
-
// reasoning_text, so a model that answers its reasoning through the other fields is still
|
|
730
|
-
// generating, and its window must open at that first fragment rather than at the answer.
|
|
731
515
|
const thinking = reasoningDelta || text(delta.reasoning) || text(delta.reasoning_text);
|
|
732
516
|
if (thinking) {
|
|
733
517
|
stampOutput(thinking);
|
|
734
518
|
blankCalls.progress();
|
|
735
519
|
}
|
|
736
520
|
const contentDelta = text(delta.content);
|
|
737
|
-
// An empty content string still records the field's presence: the whole-body path
|
|
738
|
-
// distinguishes `content: ""` from `null`, and the streamed answer must keep that
|
|
739
|
-
// distinction so an empty completion reaches the runtime's bounded repair loop
|
|
740
|
-
// instead of failing as a malformed response.
|
|
741
521
|
if (contentDelta !== null) {
|
|
742
522
|
sawText = true;
|
|
743
523
|
if (contentDelta) {
|
|
@@ -794,12 +574,8 @@ function createStreamAccumulator(onReasoning, now = Date.now) {
|
|
|
794
574
|
finish(requests, completionAdvertised) {
|
|
795
575
|
if (!sawChoice)
|
|
796
576
|
return malformed();
|
|
797
|
-
// Refusals are valid model output, even when content is null. Preserve the
|
|
798
|
-
// text for normal bounded completion handling instead of a transport error.
|
|
799
577
|
const body = [content, refusal].filter((value) => typeof value === 'string' && value.length > 0).join('\n');
|
|
800
578
|
const measured = decodeWindow();
|
|
801
|
-
// Truncated function arguments may not be JSON (or even contain a name yet).
|
|
802
|
-
// Discard the entire batch and let the runtime apply its bounded repair policy.
|
|
803
579
|
if (finishReason === 'length' || finishReason === 'content_filter') {
|
|
804
580
|
return { text: body, toolCalls: [], usage: { ...usage(chunkUsage, false), requests, ...(measured === undefined ? {} : { decodeMs: measured }) }, stopReason: finishReason };
|
|
805
581
|
}
|
|
@@ -814,7 +590,6 @@ function createStreamAccumulator(onReasoning, now = Date.now) {
|
|
|
814
590
|
},
|
|
815
591
|
};
|
|
816
592
|
}
|
|
817
|
-
/** Validate original Anthropic JSON fragments before upstream's display-oriented JSON salvage. */
|
|
818
593
|
function createAnthropicStreamAccumulator(now = Date.now) {
|
|
819
594
|
const blocks = new Map();
|
|
820
595
|
let started = false, stopped = false, finishReason;
|
|
@@ -827,12 +602,9 @@ function createAnthropicStreamAccumulator(now = Date.now) {
|
|
|
827
602
|
return malformed();
|
|
828
603
|
return block;
|
|
829
604
|
};
|
|
830
|
-
// Same decode-window rule as the OpenAI-compatible accumulator: the first generated fragment
|
|
831
|
-
// opens the window and the last closes it, so prompt processing and inter-request time stay out.
|
|
832
605
|
const stampOutput = (text) => decode.stamp(text);
|
|
833
606
|
const decodeWindow = () => decode.measure();
|
|
834
607
|
return {
|
|
835
|
-
/** The measured decode window, or undefined when the stream never gave one. */
|
|
836
608
|
get decodeMs() { return decodeWindow(); },
|
|
837
609
|
event(data) {
|
|
838
610
|
let parsed;
|
|
@@ -889,9 +661,6 @@ function createAnthropicStreamAccumulator(now = Date.now) {
|
|
|
889
661
|
const piece = delta[delta.type === 'thinking_delta' ? 'thinking' : 'signature'];
|
|
890
662
|
if (typeof piece !== 'string')
|
|
891
663
|
return malformed();
|
|
892
|
-
// A signature is continuation metadata (stored as `thinkingSignature`), not generated
|
|
893
|
-
// text: weighing it would let a long signature in the opening burst outweigh a paced
|
|
894
|
-
// answer, and the window must not open at it either.
|
|
895
664
|
if (piece && delta.type === 'thinking_delta')
|
|
896
665
|
stampOutput(piece);
|
|
897
666
|
}
|
|
@@ -922,7 +691,6 @@ function createAnthropicStreamAccumulator(now = Date.now) {
|
|
|
922
691
|
const text = ordered.filter(block => block.type === 'text').map(block => block.text).join('\n');
|
|
923
692
|
const measured = decodeWindow();
|
|
924
693
|
const measuredUsage = { requests, ...(measured === undefined ? {} : { decodeMs: measured }) };
|
|
925
|
-
// An explicit output limit discards the entire tool batch, including unfinished fragments.
|
|
926
694
|
if (finishReason === 'max_tokens')
|
|
927
695
|
return { text, toolCalls: [], stopReason: 'length', usage: { ...measuredUsage } };
|
|
928
696
|
if (ordered.some(block => !block.stopped))
|
|
@@ -935,7 +703,9 @@ function createAnthropicStreamAccumulator(now = Date.now) {
|
|
|
935
703
|
},
|
|
936
704
|
};
|
|
937
705
|
}
|
|
938
|
-
|
|
706
|
+
/** The router reads `x-andorra-session` only in this form and ignores anything else, so nothing else is sent. */
|
|
707
|
+
const ANDORRA_SESSION_ID = /^[A-Za-z0-9._:-]{1,128}$/;
|
|
708
|
+
export function createAdapter(config, options = {}) {
|
|
939
709
|
if (config.reasoningEffort !== undefined && (!['openai-compatible', 'opencode-go', 'anthropic'].includes(config.type) || !REASONING_EFFORTS.includes(config.reasoningEffort)))
|
|
940
710
|
throw new Error('Reasoning effort overrides require an OpenAI-compatible, OpenCode Go or Anthropic provider and a supported effort value.');
|
|
941
711
|
assertRequestTimeout(config);
|
|
@@ -951,9 +721,11 @@ export function createAdapter(config) {
|
|
|
951
721
|
return createOpenCodeCliAdapter(config);
|
|
952
722
|
if (config.type === 'opencode-go')
|
|
953
723
|
return createOpenCodeAdapter(config);
|
|
724
|
+
const andorra = config.type === 'andorra';
|
|
954
725
|
let base;
|
|
726
|
+
// An Andorra entry's saved URL is informational: requests always go to the router (or its loopback override).
|
|
955
727
|
try {
|
|
956
|
-
base = new URL(config.baseUrl);
|
|
728
|
+
base = new URL(andorra ? andorraBaseUrl() : config.baseUrl);
|
|
957
729
|
}
|
|
958
730
|
catch {
|
|
959
731
|
throw new Error('Provider base URL is invalid.');
|
|
@@ -961,31 +733,17 @@ export function createAdapter(config) {
|
|
|
961
733
|
if (!['https:', 'http:'].includes(base.protocol) || base.username || base.password || base.search || base.hash) {
|
|
962
734
|
throw new Error('Provider base URL must be HTTP(S) without credentials, query, or fragment.');
|
|
963
735
|
}
|
|
964
|
-
if (config.type !== 'openai-compatible' && config.type !== 'anthropic')
|
|
736
|
+
if (config.type !== 'openai-compatible' && config.type !== 'anthropic' && !andorra)
|
|
965
737
|
throw new Error('Unsupported provider type.');
|
|
738
|
+
const sessionHeader = andorra && options.sessionId !== undefined && ANDORRA_SESSION_ID.test(options.sessionId)
|
|
739
|
+
? { 'x-andorra-session': options.sessionId } : {};
|
|
966
740
|
const anthropic = config.type === 'anthropic';
|
|
967
|
-
// Resolved once per adapter: `0` is the explicit "no bound" spelling, so the caller's signal
|
|
968
|
-
// stays the only abort source and a slow-but-working request is never cut short.
|
|
969
741
|
const requestTimeoutMs = config.requestTimeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS;
|
|
970
|
-
// Discovery keeps its own bound even when inference has none, but a provider that asked for
|
|
971
|
-
// something shorter than that still gets it.
|
|
972
742
|
const listingTimeoutMs = requestTimeoutMs > 0 ? Math.min(requestTimeoutMs, MODEL_LISTING_TIMEOUT_MS) : MODEL_LISTING_TIMEOUT_MS;
|
|
973
|
-
// A configured stream inactivity bound owns inference idleness on its own, so a provider that
|
|
974
|
-
// removed `requestTimeoutMs` for a slow prefill still ends a stream that stops delivering bytes.
|
|
975
743
|
const inferenceTimeoutMs = config.streamIdleTimeoutMs ?? requestTimeoutMs;
|
|
976
|
-
/**
|
|
977
|
-
* One HTTP exchange under the caller's signal plus this call's own deadline.
|
|
978
|
-
*
|
|
979
|
-
* The deadline is kept separate from the caller's signal rather than pre-combined, because the
|
|
980
|
-
* two failures must not be confused: a caller that cancelled is a cancellation, while a deadline
|
|
981
|
-
* this adapter armed is a timeout. Collapsing them reported a stalled endpoint as a user
|
|
982
|
-
* cancellation. The deadline is returned so a failure while reading the body afterwards can
|
|
983
|
-
* still be told apart the same way.
|
|
984
|
-
*/
|
|
985
744
|
async function send(path, signal, body, timeoutMs, inference = false, forceRefresh = false) {
|
|
986
745
|
if (signal.aborted)
|
|
987
746
|
cancelled();
|
|
988
|
-
// Credentials can need a token refresh, which is bounded by this request's own deadline too.
|
|
989
747
|
const authDeadline = timeoutMs > 0 ? AbortSignal.timeout(timeoutMs) : undefined;
|
|
990
748
|
let credential;
|
|
991
749
|
try {
|
|
@@ -998,8 +756,7 @@ export function createAdapter(config) {
|
|
|
998
756
|
throw new RetryableProviderError('Provider request timed out.');
|
|
999
757
|
throw error;
|
|
1000
758
|
}
|
|
1001
|
-
const headers = { 'content-type': 'application/json', ...credential };
|
|
1002
|
-
// The credential this request carries, whichever header holds it, so a rejection that echoes it is redacted.
|
|
759
|
+
const headers = { 'content-type': 'application/json', ...sessionHeader, ...credential };
|
|
1003
760
|
const key = headers['x-api-key'] ?? headers.authorization?.replace(/^Bearer /, '');
|
|
1004
761
|
const idle = inference && timeoutMs > 0 ? new AbortController() : undefined;
|
|
1005
762
|
let timer;
|
|
@@ -1027,16 +784,19 @@ export function createAdapter(config) {
|
|
|
1027
784
|
throw new Error('Provider request cancelled.');
|
|
1028
785
|
if (deadline?.aborted)
|
|
1029
786
|
throw new RetryableProviderError('Provider request timed out.');
|
|
1030
|
-
//
|
|
1031
|
-
//
|
|
787
|
+
// A connection that could not be made is not one of the router's refusals: it gets the usual bounded
|
|
788
|
+
// retries, and the plain sentence (no address, no error code) while retrying and when they run out.
|
|
789
|
+
if (andorra) {
|
|
790
|
+
if (permanentConnectionFailure(error))
|
|
791
|
+
throw new ProviderRequestError(ANDORRA_UNAVAILABLE_MESSAGE);
|
|
792
|
+
throw new RetryableProviderError(ANDORRA_UNAVAILABLE_MESSAGE);
|
|
793
|
+
}
|
|
1032
794
|
const cause = connectionFailureDetail(error);
|
|
1033
795
|
const message = `Provider connection failed${cause ? ` (${cause})` : ''}. Check its URL and network connection.`;
|
|
1034
796
|
if (permanentConnectionFailure(error))
|
|
1035
797
|
throw new ProviderRequestError(message);
|
|
1036
798
|
throw new RetryableProviderError(message);
|
|
1037
799
|
}
|
|
1038
|
-
// A Console token can be revoked before its recorded expiry; one refresh tells that apart from a
|
|
1039
|
-
// login that is really gone, which then fails below like any other rejected credential.
|
|
1040
800
|
if (response.status === 401 && config.anthropicAuth === 'console' && !forceRefresh) {
|
|
1041
801
|
dispose();
|
|
1042
802
|
await response.body?.cancel().catch(() => { });
|
|
@@ -1044,22 +804,19 @@ export function createAdapter(config) {
|
|
|
1044
804
|
}
|
|
1045
805
|
if (!response.ok) {
|
|
1046
806
|
try {
|
|
1047
|
-
// HTTP 413 is sufficient evidence that this payload exceeds the gateway's
|
|
1048
|
-
// allowance. Do not depend on error-body format or read an unbounded body.
|
|
1049
807
|
if (response.status === 413) {
|
|
1050
808
|
await response.body?.cancel().catch(() => { });
|
|
1051
809
|
throw new ProviderRequestError('Provider input exceeds the context window.', true);
|
|
1052
810
|
}
|
|
1053
811
|
const errorData = await boundedJson(response).catch(() => undefined);
|
|
1054
|
-
// Context overflow is a classification, not a provider message: reporting it the same
|
|
1055
|
-
// way every time keeps retry policy and the run record stable across providers.
|
|
1056
812
|
if ([400, 422].includes(response.status) && errorData !== undefined && isEngineContextOverflow(JSON.stringify(errorData))) {
|
|
1057
813
|
throw new ProviderRequestError('Provider input exceeds the context window.', true);
|
|
1058
814
|
}
|
|
1059
815
|
await response.body?.cancel().catch(() => { });
|
|
1060
|
-
//
|
|
1061
|
-
|
|
1062
|
-
|
|
816
|
+
// The router's own refusals are sent once and shown as written here, never retried.
|
|
817
|
+
const refusal = andorra ? andorraRefusal(response.status, errorData, response.headers.get('retry-after')) : undefined;
|
|
818
|
+
if (refusal)
|
|
819
|
+
throw new ProviderRequestError(refusal);
|
|
1063
820
|
const detail = providerErrorDetail(errorData);
|
|
1064
821
|
const shown = detail === undefined ? undefined : redactCredential(detail, key);
|
|
1065
822
|
const message = `Provider request failed (HTTP ${response.status})${shown ? `: ${shown}` : ''}. Check credentials, model, and provider availability.`;
|
|
@@ -1158,11 +915,6 @@ export function createAdapter(config) {
|
|
|
1158
915
|
return malformed();
|
|
1159
916
|
}
|
|
1160
917
|
}
|
|
1161
|
-
/**
|
|
1162
|
-
* Run one serialized inference attempt under the shared retry policy; never re-enter the
|
|
1163
|
-
* agent/tool loop. Both the whole-body and the streaming request use it, so a connection
|
|
1164
|
-
* that drops mid-stream restarts the same request exactly like a failed handshake.
|
|
1165
|
-
*/
|
|
1166
918
|
async function withRetries(attempt, signal, onRetry, prepareRetry) {
|
|
1167
919
|
for (let retry = 0;; retry++) {
|
|
1168
920
|
if (signal.aborted)
|
|
@@ -1175,21 +927,16 @@ export function createAdapter(config) {
|
|
|
1175
927
|
cancelled();
|
|
1176
928
|
if (!(error instanceof RetryableProviderError))
|
|
1177
929
|
throw error;
|
|
1178
|
-
// Record request-local recovery state even when this was the final allowed attempt.
|
|
1179
|
-
// In particular, a malformed fourth response must still trip the adapter's sticky
|
|
1180
|
-
// whole-body circuit breaker for the next independent generation.
|
|
1181
930
|
prepareRetry?.(error);
|
|
1182
|
-
if (retry >=
|
|
931
|
+
if (retry >= error.maxRetries)
|
|
1183
932
|
throw error;
|
|
1184
|
-
// Never retry earlier than the server requests. The staged schedule gives transient
|
|
1185
|
-
// local/network failures time to recover without hammering the endpoint.
|
|
1186
933
|
if (error.retryAfterMs > MAX_AUTOMATIC_RETRY_AFTER_MS)
|
|
1187
934
|
throw new ProviderRequestError(`${error.message} Retry-After exceeds the 120-second automatic retry limit.`);
|
|
1188
935
|
const delayMs = Math.max(error.retryDelaysMs[retry] ?? error.retryDelaysMs.at(-1) ?? 0, error.retryAfterMs);
|
|
1189
936
|
const reason = error instanceof MalformedStreamProviderError
|
|
1190
937
|
? 'Provider returned a malformed streamed response; retrying without streaming.'
|
|
1191
938
|
: error.message;
|
|
1192
|
-
await onRetry?.({ retry: retry + 1, maxRetries:
|
|
939
|
+
await onRetry?.({ retry: retry + 1, maxRetries: error.maxRetries, delayMs, reason, ...(error.quiet ? { quiet: true } : {}) });
|
|
1193
940
|
try {
|
|
1194
941
|
await delay(delayMs, undefined, { signal });
|
|
1195
942
|
}
|
|
@@ -1199,9 +946,6 @@ export function createAdapter(config) {
|
|
|
1199
946
|
}
|
|
1200
947
|
}
|
|
1201
948
|
}
|
|
1202
|
-
// A provider that emits malformed SSE is kept on whole-body responses for this adapter's
|
|
1203
|
-
// lifetime. Recreating/switching the provider probes streaming again without repeatedly
|
|
1204
|
-
// sacrificing long generations to a known-bad stream path.
|
|
1205
949
|
let preferNonStreaming = false;
|
|
1206
950
|
return {
|
|
1207
951
|
async generate(input) {
|
|
@@ -1218,14 +962,11 @@ export function createAdapter(config) {
|
|
|
1218
962
|
contextWindow: model === config.model ? config.contextWindow ?? 128_000 : 128_000,
|
|
1219
963
|
reasoningEffort: model === config.model ? config.reasoningEffort : undefined,
|
|
1220
964
|
async send(body) {
|
|
1221
|
-
// A failed send must not inherit an expired deadline from an earlier response.
|
|
1222
965
|
deadline = undefined;
|
|
1223
966
|
dispose?.();
|
|
1224
967
|
dispose = undefined;
|
|
1225
968
|
requests++;
|
|
1226
969
|
onRequest?.();
|
|
1227
|
-
// Re-read the adapter-wide breaker for every attempt: another concurrent
|
|
1228
|
-
// invocation may have discovered a broken stream while this one was backing off.
|
|
1229
970
|
currentRequestNonStreaming = forceNonStreaming || preferNonStreaming;
|
|
1230
971
|
const requestBody = currentRequestNonStreaming
|
|
1231
972
|
? (() => { const plain = { ...body }; delete plain.stream_options; plain.stream = false; return plain; })()
|
|
@@ -1305,6 +1046,8 @@ export function createAdapter(config) {
|
|
|
1305
1046
|
cancelled();
|
|
1306
1047
|
if (deadline?.aborted)
|
|
1307
1048
|
throw new RetryableProviderError('Provider request timed out.');
|
|
1049
|
+
if (error instanceof Error && !(error instanceof RetryableProviderError) && error.message === MALFORMED_RESPONSE_MESSAGE)
|
|
1050
|
+
throw new MalformedResponseProviderError();
|
|
1308
1051
|
throw error;
|
|
1309
1052
|
}).finally(() => { dispose?.(); dispose = undefined; }), signal, onRetry, error => {
|
|
1310
1053
|
if (error instanceof MalformedStreamProviderError) {
|