@bitkyc08/opencodex 2.96.0 → 2.98.0-preview.20261107
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/bin/ocx.mjs +215 -20
- package/gui/dist/assets/App-6TFtZsUF.css +1 -0
- package/gui/dist/assets/App-B8_sOxoz.js +59 -0
- package/gui/dist/assets/Tray-DpWEp6ee.js +1 -0
- package/gui/dist/assets/WantedSansVariable.split.0-Dwvb1WRx.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.1-1wKD2RxI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.10-CAKA6LIP.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.11-k5H85R4b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.12-BHboLsUv.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.13-9GV377ix.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.14-DovDXnrj.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.15-DTdykCig.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.16-CKz2ccgK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.17-Z2RD_KRZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.18-BcKtfonJ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.19-DEQPOSZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.2-DryboyuA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.20-Bia5JMls.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.21-Cr4jFw-E.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.22-DjjB69TZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.23-CvUzJskt.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.24-i_eMg5ox.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.25-2aKHwPX-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.26-B6wXoCEL.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.27-D4h1WfGM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.28-kvRPCStd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.29-DHAiwleD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.3-7H--eyZi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.30-C66cfAY2.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.31-FDmtiNim.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.32-DouHt2Dd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.33-B8HVvkJX.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.34-BtkRu1FN.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.35-DBylQbtk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.36-Sg089Kgh.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.37-CYtvbriS.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.38-DKkSLf8Z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.39-CecotKZD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.4-Bv8O3ZMb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.40-DdCvkmOU.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.41-ESn674Hc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.42-DL9V7NNV.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.43-yipO0cyk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.44-6rTmLZhm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.45-BJAj8lrm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.46-BDTzMn2c.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.47-Bxd4wGgi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.48-DxnFBLnH.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.49-DnVD0aOD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.5-B1wI2pp5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.50-D9JlkZd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.51-D9Vw6Bu3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.52-ClEJk4kn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.53-BSXU0vh-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.54-EcuxkR9v.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.55-CYiFhQX8.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.56--Gk9g8BK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.57-DnkOPZcy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.58-9MB8504z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.59-ByxIsN72.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.6-Bmk0dRVw.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.60-Bxwx_aWQ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.61-DA2z5sm7.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.62-C5iJPJZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.63-DAqrmaEc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.64-BgXFsljb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.65-DKiWujvu.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.66-8po4vUZ4.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.67-Cy5qyI9O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.68-BKny7Fy3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.69-B4VU4u_b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.7-BuqwNpgA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.70-BCd4n346.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.71-CkQppaWn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.72-Db7vaoFs.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.73-DI80TYWl.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.74-tMCtDAHB.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.75-Ciw0D5WG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.76-DoLjFgp-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.77-CpT2uvMy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.78-CkcJ4iZ1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.79-DsOUJjEM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.8-DsjypPd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.80-C0VwHTte.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.81-DTelu57i.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.82-BiMndGN1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.83-CVcC6eDG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.84-DlhZVt_O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.85-S8I2D3pA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.86-DozXXpH5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.87-Dsn0Vuuo.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.88-iNwxxDCr.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.89-B63u_9CZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.9-Bi3IzpMI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.90-ByeH1Pqf.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.91-UQLlagpm.woff2 +0 -0
- package/gui/dist/assets/brand-mark-VPhzz-WE.js +1 -0
- package/gui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/gui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/gui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/gui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/gui/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/gui/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/gui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/gui/dist/assets/index-5REODpG3.css +2 -0
- package/gui/dist/assets/index-BWKBeK77.js +94 -0
- package/gui/dist/assets/segment-thumb-features-BQYzrze9.js +1 -0
- package/gui/dist/classic/assets/App-Bz65x1J6.js +58 -0
- package/gui/dist/{assets/Tray-BOPQyDbH.js → classic/assets/Tray-kk7mdO6I.js} +1 -1
- package/gui/dist/classic/assets/index-Dp2j8bSc.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CvamtHjB.js +1 -0
- package/gui/dist/classic/index.html +47 -0
- package/gui/dist/favicon.png +0 -0
- package/gui/dist/favicon.svg +14 -0
- package/gui/dist/index.html +15 -2
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +17 -8
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/google.ts +7 -7
- package/src/adapters/kiro/adapter.ts +18 -3
- package/src/adapters/kiro/conversation.ts +8 -8
- package/src/adapters/kiro/payload.ts +45 -12
- package/src/adapters/kiro/stream.ts +230 -14
- package/src/adapters/kiro/structured-output-json.ts +191 -0
- package/src/adapters/kiro/structured-output-schema.ts +542 -0
- package/src/adapters/kiro/structured-output.ts +367 -0
- package/src/adapters/kiro-constants.ts +24 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/kiro-tools.ts +14 -9
- package/src/adapters/kiro-wire.ts +9 -5
- package/src/adapters/ollama-native.ts +11 -1
- package/src/adapters/openai-chat/messages.ts +58 -5
- package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
- package/src/adapters/openai-chat/passthrough.ts +5 -3
- package/src/adapters/openai-chat/tool-schema.ts +83 -13
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/opengateway-input.ts +18 -6
- package/src/adapters/openai-responses/passthrough.ts +5 -4
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/qoder/live-models.ts +115 -1
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/failure-verdict.ts +21 -0
- package/src/claude/inbound-content-options.ts +15 -2
- package/src/claude/inbound-model-options.ts +2 -1
- package/src/claude/inbound-records.ts +2 -0
- package/src/claude/inbound.ts +17 -11
- package/src/claude/outbound.ts +98 -22
- package/src/cli/capabilities-access-remote.ts +13 -0
- package/src/cli/capabilities-base.ts +26 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capabilities-provider-models.ts +3 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +12 -4
- package/src/cli/config-command.ts +11 -2
- package/src/cli/connect.ts +17 -2
- package/src/cli/dispatch.ts +14 -177
- package/src/cli/doctor.ts +95 -7
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +17 -8
- package/src/cli/link-apply-restart.ts +9 -2
- package/src/cli/link.ts +1 -1
- package/src/cli/models.ts +124 -38
- package/src/cli/registry.ts +12 -4
- package/src/cli/restart-failure.ts +17 -0
- package/src/cli/root.ts +8 -0
- package/src/cli/stop-approval.ts +2 -2
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +161 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/cli/system-restart-client.ts +5 -0
- package/src/cli/uninstall-client-state.ts +12 -1
- package/src/cli/update-restart-child.ts +13 -3
- package/src/cli/update-restart-home.ts +6 -3
- package/src/cli/update-restart.ts +36 -19
- package/src/client/connect.ts +35 -15
- package/src/client/hub-client.ts +5 -0
- package/src/client/link-home.ts +3 -2
- package/src/client/link-management-relay.ts +39 -2
- package/src/client/link-readiness.ts +3 -1
- package/src/client/machine-api.ts +2 -1
- package/src/client/machine-listener.ts +10 -0
- package/src/client/orphan-token-recovery.ts +322 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/auth-context.ts +49 -103
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +18 -12
- package/src/codex/forward-transport-headers.ts +35 -6
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/lineage.ts +13 -7
- package/src/codex/native-profile-api.ts +27 -1
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/shim-diagnostics.ts +7 -0
- package/src/codex/shim-legacy-record.ts +290 -0
- package/src/codex/shim-windows-refresh.ts +9 -2
- package/src/codex/shim-wrapper-write.ts +7 -0
- package/src/codex/shim.ts +80 -21
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/diagnostics.ts +9 -9
- package/src/config/load-degrade.ts +27 -27
- package/src/config/process-state.ts +5 -0
- package/src/config/provider-validation.ts +9 -2
- package/src/config/removed-opencode-free-backup.ts +6 -3
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/config/tracked-runtime-inspection.ts +3 -3
- package/src/generated/compatibility-version.json +595 -255
- package/src/images/loop.ts +4 -3
- package/src/lib/client-error-body.ts +215 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership-removal.ts +422 -0
- package/src/lib/config-ownership.ts +650 -81
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/crash-guard.ts +4 -2
- package/src/lib/desktop-cli-handoff.d.mts +4 -5
- package/src/lib/desktop-cli-handoff.mjs +18 -17
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/errors.ts +1 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/local-management-capability.ts +3 -1
- package/src/lib/messages-error-body.ts +162 -0
- package/src/lib/messages-sse-error-presentation.ts +93 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/passive-read.ts +9 -4
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/socks5-fetch.ts +21 -9
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +95 -12
- package/src/lib/windows-owner-acl.ts +22 -9
- package/src/lib/winsw.ts +5 -5
- package/src/lib/workflow-budget.ts +3 -1
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +42 -73
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +21 -11
- package/src/protocols/codecs/messages-ir.ts +15 -9
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +30 -7
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/encoders/messages.ts +72 -28
- package/src/protocols/trace.ts +18 -0
- package/src/providers/antigravity-models.ts +45 -12
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/quota/anthropic-usage-windows.ts +13 -3
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/reasoning-metadata.ts +2 -1
- package/src/providers/registry/entries-extended.ts +9 -0
- package/src/providers/request-pacing.ts +3 -2
- package/src/reasoning-effort.ts +7 -2
- package/src/remote/hub-usage.ts +3 -0
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +57 -0
- package/src/server/anthropic-rate-limit-headers.ts +75 -3
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +174 -84
- package/src/server/context-history.ts +5 -1
- package/src/server/gui-static.ts +4 -1
- package/src/server/hub-usage.ts +7 -2
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/link-management.ts +8 -0
- package/src/server/index/ollama-routes.ts +91 -0
- package/src/server/index/serve-options.ts +44 -24
- package/src/server/index/startup-warnings.ts +5 -12
- package/src/server/index/websocket-handler.ts +5 -2
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +9 -3
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/logs-usage-routes.ts +89 -4
- package/src/server/management/provider-routes.ts +2 -22
- package/src/server/management/qoder-provider-probe.ts +105 -0
- package/src/server/management/route-registry.ts +4 -1
- package/src/server/management/usage-aggregate-cache.ts +15 -5
- package/src/server/management/usage-source-facets.ts +38 -0
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +12 -4
- package/src/server/messages-native.ts +123 -47
- package/src/server/messages-response-headers.ts +25 -11
- package/src/server/messages-shared.ts +99 -65
- package/src/server/messages-sse-error-filter.ts +199 -0
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +91 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +17 -6
- package/src/server/responses/adapter-delivery.ts +17 -10
- package/src/server/responses/adapter-dispatch.ts +32 -31
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +24 -19
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/codex-ws-wire.ts +19 -3
- package/src/server/responses/compact.ts +57 -24
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +7 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +43 -27
- package/src/server/responses/core-errors.ts +24 -21
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +9 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/empty-completion-guard.ts +4 -1
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +20 -18
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +69 -48
- package/src/server/responses/request-transport.ts +36 -31
- package/src/server/responses/response-effects.ts +3 -2
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/terminal-guard.ts +30 -0
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/restart-replacement.ts +3 -1
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/sse-payload-rewrite.ts +23 -11
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +4 -0
- package/src/service/definition.ts +36 -4
- package/src/service/launchd.ts +89 -32
- package/src/service/logging.ts +34 -7
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/service/plist-xml.ts +59 -0
- package/src/service/state.ts +8 -0
- package/src/service/systemd-env.ts +2 -0
- package/src/service/systemd.ts +31 -7
- package/src/service/windows-taskxml.ts +16 -7
- package/src/service-manager-probe.ts +4 -10
- package/src/types/config.ts +2 -0
- package/src/types/provider.ts +2 -0
- package/src/types/request.ts +13 -1
- package/src/update/config-preflight.ts +48 -0
- package/src/update/index.ts +148 -26
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/client.ts +43 -0
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +64 -27
- package/src/usage/source-facets.ts +51 -0
- package/src/usage/source-filter.ts +65 -0
- package/src/usage/summary.ts +50 -8
- package/src/web-search/anthropic-executor.ts +105 -24
- package/src/web-search/executor.ts +5 -3
- package/src/web-search/loop.ts +33 -6
- package/src/web-search/progress-stream.ts +64 -5
- package/gui/dist/assets/App-bwugJRKn.js +0 -58
- package/gui/dist/assets/index-ebuVUtB7.js +0 -94
- package/gui/dist/assets/quota-summary-6HsrHQAy.js +0 -1
- /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
- /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The definite context-window overflow verdict, shared by combo failover (src/combos/failover.ts,
|
|
3
|
+
* which re-exports it) and the presentation classifier (src/lib/upstream-condition.ts). It has no
|
|
4
|
+
* imports, so the dashboard's type-only use of the classifier never pulls in server modules.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** A status can carry a verdict about the REQUEST; 401/403/429 speak about the credential. */
|
|
8
|
+
const CONTEXT_VERDICT_STATUSES: ReadonlySet<number> = new Set([400, 413, 422]);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Phrases a provider emits when the INPUT does not fit this model's context window. Matched
|
|
12
|
+
* against the innermost provider message only, so an unrelated refusal that merely quotes one
|
|
13
|
+
* of these tokens in a code field cannot authorize a replay.
|
|
14
|
+
*/
|
|
15
|
+
const DEFINITE_CONTEXT_OVERFLOW_PHRASES = [
|
|
16
|
+
"exceeds the context window",
|
|
17
|
+
"exceed the context window",
|
|
18
|
+
"context window exceeded",
|
|
19
|
+
"context length exceeded",
|
|
20
|
+
"maximum context length",
|
|
21
|
+
"maximum context window",
|
|
22
|
+
"too many tokens",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Short provider verdicts that a validation error could otherwise echo as the caller's own value
|
|
27
|
+
* (#7443). Each counts only at the very start of the provider's leaf message, after JSON envelopes
|
|
28
|
+
* are unwrapped, and Anthropic's only with its token counts. Text that merely contains one, including
|
|
29
|
+
* a serialized SDK exception or a quoted caller object, is not evidence: only the phrases dev already
|
|
30
|
+
* matched as substrings keep that wider reach.
|
|
31
|
+
*/
|
|
32
|
+
const ANCHORED_CONTEXT_OVERFLOW_VERDICTS: readonly RegExp[] = [
|
|
33
|
+
/^prompt is too long: \d+ tokens > \d+ maximum/i,
|
|
34
|
+
/^input is too long for requested model\b/i,
|
|
35
|
+
/^please reduce the length of the messages or completion\b/i,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
/** Wrapper envelopes unwrapped before the leaf message is read. */
|
|
39
|
+
const MAX_CONTEXT_OVERFLOW_ENVELOPES = 4;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Parameter validation echoes the caller's own value, so its prose is not a context verdict even
|
|
43
|
+
* when the value reads like one: "Invalid 'tools[0].function.name': 'prompt is too long'". These
|
|
44
|
+
* markers are read anywhere in the text, so an SDK error wrapper that serializes such a record as a
|
|
45
|
+
* Python dict is refused too, while a quoted genuine verdict in the same wrapper stays evidence.
|
|
46
|
+
*/
|
|
47
|
+
const CONTEXT_PARAM_NAMES = "messages|input|input_text|input_tokens|prompt|contents?|max_tokens|max_completion_tokens|max_output_tokens";
|
|
48
|
+
/** A `param` naming the conversation or a token budget is consistent with an overflow. */
|
|
49
|
+
const CONTEXT_PARAM = new RegExp(`^(?:${CONTEXT_PARAM_NAMES})(?:$|[.[])`, "i");
|
|
50
|
+
const PARAMETER_VALIDATION_CODES: ReadonlySet<string> = new Set(["invalid_value", "invalid_type"]);
|
|
51
|
+
const PARAMETER_VALIDATION_MARKERS: readonly RegExp[] = [
|
|
52
|
+
/\binvalid_(?:value|type)\b/i,
|
|
53
|
+
new RegExp(`['"]param['"]\\s*:\\s*['"](?!(?:${CONTEXT_PARAM_NAMES})(?:['".[]))`, "i"),
|
|
54
|
+
/\binvalid\s+(?:value\s+for\s+)?['"`\u2018\u201c]/i,
|
|
55
|
+
/\binvalid\s+(?:tool|function|parameter|argument|field|value)\b/i,
|
|
56
|
+
/\binput_value\s*=/i,
|
|
57
|
+
/\bvalidation errors? for\b/i,
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
function isParameterValidationRecord(record: Record<string, unknown>): boolean {
|
|
61
|
+
if (typeof record.code === "string" && PARAMETER_VALIDATION_CODES.has(record.code.toLowerCase())) return true;
|
|
62
|
+
return typeof record.param === "string" && record.param.length > 0 && !CONTEXT_PARAM.test(record.param);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isDefiniteContextOverflowMessage(text: string): boolean {
|
|
66
|
+
const normalized = text.toLowerCase();
|
|
67
|
+
return normalized === "context_length_exceeded"
|
|
68
|
+
|| DEFINITE_CONTEXT_OVERFLOW_PHRASES.some(phrase => normalized.includes(phrase))
|
|
69
|
+
|| ANCHORED_CONTEXT_OVERFLOW_VERDICTS.some(verdict => verdict.test(text.trim()));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Confirm a context overflow from the provider MESSAGE rather than from a code token that
|
|
74
|
+
* merely appears somewhere in the envelope. An upstream controls both fields and can emit a
|
|
75
|
+
* contradictory pair -- `context_length_exceeded` beside `Unsupported parameter: user` -- and
|
|
76
|
+
* that is not evidence the turn is too large for this model. `classifyError` reads the whole
|
|
77
|
+
* blob, which is exactly the looseness this must not inherit.
|
|
78
|
+
*
|
|
79
|
+
* A JSON-shaped body that fails to parse is truncated or corrupt, not prose: `classificationText`
|
|
80
|
+
* is capped at 500 characters by `normalizeUpstreamErrorText` before it reaches this function, so
|
|
81
|
+
* a long envelope arrives here as a JSON prefix. Reading that prefix as plain text would let an
|
|
82
|
+
* arbitrary field that happens to sit in the first 500 bytes authorize a hop, so it fails closed.
|
|
83
|
+
*
|
|
84
|
+
* Only the exact proxy wrapper is unwrapped, within a fixed envelope budget and 16,384 characters.
|
|
85
|
+
* An optional caller matcher specializes the verdict on the unwrapped, validated leaf.
|
|
86
|
+
* Exported for the sidecar loops, which classify their own provider failures with the same rule.
|
|
87
|
+
*/
|
|
88
|
+
export function isDefiniteContextOverflow(status: number, message: string, matchMessage = isDefiniteContextOverflowMessage): boolean {
|
|
89
|
+
if (!CONTEXT_VERDICT_STATUSES.has(status) && status < 500) return false;
|
|
90
|
+
if (message.length > 16_384) return false;
|
|
91
|
+
let text = message.trim();
|
|
92
|
+
// One pass per unwrapped envelope, plus one for the leaf the last envelope yields.
|
|
93
|
+
for (let unwrapped = 0; unwrapped <= MAX_CONTEXT_OVERFLOW_ENVELOPES; unwrapped += 1) {
|
|
94
|
+
const providerPrefix = /^Provider error \d{3}:\s*/.exec(text);
|
|
95
|
+
if (providerPrefix) text = text.slice(providerPrefix[0].length).trim();
|
|
96
|
+
if (!text.startsWith("{")) return !PARAMETER_VALIDATION_MARKERS.some(marker => marker.test(text)) && matchMessage(text);
|
|
97
|
+
if (unwrapped === MAX_CONTEXT_OVERFLOW_ENVELOPES) return false;
|
|
98
|
+
let payload: unknown;
|
|
99
|
+
try { payload = JSON.parse(text); } catch { return false; }
|
|
100
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) return false;
|
|
101
|
+
const record = payload as Record<string, unknown>;
|
|
102
|
+
const response = record.response && typeof record.response === "object" && !Array.isArray(record.response)
|
|
103
|
+
? record.response as Record<string, unknown>
|
|
104
|
+
: undefined;
|
|
105
|
+
const source = [record.error, response?.error, response?.last_error, record.last_error, record]
|
|
106
|
+
.find((candidate): candidate is Record<string, unknown> =>
|
|
107
|
+
!!candidate && typeof candidate === "object" && !Array.isArray(candidate)
|
|
108
|
+
&& typeof (candidate as Record<string, unknown>).message === "string");
|
|
109
|
+
if (!source || isParameterValidationRecord(source)) return false;
|
|
110
|
+
text = (source.message as string).trim();
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
}
|
package/src/lib/crash-guard.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { appendFileSync, mkdirSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { getConfigDir } from "../config";
|
|
4
|
-
import { recordOwnedConfigPath } from "./config-ownership";
|
|
4
|
+
import { ConfigUninstallInProgressError, recordOwnedConfigPath } from "./config-ownership";
|
|
5
5
|
import { redactSecretString, redactUrlForLog } from "./redact";
|
|
6
6
|
import { sidecarBreadcrumb, activityBreadcrumb } from "./sidecar-tracker";
|
|
7
7
|
import { retainedUtf8Bytes, truncateRetainedUtf8 } from "./admission";
|
|
@@ -32,7 +32,9 @@ function crashLogPath(): string {
|
|
|
32
32
|
try {
|
|
33
33
|
recordOwnedConfigPath(dir, join(dir, "crash.log"));
|
|
34
34
|
mkdirSync(dir, { recursive: true });
|
|
35
|
-
} catch {
|
|
35
|
+
} catch (error) {
|
|
36
|
+
// During uninstall the log is skipped (both callers swallow this) rather than recreated.
|
|
37
|
+
if (error instanceof ConfigUninstallInProgressError) throw error;
|
|
36
38
|
/* best-effort: directory usually already exists */
|
|
37
39
|
}
|
|
38
40
|
return join(dir, "crash.log");
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { spawn } from "node:child_process";
|
|
2
|
-
import type { accessSync,
|
|
2
|
+
import type { accessSync, statSync } from "node:fs";
|
|
3
3
|
import type { DesktopCliRecordRead, DesktopCliRecordIssue } from "./desktop-cli-record.mjs";
|
|
4
4
|
export type DesktopHandoffIssue = DesktopCliRecordIssue | "target-invalid" | "target-self" | "target-unusable" | "spawn-failed";
|
|
5
5
|
export type DesktopCliHandoffPlan =
|
|
6
|
-
| { kind: "continue"; reason: "excluded" | "missing" | "disabled" | "
|
|
6
|
+
| { kind: "continue"; reason: "excluded" | "missing" | "disabled" | "windows-path-only" }
|
|
7
7
|
| { kind: "error"; issue: DesktopHandoffIssue }
|
|
8
8
|
| { kind: "handoff"; target: string };
|
|
9
9
|
export type DesktopCliHandoffExit =
|
|
10
|
-
| { kind: "continue" }
|
|
11
10
|
| { kind: "error"; issue: "spawn-failed" }
|
|
12
11
|
| { kind: "exit"; code: number; signal: NodeJS.Signals | null };
|
|
13
12
|
export function desktopHandoffExcluded(argv: string[], env?: NodeJS.ProcessEnv): boolean;
|
|
@@ -16,5 +15,5 @@ export function planDesktopCliHandoff(input?: {
|
|
|
16
15
|
recordRead?: DesktopCliRecordRead; selfPaths?: (string | undefined)[];
|
|
17
16
|
}, deps?: { stat?: typeof statSync; access?: typeof accessSync; realpath?: (path: string) => string }): DesktopCliHandoffPlan;
|
|
18
17
|
export function runDesktopCliHandoff(plan: Extract<DesktopCliHandoffPlan, { kind: "handoff" }>, launch: {
|
|
19
|
-
argv: string[]; env: NodeJS.ProcessEnv; proof: string; context: string;
|
|
20
|
-
}, deps?: { spawn?: typeof spawn;
|
|
18
|
+
argv: string[]; env: NodeJS.ProcessEnv; proof: string; context: string; onSpawn?: (pid: number) => void;
|
|
19
|
+
}, deps?: { spawn?: typeof spawn; parent?: Pick<NodeJS.Process, "on" | "removeListener">; platform?: NodeJS.Platform }): Promise<DesktopCliHandoffExit>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
-
import { accessSync, constants,
|
|
2
|
+
import { accessSync, constants, realpathSync, statSync } from "node:fs";
|
|
3
3
|
import { posix, win32 } from "node:path";
|
|
4
4
|
import { readDesktopCliRecord } from "./desktop-cli-record.mjs";
|
|
5
5
|
import { isCodexCliUpdateInspectionArgv } from "../update/codex-cli-update-launch-policy.mjs";
|
|
@@ -10,6 +10,7 @@ export function desktopHandoffExcluded(argv, env = process.env) {
|
|
|
10
10
|
const args = argv.filter(arg => !arg.startsWith(PROOF_PREFIX));
|
|
11
11
|
return env.OCX_NO_DESKTOP_HANDOFF === "1"
|
|
12
12
|
|| ["update", "uninstall", "remove"].includes(args[0])
|
|
13
|
+
|| (args[0] === "capabilities" && args.includes("--contracts"))
|
|
13
14
|
|| (args[0] ?? "").startsWith("__")
|
|
14
15
|
|| isCodexCliUpdateInspectionArgv(["node", "ocx.mjs", ...args]);
|
|
15
16
|
}
|
|
@@ -44,10 +45,8 @@ export function planDesktopCliHandoff(input = {}, deps = {}) {
|
|
|
44
45
|
if (key(own) === key(physical)) return { kind: "error", issue: "target-self" };
|
|
45
46
|
}
|
|
46
47
|
return { kind: "handoff", target: physical };
|
|
47
|
-
} catch
|
|
48
|
-
return error
|
|
49
|
-
? { kind: "continue", reason: "target-missing" }
|
|
50
|
-
: { kind: "error", issue: "target-unusable" };
|
|
48
|
+
} catch {
|
|
49
|
+
return { kind: "error", issue: "target-unusable" };
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
|
|
@@ -55,14 +54,7 @@ export function runDesktopCliHandoff(plan, launch, deps = {}) {
|
|
|
55
54
|
const spawnChild = deps.spawn ?? spawn;
|
|
56
55
|
const parent = deps.parent ?? process;
|
|
57
56
|
const platform = deps.platform ?? process.platform;
|
|
58
|
-
const
|
|
59
|
-
const spawnFailure = error => {
|
|
60
|
-
if (error?.code === "ENOENT") {
|
|
61
|
-
try { lstat(plan.target); }
|
|
62
|
-
catch (checkError) { if (checkError?.code === "ENOENT") return { kind: "continue" }; }
|
|
63
|
-
}
|
|
64
|
-
return { kind: "error", issue: "spawn-failed" };
|
|
65
|
-
};
|
|
57
|
+
const spawnFailure = () => ({ kind: "error", issue: "spawn-failed" });
|
|
66
58
|
const argv = launch.argv.filter(arg => !arg.startsWith(PROOF_PREFIX));
|
|
67
59
|
const env = { ...launch.env, OCX_NO_DESKTOP_HANDOFF: "1", OCX_NODE_LAUNCH_CONTEXT: launch.context };
|
|
68
60
|
delete env.OCX_BUN_RUNTIME_SOURCE;
|
|
@@ -73,8 +65,8 @@ export function runDesktopCliHandoff(plan, launch, deps = {}) {
|
|
|
73
65
|
child = spawnChild(plan.target, [`${PROOF_PREFIX}${launch.proof}`, ...argv], {
|
|
74
66
|
stdio: "inherit", shell: false, windowsHide: true, env,
|
|
75
67
|
});
|
|
76
|
-
} catch
|
|
77
|
-
resolveExit(spawnFailure(
|
|
68
|
+
} catch {
|
|
69
|
+
resolveExit(spawnFailure());
|
|
78
70
|
return;
|
|
79
71
|
}
|
|
80
72
|
const forwarded = platform === "win32" ? ["SIGINT", "SIGTERM"] : ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
@@ -86,7 +78,16 @@ export function runDesktopCliHandoff(plan, launch, deps = {}) {
|
|
|
86
78
|
const clear = () => { for (const [signal, handler] of handlers) parent.removeListener(signal, handler); };
|
|
87
79
|
let done = false;
|
|
88
80
|
const finish = result => { if (done) return; done = true; clear(); resolveExit(result); };
|
|
89
|
-
child.once("error",
|
|
90
|
-
|
|
81
|
+
child.once("error", () => finish(spawnFailure()));
|
|
82
|
+
let delegateError = false;
|
|
83
|
+
child.once("exit", (code, signal) => finish(delegateError ? { kind: "error", issue: "spawn-failed" } : { kind: "exit", code: code ?? 1, signal }));
|
|
84
|
+
if (child.pid && launch.onSpawn) {
|
|
85
|
+
try { launch.onSpawn(child.pid); }
|
|
86
|
+
catch (error) {
|
|
87
|
+
delegateError = true;
|
|
88
|
+
console.error(`opencodex: sync mutex delegate publication failed: ${error.message}`);
|
|
89
|
+
try { child.kill(); } catch (killError) { console.error(`opencodex: failed to stop sync child: ${killError.message}`); }
|
|
90
|
+
}
|
|
91
|
+
}
|
|
91
92
|
});
|
|
92
93
|
}
|
|
@@ -1,19 +1,41 @@
|
|
|
1
|
-
import { normalizeDeclaredToolName, type AdapterEvent } from "../types";
|
|
1
|
+
import { namespacedToolName, normalizeDeclaredToolName, type AdapterEvent } from "../types";
|
|
2
2
|
import { UNDECLARED_TOOL_CALL_ERROR_CODE } from "./errors";
|
|
3
3
|
import { releaseTranslatedEvent, type TranslatorBudget } from "./translator-budget";
|
|
4
4
|
import { releaseCompactionCiphertextLease } from "../responses/compaction";
|
|
5
5
|
|
|
6
|
-
/**
|
|
6
|
+
/** Current-turn names for normalization, with wire-specific membership enforcement. */
|
|
7
7
|
export interface ClientToolCatalogRestriction {
|
|
8
8
|
declaredToolNames: ReadonlySet<string>;
|
|
9
9
|
bareCustomToolNames: ReadonlySet<string>;
|
|
10
|
+
canonicalToolNames?: ReadonlySet<string>;
|
|
11
|
+
enforceDeclaredToolNames?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Current declarations may narrow the selection-filtered bridge names, never widen them. */
|
|
15
|
+
export function currentTurnToolBridgeMaps<T extends Pick<ClientToolCatalogRestriction, "declaredToolNames" | "bareCustomToolNames"> & {
|
|
16
|
+
toolNsMap: ReadonlyMap<string, { namespace: string; name: string }>;
|
|
17
|
+
}>(
|
|
18
|
+
maps: T,
|
|
19
|
+
catalog: ClientToolCatalogRestriction | undefined,
|
|
20
|
+
): T {
|
|
21
|
+
if (!catalog) return maps;
|
|
22
|
+
const currentIdentity = (name: string): boolean => {
|
|
23
|
+
const mapped = maps.toolNsMap.get(name);
|
|
24
|
+
// An ambiguous historical bare alias may lack a mapping. Keep only current identities.
|
|
25
|
+
return catalog.canonicalToolNames?.has(mapped ? namespacedToolName(mapped.namespace, mapped.name) : name) ?? true;
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
...maps,
|
|
29
|
+
declaredToolNames: new Set([...catalog.declaredToolNames].filter(name => maps.declaredToolNames.has(name) && currentIdentity(name))),
|
|
30
|
+
bareCustomToolNames: new Set([...catalog.bareCustomToolNames].filter(name => maps.bareCustomToolNames.has(name) && currentIdentity(name))),
|
|
31
|
+
};
|
|
10
32
|
}
|
|
11
33
|
|
|
12
34
|
export function emptyToolCatalogRefusal(
|
|
13
35
|
event: AdapterEvent,
|
|
14
36
|
catalog: ClientToolCatalogRestriction | undefined,
|
|
15
37
|
): Extract<AdapterEvent, { type: "error" }> | undefined {
|
|
16
|
-
if (!catalog) return;
|
|
38
|
+
if (!catalog || catalog.enforceDeclaredToolNames === false) return;
|
|
17
39
|
if (event.type === "tool_call_start") {
|
|
18
40
|
const name = normalizeDeclaredToolName(event.name, catalog.declaredToolNames, undefined, catalog.bareCustomToolNames);
|
|
19
41
|
if (catalog.declaredToolNames.has(name)) return;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Destination labels are minted locally and revalidated by the error constructor. */
|
|
2
|
+
declare const errorDestinationBrand: unique symbol;
|
|
3
|
+
export type ErrorDestinationLabel = { readonly [errorDestinationBrand]: true };
|
|
4
|
+
const labels = new WeakMap<object, { kind: "origin" | "provider"; value: string }>();
|
|
5
|
+
const fallback = "the provider";
|
|
6
|
+
const providerId = /^[A-Za-z0-9._-]{1,64}$/;
|
|
7
|
+
const schemes = new Set(["http:", "https:", "ws:", "wss:", "socks5:", "socks5h:"]);
|
|
8
|
+
function origin(value: unknown): string {
|
|
9
|
+
if (typeof value !== "string") return fallback;
|
|
10
|
+
try {
|
|
11
|
+
const url = new URL(value);
|
|
12
|
+
return schemes.has(url.protocol) && url.hostname.length > 0 && url.hostname.length <= 253
|
|
13
|
+
? `${url.protocol}//${url.host}` : fallback;
|
|
14
|
+
} catch { return fallback; }
|
|
15
|
+
}
|
|
16
|
+
function mint(kind: "origin" | "provider", value: string): ErrorDestinationLabel {
|
|
17
|
+
const label = Object.freeze({}) as ErrorDestinationLabel;
|
|
18
|
+
labels.set(label, { kind, value });
|
|
19
|
+
return label;
|
|
20
|
+
}
|
|
21
|
+
export function errorDestinationLabel(url: string): ErrorDestinationLabel { return mint("origin", origin(url)); }
|
|
22
|
+
export function providerErrorDestinationLabel(id: string): ErrorDestinationLabel {
|
|
23
|
+
return mint("provider", typeof id === "string" && providerId.test(id) ? id : fallback);
|
|
24
|
+
}
|
|
25
|
+
export function errorDestinationText(label: ErrorDestinationLabel): string {
|
|
26
|
+
// Runtime validation also handles callers that supply a value without the branded type.
|
|
27
|
+
const input: unknown = label;
|
|
28
|
+
if (typeof input === "string") return origin(input);
|
|
29
|
+
const owned = input !== null && typeof input === "object" ? labels.get(input) : undefined;
|
|
30
|
+
if (!owned) return fallback;
|
|
31
|
+
return owned.kind === "origin" ? origin(owned.value) : providerId.test(owned.value) ? owned.value : fallback;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A client selector captured before any route or helper-model rewrite. */
|
|
35
|
+
declare const clientModelBrand: unique symbol;
|
|
36
|
+
export type ClientFacingModelLabel = { readonly [clientModelBrand]: true };
|
|
37
|
+
const clientModels = new WeakMap<object, string>();
|
|
38
|
+
const clientModelId = /^[A-Za-z0-9][A-Za-z0-9._-]*(?:\/[A-Za-z0-9][A-Za-z0-9._-]*){0,3}$/;
|
|
39
|
+
export function clientFacingModelLabel(requestedModel: unknown, placeholder: "requested" | "unnamed" = "requested"): ClientFacingModelLabel {
|
|
40
|
+
const label = Object.freeze({}) as ClientFacingModelLabel;
|
|
41
|
+
clientModels.set(label, typeof requestedModel === "string" && requestedModel.length <= 128
|
|
42
|
+
&& clientModelId.test(requestedModel) ? requestedModel : placeholder === "unnamed" ? "(unnamed)" : "the requested model");
|
|
43
|
+
return label;
|
|
44
|
+
}
|
|
45
|
+
export function clientFacingModelText(label: ClientFacingModelLabel | undefined): string {
|
|
46
|
+
return label && clientModels.get(label) || "the requested model";
|
|
47
|
+
}
|
package/src/lib/errors.ts
CHANGED
|
@@ -777,6 +777,7 @@ export function httpStatusFromTerminalError(error: {
|
|
|
777
777
|
if (message && isClientClosedMessage(message)) return 499;
|
|
778
778
|
if (error.type === "invalid_request_error") return 400;
|
|
779
779
|
if (error.type === "proxy_error") return 500;
|
|
780
|
+
if (error.code === "upstream_stall_timeout") return 504;
|
|
780
781
|
// A structured server class must not be downgraded to a CLIENT error by message wording.
|
|
781
782
|
// classifyError assigns `server_error` + `upstream_server_error` to every 5xx it sees, so
|
|
782
783
|
// the class is authoritative about blame: the upstream failed, the caller did not send a
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Failure detail a request-log row may carry: a closed code plus bounded numeric or closed parameters.
|
|
3
|
+
* The dashboard renders each code as localized text; rows never hold free-form failure text.
|
|
4
|
+
*/
|
|
5
|
+
export const FAILURE_DETAIL_CODES = [
|
|
6
|
+
"provider_error",
|
|
7
|
+
"header_timeout",
|
|
8
|
+
"connect_timeout",
|
|
9
|
+
"connect_failed",
|
|
10
|
+
"client_closed",
|
|
11
|
+
"body_stall",
|
|
12
|
+
"body_overflow",
|
|
13
|
+
"stream_error_stop",
|
|
14
|
+
"stream_ended_early",
|
|
15
|
+
"stream_failed",
|
|
16
|
+
"output_limit",
|
|
17
|
+
"stall_timeout",
|
|
18
|
+
"adapter_eof",
|
|
19
|
+
"generation_timeout",
|
|
20
|
+
"turn_inactivity",
|
|
21
|
+
] as const;
|
|
22
|
+
|
|
23
|
+
export type FailureDetailCode = typeof FAILURE_DETAIL_CODES[number];
|
|
24
|
+
|
|
25
|
+
/** Closed provider error classes a provider_error detail may name (the Anthropic error envelope types). */
|
|
26
|
+
export const FAILURE_DETAIL_PROVIDER_TYPES = [
|
|
27
|
+
"invalid_request_error", "authentication_error", "permission_error", "not_found_error",
|
|
28
|
+
"rate_limit_error", "api_error", "overloaded_error", "request_too_large",
|
|
29
|
+
] as const;
|
|
30
|
+
|
|
31
|
+
export type FailureDetailProviderType = typeof FAILURE_DETAIL_PROVIDER_TYPES[number];
|
|
32
|
+
|
|
33
|
+
export interface FailureDetail {
|
|
34
|
+
code: FailureDetailCode;
|
|
35
|
+
/** Milliseconds for timeouts and stalls, bytes for an overflow. */
|
|
36
|
+
value?: number;
|
|
37
|
+
type?: FailureDetailProviderType;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const CODES: ReadonlySet<string> = new Set(FAILURE_DETAIL_CODES);
|
|
41
|
+
const TYPES: ReadonlySet<string> = new Set(FAILURE_DETAIL_PROVIDER_TYPES);
|
|
42
|
+
const MAX_VALUE = 1e12;
|
|
43
|
+
|
|
44
|
+
/** Codes whose value parameter carries meaning; the value is dropped for any other code. */
|
|
45
|
+
const VALUED: ReadonlySet<FailureDetailCode> = new Set([
|
|
46
|
+
"header_timeout", "connect_timeout", "body_stall", "body_overflow", "generation_timeout", "turn_inactivity",
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The detail when it is a closed code with valid parameters, else undefined. Free text (a legacy or
|
|
51
|
+
* edited row) is never accepted. Returns the same object when it is already exactly valid.
|
|
52
|
+
*/
|
|
53
|
+
export function boundedFailureDetail(value: unknown): FailureDetail | undefined {
|
|
54
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
55
|
+
const record = value as Record<string, unknown>;
|
|
56
|
+
if (typeof record.code !== "string" || !CODES.has(record.code)) return undefined;
|
|
57
|
+
const code = record.code as FailureDetailCode;
|
|
58
|
+
const number = record.value;
|
|
59
|
+
const valid = typeof number === "number" && Number.isSafeInteger(number) && number >= 0 && number <= MAX_VALUE && VALUED.has(code);
|
|
60
|
+
const type = code === "provider_error" && typeof record.type === "string" && TYPES.has(record.type)
|
|
61
|
+
? record.type as FailureDetailProviderType : undefined;
|
|
62
|
+
const keys = Object.keys(record);
|
|
63
|
+
const exact = keys.every(key => key === "code" || (key === "value" && valid) || (key === "type" && type !== undefined));
|
|
64
|
+
if (exact) return record as unknown as FailureDetail;
|
|
65
|
+
return { code, ...(valid ? { value: number as number } : {}), ...(type ? { type } : {}) };
|
|
66
|
+
}
|
|
@@ -20,6 +20,7 @@ export const LOCAL_MANAGEMENT_READ_PATHS = {
|
|
|
20
20
|
providerQuotas: "/api/provider-quotas",
|
|
21
21
|
usageTimeline: "/api/usage/timeline",
|
|
22
22
|
stop: "/api/stop",
|
|
23
|
+
nativeMainAdmission: "/api/native-main-profiles/admission",
|
|
23
24
|
} as const;
|
|
24
25
|
|
|
25
26
|
export type LocalManagementReadPath =
|
|
@@ -52,7 +53,8 @@ function isLocalManagementReadPath(path: string): path is LocalManagementReadPat
|
|
|
52
53
|
|| path === LOCAL_MANAGEMENT_READ_PATHS.startupHealth
|
|
53
54
|
|| path === LOCAL_MANAGEMENT_READ_PATHS.providerQuotas
|
|
54
55
|
|| path === LOCAL_MANAGEMENT_READ_PATHS.usageTimeline
|
|
55
|
-
|| path === LOCAL_MANAGEMENT_READ_PATHS.stop
|
|
56
|
+
|| path === LOCAL_MANAGEMENT_READ_PATHS.stop
|
|
57
|
+
|| path === LOCAL_MANAGEMENT_READ_PATHS.nativeMainAdmission;
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
function localReadCapabilityPayload(
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { carryReplayRefusal, isNonReplayableResponse, markResponseNonReplayable } from "./upstream-retry";
|
|
2
|
+
import {
|
|
3
|
+
ANTHROPIC_ERROR_CODES, ANTHROPIC_ERROR_TYPES, CLAUDE_CONTEXT_OVERFLOW_MESSAGE,
|
|
4
|
+
CLIENT_ERROR_CONTRACTS, clientErrorCodeMessage, actionableRefusalMessage, isProxyError, attachComboFailureEvidence, carryProxyError, proxyErrorPresentation, comboFailureEvidence, markProxyError, type ProxyErrorPresentation, type ClientErrorContract,
|
|
5
|
+
} from "./client-error-body";
|
|
6
|
+
import { classifyUpstreamCondition, upstreamConditionMessage, type UpstreamCondition, type UpstreamConditionEvidence } from "./upstream-condition";
|
|
7
|
+
|
|
8
|
+
type Rec = Record<string, unknown>;
|
|
9
|
+
const STATUS_TYPES: ReadonlyMap<number, string> = new Map([
|
|
10
|
+
[401, "authentication_error"], [402, "billing_error"], [403, "permission_error"],
|
|
11
|
+
[404, "not_found_error"], [409, "conflict_error"], [413, "request_too_large"],
|
|
12
|
+
[429, "rate_limit_error"], [504, "timeout_error"], [529, "overloaded_error"],
|
|
13
|
+
]);
|
|
14
|
+
/** Select the owned sentence from the message this path previously delivered. */
|
|
15
|
+
export function messagesOverflowPresentation(baselineMessage: unknown): boolean {
|
|
16
|
+
if (typeof baselineMessage !== "string") return false;
|
|
17
|
+
const message = baselineMessage.toLowerCase();
|
|
18
|
+
return message.includes("prompt is too long") || message.includes("input is too long for requested model");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Preserve the former JSON role display decision without rendering caller values. */
|
|
22
|
+
export function messagesRolePresentation(role: unknown): { overflow: boolean; coercionFailed: boolean } {
|
|
23
|
+
let overflow = false;
|
|
24
|
+
const active = new WeakSet<unknown[]>();
|
|
25
|
+
const stack: { array: unknown[]; index: number }[] = [];
|
|
26
|
+
let value = role;
|
|
27
|
+
for (;;) {
|
|
28
|
+
if (typeof value === "string") overflow ||= messagesOverflowPresentation(value);
|
|
29
|
+
else if (Array.isArray(value)) {
|
|
30
|
+
if (!active.has(value)) { active.add(value); stack.push({ array: value, index: 0 }); }
|
|
31
|
+
} else if (value !== null && typeof value === "object" && Object.hasOwn(value, "toString")) {
|
|
32
|
+
return { overflow: false, coercionFailed: true };
|
|
33
|
+
}
|
|
34
|
+
let next = false;
|
|
35
|
+
while (stack.length > 0) {
|
|
36
|
+
const frame = stack[stack.length - 1]!;
|
|
37
|
+
if (frame.index < frame.array.length) { value = frame.array[frame.index++]; next = true; break; }
|
|
38
|
+
active.delete(frame.array); stack.pop();
|
|
39
|
+
}
|
|
40
|
+
if (!next) return { overflow, coercionFailed: false };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function isMessagesErrorEnvelope(value: unknown): value is Rec {
|
|
45
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) return false;
|
|
46
|
+
const body = value as Rec;
|
|
47
|
+
const error = body.error;
|
|
48
|
+
return body.type === "error" || (error !== null && typeof error === "object" && !Array.isArray(error)
|
|
49
|
+
&& (typeof (error as Rec).type === "string" || typeof (error as Rec).message === "string"));
|
|
50
|
+
}
|
|
51
|
+
/** Match the SDK's diagnostic selection on the parsed body or non-JSON response text. */
|
|
52
|
+
function messagesErrorDiagnostic(value: unknown, fallback: string | undefined): string | undefined {
|
|
53
|
+
const message = value !== null && typeof value === "object" && Object.hasOwn(value, "message")
|
|
54
|
+
? (value as Rec).message : undefined;
|
|
55
|
+
return message ? typeof message === "string" ? message : JSON.stringify(message)
|
|
56
|
+
: value ? JSON.stringify(value) : fallback;
|
|
57
|
+
}
|
|
58
|
+
export function messagesRelayedOverflowPresentation(text: string, parsed: unknown): boolean {
|
|
59
|
+
return messagesOverflowPresentation(messagesErrorDiagnostic(parsed, text));
|
|
60
|
+
}
|
|
61
|
+
/** The pinned SSE APIError uses the parsed-or-raw whole body and no HTTP fallback. */
|
|
62
|
+
export function messagesSseErrorOverflowPresentation(data: string, parsed: unknown): boolean {
|
|
63
|
+
return messagesOverflowPresentation(messagesErrorDiagnostic(parsed ?? data, undefined) || "(no status code or body)");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface OwnedAnthropicErrorOptions {
|
|
67
|
+
status: number;
|
|
68
|
+
type?: string;
|
|
69
|
+
code?: string;
|
|
70
|
+
evidence: UpstreamConditionEvidence;
|
|
71
|
+
overflow?: boolean;
|
|
72
|
+
contract?: ClientErrorContract;
|
|
73
|
+
condition?: UpstreamCondition;
|
|
74
|
+
/** An object marked by the local producer; serialized fields cannot grant ownership. */
|
|
75
|
+
localError?: { message: string };
|
|
76
|
+
}
|
|
77
|
+
export function ownedAnthropicErrorPayload(options: OwnedAnthropicErrorOptions): Rec {
|
|
78
|
+
const type = ANTHROPIC_ERROR_TYPES.get(options.type ?? "")
|
|
79
|
+
?? STATUS_TYPES.get(options.status) ?? (options.status >= 500 ? "api_error" : "invalid_request_error");
|
|
80
|
+
const code = options.code === "thread_unsupported_request" ? undefined : ANTHROPIC_ERROR_CODES.get(options.code ?? "");
|
|
81
|
+
const message = options.overflow ? CLAUDE_CONTEXT_OVERFLOW_MESSAGE
|
|
82
|
+
: options.localError && isProxyError(options.localError) ? fixedLocalMessage(options.localError, options.evidence.code ?? code, options.evidence.type) ?? options.localError.message
|
|
83
|
+
: actionableRefusalMessage(options.evidence, code ?? null, options.contract)
|
|
84
|
+
?? (options.contract ? CLIENT_ERROR_CONTRACTS[options.contract] : undefined)
|
|
85
|
+
?? (options.condition ? upstreamConditionMessage(options.condition) : undefined)
|
|
86
|
+
?? clientErrorCodeMessage(code)
|
|
87
|
+
?? upstreamConditionMessage(classifyUpstreamCondition(options.evidence) ?? "upstream_failed");
|
|
88
|
+
return { type: "error", error: { type, message, ...(code ? { code } : {}) } };
|
|
89
|
+
}
|
|
90
|
+
export function ownedAnthropicErrorResponse(options: OwnedAnthropicErrorOptions, legacy?: Rec): Response {
|
|
91
|
+
const response = Response.json(ownedAnthropicErrorPayload(options), { status: options.status, headers: { "Content-Type": "application/json" } });
|
|
92
|
+
return legacy === undefined ? response : attachComboFailureEvidence(response, JSON.stringify(legacy));
|
|
93
|
+
}
|
|
94
|
+
/** Admission and presentation use separate numbers; this bounds display only. */
|
|
95
|
+
export function boundedMessagesDisplayCount(value: number): string | undefined {
|
|
96
|
+
return Number.isSafeInteger(value) && value >= 0 && value <= 1e12 ? String(value) : undefined;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const METHOD: ReadonlyMap<string, string> = new Map(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "CONNECT", "TRACE"].map(method => [method, method]));
|
|
100
|
+
const MESSAGES_PATH: ReadonlyMap<string, string> = new Map([["/v1/messages", "/v1/messages"], ["/v1/messages/count_tokens", "/v1/messages/count_tokens"]]);
|
|
101
|
+
/** Other listeners retain their own endpoint diagnostics. */
|
|
102
|
+
export function messagesUnknownEndpointMessage(req: Request): string {
|
|
103
|
+
const path = new URL(req.url).pathname;
|
|
104
|
+
const localPath = MESSAGES_PATH.get(path);
|
|
105
|
+
return localPath ? `Unknown endpoint: ${METHOD.get(req.method) ?? "unsupported"} ${localPath}`
|
|
106
|
+
: `Unknown endpoint: ${req.method} ${path}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Surface projection uses construction metadata; shared producer bodies retain their own wire. */
|
|
110
|
+
const FIXED_MESSAGES: ReadonlyMap<ProxyErrorPresentation, string> = new Map([
|
|
111
|
+
["roster", "The selected Google Antigravity account does not list the requested model. Choose a model your accounts list, select an account with access, or review account failover settings before retrying."],
|
|
112
|
+
["pacing", "The provider request queue is full or has expired. Wait for queued requests to finish, then retry."],
|
|
113
|
+
["input", "The input exceeds the configured admission limit. Start a new session or choose a model with a larger input limit."],
|
|
114
|
+
["outbound", "The provider request body exceeds the configured limit. Reduce the request size before retrying."],
|
|
115
|
+
["inbound", "The request body exceeds the configured limit. Reduce the request size before retrying."],
|
|
116
|
+
["send", "request send budget exhausted before dispatch"],
|
|
117
|
+
["cooldown", "The selected Codex account is cooling down. Run 'ocx account list openai' to find the id, then 'ocx account clear-cooldown openai <id>' to lift it, or switch accounts with 'ocx account use openai <id>'."],
|
|
118
|
+
["cooldown_pinned", "The selected Codex account is cooling down. This request is pinned to that selector and will not switch accounts; choose another account-qualified model or retry later."],
|
|
119
|
+
["hard_lock", "Codex main account is blocked by the main-account quota policy. Choose another account, wait for quota to reset, or disable codexMainAccountHardLock in Settings."],
|
|
120
|
+
["recovery", "The selected Codex account is held after repeated upstream failures and the pool's recovery budget for this window is spent, so nothing was sent upstream. Retry later. This clears on its own as the account recovers; no cooldown to lift and no account to switch."],
|
|
121
|
+
["usage", "The configured account usage limit was reached. Wait for its reset or adjust the usage limits before retrying."],
|
|
122
|
+
["model_availability", "The requested model is unavailable for the selected account. Choose a supported model or retry when it becomes available."],
|
|
123
|
+
["oauth_login", "The configured provider needs sign-in. Run ocx login for that provider, then retry."],
|
|
124
|
+
["discovery", "Antigravity login could not discover a Cloud Code Assist project for this account. Ensure the account has Antigravity/Cloud Code Assist access and try again."],
|
|
125
|
+
["muse_http", "The Muse Code credential was rejected by the Meta Model API. Renew it with `muse login` or copy it again from https://dev.meta.ai, then retry."],
|
|
126
|
+
["config", "The configured OAuth provider is unsupported. Remove or reconfigure the provider in the OpenCodex configuration."],
|
|
127
|
+
["workflow", "The configured token ceiling is spent, so this send was refused before contacting a provider. Review the task, account and pool spending limits to grant more."],
|
|
128
|
+
["workflow_unbound", "The configured token ceiling is spent, including unassigned provider-pool history. Resolve verified pool mappings or adjust the spending limits before retrying."],
|
|
129
|
+
["scope", "The requested model is not allowed for this API key."],
|
|
130
|
+
["body_stall", "anthropic passthrough body stalled: no upstream bytes arrived before the configured timeout"],
|
|
131
|
+
["body_overflow", "anthropic passthrough body exceeded the safe limit"],
|
|
132
|
+
["combo", "No available targets for combo; review target availability, quota and cooldowns before retrying."],
|
|
133
|
+
["pool_refresh", "Codex credential refresh did not complete for the selected Codex pool account; retry this request. If it keeps failing, sign in to that account again."],
|
|
134
|
+
["copilot", "GitHub Copilot Auto negotiation failed; retry or check your Copilot account permissions."],
|
|
135
|
+
]);
|
|
136
|
+
const LOCAL_CODES: ReadonlyMap<string, ProxyErrorPresentation> = new Map([
|
|
137
|
+
["request_send_budget_exhausted", "send"], ["send_budget_exhausted", "send"], ["model_not_allowed_for_key", "scope"],
|
|
138
|
+
]);
|
|
139
|
+
function fixedLocalMessage(local: object, code?: string, type?: string): string | undefined {
|
|
140
|
+
const kind = proxyErrorPresentation(local) ?? LOCAL_CODES.get(code ?? "") ?? LOCAL_CODES.get(type ?? "");
|
|
141
|
+
return kind === undefined ? undefined : FIXED_MESSAGES.get(kind);
|
|
142
|
+
}
|
|
143
|
+
function isMessagesRequest(req: Request): boolean {
|
|
144
|
+
const path = new URL(req.url).pathname;
|
|
145
|
+
return path === "/v1/messages" || path === "/v1/messages/count_tokens";
|
|
146
|
+
}
|
|
147
|
+
export async function normalizeMessagesProxyRefusal(req: Request, response: Response): Promise<Response> {
|
|
148
|
+
if (!isMessagesRequest(req) || response.ok || !isProxyError(response)) return response;
|
|
149
|
+
const kind = proxyErrorPresentation(response);
|
|
150
|
+
if (kind === undefined) return response;
|
|
151
|
+
const message = FIXED_MESSAGES.get(kind);
|
|
152
|
+
if (message === undefined) throw new Error("Unknown local Messages presentation");
|
|
153
|
+
const original = await response.clone().json() as Rec;
|
|
154
|
+
const error = original.error as Rec;
|
|
155
|
+
const next = { ...error, message: messagesOverflowPresentation(error.message) ? CLAUDE_CONTEXT_OVERFLOW_MESSAGE : message };
|
|
156
|
+
if (kind === "scope") delete (next as Rec).model;
|
|
157
|
+
const headers = new Headers(response.headers); headers.delete("content-length");
|
|
158
|
+
const out = carryProxyError(response, carryReplayRefusal(response, new Response(JSON.stringify({ ...original, error: next }), { status: response.status, headers })));
|
|
159
|
+
if (isNonReplayableResponse(response)) markResponseNonReplayable(out);
|
|
160
|
+
const evidence = comboFailureEvidence(response);
|
|
161
|
+
return evidence === undefined ? out : attachComboFailureEvidence(out, evidence);
|
|
162
|
+
}
|