@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
package/src/server/hub-usage.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { OcxConfig } from "../types";
|
|
|
2
2
|
import { MAX_HUB_USAGE_BYTES, parseHubUsage } from "../remote/hub-usage";
|
|
3
3
|
import { parseRange, parseUsageSurface, USAGE_RANGES, USAGE_SURFACES } from "../usage/summary";
|
|
4
4
|
import { parseUsageTimeWindow } from "../usage/time-range";
|
|
5
|
+
import { USAGE_SOURCE_CLIENTS, type UsageSourceClient } from "../usage/source-filter";
|
|
5
6
|
import { getFilteredUsageAggregate } from "./management/usage-aggregate-cache";
|
|
6
7
|
import { isAllowedRequestOrigin, resolveDataPlaneAdmissionSecret, withCors, type DataPlaneAdmissionOptions, type RequestPolicyView } from "./auth-cors";
|
|
7
8
|
|
|
@@ -22,14 +23,16 @@ export async function handleHubUsage(req: Request, config: OcxConfig, policy: Re
|
|
|
22
23
|
// this authenticated identity into another configured key (or no filter).
|
|
23
24
|
if (!keyId || keyId.trim() !== keyId) return error("hub_usage_key_id_invalid", "Client key identity needs repair on the hub", 403);
|
|
24
25
|
const query = new URL(req.url).searchParams;
|
|
25
|
-
const allowed = new Set(["range", "surface", "provider", "model", "since", "until"]);
|
|
26
|
+
const allowed = new Set(["range", "surface", "provider", "model", "since", "until", "client"]);
|
|
26
27
|
for (const key of query.keys()) {
|
|
27
28
|
if (!allowed.has(key) || query.getAll(key).length !== 1) return error("hub_usage_query_invalid", "Unknown or repeated usage option", 400);
|
|
28
29
|
}
|
|
29
30
|
const rangeInput = query.get("range") ?? "30d";
|
|
30
31
|
const surfaceInput = query.get("surface") ?? "all";
|
|
32
|
+
const client = query.get("client");
|
|
31
33
|
if (!(rangeInput === "1d" || (USAGE_RANGES as readonly string[]).includes(rangeInput))
|
|
32
|
-
|| !(USAGE_SURFACES as readonly string[]).includes(surfaceInput)
|
|
34
|
+
|| !(USAGE_SURFACES as readonly string[]).includes(surfaceInput)
|
|
35
|
+
|| (client !== null && (!(USAGE_SOURCE_CLIENTS as readonly string[]).includes(client) || surfaceInput !== "all"))) {
|
|
33
36
|
return error("hub_usage_query_invalid", "Invalid usage range or surface", 400);
|
|
34
37
|
}
|
|
35
38
|
let window;
|
|
@@ -38,6 +41,7 @@ export async function handleHubUsage(req: Request, config: OcxConfig, policy: Re
|
|
|
38
41
|
try {
|
|
39
42
|
const aggregate = await getFilteredUsageAggregate({
|
|
40
43
|
apiKeyId: keyId, provider: query.get("provider"), model: query.get("model"),
|
|
44
|
+
...(client !== null ? { sourceFilter: { client: client as UsageSourceClient, device: { kind: "key", id: keyId } } } : {}),
|
|
41
45
|
}, window);
|
|
42
46
|
const current = resolveDataPlaneAdmissionSecret(token, config, "dedicated", options);
|
|
43
47
|
if (current?.kind !== "configured" || current.keyId !== keyId) {
|
|
@@ -45,6 +49,7 @@ export async function handleHubUsage(req: Request, config: OcxConfig, policy: Re
|
|
|
45
49
|
}
|
|
46
50
|
const summary = aggregate.accumulator.summarize(parseRange(rangeInput), Date.now(), parseUsageSurface(surfaceInput));
|
|
47
51
|
const body = parseHubUsage({ ...summary, schemaVersion: 1, source: "hub", scope: "client",
|
|
52
|
+
...(client !== null ? { sourceFilter: { client, scope: "authenticated-key" } } : {}),
|
|
48
53
|
...(aggregate.usageIncomplete ? { usageIncomplete: true, usageIncompleteReason: "oversized_rows" } : {}),
|
|
49
54
|
});
|
|
50
55
|
if (!body) return error("hub_usage_unavailable", "Usage could not be represented; narrow the requested range", 503);
|
|
@@ -7,6 +7,7 @@ import { codexCompatibleUrl } from "../codex/context-compat";
|
|
|
7
7
|
import { addFinalRequestLog, markLocalRequestLogRefusal } from "./request-log";
|
|
8
8
|
import type { WorkflowRefusalLog } from "./workflow-refusal";
|
|
9
9
|
import { inboundBodyBudget, bindInboundBodyLease, type InboundBodyBudget } from "./inbound-body-budget";
|
|
10
|
+
import { OLLAMA_JSON_BODY_ROUTES } from "./ollama-native-paths";
|
|
10
11
|
|
|
11
12
|
export { configureInboundBodyBudget, MAX_CONCURRENT_INBOUND_BODY_BYTES } from "./inbound-body-budget";
|
|
12
13
|
|
|
@@ -145,10 +146,12 @@ export async function withRaisedInboundBodyAdmission(
|
|
|
145
146
|
configuredLimit: number | undefined,
|
|
146
147
|
work: () => Promise<Response>,
|
|
147
148
|
onRefusal: (response: Response) => Response = response => response,
|
|
148
|
-
options?: { budget?: InboundBodyBudget; maxWaitMs?: number },
|
|
149
|
+
options?: { budget?: InboundBodyBudget; maxWaitMs?: number; onAdmissionError?: (error: unknown) => Response },
|
|
149
150
|
): Promise<Response> {
|
|
150
151
|
const maxBytes = resolveInboundBodyLimitBytes(configuredLimit);
|
|
151
|
-
|
|
152
|
+
// Native Ollama generation routes are served only on the authenticated listener, so they sit in
|
|
153
|
+
// their own set: the loopback oracle checks CONFIGURABLE_JSON_BODY_ROUTES against that allowlist.
|
|
154
|
+
if (req.method !== "POST" || !(CONFIGURABLE_JSON_BODY_ROUTES.has(pathname) || OLLAMA_JSON_BODY_ROUTES.has(pathname))
|
|
152
155
|
|| maxBytes <= MAX_DECOMPRESSED_BODY_BYTES || req.signal.aborted) {
|
|
153
156
|
return work();
|
|
154
157
|
}
|
|
@@ -164,6 +167,7 @@ export async function withRaisedInboundBodyAdmission(
|
|
|
164
167
|
lease = await (options?.budget ?? inboundBodyBudget).acquire(maxBytes, req.signal, options?.maxWaitMs);
|
|
165
168
|
} catch (error) {
|
|
166
169
|
cancelUnreadBody(req, error);
|
|
170
|
+
if (options?.onAdmissionError) return options.onAdmissionError(error);
|
|
167
171
|
throw error;
|
|
168
172
|
}
|
|
169
173
|
if (!lease) {
|
|
@@ -175,6 +179,7 @@ export async function withRaisedInboundBodyAdmission(
|
|
|
175
179
|
if (req.signal.aborted) {
|
|
176
180
|
lease.release();
|
|
177
181
|
cancelUnreadBody(req, req.signal.reason);
|
|
182
|
+
if (options?.onAdmissionError) return options.onAdmissionError(req.signal.reason);
|
|
178
183
|
throw req.signal.reason;
|
|
179
184
|
}
|
|
180
185
|
const unbind = bindInboundBodyLease(req, lease);
|
|
@@ -198,6 +203,8 @@ export function runAdmittedBodyWork(
|
|
|
198
203
|
configuredLimit: number | undefined,
|
|
199
204
|
work: () => Promise<Response>,
|
|
200
205
|
refusalLog?: WorkflowRefusalLog,
|
|
206
|
+
mapRefusal?: (response: Response) => Response,
|
|
207
|
+
onAdmissionError?: (error: unknown) => Response,
|
|
201
208
|
): Promise<Response> {
|
|
202
209
|
return withRaisedInboundBodyAdmission(req, codexCompatibleUrl(req.url).pathname, configuredLimit, work, refused => {
|
|
203
210
|
if (refusalLog) {
|
|
@@ -208,6 +215,6 @@ export function runAdmittedBodyWork(
|
|
|
208
215
|
});
|
|
209
216
|
refusalLog.onLogged?.();
|
|
210
217
|
}
|
|
211
|
-
return withCors(refused, req, policy);
|
|
212
|
-
});
|
|
218
|
+
return withCors(mapRefusal ? mapRefusal(refused) : refused, req, policy);
|
|
219
|
+
}, onAdmissionError ? { onAdmissionError } : undefined);
|
|
213
220
|
}
|
|
@@ -19,6 +19,7 @@ import { linkStorePath } from "../../link/paths";
|
|
|
19
19
|
import { readLinkStore } from "../../link/store";
|
|
20
20
|
import { readBoundedResponseBytes } from "../../lib/bounded-body";
|
|
21
21
|
import { packageVersion } from "../../lib/package-version";
|
|
22
|
+
import { parseUsageSource } from "../../usage/source-filter";
|
|
22
23
|
|
|
23
24
|
const VERSION = packageVersion("0.0.0");
|
|
24
25
|
const KEPT_RESPONSE_HEADERS = ["content-type", "content-language", "etag", "last-modified"];
|
|
@@ -83,6 +84,13 @@ export async function handleLinkManagementRequest(
|
|
|
83
84
|
}
|
|
84
85
|
const target = linkManagementTarget(url);
|
|
85
86
|
if (!target) return notFound();
|
|
87
|
+
if (target.pathname === "/api/usage") {
|
|
88
|
+
const source = parseUsageSource(target.searchParams);
|
|
89
|
+
if (source.kind !== "legacy" && (source.kind !== "filtered" || !admittedKeyId
|
|
90
|
+
|| source.filter.device.kind !== "key" || source.filter.device.id !== admittedKeyId)) {
|
|
91
|
+
return refused(403, "link_usage_scope_refused");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
86
94
|
const local = new URL(`${target.pathname}${target.search}`, "http://127.0.0.1");
|
|
87
95
|
// The handlers branch on GET; an admitted HEAD runs as GET and its body is dropped below.
|
|
88
96
|
const inner = new Request(local.href, {
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dispatcher arm for the Ollama-compatible inbound API. It runs before the management /api/
|
|
3
|
+
* catch-all and only for the exact native paths; every other /api/ path is untouched. Admission
|
|
4
|
+
* reuses the data-plane gates: generation takes the same key, origin, drain, active-turn,
|
|
5
|
+
* workflow and body admission as /v1/chat/completions, and the read-only routes take the
|
|
6
|
+
* model-discovery admission /v1/models uses. Refusals keep their status and retry advice and are
|
|
7
|
+
* reshaped into the native { "error": string } body.
|
|
8
|
+
*/
|
|
9
|
+
import type { Server } from "bun";
|
|
10
|
+
import type { OcxConfig } from "../../types";
|
|
11
|
+
import type { WsData } from "../ws-bridge";
|
|
12
|
+
import { classifyUsageClient } from "../../usage/client";
|
|
13
|
+
import { admissionFields, isAllowedRequestOrigin, resolveApiAuth, resolveResponsesApiAuth, withCors, type RequestPolicyView } from "../auth-cors";
|
|
14
|
+
import { withCallerSessionIdentity } from "../caller-session-identity";
|
|
15
|
+
import { captureAdmissionPolicy } from "../capture-admission-policy";
|
|
16
|
+
import { isDraining, type ActiveTurnLease } from "../lifecycle";
|
|
17
|
+
import { handleOllamaGeneration, handleOllamaShow, handleOllamaTags, handleOllamaVersion, ollamaError, toOllamaRefusal } from "../ollama-inbound";
|
|
18
|
+
import { OLLAMA_NATIVE_ROUTES } from "../ollama-native-paths";
|
|
19
|
+
import { nextRequestLogId, type RequestLogContext } from "../request-log";
|
|
20
|
+
import { disableResponsesRequestTimeout } from "../responses";
|
|
21
|
+
import type { AdmittedHttpTurnOptions } from "../admitted-http-turn";
|
|
22
|
+
import type { WorkflowRefusalLog } from "../workflow-refusal";
|
|
23
|
+
import { withRequestLogId } from "./startup-warnings";
|
|
24
|
+
|
|
25
|
+
export interface OllamaRouteDeps {
|
|
26
|
+
config: OcxConfig;
|
|
27
|
+
policy: RequestPolicyView;
|
|
28
|
+
requestServer: Server<WsData>;
|
|
29
|
+
requestMetricsLogContext: Partial<RequestLogContext>;
|
|
30
|
+
drainingResponse: (req: Request, policy: RequestPolicyView) => Response;
|
|
31
|
+
runAdmittedHttpTurn: (
|
|
32
|
+
req: Request,
|
|
33
|
+
policy: RequestPolicyView,
|
|
34
|
+
work: (lease: ActiveTurnLease) => Promise<Response>,
|
|
35
|
+
refusalLog?: WorkflowRefusalLog,
|
|
36
|
+
options?: AdmittedHttpTurnOptions,
|
|
37
|
+
) => Promise<Response>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Returns undefined when the path is not one of the native routes. */
|
|
41
|
+
export async function dispatchOllamaRoute(req: Request, url: URL, deps: OllamaRouteDeps): Promise<Response | undefined> {
|
|
42
|
+
const route = OLLAMA_NATIVE_ROUTES.get(url.pathname);
|
|
43
|
+
if (!route) return undefined;
|
|
44
|
+
const { config, policy } = deps;
|
|
45
|
+
if (req.method !== route.method) {
|
|
46
|
+
const refused = ollamaError(405, `method ${req.method} not allowed`);
|
|
47
|
+
refused.headers.set("Allow", route.method);
|
|
48
|
+
return withCors(refused, req, policy);
|
|
49
|
+
}
|
|
50
|
+
if (route.kind === "version" || route.kind === "tags" || route.kind === "show") {
|
|
51
|
+
// Model discovery never forwards Authorization upstream, so the broader admission set is safe.
|
|
52
|
+
const admission = resolveApiAuth(req, policy);
|
|
53
|
+
if (!admission) return withCors(ollamaError(401, "opencodex API key required"), req, policy);
|
|
54
|
+
if (!isAllowedRequestOrigin(req, policy)) return withCors(ollamaError(403, "cross-origin data-plane request blocked"), req, policy);
|
|
55
|
+
const response = route.kind === "version" ? handleOllamaVersion()
|
|
56
|
+
: route.kind === "tags" ? handleOllamaTags(config, req, admission)
|
|
57
|
+
: await handleOllamaShow(config, req, admission);
|
|
58
|
+
return withCors(response, req, policy);
|
|
59
|
+
}
|
|
60
|
+
const kind = route.kind;
|
|
61
|
+
disableResponsesRequestTimeout(req, deps.requestServer);
|
|
62
|
+
if (isDraining()) return withCors(toOllamaRefusal(deps.drainingResponse(req, policy)), req, policy);
|
|
63
|
+
const admission = resolveResponsesApiAuth(req, policy);
|
|
64
|
+
if (!admission) return withCors(ollamaError(401, "opencodex API key required"), req, policy);
|
|
65
|
+
if (!isAllowedRequestOrigin(req, policy)) return withCors(ollamaError(403, "cross-origin data-plane request blocked"), req, policy);
|
|
66
|
+
const start = Date.now();
|
|
67
|
+
const requestId = nextRequestLogId(start);
|
|
68
|
+
const logCtx: RequestLogContext = {
|
|
69
|
+
model: "unknown",
|
|
70
|
+
provider: "unknown",
|
|
71
|
+
...deps.requestMetricsLogContext,
|
|
72
|
+
client: classifyUsageClient(req.headers),
|
|
73
|
+
...admissionFields(admission),
|
|
74
|
+
};
|
|
75
|
+
const sessionReq = withCallerSessionIdentity(req, admission);
|
|
76
|
+
// Expose an id only when the handler or a logged refusal owns the history row.
|
|
77
|
+
let ownsRequestLog = false;
|
|
78
|
+
const advisorAdmissionPolicy = captureAdmissionPolicy(config, admission);
|
|
79
|
+
const response = await deps.runAdmittedHttpTurn(sessionReq, policy, async turnAdmissionLease => {
|
|
80
|
+
ownsRequestLog = true;
|
|
81
|
+
return withCors(
|
|
82
|
+
await handleOllamaGeneration(kind, sessionReq, config, logCtx, { requestId, start, turnAdmissionLease, admission, advisorAdmissionPolicy }),
|
|
83
|
+
req,
|
|
84
|
+
policy,
|
|
85
|
+
);
|
|
86
|
+
}, { requestId, start, logCtx, onLogged: () => { ownsRequestLog = true; } }, {
|
|
87
|
+
mapRefusal: toOllamaRefusal,
|
|
88
|
+
onAdmissionError: () => ollamaError(499, "request cancelled"),
|
|
89
|
+
});
|
|
90
|
+
return ownsRequestLog ? withRequestLogId(response, requestId) : response;
|
|
91
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { messagesUnknownEndpointMessage } from "../../lib/messages-error-body";
|
|
1
2
|
import type { Server, ServerWebSocket } from "bun";
|
|
2
3
|
import { modelAliasIdPromoter } from "./model-alias-id";
|
|
3
4
|
import type { StartServerDeps } from "./startup-warnings";
|
|
@@ -200,9 +201,14 @@ import {
|
|
|
200
201
|
expandFastRow,
|
|
201
202
|
} from "../fast-row";
|
|
202
203
|
import type { OcxConfig } from "../../types";
|
|
204
|
+
import { classifyUsageClient } from "../../usage/client";
|
|
203
205
|
import type { PackageTreeIntegrityGuard } from "../../lib/package-tree-integrity";
|
|
204
206
|
import type { ReadinessGate } from "../readiness";
|
|
205
207
|
import type { WorkflowRefusalLog } from "../workflow-refusal";
|
|
208
|
+
import type { AdmittedHttpTurnOptions } from "../admitted-http-turn";
|
|
209
|
+
import { isOllamaNativePath } from "../ollama-native-paths";
|
|
210
|
+
import { ollamaError } from "../ollama-inbound";
|
|
211
|
+
import { dispatchOllamaRoute } from "./ollama-routes";
|
|
206
212
|
|
|
207
213
|
import { readyProtocolMetadata } from "../../remote/protocol";
|
|
208
214
|
import { homeInstanceId, stampServedBy } from "../../remote/served-by";
|
|
@@ -212,6 +218,7 @@ import { reasoningArchiveErrorResponse } from "../responses/reasoning-archive-er
|
|
|
212
218
|
import { withGrokSessionIdentity } from "../../grok/session-identity";
|
|
213
219
|
import { withCallerSessionIdentity } from "../caller-session-identity";
|
|
214
220
|
import { agentAssertionUnsupportedResponse, hasAgentAssertionAuthorization } from "../../lib/authorization-scheme";
|
|
221
|
+
import { runTurnStateCallerScope } from "../turn-state-handles";
|
|
215
222
|
|
|
216
223
|
export type ServerIngress = "public" | "unauthenticated-loopback" | "hub-management" | "claude-intercept" | "hub-link";
|
|
217
224
|
|
|
@@ -256,6 +263,7 @@ export interface ServeOptionsContext {
|
|
|
256
263
|
policy: RequestPolicyView,
|
|
257
264
|
work: (lease: ActiveTurnLease) => Promise<Response>,
|
|
258
265
|
refusalLog?: WorkflowRefusalLog,
|
|
266
|
+
options?: AdmittedHttpTurnOptions,
|
|
259
267
|
) => Promise<Response>;
|
|
260
268
|
|
|
261
269
|
config: OcxConfig;
|
|
@@ -332,14 +340,14 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
332
340
|
// silently when a route is added below.
|
|
333
341
|
if (ingress === "unauthenticated-loopback" && !loopbackRouteAllowed(codexCompatibleUrl(req.url), req)) {
|
|
334
342
|
return withCors(
|
|
335
|
-
formatErrorResponse(404, "not_found",
|
|
343
|
+
formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)),
|
|
336
344
|
req,
|
|
337
345
|
loopbackPolicy(),
|
|
338
346
|
);
|
|
339
347
|
}
|
|
340
348
|
if (ingress === "hub-link" && !linkRouteAllowed(requestUrl, req)) {
|
|
341
349
|
return withCors(
|
|
342
|
-
formatErrorResponse(404, "not_found",
|
|
350
|
+
formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)),
|
|
343
351
|
req,
|
|
344
352
|
linkPolicyView!,
|
|
345
353
|
);
|
|
@@ -348,14 +356,14 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
348
356
|
// dispatch so no data, readiness, health, WebSocket, or unknown-static handler can run.
|
|
349
357
|
if (ingress === "hub-management" && !managementIngressRouteAllowed(codexCompatibleUrl(req.url), req)) {
|
|
350
358
|
return withCors(
|
|
351
|
-
formatErrorResponse(404, "not_found",
|
|
359
|
+
formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)),
|
|
352
360
|
req,
|
|
353
361
|
config,
|
|
354
362
|
);
|
|
355
363
|
}
|
|
356
364
|
if (ingress === "claude-intercept" && !claudeInterceptRouteAllowed(codexCompatibleUrl(req.url), req)) {
|
|
357
365
|
return withCors(
|
|
358
|
-
formatErrorResponse(404, "not_found",
|
|
366
|
+
formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)),
|
|
359
367
|
req,
|
|
360
368
|
loopbackPolicy(),
|
|
361
369
|
);
|
|
@@ -414,6 +422,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
414
422
|
url.pathname === "/healthz"
|
|
415
423
|
|| readyzPath !== undefined
|
|
416
424
|
|| url.pathname.startsWith("/v1/")
|
|
425
|
+
|| isOllamaNativePath(url.pathname)
|
|
417
426
|
)) {
|
|
418
427
|
const message = "OpenCodex package files changed while this proxy was running; it restarts on its own, or run 'ocx restart' ('ocx service restart' for a background service).";
|
|
419
428
|
const fencedPort = ctx.boundPort ?? requestServer.port ?? listenPort;
|
|
@@ -437,7 +446,9 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
437
446
|
} : {}),
|
|
438
447
|
error: { code: "package_tree_changed", message },
|
|
439
448
|
}, 503, req, policy)
|
|
440
|
-
:
|
|
449
|
+
: isOllamaNativePath(url.pathname)
|
|
450
|
+
? withCors(ollamaError(503, message), req, policy)
|
|
451
|
+
: packageTreeChangedResponse(req, policy, message);
|
|
441
452
|
const headers = new Headers(response.headers);
|
|
442
453
|
headers.set("Retry-After", "5");
|
|
443
454
|
const challenge = fencedHealth ? req.headers.get(LOCAL_ATTESTATION_CHALLENGE_HEADER) : null;
|
|
@@ -451,9 +462,10 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
451
462
|
// path) must answer the deterministic JSON 404, never the generic 204
|
|
452
463
|
// preflight response that the SPA fallback would otherwise allow.
|
|
453
464
|
if (readyzPath !== undefined) {
|
|
454
|
-
return withCors(formatErrorResponse(404, "not_found",
|
|
465
|
+
return withCors(formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)), req, policy);
|
|
455
466
|
}
|
|
456
|
-
|
|
467
|
+
// The exact Ollama-compatible paths are data-plane routes and take data-plane CORS.
|
|
468
|
+
const managementPreflight = url.pathname.startsWith("/api/") && !isOllamaNativePath(url.pathname);
|
|
457
469
|
const allowed = managementPreflight
|
|
458
470
|
? isAllowedManagementOrigin(req, config)
|
|
459
471
|
: isAllowedRequestOrigin(req, policy);
|
|
@@ -626,6 +638,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
626
638
|
admission,
|
|
627
639
|
websocketLease,
|
|
628
640
|
sessionLaneIdFromRequest(req.headers),
|
|
641
|
+
classifyUsageClient(req.headers),
|
|
629
642
|
),
|
|
630
643
|
})) return undefined as unknown as Response;
|
|
631
644
|
websocketLease.release();
|
|
@@ -667,7 +680,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
667
680
|
// fallback (which would serve index.html with HTTP 200 once gui/dist exists).
|
|
668
681
|
if (readyzPath !== undefined) {
|
|
669
682
|
if (readyzPath !== "/readyz" || req.method !== "GET") {
|
|
670
|
-
return withCors(formatErrorResponse(404, "not_found",
|
|
683
|
+
return withCors(formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)), req, policy);
|
|
671
684
|
}
|
|
672
685
|
// A draining proxy must never advertise ready: every data-plane branch
|
|
673
686
|
// answers drainingResponse while isDraining() is set, but the one-shot
|
|
@@ -695,6 +708,12 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
695
708
|
return new Response(resp.body, { status: 503, headers });
|
|
696
709
|
}
|
|
697
710
|
|
|
711
|
+
// Checked synchronously: an await here would delay every later route's admission capture.
|
|
712
|
+
if (isOllamaNativePath(url.pathname)) {
|
|
713
|
+
const native = await dispatchOllamaRoute(req, url, { config, policy, requestServer, requestMetricsLogContext, drainingResponse, runAdmittedHttpTurn });
|
|
714
|
+
if (native) return native;
|
|
715
|
+
}
|
|
716
|
+
|
|
698
717
|
if (url.pathname.startsWith("/api/")) {
|
|
699
718
|
const localManagementAuth = {
|
|
700
719
|
attestationSecret: localAttestationSecret,
|
|
@@ -743,7 +762,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
743
762
|
return withManagementCors(signed, req, config);
|
|
744
763
|
}
|
|
745
764
|
if (mgmtResponse) return withManagementCors(mgmtResponse, req, config);
|
|
746
|
-
return withManagementCors(formatErrorResponse(404, "not_found",
|
|
765
|
+
return withManagementCors(formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)), req, config);
|
|
747
766
|
}
|
|
748
767
|
|
|
749
768
|
if (url.pathname === "/v1/catalog" && (req.method === "GET" || req.method === "HEAD")) {
|
|
@@ -1320,7 +1339,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1320
1339
|
const logCtx: RequestLogContext = {
|
|
1321
1340
|
model: "unknown",
|
|
1322
1341
|
provider: "unknown",
|
|
1323
|
-
...requestMetricsLogContext,
|
|
1342
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1324
1343
|
...admissionFields(admission),
|
|
1325
1344
|
inboundProtocol: "responses",
|
|
1326
1345
|
};
|
|
@@ -1360,7 +1379,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1360
1379
|
const logCtx: RequestLogContext = {
|
|
1361
1380
|
model: "image_gen",
|
|
1362
1381
|
provider: "unknown",
|
|
1363
|
-
...requestMetricsLogContext,
|
|
1382
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1364
1383
|
...admissionFields(admission),
|
|
1365
1384
|
};
|
|
1366
1385
|
const endpoint = url.pathname.endsWith("/edits") ? "edits" as const : "generations" as const;
|
|
@@ -1418,7 +1437,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1418
1437
|
const logCtx: RequestLogContext = {
|
|
1419
1438
|
model: "context_history",
|
|
1420
1439
|
provider: "unknown",
|
|
1421
|
-
...requestMetricsLogContext,
|
|
1440
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1422
1441
|
...admissionFields(admission),
|
|
1423
1442
|
};
|
|
1424
1443
|
return runAdmittedHttpTurn(req, policy, async turnAdmissionLease => {
|
|
@@ -1445,7 +1464,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1445
1464
|
const logCtx: RequestLogContext = {
|
|
1446
1465
|
model: "web_search",
|
|
1447
1466
|
provider: "unknown",
|
|
1448
|
-
...requestMetricsLogContext,
|
|
1467
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1449
1468
|
...admissionFields(admission),
|
|
1450
1469
|
};
|
|
1451
1470
|
return runAdmittedHttpTurn(req, policy, async turnAdmissionLease => {
|
|
@@ -1470,7 +1489,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1470
1489
|
const logCtx: RequestLogContext = {
|
|
1471
1490
|
model: "unknown",
|
|
1472
1491
|
provider: "unknown",
|
|
1473
|
-
...requestMetricsLogContext,
|
|
1492
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1474
1493
|
...admissionFields(admission),
|
|
1475
1494
|
inboundProtocol: "responses",
|
|
1476
1495
|
};
|
|
@@ -1565,7 +1584,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1565
1584
|
const logCtx: RequestLogContext = {
|
|
1566
1585
|
model: "unknown",
|
|
1567
1586
|
provider: "unknown",
|
|
1568
|
-
...requestMetricsLogContext,
|
|
1587
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1569
1588
|
...admissionFields(admission),
|
|
1570
1589
|
inboundProtocol: "messages",
|
|
1571
1590
|
};
|
|
@@ -1603,7 +1622,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1603
1622
|
const logCtx: RequestLogContext = {
|
|
1604
1623
|
model: "unknown",
|
|
1605
1624
|
provider: "unknown",
|
|
1606
|
-
...requestMetricsLogContext,
|
|
1625
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1607
1626
|
...admissionFields(admission),
|
|
1608
1627
|
inboundProtocol: "chat",
|
|
1609
1628
|
};
|
|
@@ -1641,7 +1660,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1641
1660
|
const logCtx: RequestLogContext = {
|
|
1642
1661
|
model: TRANSCRIPTION_MODEL,
|
|
1643
1662
|
provider: "unknown",
|
|
1644
|
-
...requestMetricsLogContext,
|
|
1663
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1645
1664
|
...admissionFields(admission),
|
|
1646
1665
|
};
|
|
1647
1666
|
return runAdmittedHttpTurn(req, policy, async lease => {
|
|
@@ -1674,7 +1693,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1674
1693
|
const logCtx: RequestLogContext = {
|
|
1675
1694
|
model: "gpt-live",
|
|
1676
1695
|
provider: "unknown",
|
|
1677
|
-
...requestMetricsLogContext,
|
|
1696
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1678
1697
|
...admissionFields(admission),
|
|
1679
1698
|
};
|
|
1680
1699
|
return runAdmittedHttpTurn(req, policy, async turnAdmissionLease => {
|
|
@@ -1722,7 +1741,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1722
1741
|
const logCtx: RequestLogContext = {
|
|
1723
1742
|
model: "gpt-live",
|
|
1724
1743
|
provider: "unknown",
|
|
1725
|
-
...requestMetricsLogContext,
|
|
1744
|
+
...requestMetricsLogContext, client: classifyUsageClient(req.headers),
|
|
1726
1745
|
...admissionFields(admission),
|
|
1727
1746
|
};
|
|
1728
1747
|
let liveRequestFinalized = false;
|
|
@@ -1885,7 +1904,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1885
1904
|
// endpoint clients — memories/*, realtime/* — would surface confusing
|
|
1886
1905
|
// serde decode errors instead of a clean not-found).
|
|
1887
1906
|
if (url.pathname.startsWith("/v1/")) {
|
|
1888
|
-
return withCors(formatErrorResponse(404, "not_found",
|
|
1907
|
+
return withCors(formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)), req, policy);
|
|
1889
1908
|
}
|
|
1890
1909
|
|
|
1891
1910
|
if (url.pathname === "/opencodex-session") {
|
|
@@ -1946,7 +1965,7 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1946
1965
|
? withManagementCors(serveSessionBootstrap(pairing), req, config)
|
|
1947
1966
|
: withManagementCors(new Response(null, { status: 401, headers: { "Cache-Control": "no-store" } }), req, config);
|
|
1948
1967
|
}
|
|
1949
|
-
return withCors(formatErrorResponse(404, "not_found",
|
|
1968
|
+
return withCors(formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)), req, policy);
|
|
1950
1969
|
}
|
|
1951
1970
|
const guiSessionCandidate = req.method === "GET" && (url.pathname === "/" || !url.pathname.includes("."))
|
|
1952
1971
|
? issueGuiSession(req, config, managementAuth, {
|
|
@@ -1965,12 +1984,13 @@ export function createServeOptions(ctx: ServeOptionsContext) {
|
|
|
1965
1984
|
return jsonResponse(rootFallbackPayload());
|
|
1966
1985
|
}
|
|
1967
1986
|
|
|
1968
|
-
return withCors(formatErrorResponse(404, "not_found",
|
|
1987
|
+
return withCors(formatErrorResponse(404, "not_found", messagesUnknownEndpointMessage(req)), req, config);
|
|
1969
1988
|
},
|
|
1970
1989
|
websocket: createWebsocketHandler(ctx, requestMetrics),
|
|
1971
1990
|
} as const;
|
|
1972
1991
|
const routeFetch = serveOptions.fetch;
|
|
1973
1992
|
// x-opencodex-served-by on GET /v1/models, whichever branch answered (src/remote/served-by.ts).
|
|
1974
|
-
|
|
1975
|
-
|
|
1993
|
+
// Each request runs with its own caller slot, which admission fills for turn-state handle binding.
|
|
1994
|
+
return { ...serveOptions, fetch: (req: Request, requestServer: Server<WsData>): Promise<Response> => runTurnStateCallerScope(async () =>
|
|
1995
|
+
stampServedBy(req.method, codexCompatibleUrl(req.url).pathname, await routeFetch(req, requestServer))) } as const;
|
|
1976
1996
|
}
|
|
@@ -100,22 +100,15 @@ import {
|
|
|
100
100
|
|
|
101
101
|
const REQUEST_LOG_ID_RESPONSE_HEADER = "x-opencodex-request-id";
|
|
102
102
|
|
|
103
|
-
/** Messages clients
|
|
103
|
+
/** Messages clients correlate requests with the proxy ledger ID. */
|
|
104
104
|
export function withMessagesRequestLogId(response: Response, requestId: string): Response {
|
|
105
|
-
const upstreamId = response.headers.get("request-id");
|
|
106
105
|
const correlated = withRequestLogId(response, requestId);
|
|
107
106
|
correlated.headers.delete("x-opencodex-upstream-request-id");
|
|
108
|
-
if (upstreamId && /^req_[A-Za-z0-9_-]{1,128}$/.test(upstreamId)) {
|
|
109
|
-
correlated.headers.set("x-opencodex-upstream-request-id", upstreamId);
|
|
110
|
-
}
|
|
111
107
|
correlated.headers.set("request-id", requestId);
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (additions.length) {
|
|
117
|
-
correlated.headers.set("Access-Control-Expose-Headers", [exposed, ...additions].filter(Boolean).join(", "));
|
|
118
|
-
}
|
|
108
|
+
const names = (correlated.headers.get("Access-Control-Expose-Headers") ?? "").split(",")
|
|
109
|
+
.map(name => name.trim().toLowerCase()).filter(name => name && name !== "x-opencodex-upstream-request-id");
|
|
110
|
+
names.push("request-id");
|
|
111
|
+
correlated.headers.set("Access-Control-Expose-Headers", [...new Set(names)].join(", "));
|
|
119
112
|
return correlated;
|
|
120
113
|
}
|
|
121
114
|
|
|
@@ -93,6 +93,7 @@ import type { ServeOptionsContext } from "./serve-options";
|
|
|
93
93
|
import type { RequestMetricsRecorder } from "../request-metrics";
|
|
94
94
|
import { resolveInboundBodyLimitBytes } from "../request-decompress";
|
|
95
95
|
import { responseToolOwnership } from "../responses/response-tool-ownership";
|
|
96
|
+
import { runTurnStateCallerScope } from "../turn-state-handles";
|
|
96
97
|
|
|
97
98
|
/**
|
|
98
99
|
* The WebSocket half of the Bun.serve options, split out of serve-options.ts to keep that file
|
|
@@ -310,7 +311,8 @@ export function createWebsocketHandler(
|
|
|
310
311
|
const payload: Record<string, unknown> = { ...frame };
|
|
311
312
|
delete payload.type;
|
|
312
313
|
turnAdmissionLease.bindAbortController(turnAbort);
|
|
313
|
-
|
|
314
|
+
// The frame runs with its own caller slot, which admission fills for turn-state handle binding.
|
|
315
|
+
void runTurnStateCallerScope(async () => {
|
|
314
316
|
const start = Date.now();
|
|
315
317
|
const requestId = nextRequestLogId(start);
|
|
316
318
|
// Resolved once at the handshake — a frame has no request headers left
|
|
@@ -323,6 +325,7 @@ export function createWebsocketHandler(
|
|
|
323
325
|
provider: "unknown",
|
|
324
326
|
...(requestMetricsRecorder ? { requestMetricsRecorder } : {}),
|
|
325
327
|
...(wsAdmission ? admissionFields(wsAdmission) : {}),
|
|
328
|
+
client: ws.data.client ?? "unknown",
|
|
326
329
|
inboundProtocol: "responses",
|
|
327
330
|
};
|
|
328
331
|
let logged = false;
|
|
@@ -431,7 +434,7 @@ export function createWebsocketHandler(
|
|
|
431
434
|
if (!logged && turnAbort.signal.aborted) finalizeLog(499);
|
|
432
435
|
if (ws.data.cancel === cancelTurn) ws.data.cancel = undefined;
|
|
433
436
|
}
|
|
434
|
-
})
|
|
437
|
+
});
|
|
435
438
|
},
|
|
436
439
|
close(ws: ServerWebSocket<WsData>, code: number, reason: string) {
|
|
437
440
|
if (ws.data.kind === "remote-workspace-agent") {
|
package/src/server/index.ts
CHANGED
|
@@ -2,7 +2,9 @@ import { remoteWorkspaceEnabled } from "../remote-control/workspace-activation";
|
|
|
2
2
|
import { scheduleDesktopCompatibilityStartup } from "./index/desktop-compatibility-startup";
|
|
3
3
|
import { AuxiliaryListenerBindError } from "./ports";
|
|
4
4
|
import { normalizeBindHostname } from "./bind-host";
|
|
5
|
-
import { configureInboundBodyBudget
|
|
5
|
+
import { configureInboundBodyBudget } from "./inbound-body-admission";
|
|
6
|
+
import { createAdmittedHttpTurn } from "./admitted-http-turn";
|
|
7
|
+
import { isOllamaNativePath } from "./ollama-native-paths";
|
|
6
8
|
import {
|
|
7
9
|
buildWarmupCompletionFrames,
|
|
8
10
|
buildWsErrorFrame,
|
|
@@ -93,9 +95,7 @@ import {
|
|
|
93
95
|
runListenerShutdown,
|
|
94
96
|
setServerRef,
|
|
95
97
|
trackStreamLifetime,
|
|
96
|
-
tryAdmitTurn,
|
|
97
98
|
unregisterTurn,
|
|
98
|
-
type ActiveTurnLease,
|
|
99
99
|
} from "./lifecycle";
|
|
100
100
|
export {
|
|
101
101
|
drainAndShutdown,
|
|
@@ -116,9 +116,7 @@ import {
|
|
|
116
116
|
type RequestLogContext,
|
|
117
117
|
type RequestLogEntry,
|
|
118
118
|
} from "./request-log";
|
|
119
|
-
import { sessionLaneIdFromRequest } from "./request-log-conversation";
|
|
120
119
|
import { setUsageLedgerRetention } from "./usage-ledger-retention";
|
|
121
|
-
import { admitHttpWorkflowTurn, workflowDecisionRefusalResponse, type WorkflowRefusalLog } from "./workflow-refusal";
|
|
122
120
|
export {
|
|
123
121
|
addFinalRequestLog,
|
|
124
122
|
filterRequestLogs, queryRequestLogs,
|
|
@@ -450,6 +448,8 @@ function startServerWithSpendLedgerOwner(port: number | undefined, deps: StartSe
|
|
|
450
448
|
}
|
|
451
449
|
if (rawPath === "/remote-workspace/pair") return remoteWorkspaceEnabled(config) && req.method === "POST";
|
|
452
450
|
if (rawPath === "/opencodex-session") return req.method === "GET" || req.method === "POST";
|
|
451
|
+
// Ollama-compatible inference paths are data plane, not management: never via Tailscale Serve.
|
|
452
|
+
if (isOllamaNativePath(rawPath)) return false;
|
|
453
453
|
if (rawPath.startsWith("/api/")) return true;
|
|
454
454
|
if (req.method !== "GET" && req.method !== "HEAD") return false;
|
|
455
455
|
let decodedPath: string;
|
|
@@ -500,37 +500,7 @@ function startServerWithSpendLedgerOwner(port: number | undefined, deps: StartSe
|
|
|
500
500
|
}), req, policy);
|
|
501
501
|
}
|
|
502
502
|
|
|
503
|
-
|
|
504
|
-
req: Request,
|
|
505
|
-
policy: RequestPolicyView,
|
|
506
|
-
work: (lease: ActiveTurnLease) => Promise<Response>,
|
|
507
|
-
refusalLog?: WorkflowRefusalLog,
|
|
508
|
-
): Promise<Response> {
|
|
509
|
-
const lease = tryAdmitTurn(sessionLaneIdFromRequest(req.headers), req.signal);
|
|
510
|
-
if (!lease) return serverBusyResponse(req, "active turns", policy);
|
|
511
|
-
// Root, lane, and the refusal that follows from them, all live in ./workflow-refusal.
|
|
512
|
-
let workflow: ReturnType<typeof admitHttpWorkflowTurn>;
|
|
513
|
-
try { workflow = admitHttpWorkflowTurn(req.headers); }
|
|
514
|
-
catch (error) { lease.release(); throw error; }
|
|
515
|
-
if (workflow && !workflow.admitted) {
|
|
516
|
-
lease.release();
|
|
517
|
-
// withCors, because without Access-Control-Allow-Origin the exposed refusal header is
|
|
518
|
-
// still unreadable to a browser dashboard -- which made exposing it pointless.
|
|
519
|
-
return withCors(workflowDecisionRefusalResponse(workflow, undefined, refusalLog), req, policy);
|
|
520
|
-
}
|
|
521
|
-
if (workflow?.admitted) lease.attach(workflow.lease);
|
|
522
|
-
let response: Response;
|
|
523
|
-
try {
|
|
524
|
-
response = await runAdmittedBodyWork(req, policy, config.maxInboundBodyBytes, () => work(lease), refusalLog);
|
|
525
|
-
} catch (error) {
|
|
526
|
-
lease.release();
|
|
527
|
-
throw error;
|
|
528
|
-
}
|
|
529
|
-
if (!lease.isTransferred()) {
|
|
530
|
-
lease.release();
|
|
531
|
-
}
|
|
532
|
-
return response;
|
|
533
|
-
}
|
|
503
|
+
const runAdmittedHttpTurn = createAdmittedHttpTurn(() => config.maxInboundBodyBytes, serverBusyResponse);
|
|
534
504
|
|
|
535
505
|
// Readiness gate: one PRIVATE controller per startServer invocation, captured
|
|
536
506
|
// by this listener's closure. Starting/failing a second server in the same
|