@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/usage/log.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { FailureDetail } from "../lib/failure-detail";
|
|
2
|
+
import { boundedModelIdentity, knownModelIdentity } from "../lib/model-identity";
|
|
3
|
+
import { boundedServiceTier } from "../lib/response-service-tier";
|
|
1
4
|
import { createHash, type Hash } from "node:crypto";
|
|
2
5
|
import { chmodSync, closeSync, existsSync, fstatSync, mkdirSync, openSync, readFileSync, readSync, appendFileSync } from "node:fs";
|
|
3
6
|
import { join } from "node:path";
|
|
@@ -5,8 +8,9 @@ import { getConfigDir } from "../config";
|
|
|
5
8
|
import type { CodexAffinityMove, CodexAffinityReason } from "../codex/routing";
|
|
6
9
|
import { enforceAppOwnedMemoryBudget } from "../lib/app-owned-memory";
|
|
7
10
|
import { recordOwnedConfigPath } from "../lib/config-ownership";
|
|
8
|
-
import {
|
|
11
|
+
import { sanitizeLogMetadataString } from "../lib/redact";
|
|
9
12
|
import { usageDisplayTotalTokens } from "./totals";
|
|
13
|
+
import { normalizeRecordedClient, type UsageClient } from "./client";
|
|
10
14
|
import {
|
|
11
15
|
normalizePersistedJevDecision,
|
|
12
16
|
type PersistedJevDecisionV1,
|
|
@@ -23,6 +27,8 @@ import { normalizeRouteDecisionTrace, type RouteDecisionTraceV1 } from "../routi
|
|
|
23
27
|
import { parseProtocolTraceV1, type ProtocolTraceV1 } from "../protocols/dto";
|
|
24
28
|
import { ACCOUNT_LOG_LABEL_RE, CODEX_ACCOUNT_LOG_LABEL_RE } from "../codex/account-label";
|
|
25
29
|
import { claudeCompatibilityReason, normalizeClaudeFeatureCodes, type ClaudeFeatureCode } from "../claude/compatibility";
|
|
30
|
+
import type { UpstreamCondition } from "../lib/upstream-condition";
|
|
31
|
+
import { errorDetailFor, normalizeLogErrorCode } from "./error-detail";
|
|
26
32
|
import type { CodexWsStageRecord, CodexWsTerminalEvent } from "../server/responses/codex-ws-wire";
|
|
27
33
|
import {
|
|
28
34
|
ATTEMPT_RECOVERY_KIND_ROSTER,
|
|
@@ -299,6 +305,8 @@ export function normalizeRequestSpend(value: unknown): PersistedRequestSpend | u
|
|
|
299
305
|
export interface PersistedUsageEntry {
|
|
300
306
|
requestedAlias?: string;
|
|
301
307
|
requestId: string;
|
|
308
|
+
/** Best-effort classified client; absent only for records predating attribution. */
|
|
309
|
+
client?: UsageClient;
|
|
302
310
|
/**
|
|
303
311
|
* Identity of the ONE logical request this row belongs to (#4546), minted by
|
|
304
312
|
* `createRequestExecutionBudget` at ingress. `requestId` identifies a log row; a retry layer,
|
|
@@ -370,8 +378,17 @@ export interface PersistedUsageEntry {
|
|
|
370
378
|
*/
|
|
371
379
|
terminalStatus?: RequestTerminalStatus;
|
|
372
380
|
closeReason?: RequestCloseReason;
|
|
373
|
-
/**
|
|
381
|
+
/**
|
|
382
|
+
* Legacy input only: older rows carried upstream error text here. It is read once on load to
|
|
383
|
+
* derive upstreamCondition / rateLimitResetAt and is never written or returned.
|
|
384
|
+
*/
|
|
374
385
|
upstreamError?: string;
|
|
386
|
+
/** Proxy-classified upstream condition (src/lib/upstream-condition.ts); a closed enum. */
|
|
387
|
+
upstreamCondition?: UpstreamCondition;
|
|
388
|
+
/** Provider quota window end in epoch ms, derived server-side and bounded (src/usage/error-detail.ts). */
|
|
389
|
+
rateLimitResetAt?: number;
|
|
390
|
+
/** Proxy-authored failure text (src/server/request-log-failure-detail.ts), never upstream text. */
|
|
391
|
+
failureDetail?: FailureDetail;
|
|
375
392
|
/** Where the terminal/failure was observed; absent on historic rows. */
|
|
376
393
|
transportPhase?: "pre_headers" | "mid_stream" | "terminal_sse";
|
|
377
394
|
/** Whether the terminal came from upstream or a proxy-generated tail. */
|
|
@@ -507,10 +524,10 @@ export function isKnownTerminalSource(value: unknown): value is NonNullable<Pers
|
|
|
507
524
|
* call site and it never reached disk for exactly that reason.
|
|
508
525
|
*/
|
|
509
526
|
const KNOWN_AFFINITY_MOVES = new Set<NonNullable<PersistedUsageEntry["affinity"]>>([
|
|
510
|
-
"reused", "held", "detour", "rebound", "new_bind", "cleared",
|
|
527
|
+
"reused", "held", "detour", "rebound", "new_bind", "cleared", "unbound",
|
|
511
528
|
]);
|
|
512
529
|
const KNOWN_AFFINITY_REASONS = new Set<NonNullable<PersistedUsageEntry["affinityReason"]>>([
|
|
513
|
-
"healthy", "quota_headroom", "quota_refusal", "transient", "transient_hold_expired",
|
|
530
|
+
"healthy", "no_conversation", "request_owned", "quota_headroom", "quota_refusal", "transient", "transient_hold_expired",
|
|
514
531
|
"unusable", "paused", "plan_excluded", "credits_off", "cooldown", "quota_avoided", "generation",
|
|
515
532
|
"expired", "model_lane",
|
|
516
533
|
]);
|
|
@@ -672,7 +689,7 @@ function normalizeAttemptTierOutcome(raw: unknown): AttemptTierOutcome | null {
|
|
|
672
689
|
if ("responseServiceTier" in outcome && typeof outcome.responseServiceTier !== "string") return null;
|
|
673
690
|
if ("responseTierAuthoritative" in outcome && typeof outcome.responseTierAuthoritative !== "boolean") return null;
|
|
674
691
|
const wireValue = sanitizeLogMetadataString(outcome.wireValue);
|
|
675
|
-
const responseServiceTier =
|
|
692
|
+
const responseServiceTier = boundedServiceTier(outcome.responseServiceTier);
|
|
676
693
|
return {
|
|
677
694
|
...(outcome.canonical === "priority" ? { canonical: "priority" as const } : {}),
|
|
678
695
|
...(outcome.wireKind === null
|
|
@@ -750,6 +767,7 @@ function normalizeUsageAttempt(raw: unknown): PersistedUsageAttempt | null {
|
|
|
750
767
|
&& ATTEMPT_RECOVERY_WITHHELD.has(value as AttemptRecoveryWithheld),
|
|
751
768
|
))]
|
|
752
769
|
: [];
|
|
770
|
+
const attemptErrorCode = normalizeLogErrorCode(attempt.errorCode, attempt.status as number);
|
|
753
771
|
return {
|
|
754
772
|
ordinal: attempt.ordinal as number,
|
|
755
773
|
provider: attempt.provider,
|
|
@@ -781,7 +799,7 @@ function normalizeUsageAttempt(raw: unknown): PersistedUsageAttempt | null {
|
|
|
781
799
|
...(isNonNegativeFiniteNumber(attempt.totalTokens)
|
|
782
800
|
? { totalTokens: attempt.totalTokens }
|
|
783
801
|
: {}),
|
|
784
|
-
...(
|
|
802
|
+
...(attemptErrorCode ? { errorCode: attemptErrorCode } : {}),
|
|
785
803
|
...(isKnownCacheTelemetryProvenance(attempt.cacheProvenance)
|
|
786
804
|
? { cacheProvenance: attempt.cacheProvenance }
|
|
787
805
|
: {}),
|
|
@@ -896,19 +914,9 @@ function capMetadataString(s: string): string {
|
|
|
896
914
|
return s.length > MAX_METADATA_STRING_LEN ? s.slice(0, MAX_METADATA_STRING_LEN) : s;
|
|
897
915
|
}
|
|
898
916
|
|
|
899
|
-
|
|
900
|
-
/**
|
|
901
|
-
* An upstream model is an identifier, never free-form text to truncate into one. A value the
|
|
902
|
-
* secret redactor would change is dropped rather than logged, because credential-shaped text can
|
|
903
|
-
* fit the identifier alphabet.
|
|
904
|
-
*/
|
|
917
|
+
/** Served and resolved models on a row use the shared model-identity bound (src/lib/model-identity.ts). */
|
|
905
918
|
export function sanitizeServedModel(value: unknown): string | undefined {
|
|
906
|
-
return
|
|
907
|
-
&& value.length <= MAX_SERVED_MODEL_LENGTH
|
|
908
|
-
&& /^[A-Za-z0-9._:/@+-]+$/.test(value)
|
|
909
|
-
&& redactSecretString(value) === value
|
|
910
|
-
? value
|
|
911
|
-
: undefined;
|
|
919
|
+
return boundedModelIdentity(value);
|
|
912
920
|
}
|
|
913
921
|
|
|
914
922
|
/** The identity fields that decide whether a response model is ocx's own echo. */
|
|
@@ -941,28 +949,56 @@ export function isClientSelectorEcho(source: ServedModelEchoSource, served: stri
|
|
|
941
949
|
|
|
942
950
|
/** Record a response-body model as the served model when it is a real upstream observation. */
|
|
943
951
|
export function recordObservedServedModel(
|
|
944
|
-
target: ServedModelEchoSource & { servedModel?: string; resolvedModel?: string; preserveResolvedModelFromRoute?: boolean },
|
|
952
|
+
target: ServedModelEchoSource & { servedModel?: string; resolvedModel?: string; preserveResolvedModelFromRoute?: boolean; attempts?: unknown },
|
|
945
953
|
value: unknown,
|
|
946
954
|
): void {
|
|
947
|
-
const servedModel =
|
|
955
|
+
const servedModel = knownModelIdentity(value, routeKnownModels(target), target.provider);
|
|
948
956
|
if (!servedModel || isClientSelectorEcho(target, servedModel)) return;
|
|
949
957
|
target.servedModel = servedModel;
|
|
950
958
|
if (!target.preserveResolvedModelFromRoute) target.resolvedModel = servedModel;
|
|
951
959
|
}
|
|
952
960
|
|
|
961
|
+
/**
|
|
962
|
+
* Model ids a row's own route already names, which an upstream-reported served or resolved model
|
|
963
|
+
* must equal to be recorded: the routed model (also without its provider prefix), the wire model,
|
|
964
|
+
* the requested model and alias, and each attempt's target. The bundled Codex catalog is checked
|
|
965
|
+
* by {@link knownModelIdentity} itself.
|
|
966
|
+
*/
|
|
967
|
+
export function routeKnownModels(source: ServedModelEchoSource & { attempts?: unknown }): string[] {
|
|
968
|
+
const known: string[] = [];
|
|
969
|
+
const add = (value: unknown) => { if (typeof value === "string" && value) known.push(value); };
|
|
970
|
+
add(source.model);
|
|
971
|
+
if (typeof source.model === "string" && source.model.includes("/")) add(source.model.slice(source.model.indexOf("/") + 1));
|
|
972
|
+
add(source.wireModel);
|
|
973
|
+
add(source.requestedModel);
|
|
974
|
+
add(source.requestedAlias);
|
|
975
|
+
if (Array.isArray(source.attempts)) {
|
|
976
|
+
for (const attempt of source.attempts as unknown[]) {
|
|
977
|
+
if (attempt && typeof attempt === "object") {
|
|
978
|
+
add((attempt as { model?: unknown }).model);
|
|
979
|
+
add((attempt as { wireModel?: unknown }).wireModel);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
return known;
|
|
984
|
+
}
|
|
985
|
+
|
|
953
986
|
/**
|
|
954
987
|
* Model identity fields for a log row. The served model is sanitized, and a resolvedModel that
|
|
955
988
|
* only echoed a dropped served model is dropped with it, so the rejected value cannot survive
|
|
956
989
|
* under the other name. A client-selector echo is dropped the same way, which also repairs
|
|
957
|
-
* rows persisted before the echo was filtered at capture.
|
|
990
|
+
* rows persisted before the echo was filtered at capture. Both are kept only when they equal a
|
|
991
|
+
* model id the row's route already names (or the bundled catalog pins); see {@link knownModelIdentity}.
|
|
958
992
|
*/
|
|
959
|
-
export function modelIdentityLogFields(source: ServedModelEchoSource & { resolvedModel?: string; servedModel?: unknown }): {
|
|
993
|
+
export function modelIdentityLogFields(source: ServedModelEchoSource & { resolvedModel?: string; servedModel?: unknown; attempts?: unknown }): {
|
|
960
994
|
resolvedModel?: string; servedModel?: string; wireModel?: string;
|
|
961
995
|
} {
|
|
962
|
-
const
|
|
996
|
+
const known = routeKnownModels(source);
|
|
997
|
+
const sanitized = knownModelIdentity(source.servedModel, known, source.provider);
|
|
963
998
|
const servedModel = isClientSelectorEcho(source, sanitized) ? undefined : sanitized;
|
|
999
|
+
// The resolved model passes the same validator on its own; it also leaves with a dropped served echo.
|
|
964
1000
|
const resolvedModel = source.servedModel !== undefined && source.resolvedModel === source.servedModel && !servedModel
|
|
965
|
-
? undefined : source.resolvedModel;
|
|
1001
|
+
? undefined : knownModelIdentity(source.resolvedModel, known, source.provider);
|
|
966
1002
|
return {
|
|
967
1003
|
...(resolvedModel ? { resolvedModel } : {}),
|
|
968
1004
|
...(servedModel ? { servedModel } : {}),
|
|
@@ -979,7 +1015,7 @@ function normalizeUsageEntry(entry: PersistedUsageEntry): PersistedUsageEntry {
|
|
|
979
1015
|
const attempts = normalizedAttempts(entry.attempts);
|
|
980
1016
|
const tierOutcome = entry.tierOutcome ? normalizeAttemptTierOutcome(entry.tierOutcome) : undefined;
|
|
981
1017
|
const callerServiceTier = sanitizeLogMetadataString(entry.callerServiceTier);
|
|
982
|
-
const responseServiceTier =
|
|
1018
|
+
const responseServiceTier = boundedServiceTier(entry.responseServiceTier);
|
|
983
1019
|
const shadowCallRewrittenFrom = sanitizeLogMetadataString(entry.shadowCallRewrittenFrom);
|
|
984
1020
|
const { servedModel, resolvedModel } = modelIdentityLogFields(entry);
|
|
985
1021
|
const claudeCompatibility = normalizeClaudeCompatibilityUsageLog(entry.claudeCompatibility);
|
|
@@ -1002,6 +1038,7 @@ function normalizeUsageEntry(entry: PersistedUsageEntry): PersistedUsageEntry {
|
|
|
1002
1038
|
const protocolTrace = parseProtocolTraceV1(entry.protocolTrace);
|
|
1003
1039
|
const normalized: PersistedUsageEntry = {
|
|
1004
1040
|
requestId: entry.requestId,
|
|
1041
|
+
...(Object.hasOwn(entry, "client") ? { client: normalizeRecordedClient(entry.client) ?? "unknown" } : {}),
|
|
1005
1042
|
...(isLogicalRequestId(entry.logicalRequestId) ? { logicalRequestId: entry.logicalRequestId } : {}),
|
|
1006
1043
|
timestamp: entry.timestamp,
|
|
1007
1044
|
provider: entry.provider,
|
|
@@ -1086,13 +1123,13 @@ function normalizeUsageEntry(entry: PersistedUsageEntry): PersistedUsageEntry {
|
|
|
1086
1123
|
...(affinity ? { affinity } : {}),
|
|
1087
1124
|
...(affinityReason ? { affinityReason } : {}),
|
|
1088
1125
|
...(conversationStateScrub ? { conversationStateScrub } : {}),
|
|
1089
|
-
|
|
1126
|
+
// Closed code, classified condition and numeric reset only; upstream text is never kept.
|
|
1127
|
+
...errorDetailFor(entry),
|
|
1090
1128
|
// Validated rather than copied on truthiness, like the inbound protocol and transport phase
|
|
1091
1129
|
// above. Harmless while these were only rendered; not harmless once the terminal status is
|
|
1092
1130
|
// a grouping-key slot, because the string is assembled from an upstream frame.
|
|
1093
1131
|
...(isRequestTerminalStatus(entry.terminalStatus) ? { terminalStatus: entry.terminalStatus } : {}),
|
|
1094
1132
|
...(isRequestCloseReason(entry.closeReason) ? { closeReason: entry.closeReason } : {}),
|
|
1095
|
-
...(entry.upstreamError ? { upstreamError: entry.upstreamError } : {}),
|
|
1096
1133
|
...(routeDecision ? { routeDecision } : {}),
|
|
1097
1134
|
...(jevDecision ? { jevDecision } : {}),
|
|
1098
1135
|
...(claudeCompatibility ? { claudeCompatibility } : {}),
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { PersistedUsageEntry } from "./log";
|
|
2
|
+
import { isLegacyCodexUsage, matchesUsageSource, snapshotConfiguredKeyIds, USAGE_SOURCE_CLIENTS,
|
|
3
|
+
type UsageDeviceFilter, type UsageSourceClient, type UsageSourceFilter } from "./source-filter";
|
|
4
|
+
import type { UsageTimeWindow } from "./time-range";
|
|
5
|
+
|
|
6
|
+
/** Fold request rows once. Only currently configured IDs get individual counters. */
|
|
7
|
+
export function createSourceFacetAccumulator(filter: UsageSourceFilter, ids: readonly string[], window: UsageTimeWindow) {
|
|
8
|
+
const configured = new Set(snapshotConfiguredKeyIds(ids));
|
|
9
|
+
const apps = Object.fromEntries(USAGE_SOURCE_CLIENTS.map(client => [client, 0])) as Record<UsageSourceClient, number>;
|
|
10
|
+
// Preserve every exact ID in `configured` for filtering, but do not advertise an
|
|
11
|
+
// ID the wire contract cannot select (a padded ID cannot be safely trimmed).
|
|
12
|
+
const selectable = [...configured].filter(id => id === id.trim()).sort();
|
|
13
|
+
const unavailableConfiguredKeys = configured.size - selectable.length;
|
|
14
|
+
const keys = new Map(selectable.map(id => [id, 0]));
|
|
15
|
+
let all = 0;
|
|
16
|
+
let noKey = 0;
|
|
17
|
+
let unconfigured = 0;
|
|
18
|
+
let legacyUnclassifiedRequests = 0;
|
|
19
|
+
const selectedDevice = { ...filter.device };
|
|
20
|
+
const matches = (entry: PersistedUsageEntry, client: UsageSourceClient, device: UsageDeviceFilter) =>
|
|
21
|
+
matchesUsageSource(entry, { client, device }, configured);
|
|
22
|
+
return {
|
|
23
|
+
add(entry: PersistedUsageEntry) {
|
|
24
|
+
if (!Number.isFinite(entry.timestamp) || entry.timestamp < window.since || entry.timestamp > window.until) return;
|
|
25
|
+
for (const client of USAGE_SOURCE_CLIENTS) {
|
|
26
|
+
if (matches(entry, client, selectedDevice)) apps[client] += 1;
|
|
27
|
+
}
|
|
28
|
+
// This is the unclassified subset of the Codex option, independently of the
|
|
29
|
+
// currently selected app; the app facets all share the selected device scope.
|
|
30
|
+
if (matches(entry, "codex", selectedDevice) && isLegacyCodexUsage(entry)) legacyUnclassifiedRequests += 1;
|
|
31
|
+
if (!matches(entry, filter.client, { kind: "all" })) return;
|
|
32
|
+
all += 1;
|
|
33
|
+
if (entry.apiKeyId === undefined) noKey += 1;
|
|
34
|
+
else if (keys.has(entry.apiKeyId)) keys.set(entry.apiKeyId, keys.get(entry.apiKeyId)! + 1);
|
|
35
|
+
if (matches(entry, filter.client, { kind: "unconfigured" })) unconfigured += 1;
|
|
36
|
+
},
|
|
37
|
+
snapshot() {
|
|
38
|
+
return {
|
|
39
|
+
apps: { ...apps },
|
|
40
|
+
devices: [
|
|
41
|
+
{ device: { kind: "all" as const }, requests: all },
|
|
42
|
+
{ device: { kind: "no-key" as const }, requests: noKey },
|
|
43
|
+
...[...keys].map(([id, requests]) => ({ device: { kind: "key" as const, id }, requests })),
|
|
44
|
+
{ device: { kind: "unconfigured" as const }, requests: unconfigured },
|
|
45
|
+
],
|
|
46
|
+
legacyUnclassifiedRequests,
|
|
47
|
+
unavailableConfiguredKeys,
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { PersistedUsageEntry } from "./log";
|
|
2
|
+
|
|
3
|
+
export const USAGE_SOURCE_CLIENTS = [
|
|
4
|
+
"all", "codex", "claude_code", "claude_desktop", "grok", "opencode", "aside", "other", "unknown",
|
|
5
|
+
] as const;
|
|
6
|
+
export type UsageSourceClient = (typeof USAGE_SOURCE_CLIENTS)[number];
|
|
7
|
+
export type UsageDeviceFilter = { kind: "all" | "no-key" | "unconfigured" } | { kind: "key"; id: string };
|
|
8
|
+
export interface UsageSourceFilter { client: UsageSourceClient; device: UsageDeviceFilter }
|
|
9
|
+
|
|
10
|
+
/** Reject excessive snapshots instead of truncating identity or retaining unbounded keys. */
|
|
11
|
+
export const MAX_USAGE_CONFIGURED_KEYS = 1024;
|
|
12
|
+
export function snapshotConfiguredKeyIds(ids: readonly string[]): string[] {
|
|
13
|
+
if (ids.length > MAX_USAGE_CONFIGURED_KEYS) throw new Error("configured key snapshot exceeds limit");
|
|
14
|
+
let size = 0;
|
|
15
|
+
for (const id of ids) {
|
|
16
|
+
if (typeof id !== "string" || !id || id.length > 256 || (size += id.length) > 65536) {
|
|
17
|
+
throw new Error("configured key snapshot exceeds limit");
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return [...new Set(ids)].sort();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Old rows in the historic Codex surface are disclosed as unclassified, never as a subtype. */
|
|
24
|
+
export function isLegacyCodexUsage(entry: PersistedUsageEntry): boolean {
|
|
25
|
+
return entry.client === undefined && entry.surface === undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function matchesUsageSource(entry: PersistedUsageEntry, filter: UsageSourceFilter, configuredIds?: ReadonlySet<string>): boolean {
|
|
29
|
+
const device = filter.device;
|
|
30
|
+
if (device.kind === "no-key" && entry.apiKeyId !== undefined) return false;
|
|
31
|
+
if (device.kind === "key" && entry.apiKeyId !== device.id) return false;
|
|
32
|
+
if (device.kind === "unconfigured" && (!configuredIds || entry.admissionKind !== "configured"
|
|
33
|
+
|| !entry.apiKeyId || configuredIds.has(entry.apiKeyId))) return false;
|
|
34
|
+
if (filter.client === "all") return true;
|
|
35
|
+
if (filter.client === "codex") {
|
|
36
|
+
return isLegacyCodexUsage(entry) || entry.client === "codex_cli"
|
|
37
|
+
|| entry.client === "codex_desktop" || entry.client === "codex_ide";
|
|
38
|
+
}
|
|
39
|
+
if (filter.client === "unknown") return entry.client === "unknown" || (entry.client === undefined && !isLegacyCodexUsage(entry));
|
|
40
|
+
return entry.client === filter.client;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type ParsedUsageSource =
|
|
44
|
+
| { kind: "legacy" }
|
|
45
|
+
| { kind: "invalid" }
|
|
46
|
+
| { kind: "filtered"; filter: UsageSourceFilter };
|
|
47
|
+
|
|
48
|
+
/** Parse a management query without letting absent or malformed fields broaden its scope. */
|
|
49
|
+
export function parseUsageSource(params: URLSearchParams): ParsedUsageSource {
|
|
50
|
+
if (!params.has("client") && !params.has("device")) return { kind: "legacy" };
|
|
51
|
+
if (params.getAll("client").length !== 1 || params.getAll("device").length !== 1
|
|
52
|
+
|| params.getAll("surface").length > 1 || params.getAll("apiKeyId").length > 1
|
|
53
|
+
|| (params.has("surface") && params.get("surface") !== "all")
|
|
54
|
+
|| params.has("jev") || params.has("failures")) return { kind: "invalid" };
|
|
55
|
+
const client = params.get("client");
|
|
56
|
+
const device = params.get("device");
|
|
57
|
+
if (!client || !(USAGE_SOURCE_CLIENTS as readonly string[]).includes(client)) return { kind: "invalid" };
|
|
58
|
+
if (device === "key") {
|
|
59
|
+
const id = params.get("apiKeyId");
|
|
60
|
+
if (!id || id !== id.trim()) return { kind: "invalid" };
|
|
61
|
+
return { kind: "filtered", filter: { client: client as UsageSourceClient, device: { kind: "key", id } } };
|
|
62
|
+
}
|
|
63
|
+
if ((device !== "all" && device !== "no-key" && device !== "unconfigured") || params.has("apiKeyId")) return { kind: "invalid" };
|
|
64
|
+
return { kind: "filtered", filter: { client: client as UsageSourceClient, device: { kind: device } } };
|
|
65
|
+
}
|
package/src/usage/summary.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { baseProviderLabel } from "../providers/label";
|
|
2
2
|
import { canonicalAntigravityUsageModel } from "../providers/antigravity-models";
|
|
3
3
|
import { usageDisplayTotalTokens } from "./totals";
|
|
4
|
+
import { isLegacyCodexUsage, matchesUsageSource, snapshotConfiguredKeyIds, type UsageSourceFilter } from "./source-filter";
|
|
4
5
|
import type { UsageTimeWindow } from "./time-range";
|
|
5
6
|
import { isUnresolvedRequestedModel, usageModelPriceOptions } from "./model-identity";
|
|
6
7
|
import {
|
|
@@ -210,6 +211,17 @@ export interface UsageSummary {
|
|
|
210
211
|
models: UsageModel[];
|
|
211
212
|
providers: UsageProvider[];
|
|
212
213
|
accounts: UsageAccount[];
|
|
214
|
+
sourceFilter?: UsageSourceFilter;
|
|
215
|
+
legacyUnclassifiedRequests?: number;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export interface UsageSummaryFilterInput {
|
|
219
|
+
provider?: string | null;
|
|
220
|
+
model?: string | null;
|
|
221
|
+
apiKeyId?: string | null;
|
|
222
|
+
sourceFilter?: UsageSourceFilter;
|
|
223
|
+
/** Internal snapshot, never a client-supplied list or part of the response echo. */
|
|
224
|
+
configuredApiKeyIds?: readonly string[];
|
|
213
225
|
}
|
|
214
226
|
|
|
215
227
|
/**
|
|
@@ -765,6 +777,7 @@ interface UsagePartition {
|
|
|
765
777
|
dayStart: number;
|
|
766
778
|
surface: UsagePartitionSurface;
|
|
767
779
|
oldestTimestamp: number | null;
|
|
780
|
+
legacyUnclassifiedRequests: number;
|
|
768
781
|
totals: UsageSummaryTotals;
|
|
769
782
|
models: Map<string, UsageModelAccumulator>;
|
|
770
783
|
providers?: Map<string, UsageModelAccumulator>;
|
|
@@ -782,6 +795,9 @@ interface NormalizedUsageFilter {
|
|
|
782
795
|
provider: string | null;
|
|
783
796
|
model: string | null;
|
|
784
797
|
apiKeyId: string | null;
|
|
798
|
+
sourceFilter?: UsageSourceFilter;
|
|
799
|
+
configuredApiKeyIds?: readonly string[];
|
|
800
|
+
configuredApiKeyIdSet?: ReadonlySet<string>;
|
|
785
801
|
}
|
|
786
802
|
|
|
787
803
|
export interface UsageSummaryAccumulator {
|
|
@@ -1058,6 +1074,7 @@ function projectedEntryForFilter(
|
|
|
1058
1074
|
filter: NormalizedUsageFilter,
|
|
1059
1075
|
): { entry: PersistedUsageEntry; comboOverlap: boolean } | null {
|
|
1060
1076
|
if (filter.apiKeyId !== null && entry.apiKeyId !== filter.apiKeyId) return null;
|
|
1077
|
+
if (filter.sourceFilter && !matchesUsageSource(entry, filter.sourceFilter, filter.configuredApiKeyIdSet)) return null;
|
|
1061
1078
|
if (!entry.attempts?.length) {
|
|
1062
1079
|
const identity = usageModelIdentity(entry.provider, entry.model, entry.resolvedModel);
|
|
1063
1080
|
return filterMatchesAttribution(filter, entry.provider, identity.model)
|
|
@@ -1285,19 +1302,31 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1285
1302
|
private estimatedRetainedBytes = ESTIMATED_ACCUMULATOR_BASE_BYTES;
|
|
1286
1303
|
|
|
1287
1304
|
constructor(options?: {
|
|
1288
|
-
filter?:
|
|
1305
|
+
filter?: UsageSummaryFilterInput;
|
|
1289
1306
|
mode?: UsageAccumulatorMode;
|
|
1290
1307
|
window?: UsageTimeWindow;
|
|
1291
1308
|
}) {
|
|
1292
1309
|
const provider = normalizeFilterValue(options?.filter?.provider);
|
|
1293
1310
|
const model = normalizeFilterValue(options?.filter?.model);
|
|
1294
1311
|
const apiKeyId = normalizeExactFilterValue(options?.filter?.apiKeyId);
|
|
1295
|
-
|
|
1312
|
+
const inputSource = options?.filter?.sourceFilter;
|
|
1313
|
+
const sourceFilter = inputSource ? { client: inputSource.client, device: { ...inputSource.device } } : undefined;
|
|
1314
|
+
const configuredApiKeyIds = options?.filter?.configuredApiKeyIds
|
|
1315
|
+
? snapshotConfiguredKeyIds(options.filter.configuredApiKeyIds) : undefined;
|
|
1316
|
+
if (sourceFilter?.device.kind === "unconfigured" && !configuredApiKeyIds) {
|
|
1317
|
+
throw new Error("configured key snapshot required");
|
|
1318
|
+
}
|
|
1319
|
+
this.filter = provider === null && model === null && apiKeyId === null && !sourceFilter
|
|
1296
1320
|
? null
|
|
1297
|
-
: { provider, model, apiKeyId }
|
|
1321
|
+
: { provider, model, apiKeyId, ...(sourceFilter ? { sourceFilter } : {}),
|
|
1322
|
+
...(configuredApiKeyIds ? { configuredApiKeyIds, configuredApiKeyIdSet: new Set(configuredApiKeyIds) } : {}) };
|
|
1298
1323
|
this.mode = options?.mode ?? "exact";
|
|
1299
1324
|
this.window = options?.window ? Object.freeze({ ...options.window }) : undefined;
|
|
1300
1325
|
this.requestIds = this.mode === "exact" ? new Map() : null;
|
|
1326
|
+
if (configuredApiKeyIds) {
|
|
1327
|
+
// Account conservatively for the array, set, and serialized retained cache identity.
|
|
1328
|
+
this.estimatedRetainedBytes += configuredApiKeyIds.reduce((bytes, id) => bytes + 128 + id.length * 8, 0);
|
|
1329
|
+
}
|
|
1301
1330
|
}
|
|
1302
1331
|
|
|
1303
1332
|
get snapshotWindow(): { start: number | null; end: number | null } {
|
|
@@ -1371,6 +1400,7 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1371
1400
|
dayStart,
|
|
1372
1401
|
surface,
|
|
1373
1402
|
oldestTimestamp: null,
|
|
1403
|
+
legacyUnclassifiedRequests: 0,
|
|
1374
1404
|
totals: blankTotals(),
|
|
1375
1405
|
models: new Map(),
|
|
1376
1406
|
...(this.mode === "row-unique" ? { providers: new Map() } : {}),
|
|
@@ -1546,7 +1576,7 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1546
1576
|
return label;
|
|
1547
1577
|
}
|
|
1548
1578
|
|
|
1549
|
-
|
|
1579
|
+
private noteSnapshot(sourceEntry: PersistedUsageEntry): void {
|
|
1550
1580
|
if (Number.isFinite(sourceEntry.timestamp)) {
|
|
1551
1581
|
this.snapshotStart = this.snapshotStart === null
|
|
1552
1582
|
? sourceEntry.timestamp
|
|
@@ -1555,13 +1585,19 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1555
1585
|
? sourceEntry.timestamp
|
|
1556
1586
|
: Math.max(this.snapshotEnd, sourceEntry.timestamp);
|
|
1557
1587
|
}
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1590
|
+
add(sourceEntry: PersistedUsageEntry): void {
|
|
1591
|
+
if (!this.filter?.sourceFilter) this.noteSnapshot(sourceEntry);
|
|
1558
1592
|
if (this.window && (!Number.isFinite(sourceEntry.timestamp)
|
|
1559
1593
|
|| sourceEntry.timestamp < this.window.since || sourceEntry.timestamp > this.window.until)) return;
|
|
1560
1594
|
const projected = this.filter ? projectedEntryForFilter(sourceEntry, this.filter) : { entry: sourceEntry, comboOverlap: false };
|
|
1561
1595
|
if (!projected) return;
|
|
1596
|
+
if (this.filter?.sourceFilter) this.noteSnapshot(sourceEntry);
|
|
1562
1597
|
this.comboOverlap ||= projected.comboOverlap;
|
|
1563
1598
|
const entry = projected.entry;
|
|
1564
1599
|
const partition = this.partitionFor(entry);
|
|
1600
|
+
if (this.filter?.sourceFilter && isLegacyCodexUsage(entry)) partition.legacyUnclassifiedRequests += 1;
|
|
1565
1601
|
const costInfo = computeEntryCost(entry);
|
|
1566
1602
|
bumpStatus(partition.totals, entry.usageStatus);
|
|
1567
1603
|
partition.totals.attemptCount += entry.attempts?.length ?? 1;
|
|
@@ -1634,10 +1670,12 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1634
1670
|
const dayAccumulators = new Map<string, UsageDayAccumulator>();
|
|
1635
1671
|
const modelOverlaps: UsageModelOverlap[] = [];
|
|
1636
1672
|
let oldestTimestamp: number | null = null;
|
|
1673
|
+
let legacyUnclassifiedRequests = 0;
|
|
1637
1674
|
|
|
1638
1675
|
for (const partition of this.partitions.values()) {
|
|
1639
1676
|
if (!usageSurfaceMatches(partition.surface, surface)) continue;
|
|
1640
1677
|
if (!this.window && since !== null && partition.dayStart < since) continue;
|
|
1678
|
+
legacyUnclassifiedRequests += partition.legacyUnclassifiedRequests;
|
|
1641
1679
|
mergeTotals(totals, partition.totals);
|
|
1642
1680
|
mergeModelMaps(models, partition.models);
|
|
1643
1681
|
if (partition.providers) mergeModelMaps(providers, partition.providers);
|
|
@@ -1713,6 +1751,8 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1713
1751
|
models: buildUsageModels(models, totals.totalTokens, modelOverlaps),
|
|
1714
1752
|
providers: buildUsageProviders(this.mode === "row-unique" ? providers : models, totals.totalTokens),
|
|
1715
1753
|
accounts: buildUsageAccounts(accounts),
|
|
1754
|
+
...(this.filter?.sourceFilter ? { sourceFilter: { client: this.filter.sourceFilter.client,
|
|
1755
|
+
device: { ...this.filter.sourceFilter.device } }, legacyUnclassifiedRequests } : {}),
|
|
1716
1756
|
};
|
|
1717
1757
|
if (!this.filter) return summary;
|
|
1718
1758
|
const matches = (provider: string, model: string): boolean =>
|
|
@@ -1742,7 +1782,7 @@ class StreamingUsageSummaryAccumulator implements UsageSummaryAccumulator {
|
|
|
1742
1782
|
}
|
|
1743
1783
|
|
|
1744
1784
|
export function createUsageSummaryAccumulator(options?: {
|
|
1745
|
-
filter?:
|
|
1785
|
+
filter?: UsageSummaryFilterInput;
|
|
1746
1786
|
mode?: UsageAccumulatorMode;
|
|
1747
1787
|
window?: UsageTimeWindow;
|
|
1748
1788
|
}): UsageSummaryAccumulator {
|
|
@@ -1790,15 +1830,16 @@ function normalizeExactFilterValue(input: string | null | undefined): string | n
|
|
|
1790
1830
|
*/
|
|
1791
1831
|
export function projectUsageSummary<T extends UsageSummary>(
|
|
1792
1832
|
summary: T,
|
|
1793
|
-
filter:
|
|
1833
|
+
filter: UsageSummaryFilterInput,
|
|
1794
1834
|
entries?: PersistedUsageEntry[],
|
|
1795
1835
|
): T & { filter?: UsageFilterEcho } {
|
|
1796
1836
|
const provider = normalizeFilterValue(filter.provider);
|
|
1797
1837
|
const model = normalizeFilterValue(filter.model);
|
|
1798
1838
|
const apiKeyId = normalizeExactFilterValue(filter.apiKeyId);
|
|
1799
|
-
if (provider === null && model === null && apiKeyId === null) return summary;
|
|
1839
|
+
if (provider === null && model === null && apiKeyId === null && !filter.sourceFilter) return summary;
|
|
1800
1840
|
const accumulator = createUsageSummaryAccumulator({
|
|
1801
|
-
filter: { provider, model, apiKeyId },
|
|
1841
|
+
filter: { provider, model, apiKeyId, ...(filter.sourceFilter ? { sourceFilter: filter.sourceFilter } : {}),
|
|
1842
|
+
...(filter.configuredApiKeyIds ? { configuredApiKeyIds: filter.configuredApiKeyIds } : {}) },
|
|
1802
1843
|
...(summary.customWindow && summary.since !== null && summary.until !== undefined
|
|
1803
1844
|
? { window: { since: summary.since, until: summary.until } } : {}),
|
|
1804
1845
|
});
|
|
@@ -1811,6 +1852,7 @@ export function projectUsageSummary<T extends UsageSummary>(
|
|
|
1811
1852
|
models: projected.models,
|
|
1812
1853
|
providers: projected.providers,
|
|
1813
1854
|
accounts: projected.accounts,
|
|
1855
|
+
...(projected.sourceFilter ? { sourceFilter: projected.sourceFilter, legacyUnclassifiedRequests: projected.legacyUnclassifiedRequests } : {}),
|
|
1814
1856
|
filter: projected.filter,
|
|
1815
1857
|
};
|
|
1816
1858
|
}
|