opencode-glm-plugin 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/gui-experimental.cjs +1 -0
- package/package.json +54 -4
- package/src/gui/bigmodel.ts +328 -0
- package/src/gui/contract.ts +17 -0
- package/src/gui/definition.ts +11 -0
- package/src/gui/i18n/en.ts +41 -0
- package/src/gui/i18n/zh.ts +39 -0
- package/src/gui/main.ts +36 -0
- package/src/gui/panel.css +331 -0
- package/src/gui/panel.tsx +318 -0
- package/src/gui/state.ts +47 -0
- package/src/gui/view.ts +78 -0
- package/src/gui/window.tsx +93 -0
- package/src/gui.tsx +10 -0
- package/src/index.ts +10 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const zh = {
|
|
2
|
+
"panel.title": "GLM 额度",
|
|
3
|
+
"panel.refresh": "刷新",
|
|
4
|
+
"pill.label": "GLM 已用 {{pct}}%",
|
|
5
|
+
"pill.loading": "GLM …",
|
|
6
|
+
"menu.open": "GLM 额度",
|
|
7
|
+
"section.today": "今天",
|
|
8
|
+
"section.quota": "套餐额度",
|
|
9
|
+
"section.7d": "最近 7 天",
|
|
10
|
+
"section.30d": "最近 30 天",
|
|
11
|
+
"usage.tokens": "Token 用量",
|
|
12
|
+
"usage.calls": "调用次数",
|
|
13
|
+
"usage.models": "按模型",
|
|
14
|
+
"usage.empty": "暂无用量数据",
|
|
15
|
+
"chart.byHour": "按小时",
|
|
16
|
+
"chart.byDay": "按天",
|
|
17
|
+
"limit.tokens-5h": "5 小时窗口",
|
|
18
|
+
"limit.credit-5h": "5 小时积分",
|
|
19
|
+
"limit.credit-week": "每周积分",
|
|
20
|
+
"limit.credit-month": "每月积分",
|
|
21
|
+
"limit.time-month": "月度工具 (MCP)",
|
|
22
|
+
"limit.other": "额度",
|
|
23
|
+
"state.used": "已用",
|
|
24
|
+
"state.usedPct": "已用 {{pct}}%",
|
|
25
|
+
"state.freePct": "可用 {{pct}}%",
|
|
26
|
+
"state.remaining": "剩余",
|
|
27
|
+
"state.limited": "已限额",
|
|
28
|
+
"state.resetIn": "{{time}}重置",
|
|
29
|
+
"state.loading": "加载中…",
|
|
30
|
+
"state.noKey": "未找到 GLM API Key",
|
|
31
|
+
"state.noKeyHint": "请先在 OpenCode 中登录智谱 (zhipuai-coding-plan),或在 opencode.json 的插件 options 里配置 apiKey。",
|
|
32
|
+
"state.error": "请求失败",
|
|
33
|
+
"state.empty": "服务端未返回额度数据",
|
|
34
|
+
"state.emptyHint": "新版积分套餐可能需要在插件 options 里配置 organization / project / planType(见 bigmodel.cn 控制台)。",
|
|
35
|
+
"foot.updated": "更新于 {{time}}",
|
|
36
|
+
"foot.auto": "每 5 分钟自动刷新",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default zh
|
package/src/gui/main.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Plugin } from "@opencode/plugin/gui"
|
|
2
|
+
import { GlmQuota } from "./contract"
|
|
3
|
+
import { fetchSnapshot, type Snapshot } from "./bigmodel"
|
|
4
|
+
|
|
5
|
+
/** The cached snapshot stays fresh for this long before `snapshot` refetches. */
|
|
6
|
+
const MIN_INTERVAL_MS = 90_000
|
|
7
|
+
|
|
8
|
+
export const main: Plugin.MainSetup = (ctx) => {
|
|
9
|
+
let cache: Snapshot | undefined
|
|
10
|
+
let inflight: Promise<Snapshot> | undefined
|
|
11
|
+
|
|
12
|
+
const load = (force: boolean): Promise<Snapshot> => {
|
|
13
|
+
const age = cache ? Date.now() - cache.fetchedAt : Number.POSITIVE_INFINITY
|
|
14
|
+
if (!force && cache && age < MIN_INTERVAL_MS) return Promise.resolve(cache)
|
|
15
|
+
if (inflight) return inflight
|
|
16
|
+
inflight = fetchSnapshot(ctx.options)
|
|
17
|
+
.then((next) => {
|
|
18
|
+
cache = next
|
|
19
|
+
return next
|
|
20
|
+
})
|
|
21
|
+
.finally(() => {
|
|
22
|
+
inflight = undefined
|
|
23
|
+
})
|
|
24
|
+
return inflight
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const provider = ctx.provide(GlmQuota, {
|
|
28
|
+
snapshot: () => load(false),
|
|
29
|
+
refresh: () => load(true),
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Warm the cache so the first panel or pill read is instant.
|
|
33
|
+
void load(false).catch(() => {})
|
|
34
|
+
|
|
35
|
+
return () => provider.dispose()
|
|
36
|
+
}
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/* The GLM quota panel. Prefixed `glmq-` so it never meets the app's classes. */
|
|
2
|
+
|
|
3
|
+
.glmq {
|
|
4
|
+
display: flex;
|
|
5
|
+
flex-direction: column;
|
|
6
|
+
gap: 10px;
|
|
7
|
+
padding: 12px;
|
|
8
|
+
font-size: 12px;
|
|
9
|
+
line-height: 1.45;
|
|
10
|
+
color: var(--v2-text-text-base);
|
|
11
|
+
height: 100%;
|
|
12
|
+
overflow-y: auto;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/* ---------- header ---------- */
|
|
16
|
+
|
|
17
|
+
.glmq-head {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
gap: 6px;
|
|
21
|
+
padding: 0 2px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.glmq-title {
|
|
25
|
+
font-weight: 620;
|
|
26
|
+
font-size: 12px;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.glmq-level {
|
|
30
|
+
padding: 1px 7px;
|
|
31
|
+
border-radius: 999px;
|
|
32
|
+
background: var(--v2-background-bg-deep);
|
|
33
|
+
color: var(--v2-text-text-muted);
|
|
34
|
+
font-size: 10px;
|
|
35
|
+
font-weight: 600;
|
|
36
|
+
text-transform: uppercase;
|
|
37
|
+
letter-spacing: 0.04em;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.glmq-flag {
|
|
41
|
+
padding: 1px 7px;
|
|
42
|
+
border-radius: 999px;
|
|
43
|
+
background: color-mix(in srgb, var(--icon-critical-base, #e5484d) 14%, transparent);
|
|
44
|
+
color: var(--icon-critical-base, #e5484d);
|
|
45
|
+
font-size: 10px;
|
|
46
|
+
font-weight: 600;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.glmq-refresh {
|
|
50
|
+
margin-left: auto;
|
|
51
|
+
display: inline-flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
width: 22px;
|
|
55
|
+
height: 22px;
|
|
56
|
+
border: none;
|
|
57
|
+
border-radius: 6px;
|
|
58
|
+
background: none;
|
|
59
|
+
color: var(--v2-icon-icon-base);
|
|
60
|
+
cursor: pointer;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.glmq-refresh:hover:not(:disabled) {
|
|
64
|
+
background: var(--v2-background-bg-deep);
|
|
65
|
+
color: var(--v2-icon-icon-accent);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.glmq-refresh:disabled {
|
|
69
|
+
opacity: 0.45;
|
|
70
|
+
cursor: default;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* ---------- cards ---------- */
|
|
74
|
+
|
|
75
|
+
.glmq-body {
|
|
76
|
+
display: flex;
|
|
77
|
+
flex-direction: column;
|
|
78
|
+
gap: 10px;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.glmq-card {
|
|
82
|
+
display: flex;
|
|
83
|
+
flex-direction: column;
|
|
84
|
+
gap: 8px;
|
|
85
|
+
padding: 10px 12px 12px;
|
|
86
|
+
border: 1px solid var(--v2-border-border-muted, transparent);
|
|
87
|
+
border-radius: 10px;
|
|
88
|
+
background: color-mix(in srgb, var(--v2-background-bg-deep) 55%, transparent);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.glmq-card-row {
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: baseline;
|
|
94
|
+
justify-content: space-between;
|
|
95
|
+
gap: 8px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.glmq-card-title {
|
|
99
|
+
font-size: 11px;
|
|
100
|
+
font-weight: 620;
|
|
101
|
+
color: var(--v2-text-text-muted);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.glmq-gran {
|
|
105
|
+
font-size: 10px;
|
|
106
|
+
color: var(--v2-text-text-faint);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* ---------- quota limits ---------- */
|
|
110
|
+
|
|
111
|
+
.glmq-limit + .glmq-limit {
|
|
112
|
+
border-top: 1px solid var(--v2-border-border-muted, transparent);
|
|
113
|
+
padding-top: 10px;
|
|
114
|
+
margin-top: 2px;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.glmq-limit-head {
|
|
118
|
+
display: flex;
|
|
119
|
+
justify-content: space-between;
|
|
120
|
+
align-items: baseline;
|
|
121
|
+
margin-bottom: 5px;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.glmq-limit-name {
|
|
125
|
+
color: var(--v2-text-text-base);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.glmq-limit-pct {
|
|
129
|
+
font-variant-numeric: tabular-nums;
|
|
130
|
+
font-weight: 620;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.glmq-bar {
|
|
134
|
+
height: 6px;
|
|
135
|
+
border-radius: 999px;
|
|
136
|
+
background: var(--v2-background-bg-deep);
|
|
137
|
+
overflow: hidden;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.glmq-fill {
|
|
141
|
+
height: 100%;
|
|
142
|
+
border-radius: 999px;
|
|
143
|
+
transition: width 0.3s ease;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.glmq-sub {
|
|
147
|
+
display: flex;
|
|
148
|
+
justify-content: space-between;
|
|
149
|
+
gap: 8px;
|
|
150
|
+
margin-top: 4px;
|
|
151
|
+
font-size: 11px;
|
|
152
|
+
color: var(--v2-text-text-muted);
|
|
153
|
+
min-height: 1em;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* ---------- usage totals ---------- */
|
|
157
|
+
|
|
158
|
+
.glmq-totals {
|
|
159
|
+
display: flex;
|
|
160
|
+
gap: 18px;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.glmq-total b {
|
|
164
|
+
display: block;
|
|
165
|
+
font-size: 15px;
|
|
166
|
+
font-weight: 620;
|
|
167
|
+
font-variant-numeric: tabular-nums;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.glmq-total span {
|
|
171
|
+
font-size: 10px;
|
|
172
|
+
color: var(--v2-text-text-muted);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/* ---------- chart with axes ---------- */
|
|
176
|
+
|
|
177
|
+
.glmq-chart {
|
|
178
|
+
display: flex;
|
|
179
|
+
flex-direction: column;
|
|
180
|
+
margin-top: 2px;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.glmq-plot {
|
|
184
|
+
position: relative;
|
|
185
|
+
display: flex;
|
|
186
|
+
height: 84px;
|
|
187
|
+
margin-top: 10px;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/* A left gutter carries the y tick labels, so they never sit over bars. */
|
|
191
|
+
.glmq-gutter {
|
|
192
|
+
position: relative;
|
|
193
|
+
flex: none;
|
|
194
|
+
width: 36px;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.glmq-ylabel {
|
|
198
|
+
position: absolute;
|
|
199
|
+
right: 5px;
|
|
200
|
+
transform: translateY(-50%);
|
|
201
|
+
font-size: 9px;
|
|
202
|
+
line-height: 1;
|
|
203
|
+
color: var(--v2-text-text-faint);
|
|
204
|
+
white-space: nowrap;
|
|
205
|
+
font-variant-numeric: tabular-nums;
|
|
206
|
+
pointer-events: none;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.glmq-area {
|
|
210
|
+
position: relative;
|
|
211
|
+
flex: 1;
|
|
212
|
+
min-width: 0;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.glmq-gridline {
|
|
216
|
+
position: absolute;
|
|
217
|
+
left: 0;
|
|
218
|
+
right: 0;
|
|
219
|
+
height: 1px;
|
|
220
|
+
background: color-mix(in srgb, var(--v2-border-border-muted, currentColor) 45%, transparent);
|
|
221
|
+
pointer-events: none;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.glmq-bars {
|
|
225
|
+
position: absolute;
|
|
226
|
+
inset: 0;
|
|
227
|
+
width: 100%;
|
|
228
|
+
height: 100%;
|
|
229
|
+
display: block;
|
|
230
|
+
color: var(--v2-icon-icon-accent);
|
|
231
|
+
opacity: 0.9;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.glmq-xlabels {
|
|
235
|
+
display: flex;
|
|
236
|
+
justify-content: space-between;
|
|
237
|
+
margin-top: 3px;
|
|
238
|
+
margin-left: 36px;
|
|
239
|
+
font-size: 9px;
|
|
240
|
+
line-height: 1;
|
|
241
|
+
color: var(--v2-text-text-faint);
|
|
242
|
+
font-variant-numeric: tabular-nums;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/* ---------- model breakdown ---------- */
|
|
246
|
+
|
|
247
|
+
.glmq-models {
|
|
248
|
+
margin-top: 4px;
|
|
249
|
+
display: flex;
|
|
250
|
+
flex-direction: column;
|
|
251
|
+
gap: 7px;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.glmq-models-title {
|
|
255
|
+
font-size: 10px;
|
|
256
|
+
color: var(--v2-text-text-faint);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.glmq-model {
|
|
260
|
+
display: flex;
|
|
261
|
+
flex-direction: column;
|
|
262
|
+
gap: 3px;
|
|
263
|
+
font-size: 11px;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.glmq-model-head {
|
|
267
|
+
display: flex;
|
|
268
|
+
align-items: baseline;
|
|
269
|
+
justify-content: space-between;
|
|
270
|
+
gap: 8px;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.glmq-model-name {
|
|
274
|
+
min-width: 0;
|
|
275
|
+
overflow: hidden;
|
|
276
|
+
text-overflow: ellipsis;
|
|
277
|
+
white-space: nowrap;
|
|
278
|
+
color: var(--v2-text-text-base);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.glmq-model-bar {
|
|
282
|
+
display: block;
|
|
283
|
+
width: 100%;
|
|
284
|
+
height: 4px;
|
|
285
|
+
border-radius: 999px;
|
|
286
|
+
background: var(--v2-background-bg-deep);
|
|
287
|
+
overflow: hidden;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.glmq-model-fill {
|
|
291
|
+
display: block;
|
|
292
|
+
height: 100%;
|
|
293
|
+
border-radius: 999px;
|
|
294
|
+
background: var(--v2-icon-icon-accent);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
.glmq-model-tokens {
|
|
298
|
+
flex: none;
|
|
299
|
+
font-variant-numeric: tabular-nums;
|
|
300
|
+
color: var(--v2-text-text-muted);
|
|
301
|
+
text-align: end;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.glmq-none {
|
|
305
|
+
font-size: 11px;
|
|
306
|
+
color: var(--v2-text-text-faint);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/* ---------- status & footer ---------- */
|
|
310
|
+
|
|
311
|
+
.glmq-status-title {
|
|
312
|
+
font-weight: 620;
|
|
313
|
+
color: var(--v2-text-text-base);
|
|
314
|
+
margin-bottom: 4px;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.glmq-status-detail {
|
|
318
|
+
font-size: 11px;
|
|
319
|
+
margin-top: 4px;
|
|
320
|
+
color: var(--v2-text-text-muted);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
.glmq-status-error .glmq-status-title {
|
|
324
|
+
color: var(--icon-critical-base, #e5484d);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
.glmq-foot {
|
|
328
|
+
font-size: 10px;
|
|
329
|
+
color: var(--v2-text-text-faint);
|
|
330
|
+
padding: 0 2px;
|
|
331
|
+
}
|