opencode-quota-gui 1.2.0 → 1.3.1
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/README.md +104 -34
- package/dist/contracts/analytics-entity.d.ts +6 -1
- package/dist/contracts/analytics-entity.js +27 -10
- package/dist/contracts/build-identity.js +1 -1
- package/dist/contracts/card-visibility.d.ts +21 -0
- package/dist/contracts/card-visibility.js +19 -0
- package/dist/contracts/dashboard.d.ts +35 -1
- package/dist/contracts/dashboard.js +2 -0
- package/dist/contracts/dto-guards.d.ts +24 -0
- package/dist/contracts/dto-guards.js +594 -0
- package/dist/contracts/openai-quota.d.ts +3 -0
- package/dist/contracts/openai-quota.js +3 -0
- package/dist/contracts/provider-failure.d.ts +18 -0
- package/dist/contracts/provider-failure.js +25 -0
- package/dist/data/modelsdev-temporal.min.json +57 -0
- package/dist/gui/config.d.ts +20 -3
- package/dist/gui/config.js +72 -4
- package/dist/gui/dashboard-errors.d.ts +32 -0
- package/dist/gui/dashboard-errors.js +97 -0
- package/dist/gui/lifecycle.d.ts +47 -12
- package/dist/gui/lifecycle.js +215 -37
- package/dist/gui/primary-quota-windows.d.ts +28 -0
- package/dist/gui/primary-quota-windows.js +149 -0
- package/dist/gui/provider-cards.d.ts +11 -3
- package/dist/gui/provider-cards.js +85 -33
- package/dist/gui/quota-notification-detector.d.ts +151 -0
- package/dist/gui/quota-notification-detector.js +318 -0
- package/dist/gui/quota-notification-observer.d.ts +54 -0
- package/dist/gui/quota-notification-observer.js +412 -0
- package/dist/gui/rpc.d.ts +61 -0
- package/dist/gui/rpc.js +310 -0
- package/dist/gui/server.d.ts +15 -27
- package/dist/gui/server.js +34 -123
- package/dist/gui/snapshot-service.d.ts +34 -5
- package/dist/gui/snapshot-service.js +301 -70
- package/dist/gui/sources.d.ts +1 -1
- package/dist/gui/sources.js +98 -56
- package/dist/gui-experimental.cjs +1761 -0
- package/dist/lib/accounting-format.js +8 -0
- package/dist/lib/alibaba-coding-plan-cli.d.ts +79 -0
- package/dist/lib/alibaba-coding-plan-cli.js +539 -0
- package/dist/lib/anthropic-auth.d.ts +2 -3
- package/dist/lib/anthropic-auth.js +2 -3
- package/dist/lib/anthropic.d.ts +53 -12
- package/dist/lib/anthropic.js +622 -270
- package/dist/lib/api-key-retry-after.d.ts +7 -0
- package/dist/lib/api-key-retry-after.js +62 -0
- package/dist/lib/atomic-json.d.ts +2 -0
- package/dist/lib/atomic-json.js +1 -0
- package/dist/lib/cache-observer-ingestion.d.ts +90 -0
- package/dist/lib/cache-observer-ingestion.js +981 -0
- package/dist/lib/cache-observer.d.ts +138 -0
- package/dist/lib/cache-observer.js +317 -0
- package/dist/lib/canonical-config-lock.d.ts +9 -0
- package/dist/lib/canonical-config-lock.js +36 -0
- package/dist/lib/chutes.js +63 -35
- package/dist/lib/claude-agent-transcript-ttl.d.ts +48 -0
- package/dist/lib/claude-agent-transcript-ttl.js +154 -0
- package/dist/lib/claude-agent-ttl-tracker.d.ts +21 -0
- package/dist/lib/claude-agent-ttl-tracker.js +152 -0
- package/dist/lib/cli-show.js +5 -3
- package/dist/lib/config-write-target.d.ts +1 -1
- package/dist/lib/config-write-target.js +5 -2
- package/dist/lib/config.d.ts +6 -1
- package/dist/lib/config.js +241 -2
- package/dist/lib/copilot.js +198 -85
- package/dist/lib/dashboard-web-policy.d.ts +35 -0
- package/dist/lib/dashboard-web-policy.js +24 -0
- package/dist/lib/deepseek.js +34 -11
- package/dist/lib/display-sanitize.js +3 -0
- package/dist/lib/entries.d.ts +26 -0
- package/dist/lib/entries.js +2 -0
- package/dist/lib/format-utils.d.ts +1 -1
- package/dist/lib/format-utils.js +2 -2
- package/dist/lib/glm-coding-plan.js +102 -68
- package/dist/lib/google-agy.js +147 -24
- package/dist/lib/google-gemini-cli.js +140 -23
- package/dist/lib/http.d.ts +4 -0
- package/dist/lib/http.js +16 -2
- package/dist/lib/init-installer.js +30 -7
- package/dist/lib/kilo.js +63 -55
- package/dist/lib/kimi.js +43 -14
- package/dist/lib/mimo.d.ts +4 -0
- package/dist/lib/mimo.js +45 -1
- package/dist/lib/nanogpt.d.ts +3 -0
- package/dist/lib/nanogpt.js +50 -6
- package/dist/lib/ollama-cloud.d.ts +1 -1
- package/dist/lib/ollama-cloud.js +51 -29
- package/dist/lib/openai.js +90 -40
- package/dist/lib/opencode-auth-sqlite.d.ts +2 -2
- package/dist/lib/opencode-auth-sqlite.js +2 -2
- package/dist/lib/opencode-auth.d.ts +3 -2
- package/dist/lib/opencode-auth.js +8 -1
- package/dist/lib/opencode-config-editor.d.ts +1 -0
- package/dist/lib/opencode-config-editor.js +6 -1
- package/dist/lib/opencode-go.js +53 -5
- package/dist/lib/opencode-version-core.d.ts +23 -0
- package/dist/lib/opencode-version-core.js +49 -0
- package/dist/lib/opencode-version.d.ts +4 -3
- package/dist/lib/opencode-version.js +15 -11
- package/dist/lib/opencode-zen.d.ts +12 -1
- package/dist/lib/opencode-zen.js +98 -12
- package/dist/lib/provider-add.js +5 -2
- package/dist/lib/provider-registration.d.ts +19 -9
- package/dist/lib/provider-registration.js +17 -6
- package/dist/lib/quota-command-format.js +1 -1
- package/dist/lib/quota-exhaustion-projection.d.ts +11 -0
- package/dist/lib/quota-exhaustion-projection.js +25 -0
- package/dist/lib/quota-providers-remote.d.ts +4 -1
- package/dist/lib/quota-providers-remote.js +137 -22
- package/dist/lib/quota-providers.d.ts +1 -1
- package/dist/lib/quota-providers.js +12 -35
- package/dist/lib/quota-render-data.d.ts +6 -0
- package/dist/lib/quota-render-data.js +43 -17
- package/dist/lib/quota-reset-notifications.d.ts +17 -0
- package/dist/lib/quota-reset-notifications.js +11 -2
- package/dist/lib/quota-state-codec.js +19 -1
- package/dist/lib/quota-state.d.ts +7 -1
- package/dist/lib/quota-state.js +208 -34
- package/dist/lib/quota-stats.js +21 -0
- package/dist/lib/quota-status.js +3 -51
- package/dist/lib/scoped-update.d.ts +1 -1
- package/dist/lib/synthetic.js +67 -48
- package/dist/lib/types.d.ts +49 -1
- package/dist/lib/types.js +16 -0
- package/dist/lib/xai.js +64 -24
- package/dist/plugin.d.ts +4 -3
- package/dist/plugin.js +293 -16
- package/dist/provider-logos/NOTICE.md +1 -1
- package/dist/provider-logos/OPENCODE-NOTICE.md +4 -3
- package/dist/providers/alibaba-coding-plan.js +107 -102
- package/dist/providers/alibaba-token-plan.js +17 -0
- package/dist/providers/anthropic.d.ts +12 -3
- package/dist/providers/anthropic.js +71 -219
- package/dist/providers/cache-policies.d.ts +11 -4
- package/dist/providers/cache-policies.js +19 -13
- package/dist/providers/claude-agent.d.ts +19 -0
- package/dist/providers/claude-agent.js +196 -0
- package/dist/providers/copilot.js +12 -2
- package/dist/providers/glm-coding-plan-provider.d.ts +3 -0
- package/dist/providers/glm-coding-plan-provider.js +5 -1
- package/dist/providers/google-account-format.js +2 -0
- package/dist/providers/google-agy.d.ts +6 -5
- package/dist/providers/google-agy.js +55 -17
- package/dist/providers/google-gemini-cli.js +13 -2
- package/dist/providers/kilo.js +10 -1
- package/dist/providers/kimi-code.js +13 -6
- package/dist/providers/mimo.js +9 -2
- package/dist/providers/minimax-coding-plan.js +28 -5
- package/dist/providers/nanogpt.js +4 -0
- package/dist/providers/ollama-cloud.js +3 -0
- package/dist/providers/openai.js +1 -0
- package/dist/providers/opencode-go.js +11 -1
- package/dist/providers/opencode-zen.js +32 -3
- package/dist/providers/openrouter.js +4 -0
- package/dist/providers/quota-providers.js +46 -9
- package/dist/providers/registry.js +2 -0
- package/dist/providers/result-helpers.d.ts +6 -0
- package/dist/providers/result-helpers.js +18 -2
- package/dist/rpc.d.ts +440 -4
- package/dist/rpc.js +507 -2
- package/dist/ui/assets/{index-Cs-nrywz.css → index-BcueIm3Z.css} +1 -1
- package/dist/ui/assets/index-C6qRSoh8.js +10 -0
- package/dist/ui/assets/{popover-DKRrwr_K.js → popover-4bFSvRZ7.js} +1 -1
- package/dist/ui/assets/providers/claude-agent.svg +3 -0
- package/dist/ui/index.html +2 -2
- package/package.json +15 -7
- package/dist/bin/opencode-quota-gui.d.ts.map +0 -1
- package/dist/bin/opencode-quota-gui.js.map +0 -1
- package/dist/contracts/analytics-entity.d.ts.map +0 -1
- package/dist/contracts/analytics-entity.js.map +0 -1
- package/dist/contracts/analytics-temporal.d.ts.map +0 -1
- package/dist/contracts/analytics-temporal.js.map +0 -1
- package/dist/contracts/build-identity.d.ts.map +0 -1
- package/dist/contracts/card-order.d.ts.map +0 -1
- package/dist/contracts/card-order.js.map +0 -1
- package/dist/contracts/collision-safe-key.d.ts.map +0 -1
- package/dist/contracts/collision-safe-key.js.map +0 -1
- package/dist/contracts/dashboard.d.ts.map +0 -1
- package/dist/contracts/dashboard.js.map +0 -1
- package/dist/contracts/guards.d.ts.map +0 -1
- package/dist/contracts/guards.js.map +0 -1
- package/dist/contracts/identity.d.ts.map +0 -1
- package/dist/contracts/identity.js.map +0 -1
- package/dist/contracts/openai-quota.d.ts.map +0 -1
- package/dist/contracts/openai-quota.js.map +0 -1
- package/dist/contracts/ranges.d.ts.map +0 -1
- package/dist/contracts/ranges.js.map +0 -1
- package/dist/contracts/settings.d.ts.map +0 -1
- package/dist/contracts/settings.js.map +0 -1
- package/dist/contracts/temporal.d.ts.map +0 -1
- package/dist/contracts/temporal.js.map +0 -1
- package/dist/contracts/time-zone.d.ts.map +0 -1
- package/dist/contracts/time-zone.js.map +0 -1
- package/dist/gui/aggregation.d.ts.map +0 -1
- package/dist/gui/aggregation.js.map +0 -1
- package/dist/gui/analytics-bridge.d.ts.map +0 -1
- package/dist/gui/analytics-bridge.js.map +0 -1
- package/dist/gui/analytics-engine.d.ts.map +0 -1
- package/dist/gui/analytics-engine.js.map +0 -1
- package/dist/gui/analytics-indexes.d.ts.map +0 -1
- package/dist/gui/analytics-indexes.js.map +0 -1
- package/dist/gui/analytics-model.d.ts.map +0 -1
- package/dist/gui/analytics-model.js.map +0 -1
- package/dist/gui/analytics-pricing-revision.d.ts.map +0 -1
- package/dist/gui/analytics-pricing-revision.js.map +0 -1
- package/dist/gui/analytics-protocol.d.ts.map +0 -1
- package/dist/gui/analytics-protocol.js.map +0 -1
- package/dist/gui/analytics-reader.d.ts.map +0 -1
- package/dist/gui/analytics-reader.js.map +0 -1
- package/dist/gui/analytics-service.d.ts.map +0 -1
- package/dist/gui/analytics-service.js.map +0 -1
- package/dist/gui/analytics-state.d.ts.map +0 -1
- package/dist/gui/analytics-state.js.map +0 -1
- package/dist/gui/analytics-worker-runtime.d.ts.map +0 -1
- package/dist/gui/analytics-worker-runtime.js.map +0 -1
- package/dist/gui/analytics-worker.d.ts.map +0 -1
- package/dist/gui/analytics-worker.js.map +0 -1
- package/dist/gui/config.d.ts.map +0 -1
- package/dist/gui/config.js.map +0 -1
- package/dist/gui/identity.d.ts.map +0 -1
- package/dist/gui/identity.js.map +0 -1
- package/dist/gui/lifecycle.d.ts.map +0 -1
- package/dist/gui/lifecycle.js.map +0 -1
- package/dist/gui/log.d.ts.map +0 -1
- package/dist/gui/log.js.map +0 -1
- package/dist/gui/provider-cards.d.ts.map +0 -1
- package/dist/gui/provider-cards.js.map +0 -1
- package/dist/gui/server.d.ts.map +0 -1
- package/dist/gui/server.js.map +0 -1
- package/dist/gui/settings-file-opener.d.ts.map +0 -1
- package/dist/gui/settings-file-opener.js.map +0 -1
- package/dist/gui/snapshot-service.d.ts.map +0 -1
- package/dist/gui/snapshot-service.js.map +0 -1
- package/dist/gui/sources.d.ts.map +0 -1
- package/dist/gui/sources.js.map +0 -1
- package/dist/gui/sse.d.ts.map +0 -1
- package/dist/gui/sse.js.map +0 -1
- package/dist/gui/temporal-quota-policy-data.d.ts.map +0 -1
- package/dist/gui/temporal-quota-policy-data.js.map +0 -1
- package/dist/gui/temporal-quota-policy.d.ts.map +0 -1
- package/dist/gui/temporal-quota-policy.js.map +0 -1
- package/dist/gui/temporal-status.d.ts.map +0 -1
- package/dist/gui/temporal-status.js.map +0 -1
- package/dist/gui/time-zone.d.ts.map +0 -1
- package/dist/gui/time-zone.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/accounting-format.d.ts.map +0 -1
- package/dist/lib/accounting-format.js.map +0 -1
- package/dist/lib/alibaba-auth.d.ts.map +0 -1
- package/dist/lib/alibaba-auth.js.map +0 -1
- package/dist/lib/alibaba-coding-plan-local-quota.d.ts +0 -47
- package/dist/lib/alibaba-coding-plan-local-quota.d.ts.map +0 -1
- package/dist/lib/alibaba-coding-plan-local-quota.js +0 -146
- package/dist/lib/alibaba-coding-plan-local-quota.js.map +0 -1
- package/dist/lib/alibaba-token-plan.d.ts.map +0 -1
- package/dist/lib/alibaba-token-plan.js.map +0 -1
- package/dist/lib/anthropic-auth.d.ts.map +0 -1
- package/dist/lib/anthropic-auth.js.map +0 -1
- package/dist/lib/anthropic.d.ts.map +0 -1
- package/dist/lib/anthropic.js.map +0 -1
- package/dist/lib/api-key-resolver.d.ts.map +0 -1
- package/dist/lib/api-key-resolver.js.map +0 -1
- package/dist/lib/atomic-json.d.ts.map +0 -1
- package/dist/lib/atomic-json.js.map +0 -1
- package/dist/lib/chutes-config.d.ts.map +0 -1
- package/dist/lib/chutes-config.js.map +0 -1
- package/dist/lib/chutes.d.ts.map +0 -1
- package/dist/lib/chutes.js.map +0 -1
- package/dist/lib/cli-reports.d.ts.map +0 -1
- package/dist/lib/cli-reports.js.map +0 -1
- package/dist/lib/cli-show.d.ts.map +0 -1
- package/dist/lib/cli-show.js.map +0 -1
- package/dist/lib/cli-status.d.ts.map +0 -1
- package/dist/lib/cli-status.js.map +0 -1
- package/dist/lib/command-parsing.d.ts.map +0 -1
- package/dist/lib/command-parsing.js.map +0 -1
- package/dist/lib/config-file-utils.d.ts.map +0 -1
- package/dist/lib/config-file-utils.js.map +0 -1
- package/dist/lib/config-write-target.d.ts.map +0 -1
- package/dist/lib/config-write-target.js.map +0 -1
- package/dist/lib/config.d.ts.map +0 -1
- package/dist/lib/config.js.map +0 -1
- package/dist/lib/copilot.d.ts.map +0 -1
- package/dist/lib/copilot.js.map +0 -1
- package/dist/lib/cursor-detection.d.ts.map +0 -1
- package/dist/lib/cursor-detection.js.map +0 -1
- package/dist/lib/cursor-pricing.d.ts.map +0 -1
- package/dist/lib/cursor-pricing.js.map +0 -1
- package/dist/lib/cursor-usage.d.ts.map +0 -1
- package/dist/lib/cursor-usage.js.map +0 -1
- package/dist/lib/dashboard-visibility.d.ts.map +0 -1
- package/dist/lib/dashboard-visibility.js.map +0 -1
- package/dist/lib/deepseek-auth.d.ts.map +0 -1
- package/dist/lib/deepseek-auth.js.map +0 -1
- package/dist/lib/deepseek.d.ts.map +0 -1
- package/dist/lib/deepseek.js.map +0 -1
- package/dist/lib/display-sanitize.d.ts.map +0 -1
- package/dist/lib/display-sanitize.js.map +0 -1
- package/dist/lib/entries.d.ts.map +0 -1
- package/dist/lib/entries.js.map +0 -1
- package/dist/lib/env-template.d.ts.map +0 -1
- package/dist/lib/env-template.js.map +0 -1
- package/dist/lib/format-utils.d.ts.map +0 -1
- package/dist/lib/format-utils.js.map +0 -1
- package/dist/lib/format.d.ts.map +0 -1
- package/dist/lib/format.js.map +0 -1
- package/dist/lib/glm-coding-plan.d.ts.map +0 -1
- package/dist/lib/glm-coding-plan.js.map +0 -1
- package/dist/lib/google-agy-companion.d.ts.map +0 -1
- package/dist/lib/google-agy-companion.js.map +0 -1
- package/dist/lib/google-agy.d.ts.map +0 -1
- package/dist/lib/google-agy.js.map +0 -1
- package/dist/lib/google-companion-credentials.d.ts.map +0 -1
- package/dist/lib/google-companion-credentials.js.map +0 -1
- package/dist/lib/google-gemini-cli-companion.d.ts.map +0 -1
- package/dist/lib/google-gemini-cli-companion.js.map +0 -1
- package/dist/lib/google-gemini-cli.d.ts.map +0 -1
- package/dist/lib/google-gemini-cli.js.map +0 -1
- package/dist/lib/google-token-cache.d.ts.map +0 -1
- package/dist/lib/google-token-cache.js.map +0 -1
- package/dist/lib/grouped-entry-normalization.d.ts.map +0 -1
- package/dist/lib/grouped-entry-normalization.js.map +0 -1
- package/dist/lib/grouped-header-format.d.ts.map +0 -1
- package/dist/lib/grouped-header-format.js.map +0 -1
- package/dist/lib/gui-config-target.d.ts.map +0 -1
- package/dist/lib/gui-config-target.js.map +0 -1
- package/dist/lib/home-dir-display.d.ts.map +0 -1
- package/dist/lib/home-dir-display.js.map +0 -1
- package/dist/lib/http.d.ts.map +0 -1
- package/dist/lib/http.js.map +0 -1
- package/dist/lib/init-installer.d.ts.map +0 -1
- package/dist/lib/init-installer.js.map +0 -1
- package/dist/lib/jsonc.d.ts.map +0 -1
- package/dist/lib/jsonc.js.map +0 -1
- package/dist/lib/kilo-config.d.ts.map +0 -1
- package/dist/lib/kilo-config.js.map +0 -1
- package/dist/lib/kilo.d.ts.map +0 -1
- package/dist/lib/kilo.js.map +0 -1
- package/dist/lib/kimi-auth.d.ts.map +0 -1
- package/dist/lib/kimi-auth.js.map +0 -1
- package/dist/lib/kimi-endpoints.d.ts.map +0 -1
- package/dist/lib/kimi-endpoints.js.map +0 -1
- package/dist/lib/kimi.d.ts.map +0 -1
- package/dist/lib/kimi.js.map +0 -1
- package/dist/lib/maintainer-announcements.d.ts.map +0 -1
- package/dist/lib/maintainer-announcements.js.map +0 -1
- package/dist/lib/map-with-concurrency.d.ts.map +0 -1
- package/dist/lib/map-with-concurrency.js.map +0 -1
- package/dist/lib/markdown-table.d.ts.map +0 -1
- package/dist/lib/markdown-table.js.map +0 -1
- package/dist/lib/mimo-config.d.ts.map +0 -1
- package/dist/lib/mimo-config.js.map +0 -1
- package/dist/lib/mimo.d.ts.map +0 -1
- package/dist/lib/mimo.js.map +0 -1
- package/dist/lib/minimax-auth.d.ts.map +0 -1
- package/dist/lib/minimax-auth.js.map +0 -1
- package/dist/lib/minimax-endpoints.d.ts.map +0 -1
- package/dist/lib/minimax-endpoints.js.map +0 -1
- package/dist/lib/modelsdev-pricing.d.ts.map +0 -1
- package/dist/lib/modelsdev-pricing.js.map +0 -1
- package/dist/lib/modelsdev-temporal.d.ts.map +0 -1
- package/dist/lib/modelsdev-temporal.js.map +0 -1
- package/dist/lib/nanogpt-config.d.ts.map +0 -1
- package/dist/lib/nanogpt-config.js.map +0 -1
- package/dist/lib/nanogpt.d.ts.map +0 -1
- package/dist/lib/nanogpt.js.map +0 -1
- package/dist/lib/ollama-cloud-config.d.ts.map +0 -1
- package/dist/lib/ollama-cloud-config.js.map +0 -1
- package/dist/lib/ollama-cloud.d.ts.map +0 -1
- package/dist/lib/ollama-cloud.js.map +0 -1
- package/dist/lib/openai.d.ts.map +0 -1
- package/dist/lib/openai.js.map +0 -1
- package/dist/lib/opencode-auth-sqlite.d.ts.map +0 -1
- package/dist/lib/opencode-auth-sqlite.js.map +0 -1
- package/dist/lib/opencode-auth.d.ts.map +0 -1
- package/dist/lib/opencode-auth.js.map +0 -1
- package/dist/lib/opencode-config-editor.d.ts.map +0 -1
- package/dist/lib/opencode-config-editor.js.map +0 -1
- package/dist/lib/opencode-config-providers.d.ts.map +0 -1
- package/dist/lib/opencode-config-providers.js.map +0 -1
- package/dist/lib/opencode-config-read.d.ts.map +0 -1
- package/dist/lib/opencode-config-read.js.map +0 -1
- package/dist/lib/opencode-console-auth.d.ts.map +0 -1
- package/dist/lib/opencode-console-auth.js.map +0 -1
- package/dist/lib/opencode-db-path.d.ts.map +0 -1
- package/dist/lib/opencode-db-path.js.map +0 -1
- package/dist/lib/opencode-go-auth.d.ts.map +0 -1
- package/dist/lib/opencode-go-auth.js.map +0 -1
- package/dist/lib/opencode-go.d.ts.map +0 -1
- package/dist/lib/opencode-go.js.map +0 -1
- package/dist/lib/opencode-runtime-paths.d.ts.map +0 -1
- package/dist/lib/opencode-runtime-paths.js.map +0 -1
- package/dist/lib/opencode-sqlite.d.ts.map +0 -1
- package/dist/lib/opencode-sqlite.js.map +0 -1
- package/dist/lib/opencode-storage.d.ts.map +0 -1
- package/dist/lib/opencode-storage.js.map +0 -1
- package/dist/lib/opencode-version.d.ts.map +0 -1
- package/dist/lib/opencode-version.js.map +0 -1
- package/dist/lib/opencode-zen.d.ts.map +0 -1
- package/dist/lib/opencode-zen.js.map +0 -1
- package/dist/lib/openrouter.d.ts.map +0 -1
- package/dist/lib/openrouter.js.map +0 -1
- package/dist/lib/private-state-paths.d.ts.map +0 -1
- package/dist/lib/private-state-paths.js.map +0 -1
- package/dist/lib/provider-add-command.d.ts.map +0 -1
- package/dist/lib/provider-add-command.js.map +0 -1
- package/dist/lib/provider-add-json-v1-questionnaire.d.ts.map +0 -1
- package/dist/lib/provider-add-json-v1-questionnaire.js.map +0 -1
- package/dist/lib/provider-add.d.ts.map +0 -1
- package/dist/lib/provider-add.js.map +0 -1
- package/dist/lib/provider-availability.d.ts.map +0 -1
- package/dist/lib/provider-availability.js.map +0 -1
- package/dist/lib/provider-metadata.d.ts.map +0 -1
- package/dist/lib/provider-metadata.js.map +0 -1
- package/dist/lib/provider-model-matching.d.ts.map +0 -1
- package/dist/lib/provider-model-matching.js.map +0 -1
- package/dist/lib/provider-registration.d.ts.map +0 -1
- package/dist/lib/provider-registration.js.map +0 -1
- package/dist/lib/quota-accounting-projection.d.ts.map +0 -1
- package/dist/lib/quota-accounting-projection.js.map +0 -1
- package/dist/lib/quota-columns.d.ts.map +0 -1
- package/dist/lib/quota-columns.js.map +0 -1
- package/dist/lib/quota-command-format.d.ts.map +0 -1
- package/dist/lib/quota-command-format.js.map +0 -1
- package/dist/lib/quota-dialog-command-specs.d.ts.map +0 -1
- package/dist/lib/quota-dialog-command-specs.js.map +0 -1
- package/dist/lib/quota-dialog-commands.d.ts.map +0 -1
- package/dist/lib/quota-dialog-commands.js.map +0 -1
- package/dist/lib/quota-entry-display.d.ts.map +0 -1
- package/dist/lib/quota-entry-display.js.map +0 -1
- package/dist/lib/quota-exhaustion-projection.d.ts.map +0 -1
- package/dist/lib/quota-exhaustion-projection.js.map +0 -1
- package/dist/lib/quota-export-types.d.ts.map +0 -1
- package/dist/lib/quota-export-types.js.map +0 -1
- package/dist/lib/quota-export.d.ts.map +0 -1
- package/dist/lib/quota-export.js.map +0 -1
- package/dist/lib/quota-format-style.d.ts.map +0 -1
- package/dist/lib/quota-format-style.js.map +0 -1
- package/dist/lib/quota-providers-local.d.ts.map +0 -1
- package/dist/lib/quota-providers-local.js.map +0 -1
- package/dist/lib/quota-providers-remote.d.ts.map +0 -1
- package/dist/lib/quota-providers-remote.js.map +0 -1
- package/dist/lib/quota-providers.d.ts.map +0 -1
- package/dist/lib/quota-providers.js.map +0 -1
- package/dist/lib/quota-render-data.d.ts.map +0 -1
- package/dist/lib/quota-render-data.js.map +0 -1
- package/dist/lib/quota-report-message.d.ts.map +0 -1
- package/dist/lib/quota-report-message.js.map +0 -1
- package/dist/lib/quota-reset-notifications.d.ts.map +0 -1
- package/dist/lib/quota-reset-notifications.js.map +0 -1
- package/dist/lib/quota-retry-wait.d.ts.map +0 -1
- package/dist/lib/quota-retry-wait.js.map +0 -1
- package/dist/lib/quota-runtime-context.d.ts.map +0 -1
- package/dist/lib/quota-runtime-context.js.map +0 -1
- package/dist/lib/quota-state-codec.d.ts.map +0 -1
- package/dist/lib/quota-state-codec.js.map +0 -1
- package/dist/lib/quota-state.d.ts.map +0 -1
- package/dist/lib/quota-state.js.map +0 -1
- package/dist/lib/quota-stats-format.d.ts.map +0 -1
- package/dist/lib/quota-stats-format.js.map +0 -1
- package/dist/lib/quota-stats.d.ts.map +0 -1
- package/dist/lib/quota-stats.js.map +0 -1
- package/dist/lib/quota-status.d.ts.map +0 -1
- package/dist/lib/quota-status.js.map +0 -1
- package/dist/lib/quota-surface-data.d.ts.map +0 -1
- package/dist/lib/quota-surface-data.js.map +0 -1
- package/dist/lib/quota-telemetry.d.ts.map +0 -1
- package/dist/lib/quota-telemetry.js.map +0 -1
- package/dist/lib/report-document.d.ts.map +0 -1
- package/dist/lib/report-document.js.map +0 -1
- package/dist/lib/resolved-auth-identity.d.ts.map +0 -1
- package/dist/lib/resolved-auth-identity.js.map +0 -1
- package/dist/lib/runtime-provider-ids.d.ts.map +0 -1
- package/dist/lib/runtime-provider-ids.js.map +0 -1
- package/dist/lib/scoped-query-chunks.d.ts.map +0 -1
- package/dist/lib/scoped-query-chunks.js.map +0 -1
- package/dist/lib/scoped-update-migration.d.ts.map +0 -1
- package/dist/lib/scoped-update-migration.js.map +0 -1
- package/dist/lib/scoped-update.d.ts.map +0 -1
- package/dist/lib/scoped-update.js.map +0 -1
- package/dist/lib/session-tokens-format.d.ts.map +0 -1
- package/dist/lib/session-tokens-format.js.map +0 -1
- package/dist/lib/session-tokens.d.ts.map +0 -1
- package/dist/lib/session-tokens.js.map +0 -1
- package/dist/lib/synthetic-config.d.ts.map +0 -1
- package/dist/lib/synthetic-config.js.map +0 -1
- package/dist/lib/synthetic.d.ts.map +0 -1
- package/dist/lib/synthetic.js.map +0 -1
- package/dist/lib/toast-format-grouped.d.ts.map +0 -1
- package/dist/lib/toast-format-grouped.js.map +0 -1
- package/dist/lib/token-buckets.d.ts.map +0 -1
- package/dist/lib/token-buckets.js.map +0 -1
- package/dist/lib/token-cost.d.ts.map +0 -1
- package/dist/lib/token-cost.js.map +0 -1
- package/dist/lib/tui-compact-format.d.ts.map +0 -1
- package/dist/lib/tui-compact-format.js.map +0 -1
- package/dist/lib/tui-panel-state.d.ts.map +0 -1
- package/dist/lib/tui-panel-state.js.map +0 -1
- package/dist/lib/tui-prompt-bar-format.d.ts.map +0 -1
- package/dist/lib/tui-prompt-bar-format.js.map +0 -1
- package/dist/lib/tui-sidebar-format.d.ts.map +0 -1
- package/dist/lib/tui-sidebar-format.js.map +0 -1
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/types.js.map +0 -1
- package/dist/lib/usage-ownership.d.ts.map +0 -1
- package/dist/lib/usage-ownership.js.map +0 -1
- package/dist/lib/version.d.ts.map +0 -1
- package/dist/lib/version.js.map +0 -1
- package/dist/lib/xai.d.ts.map +0 -1
- package/dist/lib/xai.js.map +0 -1
- package/dist/lib/zai-auth.d.ts.map +0 -1
- package/dist/lib/zai-auth.js.map +0 -1
- package/dist/lib/zai.d.ts.map +0 -1
- package/dist/lib/zai.js.map +0 -1
- package/dist/lib/zhipu-auth.d.ts.map +0 -1
- package/dist/lib/zhipu-auth.js.map +0 -1
- package/dist/lib/zhipu.d.ts.map +0 -1
- package/dist/lib/zhipu.js.map +0 -1
- package/dist/plugin.d.ts.map +0 -1
- package/dist/plugin.js.map +0 -1
- package/dist/providers/accounting-decimal.d.ts.map +0 -1
- package/dist/providers/accounting-decimal.js.map +0 -1
- package/dist/providers/alibaba-coding-plan.d.ts.map +0 -1
- package/dist/providers/alibaba-coding-plan.js.map +0 -1
- package/dist/providers/alibaba-token-plan.d.ts.map +0 -1
- package/dist/providers/alibaba-token-plan.js.map +0 -1
- package/dist/providers/anthropic.d.ts.map +0 -1
- package/dist/providers/anthropic.js.map +0 -1
- package/dist/providers/cache-policies.d.ts.map +0 -1
- package/dist/providers/cache-policies.js.map +0 -1
- package/dist/providers/chutes.d.ts.map +0 -1
- package/dist/providers/chutes.js.map +0 -1
- package/dist/providers/copilot.d.ts.map +0 -1
- package/dist/providers/copilot.js.map +0 -1
- package/dist/providers/cursor.d.ts.map +0 -1
- package/dist/providers/cursor.js.map +0 -1
- package/dist/providers/deepseek.d.ts.map +0 -1
- package/dist/providers/deepseek.js.map +0 -1
- package/dist/providers/glm-coding-plan-provider.d.ts.map +0 -1
- package/dist/providers/glm-coding-plan-provider.js.map +0 -1
- package/dist/providers/google-account-format.d.ts.map +0 -1
- package/dist/providers/google-account-format.js.map +0 -1
- package/dist/providers/google-agy.d.ts.map +0 -1
- package/dist/providers/google-agy.js.map +0 -1
- package/dist/providers/google-gemini-cli.d.ts.map +0 -1
- package/dist/providers/google-gemini-cli.js.map +0 -1
- package/dist/providers/kilo.d.ts.map +0 -1
- package/dist/providers/kilo.js.map +0 -1
- package/dist/providers/kimi-code.d.ts.map +0 -1
- package/dist/providers/kimi-code.js.map +0 -1
- package/dist/providers/mimo.d.ts.map +0 -1
- package/dist/providers/mimo.js.map +0 -1
- package/dist/providers/minimax-coding-plan.d.ts.map +0 -1
- package/dist/providers/minimax-coding-plan.js.map +0 -1
- package/dist/providers/nanogpt.d.ts.map +0 -1
- package/dist/providers/nanogpt.js.map +0 -1
- package/dist/providers/ollama-cloud.d.ts.map +0 -1
- package/dist/providers/ollama-cloud.js.map +0 -1
- package/dist/providers/openai.d.ts.map +0 -1
- package/dist/providers/openai.js.map +0 -1
- package/dist/providers/opencode-go.d.ts.map +0 -1
- package/dist/providers/opencode-go.js.map +0 -1
- package/dist/providers/opencode-zen.d.ts.map +0 -1
- package/dist/providers/opencode-zen.js.map +0 -1
- package/dist/providers/openrouter.d.ts.map +0 -1
- package/dist/providers/openrouter.js.map +0 -1
- package/dist/providers/quota-providers.d.ts.map +0 -1
- package/dist/providers/quota-providers.js.map +0 -1
- package/dist/providers/registry.d.ts.map +0 -1
- package/dist/providers/registry.js.map +0 -1
- package/dist/providers/result-helpers.d.ts.map +0 -1
- package/dist/providers/result-helpers.js.map +0 -1
- package/dist/providers/synthetic.d.ts.map +0 -1
- package/dist/providers/synthetic.js.map +0 -1
- package/dist/providers/xai.d.ts.map +0 -1
- package/dist/providers/xai.js.map +0 -1
- package/dist/providers/zai.d.ts.map +0 -1
- package/dist/providers/zai.js.map +0 -1
- package/dist/providers/zhipu.d.ts.map +0 -1
- package/dist/providers/zhipu.js.map +0 -1
- package/dist/rpc.d.ts.map +0 -1
- package/dist/rpc.js.map +0 -1
- package/dist/ui/assets/index-D9lFKhSN.js +0 -9
package/dist/lib/opencode-zen.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { providerFailureCategoryForHttpStatus } from "../contracts/provider-failure.js";
|
|
2
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
1
3
|
import { sanitizeDisplayText } from "./display-sanitize.js";
|
|
2
4
|
import { fetchWithTimeout } from "./http.js";
|
|
3
5
|
import { consoleBaseUrl, consoleHeaders, } from "./opencode-console-auth.js";
|
|
@@ -8,6 +10,20 @@ const SESSION_ERROR = "OpenCode Console session expired or invalid. Run `opencod
|
|
|
8
10
|
* one US dollar is 100,000,000 micro-cents (billing units).
|
|
9
11
|
*/
|
|
10
12
|
export const OPENCODE_ZEN_BILLING_UNITS_PER_DOLLAR = 100_000_000;
|
|
13
|
+
const routeGuard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
14
|
+
success: false,
|
|
15
|
+
error: "OpenCode Console request error 429",
|
|
16
|
+
failureCategory: providerFailureCategoryForHttpStatus(429),
|
|
17
|
+
retryAtMs,
|
|
18
|
+
}));
|
|
19
|
+
// Coalesce whole queries so a waiter cannot resend optional routes that settled
|
|
20
|
+
// while it was waiting for the required balance route.
|
|
21
|
+
const quotaQueryGuard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
22
|
+
success: false,
|
|
23
|
+
error: "OpenCode Console billing/status error 429",
|
|
24
|
+
failureCategory: providerFailureCategoryForHttpStatus(429),
|
|
25
|
+
retryAtMs,
|
|
26
|
+
}));
|
|
11
27
|
function asRecord(value) {
|
|
12
28
|
return value && typeof value === "object" && !Array.isArray(value)
|
|
13
29
|
? value
|
|
@@ -217,7 +233,26 @@ function sanitizeMessage(text, secrets = [], maxLength = 120) {
|
|
|
217
233
|
}
|
|
218
234
|
return (sanitized || "unknown").slice(0, maxLength);
|
|
219
235
|
}
|
|
220
|
-
|
|
236
|
+
/** One cooldown per workspace credential and route; other workspaces are unaffected. */
|
|
237
|
+
function fetchConsoleRoute(params) {
|
|
238
|
+
const { credential } = params;
|
|
239
|
+
const identity = JSON.stringify([
|
|
240
|
+
credential.accessToken,
|
|
241
|
+
credential.orgId ?? null,
|
|
242
|
+
consoleBaseUrl(credential),
|
|
243
|
+
params.path ?? params.route,
|
|
244
|
+
]);
|
|
245
|
+
return routeGuard(identity, () => {
|
|
246
|
+
params.onRequest?.();
|
|
247
|
+
return requestConsoleRoute(params);
|
|
248
|
+
}, params.timeoutMs, (retryAtMs) => ({
|
|
249
|
+
success: false,
|
|
250
|
+
error: `OpenCode Console ${params.route} error 429`,
|
|
251
|
+
failureCategory: providerFailureCategoryForHttpStatus(429),
|
|
252
|
+
retryAtMs,
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
async function requestConsoleRoute(params) {
|
|
221
256
|
const path = params.path ?? params.route;
|
|
222
257
|
try {
|
|
223
258
|
return await fetchWithTimeout(`${consoleBaseUrl(params.credential)}/api/${path}`, {
|
|
@@ -228,19 +263,23 @@ async function fetchConsoleRoute(params) {
|
|
|
228
263
|
},
|
|
229
264
|
timeoutMs: params.timeoutMs,
|
|
230
265
|
consume: async (response) => {
|
|
231
|
-
// Redirects and 401 mean the whole session is gone; a 403
|
|
232
|
-
//
|
|
266
|
+
// Redirects and 401 mean the whole session is gone; a 403 stays a
|
|
267
|
+
// per-route failure so optional routes can fall back gracefully, but it
|
|
268
|
+
// is still an authorization outcome at the HTTP boundary.
|
|
233
269
|
if ((response.status >= 300 && response.status < 400) || response.status === 401) {
|
|
234
|
-
return { success: false, error: SESSION_ERROR };
|
|
270
|
+
return { success: false, error: SESSION_ERROR, failureCategory: "credentials" };
|
|
235
271
|
}
|
|
236
272
|
if (!response.ok) {
|
|
273
|
+
const retryAtMs = retryAfterDeadline(response);
|
|
237
274
|
return {
|
|
238
275
|
success: false,
|
|
239
276
|
error: `OpenCode Console ${params.route} error ${response.status}`,
|
|
277
|
+
failureCategory: providerFailureCategoryForHttpStatus(response.status),
|
|
278
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
240
279
|
};
|
|
241
280
|
}
|
|
242
281
|
if (response.headers.get("content-type")?.includes("text/html")) {
|
|
243
|
-
return { success: false, error: SESSION_ERROR };
|
|
282
|
+
return { success: false, error: SESSION_ERROR, failureCategory: "credentials" };
|
|
244
283
|
}
|
|
245
284
|
const text = await response.text();
|
|
246
285
|
try {
|
|
@@ -252,6 +291,7 @@ async function fetchConsoleRoute(params) {
|
|
|
252
291
|
return {
|
|
253
292
|
success: false,
|
|
254
293
|
error: `Could not parse OpenCode Console ${params.route} response`,
|
|
294
|
+
failureCategory: "provider_api",
|
|
255
295
|
};
|
|
256
296
|
}
|
|
257
297
|
},
|
|
@@ -265,7 +305,11 @@ async function fetchConsoleRoute(params) {
|
|
|
265
305
|
accountId,
|
|
266
306
|
accountId && encodeURIComponent(accountId),
|
|
267
307
|
]);
|
|
268
|
-
return {
|
|
308
|
+
return {
|
|
309
|
+
success: false,
|
|
310
|
+
error: `OpenCode Console ${params.route} request failed: ${message}`,
|
|
311
|
+
failureCategory: "provider_api",
|
|
312
|
+
};
|
|
269
313
|
}
|
|
270
314
|
}
|
|
271
315
|
/** The member detail route key, or an error explaining why it cannot be fetched. */
|
|
@@ -275,6 +319,7 @@ function memberBudgetRequest(request) {
|
|
|
275
319
|
return {
|
|
276
320
|
success: false,
|
|
277
321
|
error: "OpenCode Console member budgets unavailable: the Console sign-in has no account id",
|
|
322
|
+
failureCategory: "discovery",
|
|
278
323
|
};
|
|
279
324
|
}
|
|
280
325
|
return fetchConsoleRoute({
|
|
@@ -284,14 +329,43 @@ function memberBudgetRequest(request) {
|
|
|
284
329
|
parse: (json) => parseMemberBudgets(json, accountId),
|
|
285
330
|
});
|
|
286
331
|
}
|
|
287
|
-
export
|
|
332
|
+
export function queryOpenCodeZenQuota(credential, options = {}) {
|
|
333
|
+
const timeoutMs = options.requestTimeoutMs ?? CONSOLE_TIMEOUT_MS;
|
|
334
|
+
const now = new Date();
|
|
335
|
+
const identity = JSON.stringify([
|
|
336
|
+
credential.accessToken,
|
|
337
|
+
credential.orgId ?? null,
|
|
338
|
+
consoleBaseUrl(credential),
|
|
339
|
+
credential.accountId?.trim() ?? null,
|
|
340
|
+
currentUtcMonth(now),
|
|
341
|
+
]);
|
|
342
|
+
return quotaQueryGuard(identity, () => queryOpenCodeZenQuotaOnce(credential, timeoutMs, now), timeoutMs);
|
|
343
|
+
}
|
|
344
|
+
async function queryOpenCodeZenQuotaOnce(credential, timeoutMs, now) {
|
|
288
345
|
const request = {
|
|
289
346
|
credential,
|
|
290
|
-
timeoutMs
|
|
347
|
+
timeoutMs,
|
|
291
348
|
};
|
|
292
|
-
|
|
349
|
+
// A fresh attempt sends every route concurrently. When billing/status did not
|
|
350
|
+
// start a request (an observed Retry-After block, or another in-flight
|
|
351
|
+
// request), settle it first: a cooldown result makes the optional routes
|
|
352
|
+
// pointless, so they are not sent.
|
|
353
|
+
let billingStarted = false;
|
|
354
|
+
const balancePending = fetchConsoleRoute({
|
|
355
|
+
...request,
|
|
356
|
+
route: "billing/status",
|
|
357
|
+
parse: parseBalance,
|
|
358
|
+
onRequest: () => {
|
|
359
|
+
billingStarted = true;
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
if (!billingStarted) {
|
|
363
|
+
const early = await balancePending;
|
|
364
|
+
if (!early.success && early.retryAtMs !== undefined)
|
|
365
|
+
return early;
|
|
366
|
+
}
|
|
293
367
|
const [balance, creditLimit, autoRecharge, member, monthlyUsage] = await Promise.all([
|
|
294
|
-
|
|
368
|
+
balancePending,
|
|
295
369
|
fetchConsoleRoute({ ...request, route: "billing/account", parse: parseCreditLimit }),
|
|
296
370
|
fetchConsoleRoute({ ...request, route: "billing/auto-recharge", parse: parseAutoRecharge }),
|
|
297
371
|
memberBudgetRequest(request),
|
|
@@ -303,7 +377,7 @@ export async function queryOpenCodeZenQuota(credential, options = {}) {
|
|
|
303
377
|
]);
|
|
304
378
|
const optional = [creditLimit, autoRecharge, member, monthlyUsage];
|
|
305
379
|
if ([balance, ...optional].some((result) => !result.success && result.error === SESSION_ERROR)) {
|
|
306
|
-
return { success: false, error: SESSION_ERROR };
|
|
380
|
+
return { success: false, error: SESSION_ERROR, failureCategory: "credentials" };
|
|
307
381
|
}
|
|
308
382
|
if (!balance.success)
|
|
309
383
|
return balance;
|
|
@@ -328,6 +402,17 @@ export async function queryOpenCodeZenQuota(credential, options = {}) {
|
|
|
328
402
|
memberBudgetsSkipped = true;
|
|
329
403
|
}
|
|
330
404
|
}
|
|
405
|
+
const optionalErrors = optional.flatMap((result) => result.success
|
|
406
|
+
? []
|
|
407
|
+
: [
|
|
408
|
+
{
|
|
409
|
+
message: result.error,
|
|
410
|
+
...(result.failureCategory !== undefined
|
|
411
|
+
? { failureCategory: result.failureCategory }
|
|
412
|
+
: {}),
|
|
413
|
+
...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
|
|
414
|
+
},
|
|
415
|
+
]);
|
|
331
416
|
return {
|
|
332
417
|
success: true,
|
|
333
418
|
data: {
|
|
@@ -342,7 +427,8 @@ export async function queryOpenCodeZenQuota(credential, options = {}) {
|
|
|
342
427
|
budgetSource,
|
|
343
428
|
memberBudgetsSkipped,
|
|
344
429
|
},
|
|
345
|
-
errors:
|
|
430
|
+
errors: optionalErrors.map((error) => error.message),
|
|
431
|
+
...(optionalErrors.length > 0 ? { optionalErrors } : {}),
|
|
346
432
|
};
|
|
347
433
|
}
|
|
348
434
|
//# sourceMappingURL=opencode-zen.js.map
|
package/dist/lib/provider-add.js
CHANGED
|
@@ -101,8 +101,11 @@ function sidecarManagedComments(index, definition) {
|
|
|
101
101
|
}
|
|
102
102
|
export async function planProviderAdd(options) {
|
|
103
103
|
const single = validateQuotaProviders([options.definition]);
|
|
104
|
-
if (!single.value) {
|
|
105
|
-
|
|
104
|
+
if (!single.value || single.value.length !== 1) {
|
|
105
|
+
const validationMessage = single.issues
|
|
106
|
+
.map((issue) => issue.key + ": " + issue.message)
|
|
107
|
+
.join("\n");
|
|
108
|
+
throw new Error(validationMessage || "definition is not a supported quota provider");
|
|
106
109
|
}
|
|
107
110
|
const definition = single.value[0];
|
|
108
111
|
const configDir = options.configDir ?? getOpencodeRuntimeDirs().configDir;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type QuotaProviderAutoSetup = "yes" | "usually" | "manual_env_config" | "needs_quick_setup";
|
|
2
|
-
export type QuotaProviderAuthentication = "opencode_auth_oauth_token" | "opencode_auth_api_key" | "companion_auth_oauth_token" | "local_cli_auth" | "github_oauth_or_pat" | "external_api_key" | "state_only";
|
|
1
|
+
export type QuotaProviderAutoSetup = "yes" | "usually" | "manual_env_config" | "needs_quick_setup" | "unavailable";
|
|
2
|
+
export type QuotaProviderAuthentication = "opencode_auth_oauth_token" | "opencode_auth_api_key" | "companion_auth_oauth_token" | "local_cli_auth" | "github_oauth_or_pat" | "external_api_key" | "state_only" | "unavailable";
|
|
3
3
|
export type QuotaProviderAuthFallback = "env_api_key" | "global_opencode_config";
|
|
4
|
-
export type QuotaProviderQuotaSource = "remote_api" | "local_estimation" | "local_runtime_accounting" | "local_cli_report";
|
|
4
|
+
export type QuotaProviderQuotaSource = "remote_api" | "local_estimation" | "local_runtime_accounting" | "local_cli_report" | "unavailable";
|
|
5
5
|
export interface QuotaProviderShapeSource {
|
|
6
6
|
recommendedReplacementId?: string;
|
|
7
7
|
autoSetup: QuotaProviderAutoSetup;
|
|
@@ -24,12 +24,22 @@ export declare const QUOTA_PROVIDER_REGISTRATION_SOURCE: readonly [{
|
|
|
24
24
|
readonly id: "anthropic";
|
|
25
25
|
readonly label: "Anthropic";
|
|
26
26
|
readonly runtimeIds: readonly ["anthropic"];
|
|
27
|
-
readonly synonyms: readonly [
|
|
27
|
+
readonly synonyms: readonly [];
|
|
28
|
+
readonly shape: {
|
|
29
|
+
readonly autoSetup: "unavailable";
|
|
30
|
+
readonly authentication: "unavailable";
|
|
31
|
+
readonly quota: "unavailable";
|
|
32
|
+
};
|
|
33
|
+
}, {
|
|
34
|
+
readonly id: "claude-agent";
|
|
35
|
+
readonly label: "Claude Agent";
|
|
36
|
+
readonly runtimeIds: readonly ["claude-agent", "claude-code"];
|
|
37
|
+
readonly synonyms: readonly ["claude-code", "claude"];
|
|
28
38
|
readonly shape: {
|
|
29
39
|
readonly autoSetup: "needs_quick_setup";
|
|
30
40
|
readonly authentication: "local_cli_auth";
|
|
31
41
|
readonly quota: "local_cli_report";
|
|
32
|
-
readonly quickSetupAnchor: "
|
|
42
|
+
readonly quickSetupAnchor: "claude-agent";
|
|
33
43
|
};
|
|
34
44
|
}, {
|
|
35
45
|
readonly id: "copilot";
|
|
@@ -95,10 +105,10 @@ export declare const QUOTA_PROVIDER_REGISTRATION_SOURCE: readonly [{
|
|
|
95
105
|
readonly synonyms: readonly ["alibaba"];
|
|
96
106
|
readonly liveLocalUsage: true;
|
|
97
107
|
readonly shape: {
|
|
98
|
-
readonly autoSetup: "
|
|
99
|
-
readonly authentication: "
|
|
100
|
-
readonly
|
|
101
|
-
readonly
|
|
108
|
+
readonly autoSetup: "needs_quick_setup";
|
|
109
|
+
readonly authentication: "local_cli_auth";
|
|
110
|
+
readonly quota: "local_cli_report";
|
|
111
|
+
readonly quickSetupAnchor: "alibaba-coding-plan";
|
|
102
112
|
};
|
|
103
113
|
}, {
|
|
104
114
|
readonly id: "alibaba-token-plan";
|
|
@@ -3,12 +3,23 @@ export const QUOTA_PROVIDER_REGISTRATION_SOURCE = [
|
|
|
3
3
|
id: "anthropic",
|
|
4
4
|
label: "Anthropic",
|
|
5
5
|
runtimeIds: ["anthropic"],
|
|
6
|
-
synonyms: [
|
|
6
|
+
synonyms: [],
|
|
7
|
+
shape: {
|
|
8
|
+
autoSetup: "unavailable",
|
|
9
|
+
authentication: "unavailable",
|
|
10
|
+
quota: "unavailable",
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
id: "claude-agent",
|
|
15
|
+
label: "Claude Agent",
|
|
16
|
+
runtimeIds: ["claude-agent", "claude-code"],
|
|
17
|
+
synonyms: ["claude-code", "claude"],
|
|
7
18
|
shape: {
|
|
8
19
|
autoSetup: "needs_quick_setup",
|
|
9
20
|
authentication: "local_cli_auth",
|
|
10
21
|
quota: "local_cli_report",
|
|
11
|
-
quickSetupAnchor: "
|
|
22
|
+
quickSetupAnchor: "claude-agent",
|
|
12
23
|
},
|
|
13
24
|
},
|
|
14
25
|
{
|
|
@@ -80,10 +91,10 @@ export const QUOTA_PROVIDER_REGISTRATION_SOURCE = [
|
|
|
80
91
|
synonyms: ["alibaba"],
|
|
81
92
|
liveLocalUsage: true,
|
|
82
93
|
shape: {
|
|
83
|
-
autoSetup: "
|
|
84
|
-
authentication: "
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
autoSetup: "needs_quick_setup",
|
|
95
|
+
authentication: "local_cli_auth",
|
|
96
|
+
quota: "local_cli_report",
|
|
97
|
+
quickSetupAnchor: "alibaba-coding-plan",
|
|
87
98
|
},
|
|
88
99
|
},
|
|
89
100
|
{
|
|
@@ -56,7 +56,7 @@ const DIALOG_TIME_WINDOWS = new Set([
|
|
|
56
56
|
/**
|
|
57
57
|
* The TUI dialog's label for a row: a time window's quota drops "quota" ("5h quota" is
|
|
58
58
|
* "5h", "Weekly quota" is "Weekly"), since the dialog's table heads that column "window".
|
|
59
|
-
* Other labels, such as "Month spend" or "Fable
|
|
59
|
+
* Other labels, such as "Month spend" or "Fable", stay whole.
|
|
60
60
|
*/
|
|
61
61
|
function getDialogMetricLabel(entry, metricLabel) {
|
|
62
62
|
const metric = entry.semantic?.metric;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
import type { FixedWindowProjectionEvidence, QuotaRunwayProjection } from "./entries.js";
|
|
2
2
|
export declare function isFixedWindowProjectionEvidence(value: unknown, resetTimeIso?: string): value is FixedWindowProjectionEvidence;
|
|
3
|
+
/**
|
|
4
|
+
* Builds fixed-window evidence for a provider window whose length is known and whose reset is
|
|
5
|
+
* observed. The start is inferred as `reset - duration`, which is only valid for windows that
|
|
6
|
+
* reset on a fixed cycle; callers must pass a duration that matches that window kind. Returns
|
|
7
|
+
* nothing unless the observation falls strictly inside the inferred window.
|
|
8
|
+
*/
|
|
9
|
+
export declare function buildFixedWindowEvidence(params: {
|
|
10
|
+
durationMs: number;
|
|
11
|
+
resetTimeIso?: string;
|
|
12
|
+
observedAtMs: number;
|
|
13
|
+
}): FixedWindowProjectionEvidence | undefined;
|
|
3
14
|
export declare function projectQuotaRunway(params: {
|
|
4
15
|
percentRemaining: number;
|
|
5
16
|
fixedWindow?: FixedWindowProjectionEvidence;
|
|
@@ -27,6 +27,31 @@ export function isFixedWindowProjectionEvidence(value, resetTimeIso) {
|
|
|
27
27
|
return false;
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Builds fixed-window evidence for a provider window whose length is known and whose reset is
|
|
32
|
+
* observed. The start is inferred as `reset - duration`, which is only valid for windows that
|
|
33
|
+
* reset on a fixed cycle; callers must pass a duration that matches that window kind. Returns
|
|
34
|
+
* nothing unless the observation falls strictly inside the inferred window.
|
|
35
|
+
*/
|
|
36
|
+
export function buildFixedWindowEvidence(params) {
|
|
37
|
+
if (!(Number.isFinite(params.durationMs) && params.durationMs > 0))
|
|
38
|
+
return undefined;
|
|
39
|
+
if (!Number.isFinite(params.observedAtMs))
|
|
40
|
+
return undefined;
|
|
41
|
+
const endsAt = parseIsoTimestamp(params.resetTimeIso);
|
|
42
|
+
if (endsAt === null)
|
|
43
|
+
return undefined;
|
|
44
|
+
const startedAt = endsAt - params.durationMs;
|
|
45
|
+
if (!(startedAt < params.observedAtMs && params.observedAtMs < endsAt))
|
|
46
|
+
return undefined;
|
|
47
|
+
return {
|
|
48
|
+
kind: "fixed_window",
|
|
49
|
+
startedAtIso: new Date(startedAt).toISOString(),
|
|
50
|
+
observedAtIso: new Date(params.observedAtMs).toISOString(),
|
|
51
|
+
endsAtIso: new Date(endsAt).toISOString(),
|
|
52
|
+
fullReset: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
30
55
|
export function projectQuotaRunway(params) {
|
|
31
56
|
const nowMs = params.nowMs ?? Date.now();
|
|
32
57
|
if (!Number.isFinite(params.percentRemaining) || !Number.isFinite(nowMs))
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ProviderFailureCategory } from "../contracts/provider-failure.js";
|
|
1
2
|
import type { QuotaToastEntry } from "./entries.js";
|
|
2
3
|
import type { RemoteApiQuotaProviderDefinition } from "./quota-providers.js";
|
|
3
4
|
export declare const QUOTA_PROVIDER_MAX_BODY_BYTES: number;
|
|
@@ -21,7 +22,9 @@ export type RemoteQuotaProviderResult = {
|
|
|
21
22
|
} | {
|
|
22
23
|
success: false;
|
|
23
24
|
error: string;
|
|
25
|
+
failureCategory?: ProviderFailureCategory;
|
|
26
|
+
retryAtMs?: number;
|
|
24
27
|
};
|
|
25
28
|
export declare function resolveQuotaProviderApiKey(source: RemoteApiQuotaProviderDefinition): Promise<QuotaProviderAuthResolution>;
|
|
26
|
-
export declare function fetchRemoteQuotaProvider(source: RemoteApiQuotaProviderDefinition, apiKey: string, requestTimeoutMs?: number): Promise<RemoteQuotaProviderResult>;
|
|
29
|
+
export declare function fetchRemoteQuotaProvider(source: RemoteApiQuotaProviderDefinition, apiKey: string | undefined, requestTimeoutMs?: number, fetcher?: typeof fetch): Promise<RemoteQuotaProviderResult>;
|
|
27
30
|
//# sourceMappingURL=quota-providers-remote.d.ts.map
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { createHmac, randomBytes } from "node:crypto";
|
|
2
|
+
import { providerFailureCategoryForHttpStatus, } from "../contracts/provider-failure.js";
|
|
1
3
|
import { createProviderApiKeyResolver, getApiKeyCheckedPaths, getGlobalOpencodeConfigCandidatePaths, } from "./api-key-resolver.js";
|
|
2
4
|
import { sanitizeSingleLineDisplayText } from "./display-sanitize.js";
|
|
3
5
|
import { getCredentialDatabasePaths, readAuthFile } from "./opencode-auth.js";
|
|
@@ -138,10 +140,10 @@ function parseQuotaV1(source, body) {
|
|
|
138
140
|
!hasOnlyKeys(body, ["version", "entries"]) ||
|
|
139
141
|
body.version !== "quota-v1" ||
|
|
140
142
|
!Array.isArray(body.entries)) {
|
|
141
|
-
return { success: false, error: "Invalid quota-v1 response" };
|
|
143
|
+
return { success: false, error: "Invalid quota-v1 response", failureCategory: "provider_api" };
|
|
142
144
|
}
|
|
143
145
|
if (body.entries.length < 1 || body.entries.length > QUOTA_PROVIDER_MAX_REMOTE_ROWS) {
|
|
144
|
-
return { success: false, error: "Invalid quota-v1 response" };
|
|
146
|
+
return { success: false, error: "Invalid quota-v1 response", failureCategory: "provider_api" };
|
|
145
147
|
}
|
|
146
148
|
const entries = [];
|
|
147
149
|
for (const raw of body.entries) {
|
|
@@ -157,7 +159,11 @@ function parseQuotaV1(source, body) {
|
|
|
157
159
|
"resetTimeIso",
|
|
158
160
|
"observedAtIso",
|
|
159
161
|
])) {
|
|
160
|
-
return {
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
error: "Invalid quota-v1 response",
|
|
165
|
+
failureCategory: "provider_api",
|
|
166
|
+
};
|
|
161
167
|
}
|
|
162
168
|
const name = boundedDisplayText(raw.name, 80);
|
|
163
169
|
const resultType = typeof raw.resultType === "string" && RESULT_TYPES.has(raw.resultType)
|
|
@@ -181,7 +187,11 @@ function parseQuotaV1(source, body) {
|
|
|
181
187
|
(raw.right !== undefined && right === null) ||
|
|
182
188
|
resetTimeIso === null ||
|
|
183
189
|
observedAtIso === null) {
|
|
184
|
-
return {
|
|
190
|
+
return {
|
|
191
|
+
success: false,
|
|
192
|
+
error: "Invalid quota-v1 response",
|
|
193
|
+
failureCategory: "provider_api",
|
|
194
|
+
};
|
|
185
195
|
}
|
|
186
196
|
const common = {
|
|
187
197
|
accounting: accountingMetadata(resultType, observedAtIso),
|
|
@@ -205,7 +215,7 @@ function parseQuotaV1(source, body) {
|
|
|
205
215
|
entries.push({ ...common, kind: "value", value });
|
|
206
216
|
continue;
|
|
207
217
|
}
|
|
208
|
-
return { success: false, error: "Invalid quota-v1 response" };
|
|
218
|
+
return { success: false, error: "Invalid quota-v1 response", failureCategory: "provider_api" };
|
|
209
219
|
}
|
|
210
220
|
return { success: true, entries };
|
|
211
221
|
}
|
|
@@ -495,6 +505,7 @@ function parseJsonV1(source, body) {
|
|
|
495
505
|
const invalid = (message) => ({
|
|
496
506
|
success: false,
|
|
497
507
|
error: `Invalid json-v1 response: ${message}`,
|
|
508
|
+
failureCategory: "provider_api",
|
|
498
509
|
});
|
|
499
510
|
if (!isJsonV1ResponseDepthValid(body)) {
|
|
500
511
|
return invalid(`nesting depth exceeded ${JSON_V1_MAX_RESPONSE_DEPTH}`);
|
|
@@ -617,18 +628,30 @@ function openRouterKeyLimitEntry(source, limit, percentRemaining, usedUsd) {
|
|
|
617
628
|
}
|
|
618
629
|
function parseOpenRouterKeyV1(source, body) {
|
|
619
630
|
if (!isRecord(body) || !isRecord(body.data)) {
|
|
620
|
-
return {
|
|
631
|
+
return {
|
|
632
|
+
success: false,
|
|
633
|
+
error: "Invalid openrouter-key-v1 response",
|
|
634
|
+
failureCategory: "provider_api",
|
|
635
|
+
};
|
|
621
636
|
}
|
|
622
637
|
const data = body.data;
|
|
623
638
|
const usage = data.usage;
|
|
624
639
|
if (typeof usage !== "number" || !Number.isFinite(usage) || usage < 0) {
|
|
625
|
-
return {
|
|
640
|
+
return {
|
|
641
|
+
success: false,
|
|
642
|
+
error: "Invalid openrouter-key-v1 response",
|
|
643
|
+
failureCategory: "provider_api",
|
|
644
|
+
};
|
|
626
645
|
}
|
|
627
646
|
const rawLimit = data.limit;
|
|
628
647
|
if (rawLimit !== null &&
|
|
629
648
|
rawLimit !== undefined &&
|
|
630
649
|
(typeof rawLimit !== "number" || !Number.isFinite(rawLimit) || rawLimit < 0)) {
|
|
631
|
-
return {
|
|
650
|
+
return {
|
|
651
|
+
success: false,
|
|
652
|
+
error: "Invalid openrouter-key-v1 response",
|
|
653
|
+
failureCategory: "provider_api",
|
|
654
|
+
};
|
|
632
655
|
}
|
|
633
656
|
// A key limit is a cap only when it is positive. Zero and null mean unlimited.
|
|
634
657
|
const limit = typeof rawLimit === "number" && rawLimit > 0 ? rawLimit : null;
|
|
@@ -636,15 +659,27 @@ function parseOpenRouterKeyV1(source, body) {
|
|
|
636
659
|
if (rawRemaining !== null &&
|
|
637
660
|
rawRemaining !== undefined &&
|
|
638
661
|
(typeof rawRemaining !== "number" || !Number.isFinite(rawRemaining))) {
|
|
639
|
-
return {
|
|
662
|
+
return {
|
|
663
|
+
success: false,
|
|
664
|
+
error: "Invalid openrouter-key-v1 response",
|
|
665
|
+
failureCategory: "provider_api",
|
|
666
|
+
};
|
|
640
667
|
}
|
|
641
668
|
// `limit_remaining` is capacity left on the key, never an account balance.
|
|
642
669
|
if (rawRemaining === null && limit !== null) {
|
|
643
|
-
return {
|
|
670
|
+
return {
|
|
671
|
+
success: false,
|
|
672
|
+
error: "Invalid openrouter-key-v1 response",
|
|
673
|
+
failureCategory: "provider_api",
|
|
674
|
+
};
|
|
644
675
|
}
|
|
645
676
|
const remaining = typeof rawRemaining === "number" ? rawRemaining : null;
|
|
646
677
|
if (limit !== null && remaining !== null && remaining > limit) {
|
|
647
|
-
return {
|
|
678
|
+
return {
|
|
679
|
+
success: false,
|
|
680
|
+
error: "Invalid openrouter-key-v1 response",
|
|
681
|
+
failureCategory: "provider_api",
|
|
682
|
+
};
|
|
648
683
|
}
|
|
649
684
|
const rawReset = data.limit_reset;
|
|
650
685
|
let reset;
|
|
@@ -652,7 +687,11 @@ function parseOpenRouterKeyV1(source, body) {
|
|
|
652
687
|
reset = null;
|
|
653
688
|
}
|
|
654
689
|
else if (typeof rawReset !== "string") {
|
|
655
|
-
return {
|
|
690
|
+
return {
|
|
691
|
+
success: false,
|
|
692
|
+
error: "Invalid openrouter-key-v1 response",
|
|
693
|
+
failureCategory: "provider_api",
|
|
694
|
+
};
|
|
656
695
|
}
|
|
657
696
|
else {
|
|
658
697
|
reset = OPENROUTER_LIMIT_RESETS.has(rawReset) ? rawReset : "unknown";
|
|
@@ -662,7 +701,11 @@ function parseOpenRouterKeyV1(source, body) {
|
|
|
662
701
|
if (value === null || value === undefined)
|
|
663
702
|
continue;
|
|
664
703
|
if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {
|
|
665
|
-
return {
|
|
704
|
+
return {
|
|
705
|
+
success: false,
|
|
706
|
+
error: "Invalid openrouter-key-v1 response",
|
|
707
|
+
failureCategory: "provider_api",
|
|
708
|
+
};
|
|
666
709
|
}
|
|
667
710
|
}
|
|
668
711
|
if (limit !== null) {
|
|
@@ -673,11 +716,19 @@ function parseOpenRouterKeyV1(source, body) {
|
|
|
673
716
|
const remainingValue = remaining !== null ? remaining : windowUsage !== null ? limit - windowUsage : null;
|
|
674
717
|
if (remainingValue !== null) {
|
|
675
718
|
if (remainingValue > limit) {
|
|
676
|
-
return {
|
|
719
|
+
return {
|
|
720
|
+
success: false,
|
|
721
|
+
error: "Invalid openrouter-key-v1 response",
|
|
722
|
+
failureCategory: "provider_api",
|
|
723
|
+
};
|
|
677
724
|
}
|
|
678
725
|
const percentRemaining = (remainingValue / limit) * 100;
|
|
679
726
|
if (!Number.isFinite(percentRemaining)) {
|
|
680
|
-
return {
|
|
727
|
+
return {
|
|
728
|
+
success: false,
|
|
729
|
+
error: "Invalid openrouter-key-v1 response",
|
|
730
|
+
failureCategory: "provider_api",
|
|
731
|
+
};
|
|
681
732
|
}
|
|
682
733
|
const usedUsd = limit - remainingValue;
|
|
683
734
|
return {
|
|
@@ -703,25 +754,81 @@ function parseOpenRouterKeyV1(source, body) {
|
|
|
703
754
|
entries: [openRouterSpendEntry(source, usage)],
|
|
704
755
|
};
|
|
705
756
|
}
|
|
706
|
-
export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs) {
|
|
757
|
+
export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs, fetcher = fetch) {
|
|
758
|
+
const identity = createHmac("sha256", remoteIdentityKey)
|
|
759
|
+
.update(JSON.stringify([source.url, apiKey ?? null]))
|
|
760
|
+
.digest("base64url");
|
|
761
|
+
const now = Date.now();
|
|
762
|
+
for (const [key, deadline] of remoteRetryDeadlines) {
|
|
763
|
+
if (deadline <= now)
|
|
764
|
+
remoteRetryDeadlines.delete(key);
|
|
765
|
+
}
|
|
766
|
+
const deadline = remoteRetryDeadlines.get(identity);
|
|
767
|
+
if (deadline !== undefined)
|
|
768
|
+
return {
|
|
769
|
+
success: false,
|
|
770
|
+
error: "HTTP 429",
|
|
771
|
+
failureCategory: "provider_api",
|
|
772
|
+
retryAtMs: deadline,
|
|
773
|
+
};
|
|
774
|
+
const previous = remoteInFlight.get(identity);
|
|
775
|
+
if (previous) {
|
|
776
|
+
if (previous.source === JSON.stringify(source) &&
|
|
777
|
+
previous.fetcher === fetcher &&
|
|
778
|
+
previous.timeout === requestTimeoutMs) {
|
|
779
|
+
return structuredClone(await previous.request);
|
|
780
|
+
}
|
|
781
|
+
await previous.request;
|
|
782
|
+
return fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs, fetcher);
|
|
783
|
+
}
|
|
784
|
+
const request = fetchRemoteQuotaProviderUncached(source, apiKey, requestTimeoutMs, fetcher);
|
|
785
|
+
const pending = { request, source: JSON.stringify(source), fetcher, timeout: requestTimeoutMs };
|
|
786
|
+
remoteInFlight.set(identity, pending);
|
|
787
|
+
try {
|
|
788
|
+
const result = await request;
|
|
789
|
+
if (!result.success && result.retryAtMs !== undefined && result.retryAtMs > Date.now()) {
|
|
790
|
+
remoteRetryDeadlines.set(identity, result.retryAtMs);
|
|
791
|
+
}
|
|
792
|
+
return result;
|
|
793
|
+
}
|
|
794
|
+
finally {
|
|
795
|
+
if (remoteInFlight.get(identity) === pending)
|
|
796
|
+
remoteInFlight.delete(identity);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
const remoteRetryDeadlines = new Map();
|
|
800
|
+
const remoteInFlight = new Map();
|
|
801
|
+
const remoteIdentityKey = randomBytes(32);
|
|
802
|
+
async function fetchRemoteQuotaProviderUncached(source, apiKey, requestTimeoutMs, fetcher = fetch) {
|
|
707
803
|
const timeoutMs = requestTimeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
708
804
|
const controller = new AbortController();
|
|
709
805
|
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
710
806
|
try {
|
|
711
|
-
const response = await
|
|
807
|
+
const response = await fetcher(source.url, {
|
|
712
808
|
method: "GET",
|
|
713
809
|
redirect: "manual",
|
|
714
810
|
signal: controller.signal,
|
|
715
811
|
headers: {
|
|
716
|
-
Authorization: `Bearer ${apiKey}
|
|
812
|
+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
717
813
|
Accept: "application/json",
|
|
718
814
|
},
|
|
719
815
|
});
|
|
720
816
|
if (response.redirected || (response.status >= 300 && response.status < 400)) {
|
|
721
|
-
return { success: false, error: "Redirect rejected" };
|
|
817
|
+
return { success: false, error: "Redirect rejected", failureCategory: "provider_api" };
|
|
722
818
|
}
|
|
723
819
|
if (!response.ok) {
|
|
724
|
-
|
|
820
|
+
const header = response.status === 429 ? response.headers.get("retry-after")?.trim() : undefined;
|
|
821
|
+
const retryAtMs = header && /^\d+$/.test(header)
|
|
822
|
+
? Date.now() + Number(header) * 1000
|
|
823
|
+
: header && /^[A-Za-z]{3}, \d{2} [A-Za-z]{3} \d{4} \d{2}:\d{2}:\d{2} GMT$/.test(header)
|
|
824
|
+
? Date.parse(header)
|
|
825
|
+
: NaN;
|
|
826
|
+
return {
|
|
827
|
+
success: false,
|
|
828
|
+
error: `HTTP ${response.status}`,
|
|
829
|
+
failureCategory: providerFailureCategoryForHttpStatus(response.status),
|
|
830
|
+
...(Number.isSafeInteger(retryAtMs) && retryAtMs > Date.now() ? { retryAtMs } : {}),
|
|
831
|
+
};
|
|
725
832
|
}
|
|
726
833
|
const body = await readBoundedJson(response);
|
|
727
834
|
switch (source.format) {
|
|
@@ -734,10 +841,14 @@ export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs)
|
|
|
734
841
|
}
|
|
735
842
|
}
|
|
736
843
|
catch (error) {
|
|
844
|
+
if (error && typeof error === "object" && "code" in error && error.code === "unsafe-endpoint") {
|
|
845
|
+
return { success: false, error: "Unsafe provider endpoint", failureCategory: "provider_api" };
|
|
846
|
+
}
|
|
737
847
|
if (controller.signal.aborted || (error instanceof Error && error.name === "AbortError")) {
|
|
738
848
|
return {
|
|
739
849
|
success: false,
|
|
740
850
|
error: `Request timeout after ${Math.round(timeoutMs / 1000)}s`,
|
|
851
|
+
failureCategory: "provider_api",
|
|
741
852
|
};
|
|
742
853
|
}
|
|
743
854
|
if (error instanceof Error &&
|
|
@@ -746,9 +857,13 @@ export async function fetchRemoteQuotaProvider(source, apiKey, requestTimeoutMs)
|
|
|
746
857
|
"Expected a JSON response",
|
|
747
858
|
"Invalid JSON response",
|
|
748
859
|
].includes(error.message)) {
|
|
749
|
-
return { success: false, error: error.message };
|
|
860
|
+
return { success: false, error: error.message, failureCategory: "provider_api" };
|
|
750
861
|
}
|
|
751
|
-
return {
|
|
862
|
+
return {
|
|
863
|
+
success: false,
|
|
864
|
+
error: "Failed to read accounting data",
|
|
865
|
+
failureCategory: "provider_api",
|
|
866
|
+
};
|
|
752
867
|
}
|
|
753
868
|
finally {
|
|
754
869
|
clearTimeout(timeoutId);
|