dsh-opencode-status 0.2.3 → 0.3.0
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 +16 -0
- package/README.md +18 -11
- package/package.json +2 -2
- package/src/client.js +435 -180
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
- 重构点击交互:侧栏常驻按钮改为打开用量面板(默认用量视图),不再直接弹出连接配置表单;参考 dsh-cpa-status 的双视图范式。
|
|
6
|
+
- 用量面板新增固定底部操作条:`↻ 刷新` 通过 `POST /api/opencode-status/sync` 绕过 30 秒缓存强制重新拉取当前剩余额度(带 `content-type: application/json`,刷新期间按钮禁用并显示旋转 +「刷新中…」),完成后侧栏与面板数值同步更新;右侧固定展示「上次同步 HH:MM:SS」(取 `status.fetchedAt`)。刷新失败时在面板内显示错误文案,不再静默。
|
|
7
|
+
- 设置改为面板内的独立视图(Base URL + API Key),底部 `⚙ 设置` 进入、`← 返回用量` 退出;保存成功后自动回到用量视图。`mode === 'needs_config'` 时面板直接显示设置视图;「取消」保持 0.2.3 语义:丢弃未保存的编辑并关闭面板。
|
|
8
|
+
- 用量面板的三个窗口行同时给出已用 % 与剩余 %、重置倒计时和进度条;颜色按剩余额度阈值(>50 正常、>20 警告、其余错误)着色,与 cpa 的 QuotaBar 语义一致;窗口 `status` 非 `ok` 时给出可见提示。
|
|
9
|
+
- 重新设计 220ms 悬浮微卡:标题 + GO 标识 + 最近同步时间,三个窗口的紧凑行(名称 / 剩余 % / ↻ 重置倒计时 / 细进度条),底部「点击查看详情」;卡片为纯展示(无假按钮),并设置 `pointer-events: none` 不遮挡 footer 按钮的点击。
|
|
10
|
+
- 侧栏常驻按钮按剩余额度着色(>50 正常、>20 警告、否则错误),文案改为「月剩余 N%」摘要;rail 模式(`wide === false`)渲染为真正的 `button`(键盘可达),点击同样打开用量视图。
|
|
11
|
+
- 保留 30 秒 GET 自动刷新;打开面板 / 切换视图只走 30 秒缓存,不触发额外的上游探测,手动刷新是唯一绕过缓存的入口。
|
|
12
|
+
- 测试目录新增 `test/index.js` 目录入口垫片:Node 22.23 的 `node --test <dir>` 不再展开目录参数,垫片让 `node --test dsh-plugins/dsh-opencode-status/test/` 与 `node --test` 两种调用方式都能执行同一套用例。
|
|
13
|
+
- 明确额度语义:上游 `/v1/usage` 只返回 rolling/weekly/monthly 百分比,没有 USD 余额接口(anomalyco/opencode#10448 仍 open),面板只表述「剩余额度 / 可用百分比」,不编造金额。
|
|
14
|
+
- store 用 `view: 'status' | 'settings'` 表达面板视图,不引入已废弃的 `editing` 标识。
|
|
15
|
+
- 修复评审 F2/F3:手动刷新发起时推进请求序号 `statusEpoch`,更早发出的在途 GET 响应(含失败)不再覆盖 `store.status` / `store.error`,手动刷新自身结果仍正常落库,30 秒轮询行为不变;设置视图的「← 返回用量」在 status 尚未加载(null)时也可见,仅 `mode === 'needs_config'` 时隐藏。
|
|
16
|
+
- 测试更新:新增刷新按钮 `POST /sync` 且带 JSON 内容类型、设置入口与视图切换、悬浮卡上次同步、侧栏着色与 rail button、剩余额度阈值着色、窗口异常提示、版本号与文档一致性断言;原有安全与配置用例保持通过(共 35 个用例,含最小 React stub 下的客户端加载、rail button、设置视图返回入口冒烟,以及 F2 的静态断言与「旧 GET 在 POST 之后返回/失败」运行时竞态回归)。
|
|
17
|
+
- 版本号升至 `0.3.0`;README 的功能特性与配置说明同步更新。
|
|
18
|
+
|
|
3
19
|
## 0.2.3
|
|
4
20
|
|
|
5
21
|
- 修复配置面板「取消」按钮点击无反应:该按钮此前只翻转 `editing` 标记,而 0.1.5 的弹窗重构之后已没有任何渲染逻辑读取它。现在「取消」会丢弃未保存的编辑并关闭面板,重新打开时表单从已保存配置重新渲染。
|
package/README.md
CHANGED
|
@@ -1,23 +1,28 @@
|
|
|
1
1
|
# dsh-opencode-status
|
|
2
2
|
|
|
3
|
-
OpenCode GO 套餐用量与配额状态监控面板插件(DeepSeek Harness
|
|
3
|
+
OpenCode GO 套餐用量与配额状态监控面板插件(DeepSeek Harness):侧栏常驻极简单行胶囊按钮,点击即打开用量面板,查看 5h 滚动窗口、周窗口、月窗口的剩余额度与重置倒计时,并可手动刷新或进入独立设置视图。
|
|
4
4
|
|
|
5
5
|
## 功能特性
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
7
|
+
- **点击打开用量面板**:侧栏常驻按钮(`● OpenCode · 月剩余 70%`)点击后打开的是用量面板(默认用量视图),不再是只弹出连接配置表单;按剩余额度着色(>50 正常、>20 警告、其余错误),rail 模式下同样是可点击的真按钮。
|
|
8
|
+
- **固定底部操作条**:
|
|
9
|
+
- `↻ 刷新`:通过 `POST /api/opencode-status/sync` 绕过 30 秒缓存,强制重新拉取当前剩余额度;刷新期间按钮禁用并显示旋转与「刷新中…」,完成后面板与侧栏数值同步更新,失败时在面板内显示错误文案而不是静默。
|
|
10
|
+
- `⚙ 设置`:进入面板内的独立连接设置视图,可随时 `← 返回用量`。
|
|
11
|
+
- 右侧固定显示「上次同步 HH:MM:SS」(取 `status.fetchedAt`)。
|
|
12
|
+
- **3 维度用量行**:每行同时给出已用 % 与剩余 %、重置倒计时和进度条,颜色按剩余额度阈值着色(与 dsh-cpa-status 的 QuotaBar 语义一致);窗口状态非 `ok` 时给出可见提示。
|
|
13
|
+
- **滚动窗口 (5h)**:`已用 30% · 剩余 70% · ↻ 4h20m`
|
|
14
|
+
- **周窗口 (Weekly)**:周额度消耗与剩余 % + 重置倒计时
|
|
15
|
+
- **月窗口 (Monthly)**:月额度消耗与剩余 % + 重置倒计时
|
|
16
|
+
- **连接设置视图**:未配置(`mode === 'needs_config'`)时面板直接显示设置视图;保存成功后自动回到用量视图;「取消」丢弃未保存的编辑并关闭面板。密钥仅存入宿主凭据库(`OPENCODE_GO_API_KEY`),API 响应不回传明文。
|
|
17
|
+
- **220ms 悬浮微卡**:鼠标悬停常驻按钮 220ms 后在面板关闭且连接正常时出现,展示标题 + GO 标识 + 最近同步时间、三个窗口的紧凑行(名称 / 剩余 % / ↻ 重置倒计时 / 细进度条)与底部「点击查看详情」;纯展示卡片,不拦截按钮点击。
|
|
18
|
+
- **缓存与刷新**:服务端 30 秒缓存 + 客户端 30 秒自动刷新;打开面板、切换视图不会额外探测上游,手动刷新是唯一绕过缓存的入口。
|
|
19
|
+
- **额度语义**:上游 `/v1/usage` 只提供 rolling/weekly/monthly 百分比,没有 USD 余额接口([anomalyco/opencode#10448](https://github.com/anomalyco/opencode/issues/10448) 仍 open),因此界面只展示「剩余额度 / 可用百分比」,不编造金额余额。
|
|
15
20
|
|
|
16
21
|
## 安装与更新
|
|
17
22
|
|
|
18
23
|
### 兼容性(DSH 0.2.x)
|
|
19
24
|
|
|
20
|
-
- 本版本(`0.
|
|
25
|
+
- 本版本(`0.3.x`)面向 **DeepSeek Harness 0.2.x**,已在 `0.2.2-rc.1` 上验证;`package.json` 通过 `engines.dsh: ">=0.2.0 <0.3.0-0"` 声明兼容范围(上界带 `-0` 显式排除 0.3.0 的预发布版;宿主用 semver `includePrerelease` 校验,已用其 `evaluatePluginCompatibility` 验证 `0.2.2-rc.1` 为 COMPATIBLE、`0.3.0-rc.1`/`0.3.0-rc.2`/`0.3.0` 为 UNMET)。
|
|
21
26
|
- DSH 0.2.x 移除了旧的插件配置注册接口,改为读取插件导出的 schemastery `Config`:`baseUrl`、`keyRef` 声明为 `volatile` 字段,由宿主生成配置表单并以 live ref 传入 `apply(ctx, config)`。因此 `0.1.x` 及更早版本在 DSH 0.2.x 上无法激活,请升级到 `0.2.0` 或更高版本。
|
|
22
27
|
- 升级方式:先把 DSH 升级到 0.2.x,再执行下面的安装命令(默认拉取 `@latest`),然后重启 `dsh web`。Base URL 会以插件配置写入当前 profile 的 `cordis.patch.yml`,API Key 仍保存在宿主凭据库,无需迁移。
|
|
23
28
|
|
|
@@ -46,10 +51,12 @@ dsh plugin --profile web remove dsh-opencode-status
|
|
|
46
51
|
|
|
47
52
|
## 配置
|
|
48
53
|
|
|
49
|
-
|
|
54
|
+
点侧栏常驻按钮打开用量面板,再点面板底部「⚙ 设置」进入连接设置视图;未配置时面板会直接显示设置视图:
|
|
50
55
|
- **Base URL**:默认 `https://opencode.ai/zen/go`(也可用环境变量 `OPENCODE_BASE_URL` 提供未持久化时的默认值)
|
|
51
56
|
- **API Key**:粘贴你的 OpenCode API Key(亦可直接在环境变量中配置 `OPENCODE_GO_API_KEY`)
|
|
52
57
|
|
|
58
|
+
保存成功后自动回到用量视图;「取消」丢弃未保存的编辑并关闭面板,重新打开时表单从已保存配置重新渲染。
|
|
59
|
+
|
|
53
60
|
配置存储方式(DSH 0.2.x):
|
|
54
61
|
- **Base URL** 属于插件 `Config` 的 `volatile` 字段:修改时通过宿主的 settings 服务写回当前 profile 条目(`opencode-status`),重启后依然生效;宿主未提供 settings 服务时,修改 Base URL 会返回明确的错误响应,插件不会崩溃。
|
|
55
62
|
- **API Key** 只写入宿主凭据库(默认引用 `OPENCODE_GO_API_KEY`),HTTP 响应仅返回 `••••` 掩码提示,不回传明文。
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-opencode-status",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "OpenCode GO quota
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
7
7
|
"keywords": [
|
package/src/client.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* dsh-opencode-status — Client half.
|
|
2
|
+
* dsh-opencode-status — Client half (0.3.0).
|
|
3
3
|
*
|
|
4
4
|
* 槽位:
|
|
5
|
-
* sidebar.footer.action
|
|
6
|
-
* shell.overlay
|
|
5
|
+
* sidebar.footer.action 常驻紧凑按钮(状态灯 + 月剩余摘要;点击打开用量面板)
|
|
6
|
+
* shell.overlay 用量面板(状态视图:三个窗口 + 固定操作条;设置视图:Base URL / API Key)
|
|
7
|
+
*
|
|
8
|
+
* 上游 /v1/usage 只提供 rolling/weekly/monthly 百分比,没有 USD 余额接口
|
|
9
|
+
* (anomalyco/opencode#10448 仍 open),界面只表述「剩余额度 / 可用百分比」,不编造金额。
|
|
7
10
|
*/
|
|
8
11
|
window.__ModuleLoader__.load({
|
|
9
12
|
id: 'dsh-opencode-status',
|
|
@@ -22,14 +25,17 @@ window.__ModuleLoader__.load({
|
|
|
22
25
|
@keyframes ocPulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.45) } 70% { box-shadow: 0 0 0 5px rgba(34,197,94,0) } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0) } }
|
|
23
26
|
.oc-panel-enter { animation: ocFadeSlideUp .2s cubic-bezier(.2,.9,.3,1.2) both }
|
|
24
27
|
.oc-panel-exit { animation: ocFadeSlideDown .15s ease-in both; pointer-events: none !important }
|
|
25
|
-
.oc-btn { min-width: 0; transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease }
|
|
26
|
-
.oc-btn:hover:not(:disabled)
|
|
27
|
-
.oc-btn-primary:hover:not(:disabled) { filter: brightness(1.12) }
|
|
28
|
+
.oc-btn { min-width: 0; transition: background .15s ease, border-color .15s ease, color .15s ease, transform .1s ease, opacity .15s ease }
|
|
29
|
+
.oc-btn:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, var(--dsw-alias-bg-layer-1)); border-color: var(--dsw-alias-border-l2) }
|
|
28
30
|
.oc-btn:active:not(:disabled) { transform: scale(.98) }
|
|
31
|
+
.oc-btn:disabled { opacity: .55; cursor: default }
|
|
29
32
|
.oc-spin { display: inline-block; animation: ocSpin .8s linear infinite }
|
|
30
33
|
.oc-dot-live { animation: ocPulse 2.4s ease-out infinite }
|
|
34
|
+
/* 悬浮微卡只读:不接收任何指针事件,避免遮挡 footer 按钮的点击 */
|
|
35
|
+
.oc-hover-card { pointer-events: none !important }
|
|
31
36
|
@media (prefers-reduced-motion: reduce) {
|
|
32
37
|
.oc-panel-enter, .oc-panel-exit, .oc-spin, .oc-dot-live { animation: none !important }
|
|
38
|
+
.oc-btn { transition: none !important }
|
|
33
39
|
}
|
|
34
40
|
`
|
|
35
41
|
|
|
@@ -85,6 +91,8 @@ window.__ModuleLoader__.load({
|
|
|
85
91
|
outline: 'none',
|
|
86
92
|
}
|
|
87
93
|
|
|
94
|
+
const labelStyle = { display: 'block', fontSize: 12, color: T.secondary, marginBottom: 4 }
|
|
95
|
+
|
|
88
96
|
function timeUntil(ts) {
|
|
89
97
|
if (!ts) return ''
|
|
90
98
|
const diff = ts - Date.now()
|
|
@@ -96,17 +104,49 @@ window.__ModuleLoader__.load({
|
|
|
96
104
|
return `${Math.floor(hours / 24)}d${hours % 24 ? `${hours % 24}h` : ''}`
|
|
97
105
|
}
|
|
98
106
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
107
|
+
/** 同步时间显示为 HH:MM:SS(本地时区,取 status.fetchedAt)。 */
|
|
108
|
+
function fmtClock(ts) {
|
|
109
|
+
if (!ts) return ''
|
|
110
|
+
const d = new Date(ts)
|
|
111
|
+
const pad = (n) => String(n).padStart(2, '0')
|
|
112
|
+
return `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** 剩余额度阈值着色:>50 正常、>20 警告、其余错误(与 cpa 的 QuotaBar 语义一致)。 */
|
|
116
|
+
function remainingColor(remaining) {
|
|
117
|
+
if (remaining === null || remaining === undefined) return T.secondary
|
|
118
|
+
if (remaining > 50) return T.ok
|
|
119
|
+
if (remaining > 20) return T.warn
|
|
120
|
+
return T.err
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function clampPct(value) {
|
|
124
|
+
return Math.max(0, Math.min(100, value))
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 月窗口剩余百分比;上游只给百分比,不存在金额余额。 */
|
|
128
|
+
function monthlyRemainingOf(status) {
|
|
129
|
+
if (!status) return null
|
|
130
|
+
const windows = Array.isArray(status.windows) ? status.windows : []
|
|
131
|
+
const monthly = windows.find((w) => w?.id === 'monthly')
|
|
132
|
+
if (monthly && typeof monthly.remainingPct === 'number') return monthly.remainingPct
|
|
133
|
+
if (typeof status.monthlyUsedPct === 'number') return Math.max(0, 100 - status.monthlyUsedPct)
|
|
134
|
+
return null
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function hostOf(url) {
|
|
138
|
+
try {
|
|
139
|
+
return new URL(url).host
|
|
140
|
+
} catch {
|
|
141
|
+
return url
|
|
142
|
+
}
|
|
104
143
|
}
|
|
105
144
|
|
|
106
145
|
// ---------- Store ----------
|
|
107
146
|
const store = {
|
|
108
147
|
state: {
|
|
109
148
|
open: false,
|
|
149
|
+
view: 'status', // 'status' 用量视图 | 'settings' 连接设置视图
|
|
110
150
|
status: null,
|
|
111
151
|
config: null,
|
|
112
152
|
refreshing: false,
|
|
@@ -127,6 +167,7 @@ window.__ModuleLoader__.load({
|
|
|
127
167
|
return React.useSyncExternalStore(store.subscribe, () => store.state)
|
|
128
168
|
}
|
|
129
169
|
|
|
170
|
+
// ---------- 本机 API ----------
|
|
130
171
|
async function api(path, options) {
|
|
131
172
|
const res = await fetch(path, options)
|
|
132
173
|
const data = await res.json().catch(() => ({}))
|
|
@@ -134,18 +175,29 @@ window.__ModuleLoader__.load({
|
|
|
134
175
|
return data
|
|
135
176
|
}
|
|
136
177
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
178
|
+
// 请求序号:手动刷新会推进 epoch,使所有更早发出的 GET 响应(成功或失败)失效,
|
|
179
|
+
// 避免极端时序下旧数据覆盖手动刷新的新结果。
|
|
180
|
+
let statusEpoch = 0
|
|
181
|
+
|
|
182
|
+
/** GET 状态:走宿主 30 秒缓存,打开面板/切换视图都不会额外探测上游。 */
|
|
183
|
+
let statusInFlight = null
|
|
184
|
+
async function refreshStatus() {
|
|
185
|
+
// 并发去重:挂载、打开面板与 30s 轮询同时触发时只发一个 GET,避免首个请求未写入缓存前重复探测。
|
|
186
|
+
if (store.state.refreshing) return
|
|
187
|
+
if (statusInFlight) return statusInFlight
|
|
188
|
+
const epoch = statusEpoch
|
|
189
|
+
statusInFlight = (async () => {
|
|
190
|
+
try {
|
|
191
|
+
const status = await api('/api/opencode-status')
|
|
192
|
+
// 只接受最新 epoch 的响应:手动刷新之后返回的在途 GET 一律丢弃。
|
|
193
|
+
if (epoch === statusEpoch) store.set({ status, error: null })
|
|
194
|
+
} catch (err) {
|
|
195
|
+
if (epoch === statusEpoch) store.set({ error: String(err?.message ?? err) })
|
|
196
|
+
} finally {
|
|
197
|
+
statusInFlight = null
|
|
198
|
+
}
|
|
199
|
+
})()
|
|
200
|
+
return statusInFlight
|
|
149
201
|
}
|
|
150
202
|
|
|
151
203
|
async function refreshConfig() {
|
|
@@ -155,15 +207,56 @@ window.__ModuleLoader__.load({
|
|
|
155
207
|
} catch {}
|
|
156
208
|
}
|
|
157
209
|
|
|
158
|
-
|
|
210
|
+
/** 手动刷新唯一入口:绕过 30 秒缓存,强制重新拉取当前剩余额度。 */
|
|
211
|
+
async function manualRefresh() {
|
|
212
|
+
if (store.state.refreshing) return
|
|
213
|
+
// 先推进序号:手动刷新发起后,任何更早发出的在途 GET 响应都不再落库。
|
|
214
|
+
statusEpoch += 1
|
|
215
|
+
store.set({ refreshing: true, error: null })
|
|
216
|
+
try {
|
|
217
|
+
const status = await api('/api/opencode-status/sync', {
|
|
218
|
+
method: 'POST',
|
|
219
|
+
headers: { 'content-type': 'application/json' },
|
|
220
|
+
})
|
|
221
|
+
// 手动刷新自身的响应始终落库(刷新期间已阻止新的 GET)。
|
|
222
|
+
store.set({ status, error: null })
|
|
223
|
+
} catch (err) {
|
|
224
|
+
store.set({ error: String(err?.message ?? err) })
|
|
225
|
+
} finally {
|
|
226
|
+
store.set({ refreshing: false })
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function openOverlay() {
|
|
231
|
+
store.set({ open: true, view: 'status' })
|
|
232
|
+
// 面板默认落用量视图;GET 命中 30 秒缓存,不触发额外上游探测。
|
|
233
|
+
refreshStatus()
|
|
234
|
+
refreshConfig()
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function closeOverlay() {
|
|
238
|
+
store.set({ open: false })
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function toggleOverlay() {
|
|
242
|
+
if (store.state.open) closeOverlay()
|
|
243
|
+
else openOverlay()
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function openSettings() {
|
|
247
|
+
refreshConfig()
|
|
248
|
+
store.set({ view: 'settings' })
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// ---------- 常驻入口(状态灯 + 月剩余摘要 + 220ms 悬浮微卡) ----------
|
|
159
252
|
function FooterEntry(props) {
|
|
160
253
|
const state = useStore()
|
|
161
254
|
const [hovering, setHovering] = useState(false)
|
|
162
255
|
const hoverTimerRef = useRef(null)
|
|
163
256
|
|
|
164
257
|
useEffect(() => {
|
|
165
|
-
refreshStatus(
|
|
166
|
-
const timer = setInterval(() => refreshStatus(
|
|
258
|
+
refreshStatus()
|
|
259
|
+
const timer = setInterval(() => refreshStatus(), 30_000)
|
|
167
260
|
return () => clearInterval(timer)
|
|
168
261
|
}, [])
|
|
169
262
|
|
|
@@ -177,95 +270,117 @@ window.__ModuleLoader__.load({
|
|
|
177
270
|
}
|
|
178
271
|
|
|
179
272
|
const st = state.status
|
|
273
|
+
const monthlyRemaining = monthlyRemainingOf(st)
|
|
180
274
|
let color = T.warn
|
|
181
|
-
let
|
|
275
|
+
let label = '连接 OpenCode'
|
|
182
276
|
let value = null
|
|
183
277
|
|
|
184
278
|
if (state.error) {
|
|
185
279
|
color = T.err
|
|
186
|
-
|
|
280
|
+
label = 'OpenCode ?'
|
|
281
|
+
} else if (st?.mode === 'needs_config') {
|
|
282
|
+
color = T.warn
|
|
283
|
+
label = 'OpenCode'
|
|
284
|
+
value = '未配置'
|
|
187
285
|
} else if (st?.mode === 'ready') {
|
|
188
286
|
if (st.ok) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
value = pct !== null ? `月用量 ${pct}%` : '在线'
|
|
287
|
+
color = monthlyRemaining === null ? T.warn : remainingColor(monthlyRemaining)
|
|
288
|
+
label = 'OpenCode'
|
|
289
|
+
value = monthlyRemaining !== null ? `月剩余 ${monthlyRemaining}%` : '在线'
|
|
193
290
|
} else {
|
|
194
291
|
color = T.err
|
|
195
|
-
|
|
292
|
+
label = 'OpenCode'
|
|
196
293
|
value = '异常'
|
|
197
294
|
}
|
|
198
295
|
}
|
|
199
296
|
|
|
297
|
+
const title = state.error
|
|
298
|
+
? `本机状态接口异常:${state.error}`
|
|
299
|
+
: st?.mode === 'needs_config'
|
|
300
|
+
? '尚未配置 OpenCode API Key,点击设置'
|
|
301
|
+
: st?.mode === 'ready' && !st.ok
|
|
302
|
+
? `用量拉取异常:${st.error?.message ?? '未知错误'}`
|
|
303
|
+
: monthlyRemaining !== null
|
|
304
|
+
? `OpenCode GO · 月剩余 ${monthlyRemaining}% · 点击查看详情`
|
|
305
|
+
: 'OpenCode GO,点击查看详情'
|
|
306
|
+
|
|
307
|
+
// rail 模式:真正的 button(键盘可达、可点击),同样打开用量视图
|
|
200
308
|
if (props?.wide === false) {
|
|
201
309
|
return h(
|
|
202
|
-
'
|
|
310
|
+
'button',
|
|
203
311
|
{
|
|
204
|
-
className: 'oc-btn',
|
|
312
|
+
className: 'oc-btn oc-footer-btn',
|
|
313
|
+
type: 'button',
|
|
314
|
+
title,
|
|
315
|
+
'aria-label': '打开 OpenCode GO 用量面板',
|
|
205
316
|
style: {
|
|
206
|
-
boxSizing: 'border-box',
|
|
207
317
|
width: 36,
|
|
208
318
|
height: 36,
|
|
209
319
|
display: 'flex',
|
|
210
320
|
alignItems: 'center',
|
|
211
321
|
justifyContent: 'center',
|
|
212
322
|
borderRadius: 8,
|
|
323
|
+
border: `1px solid ${color === T.err ? T.err : T.border}`,
|
|
324
|
+
background: 'transparent',
|
|
325
|
+
color,
|
|
213
326
|
fontSize: 10,
|
|
214
327
|
fontWeight: 700,
|
|
215
|
-
color: T.label,
|
|
216
328
|
cursor: 'pointer',
|
|
217
329
|
margin: '2px auto',
|
|
330
|
+
padding: 0,
|
|
331
|
+
fontVariantNumeric: 'tabular-nums',
|
|
218
332
|
},
|
|
219
|
-
|
|
220
|
-
onClick: () => store.set({ open: !state.open }),
|
|
333
|
+
onClick: toggleOverlay,
|
|
221
334
|
},
|
|
222
|
-
|
|
335
|
+
monthlyRemaining !== null ? `${monthlyRemaining}%` : 'GO',
|
|
223
336
|
)
|
|
224
337
|
}
|
|
225
338
|
|
|
339
|
+
const segments = [
|
|
340
|
+
{ text: label, color: T.label },
|
|
341
|
+
value ? { text: value, color } : null,
|
|
342
|
+
].filter(Boolean)
|
|
343
|
+
const labelEl = h(
|
|
344
|
+
'span',
|
|
345
|
+
{ style: { display: 'inline-flex', alignItems: 'center', lineHeight: '18px', whiteSpace: 'nowrap', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis' } },
|
|
346
|
+
segments.flatMap((s, i) =>
|
|
347
|
+
i === 0
|
|
348
|
+
? [h('span', { key: `s${i}`, style: { color: s.color, fontWeight: 500, flexShrink: 0 } }, s.text)]
|
|
349
|
+
: [
|
|
350
|
+
h('span', { key: `sep${i}`, style: { color: T.secondary, margin: '0 5px', opacity: 0.7, flexShrink: 0 } }, '·'),
|
|
351
|
+
h('span', { key: `s${i}`, style: { color: s.color, fontWeight: 500, fontVariantNumeric: 'tabular-nums', overflow: 'hidden', textOverflow: 'ellipsis' } }, s.text),
|
|
352
|
+
],
|
|
353
|
+
),
|
|
354
|
+
)
|
|
355
|
+
|
|
226
356
|
const node = h(
|
|
227
357
|
'button',
|
|
228
358
|
{
|
|
229
359
|
className: 'oc-btn oc-footer-btn',
|
|
360
|
+
type: 'button',
|
|
361
|
+
title,
|
|
230
362
|
onMouseEnter,
|
|
231
363
|
onMouseLeave,
|
|
232
364
|
style: {
|
|
233
365
|
...btnBase,
|
|
234
|
-
display:
|
|
235
|
-
width:
|
|
366
|
+
display: 'flex',
|
|
367
|
+
width: '100%',
|
|
236
368
|
boxSizing: 'border-box',
|
|
237
|
-
justifyContent:
|
|
369
|
+
justifyContent: 'flex-start',
|
|
238
370
|
margin: '2px 0',
|
|
239
371
|
minWidth: 0,
|
|
240
372
|
flexShrink: 0,
|
|
241
373
|
borderColor: state.open ? T.brand : T.border,
|
|
242
374
|
background: state.open ? 'var(--dsw-alias-interactive-bg-hover, rgba(59,130,246,.12))' : 'transparent',
|
|
243
375
|
},
|
|
244
|
-
onClick:
|
|
245
|
-
store.set({ open: !state.open })
|
|
246
|
-
if (!state.open) {
|
|
247
|
-
refreshStatus(false)
|
|
248
|
-
refreshConfig()
|
|
249
|
-
}
|
|
250
|
-
},
|
|
376
|
+
onClick: toggleOverlay,
|
|
251
377
|
},
|
|
252
378
|
h('span', { className: color === T.ok ? 'oc-dot-live' : undefined, style: dotStyle(color) }),
|
|
253
|
-
|
|
254
|
-
'span',
|
|
255
|
-
{ style: { display: 'inline-flex', alignItems: 'center', lineHeight: '18px', whiteSpace: 'nowrap', minWidth: 0, overflow: 'hidden', textOverflow: 'ellipsis' } },
|
|
256
|
-
[
|
|
257
|
-
h('span', { key: 't', style: { color: T.label, fontWeight: 500, flexShrink: 0 } }, text),
|
|
258
|
-
value
|
|
259
|
-
? [
|
|
260
|
-
h('span', { key: 'sep', style: { color: T.secondary, margin: '0 5px', opacity: 0.7, flexShrink: 0 } }, '·'),
|
|
261
|
-
h('span', { key: 'v', style: { color, fontWeight: 500, fontVariantNumeric: 'tabular-nums', overflow: 'hidden', textOverflow: 'ellipsis' } }, value),
|
|
262
|
-
]
|
|
263
|
-
: null,
|
|
264
|
-
].flat().filter(Boolean),
|
|
265
|
-
),
|
|
379
|
+
labelEl,
|
|
266
380
|
)
|
|
267
381
|
|
|
268
|
-
|
|
382
|
+
// 悬浮微卡:面板关闭、悬停 220ms、且 ready + ok 时才出现
|
|
383
|
+
if (!hovering || state.open || st?.mode !== 'ready' || !st.ok) return node
|
|
269
384
|
|
|
270
385
|
return h(
|
|
271
386
|
'div',
|
|
@@ -275,55 +390,156 @@ window.__ModuleLoader__.load({
|
|
|
275
390
|
onMouseLeave,
|
|
276
391
|
},
|
|
277
392
|
node,
|
|
278
|
-
h(
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
393
|
+
h(HoverCard, { status: st }),
|
|
394
|
+
)
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// ---------- 220ms 悬浮微卡(只读概览,无假按钮) ----------
|
|
398
|
+
function HoverCard(props) {
|
|
399
|
+
const st = props.status
|
|
400
|
+
const windows = Array.isArray(st?.windows) ? st.windows : []
|
|
401
|
+
return h(
|
|
402
|
+
'div',
|
|
403
|
+
{
|
|
404
|
+
className: 'oc-panel-enter oc-hover-card',
|
|
405
|
+
style: {
|
|
406
|
+
position: 'absolute',
|
|
407
|
+
left: 0,
|
|
408
|
+
right: 0,
|
|
409
|
+
bottom: 'calc(100% + 6px)',
|
|
410
|
+
pointerEvents: 'none',
|
|
411
|
+
background: T.bg,
|
|
412
|
+
border: `1px solid ${T.border2}`,
|
|
413
|
+
borderRadius: 10,
|
|
414
|
+
boxShadow: '0 8px 24px rgba(0,0,0,.18)',
|
|
415
|
+
padding: '10px 12px 8px',
|
|
416
|
+
fontSize: 11,
|
|
417
|
+
color: T.label,
|
|
418
|
+
zIndex: 100,
|
|
419
|
+
fontFamily: 'system-ui, -apple-system, sans-serif',
|
|
297
420
|
},
|
|
421
|
+
},
|
|
422
|
+
[
|
|
423
|
+
h('div', { key: 'hd', style: { display: 'flex', alignItems: 'center', gap: 6, marginBottom: 8 } }, [
|
|
424
|
+
h('span', { key: 't', style: { fontWeight: 600, fontSize: 12, color: T.label } }, 'OpenCode GO 用量'),
|
|
425
|
+
// Go 标识(纯展示徽章,不是按钮)
|
|
426
|
+
h(
|
|
427
|
+
'span',
|
|
428
|
+
{
|
|
429
|
+
key: 'go',
|
|
430
|
+
style: {
|
|
431
|
+
fontSize: 9,
|
|
432
|
+
fontWeight: 700,
|
|
433
|
+
letterSpacing: 0.4,
|
|
434
|
+
color: '#fff',
|
|
435
|
+
background: T.brand,
|
|
436
|
+
borderRadius: 4,
|
|
437
|
+
padding: '1px 5px',
|
|
438
|
+
lineHeight: '13px',
|
|
439
|
+
flexShrink: 0,
|
|
440
|
+
},
|
|
441
|
+
},
|
|
442
|
+
'GO',
|
|
443
|
+
),
|
|
444
|
+
h(
|
|
445
|
+
'span',
|
|
446
|
+
{ key: 'at', style: { marginLeft: 'auto', fontSize: 10, color: T.secondary, fontVariantNumeric: 'tabular-nums', flexShrink: 0 } },
|
|
447
|
+
st?.fetchedAt ? `上次同步 ${fmtClock(st.fetchedAt)}` : '尚未同步',
|
|
448
|
+
),
|
|
449
|
+
]),
|
|
298
450
|
h(
|
|
299
451
|
'div',
|
|
300
|
-
{
|
|
301
|
-
|
|
302
|
-
display: 'flex',
|
|
303
|
-
alignItems: 'center',
|
|
304
|
-
justifyContent: 'space-between',
|
|
305
|
-
marginBottom: 10,
|
|
306
|
-
},
|
|
307
|
-
},
|
|
308
|
-
h('span', { style: { fontWeight: 600, fontSize: '12px' } }, '🚀 OpenCode GO 用量概览'),
|
|
309
|
-
st.plan ? h('span', { style: { fontSize: '10px', color: T.brand, fontWeight: 600 } }, st.plan) : null,
|
|
452
|
+
{ key: 'rows', style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
|
453
|
+
windows.map((w, i) => h(MiniQuotaRow, { key: w.id ?? i, window: w })),
|
|
310
454
|
),
|
|
311
|
-
|
|
312
|
-
|
|
455
|
+
h(
|
|
456
|
+
'div',
|
|
457
|
+
{ key: 'hint', style: { marginTop: 8, paddingTop: 6, borderTop: `1px dashed ${T.border}`, fontSize: 10, color: T.secondary, textAlign: 'center' } },
|
|
458
|
+
'点击查看详情',
|
|
459
|
+
),
|
|
460
|
+
],
|
|
313
461
|
)
|
|
314
462
|
}
|
|
315
463
|
|
|
316
|
-
|
|
464
|
+
/** 悬浮卡紧凑行:名称 / 剩余 % / ↻ 重置倒计时 / 细进度条。 */
|
|
465
|
+
function MiniQuotaRow(props) {
|
|
466
|
+
const w = props.window
|
|
467
|
+
const remaining = w?.remainingPct ?? null
|
|
468
|
+
const color = remainingColor(remaining)
|
|
469
|
+
return h('div', { style: { display: 'flex', alignItems: 'center', gap: 6 } }, [
|
|
470
|
+
h('span', { key: 'n', style: { width: 46, flexShrink: 0, fontSize: 10, color: T.secondary, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, w?.shortLabel ?? w?.label ?? '—'),
|
|
471
|
+
h(
|
|
472
|
+
'div',
|
|
473
|
+
{ key: 'bar', style: { flex: 1, minWidth: 0, height: 3, borderRadius: 2, background: `color-mix(in srgb, ${color} 16%, transparent)`, overflow: 'hidden' } },
|
|
474
|
+
remaining === null
|
|
475
|
+
? null
|
|
476
|
+
: h('div', { style: { height: '100%', width: `${clampPct(remaining)}%`, background: color, borderRadius: 2 } }),
|
|
477
|
+
),
|
|
478
|
+
h('span', { key: 'v', style: { minWidth: 30, textAlign: 'right', fontSize: 10, fontWeight: 600, color, fontVariantNumeric: 'tabular-nums' } }, remaining === null ? '—' : `${remaining}%`),
|
|
479
|
+
h('span', { key: 'r', style: { minWidth: 34, textAlign: 'right', fontSize: 10, color: T.secondary, fontVariantNumeric: 'tabular-nums' } }, w?.resetAt ? `↻ ${timeUntil(w.resetAt)}` : ''),
|
|
480
|
+
])
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// ---------- 用量视图 ----------
|
|
484
|
+
function StatusView() {
|
|
485
|
+
const state = useStore()
|
|
486
|
+
const st = state.status
|
|
487
|
+
|
|
488
|
+
if (!st) {
|
|
489
|
+
return h('div', { style: { fontSize: 12, color: T.secondary } }, state.error ? `读取状态失败:${state.error}` : '加载中…')
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const windows = Array.isArray(st.windows) ? st.windows : []
|
|
493
|
+
const monthlyRemaining = monthlyRemainingOf(st)
|
|
494
|
+
const host = hostOf(st.config?.baseUrl)
|
|
495
|
+
|
|
496
|
+
return h('div', null, [
|
|
497
|
+
h('div', { key: 'sum', style: { display: 'flex', alignItems: 'center', gap: 6 } }, [
|
|
498
|
+
h('span', { key: 'd', style: dotStyle(st.ok ? T.ok : T.err) }),
|
|
499
|
+
h('span', { key: 't', style: { fontSize: 12, fontWeight: 600, color: T.label } }, st.ok ? 'OpenCode GO 已连接' : 'OpenCode GO 异常'),
|
|
500
|
+
host ? h('span', { key: 'h', style: { fontSize: 10, color: T.secondary, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, host) : null,
|
|
501
|
+
monthlyRemaining !== null
|
|
502
|
+
? h(
|
|
503
|
+
'span',
|
|
504
|
+
{ key: 'm', style: { marginLeft: 'auto', fontSize: 11, fontWeight: 600, color: remainingColor(monthlyRemaining), fontVariantNumeric: 'tabular-nums', flexShrink: 0 } },
|
|
505
|
+
`月剩余 ${monthlyRemaining}%`,
|
|
506
|
+
)
|
|
507
|
+
: null,
|
|
508
|
+
].filter(Boolean)),
|
|
509
|
+
state.error
|
|
510
|
+
? h('div', { key: 'ce', style: { fontSize: 11, color: T.err, marginTop: 8 } }, `刷新失败:${state.error}`)
|
|
511
|
+
: null,
|
|
512
|
+
!st.ok
|
|
513
|
+
? h('div', { key: 'se', style: { fontSize: 12, color: T.err, marginTop: 10 } }, st.error?.message ?? '网关返回异常,稍后重试')
|
|
514
|
+
: null,
|
|
515
|
+
st.ok && windows.length
|
|
516
|
+
? h('div', { key: 'w', style: { marginTop: 14 } }, windows.map((w, i) => h(QuotaRow, { key: w.id ?? i, window: w })))
|
|
517
|
+
: null,
|
|
518
|
+
st.ok && !windows.length
|
|
519
|
+
? h('div', { key: 'empty', style: { fontSize: 11, color: T.secondary, marginTop: 10 } }, '暂无用量窗口数据')
|
|
520
|
+
: null,
|
|
521
|
+
h(
|
|
522
|
+
'div',
|
|
523
|
+
{ key: 'note', style: { fontSize: 10, color: T.secondary, marginTop: 6, lineHeight: '15px' } },
|
|
524
|
+
'上游 /v1/usage 仅提供百分比额度,界面不展示金额余额。',
|
|
525
|
+
),
|
|
526
|
+
].filter(Boolean))
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/** 面板窗口行:已用 % + 剩余 % + 重置倒计时 + 进度条(按剩余额度着色)。 */
|
|
317
530
|
function QuotaRow(props) {
|
|
318
531
|
const w = props.window
|
|
319
|
-
const used = w
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
532
|
+
const used = w?.usedPct ?? null
|
|
533
|
+
const remaining = w?.remainingPct ?? null
|
|
534
|
+
const color = remainingColor(remaining)
|
|
535
|
+
const statusText = w?.status && w.status !== 'ok' ? w.status : null
|
|
536
|
+
return h('div', { style: { marginBottom: 12 } }, [
|
|
537
|
+
h('div', { key: 'meta', style: { display: 'flex', alignItems: 'baseline', gap: 6, fontSize: 11, marginBottom: 4, fontVariantNumeric: 'tabular-nums' } }, [
|
|
538
|
+
h('span', { key: 'l', style: { color: T.label, fontWeight: 500, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, w?.label ?? '—'),
|
|
539
|
+
h('span', { key: 'u', style: { marginLeft: 'auto', color: T.secondary, flexShrink: 0 } }, used === null ? '已用 —' : `已用 ${used}%`),
|
|
540
|
+
h('span', { key: 'r', style: { color, fontWeight: 600, flexShrink: 0 } }, remaining === null ? '剩余 —' : `剩余 ${remaining}%`),
|
|
541
|
+
w?.resetAt ? h('span', { key: 't', style: { color: T.secondary, flexShrink: 0 } }, `↻ ${timeUntil(w.resetAt)}`) : null,
|
|
542
|
+
].filter(Boolean)),
|
|
327
543
|
h(
|
|
328
544
|
'div',
|
|
329
545
|
{
|
|
@@ -336,22 +552,25 @@ window.__ModuleLoader__.load({
|
|
|
336
552
|
overflow: 'hidden',
|
|
337
553
|
},
|
|
338
554
|
},
|
|
339
|
-
|
|
555
|
+
remaining === null
|
|
340
556
|
? null
|
|
341
557
|
: h('div', {
|
|
342
558
|
style: {
|
|
343
559
|
height: '100%',
|
|
344
|
-
width: `${
|
|
560
|
+
width: `${clampPct(remaining)}%`,
|
|
345
561
|
background: color,
|
|
346
562
|
borderRadius: 3,
|
|
347
563
|
transition: 'width 0.4s ease',
|
|
348
564
|
},
|
|
349
565
|
}),
|
|
350
566
|
),
|
|
351
|
-
|
|
567
|
+
statusText
|
|
568
|
+
? h('div', { key: 'st', style: { fontSize: 10, color: T.warn, marginTop: 3 } }, `窗口状态异常:${statusText}`)
|
|
569
|
+
: null,
|
|
570
|
+
].filter(Boolean))
|
|
352
571
|
}
|
|
353
572
|
|
|
354
|
-
// ----------
|
|
573
|
+
// ---------- 连接设置视图 ----------
|
|
355
574
|
function ConfigCard() {
|
|
356
575
|
const state = useStore()
|
|
357
576
|
const cfg = state.config
|
|
@@ -374,7 +593,8 @@ window.__ModuleLoader__.load({
|
|
|
374
593
|
headers: { 'content-type': 'application/json' },
|
|
375
594
|
body: JSON.stringify({ baseUrl, ...(apiKey ? { apiKey } : {}) }),
|
|
376
595
|
})
|
|
377
|
-
|
|
596
|
+
// 保存成功后回到用量视图
|
|
597
|
+
store.set({ status: result.status, config: result.config, view: 'status', error: null })
|
|
378
598
|
setApiKey('')
|
|
379
599
|
} catch (e) {
|
|
380
600
|
setError(e?.message ?? '保存失败')
|
|
@@ -393,7 +613,7 @@ window.__ModuleLoader__.load({
|
|
|
393
613
|
headers: { 'content-type': 'application/json' },
|
|
394
614
|
body: JSON.stringify({ baseUrl, clearApiKey: true }),
|
|
395
615
|
})
|
|
396
|
-
store.set({ status: result.status, config: result.config })
|
|
616
|
+
store.set({ status: result.status, config: result.config, error: null })
|
|
397
617
|
} catch (e) {
|
|
398
618
|
setError(e?.message ?? '清除失败')
|
|
399
619
|
} finally {
|
|
@@ -406,12 +626,12 @@ window.__ModuleLoader__.load({
|
|
|
406
626
|
setBaseUrl(cfg?.baseUrl ?? '')
|
|
407
627
|
setApiKey('')
|
|
408
628
|
setError(null)
|
|
409
|
-
store.set({ open: false })
|
|
629
|
+
store.set({ open: false, view: 'status' })
|
|
410
630
|
}
|
|
411
631
|
|
|
412
632
|
return h('div', null, [
|
|
413
633
|
h('div', { key: 'u', style: { marginBottom: 10 } }, [
|
|
414
|
-
h('label', { style:
|
|
634
|
+
h('label', { style: labelStyle }, 'Base URL'),
|
|
415
635
|
h('input', {
|
|
416
636
|
style: inputStyle,
|
|
417
637
|
value: baseUrl,
|
|
@@ -420,7 +640,7 @@ window.__ModuleLoader__.load({
|
|
|
420
640
|
}),
|
|
421
641
|
]),
|
|
422
642
|
h('div', { key: 'k', style: { marginBottom: 10 } }, [
|
|
423
|
-
h('label', { style:
|
|
643
|
+
h('label', { style: labelStyle }, `API Key *${keyState.configured ? `(已保存 ${keyState.hint})` : ''}`),
|
|
424
644
|
h('input', {
|
|
425
645
|
style: { ...inputStyle, opacity: keyState.writable ? 1 : 0.6 },
|
|
426
646
|
type: 'password',
|
|
@@ -434,35 +654,101 @@ window.__ModuleLoader__.load({
|
|
|
434
654
|
h('div', { key: 'btns', style: { display: 'flex', gap: 8, marginTop: 12, alignItems: 'center' } }, [
|
|
435
655
|
h(
|
|
436
656
|
'button',
|
|
437
|
-
{ className: 'oc-btn
|
|
657
|
+
{ className: 'oc-btn', style: { ...btnBase, background: T.brand, borderColor: T.brand, color: '#fff' }, disabled: saving, onClick: save },
|
|
438
658
|
saving ? '保存中…' : '保存并连接',
|
|
439
659
|
),
|
|
440
660
|
h('button', { className: 'oc-btn', style: btnBase, disabled: saving, onClick: cancel }, '取消'),
|
|
441
661
|
keyState.configured && keyState.writable
|
|
442
662
|
? h('button', { className: 'oc-btn', style: { ...btnBase, color: T.err, marginLeft: 'auto' }, disabled: saving, onClick: clearKey }, '清除')
|
|
443
663
|
: null,
|
|
444
|
-
]),
|
|
664
|
+
].filter(Boolean)),
|
|
445
665
|
])
|
|
446
666
|
}
|
|
447
667
|
|
|
448
|
-
// ----------
|
|
668
|
+
// ---------- 固定底部操作条 ----------
|
|
669
|
+
function OpsBar(props) {
|
|
670
|
+
const state = useStore()
|
|
671
|
+
const st = state.status
|
|
672
|
+
const lastSync = st?.fetchedAt ? fmtClock(st.fetchedAt) : null
|
|
673
|
+
|
|
674
|
+
if (props?.settings) {
|
|
675
|
+
return h('div', { style: barStyle }, [
|
|
676
|
+
// 只有未配置(needs_config)时没有可返回的用量视图;status 尚未加载时也要保留返回入口。
|
|
677
|
+
st?.mode !== 'needs_config'
|
|
678
|
+
? h(
|
|
679
|
+
'button',
|
|
680
|
+
{
|
|
681
|
+
className: 'oc-btn',
|
|
682
|
+
style: btnBase,
|
|
683
|
+
onClick: () => {
|
|
684
|
+
store.set({ view: 'status' })
|
|
685
|
+
refreshStatus()
|
|
686
|
+
},
|
|
687
|
+
},
|
|
688
|
+
'← 返回用量',
|
|
689
|
+
)
|
|
690
|
+
: null,
|
|
691
|
+
h(
|
|
692
|
+
'span',
|
|
693
|
+
{ style: { marginLeft: 'auto', fontSize: 10, color: T.secondary, fontVariantNumeric: 'tabular-nums' } },
|
|
694
|
+
lastSync ? `上次同步 ${lastSync}` : '尚未同步',
|
|
695
|
+
),
|
|
696
|
+
].filter(Boolean))
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
return h(
|
|
700
|
+
'div',
|
|
701
|
+
{ style: barStyle },
|
|
702
|
+
[
|
|
703
|
+
h(
|
|
704
|
+
'button',
|
|
705
|
+
{
|
|
706
|
+
className: 'oc-btn',
|
|
707
|
+
style: btnBase,
|
|
708
|
+
disabled: state.refreshing,
|
|
709
|
+
onClick: manualRefresh,
|
|
710
|
+
title: '绕过 30 秒缓存,强制重新拉取当前剩余额度',
|
|
711
|
+
},
|
|
712
|
+
h('span', { key: 'i', className: state.refreshing ? 'oc-spin' : undefined }, '↻'),
|
|
713
|
+
state.refreshing ? '刷新中…' : '刷新',
|
|
714
|
+
),
|
|
715
|
+
h('button', { key: 'set', className: 'oc-btn', style: btnBase, onClick: openSettings, title: '配置 Base URL 与 API Key' }, '⚙ 设置'),
|
|
716
|
+
h(
|
|
717
|
+
'span',
|
|
718
|
+
{ key: 'at', style: { marginLeft: 'auto', fontSize: 10, color: T.secondary, fontVariantNumeric: 'tabular-nums' } },
|
|
719
|
+
lastSync ? `上次同步 ${lastSync}` : '尚未同步',
|
|
720
|
+
),
|
|
721
|
+
],
|
|
722
|
+
)
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
const barStyle = {
|
|
726
|
+
flexShrink: 0,
|
|
727
|
+
borderTop: `1px solid ${T.border}`,
|
|
728
|
+
padding: '10px 16px 12px',
|
|
729
|
+
display: 'flex',
|
|
730
|
+
alignItems: 'center',
|
|
731
|
+
gap: 8,
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// ---------- Overlay 面板(状态视图 / 设置视图) ----------
|
|
449
735
|
function OverlayPanel() {
|
|
450
736
|
const state = useStore()
|
|
451
737
|
const panelRef = useRef(null)
|
|
738
|
+
// 相位机:closed → open → closing(播完退场动画)→ closed。
|
|
739
|
+
// 拆成两个 effect:否则 phase 变化会清掉「170ms 后置 closed」的定时器,面板卡在不可见仍拦截点击的状态。
|
|
452
740
|
const [phase, setPhase] = useState('closed')
|
|
453
|
-
|
|
454
741
|
useEffect(() => {
|
|
455
742
|
if (state.open) setPhase('open')
|
|
456
743
|
else setPhase((p) => (p === 'open' ? 'closing' : p))
|
|
457
744
|
}, [state.open])
|
|
458
|
-
|
|
459
745
|
useEffect(() => {
|
|
460
746
|
if (phase !== 'closing') return
|
|
461
|
-
const timer = setTimeout(() => setPhase('closed'),
|
|
747
|
+
const timer = setTimeout(() => setPhase('closed'), 170)
|
|
462
748
|
return () => clearTimeout(timer)
|
|
463
749
|
}, [phase])
|
|
464
750
|
|
|
465
|
-
//
|
|
751
|
+
// 点击外部关闭;footer 常驻按钮自身不在面板内,放行它的点击。
|
|
466
752
|
useEffect(() => {
|
|
467
753
|
if (!state.open) return
|
|
468
754
|
const handleClickOutside = (e) => {
|
|
@@ -478,6 +764,8 @@ window.__ModuleLoader__.load({
|
|
|
478
764
|
if (phase === 'closed') return null
|
|
479
765
|
|
|
480
766
|
const st = state.status
|
|
767
|
+
// 未配置时必须直接落在设置视图;其余情况由 store.view 决定。
|
|
768
|
+
const settingsView = state.view === 'settings' || st?.mode === 'needs_config'
|
|
481
769
|
|
|
482
770
|
return h(
|
|
483
771
|
'div',
|
|
@@ -488,75 +776,42 @@ window.__ModuleLoader__.load({
|
|
|
488
776
|
position: 'fixed',
|
|
489
777
|
left: 12,
|
|
490
778
|
bottom: 52,
|
|
491
|
-
width:
|
|
779
|
+
width: 360,
|
|
780
|
+
maxHeight: 'calc(100vh - 80px)',
|
|
781
|
+
overflow: 'hidden',
|
|
782
|
+
display: 'flex',
|
|
783
|
+
flexDirection: 'column',
|
|
492
784
|
background: T.bg,
|
|
493
785
|
border: `1px solid ${T.border}`,
|
|
494
786
|
borderRadius: 16,
|
|
495
787
|
boxShadow: 'var(--dsw-shadow-lv3, 0 10px 32px rgba(0,0,0,0.4))',
|
|
496
|
-
padding: '14px 16px 12px',
|
|
497
788
|
zIndex: 60,
|
|
498
789
|
pointerEvents: phase === 'closing' ? 'none' : 'auto',
|
|
499
790
|
},
|
|
500
791
|
},
|
|
501
792
|
[
|
|
502
|
-
//
|
|
503
|
-
h('div', { key: 'hd', style: { display: 'flex', alignItems: 'center',
|
|
504
|
-
h('span', { style: { fontSize: 13, fontWeight: 600, color: T.label } }, '⚙ OpenCode GO 连接配置'),
|
|
505
|
-
|
|
506
|
-
h(
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
onClick: async () => {
|
|
525
|
-
store.set({ refreshing: true })
|
|
526
|
-
await refreshStatus(true)
|
|
527
|
-
store.set({ refreshing: false })
|
|
528
|
-
},
|
|
529
|
-
title: '强制刷新同步',
|
|
530
|
-
},
|
|
531
|
-
state.refreshing ? h('span', { className: 'oc-spin' }, '↻') : '↻',
|
|
532
|
-
),
|
|
533
|
-
h(
|
|
534
|
-
'button',
|
|
535
|
-
{
|
|
536
|
-
className: 'oc-btn',
|
|
537
|
-
style: {
|
|
538
|
-
width: 26,
|
|
539
|
-
height: 26,
|
|
540
|
-
padding: 0,
|
|
541
|
-
display: 'inline-flex',
|
|
542
|
-
alignItems: 'center',
|
|
543
|
-
justifyContent: 'center',
|
|
544
|
-
fontSize: 13,
|
|
545
|
-
border: 'none',
|
|
546
|
-
borderRadius: 6,
|
|
547
|
-
cursor: 'pointer',
|
|
548
|
-
color: T.secondary,
|
|
549
|
-
background: 'transparent',
|
|
550
|
-
},
|
|
551
|
-
onClick: () => store.set({ open: false }),
|
|
552
|
-
title: '关闭',
|
|
553
|
-
},
|
|
554
|
-
'✕',
|
|
555
|
-
),
|
|
556
|
-
]),
|
|
557
|
-
]),
|
|
558
|
-
// 内容:直接展示配置与连接管理
|
|
559
|
-
h(ConfigCard),
|
|
793
|
+
// 固定头部:标题 + 关闭
|
|
794
|
+
h('div', { key: 'hd', style: { display: 'flex', alignItems: 'center', padding: '14px 16px 10px', borderBottom: `1px solid ${T.border}`, flexShrink: 0 } }, [
|
|
795
|
+
h('span', { key: 't', style: { fontSize: 13, fontWeight: 600, color: T.label } }, settingsView ? '⚙ OpenCode GO 连接配置' : 'OpenCode GO 用量'),
|
|
796
|
+
!settingsView && st?.config?.baseUrl
|
|
797
|
+
? h('span', { key: 'h', style: { fontSize: 10, color: T.secondary, marginLeft: 8, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, hostOf(st.config.baseUrl))
|
|
798
|
+
: null,
|
|
799
|
+
h(
|
|
800
|
+
'button',
|
|
801
|
+
{
|
|
802
|
+
key: 'x',
|
|
803
|
+
className: 'oc-btn',
|
|
804
|
+
style: { ...btnBase, marginLeft: 'auto', border: 'none', padding: '2px 6px' },
|
|
805
|
+
onClick: closeOverlay,
|
|
806
|
+
title: '关闭',
|
|
807
|
+
},
|
|
808
|
+
'✕',
|
|
809
|
+
),
|
|
810
|
+
].filter(Boolean)),
|
|
811
|
+
// 滚动内容区
|
|
812
|
+
h('div', { key: 'body', style: { flex: 1, minHeight: 0, overflowY: 'auto', padding: '12px 16px' } }, settingsView ? h(ConfigCard) : h(StatusView)),
|
|
813
|
+
// 固定底部操作条:刷新 / 设置 / 上次同步
|
|
814
|
+
h(OpsBar, { key: 'ops', settings: settingsView }),
|
|
560
815
|
],
|
|
561
816
|
)
|
|
562
817
|
}
|