@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,5 +1,10 @@
|
|
|
1
1
|
import { freeformFallbackKeys } from "./apply-patch-envelope";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
JSON_ESCAPES,
|
|
4
|
+
JSON_WHITESPACE,
|
|
5
|
+
MAX_FREEFORM_WRAPPER_SCAN_CHARS,
|
|
6
|
+
scanFreeformWrapper,
|
|
7
|
+
} from "./freeform-wrapper-scan";
|
|
3
8
|
|
|
4
9
|
/**
|
|
5
10
|
* Whether a body could still grow into one complete outer Markdown fence.
|
|
@@ -18,66 +23,291 @@ function mayBecomeFencedBody(text: string, toolName: string): boolean {
|
|
|
18
23
|
}
|
|
19
24
|
|
|
20
25
|
const LOW_SURROGATE_ESCAPE = /^\\u[dD][c-fC-F][0-9a-fA-F]{2}$/;
|
|
26
|
+
const HEX_DIGIT = /^[0-9a-fA-F]$/;
|
|
27
|
+
const HEX_QUAD = /^[0-9a-fA-F]{4}$/;
|
|
28
|
+
const JSON_NUMBER_CHAR = /^[-+0-9.eE]$/;
|
|
29
|
+
const JSON_NUMBER = /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?$/;
|
|
30
|
+
const JSON_LITERALS = ["true", "false", "null"] as const;
|
|
31
|
+
const CANONICAL_KEY = "input";
|
|
32
|
+
const STRING_END = Symbol("string end");
|
|
33
|
+
|
|
34
|
+
const ownsBodyRepair = (toolName: string): boolean => toolName === "exec" || toolName === "apply_patch";
|
|
35
|
+
|
|
36
|
+
type NestedState =
|
|
37
|
+
| "start" | "keyOpen" | "key" | "colon" | "valueOpen" | "string"
|
|
38
|
+
| "scalar" | "container" | "afterValue" | "trailing" | "never";
|
|
21
39
|
|
|
22
40
|
/**
|
|
23
|
-
*
|
|
41
|
+
* Whether a decoded executable body can still grow into the one extra `{"input":string}`
|
|
42
|
+
* wrapper that completion removes, answered one character at a time so a streamed body is walked
|
|
43
|
+
* once rather than once per delta.
|
|
44
|
+
*
|
|
45
|
+
* Ordinary object-leading JavaScript such as `{ let x` or `({` fails within a few characters and
|
|
46
|
+
* streams from there; only a prefix that is still a possible wrapper holds. A false answer never
|
|
47
|
+
* turns true again as the body grows, so the held prefix is flushed once and streaming continues.
|
|
48
|
+
*
|
|
49
|
+
* Every member name must be `input`, because completion unwraps only a single-key object, and
|
|
50
|
+
* duplicates are followed because `JSON.parse` keeps the last. A non-string value is skipped to its
|
|
51
|
+
* end so a later duplicate can still replace it, and an object that closes on a non-string last
|
|
52
|
+
* value is ruled out. Scalars are checked against the JSON grammar; containers are skipped by
|
|
53
|
+
* bracket and string tracking alone. That skip is looser than `JSON.parse` but never unsound: it
|
|
54
|
+
* finds the true end of every valid container, and any text it misreads is invalid JSON, which
|
|
55
|
+
* completion would not unwrap either way.
|
|
56
|
+
*/
|
|
57
|
+
class NestedWrapperMatcher {
|
|
58
|
+
scanned = 0;
|
|
59
|
+
private state: NestedState = "start";
|
|
60
|
+
private key = "";
|
|
61
|
+
/** Pending escape inside the current string: "", a backslash, or `\\u` and the hex read so far. */
|
|
62
|
+
private escape = "";
|
|
63
|
+
private scalar = "";
|
|
64
|
+
private readonly closers: string[] = [];
|
|
65
|
+
private inContainerString = false;
|
|
66
|
+
private containerEscape = false;
|
|
67
|
+
private lastValueString = false;
|
|
68
|
+
|
|
69
|
+
get possible(): boolean {
|
|
70
|
+
return this.state !== "never";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
feed(text: string): boolean {
|
|
74
|
+
for (let i = 0; i < text.length && this.state !== "never"; i++) {
|
|
75
|
+
this.scanned++;
|
|
76
|
+
this.step(text[i]!);
|
|
77
|
+
}
|
|
78
|
+
return this.possible;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private step(c: string): void {
|
|
82
|
+
switch (this.state) {
|
|
83
|
+
case "start":
|
|
84
|
+
if (!JSON_WHITESPACE.has(c)) this.state = c === "{" ? "keyOpen" : "never";
|
|
85
|
+
return;
|
|
86
|
+
case "keyOpen":
|
|
87
|
+
if (JSON_WHITESPACE.has(c)) return;
|
|
88
|
+
this.state = c === '"' ? "key" : "never";
|
|
89
|
+
this.key = "";
|
|
90
|
+
this.escape = "";
|
|
91
|
+
return;
|
|
92
|
+
case "key": {
|
|
93
|
+
const part = this.stringStep(c);
|
|
94
|
+
if (part === null) this.state = "never";
|
|
95
|
+
else if (part === STRING_END) this.state = this.key === CANONICAL_KEY ? "colon" : "never";
|
|
96
|
+
else if (!CANONICAL_KEY.startsWith(this.key += part)) this.state = "never";
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
case "colon":
|
|
100
|
+
if (!JSON_WHITESPACE.has(c)) this.state = c === ":" ? "valueOpen" : "never";
|
|
101
|
+
return;
|
|
102
|
+
case "valueOpen":
|
|
103
|
+
if (JSON_WHITESPACE.has(c)) return;
|
|
104
|
+
this.lastValueString = c === '"';
|
|
105
|
+
this.escape = "";
|
|
106
|
+
if (c === '"') this.state = "string";
|
|
107
|
+
else this.startOtherValue(c);
|
|
108
|
+
return;
|
|
109
|
+
case "string": {
|
|
110
|
+
const part = this.stringStep(c);
|
|
111
|
+
if (part === null) this.state = "never";
|
|
112
|
+
else if (part === STRING_END) this.state = "afterValue";
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
case "scalar":
|
|
116
|
+
this.stepScalar(c);
|
|
117
|
+
return;
|
|
118
|
+
case "container":
|
|
119
|
+
this.stepContainer(c);
|
|
120
|
+
return;
|
|
121
|
+
case "afterValue":
|
|
122
|
+
if (JSON_WHITESPACE.has(c)) return;
|
|
123
|
+
if (c === ",") this.state = "keyOpen";
|
|
124
|
+
else this.state = c === "}" && this.lastValueString ? "trailing" : "never";
|
|
125
|
+
return;
|
|
126
|
+
case "trailing":
|
|
127
|
+
if (!JSON_WHITESPACE.has(c)) this.state = "never";
|
|
128
|
+
return;
|
|
129
|
+
case "never":
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* One character of a JSON string: the text it decodes to ("" while an escape is pending),
|
|
136
|
+
* `STRING_END` at the closing quote, or `null` when no continuation can parse. Only key
|
|
137
|
+
* text needs the decoded value, so escapes other than `\\u` keep a marker.
|
|
138
|
+
*/
|
|
139
|
+
private stringStep(c: string): string | typeof STRING_END | null {
|
|
140
|
+
if (this.escape === "") {
|
|
141
|
+
if (c === '"') return STRING_END;
|
|
142
|
+
if (c.charCodeAt(0) <= 0x1f) return null;
|
|
143
|
+
if (c !== "\\") return c;
|
|
144
|
+
this.escape = "\\";
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
if (this.escape === "\\") {
|
|
148
|
+
if (c === "u") {
|
|
149
|
+
this.escape = "\\u";
|
|
150
|
+
return "";
|
|
151
|
+
}
|
|
152
|
+
if (!JSON_ESCAPES.has(c)) return null;
|
|
153
|
+
this.escape = "";
|
|
154
|
+
return "\\" + c;
|
|
155
|
+
}
|
|
156
|
+
if (!HEX_DIGIT.test(c)) return null;
|
|
157
|
+
this.escape += c;
|
|
158
|
+
if (this.escape.length < 6) return "";
|
|
159
|
+
const code = parseInt(this.escape.slice(2), 16);
|
|
160
|
+
this.escape = "";
|
|
161
|
+
return String.fromCharCode(code);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private startOtherValue(c: string): void {
|
|
165
|
+
if (c === "{" || c === "[") {
|
|
166
|
+
this.closers.length = 0;
|
|
167
|
+
this.closers.push(c === "{" ? "}" : "]");
|
|
168
|
+
this.inContainerString = false;
|
|
169
|
+
this.containerEscape = false;
|
|
170
|
+
this.state = "container";
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (JSON_NUMBER_CHAR.test(c) || c === "t" || c === "f" || c === "n") {
|
|
174
|
+
this.scalar = c;
|
|
175
|
+
this.state = "scalar";
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
this.state = "never";
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private stepScalar(c: string): void {
|
|
182
|
+
if (JSON_WHITESPACE.has(c) || c === "," || c === "}") {
|
|
183
|
+
const complete = (JSON_LITERALS as readonly string[]).includes(this.scalar) || JSON_NUMBER.test(this.scalar);
|
|
184
|
+
if (!complete) {
|
|
185
|
+
this.state = "never";
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.state = "afterValue";
|
|
189
|
+
this.step(c);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this.scalar += c;
|
|
193
|
+
const literal = JSON_LITERALS.find(word => word[0] === this.scalar[0]);
|
|
194
|
+
const viable = literal ? literal.startsWith(this.scalar) : JSON_NUMBER_CHAR.test(c);
|
|
195
|
+
if (!viable) this.state = "never";
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
private stepContainer(c: string): void {
|
|
199
|
+
if (this.inContainerString) {
|
|
200
|
+
if (this.containerEscape) this.containerEscape = false;
|
|
201
|
+
else if (c === "\\") this.containerEscape = true;
|
|
202
|
+
else if (c === '"') this.inContainerString = false;
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (c === '"') this.inContainerString = true;
|
|
206
|
+
else if (c === "{" || c === "[") this.closers.push(c === "{" ? "}" : "]");
|
|
207
|
+
else if (c === "}" || c === "]") {
|
|
208
|
+
if (this.closers.pop() !== c) this.state = "never";
|
|
209
|
+
else if (this.closers.length === 0) this.state = "afterValue";
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
type DecodeStop = "open" | "closed" | "stalled" | "invalid";
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Decode the JSON string body in `text` from `from`, stopping at the first byte it cannot
|
|
218
|
+
* resolve. `next` is where decoding resumes once more text arrives; `scanned` counts the characters
|
|
219
|
+
* read, including a split escape that will be read again.
|
|
24
220
|
*
|
|
25
221
|
* Every stop is a hold rather than a guess, because `JSON.parse` decides the completed value
|
|
26
222
|
* and anything invented here would be retracted. Three of them are not obvious:
|
|
27
223
|
*
|
|
28
224
|
* An escape JSON does not define makes the whole wrapper unparseable no matter what arrives
|
|
29
|
-
* next, so completion falls back to the raw text.
|
|
30
|
-
*
|
|
31
|
-
*
|
|
225
|
+
* next, so completion falls back to the raw text. `invalid` stops the preview rather than
|
|
226
|
+
* continuing to decode a value the completed item will never carry. `\\b` and `\\f` are defined,
|
|
227
|
+
* and were previously decoded to the letters b and f. A literal control character is not legal
|
|
228
|
+
* inside a JSON string either, and stops the same way.
|
|
32
229
|
*
|
|
33
230
|
* A lone high surrogate is not a character. Emitting one alone puts an unpaired code unit in a
|
|
34
|
-
* delta the client has to decode by itself, so the pair is emitted together or not at all
|
|
231
|
+
* delta the client has to decode by itself, so the pair is emitted together or not at all; a
|
|
232
|
+
* complete escape that is not its low half leaves the preview `stalled` for the rest of the call.
|
|
35
233
|
*/
|
|
36
|
-
function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
234
|
+
function decodeJsonStringChunk(
|
|
235
|
+
text: string,
|
|
236
|
+
from: number,
|
|
237
|
+
): { chunk: string; next: number; stop: DecodeStop; scanned: number } {
|
|
238
|
+
let chunk = "";
|
|
239
|
+
let scanned = 0;
|
|
240
|
+
let i = from;
|
|
241
|
+
let stop: DecodeStop = "open";
|
|
242
|
+
while (i < text.length) {
|
|
243
|
+
const c = text[i]!;
|
|
244
|
+
scanned++;
|
|
245
|
+
if (c === '"') {
|
|
246
|
+
stop = "closed";
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
41
249
|
if (c !== "\\") {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
250
|
+
if (c.charCodeAt(0) <= 0x1f) {
|
|
251
|
+
stop = "invalid";
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
chunk += c;
|
|
255
|
+
i++;
|
|
47
256
|
continue;
|
|
48
257
|
}
|
|
49
|
-
const n =
|
|
258
|
+
const n = text[i + 1];
|
|
50
259
|
if (n === undefined) break; // escape split across chunks: wait for more
|
|
260
|
+
scanned++;
|
|
51
261
|
if (n === "u") {
|
|
52
|
-
const hex =
|
|
262
|
+
const hex = text.slice(i + 2, i + 6);
|
|
263
|
+
scanned += hex.length;
|
|
53
264
|
if (hex.length < 4) break; // split across chunks: wait for more
|
|
54
|
-
if (
|
|
265
|
+
if (!HEX_QUAD.test(hex)) {
|
|
266
|
+
stop = "invalid";
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
55
269
|
const code = parseInt(hex, 16);
|
|
56
270
|
if (code >= 0xd800 && code <= 0xdbff) {
|
|
57
|
-
const low =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
271
|
+
const low = text.slice(i + 6, i + 12);
|
|
272
|
+
scanned += low.length;
|
|
273
|
+
if (!LOW_SURROGATE_ESCAPE.test(low)) {
|
|
274
|
+
if (low.length === 6) stop = "stalled";
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
chunk += String.fromCharCode(code, parseInt(low.slice(2), 16));
|
|
278
|
+
i += 12;
|
|
61
279
|
continue;
|
|
62
280
|
}
|
|
63
|
-
|
|
64
|
-
i +=
|
|
281
|
+
chunk += String.fromCharCode(code);
|
|
282
|
+
i += 6;
|
|
65
283
|
continue;
|
|
66
284
|
}
|
|
67
285
|
const escaped = JSON_ESCAPES.get(n);
|
|
68
|
-
if (escaped === undefined)
|
|
69
|
-
|
|
70
|
-
|
|
286
|
+
if (escaped === undefined) {
|
|
287
|
+
stop = "invalid";
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
chunk += escaped;
|
|
291
|
+
i += 2;
|
|
71
292
|
}
|
|
72
|
-
return
|
|
293
|
+
return { chunk, next: i, stop, scanned };
|
|
73
294
|
}
|
|
74
295
|
|
|
75
296
|
/**
|
|
76
|
-
* The value to stream so far, or `null` to HOLD because nothing
|
|
297
|
+
* The value to stream so far for one call's growing arguments, or `null` to HOLD because nothing
|
|
298
|
+
* can be decided yet.
|
|
299
|
+
*
|
|
300
|
+
* A reader belongs to one call and is fed that call's whole accumulated arguments on each delta.
|
|
301
|
+
* They only grow, so it resumes where the previous delta stopped: the canonical value is decoded
|
|
302
|
+
* and checked for a nested wrapper once overall, which keeps a long body streamed in small deltas
|
|
303
|
+
* linear instead of quadratic. A shorter buffer or a different tool name starts over.
|
|
304
|
+
*
|
|
77
305
|
*
|
|
78
306
|
* `input` is decidable from its prefix: `unwrapFreeformToolInput` returns it whenever the
|
|
79
307
|
* key is present, whatever else the object carries, so its value can be unescaped
|
|
80
|
-
* progressively and never retracted
|
|
308
|
+
* progressively and never retracted, except for executable bodies that may contain one
|
|
309
|
+
* extra canonical wrapper. Such a body holds only while its prefix can still become that
|
|
310
|
+
* wrapper (`mayBecomeNestedWrapper`); the first byte that rules it out flushes the held text.
|
|
81
311
|
*
|
|
82
312
|
* One case escapes that claim and is accepted rather than fixed: a duplicate `input` key.
|
|
83
313
|
* `JSON.parse` keeps the last one, so `{"input":"a","input":"b"}` streams a and completes with
|
|
@@ -106,19 +336,98 @@ function decodeJsonStringPrefix(body: string): string | null {
|
|
|
106
336
|
* cost of holding is preview on an object body that turns out not to be a wrapper; the cost of
|
|
107
337
|
* not holding was publishing bytes the completed item removes.
|
|
108
338
|
*/
|
|
109
|
-
export
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
339
|
+
export class ProgressiveFreeformInputReader {
|
|
340
|
+
private toolName: string | undefined;
|
|
341
|
+
private seen = 0;
|
|
342
|
+
private mode: "scan" | "raw" | "hold" | "input" = "scan";
|
|
343
|
+
private next = 0;
|
|
344
|
+
private decoded = "";
|
|
345
|
+
private stop: DecodeStop = "open";
|
|
346
|
+
private nested: NestedWrapperMatcher | null = null;
|
|
347
|
+
private fenceRuledOut = false;
|
|
348
|
+
private decodeScanned = 0;
|
|
349
|
+
|
|
350
|
+
/** Characters this reader has walked so far; a test seam for the linear-work bound. */
|
|
351
|
+
get scannedChars(): number {
|
|
352
|
+
return this.decodeScanned + (this.nested?.scanned ?? 0);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
update(args: string, toolName: string): string | null {
|
|
356
|
+
if (toolName !== this.toolName || args.length < this.seen) this.reset(toolName);
|
|
357
|
+
this.seen = args.length;
|
|
358
|
+
if (this.mode === "scan") {
|
|
359
|
+
const scan = scanFreeformWrapper(args, freeformFallbackKeys(toolName));
|
|
360
|
+
if (scan.kind === "raw") {
|
|
361
|
+
// Prefix-decided: no extension of this text becomes a wrapper again.
|
|
362
|
+
this.mode = "raw";
|
|
363
|
+
} else if (scan.kind === "hold") {
|
|
364
|
+
// Past the bound the scan only ever sees the same clamped prefix, so it holds for good.
|
|
365
|
+
if (args.length > MAX_FREEFORM_WRAPPER_SCAN_CHARS) this.mode = "hold";
|
|
366
|
+
return null;
|
|
367
|
+
} else if (scan.canonical) {
|
|
368
|
+
this.mode = "input";
|
|
369
|
+
this.next = scan.valueStart;
|
|
370
|
+
this.nested = ownsBodyRepair(toolName) ? new NestedWrapperMatcher() : null;
|
|
371
|
+
} else {
|
|
372
|
+
// A closed fallback wrapper can still be withdrawn by trailing text, so it is decided
|
|
373
|
+
// afresh on each delta. Its object fits inside the scan bound, which bounds this too.
|
|
374
|
+
return this.closedFallbackValue(args, scan.valueStart, toolName);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (this.mode === "hold") return null;
|
|
378
|
+
if (this.mode === "raw") return this.mayBecomeFenced(args) ? null : args;
|
|
379
|
+
return this.canonicalValue(args);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
private reset(toolName: string): void {
|
|
383
|
+
this.toolName = toolName;
|
|
384
|
+
this.seen = 0;
|
|
385
|
+
this.mode = "scan";
|
|
386
|
+
this.next = 0;
|
|
387
|
+
this.decoded = "";
|
|
388
|
+
this.stop = "open";
|
|
389
|
+
this.nested = null;
|
|
390
|
+
this.fenceRuledOut = false;
|
|
115
391
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
392
|
+
|
|
393
|
+
private canonicalValue(args: string): string | null {
|
|
394
|
+
if (this.stop === "open") {
|
|
395
|
+
const step = decodeJsonStringChunk(args, this.next);
|
|
396
|
+
this.decodeScanned += step.scanned;
|
|
397
|
+
this.next = step.next;
|
|
398
|
+
this.stop = step.stop;
|
|
399
|
+
this.decoded += step.chunk;
|
|
400
|
+
if (this.nested?.possible) this.nested.feed(step.chunk);
|
|
401
|
+
}
|
|
402
|
+
if (this.stop === "invalid") return null;
|
|
403
|
+
// Completion may remove one extra {input:string} body wrapper, so hold while it can.
|
|
404
|
+
if (this.nested?.possible) return null;
|
|
405
|
+
return this.mayBecomeFenced(this.decoded) ? null : this.decoded;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
private closedFallbackValue(args: string, valueStart: number, toolName: string): string | null {
|
|
409
|
+
const step = decodeJsonStringChunk(args, valueStart);
|
|
410
|
+
this.decodeScanned += step.scanned;
|
|
411
|
+
if (step.stop === "invalid") return null;
|
|
412
|
+
if (ownsBodyRepair(toolName)) {
|
|
413
|
+
const nested = new NestedWrapperMatcher();
|
|
414
|
+
const possible = nested.feed(step.chunk);
|
|
415
|
+
this.decodeScanned += nested.scanned;
|
|
416
|
+
if (possible) return null;
|
|
417
|
+
}
|
|
418
|
+
return mayBecomeFencedBody(step.chunk, toolName) ? null : step.chunk;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** `mayBecomeFencedBody`, remembering a false answer: a ruled-out fence never returns. */
|
|
422
|
+
private mayBecomeFenced(text: string): boolean {
|
|
423
|
+
if (this.fenceRuledOut) return false;
|
|
424
|
+
if (mayBecomeFencedBody(text, this.toolName ?? "")) return true;
|
|
425
|
+
this.fenceRuledOut = true;
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** One-shot form of `ProgressiveFreeformInputReader` for a buffer read once. */
|
|
431
|
+
export function progressiveFreeformInput(args: string, toolName: string): string | null {
|
|
432
|
+
return new ProgressiveFreeformInputReader().update(args, toolName);
|
|
124
433
|
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* Privacy: events carry public selectors, coarse trigger codes and device ids only. No request
|
|
14
14
|
* body, credential, account id, label or email reaches the ring or the refusal body.
|
|
15
15
|
*/
|
|
16
|
+
import { formatClientRetryAfter } from "../lib/client-retry-after";
|
|
16
17
|
import type { OcxConfig } from "../types";
|
|
17
18
|
import type { OcxFallbackConfig, OcxFallbackKind, OcxFallbackSwitches } from "../types/fallback";
|
|
18
19
|
import { FALLBACK_DEVICE_ID, FALLBACK_SELECTOR } from "../config/schema/fallback-policy";
|
|
@@ -262,7 +263,8 @@ export function fallbackRefusedResponse(event: FallbackEvent, hop: Pick<Fallback
|
|
|
262
263
|
+ " fallback to " + event.to + " is off " + scopePhrase(event) + ", so OpenCodex did not send the request there."
|
|
263
264
|
+ " To allow it: ocx fallback on --kind " + event.kind + scopeFlag(event);
|
|
264
265
|
const headers = new Headers({ "x-opencodex-fallback": "refused", "cache-control": "no-store" });
|
|
265
|
-
|
|
266
|
+
const advice = formatClientRetryAfter(hop.retryAfter);
|
|
267
|
+
if (advice !== undefined) headers.set("retry-after", advice);
|
|
266
268
|
return Response.json({
|
|
267
269
|
error: {
|
|
268
270
|
message,
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { projectLocalModelRefusalLog } from "./request-log-failure-detail";
|
|
2
|
+
import { clientFacingModelLabel, clientFacingModelText, type ClientFacingModelLabel } from "../lib/error-destination";
|
|
3
|
+
import { markProxyError } from "../lib/client-error-body";
|
|
1
4
|
import type { DataPlaneAdmission } from "./auth-cors";
|
|
2
5
|
import { isApiAuthRequired } from "./auth-cors";
|
|
3
6
|
import type { OcxApiKeyEntry, OcxConfig } from "../types";
|
|
@@ -146,10 +149,10 @@ export class AdmissionModelDeniedError extends Error {
|
|
|
146
149
|
readonly requestedModel: string;
|
|
147
150
|
readonly deniedProvider: string;
|
|
148
151
|
readonly deniedModel: string;
|
|
149
|
-
constructor(requestedModel:
|
|
150
|
-
super("model " + requestedModel + " is not allowed for this API key");
|
|
152
|
+
constructor(requestedModel: ClientFacingModelLabel, route: ScopedRoute) {
|
|
153
|
+
super("model " + clientFacingModelText(requestedModel) + " is not allowed for this API key");
|
|
151
154
|
this.name = "AdmissionModelDeniedError";
|
|
152
|
-
this.requestedModel = requestedModel;
|
|
155
|
+
this.requestedModel = clientFacingModelText(requestedModel);
|
|
153
156
|
this.deniedProvider = route.providerName;
|
|
154
157
|
this.deniedModel = route.modelId;
|
|
155
158
|
}
|
|
@@ -189,13 +192,21 @@ export function admissionModelDeniedBody(error: AdmissionModelDeniedError): {
|
|
|
189
192
|
* it to retry with another, and would make an operator's own denial
|
|
190
193
|
* indistinguishable from a typo in the model name.
|
|
191
194
|
*/
|
|
195
|
+
/** Project scope refusals before any caller finalizes its request log. */
|
|
196
|
+
export function projectAdmissionModelDeniedLog(error: AdmissionModelDeniedError, logCtx: import("./request-log").RequestLogContext): AdmissionModelDeniedError {
|
|
197
|
+
projectLocalModelRefusalLog(logCtx, clientFacingModelLabel(error.requestedModel,
|
|
198
|
+
error.requestedModel === UNNAMED_DESTINATION_MODEL ? "unnamed" : "requested"));
|
|
199
|
+
logCtx.requestedModel = error.requestedModel;
|
|
200
|
+
return error;
|
|
201
|
+
}
|
|
202
|
+
|
|
192
203
|
export function admissionModelDeniedResponse(error: AdmissionModelDeniedError): Response {
|
|
193
204
|
const response = new Response(JSON.stringify(admissionModelDeniedBody(error)), {
|
|
194
205
|
status: 403,
|
|
195
206
|
headers: { "Content-Type": "application/json" },
|
|
196
207
|
});
|
|
197
208
|
markResponseNonReplayable(response);
|
|
198
|
-
return response;
|
|
209
|
+
return markProxyError(response, "scope");
|
|
199
210
|
}
|
|
200
211
|
|
|
201
212
|
/**
|
|
@@ -208,7 +219,7 @@ export function admissionModelDeniedResponse(error: AdmissionModelDeniedError):
|
|
|
208
219
|
*/
|
|
209
220
|
export function assertRouteAllowedByScope(
|
|
210
221
|
scope: AdmissionModelScope | undefined,
|
|
211
|
-
requestedModel:
|
|
222
|
+
requestedModel: ClientFacingModelLabel,
|
|
212
223
|
route: ScopedRoute,
|
|
213
224
|
): void {
|
|
214
225
|
if (!routeAllowedByScope(scope, route)) {
|
|
@@ -247,7 +258,7 @@ export function admissionScopeDenial(
|
|
|
247
258
|
: routeAllowedByScope(scope, { providerName: destination.providerName, modelId: destination.modelId });
|
|
248
259
|
if (allowed) return undefined;
|
|
249
260
|
return admissionModelDeniedResponse(new AdmissionModelDeniedError(
|
|
250
|
-
requestedModel
|
|
261
|
+
clientFacingModelLabel(requestedModel, requestedModel === undefined ? "unnamed" : "requested"),
|
|
251
262
|
{
|
|
252
263
|
providerName: destination.providerName,
|
|
253
264
|
modelId: destination.modelId ?? UNNAMED_DESTINATION_MODEL,
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { normalizeMessagesProxyRefusal } from "../lib/messages-error-body";
|
|
2
|
+
import { withCors, type RequestPolicyView } from "./auth-cors";
|
|
3
|
+
import { runAdmittedBodyWork } from "./inbound-body-admission";
|
|
4
|
+
import { tryAdmitTurn, type ActiveTurnLease } from "./lifecycle";
|
|
5
|
+
import { addFinalRequestLog } from "./request-log";
|
|
6
|
+
import { sessionLaneIdFromRequest } from "./request-log-conversation";
|
|
7
|
+
import { admitHttpWorkflowTurn, workflowDecisionRefusalResponse, type WorkflowRefusalLog } from "./workflow-refusal";
|
|
8
|
+
|
|
9
|
+
export interface AdmittedHttpTurnOptions {
|
|
10
|
+
mapRefusal?: (response: Response) => Response;
|
|
11
|
+
onAdmissionError?: (error: unknown) => Response;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createAdmittedHttpTurn(
|
|
15
|
+
configuredLimit: () => number | undefined,
|
|
16
|
+
serverBusyResponse: (req: Request, resource: string, policy: RequestPolicyView) => Response,
|
|
17
|
+
) {
|
|
18
|
+
return async function runAdmittedHttpTurn(
|
|
19
|
+
req: Request,
|
|
20
|
+
policy: RequestPolicyView,
|
|
21
|
+
work: (lease: ActiveTurnLease) => Promise<Response>,
|
|
22
|
+
refusalLog?: WorkflowRefusalLog,
|
|
23
|
+
options?: AdmittedHttpTurnOptions,
|
|
24
|
+
): Promise<Response> {
|
|
25
|
+
const map = (response: Response) => options?.mapRefusal ? options.mapRefusal(response) : response;
|
|
26
|
+
const lease = tryAdmitTurn(sessionLaneIdFromRequest(req.headers), req.signal);
|
|
27
|
+
if (!lease) {
|
|
28
|
+
const response = serverBusyResponse(req, "active turns", policy);
|
|
29
|
+
return options?.mapRefusal ? withCors(map(response), req, policy) : response;
|
|
30
|
+
}
|
|
31
|
+
let workflow: ReturnType<typeof admitHttpWorkflowTurn>;
|
|
32
|
+
try { workflow = admitHttpWorkflowTurn(req.headers); }
|
|
33
|
+
catch (error) { lease.release(); throw error; }
|
|
34
|
+
if (workflow && !workflow.admitted) {
|
|
35
|
+
lease.release();
|
|
36
|
+
return withCors(await normalizeMessagesProxyRefusal(req, map(workflowDecisionRefusalResponse(workflow, undefined, refusalLog))), req, policy);
|
|
37
|
+
}
|
|
38
|
+
if (workflow?.admitted) lease.attach(workflow.lease);
|
|
39
|
+
try {
|
|
40
|
+
const response = await runAdmittedBodyWork(req, policy, configuredLimit(), () => work(lease), refusalLog,
|
|
41
|
+
options?.mapRefusal, options?.onAdmissionError ? error => {
|
|
42
|
+
if (!req.signal.aborted || error !== req.signal.reason) throw error;
|
|
43
|
+
lease.release();
|
|
44
|
+
if (refusalLog) {
|
|
45
|
+
addFinalRequestLog(refusalLog.requestId, refusalLog.start, refusalLog.logCtx, 499, { closeReason: "client_cancel" });
|
|
46
|
+
refusalLog.onLogged?.();
|
|
47
|
+
}
|
|
48
|
+
return withCors(map(options.onAdmissionError!(error)), req, policy);
|
|
49
|
+
} : undefined);
|
|
50
|
+
if (!lease.isTransferred()) lease.release();
|
|
51
|
+
return response;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
lease.release();
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -1,7 +1,79 @@
|
|
|
1
|
+
type Normalize = (value: string) => string | undefined;
|
|
2
|
+
const MAX_EPOCH = 253402300799;
|
|
3
|
+
const STATUS: ReadonlyMap<string, string> = new Map([["allowed", "allowed"], ["rejected", "rejected"]]);
|
|
4
|
+
const count: Normalize = value => {
|
|
5
|
+
if (!/^[0-9]{1,16}$/.test(value)) return undefined;
|
|
6
|
+
const n = Number(value);
|
|
7
|
+
return n <= 1e12 ? String(n) : undefined;
|
|
8
|
+
};
|
|
9
|
+
/** Decimal arithmetic keeps half-up rounding independent of binary floating point. */
|
|
10
|
+
function decimal(value: string, grammar: RegExp, max: bigint, digits: number): string | undefined {
|
|
11
|
+
if (!grammar.test(value)) return undefined;
|
|
12
|
+
const [whole = "0", fraction = ""] = value.split(".");
|
|
13
|
+
const scale = 10n ** BigInt(fraction.length);
|
|
14
|
+
const exact = BigInt(whole) * scale + BigInt(fraction || "0");
|
|
15
|
+
if (exact > max * scale) return undefined;
|
|
16
|
+
const outputScale = 10n ** BigInt(digits);
|
|
17
|
+
const rounded = (exact * outputScale * 2n + scale) / (scale * 2n);
|
|
18
|
+
const bounded = rounded > max * outputScale ? max * outputScale : rounded;
|
|
19
|
+
const tail = String(bounded % outputScale).padStart(digits, "0").replace(/0+$/, "");
|
|
20
|
+
return `${bounded / outputScale}${tail ? `.${tail}` : ""}`;
|
|
21
|
+
}
|
|
22
|
+
const epoch: Normalize = value => decimal(value, /^[0-9]{1,12}(\.[0-9]{1,6})?$/, BigInt(MAX_EPOCH), 3);
|
|
23
|
+
const utilization: Normalize = value => decimal(value, /^[0-9]{1,6}(\.[0-9]{1,12})?$/, 100n, 4);
|
|
24
|
+
const date: Normalize = value => {
|
|
25
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})[Tt](\d{2}):(\d{2}):(\d{2})(?:\.([0-9]{1,9}))?([Zz]|[+-]\d{2}:\d{2})$/.exec(value);
|
|
26
|
+
if (!match) return undefined;
|
|
27
|
+
const [year, month, day, hour, minute, second] = match.slice(1, 7).map(Number) as [number, number, number, number, number, number];
|
|
28
|
+
const zone = match[8]!;
|
|
29
|
+
const zoneHour = zone.length === 1 ? 0 : Number(zone.slice(1, 3));
|
|
30
|
+
const zoneMinute = zone.length === 1 ? 0 : Number(zone.slice(4, 6));
|
|
31
|
+
if (year < 1970 || month < 1 || month > 12 || day < 1 || hour > 23 || minute > 59 || second > 59
|
|
32
|
+
|| zoneHour > 23 || zoneMinute > 59 || zone === "-00:00") return undefined;
|
|
33
|
+
const monthDays = (y: number, m: number): number => m === 2
|
|
34
|
+
? (y % 4 === 0 && (y % 100 !== 0 || y % 400 === 0) ? 29 : 28)
|
|
35
|
+
: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][m - 1]!;
|
|
36
|
+
if (day > monthDays(year, month)) return undefined;
|
|
37
|
+
let utcYear = year, utcMonth = month, utcDay = day;
|
|
38
|
+
const offset = (zoneHour * 60 + zoneMinute) * 60 * (zone[0] === "-" ? -1 : 1);
|
|
39
|
+
let utcSecond = hour * 3600 + minute * 60 + second - offset;
|
|
40
|
+
if (utcSecond < 0) {
|
|
41
|
+
utcSecond += 86400;
|
|
42
|
+
if (--utcDay === 0) {
|
|
43
|
+
if (--utcMonth === 0) { utcMonth = 12; utcYear--; }
|
|
44
|
+
utcDay = monthDays(utcYear, utcMonth);
|
|
45
|
+
}
|
|
46
|
+
} else if (utcSecond >= 86400) {
|
|
47
|
+
utcSecond -= 86400;
|
|
48
|
+
if (++utcDay > monthDays(utcYear, utcMonth)) {
|
|
49
|
+
utcDay = 1;
|
|
50
|
+
if (++utcMonth === 13) { utcMonth = 1; utcYear++; }
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (utcYear < 1970 || utcYear > 9999) return undefined;
|
|
54
|
+
const pad = (n: number, digits = 2): string => n.toString().padStart(digits, "0");
|
|
55
|
+
const fraction = (match[7] ?? "").replace(/0+$/, "");
|
|
56
|
+
return `${pad(utcYear, 4)}-${pad(utcMonth)}-${pad(utcDay)}T${pad(Math.floor(utcSecond / 3600))}:${pad(Math.floor(utcSecond / 60) % 60)}:${pad(utcSecond % 60)}${fraction ? `.${fraction}` : ""}Z`;
|
|
57
|
+
};
|
|
58
|
+
const EXACT: ReadonlyMap<string, Normalize> = new Map([
|
|
59
|
+
...["requests", "tokens", "input-tokens", "output-tokens"].flatMap(family => [
|
|
60
|
+
[`anthropic-ratelimit-${family}-limit`, count],
|
|
61
|
+
[`anthropic-ratelimit-${family}-remaining`, count],
|
|
62
|
+
[`anthropic-ratelimit-${family}-reset`, date],
|
|
63
|
+
] as [string, Normalize][]),
|
|
64
|
+
...["", "-5h", "-7d", "-7d_oi"].flatMap(window => [
|
|
65
|
+
[`anthropic-ratelimit-unified${window}-status`, value => STATUS.get(value)],
|
|
66
|
+
[`anthropic-ratelimit-unified${window}-reset`, epoch],
|
|
67
|
+
...(window ? [[`anthropic-ratelimit-unified${window}-utilization`, utilization] as [string, Normalize]] : []),
|
|
68
|
+
] as [string, Normalize][]),
|
|
69
|
+
]);
|
|
1
70
|
export function anthropicRateLimitHeaders(upstream: Headers): Record<string, string> {
|
|
2
71
|
const headers: Record<string, string> = {};
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
72
|
+
for (const [name, normalize] of EXACT) {
|
|
73
|
+
const input = upstream.get(name);
|
|
74
|
+
if (input === null || input.length > 128) continue;
|
|
75
|
+
const value = normalize(input.replace(/^[ \t]+|[ \t]+$/g, ""));
|
|
76
|
+
if (value !== undefined) headers[name] = value;
|
|
77
|
+
}
|
|
6
78
|
return headers;
|
|
7
79
|
}
|