dsh-notify-tray 0.1.4 → 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
@@ -103,97 +103,68 @@ window.__ModuleLoader__.load({
103
103
  }
104
104
 
105
105
  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: '「🐳 要不要放行?」',
106
+ summary: '任务做完或需要你时提醒你,状态栏里看进度和花费。',
107
+ summary_win32: '任务做完或需要你时弹通知,顺便算算今天花了多少。Windows 没有状态栏,小鲸鱼只用通知来找你。',
108
+ sectionNotify: '提醒我',
109
+ notifyWhen: '这些时候弹通知',
110
+ notifyCompleted: '做完了',
111
+ notifyChoice: '要我选',
112
+ notifyInput: '要我写字',
113
+ notifyApproval: '要我批准',
118
114
  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
115
  sound: '带提示音',
131
116
  soundHint: '系统通知响一声。',
132
117
  soundHint_darwin: 'macOS 系统通知的「叮」一声。',
133
118
  soundHint_win32: 'Windows 系统通知(右下角弹窗)的提示音。',
134
119
  soundHint_linux: '系统通知的提示音(要桌面环境支持)。',
135
- sectionTray: '状态栏里的小鲸鱼',
136
- tray: '显示状态栏小鲸鱼',
120
+
121
+ sectionTray: '状态栏小鲸鱼',
122
+ tray: '显示小鲸鱼',
137
123
  trayHint: '保存后立即生效。',
138
- trayHint_linux: '显示在系统托盘里(UOS / Deepin / 麒麟 / KDE 自带;GNOME 要装 AppIndicator 扩展)。保存后立即生效。',
124
+ trayHint_linux: 'UOS / Deepin / 麒麟 / KDE 自带托盘;GNOME 要装 AppIndicator 扩展。保存后立即生效。',
139
125
  trayHiddenNote: '状态栏图标已从它的菜单里隐藏。',
140
126
  trayShowAgain: '重新显示状态栏图标',
141
127
  trayShowing: '正在显示…',
142
128
  trayFailedNote: '状态栏图标没能启动(没有托盘宿主或 D-Bus?),只保留通知。',
143
129
  trayRetry: '重试',
144
- titleStyle: '鲸鱼旁边显示什么',
130
+ titleStyle: '鲸鱼旁边显示',
145
131
  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: '现在用的模型',
132
+ titleCount: '数字',
133
+ titleIcon: '不显示',
134
+ titleStyleHint_text: '例:🐳 待处理 1;空闲时什么都不显示。',
135
+ titleStyleHint_count: '例:🐳 1',
136
+ titleStyleHint_icon: '只有鲸鱼,状态看它的样子。',
137
+
138
+ sectionMoney: '花费与套餐',
139
+ today: '今天',
140
+ spendNone: '还没有花费记录',
168
141
  currentModelNone: '还没看到请求,先聊一句就知道了。',
169
- listedPrice: '目录价',
170
- effectivePrice: '实际按',
171
- perMillion: '每百万 token · 输入 / 缓存命中 / 输出',
172
- noListedPrice: '目录里没有这个模型的价格,请在下面填自定义价。',
142
+ perMillion: '每百万',
143
+ noListedPrice: '目录里没有这个模型的价格,可在「高级设置」里填自定义单价。',
173
144
  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: '选一家平台和套餐,价格、额度会按预设填好,每一项都能改;选「自定义」就全部自己填。留空的项不显示。',
145
+ myPlan: '我的套餐',
146
+ myPlanHint: '选好后价格、额度自动填好。',
192
147
  planProvider: '平台',
193
148
  providerNone: '不设置',
194
149
  providerCustom: '自定义',
195
150
  planId: '套餐',
196
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: '名称、价格、周期、余额、重置时间',
197
168
  planName: '套餐名',
198
169
  planNameHint: '留空用预设名。',
199
170
  planPrice: '价格',
@@ -207,39 +178,70 @@ window.__ModuleLoader__.load({
207
178
  planCurrency: '套餐币种',
208
179
  planQuota: '额度说明',
209
180
  planQuotaHint: '例如「每 5 小时 ≈ 1000 次」,留空用预设。',
210
- planBalance: '套餐余额',
211
- planBalanceHint: '预付费 / 充值余额,手填;能从接口拿到时留空即可。',
212
- planRemaining: '剩余额度',
181
+ planBalance: '套餐余额(手填)',
182
+ planBalanceHint: '预付费 / 充值余额;能从接口拿到时留空即可。',
183
+ planRemaining: '剩余额度(手填)',
213
184
  planRemainingHint: '例如「68%」「1200 次」,手填优先于接口。',
214
185
  planResetAt: '下次重置',
215
186
  planResetAtHint: '例如「今晚 20:00」「每周一」。',
216
- sectionQuota: '自动获取额度',
217
- quotaAvailable: '这家平台有额度 / 余额接口:',
218
- quotaUnavailable: '这家平台没有公开的额度接口,剩余额度和余额请手填。',
219
- quotaUnavailableCustom: '自定义平台:填一个返回 JSON 的额度地址,插件会尽量读出 balance / remaining 字段。',
220
- planApiKeyEnv: 'API Key 引用(环境变量名)',
221
- 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: '',
222
238
  planQuotaUrl: '额度查询地址',
223
239
  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: '接口',
240
+
238
241
  srcTable: '价格表',
239
242
  srcCustom: '自定义价',
240
243
  srcCatalog: '目录价',
241
244
  srcStatic: '内置价',
242
-
243
245
  overridden: '已修改',
244
246
  reset: '恢复默认',
245
247
  readOnly: '本部署的设置为只读。',
@@ -250,97 +252,68 @@ window.__ModuleLoader__.load({
250
252
  invalidNumber: '请填数字;留空表示用默认值。',
251
253
  }
252
254
  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.',
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',
257
259
  notifyCompleted: 'A task finished',
258
- notifyCompletedHint: '"🐳 All done~"',
259
260
  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?"',
261
+ notifyInput: 'Text is needed',
262
+ notifyApproval: 'Approval is needed',
265
263
  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
264
  sound: 'Play a sound',
278
265
  soundHint: 'System notifications make a sound.',
279
266
  soundHint_darwin: 'The macOS notification chime.',
280
267
  soundHint_win32: 'The Windows notification (toast) sound.',
281
268
  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',
269
+
270
+ sectionTray: 'Status-bar whale',
271
+ tray: 'Show the whale',
284
272
  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.',
273
+ trayHint_linux: 'Built into UOS / Deepin / Kylin / KDE; GNOME needs the AppIndicator extension. Takes effect as soon as you save.',
286
274
  trayHiddenNote: 'The status-bar icon was hidden from its own menu.',
287
275
  trayShowAgain: 'Show the status-bar icon again',
288
276
  trayShowing: 'Showing…',
289
277
  trayFailedNote: 'The status-bar icon could not start (no tray host or D-Bus?); notifications still work.',
290
278
  trayRetry: 'Retry',
291
- titleStyle: 'Text beside the whale',
279
+ titleStyle: 'Beside the whale',
292
280
  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',
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',
315
290
  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.',
291
+ perMillion: 'per million',
292
+ noListedPrice: 'No catalog price for this model; set a custom price under Advanced.',
320
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.',
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.',
294
+ myPlan: 'My plan',
295
+ myPlanHint: 'Price and quota are filled in from the preset.',
339
296
  planProvider: 'Provider',
340
297
  providerNone: 'None',
341
298
  providerCustom: 'Custom',
342
299
  planId: 'Plan',
343
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',
344
317
  planName: 'Plan name',
345
318
  planNameHint: 'Blank: preset name.',
346
319
  planPrice: 'Price',
@@ -354,39 +327,70 @@ window.__ModuleLoader__.load({
354
327
  planCurrency: 'Plan currency',
355
328
  planQuota: 'Quota description',
356
329
  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',
330
+ planBalance: 'Plan balance (manual)',
331
+ planBalanceHint: 'Prepaid / top-up balance; leave blank when the API supplies it.',
332
+ planRemaining: 'Remaining quota (manual)',
360
333
  planRemainingHint: 'e.g. "68%" or "1200 requests"; a typed value wins over the API.',
361
334
  planResetAt: 'Next reset',
362
335
  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',
336
+
337
+ advanced: 'Advanced',
338
+ advancedHint: 'Notification channel, spend method, custom prices, refresh intervals — rarely needed.',
339
+ advancedChanged: '{n} changed',
340
+ groupNotify: 'Notifications',
341
+ channel: 'Notification channel',
342
+ channelAuto: 'Auto',
343
+ channelClient: 'Window only',
344
+ channelSystem: 'System only',
345
+ channelBoth: 'Both',
346
+ channelOff: 'Off',
347
+ channelHint: 'Auto: the DSH window notifies while it is open; the OS does otherwise.',
348
+ suppressWhenFocused: 'Stay quiet while I am looking at that session',
349
+ suppressWhenFocusedHint: 'Off: notify even when you watch it finish.',
350
+ groupTray: 'Status bar',
351
+ showSpendInTitle: 'Add today\'s spend beside the whale',
352
+ showSpendInTitleHint: 'e.g. 运行中 1 · ¥1.82',
353
+ errorHoldMinutes: 'Minutes the "×" stays after a failure',
354
+ errorHoldMinutesHint: '0: failures are only listed in the menu.',
355
+ errorHoldMinutes_linux: 'Minutes the whale stays red after a failure',
356
+ groupSpend: 'Spend',
357
+ spendSource: 'How spend is counted',
358
+ spendAuto: 'Auto',
359
+ spendBalance: 'Balance drops',
360
+ spendEstimate: 'Price estimate',
361
+ spendSourceHint: 'Auto: real balance drops when signed in to DeepSeek, otherwise unit prices.',
362
+ currency: 'Currency',
363
+ balancePollMinutes: 'Balance refresh interval (minutes)',
364
+ balancePollMinutesHint: 'Also refreshed 5 s after every finished turn.',
365
+ groupPrice: 'Unit prices (for estimates)',
366
+ priceSource: 'Which price to use',
367
+ priceAuto: 'Auto',
368
+ priceCatalog: 'Catalog only',
369
+ priceCustom: 'Custom only',
370
+ priceSourceHint: 'Auto: price table → custom price → catalog → built-in prices.',
371
+ fillCustom: 'Copy catalog price',
372
+ customInput: 'Input (cache miss)',
373
+ customInputHint: 'per million tokens; blank: unused',
374
+ customCacheRead: 'Input (cache hit)',
375
+ customCacheReadHint: 'Blank: same as input',
376
+ customOutput: 'Output',
377
+ customOutputHint: 'per million tokens',
378
+ customPriceCurrency: 'Custom price currency',
379
+ exchangeRate: 'Rate: 1 USD = ? CNY',
380
+ exchangeRateHint: 'Catalog prices are USD; used when displaying CNY.',
381
+ groupQuota: 'Quota refresh',
382
+ planAutoQuota: 'Refresh plan quota automatically',
372
383
  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)',
384
+ planAutoQuotaHint_win32: 'Polled at the interval below; "Refresh" above fetches by hand.',
385
+ quotaPollMinutes: 'Quota refresh interval (minutes)',
375
386
  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',
387
+ planQuotaUrl: 'Quota URL',
388
+ planQuotaUrlHint: 'Blank: preset URL.',
389
+
385
390
  srcTable: 'price table',
386
391
  srcCustom: 'custom',
387
392
  srcCatalog: 'catalog',
388
393
  srcStatic: 'built-in',
389
-
390
394
  overridden: 'Changed',
391
395
  reset: 'Reset to default',
392
396
  readOnly: 'This deployment stores settings read-only.',
@@ -419,6 +423,11 @@ window.__ModuleLoader__.load({
419
423
  const NUMBERS = ['errorHoldMinutes', 'balancePollMinutes', 'customInput', 'customCacheRead', 'customOutput', 'exchangeRate', 'planPrice', 'planBalance', 'quotaPollMinutes']
420
424
  const TEXTS = ['planProvider', 'planId', 'planName', 'planQuota', 'planRemaining', 'planResetAt', 'planApiKeyEnv', 'planQuotaUrl']
421
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']
422
431
  /** Plan fields a preset fills in; switching provider clears them. */
423
432
  const PRESET_FIELDS = ['planId', 'planName', 'planPrice', 'planCurrency', 'planPeriod', 'planQuota', 'planQuotaUrl']
424
433
 
@@ -448,6 +457,12 @@ window.__ModuleLoader__.load({
448
457
 
449
458
  // ---- live data: catalog once, host state while the page is open ------------------
450
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
+ }
451
466
  function publishLive() { for (const fn of live.listeners) fn() }
452
467
  function fetchJson(url, init) {
453
468
  return fetch(url, { headers: { accept: 'application/json' }, cache: 'no-store', ...init }).then(res => (res.ok ? res.json() : undefined))
@@ -461,7 +476,7 @@ window.__ModuleLoader__.load({
461
476
  }
462
477
  // Test seam: lets a test drive the loaders without React effects.
463
478
  const currentPlatform = () => normalizePlatform(live.state && live.state.platform) || guessPlatform()
464
- exports.__settingsLive = { live, loadCatalog, loadState, currentPlatform }
479
+ exports.__settingsLive = { live, open, loadCatalog, loadState, currentPlatform }
465
480
  function useLive() {
466
481
  const [, bump] = React.useState(0)
467
482
  React.useEffect(() => {
@@ -479,7 +494,6 @@ window.__ModuleLoader__.load({
479
494
  const S = {
480
495
  section: { marginTop: 28 },
481
496
  sectionTitle: { fontSize: 15, fontWeight: 600, margin: '0 0 4px' },
482
- sectionHint: { margin: '0 0 12px', opacity: 0.65, fontSize: 13 },
483
497
  row: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 16, padding: '10px 0', borderBottom: '1px solid color-mix(in srgb, currentColor 10%, transparent)' },
484
498
  rowText: { minWidth: 0 },
485
499
  label: { fontSize: 14 },
@@ -493,12 +507,23 @@ window.__ModuleLoader__.load({
493
507
  mono: { fontFamily: 'var(--ds-font-family-code, ui-monospace, monospace)', fontSize: 13 },
494
508
  muted: { opacity: 0.65 },
495
509
  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 },
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' },
499
511
  link: { color: 'inherit', textDecoration: 'underline', opacity: 0.75 },
500
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' },
501
- 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 },
502
527
  }
503
528
 
504
529
  function Overridden({ t, field, disabled, onReset }) {
@@ -509,10 +534,11 @@ window.__ModuleLoader__.load({
509
534
  }
510
535
 
511
536
  function ToggleRow({ t, name, field, disabled, edit, resetField }) {
537
+ const hint = t(`${name}Hint`)
512
538
  return h('div', { style: S.row },
513
539
  h('div', { style: S.rowText },
514
540
  h('div', { style: S.label }, t(name), h(Overridden, { t, field, disabled, onReset: () => resetField(name) })),
515
- h('p', { style: S.hint }, t(`${name}Hint`))),
541
+ hint ? h('p', { style: S.hint }, hint) : null),
516
542
  h('div', { style: S.control },
517
543
  h(ui.Switch, { checked: field.text === 'on', disabled, label: t(name), onChange: next => edit(name, next ? 'on' : 'off') })))
518
544
  }
@@ -533,6 +559,19 @@ window.__ModuleLoader__.load({
533
559
  })))
534
560
  }
535
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
+
536
575
  function ValueField({ t, name, field, disabled, edit, resetField, numeric, placeholder, hint }) {
537
576
  return h(ui.SettingsValueField, {
538
577
  id: `notify-tray-${name}`,
@@ -554,26 +593,40 @@ window.__ModuleLoader__.load({
554
593
  const NumberField = props => h(ValueField, { numeric: true, ...props })
555
594
  const TextField = props => h(ValueField, { ...props, numeric: false })
556
595
 
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))))
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)))
568
606
  }
569
607
 
570
- function Section({ title, hint, children }) {
608
+ function Section({ title, children }) {
571
609
  return h('section', { style: S.section },
572
610
  h('h4', { style: S.sectionTitle }, title),
573
- hint ? h('p', { style: S.sectionHint }, hint) : null,
574
611
  children)
575
612
  }
576
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
+
577
630
  const SYM = { CNY: '¥', USD: '$' }
578
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))}` : '—')
579
632
  const priceLine = (p, currency) => `${fmt(p.input, currency)} / ${fmt(p.cacheRead, currency)} / ${fmt(p.output, currency)}`
@@ -583,53 +636,45 @@ window.__ModuleLoader__.load({
583
636
  return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`
584
637
  }
585
638
 
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'))]
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 = []
590
645
  if (!pricing) {
591
- rows.push(h('div', { key: 'none', style: S.muted }, t('currentModelNone')))
646
+ detail.push(h('div', { key: 'none', style: S.muted }, t('currentModelNone')))
592
647
  } 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')))
598
- }
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'))))
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')))
614
655
  }
615
656
  }
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
- }
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)
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)
633
678
  }
