dsh-notify-tray 0.1.3 → 0.1.5

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/lib/client.js CHANGED
@@ -63,6 +63,7 @@ window.__ModuleLoader__.load({
63
63
  const PACKAGE_KEY = 'dsh-notify-tray'
64
64
  const CATALOG_ROUTE = 'notify-tray/catalog'
65
65
  const REFRESH_ROUTE = 'notify-tray/refresh'
66
+ const TRAY_ROUTE = 'notify-tray/tray'
66
67
  /** How often the page re-reads the host's live state (current model, plan quota). */
67
68
  const LIVE_MS = 5000
68
69
 
@@ -102,92 +103,68 @@ window.__ModuleLoader__.load({
102
103
  }
103
104
 
104
105
  const zh = {
105
- summary: '小鲸鱼什么时候来找你、状态栏里显示什么、今天的花费怎么算、你在用哪家的套餐,都在这里调。',
106
- summary_win32: '小鲸鱼什么时候来找你、今天的花费怎么算、你在用哪家的套餐,都在这里调。Windows 没有状态栏,小鲸鱼只用通知来找你。',
107
- sectionNotify: '什么时候来找你',
108
- sectionNotifyHint: '五种事情,每种都可以单独关掉。',
109
- notifyCompleted: '任务做完了',
110
- notifyCompletedHint: '「🐳 搞定啦~」',
111
- notifyChoice: '需要你选一个',
112
- notifyChoiceHint: '「🐳 该你拍板啦」',
113
- notifyInput: '需要你写几个字',
114
- notifyInputHint: '「🐳 等你说话呢」',
115
- notifyApproval: '需要你点头批准',
116
- notifyApprovalHint: '「🐳 要不要放行?」',
106
+ summary: '任务做完或需要你时提醒你,状态栏里看进度和花费。',
107
+ summary_win32: '任务做完或需要你时弹通知,顺便算算今天花了多少。Windows 没有状态栏,小鲸鱼只用通知来找你。',
108
+ sectionNotify: '提醒我',
109
+ notifyWhen: '这些时候弹通知',
110
+ notifyCompleted: '做完了',
111
+ notifyChoice: '要我选',
112
+ notifyInput: '要我写字',
113
+ notifyApproval: '要我批准',
117
114
  notifyFailed: '翻车了',
118
- notifyFailedHint: '「🐳 呜…翻车了」',
119
- sectionHow: '怎么来找你',
120
- channel: '通知从哪里弹',
121
- channelAuto: '自动',
122
- channelClient: '只用窗口',
123
- channelSystem: '只用系统',
124
- channelBoth: '都弹',
125
- channelOff: '不弹',
126
- channelHint: '自动:有 DSH 窗口时由窗口弹(图标是 DSH 的),没有窗口时由系统弹。',
127
- suppressWhenFocused: '我正盯着这个会话时就别弹了',
128
- suppressWhenFocusedHint: '关掉后,哪怕你正看着它跑完也会弹一条。',
129
115
  sound: '带提示音',
130
116
  soundHint: '系统通知响一声。',
131
117
  soundHint_darwin: 'macOS 系统通知的「叮」一声。',
132
118
  soundHint_win32: 'Windows 系统通知(右下角弹窗)的提示音。',
133
119
  soundHint_linux: '系统通知的提示音(要桌面环境支持)。',
134
- sectionTray: '状态栏里的小鲸鱼',
135
- tray: '显示状态栏小鲸鱼',
136
- trayHint: '改了要重启 DSH 才生效。',
137
- trayHint_linux: '显示在系统托盘里(UOS / Deepin / 麒麟 / KDE 自带;GNOME 要装 AppIndicator 扩展)。改了要重启 DSH 才生效。',
138
- titleStyle: '鲸鱼旁边显示什么',
120
+
121
+ sectionTray: '状态栏小鲸鱼',
122
+ tray: '显示小鲸鱼',
123
+ trayHint: '保存后立即生效。',
124
+ trayHint_linux: 'UOS / Deepin / 麒麟 / KDE 自带托盘;GNOME 要装 AppIndicator 扩展。保存后立即生效。',
125
+ trayHiddenNote: '状态栏图标已从它的菜单里隐藏。',
126
+ trayShowAgain: '重新显示状态栏图标',
127
+ trayShowing: '正在显示…',
128
+ trayFailedNote: '状态栏图标没能启动(没有托盘宿主或 D-Bus?),只保留通知。',
129
+ trayRetry: '重试',
130
+ titleStyle: '鲸鱼旁边显示',
139
131
  titleText: '文字',
140
- titleCount: '只有数字',
141
- titleIcon: '只有鲸鱼',
142
- titleStyleHint: '文字:待处理 1 / 运行中 2;空闲时什么都不显示。',
143
- showSpendInTitle: '旁边也带上今日花费',
144
- showSpendInTitleHint: '例如「运行中 1 · ¥1.82」。',
145
- errorHoldMinutes: '失败后「×」保持几分钟',
146
- errorHoldMinutesHint: '0 表示任务一失败就只记在菜单里,鲸鱼脸上不挂「×」。',
147
- errorHoldMinutes_linux: '失败后鲸鱼保持红色几分钟',
148
- errorHoldMinutesHint_linux: '0 表示任务一失败就只记在菜单里,鲸鱼不变红。',
149
- sectionSpend: '今天花了多少钱',
150
- spendSource: '花费怎么算',
151
- spendAuto: '自动',
152
- spendBalance: '余额扣费',
153
- spendEstimate: '按价格估算',
154
- spendSourceHint: '自动:登录了 DeepSeek 账户就看余额的真实扣费,否则按下面的价格估算。',
155
- currency: '币种',
156
- balancePollMinutes: '余额几分钟刷新一次',
157
- balancePollMinutesHint: '每轮任务结束后 5 秒也会额外刷新一次。',
158
-
159
- sectionPrice: '当前 API 价格',
160
- sectionPriceHint: '估算今日花费用的单价。能从 DSH 自带的模型目录里拿到的会自动拿,拿不到的你来填,留空也行。',
161
- currentModel: '现在用的模型',
132
+ titleCount: '数字',
133
+ titleIcon: '不显示',
134
+ titleStyleHint_text: '例:🐳 待处理 1;空闲时什么都不显示。',
135
+ titleStyleHint_count: '例:🐳 1',
136
+ titleStyleHint_icon: '只有鲸鱼,状态看它的样子。',
137
+
138
+ sectionMoney: '花费与套餐',
139
+ today: '今天',
140
+ spendNone: '还没有花费记录',
162
141
  currentModelNone: '还没看到请求,先聊一句就知道了。',
163
- listedPrice: '目录价',
164
- effectivePrice: '实际按',
165
- perMillion: '每百万 token · 输入 / 缓存命中 / 输出',
166
- noListedPrice: '目录里没有这个模型的价格,请在下面填自定义价。',
167
- catalogOff: 'DSH 自带的模型目录没找到,只有插件内置价可用。',
168
- fillCustom: '把目录价填进自定义价',
169
- priceSource: '估算用哪个价',
170
- priceAuto: '自动',
171
- priceCatalog: '只用目录价',
172
- priceCustom: '只用自定义价',
173
- priceSourceHint: '自动:cordis.patch.yml 价格表 → 自定义价 → 模型目录价 → 插件内置价。',
174
- customInput: '输入(未命中缓存)',
175
- customInputHint: '每百万 token',
176
- customCacheRead: '输入(缓存命中)',
177
- customCacheReadHint: '留空按输入价',
178
- customOutput: '输出',
179
- customOutputHint: '每百万 token',
180
- customPriceCurrency: '自定义价币种',
181
- exchangeRate: '汇率:1 美元 = ? 人民币',
182
- exchangeRateHint: '目录价是美元,显示人民币时按这个换算。',
183
-
184
- sectionPlan: '你的套餐',
185
- sectionPlanHint: '选一家平台和套餐,价格、额度会按预设填好,每一项都能改;选「自定义」就全部自己填。留空的项不显示。',
142
+ perMillion: '每百万',
143
+ noListedPrice: '目录里没有这个模型的价格,可在「高级设置」里填自定义单价。',
144
+ catalogOff: 'DSH 自带的模型目录没找到,只有插件内置价可用。可设置环境变量 DSH_NOTIFY_TRAY_PI_AI 指向 DSH 的安装目录后重启。',
145
+ myPlan: '我的套餐',
146
+ myPlanHint: '选好后价格、额度自动填好。',
186
147
  planProvider: '平台',
187
148
  providerNone: '不设置',
188
149
  providerCustom: '自定义',
189
150
  planId: '套餐',
190
151
  planCustom: '手填 / 其他套餐',
152
+ pricingPage: '价格页',
153
+ consolePage: '用量页',
154
+ autoQuota: '自动查剩余额度',
155
+ autoQuotaNone: '这家平台没有公开的额度接口,剩余额度可在下面手填。',
156
+ autoQuotaCustom: '自定义平台:在「高级设置」里填一个返回 JSON 的额度查询地址。',
157
+ planApiKeyEnv: 'API Key 引用',
158
+ planApiKeyEnvHint: '填 DSH「模型」页里保存密钥时用的名字(或同名环境变量),只在查额度时读取。',
159
+ refreshNow: '刷新',
160
+ refreshing: '刷新中…',
161
+ updatedAt: '更新',
162
+ fetchFailed: '获取失败',
163
+ noFetchYet: '还没获取过',
164
+ resetsAt: '重置',
165
+ remainingShort: '剩余',
166
+ planDetails: '手动改套餐信息',
167
+ planDetailsHint: '名称、价格、周期、余额、重置时间',
191
168
  planName: '套餐名',
192
169
  planNameHint: '留空用预设名。',
193
170
  planPrice: '价格',
@@ -201,39 +178,70 @@ window.__ModuleLoader__.load({
201
178
  planCurrency: '套餐币种',
202
179
  planQuota: '额度说明',
203
180
  planQuotaHint: '例如「每 5 小时 ≈ 1000 次」,留空用预设。',
204
- planBalance: '套餐余额',
205
- planBalanceHint: '预付费 / 充值余额,手填;能从接口拿到时留空即可。',
206
- planRemaining: '剩余额度',
181
+ planBalance: '套餐余额(手填)',
182
+ planBalanceHint: '预付费 / 充值余额;能从接口拿到时留空即可。',
183
+ planRemaining: '剩余额度(手填)',
207
184
  planRemainingHint: '例如「68%」「1200 次」,手填优先于接口。',
208
185
  planResetAt: '下次重置',
209
186
  planResetAtHint: '例如「今晚 20:00」「每周一」。',
210
- sectionQuota: '自动获取额度',
211
- quotaAvailable: '这家平台有额度 / 余额接口:',
212
- quotaUnavailable: '这家平台没有公开的额度接口,剩余额度和余额请手填。',
213
- quotaUnavailableCustom: '自定义平台:填一个返回 JSON 的额度地址,插件会尽量读出 balance / remaining 字段。',
214
- planApiKeyEnv: 'API Key 引用(环境变量名)',
215
- planApiKeyEnvHint: '填 DSH「模型」页里保存密钥时用的名字,插件只在查询额度时读取它;也可以直接设置同名环境变量。',
187
+
188
+ advanced: '高级设置',
189
+ advancedHint: '通知通道、花费算法、自定义单价、刷新间隔等,一般不用改。',
190
+ advancedChanged: '已改 {n} 项',
191
+ groupNotify: '通知',
192
+ channel: '通知从哪里弹',
193
+ channelAuto: '自动',
194
+ channelClient: '只用窗口',
195
+ channelSystem: '只用系统',
196
+ channelBoth: '都弹',
197
+ channelOff: '不弹',
198
+ channelHint: '自动:开着 DSH 窗口就由窗口弹,否则由系统弹。',
199
+ suppressWhenFocused: '正看着这个会话时不弹',
200
+ suppressWhenFocusedHint: '关掉后,哪怕你正看着它跑完也会弹一条。',
201
+ groupTray: '状态栏',
202
+ showSpendInTitle: '鲸鱼旁边带上今日花费',
203
+ showSpendInTitleHint: '例:运行中 1 · ¥1.82',
204
+ errorHoldMinutes: '失败后鲸鱼保持「×」几分钟',
205
+ errorHoldMinutesHint: '0 表示只记在菜单里。',
206
+ errorHoldMinutes_linux: '失败后鲸鱼保持红色几分钟',
207
+ groupSpend: '花费',
208
+ spendSource: '花费怎么算',
209
+ spendAuto: '自动',
210
+ spendBalance: '余额扣费',
211
+ spendEstimate: '按单价估算',
212
+ spendSourceHint: '自动:登录了 DeepSeek 账户看余额扣费,否则按单价估算。',
213
+ currency: '显示币种',
214
+ balancePollMinutes: '账户余额几分钟刷新一次',
215
+ balancePollMinutesHint: '每轮任务结束后 5 秒也会刷新一次。',
216
+ groupPrice: '单价(估算用)',
217
+ priceSource: '估算用哪个价',
218
+ priceAuto: '自动',
219
+ priceCatalog: '只用目录价',
220
+ priceCustom: '只用自定义价',
221
+ priceSourceHint: '自动:价格表 → 自定义价 → 目录价 → 内置价。',
222
+ fillCustom: '填入目录价',
223
+ customInput: '输入(未命中缓存)',
224
+ customInputHint: '每百万 token,留空不用',
225
+ customCacheRead: '输入(缓存命中)',
226
+ customCacheReadHint: '留空按输入价',
227
+ customOutput: '输出',
228
+ customOutputHint: '每百万 token',
229
+ customPriceCurrency: '自定义单价币种',
230
+ exchangeRate: '汇率:1 美元 = ? 人民币',
231
+ exchangeRateHint: '目录价是美元,显示人民币时按这个换算。',
232
+ groupQuota: '额度刷新',
233
+ planAutoQuota: '自动刷新套餐额度',
234
+ planAutoQuotaHint: '按下面的间隔定时查询;状态栏菜单里也能手动刷新。',
235
+ planAutoQuotaHint_win32: '按下面的间隔定时查询;上面的「刷新」可以手动查。',
236
+ quotaPollMinutes: '额度几分钟刷新一次',
237
+ quotaPollMinutesHint: '',
216
238
  planQuotaUrl: '额度查询地址',
217
239
  planQuotaUrlHint: '留空用预设地址。',
218
- planAutoQuota: '自动刷新',
219
- planAutoQuotaHint: '按下面的间隔定时查询,菜单里也能手动刷新。',
220
- planAutoQuotaHint_win32: '按下面的间隔定时查询,也可以点下面的「立即刷新」。',
221
- quotaPollMinutes: '几分钟刷新一次',
222
- quotaPollMinutesHint: '',
223
- refreshNow: '立即刷新',
224
- refreshing: '刷新中…',
225
- lastFetch: '上次获取',
226
- fetchFailed: '获取失败',
227
- noFetchYet: '还没获取过。',
228
- pricingPage: '价格页',
229
- consolePage: '用量页',
230
- manual: '手填',
231
- fromApi: '接口',
240
+
232
241
  srcTable: '价格表',
233
242
  srcCustom: '自定义价',
234
243
  srcCatalog: '目录价',
235
244
  srcStatic: '内置价',
236
-
237
245
  overridden: '已修改',
238
246
  reset: '恢复默认',
239
247
  readOnly: '本部署的设置为只读。',
@@ -244,77 +252,125 @@ window.__ModuleLoader__.load({
244
252
  invalidNumber: '请填数字;留空表示用默认值。',
245
253
  }
246
254
  const en = {
247
- summary: 'When the whale comes to find you, what the status bar shows, how today\'s spend is counted, and which plan you are on.',
248
- summary_win32: 'When the whale comes to find you, how today\'s spend is counted, and which plan you are on. Windows has no status bar, so the whale reaches you through notifications only.',
249
- sectionNotify: 'When to notify you',
250
- sectionNotifyHint: 'Five kinds of events, each can be switched off.',
255
+ summary: 'Notifies you when a task finishes or needs you; the status bar shows progress and spend.',
256
+ summary_win32: 'Notifies you when a task finishes or needs you, and keeps count of today\'s spend. Windows has no status bar, so the whale reaches you through notifications only.',
257
+ sectionNotify: 'Notify me',
258
+ notifyWhen: 'Send a notification when',
251
259
  notifyCompleted: 'A task finished',
252
- notifyCompletedHint: '"🐳 All done~"',
253
260
  notifyChoice: 'A choice is needed',
254
- notifyChoiceHint: '"🐳 Your call"',
255
- notifyInput: 'Some text is needed',
256
- notifyInputHint: '"🐳 Waiting for your words"',
257
- notifyApproval: 'An approval is needed',
258
- notifyApprovalHint: '"🐳 May I?"',
261
+ notifyInput: 'Text is needed',
262
+ notifyApproval: 'Approval is needed',
259
263
  notifyFailed: 'A task failed',
260
- notifyFailedHint: '"🐳 Oops…"',
261
- sectionHow: 'How to notify you',
264
+ sound: 'Play a sound',
265
+ soundHint: 'System notifications make a sound.',
266
+ soundHint_darwin: 'The macOS notification chime.',
267
+ soundHint_win32: 'The Windows notification (toast) sound.',
268
+ soundHint_linux: 'The notification sound, where the desktop supports one.',
269
+
270
+ sectionTray: 'Status-bar whale',
271
+ tray: 'Show the whale',
272
+ trayHint: 'Takes effect as soon as you save.',
273
+ trayHint_linux: 'Built into UOS / Deepin / Kylin / KDE; GNOME needs the AppIndicator extension. Takes effect as soon as you save.',
274
+ trayHiddenNote: 'The status-bar icon was hidden from its own menu.',
275
+ trayShowAgain: 'Show the status-bar icon again',
276
+ trayShowing: 'Showing…',
277
+ trayFailedNote: 'The status-bar icon could not start (no tray host or D-Bus?); notifications still work.',
278
+ trayRetry: 'Retry',
279
+ titleStyle: 'Beside the whale',
280
+ titleText: 'Words',
281
+ titleCount: 'Count',
282
+ titleIcon: 'Nothing',
283
+ titleStyleHint_text: 'e.g. 🐳 待处理 1; nothing while idle.',
284
+ titleStyleHint_count: 'e.g. 🐳 1',
285
+ titleStyleHint_icon: 'Just the whale; its pose tells the state.',
286
+
287
+ sectionMoney: 'Spend & plan',
288
+ today: 'Today',
289
+ spendNone: 'No spend recorded yet',
290
+ currentModelNone: 'No request seen yet — send one message and it shows up here.',
291
+ perMillion: 'per million',
292
+ noListedPrice: 'No catalog price for this model; set a custom price under Advanced.',
293
+ catalogOff: 'DSH\'s bundled model catalog was not found; only the plugin\'s built-in prices apply. Point the DSH_NOTIFY_TRAY_PI_AI environment variable at the DSH install directory and restart.',
294
+ myPlan: 'My plan',
295
+ myPlanHint: 'Price and quota are filled in from the preset.',
296
+ planProvider: 'Provider',
297
+ providerNone: 'None',
298
+ providerCustom: 'Custom',
299
+ planId: 'Plan',
300
+ planCustom: 'Other / manual',
301
+ pricingPage: 'Pricing page',
302
+ consolePage: 'Usage page',
303
+ autoQuota: 'Fetch remaining quota',
304
+ autoQuotaNone: 'This provider has no public quota endpoint; type the remaining quota below.',
305
+ autoQuotaCustom: 'Custom provider: set a JSON quota URL under Advanced.',
306
+ planApiKeyEnv: 'API key reference',
307
+ planApiKeyEnvHint: 'The name the key was saved under on DSH\'s Models page (or a same-named environment variable); read only to query quota.',
308
+ refreshNow: 'Refresh',
309
+ refreshing: 'Refreshing…',
310
+ updatedAt: 'updated',
311
+ fetchFailed: 'Fetch failed',
312
+ noFetchYet: 'Not fetched yet',
313
+ resetsAt: 'resets',
314
+ remainingShort: 'Remaining',
315
+ planDetails: 'Edit plan details',
316
+ planDetailsHint: 'name, price, period, balance, reset time',
317
+ planName: 'Plan name',
318
+ planNameHint: 'Blank: preset name.',
319
+ planPrice: 'Price',
320
+ planPriceHint: 'Blank: preset price; 0 means pay-as-you-go.',
321
+ planPeriod: 'Period',
322
+ periodMonth: 'Monthly',
323
+ periodYear: 'Yearly',
324
+ periodWeek: 'Weekly',
325
+ periodOnce: 'One-off',
326
+ periodFree: 'Pay-as-you-go',
327
+ planCurrency: 'Plan currency',
328
+ planQuota: 'Quota description',
329
+ planQuotaHint: 'e.g. "≈1000 requests per 5 h"; blank: preset.',
330
+ planBalance: 'Plan balance (manual)',
331
+ planBalanceHint: 'Prepaid / top-up balance; leave blank when the API supplies it.',
332
+ planRemaining: 'Remaining quota (manual)',
333
+ planRemainingHint: 'e.g. "68%" or "1200 requests"; a typed value wins over the API.',
334
+ planResetAt: 'Next reset',
335
+ planResetAtHint: 'e.g. "20:00 tonight", "Mondays".',
336
+
337
+ advanced: 'Advanced',
338
+ advancedHint: 'Notification channel, spend method, custom prices, refresh intervals — rarely needed.',
339
+ advancedChanged: '{n} changed',
340
+ groupNotify: 'Notifications',
262
341
  channel: 'Notification channel',
263
342
  channelAuto: 'Auto',
264
343
  channelClient: 'Window only',
265
344
  channelSystem: 'System only',
266
345
  channelBoth: 'Both',
267
346
  channelOff: 'Off',
268
- channelHint: 'Auto: the DSH window notifies while it is open (with the DSH icon); the OS does when no window is around.',
347
+ channelHint: 'Auto: the DSH window notifies while it is open; the OS does otherwise.',
269
348
  suppressWhenFocused: 'Stay quiet while I am looking at that session',
270
349
  suppressWhenFocusedHint: 'Off: notify even when you watch it finish.',
271
- sound: 'Play a sound',
272
- soundHint: 'System notifications make a sound.',
273
- soundHint_darwin: 'The macOS notification chime.',
274
- soundHint_win32: 'The Windows notification (toast) sound.',
275
- soundHint_linux: 'The notification sound, where the desktop supports one.',
276
- sectionTray: 'The whale in the status bar',
277
- tray: 'Show the status-bar whale',
278
- trayHint: 'Takes effect after restarting DSH.',
279
- trayHint_linux: 'Shown in the system tray (built into UOS / Deepin / Kylin / KDE; GNOME needs the AppIndicator extension). Takes effect after restarting DSH.',
280
- titleStyle: 'Text beside the whale',
281
- titleText: 'Words',
282
- titleCount: 'Count only',
283
- titleIcon: 'Whale only',
284
- titleStyleHint: 'Words: 待处理 1 / 运行中 2; nothing while idle.',
285
- showSpendInTitle: 'Append today\'s spend',
286
- showSpendInTitleHint: 'e.g. "运行中 1 · ¥1.82".',
350
+ groupTray: 'Status bar',
351
+ showSpendInTitle: 'Add today\'s spend beside the whale',
352
+ showSpendInTitleHint: 'e.g. 运行中 1 · ¥1.82',
287
353
  errorHoldMinutes: 'Minutes the "×" stays after a failure',
288
354
  errorHoldMinutesHint: '0: failures are only listed in the menu.',
289
355
  errorHoldMinutes_linux: 'Minutes the whale stays red after a failure',
290
- errorHoldMinutesHint_linux: '0: failures are only listed in the menu; the whale never turns red.',
291
- sectionSpend: 'Today\'s spend',
356
+ groupSpend: 'Spend',
292
357
  spendSource: 'How spend is counted',
293
358
  spendAuto: 'Auto',
294
359
  spendBalance: 'Balance drops',
295
360
  spendEstimate: 'Price estimate',
296
- spendSourceHint: 'Auto: real balance drops when signed in to DeepSeek, otherwise the prices below.',
361
+ spendSourceHint: 'Auto: real balance drops when signed in to DeepSeek, otherwise unit prices.',
297
362
  currency: 'Currency',
298
363
  balancePollMinutes: 'Balance refresh interval (minutes)',
299
364
  balancePollMinutesHint: 'Also refreshed 5 s after every finished turn.',
300
-
301
- sectionPrice: 'Current API price',
302
- sectionPriceHint: 'Unit prices behind the estimate. Whatever DSH\'s bundled model catalog knows is picked up automatically; fill in the rest yourself, or leave it blank.',
303
- currentModel: 'Model in use',
304
- currentModelNone: 'No request seen yet — send one message and it shows up here.',
305
- listedPrice: 'Listed',
306
- effectivePrice: 'Effective',
307
- perMillion: 'per million tokens · input / cache hit / output',
308
- noListedPrice: 'No catalog price for this model; enter a custom price below.',
309
- catalogOff: 'DSH\'s bundled model catalog was not found; only the plugin\'s built-in prices apply.',
310
- fillCustom: 'Copy listed price into custom price',
365
+ groupPrice: 'Unit prices (for estimates)',
311
366
  priceSource: 'Which price to use',
312
367
  priceAuto: 'Auto',
313
368
  priceCatalog: 'Catalog only',
314
369
  priceCustom: 'Custom only',
315
- priceSourceHint: 'Auto: cordis.patch.yml table → custom price → model catalog → built-in prices.',
370
+ priceSourceHint: 'Auto: price table → custom price → catalog → built-in prices.',
371
+ fillCustom: 'Copy catalog price',
316
372
  customInput: 'Input (cache miss)',
317
- customInputHint: 'per million tokens',
373
+ customInputHint: 'per million tokens; blank: unused',
318
374
  customCacheRead: 'Input (cache hit)',
319
375
  customCacheReadHint: 'Blank: same as input',
320
376
  customOutput: 'Output',
@@ -322,60 +378,19 @@ window.__ModuleLoader__.load({
322
378
  customPriceCurrency: 'Custom price currency',
323
379
  exchangeRate: 'Rate: 1 USD = ? CNY',
324
380
  exchangeRateHint: 'Catalog prices are USD; used when displaying CNY.',
325
-
326
- sectionPlan: 'Your plan',
327
- sectionPlanHint: 'Pick a provider and a plan: price and quota are prefilled from the preset and every field stays editable; "Custom" leaves everything to you. Blank fields are not shown.',
328
- planProvider: 'Provider',
329
- providerNone: 'None',
330
- providerCustom: 'Custom',
331
- planId: 'Plan',
332
- planCustom: 'Other / manual',
333
- planName: 'Plan name',
334
- planNameHint: 'Blank: preset name.',
335
- planPrice: 'Price',
336
- planPriceHint: 'Blank: preset price; 0 means pay-as-you-go.',
337
- planPeriod: 'Period',
338
- periodMonth: 'Monthly',
339
- periodYear: 'Yearly',
340
- periodWeek: 'Weekly',
341
- periodOnce: 'One-off',
342
- periodFree: 'Pay-as-you-go',
343
- planCurrency: 'Plan currency',
344
- planQuota: 'Quota description',
345
- planQuotaHint: 'e.g. "≈1000 requests per 5 h"; blank: preset.',
346
- planBalance: 'Plan balance',
347
- planBalanceHint: 'Prepaid / top-up balance, typed by hand; leave blank when the API supplies it.',
348
- planRemaining: 'Remaining quota',
349
- planRemainingHint: 'e.g. "68%" or "1200 requests"; a typed value wins over the API.',
350
- planResetAt: 'Next reset',
351
- planResetAtHint: 'e.g. "20:00 tonight", "Mondays".',
352
- sectionQuota: 'Fetch quota automatically',
353
- quotaAvailable: 'This provider exposes a quota / balance endpoint:',
354
- quotaUnavailable: 'This provider has no public quota endpoint; type the remaining quota and balance yourself.',
355
- quotaUnavailableCustom: 'Custom provider: give a JSON quota URL and the plugin reads balance / remaining-looking fields.',
356
- planApiKeyEnv: 'API key reference (environment variable name)',
357
- planApiKeyEnvHint: 'The name used when the key was saved on DSH\'s Models page; the plugin reads it only to query quota. A same-named environment variable works too.',
358
- planQuotaUrl: 'Quota URL',
359
- planQuotaUrlHint: 'Blank: preset URL.',
360
- planAutoQuota: 'Refresh automatically',
381
+ groupQuota: 'Quota refresh',
382
+ planAutoQuota: 'Refresh plan quota automatically',
361
383
  planAutoQuotaHint: 'Polled at the interval below; the tray menu can refresh by hand too.',
362
- planAutoQuotaHint_win32: 'Polled at the interval below; "Refresh now" below fetches by hand.',
363
- quotaPollMinutes: 'Refresh interval (minutes)',
384
+ planAutoQuotaHint_win32: 'Polled at the interval below; "Refresh" above fetches by hand.',
385
+ quotaPollMinutes: 'Quota refresh interval (minutes)',
364
386
  quotaPollMinutesHint: '',
365
- refreshNow: 'Refresh now',
366
- refreshing: 'Refreshing…',
367
- lastFetch: 'Last fetch',
368
- fetchFailed: 'Fetch failed',
369
- noFetchYet: 'Not fetched yet.',
370
- pricingPage: 'Pricing page',
371
- consolePage: 'Usage page',
372
- manual: 'manual',
373
- fromApi: 'API',
387
+ planQuotaUrl: 'Quota URL',
388
+ planQuotaUrlHint: 'Blank: preset URL.',
389
+
374
390
  srcTable: 'price table',
375
391
  srcCustom: 'custom',
376
392
  srcCatalog: 'catalog',
377
393
  srcStatic: 'built-in',
378
-
379
394
  overridden: 'Changed',
380
395
  reset: 'Reset to default',
381
396
  readOnly: 'This deployment stores settings read-only.',
@@ -408,6 +423,11 @@ window.__ModuleLoader__.load({
408
423
  const NUMBERS = ['errorHoldMinutes', 'balancePollMinutes', 'customInput', 'customCacheRead', 'customOutput', 'exchangeRate', 'planPrice', 'planBalance', 'quotaPollMinutes']
409
424
  const TEXTS = ['planProvider', 'planId', 'planName', 'planQuota', 'planRemaining', 'planResetAt', 'planApiKeyEnv', 'planQuotaUrl']
410
425
  const FIELDS = [...BOOLS, ...CHOICES, ...NUMBERS, ...TEXTS]
426
+ /** The five "notify me when" switches, shown as one row of checkboxes. */
427
+ const NOTIFY_FIELDS = ['notifyCompleted', 'notifyChoice', 'notifyInput', 'notifyApproval', 'notifyFailed']
428
+ /** Fields behind the "Advanced" fold (counted for its "n changed" tag). */
429
+ const ADVANCED_FIELDS = ['channel', 'suppressWhenFocused', 'showSpendInTitle', 'errorHoldMinutes', 'spendSource', 'currency', 'balancePollMinutes', 'priceSource', 'customInput', 'customCacheRead', 'customOutput', 'customPriceCurrency', 'exchangeRate', 'planAutoQuota', 'quotaPollMinutes', 'planQuotaUrl']
430
+ const TRAY_FIELDS = ['showSpendInTitle', 'errorHoldMinutes']
411
431
  /** Plan fields a preset fills in; switching provider clears them. */
412
432
  const PRESET_FIELDS = ['planId', 'planName', 'planPrice', 'planCurrency', 'planPeriod', 'planQuota', 'planQuotaUrl']
413
433
 
@@ -437,6 +457,12 @@ window.__ModuleLoader__.load({
437
457
 
438
458
  // ---- live data: catalog once, host state while the page is open ------------------
439
459
  const live = { catalog: undefined, state: undefined, listeners: new Set() }
460
+ /** Which folds are open; kept while the page is closed and reopened. */
461
+ const open = { plan: false, advanced: false }
462
+ function useOpen(key) {
463
+ const [, bump] = React.useState(0)
464
+ return [open[key], () => { open[key] = !open[key]; bump(n => n + 1) }]
465
+ }
440
466
  function publishLive() { for (const fn of live.listeners) fn() }
441
467
  function fetchJson(url, init) {
442
468
  return fetch(url, { headers: { accept: 'application/json' }, cache: 'no-store', ...init }).then(res => (res.ok ? res.json() : undefined))
@@ -450,7 +476,7 @@ window.__ModuleLoader__.load({
450
476
  }
451
477
  // Test seam: lets a test drive the loaders without React effects.
452
478
  const currentPlatform = () => normalizePlatform(live.state && live.state.platform) || guessPlatform()
453
- exports.__settingsLive = { live, loadCatalog, loadState, currentPlatform }
479
+ exports.__settingsLive = { live, open, loadCatalog, loadState, currentPlatform }
454
480
  function useLive() {
455
481
  const [, bump] = React.useState(0)
456
482
  React.useEffect(() => {
@@ -468,7 +494,6 @@ window.__ModuleLoader__.load({
468
494
  const S = {
469
495
  section: { marginTop: 28 },
470
496
  sectionTitle: { fontSize: 15, fontWeight: 600, margin: '0 0 4px' },
471
- sectionHint: { margin: '0 0 12px', opacity: 0.65, fontSize: 13 },
472
497
  row: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16, padding: '10px 0', borderBottom: '1px solid color-mix(in srgb, currentColor 10%, transparent)' },
473
498
  rowText: { minWidth: 0 },
474
499
  label: { fontSize: 14 },
@@ -482,12 +507,23 @@ window.__ModuleLoader__.load({
482
507
  mono: { fontFamily: 'var(--ds-font-family-code, ui-monospace, monospace)', fontSize: 13 },
483
508
  muted: { opacity: 0.65 },
484
509
  error: { color: 'var(--dsw-alias-state-error-primary, #d33)' },
485
- select: { boxSizing: 'border-box', border: '.5px solid var(--dsw-alias-border-l4, color-mix(in srgb, currentColor 25%, transparent))', borderRadius: 'var(--dsw-radius-md, 6px)', width: '100%', maxWidth: 320, height: 32, font: 'inherit', background: 'var(--dsw-alias-bg-layer-1, transparent)', color: 'var(--dsw-alias-label-primary, inherit)', padding: '0 10px', fontSize: 14, lineHeight: '22px', cursor: 'pointer' },
486
- fieldLabel: { color: 'var(--dsw-alias-label-secondary, inherit)', fontSize: 12, fontWeight: 500, lineHeight: '18px', display: 'block', marginBottom: 6 },
487
- linkRow: { display: 'flex', gap: 14, marginTop: 8, fontSize: 12 },
510
+ select: { boxSizing: 'border-box', border: '.5px solid var(--dsw-alias-border-l4, color-mix(in srgb, currentColor 25%, transparent))', borderRadius: 'var(--dsw-radius-md, 6px)', width: 180, maxWidth: '100%', height: 32, font: 'inherit', background: 'var(--dsw-alias-bg-layer-1, transparent)', color: 'var(--dsw-alias-label-primary, inherit)', padding: '0 10px', fontSize: 14, lineHeight: '22px', cursor: 'pointer' },
488
511
  link: { color: 'inherit', textDecoration: 'underline', opacity: 0.75 },
489
512
  button: { font: 'inherit', fontSize: 12, padding: '4px 10px', borderRadius: 6, border: '.5px solid var(--dsw-alias-border-l4, color-mix(in srgb, currentColor 25%, transparent))', background: 'transparent', color: 'inherit', cursor: 'pointer' },
490
- lines: { margin: '6px 0 0', paddingLeft: 18 },
513
+ lines: { margin: '6px 0 0', paddingLeft: 18, fontSize: 12, opacity: 0.75 },
514
+ checks: { display: 'flex', flexWrap: 'wrap', gap: '8px 18px', marginTop: 10 },
515
+ check: { display: 'inline-flex', alignItems: 'center', gap: 6, fontSize: 13 },
516
+ spendCard: { display: 'flex', alignItems: 'center', gap: 16, border: '1px solid var(--dsw-alias-border-l3, color-mix(in srgb, currentColor 12%, transparent))', borderRadius: 'var(--dsw-radius-lg, 10px)', padding: '12px 14px', margin: '4px 0' },
517
+ spendValue: { fontSize: 22, fontWeight: 600, lineHeight: '28px' },
518
+ keyRow: { display: 'flex', alignItems: 'flex-start', gap: 8, flexWrap: 'wrap' },
519
+ disclosure: { display: 'flex', alignItems: 'center', gap: 6, width: '100%', font: 'inherit', fontSize: 13, color: 'inherit', background: 'none', border: 0, padding: '10px 0', cursor: 'pointer', textAlign: 'left' },
520
+ disclosureBig: { fontSize: 15, fontWeight: 600, padding: '14px 0' },
521
+ disclosureHint: { fontSize: 12, fontWeight: 400, opacity: 0.6, minWidth: 0 },
522
+ chevron: { width: 14, flex: 'none', opacity: 0.6 },
523
+ disclosureBody: { paddingLeft: 20, paddingBottom: 8 },
524
+ groupTitle: { fontSize: 12, fontWeight: 600, opacity: 0.65, margin: '16px 0 2px' },
525
+ advanced: { marginTop: 28, borderTop: '1px solid color-mix(in srgb, currentColor 10%, transparent)' },
526
+ fieldGap: { marginTop: 12 },
491
527
  }
492
528
 
493
529
  function Overridden({ t, field, disabled, onReset }) {
@@ -498,10 +534,11 @@ window.__ModuleLoader__.load({
498
534
  }
499
535
 
500
536
  function ToggleRow({ t, name, field, disabled, edit, resetField }) {
537
+ const hint = t(`${name}Hint`)
501
538
  return h('div', { style: S.row },
502
539
  h('div', { style: S.rowText },
503
540
  h('div', { style: S.label }, t(name), h(Overridden, { t, field, disabled, onReset: () => resetField(name) })),
504
- h('p', { style: S.hint }, t(`${name}Hint`))),
541
+ hint ? h('p', { style: S.hint }, hint) : null),
505
542
  h('div', { style: S.control },
506
543
  h(ui.Switch, { checked: field.text === 'on', disabled, label: t(name), onChange: next => edit(name, next ? 'on' : 'off') })))
507
544
  }
@@ -522,6 +559,19 @@ window.__ModuleLoader__.load({
522
559
  })))
523
560
  }
524
561
 
562
+ /** Several on/off fields as one row of checkboxes (a Switch per field where the host has no Checkbox). */
563
+ function CheckRow({ t, label, names, f, disabled, edit, resetField }) {
564
+ const Box = ui.Checkbox || ui.Switch
565
+ const changed = names.filter(name => f[name].overridden)
566
+ return h('div', { style: { ...S.row, display: 'block' } },
567
+ h('div', { style: S.label }, t(label), changed.length ? h('span', { style: S.badges },
568
+ h(ui.Tag, { tone: 'neutral' }, t('overridden')),
569
+ h('button', { type: 'button', style: S.reset, disabled, onClick: () => changed.forEach(resetField) }, t('reset'))) : null),
570
+ h('div', { style: S.checks }, names.map(name => h('span', { key: name, style: S.check },
571
+ h(Box, { checked: f[name].text === 'on', disabled, label: t(name), onChange: next => edit(name, next ? 'on' : 'off') }),
572
+ ui.Checkbox ? null : h('span', null, t(name))))))
573
+ }
574
+
525
575
  function ValueField({ t, name, field, disabled, edit, resetField, numeric, placeholder, hint }) {
526
576
  return h(ui.SettingsValueField, {
527
577
  id: `notify-tray-${name}`,
@@ -543,26 +593,40 @@ window.__ModuleLoader__.load({
543
593
  const NumberField = props => h(ValueField, { numeric: true, ...props })
544
594
  const TextField = props => h(ValueField, { ...props, numeric: false })
545
595
 
546
- function SelectField({ t, name, field, options, disabled, onChange, resetField }) {
547
- return h('div', { style: { marginTop: 12 } },
548
- h('label', { style: S.fieldLabel, htmlFor: `notify-tray-${name}` }, t(name), h(Overridden, { t, field, disabled, onReset: () => resetField(name) })),
549
- h('select', {
550
- id: `notify-tray-${name}`,
551
- style: S.select,
552
- value: field.text,
553
- disabled,
554
- 'aria-label': t(name),
555
- onChange: event => onChange(event.target.value),
556
- }, options.map(([value, label]) => h('option', { key: value, value }, label))))
596
+ /** A bare dropdown (its row carries the label). */
597
+ function Select({ t, name, field, options, disabled, onChange }) {
598
+ return h('select', {
599
+ id: `notify-tray-${name}`,
600
+ style: S.select,
601
+ value: field.text,
602
+ disabled,
603
+ 'aria-label': t(name),
604
+ onChange: event => onChange(event.target.value),
605
+ }, options.map(([value, label]) => h('option', { key: value, value }, label)))
557
606
  }
558
607
 
559
- function Section({ title, hint, children }) {
608
+ function Section({ title, children }) {
560
609
  return h('section', { style: S.section },
561
610
  h('h4', { style: S.sectionTitle }, title),
562
- hint ? h('p', { style: S.sectionHint }, hint) : null,
563
611
  children)
564
612
  }
565
613
 
614
+ /** A collapsible block: a ▸ / ▾ button, its content only while open. */
615
+ function Disclosure({ id, title, hint, badge, big, children }) {
616
+ const [isOpen, toggle] = useOpen(id)
617
+ return h('div', null,
618
+ h('button', { type: 'button', style: big ? { ...S.disclosure, ...S.disclosureBig } : S.disclosure, 'aria-expanded': isOpen, onClick: toggle },
619
+ h('span', { 'aria-hidden': true, style: S.chevron }, isOpen ? '▾' : '▸'),
620
+ h('span', null, title),
621
+ badge ? h(ui.Tag, { tone: 'neutral' }, badge) : null,
622
+ hint ? h('span', { style: S.disclosureHint }, hint) : null),
623
+ isOpen ? h('div', { style: S.disclosureBody }, children) : null)
624
+ }
625
+
626
+ function Group({ title, children }) {
627
+ return h('div', null, h('div', { style: S.groupTitle }, title), children)
628
+ }
629
+
566
630
  const SYM = { CNY: '¥', USD: '$' }
567
631
  const fmt = (n, currency) => (typeof n === 'number' ? `${SYM[currency] ?? ''}${Number.isInteger(n) ? n : (n < 1 ? n.toFixed(4).replace(/0+$/u, '').replace(/\.$/u, '') : n.toFixed(2))}` : '—')
568
632
  const priceLine = (p, currency) => `${fmt(p.input, currency)} / ${fmt(p.cacheRead, currency)} / ${fmt(p.output, currency)}`
@@ -572,63 +636,76 @@ window.__ModuleLoader__.load({
572
636
  return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
573
637
  }
574
638
 
575
- /** The read-only "model in use" card: listed price, effective price, and a copy button. */
576
- function CurrentModelCard({ t, state, disabled, edit }) {
577
- const pricing = state?.pricing
578
- const rows = [h('div', { key: 'title', style: S.cardTitle }, t('currentModel'))]
639
+ /** Read-only: today's spend, the model in use and the unit price behind the estimate. */
640
+ function SpendCard({ t, state }) {
641
+ const spend = state && state.spend
642
+ const currency = (state && state.usage && state.usage.currency) || 'CNY'
643
+ const pricing = state && state.pricing
644
+ const detail = []
579
645
  if (!pricing) {
580
- rows.push(h('div', { key: 'none', style: S.muted }, t('currentModelNone')))
646
+ detail.push(h('div', { key: 'none', style: S.muted }, t('currentModelNone')))
581
647
  } else {
582
- rows.push(h('div', { key: 'route', style: S.mono }, `${pricing.provider ? `${pricing.provider} / ` : ''}${pricing.model}${pricing.name && pricing.name !== pricing.model ? ` · ${pricing.name}` : ''}`))
583
- if (pricing.listed) {
584
- rows.push(h('div', { key: 'listed' }, `${t('listedPrice')}:`, h('span', { style: S.mono }, priceLine(pricing.listed, pricing.listed.currency)), h('span', { style: S.muted }, ` ${t('perMillion')}`)))
585
- } else {
586
- rows.push(h('div', { key: 'nolisted', style: S.muted }, t('noListedPrice')))
587
- }
588
- if (pricing.effective) {
589
- rows.push(h('div', { key: 'eff' }, `${t('effectivePrice')}:`, h('span', { style: S.mono }, priceLine(pricing.effective, pricing.effective.currency)), h('span', { style: S.muted }, `(${SOURCE_KEY[pricing.effective.source] ? t(SOURCE_KEY[pricing.effective.source]) : pricing.effective.source})`)))
590
- }
591
- if (pricing.listed) {
592
- rows.push(h('div', { key: 'copy', style: { marginTop: 8 } }, h('button', {
593
- type: 'button',
594
- style: S.button,
595
- disabled,
596
- onClick: () => {
597
- edit('customInput', String(pricing.listed.input))
598
- edit('customCacheRead', String(pricing.listed.cacheRead))
599
- edit('customOutput', String(pricing.listed.output))
600
- edit('customPriceCurrency', pricing.listed.currency)
601
- },
602
- }, t('fillCustom'))))
648
+ detail.push(h('div', { key: 'route', style: S.mono }, `${pricing.provider ? `${pricing.provider} / ` : ''}${pricing.model}`))
649
+ const price = pricing.effective
650
+ if (price) {
651
+ const source = SOURCE_KEY[price.source] ? t(SOURCE_KEY[price.source]) : price.source
652
+ detail.push(h('div', { key: 'price', style: S.muted }, `${priceLine(price, price.currency)} ${t('perMillion')} · ${source}`))
653
+ } else if (!pricing.listed) {
654
+ detail.push(h('div', { key: 'nolisted', style: S.muted }, t('noListedPrice')))
603
655
  }
604
656
  }
605
- if (state && state.catalogLoaded === false) rows.push(h('div', { key: 'cat', style: { ...S.muted, marginTop: 6 } }, t('catalogOff')))
606
- return h('div', { style: S.card }, rows)
607
- }
608
-
609
- /** Live quota panel: what the host last fetched for the configured plan. */
610
- function QuotaStatus({ t, plan, disabled, busy, onRefresh }) {
611
- const rows = []
612
- if (!plan) return null
613
- if (plan.fetch) {
614
- rows.push(h('div', { key: 'at', style: plan.fetch.ok ? undefined : S.error },
615
- plan.fetch.ok ? `${t('lastFetch')} ${clock(plan.fetch.at)}` : `${t('fetchFailed')}(${clock(plan.fetch.at)}):${plan.fetch.error}`))
616
- if (plan.fetch.ok && plan.lines.length) rows.push(h('ul', { key: 'lines', style: S.lines }, plan.lines.map((line, i) => h('li', { key: i }, line))))
617
- } else {
618
- rows.push(h('div', { key: 'none', style: S.muted }, t('noFetchYet')))
657
+ if (spend && spend.label) detail.push(h('div', { key: 'how', style: S.muted }, spend.label))
658
+ return h('div', null,
659
+ h('div', { style: S.spendCard },
660
+ h('div', { style: { flex: '1 1 0', minWidth: 0 } },
661
+ h('div', { style: S.cardTitle }, t('today')),
662
+ spend ? h('div', { style: S.spendValue }, `${SYM[currency] ?? ''}${spend.value.toFixed(2)}`) : h('div', { style: S.muted }, t('spendNone'))),
663
+ h('div', { style: { flex: '2 1 0', minWidth: 0, fontSize: 12, lineHeight: '19px' } }, detail)),
664
+ state && state.catalogLoaded === false ? h('p', { style: S.hint }, t('catalogOff')) : null)
665
+ }
666
+
667
+ /** One line on the last quota fetch, plus the fetched lines. */
668
+ function QuotaStatus({ t, plan }) {
669
+ if (!plan || !plan.fetch) return h('p', { style: S.hint }, t('noFetchYet'))
670
+ if (!plan.fetch.ok) return h('p', { style: { ...S.hint, ...S.error } }, `${t('fetchFailed')}(${clock(plan.fetch.at)}):${plan.fetch.error}`)
671
+ const bits = []
672
+ if (plan.remaining !== undefined) bits.push(`${t('remainingShort')} ${plan.remaining}`)
673
+ if (plan.resetAt) bits.push(`${String(plan.resetAt)} ${t('resetsAt')}`)
674
+ bits.push(`${clock(plan.fetch.at)} ${t('updatedAt')}`)
675
+ return h('div', null,
676
+ h('p', { style: S.hint }, bits.join(' · ')),
677
+ plan.lines && plan.lines.length ? h('ul', { style: S.lines }, plan.lines.slice(0, 4).map((line, i) => h('li', { key: i }, line))) : null)
678
+ }
679
+
680
+ /** Brings back a status-bar icon hidden from its own menu (or one that failed to start). */
681
+ function TrayStatus({ t, state }) {
682
+ const tray = state && state.tray
683
+ const [busy, setBusy] = React.useState(false)
684
+ if (!tray || !tray.supported || !tray.enabled || tray.shown || !(tray.hidden || tray.failed)) return null
685
+ const show = () => {
686
+ setBusy(true)
687
+ fetchJson(TRAY_ROUTE, { method: 'POST' }).then(() => loadState()).catch(() => {}).then(() => setBusy(false))
619
688
  }
620
- if (plan.apiKeyEnv) rows.push(h('div', { key: 'btn', style: { marginTop: 8 } }, h('button', { type: 'button', style: S.button, disabled: disabled || busy, onClick: onRefresh }, busy ? t('refreshing') : t('refreshNow'))))
621
- return h('div', { style: S.card }, rows)
689
+ return h('div', { style: S.card },
690
+ h('div', { style: tray.failed && !tray.hidden ? S.error : S.muted }, t(tray.hidden ? 'trayHiddenNote' : 'trayFailedNote')),
691
+ h('div', { style: { marginTop: 8 } }, h('button', { type: 'button', style: S.button, disabled: busy, onClick: show }, busy ? t('trayShowing') : t(tray.hidden ? 'trayShowAgain' : 'trayRetry'))))
622
692
  }
623
693
 
624
- function PlanSection({ t, f, common, state, catalog }) {
625
- const { edit, resetField, disabled } = common
626
- const providers = catalog?.providers ?? []
694
+ /** What the plan section and the advanced section both need to know about the chosen plan. */
695
+ function planContext(f, state, catalog) {
696
+ const providers = (catalog && catalog.providers) || []
627
697
  const providerId = f.planProvider.text || 'none'
628
698
  const provider = providers.find(p => p.id === providerId)
629
- const plans = provider?.plans ?? []
699
+ const plans = (provider && provider.plans) || []
630
700
  const preset = plans.find(p => p.id === f.planId.text)
631
- const livePlan = state?.plan
701
+ const livePlan = state && state.plan
702
+ const quotaSpec = livePlan && livePlan.canFetch ? { kind: livePlan.fetchKind, url: livePlan.fetchUrl } : ((preset && preset.quotaApi) || (provider && provider.quota))
703
+ return { providers, providerId, provider, plans, preset, livePlan, quotaSpec }
704
+ }
705
+
706
+ function PlanSection({ t, f, common, state, catalog }) {
707
+ const { edit, resetField, disabled } = common
708
+ const { providers, providerId, provider, plans, preset, livePlan, quotaSpec } = planContext(f, state, catalog)
632
709
  const [busy, setBusy] = React.useState(false)
633
710
  const refresh = () => {
634
711
  setBusy(true)
@@ -659,47 +736,95 @@ window.__ModuleLoader__.load({
659
736
  }
660
737
  const providerOptions = [['none', t('providerNone')], ...providers.map(p => [p.id, p.name]), ['custom', t('providerCustom')]]
661
738
  const planOptions = [...plans.map(p => [p.id, `${p.name}${p.price ? ` · ${SYM[p.currency] ?? ''}${p.price}` : ''}`]), ['', t('planCustom')]]
662
- const quotaSpec = livePlan?.canFetch ? { kind: livePlan.fetchKind, url: livePlan.fetchUrl } : (preset?.quotaApi ?? provider?.quota)
663
739
  const links = provider ? [['pricing', provider.pricingUrl], ['console', provider.consoleUrl]].filter(([, url]) => url) : []
740
+ const planChanged = f.planProvider.overridden || f.planId.overridden
664
741
 
665
- const children = [
666
- h(SelectField, { key: 'provider', t, name: 'planProvider', field: f.planProvider, options: providerOptions, disabled, onChange: chooseProvider, resetField }),
667
- ]
742
+ const children = [h('div', { key: 'pick', style: { ...S.row, flexWrap: 'wrap' } },
743
+ h('div', { style: S.rowText },
744
+ h('div', { style: S.label }, t('myPlan'), planChanged ? h('span', { style: S.badges }, h(ui.Tag, { tone: 'neutral' }, t('overridden'))) : null),
745
+ links.length
746
+ ? h('p', { style: S.hint }, links.map(([key, url], i) => h(React.Fragment || 'span', { key }, i ? ' · ' : '', h('a', { href: url, target: '_blank', rel: 'noreferrer', style: S.link }, `${t(`${key}Page`)} ↗`))))
747
+ : h('p', { style: S.hint }, t('myPlanHint'))),
748
+ h('div', { style: { ...S.control, display: 'flex', gap: 8, flexWrap: 'wrap' } },
749
+ h(Select, { t, name: 'planProvider', field: f.planProvider, options: providerOptions, disabled, onChange: chooseProvider }),
750
+ providerId !== 'none' && plans.length ? h(Select, { t, name: 'planId', field: f.planId, options: planOptions, disabled, onChange: choosePlan }) : null))]
668
751
  if (providerId === 'none') return children
669
- if (plans.length) children.push(h(SelectField, { key: 'plan', t, name: 'planId', field: f.planId, options: planOptions, disabled, onChange: choosePlan, resetField }))
670
- if (links.length) {
671
- children.push(h('div', { key: 'links', style: S.linkRow }, links.map(([key, url]) => h('a', { key, href: url, target: '_blank', rel: 'noreferrer', style: S.link }, `${t(`${key}Page`)} ↗`))))
672
- }
673
- children.push(h('div', { key: 'grid', style: S.grid },
674
- h(TextField, { name: 'planName', field: f.planName, placeholder: preset?.name ?? '', ...common }),
675
- h(NumberField, { name: 'planPrice', field: f.planPrice, placeholder: preset ? String(preset.price) : '', ...common }),
676
- h(TextField, { name: 'planQuota', field: f.planQuota, placeholder: preset?.quotaText ?? '', ...common })))
677
- children.push(h(ChoiceRow, { key: 'period', name: 'planPeriod', field: f.planPeriod, ...common, options: [['month', 'periodMonth'], ['year', 'periodYear'], ['week', 'periodWeek'], ['once', 'periodOnce'], ['free', 'periodFree']] }))
678
- children.push(h(ChoiceRow, { key: 'cur', name: 'planCurrency', field: f.planCurrency, ...common, options: [['CNY', 'CNY'], ['USD', 'USD']] }))
679
- children.push(h('div', { key: 'grid2', style: S.grid },
680
- h(NumberField, { name: 'planBalance', field: f.planBalance, placeholder: livePlan?.balance !== undefined && livePlan.remainingSource !== 'manual' ? `${t('fromApi')} ${fmt(livePlan.balance, livePlan.balanceCurrency)}` : '', ...common }),
681
- h(TextField, { name: 'planRemaining', field: f.planRemaining, placeholder: livePlan?.remaining && livePlan.remainingSource === 'api' ? `${t('fromApi')} ${livePlan.remaining}` : '', ...common }),
682
- h(TextField, { name: 'planResetAt', field: f.planResetAt, placeholder: livePlan?.resetAt && !f.planResetAt.text ? String(livePlan.resetAt) : '', ...common })))
683
-
684
- // ---- quota fetching ---------------------------------------------------------
685
- const quotaChildren = []
686
- if (quotaSpec) {
687
- quotaChildren.push(h('p', { key: 'avail', style: S.hint }, t('quotaAvailable'), ' ', h('span', { style: S.mono }, quotaSpec.url)))
688
- } else {
689
- quotaChildren.push(h('p', { key: 'unavail', style: S.hint }, t(providerId === 'custom' ? 'quotaUnavailableCustom' : 'quotaUnavailable')))
690
- }
691
- quotaChildren.push(h('div', { key: 'grid3', style: S.grid },
692
- h(TextField, { name: 'planApiKeyEnv', field: f.planApiKeyEnv, placeholder: provider?.keyEnv ?? 'XXX_API_KEY', ...common }),
693
- h(TextField, { name: 'planQuotaUrl', field: f.planQuotaUrl, placeholder: quotaSpec?.url ?? 'https://…', ...common })))
694
- if (quotaSpec || f.planQuotaUrl.text) {
695
- quotaChildren.push(h(ToggleRow, { key: 'auto', name: 'planAutoQuota', field: f.planAutoQuota, ...common }))
696
- quotaChildren.push(h('div', { key: 'poll', style: { marginTop: 12 } }, h(NumberField, { name: 'quotaPollMinutes', field: f.quotaPollMinutes, ...common })))
697
- quotaChildren.push(h(QuotaStatus, { key: 'status', t, plan: livePlan, disabled, busy, onRefresh: refresh }))
698
- }
699
- children.push(h(Section, { key: 'quota', title: t('sectionQuota') }, quotaChildren))
752
+
753
+ // ---- remaining quota: the key reference and a refresh, when the provider has an endpoint ----
754
+ const canFetch = Boolean(quotaSpec || f.planQuotaUrl.text)
755
+ children.push(h('div', { key: 'quota', style: { ...S.row, display: 'block' } },
756
+ h('div', { style: S.label }, t('autoQuota')),
757
+ canFetch
758
+ ? h('div', null,
759
+ h(QuotaStatus, { t, plan: livePlan }),
760
+ h('div', { style: S.keyRow },
761
+ h('div', { style: { flex: '1 1 240px', minWidth: 0 } }, h(TextField, { name: 'planApiKeyEnv', field: f.planApiKeyEnv, placeholder: provider?.keyEnv ?? 'XXX_API_KEY', ...common })),
762
+ livePlan && livePlan.apiKeyEnv ? h('button', { type: 'button', style: { ...S.button, marginTop: 24 }, disabled: disabled || busy, onClick: refresh }, busy ? t('refreshing') : t('refreshNow')) : null))
763
+ : h('p', { style: S.hint }, t(providerId === 'custom' ? 'autoQuotaCustom' : 'autoQuotaNone'))))
764
+
765
+ // ---- everything a preset fills in, folded away ----
766
+ const detailFields = ['planName', 'planPrice', 'planPeriod', 'planCurrency', 'planQuota', 'planBalance', 'planRemaining', 'planResetAt']
767
+ const detailsChanged = detailFields.filter(name => f[name].overridden).length
768
+ children.push(h(Disclosure, { key: 'details', id: 'plan', title: t('planDetails'), hint: t('planDetailsHint'), badge: detailsChanged ? t('advancedChanged').replace('{n}', String(detailsChanged)) : undefined },
769
+ h('div', { style: S.grid },
770
+ h(TextField, { name: 'planName', field: f.planName, placeholder: preset?.name ?? '', ...common }),
771
+ h(NumberField, { name: 'planPrice', field: f.planPrice, placeholder: preset ? String(preset.price) : '', ...common }),
772
+ h(TextField, { name: 'planQuota', field: f.planQuota, placeholder: preset?.quotaText ?? '', ...common })),
773
+ h(ChoiceRow, { name: 'planPeriod', field: f.planPeriod, ...common, options: [['month', 'periodMonth'], ['year', 'periodYear'], ['week', 'periodWeek'], ['once', 'periodOnce'], ['free', 'periodFree']] }),
774
+ h(ChoiceRow, { name: 'planCurrency', field: f.planCurrency, ...common, options: [['CNY', 'CNY'], ['USD', 'USD']] }),
775
+ h('div', { style: S.grid },
776
+ h(NumberField, { name: 'planBalance', field: f.planBalance, placeholder: livePlan?.balance !== undefined && livePlan.remainingSource !== 'manual' ? fmt(livePlan.balance, livePlan.balanceCurrency) : '', ...common }),
777
+ h(TextField, { name: 'planRemaining', field: f.planRemaining, placeholder: livePlan?.remaining && livePlan.remainingSource === 'api' ? String(livePlan.remaining) : '', ...common }),
778
+ h(TextField, { name: 'planResetAt', field: f.planResetAt, placeholder: livePlan?.resetAt && !f.planResetAt.text ? String(livePlan.resetAt) : '', ...common }))))
700
779
  return children
701
780
  }
702
781
 
782
+ /** Everything most people never touch, behind one fold. */
783
+ function AdvancedSection({ t, f, common, features, state, catalog }) {
784
+ const { disabled, edit } = common
785
+ const toggle = name => h(ToggleRow, { key: name, name, field: f[name], ...common })
786
+ const { providerId, quotaSpec } = planContext(f, state, catalog)
787
+ const pricing = state && state.pricing
788
+ const fields = ADVANCED_FIELDS.filter(name => (features.tray || !TRAY_FIELDS.includes(name)) && (features.menuBarTitle || name !== 'showSpendInTitle'))
789
+ const changed = fields.filter(name => f[name].overridden).length
790
+ return h('section', { style: S.advanced },
791
+ h(Disclosure, { id: 'advanced', big: true, title: t('advanced'), hint: t('advancedHint'), badge: changed ? t('advancedChanged').replace('{n}', String(changed)) : undefined },
792
+ h(Group, { title: t('groupNotify') },
793
+ h(ChoiceRow, { name: 'channel', field: f.channel, hint: 'channelHint', ...common, options: [['auto', 'channelAuto'], ['client', 'channelClient'], ['system', 'channelSystem'], ['both', 'channelBoth'], ['off', 'channelOff']] }),
794
+ toggle('suppressWhenFocused')),
795
+ features.tray ? h(Group, { title: t('groupTray') },
796
+ features.menuBarTitle ? toggle('showSpendInTitle') : null,
797
+ h('div', { style: S.fieldGap }, h(NumberField, { name: 'errorHoldMinutes', field: f.errorHoldMinutes, ...common }))) : null,
798
+ h(Group, { title: t('groupSpend') },
799
+ h(ChoiceRow, { name: 'spendSource', field: f.spendSource, hint: 'spendSourceHint', ...common, options: [['auto', 'spendAuto'], ['balance', 'spendBalance'], ['estimate', 'spendEstimate']] }),
800
+ h(ChoiceRow, { name: 'currency', field: f.currency, ...common, options: [['CNY', 'CNY'], ['USD', 'USD']] }),
801
+ h('div', { style: S.fieldGap }, h(NumberField, { name: 'balancePollMinutes', field: f.balancePollMinutes, ...common }))),
802
+ h(Group, { title: t('groupPrice') },
803
+ h(ChoiceRow, { name: 'priceSource', field: f.priceSource, hint: 'priceSourceHint', ...common, options: [['auto', 'priceAuto'], ['catalog', 'priceCatalog'], ['custom', 'priceCustom']] }),
804
+ pricing && pricing.listed ? h('div', { style: S.fieldGap }, h('button', {
805
+ type: 'button',
806
+ style: S.button,
807
+ disabled,
808
+ onClick: () => {
809
+ edit('customInput', String(pricing.listed.input))
810
+ edit('customCacheRead', String(pricing.listed.cacheRead))
811
+ edit('customOutput', String(pricing.listed.output))
812
+ edit('customPriceCurrency', pricing.listed.currency)
813
+ },
814
+ }, t('fillCustom')), h('span', { style: { ...S.muted, ...S.mono, marginLeft: 8, fontSize: 12 } }, priceLine(pricing.listed, pricing.listed.currency))) : null,
815
+ h('div', { style: S.grid },
816
+ h(NumberField, { name: 'customInput', field: f.customInput, ...common }),
817
+ h(NumberField, { name: 'customCacheRead', field: f.customCacheRead, ...common }),
818
+ h(NumberField, { name: 'customOutput', field: f.customOutput, ...common })),
819
+ h(ChoiceRow, { name: 'customPriceCurrency', field: f.customPriceCurrency, ...common, options: [['CNY', 'CNY'], ['USD', 'USD']] }),
820
+ h('div', { style: S.fieldGap }, h(NumberField, { name: 'exchangeRate', field: f.exchangeRate, ...common }))),
821
+ providerId !== 'none' ? h(Group, { title: t('groupQuota') },
822
+ toggle('planAutoQuota'),
823
+ h('div', { style: S.grid },
824
+ h(NumberField, { name: 'quotaPollMinutes', field: f.quotaPollMinutes, ...common }),
825
+ h(TextField, { name: 'planQuotaUrl', field: f.planQuotaUrl, placeholder: quotaSpec?.url ?? 'https://…', ...common }))) : null))
826
+ }
827
+
703
828
  function Page(props) {
704
829
  if (props.view === 'summary') return platformT(props.t, currentPlatform())('summary')
705
830
  return h(FullPage, props)
@@ -715,38 +840,24 @@ window.__ModuleLoader__.load({
715
840
  const common = { t, disabled, edit: props.edit, resetField: props.resetField }
716
841
  const f = state.fields
717
842
  const toggle = name => h(ToggleRow, { key: name, name, field: f[name], ...common })
843
+ const titleStyle = f.titleStyle.text || 'text'
718
844
  return h(ui.SettingsForm, {
719
845
  labels: { unavailable: t('unavailable'), readOnly: t('readOnly'), saveFailed: t('saveFailed'), save: t('save'), saving: t('saving') },
720
846
  state,
721
847
  onSave: props.save,
722
848
  onDiscard: props.discard,
723
849
  },
724
- h(Section, { title: t('sectionNotify'), hint: t('sectionNotifyHint') },
725
- ['notifyCompleted', 'notifyChoice', 'notifyInput', 'notifyApproval', 'notifyFailed'].map(toggle)),
726
- h(Section, { title: t('sectionHow') },
727
- h(ChoiceRow, { name: 'channel', field: f.channel, hint: 'channelHint', ...common, options: [['auto', 'channelAuto'], ['client', 'channelClient'], ['system', 'channelSystem'], ['both', 'channelBoth'], ['off', 'channelOff']] }),
728
- toggle('suppressWhenFocused'),
850
+ h(Section, { title: t('sectionNotify') },
851
+ h(CheckRow, { label: 'notifyWhen', names: NOTIFY_FIELDS, f, ...common }),
729
852
  toggle('sound')),
730
853
  features.tray ? h(Section, { title: t('sectionTray') },
731
854
  toggle('tray'),
732
- features.menuBarTitle ? h(ChoiceRow, { name: 'titleStyle', field: f.titleStyle, hint: 'titleStyleHint', ...common, options: [['text', 'titleText'], ['count', 'titleCount'], ['icon', 'titleIcon']] }) : null,
733
- features.menuBarTitle ? toggle('showSpendInTitle') : null,
734
- h('div', { style: { marginTop: 12 } }, h(NumberField, { name: 'errorHoldMinutes', field: f.errorHoldMinutes, ...common }))) : null,
735
- h(Section, { title: t('sectionSpend') },
736
- h(ChoiceRow, { name: 'spendSource', field: f.spendSource, hint: 'spendSourceHint', ...common, options: [['auto', 'spendAuto'], ['balance', 'spendBalance'], ['estimate', 'spendEstimate']] }),
737
- h(ChoiceRow, { name: 'currency', field: f.currency, ...common, options: [['CNY', 'CNY'], ['USD', 'USD']] }),
738
- h('div', { style: { marginTop: 12 } }, h(NumberField, { name: 'balancePollMinutes', field: f.balancePollMinutes, ...common }))),
739
- h(Section, { title: t('sectionPrice'), hint: t('sectionPriceHint') },
740
- h(CurrentModelCard, { t, state: liveData.state, disabled, edit: props.edit }),
741
- h(ChoiceRow, { name: 'priceSource', field: f.priceSource, hint: 'priceSourceHint', ...common, options: [['auto', 'priceAuto'], ['catalog', 'priceCatalog'], ['custom', 'priceCustom']] }),
742
- h('div', { style: S.grid },
743
- h(NumberField, { name: 'customInput', field: f.customInput, ...common }),
744
- h(NumberField, { name: 'customCacheRead', field: f.customCacheRead, ...common }),
745
- h(NumberField, { name: 'customOutput', field: f.customOutput, ...common })),
746
- h(ChoiceRow, { name: 'customPriceCurrency', field: f.customPriceCurrency, ...common, options: [['CNY', 'CNY'], ['USD', 'USD']] }),
747
- h('div', { style: { marginTop: 12 } }, h(NumberField, { name: 'exchangeRate', field: f.exchangeRate, ...common }))),
748
- h(Section, { title: t('sectionPlan'), hint: t('sectionPlanHint') },
749
- h(PlanSection, { t, f, common, state: liveData.state, catalog: liveData.catalog })))
855
+ h(TrayStatus, { t, state: liveData.state }),
856
+ features.menuBarTitle ? h(ChoiceRow, { name: 'titleStyle', field: f.titleStyle, hint: `titleStyleHint_${titleStyle}`, ...common, options: [['text', 'titleText'], ['count', 'titleCount'], ['icon', 'titleIcon']] }) : null) : null,
857
+ h(Section, { title: t('sectionMoney') },
858
+ h(SpendCard, { t, state: liveData.state }),
859
+ h(PlanSection, { t, f, common, state: liveData.state, catalog: liveData.catalog })),
860
+ h(AdvancedSection, { t, f, common, features, state: liveData.state, catalog: liveData.catalog }))
750
861
  }
751
862
 
752
863
  // ---- mount ------------------------------------------------------------------------------