dsh-provider-usage 0.3.8 → 0.3.10
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 +12 -5
- package/README_ZH.md +12 -5
- package/lib/client.js +450 -35
- package/lib/client.js.map +1 -1
- package/lib/index.js +9 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -33,17 +33,20 @@
|
|
|
33
33
|
| `vercel-ai-gateway` | `vercel-ai-gateway` | `GET {baseURL}/v1/credits` | team credit balance |
|
|
34
34
|
| `xai` | `xai` | `GET {baseURL}/billing/credits` | prepaid balance (USD) |
|
|
35
35
|
- **Credentials stay safe** — API keys are resolved per request through the harness credentials service (environment variables / `~/.dsh/.credentials.yaml`); never cached, never written to disk. For OAuth providers (OpenAI Codex) the plugin reads the grant record the sign-in flow stored, and refreshes it transparently when it is about to expire.
|
|
36
|
-
- **Floating ball widget** — a draggable floating ball opens the usage panel. Drop it anywhere in the viewport (position persisted); it docks by default at the bottom-left of the chat area with equal margins, and the panel-header home button sends it back. The halo around the ball encodes the health of the provider **in use**
|
|
36
|
+
- **Floating ball widget** — a draggable floating ball opens the usage panel. Drop it anywhere in the viewport (position persisted); it docks by default at the bottom-left of the chat area with equal margins, and the panel-header home button sends it back. The panel scrolls when the provider list grows past its height, and its top edge is draggable to resize it taller or shorter (height persisted). The halo around the ball encodes the health of the provider **in use** — the focused session's own selection (its composer's model seat), tracked live on the client, so switching sessions re-highlights that session's provider immediately without re-selecting a model: green all good, amber some quota below 30% left or a balance below the yellow threshold, red on query failure / missing key / usage ≥90% / balance below the red threshold. Idle providers with low quota do not color the ball — switch to another provider with enough quota and the ball turns green again; the panel marks the in-use provider and still lists every provider's numbers.
|
|
37
37
|
- **Version badge** — the panel header shows the running plugin version next to the title, so it is obvious which release is loaded.
|
|
38
38
|
- **Bilingual panel** — built-in Chinese/English UI; follows the harness language by default, with a one-click toggle in the panel header (persisted in localStorage).
|
|
39
39
|
- **Configurable refresh** — adjustable in the panel (15s–30min, persisted in localStorage); the default comes from the plugin config.
|
|
40
|
+
- **Configurable balance thresholds** — balance-type providers (DeepSeek, Moonshot, Vercel AI Gateway, xAI) and the `credits` rows of usage-type providers (OpenRouter, OpenAI Codex) turn red below the red threshold and yellow below the yellow threshold, compared in the balance's own currency (defaults: red < 10, yellow < 30, whether CNY or USD). Both values are editable directly in the panel footer (persisted in localStorage); the defaults come from the plugin config. For providers reporting both a subscription plan and credits (e.g. OpenAI Codex), the two are OR'ed: the ball stays green while either one has enough left, and when both are running low the lighter warning wins (the plan is normally consumed before credits).
|
|
40
41
|
- **Manual providers** — add arbitrary gateways (e.g. a self-hosted DeepSeek-compatible endpoint) via config.
|
|
41
42
|
|
|
42
43
|
## Screenshots
|
|
43
44
|
|
|
44
45
|
The floating ball (bottom-left, with the green healthy halo) and the open usage panel:
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
| DeepSeek in use | OpenAI Codex in use |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
|  |  |
|
|
47
50
|
|
|
48
51
|
## OpenAI Codex via OAuth
|
|
49
52
|
|
|
@@ -129,14 +132,18 @@ Defaults work out of the box: the plugin auto-detects every provider route of th
|
|
|
129
132
|
- id: provider-usage
|
|
130
133
|
name: dsh-provider-usage
|
|
131
134
|
config:
|
|
132
|
-
refreshSeconds: 60
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
refreshSeconds: 60 # suggested panel refresh interval (5–86400)
|
|
136
|
+
balanceRedThreshold: 10 # balance below this turns red (per the balance's own currency)
|
|
137
|
+
balanceYellowThreshold: 30 # balance below this turns yellow (per the balance's own currency)
|
|
138
|
+
autoDetect: true # enumerate provider routes from the llm registry
|
|
139
|
+
providers: [] # manual specs; an id matching a detected route overrides it
|
|
135
140
|
```
|
|
136
141
|
|
|
137
142
|
| Field | Type | Default | Description |
|
|
138
143
|
| --- | --- | --- | --- |
|
|
139
144
|
| `refreshSeconds` | number | `60` | Suggested widget refresh interval in seconds (5–86400) |
|
|
145
|
+
| `balanceRedThreshold` | number | `10` | Balance below this amount turns red, compared in the balance's own currency |
|
|
146
|
+
| `balanceYellowThreshold` | number | `30` | Balance below this amount turns yellow, compared in the balance's own currency |
|
|
140
147
|
| `autoDetect` | boolean | `true` | Enumerate live provider routes from the llm registry |
|
|
141
148
|
| `providers` | array | `[]` | Manual provider specs: `{id, kind, baseURL, apiKeyEnv, displayName?, enabled?}`; `kind` is one of the adapter table above |
|
|
142
149
|
|
package/README_ZH.md
CHANGED
|
@@ -33,17 +33,20 @@
|
|
|
33
33
|
| `vercel-ai-gateway` | `vercel-ai-gateway` | `GET {baseURL}/v1/credits` | 团队 credit 余额 |
|
|
34
34
|
| `xai` | `xai` | `GET {baseURL}/billing/credits` | 预付余额(USD) |
|
|
35
35
|
- **密钥安全** —— 通过 harness 凭据服务按次解析(环境变量 / `~/.dsh/.credentials.yaml`),不缓存、不落地。对 OAuth 类 Provider(OpenAI Codex)则直接读取登录流程存入的授权记录,并在令牌临近过期时自动刷新。
|
|
36
|
-
- **悬浮球入口** —— 可任意拖动的悬浮球点击弹出用量面板,位置持久化;默认停靠在主对话区域左下角(左边距 =
|
|
36
|
+
- **悬浮球入口** —— 可任意拖动的悬浮球点击弹出用量面板,位置持久化;默认停靠在主对话区域左下角(左边距 = 底边距),面板头部的归位按钮一键回到默认位置;Provider 列表超过面板高度时自动滚动,面板**顶部边缘可拖拽**调整面板高度(变长/变短,localStorage 持久化);球体光晕表达**当前正在使用**的 Provider——即**当前聚焦 session 自己的模型选择**(composer 模型座同源,客户端实时跟踪),因此切换 session 后无需重新选择模型,面板会立即把"使用中"标记切到该 session 的 Provider:绿色正常、黄色配额剩余不足 30% 或余额低于黄阈值、红色查询失败/缺密钥/用量 ≥90% 或余额低于红阈值。闲置的 Provider 余量不足不再影响悬浮球颜色——切换到余量充足的另一个 Provider 后球体会恢复绿色;面板会标注"使用中"的 Provider,并照常列出所有 Provider 的用量明细。
|
|
37
37
|
- **版本徽章** —— 面板标题旁显示当前运行的插件版本,一眼确认加载的是哪个发布版。
|
|
38
38
|
- **中英双语** —— 面板内置中英文界面,默认跟随 harness 系统语言,标题栏按钮一键切换(localStorage 持久化)。
|
|
39
39
|
- **刷新周期可调** —— 面板内调整(15s–30min,localStorage 持久化),默认值由插件配置提供。
|
|
40
|
+
- **余额阈值可调** —— 余额型 Provider(DeepSeek、Moonshot、Vercel AI Gateway、xAI)以及 usage 型 Provider 中的 `credits` 行(OpenRouter、OpenAI Codex)会按余额数值变色:低于红阈值变红、低于黄阈值变黄(按查询到的币种本身比较,默认红 < 10、黄 < 30,人民币/美元一致)。两个阈值可直接在面板底部修改(localStorage 持久化),默认值由插件配置提供。同一 Provider 同时上报套餐与 credits 时二者取「或」关系:只要其中一个余量充足球体即显示绿色,两者都偏低时取较轻的警示(套餐通常先用完、credits 兜底)。
|
|
40
41
|
- **手动 provider** —— 可通过配置添加任意网关(如自建 DeepSeek 兼容端点)。
|
|
41
42
|
|
|
42
43
|
## 截图
|
|
43
44
|
|
|
44
45
|
悬浮球(左下角,绿色光晕表示全部正常)与打开的用量面板:
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
| DeepSeek 使用中 | OpenAI Codex 使用中 |
|
|
48
|
+
| --- | --- |
|
|
49
|
+
|  |  |
|
|
47
50
|
|
|
48
51
|
## 通过 OAuth 添加 OpenAI Codex
|
|
49
52
|
|
|
@@ -129,14 +132,18 @@ dsh plugin --profile web add dsh-provider-usage@latest
|
|
|
129
132
|
- id: provider-usage
|
|
130
133
|
name: dsh-provider-usage
|
|
131
134
|
config:
|
|
132
|
-
refreshSeconds: 60
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
refreshSeconds: 60 # 面板默认刷新周期(秒)
|
|
136
|
+
balanceRedThreshold: 10 # 余额低于该值变红(按余额自身币种比较)
|
|
137
|
+
balanceYellowThreshold: 30 # 余额低于该值变黄(按余额自身币种比较)
|
|
138
|
+
autoDetect: true # 自动枚举 llm 注册表中的 provider
|
|
139
|
+
providers: [] # 手动补充/覆盖 provider(id 相同则覆盖自动探测结果)
|
|
135
140
|
```
|
|
136
141
|
|
|
137
142
|
| 字段 | 类型 | 默认 | 说明 |
|
|
138
143
|
| --- | --- | --- | --- |
|
|
139
144
|
| `refreshSeconds` | number | `60` | 面板建议刷新周期(秒),5–86400 |
|
|
145
|
+
| `balanceRedThreshold` | number | `10` | 余额低于该值变红,按余额自身币种比较 |
|
|
146
|
+
| `balanceYellowThreshold` | number | `30` | 余额低于该值变黄,按余额自身币种比较 |
|
|
140
147
|
| `autoDetect` | boolean | `true` | 从 llm 注册表自动枚举 provider |
|
|
141
148
|
| `providers` | array | `[]` | 手动 provider 规格:`{id, kind, baseURL, apiKeyEnv, displayName?, enabled?}`,`kind` 取上表中的任一适配器 |
|
|
142
149
|
|
package/lib/client.js
CHANGED
|
@@ -13,11 +13,15 @@ window.__ModuleLoader__.load({
|
|
|
13
13
|
"action.label": "用量",
|
|
14
14
|
"action.aria": "Provider 用量",
|
|
15
15
|
"panel.title": "Provider 用量",
|
|
16
|
+
"panel.resize": "拖拽调整面板高度",
|
|
16
17
|
"panel.refresh": "立即刷新",
|
|
17
18
|
"panel.refreshing": "刷新中…",
|
|
18
19
|
"lang.switch": "Switch to English",
|
|
19
20
|
"panel.resetPos": "悬浮球归位",
|
|
20
21
|
"panel.interval": "刷新周期",
|
|
22
|
+
"panel.thresholds": "余额阈值",
|
|
23
|
+
"panel.thresholdRed": "红",
|
|
24
|
+
"panel.thresholdYellow": "黄",
|
|
21
25
|
"panel.updated": "更新于 {time}",
|
|
22
26
|
"panel.never": "尚未获取",
|
|
23
27
|
"panel.empty": "未检测到已配置的 Provider",
|
|
@@ -42,8 +46,8 @@ window.__ModuleLoader__.load({
|
|
|
42
46
|
"status.error": "查询失败",
|
|
43
47
|
"status.inUse": "使用中",
|
|
44
48
|
"status.tone.ok": "当前 Provider 正常",
|
|
45
|
-
"status.tone.warn": "当前 Provider
|
|
46
|
-
"status.tone.danger": "当前 Provider
|
|
49
|
+
"status.tone.warn": "当前 Provider 用量接近上限或余额偏低",
|
|
50
|
+
"status.tone.danger": "当前 Provider 异常、用量将尽或余额过低",
|
|
47
51
|
"countdown.days": "{days}天{hours}小时",
|
|
48
52
|
"countdown.hours": "{hours}小时{minutes}分",
|
|
49
53
|
"countdown.minutes": "{minutes}分钟"
|
|
@@ -53,11 +57,15 @@ window.__ModuleLoader__.load({
|
|
|
53
57
|
"action.label": "Usage",
|
|
54
58
|
"action.aria": "Provider usage",
|
|
55
59
|
"panel.title": "Provider Usage",
|
|
60
|
+
"panel.resize": "Drag to resize panel",
|
|
56
61
|
"panel.refresh": "Refresh now",
|
|
57
62
|
"panel.refreshing": "Refreshing…",
|
|
58
63
|
"lang.switch": "切换到中文",
|
|
59
64
|
"panel.resetPos": "Reset ball position",
|
|
60
65
|
"panel.interval": "Refresh interval",
|
|
66
|
+
"panel.thresholds": "Balance thresholds",
|
|
67
|
+
"panel.thresholdRed": "Red",
|
|
68
|
+
"panel.thresholdYellow": "Yellow",
|
|
61
69
|
"panel.updated": "Updated {time}",
|
|
62
70
|
"panel.never": "Not fetched yet",
|
|
63
71
|
"panel.empty": "No configured provider detected",
|
|
@@ -82,8 +90,8 @@ window.__ModuleLoader__.load({
|
|
|
82
90
|
"status.error": "Query failed",
|
|
83
91
|
"status.inUse": "In use",
|
|
84
92
|
"status.tone.ok": "Current provider healthy",
|
|
85
|
-
"status.tone.warn": "Current provider usage nearing its limit",
|
|
86
|
-
"status.tone.danger": "Current provider error
|
|
93
|
+
"status.tone.warn": "Current provider usage nearing its limit or balance running low",
|
|
94
|
+
"status.tone.danger": "Current provider error, usage almost exhausted, or balance too low",
|
|
87
95
|
"countdown.days": "{days}d {hours}h",
|
|
88
96
|
"countdown.hours": "{hours}h {minutes}m",
|
|
89
97
|
"countdown.minutes": "{minutes}m"
|
|
@@ -109,7 +117,54 @@ window.__ModuleLoader__.load({
|
|
|
109
117
|
const STORAGE_KEY = "dsh.provider-usage.refreshSeconds";
|
|
110
118
|
const LANG_KEY = "dsh.provider-usage.lang";
|
|
111
119
|
const POS_KEY = "dsh.provider-usage.floatPos";
|
|
120
|
+
const THRESHOLD_RED_KEY = "dsh.provider-usage.balanceRedThreshold";
|
|
121
|
+
const THRESHOLD_YELLOW_KEY = "dsh.provider-usage.balanceYellowThreshold";
|
|
122
|
+
const PANEL_HEIGHT_KEY = "dsh.provider-usage.panelHeight";
|
|
112
123
|
const DEFAULT_INTERVAL = 60;
|
|
124
|
+
/** Balance thresholds fall back to these hardcoded defaults when neither the
|
|
125
|
+
host config nor a stored override provides them. */
|
|
126
|
+
const DEFAULT_BALANCE_RED = 10;
|
|
127
|
+
const DEFAULT_BALANCE_YELLOW = 30;
|
|
128
|
+
/** Smallest panel height the top-edge drag allows (px). */
|
|
129
|
+
const PANEL_MIN_H = 120;
|
|
130
|
+
/** Largest panel height the top-edge drag allows: the viewport minus a
|
|
131
|
+
breathing margin, so the panel can never outgrow the screen. */
|
|
132
|
+
function panelMaxHeight() {
|
|
133
|
+
return Math.max(PANEL_MIN_H, window.innerHeight - 24);
|
|
134
|
+
}
|
|
135
|
+
/** Bottom padding of the open panel (px), read live so the layout math stays
|
|
136
|
+
correct if the stylesheet ever changes it. */
|
|
137
|
+
function panelPaddingBottom(panel) {
|
|
138
|
+
const pad = Number.parseFloat(getComputedStyle(panel).paddingBottom);
|
|
139
|
+
return Number.isFinite(pad) ? pad : 0;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Natural content height of the open panel — children plus padding — even
|
|
143
|
+
* while the panel itself is height-constrained or scrolled (children rects
|
|
144
|
+
* are compensated by scrollTop). This is the grow limit: at this height the
|
|
145
|
+
* panel needs no scrolling and leaves no blank strip at the bottom.
|
|
146
|
+
*/
|
|
147
|
+
function panelContentHeight(panel) {
|
|
148
|
+
const panelTop = panel.getBoundingClientRect().top;
|
|
149
|
+
let bottom = 0;
|
|
150
|
+
for (const child of Array.from(panel.children)) {
|
|
151
|
+
const rect = child.getBoundingClientRect();
|
|
152
|
+
bottom = Math.max(bottom, rect.bottom - panelTop + panel.scrollTop);
|
|
153
|
+
}
|
|
154
|
+
return Math.ceil(bottom) + panelPaddingBottom(panel);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Shrink limit: the height that keeps the panel head plus the FIRST provider
|
|
158
|
+
* card fully visible (bottom padding included). Falls back to PANEL_MIN_H
|
|
159
|
+
* when no provider card is present (e.g. empty list).
|
|
160
|
+
*/
|
|
161
|
+
function firstCardMinHeight(panel) {
|
|
162
|
+
const card = panel.querySelector(".dsh-usage-card");
|
|
163
|
+
if (card === null) return PANEL_MIN_H;
|
|
164
|
+
const panelTop = panel.getBoundingClientRect().top;
|
|
165
|
+
const cardRect = card.getBoundingClientRect();
|
|
166
|
+
return Math.ceil(cardRect.bottom - panelTop + panel.scrollTop) + panelPaddingBottom(panel);
|
|
167
|
+
}
|
|
113
168
|
/** Floating ball diameter in px; drag math derives from it. */
|
|
114
169
|
const BALL_SIZE = 32;
|
|
115
170
|
/** Panel-level override stored in localStorage; null means follow the harness language. */
|
|
@@ -149,6 +204,43 @@ window.__ModuleLoader__.load({
|
|
|
149
204
|
localStorage.setItem(STORAGE_KEY, String(value));
|
|
150
205
|
} catch {}
|
|
151
206
|
}
|
|
207
|
+
/** Parse a threshold input: a finite number ≥ 0, or null while the field is
|
|
208
|
+
empty/transiently invalid (the string is kept in state so typing never
|
|
209
|
+
fights the controlled input). */
|
|
210
|
+
function parseThreshold(raw) {
|
|
211
|
+
const trimmed = raw.trim();
|
|
212
|
+
if (trimmed === "") return null;
|
|
213
|
+
const value = Number(trimmed);
|
|
214
|
+
return Number.isFinite(value) && value >= 0 ? value : null;
|
|
215
|
+
}
|
|
216
|
+
function readStoredThreshold(key) {
|
|
217
|
+
try {
|
|
218
|
+
const raw = localStorage.getItem(key);
|
|
219
|
+
return raw !== null && parseThreshold(raw) !== null ? raw : null;
|
|
220
|
+
} catch {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function storeThreshold(key, value) {
|
|
225
|
+
try {
|
|
226
|
+
localStorage.setItem(key, value);
|
|
227
|
+
} catch {}
|
|
228
|
+
}
|
|
229
|
+
function readStoredPanelHeight() {
|
|
230
|
+
try {
|
|
231
|
+
const raw = localStorage.getItem(PANEL_HEIGHT_KEY);
|
|
232
|
+
if (raw === null) return null;
|
|
233
|
+
const value = Number(raw);
|
|
234
|
+
return Number.isFinite(value) && value >= PANEL_MIN_H ? value : null;
|
|
235
|
+
} catch {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function storePanelHeight(value) {
|
|
240
|
+
try {
|
|
241
|
+
localStorage.setItem(PANEL_HEIGHT_KEY, String(value));
|
|
242
|
+
} catch {}
|
|
243
|
+
}
|
|
152
244
|
/** Equal margin from the chat area's left edge and the window's bottom edge. */
|
|
153
245
|
const DOCK_MARGIN = 24;
|
|
154
246
|
/**
|
|
@@ -220,11 +312,58 @@ window.__ModuleLoader__.load({
|
|
|
220
312
|
if (percent >= 70) return "warn";
|
|
221
313
|
return "ok";
|
|
222
314
|
}
|
|
315
|
+
/** Parse a balance amount string ("12.34", "0.00") into a number. */
|
|
316
|
+
function toAmount(value) {
|
|
317
|
+
const parsed = Number(value);
|
|
318
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Tone for a monetary balance, compared in the balance's own currency:
|
|
322
|
+
* below the red threshold → danger, below the yellow threshold → warn,
|
|
323
|
+
* otherwise ok. The effective red threshold never exceeds the yellow one,
|
|
324
|
+
* so the zones stay ordered no matter how the panel is configured.
|
|
325
|
+
*/
|
|
326
|
+
function balanceTone(value, red, yellow) {
|
|
327
|
+
if (value === null) return "ok";
|
|
328
|
+
if (value < Math.min(red, yellow)) return "danger";
|
|
329
|
+
if (value < yellow) return "warn";
|
|
330
|
+
return "ok";
|
|
331
|
+
}
|
|
332
|
+
const TONE_SEVERITY = {
|
|
333
|
+
ok: 0,
|
|
334
|
+
warn: 1,
|
|
335
|
+
danger: 2
|
|
336
|
+
};
|
|
337
|
+
/** More severe of two tones; used WITHIN one category. */
|
|
338
|
+
function worseTone(a, b) {
|
|
339
|
+
if (a === null) return b;
|
|
340
|
+
if (b === null) return a;
|
|
341
|
+
return TONE_SEVERITY[a] >= TONE_SEVERITY[b] ? a : b;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Aggregate tone for one provider. The subscription/usage windows ("plan")
|
|
345
|
+
* and the prepaid balance/credits are two INDEPENDENT categories joined with
|
|
346
|
+
* OR semantics: the provider stays green while either category has enough
|
|
347
|
+
* left (the plan is normally consumed before credits, so the surviving
|
|
348
|
+
* resource sets the tone), and when both are running low the lighter warning
|
|
349
|
+
* wins. Within one category the worst row still governs — an exhausted 5h
|
|
350
|
+
* window is not "enough plan" just because the weekly window is healthy.
|
|
351
|
+
*/
|
|
352
|
+
function providerTone(provider, red, yellow) {
|
|
353
|
+
let planTone = null;
|
|
354
|
+
let creditTone = null;
|
|
355
|
+
if (provider.kind === "balance") for (const row of provider.balances ?? []) creditTone = worseTone(creditTone, balanceTone(toAmount(row.total), red, yellow));
|
|
356
|
+
for (const row of provider.usages ?? []) if (row.label === "credits") creditTone = worseTone(creditTone, balanceTone(row.remaining, red, yellow));
|
|
357
|
+
else planTone = worseTone(planTone, barTone(row.percent));
|
|
358
|
+
if (planTone === null) return creditTone ?? "ok";
|
|
359
|
+
if (creditTone === null) return planTone;
|
|
360
|
+
return TONE_SEVERITY[planTone] <= TONE_SEVERITY[creditTone] ? planTone : creditTone;
|
|
361
|
+
}
|
|
223
362
|
/** Worst health across the fetch + the provider IN USE: drives the trigger's
|
|
224
363
|
status dot. Only the active provider (the composer's current selection)
|
|
225
364
|
colors the ball, so an idle low-quota provider does not alarm; when the
|
|
226
365
|
host reports no active provider, fall back to every provider. */
|
|
227
|
-
function healthTone(data, error) {
|
|
366
|
+
function healthTone(data, error, red, yellow) {
|
|
228
367
|
if (error !== null) return "danger";
|
|
229
368
|
const providers = data?.providers ?? [];
|
|
230
369
|
const active = providers.filter((provider) => provider.active);
|
|
@@ -232,11 +371,9 @@ window.__ModuleLoader__.load({
|
|
|
232
371
|
let tone = "ok";
|
|
233
372
|
for (const provider of relevant) {
|
|
234
373
|
if (provider.status === "error" || provider.status === "missing-credential" || provider.status === "missing-authorization") return "danger";
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (rowTone === "warn") tone = "warn";
|
|
239
|
-
}
|
|
374
|
+
const providerToneValue = providerTone(provider, red, yellow);
|
|
375
|
+
if (providerToneValue === "danger") return "danger";
|
|
376
|
+
if (providerToneValue === "warn") tone = "warn";
|
|
240
377
|
}
|
|
241
378
|
return tone;
|
|
242
379
|
}
|
|
@@ -244,11 +381,37 @@ window.__ModuleLoader__.load({
|
|
|
244
381
|
if (value === null) return "—";
|
|
245
382
|
return Number.isInteger(value) ? String(value) : value.toFixed(2);
|
|
246
383
|
}
|
|
247
|
-
|
|
384
|
+
/**
|
|
385
|
+
* Refine the host's `active` flags with the provider of the FOCUSED session
|
|
386
|
+
* (the composer's own state), so a session switch re-highlights instantly
|
|
387
|
+
* even though the host only tracks the last explicit selection. Returns the
|
|
388
|
+
* same object when nothing changes; `undefined` provider leaves the host's
|
|
389
|
+
* flags untouched.
|
|
390
|
+
*/
|
|
391
|
+
function applyActiveProvider(data, provider) {
|
|
392
|
+
if (provider === void 0 || !Array.isArray(data.providers)) return data;
|
|
393
|
+
let changed = false;
|
|
394
|
+
const providers = data.providers.map((entry) => {
|
|
395
|
+
const active = entry.id === provider;
|
|
396
|
+
if (active === entry.active) return entry;
|
|
397
|
+
changed = true;
|
|
398
|
+
return {
|
|
399
|
+
...entry,
|
|
400
|
+
active
|
|
401
|
+
};
|
|
402
|
+
});
|
|
403
|
+
return changed ? {
|
|
404
|
+
...data,
|
|
405
|
+
providers
|
|
406
|
+
} : data;
|
|
407
|
+
}
|
|
408
|
+
function UsageRows({ provider, now, red, yellow, t }) {
|
|
248
409
|
const rows = provider.usages ?? [];
|
|
249
410
|
if (rows.length === 0) return null;
|
|
250
411
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: rows.map((row, index) => {
|
|
251
412
|
const percent = row.percent;
|
|
413
|
+
const isCredits = row.label === "credits";
|
|
414
|
+
const tone = isCredits ? balanceTone(row.remaining, red, yellow) : barTone(row.percent);
|
|
252
415
|
const reset = row.resetAt !== null ? formatCountdown(row.resetAt, now, t) : null;
|
|
253
416
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
254
417
|
className: "dsh-usage-row",
|
|
@@ -259,14 +422,14 @@ window.__ModuleLoader__.load({
|
|
|
259
422
|
className: "dsh-usage-rowLabel",
|
|
260
423
|
children: row.label === "weekly" ? t("usage.weekly") : row.label
|
|
261
424
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
262
|
-
className: "dsh-usage-rowValue
|
|
263
|
-
children: row.limit === null ? row.used !== null ? t("usage.used", { used: formatAmount(row.used) }) : row.remaining !== null ? formatAmount(row.remaining) : t("usage.unlimited") : percent !== null ? `${Math.round(percent)}%` : t("usage.used", { used: formatAmount(row.used) })
|
|
425
|
+
className: `dsh-usage-rowValue${tone === "ok" ? "" : ` dsh-usage-rowValue--${tone}`}`,
|
|
426
|
+
children: isCredits && row.remaining !== null ? formatAmount(row.remaining) : row.limit === null ? row.used !== null ? t("usage.used", { used: formatAmount(row.used) }) : row.remaining !== null ? formatAmount(row.remaining) : t("usage.unlimited") : percent !== null ? `${Math.round(percent)}%` : t("usage.used", { used: formatAmount(row.used) })
|
|
264
427
|
})]
|
|
265
428
|
}),
|
|
266
429
|
percent !== null ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
267
430
|
className: "dsh-usage-barTrack",
|
|
268
431
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
269
|
-
className: `dsh-usage-barFill dsh-usage-barFill--${
|
|
432
|
+
className: `dsh-usage-barFill dsh-usage-barFill--${tone}`,
|
|
270
433
|
style: { width: `${Math.min(100, Math.max(0, percent))}%` }
|
|
271
434
|
})
|
|
272
435
|
}) : null,
|
|
@@ -278,7 +441,7 @@ window.__ModuleLoader__.load({
|
|
|
278
441
|
}, `${row.label}-${index}`);
|
|
279
442
|
}) });
|
|
280
443
|
}
|
|
281
|
-
function ProviderCard({ provider, now, t }) {
|
|
444
|
+
function ProviderCard({ provider, now, red, yellow, t }) {
|
|
282
445
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
283
446
|
className: `dsh-usage-card${provider.active ? " dsh-usage-card--active" : ""}`,
|
|
284
447
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -306,21 +469,26 @@ window.__ModuleLoader__.load({
|
|
|
306
469
|
": ",
|
|
307
470
|
provider.message
|
|
308
471
|
]
|
|
309
|
-
}) : provider.kind === "balance" ? (provider.balances ?? []).map((row, index) =>
|
|
310
|
-
|
|
311
|
-
children: [/* @__PURE__ */ (0, react_jsx_runtime.
|
|
312
|
-
className: "dsh-usage-
|
|
313
|
-
children:
|
|
472
|
+
}) : provider.kind === "balance" ? (provider.balances ?? []).map((row, index) => {
|
|
473
|
+
const tone = balanceTone(toAmount(row.total), red, yellow);
|
|
474
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
475
|
+
className: "dsh-usage-balanceRow",
|
|
476
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
477
|
+
className: `dsh-usage-balanceTotal${tone === "ok" ? "" : ` dsh-usage-balanceTotal--${tone}`}`,
|
|
478
|
+
children: row.total
|
|
479
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
480
|
+
className: "dsh-usage-balanceCurrency",
|
|
481
|
+
children: row.currency
|
|
482
|
+
})]
|
|
314
483
|
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
315
|
-
className: "dsh-usage-
|
|
316
|
-
children: row.
|
|
317
|
-
})]
|
|
318
|
-
})
|
|
319
|
-
className: "dsh-usage-balanceParts",
|
|
320
|
-
children: [row.granted !== "0" && row.granted !== "0.00" ? t("balance.granted", { amount: row.granted }) : null, row.toppedUp !== "0" && row.toppedUp !== "0.00" ? t("balance.toppedUp", { amount: row.toppedUp }) : null].filter(Boolean).join(" · ")
|
|
321
|
-
})] }, `${row.currency}-${index}`)) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageRows, {
|
|
484
|
+
className: "dsh-usage-balanceParts",
|
|
485
|
+
children: [row.granted !== "0" && row.granted !== "0.00" ? t("balance.granted", { amount: row.granted }) : null, row.toppedUp !== "0" && row.toppedUp !== "0.00" ? t("balance.toppedUp", { amount: row.toppedUp }) : null].filter(Boolean).join(" · ")
|
|
486
|
+
})] }, `${row.currency}-${index}`);
|
|
487
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UsageRows, {
|
|
322
488
|
provider,
|
|
323
489
|
now,
|
|
490
|
+
red,
|
|
491
|
+
yellow,
|
|
324
492
|
t
|
|
325
493
|
})]
|
|
326
494
|
});
|
|
@@ -417,13 +585,18 @@ window.__ModuleLoader__.load({
|
|
|
417
585
|
]
|
|
418
586
|
});
|
|
419
587
|
}
|
|
420
|
-
function UsageAction({ t, fetchUsage }) {
|
|
588
|
+
function UsageAction({ t, fetchUsage, getActiveProvider, subscribeActiveChange }) {
|
|
421
589
|
const [open, setOpen] = (0, react.useState)(false);
|
|
422
590
|
const [data, setData] = (0, react.useState)(null);
|
|
423
591
|
const [error, setError] = (0, react.useState)(null);
|
|
424
592
|
const [loading, setLoading] = (0, react.useState)(false);
|
|
425
593
|
const [intervalSec, setIntervalSec] = (0, react.useState)(() => readStoredInterval() ?? DEFAULT_INTERVAL);
|
|
426
594
|
const [langOverride, setLangOverride] = (0, react.useState)(() => readStoredLang());
|
|
595
|
+
/** Balance thresholds as raw input strings (kept as text so typing never
|
|
596
|
+
fights the controlled input); parsed on use, overridden locally only
|
|
597
|
+
after the user edits them. */
|
|
598
|
+
const [redThreshold, setRedThreshold] = (0, react.useState)(() => readStoredThreshold(THRESHOLD_RED_KEY) ?? String(DEFAULT_BALANCE_RED));
|
|
599
|
+
const [yellowThreshold, setYellowThreshold] = (0, react.useState)(() => readStoredThreshold(THRESHOLD_YELLOW_KEY) ?? String(DEFAULT_BALANCE_YELLOW));
|
|
427
600
|
const [now, setNow] = (0, react.useState)(() => Date.now());
|
|
428
601
|
/** Pinned spot (user-dragged) as viewport fractions; null = follow the default dock. */
|
|
429
602
|
const [pinnedPos, setPinnedPos] = (0, react.useState)(() => readStoredFloatPos());
|
|
@@ -434,6 +607,9 @@ window.__ModuleLoader__.load({
|
|
|
434
607
|
});
|
|
435
608
|
/** Transient ball position while dragging (cursor-centered); null when docked. */
|
|
436
609
|
const [dragPos, setDragPos] = (0, react.useState)(null);
|
|
610
|
+
/** User-resized panel height in px; null = auto-size to content (max-height
|
|
611
|
+
+ scroll). Persisted, like every other panel preference. */
|
|
612
|
+
const [panelHeight, setPanelHeight] = (0, react.useState)(() => readStoredPanelHeight());
|
|
437
613
|
const harnessLang = t("lang.switch") === zh["lang.switch"] ? "zh" : t("lang.switch") === en["lang.switch"] ? "en" : null;
|
|
438
614
|
const lang = langOverride ?? harnessLang ?? "en";
|
|
439
615
|
const tt = (0, react.useMemo)(() => makeT(lang === "zh" ? zh : en), [lang]);
|
|
@@ -458,13 +634,18 @@ window.__ModuleLoader__.load({
|
|
|
458
634
|
const dragRef = (0, react.useRef)(null);
|
|
459
635
|
/** Set when a drag ends so the trailing click does not toggle the panel. */
|
|
460
636
|
const suppressClickRef = (0, react.useRef)(false);
|
|
637
|
+
/** Active panel-height drag; cleared on pointerup/pointercancel. */
|
|
638
|
+
const resizeRef = (0, react.useRef)(null);
|
|
639
|
+
/** Resize bounds snapshotted at drag start from the live layout: min = first
|
|
640
|
+
provider card fully visible, max = content height (no scroll, no blank). */
|
|
641
|
+
const resizeLimitsRef = (0, react.useRef)(null);
|
|
461
642
|
const refresh = (0, react.useCallback)(async () => {
|
|
462
643
|
if (inFlight.current) return;
|
|
463
644
|
inFlight.current = true;
|
|
464
645
|
setLoading(true);
|
|
465
646
|
try {
|
|
466
647
|
const result = await fetchUsage();
|
|
467
|
-
setData(result);
|
|
648
|
+
setData(applyActiveProvider(result, getActiveProvider?.()));
|
|
468
649
|
setError(null);
|
|
469
650
|
} catch (reason) {
|
|
470
651
|
setError(reason instanceof Error ? reason.message : String(reason));
|
|
@@ -472,7 +653,7 @@ window.__ModuleLoader__.load({
|
|
|
472
653
|
inFlight.current = false;
|
|
473
654
|
setLoading(false);
|
|
474
655
|
}
|
|
475
|
-
}, [fetchUsage]);
|
|
656
|
+
}, [fetchUsage, getActiveProvider]);
|
|
476
657
|
(0, react.useEffect)(() => {
|
|
477
658
|
refresh();
|
|
478
659
|
}, [refresh]);
|
|
@@ -485,6 +666,16 @@ window.__ModuleLoader__.load({
|
|
|
485
666
|
(0, react.useEffect)(() => {
|
|
486
667
|
if (data !== null && readStoredInterval() === null && data.refreshSeconds !== intervalSec) setIntervalSec(data.refreshSeconds);
|
|
487
668
|
}, [data]);
|
|
669
|
+
(0, react.useEffect)(() => {
|
|
670
|
+
if (data === null) return;
|
|
671
|
+
if (readStoredThreshold(THRESHOLD_RED_KEY) === null && typeof data.balanceRedThreshold === "number") setRedThreshold(String(data.balanceRedThreshold));
|
|
672
|
+
if (readStoredThreshold(THRESHOLD_YELLOW_KEY) === null && typeof data.balanceYellowThreshold === "number") setYellowThreshold(String(data.balanceYellowThreshold));
|
|
673
|
+
}, [data]);
|
|
674
|
+
(0, react.useEffect)(() => {
|
|
675
|
+
return subscribeActiveChange?.(() => {
|
|
676
|
+
setData((prev) => prev === null ? prev : applyActiveProvider(prev, getActiveProvider?.()));
|
|
677
|
+
});
|
|
678
|
+
}, []);
|
|
488
679
|
(0, react.useEffect)(() => {
|
|
489
680
|
if (!open) return;
|
|
490
681
|
setNow(Date.now());
|
|
@@ -525,6 +716,16 @@ window.__ModuleLoader__.load({
|
|
|
525
716
|
pinnedPos,
|
|
526
717
|
viewport
|
|
527
718
|
]);
|
|
719
|
+
(0, react.useLayoutEffect)(() => {
|
|
720
|
+
const panel = panelRef.current;
|
|
721
|
+
if (panel === null || panelHeight === null) return;
|
|
722
|
+
const clamped = Math.min(panelHeight, panelContentHeight(panel), panelMaxHeight());
|
|
723
|
+
if (clamped !== panelHeight) setPanelHeight(clamped);
|
|
724
|
+
}, [
|
|
725
|
+
panelHeight,
|
|
726
|
+
data,
|
|
727
|
+
open
|
|
728
|
+
]);
|
|
528
729
|
(0, react.useEffect)(() => {
|
|
529
730
|
const onResize = () => setViewport({
|
|
530
731
|
w: window.innerWidth,
|
|
@@ -533,7 +734,9 @@ window.__ModuleLoader__.load({
|
|
|
533
734
|
window.addEventListener("resize", onResize);
|
|
534
735
|
return () => window.removeEventListener("resize", onResize);
|
|
535
736
|
}, []);
|
|
536
|
-
const
|
|
737
|
+
const effYellow = parseThreshold(yellowThreshold) ?? DEFAULT_BALANCE_YELLOW;
|
|
738
|
+
const effRed = Math.min(parseThreshold(redThreshold) ?? DEFAULT_BALANCE_RED, effYellow);
|
|
739
|
+
const tone = healthTone(data, error, effRed, effYellow);
|
|
537
740
|
const onKeyDown = (event) => {
|
|
538
741
|
if (event.key !== "Escape" || !open) return;
|
|
539
742
|
event.preventDefault();
|
|
@@ -583,6 +786,45 @@ window.__ModuleLoader__.load({
|
|
|
583
786
|
dragRef.current = null;
|
|
584
787
|
setDragPos(null);
|
|
585
788
|
};
|
|
789
|
+
const onResizePointerDown = (event) => {
|
|
790
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
791
|
+
const panel = panelRef.current;
|
|
792
|
+
const rect = panel?.getBoundingClientRect();
|
|
793
|
+
const startHeight = panelHeight ?? Math.round(rect?.height ?? 0);
|
|
794
|
+
if (panel !== null) {
|
|
795
|
+
const viewportMax = panelMaxHeight();
|
|
796
|
+
const max = Math.min(panelContentHeight(panel), viewportMax);
|
|
797
|
+
const min = Math.min(Math.max(firstCardMinHeight(panel), PANEL_MIN_H), max);
|
|
798
|
+
resizeLimitsRef.current = {
|
|
799
|
+
min,
|
|
800
|
+
max
|
|
801
|
+
};
|
|
802
|
+
} else resizeLimitsRef.current = {
|
|
803
|
+
min: PANEL_MIN_H,
|
|
804
|
+
max: panelMaxHeight()
|
|
805
|
+
};
|
|
806
|
+
resizeRef.current = {
|
|
807
|
+
pointerId: event.pointerId,
|
|
808
|
+
startY: event.clientY,
|
|
809
|
+
startHeight,
|
|
810
|
+
current: startHeight
|
|
811
|
+
};
|
|
812
|
+
};
|
|
813
|
+
const onResizePointerMove = (event) => {
|
|
814
|
+
const resize = resizeRef.current;
|
|
815
|
+
if (resize === null || resize.pointerId !== event.pointerId) return;
|
|
816
|
+
const limits = resizeLimitsRef.current;
|
|
817
|
+
const next = limits === null ? resize.startHeight + (resize.startY - event.clientY) : Math.min(Math.max(resize.startHeight + (resize.startY - event.clientY), limits.min), limits.max);
|
|
818
|
+
resize.current = next;
|
|
819
|
+
setPanelHeight(next);
|
|
820
|
+
};
|
|
821
|
+
const endResize = (event) => {
|
|
822
|
+
const resize = resizeRef.current;
|
|
823
|
+
if (resize === null || resize.pointerId !== event.pointerId) return;
|
|
824
|
+
resizeRef.current = null;
|
|
825
|
+
resizeLimitsRef.current = null;
|
|
826
|
+
storePanelHeight(resize.current);
|
|
827
|
+
};
|
|
586
828
|
const onBallClick = () => {
|
|
587
829
|
if (suppressClickRef.current) {
|
|
588
830
|
suppressClickRef.current = false;
|
|
@@ -625,10 +867,23 @@ window.__ModuleLoader__.load({
|
|
|
625
867
|
style: {
|
|
626
868
|
left: panelPos.left,
|
|
627
869
|
top: panelPos.top,
|
|
628
|
-
bottom: panelPos.bottom
|
|
870
|
+
bottom: panelPos.bottom,
|
|
871
|
+
...panelHeight !== null ? {
|
|
872
|
+
height: Math.min(panelHeight, panelMaxHeight()),
|
|
873
|
+
maxHeight: "none"
|
|
874
|
+
} : {}
|
|
629
875
|
},
|
|
630
876
|
onKeyDown,
|
|
631
877
|
children: [
|
|
878
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
879
|
+
className: "dsh-usage-resize",
|
|
880
|
+
title: tt("panel.resize"),
|
|
881
|
+
"aria-label": tt("panel.resize"),
|
|
882
|
+
onPointerDown: onResizePointerDown,
|
|
883
|
+
onPointerMove: onResizePointerMove,
|
|
884
|
+
onPointerUp: endResize,
|
|
885
|
+
onPointerCancel: endResize
|
|
886
|
+
}),
|
|
632
887
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
633
888
|
className: "dsh-usage-head",
|
|
634
889
|
children: [
|
|
@@ -682,6 +937,8 @@ window.__ModuleLoader__.load({
|
|
|
682
937
|
(data?.providers ?? []).map((provider) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProviderCard, {
|
|
683
938
|
provider,
|
|
684
939
|
now,
|
|
940
|
+
red: effRed,
|
|
941
|
+
yellow: effYellow,
|
|
685
942
|
t: tt
|
|
686
943
|
}, provider.id)),
|
|
687
944
|
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
@@ -709,6 +966,53 @@ window.__ModuleLoader__.load({
|
|
|
709
966
|
children: data === null ? tt("panel.never") : tt("panel.updated", { time: new Date(data.fetchedAt).toLocaleTimeString(lang === "zh" ? "zh-CN" : "en-US") })
|
|
710
967
|
})
|
|
711
968
|
]
|
|
969
|
+
}),
|
|
970
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
971
|
+
className: "dsh-usage-thresholds",
|
|
972
|
+
children: [
|
|
973
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
974
|
+
className: "dsh-usage-footLabel",
|
|
975
|
+
children: tt("panel.thresholds")
|
|
976
|
+
}),
|
|
977
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
978
|
+
className: "dsh-usage-thresholdField",
|
|
979
|
+
title: tt("panel.thresholdRed"),
|
|
980
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
981
|
+
className: "dsh-usage-thresholdLabel dsh-usage-thresholdLabel--red",
|
|
982
|
+
children: tt("panel.thresholdRed")
|
|
983
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
984
|
+
className: "dsh-usage-thresholdInput",
|
|
985
|
+
type: "number",
|
|
986
|
+
min: 0,
|
|
987
|
+
step: .01,
|
|
988
|
+
inputMode: "decimal",
|
|
989
|
+
value: redThreshold,
|
|
990
|
+
onChange: (event) => {
|
|
991
|
+
setRedThreshold(event.target.value);
|
|
992
|
+
storeThreshold(THRESHOLD_RED_KEY, event.target.value);
|
|
993
|
+
}
|
|
994
|
+
})]
|
|
995
|
+
}),
|
|
996
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
|
|
997
|
+
className: "dsh-usage-thresholdField",
|
|
998
|
+
title: tt("panel.thresholdYellow"),
|
|
999
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1000
|
+
className: "dsh-usage-thresholdLabel dsh-usage-thresholdLabel--yellow",
|
|
1001
|
+
children: tt("panel.thresholdYellow")
|
|
1002
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
1003
|
+
className: "dsh-usage-thresholdInput",
|
|
1004
|
+
type: "number",
|
|
1005
|
+
min: 0,
|
|
1006
|
+
step: .01,
|
|
1007
|
+
inputMode: "decimal",
|
|
1008
|
+
value: yellowThreshold,
|
|
1009
|
+
onChange: (event) => {
|
|
1010
|
+
setYellowThreshold(event.target.value);
|
|
1011
|
+
storeThreshold(THRESHOLD_YELLOW_KEY, event.target.value);
|
|
1012
|
+
}
|
|
1013
|
+
})]
|
|
1014
|
+
})
|
|
1015
|
+
]
|
|
712
1016
|
})
|
|
713
1017
|
]
|
|
714
1018
|
}), document.body) : null]
|
|
@@ -780,6 +1084,27 @@ window.__ModuleLoader__.load({
|
|
|
780
1084
|
--dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);
|
|
781
1085
|
--dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);
|
|
782
1086
|
}
|
|
1087
|
+
/* Top-edge resize handle: sticks to the panel top even while the body
|
|
1088
|
+
scrolls, so it is always grabbable; drag to make the panel taller/shorter
|
|
1089
|
+
(height persisted in localStorage). */
|
|
1090
|
+
.dsh-usage-resize {
|
|
1091
|
+
position: sticky; top: 0; z-index: 2; flex: none;
|
|
1092
|
+
height: 6px; margin: -4px 0 0;
|
|
1093
|
+
cursor: ns-resize; touch-action: none;
|
|
1094
|
+
border-radius: 3px;
|
|
1095
|
+
}
|
|
1096
|
+
.dsh-usage-resize::after {
|
|
1097
|
+
content: ''; position: absolute; left: 50%; top: 50%;
|
|
1098
|
+
transform: translate(-50%, -50%);
|
|
1099
|
+
width: 32px; height: 3px; border-radius: 2px;
|
|
1100
|
+
background: var(--dsw-alias-border-l2);
|
|
1101
|
+
}
|
|
1102
|
+
.dsh-usage-resize:hover, .dsh-usage-resize:active {
|
|
1103
|
+
background: color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 25%, transparent);
|
|
1104
|
+
}
|
|
1105
|
+
.dsh-usage-resize:hover::after, .dsh-usage-resize:active::after {
|
|
1106
|
+
background: var(--dsw-alias-accent, #4f8cff);
|
|
1107
|
+
}
|
|
783
1108
|
.dsh-usage-head {
|
|
784
1109
|
display: flex; align-items: center; gap: 8px; padding: 2px 4px 6px;
|
|
785
1110
|
border-bottom: 1px solid var(--dsw-alias-border-l2);
|
|
@@ -838,12 +1163,19 @@ window.__ModuleLoader__.load({
|
|
|
838
1163
|
color: var(--dsw-alias-label-primary); font-size: 18px; font-weight: 600;
|
|
839
1164
|
font-variant-numeric: tabular-nums;
|
|
840
1165
|
}
|
|
1166
|
+
/* Balance below the user-configured thresholds: red < red threshold, yellow
|
|
1167
|
+
below the yellow threshold; a healthy balance keeps the default label color. */
|
|
1168
|
+
.dsh-usage-balanceTotal--warn { color: #e2b93b; }
|
|
1169
|
+
.dsh-usage-balanceTotal--danger { color: #d94f4f; }
|
|
841
1170
|
.dsh-usage-balanceCurrency { color: var(--dsw-alias-label-secondary); font-size: 12px; }
|
|
842
1171
|
.dsh-usage-balanceParts { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; }
|
|
843
1172
|
.dsh-usage-row { display: flex; flex-direction: column; gap: 3px; }
|
|
844
1173
|
.dsh-usage-rowHead { display: flex; align-items: center; gap: 8px; font-size: 12px; line-height: 18px; }
|
|
845
1174
|
.dsh-usage-rowLabel { color: var(--dsw-alias-label-secondary); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
846
1175
|
.dsh-usage-rowValue { color: var(--dsw-alias-label-tertiary); font-variant-numeric: tabular-nums; flex: none; }
|
|
1176
|
+
/* Credits rows show a remaining balance: tinted by the balance thresholds. */
|
|
1177
|
+
.dsh-usage-rowValue--warn { color: #e2b93b; }
|
|
1178
|
+
.dsh-usage-rowValue--danger { color: #d94f4f; }
|
|
847
1179
|
.dsh-usage-barTrack {
|
|
848
1180
|
height: 4px; border-radius: 2px; overflow: hidden;
|
|
849
1181
|
background: var(--dsw-alias-border-l2);
|
|
@@ -863,6 +1195,25 @@ window.__ModuleLoader__.load({
|
|
|
863
1195
|
color: var(--dsw-alias-label-secondary); font-size: 11px; padding: 2px 4px; cursor: pointer;
|
|
864
1196
|
}
|
|
865
1197
|
.dsh-usage-updated { color: var(--dsw-alias-label-tertiary); font-size: 11px; margin-left: auto; }
|
|
1198
|
+
/* Balance threshold row under the footer: red/yellow inputs persisted locally. */
|
|
1199
|
+
.dsh-usage-thresholds {
|
|
1200
|
+
display: flex; align-items: center; gap: 10px; padding: 2px 4px 4px;
|
|
1201
|
+
}
|
|
1202
|
+
.dsh-usage-thresholdField { display: inline-flex; align-items: center; gap: 4px; }
|
|
1203
|
+
.dsh-usage-thresholdLabel { font-size: 11px; font-weight: 600; }
|
|
1204
|
+
.dsh-usage-thresholdLabel--red { color: #d94f4f; }
|
|
1205
|
+
.dsh-usage-thresholdLabel--yellow { color: #e2b93b; }
|
|
1206
|
+
.dsh-usage-thresholdInput {
|
|
1207
|
+
width: 58px; box-sizing: border-box;
|
|
1208
|
+
border: 1px solid var(--dsw-alias-border-l2); border-radius: 6px; background: 0;
|
|
1209
|
+
color: var(--dsw-alias-label-secondary); font-size: 11px; padding: 2px 4px;
|
|
1210
|
+
font-variant-numeric: tabular-nums;
|
|
1211
|
+
}
|
|
1212
|
+
.dsh-usage-thresholdInput:focus {
|
|
1213
|
+
outline: none;
|
|
1214
|
+
border-color: var(--dsw-alias-accent, #4f8cff);
|
|
1215
|
+
box-shadow: 0 0 0 1px color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 40%, transparent);
|
|
1216
|
+
}
|
|
866
1217
|
`;
|
|
867
1218
|
const TAG_ID = "dsh-provider-usage/panel.css";
|
|
868
1219
|
/** Inject the panel stylesheet once; on HMR swap, refresh the existing tag's payload in place. */
|
|
@@ -888,12 +1239,27 @@ window.__ModuleLoader__.load({
|
|
|
888
1239
|
* sidebar footer's additive action slot. Data comes from the host `usage`
|
|
889
1240
|
* Typert Remote (SRC mode — no generated descriptors) through the raw RPC
|
|
890
1241
|
* caller on the connection service.
|
|
1242
|
+
*
|
|
1243
|
+
* The "provider in use" flag is refined CLIENT-side: the host marks the route
|
|
1244
|
+
* from the GLOBAL default model selection, which only moves on an explicit
|
|
1245
|
+
* composer pick — switching between sessions with different per-session
|
|
1246
|
+
* selections would leave it stale. The focused session's own effective
|
|
1247
|
+
* selection (pending → last used → host default, mirrored by the composer's
|
|
1248
|
+
* model seat) is read live from the client session services and overrides the
|
|
1249
|
+
* host flag, so the panel follows session switches immediately.
|
|
1250
|
+
*/
|
|
1251
|
+
/**
|
|
1252
|
+
* Required client services: slot registry, locale seats, the connection RPC
|
|
1253
|
+
* caller, and the live session/model-selection state used to refine the
|
|
1254
|
+
* "in use" flag (`sessions` + `modelDirectories`, both mounted by the web
|
|
1255
|
+
* app — the latter is the composer model seat's own service).
|
|
891
1256
|
*/
|
|
892
|
-
/** Required client services: slot registry, locale seats, and the connection RPC caller. */
|
|
893
1257
|
const inject = [
|
|
894
1258
|
"slots",
|
|
895
1259
|
"locale",
|
|
896
|
-
"connection"
|
|
1260
|
+
"connection",
|
|
1261
|
+
"sessions",
|
|
1262
|
+
"modelDirectories"
|
|
897
1263
|
];
|
|
898
1264
|
function apply(ctx) {
|
|
899
1265
|
ensureStyles();
|
|
@@ -906,12 +1272,61 @@ window.__ModuleLoader__.load({
|
|
|
906
1272
|
if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
907
1273
|
return result.value;
|
|
908
1274
|
};
|
|
1275
|
+
/**
|
|
1276
|
+
* The provider the FOCUSED session's composer shows (and its agent would
|
|
1277
|
+
* use): the session's durable model selection, else the deployment default
|
|
1278
|
+
* — exactly what the host resolves per session. Undefined while the client
|
|
1279
|
+
* session state is not ready; the host's own flag then stands.
|
|
1280
|
+
*/
|
|
1281
|
+
const getActiveProvider = () => {
|
|
1282
|
+
const current = ctx.sessions?.list?.getSnapshot()?.current;
|
|
1283
|
+
if (typeof current !== "string" || current === "") return void 0;
|
|
1284
|
+
try {
|
|
1285
|
+
const provider = (ctx.modelDirectories?.directoryFor(current))?.store?.getSnapshot()?.current?.provider;
|
|
1286
|
+
return typeof provider === "string" && provider !== "" ? provider : void 0;
|
|
1287
|
+
} catch {
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
/**
|
|
1292
|
+
* Re-derive the panel's "in use" flag the moment the focused session or its
|
|
1293
|
+
* model selection changes — no need to wait for the next poll tick. The
|
|
1294
|
+
* directory subscription follows the CURRENT focused session and is
|
|
1295
|
+
* re-pointed on every session switch, so a late projection load still lands.
|
|
1296
|
+
*/
|
|
1297
|
+
const subscribeActiveChange = (onChange) => {
|
|
1298
|
+
const sessions = ctx.sessions;
|
|
1299
|
+
if (typeof sessions?.list?.subscribe !== "function") return () => {};
|
|
1300
|
+
let directoryUnsub = null;
|
|
1301
|
+
const followDirectory = () => {
|
|
1302
|
+
directoryUnsub?.();
|
|
1303
|
+
directoryUnsub = null;
|
|
1304
|
+
const current = sessions.list.getSnapshot()?.current;
|
|
1305
|
+
if (typeof current === "string" && current !== "") try {
|
|
1306
|
+
const store = ctx.modelDirectories?.directoryFor(current)?.store;
|
|
1307
|
+
if (typeof store?.subscribe === "function") directoryUnsub = store.subscribe(onChange);
|
|
1308
|
+
} catch {}
|
|
1309
|
+
};
|
|
1310
|
+
const offList = sessions.list.subscribe(() => {
|
|
1311
|
+
followDirectory();
|
|
1312
|
+
onChange();
|
|
1313
|
+
});
|
|
1314
|
+
followDirectory();
|
|
1315
|
+
return () => {
|
|
1316
|
+
offList?.();
|
|
1317
|
+
directoryUnsub?.();
|
|
1318
|
+
};
|
|
1319
|
+
};
|
|
909
1320
|
ctx.slots.inject("sidebar.footer.action", () => ctx.slots.register({
|
|
910
1321
|
name: "sidebar.footer.action",
|
|
911
1322
|
id: "provider-usage",
|
|
912
1323
|
order: 10,
|
|
913
1324
|
locale: "provider-usage",
|
|
914
|
-
inject: () => ({
|
|
1325
|
+
inject: () => ({
|
|
1326
|
+
fetchUsage,
|
|
1327
|
+
getActiveProvider,
|
|
1328
|
+
subscribeActiveChange
|
|
1329
|
+
})
|
|
915
1330
|
}, UsageAction));
|
|
916
1331
|
}
|
|
917
1332
|
//#endregion
|
package/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","names":["useState","useMemo","useCallback","useRef","createPortal"],"sources":["../src/client/locales.ts","../src/client/Panel.tsx","../src/client/styles.ts","../src/client/index.ts"],"sourcesContent":["/** Simplified Chinese dictionary (the key-set source of truth). */\nexport const zh = {\n 'action.label': '用量',\n 'action.aria': 'Provider 用量',\n 'panel.title': 'Provider 用量',\n 'panel.refresh': '立即刷新',\n 'panel.refreshing': '刷新中…',\n 'lang.switch': 'Switch to English',\n 'panel.resetPos': '悬浮球归位',\n 'panel.interval': '刷新周期',\n 'panel.updated': '更新于 {time}',\n 'panel.never': '尚未获取',\n 'panel.empty': '未检测到已配置的 Provider',\n 'interval.15s': '15 秒',\n 'interval.30s': '30 秒',\n 'interval.60s': '1 分钟',\n 'interval.300s': '5 分钟',\n 'interval.900s': '15 分钟',\n 'interval.1800s': '30 分钟',\n 'balance.total': '总额',\n 'balance.granted': '赠送 {amount}',\n 'balance.toppedUp': '充值 {amount}',\n 'usage.weekly': '每周配额',\n 'usage.used': '已用 {used}',\n 'usage.remaining': '剩余 {remaining}',\n 'usage.unlimited': '不限量',\n 'usage.resetAt': '重置于 {time}',\n 'usage.resetIn': '{countdown} 后重置',\n 'status.unsupported': '该 Provider 暂不支持额度查询',\n 'status.missingCredential': '未配置密钥({ref})',\n 'status.missingAuthorization': '未完成 OAuth 授权({key})',\n 'status.error': '查询失败',\n 'status.inUse': '使用中',\n 'status.tone.ok': '当前 Provider 正常',\n 'status.tone.warn': '当前 Provider 用量接近上限',\n 'status.tone.danger': '当前 Provider 异常或用量将尽',\n 'countdown.days': '{days}天{hours}小时',\n 'countdown.hours': '{hours}小时{minutes}分',\n 'countdown.minutes': '{minutes}分钟',\n}\n\n/** English dictionary, key-identical to the Chinese source of truth. */\nexport const en = {\n 'action.label': 'Usage',\n 'action.aria': 'Provider usage',\n 'panel.title': 'Provider Usage',\n 'panel.refresh': 'Refresh now',\n 'panel.refreshing': 'Refreshing…',\n 'lang.switch': '切换到中文',\n 'panel.resetPos': 'Reset ball position',\n 'panel.interval': 'Refresh interval',\n 'panel.updated': 'Updated {time}',\n 'panel.never': 'Not fetched yet',\n 'panel.empty': 'No configured provider detected',\n 'interval.15s': '15s',\n 'interval.30s': '30s',\n 'interval.60s': '1 min',\n 'interval.300s': '5 min',\n 'interval.900s': '15 min',\n 'interval.1800s': '30 min',\n 'balance.total': 'Total',\n 'balance.granted': 'granted {amount}',\n 'balance.toppedUp': 'topped up {amount}',\n 'usage.weekly': 'Weekly quota',\n 'usage.used': 'used {used}',\n 'usage.remaining': '{remaining} left',\n 'usage.unlimited': 'Unlimited',\n 'usage.resetAt': 'Resets at {time}',\n 'usage.resetIn': 'Resets in {countdown}',\n 'status.unsupported': 'Usage query is not supported for this provider',\n 'status.missingCredential': 'No API key configured ({ref})',\n 'status.missingAuthorization': 'OAuth authorization missing ({key})',\n 'status.error': 'Query failed',\n 'status.inUse': 'In use',\n 'status.tone.ok': 'Current provider healthy',\n 'status.tone.warn': 'Current provider usage nearing its limit',\n 'status.tone.danger': 'Current provider error or usage almost exhausted',\n 'countdown.days': '{days}d {hours}h',\n 'countdown.hours': '{hours}h {minutes}m',\n 'countdown.minutes': '{minutes}m',\n}\n","/**\n * Floating-ball quota widget: a draggable ball portaled to document.body\n * (the sidebar slot only mounts the component; the button itself no longer\n * lives in the sidebar, avoiding slot layout contention with other plugins).\n * The popover panel lists every configured provider's live balance/quota.\n * Polling interval is user-selectable (persisted in localStorage) and falls\n * back to the deployment-suggested value from the host plugin config.\n */\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport { en, zh } from './locales'\n\n/* ------------------------------------------------------------------ *\n * Wire views (mirror of the host half)\n * ------------------------------------------------------------------ */\n\ninterface BalanceRow {\n currency: string\n total: string\n granted: string\n toppedUp: string\n}\n\ninterface UsageRow {\n label: string\n used: number | null\n limit: number | null\n remaining: number | null\n percent: number | null\n resetAt: string | null\n}\n\ninterface ProviderUsageView {\n id: string\n displayName: string\n kind: 'balance' | 'usage' | null\n status: 'ok' | 'error' | 'missing-credential' | 'missing-authorization' | 'unsupported'\n message: string | null\n balances: BalanceRow[] | null\n usages: UsageRow[] | null\n /** The provider in use (absent on older hosts); it alone drives the ball tone. */\n active?: boolean\n}\n\ninterface UsageListResult {\n fetchedAt: string\n refreshSeconds: number\n /** Plugin package version (absent on older hosts). */\n version?: string\n providers: ProviderUsageView[]\n}\n\nexport interface UsageActionProps {\n /** Sidebar expansion state, owned by the sidebar footer slot. Not read\n directly — a change re-renders us, which re-anchors the default dock. */\n wide?: boolean\n /** Namespace translator injected by the locale seat. */\n t: (key: string, params?: Record<string, unknown>) => string\n /** Business face: call the host `usage/list` remote. */\n fetchUsage: () => Promise<UsageListResult>\n}\n\n/* ------------------------------------------------------------------ *\n * Refresh interval\n * ------------------------------------------------------------------ */\n\nconst INTERVAL_OPTIONS = [15, 30, 60, 300, 900, 1800] as const\nconst STORAGE_KEY = 'dsh.provider-usage.refreshSeconds'\nconst LANG_KEY = 'dsh.provider-usage.lang'\nconst POS_KEY = 'dsh.provider-usage.floatPos'\nconst DEFAULT_INTERVAL = 60\n\n/** Floating ball diameter in px; drag math derives from it. */\nconst BALL_SIZE = 32\n\ntype Lang = 'zh' | 'en'\n/** Docked ball position: the ball CENTER as fractions of the viewport, so\n both the default spot and dragged spots follow window resizes. */\ninterface FloatPos {\n fx: number\n fy: number\n}\n\n/** Panel-level override stored in localStorage; null means follow the harness language. */\nfunction readStoredLang(): Lang | null {\n try {\n const raw = localStorage.getItem(LANG_KEY)\n return raw === 'zh' || raw === 'en' ? raw : null\n } catch {\n return null\n }\n}\n\nfunction storeLang(lang: Lang): void {\n try {\n localStorage.setItem(LANG_KEY, lang)\n } catch {\n /* storage unavailable: keep the in-memory value only */\n }\n}\n\n/** Local translator over the bundled dictionaries, mirroring the shell's `{param}` interpolation. */\nfunction makeT(dict: Record<string, string>): UsageActionProps['t'] {\n return (key, params) => {\n const template = dict[key] ?? key\n if (params === undefined) return template\n return template.replace(/\\{(\\w+)\\}/g, (raw, name: string) => (name in params ? String(params[name]) : raw))\n }\n}\n\nfunction readStoredInterval(): number | null {\n try {\n const raw = localStorage.getItem(STORAGE_KEY)\n if (raw === null) return null\n const value = Number(raw)\n return Number.isFinite(value) && value >= 5 ? value : null\n } catch {\n return null\n }\n}\n\nfunction storeInterval(value: number): void {\n try {\n localStorage.setItem(STORAGE_KEY, String(value))\n } catch {\n /* storage unavailable: keep the in-memory value only */\n }\n}\n\n/* ------------------------------------------------------------------ *\n * Floating ball position\n * ------------------------------------------------------------------ */\n\n/** Equal margin from the chat area's left edge and the window's bottom edge. */\nconst DOCK_MARGIN = 24\n\n/**\n * Default dock: bottom-left of the main chat area with equal margins on both\n * axes. Returned as viewport fractions of the ball CENTER, like every other\n * position. The chat area's left edge is the sidebar's right edge, derived\n * from the full-height ancestor of the settings slot (stable data-slot hook;\n * class names are build-hashed), so it adapts to sidebar collapse.\n */\nfunction defaultFloatPos(): FloatPos {\n let sidebarRight = 264\n let node = document.querySelector('[data-slot=\"sidebar.settings\"]')?.parentElement ?? null\n while (node) {\n const rect = node.getBoundingClientRect()\n if (rect.x <= 1 && rect.height >= window.innerHeight * 0.9) {\n sidebarRight = rect.right\n break\n }\n node = node.parentElement\n }\n return {\n fx: (sidebarRight + DOCK_MARGIN + BALL_SIZE / 2) / window.innerWidth,\n fy: (window.innerHeight - DOCK_MARGIN - BALL_SIZE / 2) / window.innerHeight,\n }\n}\n\nfunction readStoredFloatPos(): FloatPos | null {\n try {\n const raw = localStorage.getItem(POS_KEY)\n if (raw === null) return null\n const parsed = JSON.parse(raw) as Partial<FloatPos> | null\n if (parsed === null || typeof parsed.fx !== 'number' || !Number.isFinite(parsed.fx)) return null\n if (typeof parsed.fy !== 'number' || !Number.isFinite(parsed.fy)) return null\n return { fx: Math.min(1, Math.max(0, parsed.fx)), fy: Math.min(1, Math.max(0, parsed.fy)) }\n } catch {\n return null\n }\n}\n\nfunction storeFloatPos(pos: FloatPos): void {\n try {\n localStorage.setItem(POS_KEY, JSON.stringify(pos))\n } catch {\n /* storage unavailable: keep the in-memory value only */\n }\n}\n\n/** 归位: forget the pinned spot; the ball follows the default dock again. */\nfunction clearStoredFloatPos(): void {\n try {\n localStorage.removeItem(POS_KEY)\n } catch {\n /* storage unavailable */\n }\n}\n\n/* ------------------------------------------------------------------ *\n * Formatting helpers\n * ------------------------------------------------------------------ */\n\nfunction formatCountdown(resetAt: string, now: number, t: UsageActionProps['t']): string | null {\n const diff = new Date(resetAt).getTime() - now\n if (!Number.isFinite(diff) || diff <= 0) return null\n const minutes = Math.floor(diff / 60000)\n if (minutes >= 60 * 24) return t('countdown.days', { days: Math.floor(minutes / (60 * 24)), hours: Math.floor((minutes % (60 * 24)) / 60) })\n if (minutes >= 60) return t('countdown.hours', { hours: Math.floor(minutes / 60), minutes: minutes % 60 })\n return t('countdown.minutes', { minutes: Math.max(1, minutes) })\n}\n\nfunction barTone(percent: number | null): 'ok' | 'warn' | 'danger' {\n if (percent === null) return 'ok'\n if (percent >= 90) return 'danger'\n if (percent >= 70) return 'warn'\n return 'ok'\n}\n\n/** Worst health across the fetch + the provider IN USE: drives the trigger's\n status dot. Only the active provider (the composer's current selection)\n colors the ball, so an idle low-quota provider does not alarm; when the\n host reports no active provider, fall back to every provider. */\nfunction healthTone(data: UsageListResult | null, error: string | null): 'ok' | 'warn' | 'danger' {\n if (error !== null) return 'danger'\n const providers = data?.providers ?? []\n const active = providers.filter((provider) => provider.active)\n const relevant = active.length > 0 ? active : providers\n let tone: 'ok' | 'warn' | 'danger' = 'ok'\n for (const provider of relevant) {\n if (provider.status === 'error' || provider.status === 'missing-credential' || provider.status === 'missing-authorization') return 'danger'\n for (const row of provider.usages ?? []) {\n const rowTone = barTone(row.percent)\n if (rowTone === 'danger') return 'danger'\n if (rowTone === 'warn') tone = 'warn'\n }\n }\n return tone\n}\n\nfunction formatAmount(value: number | null): string {\n if (value === null) return '—'\n return Number.isInteger(value) ? String(value) : value.toFixed(2)\n}\n\n/* ------------------------------------------------------------------ *\n * Provider card\n * ------------------------------------------------------------------ */\n\nfunction UsageRows({ provider, now, t }: { provider: ProviderUsageView; now: number; t: UsageActionProps['t'] }) {\n const rows = provider.usages ?? []\n if (rows.length === 0) return null\n return (\n <>\n {rows.map((row, index) => {\n const percent = row.percent\n const reset = row.resetAt !== null ? formatCountdown(row.resetAt, now, t) : null\n return (\n <div className=\"dsh-usage-row\" key={`${row.label}-${index}`}>\n <div className=\"dsh-usage-rowHead\">\n <span className=\"dsh-usage-rowLabel\">{row.label === 'weekly' ? t('usage.weekly') : row.label}</span>\n <span className=\"dsh-usage-rowValue\">\n {row.limit === null\n ? row.used !== null\n ? t('usage.used', { used: formatAmount(row.used) })\n : row.remaining !== null\n ? formatAmount(row.remaining)\n : t('usage.unlimited')\n : percent !== null\n ? `${Math.round(percent)}%`\n : t('usage.used', { used: formatAmount(row.used) })}\n </span>\n </div>\n {percent !== null ? (\n <div className=\"dsh-usage-barTrack\">\n <div\n className={`dsh-usage-barFill dsh-usage-barFill--${barTone(percent)}`}\n style={{ width: `${Math.min(100, Math.max(0, percent))}%` }}\n />\n </div>\n ) : null}\n {reset !== null ? <span className=\"dsh-usage-rowReset\">{t('usage.resetIn', { countdown: reset })}</span> : null}\n </div>\n )\n })}\n </>\n )\n}\n\nfunction ProviderCard({ provider, now, t }: { provider: ProviderUsageView; now: number; t: UsageActionProps['t'] }) {\n return (\n <div className={`dsh-usage-card${provider.active ? ' dsh-usage-card--active' : ''}`}>\n <div className=\"dsh-usage-cardHead\">\n <span className=\"dsh-usage-providerName\">{provider.displayName}</span>\n {provider.active ? <span className=\"dsh-usage-inUse\">{t('status.inUse')}</span> : null}\n </div>\n {provider.status === 'unsupported' ? (\n <span className=\"dsh-usage-message\">{t('status.unsupported')}</span>\n ) : provider.status === 'missing-credential' ? (\n <span className=\"dsh-usage-message\">{t('status.missingCredential', { ref: provider.message })}</span>\n ) : provider.status === 'missing-authorization' ? (\n <span className=\"dsh-usage-message\">{t('status.missingAuthorization', { key: provider.message })}</span>\n ) : provider.status === 'error' ? (\n <span className=\"dsh-usage-message\">{t('status.error')}: {provider.message}</span>\n ) : provider.kind === 'balance' ? (\n (provider.balances ?? []).map((row, index) => (\n <div key={`${row.currency}-${index}`}>\n <div className=\"dsh-usage-balanceRow\">\n <span className=\"dsh-usage-balanceTotal\">{row.total}</span>\n <span className=\"dsh-usage-balanceCurrency\">{row.currency}</span>\n </div>\n <span className=\"dsh-usage-balanceParts\">\n {[row.granted !== '0' && row.granted !== '0.00' ? t('balance.granted', { amount: row.granted }) : null,\n row.toppedUp !== '0' && row.toppedUp !== '0.00' ? t('balance.toppedUp', { amount: row.toppedUp }) : null]\n .filter(Boolean)\n .join(' · ')}\n </span>\n </div>\n ))\n ) : (\n <UsageRows provider={provider} now={now} t={t} />\n )}\n </div>\n )\n}\n\n/* ------------------------------------------------------------------ *\n * Trigger + popover\n * ------------------------------------------------------------------ */\n\n/** Battery level: remaining charge reads as remaining quota. */\nfunction BatteryIcon() {\n return (\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <rect width=\"16\" height=\"10\" x=\"2\" y=\"7\" rx=\"2\" ry=\"2\" />\n <path d=\"M22 11v2\" />\n <path d=\"M6 11v2\" />\n <path d=\"M10 11v2\" />\n </svg>\n )\n}\n\nfunction RefreshIcon() {\n return (\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M20 12a8 8 0 1 1-2.34-5.66\" />\n <path d=\"M20 4v4h-4\" />\n </svg>\n )\n}\n\nfunction GlobeIcon() {\n return (\n <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <circle cx=\"12\" cy=\"12\" r=\"9\" />\n <path d=\"M3 12h18\" />\n <path d=\"M12 3c2.5 2.6 3.9 5.7 3.9 9s-1.4 6.4-3.9 9c-2.5-2.6-3.9-5.7-3.9-9S9.5 5.6 12 3z\" />\n </svg>\n )\n}\n\n/** Crosshair for the \"reset ball to its default spot\" head button. */\nfunction HomeIcon() {\n return (\n <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <circle cx=\"12\" cy=\"12\" r=\"7\" />\n <path d=\"M12 2v3M12 19v3M2 12h3M19 12h3\" />\n <circle cx=\"12\" cy=\"12\" r=\"1.5\" fill=\"currentColor\" stroke=\"none\" />\n </svg>\n )\n}\n\nexport default function UsageAction({ t, fetchUsage }: UsageActionProps) {\n const [open, setOpen] = useState(false)\n const [data, setData] = useState<UsageListResult | null>(null)\n const [error, setError] = useState<string | null>(null)\n const [loading, setLoading] = useState(false)\n const [intervalSec, setIntervalSec] = useState(() => readStoredInterval() ?? DEFAULT_INTERVAL)\n const [langOverride, setLangOverride] = useState<Lang | null>(() => readStoredLang())\n const [now, setNow] = useState(() => Date.now())\n /** Pinned spot (user-dragged) as viewport fractions; null = follow the default dock. */\n const [pinnedPos, setPinnedPos] = useState<FloatPos | null>(() => readStoredFloatPos())\n /** Viewport size drives the fraction → px conversion and the default dock. */\n const [viewport, setViewport] = useState({ w: window.innerWidth, h: window.innerHeight })\n /** Transient ball position while dragging (cursor-centered); null when docked. */\n const [dragPos, setDragPos] = useState<{ x: number; y: number } | null>(null)\n\n // Follow the harness language by default: probe the shell-injected\n // translator with a known key, then let a panel-level override win.\n const harnessLang: Lang | null =\n t('lang.switch') === zh['lang.switch'] ? 'zh' : t('lang.switch') === en['lang.switch'] ? 'en' : null\n const lang: Lang = langOverride ?? harnessLang ?? 'en'\n const tt = useMemo(() => makeT(lang === 'zh' ? (zh as Record<string, string>) : (en as Record<string, string>)), [lang])\n const toggleLang = useCallback(() => {\n setLangOverride((current) => {\n const next: Lang = (current ?? harnessLang ?? 'en') === 'zh' ? 'en' : 'zh'\n storeLang(next)\n return next\n })\n }, [harnessLang])\n /** Panel-head home button: unpin the ball so it follows the default dock. */\n const resetFloatPos = () => {\n clearStoredFloatPos()\n setPinnedPos(null)\n }\n const [panelPos, setPanelPos] = useState<{ left: number; top?: number; bottom?: number } | null>(null)\n const rootRef = useRef<HTMLDivElement>(null)\n const ballRef = useRef<HTMLButtonElement>(null)\n const panelRef = useRef<HTMLDivElement>(null)\n const inFlight = useRef(false)\n /** Active ball-drag session; cleared on pointerup/pointercancel. */\n const dragRef = useRef<{ pointerId: number; startX: number; startY: number; dragging: boolean } | null>(null)\n /** Set when a drag ends so the trailing click does not toggle the panel. */\n const suppressClickRef = useRef(false)\n\n const refresh = useCallback(async () => {\n if (inFlight.current) return\n inFlight.current = true\n setLoading(true)\n try {\n const result = await fetchUsage()\n setData(result)\n setError(null)\n } catch (reason) {\n setError(reason instanceof Error ? reason.message : String(reason))\n } finally {\n inFlight.current = false\n setLoading(false)\n }\n }, [fetchUsage])\n\n // Initial fetch + fixed-interval polling; skip ticks while the tab is hidden.\n useEffect(() => {\n refresh()\n }, [refresh])\n useEffect(() => {\n const timer = setInterval(() => {\n if (document.visibilityState === 'visible') refresh()\n }, intervalSec * 1000)\n return () => clearInterval(timer)\n }, [intervalSec, refresh])\n\n // Adopt the deployment-suggested interval until the user picks one locally.\n useEffect(() => {\n if (data !== null && readStoredInterval() === null && data.refreshSeconds !== intervalSec) {\n setIntervalSec(data.refreshSeconds)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [data])\n\n // Slow tick so reset countdowns advance while the panel is open.\n useEffect(() => {\n if (!open) return\n setNow(Date.now())\n const timer = setInterval(() => setNow(Date.now()), 30000)\n return () => clearInterval(timer)\n }, [open])\n\n // Close on outside press / Escape, mirroring the shipped popover behavior.\n // The panel and the ball are portaled to document.body, so all trees count\n // as inside.\n useEffect(() => {\n if (!open) return\n const closeOutside = (event: PointerEvent) => {\n if (!(event.target instanceof Node)) return\n if (rootRef.current?.contains(event.target)) return\n if (ballRef.current?.contains(event.target)) return\n if (panelRef.current?.contains(event.target)) return\n setOpen(false)\n }\n document.addEventListener('pointerdown', closeOutside)\n return () => document.removeEventListener('pointerdown', closeOutside)\n }, [open])\n\n // Anchor the fixed-position panel to the ball; recompute while open so a\n // position reset or window resize keeps it attached. A ball in the lower\n // half of the viewport opens the panel above it, upper half below.\n useEffect(() => {\n if (!open) return\n const update = () => {\n const rect = ballRef.current?.getBoundingClientRect()\n if (!rect) return\n const left = Math.min(Math.max(8, rect.left), Math.max(8, window.innerWidth - 336))\n setPanelPos(\n rect.top > window.innerHeight / 2\n ? { left, bottom: window.innerHeight - rect.top + 6 }\n : { left, top: rect.bottom + 6 },\n )\n }\n update()\n window.addEventListener('resize', update)\n return () => window.removeEventListener('resize', update)\n }, [open, pinnedPos, viewport])\n\n // Track the viewport: fraction-based positions and the default dock follow\n // window resizes automatically.\n useEffect(() => {\n const onResize = () => setViewport({ w: window.innerWidth, h: window.innerHeight })\n window.addEventListener('resize', onResize)\n return () => window.removeEventListener('resize', onResize)\n }, [])\n\n const tone = healthTone(data, error)\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n if (event.key !== 'Escape' || !open) return\n event.preventDefault()\n setOpen(false)\n }\n\n /* Ball dragging: pointer events only (touch included via touch-action:\n none). A press becomes a drag past a 5px dead zone; while dragging the\n ball follows the cursor centered on it, and on release it stays exactly\n where dropped (no edge snapping). A plain press falls through to the\n click handler. */\n const onBallPointerDown = (event: React.PointerEvent<HTMLButtonElement>) => {\n event.currentTarget.setPointerCapture(event.pointerId)\n dragRef.current = { pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, dragging: false }\n }\n\n const onBallPointerMove = (event: React.PointerEvent<HTMLButtonElement>) => {\n const drag = dragRef.current\n if (drag === null || drag.pointerId !== event.pointerId) return\n if (!drag.dragging) {\n if (Math.abs(event.clientX - drag.startX) < 5 && Math.abs(event.clientY - drag.startY) < 5) return\n drag.dragging = true\n // The panel would detach from a moving anchor: close it on drag start.\n if (open) setOpen(false)\n }\n const half = BALL_SIZE / 2\n setDragPos({\n x: Math.min(Math.max(half, event.clientX), window.innerWidth - half),\n y: Math.min(Math.max(half, event.clientY), window.innerHeight - half),\n })\n }\n\n const endBallDrag = (event: React.PointerEvent<HTMLButtonElement>) => {\n const drag = dragRef.current\n dragRef.current = null\n if (drag === null || drag.pointerId !== event.pointerId || !drag.dragging) return\n const half = BALL_SIZE / 2\n const x = Math.min(Math.max(half, event.clientX), window.innerWidth - half)\n const y = Math.min(Math.max(half, event.clientY), window.innerHeight - half)\n // Pin the drop point as viewport fractions so it follows window resizes.\n const next: FloatPos = { fx: x / window.innerWidth, fy: y / window.innerHeight }\n setPinnedPos(next)\n storeFloatPos(next)\n setDragPos(null)\n suppressClickRef.current = true\n }\n\n const cancelBallDrag = (event: React.PointerEvent<HTMLButtonElement>) => {\n if (dragRef.current?.pointerId !== event.pointerId) return\n dragRef.current = null\n setDragPos(null)\n }\n\n const onBallClick = () => {\n if (suppressClickRef.current) {\n suppressClickRef.current = false\n return\n }\n setNow(Date.now())\n setOpen((current) => !current)\n if (!open) refresh()\n }\n\n // Ball center in px: transient drag point > pinned fractions > default dock.\n // (The default reads the sidebar edge from the DOM at render time; cheap.)\n const docked = pinnedPos ?? defaultFloatPos()\n const centerX = dragPos !== null ? dragPos.x : docked.fx * viewport.w\n const centerY = dragPos !== null ? dragPos.y : docked.fy * viewport.h\n\n return (\n <div ref={rootRef} className=\"dsh-usage-root\" onKeyDown={onKeyDown}>\n {createPortal(\n <button\n ref={ballRef}\n type=\"button\"\n className={`dsh-usage-ball dsh-usage-tone-${tone}`}\n style={{ left: centerX - BALL_SIZE / 2, top: centerY - BALL_SIZE / 2 }}\n aria-expanded={open}\n aria-label={tt('action.aria')}\n title={`${tt('action.aria')} · ${tt(`status.tone.${tone}`)}`}\n onPointerDown={onBallPointerDown}\n onPointerMove={onBallPointerMove}\n onPointerUp={endBallDrag}\n onPointerCancel={cancelBallDrag}\n onClick={onBallClick}\n onKeyDown={onKeyDown}\n >\n <BatteryIcon />\n </button>,\n document.body,\n )}\n {open && panelPos !== null\n ? createPortal(\n <div\n ref={panelRef}\n className=\"dsh-usage-panel\"\n role=\"dialog\"\n aria-label={tt('panel.title')}\n style={{ left: panelPos.left, top: panelPos.top, bottom: panelPos.bottom }}\n onKeyDown={onKeyDown}\n >\n <div className=\"dsh-usage-head\">\n <span className=\"dsh-usage-title\">{tt('panel.title')}</span>\n {data?.version ? <span className=\"dsh-usage-version\">v{data.version}</span> : null}\n <button\n type=\"button\"\n className=\"dsh-usage-home\"\n onClick={resetFloatPos}\n title={tt('panel.resetPos')}\n aria-label={tt('panel.resetPos')}\n >\n <HomeIcon />\n </button>\n <button\n type=\"button\"\n className=\"dsh-usage-lang\"\n onClick={toggleLang}\n title={tt('lang.switch')}\n aria-label={tt('lang.switch')}\n >\n <GlobeIcon />\n <span>{lang === 'zh' ? '中' : 'EN'}</span>\n </button>\n <button\n type=\"button\"\n className={`dsh-usage-refresh${loading ? ' dsh-usage-refresh--loading' : ''}`}\n disabled={loading}\n onClick={refresh}\n title={tt('panel.refresh')}\n aria-label={tt('panel.refresh')}\n >\n <RefreshIcon />\n </button>\n </div>\n {data === null && error !== null ? (\n <span className=\"dsh-usage-message\">{tt('status.error')}: {error}</span>\n ) : null}\n {data !== null && data.providers.length === 0 ? (\n <span className=\"dsh-usage-message\">{tt('panel.empty')}</span>\n ) : null}\n {(data?.providers ?? []).map((provider) => (\n <ProviderCard key={provider.id} provider={provider} now={now} t={tt} />\n ))}\n <div className=\"dsh-usage-foot\">\n <span className=\"dsh-usage-footLabel\">{tt('panel.interval')}</span>\n <select\n className=\"dsh-usage-select\"\n value={intervalSec}\n onChange={(event) => {\n const value = Number(event.target.value)\n setIntervalSec(value)\n storeInterval(value)\n }}\n >\n {INTERVAL_OPTIONS.map((seconds) => (\n <option key={seconds} value={seconds}>{tt(`interval.${seconds}s`)}</option>\n ))}\n </select>\n <span className=\"dsh-usage-updated\">\n {data === null\n ? tt('panel.never')\n : tt('panel.updated', { time: new Date(data.fetchedAt).toLocaleTimeString(lang === 'zh' ? 'zh-CN' : 'en-US') })}\n </span>\n </div>\n </div>,\n document.body,\n )\n : null}\n </div>\n )\n}\n","/**\n * Panel stylesheet, injected once per page. Follows the shipped plugins'\n * convention of a `<style data-plugin-css>` tag and design-token colors.\n */\nconst CSS = `\n.dsh-usage-root { position: relative; display: inline-flex; }\n/* Tri-tone health halo: only the shadow carries the state of the provider IN\n USE (green ok / amber remaining<30% / red error or usage>=90%) — the button\n face itself stays neutral. A 1px tone ring plus a soft halo keeps the\n state readable on both light and dark skins. */\n.dsh-usage-tone-ok { --dsh-usage-tone: #22a06b; }\n.dsh-usage-tone-warn { --dsh-usage-tone: #e2b93b; }\n.dsh-usage-tone-danger { --dsh-usage-tone: #d94f4f; }\n/* Floating ball trigger: a draggable fixed circle portaled to document.body,\n one layer below the panel (1000) so the popover always covers it. Position\n comes from inline style: docked it sits at its stored coordinates, while\n dragging it follows the cursor. Keeps the shell's lv3 lift shadow; the\n tone halo stacks on top. */\n.dsh-usage-ball {\n position: fixed; z-index: 999; width: 32px; height: 32px; border-radius: 50%;\n cursor: pointer; touch-action: none;\n display: inline-flex; align-items: center; justify-content: center;\n border: 1px solid var(--dsw-alias-border-l2);\n background-color: var(--dsw-specific-menu);\n color: var(--dsw-alias-label-tertiary);\n transition: box-shadow 0.15s;\n}\n.dsh-usage-ball:hover, .dsh-usage-ball:focus-visible { color: var(--dsw-alias-label-secondary); }\n.dsh-usage-ball svg { width: 15px; height: 15px; }\n.dsh-usage-ball.dsh-usage-tone-ok,\n.dsh-usage-ball.dsh-usage-tone-warn,\n.dsh-usage-ball.dsh-usage-tone-danger {\n box-shadow:\n var(--dsw-shadow-lv3),\n 0 0 0 1px color-mix(in srgb, var(--dsh-usage-tone) 40%, transparent),\n 0 0 14px color-mix(in srgb, var(--dsh-usage-tone) 55%, transparent);\n}\n.dsh-usage-ball.dsh-usage-tone-ok:hover,\n.dsh-usage-ball.dsh-usage-tone-warn:hover,\n.dsh-usage-ball.dsh-usage-tone-danger:hover,\n.dsh-usage-ball.dsh-usage-tone-ok:focus-visible,\n.dsh-usage-ball.dsh-usage-tone-warn:focus-visible,\n.dsh-usage-ball.dsh-usage-tone-danger:focus-visible {\n box-shadow:\n var(--dsw-shadow-lv3),\n 0 0 0 1px color-mix(in srgb, var(--dsh-usage-tone) 55%, transparent),\n 0 0 18px color-mix(in srgb, var(--dsh-usage-tone) 70%, transparent);\n}\n.dsh-usage-panel {\n z-index: 1000; box-sizing: border-box;\n border: 1px solid var(--dsw-alias-border-l2);\n background: var(--dsw-specific-menu);\n box-shadow: var(--dsw-shadow-lv3);\n border-radius: 12px; margin: 0; padding: 8px;\n width: 320px; max-width: min(360px, 100vw - 16px);\n max-height: min(460px, 100vh - 60px); overflow: auto;\n display: flex; flex-direction: column; gap: 6px;\n /* position: fixed with viewport coordinates computed inline from the\n trigger rect — absolute positioning inside the sidebar gets clipped by\n the column's overflow. */\n position: fixed;\n --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);\n --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);\n}\n.dsh-usage-head {\n display: flex; align-items: center; gap: 8px; padding: 2px 4px 6px;\n border-bottom: 1px solid var(--dsw-alias-border-l2);\n}\n.dsh-usage-title { color: var(--dsw-alias-label-primary); font-size: 13px; font-weight: 600; }\n.dsh-usage-version {\n color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px;\n padding: 0 5px; border-radius: 4px; background: var(--dsw-alias-fill-l2);\n font-variant-numeric: tabular-nums; user-select: none; margin-right: auto;\n}\n.dsh-usage-lang {\n cursor: pointer; display: inline-flex; align-items: center; gap: 4px;\n border: 0; border-radius: 6px; background: 0; padding: 3px 5px;\n color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px;\n}\n.dsh-usage-lang:hover { color: var(--dsw-alias-label-secondary); }\n.dsh-usage-refresh {\n cursor: pointer; display: inline-flex; align-items: center; justify-content: center;\n border: 0; border-radius: 6px; background: 0; padding: 4px;\n color: var(--dsw-alias-label-tertiary); line-height: 0;\n}\n.dsh-usage-refresh:hover { color: var(--dsw-alias-label-secondary); }\n.dsh-usage-refresh:disabled { opacity: 0.5; cursor: default; }\n/* Home button in the panel head: sends the ball back to its default spot. */\n.dsh-usage-home {\n cursor: pointer; display: inline-flex; align-items: center; justify-content: center;\n border: 0; border-radius: 6px; background: 0; padding: 4px;\n color: var(--dsw-alias-label-tertiary); line-height: 0;\n}\n.dsh-usage-home:hover { color: var(--dsw-alias-label-secondary); }\n@keyframes dsh-usage-spin { to { transform: rotate(360deg); } }\n.dsh-usage-refresh--loading svg { animation: dsh-usage-spin 0.9s linear infinite; }\n.dsh-usage-card {\n border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px;\n background: var(--dsw-alias-fill-l2);\n}\n/* The provider in use, whose quota alone drives the ball tone. */\n.dsh-usage-card--active {\n outline: 1px solid color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 45%, transparent);\n outline-offset: -1px;\n}\n.dsh-usage-cardHead { display: flex; align-items: center; gap: 8px; }\n.dsh-usage-providerName {\n color: var(--dsw-alias-label-primary); font-size: 13px; font-weight: 600;\n min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;\n}\n.dsh-usage-inUse {\n flex: none; font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 999px;\n color: var(--dsw-alias-label-secondary);\n background: color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 18%, transparent);\n border: 1px solid color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 35%, transparent);\n}\n.dsh-usage-message { color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; word-break: break-all; }\n.dsh-usage-balanceRow { display: flex; align-items: baseline; gap: 8px; }\n.dsh-usage-balanceTotal {\n color: var(--dsw-alias-label-primary); font-size: 18px; font-weight: 600;\n font-variant-numeric: tabular-nums;\n}\n.dsh-usage-balanceCurrency { color: var(--dsw-alias-label-secondary); font-size: 12px; }\n.dsh-usage-balanceParts { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; }\n.dsh-usage-row { display: flex; flex-direction: column; gap: 3px; }\n.dsh-usage-rowHead { display: flex; align-items: center; gap: 8px; font-size: 12px; line-height: 18px; }\n.dsh-usage-rowLabel { color: var(--dsw-alias-label-secondary); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dsh-usage-rowValue { color: var(--dsw-alias-label-tertiary); font-variant-numeric: tabular-nums; flex: none; }\n.dsh-usage-barTrack {\n height: 4px; border-radius: 2px; overflow: hidden;\n background: var(--dsw-alias-border-l2);\n}\n.dsh-usage-barFill { height: 100%; border-radius: 2px; transition: width 0.3s; }\n.dsh-usage-barFill--ok { background: #22a06b; }\n.dsh-usage-barFill--warn { background: #e2b93b; }\n.dsh-usage-barFill--danger { background: #d94f4f; }\n.dsh-usage-rowReset { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; }\n.dsh-usage-foot {\n display: flex; align-items: center; gap: 8px; padding: 6px 4px 2px;\n border-top: 1px solid var(--dsw-alias-border-l2);\n}\n.dsh-usage-footLabel { color: var(--dsw-alias-label-tertiary); font-size: 11px; }\n.dsh-usage-select {\n border: 1px solid var(--dsw-alias-border-l2); border-radius: 6px; background: 0;\n color: var(--dsw-alias-label-secondary); font-size: 11px; padding: 2px 4px; cursor: pointer;\n}\n.dsh-usage-updated { color: var(--dsw-alias-label-tertiary); font-size: 11px; margin-left: auto; }\n`\n\nconst TAG_ID = 'dsh-provider-usage/panel.css'\n\n/** Inject the panel stylesheet once; on HMR swap, refresh the existing tag's payload in place. */\nexport function ensureStyles(): void {\n if (typeof document === 'undefined') return\n const existing = document.querySelector('style[data-plugin-css=' + JSON.stringify(TAG_ID) + ']')\n if (existing !== null) {\n // A hot-swapped bundle re-runs this module while the old <style> tag is\n // still in the DOM — sync its content so the new CSS actually applies.\n if (existing.textContent !== CSS) existing.textContent = CSS\n return\n }\n const tag = document.createElement('style')\n tag.dataset.plugin = 'dsh-provider-usage'\n tag.dataset.pluginCss = TAG_ID\n tag.textContent = CSS\n document.head.appendChild(tag)\n}\n","/**\n * provider-usage — browser half.\n *\n * Registers the locale dictionaries and contributes the usage widget into the\n * sidebar footer's additive action slot. Data comes from the host `usage`\n * Typert Remote (SRC mode — no generated descriptors) through the raw RPC\n * caller on the connection service.\n */\nimport UsageAction, { type UsageActionProps } from './Panel'\nimport { en, zh } from './locales'\nimport { ensureStyles } from './styles'\n\n/** Required client services: slot registry, locale seats, and the connection RPC caller. */\nconst inject = ['slots', 'locale', 'connection']\n\ninterface ClientContext {\n effect: (fn: () => unknown, label: string) => void\n locale: { register: (ns: string, dicts: { zh: unknown; en: unknown }) => unknown }\n slots: {\n inject: (name: string, callback: () => unknown) => void\n register: (entry: Record<string, unknown>, component: unknown) => unknown\n }\n connection: {\n rpc: {\n call: (\n channel: string,\n endpoint: string,\n payload: { args: Record<string, unknown> },\n signal?: AbortSignal,\n ) => Promise<{ ok: true; value: unknown } | { ok: false; error: { code: string; message: string } }>\n }\n }\n}\n\nfunction apply(ctx: ClientContext) {\n ensureStyles()\n ctx.effect(() => ctx.locale.register('provider-usage', { zh, en }), 'provider-usage: dictionaries')\n\n const fetchUsage: UsageActionProps['fetchUsage'] = async () => {\n const result = await ctx.connection.rpc.call('/api', 'usage/list', { args: {} })\n if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`)\n return result.value as Awaited<ReturnType<UsageActionProps['fetchUsage']>>\n }\n\n ctx.slots.inject('sidebar.footer.action', () =>\n ctx.slots.register(\n {\n name: 'sidebar.footer.action',\n id: 'provider-usage',\n order: 10,\n locale: 'provider-usage',\n inject: () => ({ fetchUsage }),\n },\n UsageAction,\n ),\n )\n}\n\nexport { apply, inject }\n"],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AS;GACrB,IAAI,QAAQ,YAAY;GACxB,IAAI,cAAc;GAClB,SAAS,KAAK,YAAY,GAAG;EAC/B;;;;;;;;;;;;ECzJA,MAAM,SAAS;GAAC;GAAS;GAAU;EAAY;EAqB/C,SAAS,MAAM,KAAoB;GACjC,aAAa;GACb,IAAI,aAAa,IAAI,OAAO,SAAS,kBAAkB;IAAE;IAAI;GAAG,CAAC,GAAG,8BAA8B;GAElG,MAAM,aAA6C,YAAY;IAC7D,MAAM,SAAS,MAAM,IAAI,WAAW,IAAI,KAAK,QAAQ,cAAc,EAAE,MAAM,CAAC,EAAE,CAAC;IAC/E,IAAI,CAAC,OAAO,IAAI,MAAM,IAAI,MAAM,GAAG,OAAO,MAAM,KAAK,IAAI,OAAO,MAAM,SAAS;IAC/E,OAAO,OAAO;GAChB;GAEA,IAAI,MAAM,OAAO,+BACf,IAAI,MAAM,SACR;IACE,MAAM;IACN,IAAI;IACJ,OAAO;IACP,QAAQ;IACR,eAAe,EAAE,WAAW;GAC9B,GACA,WACF,CACF;EACF"}
|
|
1
|
+
{"version":3,"file":"client.js","names":["useState","useMemo","useCallback","useRef","createPortal"],"sources":["../src/client/locales.ts","../src/client/Panel.tsx","../src/client/styles.ts","../src/client/index.ts"],"sourcesContent":["/** Simplified Chinese dictionary (the key-set source of truth). */\nexport const zh = {\n 'action.label': '用量',\n 'action.aria': 'Provider 用量',\n 'panel.title': 'Provider 用量',\n 'panel.resize': '拖拽调整面板高度',\n 'panel.refresh': '立即刷新',\n 'panel.refreshing': '刷新中…',\n 'lang.switch': 'Switch to English',\n 'panel.resetPos': '悬浮球归位',\n 'panel.interval': '刷新周期',\n 'panel.thresholds': '余额阈值',\n 'panel.thresholdRed': '红',\n 'panel.thresholdYellow': '黄',\n 'panel.updated': '更新于 {time}',\n 'panel.never': '尚未获取',\n 'panel.empty': '未检测到已配置的 Provider',\n 'interval.15s': '15 秒',\n 'interval.30s': '30 秒',\n 'interval.60s': '1 分钟',\n 'interval.300s': '5 分钟',\n 'interval.900s': '15 分钟',\n 'interval.1800s': '30 分钟',\n 'balance.total': '总额',\n 'balance.granted': '赠送 {amount}',\n 'balance.toppedUp': '充值 {amount}',\n 'usage.weekly': '每周配额',\n 'usage.used': '已用 {used}',\n 'usage.remaining': '剩余 {remaining}',\n 'usage.unlimited': '不限量',\n 'usage.resetAt': '重置于 {time}',\n 'usage.resetIn': '{countdown} 后重置',\n 'status.unsupported': '该 Provider 暂不支持额度查询',\n 'status.missingCredential': '未配置密钥({ref})',\n 'status.missingAuthorization': '未完成 OAuth 授权({key})',\n 'status.error': '查询失败',\n 'status.inUse': '使用中',\n 'status.tone.ok': '当前 Provider 正常',\n 'status.tone.warn': '当前 Provider 用量接近上限或余额偏低',\n 'status.tone.danger': '当前 Provider 异常、用量将尽或余额过低',\n 'countdown.days': '{days}天{hours}小时',\n 'countdown.hours': '{hours}小时{minutes}分',\n 'countdown.minutes': '{minutes}分钟',\n}\n\n/** English dictionary, key-identical to the Chinese source of truth. */\nexport const en = {\n 'action.label': 'Usage',\n 'action.aria': 'Provider usage',\n 'panel.title': 'Provider Usage',\n 'panel.resize': 'Drag to resize panel',\n 'panel.refresh': 'Refresh now',\n 'panel.refreshing': 'Refreshing…',\n 'lang.switch': '切换到中文',\n 'panel.resetPos': 'Reset ball position',\n 'panel.interval': 'Refresh interval',\n 'panel.thresholds': 'Balance thresholds',\n 'panel.thresholdRed': 'Red',\n 'panel.thresholdYellow': 'Yellow',\n 'panel.updated': 'Updated {time}',\n 'panel.never': 'Not fetched yet',\n 'panel.empty': 'No configured provider detected',\n 'interval.15s': '15s',\n 'interval.30s': '30s',\n 'interval.60s': '1 min',\n 'interval.300s': '5 min',\n 'interval.900s': '15 min',\n 'interval.1800s': '30 min',\n 'balance.total': 'Total',\n 'balance.granted': 'granted {amount}',\n 'balance.toppedUp': 'topped up {amount}',\n 'usage.weekly': 'Weekly quota',\n 'usage.used': 'used {used}',\n 'usage.remaining': '{remaining} left',\n 'usage.unlimited': 'Unlimited',\n 'usage.resetAt': 'Resets at {time}',\n 'usage.resetIn': 'Resets in {countdown}',\n 'status.unsupported': 'Usage query is not supported for this provider',\n 'status.missingCredential': 'No API key configured ({ref})',\n 'status.missingAuthorization': 'OAuth authorization missing ({key})',\n 'status.error': 'Query failed',\n 'status.inUse': 'In use',\n 'status.tone.ok': 'Current provider healthy',\n 'status.tone.warn': 'Current provider usage nearing its limit or balance running low',\n 'status.tone.danger': 'Current provider error, usage almost exhausted, or balance too low',\n 'countdown.days': '{days}d {hours}h',\n 'countdown.hours': '{hours}h {minutes}m',\n 'countdown.minutes': '{minutes}m',\n}\n","/**\n * Floating-ball quota widget: a draggable ball portaled to document.body\n * (the sidebar slot only mounts the component; the button itself no longer\n * lives in the sidebar, avoiding slot layout contention with other plugins).\n * The popover panel lists every configured provider's live balance/quota.\n * Polling interval is user-selectable (persisted in localStorage) and falls\n * back to the deployment-suggested value from the host plugin config.\n */\nimport { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport { en, zh } from './locales'\n\n/* ------------------------------------------------------------------ *\n * Wire views (mirror of the host half)\n * ------------------------------------------------------------------ */\n\ninterface BalanceRow {\n currency: string\n total: string\n granted: string\n toppedUp: string\n}\n\ninterface UsageRow {\n label: string\n used: number | null\n limit: number | null\n remaining: number | null\n percent: number | null\n resetAt: string | null\n}\n\ninterface ProviderUsageView {\n id: string\n displayName: string\n kind: 'balance' | 'usage' | null\n status: 'ok' | 'error' | 'missing-credential' | 'missing-authorization' | 'unsupported'\n message: string | null\n balances: BalanceRow[] | null\n usages: UsageRow[] | null\n /** The provider in use (absent on older hosts); it alone drives the ball tone. */\n active?: boolean\n}\n\ninterface UsageListResult {\n fetchedAt: string\n refreshSeconds: number\n /** Deployment-suggested balance thresholds (absent on older hosts);\n the panel may override them locally. */\n balanceRedThreshold?: number\n balanceYellowThreshold?: number\n /** Plugin package version (absent on older hosts). */\n version?: string\n providers: ProviderUsageView[]\n}\n\nexport interface UsageActionProps {\n /** Sidebar expansion state, owned by the sidebar footer slot. Not read\n directly — a change re-renders us, which re-anchors the default dock. */\n wide?: boolean\n /** Namespace translator injected by the locale seat. */\n t: (key: string, params?: Record<string, unknown>) => string\n /** Business face: call the host `usage/list` remote. */\n fetchUsage: () => Promise<UsageListResult>\n /** Provider the FOCUSED session's composer would use (live client state);\n undefined when unavailable — the host's own flag then stands. */\n getActiveProvider?: () => string | undefined\n /** Subscribe to focused-session / model-selection changes; the panel\n re-derives the \"in use\" flag on every change, without a poll tick. */\n subscribeActiveChange?: (onChange: () => void) => (() => void)\n}\n\n/* ------------------------------------------------------------------ *\n * Refresh interval\n * ------------------------------------------------------------------ */\n\nconst INTERVAL_OPTIONS = [15, 30, 60, 300, 900, 1800] as const\nconst STORAGE_KEY = 'dsh.provider-usage.refreshSeconds'\nconst LANG_KEY = 'dsh.provider-usage.lang'\nconst POS_KEY = 'dsh.provider-usage.floatPos'\nconst THRESHOLD_RED_KEY = 'dsh.provider-usage.balanceRedThreshold'\nconst THRESHOLD_YELLOW_KEY = 'dsh.provider-usage.balanceYellowThreshold'\nconst PANEL_HEIGHT_KEY = 'dsh.provider-usage.panelHeight'\nconst DEFAULT_INTERVAL = 60\n/** Balance thresholds fall back to these hardcoded defaults when neither the\n host config nor a stored override provides them. */\nconst DEFAULT_BALANCE_RED = 10\nconst DEFAULT_BALANCE_YELLOW = 30\n/** Smallest panel height the top-edge drag allows (px). */\nconst PANEL_MIN_H = 120\n\n/** Largest panel height the top-edge drag allows: the viewport minus a\n breathing margin, so the panel can never outgrow the screen. */\nfunction panelMaxHeight(): number {\n return Math.max(PANEL_MIN_H, window.innerHeight - 24)\n}\n\n/** Bottom padding of the open panel (px), read live so the layout math stays\n correct if the stylesheet ever changes it. */\nfunction panelPaddingBottom(panel: HTMLElement): number {\n const pad = Number.parseFloat(getComputedStyle(panel).paddingBottom)\n return Number.isFinite(pad) ? pad : 0\n}\n\n/**\n * Natural content height of the open panel — children plus padding — even\n * while the panel itself is height-constrained or scrolled (children rects\n * are compensated by scrollTop). This is the grow limit: at this height the\n * panel needs no scrolling and leaves no blank strip at the bottom.\n */\nfunction panelContentHeight(panel: HTMLElement): number {\n const panelTop = panel.getBoundingClientRect().top\n let bottom = 0\n for (const child of Array.from(panel.children)) {\n const rect = (child as HTMLElement).getBoundingClientRect()\n bottom = Math.max(bottom, rect.bottom - panelTop + panel.scrollTop)\n }\n return Math.ceil(bottom) + panelPaddingBottom(panel)\n}\n\n/**\n * Shrink limit: the height that keeps the panel head plus the FIRST provider\n * card fully visible (bottom padding included). Falls back to PANEL_MIN_H\n * when no provider card is present (e.g. empty list).\n */\nfunction firstCardMinHeight(panel: HTMLElement): number {\n const card = panel.querySelector<HTMLElement>('.dsh-usage-card')\n if (card === null) return PANEL_MIN_H\n const panelTop = panel.getBoundingClientRect().top\n const cardRect = card.getBoundingClientRect()\n return Math.ceil(cardRect.bottom - panelTop + panel.scrollTop) + panelPaddingBottom(panel)\n}\n\n/** Floating ball diameter in px; drag math derives from it. */\nconst BALL_SIZE = 32\n\ntype Lang = 'zh' | 'en'\n/** Docked ball position: the ball CENTER as fractions of the viewport, so\n both the default spot and dragged spots follow window resizes. */\ninterface FloatPos {\n fx: number\n fy: number\n}\n\n/** Panel-level override stored in localStorage; null means follow the harness language. */\nfunction readStoredLang(): Lang | null {\n try {\n const raw = localStorage.getItem(LANG_KEY)\n return raw === 'zh' || raw === 'en' ? raw : null\n } catch {\n return null\n }\n}\n\nfunction storeLang(lang: Lang): void {\n try {\n localStorage.setItem(LANG_KEY, lang)\n } catch {\n /* storage unavailable: keep the in-memory value only */\n }\n}\n\n/** Local translator over the bundled dictionaries, mirroring the shell's `{param}` interpolation. */\nfunction makeT(dict: Record<string, string>): UsageActionProps['t'] {\n return (key, params) => {\n const template = dict[key] ?? key\n if (params === undefined) return template\n return template.replace(/\\{(\\w+)\\}/g, (raw, name: string) => (name in params ? String(params[name]) : raw))\n }\n}\n\nfunction readStoredInterval(): number | null {\n try {\n const raw = localStorage.getItem(STORAGE_KEY)\n if (raw === null) return null\n const value = Number(raw)\n return Number.isFinite(value) && value >= 5 ? value : null\n } catch {\n return null\n }\n}\n\nfunction storeInterval(value: number): void {\n try {\n localStorage.setItem(STORAGE_KEY, String(value))\n } catch {\n /* storage unavailable: keep the in-memory value only */\n }\n}\n\n/* ------------------------------------------------------------------ *\n * Balance thresholds (panel overrides, persisted in localStorage)\n * ------------------------------------------------------------------ */\n\n/** Parse a threshold input: a finite number ≥ 0, or null while the field is\n empty/transiently invalid (the string is kept in state so typing never\n fights the controlled input). */\nfunction parseThreshold(raw: string): number | null {\n const trimmed = raw.trim()\n if (trimmed === '') return null\n const value = Number(trimmed)\n return Number.isFinite(value) && value >= 0 ? value : null\n}\n\nfunction readStoredThreshold(key: string): string | null {\n try {\n const raw = localStorage.getItem(key)\n return raw !== null && parseThreshold(raw) !== null ? raw : null\n } catch {\n return null\n }\n}\n\nfunction storeThreshold(key: string, value: string): void {\n try {\n localStorage.setItem(key, value)\n } catch {\n /* storage unavailable: keep the in-memory value only */\n }\n}\n\n/* ------------------------------------------------------------------ *\n * Panel height (user-resized via the top-edge drag handle)\n * ------------------------------------------------------------------ */\n\nfunction readStoredPanelHeight(): number | null {\n try {\n const raw = localStorage.getItem(PANEL_HEIGHT_KEY)\n if (raw === null) return null\n const value = Number(raw)\n return Number.isFinite(value) && value >= PANEL_MIN_H ? value : null\n } catch {\n return null\n }\n}\n\nfunction storePanelHeight(value: number): void {\n try {\n localStorage.setItem(PANEL_HEIGHT_KEY, String(value))\n } catch {\n /* storage unavailable: keep the in-memory value only */\n }\n}\n\n/* ------------------------------------------------------------------ *\n * Floating ball position\n * ------------------------------------------------------------------ */\n\n/** Equal margin from the chat area's left edge and the window's bottom edge. */\nconst DOCK_MARGIN = 24\n\n/**\n * Default dock: bottom-left of the main chat area with equal margins on both\n * axes. Returned as viewport fractions of the ball CENTER, like every other\n * position. The chat area's left edge is the sidebar's right edge, derived\n * from the full-height ancestor of the settings slot (stable data-slot hook;\n * class names are build-hashed), so it adapts to sidebar collapse.\n */\nfunction defaultFloatPos(): FloatPos {\n let sidebarRight = 264\n let node = document.querySelector('[data-slot=\"sidebar.settings\"]')?.parentElement ?? null\n while (node) {\n const rect = node.getBoundingClientRect()\n if (rect.x <= 1 && rect.height >= window.innerHeight * 0.9) {\n sidebarRight = rect.right\n break\n }\n node = node.parentElement\n }\n return {\n fx: (sidebarRight + DOCK_MARGIN + BALL_SIZE / 2) / window.innerWidth,\n fy: (window.innerHeight - DOCK_MARGIN - BALL_SIZE / 2) / window.innerHeight,\n }\n}\n\nfunction readStoredFloatPos(): FloatPos | null {\n try {\n const raw = localStorage.getItem(POS_KEY)\n if (raw === null) return null\n const parsed = JSON.parse(raw) as Partial<FloatPos> | null\n if (parsed === null || typeof parsed.fx !== 'number' || !Number.isFinite(parsed.fx)) return null\n if (typeof parsed.fy !== 'number' || !Number.isFinite(parsed.fy)) return null\n return { fx: Math.min(1, Math.max(0, parsed.fx)), fy: Math.min(1, Math.max(0, parsed.fy)) }\n } catch {\n return null\n }\n}\n\nfunction storeFloatPos(pos: FloatPos): void {\n try {\n localStorage.setItem(POS_KEY, JSON.stringify(pos))\n } catch {\n /* storage unavailable: keep the in-memory value only */\n }\n}\n\n/** 归位: forget the pinned spot; the ball follows the default dock again. */\nfunction clearStoredFloatPos(): void {\n try {\n localStorage.removeItem(POS_KEY)\n } catch {\n /* storage unavailable */\n }\n}\n\n/* ------------------------------------------------------------------ *\n * Formatting helpers\n * ------------------------------------------------------------------ */\n\nfunction formatCountdown(resetAt: string, now: number, t: UsageActionProps['t']): string | null {\n const diff = new Date(resetAt).getTime() - now\n if (!Number.isFinite(diff) || diff <= 0) return null\n const minutes = Math.floor(diff / 60000)\n if (minutes >= 60 * 24) return t('countdown.days', { days: Math.floor(minutes / (60 * 24)), hours: Math.floor((minutes % (60 * 24)) / 60) })\n if (minutes >= 60) return t('countdown.hours', { hours: Math.floor(minutes / 60), minutes: minutes % 60 })\n return t('countdown.minutes', { minutes: Math.max(1, minutes) })\n}\n\nfunction barTone(percent: number | null): 'ok' | 'warn' | 'danger' {\n if (percent === null) return 'ok'\n if (percent >= 90) return 'danger'\n if (percent >= 70) return 'warn'\n return 'ok'\n}\n\n/** Parse a balance amount string (\"12.34\", \"0.00\") into a number. */\nfunction toAmount(value: string): number | null {\n const parsed = Number(value)\n return Number.isFinite(parsed) ? parsed : null\n}\n\n/**\n * Tone for a monetary balance, compared in the balance's own currency:\n * below the red threshold → danger, below the yellow threshold → warn,\n * otherwise ok. The effective red threshold never exceeds the yellow one,\n * so the zones stay ordered no matter how the panel is configured.\n */\nfunction balanceTone(value: number | null, red: number, yellow: number): 'ok' | 'warn' | 'danger' {\n if (value === null) return 'ok'\n const effRed = Math.min(red, yellow)\n if (value < effRed) return 'danger'\n if (value < yellow) return 'warn'\n return 'ok'\n}\n\ntype Tone = 'ok' | 'warn' | 'danger'\n\nconst TONE_SEVERITY: Record<Tone, number> = { ok: 0, warn: 1, danger: 2 }\n\n/** More severe of two tones; used WITHIN one category. */\nfunction worseTone(a: Tone | null, b: Tone | null): Tone | null {\n if (a === null) return b\n if (b === null) return a\n return TONE_SEVERITY[a] >= TONE_SEVERITY[b] ? a : b\n}\n\n/**\n * Aggregate tone for one provider. The subscription/usage windows (\"plan\")\n * and the prepaid balance/credits are two INDEPENDENT categories joined with\n * OR semantics: the provider stays green while either category has enough\n * left (the plan is normally consumed before credits, so the surviving\n * resource sets the tone), and when both are running low the lighter warning\n * wins. Within one category the worst row still governs — an exhausted 5h\n * window is not \"enough plan\" just because the weekly window is healthy.\n */\nfunction providerTone(provider: ProviderUsageView, red: number, yellow: number): Tone {\n let planTone: Tone | null = null\n let creditTone: Tone | null = null\n if (provider.kind === 'balance') {\n for (const row of provider.balances ?? []) {\n creditTone = worseTone(creditTone, balanceTone(toAmount(row.total), red, yellow))\n }\n }\n for (const row of provider.usages ?? []) {\n if (row.label === 'credits') {\n creditTone = worseTone(creditTone, balanceTone(row.remaining, red, yellow))\n } else {\n planTone = worseTone(planTone, barTone(row.percent))\n }\n }\n if (planTone === null) return creditTone ?? 'ok'\n if (creditTone === null) return planTone\n return TONE_SEVERITY[planTone] <= TONE_SEVERITY[creditTone] ? planTone : creditTone\n}\n\n/** Worst health across the fetch + the provider IN USE: drives the trigger's\n status dot. Only the active provider (the composer's current selection)\n colors the ball, so an idle low-quota provider does not alarm; when the\n host reports no active provider, fall back to every provider. */\nfunction healthTone(data: UsageListResult | null, error: string | null, red: number, yellow: number): 'ok' | 'warn' | 'danger' {\n if (error !== null) return 'danger'\n const providers = data?.providers ?? []\n const active = providers.filter((provider) => provider.active)\n const relevant = active.length > 0 ? active : providers\n let tone: 'ok' | 'warn' | 'danger' = 'ok'\n for (const provider of relevant) {\n if (provider.status === 'error' || provider.status === 'missing-credential' || provider.status === 'missing-authorization') return 'danger'\n const providerToneValue = providerTone(provider, red, yellow)\n if (providerToneValue === 'danger') return 'danger'\n if (providerToneValue === 'warn') tone = 'warn'\n }\n return tone\n}\n\nfunction formatAmount(value: number | null): string {\n if (value === null) return '—'\n return Number.isInteger(value) ? String(value) : value.toFixed(2)\n}\n\n/**\n * Refine the host's `active` flags with the provider of the FOCUSED session\n * (the composer's own state), so a session switch re-highlights instantly\n * even though the host only tracks the last explicit selection. Returns the\n * same object when nothing changes; `undefined` provider leaves the host's\n * flags untouched.\n */\nfunction applyActiveProvider(data: UsageListResult, provider: string | undefined): UsageListResult {\n if (provider === undefined || !Array.isArray(data.providers)) return data\n let changed = false\n const providers = data.providers.map((entry) => {\n const active = entry.id === provider\n if (active === entry.active) return entry\n changed = true\n return { ...entry, active }\n })\n return changed ? { ...data, providers } : data\n}\n\n/* ------------------------------------------------------------------ *\n * Provider card\n * ------------------------------------------------------------------ */\n\nfunction UsageRows({ provider, now, red, yellow, t }: { provider: ProviderUsageView; now: number; red: number; yellow: number; t: UsageActionProps['t'] }) {\n const rows = provider.usages ?? []\n if (rows.length === 0) return null\n return (\n <>\n {rows.map((row, index) => {\n const percent = row.percent\n const isCredits = row.label === 'credits'\n // Credits rows carry a remaining balance and are judged by the amount;\n // quota windows keep the percent-based tone.\n const tone = isCredits ? balanceTone(row.remaining, red, yellow) : barTone(row.percent)\n const reset = row.resetAt !== null ? formatCountdown(row.resetAt, now, t) : null\n return (\n <div className=\"dsh-usage-row\" key={`${row.label}-${index}`}>\n <div className=\"dsh-usage-rowHead\">\n <span className=\"dsh-usage-rowLabel\">{row.label === 'weekly' ? t('usage.weekly') : row.label}</span>\n <span className={`dsh-usage-rowValue${tone === 'ok' ? '' : ` dsh-usage-rowValue--${tone}`}`}>\n {isCredits && row.remaining !== null\n ? formatAmount(row.remaining)\n : row.limit === null\n ? row.used !== null\n ? t('usage.used', { used: formatAmount(row.used) })\n : row.remaining !== null\n ? formatAmount(row.remaining)\n : t('usage.unlimited')\n : percent !== null\n ? `${Math.round(percent)}%`\n : t('usage.used', { used: formatAmount(row.used) })}\n </span>\n </div>\n {percent !== null ? (\n <div className=\"dsh-usage-barTrack\">\n <div\n className={`dsh-usage-barFill dsh-usage-barFill--${tone}`}\n style={{ width: `${Math.min(100, Math.max(0, percent))}%` }}\n />\n </div>\n ) : null}\n {reset !== null ? <span className=\"dsh-usage-rowReset\">{t('usage.resetIn', { countdown: reset })}</span> : null}\n </div>\n )\n })}\n </>\n )\n}\n\nfunction ProviderCard({ provider, now, red, yellow, t }: { provider: ProviderUsageView; now: number; red: number; yellow: number; t: UsageActionProps['t'] }) {\n return (\n <div className={`dsh-usage-card${provider.active ? ' dsh-usage-card--active' : ''}`}>\n <div className=\"dsh-usage-cardHead\">\n <span className=\"dsh-usage-providerName\">{provider.displayName}</span>\n {provider.active ? <span className=\"dsh-usage-inUse\">{t('status.inUse')}</span> : null}\n </div>\n {provider.status === 'unsupported' ? (\n <span className=\"dsh-usage-message\">{t('status.unsupported')}</span>\n ) : provider.status === 'missing-credential' ? (\n <span className=\"dsh-usage-message\">{t('status.missingCredential', { ref: provider.message })}</span>\n ) : provider.status === 'missing-authorization' ? (\n <span className=\"dsh-usage-message\">{t('status.missingAuthorization', { key: provider.message })}</span>\n ) : provider.status === 'error' ? (\n <span className=\"dsh-usage-message\">{t('status.error')}: {provider.message}</span>\n ) : provider.kind === 'balance' ? (\n (provider.balances ?? []).map((row, index) => {\n const tone = balanceTone(toAmount(row.total), red, yellow)\n return (\n <div key={`${row.currency}-${index}`}>\n <div className=\"dsh-usage-balanceRow\">\n <span className={`dsh-usage-balanceTotal${tone === 'ok' ? '' : ` dsh-usage-balanceTotal--${tone}`}`}>{row.total}</span>\n <span className=\"dsh-usage-balanceCurrency\">{row.currency}</span>\n </div>\n <span className=\"dsh-usage-balanceParts\">\n {[row.granted !== '0' && row.granted !== '0.00' ? t('balance.granted', { amount: row.granted }) : null,\n row.toppedUp !== '0' && row.toppedUp !== '0.00' ? t('balance.toppedUp', { amount: row.toppedUp }) : null]\n .filter(Boolean)\n .join(' · ')}\n </span>\n </div>\n )\n })\n ) : (\n <UsageRows provider={provider} now={now} red={red} yellow={yellow} t={t} />\n )}\n </div>\n )\n}\n\n/* ------------------------------------------------------------------ *\n * Trigger + popover\n * ------------------------------------------------------------------ */\n\n/** Battery level: remaining charge reads as remaining quota. */\nfunction BatteryIcon() {\n return (\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <rect width=\"16\" height=\"10\" x=\"2\" y=\"7\" rx=\"2\" ry=\"2\" />\n <path d=\"M22 11v2\" />\n <path d=\"M6 11v2\" />\n <path d=\"M10 11v2\" />\n </svg>\n )\n}\n\nfunction RefreshIcon() {\n return (\n <svg width=\"14\" height=\"14\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M20 12a8 8 0 1 1-2.34-5.66\" />\n <path d=\"M20 4v4h-4\" />\n </svg>\n )\n}\n\nfunction GlobeIcon() {\n return (\n <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <circle cx=\"12\" cy=\"12\" r=\"9\" />\n <path d=\"M3 12h18\" />\n <path d=\"M12 3c2.5 2.6 3.9 5.7 3.9 9s-1.4 6.4-3.9 9c-2.5-2.6-3.9-5.7-3.9-9S9.5 5.6 12 3z\" />\n </svg>\n )\n}\n\n/** Crosshair for the \"reset ball to its default spot\" head button. */\nfunction HomeIcon() {\n return (\n <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n <circle cx=\"12\" cy=\"12\" r=\"7\" />\n <path d=\"M12 2v3M12 19v3M2 12h3M19 12h3\" />\n <circle cx=\"12\" cy=\"12\" r=\"1.5\" fill=\"currentColor\" stroke=\"none\" />\n </svg>\n )\n}\n\nexport default function UsageAction({ t, fetchUsage, getActiveProvider, subscribeActiveChange }: UsageActionProps) {\n const [open, setOpen] = useState(false)\n const [data, setData] = useState<UsageListResult | null>(null)\n const [error, setError] = useState<string | null>(null)\n const [loading, setLoading] = useState(false)\n const [intervalSec, setIntervalSec] = useState(() => readStoredInterval() ?? DEFAULT_INTERVAL)\n const [langOverride, setLangOverride] = useState<Lang | null>(() => readStoredLang())\n /** Balance thresholds as raw input strings (kept as text so typing never\n fights the controlled input); parsed on use, overridden locally only\n after the user edits them. */\n const [redThreshold, setRedThreshold] = useState<string>(() => readStoredThreshold(THRESHOLD_RED_KEY) ?? String(DEFAULT_BALANCE_RED))\n const [yellowThreshold, setYellowThreshold] = useState<string>(() => readStoredThreshold(THRESHOLD_YELLOW_KEY) ?? String(DEFAULT_BALANCE_YELLOW))\n const [now, setNow] = useState(() => Date.now())\n /** Pinned spot (user-dragged) as viewport fractions; null = follow the default dock. */\n const [pinnedPos, setPinnedPos] = useState<FloatPos | null>(() => readStoredFloatPos())\n /** Viewport size drives the fraction → px conversion and the default dock. */\n const [viewport, setViewport] = useState({ w: window.innerWidth, h: window.innerHeight })\n /** Transient ball position while dragging (cursor-centered); null when docked. */\n const [dragPos, setDragPos] = useState<{ x: number; y: number } | null>(null)\n /** User-resized panel height in px; null = auto-size to content (max-height\n + scroll). Persisted, like every other panel preference. */\n const [panelHeight, setPanelHeight] = useState<number | null>(() => readStoredPanelHeight())\n\n // Follow the harness language by default: probe the shell-injected\n // translator with a known key, then let a panel-level override win.\n const harnessLang: Lang | null =\n t('lang.switch') === zh['lang.switch'] ? 'zh' : t('lang.switch') === en['lang.switch'] ? 'en' : null\n const lang: Lang = langOverride ?? harnessLang ?? 'en'\n const tt = useMemo(() => makeT(lang === 'zh' ? (zh as Record<string, string>) : (en as Record<string, string>)), [lang])\n const toggleLang = useCallback(() => {\n setLangOverride((current) => {\n const next: Lang = (current ?? harnessLang ?? 'en') === 'zh' ? 'en' : 'zh'\n storeLang(next)\n return next\n })\n }, [harnessLang])\n /** Panel-head home button: unpin the ball so it follows the default dock. */\n const resetFloatPos = () => {\n clearStoredFloatPos()\n setPinnedPos(null)\n }\n const [panelPos, setPanelPos] = useState<{ left: number; top?: number; bottom?: number } | null>(null)\n const rootRef = useRef<HTMLDivElement>(null)\n const ballRef = useRef<HTMLButtonElement>(null)\n const panelRef = useRef<HTMLDivElement>(null)\n const inFlight = useRef(false)\n /** Active ball-drag session; cleared on pointerup/pointercancel. */\n const dragRef = useRef<{ pointerId: number; startX: number; startY: number; dragging: boolean } | null>(null)\n /** Set when a drag ends so the trailing click does not toggle the panel. */\n const suppressClickRef = useRef(false)\n /** Active panel-height drag; cleared on pointerup/pointercancel. */\n const resizeRef = useRef<{ pointerId: number; startY: number; startHeight: number; current: number } | null>(null)\n /** Resize bounds snapshotted at drag start from the live layout: min = first\n provider card fully visible, max = content height (no scroll, no blank). */\n const resizeLimitsRef = useRef<{ min: number; max: number } | null>(null)\n\n const refresh = useCallback(async () => {\n if (inFlight.current) return\n inFlight.current = true\n setLoading(true)\n try {\n const result = await fetchUsage()\n // Refine \"in use\" with the focused session's provider (the host only\n // tracks the last explicit composer selection).\n setData(applyActiveProvider(result, getActiveProvider?.()))\n setError(null)\n } catch (reason) {\n setError(reason instanceof Error ? reason.message : String(reason))\n } finally {\n inFlight.current = false\n setLoading(false)\n }\n }, [fetchUsage, getActiveProvider])\n\n // Initial fetch + fixed-interval polling; skip ticks while the tab is hidden.\n useEffect(() => {\n refresh()\n }, [refresh])\n useEffect(() => {\n const timer = setInterval(() => {\n if (document.visibilityState === 'visible') refresh()\n }, intervalSec * 1000)\n return () => clearInterval(timer)\n }, [intervalSec, refresh])\n\n // Adopt the deployment-suggested interval until the user picks one locally.\n useEffect(() => {\n if (data !== null && readStoredInterval() === null && data.refreshSeconds !== intervalSec) {\n setIntervalSec(data.refreshSeconds)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [data])\n\n // Adopt the deployment-suggested balance thresholds until the user edits\n // them locally (a stored override always wins, like the refresh interval).\n useEffect(() => {\n if (data === null) return\n if (readStoredThreshold(THRESHOLD_RED_KEY) === null && typeof data.balanceRedThreshold === 'number') {\n setRedThreshold(String(data.balanceRedThreshold))\n }\n if (readStoredThreshold(THRESHOLD_YELLOW_KEY) === null && typeof data.balanceYellowThreshold === 'number') {\n setYellowThreshold(String(data.balanceYellowThreshold))\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [data])\n\n // Follow the FOCUSED session: when it switches (or its model selection\n // changes), re-derive which provider is \"in use\" immediately — the host's\n // global-default flag would otherwise stay stale until the next poll. Falls\n // back to the host flag when no live client state is available.\n useEffect(() => {\n const unsubscribe = subscribeActiveChange?.(() => {\n setData((prev) => (prev === null ? prev : applyActiveProvider(prev, getActiveProvider?.())))\n })\n return unsubscribe\n // The subscription callbacks are stable closures created once by the\n // client half; re-subscribing on prop identity churn is not needed.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n // Slow tick so reset countdowns advance while the panel is open.\n useEffect(() => {\n if (!open) return\n setNow(Date.now())\n const timer = setInterval(() => setNow(Date.now()), 30000)\n return () => clearInterval(timer)\n }, [open])\n\n // Close on outside press / Escape, mirroring the shipped popover behavior.\n // The panel and the ball are portaled to document.body, so all trees count\n // as inside.\n useEffect(() => {\n if (!open) return\n const closeOutside = (event: PointerEvent) => {\n if (!(event.target instanceof Node)) return\n if (rootRef.current?.contains(event.target)) return\n if (ballRef.current?.contains(event.target)) return\n if (panelRef.current?.contains(event.target)) return\n setOpen(false)\n }\n document.addEventListener('pointerdown', closeOutside)\n return () => document.removeEventListener('pointerdown', closeOutside)\n }, [open])\n\n // Anchor the fixed-position panel to the ball; recompute while open so a\n // position reset or window resize keeps it attached. A ball in the lower\n // half of the viewport opens the panel above it, upper half below.\n useEffect(() => {\n if (!open) return\n const update = () => {\n const rect = ballRef.current?.getBoundingClientRect()\n if (!rect) return\n const left = Math.min(Math.max(8, rect.left), Math.max(8, window.innerWidth - 336))\n setPanelPos(\n rect.top > window.innerHeight / 2\n ? { left, bottom: window.innerHeight - rect.top + 6 }\n : { left, top: rect.bottom + 6 },\n )\n }\n update()\n window.addEventListener('resize', update)\n return () => window.removeEventListener('resize', update)\n }, [open, pinnedPos, viewport])\n\n // Keep a persisted height honest while open: never render taller than the\n // current content (no blank strip at the bottom when providers vanish) or\n // the viewport. Runs before paint, so no flash; a no-op during a drag.\n useLayoutEffect(() => {\n const panel = panelRef.current\n if (panel === null || panelHeight === null) return\n const clamped = Math.min(panelHeight, panelContentHeight(panel), panelMaxHeight())\n if (clamped !== panelHeight) setPanelHeight(clamped)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [panelHeight, data, open])\n\n // Track the viewport: fraction-based positions and the default dock follow\n // window resizes automatically.\n useEffect(() => {\n const onResize = () => setViewport({ w: window.innerWidth, h: window.innerHeight })\n window.addEventListener('resize', onResize)\n return () => window.removeEventListener('resize', onResize)\n }, [])\n\n // Effective thresholds: parse the inputs, fall back to defaults, and keep\n // the red zone at or below the yellow one so both stay meaningful.\n const effYellow = parseThreshold(yellowThreshold) ?? DEFAULT_BALANCE_YELLOW\n const effRed = Math.min(parseThreshold(redThreshold) ?? DEFAULT_BALANCE_RED, effYellow)\n\n const tone = healthTone(data, error, effRed, effYellow)\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n if (event.key !== 'Escape' || !open) return\n event.preventDefault()\n setOpen(false)\n }\n\n /* Ball dragging: pointer events only (touch included via touch-action:\n none). A press becomes a drag past a 5px dead zone; while dragging the\n ball follows the cursor centered on it, and on release it stays exactly\n where dropped (no edge snapping). A plain press falls through to the\n click handler. */\n const onBallPointerDown = (event: React.PointerEvent<HTMLButtonElement>) => {\n event.currentTarget.setPointerCapture(event.pointerId)\n dragRef.current = { pointerId: event.pointerId, startX: event.clientX, startY: event.clientY, dragging: false }\n }\n\n const onBallPointerMove = (event: React.PointerEvent<HTMLButtonElement>) => {\n const drag = dragRef.current\n if (drag === null || drag.pointerId !== event.pointerId) return\n if (!drag.dragging) {\n if (Math.abs(event.clientX - drag.startX) < 5 && Math.abs(event.clientY - drag.startY) < 5) return\n drag.dragging = true\n // The panel would detach from a moving anchor: close it on drag start.\n if (open) setOpen(false)\n }\n const half = BALL_SIZE / 2\n setDragPos({\n x: Math.min(Math.max(half, event.clientX), window.innerWidth - half),\n y: Math.min(Math.max(half, event.clientY), window.innerHeight - half),\n })\n }\n\n const endBallDrag = (event: React.PointerEvent<HTMLButtonElement>) => {\n const drag = dragRef.current\n dragRef.current = null\n if (drag === null || drag.pointerId !== event.pointerId || !drag.dragging) return\n const half = BALL_SIZE / 2\n const x = Math.min(Math.max(half, event.clientX), window.innerWidth - half)\n const y = Math.min(Math.max(half, event.clientY), window.innerHeight - half)\n // Pin the drop point as viewport fractions so it follows window resizes.\n const next: FloatPos = { fx: x / window.innerWidth, fy: y / window.innerHeight }\n setPinnedPos(next)\n storeFloatPos(next)\n setDragPos(null)\n suppressClickRef.current = true\n }\n\n const cancelBallDrag = (event: React.PointerEvent<HTMLButtonElement>) => {\n if (dragRef.current?.pointerId !== event.pointerId) return\n dragRef.current = null\n setDragPos(null)\n }\n\n /* Panel height resize: grab the top-edge handle, drag up to grow / down to\n shrink. The panel itself never moves — the anchored edge stays put, only\n the height changes. The drag is bounded at drag start: growing stops at\n the content height (no scroll, no blank strip), shrinking stops once the\n first provider card is fully visible. */\n const onResizePointerDown = (event: React.PointerEvent<HTMLDivElement>) => {\n event.currentTarget.setPointerCapture(event.pointerId)\n const panel = panelRef.current\n const rect = panel?.getBoundingClientRect()\n const startHeight = panelHeight ?? Math.round(rect?.height ?? 0)\n if (panel !== null) {\n const viewportMax = panelMaxHeight()\n const max = Math.min(panelContentHeight(panel), viewportMax)\n const min = Math.min(Math.max(firstCardMinHeight(panel), PANEL_MIN_H), max)\n resizeLimitsRef.current = { min, max }\n } else {\n resizeLimitsRef.current = { min: PANEL_MIN_H, max: panelMaxHeight() }\n }\n resizeRef.current = { pointerId: event.pointerId, startY: event.clientY, startHeight, current: startHeight }\n }\n\n const onResizePointerMove = (event: React.PointerEvent<HTMLDivElement>) => {\n const resize = resizeRef.current\n if (resize === null || resize.pointerId !== event.pointerId) return\n const limits = resizeLimitsRef.current\n const next = limits === null\n ? resize.startHeight + (resize.startY - event.clientY)\n : Math.min(Math.max(resize.startHeight + (resize.startY - event.clientY), limits.min), limits.max)\n resize.current = next\n setPanelHeight(next)\n }\n\n const endResize = (event: React.PointerEvent<HTMLDivElement>) => {\n const resize = resizeRef.current\n if (resize === null || resize.pointerId !== event.pointerId) return\n resizeRef.current = null\n resizeLimitsRef.current = null\n storePanelHeight(resize.current)\n }\n\n const onBallClick = () => {\n if (suppressClickRef.current) {\n suppressClickRef.current = false\n return\n }\n setNow(Date.now())\n setOpen((current) => !current)\n if (!open) refresh()\n }\n\n // Ball center in px: transient drag point > pinned fractions > default dock.\n // (The default reads the sidebar edge from the DOM at render time; cheap.)\n const docked = pinnedPos ?? defaultFloatPos()\n const centerX = dragPos !== null ? dragPos.x : docked.fx * viewport.w\n const centerY = dragPos !== null ? dragPos.y : docked.fy * viewport.h\n\n return (\n <div ref={rootRef} className=\"dsh-usage-root\" onKeyDown={onKeyDown}>\n {createPortal(\n <button\n ref={ballRef}\n type=\"button\"\n className={`dsh-usage-ball dsh-usage-tone-${tone}`}\n style={{ left: centerX - BALL_SIZE / 2, top: centerY - BALL_SIZE / 2 }}\n aria-expanded={open}\n aria-label={tt('action.aria')}\n title={`${tt('action.aria')} · ${tt(`status.tone.${tone}`)}`}\n onPointerDown={onBallPointerDown}\n onPointerMove={onBallPointerMove}\n onPointerUp={endBallDrag}\n onPointerCancel={cancelBallDrag}\n onClick={onBallClick}\n onKeyDown={onKeyDown}\n >\n <BatteryIcon />\n </button>,\n document.body,\n )}\n {open && panelPos !== null\n ? createPortal(\n <div\n ref={panelRef}\n className=\"dsh-usage-panel\"\n role=\"dialog\"\n aria-label={tt('panel.title')}\n style={{\n left: panelPos.left,\n top: panelPos.top,\n bottom: panelPos.bottom,\n ...(panelHeight !== null ? { height: Math.min(panelHeight, panelMaxHeight()), maxHeight: 'none' } : {}),\n }}\n onKeyDown={onKeyDown}\n >\n <div\n className=\"dsh-usage-resize\"\n title={tt('panel.resize')}\n aria-label={tt('panel.resize')}\n onPointerDown={onResizePointerDown}\n onPointerMove={onResizePointerMove}\n onPointerUp={endResize}\n onPointerCancel={endResize}\n />\n <div className=\"dsh-usage-head\">\n <span className=\"dsh-usage-title\">{tt('panel.title')}</span>\n {data?.version ? <span className=\"dsh-usage-version\">v{data.version}</span> : null}\n <button\n type=\"button\"\n className=\"dsh-usage-home\"\n onClick={resetFloatPos}\n title={tt('panel.resetPos')}\n aria-label={tt('panel.resetPos')}\n >\n <HomeIcon />\n </button>\n <button\n type=\"button\"\n className=\"dsh-usage-lang\"\n onClick={toggleLang}\n title={tt('lang.switch')}\n aria-label={tt('lang.switch')}\n >\n <GlobeIcon />\n <span>{lang === 'zh' ? '中' : 'EN'}</span>\n </button>\n <button\n type=\"button\"\n className={`dsh-usage-refresh${loading ? ' dsh-usage-refresh--loading' : ''}`}\n disabled={loading}\n onClick={refresh}\n title={tt('panel.refresh')}\n aria-label={tt('panel.refresh')}\n >\n <RefreshIcon />\n </button>\n </div>\n {data === null && error !== null ? (\n <span className=\"dsh-usage-message\">{tt('status.error')}: {error}</span>\n ) : null}\n {data !== null && data.providers.length === 0 ? (\n <span className=\"dsh-usage-message\">{tt('panel.empty')}</span>\n ) : null}\n {(data?.providers ?? []).map((provider) => (\n <ProviderCard key={provider.id} provider={provider} now={now} red={effRed} yellow={effYellow} t={tt} />\n ))}\n <div className=\"dsh-usage-foot\">\n <span className=\"dsh-usage-footLabel\">{tt('panel.interval')}</span>\n <select\n className=\"dsh-usage-select\"\n value={intervalSec}\n onChange={(event) => {\n const value = Number(event.target.value)\n setIntervalSec(value)\n storeInterval(value)\n }}\n >\n {INTERVAL_OPTIONS.map((seconds) => (\n <option key={seconds} value={seconds}>{tt(`interval.${seconds}s`)}</option>\n ))}\n </select>\n <span className=\"dsh-usage-updated\">\n {data === null\n ? tt('panel.never')\n : tt('panel.updated', { time: new Date(data.fetchedAt).toLocaleTimeString(lang === 'zh' ? 'zh-CN' : 'en-US') })}\n </span>\n </div>\n <div className=\"dsh-usage-thresholds\">\n <span className=\"dsh-usage-footLabel\">{tt('panel.thresholds')}</span>\n <label className=\"dsh-usage-thresholdField\" title={tt('panel.thresholdRed')}>\n <span className=\"dsh-usage-thresholdLabel dsh-usage-thresholdLabel--red\">{tt('panel.thresholdRed')}</span>\n <input\n className=\"dsh-usage-thresholdInput\"\n type=\"number\"\n min={0}\n step={0.01}\n inputMode=\"decimal\"\n value={redThreshold}\n onChange={(event) => {\n setRedThreshold(event.target.value)\n storeThreshold(THRESHOLD_RED_KEY, event.target.value)\n }}\n />\n </label>\n <label className=\"dsh-usage-thresholdField\" title={tt('panel.thresholdYellow')}>\n <span className=\"dsh-usage-thresholdLabel dsh-usage-thresholdLabel--yellow\">{tt('panel.thresholdYellow')}</span>\n <input\n className=\"dsh-usage-thresholdInput\"\n type=\"number\"\n min={0}\n step={0.01}\n inputMode=\"decimal\"\n value={yellowThreshold}\n onChange={(event) => {\n setYellowThreshold(event.target.value)\n storeThreshold(THRESHOLD_YELLOW_KEY, event.target.value)\n }}\n />\n </label>\n </div>\n </div>,\n document.body,\n )\n : null}\n </div>\n )\n}\n","/**\n * Panel stylesheet, injected once per page. Follows the shipped plugins'\n * convention of a `<style data-plugin-css>` tag and design-token colors.\n */\nconst CSS = `\n.dsh-usage-root { position: relative; display: inline-flex; }\n/* Tri-tone health halo: only the shadow carries the state of the provider IN\n USE (green ok / amber remaining<30% / red error or usage>=90%) — the button\n face itself stays neutral. A 1px tone ring plus a soft halo keeps the\n state readable on both light and dark skins. */\n.dsh-usage-tone-ok { --dsh-usage-tone: #22a06b; }\n.dsh-usage-tone-warn { --dsh-usage-tone: #e2b93b; }\n.dsh-usage-tone-danger { --dsh-usage-tone: #d94f4f; }\n/* Floating ball trigger: a draggable fixed circle portaled to document.body,\n one layer below the panel (1000) so the popover always covers it. Position\n comes from inline style: docked it sits at its stored coordinates, while\n dragging it follows the cursor. Keeps the shell's lv3 lift shadow; the\n tone halo stacks on top. */\n.dsh-usage-ball {\n position: fixed; z-index: 999; width: 32px; height: 32px; border-radius: 50%;\n cursor: pointer; touch-action: none;\n display: inline-flex; align-items: center; justify-content: center;\n border: 1px solid var(--dsw-alias-border-l2);\n background-color: var(--dsw-specific-menu);\n color: var(--dsw-alias-label-tertiary);\n transition: box-shadow 0.15s;\n}\n.dsh-usage-ball:hover, .dsh-usage-ball:focus-visible { color: var(--dsw-alias-label-secondary); }\n.dsh-usage-ball svg { width: 15px; height: 15px; }\n.dsh-usage-ball.dsh-usage-tone-ok,\n.dsh-usage-ball.dsh-usage-tone-warn,\n.dsh-usage-ball.dsh-usage-tone-danger {\n box-shadow:\n var(--dsw-shadow-lv3),\n 0 0 0 1px color-mix(in srgb, var(--dsh-usage-tone) 40%, transparent),\n 0 0 14px color-mix(in srgb, var(--dsh-usage-tone) 55%, transparent);\n}\n.dsh-usage-ball.dsh-usage-tone-ok:hover,\n.dsh-usage-ball.dsh-usage-tone-warn:hover,\n.dsh-usage-ball.dsh-usage-tone-danger:hover,\n.dsh-usage-ball.dsh-usage-tone-ok:focus-visible,\n.dsh-usage-ball.dsh-usage-tone-warn:focus-visible,\n.dsh-usage-ball.dsh-usage-tone-danger:focus-visible {\n box-shadow:\n var(--dsw-shadow-lv3),\n 0 0 0 1px color-mix(in srgb, var(--dsh-usage-tone) 55%, transparent),\n 0 0 18px color-mix(in srgb, var(--dsh-usage-tone) 70%, transparent);\n}\n.dsh-usage-panel {\n z-index: 1000; box-sizing: border-box;\n border: 1px solid var(--dsw-alias-border-l2);\n background: var(--dsw-specific-menu);\n box-shadow: var(--dsw-shadow-lv3);\n border-radius: 12px; margin: 0; padding: 8px;\n width: 320px; max-width: min(360px, 100vw - 16px);\n max-height: min(460px, 100vh - 60px); overflow: auto;\n display: flex; flex-direction: column; gap: 6px;\n /* position: fixed with viewport coordinates computed inline from the\n trigger rect — absolute positioning inside the sidebar gets clipped by\n the column's overflow. */\n position: fixed;\n --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);\n --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);\n}\n/* Top-edge resize handle: sticks to the panel top even while the body\n scrolls, so it is always grabbable; drag to make the panel taller/shorter\n (height persisted in localStorage). */\n.dsh-usage-resize {\n position: sticky; top: 0; z-index: 2; flex: none;\n height: 6px; margin: -4px 0 0;\n cursor: ns-resize; touch-action: none;\n border-radius: 3px;\n}\n.dsh-usage-resize::after {\n content: ''; position: absolute; left: 50%; top: 50%;\n transform: translate(-50%, -50%);\n width: 32px; height: 3px; border-radius: 2px;\n background: var(--dsw-alias-border-l2);\n}\n.dsh-usage-resize:hover, .dsh-usage-resize:active {\n background: color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 25%, transparent);\n}\n.dsh-usage-resize:hover::after, .dsh-usage-resize:active::after {\n background: var(--dsw-alias-accent, #4f8cff);\n}\n.dsh-usage-head {\n display: flex; align-items: center; gap: 8px; padding: 2px 4px 6px;\n border-bottom: 1px solid var(--dsw-alias-border-l2);\n}\n.dsh-usage-title { color: var(--dsw-alias-label-primary); font-size: 13px; font-weight: 600; }\n.dsh-usage-version {\n color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px;\n padding: 0 5px; border-radius: 4px; background: var(--dsw-alias-fill-l2);\n font-variant-numeric: tabular-nums; user-select: none; margin-right: auto;\n}\n.dsh-usage-lang {\n cursor: pointer; display: inline-flex; align-items: center; gap: 4px;\n border: 0; border-radius: 6px; background: 0; padding: 3px 5px;\n color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px;\n}\n.dsh-usage-lang:hover { color: var(--dsw-alias-label-secondary); }\n.dsh-usage-refresh {\n cursor: pointer; display: inline-flex; align-items: center; justify-content: center;\n border: 0; border-radius: 6px; background: 0; padding: 4px;\n color: var(--dsw-alias-label-tertiary); line-height: 0;\n}\n.dsh-usage-refresh:hover { color: var(--dsw-alias-label-secondary); }\n.dsh-usage-refresh:disabled { opacity: 0.5; cursor: default; }\n/* Home button in the panel head: sends the ball back to its default spot. */\n.dsh-usage-home {\n cursor: pointer; display: inline-flex; align-items: center; justify-content: center;\n border: 0; border-radius: 6px; background: 0; padding: 4px;\n color: var(--dsw-alias-label-tertiary); line-height: 0;\n}\n.dsh-usage-home:hover { color: var(--dsw-alias-label-secondary); }\n@keyframes dsh-usage-spin { to { transform: rotate(360deg); } }\n.dsh-usage-refresh--loading svg { animation: dsh-usage-spin 0.9s linear infinite; }\n.dsh-usage-card {\n border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px;\n background: var(--dsw-alias-fill-l2);\n}\n/* The provider in use, whose quota alone drives the ball tone. */\n.dsh-usage-card--active {\n outline: 1px solid color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 45%, transparent);\n outline-offset: -1px;\n}\n.dsh-usage-cardHead { display: flex; align-items: center; gap: 8px; }\n.dsh-usage-providerName {\n color: var(--dsw-alias-label-primary); font-size: 13px; font-weight: 600;\n min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1;\n}\n.dsh-usage-inUse {\n flex: none; font-size: 11px; line-height: 16px; padding: 0 6px; border-radius: 999px;\n color: var(--dsw-alias-label-secondary);\n background: color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 18%, transparent);\n border: 1px solid color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 35%, transparent);\n}\n.dsh-usage-message { color: var(--dsw-alias-label-tertiary); font-size: 12px; line-height: 18px; word-break: break-all; }\n.dsh-usage-balanceRow { display: flex; align-items: baseline; gap: 8px; }\n.dsh-usage-balanceTotal {\n color: var(--dsw-alias-label-primary); font-size: 18px; font-weight: 600;\n font-variant-numeric: tabular-nums;\n}\n/* Balance below the user-configured thresholds: red < red threshold, yellow\n below the yellow threshold; a healthy balance keeps the default label color. */\n.dsh-usage-balanceTotal--warn { color: #e2b93b; }\n.dsh-usage-balanceTotal--danger { color: #d94f4f; }\n.dsh-usage-balanceCurrency { color: var(--dsw-alias-label-secondary); font-size: 12px; }\n.dsh-usage-balanceParts { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; }\n.dsh-usage-row { display: flex; flex-direction: column; gap: 3px; }\n.dsh-usage-rowHead { display: flex; align-items: center; gap: 8px; font-size: 12px; line-height: 18px; }\n.dsh-usage-rowLabel { color: var(--dsw-alias-label-secondary); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.dsh-usage-rowValue { color: var(--dsw-alias-label-tertiary); font-variant-numeric: tabular-nums; flex: none; }\n/* Credits rows show a remaining balance: tinted by the balance thresholds. */\n.dsh-usage-rowValue--warn { color: #e2b93b; }\n.dsh-usage-rowValue--danger { color: #d94f4f; }\n.dsh-usage-barTrack {\n height: 4px; border-radius: 2px; overflow: hidden;\n background: var(--dsw-alias-border-l2);\n}\n.dsh-usage-barFill { height: 100%; border-radius: 2px; transition: width 0.3s; }\n.dsh-usage-barFill--ok { background: #22a06b; }\n.dsh-usage-barFill--warn { background: #e2b93b; }\n.dsh-usage-barFill--danger { background: #d94f4f; }\n.dsh-usage-rowReset { color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 16px; }\n.dsh-usage-foot {\n display: flex; align-items: center; gap: 8px; padding: 6px 4px 2px;\n border-top: 1px solid var(--dsw-alias-border-l2);\n}\n.dsh-usage-footLabel { color: var(--dsw-alias-label-tertiary); font-size: 11px; }\n.dsh-usage-select {\n border: 1px solid var(--dsw-alias-border-l2); border-radius: 6px; background: 0;\n color: var(--dsw-alias-label-secondary); font-size: 11px; padding: 2px 4px; cursor: pointer;\n}\n.dsh-usage-updated { color: var(--dsw-alias-label-tertiary); font-size: 11px; margin-left: auto; }\n/* Balance threshold row under the footer: red/yellow inputs persisted locally. */\n.dsh-usage-thresholds {\n display: flex; align-items: center; gap: 10px; padding: 2px 4px 4px;\n}\n.dsh-usage-thresholdField { display: inline-flex; align-items: center; gap: 4px; }\n.dsh-usage-thresholdLabel { font-size: 11px; font-weight: 600; }\n.dsh-usage-thresholdLabel--red { color: #d94f4f; }\n.dsh-usage-thresholdLabel--yellow { color: #e2b93b; }\n.dsh-usage-thresholdInput {\n width: 58px; box-sizing: border-box;\n border: 1px solid var(--dsw-alias-border-l2); border-radius: 6px; background: 0;\n color: var(--dsw-alias-label-secondary); font-size: 11px; padding: 2px 4px;\n font-variant-numeric: tabular-nums;\n}\n.dsh-usage-thresholdInput:focus {\n outline: none;\n border-color: var(--dsw-alias-accent, #4f8cff);\n box-shadow: 0 0 0 1px color-mix(in srgb, var(--dsw-alias-accent, #4f8cff) 40%, transparent);\n}\n`\n\nconst TAG_ID = 'dsh-provider-usage/panel.css'\n\n/** Inject the panel stylesheet once; on HMR swap, refresh the existing tag's payload in place. */\nexport function ensureStyles(): void {\n if (typeof document === 'undefined') return\n const existing = document.querySelector('style[data-plugin-css=' + JSON.stringify(TAG_ID) + ']')\n if (existing !== null) {\n // A hot-swapped bundle re-runs this module while the old <style> tag is\n // still in the DOM — sync its content so the new CSS actually applies.\n if (existing.textContent !== CSS) existing.textContent = CSS\n return\n }\n const tag = document.createElement('style')\n tag.dataset.plugin = 'dsh-provider-usage'\n tag.dataset.pluginCss = TAG_ID\n tag.textContent = CSS\n document.head.appendChild(tag)\n}\n","/**\n * provider-usage — browser half.\n *\n * Registers the locale dictionaries and contributes the usage widget into the\n * sidebar footer's additive action slot. Data comes from the host `usage`\n * Typert Remote (SRC mode — no generated descriptors) through the raw RPC\n * caller on the connection service.\n *\n * The \"provider in use\" flag is refined CLIENT-side: the host marks the route\n * from the GLOBAL default model selection, which only moves on an explicit\n * composer pick — switching between sessions with different per-session\n * selections would leave it stale. The focused session's own effective\n * selection (pending → last used → host default, mirrored by the composer's\n * model seat) is read live from the client session services and overrides the\n * host flag, so the panel follows session switches immediately.\n */\nimport UsageAction, { type UsageActionProps } from './Panel'\nimport { en, zh } from './locales'\nimport { ensureStyles } from './styles'\n\n/**\n * Required client services: slot registry, locale seats, the connection RPC\n * caller, and the live session/model-selection state used to refine the\n * \"in use\" flag (`sessions` + `modelDirectories`, both mounted by the web\n * app — the latter is the composer model seat's own service).\n */\nconst inject = ['slots', 'locale', 'connection', 'sessions', 'modelDirectories']\n\ninterface ClientContext {\n effect: (fn: () => unknown, label: string) => void\n locale: { register: (ns: string, dicts: { zh: unknown; en: unknown }) => unknown }\n slots: {\n inject: (name: string, callback: () => unknown) => void\n register: (entry: Record<string, unknown>, component: unknown) => unknown\n }\n connection: {\n rpc: {\n call: (\n channel: string,\n endpoint: string,\n payload: { args: Record<string, unknown> },\n signal?: AbortSignal,\n ) => Promise<{ ok: true; value: unknown } | { ok: false; error: { code: string; message: string } }>\n }\n }\n /** Client session list: the focused session id rides the same snapshot as\n the sidebar highlight (duck-typed SnapshotStore face). */\n sessions: {\n list: {\n getSnapshot(): { current?: string }\n subscribe(fn: () => void): () => void\n }\n }\n /** Per-session model directories (the composer seat's shared state): the\n focused session's effective selection mirrors the agent's resolution —\n pending selection → last used → deployment default. */\n modelDirectories: {\n directoryFor(sessionId: string): {\n store: {\n getSnapshot(): { current?: { provider: string; model: string } | null }\n subscribe(fn: () => void): () => void\n }\n }\n }\n}\n\nfunction apply(ctx: ClientContext) {\n ensureStyles()\n ctx.effect(() => ctx.locale.register('provider-usage', { zh, en }), 'provider-usage: dictionaries')\n\n const fetchUsage: UsageActionProps['fetchUsage'] = async () => {\n const result = await ctx.connection.rpc.call('/api', 'usage/list', { args: {} })\n if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`)\n return result.value as Awaited<ReturnType<UsageActionProps['fetchUsage']>>\n }\n\n /**\n * The provider the FOCUSED session's composer shows (and its agent would\n * use): the session's durable model selection, else the deployment default\n * — exactly what the host resolves per session. Undefined while the client\n * session state is not ready; the host's own flag then stands.\n */\n const getActiveProvider: UsageActionProps['getActiveProvider'] = () => {\n const current = ctx.sessions?.list?.getSnapshot()?.current\n if (typeof current !== 'string' || current === '') return undefined\n try {\n const directory = ctx.modelDirectories?.directoryFor(current)\n const provider = directory?.store?.getSnapshot()?.current?.provider\n return typeof provider === 'string' && provider !== '' ? provider : undefined\n } catch {\n // Session scope not resolvable yet — the next list event retries.\n return undefined\n }\n }\n\n /**\n * Re-derive the panel's \"in use\" flag the moment the focused session or its\n * model selection changes — no need to wait for the next poll tick. The\n * directory subscription follows the CURRENT focused session and is\n * re-pointed on every session switch, so a late projection load still lands.\n */\n const subscribeActiveChange: UsageActionProps['subscribeActiveChange'] = (onChange) => {\n const sessions = ctx.sessions\n if (typeof sessions?.list?.subscribe !== 'function') return () => {}\n let directoryUnsub: (() => void) | null = null\n const followDirectory = () => {\n directoryUnsub?.()\n directoryUnsub = null\n const current = sessions.list.getSnapshot()?.current\n if (typeof current === 'string' && current !== '') {\n try {\n const store = ctx.modelDirectories?.directoryFor(current)?.store\n if (typeof store?.subscribe === 'function') directoryUnsub = store.subscribe(onChange)\n } catch {\n /* directory not resolvable yet — the next session-list event retries */\n }\n }\n }\n const offList = sessions.list.subscribe(() => {\n followDirectory()\n onChange()\n })\n followDirectory()\n return () => {\n offList?.()\n directoryUnsub?.()\n }\n }\n\n ctx.slots.inject('sidebar.footer.action', () =>\n ctx.slots.register(\n {\n name: 'sidebar.footer.action',\n id: 'provider-usage',\n order: 10,\n locale: 'provider-usage',\n inject: () => ({ fetchUsage, getActiveProvider, subscribeActiveChange }),\n },\n UsageAction,\n ),\n )\n}\n\nexport { apply, inject }\n"],"mappings":";;;;;;;;;;;EACA,MAAa,KAAK;GAChB,gBAAgB;GAChB,eAAe;GACf,eAAe;GACf,gBAAgB;GAChB,iBAAiB;GACjB,oBAAoB;GACpB,eAAe;GACf,kBAAkB;GAClB,kBAAkB;GAClB,oBAAoB;GACpB,sBAAsB;GACtB,yBAAyB;GACzB,iBAAiB;GACjB,eAAe;GACf,eAAe;GACf,gBAAgB;GAChB,gBAAgB;GAChB,gBAAgB;GAChB,iBAAiB;GACjB,iBAAiB;GACjB,kBAAkB;GAClB,iBAAiB;GACjB,mBAAmB;GACnB,oBAAoB;GACpB,gBAAgB;GAChB,cAAc;GACd,mBAAmB;GACnB,mBAAmB;GACnB,iBAAiB;GACjB,iBAAiB;GACjB,sBAAsB;GACtB,4BAA4B;GAC5B,+BAA+B;GAC/B,gBAAgB;GAChB,gBAAgB;GAChB,kBAAkB;GAClB,oBAAoB;GACpB,sBAAsB;GACtB,kBAAkB;GAClB,mBAAmB;GACnB,qBAAqB;EACvB;;EAGA,MAAa,KAAK;GAChB,gBAAgB;GAChB,eAAe;GACf,eAAe;GACf,gBAAgB;GAChB,iBAAiB;GACjB,oBAAoB;GACpB,eAAe;GACf,kBAAkB;GAClB,kBAAkB;GAClB,oBAA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YAAY,aAAa,CAAC;IACnE,IAAI,iBAAsC;IAC1C,MAAM,wBAAwB;KAC5B,iBAAiB;KACjB,iBAAiB;KACjB,MAAM,UAAU,SAAS,KAAK,YAAY,CAAC,EAAE;KAC7C,IAAI,OAAO,YAAY,YAAY,YAAY,IAC7C,IAAI;MACF,MAAM,QAAQ,IAAI,kBAAkB,aAAa,OAAO,CAAC,EAAE;MAC3D,IAAI,OAAO,OAAO,cAAc,YAAY,iBAAiB,MAAM,UAAU,QAAQ;KACvF,QAAQ,CAER;IAEJ;IACA,MAAM,UAAU,SAAS,KAAK,gBAAgB;KAC5C,gBAAgB;KAChB,SAAS;IACX,CAAC;IACD,gBAAgB;IAChB,aAAa;KACX,UAAU;KACV,iBAAiB;IACnB;GACF;GAEA,IAAI,MAAM,OAAO,+BACf,IAAI,MAAM,SACR;IACE,MAAM;IACN,IAAI;IACJ,OAAO;IACP,QAAQ;IACR,eAAe;KAAE;KAAY;KAAmB;IAAsB;GACxE,GACA,WACF,CACF;EACF"}
|
package/lib/index.js
CHANGED
|
@@ -93,7 +93,7 @@ async function refreshOpenAiCodexGrant(refreshToken, signal) {
|
|
|
93
93
|
const name = "provider-usage";
|
|
94
94
|
/** Own package version, baked in by tsdown `define` at build time (the
|
|
95
95
|
fallback only fires if the sources are compiled some other way). */
|
|
96
|
-
const version = "0.3.
|
|
96
|
+
const version = "0.3.10";
|
|
97
97
|
/** Settings namespace this plugin owns (registered through `ctx.settings`). */
|
|
98
98
|
const NS = "provider-usage";
|
|
99
99
|
const PROVIDER_KINDS = [
|
|
@@ -123,6 +123,12 @@ const ProviderSpec = z.object({
|
|
|
123
123
|
const Config = z.object({
|
|
124
124
|
/** Suggested widget refresh interval in seconds (the panel may override it locally). */
|
|
125
125
|
refreshSeconds: z.number().step(1).min(5).max(86400).default(60),
|
|
126
|
+
/** Balance below this amount turns red, compared in the balance's own currency
|
|
127
|
+
(the panel may override it locally). */
|
|
128
|
+
balanceRedThreshold: z.number().step(.01).min(0).default(10),
|
|
129
|
+
/** Balance below this amount turns yellow, compared in the balance's own currency
|
|
130
|
+
(the panel may override it locally). */
|
|
131
|
+
balanceYellowThreshold: z.number().step(.01).min(0).default(30),
|
|
126
132
|
/** Enumerate live provider routes from the llm registry. */
|
|
127
133
|
autoDetect: z.boolean().default(true),
|
|
128
134
|
/** Manual provider specs; an id matching a detected route overrides it. */
|
|
@@ -867,6 +873,8 @@ var UsageService = class extends TypertRemoteService {
|
|
|
867
873
|
return {
|
|
868
874
|
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
869
875
|
refreshSeconds: this.options().refreshSeconds,
|
|
876
|
+
balanceRedThreshold: this.options().balanceRedThreshold,
|
|
877
|
+
balanceYellowThreshold: this.options().balanceYellowThreshold,
|
|
870
878
|
version,
|
|
871
879
|
providers
|
|
872
880
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-provider-usage",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "DeepSeek Harness plugin: live account balance/usage panel for every configured LLM provider (draggable floating-ball widget, configurable refresh interval)",
|
|
3
|
+
"version": "0.3.10",
|
|
4
|
+
"description": "DeepSeek Harness plugin: live account balance/usage panel for every configured LLM provider (draggable floating-ball widget, configurable refresh interval and balance thresholds)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|