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
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { providerFailureCategoryForHttpStatus, } from "../contracts/provider-failure.js";
|
|
1
2
|
import { readGlobalProviderConfigString } from "./api-key-resolver.js";
|
|
3
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
2
4
|
import { clearGeminiCliCompanionCacheForTests as clearGeminiCliCompanionResolutionCacheForTests, inspectGeminiCliCompanionPresence, resolveGeminiCliClientCredentials, } from "./google-gemini-cli-companion.js";
|
|
3
5
|
import { getCachedAccessToken, makeAccountCacheKey, setCachedAccessToken, } from "./google-token-cache.js";
|
|
4
|
-
import { fetchWithTimeout } from "./http.js";
|
|
6
|
+
import { fetchWithTimeout, RequestTimeoutError } from "./http.js";
|
|
5
7
|
import { mapWithConcurrency } from "./map-with-concurrency.js";
|
|
6
8
|
import { readAuthFileCached } from "./opencode-auth.js";
|
|
7
9
|
import { composeResolvedAuthIdentities, deriveResolvedAuthIdentity, } from "./resolved-auth-identity.js";
|
|
@@ -214,20 +216,36 @@ async function refreshAccessToken(params) {
|
|
|
214
216
|
timeoutMs: params.timeoutMs ?? GEMINI_TOKEN_TIMEOUT_MS,
|
|
215
217
|
consume: async (response, timeoutSignal) => {
|
|
216
218
|
if (!response.ok) {
|
|
219
|
+
const retryAtMs = retryAfterDeadline(response);
|
|
220
|
+
const retry = retryAtMs !== undefined ? { retryAtMs } : {};
|
|
217
221
|
try {
|
|
218
222
|
const errorData = (await response.json());
|
|
219
223
|
if (errorData.error === "invalid_grant") {
|
|
220
|
-
return { error: "Token revoked" };
|
|
224
|
+
return { error: "Token revoked", failureCategory: "credentials" };
|
|
221
225
|
}
|
|
222
|
-
return {
|
|
226
|
+
return {
|
|
227
|
+
error: errorData.error_description || `HTTP ${response.status}`,
|
|
228
|
+
failureCategory: providerFailureCategoryForHttpStatus(response.status),
|
|
229
|
+
...retry,
|
|
230
|
+
};
|
|
223
231
|
}
|
|
224
232
|
catch (error) {
|
|
225
233
|
if (timeoutSignal.aborted)
|
|
226
234
|
throw error;
|
|
227
|
-
return {
|
|
235
|
+
return {
|
|
236
|
+
error: `HTTP ${response.status}`,
|
|
237
|
+
failureCategory: providerFailureCategoryForHttpStatus(response.status),
|
|
238
|
+
...retry,
|
|
239
|
+
};
|
|
228
240
|
}
|
|
229
241
|
}
|
|
230
242
|
const data = (await response.json());
|
|
243
|
+
if (typeof data.access_token !== "string" ||
|
|
244
|
+
data.access_token.length === 0 ||
|
|
245
|
+
typeof data.expires_in !== "number" ||
|
|
246
|
+
!Number.isFinite(data.expires_in)) {
|
|
247
|
+
throw new Error("Token refresh response returned an unexpected response shape");
|
|
248
|
+
}
|
|
231
249
|
return {
|
|
232
250
|
accessToken: data.access_token,
|
|
233
251
|
expiresIn: data.expires_in,
|
|
@@ -236,10 +254,17 @@ async function refreshAccessToken(params) {
|
|
|
236
254
|
});
|
|
237
255
|
}
|
|
238
256
|
catch (err) {
|
|
257
|
+
if (err instanceof RequestTimeoutError) {
|
|
258
|
+
return {
|
|
259
|
+
error: "Token refresh timeout",
|
|
260
|
+
failureCategory: "provider_api",
|
|
261
|
+
...(err.retryAtMs !== undefined ? { retryAtMs: err.retryAtMs } : {}),
|
|
262
|
+
};
|
|
263
|
+
}
|
|
239
264
|
if (err instanceof Error && err.message.includes("timeout")) {
|
|
240
|
-
return { error: "Token refresh timeout" };
|
|
265
|
+
return { error: "Token refresh timeout", failureCategory: "provider_api" };
|
|
241
266
|
}
|
|
242
|
-
return { error: "Token refresh failed" };
|
|
267
|
+
return { error: "Token refresh failed", failureCategory: "provider_api" };
|
|
243
268
|
}
|
|
244
269
|
}
|
|
245
270
|
async function refreshGeminiCliAccessTokenWithCache(params) {
|
|
@@ -258,14 +283,26 @@ async function refreshGeminiCliAccessTokenWithCache(params) {
|
|
|
258
283
|
return { accessToken: params.account.accessToken };
|
|
259
284
|
}
|
|
260
285
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
286
|
+
// Guarded per refresh token: the token endpoint's limit is independent of quota reads.
|
|
287
|
+
const guarded = await tokenGuard(params.account.refreshToken, async () => {
|
|
288
|
+
const result = await refreshAccessToken({
|
|
289
|
+
refreshToken: params.account.refreshToken,
|
|
290
|
+
clientId: params.credentials.clientId,
|
|
291
|
+
clientSecret: params.credentials.clientSecret,
|
|
292
|
+
timeoutMs: params.timeoutMs,
|
|
293
|
+
});
|
|
294
|
+
return "error" in result
|
|
295
|
+
? { success: false, ...result }
|
|
296
|
+
: { success: true, ...result };
|
|
297
|
+
}, params.timeoutMs);
|
|
298
|
+
if (!guarded.success) {
|
|
299
|
+
return {
|
|
300
|
+
error: guarded.error,
|
|
301
|
+
failureCategory: guarded.failureCategory,
|
|
302
|
+
...(guarded.retryAtMs !== undefined ? { retryAtMs: guarded.retryAtMs } : {}),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
const refreshed = { accessToken: guarded.accessToken, expiresIn: guarded.expiresIn };
|
|
269
306
|
await setCachedAccessToken({
|
|
270
307
|
key,
|
|
271
308
|
entry: {
|
|
@@ -275,6 +312,29 @@ async function refreshGeminiCliAccessTokenWithCache(params) {
|
|
|
275
312
|
});
|
|
276
313
|
return { accessToken: refreshed.accessToken };
|
|
277
314
|
}
|
|
315
|
+
class GeminiCliQuotaRequestError extends Error {
|
|
316
|
+
failureCategory;
|
|
317
|
+
retryAtMs;
|
|
318
|
+
constructor(message, failureCategory, retryAtMs) {
|
|
319
|
+
super(message);
|
|
320
|
+
this.name = "GeminiCliQuotaRequestError";
|
|
321
|
+
this.failureCategory = failureCategory;
|
|
322
|
+
if (retryAtMs !== undefined)
|
|
323
|
+
this.retryAtMs = retryAtMs;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const tokenGuard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
327
|
+
success: false,
|
|
328
|
+
error: "Token refresh failed: HTTP 429",
|
|
329
|
+
failureCategory: "provider_api",
|
|
330
|
+
retryAtMs,
|
|
331
|
+
}));
|
|
332
|
+
const accountGuard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
333
|
+
success: false,
|
|
334
|
+
error: "Gemini CLI quota API error: 429",
|
|
335
|
+
failureCategory: "provider_api",
|
|
336
|
+
retryAtMs,
|
|
337
|
+
}));
|
|
278
338
|
async function retrieveGeminiCliQuota(accessToken, projectId, timeoutMs = GEMINI_QUOTA_TIMEOUT_MS) {
|
|
279
339
|
return await fetchWithTimeout(GEMINI_QUOTA_API_URL, {
|
|
280
340
|
request: {
|
|
@@ -289,10 +349,10 @@ async function retrieveGeminiCliQuota(accessToken, projectId, timeoutMs = GEMINI
|
|
|
289
349
|
timeoutMs,
|
|
290
350
|
consume: async (response) => {
|
|
291
351
|
if (!response.ok) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
352
|
+
const failureCategory = providerFailureCategoryForHttpStatus(response.status);
|
|
353
|
+
throw new GeminiCliQuotaRequestError(response.status === 401 || response.status === 403
|
|
354
|
+
? `Gemini CLI quota auth error: ${response.status}`
|
|
355
|
+
: `Gemini CLI quota API error: ${response.status}`, failureCategory, retryAfterDeadline(response));
|
|
296
356
|
}
|
|
297
357
|
return (await response.json());
|
|
298
358
|
},
|
|
@@ -383,7 +443,32 @@ function mapQuotaBuckets(buckets, account) {
|
|
|
383
443
|
});
|
|
384
444
|
return aggregateGeminiCliQualityTiers(normalizedBuckets);
|
|
385
445
|
}
|
|
446
|
+
/** Cooldowns are per refresh token + project; a concurrent identical call shares one request. */
|
|
386
447
|
async function fetchAccountQuota(params) {
|
|
448
|
+
const accountEmail = params.account.email || params.account.sourceKey;
|
|
449
|
+
const { tokenRetryAtMs, ...result } = await accountGuard(`${params.account.refreshToken}\n${params.account.projectId}`, () => fetchAccountQuotaUncached(params), params.timeoutMs, (retryAtMs) => ({
|
|
450
|
+
success: false,
|
|
451
|
+
error: "Gemini CLI quota API error: 429",
|
|
452
|
+
failureCategory: "provider_api",
|
|
453
|
+
accountEmail,
|
|
454
|
+
retryAtMs,
|
|
455
|
+
}));
|
|
456
|
+
const buckets = result.buckets?.map((bucket) => {
|
|
457
|
+
const projected = { ...bucket, sourceKey: params.account.sourceKey };
|
|
458
|
+
if (params.account.email)
|
|
459
|
+
projected.accountEmail = params.account.email;
|
|
460
|
+
else
|
|
461
|
+
delete projected.accountEmail;
|
|
462
|
+
return projected;
|
|
463
|
+
});
|
|
464
|
+
return {
|
|
465
|
+
...result,
|
|
466
|
+
accountEmail,
|
|
467
|
+
...(buckets ? { buckets } : {}),
|
|
468
|
+
...(tokenRetryAtMs !== undefined ? { retryAtMs: tokenRetryAtMs } : {}),
|
|
469
|
+
};
|
|
470
|
+
}
|
|
471
|
+
async function fetchAccountQuotaUncached(params) {
|
|
387
472
|
const accountEmail = params.account.email || params.account.sourceKey;
|
|
388
473
|
try {
|
|
389
474
|
const tokenResult = await refreshGeminiCliAccessTokenWithCache({
|
|
@@ -392,14 +477,20 @@ async function fetchAccountQuota(params) {
|
|
|
392
477
|
timeoutMs: params.timeoutMs,
|
|
393
478
|
});
|
|
394
479
|
if ("error" in tokenResult) {
|
|
395
|
-
return {
|
|
480
|
+
return {
|
|
481
|
+
success: false,
|
|
482
|
+
error: tokenResult.error,
|
|
483
|
+
failureCategory: tokenResult.failureCategory,
|
|
484
|
+
accountEmail,
|
|
485
|
+
...(tokenResult.retryAtMs !== undefined ? { tokenRetryAtMs: tokenResult.retryAtMs } : {}),
|
|
486
|
+
};
|
|
396
487
|
}
|
|
397
488
|
let quota;
|
|
398
489
|
try {
|
|
399
490
|
quota = await retrieveGeminiCliQuota(tokenResult.accessToken, params.account.projectId, params.timeoutMs);
|
|
400
491
|
}
|
|
401
492
|
catch (err) {
|
|
402
|
-
if (err instanceof
|
|
493
|
+
if (err instanceof GeminiCliQuotaRequestError && err.failureCategory === "credentials") {
|
|
403
494
|
const retryToken = await refreshGeminiCliAccessTokenWithCache({
|
|
404
495
|
account: params.account,
|
|
405
496
|
credentials: params.credentials,
|
|
@@ -407,7 +498,13 @@ async function fetchAccountQuota(params) {
|
|
|
407
498
|
timeoutMs: params.timeoutMs,
|
|
408
499
|
});
|
|
409
500
|
if ("error" in retryToken) {
|
|
410
|
-
return {
|
|
501
|
+
return {
|
|
502
|
+
success: false,
|
|
503
|
+
error: retryToken.error,
|
|
504
|
+
failureCategory: retryToken.failureCategory,
|
|
505
|
+
accountEmail,
|
|
506
|
+
...(retryToken.retryAtMs !== undefined ? { tokenRetryAtMs: retryToken.retryAtMs } : {}),
|
|
507
|
+
};
|
|
411
508
|
}
|
|
412
509
|
quota = await retrieveGeminiCliQuota(retryToken.accessToken, params.account.projectId, params.timeoutMs);
|
|
413
510
|
}
|
|
@@ -423,12 +520,24 @@ async function fetchAccountQuota(params) {
|
|
|
423
520
|
}
|
|
424
521
|
catch (err) {
|
|
425
522
|
if (err instanceof Error && err.message.includes("timeout")) {
|
|
426
|
-
return {
|
|
523
|
+
return {
|
|
524
|
+
success: false,
|
|
525
|
+
error: "API timeout",
|
|
526
|
+
failureCategory: "provider_api",
|
|
527
|
+
accountEmail,
|
|
528
|
+
...(err instanceof RequestTimeoutError && err.retryAtMs !== undefined
|
|
529
|
+
? { retryAtMs: err.retryAtMs }
|
|
530
|
+
: {}),
|
|
531
|
+
};
|
|
427
532
|
}
|
|
428
533
|
return {
|
|
429
534
|
success: false,
|
|
430
535
|
error: err instanceof Error ? err.message : String(err),
|
|
536
|
+
failureCategory: err instanceof GeminiCliQuotaRequestError ? err.failureCategory : "provider_api",
|
|
431
537
|
accountEmail,
|
|
538
|
+
...(err instanceof GeminiCliQuotaRequestError && err.retryAtMs !== undefined
|
|
539
|
+
? { retryAtMs: err.retryAtMs }
|
|
540
|
+
: {}),
|
|
432
541
|
};
|
|
433
542
|
}
|
|
434
543
|
}
|
|
@@ -450,6 +559,7 @@ export async function queryGeminiCliQuota(options = {}) {
|
|
|
450
559
|
return {
|
|
451
560
|
success: false,
|
|
452
561
|
error: getCompanionQuotaError(credentials.state),
|
|
562
|
+
failureCategory: "local",
|
|
453
563
|
};
|
|
454
564
|
}
|
|
455
565
|
const results = await mapWithConcurrency(accounts, GEMINI_ACCOUNTS_CONCURRENCY, async (account) => fetchAccountQuota({ account, credentials, timeoutMs: options.requestTimeoutMs }));
|
|
@@ -460,7 +570,14 @@ export async function queryGeminiCliQuota(options = {}) {
|
|
|
460
570
|
allBuckets.push(...result.buckets);
|
|
461
571
|
}
|
|
462
572
|
else if (!result.success && result.error && result.accountEmail) {
|
|
463
|
-
errors.push({
|
|
573
|
+
errors.push({
|
|
574
|
+
email: result.accountEmail,
|
|
575
|
+
error: result.error,
|
|
576
|
+
...(result.failureCategory !== undefined
|
|
577
|
+
? { failureCategory: result.failureCategory }
|
|
578
|
+
: {}),
|
|
579
|
+
...(result.retryAtMs !== undefined ? { retryAtMs: result.retryAtMs } : {}),
|
|
580
|
+
});
|
|
464
581
|
}
|
|
465
582
|
}
|
|
466
583
|
if (allBuckets.length === 0 && errors.length === 0) {
|
package/dist/lib/http.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* HTTP utilities for provider API calls.
|
|
3
3
|
*/
|
|
4
|
+
export declare class RequestTimeoutError extends Error {
|
|
5
|
+
readonly retryAtMs?: number;
|
|
6
|
+
constructor(message: string, retryAtMs?: number);
|
|
7
|
+
}
|
|
4
8
|
export type FetchWithTimeoutOptions<T> = {
|
|
5
9
|
request: Omit<RequestInit, "signal">;
|
|
6
10
|
timeoutMs?: number;
|
package/dist/lib/http.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* HTTP utilities for provider API calls.
|
|
3
3
|
*/
|
|
4
|
+
import { retryAfterDeadline } from "./api-key-retry-after.js";
|
|
4
5
|
import { REQUEST_TIMEOUT_MS } from "./types.js";
|
|
6
|
+
export class RequestTimeoutError extends Error {
|
|
7
|
+
retryAtMs;
|
|
8
|
+
constructor(message, retryAtMs) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "RequestTimeoutError";
|
|
11
|
+
if (retryAtMs !== undefined)
|
|
12
|
+
this.retryAtMs = retryAtMs;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
5
15
|
/**
|
|
6
16
|
* Fetch and consume a response within one timeout.
|
|
7
17
|
*
|
|
@@ -14,13 +24,16 @@ export async function fetchWithTimeout(url, options) {
|
|
|
14
24
|
const timeoutMs = options.timeoutMs ?? REQUEST_TIMEOUT_MS;
|
|
15
25
|
const controller = new AbortController();
|
|
16
26
|
let timedOut = false;
|
|
27
|
+
let observedRetryAtMs;
|
|
28
|
+
let timeoutError;
|
|
17
29
|
const timeoutErrorMessage = `Request timeout after ${Math.round(timeoutMs / 1000)}s`;
|
|
18
30
|
let timeoutId;
|
|
19
31
|
const timeout = new Promise((_resolve, reject) => {
|
|
20
32
|
timeoutId = setTimeout(() => {
|
|
21
33
|
timedOut = true;
|
|
22
34
|
controller.abort();
|
|
23
|
-
|
|
35
|
+
timeoutError = new RequestTimeoutError(timeoutErrorMessage, observedRetryAtMs);
|
|
36
|
+
reject(timeoutError);
|
|
24
37
|
}, timeoutMs);
|
|
25
38
|
});
|
|
26
39
|
try {
|
|
@@ -30,13 +43,14 @@ export async function fetchWithTimeout(url, options) {
|
|
|
30
43
|
...options.request,
|
|
31
44
|
signal: controller.signal,
|
|
32
45
|
});
|
|
46
|
+
observedRetryAtMs = retryAfterDeadline(response);
|
|
33
47
|
return await options.consume(response, controller.signal);
|
|
34
48
|
})();
|
|
35
49
|
return await Promise.race([transaction, timeout]);
|
|
36
50
|
}
|
|
37
51
|
catch (err) {
|
|
38
52
|
if (timedOut) {
|
|
39
|
-
throw new
|
|
53
|
+
throw timeoutError ?? new RequestTimeoutError(timeoutErrorMessage, observedRetryAtMs);
|
|
40
54
|
}
|
|
41
55
|
throw err;
|
|
42
56
|
}
|
|
@@ -2,14 +2,15 @@ import { existsSync } from "fs";
|
|
|
2
2
|
import { readFile } from "fs/promises";
|
|
3
3
|
import { basename, dirname, join, resolve } from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
|
-
import { getGuiConfigPath, getGuiConfigSiblingJsonPath, loadConfig } from "./config.js";
|
|
5
|
+
import { createLoadConfigMeta, getGuiConfigPath, getGuiConfigSiblingJsonPath, loadConfig, } from "./config.js";
|
|
6
6
|
import { dedupeNonEmptyStrings, findGitWorktreeRoot, getPluginSpecFromEntry, resolveEditableConfigPath, } from "./config-file-utils.js";
|
|
7
7
|
import { writeConfiguredJsonAtomic } from "./config-write-target.js";
|
|
8
|
+
import { getDashboardEnabledSetting, hasInvalidDashboardWebConfig, resolveDashboardWebEnabled, } from "./dashboard-web-policy.js";
|
|
8
9
|
import { assertGuiConfigTargetIsIndependent } from "./gui-config-target.js";
|
|
9
10
|
import { parseJsonOrJsonc } from "./jsonc.js";
|
|
10
11
|
import { applyConfigDocumentEdit, planConfigDocumentEdit, validateConfigDocumentEdit, } from "./opencode-config-editor.js";
|
|
11
12
|
import { getOpencodeRuntimeDirs } from "./opencode-runtime-paths.js";
|
|
12
|
-
import { detectOpenCodeMajor } from "./opencode-version.js";
|
|
13
|
+
import { detectOpenCodeMajor, detectOpenCodeVersion } from "./opencode-version.js";
|
|
13
14
|
import { getQuotaProviderDisplayLabel, normalizeQuotaProviderId, QUOTA_PROVIDER_SHAPES, } from "./provider-metadata.js";
|
|
14
15
|
import { getQuotaFormatStyleLabel, isQuotaFormatStyle, resolveQuotaFormatStyle, } from "./quota-format-style.js";
|
|
15
16
|
import { QUOTA_PROVIDERS_AGGREGATE_ID } from "./quota-providers.js";
|
|
@@ -652,9 +653,11 @@ function buildPlanSummary(plan) {
|
|
|
652
653
|
}
|
|
653
654
|
export function getInstallerProviderPromptOptions() {
|
|
654
655
|
return QUOTA_PROVIDER_SHAPES.map((shape) => ({
|
|
655
|
-
label: shape.autoSetup === "
|
|
656
|
-
? `${getQuotaProviderDisplayLabel(shape.id)} (
|
|
657
|
-
:
|
|
656
|
+
label: shape.autoSetup === "unavailable"
|
|
657
|
+
? `${getQuotaProviderDisplayLabel(shape.id)} (quota unavailable)`
|
|
658
|
+
: shape.autoSetup === "needs_quick_setup"
|
|
659
|
+
? `${getQuotaProviderDisplayLabel(shape.id)} (quick setup)`
|
|
660
|
+
: getQuotaProviderDisplayLabel(shape.id),
|
|
658
661
|
value: shape.id,
|
|
659
662
|
}));
|
|
660
663
|
}
|
|
@@ -1020,7 +1023,8 @@ export async function runInitInstaller(params) {
|
|
|
1020
1023
|
? "Web"
|
|
1021
1024
|
: "TUI and Web";
|
|
1022
1025
|
const configuredPaths = [...result.writtenPaths, ...result.unchangedPaths];
|
|
1023
|
-
const
|
|
1026
|
+
const configMeta = createLoadConfigMeta();
|
|
1027
|
+
const config = await loadConfig(undefined, configMeta, {
|
|
1024
1028
|
configRootDir: resolveInitInstallerBaseDir({ scope: "project", cwd: params?.cwd }),
|
|
1025
1029
|
globalConfigDir: resolveInitInstallerBaseDir({
|
|
1026
1030
|
scope: "global",
|
|
@@ -1028,13 +1032,32 @@ export async function runInitInstaller(params) {
|
|
|
1028
1032
|
homeDir: params?.homeDir,
|
|
1029
1033
|
}),
|
|
1030
1034
|
});
|
|
1035
|
+
const explicitDashboardEnabled = getDashboardEnabledSetting(config, configMeta);
|
|
1036
|
+
const invalidDashboardConfig = hasInvalidDashboardWebConfig(configMeta);
|
|
1037
|
+
// The version probe is bounded and only needed when the canonical key is
|
|
1038
|
+
// absent; explicit configuration and malformed files decide on their own.
|
|
1039
|
+
const hostVersion = explicitDashboardEnabled === undefined && !invalidDashboardConfig
|
|
1040
|
+
? await detectOpenCodeVersion()
|
|
1041
|
+
: undefined;
|
|
1042
|
+
const webEnabled = resolveDashboardWebEnabled({
|
|
1043
|
+
...(explicitDashboardEnabled !== undefined
|
|
1044
|
+
? { explicitEnabled: explicitDashboardEnabled }
|
|
1045
|
+
: {}),
|
|
1046
|
+
...(hostVersion !== undefined ? { hostVersion } : {}),
|
|
1047
|
+
invalidConfig: invalidDashboardConfig,
|
|
1048
|
+
});
|
|
1031
1049
|
const dashboardUrl = `http://localhost:${config.dashboard?.port ?? DEFAULT_DASHBOARD_PORT}/quota`;
|
|
1050
|
+
const dashboardOutro = webEnabled
|
|
1051
|
+
? `Restart OpenCode, then open ${dashboardUrl}.`
|
|
1052
|
+
: explicitDashboardEnabled === false
|
|
1053
|
+
? `Web dashboard access is disabled in the canonical config. Set "dashboard": { "enabled": true }, then restart OpenCode and open ${dashboardUrl}.`
|
|
1054
|
+
: `Web dashboard access is off. Add "dashboard": { "enabled": true } to the canonical config, then restart OpenCode and open ${dashboardUrl}.`;
|
|
1032
1055
|
prompts.outro([
|
|
1033
1056
|
"OpenCode Quota setup complete.",
|
|
1034
1057
|
`Interfaces: ${interfaceLabel}`,
|
|
1035
1058
|
"Configured paths:",
|
|
1036
1059
|
...configuredPaths.map((path) => `- ${path}`),
|
|
1037
|
-
|
|
1060
|
+
dashboardOutro,
|
|
1038
1061
|
`If OpenCode Quota helps, please consider a star: ${GITHUB_REPO_URL}`,
|
|
1039
1062
|
].join("\n"));
|
|
1040
1063
|
return 0;
|
package/dist/lib/kilo.js
CHANGED
|
@@ -5,12 +5,24 @@
|
|
|
5
5
|
* subscription-state endpoint, with a balance-only fallback for accounts
|
|
6
6
|
* without an active Kilo Pass.
|
|
7
7
|
*/
|
|
8
|
+
import { providerFailureCategoryForHttpStatus } from "../contracts/provider-failure.js";
|
|
9
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
8
10
|
import { sanitizeSingleLineDisplayText } from "./display-sanitize.js";
|
|
9
11
|
import { fetchWithTimeout } from "./http.js";
|
|
10
12
|
import { resolveKiloApiKey } from "./kilo-config.js";
|
|
11
13
|
const KILO_PASS_STATE_ENDPOINT = "https://app.kilo.ai/api/trpc/kiloPass.getState";
|
|
12
14
|
const KILO_BALANCE_ENDPOINT = "https://api.kilo.ai/api/profile/balance";
|
|
13
15
|
const MAX_RESPONSE_BYTES = 64 * 1024;
|
|
16
|
+
const kiloBlocked = (retryAtMs) => ({
|
|
17
|
+
success: false,
|
|
18
|
+
error: "Kilo Gateway API error 429",
|
|
19
|
+
failureCategory: "provider_api",
|
|
20
|
+
retryAtMs,
|
|
21
|
+
});
|
|
22
|
+
const quotaGuard = createApiKeyRetryGuard(kiloBlocked);
|
|
23
|
+
function invalidKiloResponse(error) {
|
|
24
|
+
return { success: false, error, failureCategory: "provider_api" };
|
|
25
|
+
}
|
|
14
26
|
function isRecord(value) {
|
|
15
27
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
16
28
|
}
|
|
@@ -74,41 +86,26 @@ function isNoActiveKiloPassResult(result) {
|
|
|
74
86
|
function parseKiloPassState(payload) {
|
|
75
87
|
const item = Array.isArray(payload) ? payload[0] : payload;
|
|
76
88
|
if (!isRecord(item)) {
|
|
77
|
-
return
|
|
78
|
-
success: false,
|
|
79
|
-
error: "Kilo Gateway state API returned an unexpected response shape",
|
|
80
|
-
};
|
|
89
|
+
return invalidKiloResponse("Kilo Gateway state API returned an unexpected response shape");
|
|
81
90
|
}
|
|
82
91
|
const result = item.result;
|
|
83
92
|
const data = isRecord(result) ? result.data : undefined;
|
|
84
93
|
if (!isRecord(data)) {
|
|
85
|
-
return
|
|
86
|
-
success: false,
|
|
87
|
-
error: "Kilo Gateway state API returned an unexpected response shape",
|
|
88
|
-
};
|
|
94
|
+
return invalidKiloResponse("Kilo Gateway state API returned an unexpected response shape");
|
|
89
95
|
}
|
|
90
96
|
if ("json" in data && !isRecord(data.json)) {
|
|
91
|
-
return
|
|
92
|
-
success: false,
|
|
93
|
-
error: "Kilo Gateway state API returned an unexpected response shape",
|
|
94
|
-
};
|
|
97
|
+
return invalidKiloResponse("Kilo Gateway state API returned an unexpected response shape");
|
|
95
98
|
}
|
|
96
99
|
const root = isRecord(data.json) ? data.json : data;
|
|
97
100
|
if (!isRecord(root)) {
|
|
98
|
-
return
|
|
99
|
-
success: false,
|
|
100
|
-
error: "Kilo Gateway state API returned an unexpected response shape",
|
|
101
|
-
};
|
|
101
|
+
return invalidKiloResponse("Kilo Gateway state API returned an unexpected response shape");
|
|
102
102
|
}
|
|
103
103
|
const subscription = root.subscription;
|
|
104
104
|
if (subscription === null || !("subscription" in root)) {
|
|
105
105
|
return noActiveKiloPass();
|
|
106
106
|
}
|
|
107
107
|
if (!isRecord(subscription)) {
|
|
108
|
-
return
|
|
109
|
-
success: false,
|
|
110
|
-
error: "Kilo Gateway state API returned an invalid Kilo Pass subscription",
|
|
111
|
-
};
|
|
108
|
+
return invalidKiloResponse("Kilo Gateway state API returned an invalid Kilo Pass subscription");
|
|
112
109
|
}
|
|
113
110
|
const baseCreditsUsd = nonnegativeNumber(subscription.currentPeriodBaseCreditsUsd);
|
|
114
111
|
const usageUsd = nonnegativeNumber(subscription.currentPeriodUsageUsd);
|
|
@@ -117,22 +114,13 @@ function parseKiloPassState(payload) {
|
|
|
117
114
|
? 0
|
|
118
115
|
: nonnegativeNumber(rawBonusCreditsUsd);
|
|
119
116
|
if (baseCreditsUsd === null) {
|
|
120
|
-
return
|
|
121
|
-
success: false,
|
|
122
|
-
error: "Kilo Gateway state API returned invalid currentPeriodBaseCreditsUsd",
|
|
123
|
-
};
|
|
117
|
+
return invalidKiloResponse("Kilo Gateway state API returned invalid currentPeriodBaseCreditsUsd");
|
|
124
118
|
}
|
|
125
119
|
if (usageUsd === null) {
|
|
126
|
-
return
|
|
127
|
-
success: false,
|
|
128
|
-
error: "Kilo Gateway state API returned invalid currentPeriodUsageUsd",
|
|
129
|
-
};
|
|
120
|
+
return invalidKiloResponse("Kilo Gateway state API returned invalid currentPeriodUsageUsd");
|
|
130
121
|
}
|
|
131
122
|
if (bonusCreditsUsd === null) {
|
|
132
|
-
return
|
|
133
|
-
success: false,
|
|
134
|
-
error: "Kilo Gateway state API returned invalid currentPeriodBonusCreditsUsd",
|
|
135
|
-
};
|
|
123
|
+
return invalidKiloResponse("Kilo Gateway state API returned invalid currentPeriodBonusCreditsUsd");
|
|
136
124
|
}
|
|
137
125
|
const resetTimeIso = firstValidResetTimeIso(subscription.nextBillingAt, subscription.nextRenewalAt);
|
|
138
126
|
const totalCreditsUsd = baseCreditsUsd + bonusCreditsUsd;
|
|
@@ -150,17 +138,11 @@ function parseKiloPassState(payload) {
|
|
|
150
138
|
}
|
|
151
139
|
function parseKiloBalance(payload) {
|
|
152
140
|
if (!isRecord(payload)) {
|
|
153
|
-
return
|
|
154
|
-
success: false,
|
|
155
|
-
error: "Kilo Gateway balance API returned an unexpected response shape",
|
|
156
|
-
};
|
|
141
|
+
return invalidKiloResponse("Kilo Gateway balance API returned an unexpected response shape");
|
|
157
142
|
}
|
|
158
143
|
const balanceUsd = nonnegativeNumber(payload.balance);
|
|
159
144
|
if (balanceUsd === null) {
|
|
160
|
-
return
|
|
161
|
-
success: false,
|
|
162
|
-
error: "Kilo Gateway balance API returned an invalid balance",
|
|
163
|
-
};
|
|
145
|
+
return invalidKiloResponse("Kilo Gateway balance API returned an invalid balance");
|
|
164
146
|
}
|
|
165
147
|
return { success: true, balanceUsd };
|
|
166
148
|
}
|
|
@@ -169,6 +151,8 @@ async function requestKiloPassState(key, options) {
|
|
|
169
151
|
batch: "1",
|
|
170
152
|
input: JSON.stringify({ "0": null }),
|
|
171
153
|
});
|
|
154
|
+
let responseStatus;
|
|
155
|
+
let retryAtMs;
|
|
172
156
|
try {
|
|
173
157
|
return await fetchWithTimeout(`${KILO_PASS_STATE_ENDPOINT}?${query.toString()}`, {
|
|
174
158
|
request: {
|
|
@@ -182,11 +166,15 @@ async function requestKiloPassState(key, options) {
|
|
|
182
166
|
},
|
|
183
167
|
timeoutMs: options.requestTimeoutMs,
|
|
184
168
|
consume: async (response) => {
|
|
169
|
+
responseStatus = response.status;
|
|
170
|
+
retryAtMs = retryAfterDeadline(response);
|
|
185
171
|
const text = await readResponseText(response, "state");
|
|
186
172
|
if (!response.ok) {
|
|
187
173
|
return {
|
|
188
174
|
success: false,
|
|
189
175
|
error: `Kilo Gateway state API error ${response.status}: ${sanitizeMessage(text, key)}`,
|
|
176
|
+
failureCategory: providerFailureCategoryForHttpStatus(response.status),
|
|
177
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
190
178
|
};
|
|
191
179
|
}
|
|
192
180
|
return parseKiloPassState(JSON.parse(text));
|
|
@@ -197,10 +185,16 @@ async function requestKiloPassState(key, options) {
|
|
|
197
185
|
return {
|
|
198
186
|
success: false,
|
|
199
187
|
error: sanitizeMessage(error instanceof Error ? error.message : String(error), key),
|
|
188
|
+
failureCategory: responseStatus === undefined
|
|
189
|
+
? "provider_api"
|
|
190
|
+
: providerFailureCategoryForHttpStatus(responseStatus),
|
|
191
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
200
192
|
};
|
|
201
193
|
}
|
|
202
194
|
}
|
|
203
195
|
async function requestKiloBalance(key, options) {
|
|
196
|
+
let responseStatus;
|
|
197
|
+
let retryAtMs;
|
|
204
198
|
try {
|
|
205
199
|
return await fetchWithTimeout(KILO_BALANCE_ENDPOINT, {
|
|
206
200
|
request: {
|
|
@@ -214,11 +208,15 @@ async function requestKiloBalance(key, options) {
|
|
|
214
208
|
},
|
|
215
209
|
timeoutMs: options.requestTimeoutMs,
|
|
216
210
|
consume: async (response) => {
|
|
211
|
+
responseStatus = response.status;
|
|
212
|
+
retryAtMs = retryAfterDeadline(response);
|
|
217
213
|
const text = await readResponseText(response, "balance");
|
|
218
214
|
if (!response.ok) {
|
|
219
215
|
return {
|
|
220
216
|
success: false,
|
|
221
217
|
error: `Kilo Gateway balance API error ${response.status}: ${sanitizeMessage(text, key)}`,
|
|
218
|
+
failureCategory: providerFailureCategoryForHttpStatus(response.status),
|
|
219
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
222
220
|
};
|
|
223
221
|
}
|
|
224
222
|
return parseKiloBalance(JSON.parse(text));
|
|
@@ -229,6 +227,10 @@ async function requestKiloBalance(key, options) {
|
|
|
229
227
|
return {
|
|
230
228
|
success: false,
|
|
231
229
|
error: sanitizeMessage(error instanceof Error ? error.message : String(error), key),
|
|
230
|
+
failureCategory: responseStatus === undefined
|
|
231
|
+
? "provider_api"
|
|
232
|
+
: providerFailureCategoryForHttpStatus(responseStatus),
|
|
233
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
232
234
|
};
|
|
233
235
|
}
|
|
234
236
|
}
|
|
@@ -246,20 +248,26 @@ export async function queryKiloQuota(options = {}) {
|
|
|
246
248
|
const resolved = await resolveKiloApiKey();
|
|
247
249
|
if (!resolved)
|
|
248
250
|
return null;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
251
|
+
return quotaGuard(resolved.key, async () => {
|
|
252
|
+
const passResult = await requestKiloPassState(resolved.key, options);
|
|
253
|
+
if (passResult.success) {
|
|
254
|
+
return { ...passResult, mode: "kilo_pass" };
|
|
255
|
+
}
|
|
256
|
+
if (!isNoActiveKiloPassResult(passResult)) {
|
|
257
|
+
return passResult;
|
|
258
|
+
}
|
|
259
|
+
const balanceResult = await requestKiloBalance(resolved.key, options);
|
|
260
|
+
if (balanceResult.success) {
|
|
261
|
+
return { ...balanceResult, mode: "gateway_balance" };
|
|
262
|
+
}
|
|
263
|
+
return {
|
|
264
|
+
success: false,
|
|
265
|
+
error: `Kilo Gateway has no active Kilo Pass subscription; balance fallback failed: ${balanceResult.error}`,
|
|
266
|
+
...(balanceResult.failureCategory !== undefined
|
|
267
|
+
? { failureCategory: balanceResult.failureCategory }
|
|
268
|
+
: {}),
|
|
269
|
+
...(balanceResult.retryAtMs !== undefined ? { retryAtMs: balanceResult.retryAtMs } : {}),
|
|
270
|
+
};
|
|
271
|
+
}, options.requestTimeoutMs);
|
|
264
272
|
}
|
|
265
273
|
//# sourceMappingURL=kilo.js.map
|