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/openai.js
CHANGED
|
@@ -4,10 +4,13 @@
|
|
|
4
4
|
* Uses OpenCode's opencode.db native OpenCode OAuth entries and queries:
|
|
5
5
|
* https://chatgpt.com/backend-api/wham/usage
|
|
6
6
|
*/
|
|
7
|
+
import { providerFailureCategoryForHttpStatus } from "../contracts/provider-failure.js";
|
|
8
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
7
9
|
import { sanitizeDisplayText, sanitizeSingleLineDisplayText } from "./display-sanitize.js";
|
|
8
10
|
import { clampPercent } from "./format-utils.js";
|
|
9
|
-
import { fetchWithTimeout } from "./http.js";
|
|
11
|
+
import { fetchWithTimeout, RequestTimeoutError } from "./http.js";
|
|
10
12
|
import { readAuthFileCached } from "./opencode-auth.js";
|
|
13
|
+
import { buildFixedWindowEvidence } from "./quota-exhaustion-projection.js";
|
|
11
14
|
import { deriveResolvedAuthIdentity } from "./resolved-auth-identity.js";
|
|
12
15
|
function base64UrlDecode(input) {
|
|
13
16
|
const base64 = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
@@ -94,17 +97,13 @@ function parseRateLimitWindow(window, observedAtMs) {
|
|
|
94
97
|
const value = parseWindowValue(window, observedAtMs);
|
|
95
98
|
if (!value)
|
|
96
99
|
return null;
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
endsAtIso: new Date(endsAtMs).toISOString(),
|
|
105
|
-
fullReset: true,
|
|
106
|
-
};
|
|
107
|
-
}
|
|
100
|
+
const fixedWindow = buildFixedWindowEvidence({
|
|
101
|
+
durationMs: raw.limit_window_seconds * 1000,
|
|
102
|
+
resetTimeIso: value.resetTimeIso,
|
|
103
|
+
observedAtMs,
|
|
104
|
+
});
|
|
105
|
+
if (fixedWindow)
|
|
106
|
+
value.fixedWindow = fixedWindow;
|
|
108
107
|
return { kind, value };
|
|
109
108
|
}
|
|
110
109
|
function derivePlanLabel(planType) {
|
|
@@ -120,6 +119,12 @@ function derivePlanLabel(planType) {
|
|
|
120
119
|
return "OpenAI";
|
|
121
120
|
}
|
|
122
121
|
const OPENAI_USAGE_URL = "https://chatgpt.com/backend-api/wham/usage";
|
|
122
|
+
const guard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
123
|
+
success: false,
|
|
124
|
+
error: "OpenAI API error 429",
|
|
125
|
+
failureCategory: "provider_api",
|
|
126
|
+
retryAtMs,
|
|
127
|
+
}));
|
|
123
128
|
const OPENAI_RESET_CREDITS_URL = "https://chatgpt.com/backend-api/wham/rate-limit-reset-credits";
|
|
124
129
|
export const DEFAULT_OPENAI_AUTH_CACHE_MAX_AGE_MS = 5_000;
|
|
125
130
|
// Not `opencode`: in OpenCode 2 its OAuth entry is the Console login, which
|
|
@@ -256,27 +261,47 @@ function parseAvailableResetCredits(payload) {
|
|
|
256
261
|
: Date.parse(credit.expiresAtIso);
|
|
257
262
|
return credits.sort((left, right) => rank(left) - rank(right));
|
|
258
263
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
264
|
+
// Separate from the usage guard: a limited detail endpoint must not block usage.
|
|
265
|
+
const resetCreditsGuard = createApiKeyRetryGuard((retryAtMs) => ({
|
|
266
|
+
success: false,
|
|
267
|
+
credits: [],
|
|
268
|
+
retryAtMs,
|
|
269
|
+
}));
|
|
270
|
+
async function fetchOpenAIResetCredits(headers, timeoutMs, cooldownKey) {
|
|
271
|
+
const result = await resetCreditsGuard(cooldownKey, async () => {
|
|
272
|
+
try {
|
|
273
|
+
return await fetchWithTimeout(OPENAI_RESET_CREDITS_URL, {
|
|
274
|
+
request: { headers },
|
|
275
|
+
timeoutMs,
|
|
276
|
+
consume: async (resp) => {
|
|
277
|
+
if (!resp.ok) {
|
|
278
|
+
const retryAtMs = retryAfterDeadline(resp);
|
|
279
|
+
return {
|
|
280
|
+
success: false,
|
|
281
|
+
credits: [],
|
|
282
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
return { success: true, credits: parseAvailableResetCredits(await resp.json()) };
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
return { success: false, credits: [] };
|
|
290
|
+
}
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
catch (error) {
|
|
295
|
+
return {
|
|
296
|
+
success: false,
|
|
297
|
+
credits: [],
|
|
298
|
+
...(error instanceof RequestTimeoutError && error.retryAtMs !== undefined
|
|
299
|
+
? { retryAtMs: error.retryAtMs }
|
|
300
|
+
: {}),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}, timeoutMs);
|
|
304
|
+
return result.credits;
|
|
280
305
|
}
|
|
281
306
|
export async function queryOpenAIQuota(options = {}) {
|
|
282
307
|
const resolvedAuth = options.auth ??
|
|
@@ -295,12 +320,13 @@ export async function queryOpenAIQuota(options = {}) {
|
|
|
295
320
|
return {
|
|
296
321
|
success: false,
|
|
297
322
|
error: `OpenAI sign-in could not be refreshed: ${resolvedAuth.error}. ${fix}`,
|
|
323
|
+
failureCategory: "credentials",
|
|
298
324
|
};
|
|
299
325
|
}
|
|
300
326
|
if (resolvedAuth.state !== "configured")
|
|
301
327
|
return null;
|
|
302
328
|
if (resolvedAuth.expiresAt && resolvedAuth.expiresAt < Date.now()) {
|
|
303
|
-
return { success: false, error: "Token expired" };
|
|
329
|
+
return { success: false, error: "Token expired", failureCategory: "credentials" };
|
|
304
330
|
}
|
|
305
331
|
try {
|
|
306
332
|
const headers = {
|
|
@@ -311,15 +337,24 @@ export async function queryOpenAIQuota(options = {}) {
|
|
|
311
337
|
if (accountId) {
|
|
312
338
|
headers["ChatGPT-Account-Id"] = accountId;
|
|
313
339
|
}
|
|
314
|
-
|
|
340
|
+
// The ChatGPT account id names a workspace shared by its members, so it
|
|
341
|
+
// cannot identify a credential (and an email claim does not prove identity
|
|
342
|
+
// either). Key on the credential itself: the refresh token survives access
|
|
343
|
+
// token rotation, the access token is the fallback when there is none. The
|
|
344
|
+
// guard hashes the key and never retains it.
|
|
345
|
+
const cooldownKey = `${accountId ?? ""}\0${resolvedAuth.refreshToken ?? resolvedAuth.accessToken}`;
|
|
346
|
+
const result = await guard(cooldownKey, () => fetchWithTimeout(OPENAI_USAGE_URL, {
|
|
315
347
|
request: { headers },
|
|
316
348
|
timeoutMs: options.requestTimeoutMs,
|
|
317
349
|
consume: async (resp) => {
|
|
318
350
|
if (!resp.ok) {
|
|
351
|
+
const retryAtMs = retryAfterDeadline(resp);
|
|
319
352
|
const code = await readOpenAIErrorCode(resp);
|
|
320
353
|
return {
|
|
321
354
|
success: false,
|
|
322
355
|
error: `OpenAI API error ${resp.status}${code ? ` (${code})` : ""}`,
|
|
356
|
+
failureCategory: providerFailureCategoryForHttpStatus(resp.status),
|
|
357
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
323
358
|
};
|
|
324
359
|
}
|
|
325
360
|
const data = (await resp.json());
|
|
@@ -363,8 +398,10 @@ export async function queryOpenAIQuota(options = {}) {
|
|
|
363
398
|
Number(mappedCredits.balance) > 0));
|
|
364
399
|
// Empty bodies stay invalid; a useful Credits-only/reset-count-only
|
|
365
400
|
// payload is a real measurement even without a percent window.
|
|
366
|
-
if (Object.keys(windows).length === 0 &&
|
|
367
|
-
|
|
401
|
+
if (Object.keys(windows).length === 0 &&
|
|
402
|
+
!positiveCredits &&
|
|
403
|
+
availableResetCount === null) {
|
|
404
|
+
return { success: false, error: "No quota data", failureCategory: "provider_api" };
|
|
368
405
|
}
|
|
369
406
|
return {
|
|
370
407
|
success: true,
|
|
@@ -377,17 +414,30 @@ export async function queryOpenAIQuota(options = {}) {
|
|
|
377
414
|
: {}),
|
|
378
415
|
};
|
|
379
416
|
},
|
|
380
|
-
})
|
|
381
|
-
|
|
417
|
+
}).catch((err) => {
|
|
418
|
+
if (!(err instanceof RequestTimeoutError) || err.retryAtMs === undefined)
|
|
419
|
+
throw err;
|
|
420
|
+
return {
|
|
421
|
+
success: false,
|
|
422
|
+
error: sanitizeDisplayText(err.message),
|
|
423
|
+
failureCategory: "provider_api",
|
|
424
|
+
retryAtMs: err.retryAtMs,
|
|
425
|
+
};
|
|
426
|
+
}), options.requestTimeoutMs);
|
|
427
|
+
if (!result.success || !result.bankedResets || !options.includeResetDetails) {
|
|
382
428
|
return result;
|
|
383
429
|
}
|
|
384
|
-
result.bankedResets.credits = await fetchOpenAIResetCredits(headers, options.requestTimeoutMs);
|
|
430
|
+
result.bankedResets.credits = await fetchOpenAIResetCredits(headers, options.requestTimeoutMs, `reset-credits:${cooldownKey}`);
|
|
385
431
|
return result;
|
|
386
432
|
}
|
|
387
433
|
catch (err) {
|
|
388
434
|
return {
|
|
389
435
|
success: false,
|
|
390
436
|
error: sanitizeDisplayText(err instanceof Error ? err.message : String(err)),
|
|
437
|
+
failureCategory: "provider_api",
|
|
438
|
+
...(err instanceof RequestTimeoutError && err.retryAtMs !== undefined
|
|
439
|
+
? { retryAtMs: err.retryAtMs }
|
|
440
|
+
: {}),
|
|
391
441
|
};
|
|
392
442
|
}
|
|
393
443
|
}
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* `opencode-quota-gui show` and `status` bind this source while one report runs, so they work
|
|
5
5
|
* with OpenCode closed. It is the only code that queries OpenCode's `credential` table. It
|
|
6
6
|
* never refreshes or writes a login: a sign-in whose token expired stays expired here until
|
|
7
|
-
* OpenCode refreshes it. The server plugin
|
|
8
|
-
* (`tests/
|
|
7
|
+
* OpenCode refreshes it. The server plugin must never import this file
|
|
8
|
+
* (`tests/plugin-dist-import-graph.test.ts`).
|
|
9
9
|
*/
|
|
10
10
|
import { type CredentialSource } from "./opencode-auth.js";
|
|
11
11
|
/**
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* `opencode-quota-gui show` and `status` bind this source while one report runs, so they work
|
|
5
5
|
* with OpenCode closed. It is the only code that queries OpenCode's `credential` table. It
|
|
6
6
|
* never refreshes or writes a login: a sign-in whose token expired stays expired here until
|
|
7
|
-
* OpenCode refreshes it. The server plugin
|
|
8
|
-
* (`tests/
|
|
7
|
+
* OpenCode refreshes it. The server plugin must never import this file
|
|
8
|
+
* (`tests/plugin-dist-import-graph.test.ts`).
|
|
9
9
|
*/
|
|
10
10
|
import { existsSync } from "fs";
|
|
11
11
|
import { getCredentialDatabasePaths, } from "./opencode-auth.js";
|
|
@@ -24,8 +24,9 @@ export type CredentialRow = {
|
|
|
24
24
|
/**
|
|
25
25
|
* Why OpenCode could not return this login (for example a failed token
|
|
26
26
|
* refresh), as `<category>: <scrubbed detail>`. A failed row keeps its id,
|
|
27
|
-
* label and position, but its `value` is only `{ type: "api" | "oauth" }
|
|
28
|
-
*
|
|
27
|
+
* label and position, but its `value` is only `{ type: "api" | "oauth" }`.
|
|
28
|
+
* A failed `external` connection uses the same fallback because the failed-row
|
|
29
|
+
* shape only names api/oauth; consumers show `resolveError` as a per-account error.
|
|
29
30
|
*/
|
|
30
31
|
resolveError?: string;
|
|
31
32
|
};
|
|
@@ -304,7 +304,14 @@ async function credentialRowForSlot(integration, slot, methods) {
|
|
|
304
304
|
* has rows, since a firstOnly read returns one active connection per id.
|
|
305
305
|
*/
|
|
306
306
|
async function credentialRowsForSlots(integration, slots, methods, activeConnections) {
|
|
307
|
-
const wanted = slots.filter((slot) =>
|
|
307
|
+
const wanted = slots.filter((slot) => {
|
|
308
|
+
if (!methods || !("connection" in slot))
|
|
309
|
+
return true;
|
|
310
|
+
// SDK 2.2 added the host-provided `external` connection method. It is never
|
|
311
|
+
// one of the readable key/OAuth slots, so compare values instead of asking
|
|
312
|
+
// a narrower array whether it includes a wider union.
|
|
313
|
+
return methods.some((method) => method === slot.connection.method);
|
|
314
|
+
});
|
|
308
315
|
const pairs = await Promise.all(wanted.map(async (slot) => ({
|
|
309
316
|
slot,
|
|
310
317
|
row: await credentialRowForSlot(integration, slot, methods),
|
|
@@ -58,5 +58,6 @@ export declare function applyConfigDocumentEdit(edit: ConfigDocumentEdit, option
|
|
|
58
58
|
pathExists?: (path: string) => boolean;
|
|
59
59
|
writeText?: (path: string, content: string) => Promise<void>;
|
|
60
60
|
removePath?: (path: string) => Promise<void>;
|
|
61
|
+
beforeRename?: () => Promise<void>;
|
|
61
62
|
}): Promise<void>;
|
|
62
63
|
//# sourceMappingURL=opencode-config-editor.d.ts.map
|
|
@@ -352,15 +352,20 @@ export async function applyConfigDocumentEdit(edit, options = {}) {
|
|
|
352
352
|
return;
|
|
353
353
|
}
|
|
354
354
|
await validateConfigDocumentEdit(edit, options);
|
|
355
|
+
const validateBeforeRename = async () => {
|
|
356
|
+
await options.beforeRename?.();
|
|
357
|
+
await validateConfigDocumentEdit(edit, options);
|
|
358
|
+
};
|
|
355
359
|
const removePath = options.removePath ?? ((path) => rm(path));
|
|
356
360
|
try {
|
|
357
361
|
const currentTarget = await resolveConfigWriteTarget(edit.path);
|
|
358
362
|
assertSameConfigWriteTarget(edit.writeTarget, currentTarget);
|
|
359
363
|
if (options.writeText) {
|
|
364
|
+
await validateBeforeRename();
|
|
360
365
|
await options.writeText(currentTarget.writePath, edit.updated);
|
|
361
366
|
}
|
|
362
367
|
else {
|
|
363
|
-
await writeResolvedConfigText(currentTarget, edit.updated);
|
|
368
|
+
await writeResolvedConfigText(currentTarget, edit.updated, validateBeforeRename);
|
|
364
369
|
}
|
|
365
370
|
}
|
|
366
371
|
catch (error) {
|
package/dist/lib/opencode-go.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createApiKeyRetryGuard, retryAfterDeadline } from "./api-key-retry-after.js";
|
|
1
2
|
import { sanitizeDisplayText } from "./display-sanitize.js";
|
|
2
3
|
import { fetchWithTimeout } from "./http.js";
|
|
3
4
|
import { consoleBaseUrl, consoleHeaders, } from "./opencode-console-auth.js";
|
|
@@ -21,7 +22,15 @@ function errorMessage(error, accessToken) {
|
|
|
21
22
|
return sanitizeMessage(error instanceof Error ? error.message : String(error), accessToken);
|
|
22
23
|
}
|
|
23
24
|
function contractError(message) {
|
|
24
|
-
return {
|
|
25
|
+
return {
|
|
26
|
+
success: false,
|
|
27
|
+
error: `Invalid OpenCode Go API response: ${message}`,
|
|
28
|
+
failureCategory: "provider_api",
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/** 401/403 resolve credentials before the endpoint contract can be read. */
|
|
32
|
+
function httpFailureCategory(status) {
|
|
33
|
+
return status === 401 || status === 403 ? "credentials" : "provider_api";
|
|
25
34
|
}
|
|
26
35
|
function isRetryableHttpStatus(status) {
|
|
27
36
|
return status === 408 || status === 425 || status === 429 || status >= 500;
|
|
@@ -110,7 +119,19 @@ function isNotSubscribedResponse(status, text) {
|
|
|
110
119
|
return false;
|
|
111
120
|
}
|
|
112
121
|
}
|
|
113
|
-
|
|
122
|
+
const rateLimited = (retryAtMs) => ({
|
|
123
|
+
success: false,
|
|
124
|
+
error: "OpenCode Go API error 429",
|
|
125
|
+
retryable: true,
|
|
126
|
+
failureCategory: "provider_api",
|
|
127
|
+
retryAtMs,
|
|
128
|
+
});
|
|
129
|
+
const apiKeyGuard = createApiKeyRetryGuard(rateLimited);
|
|
130
|
+
const consoleGuard = createApiKeyRetryGuard(rateLimited);
|
|
131
|
+
export function queryOpenCodeGoQuota(accessToken, options = {}) {
|
|
132
|
+
return apiKeyGuard(accessToken, () => fetchOpenCodeGoQuota(accessToken, options), options.requestTimeoutMs);
|
|
133
|
+
}
|
|
134
|
+
async function fetchOpenCodeGoQuota(accessToken, options) {
|
|
114
135
|
try {
|
|
115
136
|
return await fetchWithTimeout(OPENCODE_GO_USAGE_URL, {
|
|
116
137
|
request: {
|
|
@@ -123,6 +144,7 @@ export async function queryOpenCodeGoQuota(accessToken, options = {}) {
|
|
|
123
144
|
timeoutMs: options.requestTimeoutMs,
|
|
124
145
|
consume: async (response) => {
|
|
125
146
|
if (!response.ok) {
|
|
147
|
+
const retryAtMs = retryAfterDeadline(response);
|
|
126
148
|
let text;
|
|
127
149
|
try {
|
|
128
150
|
text = await response.text();
|
|
@@ -132,6 +154,8 @@ export async function queryOpenCodeGoQuota(accessToken, options = {}) {
|
|
|
132
154
|
success: false,
|
|
133
155
|
error: `OpenCode Go API error ${response.status}: ${errorMessage(error, accessToken)}`,
|
|
134
156
|
retryable: isRetryableHttpStatus(response.status),
|
|
157
|
+
failureCategory: httpFailureCategory(response.status),
|
|
158
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
135
159
|
};
|
|
136
160
|
}
|
|
137
161
|
if (isNotSubscribedResponse(response.status, text)) {
|
|
@@ -146,6 +170,8 @@ export async function queryOpenCodeGoQuota(accessToken, options = {}) {
|
|
|
146
170
|
success: false,
|
|
147
171
|
error: `OpenCode Go API error ${response.status}: ${sanitizeMessage(text, accessToken)}`,
|
|
148
172
|
retryable: isRetryableHttpStatus(response.status),
|
|
173
|
+
failureCategory: httpFailureCategory(response.status),
|
|
174
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
149
175
|
};
|
|
150
176
|
}
|
|
151
177
|
let payload;
|
|
@@ -160,7 +186,12 @@ export async function queryOpenCodeGoQuota(accessToken, options = {}) {
|
|
|
160
186
|
});
|
|
161
187
|
}
|
|
162
188
|
catch (error) {
|
|
163
|
-
return {
|
|
189
|
+
return {
|
|
190
|
+
success: false,
|
|
191
|
+
error: errorMessage(error, accessToken),
|
|
192
|
+
retryable: true,
|
|
193
|
+
failureCategory: "provider_api",
|
|
194
|
+
};
|
|
164
195
|
}
|
|
165
196
|
}
|
|
166
197
|
function asMicroCents(value) {
|
|
@@ -204,7 +235,16 @@ function normalizeConsoleMeter(windowKey, meter) {
|
|
|
204
235
|
* accounts without any pre-2.0 workspace API key. The request goes to the
|
|
205
236
|
* login's Console server, scoped to the login's org when it has one.
|
|
206
237
|
*/
|
|
207
|
-
export
|
|
238
|
+
export function queryOpenCodeGoConsoleStatus(credential, options = {}) {
|
|
239
|
+
// Same token under another org or server is a different account.
|
|
240
|
+
const identity = JSON.stringify([
|
|
241
|
+
credential.accessToken,
|
|
242
|
+
credential.orgId ?? null,
|
|
243
|
+
consoleBaseUrl(credential),
|
|
244
|
+
]);
|
|
245
|
+
return consoleGuard(identity, () => fetchOpenCodeGoConsoleStatus(credential, options), options.requestTimeoutMs);
|
|
246
|
+
}
|
|
247
|
+
async function fetchOpenCodeGoConsoleStatus(credential, options) {
|
|
208
248
|
try {
|
|
209
249
|
return await fetchWithTimeout(`${consoleBaseUrl(credential)}/api/go/status`, {
|
|
210
250
|
request: {
|
|
@@ -225,10 +265,13 @@ export async function queryOpenCodeGoConsoleStatus(credential, options = {}) {
|
|
|
225
265
|
notSubscribed: true,
|
|
226
266
|
};
|
|
227
267
|
}
|
|
268
|
+
const retryAtMs = retryAfterDeadline(response);
|
|
228
269
|
return {
|
|
229
270
|
success: false,
|
|
230
271
|
error: `OpenCode Console API error ${response.status} (/api/go/status)`,
|
|
231
272
|
retryable: isRetryableHttpStatus(response.status),
|
|
273
|
+
failureCategory: httpFailureCategory(response.status),
|
|
274
|
+
...(retryAtMs !== undefined ? { retryAtMs } : {}),
|
|
232
275
|
};
|
|
233
276
|
}
|
|
234
277
|
let payload;
|
|
@@ -278,7 +321,12 @@ export async function queryOpenCodeGoConsoleStatus(credential, options = {}) {
|
|
|
278
321
|
});
|
|
279
322
|
}
|
|
280
323
|
catch (error) {
|
|
281
|
-
return {
|
|
324
|
+
return {
|
|
325
|
+
success: false,
|
|
326
|
+
error: errorMessage(error, credential.accessToken),
|
|
327
|
+
retryable: true,
|
|
328
|
+
failureCategory: "provider_api",
|
|
329
|
+
};
|
|
282
330
|
}
|
|
283
331
|
}
|
|
284
332
|
//# sourceMappingURL=opencode-go.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type OpenCodeMajor = 1 | 2;
|
|
2
|
+
/** Numeric host version; a prerelease/build suffix is ignored. */
|
|
3
|
+
export interface OpenCodeVersion {
|
|
4
|
+
major: number;
|
|
5
|
+
minor: number;
|
|
6
|
+
patch: number;
|
|
7
|
+
}
|
|
8
|
+
/** Parses the numeric version core; a prerelease or build suffix is ignored. */
|
|
9
|
+
export declare function parseOpenCodeVersion(output: string): OpenCodeVersion | undefined;
|
|
10
|
+
/** OpenCode 1 prints a bare `1.18.32`; OpenCode 2 prints `opencode v2.0.16`. */
|
|
11
|
+
export declare function parseOpenCodeMajor(output: string): OpenCodeMajor | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Whether the host has the full Native GUI baseline (2.2.1+). Missing or
|
|
14
|
+
* unparseable versions are not assumed capable.
|
|
15
|
+
*/
|
|
16
|
+
export declare function supportsNativeGui(version: string | OpenCodeVersion | undefined): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether the host predates the Native GUI and therefore keeps the compatibility
|
|
19
|
+
* web dashboard on by default. Only a parseable version below 2.2.1 qualifies;
|
|
20
|
+
* missing or unparseable versions fail closed.
|
|
21
|
+
*/
|
|
22
|
+
export declare function isPreNativeGuiVersion(version: string | OpenCodeVersion | undefined): boolean;
|
|
23
|
+
//# sourceMappingURL=opencode-version-core.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** The numeric core of `1.18.32`, `opencode v2.2.0`, or `2.2.1-beta.1`. */
|
|
2
|
+
const OPENCODE_VERSION_PATTERN = /^(?:opencode\s+)?v?(\d+)\.(\d+)\.(\d+)/;
|
|
3
|
+
/** Parses the numeric version core; a prerelease or build suffix is ignored. */
|
|
4
|
+
export function parseOpenCodeVersion(output) {
|
|
5
|
+
const match = OPENCODE_VERSION_PATTERN.exec(output.trim());
|
|
6
|
+
if (!match)
|
|
7
|
+
return undefined;
|
|
8
|
+
const major = Number(match[1]);
|
|
9
|
+
const minor = Number(match[2]);
|
|
10
|
+
const patch = Number(match[3]);
|
|
11
|
+
if (![major, minor, patch].every((part) => Number.isSafeInteger(part)))
|
|
12
|
+
return undefined;
|
|
13
|
+
return { major, minor, patch };
|
|
14
|
+
}
|
|
15
|
+
/** OpenCode 1 prints a bare `1.18.32`; OpenCode 2 prints `opencode v2.0.16`. */
|
|
16
|
+
export function parseOpenCodeMajor(output) {
|
|
17
|
+
const version = parseOpenCodeVersion(output);
|
|
18
|
+
if (version?.major === 1)
|
|
19
|
+
return 1;
|
|
20
|
+
if (version?.major === 2)
|
|
21
|
+
return 2;
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
/** Compares the numeric parts only; a prerelease suffix never lowers the result. */
|
|
25
|
+
function isAtLeast(version, major, minor, patch) {
|
|
26
|
+
if (version.major !== major)
|
|
27
|
+
return version.major > major;
|
|
28
|
+
if (version.minor !== minor)
|
|
29
|
+
return version.minor > minor;
|
|
30
|
+
return version.patch >= patch;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether the host has the full Native GUI baseline (2.2.1+). Missing or
|
|
34
|
+
* unparseable versions are not assumed capable.
|
|
35
|
+
*/
|
|
36
|
+
export function supportsNativeGui(version) {
|
|
37
|
+
const parsed = typeof version === "string" ? parseOpenCodeVersion(version) : version;
|
|
38
|
+
return parsed !== undefined && isAtLeast(parsed, 2, 2, 1);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether the host predates the Native GUI and therefore keeps the compatibility
|
|
42
|
+
* web dashboard on by default. Only a parseable version below 2.2.1 qualifies;
|
|
43
|
+
* missing or unparseable versions fail closed.
|
|
44
|
+
*/
|
|
45
|
+
export function isPreNativeGuiVersion(version) {
|
|
46
|
+
const parsed = typeof version === "string" ? parseOpenCodeVersion(version) : version;
|
|
47
|
+
return parsed !== undefined && !isAtLeast(parsed, 2, 2, 1);
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=opencode-version-core.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { type OpenCodeMajor, type OpenCodeVersion } from "./opencode-version-core.js";
|
|
2
|
+
export * from "./opencode-version-core.js";
|
|
3
|
+
/** Returns undefined when `opencode` is not on PATH, fails, times out, or prints an unknown version. */
|
|
4
|
+
export declare function detectOpenCodeVersion(runVersion?: () => Promise<string>): Promise<OpenCodeVersion | undefined>;
|
|
4
5
|
/** Returns undefined when `opencode` is not on PATH, fails, times out, or prints an unknown version. */
|
|
5
6
|
export declare function detectOpenCodeMajor(runVersion?: () => Promise<string>): Promise<OpenCodeMajor | undefined>;
|
|
6
7
|
//# sourceMappingURL=opencode-version.d.ts.map
|
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
+
import { parseOpenCodeVersion, } from "./opencode-version-core.js";
|
|
3
|
+
// Keep this legacy module path's public surface intact while the implementation
|
|
4
|
+
// of pure version helpers lives in a browser-safe module.
|
|
5
|
+
export * from "./opencode-version-core.js";
|
|
2
6
|
const OPENCODE_VERSION_TIMEOUT_MS = 5_000;
|
|
3
|
-
/** OpenCode 1 prints a bare `1.18.32`; OpenCode 2 prints `opencode v2.0.16`. */
|
|
4
|
-
export function parseOpenCodeMajor(output) {
|
|
5
|
-
const match = /^(?:opencode\s+)?v?(\d+)\.\d+\.\d+/.exec(output.trim());
|
|
6
|
-
if (match?.[1] === "1")
|
|
7
|
-
return 1;
|
|
8
|
-
if (match?.[1] === "2")
|
|
9
|
-
return 2;
|
|
10
|
-
return undefined;
|
|
11
|
-
}
|
|
12
7
|
function runOpenCodeVersion() {
|
|
13
8
|
return new Promise((resolve, reject) => {
|
|
14
9
|
execFile("opencode", ["--version"], { encoding: "utf8", timeout: OPENCODE_VERSION_TIMEOUT_MS, windowsHide: true }, (error, stdout) => (error ? reject(error) : resolve(stdout)));
|
|
15
10
|
});
|
|
16
11
|
}
|
|
17
12
|
/** Returns undefined when `opencode` is not on PATH, fails, times out, or prints an unknown version. */
|
|
18
|
-
export async function
|
|
13
|
+
export async function detectOpenCodeVersion(runVersion = runOpenCodeVersion) {
|
|
19
14
|
try {
|
|
20
|
-
return
|
|
15
|
+
return parseOpenCodeVersion(await runVersion());
|
|
21
16
|
}
|
|
22
17
|
catch {
|
|
23
18
|
return undefined;
|
|
24
19
|
}
|
|
25
20
|
}
|
|
21
|
+
/** Returns undefined when `opencode` is not on PATH, fails, times out, or prints an unknown version. */
|
|
22
|
+
export async function detectOpenCodeMajor(runVersion = runOpenCodeVersion) {
|
|
23
|
+
const version = await detectOpenCodeVersion(runVersion);
|
|
24
|
+
if (version?.major === 1)
|
|
25
|
+
return 1;
|
|
26
|
+
if (version?.major === 2)
|
|
27
|
+
return 2;
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
26
30
|
//# sourceMappingURL=opencode-version.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ProviderFailureCategory } from "../contracts/provider-failure.js";
|
|
1
2
|
import { type OpenCodeConsoleCredential } from "./opencode-console-auth.js";
|
|
2
3
|
/**
|
|
3
4
|
* The OpenCode Console reports amounts in micro-cents:
|
|
@@ -39,15 +40,25 @@ export interface OpenCodeZenBillingData {
|
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
42
|
* billing/status (balance) is required. The other routes are optional: when one fails,
|
|
42
|
-
* its fields are null and its error is listed in `errors`.
|
|
43
|
+
* its fields are null and its error is listed in `errors`. `optionalErrors`
|
|
44
|
+
* carries the same messages with their producer-assigned failure category.
|
|
43
45
|
*/
|
|
46
|
+
export type OpenCodeZenOptionalError = {
|
|
47
|
+
message: string;
|
|
48
|
+
failureCategory?: ProviderFailureCategory;
|
|
49
|
+
/** Deadline observed in an upstream Retry-After response. */
|
|
50
|
+
retryAtMs?: number;
|
|
51
|
+
};
|
|
44
52
|
export type OpenCodeZenResult = {
|
|
45
53
|
success: true;
|
|
46
54
|
data: OpenCodeZenBillingData;
|
|
47
55
|
errors: string[];
|
|
56
|
+
optionalErrors?: OpenCodeZenOptionalError[];
|
|
48
57
|
} | {
|
|
49
58
|
success: false;
|
|
50
59
|
error: string;
|
|
60
|
+
failureCategory?: ProviderFailureCategory;
|
|
61
|
+
retryAtMs?: number;
|
|
51
62
|
};
|
|
52
63
|
export declare function queryOpenCodeZenQuota(credential: OpenCodeConsoleCredential, options?: {
|
|
53
64
|
requestTimeoutMs?: number;
|