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
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Owns computation, caching, single-flight, viewer-scoped polling and
|
|
5
5
|
* invalidation. Cache keys are `(kind, resourceId, range)`; quota is its own
|
|
6
6
|
* key. Failures serve the last good snapshot with `stale: true` when one
|
|
7
|
-
* exists. Pollers run only while at least one
|
|
8
|
-
* never overlap within a kind.
|
|
7
|
+
* exists. Pollers run only while at least one transport viewer (SSE or RPC) is
|
|
8
|
+
* attached and ticks never overlap within a kind.
|
|
9
9
|
*
|
|
10
10
|
* Quota and analytics poll on independent timers: quota uses the existing
|
|
11
11
|
* positive `minIntervalMs` configuration (default 60000), analytics defaults
|
|
@@ -32,6 +32,12 @@
|
|
|
32
32
|
* newer one). A load on a closed service still computes for its caller but
|
|
33
33
|
* never touches tracking, registration, or cache.
|
|
34
34
|
*
|
|
35
|
+
* An owner/source handoff uses a source generation: entries retain the
|
|
36
|
+
* generation that produced them and old entries are last-good only. A
|
|
37
|
+
* pre-handoff result is marked stale when the DTO supports it, or failed when
|
|
38
|
+
* it does not (`SessionSnapshot`), so the previous owner's data is never
|
|
39
|
+
* presented as fresh.
|
|
40
|
+
*
|
|
35
41
|
* No TTL, sequence, watermark, or budget machinery exists (R9).
|
|
36
42
|
*/
|
|
37
43
|
import type { AnalyticsGroupQuery, AnalyticsGroupSnapshot, DashboardDataSource, DashboardEvent, HomeSnapshot, ProjectSnapshot, QuotaSnapshot, SessionSnapshot } from "../contracts/dashboard.js";
|
|
@@ -59,7 +65,7 @@ export declare const MAX_TRACKED_PAGES = 16;
|
|
|
59
65
|
* optional at this seam so older injected mocks keep compiling; production
|
|
60
66
|
* always provides it and `/api/v1/quota` returns a controlled 500 otherwise.
|
|
61
67
|
* `refreshAnalytics` is an optional shared worker refresh seam, and `close` is
|
|
62
|
-
* closed by the
|
|
68
|
+
* closed by the lifecycle when the last lease disposes, not by this service.
|
|
63
69
|
*/
|
|
64
70
|
export type SnapshotSource = Pick<DashboardDataSource, "home" | "project" | "session"> & {
|
|
65
71
|
quota?: DashboardDataSource["quota"];
|
|
@@ -92,11 +98,17 @@ export interface SnapshotServiceOptions {
|
|
|
92
98
|
* to `analytics` so clients that never signal keep the previous behaviour.
|
|
93
99
|
*/
|
|
94
100
|
export type SnapshotViewScope = "analytics" | "quota";
|
|
101
|
+
/** One viewer that carries its own active-surface scope. */
|
|
102
|
+
export interface SnapshotViewer {
|
|
103
|
+
release(): void;
|
|
104
|
+
}
|
|
95
105
|
export interface SnapshotService {
|
|
96
106
|
home(input: {
|
|
97
107
|
range: RangeKey;
|
|
98
108
|
}): Promise<HomeSnapshot>;
|
|
99
|
-
quota(
|
|
109
|
+
quota(input?: {
|
|
110
|
+
refresh?: boolean;
|
|
111
|
+
}): Promise<QuotaSnapshot>;
|
|
100
112
|
project(input: {
|
|
101
113
|
projectId: string;
|
|
102
114
|
range: RangeKey;
|
|
@@ -107,8 +119,17 @@ export interface SnapshotService {
|
|
|
107
119
|
groups(query: AnalyticsGroupQuery): Promise<AnalyticsGroupSnapshot>;
|
|
108
120
|
/** Invalidations broadcast over SSE (three topics, never raw snapshots). */
|
|
109
121
|
subscribe(listener: (event: DashboardEvent) => void): () => void;
|
|
110
|
-
/**
|
|
122
|
+
/**
|
|
123
|
+
* Registers a legacy unscoped viewer (HTTP/SSE); the returned disposer
|
|
124
|
+
* detaches it. Its active surface comes from `setViewScope`.
|
|
125
|
+
*/
|
|
111
126
|
addViewer(): () => void;
|
|
127
|
+
/**
|
|
128
|
+
* Registers a viewer that carries its own active-surface scope (RPC/native).
|
|
129
|
+
* Concurrent viewers aggregate: analytics refresh runs while any viewer needs
|
|
130
|
+
* analytics, regardless of other viewers' quota signals.
|
|
131
|
+
*/
|
|
132
|
+
addScopedViewer(scope: SnapshotViewScope): SnapshotViewer;
|
|
112
133
|
/**
|
|
113
134
|
* A settings write: clears quota/home/project caches and broadcasts
|
|
114
135
|
* `settings.changed`. `scope: "visibility"` only broadcasts (no invalidation,
|
|
@@ -124,6 +145,14 @@ export interface SnapshotService {
|
|
|
124
145
|
* while the scope is `quota`, analytics refresh/derivation is skipped.
|
|
125
146
|
*/
|
|
126
147
|
setViewScope(scope: SnapshotViewScope, origin?: "signal" | "request"): void;
|
|
148
|
+
/**
|
|
149
|
+
* The host's active source identity changed (owner handoff in the lifecycle).
|
|
150
|
+
* Cached pages belong to the previous owner, so they are marked stale; any
|
|
151
|
+
* pre-handoff in-flight result is never presented as fresh (stale-marked when
|
|
152
|
+
* the DTO supports it, otherwise failed), and both data topics are emitted so
|
|
153
|
+
* connected clients refetch through the new source.
|
|
154
|
+
*/
|
|
155
|
+
sourceChanged(): void;
|
|
127
156
|
close(): void;
|
|
128
157
|
}
|
|
129
158
|
export declare function createSnapshotService(options: SnapshotServiceOptions): SnapshotService;
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Owns computation, caching, single-flight, viewer-scoped polling and
|
|
5
5
|
* invalidation. Cache keys are `(kind, resourceId, range)`; quota is its own
|
|
6
6
|
* key. Failures serve the last good snapshot with `stale: true` when one
|
|
7
|
-
* exists. Pollers run only while at least one
|
|
8
|
-
* never overlap within a kind.
|
|
7
|
+
* exists. Pollers run only while at least one transport viewer (SSE or RPC) is
|
|
8
|
+
* attached and ticks never overlap within a kind.
|
|
9
9
|
*
|
|
10
10
|
* Quota and analytics poll on independent timers: quota uses the existing
|
|
11
11
|
* positive `minIntervalMs` configuration (default 60000), analytics defaults
|
|
@@ -32,6 +32,12 @@
|
|
|
32
32
|
* newer one). A load on a closed service still computes for its caller but
|
|
33
33
|
* never touches tracking, registration, or cache.
|
|
34
34
|
*
|
|
35
|
+
* An owner/source handoff uses a source generation: entries retain the
|
|
36
|
+
* generation that produced them and old entries are last-good only. A
|
|
37
|
+
* pre-handoff result is marked stale when the DTO supports it, or failed when
|
|
38
|
+
* it does not (`SessionSnapshot`), so the previous owner's data is never
|
|
39
|
+
* presented as fresh.
|
|
40
|
+
*
|
|
35
41
|
* No TTL, sequence, watermark, or budget machinery exists (R9).
|
|
36
42
|
*/
|
|
37
43
|
import { encodeAnalyticsGroupQueryKey } from "../contracts/analytics-entity.js";
|
|
@@ -130,13 +136,27 @@ function payloadIsStale(snapshot) {
|
|
|
130
136
|
return false;
|
|
131
137
|
return staleFlag(snapshot.usage);
|
|
132
138
|
}
|
|
139
|
+
/** True when the contract carries the top-level `stale` marker. */
|
|
140
|
+
function hasStaleMarker(snapshot) {
|
|
141
|
+
return typeof snapshot === "object" && snapshot !== null && "stale" in snapshot;
|
|
142
|
+
}
|
|
133
143
|
/** Session snapshots have no `stale` field; they are served as-is. */
|
|
134
144
|
function markStale(snapshot) {
|
|
135
|
-
if (
|
|
145
|
+
if (!hasStaleMarker(snapshot))
|
|
136
146
|
return snapshot;
|
|
137
|
-
}
|
|
138
147
|
return { ...snapshot, stale: true };
|
|
139
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* A source handoff completed while a load that cannot carry the `stale` marker
|
|
151
|
+
* was still in flight. Failing is safer than returning the previous owner's
|
|
152
|
+
* payload as fresh; the transport maps it like any other snapshot failure.
|
|
153
|
+
*/
|
|
154
|
+
class SnapshotSourceChangedError extends Error {
|
|
155
|
+
constructor() {
|
|
156
|
+
super("Snapshot source changed before the snapshot completed");
|
|
157
|
+
this.name = "SnapshotSourceChangedError";
|
|
158
|
+
}
|
|
159
|
+
}
|
|
140
160
|
/** Safe log label: an allowlisted-shape code, never a raw message. */
|
|
141
161
|
function failureLabel(error) {
|
|
142
162
|
if (error !== null && typeof error === "object" && "code" in error) {
|
|
@@ -150,6 +170,8 @@ export function createSnapshotService(options) {
|
|
|
150
170
|
const logger = options.logger ?? createGuiLogger();
|
|
151
171
|
const now = options.now ?? Date.now;
|
|
152
172
|
const cache = new Map();
|
|
173
|
+
let quotaRefresh;
|
|
174
|
+
let quotaPoll;
|
|
153
175
|
const computes = new Map();
|
|
154
176
|
const inflight = new Map();
|
|
155
177
|
const listeners = new Set();
|
|
@@ -157,15 +179,31 @@ export function createSnapshotService(options) {
|
|
|
157
179
|
const tracked = new Map();
|
|
158
180
|
let versionCounter = 0;
|
|
159
181
|
let viewers = 0;
|
|
182
|
+
/**
|
|
183
|
+
* Scoped viewers are real consumers with their own active surface. Legacy
|
|
184
|
+
* (HTTP/SSE) viewers stay unscoped and vote through `viewScope`; the effective
|
|
185
|
+
* scope below aggregates both instead of letting the last signal win.
|
|
186
|
+
*/
|
|
187
|
+
const scopedViewers = new Map();
|
|
188
|
+
let nextScopedViewerId = 1;
|
|
160
189
|
/**
|
|
161
190
|
* Bumped when the viewer session ends (last disconnect or close). It disowns
|
|
162
191
|
* in-flight poll ticks and any HTTP cache commit started before that point.
|
|
163
192
|
*/
|
|
164
193
|
let viewerEpoch = 0;
|
|
194
|
+
/**
|
|
195
|
+
* Bumped when the active source identity changes (owner handoff). The cache
|
|
196
|
+
* remains as last-good fallback, but pre-handoff commits and poll results must
|
|
197
|
+
* not freshen it, and a new request must not join a pre-handoff task.
|
|
198
|
+
*/
|
|
199
|
+
let sourceGeneration = 0;
|
|
165
200
|
let viewScope = "analytics";
|
|
166
201
|
/** Explicit UI signal outranks read-request inference for this viewer session. */
|
|
167
202
|
let viewScopeExplicit = false;
|
|
168
203
|
let quotaTimer;
|
|
204
|
+
let quotaRetryTimer;
|
|
205
|
+
let quotaRetried = false;
|
|
206
|
+
let pollerEpoch = 0;
|
|
169
207
|
let analyticsTimer;
|
|
170
208
|
let quotaTicking = false;
|
|
171
209
|
let analyticsTicking = false;
|
|
@@ -222,6 +260,45 @@ export function createSnapshotService(options) {
|
|
|
222
260
|
function analyticsIntervalMs() {
|
|
223
261
|
return readInterval(options.analyticsIntervalMs, DEFAULT_ANALYTICS_INTERVAL_MS);
|
|
224
262
|
}
|
|
263
|
+
/**
|
|
264
|
+
* True when any real consumer still needs analytics. A scoped analytics
|
|
265
|
+
* viewer always wins, so a quota signal from a concurrent window cannot stop
|
|
266
|
+
* another window's refresh. Legacy viewers vote through `viewScope`; with no
|
|
267
|
+
* legacy viewer only scoped interests count.
|
|
268
|
+
*/
|
|
269
|
+
function analyticsViewActive() {
|
|
270
|
+
for (const scope of scopedViewers.values()) {
|
|
271
|
+
if (scope === "analytics")
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
const legacyViewers = viewers - scopedViewers.size;
|
|
275
|
+
return legacyViewers > 0 && viewScope === "analytics";
|
|
276
|
+
}
|
|
277
|
+
function retainViewer() {
|
|
278
|
+
if (closed)
|
|
279
|
+
return;
|
|
280
|
+
viewers += 1;
|
|
281
|
+
if (viewers === 1)
|
|
282
|
+
startPollers();
|
|
283
|
+
}
|
|
284
|
+
function releaseViewer() {
|
|
285
|
+
if (closed)
|
|
286
|
+
return;
|
|
287
|
+
viewers = Math.max(0, viewers - 1);
|
|
288
|
+
if (viewers === 0) {
|
|
289
|
+
stopPollers();
|
|
290
|
+
// End the viewer session: abandoned ticks poll no further keys, a
|
|
291
|
+
// reconnect starts with no stale poll interests, and pages are only
|
|
292
|
+
// polled again after an actual load re-registers them. Scope signals are
|
|
293
|
+
// viewer-scoped and reset with it.
|
|
294
|
+
viewerEpoch += 1;
|
|
295
|
+
viewScope = "analytics";
|
|
296
|
+
viewScopeExplicit = false;
|
|
297
|
+
scopedViewers.clear();
|
|
298
|
+
computes.clear();
|
|
299
|
+
dirty();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
225
302
|
function emit(event) {
|
|
226
303
|
// Copy before calling out: a listener may unsubscribe while it runs.
|
|
227
304
|
for (const listener of Array.from(listeners)) {
|
|
@@ -274,8 +351,9 @@ export function createSnapshotService(options) {
|
|
|
274
351
|
}
|
|
275
352
|
return version;
|
|
276
353
|
}
|
|
277
|
-
function load(key, compute) {
|
|
354
|
+
function load(key, compute, force = false) {
|
|
278
355
|
const epoch = viewerEpoch;
|
|
356
|
+
const generation = sourceGeneration;
|
|
279
357
|
// A closed service does not track, register, or cache: the caller still
|
|
280
358
|
// gets its computation, but a probe (or a late request) cannot repopulate
|
|
281
359
|
// state that close() released.
|
|
@@ -283,23 +361,28 @@ export function createSnapshotService(options) {
|
|
|
283
361
|
if (!closed)
|
|
284
362
|
computes.set(key, compute);
|
|
285
363
|
const existing = cache.get(key);
|
|
286
|
-
if (
|
|
364
|
+
if (!force &&
|
|
365
|
+
existing &&
|
|
366
|
+
existing.sourceGeneration === sourceGeneration &&
|
|
367
|
+
(!existing.stale ||
|
|
368
|
+
(isQuotaKey(key) && !existing.invalidated && payloadIsStale(existing.snapshot)))) {
|
|
287
369
|
// SAFETY: `load<T>` is only called with a key built from `(kind, resourceId,
|
|
288
370
|
// range)`, and the entry under this key was stored by a compute of that key.
|
|
289
371
|
return Promise.resolve(existing.snapshot);
|
|
290
372
|
}
|
|
291
373
|
const pending = inflight.get(key);
|
|
292
|
-
if (pending && pending.epoch === epoch) {
|
|
293
|
-
// The key was requested again in the same viewer session
|
|
294
|
-
// was still pending: preserve single-flight
|
|
374
|
+
if (pending && pending.epoch === epoch && pending.sourceGeneration === generation) {
|
|
375
|
+
// The key was requested again in the same viewer session and source
|
|
376
|
+
// generation while its compute was still pending: preserve single-flight
|
|
377
|
+
// and let it cache again.
|
|
295
378
|
if (!closed)
|
|
296
379
|
pending.version = version;
|
|
297
380
|
// SAFETY: same key contract as the cache above; the inflight task was created
|
|
298
381
|
// by a `load<T>` call for this exact key.
|
|
299
382
|
return pending.promise;
|
|
300
383
|
}
|
|
301
|
-
// A pending task from an ended viewer session
|
|
302
|
-
//
|
|
384
|
+
// A pending task from an ended viewer session or a previous source identity
|
|
385
|
+
// is disowned: this caller runs its own compute instead.
|
|
303
386
|
let computation;
|
|
304
387
|
try {
|
|
305
388
|
computation = compute();
|
|
@@ -307,13 +390,42 @@ export function createSnapshotService(options) {
|
|
|
307
390
|
catch (error) {
|
|
308
391
|
computation = Promise.reject(error);
|
|
309
392
|
}
|
|
310
|
-
const task = {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
393
|
+
const task = {
|
|
394
|
+
epoch,
|
|
395
|
+
sourceGeneration: generation,
|
|
396
|
+
promise: Promise.resolve(),
|
|
397
|
+
version,
|
|
398
|
+
};
|
|
399
|
+
const attempt = (async () => {
|
|
400
|
+
let snapshot;
|
|
401
|
+
try {
|
|
402
|
+
snapshot = await computation;
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
const fallback = tracked.get(key) === task.version ? cache.get(key) : undefined;
|
|
406
|
+
if (!fallback)
|
|
407
|
+
throw error;
|
|
408
|
+
// A previous owner's last-good entry may be served only when the DTO
|
|
409
|
+
// can carry the stale marker. Session snapshots cannot, so their
|
|
410
|
+
// failure is surfaced rather than presented as fresh old-owner data.
|
|
411
|
+
if (fallback.sourceGeneration !== sourceGeneration && !hasStaleMarker(fallback.snapshot)) {
|
|
412
|
+
throw error;
|
|
413
|
+
}
|
|
414
|
+
if (!closed && task.epoch === viewerEpoch && task.sourceGeneration === sourceGeneration) {
|
|
415
|
+
fallback.stale = true;
|
|
416
|
+
logger.warn("snapshot compute failed; serving last good snapshot", failureLabel(error));
|
|
417
|
+
}
|
|
418
|
+
// SAFETY: the cached entry under this key is a previous successful compute
|
|
419
|
+
// of the same `(kind, resourceId, range)` key, so it is a T snapshot.
|
|
420
|
+
return markStale(fallback.snapshot);
|
|
421
|
+
}
|
|
422
|
+
// A commit belongs to the viewer session and source identity that started
|
|
423
|
+
// the load: a disconnect or owner handoff already dirtied the entries, so
|
|
424
|
+
// an old result never re-freshens them.
|
|
425
|
+
if (!closed &&
|
|
426
|
+
task.epoch === viewerEpoch &&
|
|
427
|
+
task.sourceGeneration === sourceGeneration &&
|
|
428
|
+
tracked.get(key) === task.version) {
|
|
317
429
|
cache.set(key, {
|
|
318
430
|
snapshot,
|
|
319
431
|
substantive: substantiveOf(snapshot),
|
|
@@ -321,23 +433,21 @@ export function createSnapshotService(options) {
|
|
|
321
433
|
// for this caller; the next read must recompute rather than serve
|
|
322
434
|
// stale data as fresh until the next poll.
|
|
323
435
|
stale: payloadIsStale(snapshot),
|
|
436
|
+
sourceGeneration: task.sourceGeneration,
|
|
324
437
|
});
|
|
438
|
+
return snapshot;
|
|
325
439
|
}
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
fallback.stale = true;
|
|
334
|
-
logger.warn("snapshot compute failed; serving last good snapshot", failureLabel(error));
|
|
440
|
+
if (task.sourceGeneration !== sourceGeneration) {
|
|
441
|
+
// A handoff happened while this load was in flight. Never present the
|
|
442
|
+
// previous owner's payload as fresh: mark it when the contract supports
|
|
443
|
+
// it, otherwise fail like a post-handoff read would.
|
|
444
|
+
if (!hasStaleMarker(snapshot))
|
|
445
|
+
throw new SnapshotSourceChangedError();
|
|
446
|
+
return markStale(snapshot);
|
|
335
447
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
})
|
|
340
|
-
.finally(() => {
|
|
448
|
+
return snapshot;
|
|
449
|
+
})();
|
|
450
|
+
task.promise = attempt.finally(() => {
|
|
341
451
|
// Never delete a newer task that replaced this one after reconnect.
|
|
342
452
|
if (inflight.get(key) === task)
|
|
343
453
|
inflight.delete(key);
|
|
@@ -349,7 +459,8 @@ export function createSnapshotService(options) {
|
|
|
349
459
|
* Polls one registered key. Returns false when the viewer session ended or
|
|
350
460
|
* the service closed and the tick must stop.
|
|
351
461
|
*/
|
|
352
|
-
async function pollOne(key, compute, epoch, changed) {
|
|
462
|
+
async function pollOne(key, compute, epoch, changed, onSnapshot) {
|
|
463
|
+
const generation = sourceGeneration;
|
|
353
464
|
if (closed || viewerEpoch !== epoch || viewers === 0)
|
|
354
465
|
return false;
|
|
355
466
|
if (computes.get(key) !== compute)
|
|
@@ -365,10 +476,12 @@ export function createSnapshotService(options) {
|
|
|
365
476
|
}
|
|
366
477
|
catch (error) {
|
|
367
478
|
// A key evicted (or re-loaded) while the poll was pending must not be
|
|
368
|
-
// marked current by this late result; an ended viewer session
|
|
369
|
-
// be updated or logged for at all.
|
|
479
|
+
// marked current by this late result; an ended viewer session or a
|
|
480
|
+
// previous source identity must not be updated or logged for at all.
|
|
370
481
|
if (closed || viewerEpoch !== epoch || viewers === 0)
|
|
371
482
|
return false;
|
|
483
|
+
if (sourceGeneration !== generation)
|
|
484
|
+
return false;
|
|
372
485
|
if (tracked.get(key) === version && computes.get(key) === compute) {
|
|
373
486
|
const entry = cache.get(key);
|
|
374
487
|
if (entry)
|
|
@@ -378,40 +491,97 @@ export function createSnapshotService(options) {
|
|
|
378
491
|
return true;
|
|
379
492
|
}
|
|
380
493
|
// Late poll results never resurrect an evicted key, overwrite a key loaded
|
|
381
|
-
// again mid-poll,
|
|
494
|
+
// again mid-poll, land in a viewer session that has ended, or cross a
|
|
495
|
+
// source-identity handoff.
|
|
382
496
|
if (closed || viewerEpoch !== epoch || viewers === 0)
|
|
383
497
|
return false;
|
|
498
|
+
if (sourceGeneration !== generation)
|
|
499
|
+
return false;
|
|
384
500
|
if (tracked.get(key) !== version || computes.get(key) !== compute)
|
|
385
501
|
return true;
|
|
386
502
|
const substantive = substantiveOf(snapshot);
|
|
387
503
|
const entry = cache.get(key);
|
|
388
|
-
const
|
|
389
|
-
|
|
504
|
+
const stale = payloadIsStale(snapshot);
|
|
505
|
+
const changedNow = entry === undefined ||
|
|
506
|
+
entry.stale !== stale ||
|
|
507
|
+
entry.substantive !== substantive ||
|
|
508
|
+
(isQuotaKey(key) &&
|
|
509
|
+
entry.snapshot.providers.polledAtMs !==
|
|
510
|
+
snapshot.providers.polledAtMs);
|
|
511
|
+
cache.set(key, {
|
|
512
|
+
snapshot,
|
|
513
|
+
substantive,
|
|
514
|
+
stale,
|
|
515
|
+
sourceGeneration: generation,
|
|
516
|
+
});
|
|
517
|
+
onSnapshot?.(snapshot);
|
|
390
518
|
if (changedNow)
|
|
391
519
|
changed.add(topicFor(key));
|
|
392
520
|
return true;
|
|
393
521
|
}
|
|
394
|
-
async function tickQuota() {
|
|
395
|
-
if (quotaTicking || closed || viewers === 0)
|
|
522
|
+
async function tickQuota(earlyRetry = false) {
|
|
523
|
+
if (quotaTicking || quotaRefresh || closed || viewers === 0)
|
|
396
524
|
return;
|
|
525
|
+
if (!earlyRetry && quotaRetryTimer) {
|
|
526
|
+
clearTimeout(quotaRetryTimer);
|
|
527
|
+
quotaRetryTimer = undefined;
|
|
528
|
+
quotaRetried = true;
|
|
529
|
+
}
|
|
397
530
|
quotaTicking = true;
|
|
398
531
|
const epoch = viewerEpoch;
|
|
532
|
+
const tickPollerEpoch = pollerEpoch;
|
|
533
|
+
const generation = sourceGeneration;
|
|
399
534
|
const changed = new Set();
|
|
535
|
+
let polledSnapshot;
|
|
400
536
|
try {
|
|
401
537
|
// Copy before the async body: `load` can register new computes while a
|
|
402
538
|
// tick awaits, and one tick must not grow while it runs.
|
|
403
539
|
for (const [key, compute] of Array.from(computes)) {
|
|
404
540
|
if (kindOf(key) !== "quota")
|
|
405
541
|
continue;
|
|
406
|
-
|
|
407
|
-
|
|
542
|
+
const poll = pollOne(key, compute, epoch, changed, (snapshot) => {
|
|
543
|
+
polledSnapshot = snapshot;
|
|
544
|
+
});
|
|
545
|
+
quotaPoll = poll;
|
|
546
|
+
try {
|
|
547
|
+
if (!(await poll))
|
|
548
|
+
break;
|
|
549
|
+
}
|
|
550
|
+
finally {
|
|
551
|
+
if (quotaPoll === poll)
|
|
552
|
+
quotaPoll = undefined;
|
|
553
|
+
}
|
|
408
554
|
}
|
|
409
555
|
}
|
|
410
556
|
finally {
|
|
411
557
|
quotaTicking = false;
|
|
412
558
|
}
|
|
413
|
-
if (closed || viewerEpoch !== epoch)
|
|
559
|
+
if (closed || viewerEpoch !== epoch || pollerEpoch !== tickPollerEpoch)
|
|
414
560
|
return;
|
|
561
|
+
if (sourceGeneration !== generation)
|
|
562
|
+
return;
|
|
563
|
+
if (polledSnapshot) {
|
|
564
|
+
const eligible = polledSnapshot.providers.cards.some((card) => card.errors.some((error) => error.kind !== "intentional-filter" &&
|
|
565
|
+
(error.failureCategory === "provider_api" ||
|
|
566
|
+
error.failureCategory === "discovery" ||
|
|
567
|
+
error.failureCategory === "local") &&
|
|
568
|
+
!(error.retryAtMs !== undefined && error.retryAtMs > now())));
|
|
569
|
+
if (!eligible) {
|
|
570
|
+
quotaRetried = false;
|
|
571
|
+
if (quotaRetryTimer)
|
|
572
|
+
clearTimeout(quotaRetryTimer);
|
|
573
|
+
quotaRetryTimer = undefined;
|
|
574
|
+
}
|
|
575
|
+
else if (!earlyRetry && !quotaRetried && !quotaRetryTimer && !quotaRefresh) {
|
|
576
|
+
// quota-state caches per provider, so healthy accounts within the failed provider may also be re-requested once per episode.
|
|
577
|
+
quotaRetryTimer = setTimeout(() => {
|
|
578
|
+
quotaRetryTimer = undefined;
|
|
579
|
+
quotaRetried = true;
|
|
580
|
+
void tickQuota(true);
|
|
581
|
+
}, Math.min(10_000, quotaIntervalMs()));
|
|
582
|
+
quotaRetryTimer.unref();
|
|
583
|
+
}
|
|
584
|
+
}
|
|
415
585
|
if (changed.has("quota.changed"))
|
|
416
586
|
emit({ topic: "quota.changed", at: now() });
|
|
417
587
|
}
|
|
@@ -426,9 +596,10 @@ export function createSnapshotService(options) {
|
|
|
426
596
|
}
|
|
427
597
|
if (closed || viewers === 0)
|
|
428
598
|
return;
|
|
429
|
-
// Visited once is not an active interest:
|
|
430
|
-
// analytics refresh or range derivation runs even
|
|
431
|
-
|
|
599
|
+
// Visited once is not an active interest: while every live viewer is on
|
|
600
|
+
// the quota surface, no analytics refresh or range derivation runs even
|
|
601
|
+
// though keys are loaded.
|
|
602
|
+
if (!analyticsViewActive())
|
|
432
603
|
return;
|
|
433
604
|
const epoch = viewerEpoch;
|
|
434
605
|
// Analytics interests are exactly the loaded home/project/session keys.
|
|
@@ -487,6 +658,11 @@ export function createSnapshotService(options) {
|
|
|
487
658
|
analyticsTimer.unref();
|
|
488
659
|
}
|
|
489
660
|
function stopPollers() {
|
|
661
|
+
pollerEpoch += 1;
|
|
662
|
+
if (quotaRetryTimer)
|
|
663
|
+
clearTimeout(quotaRetryTimer);
|
|
664
|
+
quotaRetryTimer = undefined;
|
|
665
|
+
quotaRetried = false;
|
|
490
666
|
if (quotaTimer) {
|
|
491
667
|
clearInterval(quotaTimer);
|
|
492
668
|
quotaTimer = undefined;
|
|
@@ -504,17 +680,51 @@ export function createSnapshotService(options) {
|
|
|
504
680
|
startPollers();
|
|
505
681
|
}
|
|
506
682
|
function dirty() {
|
|
507
|
-
for (const entry of cache.values())
|
|
683
|
+
for (const entry of cache.values()) {
|
|
508
684
|
entry.stale = true;
|
|
685
|
+
entry.invalidated = true;
|
|
686
|
+
}
|
|
509
687
|
}
|
|
510
688
|
return {
|
|
511
689
|
home: (input) => load(homeKey(input.range), () => options.source.home({ range: input.range })),
|
|
512
|
-
quota: () =>
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
690
|
+
quota: (input) => {
|
|
691
|
+
const compute = () => {
|
|
692
|
+
if (!options.source.quota) {
|
|
693
|
+
return Promise.reject(new Error("Quota source unavailable"));
|
|
694
|
+
}
|
|
695
|
+
return options.source.quota();
|
|
696
|
+
};
|
|
697
|
+
if (!input?.refresh)
|
|
698
|
+
return load(quotaKey(), compute);
|
|
699
|
+
if (quotaRefresh)
|
|
700
|
+
return quotaRefresh;
|
|
701
|
+
const refresh = (async () => {
|
|
702
|
+
await quotaPoll;
|
|
703
|
+
await inflight.get(quotaKey())?.promise.catch(() => undefined);
|
|
704
|
+
const cached = cache.get(quotaKey());
|
|
705
|
+
if (cached)
|
|
706
|
+
cached.stale = true;
|
|
707
|
+
const forcedCompute = () => options.source.quota({ refresh: true });
|
|
708
|
+
try {
|
|
709
|
+
const result = await load(quotaKey(), forcedCompute, true);
|
|
710
|
+
if (!closed)
|
|
711
|
+
emit({ topic: "quota.changed", at: now() });
|
|
712
|
+
return result;
|
|
713
|
+
}
|
|
714
|
+
finally {
|
|
715
|
+
if (!closed && computes.get(quotaKey()) === forcedCompute)
|
|
716
|
+
computes.set(quotaKey(), compute);
|
|
717
|
+
}
|
|
718
|
+
})();
|
|
719
|
+
quotaRefresh = refresh;
|
|
720
|
+
void refresh
|
|
721
|
+
.finally(() => {
|
|
722
|
+
if (quotaRefresh === refresh)
|
|
723
|
+
quotaRefresh = undefined;
|
|
724
|
+
})
|
|
725
|
+
.catch(() => undefined);
|
|
726
|
+
return refresh;
|
|
727
|
+
},
|
|
518
728
|
project: (input) => load(projectKey(input.projectId, input.range), () => options.source.project({ projectId: input.projectId, range: input.range })),
|
|
519
729
|
session: (input) => load(sessionKey(input.sessionId), () => options.source.session({ sessionId: input.sessionId })),
|
|
520
730
|
groups: (query) => load(groupsKey(query), () => {
|
|
@@ -530,27 +740,31 @@ export function createSnapshotService(options) {
|
|
|
530
740
|
addViewer() {
|
|
531
741
|
if (closed)
|
|
532
742
|
return () => { };
|
|
533
|
-
|
|
534
|
-
if (viewers === 1)
|
|
535
|
-
startPollers();
|
|
743
|
+
retainViewer();
|
|
536
744
|
let released = false;
|
|
537
745
|
return () => {
|
|
538
746
|
if (released || closed)
|
|
539
747
|
return;
|
|
540
748
|
released = true;
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
749
|
+
releaseViewer();
|
|
750
|
+
};
|
|
751
|
+
},
|
|
752
|
+
addScopedViewer(scope) {
|
|
753
|
+
if (closed)
|
|
754
|
+
return { release: () => { } };
|
|
755
|
+
const id = nextScopedViewerId;
|
|
756
|
+
nextScopedViewerId += 1;
|
|
757
|
+
scopedViewers.set(id, scope);
|
|
758
|
+
retainViewer();
|
|
759
|
+
let released = false;
|
|
760
|
+
return {
|
|
761
|
+
release: () => {
|
|
762
|
+
if (released || closed)
|
|
763
|
+
return;
|
|
764
|
+
released = true;
|
|
765
|
+
scopedViewers.delete(id);
|
|
766
|
+
releaseViewer();
|
|
767
|
+
},
|
|
554
768
|
};
|
|
555
769
|
},
|
|
556
770
|
notifySettingsChanged(settingsOptions) {
|
|
@@ -559,8 +773,10 @@ export function createSnapshotService(options) {
|
|
|
559
773
|
if (settingsOptions?.scope !== "visibility") {
|
|
560
774
|
for (const [key, entry] of cache) {
|
|
561
775
|
const kind = kindOf(key);
|
|
562
|
-
if (kind === "quota" || kind === "home" || kind === "project")
|
|
776
|
+
if (kind === "quota" || kind === "home" || kind === "project") {
|
|
563
777
|
entry.stale = true;
|
|
778
|
+
entry.invalidated = true;
|
|
779
|
+
}
|
|
564
780
|
}
|
|
565
781
|
// Re-read both interval getters from live settings (R16).
|
|
566
782
|
restartPollers();
|
|
@@ -580,6 +796,20 @@ export function createSnapshotService(options) {
|
|
|
580
796
|
if (origin === "signal")
|
|
581
797
|
viewScopeExplicit = true;
|
|
582
798
|
},
|
|
799
|
+
sourceChanged() {
|
|
800
|
+
if (closed)
|
|
801
|
+
return;
|
|
802
|
+
if (quotaRetryTimer)
|
|
803
|
+
clearTimeout(quotaRetryTimer);
|
|
804
|
+
quotaRetryTimer = undefined;
|
|
805
|
+
quotaRetried = false;
|
|
806
|
+
// The cached payloads remain useful as last-good fallback, but they must
|
|
807
|
+
// never be served as fresh data from the previous owner.
|
|
808
|
+
sourceGeneration += 1;
|
|
809
|
+
dirty();
|
|
810
|
+
emit({ topic: "quota.changed", at: now() });
|
|
811
|
+
emit({ topic: "sessions.changed", at: now() });
|
|
812
|
+
},
|
|
583
813
|
close() {
|
|
584
814
|
if (closed)
|
|
585
815
|
return;
|
|
@@ -595,6 +825,7 @@ export function createSnapshotService(options) {
|
|
|
595
825
|
cache.clear();
|
|
596
826
|
inflight.clear();
|
|
597
827
|
tracked.clear();
|
|
828
|
+
scopedViewers.clear();
|
|
598
829
|
},
|
|
599
830
|
};
|
|
600
831
|
}
|
package/dist/gui/sources.d.ts
CHANGED
|
@@ -76,7 +76,7 @@ export type DashboardReadSource = Pick<DashboardDataSource, "home" | "quota" | "
|
|
|
76
76
|
refreshAnalytics?(): Promise<void>;
|
|
77
77
|
/** Worker background-generation notifications (lazy; never starts analytics). */
|
|
78
78
|
subscribeAnalytics?(listener: () => void): () => void;
|
|
79
|
-
/** Final
|
|
79
|
+
/** Final host-dispose cleanup; closes the analytics worker. */
|
|
80
80
|
close?(): Promise<void>;
|
|
81
81
|
};
|
|
82
82
|
/**
|