634
679
 
635
680
  /** Brings back a status-bar icon hidden from its own menu (or one that failed to start). */
@@ -646,14 +691,21 @@ window.__ModuleLoader__.load({
646
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'))))
647
692
  }
648
693
 
649
- function PlanSection({ t, f, common, state, catalog }) {
650
- const { edit, resetField, disabled } = common
651
- 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) || []
652
697
  const providerId = f.planProvider.text || 'none'
653
698
  const provider = providers.find(p => p.id === providerId)
654
- const plans = provider?.plans ?? []
699
+ const plans = (provider && provider.plans) || []
655
700
  const preset = plans.find(p => p.id === f.planId.text)
656
- 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)
657
709
  const [busy, setBusy] = React.useState(false)
658
710
  const refresh = () => {
659
711
  setBusy(true)
@@ -684,47 +736,95 @@ window.__ModuleLoader__.load({
684
736
  }
685
737
  const providerOptions = [['none', t('providerNone')], ...providers.map(p => [p.id, p.name]), ['custom', t('providerCustom')]]
686
738
  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
739
  const links = provider ? [['pricing', provider.pricingUrl], ['console', provider.consoleUrl]].filter(([, url]) => url) : []
740
+ const planChanged = f.planProvider.overridden || f.planId.overridden
689
741
 
690
- const children = [
691
- h(SelectField, { key: 'provider', t, name: 'planProvider', field: f.planProvider, options: providerOptions, disabled, onChange: chooseProvider, resetField }),
692
- ]
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))]
693
751
  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))
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 }))))
725
779
  return children
