@slkiser/opencode-quota 4.10.6 → 5.0.0-beta.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 +42 -31
- package/dist/bin/opencode-quota.d.ts +6 -0
- package/dist/bin/opencode-quota.d.ts.map +1 -1
- package/dist/bin/opencode-quota.js +17 -0
- package/dist/bin/opencode-quota.js.map +1 -1
- package/dist/data/modelsdev-pricing.min.json +83 -2
- package/dist/index.d.ts +1 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -13
- package/dist/index.js.map +1 -1
- package/dist/lib/accounting-format.js +1 -1
- package/dist/lib/accounting-format.js.map +1 -1
- package/dist/lib/alibaba-auth.d.ts +5 -5
- package/dist/lib/alibaba-auth.d.ts.map +1 -1
- package/dist/lib/alibaba-auth.js +15 -8
- package/dist/lib/alibaba-auth.js.map +1 -1
- package/dist/lib/alibaba-token-plan.d.ts +7 -4
- package/dist/lib/alibaba-token-plan.d.ts.map +1 -1
- package/dist/lib/alibaba-token-plan.js +32 -10
- package/dist/lib/alibaba-token-plan.js.map +1 -1
- package/dist/lib/anthropic-auth.d.ts +4 -1
- package/dist/lib/anthropic-auth.d.ts.map +1 -1
- package/dist/lib/anthropic-auth.js +5 -1
- package/dist/lib/anthropic-auth.js.map +1 -1
- package/dist/lib/anthropic.d.ts +7 -1
- package/dist/lib/anthropic.d.ts.map +1 -1
- package/dist/lib/anthropic.js +61 -7
- package/dist/lib/anthropic.js.map +1 -1
- package/dist/lib/api-key-resolver.d.ts +27 -16
- package/dist/lib/api-key-resolver.d.ts.map +1 -1
- package/dist/lib/api-key-resolver.js +46 -19
- package/dist/lib/api-key-resolver.js.map +1 -1
- package/dist/lib/chutes-config.d.ts +2 -2
- package/dist/lib/chutes-config.d.ts.map +1 -1
- package/dist/lib/chutes-config.js +4 -4
- package/dist/lib/chutes-config.js.map +1 -1
- package/dist/lib/cli-reports.d.ts +30 -0
- package/dist/lib/cli-reports.d.ts.map +1 -0
- package/dist/lib/cli-reports.js +172 -0
- package/dist/lib/cli-reports.js.map +1 -0
- package/dist/lib/cli-show.d.ts +14 -1
- package/dist/lib/cli-show.d.ts.map +1 -1
- package/dist/lib/cli-show.js +40 -138
- package/dist/lib/cli-show.js.map +1 -1
- package/dist/lib/cli-status.d.ts.map +1 -1
- package/dist/lib/cli-status.js +9 -36
- package/dist/lib/cli-status.js.map +1 -1
- package/dist/lib/config-file-utils.d.ts +10 -13
- package/dist/lib/config-file-utils.d.ts.map +1 -1
- package/dist/lib/config-file-utils.js +28 -30
- package/dist/lib/config-file-utils.js.map +1 -1
- package/dist/lib/config.d.ts +2 -2
- package/dist/lib/config.d.ts.map +1 -1
- package/dist/lib/config.js +6 -17
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/copilot.d.ts +4 -1
- package/dist/lib/copilot.d.ts.map +1 -1
- package/dist/lib/copilot.js +17 -19
- package/dist/lib/copilot.js.map +1 -1
- package/dist/lib/cursor-detection.d.ts +1 -1
- package/dist/lib/cursor-detection.d.ts.map +1 -1
- package/dist/lib/cursor-detection.js +54 -51
- package/dist/lib/cursor-detection.js.map +1 -1
- package/dist/lib/cursor-pricing.d.ts +1 -1
- package/dist/lib/cursor-pricing.d.ts.map +1 -1
- package/dist/lib/cursor-pricing.js +85 -0
- package/dist/lib/cursor-pricing.js.map +1 -1
- package/dist/lib/deepseek-auth.d.ts +2 -2
- package/dist/lib/deepseek-auth.d.ts.map +1 -1
- package/dist/lib/deepseek-auth.js +4 -4
- package/dist/lib/deepseek-auth.js.map +1 -1
- package/dist/lib/display-sanitize.js +1 -1
- package/dist/lib/display-sanitize.js.map +1 -1
- package/dist/lib/entries.d.ts +7 -2
- package/dist/lib/entries.d.ts.map +1 -1
- package/dist/lib/format-utils.d.ts +1 -1
- package/dist/lib/format-utils.js +1 -1
- package/dist/lib/glm-coding-plan.d.ts +1 -0
- package/dist/lib/glm-coding-plan.d.ts.map +1 -1
- package/dist/lib/glm-coding-plan.js +3 -1
- package/dist/lib/glm-coding-plan.js.map +1 -1
- package/dist/lib/google-agy.d.ts +6 -12
- package/dist/lib/google-agy.d.ts.map +1 -1
- package/dist/lib/google-agy.js +26 -24
- package/dist/lib/google-agy.js.map +1 -1
- package/dist/lib/google-companion-credentials.d.ts.map +1 -1
- package/dist/lib/google-companion-credentials.js +76 -26
- package/dist/lib/google-companion-credentials.js.map +1 -1
- package/dist/lib/google-gemini-cli.d.ts +7 -12
- package/dist/lib/google-gemini-cli.d.ts.map +1 -1
- package/dist/lib/google-gemini-cli.js +42 -31
- package/dist/lib/google-gemini-cli.js.map +1 -1
- package/dist/lib/init-installer.d.ts +3 -1
- package/dist/lib/init-installer.d.ts.map +1 -1
- package/dist/lib/init-installer.js +69 -172
- package/dist/lib/init-installer.js.map +1 -1
- package/dist/lib/kilo-config.d.ts +2 -2
- package/dist/lib/kilo-config.d.ts.map +1 -1
- package/dist/lib/kilo-config.js +6 -5
- package/dist/lib/kilo-config.js.map +1 -1
- package/dist/lib/kimi-auth.d.ts +2 -2
- package/dist/lib/kimi-auth.d.ts.map +1 -1
- package/dist/lib/kimi-auth.js +4 -4
- package/dist/lib/kimi-auth.js.map +1 -1
- package/dist/lib/maintainer-announcements.d.ts.map +1 -1
- package/dist/lib/maintainer-announcements.js +5 -5
- package/dist/lib/maintainer-announcements.js.map +1 -1
- package/dist/lib/mimo-config.d.ts.map +1 -1
- package/dist/lib/mimo-config.js +2 -3
- package/dist/lib/mimo-config.js.map +1 -1
- package/dist/lib/minimax-auth.d.ts +6 -6
- package/dist/lib/minimax-auth.d.ts.map +1 -1
- package/dist/lib/minimax-auth.js +18 -17
- package/dist/lib/minimax-auth.js.map +1 -1
- package/dist/lib/nanogpt-config.d.ts +2 -2
- package/dist/lib/nanogpt-config.d.ts.map +1 -1
- package/dist/lib/nanogpt-config.js +4 -4
- package/dist/lib/nanogpt-config.js.map +1 -1
- package/dist/lib/ollama-cloud-config.d.ts +2 -2
- package/dist/lib/ollama-cloud-config.d.ts.map +1 -1
- package/dist/lib/ollama-cloud-config.js +6 -5
- package/dist/lib/ollama-cloud-config.js.map +1 -1
- package/dist/lib/openai.d.ts +7 -2
- package/dist/lib/openai.d.ts.map +1 -1
- package/dist/lib/openai.js +22 -8
- package/dist/lib/openai.js.map +1 -1
- package/dist/lib/opencode-auth-sqlite.d.ts +17 -0
- package/dist/lib/opencode-auth-sqlite.d.ts.map +1 -0
- package/dist/lib/opencode-auth-sqlite.js +105 -0
- package/dist/lib/opencode-auth-sqlite.js.map +1 -0
- package/dist/lib/opencode-auth.d.ts +127 -14
- package/dist/lib/opencode-auth.d.ts.map +1 -1
- package/dist/lib/opencode-auth.js +373 -46
- package/dist/lib/opencode-auth.js.map +1 -1
- package/dist/lib/opencode-config-providers.d.ts.map +1 -1
- package/dist/lib/opencode-config-providers.js +17 -18
- package/dist/lib/opencode-config-providers.js.map +1 -1
- package/dist/lib/opencode-console-auth.d.ts +47 -0
- package/dist/lib/opencode-console-auth.d.ts.map +1 -0
- package/dist/lib/opencode-console-auth.js +63 -0
- package/dist/lib/opencode-console-auth.js.map +1 -0
- package/dist/lib/opencode-db-path.d.ts +9 -0
- package/dist/lib/opencode-db-path.d.ts.map +1 -0
- package/dist/lib/opencode-db-path.js +16 -0
- package/dist/lib/opencode-db-path.js.map +1 -0
- package/dist/lib/opencode-go-auth.d.ts +4 -2
- package/dist/lib/opencode-go-auth.d.ts.map +1 -1
- package/dist/lib/opencode-go-auth.js +9 -5
- package/dist/lib/opencode-go-auth.js.map +1 -1
- package/dist/lib/opencode-go.d.ts +12 -0
- package/dist/lib/opencode-go.d.ts.map +1 -1
- package/dist/lib/opencode-go.js +113 -0
- package/dist/lib/opencode-go.js.map +1 -1
- package/dist/lib/opencode-runtime-paths.d.ts +6 -12
- package/dist/lib/opencode-runtime-paths.d.ts.map +1 -1
- package/dist/lib/opencode-runtime-paths.js +12 -82
- package/dist/lib/opencode-runtime-paths.js.map +1 -1
- package/dist/lib/opencode-sqlite.d.ts +4 -0
- package/dist/lib/opencode-sqlite.d.ts.map +1 -1
- package/dist/lib/opencode-sqlite.js +17 -52
- package/dist/lib/opencode-sqlite.js.map +1 -1
- package/dist/lib/opencode-storage.d.ts +4 -8
- package/dist/lib/opencode-storage.d.ts.map +1 -1
- package/dist/lib/opencode-storage.js +66 -90
- package/dist/lib/opencode-storage.js.map +1 -1
- package/dist/lib/opencode-version.d.ts +6 -0
- package/dist/lib/opencode-version.d.ts.map +1 -0
- package/dist/lib/opencode-version.js +26 -0
- package/dist/lib/opencode-version.js.map +1 -0
- package/dist/lib/opencode-zen.d.ts +10 -4
- package/dist/lib/opencode-zen.d.ts.map +1 -1
- package/dist/lib/opencode-zen.js +11 -11
- package/dist/lib/opencode-zen.js.map +1 -1
- package/dist/lib/provider-registration.d.ts +3 -4
- package/dist/lib/provider-registration.d.ts.map +1 -1
- package/dist/lib/provider-registration.js +3 -4
- package/dist/lib/provider-registration.js.map +1 -1
- package/dist/lib/quota-dialog-command-specs.d.ts +59 -0
- package/dist/lib/quota-dialog-command-specs.d.ts.map +1 -0
- package/dist/lib/quota-dialog-command-specs.js +145 -0
- package/dist/lib/quota-dialog-command-specs.js.map +1 -0
- package/dist/lib/quota-dialog-commands.d.ts +1 -25
- package/dist/lib/quota-dialog-commands.d.ts.map +1 -1
- package/dist/lib/quota-dialog-commands.js +13 -132
- package/dist/lib/quota-dialog-commands.js.map +1 -1
- package/dist/lib/quota-export.d.ts.map +1 -1
- package/dist/lib/quota-export.js +1 -0
- package/dist/lib/quota-export.js.map +1 -1
- package/dist/lib/quota-providers-remote.d.ts +2 -2
- package/dist/lib/quota-providers-remote.d.ts.map +1 -1
- package/dist/lib/quota-providers-remote.js +6 -4
- package/dist/lib/quota-providers-remote.js.map +1 -1
- package/dist/lib/quota-render-data.d.ts +3 -0
- package/dist/lib/quota-render-data.d.ts.map +1 -1
- package/dist/lib/quota-render-data.js +2 -0
- package/dist/lib/quota-render-data.js.map +1 -1
- package/dist/lib/quota-report-message.d.ts +21 -0
- package/dist/lib/quota-report-message.d.ts.map +1 -0
- package/dist/lib/quota-report-message.js +40 -0
- package/dist/lib/quota-report-message.js.map +1 -0
- package/dist/lib/quota-runtime-context.d.ts +1 -0
- package/dist/lib/quota-runtime-context.d.ts.map +1 -1
- package/dist/lib/quota-runtime-context.js +1 -0
- package/dist/lib/quota-runtime-context.js.map +1 -1
- package/dist/lib/quota-state-codec.js +5 -5
- package/dist/lib/quota-state-codec.js.map +1 -1
- package/dist/lib/quota-stats.js +2 -1
- package/dist/lib/quota-stats.js.map +1 -1
- package/dist/lib/quota-status.d.ts +2 -10
- package/dist/lib/quota-status.d.ts.map +1 -1
- package/dist/lib/quota-status.js +33 -42
- package/dist/lib/quota-status.js.map +1 -1
- package/dist/lib/quota-surface-data.d.ts +26 -0
- package/dist/lib/quota-surface-data.d.ts.map +1 -0
- package/dist/lib/quota-surface-data.js +299 -0
- package/dist/lib/quota-surface-data.js.map +1 -0
- package/dist/lib/scoped-update-migration.d.ts +4 -4
- package/dist/lib/scoped-update-migration.d.ts.map +1 -1
- package/dist/lib/scoped-update-migration.js +11 -18
- package/dist/lib/scoped-update-migration.js.map +1 -1
- package/dist/lib/scoped-update.d.ts +5 -1
- package/dist/lib/scoped-update.d.ts.map +1 -1
- package/dist/lib/scoped-update.js +73 -51
- package/dist/lib/scoped-update.js.map +1 -1
- package/dist/lib/synthetic-config.d.ts +2 -2
- package/dist/lib/synthetic-config.d.ts.map +1 -1
- package/dist/lib/synthetic-config.js +4 -4
- package/dist/lib/synthetic-config.js.map +1 -1
- package/dist/lib/toast-format-grouped.js +1 -1
- package/dist/lib/toast-format-grouped.js.map +1 -1
- package/dist/lib/tui-panel-state.d.ts +0 -49
- package/dist/lib/tui-panel-state.d.ts.map +1 -1
- package/dist/lib/tui-panel-state.js +1 -41
- package/dist/lib/tui-panel-state.js.map +1 -1
- package/dist/lib/tui-sidebar-format.d.ts.map +1 -1
- package/dist/lib/tui-sidebar-format.js +8 -1
- package/dist/lib/tui-sidebar-format.js.map +1 -1
- package/dist/lib/types.d.ts +26 -7
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/types.js +1 -2
- package/dist/lib/types.js.map +1 -1
- package/dist/lib/xai.d.ts +5 -1
- package/dist/lib/xai.d.ts.map +1 -1
- package/dist/lib/xai.js +13 -4
- package/dist/lib/xai.js.map +1 -1
- package/dist/lib/zai-auth.d.ts +2 -2
- package/dist/lib/zai-auth.d.ts.map +1 -1
- package/dist/lib/zai-auth.js +4 -4
- package/dist/lib/zai-auth.js.map +1 -1
- package/dist/lib/zai.d.ts +1 -0
- package/dist/lib/zai.d.ts.map +1 -1
- package/dist/lib/zai.js.map +1 -1
- package/dist/lib/zhipu-auth.d.ts +2 -2
- package/dist/lib/zhipu-auth.d.ts.map +1 -1
- package/dist/lib/zhipu-auth.js +4 -4
- package/dist/lib/zhipu-auth.js.map +1 -1
- package/dist/lib/zhipu.d.ts +1 -0
- package/dist/lib/zhipu.d.ts.map +1 -1
- package/dist/lib/zhipu.js.map +1 -1
- package/dist/plugin.d.ts +6 -9
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +213 -259
- package/dist/plugin.js.map +1 -1
- package/dist/providers/alibaba-coding-plan.d.ts.map +1 -1
- package/dist/providers/alibaba-coding-plan.js +1 -1
- package/dist/providers/alibaba-coding-plan.js.map +1 -1
- package/dist/providers/alibaba-token-plan.d.ts.map +1 -1
- package/dist/providers/alibaba-token-plan.js +1 -0
- package/dist/providers/alibaba-token-plan.js.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +83 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/cache-policies.d.ts +2 -2
- package/dist/providers/cache-policies.d.ts.map +1 -1
- package/dist/providers/cache-policies.js +10 -9
- package/dist/providers/cache-policies.js.map +1 -1
- package/dist/providers/copilot.d.ts.map +1 -1
- package/dist/providers/copilot.js +60 -9
- package/dist/providers/copilot.js.map +1 -1
- package/dist/providers/deepseek.js +1 -1
- package/dist/providers/deepseek.js.map +1 -1
- package/dist/providers/glm-coding-plan-provider.d.ts +13 -1
- package/dist/providers/glm-coding-plan-provider.d.ts.map +1 -1
- package/dist/providers/glm-coding-plan-provider.js +53 -0
- package/dist/providers/glm-coding-plan-provider.js.map +1 -1
- package/dist/providers/google-agy.d.ts.map +1 -1
- package/dist/providers/google-agy.js +56 -7
- package/dist/providers/google-agy.js.map +1 -1
- package/dist/providers/google-gemini-cli.d.ts.map +1 -1
- package/dist/providers/google-gemini-cli.js +72 -7
- package/dist/providers/google-gemini-cli.js.map +1 -1
- package/dist/providers/kilo.js +1 -1
- package/dist/providers/kilo.js.map +1 -1
- package/dist/providers/kimi-code.d.ts.map +1 -1
- package/dist/providers/kimi-code.js +60 -1
- package/dist/providers/kimi-code.js.map +1 -1
- package/dist/providers/minimax-coding-plan.d.ts.map +1 -1
- package/dist/providers/minimax-coding-plan.js +52 -1
- package/dist/providers/minimax-coding-plan.js.map +1 -1
- package/dist/providers/nanogpt.js +1 -1
- package/dist/providers/nanogpt.js.map +1 -1
- package/dist/providers/ollama-cloud.js +1 -1
- package/dist/providers/ollama-cloud.js.map +1 -1
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +59 -29
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/opencode-go.d.ts.map +1 -1
- package/dist/providers/opencode-go.js +207 -55
- package/dist/providers/opencode-go.js.map +1 -1
- package/dist/providers/opencode-zen.d.ts.map +1 -1
- package/dist/providers/opencode-zen.js +37 -51
- package/dist/providers/opencode-zen.js.map +1 -1
- package/dist/providers/openrouter.js +1 -1
- package/dist/providers/openrouter.js.map +1 -1
- package/dist/providers/quota-providers.js +9 -9
- package/dist/providers/quota-providers.js.map +1 -1
- package/dist/providers/result-helpers.d.ts +2 -2
- package/dist/providers/result-helpers.d.ts.map +1 -1
- package/dist/providers/result-helpers.js +2 -2
- package/dist/providers/result-helpers.js.map +1 -1
- package/dist/providers/xai.d.ts.map +1 -1
- package/dist/providers/xai.js +49 -1
- package/dist/providers/xai.js.map +1 -1
- package/dist/providers/zai.d.ts.map +1 -1
- package/dist/providers/zai.js +3 -1
- package/dist/providers/zai.js.map +1 -1
- package/dist/providers/zhipu.d.ts.map +1 -1
- package/dist/providers/zhipu.js +3 -1
- package/dist/providers/zhipu.js.map +1 -1
- package/dist/rpc.d.ts +72 -0
- package/dist/rpc.d.ts.map +1 -0
- package/dist/rpc.js +77 -0
- package/dist/rpc.js.map +1 -0
- package/dist/tui-v2.d.ts +5 -0
- package/dist/tui-v2.d.ts.map +1 -0
- package/dist/tui-v2.jsx +498 -0
- package/dist/tui-v2.jsx.map +1 -0
- package/dist/tui.d.ts +4 -6
- package/dist/tui.d.ts.map +1 -1
- package/dist/tui.js +542 -955
- package/package.json +7 -19
- package/dist/lib/cache.d.ts +0 -39
- package/dist/lib/cache.d.ts.map +0 -1
- package/dist/lib/cache.js +0 -124
- package/dist/lib/cache.js.map +0 -1
- package/dist/lib/command-handled.d.ts +0 -17
- package/dist/lib/command-handled.d.ts.map +0 -1
- package/dist/lib/command-handled.js +0 -36
- package/dist/lib/command-handled.js.map +0 -1
- package/dist/lib/command-surfaces.d.ts +0 -10
- package/dist/lib/command-surfaces.d.ts.map +0 -1
- package/dist/lib/command-surfaces.js +0 -9
- package/dist/lib/command-surfaces.js.map +0 -1
- package/dist/lib/opencode-zen-config.d.ts +0 -33
- package/dist/lib/opencode-zen-config.d.ts.map +0 -1
- package/dist/lib/opencode-zen-config.js +0 -158
- package/dist/lib/opencode-zen-config.js.map +0 -1
- package/dist/lib/path-pick.d.ts +0 -2
- package/dist/lib/path-pick.d.ts.map +0 -1
- package/dist/lib/path-pick.js +0 -15
- package/dist/lib/path-pick.js.map +0 -1
- package/dist/lib/quota-toast-runtime.d.ts +0 -60
- package/dist/lib/quota-toast-runtime.d.ts.map +0 -1
- package/dist/lib/quota-toast-runtime.js +0 -766
- package/dist/lib/quota-toast-runtime.js.map +0 -1
- package/dist/lib/tui-config-diagnostics.d.ts +0 -17
- package/dist/lib/tui-config-diagnostics.d.ts.map +0 -1
- package/dist/lib/tui-config-diagnostics.js +0 -72
- package/dist/lib/tui-config-diagnostics.js.map +0 -1
- package/dist/lib/tui-line-style.d.ts +0 -3
- package/dist/lib/tui-line-style.d.ts.map +0 -1
- package/dist/lib/tui-line-style.js +0 -7
- package/dist/lib/tui-line-style.js.map +0 -1
- package/dist/lib/tui-native-provider-quota.d.ts +0 -7
- package/dist/lib/tui-native-provider-quota.d.ts.map +0 -1
- package/dist/lib/tui-native-provider-quota.js +0 -25
- package/dist/lib/tui-native-provider-quota.js.map +0 -1
- package/dist/lib/tui-refresh-lifecycle.d.ts +0 -17
- package/dist/lib/tui-refresh-lifecycle.d.ts.map +0 -1
- package/dist/lib/tui-refresh-lifecycle.js +0 -82
- package/dist/lib/tui-refresh-lifecycle.js.map +0 -1
- package/dist/lib/tui-runtime.d.ts +0 -84
- package/dist/lib/tui-runtime.d.ts.map +0 -1
- package/dist/lib/tui-runtime.js +0 -527
- package/dist/lib/tui-runtime.js.map +0 -1
- package/dist/lib/tui-sidebar-content.d.ts +0 -32
- package/dist/lib/tui-sidebar-content.d.ts.map +0 -1
- package/dist/lib/tui-sidebar-content.js +0 -52
- package/dist/lib/tui-sidebar-content.js.map +0 -1
- package/dist/tui.tsx +0 -1030
|
@@ -1,766 +0,0 @@
|
|
|
1
|
-
import { getProviders } from "../providers/registry.js";
|
|
2
|
-
import { DEFAULT_ALIBABA_AUTH_CACHE_MAX_AGE_MS, isAlibabaModelId, resolveAlibabaCodingPlanAuthCached, } from "./alibaba-auth.js";
|
|
3
|
-
import { getOrFetchWithCacheControl } from "./cache.js";
|
|
4
|
-
import { createLoadConfigMeta } from "./config.js";
|
|
5
|
-
import { isCursorModelId, isCursorProviderId } from "./cursor-pricing.js";
|
|
6
|
-
import { sanitizeDisplayText } from "./display-sanitize.js";
|
|
7
|
-
import { formatQuotaRows } from "./format.js";
|
|
8
|
-
import { formatQuotaModeHeading } from "./format-utils.js";
|
|
9
|
-
import { BUNDLED_MAINTAINER_ANNOUNCEMENTS, formatMaintainerAnnouncementHomeCountLine, getMaintainerAnnouncementsSummary, } from "./maintainer-announcements.js";
|
|
10
|
-
import { maybeRefreshPricingSnapshot, setPricingSnapshotAutoRefresh, setPricingSnapshotSelection, } from "./modelsdev-pricing.js";
|
|
11
|
-
import { resolveQuotaFormatStyle } from "./quota-format-style.js";
|
|
12
|
-
import { customQuotaProviderDefinitions, QUOTA_PROVIDERS_AGGREGATE_ID } from "./quota-providers.js";
|
|
13
|
-
import { collectQuotaRenderData, } from "./quota-render-data.js";
|
|
14
|
-
import { formatQuotaResetNotification, observeQuotaResetNotifications, } from "./quota-reset-notifications.js";
|
|
15
|
-
import { createQuotaRuntimeRequestContext, resolveQuotaRuntimeContext, } from "./quota-runtime-context.js";
|
|
16
|
-
import { inspectTuiConfig } from "./tui-config-diagnostics.js";
|
|
17
|
-
import { DEFAULT_CONFIG } from "./types.js";
|
|
18
|
-
const DEFERRED_QUOTA_REFRESH_DELAYS_MS = [3_000, 15_000, 60_000, 300_000];
|
|
19
|
-
export function createQuotaToastRuntime(dependencies) {
|
|
20
|
-
let config = DEFAULT_CONFIG;
|
|
21
|
-
let configLoaded = false;
|
|
22
|
-
let configInFlight = null;
|
|
23
|
-
let configMeta = createLoadConfigMeta();
|
|
24
|
-
let runtimeProviders = getProviders();
|
|
25
|
-
let initDone = false;
|
|
26
|
-
const deferredQuotaRefreshes = new Map();
|
|
27
|
-
const detectedProviderIdsByToastCacheKey = new Map();
|
|
28
|
-
const maintainerAnnouncementToastFallback = {
|
|
29
|
-
pending: true,
|
|
30
|
-
inFlight: false,
|
|
31
|
-
};
|
|
32
|
-
function getDeferredQuotaRefreshDelayMs(attempts) {
|
|
33
|
-
const index = Math.min(Math.max(0, attempts), DEFERRED_QUOTA_REFRESH_DELAYS_MS.length - 1);
|
|
34
|
-
return DEFERRED_QUOTA_REFRESH_DELAYS_MS[index];
|
|
35
|
-
}
|
|
36
|
-
function clearDeferredQuotaRefresh(sessionID) {
|
|
37
|
-
const state = deferredQuotaRefreshes.get(sessionID);
|
|
38
|
-
if (state?.timer) {
|
|
39
|
-
clearTimeout(state.timer);
|
|
40
|
-
}
|
|
41
|
-
deferredQuotaRefreshes.delete(sessionID);
|
|
42
|
-
}
|
|
43
|
-
function clearDeferredQuotaRefreshTimer(state) {
|
|
44
|
-
if (!state.timer)
|
|
45
|
-
return;
|
|
46
|
-
clearTimeout(state.timer);
|
|
47
|
-
state.timer = null;
|
|
48
|
-
}
|
|
49
|
-
function scheduleDeferredQuotaRefresh(params) {
|
|
50
|
-
let state = deferredQuotaRefreshes.get(params.sessionID);
|
|
51
|
-
if (!state) {
|
|
52
|
-
state = {
|
|
53
|
-
sessionID: params.sessionID,
|
|
54
|
-
attempts: 0,
|
|
55
|
-
reason: params.reason,
|
|
56
|
-
queuedAtMs: Date.now(),
|
|
57
|
-
timer: null,
|
|
58
|
-
inFlight: false,
|
|
59
|
-
};
|
|
60
|
-
deferredQuotaRefreshes.set(params.sessionID, state);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
if (params.incrementAttempts) {
|
|
64
|
-
state.attempts += 1;
|
|
65
|
-
}
|
|
66
|
-
state.reason = params.reason;
|
|
67
|
-
clearDeferredQuotaRefreshTimer(state);
|
|
68
|
-
}
|
|
69
|
-
const delayMs = getDeferredQuotaRefreshDelayMs(state.attempts);
|
|
70
|
-
state.timer = setTimeout(() => {
|
|
71
|
-
void runDeferredQuotaRefresh(params.sessionID);
|
|
72
|
-
}, delayMs);
|
|
73
|
-
state.timer.unref?.();
|
|
74
|
-
void dependencies.log("Deferred quota refresh scheduled", {
|
|
75
|
-
sessionID: params.sessionID,
|
|
76
|
-
reason: params.reason,
|
|
77
|
-
attempts: state.attempts,
|
|
78
|
-
delayMs,
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
async function runDeferredQuotaRefresh(sessionID) {
|
|
82
|
-
const state = deferredQuotaRefreshes.get(sessionID);
|
|
83
|
-
if (!state || state.inFlight)
|
|
84
|
-
return;
|
|
85
|
-
await handleTriggerInternal({
|
|
86
|
-
sessionID,
|
|
87
|
-
trigger: "deferred.retry",
|
|
88
|
-
deferredRetry: true,
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
function isProviderEnabled(providerId) {
|
|
92
|
-
return config.enabledProviders === "auto" || config.enabledProviders.includes(providerId);
|
|
93
|
-
}
|
|
94
|
-
async function shouldBypassToastCacheForLiveLocalUsage(params) {
|
|
95
|
-
if (isProviderEnabled(QUOTA_PROVIDERS_AGGREGATE_ID) &&
|
|
96
|
-
customQuotaProviderDefinitions(config.quotaProviders).some((definition) => definition.mode === "local-estimate")) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
const currentSession = params.sessionMeta ?? (await dependencies.resolveSessionMeta(params.sessionID));
|
|
100
|
-
const currentModel = currentSession.modelID;
|
|
101
|
-
if (currentSession.providerID === "alibaba-coding-plan" ||
|
|
102
|
-
currentSession.providerID === "alibaba" ||
|
|
103
|
-
isAlibabaModelId(currentModel)) {
|
|
104
|
-
const plan = await resolveAlibabaCodingPlanAuthCached({
|
|
105
|
-
maxAgeMs: DEFAULT_ALIBABA_AUTH_CACHE_MAX_AGE_MS,
|
|
106
|
-
fallbackTier: "lite",
|
|
107
|
-
});
|
|
108
|
-
return plan.state === "configured" && isProviderEnabled("alibaba-coding-plan");
|
|
109
|
-
}
|
|
110
|
-
if (isCursorProviderId(currentSession.providerID) || isCursorModelId(currentModel)) {
|
|
111
|
-
return isProviderEnabled("cursor");
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
function buildToastCacheKey(params) {
|
|
116
|
-
const formatStyle = resolveQuotaFormatStyle(config.formatStyle);
|
|
117
|
-
const enabledProviders = config.enabledProviders === "auto" ? "auto" : config.enabledProviders.join(",");
|
|
118
|
-
const currentModel = config.onlyCurrentModel && params.sessionID ? (params.sessionMeta?.modelID ?? "") : "";
|
|
119
|
-
const currentProviderID = config.onlyCurrentModel && params.sessionID ? (params.sessionMeta?.providerID ?? "") : "";
|
|
120
|
-
const renderIdentity = JSON.stringify({
|
|
121
|
-
accountingDetail: config.accountingDetail,
|
|
122
|
-
quotaProjection: config.quotaProjection,
|
|
123
|
-
percentLabelStyle: config.percentLabelStyle,
|
|
124
|
-
resetTimeDecimals: config.resetTimeDecimals,
|
|
125
|
-
resetTimeSpaced: config.resetTimeSpaced,
|
|
126
|
-
sessionTokenScope: config.sessionTokenScope,
|
|
127
|
-
opencodeGoWindows: config.opencodeGoWindows,
|
|
128
|
-
opencodeMonthlyLimit: config.opencodeMonthlyLimit,
|
|
129
|
-
quotaProviders: config.quotaProviders,
|
|
130
|
-
});
|
|
131
|
-
const rootIdentity = JSON.stringify(dependencies.roots());
|
|
132
|
-
return [
|
|
133
|
-
`sessionID=${params.sessionID}`,
|
|
134
|
-
`enabledProviders=${enabledProviders}`,
|
|
135
|
-
`formatStyle=${formatStyle}`,
|
|
136
|
-
`percentDisplayMode=${config.percentDisplayMode}`,
|
|
137
|
-
`layout=${JSON.stringify(config.layout)}`,
|
|
138
|
-
`showSessionTokens=${config.showSessionTokens ? "yes" : "no"}`,
|
|
139
|
-
`onlyCurrentModel=${config.onlyCurrentModel ? "yes" : "no"}`,
|
|
140
|
-
`currentModel=${currentModel}`,
|
|
141
|
-
`currentProviderID=${currentProviderID}`,
|
|
142
|
-
`anthropicBinaryPath=${config.anthropicBinaryPath}`,
|
|
143
|
-
`cursorPlan=${config.cursorPlan}`,
|
|
144
|
-
`cursorIncludedApiUsd=${config.cursorIncludedApiUsd ?? ""}`,
|
|
145
|
-
`cursorBillingCycleStartDay=${config.cursorBillingCycleStartDay ?? ""}`,
|
|
146
|
-
`renderIdentity=${renderIdentity}`,
|
|
147
|
-
`rootIdentity=${rootIdentity}`,
|
|
148
|
-
].join("|");
|
|
149
|
-
}
|
|
150
|
-
async function kickPricingRefresh(params) {
|
|
151
|
-
try {
|
|
152
|
-
const refreshPromise = maybeRefreshPricingSnapshot({
|
|
153
|
-
reason: params.reason,
|
|
154
|
-
snapshotSelection: config.pricingSnapshot.source,
|
|
155
|
-
});
|
|
156
|
-
const guardedRefreshPromise = refreshPromise.catch(() => undefined);
|
|
157
|
-
if (!params.maxWaitMs || params.maxWaitMs <= 0) {
|
|
158
|
-
void guardedRefreshPromise;
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
await Promise.race([
|
|
162
|
-
guardedRefreshPromise,
|
|
163
|
-
new Promise((resolve) => {
|
|
164
|
-
setTimeout(resolve, params.maxWaitMs);
|
|
165
|
-
}),
|
|
166
|
-
]);
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
await dependencies.log("Pricing refresh failed", {
|
|
170
|
-
reason: params.reason,
|
|
171
|
-
error: error instanceof Error ? error.message : String(error),
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
function onFirstConfigLoaded() {
|
|
176
|
-
if (initDone)
|
|
177
|
-
return;
|
|
178
|
-
initDone = true;
|
|
179
|
-
if (config.enabled) {
|
|
180
|
-
void kickPricingRefresh({ reason: "init" });
|
|
181
|
-
}
|
|
182
|
-
dependencies.onInitialized({
|
|
183
|
-
configLoaded,
|
|
184
|
-
configSource: configMeta.source,
|
|
185
|
-
configPaths: configMeta.paths,
|
|
186
|
-
enabledProviders: config.enabledProviders,
|
|
187
|
-
minIntervalMs: config.minIntervalMs,
|
|
188
|
-
cursorPlan: config.cursorPlan,
|
|
189
|
-
cursorIncludedApiUsd: config.cursorIncludedApiUsd,
|
|
190
|
-
cursorBillingCycleStartDay: config.cursorBillingCycleStartDay,
|
|
191
|
-
pricingSnapshotSource: config.pricingSnapshot.source,
|
|
192
|
-
pricingSnapshotAutoRefresh: config.pricingSnapshot.autoRefresh,
|
|
193
|
-
showOnIdle: config.showOnIdle,
|
|
194
|
-
showOnQuestion: config.showOnQuestion,
|
|
195
|
-
showOnCompact: config.showOnCompact,
|
|
196
|
-
showOnBothFail: config.showOnBothFail,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
async function refreshConfig() {
|
|
200
|
-
if (configInFlight)
|
|
201
|
-
return configInFlight;
|
|
202
|
-
configInFlight = (async () => {
|
|
203
|
-
try {
|
|
204
|
-
const runtime = await resolveQuotaRuntimeContext({
|
|
205
|
-
client: dependencies.client,
|
|
206
|
-
roots: dependencies.roots(),
|
|
207
|
-
});
|
|
208
|
-
configMeta = runtime.configMeta;
|
|
209
|
-
config = runtime.config;
|
|
210
|
-
runtimeProviders = runtime.providers;
|
|
211
|
-
setPricingSnapshotAutoRefresh(config.pricingSnapshot.autoRefresh);
|
|
212
|
-
setPricingSnapshotSelection(config.pricingSnapshot.source);
|
|
213
|
-
configLoaded = true;
|
|
214
|
-
onFirstConfigLoaded();
|
|
215
|
-
}
|
|
216
|
-
catch {
|
|
217
|
-
config = DEFAULT_CONFIG;
|
|
218
|
-
configMeta = createLoadConfigMeta();
|
|
219
|
-
runtimeProviders = getProviders();
|
|
220
|
-
setPricingSnapshotAutoRefresh(DEFAULT_CONFIG.pricingSnapshot.autoRefresh);
|
|
221
|
-
setPricingSnapshotSelection(DEFAULT_CONFIG.pricingSnapshot.source);
|
|
222
|
-
}
|
|
223
|
-
finally {
|
|
224
|
-
configInFlight = null;
|
|
225
|
-
}
|
|
226
|
-
})();
|
|
227
|
-
return configInFlight;
|
|
228
|
-
}
|
|
229
|
-
async function resolvePluginRuntimeContext(params) {
|
|
230
|
-
return resolveQuotaRuntimeContext({
|
|
231
|
-
client: dependencies.client,
|
|
232
|
-
roots: dependencies.roots(),
|
|
233
|
-
config,
|
|
234
|
-
configMeta,
|
|
235
|
-
providers: runtimeProviders,
|
|
236
|
-
sessionID: params.sessionID,
|
|
237
|
-
sessionMeta: params.sessionMeta,
|
|
238
|
-
resolveSessionMeta: dependencies.resolveSessionMeta,
|
|
239
|
-
includeSessionMeta: (runtimeConfig) => runtimeConfig.onlyCurrentModel,
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
function emptyCollectionResult(params) {
|
|
243
|
-
return {
|
|
244
|
-
message: params.message,
|
|
245
|
-
cacheRenderedMessage: false,
|
|
246
|
-
retryable: params.retryable,
|
|
247
|
-
retryReason: params.retryReason,
|
|
248
|
-
hasQuotaRows: false,
|
|
249
|
-
detectedProviderIds: [],
|
|
250
|
-
freshProviderResults: [],
|
|
251
|
-
shouldReconcileDetectedProviders: false,
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
async function fetchQuotaMessageResult(params) {
|
|
255
|
-
if (!configLoaded) {
|
|
256
|
-
await refreshConfig();
|
|
257
|
-
}
|
|
258
|
-
if (!configLoaded) {
|
|
259
|
-
return emptyCollectionResult({
|
|
260
|
-
message: config.debug
|
|
261
|
-
? formatQuotaToastDebugInfo({
|
|
262
|
-
trigger: params.trigger,
|
|
263
|
-
reason: "config load failed",
|
|
264
|
-
config,
|
|
265
|
-
configMeta,
|
|
266
|
-
})
|
|
267
|
-
: null,
|
|
268
|
-
retryable: true,
|
|
269
|
-
retryReason: "config_load_failed",
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
if (!config.enabled) {
|
|
273
|
-
return emptyCollectionResult({
|
|
274
|
-
message: config.debug
|
|
275
|
-
? formatQuotaToastDebugInfo({
|
|
276
|
-
trigger: params.trigger,
|
|
277
|
-
reason: "disabled",
|
|
278
|
-
config,
|
|
279
|
-
configMeta,
|
|
280
|
-
})
|
|
281
|
-
: null,
|
|
282
|
-
retryable: false,
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
if (config.enabledProviders !== "auto" && config.enabledProviders.length === 0) {
|
|
286
|
-
return emptyCollectionResult({
|
|
287
|
-
message: config.debug
|
|
288
|
-
? formatQuotaToastDebugInfo({
|
|
289
|
-
trigger: params.trigger,
|
|
290
|
-
reason: "enabledProviders empty",
|
|
291
|
-
config,
|
|
292
|
-
configMeta,
|
|
293
|
-
})
|
|
294
|
-
: null,
|
|
295
|
-
retryable: false,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
const runtime = await resolvePluginRuntimeContext({
|
|
299
|
-
sessionID: params.sessionID,
|
|
300
|
-
sessionMeta: params.sessionMeta,
|
|
301
|
-
});
|
|
302
|
-
const collection = await collectQuotaToastMessage({
|
|
303
|
-
trigger: params.trigger,
|
|
304
|
-
runtime,
|
|
305
|
-
bypassProviderCache: params.bypassProviderCache,
|
|
306
|
-
});
|
|
307
|
-
if (collection.shouldReconcileDetectedProviders) {
|
|
308
|
-
await dependencies.reconcileDetectedProviders(collection.detectedProviderIds);
|
|
309
|
-
}
|
|
310
|
-
if (runtime.config.showSessionTokens) {
|
|
311
|
-
dependencies.setSessionTokenError(collection.sessionTokenError);
|
|
312
|
-
}
|
|
313
|
-
return collection;
|
|
314
|
-
}
|
|
315
|
-
async function reconcileDeferredQuotaRefresh(params) {
|
|
316
|
-
const existing = deferredQuotaRefreshes.get(params.sessionID);
|
|
317
|
-
if (!params.result.retryable) {
|
|
318
|
-
if (existing) {
|
|
319
|
-
clearDeferredQuotaRefresh(params.sessionID);
|
|
320
|
-
await dependencies.log("Deferred quota refresh cleared", {
|
|
321
|
-
sessionID: params.sessionID,
|
|
322
|
-
trigger: params.trigger,
|
|
323
|
-
reason: params.result.hasQuotaRows ? "quota_rows_available" : "not_retryable",
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
if (!params.result.retryReason)
|
|
329
|
-
return;
|
|
330
|
-
scheduleDeferredQuotaRefresh({
|
|
331
|
-
sessionID: params.sessionID,
|
|
332
|
-
reason: params.result.retryReason,
|
|
333
|
-
incrementAttempts: params.consumedDeferredRetry,
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
function isTriggerEnabled(trigger) {
|
|
337
|
-
if (trigger === "session.idle")
|
|
338
|
-
return config.showOnIdle;
|
|
339
|
-
if (trigger === "session.compacted")
|
|
340
|
-
return config.showOnCompact;
|
|
341
|
-
if (trigger === "question")
|
|
342
|
-
return config.showOnQuestion;
|
|
343
|
-
return trigger === "deferred.retry";
|
|
344
|
-
}
|
|
345
|
-
function triggerMaintainerAnnouncementToastFallback(trigger, detectedProviderIds, runtimeConfig) {
|
|
346
|
-
if (!maintainerAnnouncementToastFallback.pending ||
|
|
347
|
-
maintainerAnnouncementToastFallback.inFlight) {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
if (!runtimeConfig.enabled || !runtimeConfig.enableToast) {
|
|
351
|
-
maintainerAnnouncementToastFallback.pending = false;
|
|
352
|
-
return;
|
|
353
|
-
}
|
|
354
|
-
if (!runtimeConfig.maintainerAnnouncements.enabled ||
|
|
355
|
-
!runtimeConfig.maintainerAnnouncements.home) {
|
|
356
|
-
maintainerAnnouncementToastFallback.pending = false;
|
|
357
|
-
return;
|
|
358
|
-
}
|
|
359
|
-
maintainerAnnouncementToastFallback.inFlight = true;
|
|
360
|
-
void (async () => {
|
|
361
|
-
try {
|
|
362
|
-
const summary = getMaintainerAnnouncementsSummary({
|
|
363
|
-
announcements: BUNDLED_MAINTAINER_ANNOUNCEMENTS,
|
|
364
|
-
enabledProviders: detectedProviderIds,
|
|
365
|
-
});
|
|
366
|
-
if (summary.activeCount <= 0) {
|
|
367
|
-
if (summary.futureCount <= 0) {
|
|
368
|
-
maintainerAnnouncementToastFallback.pending = false;
|
|
369
|
-
}
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
const tuiDiagnostics = await inspectTuiConfig({ roots: dependencies.roots() });
|
|
373
|
-
if (tuiDiagnostics.quotaPluginConfigured) {
|
|
374
|
-
maintainerAnnouncementToastFallback.pending = false;
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
const message = formatMaintainerAnnouncementHomeCountLine(summary.activeCount);
|
|
378
|
-
if (!message)
|
|
379
|
-
return;
|
|
380
|
-
await dependencies.showToast({
|
|
381
|
-
message: sanitizeDisplayText(message),
|
|
382
|
-
variant: "info",
|
|
383
|
-
duration: runtimeConfig.toastDurationMs,
|
|
384
|
-
});
|
|
385
|
-
maintainerAnnouncementToastFallback.pending = false;
|
|
386
|
-
await dependencies.log("Displayed maintainer announcement fallback toast", { trigger });
|
|
387
|
-
}
|
|
388
|
-
catch (error) {
|
|
389
|
-
await dependencies.log("Failed to show maintainer announcement fallback toast", {
|
|
390
|
-
trigger,
|
|
391
|
-
error: error instanceof Error ? error.message : String(error),
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
finally {
|
|
395
|
-
maintainerAnnouncementToastFallback.inFlight = false;
|
|
396
|
-
}
|
|
397
|
-
})();
|
|
398
|
-
}
|
|
399
|
-
async function emitQuotaToastPlan(params) {
|
|
400
|
-
const { config: runtimeConfig, message, detectedProviderIds, freshProviderResults, } = params.plan;
|
|
401
|
-
let resetNotification;
|
|
402
|
-
if (runtimeConfig.enableToast &&
|
|
403
|
-
runtimeConfig.resetNotifications.enabled &&
|
|
404
|
-
freshProviderResults.length > 0) {
|
|
405
|
-
try {
|
|
406
|
-
const notices = await observeQuotaResetNotifications({
|
|
407
|
-
providers: freshProviderResults,
|
|
408
|
-
windows: runtimeConfig.resetNotifications.windows,
|
|
409
|
-
});
|
|
410
|
-
resetNotification = formatQuotaResetNotification(notices) ?? undefined;
|
|
411
|
-
}
|
|
412
|
-
catch (error) {
|
|
413
|
-
await dependencies.log("Failed to observe quota reset transitions", {
|
|
414
|
-
error: error instanceof Error ? error.message : String(error),
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
if (params.plan.deferredRetryResult) {
|
|
419
|
-
await dependencies.log("Deferred quota refresh did not produce reportable data", {
|
|
420
|
-
sessionID: params.sessionID,
|
|
421
|
-
trigger: params.trigger,
|
|
422
|
-
retryable: params.plan.deferredRetryResult.retryable,
|
|
423
|
-
retryReason: params.plan.deferredRetryResult.retryReason,
|
|
424
|
-
});
|
|
425
|
-
return;
|
|
426
|
-
}
|
|
427
|
-
if (!message) {
|
|
428
|
-
await dependencies.log("No quota message to display", { trigger: params.trigger });
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
if (!runtimeConfig.enableToast) {
|
|
432
|
-
await dependencies.log("Toast disabled (enableToast=false)", { trigger: params.trigger });
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
try {
|
|
436
|
-
await dependencies.showToast({
|
|
437
|
-
...(runtimeConfig.percentLabelStyle === "bare"
|
|
438
|
-
? { title: formatQuotaModeHeading(runtimeConfig.percentDisplayMode) }
|
|
439
|
-
: {}),
|
|
440
|
-
message: sanitizeDisplayText(message),
|
|
441
|
-
variant: "info",
|
|
442
|
-
duration: runtimeConfig.toastDurationMs,
|
|
443
|
-
});
|
|
444
|
-
triggerMaintainerAnnouncementToastFallback(params.trigger, detectedProviderIds, runtimeConfig);
|
|
445
|
-
await dependencies.log("Displayed quota toast", { message, trigger: params.trigger });
|
|
446
|
-
if (resetNotification) {
|
|
447
|
-
await dependencies.showToast({
|
|
448
|
-
title: "Quota available",
|
|
449
|
-
message: sanitizeDisplayText(resetNotification),
|
|
450
|
-
variant: "success",
|
|
451
|
-
duration: runtimeConfig.toastDurationMs,
|
|
452
|
-
});
|
|
453
|
-
await dependencies.log("Displayed quota reset notification", {
|
|
454
|
-
message: resetNotification,
|
|
455
|
-
trigger: params.trigger,
|
|
456
|
-
});
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
catch (error) {
|
|
460
|
-
await dependencies.log("Failed to show toast", {
|
|
461
|
-
error: error instanceof Error ? error.message : String(error),
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
async function prepareTrigger(params) {
|
|
466
|
-
if (!configLoaded) {
|
|
467
|
-
await refreshConfig();
|
|
468
|
-
}
|
|
469
|
-
if (!config.enabled) {
|
|
470
|
-
clearDeferredQuotaRefresh(params.sessionID);
|
|
471
|
-
return null;
|
|
472
|
-
}
|
|
473
|
-
if (!isTriggerEnabled(params.trigger))
|
|
474
|
-
return null;
|
|
475
|
-
const pendingDeferred = deferredQuotaRefreshes.get(params.sessionID);
|
|
476
|
-
const consumedDeferredRetry = params.deferredRetry === true || Boolean(pendingDeferred);
|
|
477
|
-
if (pendingDeferred) {
|
|
478
|
-
if (pendingDeferred.inFlight && !params.deferredRetry) {
|
|
479
|
-
await dependencies.log("Skipping duplicate deferred quota refresh", {
|
|
480
|
-
sessionID: params.sessionID,
|
|
481
|
-
trigger: params.trigger,
|
|
482
|
-
});
|
|
483
|
-
return null;
|
|
484
|
-
}
|
|
485
|
-
pendingDeferred.inFlight = true;
|
|
486
|
-
clearDeferredQuotaRefreshTimer(pendingDeferred);
|
|
487
|
-
}
|
|
488
|
-
let planPrepared = false;
|
|
489
|
-
let completed = false;
|
|
490
|
-
const complete = () => {
|
|
491
|
-
if (completed)
|
|
492
|
-
return;
|
|
493
|
-
completed = true;
|
|
494
|
-
const state = deferredQuotaRefreshes.get(params.sessionID);
|
|
495
|
-
if (state && state === pendingDeferred) {
|
|
496
|
-
state.inFlight = false;
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
try {
|
|
500
|
-
if (await dependencies.isSubagentSession(params.sessionID)) {
|
|
501
|
-
if (consumedDeferredRetry) {
|
|
502
|
-
clearDeferredQuotaRefresh(params.sessionID);
|
|
503
|
-
}
|
|
504
|
-
await dependencies.log("Skipping toast for subagent session", {
|
|
505
|
-
sessionID: params.sessionID,
|
|
506
|
-
trigger: params.trigger,
|
|
507
|
-
});
|
|
508
|
-
return null;
|
|
509
|
-
}
|
|
510
|
-
const sessionMeta = await dependencies.resolveSessionMeta(params.sessionID);
|
|
511
|
-
const bypassForLiveLocalUsage = await shouldBypassToastCacheForLiveLocalUsage({
|
|
512
|
-
sessionID: params.sessionID,
|
|
513
|
-
sessionMeta,
|
|
514
|
-
});
|
|
515
|
-
const bypassMessageCache = config.debug || consumedDeferredRetry || bypassForLiveLocalUsage;
|
|
516
|
-
const bypassProviderCache = consumedDeferredRetry || bypassForLiveLocalUsage;
|
|
517
|
-
const toastCacheKey = buildToastCacheKey({
|
|
518
|
-
sessionID: params.sessionID,
|
|
519
|
-
sessionMeta,
|
|
520
|
-
});
|
|
521
|
-
let fetchResult;
|
|
522
|
-
const fetchForToast = () => fetchQuotaMessageResult({
|
|
523
|
-
trigger: params.trigger,
|
|
524
|
-
sessionID: params.sessionID,
|
|
525
|
-
sessionMeta,
|
|
526
|
-
bypassProviderCache,
|
|
527
|
-
});
|
|
528
|
-
const message = bypassMessageCache
|
|
529
|
-
? await (async () => {
|
|
530
|
-
fetchResult = await fetchForToast();
|
|
531
|
-
return fetchResult.message;
|
|
532
|
-
})()
|
|
533
|
-
: await (async () => {
|
|
534
|
-
const fetched = {};
|
|
535
|
-
const cachedMessage = await getOrFetchWithCacheControl(toastCacheKey, async () => {
|
|
536
|
-
const result = await fetchForToast();
|
|
537
|
-
fetched.result = result;
|
|
538
|
-
return {
|
|
539
|
-
message: result.message,
|
|
540
|
-
cache: Boolean(result.message && result.cacheRenderedMessage && result.hasQuotaRows),
|
|
541
|
-
};
|
|
542
|
-
}, config.minIntervalMs);
|
|
543
|
-
fetchResult = fetched.result;
|
|
544
|
-
return cachedMessage;
|
|
545
|
-
})();
|
|
546
|
-
if (fetchResult) {
|
|
547
|
-
detectedProviderIdsByToastCacheKey.set(toastCacheKey, [...fetchResult.detectedProviderIds]);
|
|
548
|
-
await reconcileDeferredQuotaRefresh({
|
|
549
|
-
sessionID: params.sessionID,
|
|
550
|
-
result: fetchResult,
|
|
551
|
-
consumedDeferredRetry,
|
|
552
|
-
trigger: params.trigger,
|
|
553
|
-
});
|
|
554
|
-
}
|
|
555
|
-
planPrepared = true;
|
|
556
|
-
return {
|
|
557
|
-
config,
|
|
558
|
-
message,
|
|
559
|
-
detectedProviderIds: fetchResult?.detectedProviderIds ??
|
|
560
|
-
detectedProviderIdsByToastCacheKey.get(toastCacheKey) ??
|
|
561
|
-
[],
|
|
562
|
-
freshProviderResults: fetchResult?.freshProviderResults ?? [],
|
|
563
|
-
complete,
|
|
564
|
-
deferredRetryResult: params.deferredRetry && fetchResult && !fetchResult.hasQuotaRows
|
|
565
|
-
? {
|
|
566
|
-
retryable: fetchResult.retryable,
|
|
567
|
-
retryReason: fetchResult.retryReason,
|
|
568
|
-
}
|
|
569
|
-
: undefined,
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
finally {
|
|
573
|
-
if (!planPrepared)
|
|
574
|
-
complete();
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
async function handleTriggerInternal(params) {
|
|
578
|
-
const plan = await prepareTrigger(params);
|
|
579
|
-
if (!plan)
|
|
580
|
-
return;
|
|
581
|
-
try {
|
|
582
|
-
await emitQuotaToastPlan({ ...params, plan });
|
|
583
|
-
}
|
|
584
|
-
finally {
|
|
585
|
-
plan.complete();
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
async function handleTrigger(params) {
|
|
589
|
-
await handleTriggerInternal(params);
|
|
590
|
-
}
|
|
591
|
-
return { handleTrigger };
|
|
592
|
-
}
|
|
593
|
-
export function formatQuotaToastDebugInfo(params) {
|
|
594
|
-
const availability = params.availability
|
|
595
|
-
? params.availability.map((item) => `${item.id}=${item.ok ? "ok" : "no"}`).join(" ")
|
|
596
|
-
: "unknown";
|
|
597
|
-
const providers = params.config.enabledProviders === "auto"
|
|
598
|
-
? "(auto)"
|
|
599
|
-
: params.config.enabledProviders.length > 0
|
|
600
|
-
? params.config.enabledProviders.join(",")
|
|
601
|
-
: "(none)";
|
|
602
|
-
const modelPart = params.currentModel ? ` model=${params.currentModel}` : "";
|
|
603
|
-
const paths = params.configMeta.paths.length > 0 ? params.configMeta.paths.join(" | ") : "(none)";
|
|
604
|
-
return [
|
|
605
|
-
"Quota Toast Debug (opencode-quota)",
|
|
606
|
-
`trigger=${params.trigger} reason=${params.reason}`,
|
|
607
|
-
`configSource=${params.configMeta.source} paths=${paths}`,
|
|
608
|
-
`enabled=${params.config.enabled} providers=${providers}${modelPart}`,
|
|
609
|
-
`available=${availability}`,
|
|
610
|
-
].join("\n");
|
|
611
|
-
}
|
|
612
|
-
function hasRetryableProviderError(errors) {
|
|
613
|
-
return errors.some((error) => error.retryable === true);
|
|
614
|
-
}
|
|
615
|
-
export async function collectQuotaToastMessage(params) {
|
|
616
|
-
const runtimeConfig = params.runtime.config;
|
|
617
|
-
const quotaResult = await collectQuotaRenderData({
|
|
618
|
-
client: params.runtime.client,
|
|
619
|
-
resolveRuntimeProviderIds: params.runtime.resolveRuntimeProviderIds,
|
|
620
|
-
config: runtimeConfig,
|
|
621
|
-
configMeta: params.runtime.configMeta,
|
|
622
|
-
request: createQuotaRuntimeRequestContext(params.runtime),
|
|
623
|
-
surfaceExplicitProviderIssues: true,
|
|
624
|
-
formatStyle: resolveQuotaFormatStyle(runtimeConfig.formatStyle),
|
|
625
|
-
bypassProviderCache: params.bypassProviderCache,
|
|
626
|
-
providers: params.runtime.providers,
|
|
627
|
-
});
|
|
628
|
-
const { selection, availability, active, providerResults, attemptedAny, hasExplicitProviderIssues, data, } = quotaResult;
|
|
629
|
-
const detectedProviderIds = active.map((provider) => provider.id);
|
|
630
|
-
const collectionMetadata = {
|
|
631
|
-
detectedProviderIds,
|
|
632
|
-
freshProviderResults: providerResults,
|
|
633
|
-
sessionTokenError: quotaResult.sessionTokenError,
|
|
634
|
-
shouldReconcileDetectedProviders: selection?.isAutoMode === true,
|
|
635
|
-
};
|
|
636
|
-
const currentModel = selection?.currentModel;
|
|
637
|
-
const errors = data?.errors ?? [];
|
|
638
|
-
const hasProviderQuotaRows = Boolean(data?.entries.length);
|
|
639
|
-
const hasQuotaRows = Boolean(hasProviderQuotaRows || data?.sessionTokens);
|
|
640
|
-
const hasRetryableFetchFailure = attemptedAny && hasRetryableProviderError(errors);
|
|
641
|
-
const retryableAvailabilityFailure = active.length === 0 && availability.some((item) => !item.ok && item.error === true);
|
|
642
|
-
if (active.length === 0 && !(hasExplicitProviderIssues && errors.length > 0)) {
|
|
643
|
-
const message = runtimeConfig.debug
|
|
644
|
-
? formatQuotaToastDebugInfo({
|
|
645
|
-
trigger: params.trigger,
|
|
646
|
-
reason: "no enabled providers available",
|
|
647
|
-
config: runtimeConfig,
|
|
648
|
-
configMeta: params.runtime.configMeta,
|
|
649
|
-
currentModel,
|
|
650
|
-
availability: availability.map((item) => ({
|
|
651
|
-
id: item.provider.id,
|
|
652
|
-
ok: item.ok,
|
|
653
|
-
})),
|
|
654
|
-
})
|
|
655
|
-
: null;
|
|
656
|
-
const retryableNoProviders = selection?.isAutoMode === true || retryableAvailabilityFailure;
|
|
657
|
-
return {
|
|
658
|
-
message,
|
|
659
|
-
cacheRenderedMessage: false,
|
|
660
|
-
retryable: retryableNoProviders,
|
|
661
|
-
retryReason: retryableNoProviders ? "no_available_providers" : undefined,
|
|
662
|
-
hasQuotaRows: false,
|
|
663
|
-
...collectionMetadata,
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
if (hasQuotaRows) {
|
|
667
|
-
const formatted = formatQuotaRows({
|
|
668
|
-
version: "1.0.0",
|
|
669
|
-
layout: runtimeConfig.layout,
|
|
670
|
-
entries: data?.entries ?? [],
|
|
671
|
-
errors: data?.errors ?? [],
|
|
672
|
-
style: resolveQuotaFormatStyle(runtimeConfig.formatStyle),
|
|
673
|
-
percentDisplayMode: runtimeConfig.percentDisplayMode,
|
|
674
|
-
percentLabelStyle: runtimeConfig.percentLabelStyle,
|
|
675
|
-
accountingDetail: runtimeConfig.accountingDetail,
|
|
676
|
-
resetTimeDecimals: runtimeConfig.resetTimeDecimals,
|
|
677
|
-
resetTimeSpaced: runtimeConfig.resetTimeSpaced,
|
|
678
|
-
sessionTokens: data?.sessionTokens,
|
|
679
|
-
});
|
|
680
|
-
const retryableMaskedProviderFailure = !hasProviderQuotaRows && hasRetryableFetchFailure;
|
|
681
|
-
if (!runtimeConfig.debug) {
|
|
682
|
-
return {
|
|
683
|
-
message: formatted,
|
|
684
|
-
cacheRenderedMessage: true,
|
|
685
|
-
retryable: retryableMaskedProviderFailure,
|
|
686
|
-
retryReason: retryableMaskedProviderFailure ? "provider_fetch_failed" : undefined,
|
|
687
|
-
hasQuotaRows: true,
|
|
688
|
-
...collectionMetadata,
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
const debugFooter = `\n\n[debug] src=${params.runtime.configMeta.source} providers=${runtimeConfig.enabledProviders === "auto" ? "(auto)" : runtimeConfig.enabledProviders.join(",") || "(none)"} avail=${availability
|
|
692
|
-
.map((item) => `${item.provider.id}:${item.ok ? "ok" : "no"}`)
|
|
693
|
-
.join(" ")}`;
|
|
694
|
-
return {
|
|
695
|
-
message: formatted + debugFooter,
|
|
696
|
-
cacheRenderedMessage: false,
|
|
697
|
-
retryable: retryableMaskedProviderFailure,
|
|
698
|
-
retryReason: retryableMaskedProviderFailure ? "provider_fetch_failed" : undefined,
|
|
699
|
-
hasQuotaRows: true,
|
|
700
|
-
...collectionMetadata,
|
|
701
|
-
};
|
|
702
|
-
}
|
|
703
|
-
if ((runtimeConfig.showOnBothFail && attemptedAny && errors.length > 0) ||
|
|
704
|
-
hasExplicitProviderIssues) {
|
|
705
|
-
const errorLines = errors.map((error) => `${error.label}: ${error.message}`).join("\n");
|
|
706
|
-
const retryableFetchFailure = hasRetryableFetchFailure;
|
|
707
|
-
const retryableFailure = retryableFetchFailure || retryableAvailabilityFailure;
|
|
708
|
-
const retryReason = retryableFetchFailure
|
|
709
|
-
? "provider_fetch_failed"
|
|
710
|
-
: retryableAvailabilityFailure
|
|
711
|
-
? "no_available_providers"
|
|
712
|
-
: undefined;
|
|
713
|
-
const message = !runtimeConfig.debug
|
|
714
|
-
? errorLines || "Quota unavailable"
|
|
715
|
-
: (errorLines || "Quota unavailable") +
|
|
716
|
-
"\n\n" +
|
|
717
|
-
formatQuotaToastDebugInfo({
|
|
718
|
-
trigger: params.trigger,
|
|
719
|
-
reason: hasExplicitProviderIssues
|
|
720
|
-
? "providers missing/unavailable"
|
|
721
|
-
: "all providers failed",
|
|
722
|
-
config: runtimeConfig,
|
|
723
|
-
configMeta: params.runtime.configMeta,
|
|
724
|
-
currentModel,
|
|
725
|
-
availability: availability.map((item) => ({
|
|
726
|
-
id: item.provider.id,
|
|
727
|
-
ok: item.ok,
|
|
728
|
-
})),
|
|
729
|
-
});
|
|
730
|
-
return {
|
|
731
|
-
message,
|
|
732
|
-
cacheRenderedMessage: false,
|
|
733
|
-
retryable: retryableFailure,
|
|
734
|
-
retryReason,
|
|
735
|
-
hasQuotaRows: false,
|
|
736
|
-
...collectionMetadata,
|
|
737
|
-
};
|
|
738
|
-
}
|
|
739
|
-
const retryableNoData = hasRetryableFetchFailure ||
|
|
740
|
-
(selection?.isAutoMode === true && active.length > 0 && errors.length === 0);
|
|
741
|
-
return {
|
|
742
|
-
message: runtimeConfig.debug
|
|
743
|
-
? formatQuotaToastDebugInfo({
|
|
744
|
-
trigger: params.trigger,
|
|
745
|
-
reason: "no entries",
|
|
746
|
-
config: runtimeConfig,
|
|
747
|
-
configMeta: params.runtime.configMeta,
|
|
748
|
-
currentModel,
|
|
749
|
-
availability: availability.map((item) => ({
|
|
750
|
-
id: item.provider.id,
|
|
751
|
-
ok: item.ok,
|
|
752
|
-
})),
|
|
753
|
-
})
|
|
754
|
-
: null,
|
|
755
|
-
cacheRenderedMessage: false,
|
|
756
|
-
retryable: retryableNoData,
|
|
757
|
-
retryReason: hasRetryableFetchFailure
|
|
758
|
-
? "provider_fetch_failed"
|
|
759
|
-
: retryableNoData
|
|
760
|
-
? "no_reportable_data"
|
|
761
|
-
: undefined,
|
|
762
|
-
hasQuotaRows: false,
|
|
763
|
-
...collectionMetadata,
|
|
764
|
-
};
|
|
765
|
-
}
|
|
766
|
-
//# sourceMappingURL=quota-toast-runtime.js.map
|