dsh-opencode-status 0.4.1 → 0.4.4
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/CHANGELOG.md +21 -0
- package/README.md +8 -6
- package/package.json +1 -1
- package/src/client.js +40 -6
- package/src/index.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.4.4
|
|
4
|
+
|
|
5
|
+
- **去掉面板内的两处重复**:
|
|
6
|
+
- 状态行原本是「OpenCode GO 已连接」,而标题已经是「OpenCode GO 用量」,同一产品名在 40px 内出现两次;现在状态行只表达连接状态(「已连接」/「异常」)。
|
|
7
|
+
- 头部「最紧张」摘要不再带百分比:该数字在对应窗口行已经出现一次(`最紧张 月窗口` + `月窗口 剩余 78%` 是同一个数),现在摘要只给判断,具体数值保留在悬停 `title` 里。
|
|
8
|
+
- 测试 49 保持全绿:更新 2 处头部摘要断言,并新增「该百分比只在窗口行出现一次」的反向断言。
|
|
9
|
+
|
|
10
|
+
## 0.4.3
|
|
11
|
+
|
|
12
|
+
- **修掉主面板的中英夹杂**:面板头部「最紧张」摘要此前复用了 `shortLabel`(`Weekly` / `Monthly`),而那是给 220px 悬浮微卡窄列准备的紧凑缩写。现在头部改用中文窗口名(`最紧张 月窗口 78%`),`shortLabel` 本身也改为 `5h` / `周` / `月`,两个位置都不再出现英文整词。
|
|
13
|
+
- **新增「采样中」提示**:已有采样点但还攒不够(少于 3 个点,或跨度不足 10 分钟)时,原本的位置显示「采样中」,`title` 说明已有几个点、跨了多少分钟。此前这种情况与「插件没加载」在界面上完全一样,都是空白,用户无法判断该等还是该重启。它只说明状态、不含任何数字,速率为 0 / 剩余为 0 / 重置过期时仍然完全不渲染。
|
|
14
|
+
- 面板头部标题在窄视口下可省略(`flexShrink:1` + ellipsis),把空间让给右侧摘要,避免中文全名撑破一行。
|
|
15
|
+
- 测试 48 → 49:新增「采样中 → 真实估算」的状态迁移用例与悬浮卡不显示采样提示的断言。
|
|
16
|
+
|
|
17
|
+
## 0.4.2
|
|
18
|
+
|
|
19
|
+
- **估算时长按两位有效数字粗化**:`<1h` 取 5 分钟、`1–10h` 取 30 分钟、`≥10h` 取 1 小时、`≥48h` 取 1 天(下限 5 分钟,不会出现「约 0m」)。上游只给整数 percent,量化误差会让 ETA 的真实区间比点值宽 2–3 倍,分钟级精度属于虚假精确;现在 `约 13h10m 后耗尽` 显示为 `约 13h 后耗尽`,`约 1h54m` 显示为 `约 2h`。
|
|
20
|
+
- 修复 220ms 悬停定时器在组件卸载时未清理的问题(原先可能在卸载后对已卸载组件 `setState`)。
|
|
21
|
+
- 修复底部操作条「刷新」按钮缺少 React `key` 导致的开发期警告。
|
|
22
|
+
- 测试 47 → 48:新增 ETA 粗化的四档边界用例与最小 5 分钟下限断言。
|
|
23
|
+
|
|
3
24
|
## 0.4.1
|
|
4
25
|
|
|
5
26
|
- 新增**按当前消耗速率的可用时长估算**:用量面板的窗口行在「剩余 %」与「⏱ 重置倒计时」之间给出「按现在的用法还能撑多久」。估算用最近的实测采样外推(只用首尾两点,不做回归),三种状态严格区分:
|
package/README.md
CHANGED
|
@@ -10,15 +10,17 @@ OpenCode GO 套餐用量与配额状态监控面板插件(DeepSeek Harness)
|
|
|
10
10
|
- `⚙ 设置`:进入面板内的独立连接设置视图,可随时 `← 返回用量`。
|
|
11
11
|
- 右侧显示相对时间「上次同步 12s 前」(刚刚 / Ns 前 / N 分钟前 / N 小时前 / N 天前),绝对时刻 HH:MM:SS 保留在 `title`;同步数据超过 2 分钟追加「· 可能已过期」并用警告色,避免把旧额度当成实时值。
|
|
12
12
|
- **3 维度用量行**:主百分比只给剩余额度,进度条条长与它同源(条长 = 剩余占比,条色 = 剩余档位),「已用」放在 `title` 与 `aria-valuetext` 里,同一行不再重复表达同一个数字;窗口状态非 `ok` 时给出可见提示。
|
|
13
|
-
- **滚动窗口 (5h)**:`剩余 70% · 约
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- 面板头部只给判断性摘要「最紧张
|
|
13
|
+
- **滚动窗口 (5h)**:`剩余 70% · 约 13h 后耗尽 · ⏱ 4h20m`
|
|
14
|
+
- **周窗口**:周额度剩余 % + 可用时长估算 + ⏱ 重置倒计时
|
|
15
|
+
- **月窗口**:月额度剩余 % + 可用时长估算 + ⏱ 重置倒计时
|
|
16
|
+
- 面板头部只给判断性摘要「最紧张 月窗口」(取剩余最小的窗口,用中文窗口名而不是悬浮卡的紧凑缩写),**不带百分比**——数字只在该窗口行出现一次,悬停摘要可看具体数值。
|
|
17
17
|
- **可用时长估算(按当前速率,仅供参考)**:窗口行会顺带告诉你「按现在的用法还能撑多久」。三种状态严格区分,不存在第四种:
|
|
18
|
-
- `约
|
|
18
|
+
- `约 13h 后耗尽`(警告色):按当前速率会在窗口重置前用完;
|
|
19
19
|
- `可支撑到重置`(中性色):按当前速率能撑到重置,此时不再显示具体时长;
|
|
20
|
-
-
|
|
20
|
+
- **采样中**:已有采样点但还攒不够(少于 3 个点,或首尾跨度不足 10 分钟)时显示「采样中」,`title` 给出已有几个点、跨了多少分钟。它只是状态说明,不含任何数字,用来区分「功能没加载」和「还在攒数据」。
|
|
21
|
+
- **不显示**:速率为 0、剩余为 0、重置时间缺失或已过期时,这个位置直接不出现,也不用「--」「0m」之类占位凑数。
|
|
21
22
|
- 鼠标悬停会说明依据:「按最近 N 分钟的消耗速率估算(按当前速率),仅供参考」。它是对已有采样点的机械外推(只用首尾两点,不做回归),**不是预测或承诺**。
|
|
23
|
+
- 时长按两位有效数字粗化:<1h 取 5 分钟、1–10h 取 30 分钟、≥10h 取 1 小时、≥48h 取 1 天。上游只有整数百分比,分钟级精度属于虚假精确,粗化后不再暗示比实际更准。
|
|
22
24
|
- 采样只存在于页面打开期间的内存里(每窗口最近 60 分钟、最多 120 个点),刷新页面即清空,需要重新积累约 10 分钟才可能再次出现;上游只给整数百分比,样本不足时宁可不出数,也不给看起来精确的假时长。
|
|
23
25
|
- 纯前端计算:不新增网络请求、不新增依赖,数据仍只来自既有的 30 秒轮询与手动刷新。220ms 悬浮微卡不显示估算(一行放不下五项,缩字号或截断都不可接受,因此有意省略)。
|
|
24
26
|
- **可访问性与键盘交互**:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-opencode-status",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "OpenCode GO quota status panel for DeepSeek Harness: click to open a usage panel with manual refresh, per-window remaining quota, a hover overview card, and in-app connection settings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
package/src/client.js
CHANGED
|
@@ -244,6 +244,20 @@ window.__ModuleLoader__.load({
|
|
|
244
244
|
return `${days}d${hours % 24 ? `${hours % 24}h` : ''}`
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
+
/**
|
|
248
|
+
* 估算值粗化:上游只给整数 percent,量化误差会让 ETA 的真实区间比点值宽 2-3 倍,
|
|
249
|
+
* 分钟级精度属于虚假精确。按「两位有效数字」粗化,既保留量级又不再暗示精度:
|
|
250
|
+
* <1h 取 5 分钟、1-10h 取 30 分钟、≥10h 取 1 小时、≥48h 取 1 天。
|
|
251
|
+
*/
|
|
252
|
+
function coarsenEta(ms) {
|
|
253
|
+
const minutes = ms / 60_000
|
|
254
|
+
if (minutes < 60) return Math.max(5, Math.round(minutes / 5) * 5) * 60_000
|
|
255
|
+
if (minutes < 600) return Math.round(minutes / 30) * 30 * 60_000
|
|
256
|
+
const hours = minutes / 60
|
|
257
|
+
if (hours < 48) return Math.round(hours) * 3_600_000
|
|
258
|
+
return Math.round(hours / 24) * 86_400_000
|
|
259
|
+
}
|
|
260
|
+
|
|
247
261
|
/**
|
|
248
262
|
* 估算文案的三态:不可估算返回 null(调用方完全不渲染节点,不显示 "--"/"估算中" 之类占位);
|
|
249
263
|
* 撑不到重置用告警色「约 X 后耗尽」,撑得到用中性色「可支撑到重置」。
|
|
@@ -257,15 +271,28 @@ window.__ModuleLoader__.load({
|
|
|
257
271
|
function etaView(w, options = {}) {
|
|
258
272
|
if (options?.compact) return null
|
|
259
273
|
const entry = etaSamples.get(w?.id)
|
|
260
|
-
if (!entry) return null
|
|
274
|
+
if (!entry || !entry.samples.length) return null
|
|
261
275
|
const estimate = estimateEta(entry.samples, w?.remainingPct, w?.resetAt)
|
|
262
|
-
if (!estimate)
|
|
276
|
+
if (!estimate) {
|
|
277
|
+
// 「采样中」只在样本数或跨度还不够时出现:让用户能区分「功能没加载」与「还在攒数据」。
|
|
278
|
+
// 速率 0、剩余 0、重置缺失或已过期都不是采样问题,仍然什么都不显示。
|
|
279
|
+
const samples = entry.samples
|
|
280
|
+
const span = samples[samples.length - 1].at - samples[0].at
|
|
281
|
+
if (samples.length >= ETA_MIN_SAMPLES && span >= ETA_MIN_SPAN_MS) return null
|
|
282
|
+
if (typeof w?.remainingPct !== 'number' || w.remainingPct <= 0) return null
|
|
283
|
+
if (!w?.resetAt || w.resetAt <= Date.now()) return null
|
|
284
|
+
return {
|
|
285
|
+
text: '采样中',
|
|
286
|
+
color: T.secondary,
|
|
287
|
+
title: `正在积累采样:已有 ${samples.length} 个点、跨度约 ${Math.max(1, Math.round(span / 60_000))} 分钟;需要 ${ETA_MIN_SAMPLES} 个点且跨度满 ${ETA_MIN_SPAN_MS / 60_000} 分钟`,
|
|
288
|
+
}
|
|
289
|
+
}
|
|
263
290
|
const minutes = Math.max(1, Math.round(estimate.spanMs / 60_000))
|
|
264
291
|
// 文案只说「按最近 N 分钟的消耗速率(按当前速率)」的实测依据,不写「预计/将」这类预测口吻。
|
|
265
292
|
const title = `按最近 ${minutes} 分钟的消耗速率估算(按当前速率),仅供参考`
|
|
266
293
|
// 保留完整字面「约 X 后耗尽」:真实 Chrome 实测在 326px/262px 内容宽下都不会截断,只会让标签多收缩。
|
|
267
294
|
return estimate.exhaustsBeforeReset
|
|
268
|
-
? { text: `约 ${fmtEtaDuration(estimate.etaMs)} 后耗尽`, color: T.warn, title }
|
|
295
|
+
? { text: `约 ${fmtEtaDuration(coarsenEta(estimate.etaMs))} 后耗尽`, color: T.warn, title }
|
|
269
296
|
: { text: '可支撑到重置', color: T.secondary, title }
|
|
270
297
|
}
|
|
271
298
|
|
|
@@ -434,6 +461,9 @@ window.__ModuleLoader__.load({
|
|
|
434
461
|
}
|
|
435
462
|
}, [])
|
|
436
463
|
|
|
464
|
+
// 卸载时清掉待触发的悬停定时器,避免 220ms 后对已卸载组件 setState。
|
|
465
|
+
useEffect(() => () => clearTimeout(hoverTimerRef.current), [])
|
|
466
|
+
|
|
437
467
|
const onMouseEnter = () => {
|
|
438
468
|
clearTimeout(hoverTimerRef.current)
|
|
439
469
|
hoverTimerRef.current = setTimeout(() => setHovering(true), 220)
|
|
@@ -690,7 +720,8 @@ window.__ModuleLoader__.load({
|
|
|
690
720
|
return h('div', null, [
|
|
691
721
|
h('div', { key: 'sum', style: { display: 'flex', alignItems: 'center', gap: 6 } }, [
|
|
692
722
|
h('span', { key: 'd', style: dotStyle(st.ok ? T.ok : T.err) }),
|
|
693
|
-
|
|
723
|
+
// 窄视口下让标题让位给右侧摘要:摘要 flexShrink:0,标题可省略。
|
|
724
|
+
h('span', { key: 't', style: { fontSize: 12, fontWeight: 600, color: T.label, minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', flexShrink: 1 } }, st.ok ? '已连接' : '异常'),
|
|
694
725
|
tightest
|
|
695
726
|
? h(
|
|
696
727
|
'span',
|
|
@@ -700,7 +731,9 @@ window.__ModuleLoader__.load({
|
|
|
700
731
|
title: `最紧张窗口:${tightest.label ?? tightest.id ?? '—'},剩余 ${pctText(tightest.remainingPct)}`,
|
|
701
732
|
style: { marginLeft: 'auto', fontSize: 11, fontWeight: 600, color: remainingColor(tightest.remainingPct), fontVariantNumeric: 'tabular-nums', flexShrink: 0 },
|
|
702
733
|
},
|
|
703
|
-
|
|
734
|
+
// 用 label 而不是 shortLabel:shortLabel 是给 220px 悬浮微卡的窄列设计的紧凑缩写,
|
|
735
|
+
// 复用到这里会把「Weekly / Monthly」这类英文缩写漏进主面板。
|
|
736
|
+
`最紧张 ${tightest.label ?? tightest.id ?? '—'}`,
|
|
704
737
|
)
|
|
705
738
|
: null,
|
|
706
739
|
].filter(Boolean)),
|
|
@@ -935,6 +968,7 @@ window.__ModuleLoader__.load({
|
|
|
935
968
|
h(
|
|
936
969
|
'button',
|
|
937
970
|
{
|
|
971
|
+
key: 'refresh',
|
|
938
972
|
className: 'oc-btn',
|
|
939
973
|
style: btnBase,
|
|
940
974
|
disabled: state.refreshing,
|
|
@@ -1126,7 +1160,7 @@ window.__ModuleLoader__.load({
|
|
|
1126
1160
|
exports.apply = apply
|
|
1127
1161
|
exports.inject = ['slots']
|
|
1128
1162
|
// 仅供测试与诊断:估算/采样是纯函数 + 模块内状态,导出以便做真实单元测试(宿主侧不消费)。
|
|
1129
|
-
exports.__internal = { estimateEta, recordSamples, getSamples, resetEtaSamples, fmtEtaDuration, etaView }
|
|
1163
|
+
exports.__internal = { estimateEta, recordSamples, getSamples, resetEtaSamples, fmtEtaDuration, coarsenEta, etaView }
|
|
1130
1164
|
return module.exports
|
|
1131
1165
|
},
|
|
1132
1166
|
})
|
package/src/index.js
CHANGED
|
@@ -287,7 +287,7 @@ export function apply(ctx, config = {}) {
|
|
|
287
287
|
{
|
|
288
288
|
id: 'weekly',
|
|
289
289
|
label: '周窗口',
|
|
290
|
-
shortLabel: '
|
|
290
|
+
shortLabel: '周',
|
|
291
291
|
...pctPair(u.weekly?.percent),
|
|
292
292
|
status: u.weekly?.status ?? 'ok',
|
|
293
293
|
resetAt: u.weekly?.resetsAt ? Date.parse(u.weekly.resetsAt) : null,
|
|
@@ -295,7 +295,7 @@ export function apply(ctx, config = {}) {
|
|
|
295
295
|
{
|
|
296
296
|
id: 'monthly',
|
|
297
297
|
label: '月窗口',
|
|
298
|
-
shortLabel: '
|
|
298
|
+
shortLabel: '月',
|
|
299
299
|
...pctPair(u.monthly?.percent),
|
|
300
300
|
status: u.monthly?.status ?? 'ok',
|
|
301
301
|
resetAt: u.monthly?.resetsAt ? Date.parse(u.monthly.resetsAt) : null,
|