@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,6 @@
|
|
|
1
|
+
import type { MessagesSseErrorFilter } from "./messages-sse-error-filter";
|
|
2
|
+
import { MessagesSseFrameContext, messagesSseLocalFrame, type MessagesSseLocalOrigin } from "../lib/messages-sse-error-presentation";
|
|
3
|
+
import { markProxyError } from "../lib/client-error-body";
|
|
1
4
|
/**
|
|
2
5
|
* Accounting and measurement pieces shared by the two Claude Messages lanes.
|
|
3
6
|
*
|
|
@@ -28,6 +31,7 @@ import { isTranslatorBudgetExceededError } from "../lib/translator-budget";
|
|
|
28
31
|
import { AnthropicRequestError, isRec, type Rec } from "../claude/inbound-records";
|
|
29
32
|
import type { RequestLogContext } from "./request-log";
|
|
30
33
|
import { recordGenerationEvent } from "./request-log-generation-window";
|
|
34
|
+
import { recordLocalFailureDetail } from "./request-log-failure-detail";
|
|
31
35
|
import type { OcxConfig } from "../types";
|
|
32
36
|
|
|
33
37
|
export function anthropicUsageToOcx(usage: Rec | undefined): { inputTokens: number; outputTokens: number; cachedInputTokens?: number; cacheReadInputTokens?: number; cacheCreationInputTokens?: number; cacheCreation1hInputTokens?: number } | undefined {
|
|
@@ -109,6 +113,8 @@ export function tapAnthropicSseForLog(
|
|
|
109
113
|
logCtx: RequestLogContext,
|
|
110
114
|
finalize: (status: number, meta: PassthroughFinalizeMeta) => void,
|
|
111
115
|
guard?: PassthroughBodyGuard,
|
|
116
|
+
frames?: MessagesSseFrameContext,
|
|
117
|
+
clientFilter?: MessagesSseErrorFilter,
|
|
112
118
|
): ReadableStream<Uint8Array> {
|
|
113
119
|
const decoder = new TextDecoder();
|
|
114
120
|
const encoder = new TextEncoder();
|
|
@@ -235,16 +241,32 @@ export function tapAnthropicSseForLog(
|
|
|
235
241
|
let bodyBytes = 0;
|
|
236
242
|
let tapController: ReadableStreamDefaultController<Uint8Array> | undefined;
|
|
237
243
|
|
|
244
|
+
let deliveryFailed = false;
|
|
245
|
+
const enqueue = (bytes: Uint8Array): number => {
|
|
246
|
+
let count = 0;
|
|
247
|
+
try {
|
|
248
|
+
if (clientFilter) clientFilter.push(bytes, value => { tapController!.enqueue(value); count++; });
|
|
249
|
+
else { tapController!.enqueue(bytes); count++; }
|
|
250
|
+
return count;
|
|
251
|
+
} catch (error) {
|
|
252
|
+
deliveryFailed = clientFilter !== undefined;
|
|
253
|
+
clientFilter?.dispose();
|
|
254
|
+
throw error;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const close = () => { clientFilter?.finish(value => tapController!.enqueue(value)); tapController!.close(); };
|
|
238
258
|
const recordUsage = () => {
|
|
239
259
|
logCtx.usage = anthropicUsageToOcx(Object.keys(usageAcc).length > 0 ? usageAcc : undefined);
|
|
240
260
|
};
|
|
241
|
-
const closeWithErrorFrame = (errType: string, message: string) => {
|
|
261
|
+
const closeWithErrorFrame = (errType: string, message: string, origin: MessagesSseLocalOrigin) => {
|
|
242
262
|
const payload = JSON.stringify({ type: "error", error: { type: errType, message } });
|
|
243
263
|
try {
|
|
244
264
|
// Leading blank line terminates any partial SSE block so the frame parses cleanly
|
|
245
265
|
// (relaySseWithFailedTail policy, Anthropic wire shape).
|
|
246
|
-
|
|
247
|
-
|
|
266
|
+
const bytes = encoder.encode(`\n\nevent: error\ndata: ${payload}\n\n`);
|
|
267
|
+
frames?.register(bytes, { client: messagesSseLocalFrame(origin, message) });
|
|
268
|
+
enqueue(bytes);
|
|
269
|
+
close();
|
|
248
270
|
} catch { /* client already torn down */ }
|
|
249
271
|
};
|
|
250
272
|
const failBody = (closeReason: "body_stall" | "body_overflow", errType: string, message: string) => {
|
|
@@ -260,16 +282,17 @@ export function tapAnthropicSseForLog(
|
|
|
260
282
|
// including the restored blank line for a terminal found only in the tail.
|
|
261
283
|
finalize(200, { closeReason: "terminal" });
|
|
262
284
|
try {
|
|
263
|
-
if (terminalInTail)
|
|
264
|
-
|
|
285
|
+
if (terminalInTail) enqueue(encoder.encode("\n\n"));
|
|
286
|
+
close();
|
|
265
287
|
} catch { /* client already torn down */ }
|
|
266
288
|
} else {
|
|
267
289
|
// A cut-short turn, logged as the Responses relay logs a stall-timeout incomplete
|
|
268
290
|
// (httpStatusForRequestLogTerminal: only a max_output_tokens incomplete is a 200). A 200
|
|
269
291
|
// row with no terminalStatus also lost its failure diagnostics in usage.jsonl.
|
|
270
|
-
logCtx
|
|
292
|
+
recordLocalFailureDetail(logCtx, message, closeReason === "body_stall"
|
|
293
|
+
? { code: "body_stall", value: guard?.stallMs ?? 0 } : { code: "body_overflow", value: guard?.maxBytes ?? 0 });
|
|
271
294
|
finalize(502, { terminalStatus: "incomplete", closeReason });
|
|
272
|
-
closeWithErrorFrame(errType, message);
|
|
295
|
+
closeWithErrorFrame(errType, message, closeReason === "body_stall" ? "stall" : "cap");
|
|
273
296
|
}
|
|
274
297
|
reader.cancel(new DOMException(message, closeReason === "body_stall" ? "TimeoutError" : "QuotaExceededError")).catch(() => {});
|
|
275
298
|
};
|
|
@@ -290,6 +313,7 @@ export function tapAnthropicSseForLog(
|
|
|
290
313
|
idle.cancel();
|
|
291
314
|
detachAbort();
|
|
292
315
|
finalize(499, { closeReason: "client_cancel" });
|
|
316
|
+
clientFilter?.dispose();
|
|
293
317
|
try { tapController?.close(); } catch { /* downstream already torn down */ }
|
|
294
318
|
reader.cancel(guard?.reqSignal?.reason).catch(() => {});
|
|
295
319
|
};
|
|
@@ -311,64 +335,66 @@ export function tapAnthropicSseForLog(
|
|
|
311
335
|
async pull(controller) {
|
|
312
336
|
if (settled) return;
|
|
313
337
|
try {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
338
|
+
for (;;) {
|
|
339
|
+
idle.reset();
|
|
340
|
+
const { done, value } = await reader.read();
|
|
341
|
+
idle.pause();
|
|
342
|
+
if (settled) return; // stall/overflow/abort won the race while we awaited
|
|
343
|
+
if (done) {
|
|
344
|
+
// Bun can resolve a cancelled read as done before the abort listener runs: a client
|
|
345
|
+
// that left is a cancel, not a cut upstream.
|
|
346
|
+
if (guard?.reqSignal?.aborted) {
|
|
347
|
+
onClientAbort();
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
settled = true;
|
|
351
|
+
idle.cancel();
|
|
352
|
+
detachAbort();
|
|
353
|
+
const { terminalInTail, tailClean } = flushTail();
|
|
354
|
+
recordUsage();
|
|
355
|
+
// A clean EOF ends the turn only when the client already has its terminal, or a
|
|
356
|
+
// complete non-error stop_reason with nothing cut after it (compatible providers may
|
|
357
|
+
// omit message_stop; the translated adapter accepts the same shape). The opt-in
|
|
358
|
+
// anthropicEofTolerance profile keeps a content-only EOF as it always was.
|
|
359
|
+
const failure = terminalSeen
|
|
360
|
+
? null
|
|
361
|
+
: lastDeliveredStop === "error"
|
|
362
|
+
? 'upstream ended the turn with stop_reason "error"'
|
|
363
|
+
: !tailClean
|
|
364
|
+
? "anthropic passthrough upstream stream ended before message_stop"
|
|
365
|
+
: lastDeliveredStop !== null || guard?.eofTolerant === true
|
|
366
|
+
? null
|
|
367
|
+
: "anthropic passthrough upstream stream ended before message_stop";
|
|
368
|
+
if (failure === null) {
|
|
369
|
+
finalize(200, { closeReason: "terminal" });
|
|
370
|
+
if (terminalInTail) enqueue(encoder.encode("\n\n"));
|
|
371
|
+
close();
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
// A body that stopped short is a failed turn, logged and surfaced like a mid-stream
|
|
375
|
+
// reset (below), so the client never reads a partial answer as a finished message.
|
|
376
|
+
logCtx.transportPhase = "mid_stream";
|
|
377
|
+
logCtx.terminalSource = "synthetic";
|
|
378
|
+
recordLocalFailureDetail(logCtx, failure, { code: lastDeliveredStop === "error" ? "stream_error_stop" : "stream_ended_early" });
|
|
379
|
+
if (logCtx.activeAttempt) logCtx.activeAttempt.streamAborted = true;
|
|
380
|
+
finalize(502, { terminalStatus: "failed", closeReason: "terminal" });
|
|
381
|
+
closeWithErrorFrame("api_error", failure, lastDeliveredStop === "error" ? "stop-error" : "eof");
|
|
347
382
|
return;
|
|
348
383
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
if (value.byteLength > 0) {
|
|
360
|
-
bodyBytes += value.byteLength;
|
|
361
|
-
if (guard && guard.maxBytes > 0 && bodyBytes > guard.maxBytes) {
|
|
362
|
-
failBody(
|
|
363
|
-
"body_overflow",
|
|
364
|
-
"api_error",
|
|
365
|
-
`anthropic passthrough body exceeded ${guard.maxBytes} bytes`,
|
|
366
|
-
);
|
|
367
|
-
return;
|
|
384
|
+
if (value.byteLength > 0) {
|
|
385
|
+
bodyBytes += value.byteLength;
|
|
386
|
+
if (guard && guard.maxBytes > 0 && bodyBytes > guard.maxBytes) {
|
|
387
|
+
failBody(
|
|
388
|
+
"body_overflow",
|
|
389
|
+
"api_error",
|
|
390
|
+
`anthropic passthrough body exceeded ${guard.maxBytes} bytes`,
|
|
391
|
+
);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
368
394
|
}
|
|
395
|
+
inspect(value);
|
|
396
|
+
if (enqueue(value) > 0) return;
|
|
369
397
|
}
|
|
370
|
-
inspect(value);
|
|
371
|
-
controller.enqueue(value);
|
|
372
398
|
} catch (err) {
|
|
373
399
|
if (settled) return;
|
|
374
400
|
// Bun can settle a fetch body read before it dispatches the abort listeners
|
|
@@ -387,6 +413,7 @@ export function tapAnthropicSseForLog(
|
|
|
387
413
|
// A local cap, not an upstream failure: the non-streaming native Messages fold
|
|
388
414
|
// maps this error to a 413 itself, so it still errors the stream.
|
|
389
415
|
finalize(200, { closeReason: "terminal" });
|
|
416
|
+
clientFilter?.dispose();
|
|
390
417
|
try { controller.error(err); } catch { /* torn down */ }
|
|
391
418
|
return;
|
|
392
419
|
}
|
|
@@ -397,8 +424,11 @@ export function tapAnthropicSseForLog(
|
|
|
397
424
|
try {
|
|
398
425
|
// An SSE parser drops an event that EOF cuts off before its blank line, so restore
|
|
399
426
|
// the delimiter when the terminal was only found in that unterminated tail.
|
|
400
|
-
if (
|
|
401
|
-
|
|
427
|
+
if (deliveryFailed) controller.error(err);
|
|
428
|
+
else {
|
|
429
|
+
if (terminalInTail) enqueue(encoder.encode("\n\n"));
|
|
430
|
+
close();
|
|
431
|
+
}
|
|
402
432
|
} catch { /* torn down */ }
|
|
403
433
|
reader.cancel(err).catch(() => {});
|
|
404
434
|
return;
|
|
@@ -411,14 +441,18 @@ export function tapAnthropicSseForLog(
|
|
|
411
441
|
const message = redactSecretString(`anthropic passthrough upstream stream failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
412
442
|
logCtx.transportPhase = "mid_stream";
|
|
413
443
|
logCtx.terminalSource = "synthetic";
|
|
444
|
+
// The runtime error text stays internal; the row keeps the fixed sentence only.
|
|
445
|
+
recordLocalFailureDetail(logCtx, "anthropic passthrough upstream stream failed", { code: "stream_failed" });
|
|
414
446
|
logCtx.upstreamError = message.slice(0, 500);
|
|
415
447
|
if (logCtx.activeAttempt) logCtx.activeAttempt.streamAborted = true;
|
|
416
448
|
finalize(502, { terminalStatus: "failed", closeReason: "terminal" });
|
|
417
|
-
|
|
449
|
+
if (deliveryFailed) { clientFilter?.dispose(); try { controller.error(err); } catch { /* torn down */ } }
|
|
450
|
+
else closeWithErrorFrame("api_error", message, "read");
|
|
418
451
|
reader.cancel(err).catch(() => {});
|
|
419
452
|
}
|
|
420
453
|
},
|
|
421
454
|
cancel(reason) {
|
|
455
|
+
clientFilter?.dispose();
|
|
422
456
|
if (!settled) {
|
|
423
457
|
settled = true;
|
|
424
458
|
idle.cancel();
|
|
@@ -463,7 +497,7 @@ export function sanitizePassthroughToolCallIds(messages: unknown[]): void {
|
|
|
463
497
|
const field = fieldOf(block);
|
|
464
498
|
if (!field || typeof block[field] !== "string") continue;
|
|
465
499
|
const wire = callIds.allocate(block[field] as string);
|
|
466
|
-
if (wire === undefined) throw new AnthropicRequestError(
|
|
500
|
+
if (wire === undefined) throw markProxyError(new AnthropicRequestError(field === "id" ? "tool_use block has an empty id" : "tool_result block has an empty tool_use_id"));
|
|
467
501
|
block[field] = wire;
|
|
468
502
|
}
|
|
469
503
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MESSAGES_SSE_ERROR_HOLD_BYTES, MessagesSseFrameContext, messagesSseErrorPayload, messagesSseOversizePayload,
|
|
3
|
+
} from "../lib/messages-sse-error-presentation";
|
|
4
|
+
import { sseFieldValue } from "../lib/sse-decoder";
|
|
5
|
+
|
|
6
|
+
const encoder = new TextEncoder();
|
|
7
|
+
type Newline = "\n" | "\r" | "\r\n";
|
|
8
|
+
/** Final errors emit only data fields after the already-public, closed error declaration. */
|
|
9
|
+
function ownedSuffix(bytes: Uint8Array, space: boolean, newline: Newline): Uint8Array {
|
|
10
|
+
const text = new TextDecoder().decode(bytes);
|
|
11
|
+
const lines = [...text.matchAll(/([^\r\n]*)(\r\n|\r|\n|$)/g)].filter(match => match[0] !== "");
|
|
12
|
+
const data = lines.map(line => sseFieldValue(line[1]!, "data")).filter(value => value !== null).join("\n");
|
|
13
|
+
// An empty named error still dispatches the SDK's generic APIError; add no parseable data.
|
|
14
|
+
if (data === "") return encoder.encode(lines.filter(line => sseFieldValue(line[1]!, "data") !== null).map(line => line[0]).join(""));
|
|
15
|
+
const payload = messagesSseErrorPayload(data);
|
|
16
|
+
let replaced = false;
|
|
17
|
+
return encoder.encode(lines.map(line => {
|
|
18
|
+
if (sseFieldValue(line[1]!, "data") === null) return "";
|
|
19
|
+
if (replaced) return "";
|
|
20
|
+
replaced = true;
|
|
21
|
+
return `data:${space ? " " : ""}${payload}${line[2] ? newline : ""}`;
|
|
22
|
+
}).join(""));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface MessagesSseErrorFilter {
|
|
26
|
+
push(value: Uint8Array, emit: (bytes: Uint8Array) => void): void;
|
|
27
|
+
finish(emit: (bytes: Uint8Array) => void): void;
|
|
28
|
+
dispose(): void;
|
|
29
|
+
}
|
|
30
|
+
/** Final client-only delivery on the existing enqueue turn; no new queue, pump or admission. */
|
|
31
|
+
export function createMessagesSseErrorFilter(context = new MessagesSseFrameContext()): MessagesSseErrorFilter {
|
|
32
|
+
let disposed = false;
|
|
33
|
+
let hold: Uint8Array | undefined, held = 0, oversize = false;
|
|
34
|
+
let eligibility: "unseen" | "first" | "pass" | "error" = "unseen";
|
|
35
|
+
let lastError = false, headerSpace = true, newline: Newline = "\n";
|
|
36
|
+
let lineLength = 0, comment = false, namePosition = 0, nameMatches = true;
|
|
37
|
+
let inValue = false, eventField = false, optionalSpace = true, valuePosition = 0, valueMatches = true, fieldSpace = false;
|
|
38
|
+
let skipLf = false, headerCr = false, suppressLf = false;
|
|
39
|
+
let bomPosition = 0, atStreamStart = true;
|
|
40
|
+
const clearHold = () => { hold = undefined; held = 0; oversize = false; };
|
|
41
|
+
const resetLine = () => {
|
|
42
|
+
lineLength = 0; comment = false; namePosition = 0; nameMatches = true;
|
|
43
|
+
inValue = false; eventField = false; optionalSpace = true; valuePosition = 0; valueMatches = true; fieldSpace = false;
|
|
44
|
+
};
|
|
45
|
+
const resetBlock = () => { eligibility = "unseen"; lastError = false; clearHold(); };
|
|
46
|
+
const retain = (byte: number) => {
|
|
47
|
+
if (oversize) return;
|
|
48
|
+
if (held === MESSAGES_SSE_ERROR_HOLD_BYTES) { hold = undefined; held = 0; oversize = true; return; }
|
|
49
|
+
hold ??= new Uint8Array(MESSAGES_SSE_ERROR_HOLD_BYTES);
|
|
50
|
+
hold[held++] = byte;
|
|
51
|
+
};
|
|
52
|
+
const fieldByte = (byte: number) => {
|
|
53
|
+
if (lineLength++ === 0) {
|
|
54
|
+
comment = byte === 58;
|
|
55
|
+
if (!comment && eligibility === "unseen") eligibility = "first";
|
|
56
|
+
}
|
|
57
|
+
if (comment) return;
|
|
58
|
+
if (!inValue) {
|
|
59
|
+
if (byte === 58) { inValue = true; eventField = nameMatches && namePosition === 5; }
|
|
60
|
+
else { nameMatches &&= byte === "event".charCodeAt(namePosition); namePosition = Math.min(6, namePosition + 1); }
|
|
61
|
+
} else {
|
|
62
|
+
if (optionalSpace) { optionalSpace = false; if (byte === 32) { fieldSpace = true; return; } }
|
|
63
|
+
valueMatches &&= byte === "error".charCodeAt(valuePosition);
|
|
64
|
+
valuePosition = Math.min(6, valuePosition + 1);
|
|
65
|
+
}
|
|
66
|
+
// Mismatching first fields become permanently ordinary immediately.
|
|
67
|
+
if (eligibility === "first" && (!nameMatches || inValue && (!eventField || !valueMatches))) eligibility = "pass";
|
|
68
|
+
};
|
|
69
|
+
const finishField = (ending: number) => {
|
|
70
|
+
if (comment) return;
|
|
71
|
+
const error = eventField && valueMatches && valuePosition === 5;
|
|
72
|
+
if (eligibility === "first") {
|
|
73
|
+
eligibility = error ? "error" : "pass";
|
|
74
|
+
if (error) {
|
|
75
|
+
lastError = true; headerSpace = fieldSpace; newline = ending === 13 ? "\r" : "\n";
|
|
76
|
+
headerCr = ending === 13;
|
|
77
|
+
}
|
|
78
|
+
} else if (eligibility === "error" && (eventField || !inValue && nameMatches && namePosition === 5)) lastError = error;
|
|
79
|
+
};
|
|
80
|
+
const finishError = (emit: (bytes: Uint8Array) => void, delimiter: boolean, ending?: number): boolean => {
|
|
81
|
+
const forced = oversize;
|
|
82
|
+
if (forced) {
|
|
83
|
+
emit(encoder.encode(`data:${headerSpace ? " " : ""}${messagesSseOversizePayload()}${delimiter ? newline + newline : ""}`));
|
|
84
|
+
} else {
|
|
85
|
+
const suffix = hold?.subarray(0, held) ?? new Uint8Array();
|
|
86
|
+
emit(lastError ? ownedSuffix(suffix, headerSpace, newline) : suffix);
|
|
87
|
+
if (delimiter) emit(lastError ? encoder.encode(newline) : new Uint8Array([ending!]));
|
|
88
|
+
}
|
|
89
|
+
const suppressContinuation = delimiter && (forced || lastError);
|
|
90
|
+
resetBlock();
|
|
91
|
+
return suppressContinuation;
|
|
92
|
+
};
|
|
93
|
+
const scan = (value: Uint8Array, emit: (bytes: Uint8Array) => void) => {
|
|
94
|
+
let start = 0;
|
|
95
|
+
const forward = (end: number) => { if (end > start) emit(start === 0 && end === value.length ? value : value.subarray(start, end)); start = end; };
|
|
96
|
+
for (let i = 0; i < value.length; i++) {
|
|
97
|
+
const byte = value[i]!;
|
|
98
|
+
if (atStreamStart) {
|
|
99
|
+
const bom = [239, 187, 191];
|
|
100
|
+
if (byte === bom[bomPosition]) { bomPosition++; if (bomPosition === 3) atStreamStart = false; continue; }
|
|
101
|
+
atStreamStart = false;
|
|
102
|
+
if (bomPosition > 0) eligibility = "pass";
|
|
103
|
+
}
|
|
104
|
+
if (skipLf) {
|
|
105
|
+
skipLf = false;
|
|
106
|
+
if (byte === 10) {
|
|
107
|
+
const declarationLf = headerCr;
|
|
108
|
+
if (headerCr) { newline = "\r\n"; headerCr = false; }
|
|
109
|
+
if (suppressLf) { forward(i); start = i + 1; suppressLf = false; }
|
|
110
|
+
else if (eligibility === "error" && !declarationLf) {
|
|
111
|
+
// The first declaration's optional LF is already public; suffix CRLF belongs to the hold.
|
|
112
|
+
forward(i); retain(byte); start = i + 1;
|
|
113
|
+
}
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
headerCr = false; suppressLf = false;
|
|
117
|
+
}
|
|
118
|
+
const holding = eligibility === "error";
|
|
119
|
+
if (byte === 10 || byte === 13) {
|
|
120
|
+
skipLf = byte === 13;
|
|
121
|
+
if (lineLength === 0) {
|
|
122
|
+
if (holding) {
|
|
123
|
+
forward(i); suppressLf = finishError(emit, true, byte); start = i + 1;
|
|
124
|
+
} else resetBlock();
|
|
125
|
+
} else {
|
|
126
|
+
if (holding) { forward(i); retain(byte); start = i + 1; }
|
|
127
|
+
finishField(byte);
|
|
128
|
+
// A just-confirmed declaration remains part of this original public prefix.
|
|
129
|
+
if (!holding && eligibility === "error") forward(i + 1);
|
|
130
|
+
}
|
|
131
|
+
resetLine();
|
|
132
|
+
} else {
|
|
133
|
+
if (holding) { forward(i); retain(byte); start = i + 1; }
|
|
134
|
+
fieldByte(byte);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
forward(value.length);
|
|
138
|
+
};
|
|
139
|
+
return {
|
|
140
|
+
push(value, deliver) {
|
|
141
|
+
if (disposed) return;
|
|
142
|
+
if (value.length === 0 && eligibility !== "error") { deliver(value); return; }
|
|
143
|
+
const emit = (bytes: Uint8Array) => { if (bytes.length) deliver(bytes); };
|
|
144
|
+
try {
|
|
145
|
+
const origin = context.take(value);
|
|
146
|
+
if (origin && "client" in origin) {
|
|
147
|
+
const prefix = value[0] === 10 && value[1] === 10 ? 2 : 0;
|
|
148
|
+
const ordinary = eligibility !== "error";
|
|
149
|
+
if (prefix) scan(value.subarray(0, prefix), ordinary ? () => {} : emit);
|
|
150
|
+
emit(ordinary ? origin.client : origin.client.subarray(prefix));
|
|
151
|
+
resetBlock(); resetLine(); skipLf = false;
|
|
152
|
+
} else if (origin?.echoRenamedError) {
|
|
153
|
+
const header = encoder.encode("event: message_start\n");
|
|
154
|
+
if (eligibility !== "unseen" || lineLength || !header.every((byte, index) => value[index] === byte)
|
|
155
|
+
|| value.at(-1) !== 10 || value.at(-2) !== 10) throw new Error("The proxy could not reach or read the provider.");
|
|
156
|
+
emit(value.subarray(0, header.length));
|
|
157
|
+
const suffix = value.subarray(header.length, value.length - 1);
|
|
158
|
+
emit(suffix.length > MESSAGES_SSE_ERROR_HOLD_BYTES ? encoder.encode(`data: ${messagesSseOversizePayload()}\n`) : ownedSuffix(suffix, true, "\n"));
|
|
159
|
+
emit(encoder.encode("\n"));
|
|
160
|
+
resetBlock(); resetLine(); skipLf = false;
|
|
161
|
+
} else scan(value, emit);
|
|
162
|
+
} catch (error) { clearHold(); disposed = true; throw error; }
|
|
163
|
+
},
|
|
164
|
+
finish(emit) {
|
|
165
|
+
if (disposed) return;
|
|
166
|
+
try {
|
|
167
|
+
if (eligibility === "error") {
|
|
168
|
+
if (lineLength) finishField(10);
|
|
169
|
+
finishError(bytes => { if (bytes.length) emit(bytes); }, false);
|
|
170
|
+
}
|
|
171
|
+
} finally { clearHold(); disposed = true; }
|
|
172
|
+
},
|
|
173
|
+
dispose() { disposed = true; resetBlock(); resetLine(); skipLf = false; headerCr = false; suppressLf = false; },
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Standalone reader adapter for callers without an existing final enqueue stage. */
|
|
178
|
+
export function filterMessagesSseErrors(source: ReadableStream<Uint8Array>, context?: MessagesSseFrameContext): ReadableStream<Uint8Array> {
|
|
179
|
+
const reader = source.getReader(), filter = createMessagesSseErrorFilter(context);
|
|
180
|
+
let cancelled = false;
|
|
181
|
+
return new ReadableStream<Uint8Array>({
|
|
182
|
+
async pull(controller) {
|
|
183
|
+
let emitted = false;
|
|
184
|
+
const emit = (bytes: Uint8Array) => { controller.enqueue(bytes); emitted = true; };
|
|
185
|
+
try {
|
|
186
|
+
do {
|
|
187
|
+
const { done, value } = await reader.read();
|
|
188
|
+
if (cancelled) return;
|
|
189
|
+
if (done) { filter.finish(emit); controller.close(); return; }
|
|
190
|
+
filter.push(value, emit);
|
|
191
|
+
} while (!emitted);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
filter.dispose();
|
|
194
|
+
if (!cancelled) { cancelled = true; void reader.cancel(error).catch(() => {}); controller.error(error); }
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
cancel(reason) { cancelled = true; filter.dispose(); return reader.cancel(reason); },
|
|
198
|
+
}, { highWaterMark: 0 });
|
|
199
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Final request-log ownership for a native ingress that converts an inner Chat response.
|
|
3
|
+
*
|
|
4
|
+
* The inner Chat path keeps its own observation, attempt and usage accounting and its own
|
|
5
|
+
* callback ordering. Its final-log requests are intercepted: the first one is recorded as the
|
|
6
|
+
* physical attempt's settlement and nothing is written. The native handler, which alone knows
|
|
7
|
+
* whether its conversion succeeded or the client went away, commits exactly once through the
|
|
8
|
+
* ordinary writer. Later inner requests stay inert, so a delayed callback cannot add a row.
|
|
9
|
+
*/
|
|
10
|
+
import type { ResponsesTerminalStatus } from "../bridge";
|
|
11
|
+
import {
|
|
12
|
+
addRequestLog,
|
|
13
|
+
commitInterceptedFinalRequestLog,
|
|
14
|
+
interceptFinalRequestLog,
|
|
15
|
+
type RequestLogContext,
|
|
16
|
+
type RequestLogEntry,
|
|
17
|
+
} from "./request-log";
|
|
18
|
+
|
|
19
|
+
/** How long a known outer outcome waits for a missing inner settlement before cutting off. */
|
|
20
|
+
export const NATIVE_FINAL_LOG_FALLBACK_MS = 100;
|
|
21
|
+
export const NATIVE_FINAL_LOG_CUTOFF_CODE = "observation_barrier_timeout";
|
|
22
|
+
|
|
23
|
+
export interface NativeFinalOutcome {
|
|
24
|
+
status: number;
|
|
25
|
+
terminalStatus?: ResponsesTerminalStatus;
|
|
26
|
+
closeReason: NonNullable<RequestLogEntry["closeReason"]>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface NativeFinalLog {
|
|
30
|
+
/** True once the inner path requested its final log. */
|
|
31
|
+
innerSettled(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Call once the outer outcome is known. Resolves true when the inner path has settled, or
|
|
34
|
+
* false when the bounded fallback elapsed first. Never waits on an upstream cancellation.
|
|
35
|
+
*/
|
|
36
|
+
waitForInner(): Promise<boolean>;
|
|
37
|
+
/** Write the single row. Returns false when a row was already committed. */
|
|
38
|
+
commit(outcome: NativeFinalOutcome): boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createNativeFinalLog(
|
|
42
|
+
requestId: string,
|
|
43
|
+
start: number,
|
|
44
|
+
logCtx: RequestLogContext,
|
|
45
|
+
options: { fallbackMs?: number; addLog?: (entry: RequestLogEntry) => void } = {},
|
|
46
|
+
): NativeFinalLog {
|
|
47
|
+
const fallbackMs = options.fallbackMs ?? NATIVE_FINAL_LOG_FALLBACK_MS;
|
|
48
|
+
let innerStatus: number | undefined;
|
|
49
|
+
let wake: (() => void) | undefined;
|
|
50
|
+
let waiting: Promise<boolean> | undefined;
|
|
51
|
+
let committed = false;
|
|
52
|
+
interceptFinalRequestLog(logCtx, status => {
|
|
53
|
+
if (innerStatus !== undefined) return;
|
|
54
|
+
innerStatus = status;
|
|
55
|
+
// Resolved on a later microtask, so observations the inner producer makes later in the same
|
|
56
|
+
// synchronous pass (a relay's completed-response hook, for example) land before the commit.
|
|
57
|
+
wake?.();
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
innerSettled: () => innerStatus !== undefined,
|
|
61
|
+
waitForInner() {
|
|
62
|
+
waiting ??= innerStatus !== undefined
|
|
63
|
+
? Promise.resolve(true)
|
|
64
|
+
: new Promise<boolean>(resolve => {
|
|
65
|
+
const timer = setTimeout(() => { wake = undefined; resolve(innerStatus !== undefined); }, fallbackMs);
|
|
66
|
+
wake = () => { clearTimeout(timer); wake = undefined; resolve(true); };
|
|
67
|
+
});
|
|
68
|
+
return waiting;
|
|
69
|
+
},
|
|
70
|
+
commit(outcome) {
|
|
71
|
+
if (committed) return false;
|
|
72
|
+
committed = true;
|
|
73
|
+
// Upstream evidence stays on the context so the final writer can classify it; the row
|
|
74
|
+
// projection (src/usage/error-detail.ts) removes upstream-authored text before any writer.
|
|
75
|
+
let { status, terminalStatus } = outcome;
|
|
76
|
+
if (innerStatus === undefined) {
|
|
77
|
+
// Cut off before the inner path settled: what it observed so far is not a complete
|
|
78
|
+
// account. Drop it, so the row reads unreported and the terminal send settles as
|
|
79
|
+
// unresolved rather than being priced from a partial count, and never report success.
|
|
80
|
+
delete logCtx.usage;
|
|
81
|
+
delete logCtx.usageLogInputTokens;
|
|
82
|
+
if (logCtx.activeAttempt) delete logCtx.activeAttempt.usage;
|
|
83
|
+
logCtx.errorCode = NATIVE_FINAL_LOG_CUTOFF_CODE;
|
|
84
|
+
if (status < 400) { status = 502; terminalStatus = "failed"; }
|
|
85
|
+
}
|
|
86
|
+
commitInterceptedFinalRequestLog(requestId, start, logCtx, status, {
|
|
87
|
+
...(terminalStatus ? { terminalStatus } : {}),
|
|
88
|
+
closeReason: status === 499 ? "client_cancel" : outcome.closeReason,
|
|
89
|
+
}, innerStatus ?? status, options.addLog ?? addRequestLog);
|
|
90
|
+
return true;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|