@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
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clientFacingModelText } from "../../lib/error-destination";
|
|
1
2
|
import { createAnthropicThinkingRecovery } from "./anthropic-thinking-recovery";
|
|
2
3
|
import { rotateAnthropicAccountOnResponseForInstance } from "../../oauth/anthropic-account-refusal";
|
|
3
4
|
import type { ResponsesRequestContext } from "./core-options";
|
|
@@ -33,10 +34,10 @@ import {
|
|
|
33
34
|
failoverAccountSnapshot,
|
|
34
35
|
} from "../../oauth/generic-account-failover";
|
|
35
36
|
import { classifyKiroRefusal } from "../../adapters/kiro-refusal";
|
|
36
|
-
import { isNonReplayableResponse, SendBudgetExhaustedError } from "../../lib/upstream-retry";
|
|
37
|
+
import { isNonReplayableResponse, SendBudgetExhaustedError, errorDestinationLabel } from "../../lib/upstream-retry";
|
|
37
38
|
import { isVerifiedModelNotInPlanResponse, markVerifiedModelNotInPlanResponse } from "../../lib/errors";
|
|
38
39
|
import { unwrapUpstreamRetryEvidenceError } from "../../codex/auth-context";
|
|
39
|
-
import { AdmissionModelDeniedError, admissionModelDeniedResponse } from "../admission-model-scope";
|
|
40
|
+
import { AdmissionModelDeniedError, admissionModelDeniedResponse, projectAdmissionModelDeniedLog } from "../admission-model-scope";
|
|
40
41
|
import { noteKiroMonthlyRefusal, noteKiroServedSuccess } from "../../providers/kiro-usage";
|
|
41
42
|
import { persistKiroAccountState } from "../../providers/kiro-account-state-disk";
|
|
42
43
|
import { anthropicPoolCooldownResponse, readDisplaySafeErrorText } from "./core-errors";
|
|
@@ -48,7 +49,7 @@ import {
|
|
|
48
49
|
} from "../../oauth/anthropic-routing";
|
|
49
50
|
import { resolveWireProtocolOverride } from "../adapter-resolve";
|
|
50
51
|
import { bindRouteReasoningReplayScope, adapterNeedsForcedContinuation, adapterNeedsToolCallContinuation } from "./core-replay";
|
|
51
|
-
import { namespacedToolName } from "../../types";
|
|
52
|
+
import { namespacedToolName, toolChoiceToolPredicate } from "../../types";
|
|
52
53
|
import { providerFetch } from "./fetch-helpers";
|
|
53
54
|
import type { AttemptRecoveryKind } from "../../usage/log";
|
|
54
55
|
import { recordAdapterReasoning, recordAdapterTier } from "../request-log";
|
|
@@ -248,7 +249,7 @@ export async function executeResponsesSidecars(
|
|
|
248
249
|
if (!sidecarScopeDenial || response.ok) return undefined;
|
|
249
250
|
void response.body?.cancel().catch(() => {});
|
|
250
251
|
releaseSearchProbeLease();
|
|
251
|
-
return admissionModelDeniedResponse(sidecarScopeDenial);
|
|
252
|
+
return admissionModelDeniedResponse(projectAdmissionModelDeniedLog(sidecarScopeDenial, logCtx));
|
|
252
253
|
};
|
|
253
254
|
/** Admit a replacement credential, or leave the loop's original refusal authoritative. */
|
|
254
255
|
const rotateSidecarProviderOn429 = async (
|
|
@@ -471,7 +472,7 @@ export async function executeResponsesSidecars(
|
|
|
471
472
|
options.abortSignal ?? new AbortController().signal, { attempted: false },
|
|
472
473
|
() => !sendBudgetState.sendBudgetExhausted()
|
|
473
474
|
&& !!sendBudgetState.adapterDispatchBudget
|
|
474
|
-
&& sendBudgetState.adapterDispatchBudget.spendEnforced !== true);
|
|
475
|
+
&& sendBudgetState.adapterDispatchBudget.spendEnforced !== true, logCtx);
|
|
475
476
|
const thinkingReceipt = (request: AdapterRequest, adapter: ProviderAdapter, recovery?: AttemptRecoveryKind) =>
|
|
476
477
|
adapter.name !== "anthropic" ? {} : { onPhysicalDispatch: () => {
|
|
477
478
|
if (recovery === "opaque-blob-rejection") {
|
|
@@ -480,7 +481,7 @@ export async function executeResponsesSidecars(
|
|
|
480
481
|
});
|
|
481
482
|
if (sendBudgetState.adapterDispatchBudget?.spendEnforced || !decision?.allowed) {
|
|
482
483
|
if (decision?.allowed) decision.permit.release();
|
|
483
|
-
throw new SendBudgetExhaustedError(
|
|
484
|
+
throw new SendBudgetExhaustedError(errorDestinationLabel(request.url));
|
|
484
485
|
}
|
|
485
486
|
try { sendBudgetState.noteInitialDispatch(decision.permit); }
|
|
486
487
|
finally { decision.permit.release(); }
|
|
@@ -579,7 +580,7 @@ export async function executeResponsesSidecars(
|
|
|
579
580
|
? clampImageMaxRounds(config.images?.maxRounds)
|
|
580
581
|
: clampImageMaxRounds(config.images?.videoMaxRounds ?? 2),
|
|
581
582
|
connectTimeoutMs: config.connectTimeoutMs ?? 200_000,
|
|
582
|
-
stallTimeoutSec: config.stallTimeoutSec,
|
|
583
|
+
stallTimeoutSec: config.stallTimeoutSec, proxyErrorContext: logCtx,
|
|
583
584
|
waitForRequestSlot: imageProviderFetch.waitForPacing,
|
|
584
585
|
fetchImpl: imageProviderFetch.unpacedFetch ?? imageProviderFetch,
|
|
585
586
|
fetchForRequest: (request, iterParsed, adapter, recovery) => {
|
|
@@ -633,7 +634,7 @@ export async function executeResponsesSidecars(
|
|
|
633
634
|
if (imgScopeRefusal) return imgScopeRefusal;
|
|
634
635
|
// A provider overflow on the first iteration answers as the main path's context failure (#7316).
|
|
635
636
|
const imgResponse = options.comboAttempt ? imgLoopResponse : sidecarContextOverflowResponse(imgLoopResponse, {
|
|
636
|
-
stream: parsed.stream, modelId:
|
|
637
|
+
stream: parsed.stream, modelId: clientFacingModelText(options.clientModelLabel), translatorBudget,
|
|
637
638
|
});
|
|
638
639
|
if (imgResponse.body) {
|
|
639
640
|
const imgTurnAc = new AbortController();
|
|
@@ -657,12 +658,15 @@ export async function executeResponsesSidecars(
|
|
|
657
658
|
// Placed BEFORE the runTurn early-return for non-runTurn adapters so dual-tool turns dispatch
|
|
658
659
|
// through web-search instead of being swallowed. runTurn adapters never enter this branch.
|
|
659
660
|
if (canRunWebSearch && wsPlan) {
|
|
660
|
-
const
|
|
661
|
+
const requestedTools = parsed.context.tools ?? [];
|
|
662
|
+
const advisorAllowed = advisorPlan
|
|
663
|
+
&& toolChoiceToolPredicate(parsed.options.toolChoice, [...requestedTools, advisorPlan.tool])(advisorPlan.tool);
|
|
664
|
+
const webSearchAdvisor = advisorPlan && advisorAllowed && !routedCompaction
|
|
661
665
|
&& typeof advisorPlan.consult === "function" && typeof advisorPlan.formatUnavailable === "function"
|
|
662
666
|
? advisorPlan
|
|
663
667
|
: undefined;
|
|
664
668
|
parsed.context.tools = [
|
|
665
|
-
...
|
|
669
|
+
...requestedTools.filter(tool => !webSearchAdvisor || (!tool.advisor && tool.name !== ADVISOR_TOOL_NAME)),
|
|
666
670
|
buildWebSearchTool(),
|
|
667
671
|
...(webSearchAdvisor ? [webSearchAdvisor.tool] : []),
|
|
668
672
|
];
|
|
@@ -734,7 +738,7 @@ export async function executeResponsesSidecars(
|
|
|
734
738
|
beforeSidecarDispatch: wsPlan.forwardSidecar?.beforeDispatch,
|
|
735
739
|
connectTimeoutMs: config.connectTimeoutMs ?? 200_000,
|
|
736
740
|
routedModelStallTimeoutMs: wsPlan.routedModelStallTimeoutMs,
|
|
737
|
-
stallTimeoutSec: wsPlan.stallTimeoutSec,
|
|
741
|
+
stallTimeoutSec: wsPlan.stallTimeoutSec, proxyErrorContext: logCtx,
|
|
738
742
|
streamRoutedModelOutput: wsPlan.streamRoutedModelOutput,
|
|
739
743
|
on429: rotateSidecarProviderOn429,
|
|
740
744
|
onRotatedUsage: billRotatedUsage,
|
|
@@ -770,7 +774,7 @@ export async function executeResponsesSidecars(
|
|
|
770
774
|
const wsResponse = poolUsageLimit ? anthropicPoolCooldownResponse(poolUsageLimit, { logCtx })
|
|
771
775
|
: options.comboAttempt ? loopResponse
|
|
772
776
|
: sidecarContextOverflowResponse(loopResponse, {
|
|
773
|
-
stream: parsed.stream, modelId:
|
|
777
|
+
stream: parsed.stream, modelId: clientFacingModelText(options.clientModelLabel), translatorBudget,
|
|
774
778
|
});
|
|
775
779
|
// Register the sidecar stream as an active turn so drainAndShutdown waits for (or aborts)
|
|
776
780
|
// in-flight web-search turns instead of skipping them during graceful shutdown.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { markProxyError } from "../../lib/client-error-body";
|
|
1
2
|
import { formatErrorResponse } from "../../bridge";
|
|
2
3
|
import { SPEND_LEDGER_STORAGE_UNAVAILABLE_CODE } from "../../lib/errors";
|
|
3
4
|
import { markLocalRequestLogRefusal, type RequestLogContext } from "../request-log";
|
|
@@ -29,5 +30,5 @@ export function mapSpendLedgerStorageError(error: unknown, logCtx?: StorageRefus
|
|
|
29
30
|
|
|
30
31
|
export function spendLedgerStorageErrorResponse(error: unknown, logCtx?: StorageRefusalLog): Response | undefined {
|
|
31
32
|
const refusal = mapSpendLedgerStorageError(error, logCtx);
|
|
32
|
-
return refusal && formatErrorResponse(refusal.status, refusal.code, refusal.message);
|
|
33
|
+
return refusal && markProxyError(formatErrorResponse(refusal.status, refusal.code, refusal.message));
|
|
33
34
|
}
|
|
@@ -82,6 +82,27 @@ function recentTurnHasToolActivity(parsed: OcxParsedRequest): boolean {
|
|
|
82
82
|
return false;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Reports whether the current turn already executed tools: a tool call or tool result after the
|
|
87
|
+
* latest user message. A text-only plan announcement after the last tool activity means the turn
|
|
88
|
+
* stalled there, so it does not count, matching `recentTurnHasToolActivity`.
|
|
89
|
+
*/
|
|
90
|
+
function toolActivitySinceLatestUser(parsed: OcxParsedRequest): boolean {
|
|
91
|
+
for (let i = parsed.context.messages.length - 1; i >= 0; i -= 1) {
|
|
92
|
+
const message = parsed.context.messages[i];
|
|
93
|
+
if (message.role === "user") return false;
|
|
94
|
+
if (message.role === "toolResult") return true;
|
|
95
|
+
if (message.role !== "assistant") continue;
|
|
96
|
+
if (message.content.some(part => part.type === "toolCall")) return true;
|
|
97
|
+
const text = message.content
|
|
98
|
+
.filter(part => part.type === "text")
|
|
99
|
+
.map(part => part.text)
|
|
100
|
+
.join("");
|
|
101
|
+
if (PLAN_INTENT_RE.test(text)) return false;
|
|
102
|
+
}
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
85
106
|
function assistantText(events: readonly AdapterEvent[]): string {
|
|
86
107
|
return events
|
|
87
108
|
.filter((event): event is Extract<AdapterEvent, { type: "text_delta" }> => event.type === "text_delta")
|
|
@@ -89,6 +110,12 @@ function assistantText(events: readonly AdapterEvent[]): string {
|
|
|
89
110
|
.join("");
|
|
90
111
|
}
|
|
91
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Classifies a finished upstream turn that made no tool call. `continue` means the model only
|
|
115
|
+
* announced work for an actionable request, so the relay re-asks it with `TERMINAL_GUARD_NUDGE`.
|
|
116
|
+
* A completion summary after tool activity in the same turn passes; a renewed first-person plan
|
|
117
|
+
* announcement (`PLAN_INTENT_RE`) after that activity is still continued.
|
|
118
|
+
*/
|
|
92
119
|
export function analyzeTerminalTurn(parsed: OcxParsedRequest, events: readonly AdapterEvent[]): TerminalTurnAnalysis {
|
|
93
120
|
const userText = latestUserText(parsed);
|
|
94
121
|
const text = assistantText(events);
|
|
@@ -105,6 +132,9 @@ export function analyzeTerminalTurn(parsed: OcxParsedRequest, events: readonly A
|
|
|
105
132
|
if (PLAN_ONLY_REQUEST_RE.test(userText)) {
|
|
106
133
|
return { decision: "pass", reason: "no_actionable_request", assistantText: text, userText, hasToolCall };
|
|
107
134
|
}
|
|
135
|
+
if (toolActivitySinceLatestUser(parsed) && !PLAN_INTENT_RE.test(text)) {
|
|
136
|
+
return { decision: "pass", reason: "recent_tool_activity", assistantText: text, userText, hasToolCall };
|
|
137
|
+
}
|
|
108
138
|
if (EXPLICIT_CONTINUE_RE.test(userText) && recentTurnHasToolActivity(parsed)) {
|
|
109
139
|
return { decision: "pass", reason: "recent_tool_activity", assistantText: text, userText, hasToolCall };
|
|
110
140
|
}
|
|
@@ -21,6 +21,7 @@ import { resolveProxyRoute, socks5ProxyFromEnv } from "../../lib/proxy-env";
|
|
|
21
21
|
import type { CodexWsQuotaObserver } from "./codex-ws-metadata";
|
|
22
22
|
import { CODEX_RESPONSES_HTTP_URL, CODEX_RESPONSES_WS_URL, CODEX_WS_FRAME_HEADERS, prepareCodexHttpInit, prepareCodexWsRequest } from "./codex-ws-request";
|
|
23
23
|
import { codexWsExchange } from "./codex-ws-exchange";
|
|
24
|
+
import { TURN_STATE_BINDING_INIT } from "../turn-state-handles";
|
|
24
25
|
import { CodexWsSession } from "./codex-ws-session";
|
|
25
26
|
import { codexWsPool, codexWsReuseIdentity } from "./codex-ws-pool";
|
|
26
27
|
import { codexWsCreateFrameExceedsLimit, type CodexWsPreOutputRefusalHold } from "./codex-ws-wire";
|
|
@@ -252,5 +253,13 @@ export async function codexWsUpstreamFetch(
|
|
|
252
253
|
beforeContinuation, onPhysicalDispatch,
|
|
253
254
|
preOutputRefusalHold,
|
|
254
255
|
bunVersion: typeof runtime === "string" ? runtime : runtime.version,
|
|
256
|
+
metadataContext: codexWsMetadataContext(init, prepared.model),
|
|
255
257
|
});
|
|
256
258
|
}
|
|
259
|
+
|
|
260
|
+
/** The binding the provider fetch attached to this send, and the requested model, for relayed metadata. */
|
|
261
|
+
function codexWsMetadataContext(init: RequestInit, model: string | undefined): { turnStateBinding?: string; knownModels: string[]; provider: string } {
|
|
262
|
+
const binding = (init as Record<symbol, unknown>)[TURN_STATE_BINDING_INIT];
|
|
263
|
+
// This upstream is the ChatGPT Codex backend, so its bundled model catalog also counts as known.
|
|
264
|
+
return { ...(typeof binding === "string" ? { turnStateBinding: binding } : {}), knownModels: model ? [model] : [], provider: "openai-codex" };
|
|
265
|
+
}
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from "../responses/apply-patch-envelope";
|
|
7
7
|
import { compileCodeModeHelperInput, resolveCodeModeHelperName } from "../responses/code-mode-helper-compat";
|
|
8
8
|
import { mayBecomeCodeModeShellInput } from "../responses/code-mode-shell-input";
|
|
9
|
-
import {
|
|
9
|
+
import { ProgressiveFreeformInputReader } from "../responses/progressive-freeform-input";
|
|
10
10
|
import { declaresCodeModeExec } from "../types/tools";
|
|
11
11
|
import {
|
|
12
12
|
customToolItemId,
|
|
@@ -41,9 +41,12 @@ function replaceSseEventName(block: string, type: string): string {
|
|
|
41
41
|
|
|
42
42
|
type OpenCustomCall = {
|
|
43
43
|
argumentsText: string;
|
|
44
|
+
argumentsTail: string;
|
|
44
45
|
emittedInput: string;
|
|
45
46
|
canonicalPatchProgress: boolean;
|
|
46
47
|
retainedBytes: number;
|
|
48
|
+
// Resumes across deltas so the growing arguments are decoded once rather than once per delta.
|
|
49
|
+
freeformReader?: ProgressiveFreeformInputReader;
|
|
47
50
|
};
|
|
48
51
|
|
|
49
52
|
export class RoutedCustomToolProgressError extends Error {
|
|
@@ -77,6 +80,7 @@ export function createRoutedCustomToolRestoreBlockRewrite(
|
|
|
77
80
|
|
|
78
81
|
const emptyOpenCall = (): OpenCustomCall => ({
|
|
79
82
|
argumentsText: "",
|
|
83
|
+
argumentsTail: "",
|
|
80
84
|
emittedInput: "",
|
|
81
85
|
canonicalPatchProgress: false,
|
|
82
86
|
retainedBytes: 0,
|
|
@@ -282,6 +286,7 @@ export function createRoutedCustomToolRestoreBlockRewrite(
|
|
|
282
286
|
const deltaBytes = Buffer.byteLength(delta, "utf8");
|
|
283
287
|
if (deltaBytes > 0) budget?.chargeRetained(deltaBytes, { kind: "retained_collectors" });
|
|
284
288
|
open.argumentsText += delta;
|
|
289
|
+
open.argumentsTail = (open.argumentsTail + delta).slice(-64);
|
|
285
290
|
open.retainedBytes += deltaBytes;
|
|
286
291
|
openCalls.set(upstreamItemId, open);
|
|
287
292
|
if (customExecItemNames.get(upstreamItemId) !== "exec"
|
|
@@ -341,6 +346,7 @@ export function createRoutedCustomToolRestoreBlockRewrite(
|
|
|
341
346
|
const deltaBytes = Buffer.byteLength(delta, "utf8");
|
|
342
347
|
if (deltaBytes > 0) budget?.chargeRetained(deltaBytes, { kind: "retained_collectors" });
|
|
343
348
|
open.argumentsText += delta;
|
|
349
|
+
open.argumentsTail = (open.argumentsTail + delta).slice(-64);
|
|
344
350
|
open.retainedBytes += deltaBytes;
|
|
345
351
|
openCalls.set(upstreamItemId, open);
|
|
346
352
|
// A helper alias will become JavaScript at completion, never raw patch/JSON.
|
|
@@ -348,7 +354,8 @@ export function createRoutedCustomToolRestoreBlockRewrite(
|
|
|
348
354
|
const itemName = itemNames.get(upstreamItemId);
|
|
349
355
|
const ownsFreeformGrammar = itemName?.namespace === undefined
|
|
350
356
|
|| itemName?.namespace === "functions";
|
|
351
|
-
|
|
357
|
+
open.freeformReader ??= new ProgressiveFreeformInputReader();
|
|
358
|
+
const fullInput = open.freeformReader.update(
|
|
352
359
|
open.argumentsText,
|
|
353
360
|
ownsFreeformGrammar ? itemName?.name ?? "" : "",
|
|
354
361
|
);
|
|
@@ -374,7 +381,11 @@ export function createRoutedCustomToolRestoreBlockRewrite(
|
|
|
374
381
|
if (mayCompile && mayBecomePatchEnvelope(fullInput)) return [];
|
|
375
382
|
let streamInput = fullInput;
|
|
376
383
|
if (mayNormalize && mayBecomePatchEnvelope(fullInput)) {
|
|
377
|
-
const stablePrefix = stableCanonicalPatchPrefix(
|
|
384
|
+
const stablePrefix = stableCanonicalPatchPrefix(
|
|
385
|
+
fullInput,
|
|
386
|
+
fullInput === open.argumentsText ? open.argumentsTail : fullInput.slice(-64),
|
|
387
|
+
open.canonicalPatchProgress,
|
|
388
|
+
);
|
|
378
389
|
if (stablePrefix === null) return [];
|
|
379
390
|
streamInput = stablePrefix;
|
|
380
391
|
if (stablePrefix.length > 0) open.canonicalPatchProgress = true;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rememberProxyIncomplete, carryProxyIncompleteContext } from "../lib/client-error-body";
|
|
1
2
|
import type { TranslatorBudget } from "../lib/translator-budget";
|
|
2
3
|
import type { ResponsesTerminalRepairPolicy } from "../providers/registry";
|
|
3
4
|
import { nextSseBlock, sseDataPayload } from "./sse-payload-rewrite";
|
|
@@ -80,6 +81,7 @@ export function relayResponsesSseWithTerminalRepair(
|
|
|
80
81
|
policy: ResponsesTerminalRepairPolicy,
|
|
81
82
|
budget: TranslatorBudget,
|
|
82
83
|
scheduler: ResponsesTerminalRepairScheduler = systemScheduler,
|
|
84
|
+
proxyErrorContext: object = {},
|
|
83
85
|
): ReadableStream<Uint8Array> {
|
|
84
86
|
const reader = body.getReader();
|
|
85
87
|
const decoder = new TextDecoder();
|
|
@@ -191,6 +193,7 @@ export function relayResponsesSseWithTerminalRepair(
|
|
|
191
193
|
? { incomplete_details: { reason: "missing_terminal_event" } }
|
|
192
194
|
: {}),
|
|
193
195
|
};
|
|
196
|
+
if (kind === "incomplete") rememberProxyIncomplete(proxyErrorContext, "missing_terminal_event");
|
|
194
197
|
const type = `response.${kind}`;
|
|
195
198
|
return encoder.encode(`event: ${type}\ndata: ${JSON.stringify({
|
|
196
199
|
type,
|
|
@@ -351,7 +354,7 @@ export function relayResponsesSseWithTerminalRepair(
|
|
|
351
354
|
}
|
|
352
355
|
};
|
|
353
356
|
|
|
354
|
-
return new ReadableStream<Uint8Array>({
|
|
357
|
+
return carryProxyIncompleteContext(proxyErrorContext, new ReadableStream<Uint8Array>({
|
|
355
358
|
start(controller) {
|
|
356
359
|
controllerRef = controller;
|
|
357
360
|
if (upstream.signal.aborted) {
|
|
@@ -372,5 +375,5 @@ export function relayResponsesSseWithTerminalRepair(
|
|
|
372
375
|
upstream.abort(reason);
|
|
373
376
|
return reader.cancel(reason);
|
|
374
377
|
},
|
|
375
|
-
});
|
|
378
|
+
}));
|
|
376
379
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { UNDECLARED_TOOL_CALL_MESSAGE } from "../lib/client-error-body";
|
|
1
2
|
import { UNDECLARED_TOOL_CALL_ERROR_CODE } from "../lib/errors";
|
|
2
3
|
import { hasItemProvenance, isHistoricalItem } from "../responses/item-provenance";
|
|
3
4
|
import {
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
13
14
|
normalizeDeclaredToolName,
|
|
14
15
|
} from "../types";
|
|
15
16
|
import { replaceSseDataPayload, sseDataPayload, type SseBlockRewrite } from "./sse-payload-rewrite";
|
|
17
|
+
import { TOOL_SEARCH_FUNCTION_NAME } from "../responses/tool-search-compat";
|
|
16
18
|
|
|
17
19
|
/** Item types the client executes through a request-declared wire name. */
|
|
18
20
|
export const CLIENT_EXECUTED_CALL_TYPES: ReadonlySet<string> = new Set([
|
|
@@ -77,9 +79,6 @@ const NAMELESS_TOOL_SPEC_TYPES = new Set([
|
|
|
77
79
|
"x_search",
|
|
78
80
|
]);
|
|
79
81
|
|
|
80
|
-
/** An upstream-supplied name reaches the error message; keep it bounded. */
|
|
81
|
-
const MAX_REPORTED_NAME_CHARS = 100;
|
|
82
|
-
|
|
83
82
|
export { UNDECLARED_TOOL_CALL_ERROR_CODE };
|
|
84
83
|
|
|
85
84
|
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
@@ -91,6 +90,7 @@ function addWireToolName(
|
|
|
91
90
|
tool: unknown,
|
|
92
91
|
namespace?: string,
|
|
93
92
|
ambiguousDottedAliases?: ReadonlySet<string>,
|
|
93
|
+
canonicalOnly = false,
|
|
94
94
|
): void {
|
|
95
95
|
if (!isPlainObject(tool)) return;
|
|
96
96
|
const name = wireToolInnerName(tool);
|
|
@@ -103,6 +103,7 @@ function addWireToolName(
|
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
105
|
names.add(namespacedToolName(namespace, name));
|
|
106
|
+
if (canonicalOnly) return;
|
|
106
107
|
// Some routed providers echo the flattened wire name with a dot (`ns.name`, observed with
|
|
107
108
|
// muse-spark via opencode-go) instead of `ns__name`. It is the same tool identity, so register
|
|
108
109
|
// the dotted spelling too, mirroring `toolChoiceAliases` (#3402) -- but only while that
|
|
@@ -150,16 +151,17 @@ function addWireToolSpecs(
|
|
|
150
151
|
names: Set<string>,
|
|
151
152
|
specs: unknown,
|
|
152
153
|
ambiguousDottedAliases?: ReadonlySet<string>,
|
|
154
|
+
canonicalOnly = false,
|
|
153
155
|
): void {
|
|
154
156
|
if (!Array.isArray(specs)) return;
|
|
155
157
|
for (const spec of specs) {
|
|
156
158
|
if (!isPlainObject(spec)) continue;
|
|
157
159
|
if (spec.type === "namespace" && Array.isArray(spec.tools)) {
|
|
158
160
|
const namespace = typeof spec.name === "string" ? spec.name : undefined;
|
|
159
|
-
for (const inner of spec.tools) addWireToolName(names, inner, namespace, ambiguousDottedAliases);
|
|
161
|
+
for (const inner of spec.tools) addWireToolName(names, inner, namespace, ambiguousDottedAliases, canonicalOnly);
|
|
160
162
|
continue;
|
|
161
163
|
}
|
|
162
|
-
addWireToolName(names, spec, undefined, ambiguousDottedAliases);
|
|
164
|
+
addWireToolName(names, spec, undefined, ambiguousDottedAliases, canonicalOnly);
|
|
163
165
|
}
|
|
164
166
|
}
|
|
165
167
|
|
|
@@ -171,7 +173,7 @@ function addWireToolSpecs(
|
|
|
171
173
|
* inside `input`, routed custom-tool rewrites) that the internal list flattens or renames, and
|
|
172
174
|
* only the wire names can be compared against what the provider echoes back.
|
|
173
175
|
*/
|
|
174
|
-
export function collectDeclaredWireToolNames(body: unknown): Set<string> {
|
|
176
|
+
export function collectDeclaredWireToolNames(body: unknown, options?: { canonicalOnly?: boolean }): Set<string> {
|
|
175
177
|
const names = new Set<string>();
|
|
176
178
|
if (!isPlainObject(body)) return names;
|
|
177
179
|
const specGroups: unknown[] = [body.tools];
|
|
@@ -184,7 +186,29 @@ export function collectDeclaredWireToolNames(body: unknown): Set<string> {
|
|
|
184
186
|
}
|
|
185
187
|
}
|
|
186
188
|
const ambiguousDottedAliases = collectAmbiguousDottedAliases(specGroups);
|
|
187
|
-
for (const specs of specGroups) addWireToolSpecs(names, specs, ambiguousDottedAliases);
|
|
189
|
+
for (const specs of specGroups) addWireToolSpecs(names, specs, ambiguousDottedAliases, options?.canonicalOnly);
|
|
190
|
+
return names;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Function names that translated adapters give to nameless hosted declarations in this catalog.
|
|
195
|
+
* The parser exposes a declared `{type:"tool_search"}` to Chat-style providers as the function
|
|
196
|
+
* `tool_search`, so only a declaration present in this (current-turn) body authorizes that name.
|
|
197
|
+
*/
|
|
198
|
+
export function collectTranslatedHostedToolNames(body: unknown): Set<string> {
|
|
199
|
+
const names = new Set<string>();
|
|
200
|
+
if (!isPlainObject(body)) return names;
|
|
201
|
+
const specGroups: unknown[] = [body.tools];
|
|
202
|
+
if (Array.isArray(body.input)) {
|
|
203
|
+
for (const item of body.input) {
|
|
204
|
+
if (isPlainObject(item) && item.type === "additional_tools") specGroups.push(item.tools);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
for (const specs of specGroups) {
|
|
208
|
+
if (Array.isArray(specs) && specs.some(spec => isPlainObject(spec) && spec.type === "tool_search")) {
|
|
209
|
+
names.add(TOOL_SEARCH_FUNCTION_NAME);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
188
212
|
return names;
|
|
189
213
|
}
|
|
190
214
|
|
|
@@ -519,12 +543,10 @@ export function undeclaredToolCallNameInResponse(
|
|
|
519
543
|
/**
|
|
520
544
|
* Formats an error message indicating that a routed provider emitted an undeclared tool call.
|
|
521
545
|
*
|
|
522
|
-
* @param name - The undeclared tool name emitted by the provider.
|
|
523
546
|
* @returns A formatted error message string.
|
|
524
547
|
*/
|
|
525
|
-
export function undeclaredToolCallMessage(
|
|
526
|
-
|
|
527
|
-
return `routed provider emitted undeclared client tool "${reported}"; only request-declared tools may be called`;
|
|
548
|
+
export function undeclaredToolCallMessage(): string {
|
|
549
|
+
return UNDECLARED_TOOL_CALL_MESSAGE;
|
|
528
550
|
}
|
|
529
551
|
|
|
530
552
|
/**
|
|
@@ -694,11 +716,11 @@ export function normalizeDefaultNamespaceInJson(
|
|
|
694
716
|
}
|
|
695
717
|
}
|
|
696
718
|
|
|
697
|
-
function failedBlocks(
|
|
719
|
+
function failedBlocks(newline: string): readonly string[] {
|
|
698
720
|
const failure = {
|
|
699
721
|
type: "upstream_error",
|
|
700
722
|
code: UNDECLARED_TOOL_CALL_ERROR_CODE,
|
|
701
|
-
message: undeclaredToolCallMessage(
|
|
723
|
+
message: undeclaredToolCallMessage(),
|
|
702
724
|
};
|
|
703
725
|
const payload = JSON.stringify({
|
|
704
726
|
type: "response.failed",
|
|
@@ -716,7 +738,7 @@ function failedBlocks(name: string, newline: string): readonly string[] {
|
|
|
716
738
|
* it has no top-level handler for — `apply_patch`, which under code mode exists only as a nested
|
|
717
739
|
* `tools.apply_patch(...)` helper inside `exec` — and the turn surfaced as a bare `aborted` with
|
|
718
740
|
* no output and no explanation. Replacing the offending event with an explicit `response.failed`
|
|
719
|
-
* turns that silent dead end into a compatibility error
|
|
741
|
+
* turns that silent dead end into a compatibility error describing the request catalog restriction.
|
|
720
742
|
*
|
|
721
743
|
* Everything after the trip is dropped so a later `response.completed` cannot contradict the
|
|
722
744
|
* terminal already sent. Non-JSON and non-item blocks pass through untouched.
|
|
@@ -734,7 +756,7 @@ export function createUndeclaredToolCallGuardBlockRewrite(
|
|
|
734
756
|
providerExecutedCallTypes: ProviderExecutedCallTypes = EMPTY_PROVIDER_EXECUTED_CALL_TYPES,
|
|
735
757
|
declaredBare?: ReadonlySet<string>,
|
|
736
758
|
declaredCustom?: ReadonlySet<string>,
|
|
737
|
-
options?: { refuseUndeclared?: boolean },
|
|
759
|
+
options?: { refuseUndeclared?: boolean; onRefusal?: (message: string) => void },
|
|
738
760
|
): SseBlockRewrite {
|
|
739
761
|
// Deferred-catalog wires (Chat/Anthropic) keep the default-namespace normalization — the
|
|
740
762
|
// client can only resolve the bare name it declared — while the refusal itself stays off.
|
|
@@ -754,7 +776,8 @@ export function createUndeclaredToolCallGuardBlockRewrite(
|
|
|
754
776
|
const name = undeclaredToolCallName(parsed, declared, declaredNamelessClientCallTypes, providerExecutedCallTypes, declaredBare, declaredCustom);
|
|
755
777
|
if (name !== undefined) {
|
|
756
778
|
tripped = true;
|
|
757
|
-
|
|
779
|
+
options?.onRefusal?.(undeclaredToolCallMessage());
|
|
780
|
+
return failedBlocks(block.includes("\r\n") ? "\r\n" : "\n");
|
|
758
781
|
}
|
|
759
782
|
}
|
|
760
783
|
const normalized = normalizeDefaultNamespaceInPayload(parsed, declared, declaredBare);
|
|
@@ -202,7 +202,9 @@ function openDefaultRestartHandoffLog(now: () => number): RestartHandoffLog | nu
|
|
|
202
202
|
const configDir = getConfigDir();
|
|
203
203
|
const path = restartHandoffLogPath(configDir);
|
|
204
204
|
// Owned like crash.log, so uninstall removes it with the rest of the config directory.
|
|
205
|
-
|
|
205
|
+
// The log is optional: a refused registration (uninstall in progress) skips it rather than
|
|
206
|
+
// creating a file uninstall does not know about.
|
|
207
|
+
try { recordOwnedConfigPath(configDir, path); } catch { return null; }
|
|
206
208
|
return openRestartHandoffLog(path, now);
|
|
207
209
|
}
|
|
208
210
|
|
|
@@ -1,23 +1,172 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { formatClientRetryAfter } from "../lib/client-retry-after";
|
|
2
|
+
import { knownModelIdentity } from "../lib/model-identity";
|
|
3
|
+
import { isLiveTurnStateHandle, issueTurnStateHandle } from "./turn-state-handles";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Upstream response headers a client may receive as response metadata (WebSocket frames, the
|
|
7
|
+
* WS-to-HTTP projection). Each name is listed explicitly and each value is validated or rebuilt
|
|
8
|
+
* against its contract; a value that does not fit is dropped. No value is copied: numbers and
|
|
9
|
+
* booleans are reformatted, a model header is kept only as a model id the proxy already knows for
|
|
10
|
+
* the request, and the turn-state token is replaced by a handle bound to the request. Request ids,
|
|
11
|
+
* the models etag and quota limit labels are not relayed.
|
|
12
|
+
*/
|
|
13
|
+
export type ResponseMetadataContext = {
|
|
14
|
+
/** Binding of the send that produced these headers; without one, a turn-state token is dropped. */
|
|
15
|
+
turnStateBinding?: string;
|
|
16
|
+
/** Model ids the request already names (requested and routed); the bundled catalog also counts. */
|
|
17
|
+
knownModels?: readonly string[];
|
|
18
|
+
/** Provider (or metadata vendor) whose bundled model catalog also counts as known. */
|
|
19
|
+
provider?: string;
|
|
20
|
+
};
|
|
21
|
+
type Normalize = (value: string, context: ResponseMetadataContext) => string | undefined;
|
|
22
|
+
|
|
23
|
+
const OPAQUE_TOKEN = /^[A-Za-z0-9._~+/=:-]{1,8192}$/;
|
|
24
|
+
const NUMBER = /^\d{1,15}(?:\.\d{1,6})?$/;
|
|
25
|
+
|
|
26
|
+
function bool(value: string): string | undefined {
|
|
27
|
+
const folded = value.trim().toLowerCase();
|
|
28
|
+
return folded === "true" || folded === "false" ? folded : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function parseNonNegative(value: string): number | undefined {
|
|
32
|
+
const trimmed = value.trim();
|
|
33
|
+
if (!NUMBER.test(trimmed)) return undefined;
|
|
34
|
+
const number = Number(trimmed);
|
|
35
|
+
return Number.isFinite(number) ? number : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A non-negative decimal rebuilt by this proxy (so "1e3", signs and padding never pass through). */
|
|
39
|
+
function decimal(max: number): Normalize {
|
|
40
|
+
return value => {
|
|
41
|
+
const number = parseNonNegative(value);
|
|
42
|
+
return number !== undefined && number <= max ? String(number) : undefined;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A non-negative integer formatted by this proxy: fractions round down, large values clamp to max. */
|
|
47
|
+
function count(max: number): Normalize {
|
|
48
|
+
return value => {
|
|
49
|
+
const number = parseNonNegative(value);
|
|
50
|
+
return number === undefined ? undefined : String(Math.min(Math.floor(number), max));
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A non-negative integer exact to the contract (an epoch or window length); anything else drops. */
|
|
55
|
+
function integer(max: number): Normalize {
|
|
56
|
+
return value => {
|
|
57
|
+
const trimmed = value.trim();
|
|
58
|
+
if (!/^\d{1,15}$/.test(trimmed)) return undefined;
|
|
59
|
+
const number = Number(trimmed);
|
|
60
|
+
return number <= max ? String(number) : undefined;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const DURATION_PART = /(\d{1,9}(?:\.\d{1,6})?)(h|ms|m|s)/gy;
|
|
65
|
+
const DURATION_UNIT_MS = new Map<string, number>([["h", 3_600_000], ["m", 60_000], ["s", 1_000], ["ms", 1]]);
|
|
66
|
+
const MAX_RESET_MS = 8 * 24 * 60 * 60 * 1000;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A rate-limit reset: plain seconds, or a Go-style duration ("6m0s", "20ms"). Both are rebuilt from
|
|
70
|
+
* whole units — seconds round up, sub-second durations become whole milliseconds — and clamp to 8 days.
|
|
71
|
+
*/
|
|
72
|
+
function resetDuration(value: string): string | undefined {
|
|
73
|
+
const trimmed = value.trim();
|
|
74
|
+
const seconds = parseNonNegative(trimmed);
|
|
75
|
+
if (seconds !== undefined) return String(Math.min(Math.ceil(seconds), MAX_RESET_MS / 1000));
|
|
76
|
+
if (!trimmed || trimmed.length > 64) return undefined;
|
|
77
|
+
let ms = 0;
|
|
78
|
+
let offset = 0;
|
|
79
|
+
DURATION_PART.lastIndex = 0;
|
|
80
|
+
for (let match = DURATION_PART.exec(trimmed); match; match = DURATION_PART.exec(trimmed)) {
|
|
81
|
+
ms += Number(match[1]) * DURATION_UNIT_MS.get(match[2]!)!;
|
|
82
|
+
offset = DURATION_PART.lastIndex;
|
|
83
|
+
}
|
|
84
|
+
if (offset === 0 || offset !== trimmed.length || !Number.isFinite(ms)) return undefined;
|
|
85
|
+
const clamped = Math.min(ms, MAX_RESET_MS);
|
|
86
|
+
if (clamped < 1000) return `${Math.ceil(clamped)}ms`;
|
|
87
|
+
const whole = Math.ceil(clamped / 1000);
|
|
88
|
+
const hours = Math.floor(whole / 3600);
|
|
89
|
+
const minutes = Math.floor((whole % 3600) / 60);
|
|
90
|
+
const secs = whole % 60;
|
|
91
|
+
return `${hours ? `${hours}h` : ""}${hours || minutes ? `${minutes}m` : ""}${secs}s`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const COUNT = count(1e12);
|
|
95
|
+
|
|
96
|
+
// A Map, so a header named after an Object.prototype member ("constructor", "__proto__",
|
|
97
|
+
// "toString") can never resolve to an inherited value.
|
|
98
|
+
const EXACT: ReadonlyMap<string, Normalize> = new Map<string, Normalize>([
|
|
99
|
+
["retry-after", value => formatClientRetryAfter(value)],
|
|
100
|
+
// Codex echoes the turn-state token on later requests of the turn; it receives a handle bound to
|
|
101
|
+
// this send, which src/server/turn-state-handles.ts maps back only for a send with the same binding.
|
|
102
|
+
["x-codex-turn-state", (value, context) => !OPAQUE_TOKEN.test(value) ? undefined
|
|
103
|
+
: isLiveTurnStateHandle(value) ? value
|
|
104
|
+
: context.turnStateBinding ? issueTurnStateHandle(value, context.turnStateBinding) : undefined],
|
|
105
|
+
["openai-model", (value, context) => knownModelIdentity(value, context.knownModels, context.provider)],
|
|
106
|
+
["x-codex-safety-buffering-faster-model", (value, context) => knownModelIdentity(value, context.knownModels, context.provider)],
|
|
107
|
+
["x-reasoning-included", bool],
|
|
108
|
+
["x-codex-credits-has-credits", bool],
|
|
109
|
+
["x-codex-credits-unlimited", bool],
|
|
110
|
+
["x-codex-credits-balance", decimal(1e12)],
|
|
111
|
+
["x-codex-safety-buffering-enabled", bool],
|
|
112
|
+
["x-ratelimit-limit", COUNT],
|
|
113
|
+
["x-ratelimit-remaining", COUNT],
|
|
114
|
+
["x-ratelimit-reset", resetDuration],
|
|
115
|
+
["x-ratelimit-limit-requests", COUNT],
|
|
116
|
+
["x-ratelimit-limit-tokens", COUNT],
|
|
117
|
+
["x-ratelimit-remaining-requests", COUNT],
|
|
118
|
+
["x-ratelimit-remaining-tokens", COUNT],
|
|
119
|
+
["x-ratelimit-reset-requests", resetDuration],
|
|
120
|
+
["x-ratelimit-reset-tokens", resetDuration],
|
|
121
|
+
["x-ratelimit-limit-req-minute", COUNT],
|
|
122
|
+
["x-ratelimit-remaining-req-minute", COUNT],
|
|
123
|
+
["x-ratelimit-limit-tokens-minute", COUNT],
|
|
124
|
+
["x-ratelimit-remaining-tokens-minute", COUNT],
|
|
125
|
+
["x-ratelimit-limit-tokens-month", COUNT],
|
|
126
|
+
["x-ratelimit-remaining-tokens-month", COUNT],
|
|
127
|
+
["x-ratelimit-tokens-query-cost", COUNT],
|
|
6
128
|
]);
|
|
7
129
|
|
|
8
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* Codex quota limit families this proxy relays: the ordinary windows (`x-codex-primary-...`) and the
|
|
132
|
+
* metered `bengalfox` family (`x-codex-bengalfox-primary-...`, native `codex_bengalfox`). A header
|
|
133
|
+
* name is upstream text too, so any other family is dropped rather than echoed.
|
|
134
|
+
*/
|
|
135
|
+
export const CODEX_QUOTA_FAMILIES = ["bengalfox"] as const;
|
|
136
|
+
const QUOTA_WINDOW = new RegExp(`^x-codex(?:-(?:${CODEX_QUOTA_FAMILIES.join("|")}))?-(?:primary|secondary|tertiary)-(used-percent|window-minutes|reset-at)$`);
|
|
137
|
+
const QUOTA_VALUE: ReadonlyMap<string, Normalize> = new Map<string, Normalize>([
|
|
138
|
+
["used-percent", decimal(100)],
|
|
139
|
+
["window-minutes", integer(1e7)],
|
|
140
|
+
["reset-at", integer(1e11)],
|
|
141
|
+
]);
|
|
142
|
+
|
|
143
|
+
function normalizer(lower: string): Normalize | undefined {
|
|
144
|
+
if (lower.length > 96) return undefined;
|
|
145
|
+
const exact = EXACT.get(lower);
|
|
146
|
+
if (exact) return exact;
|
|
147
|
+
const window = QUOTA_WINDOW.exec(lower);
|
|
148
|
+
if (window) return QUOTA_VALUE.get(window[1]!);
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** True for a header name this proxy may relay as response metadata. */
|
|
9
153
|
export function isSafeResponseHeader(name: string): boolean {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
154
|
+
return typeof name === "string" && normalizer(name.toLowerCase()) !== undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The value this proxy relays for an allowlisted header, rebuilt or validated; undefined drops it. */
|
|
158
|
+
export function normalizeSafeResponseHeader(name: string, value: string, context: ResponseMetadataContext = {}): string | undefined {
|
|
159
|
+
if (typeof name !== "string" || typeof value !== "string") return undefined;
|
|
160
|
+
const normalize = normalizer(name.toLowerCase());
|
|
161
|
+
const normalized = normalize?.(value, context);
|
|
162
|
+
return typeof normalized === "string" ? normalized : undefined;
|
|
15
163
|
}
|
|
16
164
|
|
|
17
|
-
export function safeResponseHeaders(headers: Headers): Record<string, string> {
|
|
165
|
+
export function safeResponseHeaders(headers: Headers, context: ResponseMetadataContext = {}): Record<string, string> {
|
|
18
166
|
const out: Record<string, string> = {};
|
|
19
167
|
for (const [name, value] of headers) {
|
|
20
|
-
|
|
168
|
+
const normalized = normalizeSafeResponseHeader(name, value, context);
|
|
169
|
+
if (normalized !== undefined) out[name.toLowerCase()] = normalized;
|
|
21
170
|
}
|
|
22
171
|
return out;
|
|
23
172
|
}
|