@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
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Caller-owned affinity is scoped to the exact Authorization value and conversation key under a
|
|
3
|
+
* process-random HMAC key. It is process-local and must never be anchored or persisted, as required
|
|
4
|
+
* by the structure contract. Decisions describe the binding at selection time.
|
|
5
|
+
*/
|
|
6
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
7
|
+
import { MAIN_CODEX_ACCOUNT_ID } from "./account-id";
|
|
8
|
+
import { codexConversationIdentity } from "./lineage";
|
|
9
|
+
import { getThreadAffinity, getModelDetourAffinity, deleteThreadAffinity, deleteModelDetourAffinity, notePendingReleaseReason, type CodexAffinityDecision, type CodexAffinityReason, type ThreadAffinityEntry } from "./routing/thread-affinity";
|
|
10
|
+
import type { CodexQuotaScope } from "./routing/health-store";
|
|
11
|
+
import { classifyCodexUpstreamOutcome } from "./routing/cooldown-math";
|
|
12
|
+
import type { CodexAuthContext } from "./auth-context";
|
|
13
|
+
import { isRequestOwnedAffinityKey, REQUEST_OWNED_AFFINITY_KEY_PREFIX } from "./request-owned-affinity-key";
|
|
14
|
+
export { isRequestOwnedAffinityKey } from "./request-owned-affinity-key";
|
|
15
|
+
|
|
16
|
+
const key = randomBytes(32);
|
|
17
|
+
const prefix = REQUEST_OWNED_AFFINITY_KEY_PREFIX;
|
|
18
|
+
|
|
19
|
+
/** Derive the opaque key for this caller and conversation, if both exist. */
|
|
20
|
+
export function requestOwnedAffinityKey(headers: Headers): string | undefined {
|
|
21
|
+
const authorization = headers.get("authorization");
|
|
22
|
+
const conversation = codexConversationIdentity(headers)?.conversationKey;
|
|
23
|
+
if (!authorization || !conversation) return undefined;
|
|
24
|
+
return prefix + createHmac("sha256", key)
|
|
25
|
+
.update("opencodex-request-owned-affinity-v1\0").update(authorization).update("\0").update(conversation)
|
|
26
|
+
.digest("base64url");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Report a bind only when the selection-time entry names the selected account. */
|
|
30
|
+
export function honestAffinityDecision(
|
|
31
|
+
decision: CodexAffinityDecision | undefined,
|
|
32
|
+
affinityKey: string | undefined,
|
|
33
|
+
accountId: string,
|
|
34
|
+
quotaScope?: CodexQuotaScope,
|
|
35
|
+
modelId?: string,
|
|
36
|
+
requestOwnedKeyWithheld = false,
|
|
37
|
+
): CodexAffinityDecision | undefined {
|
|
38
|
+
if (!decision || (decision.move !== "new_bind" && decision.move !== "rebound")) return decision;
|
|
39
|
+
// This is a selection-time snapshot, immediately after the synchronous selector returns.
|
|
40
|
+
if (affinityKey && (getThreadAffinity(affinityKey, quotaScope)?.accountId === accountId
|
|
41
|
+
|| getModelDetourAffinity(affinityKey, modelId, quotaScope)?.accountId === accountId)) return decision;
|
|
42
|
+
if (decision.move === "rebound") return { move: "cleared", reason: decision.reason };
|
|
43
|
+
return { move: "unbound", reason: affinityKey ? decision.reason : requestOwnedKeyWithheld ? "request_owned" : "no_conversation" };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Identify the issuer for a Pool or keyed caller-main context. */
|
|
47
|
+
export function conversationStateAccountId(ctx: { kind: "main" | "pool" | "main-pool"; accountId: string | null; affinityKey?: string; conversationStateKey?: string }): string | undefined {
|
|
48
|
+
return ctx.kind === "main" ? (ctx.affinityKey || ctx.conversationStateKey ? MAIN_CODEX_ACCOUNT_ID : undefined) : ctx.accountId ?? undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Describe the account actually serving a caller-owned fallback. */
|
|
52
|
+
export function callerOwnedFallbackAffinityDecision(
|
|
53
|
+
decision: CodexAffinityDecision | undefined, affinityKey: string | undefined, quotaScope: CodexQuotaScope | undefined,
|
|
54
|
+
modelId: string | undefined, requestOwnedKeyWithheld: boolean, reason: "cooldown" | "unusable",
|
|
55
|
+
): CodexAffinityDecision {
|
|
56
|
+
const ordinary = affinityKey ? getThreadAffinity(affinityKey, quotaScope) : undefined;
|
|
57
|
+
const detour = affinityKey ? getModelDetourAffinity(affinityKey, modelId, quotaScope) : undefined;
|
|
58
|
+
if (ordinary?.accountId === MAIN_CODEX_ACCOUNT_ID || detour?.accountId === MAIN_CODEX_ACCOUNT_ID)
|
|
59
|
+
return honestAffinityDecision(decision ?? { move: "reused", reason: "healthy" }, affinityKey, MAIN_CODEX_ACCOUNT_ID, quotaScope, modelId, requestOwnedKeyWithheld)!;
|
|
60
|
+
if (ordinary || detour) return { move: "detour", reason };
|
|
61
|
+
return { move: "unbound", reason: affinityKey ? decision?.reason ?? "healthy" : requestOwnedKeyWithheld ? "request_owned" : "no_conversation" };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Opaque process-local identity for the bindings present when main was selected. */
|
|
65
|
+
export type RequestOwnedBindingSnapshot = object;
|
|
66
|
+
type EntryIdentity = { entry: ThreadAffinityEntry; accountId: string; generation: number; createdAt: number };
|
|
67
|
+
const bindingSnapshots = new WeakMap<RequestOwnedBindingSnapshot, { key: string; scope?: CodexQuotaScope; modelId?: string; ordinary?: EntryIdentity; detour?: EntryIdentity }>();
|
|
68
|
+
|
|
69
|
+
function identity(entry: ThreadAffinityEntry | undefined): EntryIdentity | undefined {
|
|
70
|
+
return entry && { entry, accountId: entry.accountId, generation: entry.generation, createdAt: entry.createdAt };
|
|
71
|
+
}
|
|
72
|
+
function matches(captured: EntryIdentity | undefined, current: ThreadAffinityEntry | undefined): boolean {
|
|
73
|
+
return !!captured && captured.entry === current && captured.accountId === current.accountId
|
|
74
|
+
&& captured.generation === current.generation && captured.createdAt === current.createdAt;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Capture the exact entries that a request is authorized to release after selection. */
|
|
78
|
+
export function captureRequestOwnedAffinityBindings(key: string | undefined, scope?: CodexQuotaScope, modelId?: string): RequestOwnedBindingSnapshot | undefined {
|
|
79
|
+
if (!key || !isRequestOwnedAffinityKey(key)) return undefined;
|
|
80
|
+
const snapshot = {};
|
|
81
|
+
bindingSnapshots.set(snapshot, { key, scope, modelId, ordinary: identity(getThreadAffinity(key, scope)), detour: identity(getModelDetourAffinity(key, modelId, scope)) });
|
|
82
|
+
return snapshot;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Whether a context carries a caller-owned routing key. */
|
|
86
|
+
export function isKeyedRequestOwnedMain(ctx: CodexAuthContext): ctx is Extract<CodexAuthContext, { kind: "main" }> & { affinityKey: string } {
|
|
87
|
+
return ctx.kind === "main" && !!ctx.affinityKey && isRequestOwnedAffinityKey(ctx.affinityKey);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Release this caller’s scoped binding after its own main credential is refused. */
|
|
91
|
+
export function releaseRequestOwnedMainOnOutcome(ctx: CodexAuthContext, outcome: number, _modelId?: string): void {
|
|
92
|
+
if (!isKeyedRequestOwnedMain(ctx) || !ctx.affinityBindingSnapshot) return;
|
|
93
|
+
const snapshot = bindingSnapshots.get(ctx.affinityBindingSnapshot);
|
|
94
|
+
if (!snapshot || snapshot.key !== ctx.affinityKey) return;
|
|
95
|
+
const outcomeClass = classifyCodexUpstreamOutcome(outcome);
|
|
96
|
+
const reason: CodexAffinityReason | undefined = outcomeClass === "quota" ? "quota_refusal"
|
|
97
|
+
: outcomeClass === "credential" ? "unusable" : outcomeClass === "transient" ? "transient" : undefined;
|
|
98
|
+
if (!reason) return;
|
|
99
|
+
const key = ctx.affinityKey;
|
|
100
|
+
const { scope, modelId: selectedModelId } = snapshot;
|
|
101
|
+
let released = false;
|
|
102
|
+
const ordinary = getThreadAffinity(key, scope);
|
|
103
|
+
const detour = getModelDetourAffinity(key, selectedModelId, scope);
|
|
104
|
+
const mainDetour = matches(snapshot.detour, detour) && detour?.accountId === MAIN_CODEX_ACCOUNT_ID;
|
|
105
|
+
// A caller-main fallback or model detour can leave an ordinary binding on a different
|
|
106
|
+
// account. Retire it too so the next placement reports the release rather than reuse. If
|
|
107
|
+
// main was itself bound and another turn has since rebound elsewhere, keep that newer entry.
|
|
108
|
+
const callerMainDetour = ctx.affinityDecision?.move === "detour";
|
|
109
|
+
if (matches(snapshot.ordinary, ordinary) && (ordinary?.accountId === MAIN_CODEX_ACCOUNT_ID || mainDetour || callerMainDetour)) {
|
|
110
|
+
deleteThreadAffinity(key, scope);
|
|
111
|
+
released = true;
|
|
112
|
+
}
|
|
113
|
+
if (mainDetour) {
|
|
114
|
+
deleteModelDetourAffinity(key, selectedModelId, scope);
|
|
115
|
+
released = true;
|
|
116
|
+
}
|
|
117
|
+
if (released) notePendingReleaseReason(key, reason);
|
|
118
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { CodexAuthPolicyConfig } from "./auth-context";
|
|
2
|
+
import type { OcxConfig } from "../types";
|
|
3
|
+
import type { CodexQuotaScope } from "./routing";
|
|
4
|
+
import { MAIN_CODEX_ACCOUNT_ID } from "./account-id";
|
|
5
|
+
import { computeCodexUsageScore, getCodexQuotaHealthSnapshot, isEffectiveCodexAccountPinned } from "./routing";
|
|
6
|
+
import { getEffectiveCodexAutoSwitchThreshold } from "./account-auto-switch";
|
|
7
|
+
import { codexAccountUsesCreditsAfterLimit, codexUsageLimitResetAt } from "./account-credit-use";
|
|
8
|
+
import { CODEX_UNKNOWN_USAGE_SCORE, getAccountQuota, getMainPolicyQuota } from "./quota";
|
|
9
|
+
import { hasSpendableCodexCredits } from "./quota-types";
|
|
10
|
+
import { isMainAccountHardLocked } from "./main-account-hard-lock";
|
|
11
|
+
import { authorizationCredential } from "../lib/authorization-scheme";
|
|
12
|
+
import { extractAccountId } from "../oauth/chatgpt";
|
|
13
|
+
import { matchesMainQuotaCredential } from "./main-account-cache";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A request-owned bearer cannot inspect the physical main credential for its plan, but cached
|
|
17
|
+
* WHAM usage is still valid routing evidence for the same logical main account. Score it with
|
|
18
|
+
* the conservative unknown-plan rule: an unobserved governing window preserves the pin, while
|
|
19
|
+
* any known weekly/monthly/short value at the threshold releases it through the ordinary Pool
|
|
20
|
+
* path. This keeps the keyring boundary intact instead of reading auth.json just to classify a
|
|
21
|
+
* request that already brought its own credential (#3157).
|
|
22
|
+
*/
|
|
23
|
+
function requestOwnedMainPinHasQuotaHeadroom(config: OcxConfig): boolean {
|
|
24
|
+
const threshold = getEffectiveCodexAutoSwitchThreshold(config, MAIN_CODEX_ACCOUNT_ID);
|
|
25
|
+
if (threshold <= 0) return true;
|
|
26
|
+
const usage = computeCodexUsageScore(getAccountQuota(MAIN_CODEX_ACCOUNT_ID), undefined, Date.now(), codexAccountUsesCreditsAfterLimit(config, MAIN_CODEX_ACCOUNT_ID));
|
|
27
|
+
return usage >= CODEX_UNKNOWN_USAGE_SCORE || usage < threshold;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Whether a request carrying its OWN main credential still serves on main because the operator
|
|
32
|
+
* manually pinned it (#3166), split from the surrounding resolution so request preview can ask
|
|
33
|
+
* the identical question (#4850).
|
|
34
|
+
*
|
|
35
|
+
* Exported for exactly one reason: two copies of this fence is how #4850 happened. Final
|
|
36
|
+
* authentication honoured the ownership boundary while request preview, computing its fence from
|
|
37
|
+
* recovery and drain state alone, still handed pool eligibility the default liveness probe and
|
|
38
|
+
* opened the physical `auth.json` twice per spawn. A predicate one caller can forget is a
|
|
39
|
+
* predicate the other caller will eventually disagree with.
|
|
40
|
+
*
|
|
41
|
+
* Read-free by construction, which is what makes it usable on the fenced side. Every input is
|
|
42
|
+
* config, policy, or in-memory runtime state: the pin fields, the paused list, the cached quota
|
|
43
|
+
* score, the main policy quota the hard lock and the credits switch read, and `callerMatchesObservedMain`, which compares HMAC digests against the observed
|
|
44
|
+
* credential record in `main-account-cache.ts`. Nothing here opens a file.
|
|
45
|
+
*
|
|
46
|
+
* `candidate` is the pin before the hard-lock question, because the caller still owes the
|
|
47
|
+
* pending-binding check that only final authentication can fail closed on.
|
|
48
|
+
*/
|
|
49
|
+
export function requestOwnedMainPinState(
|
|
50
|
+
headers: Headers,
|
|
51
|
+
config: OcxConfig,
|
|
52
|
+
policy: CodexAuthPolicyConfig,
|
|
53
|
+
requestScopedMainCredential: boolean,
|
|
54
|
+
fixedAccountId: string | undefined,
|
|
55
|
+
quotaScope?: CodexQuotaScope,
|
|
56
|
+
): { candidate: boolean; preserve: boolean } {
|
|
57
|
+
const candidate = requestScopedMainCredential
|
|
58
|
+
&& fixedAccountId === undefined
|
|
59
|
+
&& config.activeCodexAccountPinned === MAIN_CODEX_ACCOUNT_ID
|
|
60
|
+
&& isEffectiveCodexAccountPinned(config)
|
|
61
|
+
&& !policy.pausedCodexAccountIds?.includes(MAIN_CODEX_ACCOUNT_ID)
|
|
62
|
+
&& requestOwnedMainPinHasQuotaHeadroom(config);
|
|
63
|
+
return {
|
|
64
|
+
candidate,
|
|
65
|
+
preserve: candidate && !(callerMatchesObservedMain(headers)
|
|
66
|
+
&& (isMainAccountHardLocked(policy)
|
|
67
|
+
|| mainCreditsHoldResetAt(policy) !== undefined
|
|
68
|
+
|| getCodexQuotaHealthSnapshot(MAIN_CODEX_ACCOUNT_ID, quotaScope)?.cooldownUntil)),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function mainCreditsHoldResetAt(config: Pick<OcxConfig, "creditCodexAccountIds">): number | undefined {
|
|
73
|
+
if (codexAccountUsesCreditsAfterLimit(config, MAIN_CODEX_ACCOUNT_ID)
|
|
74
|
+
&& hasSpendableCodexCredits(getMainPolicyQuota())) return undefined;
|
|
75
|
+
return codexUsageLimitResetAt(getMainPolicyQuota(), undefined, Date.now());
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
/** No auth-file I/O: an unsigned claim alone never identifies a caller as stored main. */
|
|
80
|
+
export function callerMatchesObservedMain(headers: Headers): boolean {
|
|
81
|
+
const bearer = authorizationCredential(headers);
|
|
82
|
+
if (!bearer) return false;
|
|
83
|
+
const effectiveAccountId = headers.get("chatgpt-account-id")
|
|
84
|
+
?? extractAccountId(undefined, bearer);
|
|
85
|
+
return matchesMainQuotaCredential(bearer, effectiveAccountId);
|
|
86
|
+
}
|
|
@@ -2,19 +2,21 @@
|
|
|
2
2
|
* Measured capability per task domain, so role auto-assign can tier candidates by what they score
|
|
3
3
|
* instead of what they cost. Artificial Analysis is read live when configured:
|
|
4
4
|
*
|
|
5
|
-
* - Artificial Analysis (https://artificialanalysis.ai/api
|
|
5
|
+
* - Artificial Analysis (https://artificialanalysis.ai/data-api/docs), when the user configures
|
|
6
6
|
* their own API key. Its terms allow that user's internal use with attribution and forbid
|
|
7
7
|
* redistributing the raw data, so its scores never leave this process.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* Every domain reads the Intelligence Index: Artificial Analysis no longer publishes a Coding or
|
|
10
|
+
* an Agentic Index (both are always null) and its free model list carries no math index. The
|
|
11
|
+
* source names a model by display name with one row per reasoning setting ("Claude Opus 5.5
|
|
12
|
+
* (High)"); capabilityModelKey drops the setting and folds the rest to a slug, which matches a
|
|
13
|
+
* catalog id once its provider prefix is gone ("cpa/claude-opus-5-5"). The best setting's score
|
|
14
|
+
* stands for the model, since a role can be given that setting. A candidate with no row is
|
|
15
|
+
* unmeasured, never guessed.
|
|
14
16
|
*/
|
|
15
17
|
import { resolveProviderApiKey } from "../providers/api-key-resolve";
|
|
16
18
|
import type { OcxConfig } from "../types";
|
|
17
|
-
import type
|
|
19
|
+
import { SIZING_DOMAINS, type SizingDomain } from "./role-sizing";
|
|
18
20
|
|
|
19
21
|
export interface CapabilitySource {
|
|
20
22
|
readonly name: string;
|
|
@@ -31,21 +33,23 @@ export const ARTIFICIAL_ANALYSIS_SOURCE: CapabilitySource = {
|
|
|
31
33
|
redistributable: false,
|
|
32
34
|
};
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
/**
|
|
37
|
+
* The free-tier language model list, which any key may read. It replaced
|
|
38
|
+
* /api/v2/data/llms/models, retired at 2026-11-04 23:59 UTC with 410 Gone afterwards
|
|
39
|
+
* (https://artificialanalysis.ai/data-api/migrate-v2-data).
|
|
40
|
+
*/
|
|
41
|
+
export const ARTIFICIAL_ANALYSIS_URL = "https://artificialanalysis.ai/api/v2/language/models/free";
|
|
35
42
|
|
|
36
|
-
/** Per domain, the indexes to read in order; the first one the response carries is used. */
|
|
37
43
|
const INTELLIGENCE_INDEX = "artificial_analysis_intelligence_index";
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
general: [INTELLIGENCE_INDEX],
|
|
45
|
-
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Pages read per refresh. The list is paginated (200 rows a page in the published example, two
|
|
47
|
+
* pages); ten pages bound one daily refresh to a tenth of the free tier's 100 requests a day.
|
|
48
|
+
*/
|
|
49
|
+
export const MAX_TABLE_PAGES = 10;
|
|
46
50
|
|
|
47
51
|
const FETCH_TIMEOUT_MS = 30_000;
|
|
48
|
-
/**
|
|
52
|
+
/** The bytes all pages of one refresh may total; the list is under 1 MB today, 16 MB still bounds memory. */
|
|
49
53
|
export const MAX_TABLE_BYTES = 16 * 1024 * 1024;
|
|
50
54
|
|
|
51
55
|
export interface CapabilityTable {
|
|
@@ -74,22 +78,15 @@ function keepBest(scores: Map<string, number>, key: string, value: number) {
|
|
|
74
78
|
export function capabilityTableFromArtificialAnalysis(body: unknown): CapabilityTable {
|
|
75
79
|
const rows = (body as { data?: unknown } | null)?.data;
|
|
76
80
|
if (!Array.isArray(rows)) throw new Error("Artificial Analysis returned no model list");
|
|
77
|
-
const
|
|
78
|
-
for (const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (typeof value !== "number" || !Number.isFinite(value)) continue;
|
|
84
|
-
if (typeof row.name === "string") keepBest(scores, capabilityModelKey(row.name), value);
|
|
85
|
-
if (typeof row.slug === "string") keepBest(scores, capabilityModelKey(row.slug), value);
|
|
86
|
-
}
|
|
87
|
-
if (scores.size > 0) {
|
|
88
|
-
domains[domain] = scores;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
81
|
+
const scores = new Map<string, number>();
|
|
82
|
+
for (const row of rows as Record<string, unknown>[]) {
|
|
83
|
+
const value = (row?.evaluations as Record<string, unknown> | undefined)?.[INTELLIGENCE_INDEX];
|
|
84
|
+
if (typeof value !== "number" || !Number.isFinite(value)) continue;
|
|
85
|
+
if (typeof row.name === "string") keepBest(scores, capabilityModelKey(row.name), value);
|
|
86
|
+
if (typeof row.slug === "string") keepBest(scores, capabilityModelKey(row.slug), value);
|
|
92
87
|
}
|
|
88
|
+
const domains: Partial<Record<SizingDomain, ReadonlyMap<string, number>>> = {};
|
|
89
|
+
if (scores.size > 0) for (const domain of SIZING_DOMAINS) domains[domain] = scores;
|
|
93
90
|
return { source: ARTIFICIAL_ANALYSIS_SOURCE, publishedAt: null, domains };
|
|
94
91
|
}
|
|
95
92
|
|
|
@@ -118,15 +115,29 @@ export async function readBoundedBytes(response: Response, maxBytes: number): Pr
|
|
|
118
115
|
return out.buffer;
|
|
119
116
|
}
|
|
120
117
|
|
|
118
|
+
/** A list past either bound fails whole, so price ranking takes over rather than tiering on part of it. */
|
|
121
119
|
export async function fetchArtificialAnalysisTable(apiKey: string, fetchImpl: typeof fetch = fetch): Promise<CapabilityTable> {
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
120
|
+
const rows: unknown[] = [];
|
|
121
|
+
let budget = MAX_TABLE_BYTES;
|
|
122
|
+
for (let page = 1; page <= MAX_TABLE_PAGES; page++) {
|
|
123
|
+
const url = new URL(ARTIFICIAL_ANALYSIS_URL);
|
|
124
|
+
url.searchParams.set("page", String(page));
|
|
125
|
+
const response = await fetchImpl(url.href, {
|
|
126
|
+
redirect: "error",
|
|
127
|
+
headers: { "x-api-key": apiKey },
|
|
128
|
+
signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
|
|
129
|
+
});
|
|
130
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
131
|
+
const bytes = await readBoundedBytes(response, budget);
|
|
132
|
+
budget -= bytes.byteLength;
|
|
133
|
+
const body = JSON.parse(new TextDecoder().decode(bytes)) as { data?: unknown; pagination?: { has_more?: unknown } } | null;
|
|
134
|
+
if (!Array.isArray(body?.data)) throw new Error("Artificial Analysis returned no model list");
|
|
135
|
+
const hasMore = body.pagination?.has_more;
|
|
136
|
+
if (typeof hasMore !== "boolean") throw new Error("Artificial Analysis returned no pagination.has_more");
|
|
137
|
+
rows.push(...body.data);
|
|
138
|
+
if (!hasMore) return capabilityTableFromArtificialAnalysis({ data: rows });
|
|
139
|
+
}
|
|
140
|
+
throw new Error(`Artificial Analysis listed more than ${MAX_TABLE_PAGES} pages`);
|
|
130
141
|
}
|
|
131
142
|
|
|
132
143
|
/** One fetch per period key; a failed fetch is forgotten so the next request retries. */
|
|
@@ -32,13 +32,14 @@ let runtimeActiveCodexAccountId: string | undefined;
|
|
|
32
32
|
|
|
33
33
|
/** Manual selection resets transient routing evidence without bypassing a real 429 cooldown. */
|
|
34
34
|
export function resetCodexRoutingForManualSelection(accountId: string): void {
|
|
35
|
-
clearThreadAccountMap();
|
|
35
|
+
clearThreadAccountMap({ preserveConversationStateIssuers: true });
|
|
36
36
|
// Manual selection is the operator source of truth — drop any automatic runtime cursor.
|
|
37
37
|
runtimeActiveCodexAccountId = undefined;
|
|
38
|
-
// Record the pick as an unspent one-shot on the
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
//
|
|
38
|
+
// Record the pick as an unspent one-shot on the shared scope and on each independent scope
|
|
39
|
+
// whose ring is seeded below. The cursor guard (`manualPreferenceBlocks`) still only acts on
|
|
40
|
+
// the shared scope: every write site it protects skips independent scopes. The independent
|
|
41
|
+
// entries have exactly one reader, round-robin placement, which keeps the selected account
|
|
42
|
+
// among its candidates until a dispatch in that scope spends the entry.
|
|
42
43
|
//
|
|
43
44
|
// Seeding happens ONLY here. A pool-driven promote must never create or move a preference,
|
|
44
45
|
// or the pool would manufacture an operator intent nobody expressed.
|
|
@@ -50,6 +51,7 @@ export function resetCodexRoutingForManualSelection(accountId: string): void {
|
|
|
50
51
|
for (const scope of new Set(Object.values(NATIVE_MODEL_QUOTA_SCOPES))) {
|
|
51
52
|
if (isIndependentCodexQuotaScope(scope)) {
|
|
52
53
|
seedPoolRotationAccount(codexPoolKeyForScope(scope), accountId);
|
|
54
|
+
manualPreference.set(codexPoolKeyForScope(scope), accountId);
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
// Quota avoidance is a preference, like the soft avoid dropped above, and an operator naming
|
|
@@ -91,6 +93,7 @@ export function resetCodexRoutingForClearedSelection(): void {
|
|
|
91
93
|
for (const scope of new Set(Object.values(NATIVE_MODEL_QUOTA_SCOPES))) {
|
|
92
94
|
if (isIndependentCodexQuotaScope(scope)) {
|
|
93
95
|
clearPoolRotationState(codexPoolKeyForScope(scope));
|
|
96
|
+
manualPreference.delete(codexPoolKeyForScope(scope));
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
}
|
|
@@ -143,6 +146,11 @@ export function manualPreferenceBlocks(poolKey: string, accountId: string): bool
|
|
|
143
146
|
return preferred !== undefined && preferred !== accountId;
|
|
144
147
|
}
|
|
145
148
|
|
|
149
|
+
/** The unspent operator selection for this pool scope, if any. Read-only. */
|
|
150
|
+
export function unspentManualPreference(poolKey: string): string | undefined {
|
|
151
|
+
return manualPreference.get(poolKey);
|
|
152
|
+
}
|
|
153
|
+
|
|
146
154
|
export function getEffectiveActiveCodexAccountId(config: OcxConfig): string | undefined {
|
|
147
155
|
return runtimeActiveCodexAccountId ?? config.activeCodexAccountId;
|
|
148
156
|
}
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
promoteActiveCodexAccount,
|
|
40
40
|
rememberActiveCodexAccount,
|
|
41
41
|
setActiveCodexAccount,
|
|
42
|
+
unspentManualPreference,
|
|
42
43
|
} from "./active-account";
|
|
43
44
|
|
|
44
45
|
/**
|
|
@@ -302,6 +303,38 @@ export function hasCodexQuotaHeadroom(
|
|
|
302
303
|
return usage < threshold;
|
|
303
304
|
}
|
|
304
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Where round-robin may place a NEW conversation: the eligible accounts that still have headroom
|
|
308
|
+
* under their own threshold, or the whole eligible list when none does.
|
|
309
|
+
*
|
|
310
|
+
* Rotation by count alone put a fresh conversation on an account already at 95%. The conversation
|
|
311
|
+
* binds there, and when the account runs out it has to move to another account with a cold prompt
|
|
312
|
+
* cache. Preferring headroom at placement avoids that hop without touching anything already bound:
|
|
313
|
+
* live bindings never reach this function, and failover ({@link pickAlternateCodexAccount}) keeps
|
|
314
|
+
* plain ring order because leaving a failing account is not a placement.
|
|
315
|
+
*
|
|
316
|
+
* The score is {@link hasCodexQuotaHeadroom}, the one fill-first and the priority tier already use,
|
|
317
|
+
* so a threshold of 0 or unknown usage counts as headroom. It is a preference, never eligibility:
|
|
318
|
+
* when every account is at or over its threshold the ring sees the full list, exactly as before.
|
|
319
|
+
*
|
|
320
|
+
* An operator's unspent manual selection for this scope stays in the list whatever its usage.
|
|
321
|
+
* Manual selection seeds the ring so the next placement lands on the chosen account, and a
|
|
322
|
+
* preference must not overrule a person's explicit choice: dropping it here would clear that seed.
|
|
323
|
+
* Once a dispatch on it succeeds the selection is spent and the account is treated like any other.
|
|
324
|
+
*/
|
|
325
|
+
function roundRobinPlacementCandidates(
|
|
326
|
+
config: OcxConfig,
|
|
327
|
+
eligible: readonly string[],
|
|
328
|
+
now: number,
|
|
329
|
+
quotaScope?: CodexQuotaScope,
|
|
330
|
+
selectionOptions?: CodexAccountUsabilityOptions,
|
|
331
|
+
): readonly string[] {
|
|
332
|
+
const operatorChoice = unspentManualPreference(codexPoolKeyForScope(quotaScope));
|
|
333
|
+
const withHeadroom = eligible.filter(id =>
|
|
334
|
+
id === operatorChoice || hasCodexQuotaHeadroom(config, id, selectionOptions, now));
|
|
335
|
+
return withHeadroom.length > 0 ? withHeadroom : eligible;
|
|
336
|
+
}
|
|
337
|
+
|
|
305
338
|
/**
|
|
306
339
|
* Is a live binding held for its prompt cache?
|
|
307
340
|
*
|
|
@@ -475,7 +508,13 @@ export function pickUnboundStrategyAccount(
|
|
|
475
508
|
|
|
476
509
|
let picked: string | null = null;
|
|
477
510
|
if (strategy === "round-robin") {
|
|
478
|
-
const eligible =
|
|
511
|
+
const eligible = roundRobinPlacementCandidates(
|
|
512
|
+
config,
|
|
513
|
+
listEligibleCodexAccountIds(config, now, quotaScope, selectionOptions),
|
|
514
|
+
now,
|
|
515
|
+
quotaScope,
|
|
516
|
+
selectionOptions,
|
|
517
|
+
);
|
|
479
518
|
const limit = stickyLimitForConfig(config);
|
|
480
519
|
if (!commit) {
|
|
481
520
|
return peekRoundRobinAccount(poolKey, eligible, limit);
|