opencode-quota-gui 1.2.0 → 1.3.0
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 +90 -30
- package/dist/bin/opencode-quota-gui.js +0 -0
- 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 +27 -0
- package/dist/contracts/dashboard.js +2 -0
- package/dist/contracts/dto-guards.d.ts +24 -0
- package/dist/contracts/dto-guards.js +592 -0
- package/dist/contracts/provider-failure.d.ts +18 -0
- package/dist/contracts/provider-failure.js +25 -0
- package/dist/gui/config.d.ts +20 -3
- package/dist/gui/config.js +42 -3
- package/dist/gui/dashboard-errors.d.ts +32 -0
- package/dist/gui/dashboard-errors.js +97 -0
- package/dist/gui/lifecycle.d.ts +44 -11
- package/dist/gui/lifecycle.js +214 -36
- package/dist/gui/primary-quota-windows.d.ts +28 -0
- package/dist/gui/primary-quota-windows.js +147 -0
- package/dist/gui/provider-cards.d.ts +1 -1
- package/dist/gui/provider-cards.js +40 -16
- package/dist/gui/quota-notification-detector.d.ts +151 -0
- package/dist/gui/quota-notification-detector.js +284 -0
- package/dist/gui/quota-notification-observer.d.ts +55 -0
- package/dist/gui/quota-notification-observer.js +363 -0
- package/dist/gui/rpc.d.ts +59 -0
- package/dist/gui/rpc.js +302 -0
- package/dist/gui/server.d.ts +15 -27
- package/dist/gui/server.js +23 -121
- package/dist/gui/snapshot-service.d.ts +31 -4
- package/dist/gui/snapshot-service.js +177 -54
- package/dist/gui/sources.d.ts +1 -1
- package/dist/gui-experimental.cjs +1756 -0
- package/dist/lib/anthropic.d.ts +5 -0
- package/dist/lib/anthropic.js +18 -1
- package/dist/lib/chutes.js +19 -2
- package/dist/lib/config.d.ts +5 -1
- package/dist/lib/config.js +48 -0
- package/dist/lib/copilot.js +42 -14
- package/dist/lib/dashboard-web-policy.d.ts +35 -0
- package/dist/lib/dashboard-web-policy.js +24 -0
- package/dist/lib/deepseek.js +12 -1
- package/dist/lib/display-sanitize.js +2 -0
- package/dist/lib/entries.d.ts +3 -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 +14 -4
- package/dist/lib/google-agy.js +59 -14
- package/dist/lib/google-gemini-cli.js +58 -14
- package/dist/lib/init-installer.js +25 -4
- package/dist/lib/kilo.js +29 -40
- package/dist/lib/kimi.js +13 -1
- package/dist/lib/mimo.d.ts +2 -0
- package/dist/lib/mimo.js +9 -1
- package/dist/lib/nanogpt.d.ts +2 -0
- package/dist/lib/nanogpt.js +24 -3
- package/dist/lib/ollama-cloud.js +9 -0
- package/dist/lib/openai.js +6 -2
- package/dist/lib/opencode-auth.d.ts +3 -2
- package/dist/lib/opencode-auth.js +8 -1
- package/dist/lib/opencode-go.js +24 -3
- package/dist/lib/opencode-version.d.ts +21 -0
- package/dist/lib/opencode-version.js +53 -5
- package/dist/lib/opencode-zen.d.ts +9 -1
- package/dist/lib/opencode-zen.js +27 -7
- package/dist/lib/quota-providers-remote.d.ts +2 -0
- package/dist/lib/quota-providers-remote.js +78 -19
- 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 +3 -1
- package/dist/lib/synthetic.js +8 -0
- package/dist/lib/types.d.ts +18 -0
- package/dist/lib/types.js +3 -0
- package/dist/lib/xai.js +16 -2
- package/dist/plugin.d.ts +4 -3
- package/dist/plugin.js +33 -4
- package/dist/providers/alibaba-coding-plan.js +3 -1
- package/dist/providers/alibaba-token-plan.js +17 -0
- package/dist/providers/anthropic.js +12 -3
- package/dist/providers/copilot.js +10 -2
- package/dist/providers/glm-coding-plan-provider.d.ts +2 -0
- package/dist/providers/glm-coding-plan-provider.js +5 -1
- package/dist/providers/google-account-format.js +1 -0
- package/dist/providers/google-agy.js +12 -2
- package/dist/providers/google-gemini-cli.js +12 -2
- package/dist/providers/kilo.js +9 -1
- package/dist/providers/kimi-code.js +11 -6
- package/dist/providers/mimo.js +8 -2
- package/dist/providers/minimax-coding-plan.js +28 -5
- package/dist/providers/nanogpt.js +3 -0
- package/dist/providers/ollama-cloud.js +3 -0
- package/dist/providers/openai.js +1 -0
- package/dist/providers/opencode-go.js +8 -1
- package/dist/providers/opencode-zen.js +30 -3
- package/dist/providers/openrouter.js +3 -0
- package/dist/providers/quota-providers.js +30 -4
- package/dist/providers/result-helpers.d.ts +4 -0
- package/dist/providers/result-helpers.js +16 -2
- package/dist/rpc.d.ts +327 -4
- package/dist/rpc.js +315 -2
- package/dist/ui/assets/index-DLHeXYff.js +9 -0
- package/dist/ui/assets/{index-Cs-nrywz.css → index-cDd9jUVY.css} +1 -1
- package/dist/ui/assets/{popover-DKRrwr_K.js → popover-BGkgv9s0.js} +1 -1
- package/dist/ui/index.html +2 -2
- package/package.json +49 -40
- 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.map +0 -1
- 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
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-runtime quota notification observation.
|
|
3
|
+
*
|
|
4
|
+
* The runtime calls `observe` once for every fresh, non-stale quota snapshot the
|
|
5
|
+
* existing shared poller produces. The pure detector owns transition policy;
|
|
6
|
+
* this module owns effective settings, the in-memory baseline, cooldown
|
|
7
|
+
* persistence, safe event wording and the live notification bus.
|
|
8
|
+
*
|
|
9
|
+
* Baseline semantics are deliberately simple: detector rows/providers are never
|
|
10
|
+
* persisted, so the first snapshot after startup or a source handoff silently
|
|
11
|
+
* re-baselines. Only fingerprint cooldowns survive, through the existing
|
|
12
|
+
* private atomic JSON write, which prevents a notification storm across quick
|
|
13
|
+
* app restarts. There is no lock, claim, outbox or acknowledgement protocol:
|
|
14
|
+
* cooldown writes are best effort per owner and may race across processes.
|
|
15
|
+
*
|
|
16
|
+
* Events are live-only. If no window is listening when an event is emitted it
|
|
17
|
+
* is lost; the next transition is the next opportunity to alert.
|
|
18
|
+
*/
|
|
19
|
+
import { readFile } from "node:fs/promises";
|
|
20
|
+
import { writeJsonAtomic } from "../lib/atomic-json.js";
|
|
21
|
+
import { formatResetCountdown } from "../lib/format-utils.js";
|
|
22
|
+
import { getGuiPrivateStatePath } from "../lib/private-state-paths.js";
|
|
23
|
+
import { DEFAULT_CONFIG } from "../lib/types.js";
|
|
24
|
+
import { createGuiLogger } from "./log.js";
|
|
25
|
+
import { detectQuotaNotifications, QUOTA_NOTIFICATION_DETECTOR_STATE_VERSION, } from "./quota-notification-detector.js";
|
|
26
|
+
const PERSISTED_STATE_VERSION = 1;
|
|
27
|
+
const DEFAULT_STATE_FILE = "quota-notifications.json";
|
|
28
|
+
const MAX_LABEL_LENGTH = 80;
|
|
29
|
+
const CONFIG_UNAVAILABLE = "config unavailable";
|
|
30
|
+
function isRecord(value) {
|
|
31
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
function isFiniteNumber(value) {
|
|
34
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
35
|
+
}
|
|
36
|
+
function numberSetting(values, key, fallback, min, max) {
|
|
37
|
+
const value = values[key];
|
|
38
|
+
if (value === undefined || value === null)
|
|
39
|
+
return fallback;
|
|
40
|
+
if (!isFiniteNumber(value) || value < min || value > max) {
|
|
41
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
function displayModeSetting(values) {
|
|
46
|
+
const value = values.percentDisplayMode;
|
|
47
|
+
if (value === undefined || value === null)
|
|
48
|
+
return DEFAULT_CONFIG.percentDisplayMode;
|
|
49
|
+
if (value !== "used" && value !== "remaining")
|
|
50
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function hiddenIds(value) {
|
|
54
|
+
if (!Array.isArray(value))
|
|
55
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
56
|
+
const result = [];
|
|
57
|
+
for (const entry of value) {
|
|
58
|
+
if (typeof entry !== "string" || entry.length === 0) {
|
|
59
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
60
|
+
}
|
|
61
|
+
result.push(entry);
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Maps the canonical settings snapshot to the observer's effective values.
|
|
67
|
+
* Missing keys use the product defaults; malformed values and malformed or
|
|
68
|
+
* missing visibility fail closed so the caller can re-baseline instead of
|
|
69
|
+
* alerting with guessed policy (including guessed hidden-card state).
|
|
70
|
+
*/
|
|
71
|
+
export function quotaNotificationSettingsFromSnapshot(snapshot) {
|
|
72
|
+
if (!isRecord(snapshot.values))
|
|
73
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
74
|
+
if (!isRecord(snapshot.visibility))
|
|
75
|
+
throw new Error(CONFIG_UNAVAILABLE);
|
|
76
|
+
const cooldownMinutes = numberSetting(snapshot.values, "duplicateCooldownMinutes", DEFAULT_CONFIG.duplicateCooldownMinutes, 0, Number.MAX_SAFE_INTEGER);
|
|
77
|
+
return {
|
|
78
|
+
lowThresholdPercent: numberSetting(snapshot.values, "lowQuotaThresholdRemainingPercent", DEFAULT_CONFIG.lowQuotaThresholdRemainingPercent, 0, 100),
|
|
79
|
+
cooldownMs: cooldownMinutes * 60_000,
|
|
80
|
+
hiddenCards: hiddenIds(snapshot.visibility.hiddenCards),
|
|
81
|
+
hiddenRows: hiddenIds(snapshot.visibility.hiddenRows),
|
|
82
|
+
percentDisplayMode: displayModeSetting(snapshot.values),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Reads persisted cooldowns best effort. A missing, malformed, unreadable or
|
|
87
|
+
* version-mismatched file means "no suppression state"; a notification is never
|
|
88
|
+
* dropped merely because this read failed.
|
|
89
|
+
*/
|
|
90
|
+
async function readCooldowns(path) {
|
|
91
|
+
let content;
|
|
92
|
+
try {
|
|
93
|
+
content = await readFile(path, "utf8");
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
let parsed;
|
|
99
|
+
try {
|
|
100
|
+
parsed = JSON.parse(content);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return {};
|
|
104
|
+
}
|
|
105
|
+
if (!isRecord(parsed) || parsed.version !== PERSISTED_STATE_VERSION)
|
|
106
|
+
return {};
|
|
107
|
+
if (!isRecord(parsed.cooldowns))
|
|
108
|
+
return {};
|
|
109
|
+
const cooldowns = {};
|
|
110
|
+
for (const [fingerprint, value] of Object.entries(parsed.cooldowns)) {
|
|
111
|
+
if (fingerprint.length > 0 && isFiniteNumber(value) && value >= 0) {
|
|
112
|
+
cooldowns[fingerprint] = value;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return cooldowns;
|
|
116
|
+
}
|
|
117
|
+
/** Newest timestamp wins; a suppression record is never discarded. */
|
|
118
|
+
function mergeCooldowns(local, persisted) {
|
|
119
|
+
const merged = { ...local };
|
|
120
|
+
for (const [fingerprint, observedAtMs] of Object.entries(persisted)) {
|
|
121
|
+
const current = merged[fingerprint];
|
|
122
|
+
if (current === undefined || observedAtMs > current)
|
|
123
|
+
merged[fingerprint] = observedAtMs;
|
|
124
|
+
}
|
|
125
|
+
return merged;
|
|
126
|
+
}
|
|
127
|
+
function pruneCooldowns(cooldowns, nowMs, cooldownMs) {
|
|
128
|
+
if (!Number.isFinite(nowMs) || cooldownMs <= 0)
|
|
129
|
+
return {};
|
|
130
|
+
const pruned = {};
|
|
131
|
+
for (const [fingerprint, timestamp] of Object.entries(cooldowns)) {
|
|
132
|
+
const ageMs = nowMs - timestamp;
|
|
133
|
+
if (Number.isFinite(ageMs) && ageMs >= 0 && ageMs < cooldownMs) {
|
|
134
|
+
pruned[fingerprint] = timestamp;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return pruned;
|
|
138
|
+
}
|
|
139
|
+
function sameCooldowns(left, right) {
|
|
140
|
+
const leftEntries = Object.entries(left);
|
|
141
|
+
return (leftEntries.length === Object.keys(right).length &&
|
|
142
|
+
leftEntries.every(([fingerprint, timestamp]) => right[fingerprint] === timestamp));
|
|
143
|
+
}
|
|
144
|
+
function safeLabel(value, fallback) {
|
|
145
|
+
let withoutControls = "";
|
|
146
|
+
for (const character of value ?? "") {
|
|
147
|
+
const code = character.codePointAt(0) ?? 0;
|
|
148
|
+
withoutControls += code < 0x20 || code === 0x7f ? " " : character;
|
|
149
|
+
}
|
|
150
|
+
const cleaned = withoutControls.replace(/\s+/gu, " ").trim().slice(0, MAX_LABEL_LENGTH);
|
|
151
|
+
return cleaned.length > 0 ? cleaned : fallback;
|
|
152
|
+
}
|
|
153
|
+
function displayPercent(percentRemaining, mode) {
|
|
154
|
+
const remaining = Math.min(100, Math.max(0, percentRemaining));
|
|
155
|
+
const value = mode === "used" ? 100 - remaining : remaining;
|
|
156
|
+
return `${Math.round(value)}% ${mode === "used" ? "used" : "remaining"}`;
|
|
157
|
+
}
|
|
158
|
+
function resetCountdownDescription(resetAtIso, nowMs) {
|
|
159
|
+
const countdown = resetAtIso === undefined ? "reset" : formatResetCountdown(resetAtIso, { spaced: true }, nowMs);
|
|
160
|
+
return countdown === "reset" ? " Reset timing unavailable." : ` Resets in ${countdown}.`;
|
|
161
|
+
}
|
|
162
|
+
function notificationTitle(notification) {
|
|
163
|
+
const provider = safeLabel(notification.providerLabel, "Provider");
|
|
164
|
+
switch (notification.kind) {
|
|
165
|
+
case "low":
|
|
166
|
+
return `${provider} quota low`;
|
|
167
|
+
case "exhausted":
|
|
168
|
+
return `${provider} quota exhausted`;
|
|
169
|
+
case "reset":
|
|
170
|
+
return `${provider} quota reset`;
|
|
171
|
+
case "provider-error":
|
|
172
|
+
return `${provider} quota error`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function notificationDescription(notification, mode, nowMs) {
|
|
176
|
+
const account = safeLabel(notification.accountLabel, "Account");
|
|
177
|
+
switch (notification.kind) {
|
|
178
|
+
case "low":
|
|
179
|
+
case "exhausted": {
|
|
180
|
+
return `${account}: ${safeLabel(notification.rowLabel, "Quota")}: ${displayPercent(notification.percentRemaining, mode)}.${resetCountdownDescription(notification.resetAtIso, nowMs)}`;
|
|
181
|
+
}
|
|
182
|
+
case "reset":
|
|
183
|
+
return `${account}: ${safeLabel(notification.rowLabel, "Quota")}: quota reset; ${displayPercent(notification.percentRemaining, mode)}.${resetCountdownDescription(notification.resetAtIso, nowMs)}`;
|
|
184
|
+
case "provider-error":
|
|
185
|
+
// Only the safe category is known; labels and raw messages never reach
|
|
186
|
+
// the event, so no provider error detail can leak.
|
|
187
|
+
return `${account}: provider API error.`;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* One event identity for every window. The fingerprint proves which transition
|
|
192
|
+
* it is; the observation timestamp makes a later repetition of the same
|
|
193
|
+
* fingerprint a distinct event for host notification dedupe.
|
|
194
|
+
*/
|
|
195
|
+
function quotaNotificationEvent(notification, mode) {
|
|
196
|
+
return {
|
|
197
|
+
id: `${notification.fingerprint}:${notification.observedAtMs}`,
|
|
198
|
+
kind: notification.kind,
|
|
199
|
+
title: notificationTitle(notification),
|
|
200
|
+
description: notificationDescription(notification, mode, notification.observedAtMs),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
async function defaultWriteState(statePath, cooldowns) {
|
|
204
|
+
await writeJsonAtomic(statePath, { version: PERSISTED_STATE_VERSION, cooldowns }, { trailingNewline: true, directoryMode: 0o700, fileMode: 0o600 });
|
|
205
|
+
}
|
|
206
|
+
export function createQuotaNotificationObserver(options) {
|
|
207
|
+
const logger = options.logger ?? createGuiLogger();
|
|
208
|
+
const now = options.now ?? Date.now;
|
|
209
|
+
const statePath = options.statePath ?? getGuiPrivateStatePath(DEFAULT_STATE_FILE);
|
|
210
|
+
const listeners = new Set();
|
|
211
|
+
let detectorState;
|
|
212
|
+
let cooldowns = {};
|
|
213
|
+
let cooldownsLoaded = false;
|
|
214
|
+
let needsBaseline = true;
|
|
215
|
+
/** Source identity; bumped by a handoff or close. */
|
|
216
|
+
let sourceEpoch = 0;
|
|
217
|
+
let closed = false;
|
|
218
|
+
let chain = Promise.resolve();
|
|
219
|
+
function current(epoch) {
|
|
220
|
+
return !closed && epoch === sourceEpoch;
|
|
221
|
+
}
|
|
222
|
+
function publish(event, epoch) {
|
|
223
|
+
if (!current(epoch))
|
|
224
|
+
return;
|
|
225
|
+
// A listener may hand the host off or close the observer synchronously.
|
|
226
|
+
// Re-check before every callback so the copied listener list cannot deliver
|
|
227
|
+
// the old source's event to the remaining windows.
|
|
228
|
+
for (const listener of Array.from(listeners)) {
|
|
229
|
+
if (!current(epoch))
|
|
230
|
+
return;
|
|
231
|
+
try {
|
|
232
|
+
listener(event);
|
|
233
|
+
}
|
|
234
|
+
catch {
|
|
235
|
+
// One window listener never breaks observation or persistence.
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function failObservation() {
|
|
240
|
+
// Fail closed: without the effective threshold/visibility, no transition is
|
|
241
|
+
// safe. The next successful read re-baselines silently.
|
|
242
|
+
needsBaseline = true;
|
|
243
|
+
detectorState = undefined;
|
|
244
|
+
logger.warn("quota notification settings unavailable", "config-unavailable");
|
|
245
|
+
}
|
|
246
|
+
async function persist(next, nowMs, cooldownMs) {
|
|
247
|
+
// Best-effort read/merge/write. There is no lock; a concurrent process can
|
|
248
|
+
// still lose this entry or overwrite it with its own atomic replace.
|
|
249
|
+
const persisted = await readCooldowns(statePath);
|
|
250
|
+
const merged = pruneCooldowns(mergeCooldowns(next, persisted), nowMs, cooldownMs);
|
|
251
|
+
try {
|
|
252
|
+
await (options.writeState ?? defaultWriteState)(statePath, merged);
|
|
253
|
+
return merged;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
logger.warn("quota notification state write failed", "failed");
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
async function observeNow(snapshot, epoch) {
|
|
261
|
+
if (closed || epoch !== sourceEpoch)
|
|
262
|
+
return;
|
|
263
|
+
if (snapshot.stale === true)
|
|
264
|
+
return;
|
|
265
|
+
let settings;
|
|
266
|
+
try {
|
|
267
|
+
settings = await options.loadSettings();
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
if (epoch === sourceEpoch)
|
|
271
|
+
failObservation();
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (closed || epoch !== sourceEpoch)
|
|
275
|
+
return;
|
|
276
|
+
const nowMs = now();
|
|
277
|
+
if (!cooldownsLoaded) {
|
|
278
|
+
cooldowns = mergeCooldowns(cooldowns, await readCooldowns(statePath));
|
|
279
|
+
cooldownsLoaded = true;
|
|
280
|
+
if (closed || epoch !== sourceEpoch)
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const prunedCooldowns = pruneCooldowns(cooldowns, nowMs, settings.cooldownMs);
|
|
284
|
+
const cooldownsWerePruned = !sameCooldowns(cooldowns, prunedCooldowns);
|
|
285
|
+
cooldowns = prunedCooldowns;
|
|
286
|
+
if (cooldownsWerePruned) {
|
|
287
|
+
const persisted = await persist(cooldowns, nowMs, settings.cooldownMs);
|
|
288
|
+
cooldowns = persisted ?? cooldowns;
|
|
289
|
+
if (closed || epoch !== sourceEpoch)
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
const result = detectQuotaNotifications({
|
|
293
|
+
cards: snapshot.providers.cards,
|
|
294
|
+
hiddenCards: settings.hiddenCards,
|
|
295
|
+
hiddenRows: settings.hiddenRows,
|
|
296
|
+
...(needsBaseline || detectorState === undefined ? {} : { state: detectorState }),
|
|
297
|
+
cooldowns,
|
|
298
|
+
nowMs,
|
|
299
|
+
lowThresholdPercent: settings.lowThresholdPercent,
|
|
300
|
+
cooldownMs: settings.cooldownMs,
|
|
301
|
+
});
|
|
302
|
+
if (closed || epoch !== sourceEpoch)
|
|
303
|
+
return;
|
|
304
|
+
detectorState = {
|
|
305
|
+
version: QUOTA_NOTIFICATION_DETECTOR_STATE_VERSION,
|
|
306
|
+
rows: result.state.rows,
|
|
307
|
+
providers: result.state.providers,
|
|
308
|
+
};
|
|
309
|
+
needsBaseline = false;
|
|
310
|
+
cooldowns = pruneCooldowns(result.cooldowns, nowMs, settings.cooldownMs);
|
|
311
|
+
if (result.notifications.length === 0)
|
|
312
|
+
return;
|
|
313
|
+
const persisted = await persist(cooldowns, nowMs, settings.cooldownMs);
|
|
314
|
+
cooldowns = persisted ?? cooldowns;
|
|
315
|
+
// A handoff can land while the cooldown write is in flight. Fence before
|
|
316
|
+
// publishing so the old source's event never reaches the new generation.
|
|
317
|
+
if (closed || epoch !== sourceEpoch)
|
|
318
|
+
return;
|
|
319
|
+
for (const notification of result.notifications) {
|
|
320
|
+
if (!current(epoch))
|
|
321
|
+
return;
|
|
322
|
+
publish(quotaNotificationEvent(notification, settings.percentDisplayMode), epoch);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return {
|
|
326
|
+
observe(snapshot, capturedEpoch) {
|
|
327
|
+
if (closed)
|
|
328
|
+
return;
|
|
329
|
+
const epoch = capturedEpoch ?? sourceEpoch;
|
|
330
|
+
chain = chain
|
|
331
|
+
.then(() => observeNow(snapshot, epoch))
|
|
332
|
+
.catch(() => {
|
|
333
|
+
logger.warn("quota notification observation failed", "failed");
|
|
334
|
+
});
|
|
335
|
+
},
|
|
336
|
+
epoch() {
|
|
337
|
+
return sourceEpoch;
|
|
338
|
+
},
|
|
339
|
+
sourceChanged() {
|
|
340
|
+
sourceEpoch += 1;
|
|
341
|
+
needsBaseline = true;
|
|
342
|
+
detectorState = undefined;
|
|
343
|
+
},
|
|
344
|
+
flush() {
|
|
345
|
+
return chain;
|
|
346
|
+
},
|
|
347
|
+
subscribe(listener) {
|
|
348
|
+
if (closed)
|
|
349
|
+
return () => { };
|
|
350
|
+
listeners.add(listener);
|
|
351
|
+
return () => listeners.delete(listener);
|
|
352
|
+
},
|
|
353
|
+
async close() {
|
|
354
|
+
if (closed)
|
|
355
|
+
return;
|
|
356
|
+
closed = true;
|
|
357
|
+
sourceEpoch += 1;
|
|
358
|
+
listeners.clear();
|
|
359
|
+
await chain;
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
//# sourceMappingURL=quota-notification-observer.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed dashboard RPC transport (Stage 3).
|
|
3
|
+
*
|
|
4
|
+
* This adapter attaches to the host-owned `SnapshotService` and settings store
|
|
5
|
+
* from `lifecycle.ts`. It never constructs a source, snapshot service, worker or
|
|
6
|
+
* poller, so native-only, web-only, both and neither all share one runtime.
|
|
7
|
+
* Inputs are validated by the RPC definition; failures are mapped to the fixed
|
|
8
|
+
* transport error vocabulary without raw messages or private paths. No method
|
|
9
|
+
* accepts a filesystem path, credential, or workspace override: reads execute
|
|
10
|
+
* through the host's active owner and its configured workspace.
|
|
11
|
+
*
|
|
12
|
+
* Authorization is the host's: OpenCode applies its server-wide
|
|
13
|
+
* `Authorization` middleware to the RPC route (the normal CLI defaults to
|
|
14
|
+
* loopback plus a generated password; embedded/passwordless hosts rely on their
|
|
15
|
+
* embedder). No caller identity or per-method permission is exposed to a
|
|
16
|
+
* handler (2.0.16 `RpcCallContext` has only `signal` and `error`), so this
|
|
17
|
+
* transport does not invent a second permission model. Settings writes keep
|
|
18
|
+
* their optimistic `expectedRevision` guard but rely on the host's server-level
|
|
19
|
+
* access control.
|
|
20
|
+
*/
|
|
21
|
+
import type { RpcDomain, RpcRegistration } from "@opencode/plugin/promise/rpc";
|
|
22
|
+
import type { GuiSettingsStore } from "../contracts/dashboard.js";
|
|
23
|
+
import { DashboardRpc } from "../rpc.js";
|
|
24
|
+
import { type GuiLogger } from "./log.js";
|
|
25
|
+
import type { QuotaNotificationObserver } from "./quota-notification-observer.js";
|
|
26
|
+
import type { SnapshotService } from "./snapshot-service.js";
|
|
27
|
+
/** The host-owned dependencies every transport attaches to. */
|
|
28
|
+
export interface DashboardRpcRuntime {
|
|
29
|
+
readonly snapshots: SnapshotService;
|
|
30
|
+
readonly settings: GuiSettingsStore;
|
|
31
|
+
/** Optional host observer; its safe events use their own dashboard channel. */
|
|
32
|
+
readonly quotaNotifications?: Pick<QuotaNotificationObserver, "subscribe">;
|
|
33
|
+
}
|
|
34
|
+
/** The complete OpenCode location whose event stream this transport serves. */
|
|
35
|
+
export interface DashboardRpcLocation {
|
|
36
|
+
readonly directory: string;
|
|
37
|
+
readonly workspaceID?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface RegisterDashboardRpcOptions {
|
|
40
|
+
logger?: GuiLogger;
|
|
41
|
+
/**
|
|
42
|
+
* The complete location this setup serves. OpenCode's event bus filters on
|
|
43
|
+
* both `directory` and `workspaceID`, so sharing is keyed by both: setups at
|
|
44
|
+
* the same directory but different workspaces keep independent
|
|
45
|
+
* subscriptions. A missing location never shares with a present one.
|
|
46
|
+
*/
|
|
47
|
+
location?: DashboardRpcLocation;
|
|
48
|
+
}
|
|
49
|
+
export type DashboardRpcRegister = Pick<RpcDomain, "register">;
|
|
50
|
+
/**
|
|
51
|
+
* Registers one setup's dashboard contract in that setup's SDK scope and joins
|
|
52
|
+
* the shared snapshot subscription for its location. Duplicate setups with the
|
|
53
|
+
* same host runtime and location still produce one invalidation per snapshot
|
|
54
|
+
* change, but each owns its registration, so an SDK scope finalizer can dispose
|
|
55
|
+
* one setup without affecting the others. The returned lease releases its own
|
|
56
|
+
* viewers and registration; the final lease releases the shared subscription.
|
|
57
|
+
*/
|
|
58
|
+
export declare function registerDashboardRpc(rpc: DashboardRpcRegister, runtime: DashboardRpcRuntime, options?: RegisterDashboardRpcOptions): Promise<RpcRegistration<typeof DashboardRpc>>;
|
|
59
|
+
//# sourceMappingURL=rpc.d.ts.map
|