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/README.md +8 -8
- package/README.zh-CN.md +8 -8
- package/lib/client.js +399 -314
- package/lib/format.js +59 -65
- package/lib/index.js +5 -2
- package/package.json +2 -2
package/lib/format.js
CHANGED
|
@@ -35,9 +35,14 @@ const KIND_ICON = {
|
|
|
35
35
|
failed: 'xmark.circle',
|
|
36
36
|
aborted: 'stop.circle',
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
/** First-level rows. */
|
|
39
|
+
const LABEL_MAX = 28
|
|
39
40
|
/** Submenu rows: kept short so a submenu opened toward the screen edge stays readable. */
|
|
40
|
-
const SUB_MAX =
|
|
41
|
+
const SUB_MAX = 24
|
|
42
|
+
/** Task rows on the first level; the rest are one "还有 n 个…" row. */
|
|
43
|
+
const TASK_ROWS = 5
|
|
44
|
+
/** Rows per submenu, separators included. */
|
|
45
|
+
const SUB_ROWS = 6
|
|
41
46
|
|
|
42
47
|
/** Long text as several short menu rows, broken at its own separators where it can be. */
|
|
43
48
|
export function wrapText(text, max = SUB_MAX) {
|
|
@@ -86,6 +91,10 @@ function clock(time) {
|
|
|
86
91
|
}
|
|
87
92
|
|
|
88
93
|
const trim = (text, max = LABEL_MAX) => (text.length > max ? `${text.slice(0, max - 1)}…` : text)
|
|
94
|
+
/** "<name> <amount>" within SUB_MAX, shortening the name so the amount always shows. */
|
|
95
|
+
const trimEnd = (name, amount) => `${trim(name, Math.max(4, SUB_MAX - amount.length - 1))} ${amount}`
|
|
96
|
+
/** The spend figure's source, in a word or two. */
|
|
97
|
+
const spendHow = spend => (spend.mixed ? '含估算' : spend.label.startsWith('估算') ? '估算' : '余额扣费')
|
|
89
98
|
|
|
90
99
|
/** A reset time: ISO strings become a clock, anything the user typed stays as typed. */
|
|
91
100
|
function resetText(value) {
|
|
@@ -164,7 +173,8 @@ export function buildView(tasks, usage, config, now = Date.now(), plan = undefin
|
|
|
164
173
|
let headline
|
|
165
174
|
let headIcon
|
|
166
175
|
if (tasks.waiting.length > 0) {
|
|
167
|
-
|
|
176
|
+
const others = tasks.runningList.filter(item => !tasks.waiting.some(wait => wait.sessionId === item.sessionId)).length
|
|
177
|
+
headline = `${tasks.waiting.length} 件事等你${others > 0 ? ` · ${others} 个在跑` : ''}`
|
|
168
178
|
headIcon = 'bell.badge'
|
|
169
179
|
} else if (tasks.running > 0) {
|
|
170
180
|
headline = `正在运行 ${tasks.running} 个任务`
|
|
@@ -176,94 +186,78 @@ export function buildView(tasks, usage, config, now = Date.now(), plan = undefin
|
|
|
176
186
|
headline = '搞定啦~ 刚完成一个任务'
|
|
177
187
|
headIcon = 'sparkles'
|
|
178
188
|
} else {
|
|
179
|
-
headline = today.completed + today.failed > 0 ? `空闲 ·
|
|
189
|
+
headline = today.completed + today.failed > 0 ? `空闲 · 今天完成 ${today.completed} 个` : '空闲,等你派活'
|
|
180
190
|
headIcon = 'moon.zzz'
|
|
181
191
|
}
|
|
182
192
|
|
|
193
|
+
// The menu is kept short and shallow: Windows / Linux trays open submenus
|
|
194
|
+
// beside the panel, and long rows or deep submenus run off the screen edge.
|
|
195
|
+
// At most TASK_ROWS task rows, one level of submenus, SUB_ROWS rows each.
|
|
183
196
|
const menu = []
|
|
184
197
|
menu.push({ id: 'headline', label: headline, icon: headIcon, enabled: false })
|
|
185
198
|
|
|
186
199
|
// ---- the tasks themselves --------------------------------------------------
|
|
187
|
-
|
|
200
|
+
const taskRows = []
|
|
201
|
+
for (const wait of tasks.waiting) {
|
|
188
202
|
const detail = wait.text ? `:${wait.text}` : ''
|
|
189
|
-
|
|
203
|
+
taskRows.push({ id: `open:${wait.sessionId}`, icon: KIND_ICON[wait.kind], label: trim(`${KIND_LABEL[wait.kind]} · ${wait.title}${detail}`) })
|
|
190
204
|
}
|
|
191
|
-
for (const item of tasks.runningList
|
|
205
|
+
for (const item of tasks.runningList) {
|
|
192
206
|
if (tasks.waiting.some(wait => wait.sessionId === item.sessionId)) continue
|
|
193
|
-
const bits = [item.title]
|
|
194
207
|
const age = elapsed(item.since, now)
|
|
195
|
-
|
|
196
|
-
if (item.tool) bits.push(item.tool)
|
|
197
|
-
menu.push({ id: `open:${item.sessionId}`, icon: 'play.circle', label: trim(bits.join(' · ')) })
|
|
208
|
+
taskRows.push({ id: `open:${item.sessionId}`, icon: 'play.circle', label: trim([item.title, age].filter(Boolean).join(' · ')) })
|
|
198
209
|
}
|
|
210
|
+
menu.push(...taskRows.slice(0, TASK_ROWS))
|
|
211
|
+
if (taskRows.length > TASK_ROWS) menu.push({ id: 'show-app', icon: 'ellipsis.circle', label: `还有 ${taskRows.length - TASK_ROWS} 个…` })
|
|
199
212
|
menu.push({ separator: true })
|
|
200
213
|
|
|
201
|
-
// ---- today
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const usageRows = []
|
|
209
|
-
usageRows.push({ id: 'info', enabled: false, icon: 'checkmark.circle', label: `完成 ${today.completed} · 失败 ${today.failed}${today.aborted ? ` · 停止 ${today.aborted}` : ''}` })
|
|
210
|
-
if (spend) usageRows.push({ id: 'info', enabled: false, icon: 'yensign.circle', label: `花费 ${spendText}(${spend.label})` })
|
|
211
|
-
if (usage.estimate !== undefined && spend?.label !== undefined && !spend.label.startsWith('估算') && spend.value !== usage.estimate) {
|
|
212
|
-
usageRows.push({ id: 'info', enabled: false, icon: 'function', label: `按价格估算 ${money(usage.estimate, usage.currency)}` })
|
|
213
|
-
}
|
|
214
|
-
if (spend?.mixed || (spend && usage.balanceSpend !== undefined && spend.label.startsWith('估算'))) {
|
|
215
|
-
usageRows.push({ id: 'info', enabled: false, icon: 'creditcard', label: `余额已扣 ${money(usage.balanceSpend ?? 0, usage.currency)}` })
|
|
216
|
-
}
|
|
217
|
-
usageRows.push({ id: 'info', enabled: false, icon: 'number', label: `Token ${compactTokens(usage.tokens.total)}(输出 ${compactTokens(usage.tokens.output)})` })
|
|
218
|
-
// One row per provider/model route used today, biggest first. Rows stay
|
|
219
|
-
// short: Windows / Linux trays open submenus beside the panel and long rows
|
|
220
|
-
// run off the screen edge, so the provider only shows when two routes share
|
|
221
|
-
// a model id, and the route in use is split into model + provider rows.
|
|
222
|
-
const routes = (usage.byModel ?? []).slice(0, 6)
|
|
214
|
+
// ---- today -------------------------------------------------------------------
|
|
215
|
+
const todayRows = []
|
|
216
|
+
todayRows.push({ id: 'info', enabled: false, icon: 'checkmark.circle', label: `完成 ${today.completed} · 失败 ${today.failed}${today.aborted ? ` · 停止 ${today.aborted}` : ''}` })
|
|
217
|
+
if (spend) todayRows.push({ id: 'info', enabled: false, icon: 'yensign.circle', label: `花费 ${spendText} · ${spendHow(spend)}` })
|
|
218
|
+
todayRows.push({ id: 'info', enabled: false, icon: 'number', label: `Token ${compactTokens(usage.tokens.total)}` })
|
|
219
|
+
// The biggest routes used today; the provider only shows when two routes share a model id.
|
|
220
|
+
const routes = (usage.byModel ?? []).slice(0, SUB_ROWS - todayRows.length)
|
|
223
221
|
const modelCount = {}
|
|
224
222
|
for (const row of routes) modelCount[row.model] = (modelCount[row.model] ?? 0) + 1
|
|
225
223
|
for (const row of routes) {
|
|
226
224
|
const name = row.key === 'unknown' ? '未知模型' : modelCount[row.model] > 1 ? row.key : row.model
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
usageRows.push({ id: 'info', enabled: false, icon: 'cpu', label: trim(bits.join(' · '), SUB_MAX) })
|
|
225
|
+
const amount = row.cost !== undefined ? money(row.cost, usage.currency) : compactTokens(row.tokens.input + row.tokens.cacheRead + row.tokens.cacheWrite + row.tokens.output)
|
|
226
|
+
todayRows.push({ id: 'info', enabled: false, icon: 'cpu', label: trimEnd(name, amount) })
|
|
230
227
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
const todayLabel = spendText ? `今日用量 · ${spendText}` : '今日用量'
|
|
236
|
-
menu.push({ id: 'today', icon: 'chart.bar', label: todayLabel, children: usageRows })
|
|
228
|
+
const todayBits = ['今日']
|
|
229
|
+
if (spendText) todayBits.push(spendText)
|
|
230
|
+
menu.push({ id: 'today', icon: 'chart.bar', label: `${todayBits.join(' ')} · 完成 ${today.completed}`, children: todayRows })
|
|
237
231
|
|
|
238
|
-
// ----
|
|
232
|
+
// ---- balance and plan: one submenu -------------------------------------------------
|
|
233
|
+
const accountRows = []
|
|
234
|
+
if (usage.balance !== undefined) accountRows.push({ id: 'info', enabled: false, icon: 'creditcard', label: `DeepSeek 余额 ${money(usage.balance, usage.currency)}` })
|
|
239
235
|
if (plan) {
|
|
240
|
-
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
if (plan.
|
|
244
|
-
if (plan.
|
|
245
|
-
if (plan.
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (plan.links.pricing) planRows.push({ id: `url:${plan.links.pricing}`, icon: 'tag', label: '价格页…' })
|
|
259
|
-
menu.push({ id: 'plan', icon: 'creditcard.circle', label: trim(`套餐 · ${headBits.join(' · ')}`, 72), children: planRows })
|
|
236
|
+
accountRows.push({ id: 'info', enabled: false, icon: 'creditcard.circle', label: trim([plan.name, plan.priceText].filter(Boolean).join(' · '), SUB_MAX) })
|
|
237
|
+
const left = [plan.remaining !== undefined ? `剩余 ${plan.remaining}${plan.remainingSource === 'manual' ? '(手填)' : ''}` : undefined, plan.resetAt ? `${resetText(plan.resetAt)} 重置` : undefined].filter(Boolean)
|
|
238
|
+
if (left.length) accountRows.push({ id: 'info', enabled: false, icon: 'gauge.with.dots.needle.33percent', label: trim(left.join(' · '), SUB_MAX) })
|
|
239
|
+
if (plan.balance !== undefined) accountRows.push({ id: 'info', enabled: false, icon: 'wallet.pass', label: `套餐余额 ${money(plan.balance, plan.balanceCurrency)}` })
|
|
240
|
+
if (plan.fetch && !plan.fetch.ok) accountRows.push({ id: 'info', enabled: false, icon: 'exclamationmark.icloud', label: '额度获取失败,详见设置页' })
|
|
241
|
+
else if (plan.canFetch && !plan.apiKeyEnv) accountRows.push({ id: 'info', enabled: false, icon: 'key', label: '设置页填 API Key 后可查额度' })
|
|
242
|
+
}
|
|
243
|
+
const actions = []
|
|
244
|
+
if (plan?.canFetch && plan.apiKeyEnv) actions.push({ id: 'refresh-quota', icon: 'arrow.triangle.2.circlepath', label: '刷新额度' })
|
|
245
|
+
const consoles = [usage.usageUrl ? ['usage-page', 'DeepSeek'] : undefined, plan?.links.console ? [`url:${plan.links.console}`, plan.providerName] : undefined].filter(Boolean)
|
|
246
|
+
for (const [id, name] of consoles) actions.push({ id, icon: 'safari', label: consoles.length > 1 ? trim(`${name} 用量页…`, SUB_MAX) : '打开用量页…' })
|
|
247
|
+
if (accountRows.length || actions.length) {
|
|
248
|
+
const accountBits = []
|
|
249
|
+
if (usage.balance !== undefined) accountBits.push(`余额 ${money(usage.balance, usage.currency)}`)
|
|
250
|
+
if (plan?.remaining !== undefined) accountBits.push(`${plan.providerName ?? plan.name} 剩 ${plan.remaining}`)
|
|
251
|
+
else if (plan && usage.balance === undefined) accountBits.push(`套餐 · ${plan.name}`)
|
|
252
|
+
const children = [...accountRows.slice(0, SUB_ROWS - actions.length), ...(accountRows.length && actions.length ? [{ separator: true }] : []), ...actions]
|
|
253
|
+
menu.push({ id: 'account', icon: 'creditcard', label: trim(accountBits.join(' · ') || '账户与套餐'), children })
|
|
260
254
|
}
|
|
261
255
|
|
|
262
256
|
if (tasks.recent.length > 0) {
|
|
263
|
-
const rows = tasks.recent.map(item => ({
|
|
257
|
+
const rows = tasks.recent.slice(0, SUB_ROWS).map(item => ({
|
|
264
258
|
id: `open:${item.sessionId}`,
|
|
265
259
|
icon: KIND_ICON[item.kind],
|
|
266
|
-
label: trim(`${clock(item.at)}
|
|
260
|
+
label: trim(`${clock(item.at)} ${KIND_LABEL[item.kind]} · ${item.title}`, SUB_MAX),
|
|
267
261
|
}))
|
|
268
262
|
menu.push({ id: 'recent', icon: 'clock.arrow.circlepath', label: '最近结束', children: rows })
|
|
269
263
|
}
|
package/lib/index.js
CHANGED
|
@@ -21,7 +21,7 @@ import { appendFileSync, mkdirSync } from 'node:fs'
|
|
|
21
21
|
import { homedir } from 'node:os'
|
|
22
22
|
import { join } from 'node:path'
|
|
23
23
|
import { planView, publicCatalog, quotaSpecFor } from './catalog.js'
|
|
24
|
-
import { buildView, DONE_HOLD_MS, TITLES } from './format.js'
|
|
24
|
+
import { buildView, DONE_HOLD_MS, spendOf, TITLES } from './format.js'
|
|
25
25
|
import { Ledger } from './ledger.js'
|
|
26
26
|
import { describeRoute, loadPiCatalog, makeResolver } from './pricing.js'
|
|
27
27
|
import { fetchQuota } from './quota.js'
|
|
@@ -472,6 +472,7 @@ export function apply(ctx, config) {
|
|
|
472
472
|
const after = Number(url.searchParams.get('after') ?? '-1')
|
|
473
473
|
const channel = cfg.channel
|
|
474
474
|
const clientSide = channel === 'auto' || channel === 'client' || channel === 'both'
|
|
475
|
+
const currentUsage = usage()
|
|
475
476
|
const enabled = Object.fromEntries(Object.entries(EVENT_SWITCH).map(([type, key]) => [type, Boolean(cfg[key])]))
|
|
476
477
|
const body = {
|
|
477
478
|
boot,
|
|
@@ -487,7 +488,9 @@ export function apply(ctx, config) {
|
|
|
487
488
|
suppressWhenFocused: cfg.suppressWhenFocused,
|
|
488
489
|
focus: focusQueue,
|
|
489
490
|
summary: tracker.summary(),
|
|
490
|
-
usage:
|
|
491
|
+
usage: currentUsage,
|
|
492
|
+
// Today's figure exactly as the tray shows it, for the settings page's spend card.
|
|
493
|
+
spend: spendOf(currentUsage, cfg.spendSource) ?? null,
|
|
491
494
|
pricing: pricing(),
|
|
492
495
|
plan: plan(),
|
|
493
496
|
catalogLoaded: Boolean(pi),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-notify-tray",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "DeepSeek Harness 通知 + 状态栏插件:任务完成、需要输入、需要选择时弹系统通知(macOS / Windows / Linux);macOS 与 Linux(含 UOS、Deepin、麒麟)状态栏常驻小图标,显示任务进度与花费。Windows 没有状态栏,只弹通知。",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"deepseek",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"node": ">=20"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
|
-
"test": "node --test --test-force-exit test
|
|
52
|
+
"test": "node --test --test-force-exit test/*.test.js"
|
|
53
53
|
},
|
|
54
54
|
"dsh": {
|
|
55
55
|
"bundle": {
|