@vantran-se/openchamber-web 1.22.2 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +7 -0
- package/dist/assets/{CodeMirrorCommentWidgets-CV1HNV5l.js → CodeMirrorCommentWidgets-DFg2wnpo.js} +1 -1
- package/dist/assets/DiffView-3Dn4QHbu.js +4 -0
- package/dist/assets/{DirtyBranchSwitchDialog-DW4WaXPc.js → DirtyBranchSwitchDialog-CwOerqVi.js} +1 -1
- package/dist/assets/FilesView-BdTOpew9.js +17 -0
- package/dist/assets/{GitView-1Ixo8z-M.js → GitView-Dqf9vHJh.js} +4 -4
- package/dist/assets/{JsonTreeView-DvCLL7dT.js → JsonTreeView-BKdsjg5B.js} +1 -1
- package/dist/assets/{LinearIssuesView-Bs1rZrF2.js → LinearIssuesView-CmbeL7I6.js} +1 -1
- package/dist/assets/MarkdownImageGallery-_5gEVr0X.js +1 -0
- package/dist/assets/MarkdownRendererImpl-wVZlx4dd.js +12 -0
- package/dist/assets/OnboardingScreen-DdP4_nuc.js +1 -0
- package/dist/assets/{PatchDiff-CAduNjfZ.js → PatchDiff-am3SAss2.js} +1 -1
- package/dist/assets/PierreDiffViewer-DCsydlKs.js +161 -0
- package/dist/assets/{PlanView-trDaszfq.js → PlanView-BoJxdRZe.js} +1 -1
- package/dist/assets/SettingsView-CcM8pF5O.js +28 -0
- package/dist/assets/{SettingsWindow-DQQFnrSZ.js → SettingsWindow-DVTdDSol.js} +1 -1
- package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
- package/dist/assets/{ToolOutputDialog-SjY2XZlA.js → ToolOutputDialog-BgfTbDZ4.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-DJdzUQPE.js → ToolPartDiffPreview-C7WLk5i9.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-Iehm4iMH.js → VirtualizedFileDiff-DcdgkH-x.js} +1 -1
- package/dist/assets/WalkthroughView-BEVUDxuw.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-BKZA43vN.js → computeVirtualFileMetrics-C8byMnRh.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-CirXEPJq.js +1 -0
- package/dist/assets/de-C8jV7J9y.js +10 -0
- package/dist/assets/es-BI6J1M5R.js +16 -0
- package/dist/assets/fr-D6oDFt7E.js +14 -0
- package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
- package/dist/assets/{index-Ce0LR32V.js → index-BB7ryz8y.js} +1 -1
- package/dist/assets/index-BqhiCmYS.js +39 -0
- package/dist/assets/index-FqSOBz0J.css +1 -0
- package/dist/assets/{isDiffPlainText-DaB2u_Kv.js → isDiffPlainText-45ujMPGb.js} +1 -1
- package/dist/assets/{isFilePlainText-yJZa2IAC.js → isFilePlainText-Cc4KFSYi.js} +1 -1
- package/dist/assets/ja-C_4i5EQu.js +16 -0
- package/dist/assets/ko-BFbOTpbq.js +16 -0
- package/dist/assets/{main-CyQrD9dG.js → main-C9ETLKFc.js} +2 -2
- package/dist/assets/main-CJmb2dF8.js +930 -0
- package/dist/assets/markdownCore-DVuZpnli.js +5 -0
- package/dist/assets/{miniChat-7cPEx4sV.js → miniChat-B4Ytoq2n.js} +2 -2
- package/dist/assets/{mobile-QtzkPTM8.js → mobile-BUT6-lo1.js} +2 -2
- package/dist/assets/patchFileDiff-8j1apICU.js +13 -0
- package/dist/assets/pl-COFvT56l.js +16 -0
- package/dist/assets/pt-BR-DtVOO2Lj.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-B6vUG-vF.js +2 -0
- package/dist/assets/renderMobileApp-BNgHraq6.js +25 -0
- package/dist/assets/runtimeEndpointReset-B8LYpWvr.js +17 -0
- package/dist/assets/scheduledTasksApi-GC4epIYA.js +1 -0
- package/dist/assets/{shikiHighlight-EHEg58-n.js → shikiHighlight-BJISeZsQ.js} +1 -1
- package/dist/assets/surface-BvRzS58U.js +1 -0
- package/dist/assets/tr-B8Q0Go2l.js +7 -0
- package/dist/assets/uk-Dk4a-Fn-.js +16 -0
- package/dist/assets/{useAppFontEffects-CuJPKtI1.js → useAppFontEffects-DpFNefUA.js} +143 -140
- package/dist/assets/useGitComparison-Dfxaqd0s.js +1 -0
- package/dist/assets/useInlineCommentController-CscsE4t-.js +2 -0
- package/dist/assets/useRootScrollLock-BaCvuRlT.js +1 -0
- package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-9ZzoH0o0.js → vendor-codemirror-language-data-DzlSIu_W.js} +2 -2
- package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
- package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
- package/dist/assets/{web-components-PttKBrhi.js → web-components-CdGfR2XJ.js} +1 -1
- package/dist/assets/zh-CN-B_BXxG1Q.js +16 -0
- package/dist/assets/zh-TW-DLrl1SPZ.js +16 -0
- package/dist/index.html +5 -43
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +2 -3
- package/server/index.d.ts +15 -0
- package/server/index.js +45 -9
- package/server/lib/data-dir-migration.js +40 -0
- package/server/lib/data-dir-migration.test.js +59 -0
- package/server/lib/event-stream/runtime.test.js +12 -12
- package/server/lib/fs/DOCUMENTATION.md +3 -0
- package/server/lib/fs/routes.js +31 -0
- package/server/lib/fs/routes.test.js +110 -1
- package/server/lib/git/DOCUMENTATION.md +29 -5
- package/server/lib/git/routes.js +24 -4
- package/server/lib/git/service.js +184 -198
- package/server/lib/git/service.test.js +422 -25
- package/server/lib/inherited-env.js +16 -9
- package/server/lib/inherited-env.test.js +8 -9
- package/server/lib/message-queue/DOCUMENTATION.md +4 -1
- package/server/lib/network-defaults.js +23 -0
- package/server/lib/network-defaults.test.js +52 -0
- package/server/lib/opencode/DOCUMENTATION.md +17 -1
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/openchamber-routes.js +64 -4
- package/server/lib/opencode/openchamber-routes.test.js +128 -1
- package/server/lib/opencode/routes.js +5 -3
- package/server/lib/opencode/settings-files.js +214 -0
- package/server/lib/opencode/settings-helpers.js +85 -41
- package/server/lib/opencode/settings-helpers.test.js +166 -1
- package/server/lib/opencode/settings-registry.json +747 -0
- package/server/lib/opencode/settings-runtime.js +139 -18
- package/server/lib/opencode/settings-runtime.test.js +163 -5
- package/server/lib/project-context/DOCUMENTATION.md +25 -1
- package/server/lib/project-context/routes.http.test.js +18 -0
- package/server/lib/project-context/routes.js +15 -0
- package/server/lib/project-context/runtime.js +248 -23
- package/server/lib/project-context/runtime.test.js +106 -3
- package/server/lib/projects/DOCUMENTATION.md +76 -0
- package/server/lib/projects/project-config.js +142 -9
- package/server/lib/projects/project-id.js +17 -0
- package/server/lib/projects/project-setup.js +409 -0
- package/server/lib/projects/project-setup.test.js +557 -0
- package/server/lib/projects/routes.js +59 -0
- package/server/lib/quota/DOCUMENTATION.md +38 -1
- package/server/lib/quota/index.js +1 -0
- package/server/lib/quota/providers/cline-pass.js +125 -0
- package/server/lib/quota/providers/cline-pass.test.js +103 -0
- package/server/lib/quota/providers/hyper.js +118 -0
- package/server/lib/quota/providers/hyper.test.js +126 -0
- package/server/lib/quota/providers/index.js +15 -0
- package/server/lib/quota/providers/neuralwatt.js +3 -6
- package/server/lib/quota/providers/neuralwatt.test.js +7 -7
- package/server/lib/quota/providers/ollama-cloud.js +31 -0
- package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
- package/server/lib/quota/providers/opencode-go.js +1 -1
- package/server/lib/quota/providers/opencode-go.test.js +26 -1
- package/server/lib/quota/providers/openrouter.js +119 -24
- package/server/lib/quota/providers/openrouter.test.js +330 -0
- package/server/lib/relay/DOCUMENTATION.md +55 -0
- package/server/lib/relay/cross-compat.test.js +26 -0
- package/server/lib/relay/downstream-scheduler.js +154 -0
- package/server/lib/relay/downstream-scheduler.test.js +162 -0
- package/server/lib/relay/e2ee.js +10 -8
- package/server/lib/relay/flow-control.test.js +177 -0
- package/server/lib/relay/host-client.js +37 -8
- package/server/lib/relay/tunnel-codec.js +9 -0
- package/server/lib/relay/tunnel-host.js +66 -17
- package/server/lib/session-assist/runtime.js +6 -10
- package/server/lib/session-goal/runtime.js +4 -9
- package/server/lib/small-model/DOCUMENTATION.md +3 -2
- package/server/lib/small-model/call.js +9 -4
- package/server/lib/small-model/call.test.js +29 -0
- package/server/lib/small-model/index.js +5 -10
- package/server/lib/small-model/runtime-providers.js +15 -7
- package/server/lib/small-model/runtime-providers.test.js +7 -1
- package/server/lib/terminal/DOCUMENTATION.md +4 -4
- package/server/lib/terminal/runtime.js +11 -6
- package/server/lib/terminal/runtime.test.js +20 -13
- package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
- package/server/lib/walkthrough/model-settings.js +8 -12
- package/server/lib/walkthrough/prompt.js +3 -1
- package/server/lib/walkthrough/sources.js +23 -2
- package/dist/assets/DiffView-DkkSa30n.js +0 -4
- package/dist/assets/FilesView-DDu8zDy5.js +0 -17
- package/dist/assets/MarkdownImageGallery-DyJUc6h9.js +0 -1
- package/dist/assets/MarkdownRendererImpl-Bdm8vMkS.js +0 -12
- package/dist/assets/OnboardingScreen-Dg66B6oB.js +0 -1
- package/dist/assets/PierreDiffViewer-CTIb1GYD.js +0 -157
- package/dist/assets/SettingsView-DStMfBmy.js +0 -28
- package/dist/assets/WalkthroughView-BALp2d9O.js +0 -4
- package/dist/assets/contextPanelEmbeddedChat-D2PM_pEv.js +0 -1
- package/dist/assets/de-DlSNLAcy.js +0 -10
- package/dist/assets/es-D1GbowZ3.js +0 -16
- package/dist/assets/fr-BPOLXIAY.js +0 -14
- package/dist/assets/index-D42fPvt4.css +0 -1
- package/dist/assets/index-DlFbCkEy.js +0 -39
- package/dist/assets/ja-Dm2-m9io.js +0 -16
- package/dist/assets/ko-CIXlzQ5-.js +0 -16
- package/dist/assets/main-B7qTsd_w.js +0 -930
- package/dist/assets/markdownCore-CeEwGgEK.js +0 -3
- package/dist/assets/patchFileDiff-No55fDiD.js +0 -10
- package/dist/assets/pl-B2zmkOpw.js +0 -16
- package/dist/assets/pt-BR-C-JE5H6y.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-ePTkBJNS.js +0 -2
- package/dist/assets/renderMobileApp-D9RjB9DX.js +0 -25
- package/dist/assets/runtimeEndpointReset-DfJIWwwo.js +0 -17
- package/dist/assets/scheduledTasksApi-DuhdyYEa.js +0 -1
- package/dist/assets/tr-MJmRIzEY.js +0 -7
- package/dist/assets/uk-BmD7eM8k.js +0 -16
- package/dist/assets/useInlineCommentController-DD7_7OP_.js +0 -2
- package/dist/assets/useRootScrollLock-DRGAe8PN.js +0 -1
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
- package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
- package/dist/assets/vendor-zod-CK21ihK-.js +0 -39
- package/dist/assets/zh-CN-JJHl4ehT.js +0 -16
- package/dist/assets/zh-TW-DPc4DEEW.js +0 -16
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
## Purpose
|
|
4
4
|
This module fetches quota and usage signals for supported providers in the web server runtime.
|
|
5
5
|
|
|
6
|
+
Node server entrypoints apply `../network-defaults.js` before serving requests,
|
|
7
|
+
including the daemon launched directly through `server/index.js`. Connection
|
|
8
|
+
attempts get 5 seconds without changing address-family selection. The VS Code
|
|
9
|
+
extension applies the same policy in its own process at activation.
|
|
10
|
+
|
|
6
11
|
## Entrypoints and structure
|
|
7
12
|
- `packages/web/server/lib/quota/index.js`: public entrypoint imported by `packages/web/server/index.js`.
|
|
8
13
|
- `packages/web/server/lib/quota/routes.js`: Express route registration for quota endpoints.
|
|
@@ -18,6 +23,7 @@ These provider IDs are currently dispatchable via `fetchQuotaForProvider(provide
|
|
|
18
23
|
| Provider ID | Display name | Module | Auth aliases/keys |
|
|
19
24
|
| --- | --- | --- | --- |
|
|
20
25
|
| `claude` | Claude | `providers/claude/` | Claude Code Keychain entry, Claude Code credentials file, OpenCode `auth.json` (`anthropic`, `claude`), `CLAUDE_CODE_OAUTH_TOKEN` |
|
|
26
|
+
| `cline-pass` | ClinePass | `providers/cline-pass.js` | `cline-pass` (API key under `key` or `token`) |
|
|
21
27
|
| `codex` | Codex | `providers/codex.js` | `openai`, `codex`, `chatgpt` |
|
|
22
28
|
| `command-code` | Command Code | `providers/command-code.js` | `command-code` OAuth/API credential in OpenCode `auth.json`, or `COMMAND_CODE_API_KEY` |
|
|
23
29
|
| `cursor` | Cursor | `providers/cursor.js` | Environment/token files, OpenChamber-managed credentials, or explicit one-time Cursor import |
|
|
@@ -25,6 +31,7 @@ These provider IDs are currently dispatchable via `fetchQuotaForProvider(provide
|
|
|
25
31
|
| `deepseek` | DeepSeek | `providers/deepseek.js` | `deepseek` (API key under `key` or `token`) |
|
|
26
32
|
| `exe-dev` | exe.dev | `providers/exe-dev.js` | Usage API token stored under `~/.config/openchamber/quota/` |
|
|
27
33
|
| `google` | Google | `providers/google/index.js` | `google`, `google.oauth`, Antigravity accounts file |
|
|
34
|
+
| `hyper` | Charm Hyper | `providers/hyper.js` | `hyper` (API key under `key` or `token`) |
|
|
28
35
|
| `github-copilot` | GitHub Copilot | `providers/copilot.js` | `github-copilot`, `copilot` |
|
|
29
36
|
| `github-copilot-addon` | GitHub Copilot Add-on | `providers/copilot.js` | `github-copilot`, `copilot` |
|
|
30
37
|
| `kimi-for-coding` | Kimi for Coding | `providers/kimi.js` | `kimi-for-coding`, `kimi` |
|
|
@@ -34,7 +41,7 @@ These provider IDs are currently dispatchable via `fetchQuotaForProvider(provide
|
|
|
34
41
|
| `zhipuai-coding-plan` | Zhipu AI Coding Plan | `providers/zhipuai-coding-plan.js` | `zhipuai-coding-plan`, `zhipuai`, `zhipu` |
|
|
35
42
|
| `minimax-coding-plan` | MiniMax Coding Plan (minimax.io) | `providers/minimax-coding-plan.js` / `providers/minimax-shared.js` | `minimax-coding-plan` |
|
|
36
43
|
| `minimax-cn-coding-plan` | MiniMax Coding Plan (minimaxi.com) | `providers/minimax-cn-coding-plan.js` / `providers/minimax-shared.js` | `minimax-cn-coding-plan` |
|
|
37
|
-
| `ollama-cloud` | Ollama Cloud | `providers/ollama-cloud.js` | Manual cookie stored under `~/.config/openchamber/quota/` |
|
|
44
|
+
| `ollama-cloud` | Ollama Cloud | `providers/ollama-cloud.js` | Manual cookie pasted into Settings (`aid=...; __Secure-session=...` from `ollama.com`), stored under `~/.config/openchamber/quota/` |
|
|
38
45
|
| `wafer` | Wafer.ai | `providers/wafer.js` | `wafer`, `wafer-ai`, `wafer_ai`, `wafer.ai` |
|
|
39
46
|
| `opencode-go` | OpenCode Go | `providers/opencode-go.js` | `opencode-go` API key from OpenCode `auth.json` |
|
|
40
47
|
| `neuralwatt` | NeuralWatt | `providers/neuralwatt.js` | `neuralwatt` (API key under `key` or `token`) |
|
|
@@ -90,6 +97,22 @@ In 2025/2026 MiniMax rebranded "Coding Plan" to "Token Plan" alongside the M3 mo
|
|
|
90
97
|
- **model_remains array**: Now contains entries for multiple model categories (chat, speech, video, image). The provider selects the chat-model entry by matching `MiniMax-M*`, then `general`/`chat`/`text` by name, then any entry with a remaining percent.
|
|
91
98
|
- **Window status**: The `current_interval_status` and `current_weekly_status` fields indicate whether a window is active. Status `3` means the window is not applicable for the current plan tier (e.g. legacy plans without weekly limits). The provider omits inactive windows.
|
|
92
99
|
|
|
100
|
+
## ClinePass quota semantics
|
|
101
|
+
|
|
102
|
+
ClinePass reads `data.limits` from its usage-limits endpoint. Web/Electron and
|
|
103
|
+
VS Code accept only known window types with finite numeric or non-empty numeric
|
|
104
|
+
string percentages. Invalid windows are skipped independently; no usable windows
|
|
105
|
+
is a failed refresh, not zero usage. Both implementations choose a non-empty
|
|
106
|
+
`key`, then `token`, and expose auth/fetch dependencies for focused tests.
|
|
107
|
+
Saved UI provider-visibility lists remain authoritative; installations without a
|
|
108
|
+
saved list include ClinePass through the provider registry.
|
|
109
|
+
|
|
110
|
+
## Charm Hyper balance semantics
|
|
111
|
+
|
|
112
|
+
`GET https://hyper.charm.land/v1/credits` returns a team's current Hypercredit balance, not a percentage or reset timestamp. The [Hyper FAQ](https://hyper.charm.land/faq) defines one Hypercredit as $0.05. Both runtimes expose `credits_balance` in dollars and `credits` as a numeric label under the UI's localized window title. Keep English unit text out of that numeric label.
|
|
113
|
+
|
|
114
|
+
Web and VS Code accept finite numeric balances and non-empty numeric strings. Missing, blank, or malformed balances remain explicit failures; zero is valid. Credential lookup uses a non-empty string `key`, then `token`, so malformed or blank keys cannot mark the provider configured or hide a valid fallback token. Hyper fetchers accept `readAuth` and `fetchImpl` dependencies for tests without replacing filesystem or auth modules.
|
|
115
|
+
|
|
93
116
|
## Kimi for Coding field semantics
|
|
94
117
|
|
|
95
118
|
`GET https://api.kimi.com/coding/v1/usages` is inconsistent about which field carries consumption:
|
|
@@ -98,6 +121,10 @@ In 2025/2026 MiniMax rebranded "Coding Plan" to "Token Plan" alongside the M3 mo
|
|
|
98
121
|
|
|
99
122
|
The provider computes `usedPercent` from whichever of `used`/`remaining` is present (`used` takes precedence when both exist) rather than assuming one field name. Both `packages/web/server/lib/quota/providers/kimi.js` and `packages/vscode/src/quotaProviders.ts` (`fetchKimiQuota`) must stay in sync — the VS Code extension duplicates this parsing logic rather than importing it.
|
|
100
123
|
|
|
124
|
+
## Ollama Cloud settings-page shapes
|
|
125
|
+
|
|
126
|
+
Ollama Cloud authentication uses two cookies (`aid` and `__Secure-session`) pasted together as one single-line Cookie header value. Ollama serves two different `/settings` page shapes and `parseOllamaSettingsHtml` supports both: session/weekly/premium-interaction windows (percent-based plans) and a `monthly` window derived from "Monthly usage: $X of $Y used" (cost-based plans) with a symmetric `$X / $Y` money `valueLabel` that reads correctly in both used/remaining display modes. The "Extra usage" credits block is surfaced as a balance-only `credits_balance` window with a plain money `valueLabel` when present, matching the Codex/DeepSeek credits treatment ("Credits Balance" in the UI); a $0 balance is omitted instead of showing an empty credits row. Keep `packages/web/server/lib/quota/providers/ollama-cloud.js` and `packages/vscode/src/quotaProviders.ts` (`parseOllamaSettingsHtml`) in sync — the VS Code extension duplicates this parsing logic rather than importing it.
|
|
127
|
+
|
|
101
128
|
## GitHub Copilot quota semantics
|
|
102
129
|
|
|
103
130
|
GitHub Copilot usage exposes only the `premium_interactions` snapshot as the
|
|
@@ -117,6 +144,16 @@ snapshot carries `entitlement`, `remaining`, `unlimited`, and
|
|
|
117
144
|
- When entitlement/remaining are unusable, fall back to `100 - percent_remaining`.
|
|
118
145
|
- Snapshots other than `premium_interactions` (legacy annual plans) yield zero windows.
|
|
119
146
|
|
|
147
|
+
## OpenRouter key semantics
|
|
148
|
+
|
|
149
|
+
OpenRouter quota reads `GET https://openrouter.ai/api/v1/key`, which is documented as callable with any valid API key. `GET /api/v1/credits` is documented as "Management key required" and is not used. Calling `/credits` with a normal inference key has been observed to return HTTP 200 with `{total_credits:0, total_usage:0}` rather than an error; this behavior is not documented and is why the old implementation silently rendered "$0.00 left · $0.00 spent". A `/credits` fallback for unlimited keys would render the same zeros, so unlimited keys report `usage_monthly` instead.
|
|
150
|
+
|
|
151
|
+
The documented `limit`, `limit_remaining`, and `limit_reset` fields are present and null on unlimited keys; null means unlimited, never missing data. For a limited key, window usage is `limit - limit_remaining`, not `usage`: `usage` is all-time and measures a different axis from the current reset window. Pairing `usage` with the current limit produces a wrong number. `limit_remaining` is server-computed and already honors `include_byok_in_limit`, so `byok_*` fields are ignored.
|
|
152
|
+
|
|
153
|
+
Unlimited keys report `usage_monthly` in a `monthly` window with no percent. `limit_reset` is a period string (`daily`, `weekly`, `monthly`, or null), not a timestamp; `resetAt` is derived from the documented midnight-UTC boundaries, with weeks starting Monday. A set `limit` with a null `limit_reset` is a lifetime cap and maps to the `credits` window with no reset.
|
|
154
|
+
|
|
155
|
+
Keep `packages/web/server/lib/quota/providers/openrouter.js` and `packages/vscode/src/quotaProviders.ts` in sync, as with the Kimi and Copilot providers; the VS Code extension duplicates this parsing logic rather than importing the web provider.
|
|
156
|
+
|
|
120
157
|
## Notes for contributors
|
|
121
158
|
- Keep provider IDs stable; clients use them directly.
|
|
122
159
|
- Avoid adding alias-based dispatch in `fetchQuotaForProvider`; dispatch currently expects exact provider IDs.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { readAuthFile } from '../../opencode/auth.js';
|
|
2
|
+
import {
|
|
3
|
+
getAuthEntry,
|
|
4
|
+
normalizeAuthEntry,
|
|
5
|
+
asObject,
|
|
6
|
+
asNonEmptyString,
|
|
7
|
+
buildResult,
|
|
8
|
+
toUsageWindow,
|
|
9
|
+
toNumber,
|
|
10
|
+
toTimestamp
|
|
11
|
+
} from '../utils/index.js';
|
|
12
|
+
|
|
13
|
+
export const providerId = 'cline-pass';
|
|
14
|
+
export const providerName = 'ClinePass';
|
|
15
|
+
export const aliases = ['cline-pass'];
|
|
16
|
+
const CLINE_USAGE_URL = 'https://api.cline.bot/api/v1/users/me/plan/usage-limits';
|
|
17
|
+
|
|
18
|
+
// Cline reports a rolling five-hour window, a rolling weekly window, and a
|
|
19
|
+
// calendar-month limit. Each window carries its duration so consumers can rank
|
|
20
|
+
// limits by how soon they run out; the calendar month has no fixed duration.
|
|
21
|
+
const WINDOW_KINDS = new Map([
|
|
22
|
+
['five_hour', { key: '5h', windowSeconds: 5 * 60 * 60 }],
|
|
23
|
+
['weekly', { key: 'weekly', windowSeconds: 7 * 24 * 60 * 60 }],
|
|
24
|
+
['monthly', { key: 'monthly', windowSeconds: null }]
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const getApiKey = (auth) => {
|
|
28
|
+
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
29
|
+
return asNonEmptyString(entry?.key) ?? asNonEmptyString(entry?.token);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const isConfigured = (auth = readAuthFile()) => Boolean(getApiKey(auth));
|
|
33
|
+
|
|
34
|
+
export const fetchQuota = async ({ readAuth = readAuthFile, fetchImpl = fetch } = {}) => {
|
|
35
|
+
const apiKey = getApiKey(readAuth());
|
|
36
|
+
|
|
37
|
+
if (!apiKey) {
|
|
38
|
+
return buildResult({
|
|
39
|
+
providerId,
|
|
40
|
+
providerName,
|
|
41
|
+
ok: false,
|
|
42
|
+
configured: false,
|
|
43
|
+
error: 'Not configured'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const timeoutSignal = AbortSignal.timeout(15_000);
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
const response = await fetchImpl(CLINE_USAGE_URL, {
|
|
51
|
+
method: 'GET',
|
|
52
|
+
headers: {
|
|
53
|
+
Authorization: `Bearer ${apiKey}`,
|
|
54
|
+
'Accept-Encoding': 'identity'
|
|
55
|
+
},
|
|
56
|
+
signal: timeoutSignal
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
return buildResult({
|
|
61
|
+
providerId,
|
|
62
|
+
providerName,
|
|
63
|
+
ok: false,
|
|
64
|
+
configured: true,
|
|
65
|
+
error: response.status === 401
|
|
66
|
+
? 'Session expired — please re-authenticate with ClinePass'
|
|
67
|
+
: `API error: ${response.status}`
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const payload = asObject(await response.json());
|
|
72
|
+
const data = asObject(payload?.data);
|
|
73
|
+
const limits = Array.isArray(data?.limits) ? data.limits : [];
|
|
74
|
+
|
|
75
|
+
const windows = {};
|
|
76
|
+
for (const item of limits) {
|
|
77
|
+
const limit = asObject(item);
|
|
78
|
+
if (!limit) continue;
|
|
79
|
+
const kind = WINDOW_KINDS.get(asNonEmptyString(limit.type));
|
|
80
|
+
if (!kind) continue;
|
|
81
|
+
const usedPercent = toNumber(asNonEmptyString(limit.percentUsed)
|
|
82
|
+
?? (Number.isFinite(limit.percentUsed) ? limit.percentUsed : null));
|
|
83
|
+
if (usedPercent === null) continue;
|
|
84
|
+
windows[kind.key] = toUsageWindow({
|
|
85
|
+
usedPercent,
|
|
86
|
+
windowSeconds: kind.windowSeconds,
|
|
87
|
+
resetAt: toTimestamp(limit.resetsAt)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (Object.keys(windows).length === 0) {
|
|
92
|
+
return buildResult({
|
|
93
|
+
providerId,
|
|
94
|
+
providerName,
|
|
95
|
+
ok: false,
|
|
96
|
+
configured: true,
|
|
97
|
+
error: 'No quota data in response'
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return buildResult({
|
|
102
|
+
providerId,
|
|
103
|
+
providerName,
|
|
104
|
+
ok: true,
|
|
105
|
+
configured: true,
|
|
106
|
+
usage: { windows }
|
|
107
|
+
});
|
|
108
|
+
} catch (error) {
|
|
109
|
+
const isTimeout = error instanceof DOMException && (
|
|
110
|
+
error.name === 'TimeoutError' || (error.name === 'AbortError' && timeoutSignal.aborted)
|
|
111
|
+
);
|
|
112
|
+
const isParseError = error instanceof SyntaxError;
|
|
113
|
+
return buildResult({
|
|
114
|
+
providerId,
|
|
115
|
+
providerName,
|
|
116
|
+
ok: false,
|
|
117
|
+
configured: true,
|
|
118
|
+
error: isTimeout
|
|
119
|
+
? 'Request timed out'
|
|
120
|
+
: isParseError
|
|
121
|
+
? 'Invalid response from provider'
|
|
122
|
+
: (error instanceof Error ? error.message : 'Request failed')
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { fetchQuota, isConfigured } from './cline-pass.js';
|
|
3
|
+
|
|
4
|
+
const readAuth = () => ({ 'cline-pass': { key: 'test-token' } });
|
|
5
|
+
|
|
6
|
+
// Response shape verified by the contributor against the live ClinePass API.
|
|
7
|
+
const documentedPayload = {
|
|
8
|
+
data: { limits: [
|
|
9
|
+
{ type: 'five_hour', percentUsed: 43, resetsAt: '2026-09-08T17:00:44.598174595Z' },
|
|
10
|
+
{ type: 'weekly', percentUsed: 17 },
|
|
11
|
+
{ type: 'monthly', percentUsed: 8 },
|
|
12
|
+
] },
|
|
13
|
+
success: true,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('ClinePass quota provider', () => {
|
|
17
|
+
it('maps the documented windows and sends credentials only in headers', async () => {
|
|
18
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async (url, options) => {
|
|
19
|
+
expect(url).toBe('https://api.cline.bot/api/v1/users/me/plan/usage-limits');
|
|
20
|
+
expect(new Headers(options.headers).get('Authorization')).toBe('Bearer test-token');
|
|
21
|
+
expect(options.signal).toBeInstanceOf(AbortSignal);
|
|
22
|
+
return Response.json(documentedPayload);
|
|
23
|
+
} });
|
|
24
|
+
expect(result.ok).toBe(true);
|
|
25
|
+
expect(result.providerId).toBe('cline-pass');
|
|
26
|
+
expect(Object.keys(result.usage.windows)).toEqual(['5h', 'weekly', 'monthly']);
|
|
27
|
+
expect(result.usage.windows['5h'].usedPercent).toBe(43);
|
|
28
|
+
expect(result.usage.windows['5h'].remainingPercent).toBe(57);
|
|
29
|
+
expect(result.usage.windows['5h'].windowSeconds).toBe(18_000);
|
|
30
|
+
expect(result.usage.windows['5h'].resetAt).toBe(Date.parse('2026-09-08T17:00:44.598174595Z'));
|
|
31
|
+
expect(result.usage.windows.weekly.usedPercent).toBe(17);
|
|
32
|
+
expect(result.usage.windows.weekly.windowSeconds).toBe(604_800);
|
|
33
|
+
expect(result.usage.windows.monthly.usedPercent).toBe(8);
|
|
34
|
+
expect(result.usage.windows.monthly.windowSeconds).toBeNull();
|
|
35
|
+
expect(JSON.stringify(result)).not.toContain('test-token');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it.each([0, '0', '51'])('accepts finite percentage %s', async (percentUsed) => {
|
|
39
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async () => Response.json({ data: { limits: [{ type: 'weekly', percentUsed }] } }) });
|
|
40
|
+
expect(result.ok).toBe(true);
|
|
41
|
+
expect(result.usage.windows.weekly.usedPercent).toBe(Number(percentUsed));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it.each([
|
|
45
|
+
{ type: 'constructor', percentUsed: 5 }, { type: 'toString', percentUsed: 5 },
|
|
46
|
+
{ type: '__proto__', percentUsed: 5 }, { type: 'quarterly', percentUsed: 5 },
|
|
47
|
+
{ type: 'weekly', percentUsed: '' }, { type: 'weekly', percentUsed: ' ' },
|
|
48
|
+
{ type: 'weekly', percentUsed: null }, { type: 'weekly', percentUsed: true },
|
|
49
|
+
{ type: 'weekly', percentUsed: 'NaN' }, null,
|
|
50
|
+
])('ignores malformed windows without discarding valid siblings: %j', async (limit) => {
|
|
51
|
+
const invalid = await fetchQuota({ readAuth, fetchImpl: async () => Response.json({ data: { limits: [limit] } }) });
|
|
52
|
+
expect(invalid.ok).toBe(false);
|
|
53
|
+
expect(invalid.configured).toBe(true);
|
|
54
|
+
expect(invalid.usage).toBeNull();
|
|
55
|
+
const mixed = await fetchQuota({ readAuth, fetchImpl: async () => Response.json({ data: { limits: [limit, { type: 'monthly', percentUsed: 8 }] } }) });
|
|
56
|
+
expect(mixed.ok).toBe(true);
|
|
57
|
+
expect(Object.keys(mixed.usage.windows)).toEqual(['monthly']);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it.each([null, [], {}, { data: null }, { data: { limits: [] } }])('rejects empty or malformed payload %j', async (payload) => {
|
|
61
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async () => Response.json(payload) });
|
|
62
|
+
expect(result.ok).toBe(false);
|
|
63
|
+
expect(result.usage).toBeNull();
|
|
64
|
+
expect(result.error).toBe('No quota data in response');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it.each([{ key: '' }, { key: ' ' }, { key: 42 }, {}])('uses a usable token when the key is malformed: %j', async (entry) => {
|
|
68
|
+
const auth = { 'cline-pass': { ...entry, token: 'test-token' } };
|
|
69
|
+
expect(isConfigured(auth)).toBe(true);
|
|
70
|
+
const result = await fetchQuota({ readAuth: () => auth, fetchImpl: async (_url, options) => {
|
|
71
|
+
expect(new Headers(options.headers).get('Authorization')).toBe('Bearer test-token');
|
|
72
|
+
return Response.json(documentedPayload);
|
|
73
|
+
} });
|
|
74
|
+
expect(result.ok).toBe(true);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it.each([{}, { 'cline-pass': { key: '' } }, { 'cline-pass': { key: 42 } }])('does not fetch without usable credentials: %j', async (auth) => {
|
|
78
|
+
expect(isConfigured(auth)).toBe(false);
|
|
79
|
+
const result = await fetchQuota({ readAuth: () => auth, fetchImpl: async () => { throw new Error('Unexpected fetch'); } });
|
|
80
|
+
expect(result.configured).toBe(false);
|
|
81
|
+
expect(result.error).toBe('Not configured');
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it.each([[401, 'Session expired — please re-authenticate with ClinePass'], [503, 'API error: 503']])('reports HTTP %s', async (status, error) => {
|
|
85
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async () => new Response(null, { status }) });
|
|
86
|
+
expect(result.ok).toBe(false);
|
|
87
|
+
expect(result.usage).toBeNull();
|
|
88
|
+
expect(result.error).toBe(error);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('reports invalid JSON', async () => {
|
|
92
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async () => new Response('{') });
|
|
93
|
+
expect(result.error).toBe('Invalid response from provider');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('recognizes the timeout exception from AbortSignal.timeout', async () => {
|
|
97
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async () => { throw new DOMException('Timed out', 'TimeoutError'); } });
|
|
98
|
+
expect(result.ok).toBe(false);
|
|
99
|
+
expect(result.configured).toBe(true);
|
|
100
|
+
expect(result.usage).toBeNull();
|
|
101
|
+
expect(result.error).toBe('Request timed out');
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { readAuthFile } from '../../opencode/auth.js';
|
|
2
|
+
import {
|
|
3
|
+
getAuthEntry,
|
|
4
|
+
normalizeAuthEntry,
|
|
5
|
+
buildResult,
|
|
6
|
+
toUsageWindow,
|
|
7
|
+
toNumber,
|
|
8
|
+
formatMoney,
|
|
9
|
+
asObject,
|
|
10
|
+
asNonEmptyString
|
|
11
|
+
} from '../utils/index.js';
|
|
12
|
+
|
|
13
|
+
export const providerId = 'hyper';
|
|
14
|
+
export const providerName = 'Charm Hyper';
|
|
15
|
+
export const aliases = ['hyper'];
|
|
16
|
+
const HYPER_QUOTA_URL = 'https://hyper.charm.land/v1/credits';
|
|
17
|
+
const CREDIT_TO_USD = 0.05;
|
|
18
|
+
|
|
19
|
+
const getApiKey = (auth) => {
|
|
20
|
+
const entry = normalizeAuthEntry(getAuthEntry(auth, aliases));
|
|
21
|
+
return asNonEmptyString(entry?.key) ?? asNonEmptyString(entry?.token);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const isConfigured = (auth = readAuthFile()) => Boolean(getApiKey(auth));
|
|
25
|
+
|
|
26
|
+
export const fetchQuota = async ({ readAuth = readAuthFile, fetchImpl = fetch } = {}) => {
|
|
27
|
+
const apiKey = getApiKey(readAuth());
|
|
28
|
+
|
|
29
|
+
if (!apiKey) {
|
|
30
|
+
return buildResult({
|
|
31
|
+
providerId,
|
|
32
|
+
providerName,
|
|
33
|
+
ok: false,
|
|
34
|
+
configured: false,
|
|
35
|
+
error: 'Not configured'
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const timeoutSignal = AbortSignal.timeout(15_000);
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const response = await fetchImpl(HYPER_QUOTA_URL, {
|
|
43
|
+
method: 'GET',
|
|
44
|
+
headers: {
|
|
45
|
+
Authorization: `Bearer ${apiKey}`,
|
|
46
|
+
'Accept-Encoding': 'identity'
|
|
47
|
+
},
|
|
48
|
+
signal: timeoutSignal
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
return buildResult({
|
|
53
|
+
providerId,
|
|
54
|
+
providerName,
|
|
55
|
+
ok: false,
|
|
56
|
+
configured: true,
|
|
57
|
+
error: response.status === 401 || response.status === 403
|
|
58
|
+
? 'Session expired — please re-authenticate with Charm Hyper'
|
|
59
|
+
: `API error: ${response.status}`
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const payload = asObject(await response.json());
|
|
64
|
+
const rawBalance = payload?.balance;
|
|
65
|
+
const balance = toNumber(asNonEmptyString(rawBalance)
|
|
66
|
+
?? (Number.isFinite(rawBalance) ? rawBalance : null));
|
|
67
|
+
|
|
68
|
+
if (balance === null) {
|
|
69
|
+
return buildResult({
|
|
70
|
+
providerId,
|
|
71
|
+
providerName,
|
|
72
|
+
ok: false,
|
|
73
|
+
configured: true,
|
|
74
|
+
error: 'No quota data in response'
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const creditsLabel = Number.isInteger(balance) ? String(balance) : formatMoney(balance);
|
|
79
|
+
const windows = {
|
|
80
|
+
credits_balance: toUsageWindow({
|
|
81
|
+
usedPercent: null,
|
|
82
|
+
windowSeconds: null,
|
|
83
|
+
resetAt: null,
|
|
84
|
+
valueLabel: `$${formatMoney(balance * CREDIT_TO_USD)}`
|
|
85
|
+
}),
|
|
86
|
+
credits: toUsageWindow({
|
|
87
|
+
usedPercent: null,
|
|
88
|
+
windowSeconds: null,
|
|
89
|
+
resetAt: null,
|
|
90
|
+
valueLabel: creditsLabel
|
|
91
|
+
})
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return buildResult({
|
|
95
|
+
providerId,
|
|
96
|
+
providerName,
|
|
97
|
+
ok: true,
|
|
98
|
+
configured: true,
|
|
99
|
+
usage: { windows }
|
|
100
|
+
});
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const isTimeout = error instanceof DOMException && (
|
|
103
|
+
error.name === 'TimeoutError' || (error.name === 'AbortError' && timeoutSignal.aborted)
|
|
104
|
+
);
|
|
105
|
+
const isParseError = error instanceof SyntaxError;
|
|
106
|
+
return buildResult({
|
|
107
|
+
providerId,
|
|
108
|
+
providerName,
|
|
109
|
+
ok: false,
|
|
110
|
+
configured: true,
|
|
111
|
+
error: isTimeout
|
|
112
|
+
? 'Request timed out'
|
|
113
|
+
: isParseError
|
|
114
|
+
? 'Invalid response from provider'
|
|
115
|
+
: (error instanceof Error ? error.message : 'Request failed')
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { fetchQuota, isConfigured } from './hyper.js';
|
|
3
|
+
|
|
4
|
+
const readAuth = () => ({ hyper: { key: 'test-token' } });
|
|
5
|
+
|
|
6
|
+
// https://hyper.charm.land/docs/api/credits.html documents the balance payload.
|
|
7
|
+
// https://hyper.charm.land/faq defines one Hypercredit as $0.05.
|
|
8
|
+
describe('Charm Hyper quota provider', () => {
|
|
9
|
+
it.each([
|
|
10
|
+
[100, '100', '$5.00'],
|
|
11
|
+
['50', '50', '$2.50'],
|
|
12
|
+
[25.5, '25.50', '$1.28'],
|
|
13
|
+
[0, '0', '$0.00'],
|
|
14
|
+
['0', '0', '$0.00'],
|
|
15
|
+
])('formats balance %s without an untranslated unit', async (balance, credits, dollars) => {
|
|
16
|
+
const result = await fetchQuota({
|
|
17
|
+
readAuth,
|
|
18
|
+
fetchImpl: async () => Response.json({ balance }),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result.ok).toBe(true);
|
|
22
|
+
expect(result.providerId).toBe('hyper');
|
|
23
|
+
expect(result.configured).toBe(true);
|
|
24
|
+
expect(result.usage.windows.credits.valueLabel).toBe(credits);
|
|
25
|
+
expect(result.usage.windows.credits_balance.valueLabel).toBe(dollars);
|
|
26
|
+
for (const window of Object.values(result.usage.windows)) {
|
|
27
|
+
expect(window.usedPercent).toBeNull();
|
|
28
|
+
expect(window.remainingPercent).toBeNull();
|
|
29
|
+
expect(window.windowSeconds).toBeNull();
|
|
30
|
+
expect(window.resetAt).toBeNull();
|
|
31
|
+
expect(window.resetAfterSeconds).toBeNull();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it.each([
|
|
36
|
+
{}, null, [], { balance: '' }, { balance: ' \t ' }, { balance: 'NaN' },
|
|
37
|
+
{ balance: 'Infinity' }, { balance: null }, { balance: true }, { balance: [] },
|
|
38
|
+
{ balance: {} },
|
|
39
|
+
])('rejects invalid payload %j instead of showing zero', async (payload) => {
|
|
40
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async () => Response.json(payload) });
|
|
41
|
+
|
|
42
|
+
expect(result.ok).toBe(false);
|
|
43
|
+
expect(result.configured).toBe(true);
|
|
44
|
+
expect(result.error).toBe('No quota data in response');
|
|
45
|
+
expect(result.usage).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it.each([
|
|
49
|
+
{ hyper: { key: 'test-token' } },
|
|
50
|
+
{ hyper: { token: 'test-token' } },
|
|
51
|
+
{ hyper: 'test-token' },
|
|
52
|
+
{ hyper: { key: ' ', token: 'test-token' } },
|
|
53
|
+
{ hyper: { key: 42, token: 'test-token' } },
|
|
54
|
+
])('uses a validated credential for the documented request', async (auth) => {
|
|
55
|
+
expect(isConfigured(auth)).toBe(true);
|
|
56
|
+
let requests = 0;
|
|
57
|
+
const result = await fetchQuota({
|
|
58
|
+
readAuth: () => auth,
|
|
59
|
+
fetchImpl: async (url, options) => {
|
|
60
|
+
requests += 1;
|
|
61
|
+
expect(url).toBe('https://hyper.charm.land/v1/credits');
|
|
62
|
+
expect(options.method).toBe('GET');
|
|
63
|
+
expect(new Headers(options.headers).get('Authorization')).toBe('Bearer test-token');
|
|
64
|
+
expect(options.signal).toBeInstanceOf(AbortSignal);
|
|
65
|
+
return Response.json({ balance: 100 });
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(requests).toBe(1);
|
|
70
|
+
expect(result.ok).toBe(true);
|
|
71
|
+
expect(JSON.stringify(result)).not.toContain('test-token');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it.each([{}, { hyper: { key: '' } }, { hyper: { key: ' ' } }, { hyper: { key: 42 } }])(
|
|
75
|
+
'does not request usage without a valid credential',
|
|
76
|
+
async (auth) => {
|
|
77
|
+
expect(isConfigured(auth)).toBe(false);
|
|
78
|
+
let requests = 0;
|
|
79
|
+
const result = await fetchQuota({
|
|
80
|
+
readAuth: () => auth,
|
|
81
|
+
fetchImpl: async () => {
|
|
82
|
+
requests += 1;
|
|
83
|
+
return Response.json({ balance: 100 });
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(requests).toBe(0);
|
|
88
|
+
expect(result.ok).toBe(false);
|
|
89
|
+
expect(result.configured).toBe(false);
|
|
90
|
+
expect(result.error).toBe('Not configured');
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
it.each([
|
|
95
|
+
[401, 'Session expired — please re-authenticate with Charm Hyper'],
|
|
96
|
+
[403, 'Session expired — please re-authenticate with Charm Hyper'],
|
|
97
|
+
[429, 'API error: 429'],
|
|
98
|
+
[500, 'API error: 500'],
|
|
99
|
+
])('reports HTTP %s as a failure', async (status, error) => {
|
|
100
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async () => new Response(null, { status }) });
|
|
101
|
+
|
|
102
|
+
expect(result.ok).toBe(false);
|
|
103
|
+
expect(result.configured).toBe(true);
|
|
104
|
+
expect(result.error).toBe(error);
|
|
105
|
+
expect(result.usage).toBeNull();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('reports invalid JSON as a parse failure', async () => {
|
|
109
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async () => new Response('{') });
|
|
110
|
+
expect(result.error).toBe('Invalid response from provider');
|
|
111
|
+
expect(result.ok).toBe(false);
|
|
112
|
+
expect(result.configured).toBe(true);
|
|
113
|
+
expect(result.usage).toBeNull();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it.each([
|
|
117
|
+
[new DOMException('Timed out', 'TimeoutError'), 'Request timed out'],
|
|
118
|
+
[new Error('Network unavailable'), 'Network unavailable'],
|
|
119
|
+
])('reports request failure', async (failure, message) => {
|
|
120
|
+
const result = await fetchQuota({ readAuth, fetchImpl: async () => { throw failure; } });
|
|
121
|
+
expect(result.error).toBe(message);
|
|
122
|
+
expect(result.ok).toBe(false);
|
|
123
|
+
expect(result.configured).toBe(true);
|
|
124
|
+
expect(result.usage).toBeNull();
|
|
125
|
+
});
|
|
126
|
+
});
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { buildResult } from '../utils/index.js';
|
|
9
9
|
|
|
10
10
|
import * as claude from './claude/index.js';
|
|
11
|
+
import * as clinePass from './cline-pass.js';
|
|
11
12
|
import * as codex from './codex.js';
|
|
12
13
|
import * as copilot from './copilot.js';
|
|
13
14
|
import * as crof from './crof.js';
|
|
@@ -15,6 +16,7 @@ import * as cursor from './cursor.js';
|
|
|
15
16
|
import * as deepseek from './deepseek.js';
|
|
16
17
|
import * as exeDev from './exe-dev.js';
|
|
17
18
|
import * as google from './google/index.js';
|
|
19
|
+
import * as hyper from './hyper.js';
|
|
18
20
|
import * as kimi from './kimi.js';
|
|
19
21
|
import * as nanogpt from './nanogpt.js';
|
|
20
22
|
import * as openai from './openai.js';
|
|
@@ -36,6 +38,12 @@ const registry = {
|
|
|
36
38
|
isConfigured: claude.isConfigured,
|
|
37
39
|
fetchQuota: claude.fetchQuota
|
|
38
40
|
},
|
|
41
|
+
'cline-pass': {
|
|
42
|
+
providerId: clinePass.providerId,
|
|
43
|
+
providerName: clinePass.providerName,
|
|
44
|
+
isConfigured: clinePass.isConfigured,
|
|
45
|
+
fetchQuota: clinePass.fetchQuota
|
|
46
|
+
},
|
|
39
47
|
codex: {
|
|
40
48
|
providerId: codex.providerId,
|
|
41
49
|
providerName: codex.providerName,
|
|
@@ -72,6 +80,12 @@ const registry = {
|
|
|
72
80
|
isConfigured: google.isConfigured,
|
|
73
81
|
fetchQuota: google.fetchGoogleQuota
|
|
74
82
|
},
|
|
83
|
+
hyper: {
|
|
84
|
+
providerId: hyper.providerId,
|
|
85
|
+
providerName: hyper.providerName,
|
|
86
|
+
isConfigured: hyper.isConfigured,
|
|
87
|
+
fetchQuota: hyper.fetchQuota
|
|
88
|
+
},
|
|
75
89
|
'zai-coding-plan': {
|
|
76
90
|
providerId: zai.providerId,
|
|
77
91
|
providerName: zai.providerName,
|
|
@@ -220,6 +234,7 @@ export const fetchGoogleQuota = google.fetchGoogleQuota;
|
|
|
220
234
|
export const fetchCodexQuota = codex.fetchQuota;
|
|
221
235
|
export const fetchCursorQuota = cursor.fetchQuota;
|
|
222
236
|
export const fetchDeepseekQuota = deepseek.fetchQuota;
|
|
237
|
+
export const fetchHyperQuota = hyper.fetchQuota;
|
|
223
238
|
export const fetchCopilotQuota = copilot.fetchQuota;
|
|
224
239
|
export const fetchCopilotAddonQuota = copilot.fetchQuotaAddon;
|
|
225
240
|
export const fetchKimiQuota = kimi.fetchQuota;
|
|
@@ -74,7 +74,6 @@ export const fetchQuota = async () => {
|
|
|
74
74
|
const subscription = payload?.subscription ?? null;
|
|
75
75
|
const inOverage = Boolean(subscription?.in_overage);
|
|
76
76
|
const allowance = payload?.key?.allowance ?? null;
|
|
77
|
-
const keyName = payload?.key?.name ?? null;
|
|
78
77
|
const creditsRemaining = toNumber(payload?.balance?.credits_remaining_usd);
|
|
79
78
|
|
|
80
79
|
const windows = {};
|
|
@@ -116,19 +115,17 @@ export const fetchQuota = async () => {
|
|
|
116
115
|
: (spent !== null && effectiveLimit !== null && effectiveLimit > 0
|
|
117
116
|
? Math.max(0, Math.min(100, (spent / effectiveLimit) * 100))
|
|
118
117
|
: null);
|
|
119
|
-
// Window title is the localized period label (daily/weekly/monthly);
|
|
120
|
-
//
|
|
118
|
+
// Window title is the localized period label (daily/weekly/monthly); the
|
|
119
|
+
// usage value stays a percent so the UI's display-mode toggle applies.
|
|
121
120
|
const periodKey = (period === 'daily' || period === 'weekly' || period === 'monthly' || period === 'month')
|
|
122
121
|
? (period === 'month' ? 'monthly' : period)
|
|
123
122
|
: 'billing_cycle';
|
|
124
|
-
const labelName = asNonEmptyString(keyName);
|
|
125
123
|
const resetAt = toTimestamp(allowance.reset_at);
|
|
126
124
|
const windowSeconds = period ? periodToWindowSeconds(period) : null;
|
|
127
125
|
windows[periodKey] = toUsageWindow({
|
|
128
126
|
usedPercent,
|
|
129
127
|
windowSeconds,
|
|
130
|
-
resetAt
|
|
131
|
-
...(labelName ? { valueLabel: labelName } : {})
|
|
128
|
+
resetAt
|
|
132
129
|
});
|
|
133
130
|
} else if (creditsRemaining !== null) {
|
|
134
131
|
windows.credits_balance = toUsageWindow({
|