mixdog 0.9.172 → 0.9.173
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/package.json +3 -3
- package/scripts/code-graph-description-contract.mjs +1 -2
- package/scripts/context-renewal-live-check.mjs +1 -1
- package/scripts/coverage-query.mjs +27 -0
- package/scripts/generate-runtime-manifest.mjs +12 -16
- package/scripts/graph-parity.mjs +108 -75
- package/scripts/lib/coverage.mjs +309 -0
- package/scripts/lib/embedding-model-bench-core.mjs +4 -2
- package/scripts/lib/recall-bench-eval.mjs +4 -4
- package/scripts/lib/run-node-tests.mjs +137 -13
- package/scripts/lib/test-failure-records.mjs +46 -0
- package/scripts/lib/test-failure-summary.mjs +59 -0
- package/scripts/lib/test-summary-reporter.mjs +7 -3
- package/scripts/mouse-probe.mjs +1 -3
- package/scripts/office/build-pptx-icons.mjs +0 -1
- package/scripts/perf/transcript-runtime-probe.mjs +20 -4
- package/scripts/pg-memory-diet.mjs +2 -4
- package/scripts/routing-corpus.mjs +0 -2
- package/scripts/session-diag.mjs +0 -7
- package/scripts/session-sweep.mjs +102 -56
- package/scripts/test.mjs +113 -37
- package/scripts/tui-frame-harness.mjs +1 -1
- package/src/app.mjs +79 -74
- package/src/cli.mjs +0 -2
- package/src/defaults/skills/browser-use/SKILL.md +8 -6
- package/src/defaults/skills/code-tidy/SKILL.md +67 -17
- package/src/defaults/skills/code-tidy/references/agent-cleanup.md +26 -3
- package/src/defaults/skills/computer-use/SKILL.md +12 -5
- package/src/defaults/skills/goal-management/SKILL.md +16 -9
- package/src/defaults/skills/pdf/SKILL.md +2 -1
- package/src/defaults/skills/xlsx/SKILL.md +3 -3
- package/src/headless-exec.mjs +1 -2
- package/src/help.mjs +2 -2
- package/src/lib/rules-builder.cjs +0 -23
- package/src/repl/slash-commands.mjs +1 -5
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch/turn.mjs +4 -4
- package/src/runtime/agent/orchestrator/agent-runtime/cache-strategy.mjs +25 -41
- package/src/runtime/agent/orchestrator/agent-trace-format.mjs +25 -24
- package/src/runtime/agent/orchestrator/agent-trace-io.mjs +15 -22
- package/src/runtime/agent/orchestrator/agent-trace.mjs +0 -22
- package/src/runtime/agent/orchestrator/config-providers-merge.mjs +56 -0
- package/src/runtime/agent/orchestrator/config.mjs +34 -76
- package/src/runtime/agent/orchestrator/context/role-instructions.mjs +1 -1
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +40 -39
- package/src/runtime/agent/orchestrator/providers/anthropic-api-recovery.mjs +75 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-api-request.mjs +152 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-api-transport.mjs +168 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-messages.mjs +2 -1
- package/src/runtime/agent/orchestrator/providers/anthropic-midstream-recovery.mjs +248 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-midstream.mjs +16 -206
- package/src/runtime/agent/orchestrator/providers/anthropic-oauth-recovery.mjs +11 -63
- package/src/runtime/agent/orchestrator/providers/anthropic-recovery-guards.mjs +86 -0
- package/src/runtime/agent/orchestrator/providers/anthropic-turn-result.mjs +88 -0
- package/src/runtime/agent/orchestrator/providers/anthropic.mjs +87 -591
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth.mjs +32 -288
- package/src/runtime/agent/orchestrator/providers/antigravity-response.mjs +101 -0
- package/src/runtime/agent/orchestrator/providers/antigravity-stream.mjs +161 -0
- package/src/runtime/agent/orchestrator/providers/antigravity-transport.mjs +114 -0
- package/src/runtime/agent/orchestrator/providers/gemini-cache-policy.mjs +266 -0
- package/src/runtime/agent/orchestrator/providers/gemini-request-body.mjs +54 -0
- package/src/runtime/agent/orchestrator/providers/gemini-response.mjs +145 -0
- package/src/runtime/agent/orchestrator/providers/gemini-schema.mjs +56 -39
- package/src/runtime/agent/orchestrator/providers/gemini-sdk-request.mjs +107 -0
- package/src/runtime/agent/orchestrator/providers/gemini.mjs +23 -533
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +10 -4
- package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +83 -32
- package/src/runtime/agent/orchestrator/providers/openai-compat-responses.mjs +41 -25
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-outcome.mjs +4 -98
- package/src/runtime/agent/orchestrator/providers/openai-http-sse-response-state/response-stamps.mjs +114 -0
- package/src/runtime/agent/orchestrator/providers/openai-oauth-dispatch.mjs +258 -0
- package/src/runtime/agent/orchestrator/providers/openai-oauth.mjs +48 -214
- package/src/runtime/agent/orchestrator/providers/openai-responses-input.mjs +80 -60
- package/src/runtime/agent/orchestrator/providers/openai-ws-handshake.mjs +108 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +8 -87
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-outcome.mjs +52 -293
- package/src/runtime/agent/orchestrator/providers/openai-ws-send-trace.mjs +316 -0
- package/src/runtime/agent/orchestrator/providers/opencode-go-usage.mjs +76 -253
- package/src/runtime/agent/orchestrator/session/cache/scoped-cache.mjs +1 -7
- package/src/runtime/agent/orchestrator/session/compact/budget.mjs +17 -16
- package/src/runtime/agent/orchestrator/session/compact/runner.mjs +6 -4
- package/src/runtime/agent/orchestrator/session/compact/summary-schema.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/context-compaction-policy.mjs +9 -13
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +1 -2
- package/src/runtime/agent/orchestrator/session/evidence-union.mjs +6 -9
- package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +2 -3
- package/src/runtime/agent/orchestrator/session/loop/diagnostics.mjs +1 -8
- package/src/runtime/agent/orchestrator/session/loop/tool-classify.mjs +1 -3
- package/src/runtime/agent/orchestrator/session/loop/tool-exec/call-prep.mjs +1 -5
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-execute.mjs +0 -1
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-loop-options.mjs +4 -55
- package/src/runtime/agent/orchestrator/session/manager/ask-turn-steering-drain.mjs +63 -0
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/manager/foreign-pending-messages.mjs +80 -65
- package/src/runtime/agent/orchestrator/session/manager/pending-claim-ledger.mjs +68 -0
- package/src/runtime/agent/orchestrator/session/manager/pending-delivered-ledger.mjs +56 -0
- package/src/runtime/agent/orchestrator/session/manager/pending-lifecycle-epoch.mjs +84 -0
- package/src/runtime/agent/orchestrator/session/manager/pending-messages.mjs +51 -651
- package/src/runtime/agent/orchestrator/session/manager/pending-persist-queue.mjs +264 -0
- package/src/runtime/agent/orchestrator/session/manager/pending-spool-file.mjs +131 -0
- package/src/runtime/agent/orchestrator/session/manager/pending-spool-sweep.mjs +73 -0
- package/src/runtime/agent/orchestrator/session/manager/prepared-resume-cache.mjs +122 -0
- package/src/runtime/agent/orchestrator/session/manager/prompt-utils.mjs +2 -1
- package/src/runtime/agent/orchestrator/session/manager/runtime-liveness.mjs +5 -4
- package/src/runtime/agent/orchestrator/session/manager/session-close.mjs +60 -35
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +3 -2
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +22 -646
- package/src/runtime/agent/orchestrator/session/manager/session-owner-liveness.mjs +135 -0
- package/src/runtime/agent/orchestrator/session/manager/session-prompt-composition.mjs +150 -0
- package/src/runtime/agent/orchestrator/session/manager/session-record.mjs +154 -0
- package/src/runtime/agent/orchestrator/session/manager/session-tool-surface.mjs +135 -0
- package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +4 -11
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +0 -6
- package/src/runtime/agent/orchestrator/session/manager/usage-metrics.mjs +1 -3
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +11 -12
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +23 -32
- package/src/runtime/agent/orchestrator/session/store/lifecycle-barriers.mjs +275 -0
- package/src/runtime/agent/orchestrator/session/store/lifecycle-read.mjs +67 -0
- package/src/runtime/agent/orchestrator/session/store/listing.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/store/live-cache-eviction.mjs +72 -0
- package/src/runtime/agent/orchestrator/session/store/liveness-veto.mjs +53 -0
- package/src/runtime/agent/orchestrator/session/store/load-session.mjs +60 -0
- package/src/runtime/agent/orchestrator/session/store/pending-saves.mjs +55 -0
- package/src/runtime/agent/orchestrator/session/store/serialize.mjs +7 -15
- package/src/runtime/agent/orchestrator/session/store/session-delete.mjs +149 -0
- package/src/runtime/agent/orchestrator/session/store/session-observers.mjs +55 -0
- package/src/runtime/agent/orchestrator/session/store/write-admission.mjs +108 -0
- package/src/runtime/agent/orchestrator/session/store-agent-worker-rows.mjs +531 -0
- package/src/runtime/agent/orchestrator/session/store-summary-archived-agent.mjs +126 -0
- package/src/runtime/agent/orchestrator/session/store-summary-fields.mjs +24 -0
- package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +2 -10
- package/src/runtime/agent/orchestrator/session/store-summary-locations.mjs +46 -0
- package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +11 -791
- package/src/runtime/agent/orchestrator/session/store-transcript-projection.mjs +126 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +33 -771
- package/src/runtime/agent/orchestrator/session/tool-batch/finalize.mjs +1 -1
- package/src/runtime/agent/orchestrator/session/tool-result-offload.mjs +13 -7
- package/src/runtime/agent/orchestrator/stable-hash-stringify.mjs +10 -0
- package/src/runtime/agent/orchestrator/tools/builtin/arg-guard.mjs +50 -75
- package/src/runtime/agent/orchestrator/tools/builtin/builtin-tools.mjs +2 -1
- package/src/runtime/agent/orchestrator/tools/builtin/cache-layers.mjs +22 -21
- package/src/runtime/agent/orchestrator/tools/builtin/external-tool-adapters.mjs +0 -2
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.mjs +44 -27
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.mjs +36 -54
- package/src/runtime/agent/orchestrator/tools/builtin/git-partial-stage.mjs +8 -5
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-context-expander.mjs +8 -5
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-output.mjs +18 -9
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-request.mjs +2 -3
- package/src/runtime/agent/orchestrator/tools/builtin/lib/grep-single-file-rescue.mjs +80 -67
- package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-task-output.mjs +12 -4
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-client.mjs +1 -4
- package/src/runtime/agent/orchestrator/tools/builtin/path-diagnostics.mjs +61 -72
- package/src/runtime/agent/orchestrator/tools/builtin/read-formatting.mjs +0 -5
- package/src/runtime/agent/orchestrator/tools/builtin/read-office-files.mjs +3 -3
- package/src/runtime/agent/orchestrator/tools/builtin/read-range-index.mjs +11 -14
- package/src/runtime/agent/orchestrator/tools/builtin/read-single-render.mjs +3 -6
- package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +1 -2
- package/src/runtime/agent/orchestrator/tools/builtin/read-streaming.mjs +124 -94
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/batch-dispatch.mjs +6 -3
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool/reach-preflight.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/read-tool.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/read-windows.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/search-builders.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/search-glob-tool.mjs +6 -6
- package/src/runtime/agent/orchestrator/tools/builtin/search-grep-tool.mjs +2 -2
- package/src/runtime/agent/orchestrator/tools/builtin/shell-analysis.mjs +21 -35
- package/src/runtime/agent/orchestrator/tools/builtin/shell-jobs.mjs +0 -3
- package/src/runtime/agent/orchestrator/tools/builtin/shell-lossless-compact.mjs +1 -3
- package/src/runtime/agent/orchestrator/tools/builtin/shell-output.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/builtin/shell-runtime.mjs +0 -2
- package/src/runtime/agent/orchestrator/tools/builtin/task-tool.mjs +4 -3
- package/src/runtime/agent/orchestrator/tools/builtin/text-stats.mjs +6 -3
- package/src/runtime/agent/orchestrator/tools/builtin.mjs +0 -4
- package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-roots.mjs +7 -7
- package/src/runtime/agent/orchestrator/tools/code-graph/ast-calls.mjs +0 -3
- package/src/runtime/agent/orchestrator/tools/code-graph/build-file-infos.mjs +182 -0
- package/src/runtime/agent/orchestrator/tools/code-graph/build.mjs +14 -159
- package/src/runtime/agent/orchestrator/tools/code-graph/constants.mjs +2 -3
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.mjs +21 -8
- package/src/runtime/agent/orchestrator/tools/code-graph/graph-binary.mjs +0 -3
- package/src/runtime/agent/orchestrator/tools/code-graph/search-references.mjs +5 -3
- package/src/runtime/agent/orchestrator/tools/code-graph/search.mjs +2 -3
- package/src/runtime/agent/orchestrator/tools/code-graph/symbol-index.mjs +1 -2
- package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.golden.json +1 -1
- package/src/runtime/agent/orchestrator/tools/code-graph/text-mask.mjs +0 -1
- package/src/runtime/agent/orchestrator/tools/graph-manifest.json +11 -11
- package/src/runtime/agent/orchestrator/tools/lib/shell-run-state.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/lib/shell-warm-standby.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/patch/dispatch.mjs +3 -6
- package/src/runtime/agent/orchestrator/tools/patch/mutation-output.mjs +1 -1
- package/src/runtime/agent/orchestrator/tools/patch/native-server.mjs +25 -39
- package/src/runtime/agent/orchestrator/tools/patch/parsing.mjs +9 -14
- package/src/runtime/agent/orchestrator/tools/patch/paths.mjs +11 -6
- package/src/runtime/agent/orchestrator/tools/patch/replay-capture.mjs +5 -6
- package/src/runtime/agent/orchestrator/tools/patch/text-lines.mjs +4 -4
- package/src/runtime/agent/orchestrator/tools/patch/v4a-anchors.mjs +10 -7
- package/src/runtime/agent/orchestrator/tools/patch/v4a-convert.mjs +20 -30
- package/src/runtime/agent/orchestrator/tools/patch/v4a-windows.mjs +4 -19
- package/src/runtime/agent/orchestrator/tools/patch/wave.mjs +13 -2
- package/src/runtime/agent/orchestrator/tools/patch.mjs +0 -19
- package/src/runtime/agent/orchestrator/tools/shell-command.mjs +60 -36
- package/src/runtime/agent/orchestrator/tools/shell-exec-output.mjs +0 -4
- package/src/runtime/agent/orchestrator/tools/shell-policy.mjs +6 -7
- package/src/runtime/attachments/store.mjs +13 -12
- package/src/runtime/browser-bridge/client.mjs +19 -9
- package/src/runtime/channels/index.mjs +1 -1
- package/src/runtime/channels/lib/event-pipeline.mjs +8 -8
- package/src/runtime/channels/lib/event-queue.mjs +15 -20
- package/src/runtime/channels/lib/executor.mjs +10 -7
- package/src/runtime/channels/lib/owner-heartbeat.mjs +0 -4
- package/src/runtime/channels/lib/runtime-paths.mjs +30 -33
- package/src/runtime/channels/lib/scheduler.mjs +11 -20
- package/src/runtime/channels/lib/voice-runtime-fetcher.mjs +0 -4
- package/src/runtime/channels/lib/voice-transcription.mjs +127 -104
- package/src/runtime/channels/lib/webhook/verification.mjs +33 -20
- package/src/runtime/channels/lib/worker-bootstrap.mjs +0 -2
- package/src/runtime/channels/lib/worker-main.mjs +2 -2
- package/src/runtime/computer-bridge/action-schema.mjs +20 -0
- package/src/runtime/computer-bridge/core-actions.mjs +15 -0
- package/src/runtime/github/client.mjs +2 -3
- package/src/runtime/github/commands.mjs +9 -3
- package/src/runtime/github/contract.mjs +7 -0
- package/src/runtime/local-provider/catalog.mjs +4 -3
- package/src/runtime/local-provider/hardware.mjs +7 -20
- package/src/runtime/local-provider/resumable-installations.mjs +12 -19
- package/src/runtime/media/auth.mjs +16 -13
- package/src/runtime/media/catalog.mjs +14 -6
- package/src/runtime/media/lanes.mjs +2 -1
- package/src/runtime/memory/index.mjs +5 -10
- package/src/runtime/memory/lib/core-memory-store.mjs +3 -7
- package/src/runtime/memory/lib/embedding-provider.mjs +9 -19
- package/src/runtime/memory/lib/embedding-worker.mjs +24 -28
- package/src/runtime/memory/lib/http-router/admin-routes.mjs +5 -51
- package/src/runtime/memory/lib/http-router/admin-trace-routes.mjs +65 -0
- package/src/runtime/memory/lib/memory-action-handlers/cycle-actions.mjs +18 -143
- package/src/runtime/memory/lib/memory-action-handlers/cycle-backfill-action.mjs +84 -0
- package/src/runtime/memory/lib/memory-action-handlers/cycle-rebuild-action.mjs +94 -0
- package/src/runtime/memory/lib/memory-action-handlers/manage-actions.mjs +92 -53
- package/src/runtime/memory/lib/memory-categories.mjs +13 -0
- package/src/runtime/memory/lib/memory-chunk-quality.mjs +134 -74
- package/src/runtime/memory/lib/memory-cycle-requests.mjs +64 -70
- package/src/runtime/memory/lib/memory-cycle1.mjs +17 -33
- package/src/runtime/memory/lib/memory-embed.mjs +10 -2
- package/src/runtime/memory/lib/memory-ops-policy.mjs +3 -2
- package/src/runtime/memory/lib/memory-recall-scope-filter.mjs +1 -1
- package/src/runtime/memory/lib/memory.mjs +7 -35
- package/src/runtime/memory/lib/pg/adapter.mjs +3 -4
- package/src/runtime/memory/lib/pg/process.mjs +23 -28
- package/src/runtime/memory/lib/pg/supervisor.mjs +10 -11
- package/src/runtime/memory/lib/query-hybrid-search.mjs +2 -2
- package/src/runtime/memory/lib/query-maintenance-handlers.mjs +112 -89
- package/src/runtime/memory/lib/query-ranking.mjs +8 -11
- package/src/runtime/memory/lib/recall-format.mjs +6 -12
- package/src/runtime/memory/lib/recall-hybrid/plan.mjs +1 -1
- package/src/runtime/memory/lib/runtime-fetcher.mjs +73 -65
- package/src/runtime/memory/lib/trace-store.mjs +10 -19
- package/src/runtime/memory/lib/transcript-ingest.mjs +7 -4
- package/src/runtime/memory/tool-defs.mjs +5 -8
- package/src/runtime/office/authoring/pptx-author-action.mjs +2 -2
- package/src/runtime/office/authoring/pptx-author-session.mjs +6 -9
- package/src/runtime/office/authoring/pptx-brief.mjs +11 -4
- package/src/runtime/office/authoring/pptx-receipt.mjs +79 -60
- package/src/runtime/office/bench/benchmark.mjs +102 -82
- package/src/runtime/office/capabilities-catalog.mjs +2 -0
- package/src/runtime/office/capabilities-signatures.mjs +8 -0
- package/src/runtime/office/capabilities.mjs +3 -4
- package/src/runtime/office/com/com-adapter.mjs +13 -1
- package/src/runtime/office/com/office-com-host.ps1 +63 -1
- package/src/runtime/office/core/office-actions-batch.mjs +12 -12
- package/src/runtime/office/core/office-actions-open.mjs +2 -7
- package/src/runtime/office/core/office-core.mjs +20 -1
- package/src/runtime/office/core/office-finalize/session-save.mjs +9 -6
- package/src/runtime/office/core/office-session-dispatch.mjs +86 -0
- package/src/runtime/office/core/office-sessionless-actions.mjs +115 -0
- package/src/runtime/office/core/office-sessions.mjs +2 -2
- package/src/runtime/office/core/office-transactions.mjs +2 -4
- package/src/runtime/office/core/tabular.mjs +13 -16
- package/src/runtime/office/design/composition-system.mjs +32 -28
- package/src/runtime/office/design/content-model.mjs +2 -1
- package/src/runtime/office/design/design-art-direction.mjs +17 -14
- package/src/runtime/office/design/design-creative-director.mjs +1 -1
- package/src/runtime/office/design/design-discipline.mjs +8 -0
- package/src/runtime/office/design/design-tokens.mjs +9 -5
- package/src/runtime/office/design/docx/design-docx-components.mjs +88 -156
- package/src/runtime/office/design/library/design-library-pack.mjs +11 -23
- package/src/runtime/office/design/library/design-library.mjs +15 -37
- package/src/runtime/office/design/library/design-template-index.mjs +1 -9
- package/src/runtime/office/design/library/design-template-induct.mjs +2 -1
- package/src/runtime/office/design/native-design.mjs +2 -3
- package/src/runtime/office/index.mjs +7 -160
- package/src/runtime/office/pdf/pdf-adapter.mjs +17 -2
- package/src/runtime/office/pdf/pdf-ocr.mjs +2 -1
- package/src/runtime/office/pdf/pdf-render.mjs +12 -13
- package/src/runtime/office/pdf/pdf-writer.mjs +135 -6
- package/src/runtime/office/portable/docx-revisions.mjs +5 -5
- package/src/runtime/office/portable/docx-runs.mjs +4 -7
- package/src/runtime/office/portable/docx-tracked-edits.mjs +14 -9
- package/src/runtime/office/portable/font-provisioner.mjs +2 -2
- package/src/runtime/office/portable/ooxml-validator.mjs +4 -1
- package/src/runtime/office/portable/portable-docx-edits.mjs +61 -45
- package/src/runtime/office/portable/portable-docx-operations.mjs +13 -4
- package/src/runtime/office/portable/portable-docx-parts.mjs +59 -70
- package/src/runtime/office/portable/portable-docx-xml.mjs +3 -5
- package/src/runtime/office/portable/portable-opc.mjs +63 -39
- package/src/runtime/office/portable/portable-package.mjs +5 -23
- package/src/runtime/office/portable/portable-pptx-chart.mjs +7 -6
- package/src/runtime/office/portable/portable-pptx-charts.mjs +27 -20
- package/src/runtime/office/portable/portable-pptx-core.mjs +10 -21
- package/src/runtime/office/portable/portable-pptx-deck.mjs +5 -8
- package/src/runtime/office/portable/portable-pptx-package.mjs +23 -30
- package/src/runtime/office/portable/portable-pptx-shapes.mjs +21 -57
- package/src/runtime/office/portable/portable-sheet-audits.mjs +14 -36
- package/src/runtime/office/portable/portable-sheet-page.mjs +22 -23
- package/src/runtime/office/portable/portable-sheet-parts.mjs +4 -5
- package/src/runtime/office/portable/portable-sheet-styles.mjs +11 -19
- package/src/runtime/office/portable/portable-sheet-xml.mjs +15 -7
- package/src/runtime/office/portable/portable-slide-shapes.mjs +4 -0
- package/src/runtime/office/portable/portable-snapshot-pptx.mjs +2 -2
- package/src/runtime/office/portable/portable-snapshot-shared.mjs +1 -1
- package/src/runtime/office/portable/portable-snapshot-xlsx.mjs +16 -17
- package/src/runtime/office/portable/portable-soffice.mjs +176 -13
- package/src/runtime/office/portable/portable-validation-package.mjs +16 -18
- package/src/runtime/office/portable/portable-validation.mjs +57 -31
- package/src/runtime/office/portable/portable-xlsx-cell-values.mjs +15 -0
- package/src/runtime/office/portable/portable-xlsx-charts.mjs +192 -0
- package/src/runtime/office/portable/portable-xlsx-drawings.mjs +323 -0
- package/src/runtime/office/portable/portable-xlsx-operations.mjs +29 -627
- package/src/runtime/office/portable/portable-xlsx-pivot-ops.mjs +94 -0
- package/src/runtime/office/portable/portable-xlsx-range-layout.mjs +236 -0
- package/src/runtime/office/portable/portable-xlsx-sheet-edits.mjs +19 -14
- package/src/runtime/office/portable/portable-xlsx.mjs +32 -0
- package/src/runtime/office/portable/portable-xml.mjs +9 -0
- package/src/runtime/office/portable/pptx-relations.mjs +11 -0
- package/src/runtime/office/portable/pptx-targets.mjs +2 -1
- package/src/runtime/office/portable/review-editability.mjs +4 -11
- package/src/runtime/office/portable/text-metrics.mjs +35 -55
- package/src/runtime/office/portable/xlsx-assertions.mjs +2 -15
- package/src/runtime/office/portable/xlsx-audit-support.mjs +2 -6
- package/src/runtime/office/portable/xlsx-contract.mjs +4 -0
- package/src/runtime/office/portable/xlsx-formula-audit.mjs +11 -4
- package/src/runtime/office/portable/xlsx-recalculate.mjs +1 -1
- package/src/runtime/office/portable/xlsx-sheet-hygiene.mjs +5 -1
- package/src/runtime/office/quality/assurance-rendered.mjs +3 -2
- package/src/runtime/office/quality/assurance-structure-pptx.mjs +16 -15
- package/src/runtime/office/quality/assurance-trust.mjs +25 -10
- package/src/runtime/office/quality/design-aesthetics.mjs +172 -145
- package/src/runtime/office/quality/design-deck-diversity.mjs +2 -5
- package/src/runtime/office/quality/design-review-authored.mjs +2 -2
- package/src/runtime/office/quality/design-review-critique.mjs +36 -37
- package/src/runtime/office/quality/design-review.mjs +113 -96
- package/src/runtime/office/quality/document-acceptance.mjs +10 -3
- package/src/runtime/office/quality/inline-audit.mjs +7 -2
- package/src/runtime/office/quality/pptx-deck-rubric.mjs +14 -6
- package/src/runtime/office/quality/pptx-slide-roles.mjs +7 -9
- package/src/runtime/office/quality/presentation-acceptance.mjs +2 -6
- package/src/runtime/office/quality/quality-pipeline.mjs +21 -14
- package/src/runtime/office/quality/quality-score.mjs +2 -2
- package/src/runtime/office/quality/render-air.mjs +12 -5
- package/src/runtime/shared/atomic-file.mjs +19 -8
- package/src/runtime/shared/config.mjs +7 -13
- package/src/runtime/shared/err-text.mjs +11 -6
- package/src/runtime/shared/file-lock.mjs +10 -6
- package/src/runtime/shared/inline-file-kind.mjs +51 -0
- package/src/runtime/shared/llm/usage-accounting.mjs +9 -6
- package/src/runtime/shared/llm/usage-ledger-rollup.mjs +272 -0
- package/src/runtime/shared/llm/usage-ledger.mjs +8 -218
- package/src/runtime/shared/pristine-execution.mjs +2 -6
- package/src/runtime/shared/process-lifecycle.mjs +34 -52
- package/src/runtime/shared/process-shutdown.mjs +1 -1
- package/src/runtime/shared/schedule-model-ref.mjs +14 -0
- package/src/runtime/shared/schedule-session-run.mjs +3 -13
- package/src/runtime/shared/schedules-db.mjs +16 -39
- package/src/runtime/shared/staged-child-result.mjs +2 -7
- package/src/runtime/shared/staged-update.mjs +1 -5
- package/src/runtime/shared/tool-card-model/agent-surface.mjs +8 -3
- package/src/runtime/shared/tool-card-model/card-status.mjs +2 -1
- package/src/runtime/shared/tool-card-model/displayed-result.mjs +2 -3
- package/src/runtime/shared/tool-card-model/generic-detail.mjs +5 -3
- package/src/runtime/shared/tool-card-model.golden-cases.mjs +10 -2
- package/src/runtime/shared/tool-card-model.golden.json +3 -12
- package/src/runtime/shared/tool-execution-contract.mjs +22 -26
- package/src/runtime/shared/tool-result-summary.mjs +7 -14
- package/src/runtime/shared/tool-surface.mjs +30 -33
- package/src/runtime/shared/tool-work-units.mjs +12 -8
- package/src/runtime/shared/turn-snapshot-store.mjs +2 -4
- package/src/runtime/shared/turn-worktree-snapshot.mjs +13 -16
- package/src/runtime/shared/update-checker.mjs +5 -0
- package/src/runtime/shared/user-data-guard.mjs +10 -17
- package/src/runtime/shared/webhook-session-run.mjs +3 -15
- package/src/runtime/tidy/history-comment.mjs +32 -27
- package/src/runtime/tidy/process.mjs +18 -21
- package/src/runtime/tidy/report.mjs +50 -9
- package/src/runtime/tidy/resolve.mjs +13 -14
- package/src/runtime/tidy/runners/air.mjs +2 -20
- package/src/runtime/tidy/runners/biome.mjs +4 -6
- package/src/runtime/tidy/runners/dprint.mjs +2 -23
- package/src/runtime/tidy/runners/mago.mjs +2 -20
- package/src/runtime/tidy/runners/ruff.mjs +2 -8
- package/src/runtime/tidy/runners/shared.mjs +35 -9
- package/src/runtime/tidy/runners/stylua.mjs +2 -20
- package/src/runtime/tidy/shadow.mjs +138 -0
- package/src/runtime/tidy/tool.mjs +33 -0
- package/src/runtime/tidy/worktree.mjs +114 -0
- package/src/runtime/web-search/index.mjs +64 -68
- package/src/runtime/web-search/lib/http-fetch.mjs +39 -54
- package/src/runtime/web-search/lib/ssrf-guard.mjs +19 -52
- package/src/runtime/web-search/lib/web-tools.mjs +2 -2
- package/src/session-runtime/config-helpers.mjs +9 -9
- package/src/session-runtime/context-inspection.mjs +64 -23
- package/src/session-runtime/context-status-cache.mjs +0 -2
- package/src/session-runtime/context-status-inspection.mjs +54 -25
- package/src/session-runtime/context-status-shape.mjs +1 -18
- package/src/session-runtime/goal-facade-api.mjs +15 -12
- package/src/session-runtime/goal-mutations.mjs +4 -3
- package/src/session-runtime/goal-runtime.mjs +5 -0
- package/src/session-runtime/goal-tasks.mjs +5 -10
- package/src/session-runtime/goal-text.mjs +46 -9
- package/src/session-runtime/goal-tool-defs.mjs +7 -8
- package/src/session-runtime/goal-tool-exec.mjs +1 -1
- package/src/session-runtime/goal-turns.mjs +54 -3
- package/src/session-runtime/hook-payload.mjs +2 -1
- package/src/session-runtime/inheritance-fit.mjs +3 -3
- package/src/session-runtime/lifecycle/teardown.mjs +9 -1
- package/src/session-runtime/mcp-glue/server-catalog.mjs +4 -6
- package/src/session-runtime/model-capabilities.mjs +1 -3
- package/src/session-runtime/notification-bus.mjs +30 -7
- package/src/session-runtime/plugin-mcp.mjs +0 -2
- package/src/session-runtime/provider-auth/accounts.mjs +2 -2
- package/src/session-runtime/provider-auth/login.mjs +0 -7
- package/src/session-runtime/provider-usage.mjs +1 -1
- package/src/session-runtime/runtime-paths.mjs +1 -3
- package/src/session-runtime/session-hooks.mjs +37 -96
- package/src/session-runtime/statusline-route.mjs +1 -4
- package/src/session-runtime/tool-catalog-schema.mjs +0 -6
- package/src/session-runtime/tool-catalog.mjs +10 -15
- package/src/session-runtime/workflow-ids.mjs +1 -2
- package/src/standalone/agent-task-status.mjs +1 -2
- package/src/standalone/agent-tool/close-flow/close-all.mjs +67 -0
- package/src/standalone/agent-tool/close-flow.mjs +2 -58
- package/src/standalone/agent-tool/execute-send.mjs +91 -0
- package/src/standalone/agent-tool/execute-spawn.mjs +76 -0
- package/src/standalone/agent-tool/execute.mjs +7 -147
- package/src/standalone/agent-tool/helpers.mjs +3 -6
- package/src/standalone/agent-tool/notify/early-completion.mjs +58 -0
- package/src/standalone/agent-tool/notify.mjs +7 -55
- package/src/standalone/agent-tool/provider-init.mjs +73 -64
- package/src/standalone/agent-tool/render.mjs +123 -115
- package/src/standalone/agent-tool/spawn-flow/spawn-plan.mjs +89 -0
- package/src/standalone/agent-tool/spawn-flow/spawn-prep.mjs +16 -75
- package/src/standalone/agent-tool/spawn-flow/spawn-run.mjs +1 -1
- package/src/standalone/agent-tool/worker-rows.mjs +0 -7
- package/src/standalone/channel-admin.mjs +13 -18
- package/src/standalone/channel-transport/remote-binding.mjs +10 -79
- package/src/standalone/channel-transport/remote-intent.mjs +52 -0
- package/src/standalone/channel-transport/remote-notify.mjs +15 -107
- package/src/standalone/channel-transport/remote-pointer.mjs +124 -0
- package/src/standalone/channel-transport/remote-state.mjs +47 -0
- package/src/standalone/daemon-agent-control.mjs +65 -0
- package/src/standalone/daemon-channels-loader.mjs +60 -0
- package/src/standalone/daemon-desktop-runtime.mjs +28 -0
- package/src/standalone/daemon-local-session-bridge.mjs +62 -0
- package/src/standalone/daemon-stored-session-views.mjs +55 -0
- package/src/standalone/daemon.mjs +175 -320
- package/src/standalone/desktop-service-registry.mjs +9 -7
- package/src/standalone/folder-dialog.mjs +11 -12
- package/src/standalone/hook-bus/command-handler.mjs +60 -49
- package/src/standalone/hook-bus/event-runner.mjs +7 -74
- package/src/standalone/hook-bus/handler-dispatch.mjs +75 -0
- package/src/standalone/provider-admin.mjs +14 -35
- package/src/standalone/session-client/attachment-calls.mjs +67 -0
- package/src/standalone/session-client/stream-link.mjs +85 -0
- package/src/standalone/session-client.mjs +31 -106
- package/src/standalone/session-frame-stream.mjs +4 -2
- package/src/standalone/session-protocol.mjs +0 -1
- package/src/standalone/session-runtime-agent-control-client.mjs +11 -27
- package/src/standalone/session-runtime-agent-control.mjs +85 -0
- package/src/standalone/session-runtime-host.mjs +30 -472
- package/src/standalone/session-runtime-inline-host/telemetry.mjs +38 -0
- package/src/standalone/session-runtime-inline-host.mjs +6 -37
- package/src/standalone/session-runtime-proxy.mjs +164 -0
- package/src/standalone/session-runtime-shard-router.mjs +4 -7
- package/src/standalone/session-runtime-spawn-leases.mjs +82 -0
- package/src/standalone/session-runtime-worker.mjs +27 -7
- package/src/standalone/session-service/agent-tree/agent-child.mjs +59 -0
- package/src/standalone/session-service/agent-tree/agent-turns.mjs +4 -55
- package/src/standalone/session-service/agent-tree.mjs +3 -1
- package/src/standalone/session-service/entries/disposal.mjs +72 -0
- package/src/standalone/session-service/entries/external-binding.mjs +6 -3
- package/src/standalone/session-service/entries/lifecycle.mjs +15 -59
- package/src/standalone/session-service/retention/busy.mjs +50 -0
- package/src/standalone/session-service/retention.mjs +5 -44
- package/src/standalone/session-service/session-calls/goal-recovery.mjs +44 -0
- package/src/standalone/session-service/session-calls/session-action.mjs +5 -8
- package/src/standalone/session-service/session-calls/session-turns.mjs +12 -42
- package/src/standalone/session-service/session-calls/session-views.mjs +8 -8
- package/src/standalone/session-transport/stack.mjs +131 -0
- package/src/standalone/session-transport.mjs +10 -103
- package/src/standalone/usage-dashboard.mjs +167 -165
- package/src/standalone/usage-stats-model.mjs +117 -97
- package/src/tui/App.jsx +27 -210
- package/src/tui/app/app-format.mjs +7 -0
- package/src/tui/app/app-view/floating-panel.jsx +229 -0
- package/src/tui/app/app-view/text-entry-labels.mjs +81 -0
- package/src/tui/app/app-view/transcript-viewport/trailing-bands.jsx +94 -0
- package/src/tui/app/app-view/transcript-viewport/transcript-rows.jsx +87 -0
- package/src/tui/app/app-view/transcript-viewport.jsx +74 -0
- package/src/tui/app/app-view.jsx +12 -450
- package/src/tui/app/core-memory-picker/core-rows.mjs +32 -0
- package/src/tui/app/core-memory-picker/entry-prompts.mjs +45 -0
- package/src/tui/app/core-memory-picker/list-panels.mjs +75 -0
- package/src/tui/app/core-memory-picker.mjs +26 -120
- package/src/tui/app/doctor.mjs +17 -12
- package/src/tui/app/extension-pickers/skills-pickers/project-skills.mjs +38 -0
- package/src/tui/app/extension-pickers/skills-pickers/skill-detail.mjs +80 -0
- package/src/tui/app/extension-pickers/skills-pickers/skill-items.mjs +44 -0
- package/src/tui/app/extension-pickers/skills-pickers.mjs +31 -137
- package/src/tui/app/model-picker/route-selection/context-window.mjs +47 -0
- package/src/tui/app/model-picker/route-selection/effort.mjs +87 -0
- package/src/tui/app/model-picker/route-selection/fast-parameters.mjs +84 -0
- package/src/tui/app/model-picker/route-selection/model-key.mjs +5 -0
- package/src/tui/app/model-picker/route-selection.mjs +34 -200
- package/src/tui/app/mouse-input/edge-autoscroll.mjs +53 -0
- package/src/tui/app/mouse-input/geometry.mjs +109 -0
- package/src/tui/app/mouse-input/sgr-buttons.mjs +14 -0
- package/src/tui/app/mouse-input/wheel-router.mjs +96 -0
- package/src/tui/app/panel-signature.mjs +58 -0
- package/src/tui/app/project-picker/project-service.mjs +3 -7
- package/src/tui/app/prompt-submit.mjs +2 -7
- package/src/tui/app/provider-setup/api-key-actions.mjs +7 -80
- package/src/tui/app/provider-setup/oauth-actions.mjs +2 -10
- package/src/tui/app/provider-setup/provider-items.mjs +20 -3
- package/src/tui/app/settings-picker/settings-toggles/cycled.mjs +4 -0
- package/src/tui/app/settings-picker/settings-toggles/listed-cyclers.mjs +77 -0
- package/src/tui/app/settings-picker/settings-toggles/store-toggles.mjs +61 -0
- package/src/tui/app/settings-picker/settings-toggles/theme-cycler.mjs +36 -0
- package/src/tui/app/settings-picker/settings-toggles.mjs +21 -149
- package/src/tui/app/slash-commands.mjs +14 -4
- package/src/tui/app/store-service-call.mjs +17 -0
- package/src/tui/app/text-entry-policy.mjs +1 -3
- package/src/tui/app/transcript-row-estimate.mjs +31 -91
- package/src/tui/app/transcript-window.mjs +19 -0
- package/src/tui/app/use-disabled-skills.mjs +52 -0
- package/src/tui/app/use-global-key-input/copy-first.mjs +43 -0
- package/src/tui/app/use-global-key-input/shift-arrow.mjs +30 -0
- package/src/tui/app/use-global-key-input.mjs +10 -67
- package/src/tui/app/use-model-catalog-cache.mjs +86 -0
- package/src/tui/app/use-mouse-input.mjs +64 -218
- package/src/tui/app/use-pasted-buffers.mjs +55 -81
- package/src/tui/app/use-prompt-draft-flow/draft-change.mjs +66 -0
- package/src/tui/app/use-prompt-draft-flow/prompt-cancels.mjs +40 -0
- package/src/tui/app/use-prompt-draft-flow.mjs +38 -77
- package/src/tui/app/use-prompt-queue-history/prompt-history.mjs +22 -0
- package/src/tui/app/use-prompt-queue-history/restore-to-prompt.mjs +147 -0
- package/src/tui/app/use-prompt-queue-history.mjs +20 -117
- package/src/tui/app/use-selection-focus.mjs +2 -1
- package/src/tui/app/use-selection-geometry.mjs +9 -12
- package/src/tui/app/use-selection-paint/paint-queue.mjs +90 -0
- package/src/tui/app/use-selection-paint/selection-clip.mjs +33 -0
- package/src/tui/app/use-selection-paint.mjs +31 -102
- package/src/tui/app/use-transcript-activity.mjs +1 -1
- package/src/tui/app/use-transcript-window/instance-state.mjs +1 -1
- package/src/tui/app/use-welcome-prompt-hint.mjs +1 -1
- package/src/tui/app/workflow-cycle.mjs +63 -0
- package/src/tui/components/AnsiText.jsx +47 -15
- package/src/tui/components/ItemRightHintOverprint.jsx +2 -15
- package/src/tui/components/Picker.jsx +9 -23
- package/src/tui/components/PromptInput.jsx +89 -335
- package/src/tui/components/QueuedCommands.jsx +1 -3
- package/src/tui/components/Spinner.jsx +1 -2
- package/src/tui/components/StatusLine.jsx +11 -21
- package/src/tui/components/TextEntryPanel.jsx +5 -52
- package/src/tui/components/ToolExecution.jsx +5 -14
- package/src/tui/components/TranscriptItem.jsx +0 -2
- package/src/tui/components/TurnDone.jsx +2 -14
- package/src/tui/components/prompt-input/cursor-anchor.mjs +65 -0
- package/src/tui/components/prompt-input/edit-helpers.mjs +1 -2
- package/src/tui/components/prompt-input/key-signals.mjs +122 -0
- package/src/tui/components/prompt-input/mouse-selection.mjs +114 -0
- package/src/tui/components/prompt-input/restore-policy.d.mts +0 -1
- package/src/tui/components/prompt-input/restore-policy.mjs +3 -8
- package/src/tui/components/prompt-input/selected-text.jsx +25 -0
- package/src/tui/components/prompt-input/undo-stack.mjs +75 -0
- package/src/tui/components/tool-output-format.mjs +1 -2
- package/src/tui/dist/index.mjs +2841 -2469
- package/src/tui/index.jsx +2 -2
- package/src/tui/markdown/measure-rendered-rows.mjs +8 -33
- package/src/tui/markdown/render-ansi.mjs +5 -5
- package/src/tui/markdown/table-layout/box-lines.mjs +46 -0
- package/src/tui/markdown/table-layout/cells.mjs +23 -0
- package/src/tui/markdown/table-layout/column-widths.mjs +65 -0
- package/src/tui/markdown/table-layout/vertical-lines.mjs +46 -0
- package/src/tui/markdown/table-layout.mjs +21 -151
- package/src/tui/prompt-history-store.mjs +0 -9
- package/src/tui/session/active-tool-summary.mjs +19 -27
- package/src/tui/session/agent-envelope.mjs +9 -9
- package/src/tui/session/live-share/owner.mjs +9 -7
- package/src/tui/session/live-share/retry.mjs +15 -0
- package/src/tui/session/live-share/viewer/frame-router.mjs +32 -0
- package/src/tui/session/live-share/viewer/pipe-client.mjs +108 -0
- package/src/tui/session/live-share/viewer.mjs +23 -114
- package/src/tui/session/notice-surface.mjs +1 -1
- package/src/tui/session/notice-text.mjs +21 -17
- package/src/tui/session/queue-helpers.mjs +12 -14
- package/src/tui/session/session-api/intake/submission.mjs +3 -8
- package/src/tui/session/session-api/integrations.mjs +0 -11
- package/src/tui/session/session-api/lifecycle/session-reset.mjs +76 -74
- package/src/tui/session/session-flow/drain.mjs +18 -5
- package/src/tui/session/session-flow/queue/entry-shape.mjs +53 -0
- package/src/tui/session/session-flow/queue/take-entries.mjs +82 -0
- package/src/tui/session/session-flow/queue.mjs +10 -112
- package/src/tui/session/session-flow/session-reset.mjs +2 -7
- package/src/tui/session/tool-approval.mjs +13 -17
- package/src/tui/session/tool-result-text.mjs +16 -28
- package/src/tui/session/transcript-spill.mjs +3 -7
- package/src/tui/session/transcript-store/replace-items.mjs +66 -0
- package/src/tui/session/transcript-store/streaming-tail.mjs +49 -0
- package/src/tui/session/transcript-store.mjs +16 -95
- package/src/tui/statusline-ansi-bridge.mjs +1 -40
- package/src/ui/markdown.mjs +3 -2
- package/src/ui/statusline-agents.mjs +9 -14
- package/src/ui/statusline.mjs +4 -4
- package/src/runtime/channels/lib/cli-worker-host.mjs +0 -2
- package/src/runtime/memory/lib/llm-worker-host.mjs +0 -11
- package/src/standalone/opencode-go-login.mjs +0 -140
|
@@ -1,73 +1,29 @@
|
|
|
1
1
|
import { getAgentApiKey } from '../../../shared/provider-api-key.mjs';
|
|
2
2
|
import { sanitizeToolPairs } from '../session/context-utils.mjs';
|
|
3
|
-
import {
|
|
4
|
-
ANTHROPIC_RETRY_BACKOFF_MS,
|
|
5
|
-
ANTHROPIC_RETRY_JITTER_RATIO,
|
|
6
|
-
AnthropicFallbackTriggeredError,
|
|
7
|
-
anthropicMaxAttempts,
|
|
8
|
-
anthropicRequestTimeoutMs,
|
|
9
|
-
classifyError,
|
|
10
|
-
markProviderRecoveryExhausted,
|
|
11
|
-
resolveStallRetryBudget,
|
|
12
|
-
midstreamBackoffFor,
|
|
13
|
-
STREAM_STALL_RETRY_BUDGET_MS,
|
|
14
|
-
withRetry,
|
|
15
|
-
retryAfterMsFromError,
|
|
16
|
-
retryDelayLabel,
|
|
17
|
-
} from './retry-classifier.mjs';
|
|
3
|
+
import { AnthropicFallbackTriggeredError } from './retry-classifier.mjs';
|
|
18
4
|
import { readStreamOutcome } from './lib/stream-outcome.mjs';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
PROVIDER_FIRST_BYTE_TIMEOUT_MS,
|
|
22
|
-
PROVIDER_NONSTREAM_TOTAL_TIMEOUT_MS,
|
|
23
|
-
createTimeoutSignal,
|
|
24
|
-
createPassthroughSignal,
|
|
25
|
-
} from '../stall-policy.mjs';
|
|
5
|
+
import { createPassthroughSignal } from '../stall-policy.mjs';
|
|
26
6
|
import { createAbortController } from '../../../shared/abort-controller.mjs';
|
|
27
|
-
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
} from './anthropic-
|
|
33
|
-
import {
|
|
34
|
-
import { applyAnthropicServerFallback } from './anthropic-server-fallback.mjs';
|
|
35
|
-
import { fastModeAvailable, noteFastModeCapacityError } from './anthropic-fast-mode.mjs';
|
|
36
|
-
import { applyAnthropicEffortToBody, shouldIncludeEffortBeta } from './anthropic-effort.mjs';
|
|
37
|
-
import { prepareAnthropicImages } from './lib/anthropic-image-input.mjs';
|
|
7
|
+
import { ANTHROPIC_MAX_MIDSTREAM_RETRIES, parseSSEStream } from './anthropic-sse.mjs';
|
|
8
|
+
import { buildAnthropicBetaHeaders } from './anthropic-betas.mjs';
|
|
9
|
+
import { buildAnthropicApiRequest } from './anthropic-api-request.mjs';
|
|
10
|
+
import { armFirstByteWatchdog, createAnthropicApiTransport } from './anthropic-api-transport.mjs';
|
|
11
|
+
import { createAnthropicApiRecovery } from './anthropic-api-recovery.mjs';
|
|
12
|
+
import { buildAnthropicTurnResult } from './anthropic-turn-result.mjs';
|
|
13
|
+
import { createAnthropicMidState, createAnthropicMidstreamRecovery } from './anthropic-midstream-recovery.mjs';
|
|
38
14
|
import { enrichModels } from './model-catalog.mjs';
|
|
39
15
|
import { sanitizeModelList } from './model-list-sanitize.mjs';
|
|
40
16
|
import { getLlmDispatcher } from '../../../shared/llm/http-agent.mjs';
|
|
41
|
-
import { notifyCurrentAnthropicRateLimit } from './admission-scheduler.mjs';
|
|
42
|
-
import {
|
|
43
|
-
applyAnthropicCacheMarkers,
|
|
44
|
-
clampAnthropicThinkingBudget as clampThinkingBudgetTokens,
|
|
45
|
-
normalizeAnthropicNonStreamingResponse,
|
|
46
|
-
resolveAnthropicCacheTtls as resolveCacheTtls,
|
|
47
|
-
resolveAnthropicMessageCacheSlots,
|
|
48
|
-
toAnthropicToolChoice,
|
|
49
|
-
} from './lib/anthropic-request-utils.mjs';
|
|
50
17
|
|
|
51
18
|
import {
|
|
52
19
|
loadAnthropic,
|
|
53
|
-
_midstreamSleepWithAbort,
|
|
54
|
-
buildSystemBlocks,
|
|
55
20
|
MODELS,
|
|
56
21
|
ANTHROPIC_VERSION,
|
|
57
22
|
_normalizeAnthropicModel,
|
|
58
23
|
_setApiKeyCatalogMirror,
|
|
59
|
-
resolveMaxTokens,
|
|
60
|
-
requestAnthropicTools,
|
|
61
|
-
toAnthropicMessages,
|
|
62
24
|
} from './anthropic-messages.mjs';
|
|
63
25
|
export { _test, _toAnthropicMessagesForTest } from './anthropic-messages.mjs';
|
|
64
26
|
|
|
65
|
-
import {
|
|
66
|
-
EFFORT_CONFIGURATION_BETA,
|
|
67
|
-
projectEffortConfiguration,
|
|
68
|
-
lowerAnthropicEffortHistory,
|
|
69
|
-
} from './effort-configuration.mjs';
|
|
70
|
-
|
|
71
27
|
export class AnthropicProvider {
|
|
72
28
|
// Anthropic reports usage.input_tokens EXCLUDING cache_read/cache_creation
|
|
73
29
|
// (those are separate fields), so the live context-window footprint must
|
|
@@ -146,87 +102,20 @@ export class AnthropicProvider {
|
|
|
146
102
|
async _doSend(messages, model, tools, sendOpts) {
|
|
147
103
|
if (!model) throw new Error(`[${this.name}] model is required — pass it from the caller preset`);
|
|
148
104
|
const useModel = model;
|
|
149
|
-
const maxTokens = resolveMaxTokens(useModel);
|
|
150
105
|
const opts = sendOpts || {};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
const systemBlocks = buildSystemBlocks(systemMsgs, ttls.system, ttls.tier3);
|
|
163
|
-
|
|
164
|
-
// Message-tail cache budget (4-BP layout + ANTHROPIC_MSG_SLOTS) is
|
|
165
|
-
// shared with anthropic-oauth — see resolveAnthropicMessageCacheSlots.
|
|
166
|
-
const messageCacheSlots = resolveAnthropicMessageCacheSlots(systemBlocks, ttls);
|
|
167
|
-
// Tools are resolved BEFORE the messages: the lowering needs the final
|
|
168
|
-
// tool list to drop tool_reference blocks whose tool no longer ships
|
|
169
|
-
// in this request (otherwise the API rejects the whole turn).
|
|
170
|
-
const requestTools = requestAnthropicTools(tools, chatMsgs, opts);
|
|
171
|
-
// Build → sanitize (once, inside toAnthropicMessages) → mark. Markers
|
|
172
|
-
// are applied to the FINAL sanitized array by invariant, so block
|
|
173
|
-
// drops / inserts / reorders performed by the sanitizer can never move
|
|
174
|
-
// or delete a marked block. NEVER sanitize again after this.
|
|
175
|
-
const anthropicMessages = applyAnthropicCacheMarkers(
|
|
176
|
-
lowerAnthropicEffortHistory(chatMsgs, (segment) => toAnthropicMessages(segment, requestTools), effortProjection),
|
|
177
|
-
messageCacheSlots
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
const params = {
|
|
181
|
-
model: useModel,
|
|
182
|
-
max_tokens: maxTokens,
|
|
183
|
-
system: systemBlocks.length ? systemBlocks : undefined,
|
|
184
|
-
messages: await prepareAnthropicImages(anthropicMessages, { signal: opts.signal }),
|
|
185
|
-
};
|
|
186
|
-
applyAnthropicServerFallback(params, useModel, {
|
|
187
|
-
enabled: this.config?.disableBetaHeaders !== true && opts.serverFallback !== false,
|
|
188
|
-
});
|
|
189
|
-
if (requestTools.length) {
|
|
190
|
-
// No cache_control on tools — the system BP covers tools via
|
|
191
|
-
// Anthropic prefix semantics (order: tools → system → messages).
|
|
192
|
-
params.tools = requestTools;
|
|
193
|
-
}
|
|
194
|
-
// tool_choice only when tools are actually present (Anthropic rejects
|
|
195
|
-
// tool_choice without tools). 'none' rides the hard-cap final turn to
|
|
196
|
-
// forbid tool USE while keeping the tools prefix stable for cache reuse.
|
|
197
|
-
if (params.tools) {
|
|
198
|
-
const toolChoice = toAnthropicToolChoice(opts.toolChoice);
|
|
199
|
-
if (toolChoice) params.tool_choice = toolChoice;
|
|
200
|
-
}
|
|
201
|
-
const hasDeferredTools = Array.isArray(params.tools) && params.tools.some((tool) => tool?.defer_loading === true);
|
|
202
|
-
// Known tool names for the shared parseSSEStream leaked-tool-call guard
|
|
203
|
-
// (same guard fixes both Anthropic providers). Recovered leaked calls
|
|
204
|
-
// are only synthesized when they name a tool actually offered here.
|
|
205
|
-
const knownToolNames = new Set(
|
|
206
|
-
(Array.isArray(params.tools) ? params.tools : [])
|
|
207
|
-
.map((t) => (t && typeof t.name === 'string' ? t.name : null))
|
|
208
|
-
.filter(Boolean)
|
|
209
|
-
);
|
|
210
|
-
applyAnthropicEffortToBody(params, {
|
|
211
|
-
model: useModel,
|
|
212
|
-
opts: effortProjection ? { ...opts, effort: effortProjection.initialEffort } : opts,
|
|
213
|
-
maxTokens,
|
|
214
|
-
clampThinkingBudgetTokens,
|
|
215
|
-
logTag: this.name,
|
|
106
|
+
// Wire request (system/cache layout, tools, effort, fast mode, images)
|
|
107
|
+
// and the per-request beta headers derived from that final body —
|
|
108
|
+
// anthropic-api-request.mjs. Fast mode latches on the provider instance.
|
|
109
|
+
const { params, requestHeaders, knownToolNames, fastModeLatched } = await buildAnthropicApiRequest({
|
|
110
|
+
name: this.name,
|
|
111
|
+
config: this.config,
|
|
112
|
+
messages,
|
|
113
|
+
useModel,
|
|
114
|
+
tools,
|
|
115
|
+
opts,
|
|
116
|
+
fastModeLatched: this.fastModeBetaHeaderLatched,
|
|
216
117
|
});
|
|
217
|
-
|
|
218
|
-
// Suppressed while the fast capacity pool is cooling down.
|
|
219
|
-
if (opts.fast === true && supportsAnthropicFastMode(useModel) && fastModeAvailable()) {
|
|
220
|
-
params.speed = 'fast';
|
|
221
|
-
this.fastModeBetaHeaderLatched = true;
|
|
222
|
-
}
|
|
223
|
-
// NOTE: do NOT sanitize here. params.messages was already sanitized
|
|
224
|
-
// once inside toAnthropicMessages and then had cache markers applied.
|
|
225
|
-
// Re-sanitizing after marking could drop/reorder a marked block and
|
|
226
|
-
// move the provider-visible cache breakpoint off the cached one — the
|
|
227
|
-
// exact COLD-turn bug this change fixes. Order: build → sanitize
|
|
228
|
-
// (once) → mark → prepare image bytes → send.
|
|
229
|
-
params.stream = true;
|
|
118
|
+
this.fastModeBetaHeaderLatched = fastModeLatched;
|
|
230
119
|
|
|
231
120
|
const onStageChange = typeof opts.onStageChange === 'function' ? opts.onStageChange : null;
|
|
232
121
|
const onStreamDelta = typeof opts.onStreamDelta === 'function' ? opts.onStreamDelta : null;
|
|
@@ -251,204 +140,54 @@ export class AnthropicProvider {
|
|
|
251
140
|
} catch {}
|
|
252
141
|
};
|
|
253
142
|
|
|
254
|
-
//
|
|
255
|
-
//
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
const cacheRead = parseResult.usage?.cachedTokens || 0;
|
|
300
|
-
const cacheWrite = parseResult.usage?.cacheWriteTokens || 0;
|
|
301
|
-
const output = parseResult.usage?.outputTokens || 0;
|
|
302
|
-
const promptTokens = parseResult.usage?.promptTokens ?? input + cacheRead + cacheWrite;
|
|
303
|
-
const liveModel = parseResult.model || useModel;
|
|
304
|
-
|
|
305
|
-
if (usageRaw || input || output || cacheRead || cacheWrite) {
|
|
306
|
-
traceAgentUsage({
|
|
307
|
-
sessionId: opts.sessionId || opts.session?.id || null,
|
|
308
|
-
iteration: Number.isFinite(Number(opts.iteration)) ? Number(opts.iteration) : null,
|
|
309
|
-
inputTokens: input,
|
|
310
|
-
outputTokens: output,
|
|
311
|
-
cachedTokens: cacheRead,
|
|
312
|
-
cacheWriteTokens: cacheWrite,
|
|
313
|
-
promptTokens,
|
|
314
|
-
model: liveModel,
|
|
315
|
-
modelDisplay: liveModel,
|
|
316
|
-
responseId: null,
|
|
317
|
-
rawUsage: usageRaw,
|
|
318
|
-
provider: this.name,
|
|
319
|
-
requestKind: opts.requestKind || null,
|
|
320
|
-
// Anthropic usage is additive at this inner transport
|
|
321
|
-
// boundary, even when OpenCode Go supplies the provider id.
|
|
322
|
-
inputTokensInclusive: false,
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return {
|
|
327
|
-
content: parseResult.content || '',
|
|
328
|
-
model: liveModel,
|
|
329
|
-
toolCalls: parseResult.toolCalls,
|
|
330
|
-
stopReason: parseResult.stopReason || null,
|
|
331
|
-
hasThinkingContent: !!parseResult.hasThinkingContent,
|
|
332
|
-
contentBlockTypes: Array.isArray(parseResult.contentBlockTypes) ? parseResult.contentBlockTypes : [],
|
|
333
|
-
// Round-trip adaptive-thinking blocks (verbatim thinking +
|
|
334
|
-
// signature) so the loop can store them and replay them before
|
|
335
|
-
// tool_use on the next turn. Matches anthropic-oauth's return.
|
|
336
|
-
thinkingBlocks:
|
|
337
|
-
Array.isArray(parseResult.thinkingBlocks) && parseResult.thinkingBlocks.length
|
|
338
|
-
? parseResult.thinkingBlocks
|
|
339
|
-
: undefined,
|
|
340
|
-
// Ordered NATIVE server-tool blocks (server_tool_use +
|
|
341
|
-
// *_tool_result) exist ONLY in this verbatim list — they are
|
|
342
|
-
// never dispatched as client tool calls and cannot be rebuilt
|
|
343
|
-
// from content/toolCalls/thinkingBlocks. Dropping them here
|
|
344
|
-
// broke `pause_turn` continuations on the API-key path (the
|
|
345
|
-
// OAuth provider returns the parse result as-is). Absent for
|
|
346
|
-
// ordinary turns, so nothing else changes.
|
|
347
|
-
assistantBlocks:
|
|
348
|
-
Array.isArray(parseResult.assistantBlocks) && parseResult.assistantBlocks.length
|
|
349
|
-
? parseResult.assistantBlocks
|
|
350
|
-
: undefined,
|
|
351
|
-
...(parseResult.providerReplay ? { providerReplay: parseResult.providerReplay } : {}),
|
|
352
|
-
...(parseResult.providerMetadata && typeof parseResult.providerMetadata === 'object'
|
|
353
|
-
? { providerMetadata: parseResult.providerMetadata }
|
|
354
|
-
: {}),
|
|
355
|
-
usage: {
|
|
356
|
-
inputTokens: input,
|
|
357
|
-
outputTokens: output,
|
|
358
|
-
cachedTokens: cacheRead,
|
|
359
|
-
cacheWriteTokens: cacheWrite,
|
|
360
|
-
promptTokens,
|
|
361
|
-
},
|
|
362
|
-
};
|
|
363
|
-
};
|
|
364
|
-
|
|
365
|
-
// Core non-streaming re-issue shared by the exposed-text recovery
|
|
366
|
-
// (onTextReset-gated) and the no-exposure stall fallback (trivially
|
|
367
|
-
// safe — nothing was relayed or dispatched). Mirrors anthropic-oauth.
|
|
368
|
-
const issueNonStreamingFallback = async (streamController, abortReason) => {
|
|
369
|
-
try {
|
|
370
|
-
streamController.abort?.(abortReason);
|
|
371
|
-
} catch {}
|
|
372
|
-
try {
|
|
373
|
-
onStageChange?.('requesting', { transport: 'non-streaming-fallback' });
|
|
374
|
-
} catch {}
|
|
375
|
-
const nonStreamingParams = { ...params, stream: false };
|
|
376
|
-
const timeoutMs =
|
|
377
|
-
Number(opts._nonStreamingTimeoutMs) > 0
|
|
378
|
-
? Number(opts._nonStreamingTimeoutMs)
|
|
379
|
-
: PROVIDER_NONSTREAM_TOTAL_TIMEOUT_MS;
|
|
380
|
-
const lifetime = createTimeoutSignal(totalSignal, timeoutMs, `${this.name} Anthropic non-streaming fallback`);
|
|
381
|
-
try {
|
|
382
|
-
const message = await withRetry(
|
|
383
|
-
async ({ signal: attemptSignal }) =>
|
|
384
|
-
this.client.messages.create(nonStreamingParams, {
|
|
385
|
-
signal: attemptSignal,
|
|
386
|
-
...(requestHeaders ? { headers: requestHeaders } : {}),
|
|
387
|
-
}),
|
|
388
|
-
{
|
|
389
|
-
signal: lifetime.signal,
|
|
390
|
-
maxAttempts: anthropicMaxAttempts(),
|
|
391
|
-
backoffMs: ANTHROPIC_RETRY_BACKOFF_MS,
|
|
392
|
-
retryJitterRatio: ANTHROPIC_RETRY_JITTER_RATIO,
|
|
393
|
-
retryJitterMode: 'positive',
|
|
394
|
-
perAttemptTimeoutMs: anthropicRequestTimeoutMs(),
|
|
395
|
-
perAttemptLabel: `${this.name} Anthropic non-streaming fallback`,
|
|
396
|
-
provider: 'anthropic',
|
|
397
|
-
recoveryOwner: `${this.name}-nonstreaming-request`,
|
|
398
|
-
model: useModel,
|
|
399
|
-
fallbackModel: opts._fallbackTriggered ? undefined : opts.fallbackModel,
|
|
400
|
-
}
|
|
401
|
-
);
|
|
402
|
-
return buildReturnFromParse(normalizeAnthropicNonStreamingResponse(message, useModel));
|
|
403
|
-
} catch (error) {
|
|
404
|
-
if (error instanceof AnthropicFallbackTriggeredError || totalSignal?.aborted) throw error;
|
|
405
|
-
throw markProviderRecoveryExhausted(error, {
|
|
406
|
-
owner: `${this.name}-nonstreaming-fallback`,
|
|
407
|
-
});
|
|
408
|
-
} finally {
|
|
409
|
-
lifetime.cleanup();
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
// Exposed text and exposed thinking are both retractable via the
|
|
414
|
-
// owner's ack; only a dispatched/partial tool call denies the replay.
|
|
415
|
-
const recoverNonStreaming = async (midState, streamingError, streamController) => {
|
|
416
|
-
const exposedChars = Number(midState?.emittedTextChars) || 0;
|
|
417
|
-
const exposedReasoning = midState?.emittedThinking === true;
|
|
418
|
-
if (
|
|
419
|
-
!onTextReset ||
|
|
420
|
-
(exposedChars <= 0 && !exposedReasoning) ||
|
|
421
|
-
midState.emittedToolCall ||
|
|
422
|
-
midState.partialToolCall
|
|
423
|
-
) {
|
|
424
|
-
try {
|
|
425
|
-
streamingError.liveTextEmitted = true;
|
|
426
|
-
streamingError.unsafeToRetry = true;
|
|
427
|
-
} catch {}
|
|
428
|
-
throw streamingError;
|
|
429
|
-
}
|
|
430
|
-
let resetAccepted = false;
|
|
431
|
-
try {
|
|
432
|
-
resetAccepted =
|
|
433
|
-
(await onTextReset({
|
|
434
|
-
chars: exposedChars,
|
|
435
|
-
reasoning: exposedReasoning,
|
|
436
|
-
reason: 'anthropic-streaming-fallback',
|
|
437
|
-
})) === true;
|
|
438
|
-
} catch {}
|
|
439
|
-
if (!resetAccepted) {
|
|
440
|
-
try {
|
|
441
|
-
streamingError.liveTextEmitted = true;
|
|
442
|
-
streamingError.unsafeToRetry = true;
|
|
443
|
-
} catch {}
|
|
444
|
-
throw streamingError;
|
|
445
|
-
}
|
|
446
|
-
requireTransportRecoveryBudget(streamingError, streamController);
|
|
447
|
-
return issueNonStreamingFallback(streamController, streamingError);
|
|
448
|
-
};
|
|
143
|
+
// The SDK calls and their initial-response retry policy
|
|
144
|
+
// (anthropic-api-transport.mjs).
|
|
145
|
+
const transport = createAnthropicApiTransport({
|
|
146
|
+
client: this.client,
|
|
147
|
+
label: this.name,
|
|
148
|
+
opts,
|
|
149
|
+
useModel,
|
|
150
|
+
params,
|
|
151
|
+
requestHeaders,
|
|
152
|
+
totalSignal,
|
|
153
|
+
});
|
|
154
|
+
// Usage accounting + caller-visible projection, shared by the streaming
|
|
155
|
+
// success path and the non-streaming fallback (anthropic-turn-result.mjs).
|
|
156
|
+
const buildTurnResult = (parseResult) =>
|
|
157
|
+
buildAnthropicTurnResult(parseResult, { provider: this.name, useModel, opts });
|
|
158
|
+
// Non-streaming re-issue of a dead stream, behind the transport-recovery
|
|
159
|
+
// budget and the exposed-output retraction handshake
|
|
160
|
+
// (anthropic-api-recovery.mjs).
|
|
161
|
+
const recovery = createAnthropicApiRecovery({
|
|
162
|
+
label: this.name,
|
|
163
|
+
opts,
|
|
164
|
+
useModel,
|
|
165
|
+
params,
|
|
166
|
+
totalSignal,
|
|
167
|
+
transport,
|
|
168
|
+
buildTurnResult,
|
|
169
|
+
onStageChange,
|
|
170
|
+
onTextReset,
|
|
171
|
+
});
|
|
172
|
+
// Bounded mid-stream retries for transient stream loss; jittered backoff
|
|
173
|
+
// between attempts (anthropic-midstream-recovery.mjs, shared with
|
|
174
|
+
// anthropic-oauth).
|
|
175
|
+
const midstream = createAnthropicMidstreamRecovery({
|
|
176
|
+
label: this.name,
|
|
177
|
+
outcomeProvider: 'anthropic',
|
|
178
|
+
midstreamOwner: `${this.name}-midstream`,
|
|
179
|
+
unreachableMessage: 'Anthropic mid-stream retry: unreachable',
|
|
180
|
+
// The transport's withRetry already exhausted the full request-level
|
|
181
|
+
// budget for a non-OK initial response, so it must not earn an
|
|
182
|
+
// additional SSE retry budget here.
|
|
183
|
+
initialResponseErrorTerminal: true,
|
|
184
|
+
maxRetries: ANTHROPIC_MAX_MIDSTREAM_RETRIES,
|
|
185
|
+
totalSignal,
|
|
186
|
+
recovery,
|
|
187
|
+
});
|
|
449
188
|
|
|
450
189
|
try {
|
|
451
|
-
for (let attemptIndex = 0; attemptIndex <=
|
|
190
|
+
for (let attemptIndex = 0; attemptIndex <= ANTHROPIC_MAX_MIDSTREAM_RETRIES; attemptIndex++) {
|
|
452
191
|
const streamController = createAbortController();
|
|
453
192
|
let cancelHandler = null;
|
|
454
193
|
|
|
@@ -465,24 +204,9 @@ export class AnthropicProvider {
|
|
|
465
204
|
totalSignal.addEventListener('abort', cancelHandler, { once: true });
|
|
466
205
|
}
|
|
467
206
|
|
|
468
|
-
const midState =
|
|
469
|
-
attemptIndex,
|
|
470
|
-
sawMessageStart: false,
|
|
471
|
-
sawCompleted: false,
|
|
472
|
-
emittedToolCall: false,
|
|
473
|
-
partialToolCall: false,
|
|
474
|
-
emittedThinking: false,
|
|
475
|
-
// Gateway live-text relay invariant: set by parseSSEStream
|
|
476
|
-
// once a non-empty text chunk has been forwarded. A later
|
|
477
|
-
// failure is non-retryable (rendered text cannot be
|
|
478
|
-
// withdrawn; a retry would concatenate attempts).
|
|
479
|
-
emittedText: false,
|
|
480
|
-
userAbort: false,
|
|
481
|
-
watchdogAbort: null,
|
|
482
|
-
};
|
|
207
|
+
const midState = createAnthropicMidState(attemptIndex);
|
|
483
208
|
|
|
484
|
-
let
|
|
485
|
-
let firstByteTimeout = null;
|
|
209
|
+
let firstByte = null;
|
|
486
210
|
let response = null;
|
|
487
211
|
|
|
488
212
|
try {
|
|
@@ -490,101 +214,13 @@ export class AnthropicProvider {
|
|
|
490
214
|
onStageChange?.('requesting');
|
|
491
215
|
} catch {}
|
|
492
216
|
|
|
493
|
-
response = await
|
|
494
|
-
async ({ signal: attemptSignal }) => {
|
|
495
|
-
const res = await this.client.messages
|
|
496
|
-
.create(params, {
|
|
497
|
-
signal: attemptSignal,
|
|
498
|
-
...(requestHeaders ? { headers: requestHeaders } : {}),
|
|
499
|
-
})
|
|
500
|
-
.asResponse();
|
|
501
|
-
if (!res.ok) {
|
|
502
|
-
const text = await res.text().catch(() => '');
|
|
503
|
-
const err = new Error(`Anthropic API ${res.status}: ${text.slice(0, 200)}`);
|
|
504
|
-
err.status = res.status;
|
|
505
|
-
err.httpStatus = res.status;
|
|
506
|
-
err.initialResponseError = true;
|
|
507
|
-
// Carry response headers so withRetry can honor a
|
|
508
|
-
// short Retry-After and upstream can read quota hints.
|
|
509
|
-
err.headers = res.headers;
|
|
510
|
-
err.response = { status: res.status, headers: res.headers };
|
|
511
|
-
// This is an initial-response 429, before SSE
|
|
512
|
-
// output/tool exposure, so the request-local
|
|
513
|
-
// withRetry loop may retry it with jitter.
|
|
514
|
-
if (res.status === 429) {
|
|
515
|
-
const retryAfterMs = retryAfterMsFromError({
|
|
516
|
-
headers: res.headers,
|
|
517
|
-
response: { headers: res.headers },
|
|
518
|
-
});
|
|
519
|
-
err.name = 'ProviderQuotaError';
|
|
520
|
-
err.code = 'PROVIDER_QUOTA';
|
|
521
|
-
err.retryAfterMs = retryAfterMs;
|
|
522
|
-
err.providerQuota = true;
|
|
523
|
-
err.quotaExceeded = true;
|
|
524
|
-
}
|
|
525
|
-
throw err;
|
|
526
|
-
}
|
|
527
|
-
if (!res.body) {
|
|
528
|
-
throw new Error('Anthropic streaming response has no body');
|
|
529
|
-
}
|
|
530
|
-
return res;
|
|
531
|
-
},
|
|
532
|
-
{
|
|
533
|
-
signal: totalSignal,
|
|
534
|
-
maxAttempts: anthropicMaxAttempts(),
|
|
535
|
-
backoffMs: ANTHROPIC_RETRY_BACKOFF_MS,
|
|
536
|
-
retryJitterRatio: ANTHROPIC_RETRY_JITTER_RATIO,
|
|
537
|
-
retryJitterMode: 'positive',
|
|
538
|
-
perAttemptTimeoutMs: anthropicRequestTimeoutMs(),
|
|
539
|
-
perAttemptLabel: `${this.name} Anthropic streaming response`,
|
|
540
|
-
provider: 'anthropic',
|
|
541
|
-
recoveryOwner: `${this.name}-initial-response`,
|
|
542
|
-
model: useModel,
|
|
543
|
-
fallbackModel: opts._fallbackTriggered ? undefined : opts.fallbackModel,
|
|
544
|
-
onRetry: ({ attempt, lastErr, delayMs, delayReason }) => {
|
|
545
|
-
// Long/unknown fast-pool window: replay at
|
|
546
|
-
// standard speed rather than waiting it out.
|
|
547
|
-
if (params?.speed === 'fast' && noteFastModeCapacityError(lastErr, { fast: true }) !== 'retry-fast') {
|
|
548
|
-
delete params.speed;
|
|
549
|
-
}
|
|
550
|
-
const status = Number(lastErr?.httpStatus || lastErr?.status || lastErr?.response?.status || 0);
|
|
551
|
-
if (status === 429) notifyCurrentAnthropicRateLimit(lastErr);
|
|
552
|
-
const delayLabel = retryDelayLabel(delayMs, delayReason);
|
|
553
|
-
process.stderr.write(
|
|
554
|
-
`[${this.name}] retry attempt ${attempt + 1} after ${lastErr?.message || lastErr?.code || 'transient error'}${delayLabel}\n`
|
|
555
|
-
);
|
|
556
|
-
},
|
|
557
|
-
}
|
|
558
|
-
);
|
|
217
|
+
response = await transport.requestStreamingResponse();
|
|
559
218
|
|
|
560
219
|
try {
|
|
561
220
|
onStageChange?.('streaming');
|
|
562
221
|
} catch {}
|
|
563
222
|
|
|
564
|
-
|
|
565
|
-
streamController.signal,
|
|
566
|
-
PROVIDER_FIRST_BYTE_TIMEOUT_MS,
|
|
567
|
-
'Anthropic SSE first byte'
|
|
568
|
-
);
|
|
569
|
-
firstByteTimeout.signal.addEventListener(
|
|
570
|
-
'abort',
|
|
571
|
-
() => {
|
|
572
|
-
if (!midState.sawMessageStart) {
|
|
573
|
-
try {
|
|
574
|
-
streamController.abort(firstByteTimeout.signal.reason);
|
|
575
|
-
} catch {}
|
|
576
|
-
}
|
|
577
|
-
},
|
|
578
|
-
{ once: true }
|
|
579
|
-
);
|
|
580
|
-
|
|
581
|
-
firstBytePoll = setInterval(() => {
|
|
582
|
-
if (midState.sawMessageStart) {
|
|
583
|
-
firstByteTimeout?.cleanup();
|
|
584
|
-
clearInterval(firstBytePoll);
|
|
585
|
-
firstBytePoll = null;
|
|
586
|
-
}
|
|
587
|
-
}, 25);
|
|
223
|
+
firstByte = armFirstByteWatchdog(streamController, midState);
|
|
588
224
|
|
|
589
225
|
const parseResult = await parseSSEStream(
|
|
590
226
|
response,
|
|
@@ -600,11 +236,7 @@ export class AnthropicProvider {
|
|
|
600
236
|
streamController.abort?.('Anthropic SSE complete');
|
|
601
237
|
} catch {}
|
|
602
238
|
|
|
603
|
-
|
|
604
|
-
clearInterval(firstBytePoll);
|
|
605
|
-
firstBytePoll = null;
|
|
606
|
-
}
|
|
607
|
-
firstByteTimeout?.cleanup();
|
|
239
|
+
firstByte.cleanup();
|
|
608
240
|
|
|
609
241
|
if (
|
|
610
242
|
!midState.sawMessageStart &&
|
|
@@ -622,7 +254,7 @@ export class AnthropicProvider {
|
|
|
622
254
|
throw emptyErr;
|
|
623
255
|
}
|
|
624
256
|
|
|
625
|
-
return
|
|
257
|
+
return buildTurnResult(parseResult);
|
|
626
258
|
} catch (err) {
|
|
627
259
|
if (err instanceof AnthropicFallbackTriggeredError) {
|
|
628
260
|
process.stderr.write(`[${this.name}] ${err.message}\n`);
|
|
@@ -632,160 +264,24 @@ export class AnthropicProvider {
|
|
|
632
264
|
_fallbackTriggered: true,
|
|
633
265
|
});
|
|
634
266
|
}
|
|
635
|
-
//
|
|
636
|
-
//
|
|
637
|
-
//
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
// Without that acknowledgement, recoverNonStreaming stamps
|
|
648
|
-
// the error unsafe and preserves the no-concatenation rule.
|
|
649
|
-
if (midState.emittedText || midState.emittedThinking) {
|
|
650
|
-
return await recoverNonStreaming(midState, err, streamController);
|
|
651
|
-
}
|
|
652
|
-
// Real exposure (dispatched tool, exposed thinking, or a
|
|
653
|
-
// parser-recorded started/complete call) is a replay
|
|
654
|
-
// boundary. The canonical merge above already recorded it
|
|
655
|
-
// AND wrote the compatibility aliases; writing coarse
|
|
656
|
-
// midState flags here would DOWNGRADE the parser's
|
|
657
|
-
// authoritative verdict that an incomplete, never
|
|
658
|
-
// dispatched tool input is still replay-safe.
|
|
659
|
-
if (_outcome?.replayUnsafe === true) {
|
|
660
|
-
try {
|
|
661
|
-
streamController.abort?.(err);
|
|
662
|
-
} catch {}
|
|
663
|
-
throw err;
|
|
664
|
-
}
|
|
665
|
-
// withRetry already exhausted the full request-level budget.
|
|
666
|
-
// Do not accidentally grant an additional SSE retry budget
|
|
667
|
-
// to an initial HTTP 429 that never produced a stream.
|
|
668
|
-
if (err?.initialResponseError) throw err;
|
|
669
|
-
if (err?.isEmptyStream && attemptIndex < MAX_MIDSTREAM_RETRIES) {
|
|
670
|
-
firstAttemptError = err;
|
|
671
|
-
firstAttemptClassifier = 'empty_stream';
|
|
672
|
-
try {
|
|
673
|
-
streamController.abort?.(err);
|
|
674
|
-
} catch {}
|
|
675
|
-
try {
|
|
676
|
-
process.stderr.write(
|
|
677
|
-
`[${this.name}] empty stream (no message_start) — retry ${attemptIndex + 1}/${MAX_MIDSTREAM_RETRIES}\n`
|
|
678
|
-
);
|
|
679
|
-
} catch {}
|
|
680
|
-
await _midstreamSleepWithAbort(midstreamBackoffFor(attemptIndex + 1), totalSignal);
|
|
681
|
-
continue;
|
|
682
|
-
}
|
|
683
|
-
if (
|
|
684
|
-
classifyError(err) === 'transient' &&
|
|
685
|
-
!midState.sawMessageStart &&
|
|
686
|
-
_outcome?.replayUnsafe !== true &&
|
|
687
|
-
attemptIndex < MAX_MIDSTREAM_RETRIES
|
|
688
|
-
) {
|
|
689
|
-
firstAttemptError = err;
|
|
690
|
-
firstAttemptClassifier = err?.providerErrorType || 'sse_transient';
|
|
691
|
-
try {
|
|
692
|
-
streamController.abort?.(err);
|
|
693
|
-
} catch {}
|
|
694
|
-
try {
|
|
695
|
-
process.stderr.write(
|
|
696
|
-
`[${this.name}] transient SSE error — retry ${attemptIndex + 1}/${MAX_MIDSTREAM_RETRIES} (${err?.providerErrorType || err?.message || 'unknown'})\n`
|
|
697
|
-
);
|
|
698
|
-
} catch {}
|
|
699
|
-
await _midstreamSleepWithAbort(midstreamBackoffFor(attemptIndex + 1), totalSignal);
|
|
700
|
-
continue;
|
|
701
|
-
}
|
|
702
|
-
if (
|
|
703
|
-
(err?.truncatedStream === true || err?.code === 'TRUNCATED_STREAM') &&
|
|
704
|
-
classifyError(err) === 'transient' &&
|
|
705
|
-
_outcome?.replayUnsafe !== true &&
|
|
706
|
-
attemptIndex < MAX_MIDSTREAM_RETRIES
|
|
707
|
-
) {
|
|
708
|
-
firstAttemptError = err;
|
|
709
|
-
firstAttemptClassifier = 'truncated_stream';
|
|
710
|
-
try {
|
|
711
|
-
streamController.abort?.(err);
|
|
712
|
-
} catch {}
|
|
713
|
-
try {
|
|
714
|
-
process.stderr.write(
|
|
715
|
-
`[${this.name}] truncated stream — retry ${attemptIndex + 1}/${MAX_MIDSTREAM_RETRIES}\n`
|
|
716
|
-
);
|
|
717
|
-
} catch {}
|
|
718
|
-
await _midstreamSleepWithAbort(midstreamBackoffFor(attemptIndex + 1), totalSignal);
|
|
719
|
-
continue;
|
|
720
|
-
}
|
|
721
|
-
const classifier = _classifyMidstreamError(err, midState);
|
|
722
|
-
// Stall recovery (shared with anthropic-oauth,
|
|
723
|
-
// 2026-08-03): a stalled stream that exposed NOTHING is
|
|
724
|
-
// re-issued non-streaming instead of retrying the same
|
|
725
|
-
// streaming shape into the same idle window. Replay is
|
|
726
|
-
// trivially safe — nothing was relayed or dispatched.
|
|
727
|
-
if (
|
|
728
|
-
classifier === 'stream_stalled' &&
|
|
729
|
-
_outcome?.replayUnsafe !== true &&
|
|
730
|
-
!midState.emittedText &&
|
|
731
|
-
!midState.emittedToolCall &&
|
|
732
|
-
!midState.partialToolCall &&
|
|
733
|
-
!midState.emittedThinking
|
|
734
|
-
) {
|
|
735
|
-
requireTransportRecoveryBudget(err, streamController);
|
|
736
|
-
try {
|
|
737
|
-
process.stderr.write(`[${this.name}] stream stalled with no exposure — retrying non-streaming\n`);
|
|
738
|
-
} catch {}
|
|
739
|
-
return await issueNonStreamingFallback(streamController, err);
|
|
740
|
-
}
|
|
741
|
-
if (classifier === 'stream_stalled') {
|
|
742
|
-
requireTransportRecoveryBudget(err, streamController);
|
|
743
|
-
}
|
|
744
|
-
if (classifier && attemptIndex < MAX_MIDSTREAM_RETRIES) {
|
|
745
|
-
firstAttemptError = err;
|
|
746
|
-
firstAttemptClassifier = classifier;
|
|
747
|
-
const status = Number(err?.httpStatus || err?.status || 0);
|
|
748
|
-
let retryDelayMs = null;
|
|
749
|
-
if (status === 429) {
|
|
750
|
-
if (!err.headers && response?.headers) err.headers = response.headers;
|
|
751
|
-
if (!err.response && response) err.response = { status, headers: response.headers };
|
|
752
|
-
retryDelayMs = retryAfterMsFromError(err);
|
|
753
|
-
if (retryDelayMs != null) err.retryAfterMs = retryDelayMs;
|
|
754
|
-
notifyCurrentAnthropicRateLimit(err);
|
|
755
|
-
}
|
|
756
|
-
try {
|
|
757
|
-
streamController.abort?.(err);
|
|
758
|
-
} catch {}
|
|
759
|
-
try {
|
|
760
|
-
process.stderr.write(
|
|
761
|
-
`[${this.name}] mid-stream recovered: retry ${attemptIndex + 1}/${MAX_MIDSTREAM_RETRIES} (cause: ${classifier})\n`
|
|
762
|
-
);
|
|
763
|
-
} catch {}
|
|
764
|
-
await _midstreamSleepWithAbort(retryDelayMs ?? midstreamBackoffFor(attemptIndex + 1), totalSignal);
|
|
765
|
-
continue;
|
|
766
|
-
}
|
|
767
|
-
if (classifier && attemptIndex >= MAX_MIDSTREAM_RETRIES) {
|
|
768
|
-
markProviderRecoveryExhausted(err, {
|
|
769
|
-
owner: `${this.name}-midstream`,
|
|
770
|
-
attempts: attemptIndex + 1,
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
if (attemptIndex > 0 && firstAttemptError) {
|
|
774
|
-
try {
|
|
775
|
-
err.midstreamRetries = attemptIndex;
|
|
776
|
-
} catch {}
|
|
777
|
-
try {
|
|
778
|
-
err.midstreamClassifier = firstAttemptClassifier;
|
|
779
|
-
} catch {}
|
|
780
|
-
}
|
|
781
|
-
throw err;
|
|
267
|
+
// Ordered recovery ladder: canonical outcome stamp, acknowledged
|
|
268
|
+
// non-streaming replay for exposed output, bounded streaming
|
|
269
|
+
// retries, silent-stall fallback, classifier-driven retries.
|
|
270
|
+
const decision = await midstream.onStreamError({
|
|
271
|
+
err,
|
|
272
|
+
midState,
|
|
273
|
+
controller: streamController,
|
|
274
|
+
response,
|
|
275
|
+
attemptIndex,
|
|
276
|
+
});
|
|
277
|
+
if (decision.retry) continue;
|
|
278
|
+
return decision.value;
|
|
782
279
|
} finally {
|
|
783
|
-
|
|
784
|
-
firstByteTimeout?.cleanup();
|
|
280
|
+
firstByte?.cleanup();
|
|
785
281
|
cleanupCancelHandler(cancelHandler);
|
|
786
282
|
}
|
|
787
283
|
}
|
|
788
|
-
throw
|
|
284
|
+
throw midstream.exhaustedError();
|
|
789
285
|
} finally {
|
|
790
286
|
totalTimeout.cleanup();
|
|
791
287
|
}
|