dsh-notify-tray 0.1.4 → 0.1.6

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