@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
|
@@ -11,6 +11,7 @@ import { CLAUDE_CODE_HEADERS, claudeCodeSessionId } from "../adapters/client-fin
|
|
|
11
11
|
import { signalWithTimeout, cancelBodyOnAbort } from "../lib/abort";
|
|
12
12
|
import { sidecarEnter } from "../lib/sidecar-tracker";
|
|
13
13
|
import { applyUpstreamRecoveryInit, fetchWithResetRetry } from "../lib/upstream-retry";
|
|
14
|
+
import { sseFieldValue } from "../lib/sse-decoder";
|
|
14
15
|
import {
|
|
15
16
|
MAX_SIDECAR_RESPONSE_BYTES,
|
|
16
17
|
cancelReaderWithoutWaiting,
|
|
@@ -22,6 +23,8 @@ import { BASE_INSTRUCTION, IMAGE_INSTRUCTION, type SidecarOutcome, type SidecarS
|
|
|
22
23
|
const ANTHROPIC_MAX_USES = 3;
|
|
23
24
|
/** Answer budget; the injected tool_result is clamped downstream, so this only bounds the sidecar turn. */
|
|
24
25
|
const ANTHROPIC_MAX_TOKENS = 8192;
|
|
26
|
+
/** A terminal exactly at the wire cap must prove EOF without holding a reader indefinitely. */
|
|
27
|
+
const ANTHROPIC_CAP_EOF_PROBE_TIMEOUT_MS = 1_000;
|
|
25
28
|
|
|
26
29
|
function isRec(v: unknown): v is Record<string, unknown> {
|
|
27
30
|
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
@@ -60,7 +63,8 @@ async function readBoundedText(res: Response): Promise<string> {
|
|
|
60
63
|
* Anthropic streams the FULL `web_search_tool_result.content` array on `content_block_start` (not via
|
|
61
64
|
* deltas), so sources are collected there; the answer text arrives as `text_delta` events, and
|
|
62
65
|
* `citations_delta` (web_search_result_location) contributes any additional cited URLs. A
|
|
63
|
-
* `web_search_tool_result_error` content object yields
|
|
66
|
+
* `web_search_tool_result_error` content object yields an error. Never throws; partial text is
|
|
67
|
+
* retained with an error when the search or stream did not complete successfully.
|
|
64
68
|
*/
|
|
65
69
|
export async function parseAnthropicSidecarSSE(res: Response): Promise<SidecarOutcome> {
|
|
66
70
|
const sources: WebSearchSource[] = [];
|
|
@@ -73,6 +77,10 @@ export async function parseAnthropicSidecarSSE(res: Response): Promise<SidecarOu
|
|
|
73
77
|
|
|
74
78
|
let text = "";
|
|
75
79
|
let sawToolResultError = false;
|
|
80
|
+
let failure: string | undefined;
|
|
81
|
+
let sawMessageStop = false;
|
|
82
|
+
let cleanEof = false;
|
|
83
|
+
let stopReason: string | undefined;
|
|
76
84
|
if (!res.body) return { text: "", sources, error: "anthropic sidecar returned no response body" };
|
|
77
85
|
|
|
78
86
|
const decoder = new TextDecoder();
|
|
@@ -80,8 +88,21 @@ export async function parseAnthropicSidecarSSE(res: Response): Promise<SidecarOu
|
|
|
80
88
|
let buffer = "";
|
|
81
89
|
let responseBytes = 0;
|
|
82
90
|
|
|
83
|
-
const handleFrame = (data: Record<string, unknown
|
|
84
|
-
|
|
91
|
+
const handleFrame = (data: Record<string, unknown>, type: string, complete: boolean): void => {
|
|
92
|
+
if (type === "ping") return;
|
|
93
|
+
if (sawMessageStop) failure ??= "anthropic sidecar returned data after completion";
|
|
94
|
+
cleanEof = false;
|
|
95
|
+
if (type === "error") {
|
|
96
|
+
failure ??= "anthropic sidecar returned a stream error";
|
|
97
|
+
} else if (type === "message_stop") {
|
|
98
|
+
sawMessageStop = true;
|
|
99
|
+
} else if (type === "message_delta") {
|
|
100
|
+
const delta = isRec(data.delta) ? data.delta : {};
|
|
101
|
+
if (typeof delta.stop_reason === "string") {
|
|
102
|
+
stopReason = delta.stop_reason;
|
|
103
|
+
cleanEof = complete;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
85
106
|
if (type === "content_block_start") {
|
|
86
107
|
const block = isRec(data.content_block) ? data.content_block : {};
|
|
87
108
|
if (block.type === "web_search_tool_result") {
|
|
@@ -105,15 +126,61 @@ export async function parseAnthropicSidecarSSE(res: Response): Promise<SidecarOu
|
|
|
105
126
|
};
|
|
106
127
|
|
|
107
128
|
// Parse one SSE frame's `data:` payload and fold it. Shared by the streaming loop and the EOF flush.
|
|
108
|
-
const processFrame = (rawFrame: string): void => {
|
|
109
|
-
|
|
129
|
+
const processFrame = (rawFrame: string, complete = true): void => {
|
|
130
|
+
const invalidFrame = (): void => {
|
|
131
|
+
cleanEof = false;
|
|
132
|
+
failure ??= sawMessageStop
|
|
133
|
+
? "anthropic sidecar returned data after completion"
|
|
134
|
+
: "anthropic sidecar returned an invalid stream frame";
|
|
135
|
+
};
|
|
136
|
+
const dataLines: string[] = [];
|
|
137
|
+
let eventName: string | undefined;
|
|
110
138
|
for (const line of rawFrame.split("\n")) {
|
|
111
|
-
|
|
139
|
+
const dataValue = sseFieldValue(line, "data");
|
|
140
|
+
if (dataValue !== null) dataLines.push(dataValue);
|
|
141
|
+
const eventValue = sseFieldValue(line, "event");
|
|
142
|
+
if (eventValue !== null) eventName = eventValue;
|
|
112
143
|
}
|
|
113
|
-
if (
|
|
144
|
+
if (eventName === "ping") return;
|
|
145
|
+
if (dataLines.length === 0 && (complete || rawFrame.split("\n").every(line => !line.trim() || line.startsWith(":")))) return;
|
|
146
|
+
const dataLine = dataLines.join("\n");
|
|
147
|
+
if (!dataLine || dataLine === "[DONE]") { invalidFrame(); return; }
|
|
114
148
|
let data: unknown;
|
|
115
|
-
try { data = JSON.parse(dataLine); } catch { return; }
|
|
116
|
-
if (isRec(data))
|
|
149
|
+
try { data = JSON.parse(dataLine); } catch { invalidFrame(); return; }
|
|
150
|
+
if (isRec(data)) {
|
|
151
|
+
const type = eventName || (typeof data.type === "string" ? data.type : "");
|
|
152
|
+
handleFrame(data, type, complete);
|
|
153
|
+
} else invalidFrame();
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const processCompleteFrames = (): void => {
|
|
157
|
+
let sep: number;
|
|
158
|
+
while ((sep = buffer.indexOf("\n\n")) !== -1) {
|
|
159
|
+
const rawFrame = buffer.slice(0, sep);
|
|
160
|
+
buffer = buffer.slice(sep + 2);
|
|
161
|
+
processFrame(rawFrame);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const verifyEofAtCap = async (): Promise<boolean> => {
|
|
166
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
167
|
+
let expired = false;
|
|
168
|
+
const timeout = new Promise<null>(resolve => {
|
|
169
|
+
timer = setTimeout(() => { expired = true; resolve(null); }, ANTHROPIC_CAP_EOF_PROBE_TIMEOUT_MS);
|
|
170
|
+
});
|
|
171
|
+
try {
|
|
172
|
+
for (;;) {
|
|
173
|
+
if (expired) return false;
|
|
174
|
+
const next = await Promise.race([reader.read(), timeout]);
|
|
175
|
+
if (expired || next === null) return false;
|
|
176
|
+
if (next.done) return true;
|
|
177
|
+
if (next.value.byteLength > 0) return false;
|
|
178
|
+
// A source that synchronously produces empty chunks must not starve the probe timer.
|
|
179
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
180
|
+
}
|
|
181
|
+
} catch {
|
|
182
|
+
return false;
|
|
183
|
+
} finally { if (timer !== undefined) clearTimeout(timer); }
|
|
117
184
|
};
|
|
118
185
|
|
|
119
186
|
try {
|
|
@@ -125,33 +192,47 @@ export async function parseAnthropicSidecarSSE(res: Response): Promise<SidecarOu
|
|
|
125
192
|
const remaining = MAX_SIDECAR_RESPONSE_BYTES - responseBytes;
|
|
126
193
|
const accepted = value.byteLength <= remaining ? value : value.subarray(0, remaining);
|
|
127
194
|
responseBytes += accepted.byteLength;
|
|
128
|
-
//
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
let sep: number;
|
|
132
|
-
while ((sep = buffer.indexOf("\n\n")) !== -1) {
|
|
133
|
-
const rawFrame = buffer.slice(0, sep);
|
|
134
|
-
buffer = buffer.slice(sep + 2);
|
|
135
|
-
processFrame(rawFrame);
|
|
136
|
-
}
|
|
195
|
+
// Preserve a trailing CR until the next chunk so split CRLF remains one line break.
|
|
196
|
+
buffer = (buffer + decoder.decode(accepted, { stream: true })).replace(/\r\n/g, "\n").replace(/\r(?!$)/g, "\n");
|
|
197
|
+
processCompleteFrames();
|
|
137
198
|
if (responseBytes >= MAX_SIDECAR_RESPONSE_BYTES) {
|
|
138
|
-
//
|
|
139
|
-
|
|
199
|
+
// A trailing CR can complete a CR-only terminal delimiter at the exact boundary.
|
|
200
|
+
if (buffer.endsWith("\r")) {
|
|
201
|
+
buffer = buffer.slice(0, -1) + "\n";
|
|
202
|
+
processCompleteFrames();
|
|
203
|
+
}
|
|
204
|
+
const trailingCommentsOnly = buffer.split("\n").every(line => !line.trim() || line.startsWith(":"));
|
|
205
|
+
// A complete terminal or stop-reason delta at the cap needs bounded EOF proof; an
|
|
206
|
+
// oversized chunk or partial trailing frame is an error. Never await upstream teardown.
|
|
207
|
+
if ((!sawMessageStop && !cleanEof) || value.byteLength > remaining || !trailingCommentsOnly) {
|
|
208
|
+
failure ??= "anthropic sidecar response exceeded the byte limit";
|
|
209
|
+
} else if (!failure && !sawToolResultError
|
|
210
|
+
&& (stopReason === undefined || stopReason === "end_turn" || stopReason === "stop_sequence")
|
|
211
|
+
&& !(await verifyEofAtCap())) {
|
|
212
|
+
failure = "anthropic sidecar response byte limit reached before EOF";
|
|
213
|
+
}
|
|
140
214
|
cancelReaderWithoutWaiting(reader, "sidecar response byte limit reached");
|
|
141
215
|
buffer = "";
|
|
142
216
|
break;
|
|
143
217
|
}
|
|
144
218
|
}
|
|
145
219
|
// Flush the decoder and process any final unterminated frame (a stream that ends without \n\n).
|
|
146
|
-
buffer = (buffer + decoder.decode()).replace(/\r\n/g, "\n");
|
|
147
|
-
|
|
220
|
+
buffer = (buffer + decoder.decode()).replace(/\r\n|\r/g, "\n");
|
|
221
|
+
processCompleteFrames();
|
|
222
|
+
if (buffer.trim().length > 0) processFrame(buffer, false);
|
|
148
223
|
} catch {
|
|
149
|
-
|
|
224
|
+
failure ??= "anthropic sidecar stream could not be read";
|
|
150
225
|
}
|
|
151
226
|
|
|
152
227
|
const trimmed = text.trim();
|
|
228
|
+
if (sawToolResultError) failure ??= "anthropic web search returned an error result";
|
|
229
|
+
if (stopReason !== undefined && stopReason !== "end_turn" && stopReason !== "stop_sequence") {
|
|
230
|
+
failure ??= "anthropic sidecar produced an incomplete answer";
|
|
231
|
+
}
|
|
232
|
+
if (!sawMessageStop && !cleanEof) failure ??= "anthropic sidecar stream ended before completion";
|
|
233
|
+
if (failure) return { text: trimmed, sources, error: failure };
|
|
153
234
|
if (trimmed.length === 0) {
|
|
154
|
-
return { text: "", sources, error:
|
|
235
|
+
return { text: "", sources, error: "anthropic sidecar produced no answer" };
|
|
155
236
|
}
|
|
156
237
|
return { text: trimmed, sources };
|
|
157
238
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OcxProviderConfig } from "../types";
|
|
2
|
-
import { mergeCodexSelectedHeaders } from "../codex/forward-transport-headers";
|
|
2
|
+
import { CODEX_RESPONSES_LITE_HEADER, mergeCodexSelectedHeaders } from "../codex/forward-transport-headers";
|
|
3
3
|
import { signalWithTimeout, cancelBodyOnAbort } from "../lib/abort";
|
|
4
4
|
import { redactSecretString } from "../lib/redact";
|
|
5
5
|
import { sidecarEnter } from "../lib/sidecar-tracker";
|
|
@@ -84,9 +84,11 @@ export async function runWebSearch(
|
|
|
84
84
|
if (settings.reserveCompatibility && settings.model === NATIVE_RESERVE_MODEL) {
|
|
85
85
|
return { text: "", sources: [], error: "Luna Reserve compatibility is only available as a conversation model, not a search helper. Choose another search helper model." };
|
|
86
86
|
}
|
|
87
|
-
const
|
|
87
|
+
const mergedHeaders = mergeCodexSelectedHeaders(
|
|
88
88
|
{ "Content-Type": "application/json", ...forwardProvider.headers }, selectedForwardHeaders,
|
|
89
|
-
)
|
|
89
|
+
);
|
|
90
|
+
mergedHeaders.delete(CODEX_RESPONSES_LITE_HEADER);
|
|
91
|
+
const headers = Object.fromEntries(mergedHeaders);
|
|
90
92
|
const body = {
|
|
91
93
|
model: settings.model,
|
|
92
94
|
instructions: settings.describeImages ? BASE_INSTRUCTION + IMAGE_INSTRUCTION : BASE_INSTRUCTION,
|
package/src/web-search/loop.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { bridgeToResponsesSSE } from "../bridge";
|
|
|
14
14
|
import { guardEmptyToolCatalogStream, type ClientToolCatalogRestriction } from "../lib/empty-tool-catalog";
|
|
15
15
|
import { mergeUsage } from "../server/responses/empty-completion-guard";
|
|
16
16
|
import { markSidecarContextOverflow, sidecarLoopTerminalEvent, upstreamErrorCode, type SidecarLoopFailure } from "../server/responses/context-overflow";
|
|
17
|
-
import { markVerifiedModelNotInPlanResponse, MODEL_NOT_IN_PLAN_CODE, verifiedPlanRefusalMessage } from "../lib/errors";
|
|
17
|
+
import { markVerifiedModelNotInPlanResponse, MODEL_NOT_IN_PLAN_CODE, UNDECLARED_TOOL_CALL_ERROR_CODE, verifiedPlanRefusalMessage } from "../lib/errors";
|
|
18
18
|
import { runWebSearch, type SidecarOutcome, type SidecarOutcomeRecorder, type SidecarSettings } from "./executor";
|
|
19
19
|
import { runAnthropicWebSearch } from "./anthropic-executor";
|
|
20
20
|
import { runXaiWebSearch, type XaiSearchOptions } from "./xai-executor";
|
|
@@ -33,7 +33,7 @@ import {
|
|
|
33
33
|
TranslatorBudgetExceededError,
|
|
34
34
|
} from "../lib/translator-budget";
|
|
35
35
|
import { formatWebSearchResults } from "./format-result";
|
|
36
|
-
import { parseStreamWithProgress, RoutedModelInactivityError, WebSearchStreamProtocolError, WebSearchAdapterEventError } from "./progress-stream";
|
|
36
|
+
import { parseStreamWithProgress, RoutedModelInactivityError, WebSearchConsumerInactivityError, WebSearchStreamProtocolError, WebSearchAdapterEventError } from "./progress-stream";
|
|
37
37
|
import { WEB_SEARCH_TOOL_NAME } from "./synthetic-tool";
|
|
38
38
|
import { newSidecarSearchCellId, rememberSidecarSearch, restoreSidecarSearchResults } from "./sidecar-search-replay";
|
|
39
39
|
import {
|
|
@@ -90,7 +90,7 @@ function parseQueries(argsBuf: string): string[] {
|
|
|
90
90
|
* (Codex never sees the synthetic tool); every other event — text, thinking, real tool calls, done —
|
|
91
91
|
* is preserved in order.
|
|
92
92
|
*/
|
|
93
|
-
export function scanEventsForWebSearch(events: AdapterEvent[], options: { advisor?: boolean } = {}): {
|
|
93
|
+
export function scanEventsForWebSearch(events: AdapterEvent[], options: { advisor?: boolean; clientAdvisorAllowed?: boolean } = {}): {
|
|
94
94
|
calls: WebSearchCall[];
|
|
95
95
|
passthrough: AdapterEvent[];
|
|
96
96
|
hasRealToolCall: boolean;
|
|
@@ -100,6 +100,7 @@ export function scanEventsForWebSearch(events: AdapterEvent[], options: { adviso
|
|
|
100
100
|
const passthrough: AdapterEvent[] = [];
|
|
101
101
|
let hasRealToolCall = false;
|
|
102
102
|
let hasMalformedToolCall = false;
|
|
103
|
+
let refusal: Extract<AdapterEvent, { type: "error" }> | undefined;
|
|
103
104
|
let pending: { name: string; id: string; argsBuf: string; closed: boolean; events: AdapterEvent[]; providerMetadata?: OcxProviderOpaqueToolCallMetadata } | null = null;
|
|
104
105
|
const isBlank = (value: string): boolean => value.trim().length === 0;
|
|
105
106
|
const flushPending = (): void => {
|
|
@@ -113,8 +114,18 @@ export function scanEventsForWebSearch(events: AdapterEvent[], options: { adviso
|
|
|
113
114
|
pending = null;
|
|
114
115
|
};
|
|
115
116
|
for (const e of events) {
|
|
117
|
+
if (refusal) {
|
|
118
|
+
if ((e.type === "done" || e.type === "incomplete" || e.type === "error") && e.usage) refusal.usage = e.usage;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
116
121
|
if (e.type === "tool_call_start") {
|
|
117
122
|
flushPending();
|
|
123
|
+
if (e.name === ADVISOR_TOOL_NAME && !options.advisor && !options.clientAdvisorAllowed) {
|
|
124
|
+
refusal = { type: "error", status: 502, errorType: "upstream_error", code: UNDECLARED_TOOL_CALL_ERROR_CODE,
|
|
125
|
+
message: "routed provider emitted advisor outside the current iteration's permitted tool catalog" };
|
|
126
|
+
passthrough.push(refusal);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
118
129
|
if (isBlank(e.id) || isBlank(e.name)) hasMalformedToolCall = true;
|
|
119
130
|
pending = { name: e.name, id: e.id, argsBuf: "", closed: false, events: [e], providerMetadata: e.providerMetadata };
|
|
120
131
|
} else if (e.type === "tool_call_delta") {
|
|
@@ -400,6 +411,7 @@ export interface WebSearchLoopDeps {
|
|
|
400
411
|
onFirstOutput?: () => void;
|
|
401
412
|
/** Raw adapter usage at the terminal event, pre wire-normalization (see bridgeToResponsesSSE onUsage). */
|
|
402
413
|
onUsage?: (usage: OcxUsage | undefined) => void;
|
|
414
|
+
proxyErrorContext?: object;
|
|
403
415
|
/**
|
|
404
416
|
* After an `on429` rotation, offered the usage of the hidden iterations the left credential
|
|
405
417
|
* served. Returning true means it was billed to that credential's attempt, so `onUsage` will not
|
|
@@ -513,6 +525,8 @@ export async function runWithWebSearch(deps: WebSearchLoopDeps): Promise<Respons
|
|
|
513
525
|
interface IterationResponse {
|
|
514
526
|
response: Response;
|
|
515
527
|
responseAdapter: ProviderAdapter;
|
|
528
|
+
clientAdvisorAllowed: boolean;
|
|
529
|
+
syntheticAdvisorAllowed: boolean;
|
|
516
530
|
recover?: (error: WebSearchAdapterEventError) => Promise<IterationResponse | undefined>;
|
|
517
531
|
}
|
|
518
532
|
type IterationSplit = ReturnType<typeof scanEventsForWebSearch> & {
|
|
@@ -692,7 +706,19 @@ export async function runWithWebSearch(deps: WebSearchLoopDeps): Promise<Respons
|
|
|
692
706
|
request.releaseBodyObservation?.();
|
|
693
707
|
}
|
|
694
708
|
bindAnthropicRejectionResponse(request, response);
|
|
695
|
-
|
|
709
|
+
const iterTools = iterParsed.context.tools ?? [];
|
|
710
|
+
const toolAllowed = toolChoiceToolPredicate(iterParsed.options.toolChoice, iterTools);
|
|
711
|
+
const clientAdvisorAllowed = iterTools.some(tool => !tool.advisor && !tool.namespace
|
|
712
|
+
&& tool.name === ADVISOR_TOOL_NAME && toolAllowed(tool));
|
|
713
|
+
const declaredAdvisor = iterTools.find(tool => tool.advisor && tool.name === ADVISOR_TOOL_NAME);
|
|
714
|
+
// Exhaustion removes the declaration, but its paired limit result still belongs
|
|
715
|
+
// to the sidecar. A tools-disabled recovery revokes that permission too.
|
|
716
|
+
const advisorCandidate = declaredAdvisor ?? { name: ADVISOR_TOOL_NAME };
|
|
717
|
+
const syntheticAdvisorAllowed = !!deps.advisor && !recoveringEmptyAnswer
|
|
718
|
+
&& (!!declaredAdvisor || deps.advisor.exhausted())
|
|
719
|
+
&& toolChoiceToolPredicate(iterParsed.options.toolChoice,
|
|
720
|
+
declaredAdvisor ? iterTools : [...iterTools, advisorCandidate])(advisorCandidate);
|
|
721
|
+
return { response, responseAdapter: requestAdapter, clientAdvisorAllowed, syntheticAdvisorAllowed };
|
|
696
722
|
};
|
|
697
723
|
|
|
698
724
|
const recover = async (error: WebSearchAdapterEventError): Promise<IterationResponse | undefined> => {
|
|
@@ -890,6 +916,7 @@ export async function runWithWebSearch(deps: WebSearchLoopDeps): Promise<Respons
|
|
|
890
916
|
}
|
|
891
917
|
if (error instanceof LoopError) throw error;
|
|
892
918
|
if (error instanceof RoutedModelInactivityError) throw new LoopError(504, error.message);
|
|
919
|
+
if (error instanceof WebSearchConsumerInactivityError) throw new LoopError(504, error.message);
|
|
893
920
|
if (error instanceof WebSearchStreamProtocolError) throw new LoopError(502, error.message);
|
|
894
921
|
throw new LoopError(502, `Provider stream error: ${error instanceof Error ? error.message : String(error)}`);
|
|
895
922
|
} finally { releaseCapture(); }
|
|
@@ -908,7 +935,7 @@ export async function runWithWebSearch(deps: WebSearchLoopDeps): Promise<Respons
|
|
|
908
935
|
throw new LoopError(502, terminal.message, terminal.code === "context_length_exceeded" ? terminal : undefined);
|
|
909
936
|
}
|
|
910
937
|
deps.thinkingRecovery?.observeIteration(events);
|
|
911
|
-
return { ...scanEventsForWebSearch(events, { advisor:
|
|
938
|
+
return { ...scanEventsForWebSearch(events, { advisor: prepared.syntheticAdvisorAllowed, clientAdvisorAllowed: prepared.clientAdvisorAllowed }), streamedPassthroughCount, events, anthropicReplay };
|
|
912
939
|
};
|
|
913
940
|
|
|
914
941
|
/**
|
|
@@ -1303,7 +1330,7 @@ export async function runWithWebSearch(deps: WebSearchLoopDeps): Promise<Respons
|
|
|
1303
1330
|
internalAbort.abort("client closed responses stream");
|
|
1304
1331
|
}, undefined,
|
|
1305
1332
|
{
|
|
1306
|
-
translatorBudget,
|
|
1333
|
+
translatorBudget, proxyErrorContext: deps.proxyErrorContext,
|
|
1307
1334
|
replayCacheScope: parsed._reasoningReplayScope,
|
|
1308
1335
|
...(deps.clientToolCatalogRestriction ? { ...deps.clientToolCatalogRestriction, enforceDeclaredToolNames: false } : {}),
|
|
1309
1336
|
...(deps.forceEmptyResponseId ? { responseId: "" } : {}),
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "../lib/translator-budget";
|
|
9
9
|
|
|
10
10
|
const DEFAULT_POST_TERMINAL_DRAIN_TIMEOUT_MS = 5_000;
|
|
11
|
+
const DEFAULT_CONSUMER_TIMEOUT_MS = 300_000;
|
|
11
12
|
|
|
12
13
|
export class RoutedModelInactivityError extends Error {
|
|
13
14
|
readonly timeoutMs: number;
|
|
@@ -26,6 +27,13 @@ export class WebSearchStreamProtocolError extends Error {
|
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
export class WebSearchConsumerInactivityError extends Error {
|
|
31
|
+
constructor(readonly timeoutMs: number) {
|
|
32
|
+
super(`Web-search consumer did not accept an event within ${timeoutMs}ms`);
|
|
33
|
+
this.name = "WebSearchConsumerInactivityError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
29
37
|
/** Opt-in preserves an adapter refusal before it becomes an untyped parser exception. */
|
|
30
38
|
export class WebSearchAdapterEventError extends Error {
|
|
31
39
|
constructor(readonly event: Extract<AdapterEvent, { type: "error" }>, readonly replaySafe: boolean) {
|
|
@@ -40,6 +48,8 @@ export interface ParseStreamWithProgressOptions {
|
|
|
40
48
|
signal?: AbortSignal;
|
|
41
49
|
/** Kept configurable for focused tests; production callers should use the 5 second default. */
|
|
42
50
|
postTerminalDrainTimeoutMs?: number;
|
|
51
|
+
/** Bounds an abandoned downstream consumer separately from upstream byte inactivity. */
|
|
52
|
+
consumerTimeoutMs?: number;
|
|
43
53
|
/** Receives the usage an adapter `error` event carries before the stream fails on it. */
|
|
44
54
|
onErrorUsage?: (usage: OcxUsage) => void;
|
|
45
55
|
}
|
|
@@ -156,11 +166,19 @@ export async function* parseStreamWithProgress(
|
|
|
156
166
|
options.postTerminalDrainTimeoutMs ?? DEFAULT_POST_TERMINAL_DRAIN_TIMEOUT_MS,
|
|
157
167
|
"postTerminalDrainTimeoutMs",
|
|
158
168
|
);
|
|
169
|
+
const consumerTimeoutMs = normalizeTimeout(
|
|
170
|
+
options.consumerTimeoutMs ?? Math.max(DEFAULT_CONSUMER_TIMEOUT_MS, inactivityTimeoutMs),
|
|
171
|
+
"consumerTimeoutMs",
|
|
172
|
+
);
|
|
159
173
|
const handoff = new ProgressHandoff();
|
|
160
174
|
const reader = response.body?.getReader();
|
|
161
175
|
if (!reader) throw new WebSearchStreamProtocolError("upstream response has no body");
|
|
162
176
|
|
|
163
177
|
let inactivityTimer: ReturnType<typeof setTimeout> | undefined;
|
|
178
|
+
let inactivityRemainingMs = inactivityTimeoutMs;
|
|
179
|
+
let inactivityArmedAt = 0;
|
|
180
|
+
let consumerBlocked = false;
|
|
181
|
+
let terminalSeen = false;
|
|
164
182
|
let tappedController: ReadableStreamDefaultController<Uint8Array> | undefined;
|
|
165
183
|
let settled = false;
|
|
166
184
|
let iterator: AsyncGenerator<AdapterEvent> | undefined;
|
|
@@ -210,10 +228,46 @@ export async function* parseStreamWithProgress(
|
|
|
210
228
|
cancelReader(reason);
|
|
211
229
|
};
|
|
212
230
|
|
|
231
|
+
// Count only active upstream-wait time; a blocked downstream handoff has its own deadline.
|
|
232
|
+
const armInactivity = (): void => {
|
|
233
|
+
if (settled || consumerBlocked || terminalSeen || inactivityTimer !== undefined) return;
|
|
234
|
+
if (inactivityRemainingMs <= 0) {
|
|
235
|
+
fail(new RoutedModelInactivityError(inactivityTimeoutMs));
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
inactivityArmedAt = performance.now();
|
|
239
|
+
inactivityTimer = setTimeout(() => fail(new RoutedModelInactivityError(inactivityTimeoutMs)), inactivityRemainingMs);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const pauseInactivity = (): void => {
|
|
243
|
+
if (inactivityTimer === undefined) return;
|
|
244
|
+
inactivityRemainingMs = Math.max(0, inactivityRemainingMs - (performance.now() - inactivityArmedAt));
|
|
245
|
+
clearInactivity();
|
|
246
|
+
if (inactivityRemainingMs <= 0) fail(new RoutedModelInactivityError(inactivityTimeoutMs));
|
|
247
|
+
};
|
|
248
|
+
|
|
213
249
|
const resetInactivity = (): void => {
|
|
214
|
-
if (settled) return;
|
|
250
|
+
if (settled || terminalSeen) return;
|
|
215
251
|
clearInactivity();
|
|
216
|
-
|
|
252
|
+
inactivityRemainingMs = inactivityTimeoutMs;
|
|
253
|
+
armInactivity();
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const deliverWithTimeout = async (event: AdapterEvent, suspendInactivity: boolean): Promise<void> => {
|
|
257
|
+
if (suspendInactivity) {
|
|
258
|
+
consumerBlocked = true;
|
|
259
|
+
pauseInactivity();
|
|
260
|
+
}
|
|
261
|
+
const timer = setTimeout(() => fail(new WebSearchConsumerInactivityError(consumerTimeoutMs)), consumerTimeoutMs);
|
|
262
|
+
try {
|
|
263
|
+
await handoff.deliver(event);
|
|
264
|
+
} finally {
|
|
265
|
+
clearTimeout(timer);
|
|
266
|
+
if (suspendInactivity) {
|
|
267
|
+
consumerBlocked = false;
|
|
268
|
+
armInactivity();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
217
271
|
};
|
|
218
272
|
|
|
219
273
|
const onAbort = (): void => fail(options.signal?.reason);
|
|
@@ -233,7 +287,11 @@ export async function* parseStreamWithProgress(
|
|
|
233
287
|
controller.close();
|
|
234
288
|
return;
|
|
235
289
|
}
|
|
236
|
-
if (result.value.byteLength === 0)
|
|
290
|
+
if (result.value.byteLength === 0) {
|
|
291
|
+
// A synchronous empty-chunk producer can otherwise starve the timer in microtasks.
|
|
292
|
+
await new Promise<void>(resolve => setTimeout(resolve, 0));
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
237
295
|
resetInactivity();
|
|
238
296
|
handoff.offerProgress();
|
|
239
297
|
controller.enqueue(result.value);
|
|
@@ -287,7 +345,7 @@ export async function* parseStreamWithProgress(
|
|
|
287
345
|
|
|
288
346
|
if (result.done) {
|
|
289
347
|
if (!heldTerminal) throw new WebSearchStreamProtocolError("adapter returned without a terminal event");
|
|
290
|
-
await
|
|
348
|
+
await deliverWithTimeout(heldTerminal, false);
|
|
291
349
|
if (!settled) {
|
|
292
350
|
settled = true;
|
|
293
351
|
clearInactivity();
|
|
@@ -319,13 +377,14 @@ export async function* parseStreamWithProgress(
|
|
|
319
377
|
replaySafe &&= event.type === "heartbeat" && event.replayUnsafe !== true;
|
|
320
378
|
if (event.type === "done" || event.type === "incomplete") {
|
|
321
379
|
heldTerminal = event;
|
|
380
|
+
terminalSeen = true;
|
|
322
381
|
// Response-byte inactivity ends once the adapter has produced a terminal event.
|
|
323
382
|
// From here the separate post-terminal drain guard owns the bounded wait for
|
|
324
383
|
// iterator cleanup, so leaving the inactivity timer armed creates a false timeout.
|
|
325
384
|
clearInactivity();
|
|
326
385
|
continue;
|
|
327
386
|
}
|
|
328
|
-
await
|
|
387
|
+
await deliverWithTimeout(event, true);
|
|
329
388
|
}
|
|
330
389
|
} catch (error) {
|
|
331
390
|
fail(isTranslatorBudgetExceededError(error)
|