@bitkyc08/opencodex 2.96.0 → 2.98.0-preview.20261107
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ocx.mjs +215 -20
- package/gui/dist/assets/App-6TFtZsUF.css +1 -0
- package/gui/dist/assets/App-B8_sOxoz.js +59 -0
- package/gui/dist/assets/Tray-DpWEp6ee.js +1 -0
- package/gui/dist/assets/WantedSansVariable.split.0-Dwvb1WRx.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.1-1wKD2RxI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.10-CAKA6LIP.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.11-k5H85R4b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.12-BHboLsUv.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.13-9GV377ix.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.14-DovDXnrj.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.15-DTdykCig.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.16-CKz2ccgK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.17-Z2RD_KRZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.18-BcKtfonJ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.19-DEQPOSZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.2-DryboyuA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.20-Bia5JMls.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.21-Cr4jFw-E.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.22-DjjB69TZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.23-CvUzJskt.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.24-i_eMg5ox.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.25-2aKHwPX-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.26-B6wXoCEL.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.27-D4h1WfGM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.28-kvRPCStd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.29-DHAiwleD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.3-7H--eyZi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.30-C66cfAY2.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.31-FDmtiNim.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.32-DouHt2Dd.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.33-B8HVvkJX.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.34-BtkRu1FN.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.35-DBylQbtk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.36-Sg089Kgh.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.37-CYtvbriS.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.38-DKkSLf8Z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.39-CecotKZD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.4-Bv8O3ZMb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.40-DdCvkmOU.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.41-ESn674Hc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.42-DL9V7NNV.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.43-yipO0cyk.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.44-6rTmLZhm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.45-BJAj8lrm.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.46-BDTzMn2c.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.47-Bxd4wGgi.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.48-DxnFBLnH.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.49-DnVD0aOD.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.5-B1wI2pp5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.50-D9JlkZd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.51-D9Vw6Bu3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.52-ClEJk4kn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.53-BSXU0vh-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.54-EcuxkR9v.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.55-CYiFhQX8.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.56--Gk9g8BK.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.57-DnkOPZcy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.58-9MB8504z.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.59-ByxIsN72.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.6-Bmk0dRVw.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.60-Bxwx_aWQ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.61-DA2z5sm7.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.62-C5iJPJZn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.63-DAqrmaEc.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.64-BgXFsljb.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.65-DKiWujvu.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.66-8po4vUZ4.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.67-Cy5qyI9O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.68-BKny7Fy3.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.69-B4VU4u_b.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.7-BuqwNpgA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.70-BCd4n346.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.71-CkQppaWn.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.72-Db7vaoFs.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.73-DI80TYWl.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.74-tMCtDAHB.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.75-Ciw0D5WG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.76-DoLjFgp-.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.77-CpT2uvMy.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.78-CkcJ4iZ1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.79-DsOUJjEM.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.8-DsjypPd6.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.80-C0VwHTte.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.81-DTelu57i.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.82-BiMndGN1.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.83-CVcC6eDG.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.84-DlhZVt_O.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.85-S8I2D3pA.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.86-DozXXpH5.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.87-Dsn0Vuuo.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.88-iNwxxDCr.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.89-B63u_9CZ.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.9-Bi3IzpMI.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.90-ByeH1Pqf.woff2 +0 -0
- package/gui/dist/assets/WantedSansVariable.split.91-UQLlagpm.woff2 +0 -0
- package/gui/dist/assets/brand-mark-VPhzz-WE.js +1 -0
- package/gui/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/gui/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/gui/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/gui/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/gui/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/gui/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/gui/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/gui/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/gui/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/gui/dist/assets/index-5REODpG3.css +2 -0
- package/gui/dist/assets/index-BWKBeK77.js +94 -0
- package/gui/dist/assets/segment-thumb-features-BQYzrze9.js +1 -0
- package/gui/dist/classic/assets/App-Bz65x1J6.js +58 -0
- package/gui/dist/{assets/Tray-BOPQyDbH.js → classic/assets/Tray-kk7mdO6I.js} +1 -1
- package/gui/dist/classic/assets/index-Dp2j8bSc.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CvamtHjB.js +1 -0
- package/gui/dist/classic/index.html +47 -0
- package/gui/dist/favicon.png +0 -0
- package/gui/dist/favicon.svg +14 -0
- package/gui/dist/index.html +15 -2
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +17 -8
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/google.ts +7 -7
- package/src/adapters/kiro/adapter.ts +18 -3
- package/src/adapters/kiro/conversation.ts +8 -8
- package/src/adapters/kiro/payload.ts +45 -12
- package/src/adapters/kiro/stream.ts +230 -14
- package/src/adapters/kiro/structured-output-json.ts +191 -0
- package/src/adapters/kiro/structured-output-schema.ts +542 -0
- package/src/adapters/kiro/structured-output.ts +367 -0
- package/src/adapters/kiro-constants.ts +24 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/kiro-tools.ts +14 -9
- package/src/adapters/kiro-wire.ts +9 -5
- package/src/adapters/ollama-native.ts +11 -1
- package/src/adapters/openai-chat/messages.ts +58 -5
- package/src/adapters/openai-chat/mistral-image-limit.ts +50 -0
- package/src/adapters/openai-chat/passthrough.ts +5 -3
- package/src/adapters/openai-chat/tool-schema.ts +83 -13
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/opengateway-input.ts +18 -6
- package/src/adapters/openai-responses/passthrough.ts +5 -4
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/openai-responses/tool-output-recovery.ts +79 -0
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/qoder/live-models.ts +115 -1
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/failure-verdict.ts +21 -0
- package/src/claude/inbound-content-options.ts +15 -2
- package/src/claude/inbound-model-options.ts +2 -1
- package/src/claude/inbound-records.ts +2 -0
- package/src/claude/inbound.ts +17 -11
- package/src/claude/outbound.ts +98 -22
- package/src/cli/capabilities-access-remote.ts +13 -0
- package/src/cli/capabilities-base.ts +26 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capabilities-provider-models.ts +3 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +12 -4
- package/src/cli/config-command.ts +11 -2
- package/src/cli/connect.ts +17 -2
- package/src/cli/dispatch.ts +14 -177
- package/src/cli/doctor.ts +95 -7
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +17 -8
- package/src/cli/link-apply-restart.ts +9 -2
- package/src/cli/link.ts +1 -1
- package/src/cli/models.ts +124 -38
- package/src/cli/registry.ts +12 -4
- package/src/cli/restart-failure.ts +17 -0
- package/src/cli/root.ts +8 -0
- package/src/cli/stop-approval.ts +2 -2
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +161 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/cli/system-restart-client.ts +5 -0
- package/src/cli/uninstall-client-state.ts +12 -1
- package/src/cli/update-restart-child.ts +13 -3
- package/src/cli/update-restart-home.ts +6 -3
- package/src/cli/update-restart.ts +36 -19
- package/src/client/connect.ts +35 -15
- package/src/client/hub-client.ts +5 -0
- package/src/client/link-home.ts +3 -2
- package/src/client/link-management-relay.ts +39 -2
- package/src/client/link-readiness.ts +3 -1
- package/src/client/machine-api.ts +2 -1
- package/src/client/machine-listener.ts +10 -0
- package/src/client/orphan-token-recovery.ts +322 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/auth-context.ts +49 -103
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +18 -12
- package/src/codex/forward-transport-headers.ts +35 -6
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/lineage.ts +13 -7
- package/src/codex/native-profile-api.ts +27 -1
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/shim-diagnostics.ts +7 -0
- package/src/codex/shim-legacy-record.ts +290 -0
- package/src/codex/shim-windows-refresh.ts +9 -2
- package/src/codex/shim-wrapper-write.ts +7 -0
- package/src/codex/shim.ts +80 -21
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/diagnostics.ts +9 -9
- package/src/config/load-degrade.ts +27 -27
- package/src/config/process-state.ts +5 -0
- package/src/config/provider-validation.ts +9 -2
- package/src/config/removed-opencode-free-backup.ts +6 -3
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/config/tracked-runtime-inspection.ts +3 -3
- package/src/generated/compatibility-version.json +595 -255
- package/src/images/loop.ts +4 -3
- package/src/lib/client-error-body.ts +215 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership-removal.ts +422 -0
- package/src/lib/config-ownership.ts +650 -81
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/crash-guard.ts +4 -2
- package/src/lib/desktop-cli-handoff.d.mts +4 -5
- package/src/lib/desktop-cli-handoff.mjs +18 -17
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/errors.ts +1 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/local-management-capability.ts +3 -1
- package/src/lib/messages-error-body.ts +162 -0
- package/src/lib/messages-sse-error-presentation.ts +93 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/passive-read.ts +9 -4
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/socks5-fetch.ts +21 -9
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +95 -12
- package/src/lib/windows-owner-acl.ts +22 -9
- package/src/lib/winsw.ts +5 -5
- package/src/lib/workflow-budget.ts +3 -1
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +42 -73
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +21 -11
- package/src/protocols/codecs/messages-ir.ts +15 -9
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +30 -7
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/encoders/messages.ts +72 -28
- package/src/protocols/trace.ts +18 -0
- package/src/providers/antigravity-models.ts +45 -12
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/quota/anthropic-usage-windows.ts +13 -3
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/reasoning-metadata.ts +2 -1
- package/src/providers/registry/entries-extended.ts +9 -0
- package/src/providers/request-pacing.ts +3 -2
- package/src/reasoning-effort.ts +7 -2
- package/src/remote/hub-usage.ts +3 -0
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +57 -0
- package/src/server/anthropic-rate-limit-headers.ts +75 -3
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +174 -84
- package/src/server/context-history.ts +5 -1
- package/src/server/gui-static.ts +4 -1
- package/src/server/hub-usage.ts +7 -2
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/link-management.ts +8 -0
- package/src/server/index/ollama-routes.ts +91 -0
- package/src/server/index/serve-options.ts +44 -24
- package/src/server/index/startup-warnings.ts +5 -12
- package/src/server/index/websocket-handler.ts +5 -2
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +9 -3
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/logs-usage-routes.ts +89 -4
- package/src/server/management/provider-routes.ts +2 -22
- package/src/server/management/qoder-provider-probe.ts +105 -0
- package/src/server/management/route-registry.ts +4 -1
- package/src/server/management/usage-aggregate-cache.ts +15 -5
- package/src/server/management/usage-source-facets.ts +38 -0
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +12 -4
- package/src/server/messages-native.ts +123 -47
- package/src/server/messages-response-headers.ts +25 -11
- package/src/server/messages-shared.ts +99 -65
- package/src/server/messages-sse-error-filter.ts +199 -0
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +91 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +17 -6
- package/src/server/responses/adapter-delivery.ts +17 -10
- package/src/server/responses/adapter-dispatch.ts +32 -31
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +24 -19
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/codex-ws-wire.ts +19 -3
- package/src/server/responses/compact.ts +57 -24
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +7 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +43 -27
- package/src/server/responses/core-errors.ts +24 -21
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +9 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/empty-completion-guard.ts +4 -1
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +20 -18
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +69 -48
- package/src/server/responses/request-transport.ts +36 -31
- package/src/server/responses/response-effects.ts +3 -2
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/terminal-guard.ts +30 -0
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/restart-replacement.ts +3 -1
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/sse-payload-rewrite.ts +23 -11
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +4 -0
- package/src/service/definition.ts +36 -4
- package/src/service/launchd.ts +89 -32
- package/src/service/logging.ts +34 -7
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/service/plist-xml.ts +59 -0
- package/src/service/state.ts +8 -0
- package/src/service/systemd-env.ts +2 -0
- package/src/service/systemd.ts +31 -7
- package/src/service/windows-taskxml.ts +16 -7
- package/src/service-manager-probe.ts +4 -10
- package/src/types/config.ts +2 -0
- package/src/types/provider.ts +2 -0
- package/src/types/request.ts +13 -1
- package/src/update/config-preflight.ts +48 -0
- package/src/update/index.ts +148 -26
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/client.ts +43 -0
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +64 -27
- package/src/usage/source-facets.ts +51 -0
- package/src/usage/source-filter.ts +65 -0
- package/src/usage/summary.ts +50 -8
- package/src/web-search/anthropic-executor.ts +105 -24
- package/src/web-search/executor.ts +5 -3
- package/src/web-search/loop.ts +33 -6
- package/src/web-search/progress-stream.ts +64 -5
- package/gui/dist/assets/App-bwugJRKn.js +0 -58
- package/gui/dist/assets/index-ebuVUtB7.js +0 -94
- package/gui/dist/assets/quota-summary-6HsrHQAy.js +0 -1
- /package/gui/dist/{assets → classic/assets}/App-B4j-Txmb.css +0 -0
- /package/gui/dist/{assets → classic/assets}/index-CHWwDo9L.css +0 -0
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { MessagesFailureVerdictSink } from "../../claude/failure-verdict";
|
|
2
|
+
import type { FailureVerdictSink } from "../../chat/failure-verdict";
|
|
1
3
|
/**
|
|
2
4
|
* Adapter delivery straight into a Chat or Messages client's wire (PF-09).
|
|
3
5
|
*
|
|
@@ -215,6 +217,8 @@ export async function deliverClientEncodedResponse(input: ClientEncodedDelivery)
|
|
|
215
217
|
recorder?.noteRelayedEvent(observation);
|
|
216
218
|
},
|
|
217
219
|
};
|
|
220
|
+
const failureVerdictSink: FailureVerdictSink = {};
|
|
221
|
+
const messagesFailureVerdictSink: MessagesFailureVerdictSink = {};
|
|
218
222
|
const encodeOptions = {
|
|
219
223
|
model: encoder.model,
|
|
220
224
|
translatorBudget,
|
|
@@ -224,9 +228,11 @@ export async function deliverClientEncodedResponse(input: ClientEncodedDelivery)
|
|
|
224
228
|
hooks,
|
|
225
229
|
};
|
|
226
230
|
const encoded = encoder.protocol === "chat"
|
|
227
|
-
? encodeChatCompletionSse(events, encodeOptions)
|
|
231
|
+
? encodeChatCompletionSse(events, { ...encodeOptions, failureVerdictSink, proxyErrorContext: logCtx, get localUpstream() { return input.localUpstream; } })
|
|
228
232
|
: encodeAnthropicMessageSse(events, {
|
|
229
233
|
...encodeOptions,
|
|
234
|
+
failureVerdictSink: encoder.stream ? undefined : messagesFailureVerdictSink,
|
|
235
|
+
proxyErrorContext: logCtx,
|
|
230
236
|
get localUpstream() { return input.localUpstream; },
|
|
231
237
|
...(encoder.inputTokenFloor !== undefined ? { inputTokenFloor: encoder.inputTokenFloor } : {}),
|
|
232
238
|
});
|
|
@@ -238,8 +244,8 @@ export async function deliverClientEncodedResponse(input: ClientEncodedDelivery)
|
|
|
238
244
|
} else {
|
|
239
245
|
// The routed turn always streams internally; a non-streaming client gets the fold.
|
|
240
246
|
response = encoder.protocol === "chat"
|
|
241
|
-
? await collectChatCompletionResponse(tracked, encoder.model, translatorBudget)
|
|
242
|
-
: await collectAnthropicMessageResponse(tracked, encoder.model, translatorBudget);
|
|
247
|
+
? await collectChatCompletionResponse(tracked, encoder.model, translatorBudget, failureVerdictSink)
|
|
248
|
+
: await collectAnthropicMessageResponse(tracked, encoder.model, translatorBudget, messagesFailureVerdictSink);
|
|
243
249
|
}
|
|
244
250
|
return attachClientWireLog(markClientWire(response, encoder.protocol), log);
|
|
245
251
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Buffer } from "node:buffer";
|
|
2
|
+
|
|
3
|
+
type Frame =
|
|
4
|
+
| { items: readonly unknown[]; index: number }
|
|
5
|
+
| { record: Record<string, unknown>; keys: readonly string[]; index: number };
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* UTF-8 byte length of JSON.stringify(value) for a JSON.parse result, computed without
|
|
9
|
+
* recursion: a valid body nested deeper than the call stack must be measured, not crash.
|
|
10
|
+
* Each open container keeps one cursor frame, so arrays add no per-element queue; an object
|
|
11
|
+
* frame retains its key list, which stays bounded by the input size.
|
|
12
|
+
*/
|
|
13
|
+
export function serializedJsonByteLength(value: unknown): number {
|
|
14
|
+
let bytes = 0;
|
|
15
|
+
const stack: Frame[] = [];
|
|
16
|
+
const visit = (item: unknown): void => {
|
|
17
|
+
if (item === null || typeof item !== "object") {
|
|
18
|
+
bytes += Buffer.byteLength(JSON.stringify(item) ?? "null", "utf8");
|
|
19
|
+
} else if (Array.isArray(item)) {
|
|
20
|
+
bytes += 2 + Math.max(0, item.length - 1);
|
|
21
|
+
stack.push({ items: item, index: 0 });
|
|
22
|
+
} else {
|
|
23
|
+
const record = item as Record<string, unknown>;
|
|
24
|
+
const keys = Object.keys(record);
|
|
25
|
+
bytes += 2 + Math.max(0, keys.length - 1);
|
|
26
|
+
stack.push({ record, keys, index: 0 });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
visit(value);
|
|
30
|
+
while (stack.length > 0) {
|
|
31
|
+
const frame = stack[stack.length - 1]!;
|
|
32
|
+
if ("items" in frame) {
|
|
33
|
+
if (frame.index < frame.items.length) visit(frame.items[frame.index++]);
|
|
34
|
+
else stack.pop();
|
|
35
|
+
} else if (frame.index < frame.keys.length) {
|
|
36
|
+
const key = frame.keys[frame.index++]!;
|
|
37
|
+
bytes += Buffer.byteLength(JSON.stringify(key), "utf8") + 1;
|
|
38
|
+
visit(frame.record[key]);
|
|
39
|
+
} else {
|
|
40
|
+
stack.pop();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return bytes;
|
|
44
|
+
}
|
|
@@ -562,26 +562,28 @@ async function handleAgentSettingsRoutesImpl(ctx: ManagementContext): Promise<Re
|
|
|
562
562
|
const body = parsedBody as { enabled?: unknown };
|
|
563
563
|
if (typeof body.enabled !== "boolean") return jsonResponse({ error: "body.enabled must be a boolean" }, 400);
|
|
564
564
|
const { isDefaultModeRequestUserInputEnabled, DEFAULT_MODE_REQUEST_USER_INPUT_FEATURE_KEY, activeCodexConfigPath } = await import("../../codex/features");
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
565
|
+
const selectionWrite = await beginCodexCliSelectionParentWriteAsync({ signal: req.signal });
|
|
566
|
+
if (!selectionWrite.entered) return jsonResponse({ error: "codex_cli_selection_busy", retryable: true }, 503);
|
|
567
|
+
try {
|
|
568
|
+
const before = isDefaultModeRequestUserInputEnabled();
|
|
569
|
+
let toggle = deps.toggleDefaultModeRequestUserInput;
|
|
570
|
+
if (!toggle) {
|
|
571
|
+
try {
|
|
572
|
+
const { codexFeaturesInvocation, runCodexFeaturesCommand } = await import("../../cli/v2");
|
|
573
|
+
const action = body.enabled ? "enable" : "disable";
|
|
574
|
+
const invocation = selectionWrite.commit(() => codexFeaturesInvocation(action, DEFAULT_MODE_REQUEST_USER_INPUT_FEATURE_KEY, process.platform, { requireAvailable: true }));
|
|
575
|
+
toggle = (_enabled, env, validate) => runCodexFeaturesCommand(action, DEFAULT_MODE_REQUEST_USER_INPUT_FEATURE_KEY, env, validate, invocation);
|
|
576
|
+
} catch (error) {
|
|
577
|
+
if (error instanceof CodexCliSelectionMutationBusyError) throw error;
|
|
578
|
+
return jsonResponse({ error: `default_mode_request_user_input toggle failed: ${error instanceof Error ? error.message : String(error)}` }, 502);
|
|
579
|
+
}
|
|
575
580
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
// Preserve native home creation only after executable resolution succeeds.
|
|
583
|
-
prepareCodexHome(dirname(configPath));
|
|
584
|
-
{
|
|
581
|
+
// Keep selection ownership across the config-lock await and the whole
|
|
582
|
+
// synchronous child execution: an updater must not replace this command.
|
|
583
|
+
const { acquireConfigWriteLock, releaseConfigWriteLock, configWriteLockFailureMessage, runConfigWriteChild, ConfigWriteDestinationChanged } = await import("../../codex/config-write-lock");
|
|
584
|
+
const configPath = activeCodexConfigPath();
|
|
585
|
+
// Preserve native home creation only after executable resolution succeeds.
|
|
586
|
+
selectionWrite.commit(() => prepareCodexHome(dirname(configPath)));
|
|
585
587
|
const configLock = await acquireConfigWriteLock(configPath);
|
|
586
588
|
if (!configLock.ok) {
|
|
587
589
|
return jsonResponse({ error: configWriteLockFailureMessage(configLock), retryable: configLock.error === "locked" }, 502);
|
|
@@ -589,8 +591,9 @@ async function handleAgentSettingsRoutesImpl(ctx: ManagementContext): Promise<Re
|
|
|
589
591
|
let toggleError: string | null = null;
|
|
590
592
|
let destinationChanged = false;
|
|
591
593
|
try {
|
|
592
|
-
runConfigWriteChild(configPath, configLock.handle, (env, validate) => toggle!(body.enabled as boolean, env, validate));
|
|
594
|
+
selectionWrite.commit(() => runConfigWriteChild(configPath, configLock.handle, (env, validate) => toggle!(body.enabled as boolean, env, validate)));
|
|
593
595
|
} catch (error) {
|
|
596
|
+
if (error instanceof CodexCliSelectionMutationBusyError) throw error;
|
|
594
597
|
destinationChanged = error instanceof ConfigWriteDestinationChanged;
|
|
595
598
|
const err = error as { stderr?: unknown; message?: string };
|
|
596
599
|
const raw = err.stderr;
|
|
@@ -613,7 +616,7 @@ async function handleAgentSettingsRoutesImpl(ctx: ManagementContext): Promise<Re
|
|
|
613
616
|
warnings.push("Applies to new sessions; restart the Codex app or wait out its picker cache to see the change.");
|
|
614
617
|
}
|
|
615
618
|
return jsonResponse({ ok: true, enabled, changed: enabled !== before, warnings });
|
|
616
|
-
}
|
|
619
|
+
} finally { selectionWrite.exit(); }
|
|
617
620
|
}
|
|
618
621
|
|
|
619
622
|
// Subagent prompt injection model: single native or routed model whose info is
|
|
@@ -25,7 +25,8 @@ export async function handleCodexCliUpdateRoutes(ctx: ManagementContext): Promis
|
|
|
25
25
|
}
|
|
26
26
|
if (ctx.url.pathname !== "/api/codex/cli-update/apply") return null;
|
|
27
27
|
if (ctx.req.method !== "POST") return jsonResponse({ error: "method_not_allowed" }, 405, ctx.req, ctx.config);
|
|
28
|
-
if (!hasHumanDashboardSession(ctx) || !ctx.trustedLoopbackIngress
|
|
28
|
+
if (!hasHumanDashboardSession(ctx) || !ctx.trustedLoopbackIngress
|
|
29
|
+
|| ctx.sessionControl?.isPaired(ctx.req, ctx.config) !== true) {
|
|
29
30
|
return jsonResponse({ error: "local_dashboard_confirmation_required" }, 403, ctx.req, ctx.config);
|
|
30
31
|
}
|
|
31
32
|
let body: unknown;
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
} from "../../oauth";
|
|
24
24
|
import { removeCredential } from "../../oauth/store";
|
|
25
25
|
import { getFailureProjection } from "../../usage/failure-projection-cache";
|
|
26
|
+
import { MAX_USAGE_CONFIGURED_KEYS, parseUsageSource, snapshotConfiguredKeyIds } from "../../usage/source-filter";
|
|
26
27
|
import { providerDestinationResolvedError } from "../../lib/destination-policy";
|
|
27
28
|
import { enrichProviderFromCatalog, listKeyLoginProviders } from "../../oauth/key-providers";
|
|
28
29
|
import { deriveProviderPresets } from "../../providers/derive";
|
|
@@ -110,6 +111,17 @@ function refreshedUsageSummary<T extends UsageSummary & { historyTruncated: bool
|
|
|
110
111
|
return { ...summary, since, generatedAt: now };
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
function configuredUsageKeyIds(config: OcxConfig): string[] {
|
|
115
|
+
const keys = config.apiKeys ?? [];
|
|
116
|
+
if (keys.length > MAX_USAGE_CONFIGURED_KEYS) throw new Error("configured key snapshot exceeds limit");
|
|
117
|
+
return snapshotConfiguredKeyIds(keys.map(key => key.id));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Only used after a previously authorized session expires during an async read. */
|
|
121
|
+
function expiredUsageSession(): Response {
|
|
122
|
+
return Response.json({ error: "session_expired" }, { status: 401, headers: { "cache-control": "no-store" } });
|
|
123
|
+
}
|
|
124
|
+
|
|
113
125
|
export async function handleLogsUsageRoutes(ctx: ManagementContext): Promise<Response | null> {
|
|
114
126
|
const { req, url, config, deps, syncClaudeAgentDefsBestEffort } = ctx;
|
|
115
127
|
|
|
@@ -185,7 +197,67 @@ export async function handleLogsUsageRoutes(ctx: ManagementContext): Promise<Res
|
|
|
185
197
|
return jsonResponse(setDebugSettings(partial));
|
|
186
198
|
}
|
|
187
199
|
|
|
200
|
+
if (url.pathname === "/api/usage/source-facets" && req.method === "GET") {
|
|
201
|
+
const { auth, readStoreFor } = await import("./link-route-state");
|
|
202
|
+
const denied = auth(ctx, "dashboard");
|
|
203
|
+
if (denied) return denied;
|
|
204
|
+
if (config.runtimeRole === "client") return jsonResponse({ error: "source facets unavailable on a child" }, 403);
|
|
205
|
+
const parsed = parseUsageSource(url.searchParams);
|
|
206
|
+
if (parsed.kind !== "filtered" || [...url.searchParams.keys()].some(key => !["client", "device", "apiKeyId"].includes(key))) {
|
|
207
|
+
return Response.json({ error: "invalid usage source filter" }, { status: 400, headers: { "cache-control": "no-store" } });
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const ids = configuredUsageKeyIds(config);
|
|
211
|
+
if (parsed.filter.device.kind === "key" && !ids.includes(parsed.filter.device.id)) {
|
|
212
|
+
return Response.json({ error: "unknown key" }, { status: 400, headers: { "cache-control": "no-store" } });
|
|
213
|
+
}
|
|
214
|
+
const links = JSON.stringify(readStoreFor(ctx).links.map(({ apiKeyId, alias }) => [apiKeyId, alias]).sort());
|
|
215
|
+
const { getUsageSourceFacets } = await import("./usage-source-facets");
|
|
216
|
+
const facets = await getUsageSourceFacets(parsed.filter, ids);
|
|
217
|
+
const revoked = auth(ctx, "dashboard");
|
|
218
|
+
if (revoked) return expiredUsageSession();
|
|
219
|
+
const currentIds = configuredUsageKeyIds(config);
|
|
220
|
+
const currentLinks = JSON.stringify(readStoreFor(ctx).links.map(({ apiKeyId, alias }) => [apiKeyId, alias]).sort());
|
|
221
|
+
if (JSON.stringify(ids) !== JSON.stringify(currentIds) || links !== currentLinks) throw new Error("inventory changed");
|
|
222
|
+
return Response.json(facets, { headers: { "cache-control": "no-store" } });
|
|
223
|
+
} catch {
|
|
224
|
+
if (auth(ctx, "dashboard")) return expiredUsageSession();
|
|
225
|
+
return Response.json({ error: "usage_facets_unavailable" }, { status: 503, headers: { "cache-control": "no-store", "retry-after": "1" } });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (url.pathname === "/api/usage/devices" && req.method === "GET") {
|
|
230
|
+
const { auth, readStoreFor } = await import("./link-route-state");
|
|
231
|
+
const denied = auth(ctx, "dashboard");
|
|
232
|
+
if (denied) return denied;
|
|
233
|
+
if (ctx.config.runtimeRole === "client") return jsonResponse({ error: "device inventory unavailable on a child" }, 403);
|
|
234
|
+
try {
|
|
235
|
+
const aliases = new Map<string, string | null>();
|
|
236
|
+
for (const link of readStoreFor(ctx).links) {
|
|
237
|
+
aliases.set(link.apiKeyId, aliases.has(link.apiKeyId) ? null : link.alias);
|
|
238
|
+
}
|
|
239
|
+
const devices = [...aliases].sort(([left], [right]) => left.localeCompare(right))
|
|
240
|
+
.map(([apiKeyId, alias]) => ({ apiKeyId, alias }));
|
|
241
|
+
return Response.json({ devices }, { headers: { "cache-control": "no-store" } });
|
|
242
|
+
} catch {
|
|
243
|
+
return jsonResponse({ error: "link_store_unavailable" }, 503);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
188
247
|
if (url.pathname === "/api/usage" && req.method === "GET") {
|
|
248
|
+
const source = parseUsageSource(url.searchParams);
|
|
249
|
+
if (source.kind === "invalid") return jsonResponse({ error: "invalid usage source filter" }, 400);
|
|
250
|
+
const unconfigured = source.kind === "filtered" && source.filter.device.kind === "unconfigured";
|
|
251
|
+
const sessionGuard = unconfigured ? (await import("./link-route-state")).auth : null;
|
|
252
|
+
if (sessionGuard) {
|
|
253
|
+
const denied = sessionGuard(ctx, "dashboard");
|
|
254
|
+
if (denied) return denied;
|
|
255
|
+
}
|
|
256
|
+
let configuredIds: string[] | undefined;
|
|
257
|
+
if (unconfigured) {
|
|
258
|
+
try { configuredIds = configuredUsageKeyIds(config); }
|
|
259
|
+
catch { return Response.json({ error: "usage_inventory_unavailable" }, { status: 503, headers: { "cache-control": "no-store" } }); }
|
|
260
|
+
}
|
|
189
261
|
if (url.searchParams.get("jev") === "1") {
|
|
190
262
|
const range = parseRange(url.searchParams.get("range"));
|
|
191
263
|
const rawComboId = url.searchParams.get("comboId");
|
|
@@ -244,8 +316,10 @@ export async function handleLogsUsageRoutes(ctx: ManagementContext): Promise<Res
|
|
|
244
316
|
provider: url.searchParams.get("provider"),
|
|
245
317
|
model: url.searchParams.get("model"),
|
|
246
318
|
apiKeyId: url.searchParams.get("apiKeyId"),
|
|
319
|
+
...(source.kind === "filtered" ? { sourceFilter: source.filter } : {}),
|
|
320
|
+
...(configuredIds ? { configuredApiKeyIds: configuredIds } : {}),
|
|
247
321
|
};
|
|
248
|
-
const filterRequested = window !== undefined || [filter.provider, filter.model, filter.apiKeyId]
|
|
322
|
+
const filterRequested = source.kind === "filtered" || window !== undefined || [filter.provider, filter.model, filter.apiKeyId]
|
|
249
323
|
.some(value => typeof value === "string" && value.trim() !== "");
|
|
250
324
|
const now = Date.now();
|
|
251
325
|
try {
|
|
@@ -272,17 +346,27 @@ export async function handleLogsUsageRoutes(ctx: ManagementContext): Promise<Res
|
|
|
272
346
|
if (cached && !filterRequested) discardUsageSummaryCacheEntry(cacheKey);
|
|
273
347
|
if (filterRequested) {
|
|
274
348
|
const filteredAggregate = await getFilteredUsageAggregate(filter, window);
|
|
349
|
+
if (sessionGuard) {
|
|
350
|
+
const denied = sessionGuard(ctx, "dashboard");
|
|
351
|
+
if (denied) return expiredUsageSession();
|
|
352
|
+
const currentIds = configuredUsageKeyIds(config);
|
|
353
|
+
if (JSON.stringify(currentIds) !== JSON.stringify(configuredIds)) {
|
|
354
|
+
return Response.json({ error: "usage_inventory_changed" }, { status: 503, headers: { "cache-control": "no-store" } });
|
|
355
|
+
}
|
|
356
|
+
}
|
|
275
357
|
const accumulator = filteredAggregate.accumulator;
|
|
276
|
-
|
|
358
|
+
const body = {
|
|
277
359
|
...accumulator.summarize(range, now, surface),
|
|
278
|
-
...(filteredAggregate.usageIncomplete ? { usageIncomplete: true as const, usageIncompleteReason: "oversized_rows" as const }
|
|
360
|
+
...(filteredAggregate.usageIncomplete ? { usageIncomplete: true as const, usageIncompleteReason: "oversized_rows" as const }
|
|
361
|
+
: unconfigured && filteredAggregate.usageInvalidRows ? { usageIncomplete: true as const } : {}),
|
|
279
362
|
historyTruncated: false,
|
|
280
363
|
truncatedPrefixBytes: 0,
|
|
281
364
|
entriesTruncated: false,
|
|
282
365
|
entriesDropped: 0,
|
|
283
366
|
snapshotWindowStart: accumulator.snapshotWindow.start,
|
|
284
367
|
snapshotWindowEnd: accumulator.snapshotWindow.end,
|
|
285
|
-
}
|
|
368
|
+
};
|
|
369
|
+
return unconfigured ? Response.json(body, { headers: { "cache-control": "no-store" } }) : jsonResponse(body);
|
|
286
370
|
}
|
|
287
371
|
|
|
288
372
|
const configuredApiKeyIds = (config.apiKeys ?? []).map(key => key.id);
|
|
@@ -348,6 +432,7 @@ export async function handleLogsUsageRoutes(ctx: ManagementContext): Promise<Res
|
|
|
348
432
|
}
|
|
349
433
|
return jsonResponse(requestedSummary);
|
|
350
434
|
} catch {
|
|
435
|
+
if (sessionGuard && sessionGuard(ctx, "dashboard")) return expiredUsageSession();
|
|
351
436
|
// A missing ledger is handled as an empty installation by the reader. Reaching this catch
|
|
352
437
|
// therefore means the report is unavailable, not that usage was measured as zero. Keep the
|
|
353
438
|
// transport status aligned with the JEV projection above so every dashboard consumer can
|
|
@@ -49,8 +49,6 @@ import { ProviderOutboundPolicyError, providerOutboundGet, providerOutboundPost,
|
|
|
49
49
|
import { fetchCursorUsableModels } from "../../adapters/cursor/live-models";
|
|
50
50
|
import { fetchDevinUsableModels } from "../../adapters/devin/live-models";
|
|
51
51
|
import { resolveDevinApiBaseUrl } from "../../oauth/devin/api-base";
|
|
52
|
-
import { fetchQoderModels } from "../../adapters/qoder/live-models";
|
|
53
|
-
import { resolveQoderProfile } from "../../adapters/qoder/profiles";
|
|
54
52
|
import { parseAntigravityAvailableModels } from "../../providers/antigravity-models";
|
|
55
53
|
import { enrichProviderFromCatalog, listKeyLoginProviders } from "../../oauth/key-providers";
|
|
56
54
|
import {
|
|
@@ -1702,26 +1700,8 @@ export async function handleProviderRoutes(ctx: ManagementContext): Promise<Resp
|
|
|
1702
1700
|
});
|
|
1703
1701
|
}
|
|
1704
1702
|
if (prov.adapter === "qoder") {
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
if (!profile) {
|
|
1708
|
-
return jsonResponse({ ok: false, latencyMs: 0, error: "qoder discovery refused a non-canonical destination" });
|
|
1709
|
-
}
|
|
1710
|
-
const live = await fetchQoderModels(profile, apiKey ?? "");
|
|
1711
|
-
const latencyMs = Date.now() - started;
|
|
1712
|
-
if (!live.ok) {
|
|
1713
|
-
return jsonResponse({
|
|
1714
|
-
ok: false,
|
|
1715
|
-
latencyMs,
|
|
1716
|
-
error: `qoder discovery ${live.error}${live.detail ? `: ${live.detail}` : ""}`,
|
|
1717
|
-
});
|
|
1718
|
-
}
|
|
1719
|
-
return jsonResponse({
|
|
1720
|
-
ok: true,
|
|
1721
|
-
latencyMs,
|
|
1722
|
-
models: live.models.length,
|
|
1723
|
-
message: `Connected. ${live.models.length} models.`,
|
|
1724
|
-
});
|
|
1703
|
+
// A late success re-syncs the catalog through the same convergence every mutation uses.
|
|
1704
|
+
return (await import("./qoder-provider-probe")).probeQoderProvider(name, prov, apiKey, convergeCodexCatalog);
|
|
1725
1705
|
}
|
|
1726
1706
|
const project = prov.project ?? snapshot?.projectId;
|
|
1727
1707
|
if (antigravity && !project) {
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { discoverQoderModels, QODER_INTERACTIVE_DEADLINE_MS } from "../../adapters/qoder/live-models";
|
|
2
|
+
import { resolveQoderProfile } from "../../adapters/qoder/profiles";
|
|
3
|
+
import { captureModelCacheGeneration, isModelCacheGenerationCurrent } from "../../codex/model-cache";
|
|
4
|
+
import { clearGatherRoutedModelsInflight } from "../../codex/catalog/routed-gather";
|
|
5
|
+
import type { OcxProviderConfig } from "../../types";
|
|
6
|
+
import { jsonResponse } from "../auth-cors";
|
|
7
|
+
|
|
8
|
+
export interface QoderProbeDeps {
|
|
9
|
+
deadlineMs?: number;
|
|
10
|
+
/** Waits between re-sync attempts; the first attempt runs at once. */
|
|
11
|
+
resyncDelaysMs?: readonly number[];
|
|
12
|
+
sleep?: (ms: number) => Promise<void>;
|
|
13
|
+
clearGatherInflight?: () => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Re-sync attempts after a late success: at once, then while a busy or stale convergence clears. */
|
|
17
|
+
export const QODER_LATE_RESYNC_DELAYS_MS = [0, 2_000, 5_000, 10_000] as const;
|
|
18
|
+
|
|
19
|
+
function retryable(disposition: unknown): boolean {
|
|
20
|
+
const outcome = disposition as { status?: unknown; retryable?: unknown } | null | undefined;
|
|
21
|
+
return (outcome?.status === "skipped" || outcome?.status === "failed") && outcome.retryable === true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Publish a late roster. The finished run is not stored yet, so the convergence gather prefers it
|
|
26
|
+
* over the cached roster, which stays as the fallback if publication never happens. Each attempt
|
|
27
|
+
* first drops in-flight aggregate gathers, as a provider reload does: one that started before the
|
|
28
|
+
* run finished may already hold the old roster and would hand it to the convergence that joins it.
|
|
29
|
+
* A busy or stale convergence is retried; an invalidated cache generation ends the attempts.
|
|
30
|
+
*/
|
|
31
|
+
async function resyncAfterLateSuccess(
|
|
32
|
+
name: string,
|
|
33
|
+
generation: string,
|
|
34
|
+
converge: () => Promise<unknown>,
|
|
35
|
+
deps: QoderProbeDeps,
|
|
36
|
+
): Promise<void> {
|
|
37
|
+
const sleep = deps.sleep ?? (ms => new Promise<void>(resolve => { setTimeout(resolve, ms).unref?.(); }));
|
|
38
|
+
for (const delay of deps.resyncDelaysMs ?? QODER_LATE_RESYNC_DELAYS_MS) {
|
|
39
|
+
if (delay > 0) await sleep(delay);
|
|
40
|
+
if (!isModelCacheGenerationCurrent(name, generation)) return;
|
|
41
|
+
(deps.clearGatherInflight ?? clearGatherRoutedModelsInflight)();
|
|
42
|
+
let disposition: unknown;
|
|
43
|
+
try { disposition = await converge(); } catch { continue; }
|
|
44
|
+
if (!retryable(disposition)) return;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Connection test for Qoder (#8115). Lives outside `provider-routes.ts`, which sits at the
|
|
50
|
+
* file-size threshold.
|
|
51
|
+
*
|
|
52
|
+
* `qoder --list-models` can take longer than this interactive test should wait, so the test joins
|
|
53
|
+
* the shared background discovery (the same run the catalog gather uses, with its longer bound)
|
|
54
|
+
* and waits only its own short deadline. Past it, the provider is reported as still discovering
|
|
55
|
+
* rather than failed. A later success runs `converge`, the management catalog convergence, whose
|
|
56
|
+
* gather reads that run ahead of the cached roster and publishes the models without a proxy
|
|
57
|
+
* restart; running Codex sessions keep their copy until restarted (see
|
|
58
|
+
* {@link resyncAfterLateSuccess}). Nothing happens when the cache was invalidated meanwhile: the run
|
|
59
|
+
* belongs to the previous generation.
|
|
60
|
+
*/
|
|
61
|
+
export async function probeQoderProvider(
|
|
62
|
+
name: string,
|
|
63
|
+
prov: OcxProviderConfig,
|
|
64
|
+
apiKey: string | undefined,
|
|
65
|
+
converge: () => Promise<unknown>,
|
|
66
|
+
deps: QoderProbeDeps = {},
|
|
67
|
+
): Promise<Response> {
|
|
68
|
+
const started = Date.now();
|
|
69
|
+
const profile = resolveQoderProfile(prov.baseUrl);
|
|
70
|
+
if (!profile) {
|
|
71
|
+
return jsonResponse({ ok: false, latencyMs: 0, error: "qoder discovery refused a non-canonical destination" });
|
|
72
|
+
}
|
|
73
|
+
const generation = captureModelCacheGeneration(name);
|
|
74
|
+
const run = discoverQoderModels(profile, apiKey ?? "", `${name}\0${generation}`);
|
|
75
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
76
|
+
const deadline = new Promise<null>(resolve => {
|
|
77
|
+
timer = setTimeout(() => resolve(null), deps.deadlineMs ?? QODER_INTERACTIVE_DEADLINE_MS);
|
|
78
|
+
});
|
|
79
|
+
const live = await Promise.race([run, deadline]).finally(() => clearTimeout(timer));
|
|
80
|
+
const latencyMs = Date.now() - started;
|
|
81
|
+
if (live === null) {
|
|
82
|
+
void run.then(result => {
|
|
83
|
+
if (result.ok) return resyncAfterLateSuccess(name, generation, converge, deps);
|
|
84
|
+
}).catch(() => undefined);
|
|
85
|
+
return jsonResponse({
|
|
86
|
+
ok: true,
|
|
87
|
+
discovering: true,
|
|
88
|
+
latencyMs,
|
|
89
|
+
message: "Qoder is still listing models; they appear in the catalog when discovery finishes.",
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (!live.ok) {
|
|
93
|
+
return jsonResponse({
|
|
94
|
+
ok: false,
|
|
95
|
+
latencyMs,
|
|
96
|
+
error: `qoder discovery ${live.error}${live.detail ? `: ${live.detail}` : ""}`,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return jsonResponse({
|
|
100
|
+
ok: true,
|
|
101
|
+
latencyMs,
|
|
102
|
+
models: live.models.length,
|
|
103
|
+
message: `Connected. ${live.models.length} models.`,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
@@ -136,6 +136,7 @@ export const MANAGEMENT_ROUTES: readonly ManagementRoute[] = [
|
|
|
136
136
|
{ method: "PUT", path: "/api/codex-auth/pool-strategy", module: "codex/auth-api/routes", mutates: true, exempt: { reason: "compatibility-alias", why: "Superseded by PUT /api/pool/settings, which the CLI now drives. Kept working for existing clients and pinned by exact-body goldens in tests/server/account-pool-management-api.test.ts; no CLI verb targets it any more." } },
|
|
137
137
|
// codex/native-profile-api
|
|
138
138
|
{ method: "GET", path: "/api/native-main-profiles", module: "codex/native-profile-api", mutates: false },
|
|
139
|
+
{ method: "GET", path: "/api/native-main-profiles/admission", module: "codex/native-profile-api", mutates: false, exempt: { reason: "deferred-verb", why: "Read by `ocx doctor` over its single-use local read capability; ocx doctor is not a registry verb, and no operator verb reports admission on its own yet.", owner: "native-main admission", ownerDoc: "structure/codex-home.md" } },
|
|
139
140
|
{ method: "GET", path: "/api/native-main-profiles/doctor", module: "codex/native-profile-api", mutates: false },
|
|
140
141
|
{ method: "POST", path: "/api/native-main-profiles/recover", module: "codex/native-profile-api", mutates: true },
|
|
141
142
|
{ method: "POST", path: "/api/native-main-profiles/register", module: "codex/native-profile-api", mutates: true },
|
|
@@ -180,7 +181,7 @@ export const MANAGEMENT_ROUTES: readonly ManagementRoute[] = [
|
|
|
180
181
|
{ method: "POST", path: "/api/codex/desktop-compatibility/settings", module: "server/management/desktop-compatibility-settings-routes", mutates: true, mechanism: "path-constant", exempt: { reason: "session-only", why: "Saved native observation intent requires an operator-paired local GUI action and fresh field revision." } },
|
|
181
182
|
// server/management/codex-cli-update-routes
|
|
182
183
|
{ method: "GET", path: "/api/codex/cli-update/plan", module: "server/management/codex-cli-update-routes", mutates: false, exempt: { reason: "local-transport", why: "The CLI runs the same proof-bound plan builder locally; the authenticated route also supplies the dashboard plan." } },
|
|
183
|
-
{ method: "POST", path: "/api/codex/cli-update/apply", module: "server/management/codex-cli-update-routes", mutates: true, exempt: { reason: "session-only", why: "HTTP apply requires a
|
|
184
|
+
{ method: "POST", path: "/api/codex/cli-update/apply", module: "server/management/codex-cli-update-routes", mutates: true, exempt: { reason: "session-only", why: "HTTP apply requires a current paired dashboard session on trusted loopback ingress, matching origin, CSRF and confirmed: true; the local CLI uses --yes independently." } },
|
|
184
185
|
{ method: "GET", path: "/api/codex/cli-update/jobs/{jobId}", module: "server/management/codex-cli-update-routes", mutates: false, mechanism: "regex", exempt: { reason: "local-transport", why: "The CLI status command reads the same protected job record directly and does not use job IDs as authorization." } },
|
|
185
186
|
{ method: "PUT", path: "/api/codex-auth/features/default-mode-request-user-input", module: "server/management/agent-settings-routes", mutates: true },
|
|
186
187
|
{ method: "PUT", path: "/api/effort-caps", module: "server/management/agent-settings-routes", mutates: true },
|
|
@@ -288,6 +289,8 @@ export const MANAGEMENT_ROUTES: readonly ManagementRoute[] = [
|
|
|
288
289
|
{ method: "GET", path: "/api/storage/trash", module: "server/management/logs-usage-routes", mutates: false },
|
|
289
290
|
{ method: "GET", path: "/api/storage/trash/restore/test-stream", module: "server/management/logs-usage-routes", mutates: false, exempt: { reason: "test-seam", why: "Opt-in streaming seam declared at src/storage/restore-job.ts:34." } },
|
|
290
291
|
{ method: "GET", path: "/api/usage", module: "server/management/logs-usage-routes", mutates: false },
|
|
292
|
+
{ method: "GET", path: "/api/usage/devices", module: "server/management/logs-usage-routes", mutates: false, exempt: { reason: "session-only", why: "Device inventory requires a current dashboard session and refuses raw admin and data keys." } },
|
|
293
|
+
{ method: "GET", path: "/api/usage/source-facets", module: "server/management/logs-usage-routes", mutates: false, exempt: { reason: "session-only", why: "Usage source facets require a current dashboard session and refuse raw admin and data keys." } },
|
|
291
294
|
// server/management/usage-timeline-routes
|
|
292
295
|
{ method: "GET", path: "/api/usage/timeline", module: "server/management/usage-timeline-routes", mutates: false },
|
|
293
296
|
// server/management/advisor-routes
|
|
@@ -12,9 +12,11 @@ import {
|
|
|
12
12
|
import {
|
|
13
13
|
createUsageSummaryAccumulator,
|
|
14
14
|
type UsageSummaryAccumulator,
|
|
15
|
+
type UsageSummaryFilterInput,
|
|
15
16
|
} from "../../usage/summary";
|
|
16
17
|
import { userCostOverlayVersion } from "../../usage/user-cost-overlays";
|
|
17
18
|
import type { UsageTimeWindow } from "../../usage/time-range";
|
|
19
|
+
import { snapshotConfiguredKeyIds } from "../../usage/source-filter";
|
|
18
20
|
import {
|
|
19
21
|
createJevStatsAccumulator,
|
|
20
22
|
type JevStatsAccumulator,
|
|
@@ -28,6 +30,7 @@ import {
|
|
|
28
30
|
interface RetainedUsageAggregate {
|
|
29
31
|
accumulator: UsageSummaryAccumulator;
|
|
30
32
|
usageIncomplete: boolean;
|
|
33
|
+
usageInvalidRows: boolean;
|
|
31
34
|
revision: UsageLogRevision | null;
|
|
32
35
|
identityKey: string;
|
|
33
36
|
revisionKey: string;
|
|
@@ -54,6 +57,7 @@ type RetainedAggregateState = RetainedUsageAggregate | RetainedJevStatsAggregate
|
|
|
54
57
|
export interface UsageAggregateResult {
|
|
55
58
|
accumulator: UsageSummaryAccumulator;
|
|
56
59
|
usageIncomplete: boolean;
|
|
60
|
+
usageInvalidRows: boolean;
|
|
57
61
|
revision: UsageLogRevision | null;
|
|
58
62
|
processedThroughBytes: number;
|
|
59
63
|
overlayVersion: number;
|
|
@@ -108,6 +112,7 @@ function resultFrom(
|
|
|
108
112
|
return {
|
|
109
113
|
accumulator: state.accumulator,
|
|
110
114
|
usageIncomplete: state.usageIncomplete,
|
|
115
|
+
usageInvalidRows: state.usageInvalidRows,
|
|
111
116
|
revision: state.revision,
|
|
112
117
|
processedThroughBytes: state.processedThroughBytes,
|
|
113
118
|
overlayVersion: state.overlayVersion,
|
|
@@ -133,6 +138,7 @@ function makeRetainedAggregate(
|
|
|
133
138
|
return {
|
|
134
139
|
accumulator,
|
|
135
140
|
usageIncomplete: scan.oversizedRows > 0,
|
|
141
|
+
usageInvalidRows: scan.invalidRows > 0,
|
|
136
142
|
revision: scan.revision,
|
|
137
143
|
identityKey: usageLogIdentityKey(scan.revision),
|
|
138
144
|
revisionKey: usageLogRevisionKey(scan.revision),
|
|
@@ -233,6 +239,7 @@ async function appendAggregate(
|
|
|
233
239
|
// A partial unterminated row can be scanned again on the next append.
|
|
234
240
|
// Preserve a boolean diagnostic rather than double-counting omissions.
|
|
235
241
|
usageIncomplete: state.usageIncomplete || scan.oversizedRows > 0,
|
|
242
|
+
usageInvalidRows: state.usageInvalidRows || scan.invalidRows > 0,
|
|
236
243
|
revision: scan.revision,
|
|
237
244
|
identityKey: usageLogIdentityKey(scan.revision),
|
|
238
245
|
revisionKey: usageLogRevisionKey(scan.revision),
|
|
@@ -293,21 +300,21 @@ function normalizeExactFilterValue(value: string | null | undefined): string | n
|
|
|
293
300
|
return normalized || null;
|
|
294
301
|
}
|
|
295
302
|
|
|
296
|
-
export async function getFilteredUsageAggregate(filter: {
|
|
297
|
-
provider?: string | null;
|
|
298
|
-
model?: string | null;
|
|
299
|
-
apiKeyId?: string | null;
|
|
300
|
-
}, window?: UsageTimeWindow): Promise<UsageAggregateResult> {
|
|
303
|
+
export async function getFilteredUsageAggregate(filter: UsageSummaryFilterInput, window?: UsageTimeWindow): Promise<UsageAggregateResult> {
|
|
301
304
|
const fixedWindow = window ? Object.freeze({ ...window }) : undefined;
|
|
302
305
|
const normalizedFilter = {
|
|
303
306
|
provider: normalizeFilterValue(filter.provider),
|
|
304
307
|
model: normalizeFilterValue(filter.model),
|
|
305
308
|
apiKeyId: normalizeExactFilterValue(filter.apiKeyId),
|
|
309
|
+
...(filter.sourceFilter ? { sourceFilter: { client: filter.sourceFilter.client, device: { ...filter.sourceFilter.device } } } : {}),
|
|
310
|
+
...(filter.configuredApiKeyIds ? { configuredApiKeyIds: snapshotConfiguredKeyIds(filter.configuredApiKeyIds) } : {}),
|
|
306
311
|
};
|
|
307
312
|
const key = JSON.stringify([
|
|
308
313
|
normalizedFilter.provider,
|
|
309
314
|
normalizedFilter.model,
|
|
310
315
|
normalizedFilter.apiKeyId,
|
|
316
|
+
normalizedFilter.sourceFilter ?? null,
|
|
317
|
+
normalizedFilter.configuredApiKeyIds ?? null,
|
|
311
318
|
fixedWindow?.since ?? null,
|
|
312
319
|
fixedWindow?.until ?? null,
|
|
313
320
|
]);
|
|
@@ -330,6 +337,8 @@ type NormalizedUsageFilter = {
|
|
|
330
337
|
provider: string | null;
|
|
331
338
|
model: string | null;
|
|
332
339
|
apiKeyId: string | null;
|
|
340
|
+
sourceFilter?: UsageSummaryFilterInput["sourceFilter"];
|
|
341
|
+
configuredApiKeyIds?: readonly string[];
|
|
333
342
|
};
|
|
334
343
|
|
|
335
344
|
function trimRetainedFilteredAggregates(): void {
|
|
@@ -405,6 +414,7 @@ async function appendFilteredAggregate(
|
|
|
405
414
|
...state,
|
|
406
415
|
accumulator: candidate,
|
|
407
416
|
usageIncomplete: state.usageIncomplete || scan.oversizedRows > 0,
|
|
417
|
+
usageInvalidRows: state.usageInvalidRows || scan.invalidRows > 0,
|
|
408
418
|
revision: scan.revision,
|
|
409
419
|
identityKey: usageLogIdentityKey(scan.revision),
|
|
410
420
|
revisionKey: usageLogRevisionKey(scan.revision),
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { scanUsageLedgerCooperatively } from "../../usage/ledger-scanner";
|
|
2
|
+
import { currentUsageLogRevision, usageLogIdentityKey, usageLogRevisionKey } from "../../usage/log";
|
|
3
|
+
import { createSourceFacetAccumulator } from "../../usage/source-facets";
|
|
4
|
+
import { snapshotConfiguredKeyIds, type UsageSourceFilter } from "../../usage/source-filter";
|
|
5
|
+
import { rangeWindow } from "../../usage/summary";
|
|
6
|
+
|
|
7
|
+
const MAX_FLIGHTS = 4;
|
|
8
|
+
const flights = new Map<string, Promise<SourceFacets>>();
|
|
9
|
+
|
|
10
|
+
export class SourceFacetsBusyError extends Error {}
|
|
11
|
+
type SourceFacets = ReturnType<ReturnType<typeof createSourceFacetAccumulator>["snapshot"]> & {
|
|
12
|
+
sourceFilter: UsageSourceFilter;
|
|
13
|
+
window: { since: number; until: number; timeZone: string };
|
|
14
|
+
usageIncomplete: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** Single-flight identical requests; never retain arbitrary historical key IDs. */
|
|
18
|
+
export async function getUsageSourceFacets(filter: UsageSourceFilter, configuredIds: readonly string[]): Promise<SourceFacets> {
|
|
19
|
+
const ids = snapshotConfiguredKeyIds(configuredIds);
|
|
20
|
+
const captured: UsageSourceFilter = { client: filter.client, device: { ...filter.device } };
|
|
21
|
+
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
22
|
+
const revision = currentUsageLogRevision();
|
|
23
|
+
const key = JSON.stringify([captured, ids, timeZone, usageLogIdentityKey(revision), usageLogRevisionKey(revision)]);
|
|
24
|
+
const existing = flights.get(key);
|
|
25
|
+
if (existing) return existing;
|
|
26
|
+
if (flights.size >= MAX_FLIGHTS) throw new SourceFacetsBusyError("usage facets busy");
|
|
27
|
+
const flight = (async () => {
|
|
28
|
+
const until = Date.now();
|
|
29
|
+
const since = rangeWindow("30d", until).since!;
|
|
30
|
+
const accumulator = createSourceFacetAccumulator(captured, ids, { since, until });
|
|
31
|
+
const scan = await scanUsageLedgerCooperatively({ onEntry: row => accumulator.add(row) });
|
|
32
|
+
if (Intl.DateTimeFormat().resolvedOptions().timeZone !== timeZone) throw new Error("time zone changed");
|
|
33
|
+
return { ...accumulator.snapshot(), sourceFilter: captured, window: { since, until, timeZone },
|
|
34
|
+
usageIncomplete: scan.oversizedRows > 0 || scan.invalidRows > 0 };
|
|
35
|
+
})();
|
|
36
|
+
flights.set(key, flight);
|
|
37
|
+
try { return await flight; } finally { if (flights.get(key) === flight) flights.delete(key); }
|
|
38
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clientFacingModelLabel } from "../lib/error-destination";
|
|
1
2
|
import {
|
|
2
3
|
AdmissionModelDeniedError, routeAllowedByScope, UNNAMED_DESTINATION_MODEL, type AdmissionModelScope,
|
|
3
4
|
} from "./admission-model-scope";
|
|
@@ -58,7 +59,7 @@ export function nativeMessagesToolScopeDenial(
|
|
|
58
59
|
if (!isAdvisor(tool)) continue;
|
|
59
60
|
const modelId = typeof tool.model === "string" && tool.model.trim() ? tool.model : undefined;
|
|
60
61
|
if (modelId === undefined || !routeAllowedByScope(scope, { providerName, modelId })) {
|
|
61
|
-
return new AdmissionModelDeniedError(requestedModel, { providerName, modelId: modelId ?? UNNAMED_DESTINATION_MODEL });
|
|
62
|
+
return new AdmissionModelDeniedError(clientFacingModelLabel(requestedModel), { providerName, modelId: modelId ?? UNNAMED_DESTINATION_MODEL });
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
return undefined;
|