726
780
  }
727
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
+
728
828
  function Page(props) {
729
829
  if (props.view === 'summary') return platformT(props.t, currentPlatform())('summary')
730
830
  return h(FullPage, props)
@@ -740,39 +840,24 @@ window.__ModuleLoader__.load({
740
840
  const common = { t, disabled, edit: props.edit, resetField: props.resetField }
741
841
  const f = state.fields
742
842
  const toggle = name => h(ToggleRow, { key: name, name, field: f[name], ...common })
843
+ const titleStyle = f.titleStyle.text || 'text'
743
844
  return h(ui.SettingsForm, {
744
845
  labels: { unavailable: t('unavailable'), readOnly: t('readOnly'), saveFailed: t('saveFailed'), save: t('save'), saving: t('saving') },
745
846
  state,
746
847
  onSave: props.save,
747
848
  onDiscard: props.discard,
748
849
  },
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'),
850
+ h(Section, { title: t('sectionNotify') },
851
+ h(CheckRow, { label: 'notifyWhen', names: NOTIFY_FIELDS, f, ...common }),
754
852
  toggle('sound')),
755
853
  features.tray ? h(Section, { title: t('sectionTray') },
756
854
  toggle('tray'),
757
855
  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 })))
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 }))
776
861
  }
777
862
 
778
863
  // ---- mount ------------------------------------------------------------------------------