opencode-visual-cache 1.6.2 → 1.7.0-beta.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 -21
- package/README.md +247 -247
- package/README_EN.md +247 -247
- package/dist/_version.d.ts +1 -1
- package/dist/_version.js +1 -1
- package/dist/core/color.d.ts +37 -0
- package/dist/core/color.js +108 -0
- package/dist/core/currency.d.ts +17 -0
- package/dist/core/currency.js +43 -0
- package/dist/core/estimate.d.ts +1 -0
- package/dist/core/estimate.js +40 -0
- package/dist/core/format.d.ts +15 -0
- package/dist/core/format.js +90 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +5 -0
- package/dist/core/types.d.ts +17 -0
- package/dist/core/types.js +1 -0
- package/dist/index.js +12 -818
- package/dist/panel/TokenCachePanel.d.ts +10 -0
- package/dist/panel/TokenCachePanel.js +549 -0
- package/dist/panel/panel-api.d.ts +119 -0
- package/dist/panel/panel-api.js +1 -0
- package/dist/tui.js +223 -209
- package/dist/v2/commands.d.ts +10 -0
- package/dist/v2/commands.js +490 -0
- package/dist/v2/data.d.ts +27 -0
- package/dist/v2/data.js +103 -0
- package/dist/v2/index.d.ts +4 -0
- package/dist/v2/index.js +163 -0
- package/dist/v2/sidebar.d.ts +6 -0
- package/dist/v2/sidebar.js +36 -0
- package/dist/v2/status.d.ts +14 -0
- package/dist/v2/status.js +83 -0
- package/dist/v2/theme.d.ts +8 -0
- package/dist/v2/theme.js +16 -0
- package/dist/v2/types.d.ts +219 -0
- package/dist/v2/types.js +6 -0
- package/dist/v2/v2-panel-api.d.ts +8 -0
- package/dist/v2/v2-panel-api.js +176 -0
- package/dist/v2.js +2941 -0
- package/package.json +70 -67
- package/src/_version.ts +1 -1
- package/src/balance-providers.ts +153 -153
- package/src/core/color.ts +108 -0
- package/src/core/currency.ts +46 -0
- package/src/core/estimate.ts +36 -0
- package/src/core/format.ts +81 -0
- package/src/core/index.ts +5 -0
- package/src/core/types.ts +17 -0
- package/src/i18n.ts +380 -380
- package/src/index.tsx +1035 -2120
- package/src/panel/TokenCachePanel.tsx +776 -0
- package/src/panel/panel-api.ts +104 -0
- package/src/server.ts +10 -10
- package/src/v2/commands.ts +471 -0
- package/src/v2/data.ts +112 -0
- package/src/v2/index.tsx +184 -0
- package/src/v2/sidebar.tsx +69 -0
- package/src/v2/status.tsx +96 -0
- package/src/v2/theme.ts +19 -0
- package/src/v2/types.ts +159 -0
- package/src/v2/v2-panel-api.ts +177 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** @jsxImportSource @opentui/solid */
|
|
2
|
+
import type { JSX } from "@opentui/solid";
|
|
3
|
+
import type { TuiThemeCurrent } from "@opencode-ai/plugin/tui";
|
|
4
|
+
import type { PanelApi, PanelSignals } from "./panel-api";
|
|
5
|
+
export declare function TokenCachePanel(props: {
|
|
6
|
+
theme: TuiThemeCurrent;
|
|
7
|
+
api: PanelApi;
|
|
8
|
+
sessionId: string;
|
|
9
|
+
signals: PanelSignals;
|
|
10
|
+
}): JSX.Element;
|
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@opentui/solid/jsx-runtime";
|
|
2
|
+
import { createMemo, createSignal, createEffect, onMount, onCleanup, Show, untrack } from "solid-js";
|
|
3
|
+
import { balanceProviders, getBalanceProvider, matchBalanceProvider } from "../balance-providers";
|
|
4
|
+
import { createT } from "../i18n";
|
|
5
|
+
import { MAX_SAT, FALLBACK, desaturateTo, dimColor, fmt, fmtCost, num, estimateTokens, progressBar, visualWidth, truncateVisual, formatBalanceText } from "../core";
|
|
6
|
+
import { PLUGIN_VERSION } from "../_version";
|
|
7
|
+
const MIN_PANEL_WIDTH = 20;
|
|
8
|
+
const DEFAULT_PANEL_WIDTH = 26;
|
|
9
|
+
/** ── layout measurement constants (visual columns) ── */
|
|
10
|
+
const LABEL_GAP = 1; // label(如 "Hit")后面的空格
|
|
11
|
+
const BAR_BRACKETS = 2; // "[" + "]" 包围进度条
|
|
12
|
+
const BAR_GAP = 1; // "]" 后面的空格
|
|
13
|
+
const PCT_FIXED_WIDTH = 5; // "XX.X%" 固定 5 字符宽度
|
|
14
|
+
const HEADER_PREFIX = 2; // 折叠态标题行:▼/▶ 图标 + 图标后空格
|
|
15
|
+
const UNIT_GAP = 1; // 数值与单位前的空格(如 " tok")
|
|
16
|
+
export function TokenCachePanel(props) {
|
|
17
|
+
const [panelWidth, setPanelWidth] = createSignal(DEFAULT_PANEL_WIDTH);
|
|
18
|
+
const [open, setOpen] = createSignal(true);
|
|
19
|
+
const [detailOpen, setDetailOpen] = createSignal(true);
|
|
20
|
+
const [modelOpen, setModelOpen] = createSignal(true);
|
|
21
|
+
const [distOpen, setDistOpen] = createSignal(false);
|
|
22
|
+
const [skillsOpen, setSkillsOpen] = createSignal(true);
|
|
23
|
+
let boxEl;
|
|
24
|
+
// 侧边栏可见性通知:本面板挂载 ⇒ 宿主侧边栏可见(固定占用 42 列输入框宽度)
|
|
25
|
+
createEffect(() => {
|
|
26
|
+
props.signals.setSidebarVisible(true);
|
|
27
|
+
onCleanup(() => props.signals.setSidebarVisible(false));
|
|
28
|
+
});
|
|
29
|
+
// ── shared signals (de-structured so internal code is unchanged) ──
|
|
30
|
+
const { currencySymbol, setCurrencySymbol, exchangeRate, setExchangeRate, langCode, sectionDetail, setSectionDetail, sectionModel, setSectionModel, sectionDist, setSectionDist, sectionSkills, setSectionSkills, sectionBalance, setSectionBalance, balanceRefresh, balanceProviderId, setBalanceProviderId, autoBalance, setAutoBalance, balanceUnsupported, setBalanceUnsupported, balanceState, balanceCurrency, setBalanceCurrency, borderVisible, setBorderVisible, } = props.signals;
|
|
31
|
+
// ── reactive translation (follows langCode signal) ──
|
|
32
|
+
const t = createT(() => langCode());
|
|
33
|
+
// ── scan session messages reactively ──
|
|
34
|
+
// SolidJS createMemo re-evaluates whenever the underlying
|
|
35
|
+
// api.state.session state changes — no event listener needed.
|
|
36
|
+
// ── distribution cache ────────────────────────────────────────
|
|
37
|
+
// When data() re-computes before api.state.part() is warm (e.g. after
|
|
38
|
+
// a view switch), hasDistData flips to false and the distribution
|
|
39
|
+
// block disappears. Keep the last valid snapshot so the UI stays
|
|
40
|
+
// stable until the next successful computation arrives.
|
|
41
|
+
const [lastDist, setLastDist] = createSignal({
|
|
42
|
+
system: 0, user: 0, agent: 0, toolCall: 0, toolResult: 0,
|
|
43
|
+
output: 0, reasoning: 0, apiOutput: 0, apiInput: 0, stepCost: 0, stepCount: 0,
|
|
44
|
+
});
|
|
45
|
+
const [lastHasDist, setLastHasDist] = createSignal(false);
|
|
46
|
+
const [dataSignal, setDataSignal] = createSignal({
|
|
47
|
+
hitRate: 0, read: 0, write: 0, freshInput: 0, output: 0,
|
|
48
|
+
cost: 0, saved: 0, model: "", inputRate: 0, cacheReadRate: 0, cacheWriteRate: 0,
|
|
49
|
+
hasPricing: false, hasData: false, trend: 0, hasTrendData: false,
|
|
50
|
+
providerName: "", sessionHitRate: 0,
|
|
51
|
+
dist: { system: 0, user: 0, agent: 0, toolCall: 0, toolResult: 0, output: 0, reasoning: 0, apiOutput: 0, apiInput: 0, stepCost: 0, stepCount: 0 },
|
|
52
|
+
hasDistData: false,
|
|
53
|
+
skills: [],
|
|
54
|
+
hasSkills: false,
|
|
55
|
+
});
|
|
56
|
+
const [refreshTick, setRefreshTick] = createSignal(0);
|
|
57
|
+
// 当前 provider 显示名(余额查询状态为共享信号,见 PanelSignals.balanceState)
|
|
58
|
+
const providerName = createMemo(() => getBalanceProvider(balanceProviderId()).name);
|
|
59
|
+
// 自动切换当前会话的 provider(前缀匹配)。手动切换会关闭此行为。
|
|
60
|
+
// 直接追踪 messages 取最后一条 assistant 消息的 providerID——
|
|
61
|
+
// 不依赖 session.model 的响应式更新(模型切换时该链路可能不触发重算)。
|
|
62
|
+
createEffect(() => {
|
|
63
|
+
if (!autoBalance())
|
|
64
|
+
return;
|
|
65
|
+
const sid = props.signals.overrideSessionId() ?? props.sessionId;
|
|
66
|
+
const msgs = props.api.state.session.messages(sid);
|
|
67
|
+
let pid = "";
|
|
68
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
69
|
+
const m = msgs[i];
|
|
70
|
+
if (m.role === "assistant" && m.providerID) {
|
|
71
|
+
pid = m.providerID;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// 会话尚无 assistant 消息(新会话 / 刚切换模型未对话 / 消息未加载)
|
|
76
|
+
// → 回退到会话级模型元数据,反映当前正在使用的 provider
|
|
77
|
+
if (!pid) {
|
|
78
|
+
try {
|
|
79
|
+
const session = props.api.state.session.get(sid);
|
|
80
|
+
pid = session?.model?.providerID ?? "";
|
|
81
|
+
}
|
|
82
|
+
catch { /* ignore */ }
|
|
83
|
+
}
|
|
84
|
+
if (!pid)
|
|
85
|
+
return;
|
|
86
|
+
const hit = matchBalanceProvider(pid);
|
|
87
|
+
if (hit) {
|
|
88
|
+
setBalanceUnsupported(false);
|
|
89
|
+
if (hit.id !== balanceProviderId()) {
|
|
90
|
+
setBalanceProviderId(hit.id);
|
|
91
|
+
props.signals.setBalanceRefresh(props.signals.balanceRefresh() + 1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// 当前提供商没有余额适配器 → 标记不支持,余额显示 N/A 并停止轮询
|
|
96
|
+
setBalanceUnsupported(true);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
// ── auto-clear override when the user navigates to a different main session ──
|
|
100
|
+
let lastMainSid = props.sessionId;
|
|
101
|
+
createEffect(() => {
|
|
102
|
+
const sid = props.sessionId;
|
|
103
|
+
if (sid !== lastMainSid) {
|
|
104
|
+
lastMainSid = sid;
|
|
105
|
+
if (props.signals.overrideSessionId()) {
|
|
106
|
+
props.signals.setOverrideSessionId(undefined);
|
|
107
|
+
props.api.kv.set(`${KV_PREFIX}.session`, "");
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
createEffect(() => {
|
|
112
|
+
const sid = props.signals.overrideSessionId() ?? props.sessionId;
|
|
113
|
+
void refreshTick();
|
|
114
|
+
void partVersion();
|
|
115
|
+
// 自然追踪 messages 和 provider(SDK 数据就绪时自动重新执行)
|
|
116
|
+
const msgs = props.api.state.session.messages(sid);
|
|
117
|
+
const session = typeof props.api.state.session.get === "function"
|
|
118
|
+
? props.api.state.session.get(sid)
|
|
119
|
+
: undefined;
|
|
120
|
+
// 累计值优先使用 Session 聚合字段(数据库级,不受 sync 层 limit:100 截断)
|
|
121
|
+
// 若字段不存在(旧版本 SDK),降级到消息遍历累加
|
|
122
|
+
let input = session?.tokens?.input ?? 0;
|
|
123
|
+
let read = session?.tokens?.cache?.read ?? 0;
|
|
124
|
+
let write = session?.tokens?.cache?.write ?? 0;
|
|
125
|
+
let output = session?.tokens?.output ?? 0;
|
|
126
|
+
let cost = session?.cost ?? 0;
|
|
127
|
+
let pid = session?.model?.providerID ?? "";
|
|
128
|
+
let mid = session?.model?.id ?? "";
|
|
129
|
+
const fallbackTokens = session?.tokens == null;
|
|
130
|
+
const fallbackCost = session?.cost == null;
|
|
131
|
+
const fallbackModel = !pid || !mid;
|
|
132
|
+
let prevMsgHitRate = -1, lastMsgHitRate = -1;
|
|
133
|
+
for (const msg of msgs) {
|
|
134
|
+
if (msg.role !== "assistant")
|
|
135
|
+
continue;
|
|
136
|
+
const tok = msg.tokens;
|
|
137
|
+
if (!tok)
|
|
138
|
+
continue;
|
|
139
|
+
const mit = num(tok.input) + num(tok.cache?.read) + num(tok.cache?.write), mrt = num(tok.cache?.read);
|
|
140
|
+
if (mit > 0) {
|
|
141
|
+
prevMsgHitRate = lastMsgHitRate;
|
|
142
|
+
lastMsgHitRate = (mrt / mit) * 100;
|
|
143
|
+
}
|
|
144
|
+
if (fallbackTokens) {
|
|
145
|
+
input += num(tok.input);
|
|
146
|
+
read += num(tok.cache?.read);
|
|
147
|
+
write += num(tok.cache?.write);
|
|
148
|
+
output += num(tok.output);
|
|
149
|
+
}
|
|
150
|
+
if (fallbackCost) {
|
|
151
|
+
cost += num(msg.cost);
|
|
152
|
+
}
|
|
153
|
+
if (fallbackModel && msg.providerID && msg.modelID) {
|
|
154
|
+
pid = msg.providerID;
|
|
155
|
+
mid = msg.modelID;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
let saved = 0, inputRate = 0, cacheReadRate = 0, cacheWriteRate = 0;
|
|
159
|
+
if (read > 0 && pid && mid && Array.isArray(props.api.state.provider))
|
|
160
|
+
for (const provider of props.api.state.provider) {
|
|
161
|
+
if (provider.id !== pid)
|
|
162
|
+
continue;
|
|
163
|
+
const model = provider.models[mid];
|
|
164
|
+
if (!model?.cost)
|
|
165
|
+
continue;
|
|
166
|
+
inputRate = num(model.cost.input);
|
|
167
|
+
cacheReadRate = num(model.cost.cache?.read);
|
|
168
|
+
cacheWriteRate = num(model.cost.cache?.write);
|
|
169
|
+
if (inputRate > cacheReadRate)
|
|
170
|
+
saved = (read * (inputRate - cacheReadRate)) / 1_000_000;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
const hitRate = lastMsgHitRate >= 0 ? lastMsgHitRate : 0;
|
|
174
|
+
// 总命中率分母含缓存写(业界口径:read / (input+read+write))
|
|
175
|
+
const freshTotal = input + read + write, sessionHitRate = freshTotal > 0 ? (read / freshTotal) * 100 : 0;
|
|
176
|
+
const model = mid.split("/").pop() ?? mid, hasPricing = inputRate > 0 || cacheReadRate > 0 || cacheWriteRate > 0;
|
|
177
|
+
const hasTrendData = prevMsgHitRate >= 0 && lastMsgHitRate >= 0;
|
|
178
|
+
const trend = hasTrendData ? lastMsgHitRate - prevMsgHitRate : 0, providerName = pid || "";
|
|
179
|
+
// untrack 只包裹已知触发死锁的 API
|
|
180
|
+
const distData = untrack(() => {
|
|
181
|
+
let dist = { system: 0, user: 0, agent: 0, toolCall: 0, toolResult: 0, output: 0, reasoning: 0, apiOutput: 0, apiInput: 0, stepCost: 0, stepCount: 0 };
|
|
182
|
+
let hasDistData = false;
|
|
183
|
+
const loadedSkills = new Map();
|
|
184
|
+
try {
|
|
185
|
+
const cfg = props.api.state.config;
|
|
186
|
+
const agentName = String(session?.agent ?? cfg?.default_agent ?? "build");
|
|
187
|
+
const agents = cfg?.agent;
|
|
188
|
+
const agentCfg = agents?.[agentName];
|
|
189
|
+
const sysPrompt = typeof agentCfg?.prompt === "string" ? agentCfg.prompt : "";
|
|
190
|
+
if (sysPrompt)
|
|
191
|
+
dist.system = estimateTokens(sysPrompt);
|
|
192
|
+
let lastAssMsg;
|
|
193
|
+
for (const msg of msgs) {
|
|
194
|
+
if (msg.role === "user") {
|
|
195
|
+
const um = msg;
|
|
196
|
+
if (um.system)
|
|
197
|
+
dist.system += estimateTokens(um.system);
|
|
198
|
+
let parts = [];
|
|
199
|
+
try {
|
|
200
|
+
parts = props.api.state.part(msg.id);
|
|
201
|
+
}
|
|
202
|
+
catch { }
|
|
203
|
+
for (const p of parts) {
|
|
204
|
+
if (p.type === "text" && !p.synthetic && !p.ignored)
|
|
205
|
+
dist.user += estimateTokens(p.text);
|
|
206
|
+
else if (p.type === "file") {
|
|
207
|
+
const fp = p;
|
|
208
|
+
if (fp.source?.text?.value)
|
|
209
|
+
dist.user += estimateTokens(fp.source.text.value);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
else if (msg.role === "assistant") {
|
|
214
|
+
const am = msg;
|
|
215
|
+
dist.output += num(am.tokens?.output);
|
|
216
|
+
dist.reasoning += num(am.tokens?.reasoning);
|
|
217
|
+
let parts = [];
|
|
218
|
+
try {
|
|
219
|
+
parts = props.api.state.part(msg.id);
|
|
220
|
+
}
|
|
221
|
+
catch { }
|
|
222
|
+
for (const p of parts) {
|
|
223
|
+
if (p.type === "tool") {
|
|
224
|
+
const tp = p;
|
|
225
|
+
let rawInput = "";
|
|
226
|
+
try {
|
|
227
|
+
rawInput = tp.state.raw ?? (tp.state.input != null ? JSON.stringify(tp.state.input) : "");
|
|
228
|
+
}
|
|
229
|
+
catch { }
|
|
230
|
+
if (rawInput)
|
|
231
|
+
dist.toolCall += estimateTokens(rawInput);
|
|
232
|
+
// 子代理委托(task 工具):任务描述计入子代理指令(1.15.x 无 subtask part)
|
|
233
|
+
if (tp.tool === "task" && tp.state?.input) {
|
|
234
|
+
const ti = tp.state.input;
|
|
235
|
+
const prompt = typeof ti.prompt === "string" ? ti.prompt : "";
|
|
236
|
+
const desc = typeof ti.description === "string" ? ti.description : "";
|
|
237
|
+
dist.agent += estimateTokens(prompt || desc);
|
|
238
|
+
}
|
|
239
|
+
if (tp.state.status === "completed") {
|
|
240
|
+
const c = tp.state;
|
|
241
|
+
if (c.output)
|
|
242
|
+
dist.toolResult += estimateTokens(c.output);
|
|
243
|
+
}
|
|
244
|
+
else if (tp.state.status === "error") {
|
|
245
|
+
const e = tp.state;
|
|
246
|
+
if (e.error)
|
|
247
|
+
dist.toolResult += estimateTokens(e.error);
|
|
248
|
+
}
|
|
249
|
+
if (tp.tool === "skill" && tp.state.status === "completed") {
|
|
250
|
+
// TUI SDK strips tool metadata — extract skill name from well-known output format.
|
|
251
|
+
// Cross-validated against api.client.app.skills() when available.
|
|
252
|
+
let name = tp.state.metadata?.name;
|
|
253
|
+
if (typeof name !== "string") {
|
|
254
|
+
const m = typeof tp.state.output === "string"
|
|
255
|
+
? tp.state.output.match(/^#{1,2}\s*Skill:\s*(.+)/m)
|
|
256
|
+
: null;
|
|
257
|
+
if (m)
|
|
258
|
+
name = m[1].trim();
|
|
259
|
+
}
|
|
260
|
+
if (typeof name === "string") {
|
|
261
|
+
const tokens = typeof tp.state.output === "string" ? estimateTokens(tp.state.output) : 0;
|
|
262
|
+
const existing = loadedSkills.get(name);
|
|
263
|
+
if (!existing || existing.tokens < tokens) {
|
|
264
|
+
loadedSkills.set(name, { name, tokens });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else if (p.type === "subtask") {
|
|
270
|
+
const sub = p;
|
|
271
|
+
dist.agent += estimateTokens(sub.prompt || sub.description || "");
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
// 从后往前找最后一条有 token 数据的 assistant 消息(避免取到 streaming 中未填充的消息)
|
|
277
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
278
|
+
if (msgs[i].role !== "assistant")
|
|
279
|
+
continue;
|
|
280
|
+
const tok = msgs[i].tokens;
|
|
281
|
+
if (tok && ((tok.input ?? 0) > 0 || (tok.cache?.read ?? 0) > 0 || (tok.cache?.write ?? 0) > 0)) {
|
|
282
|
+
lastAssMsg = msgs[i];
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
// 取最后一条有数据消息的总输入(含缓存读/写)作为当前 context 大小
|
|
287
|
+
dist.apiInput = num(lastAssMsg?.tokens?.input) + num(lastAssMsg?.tokens?.cache?.read) + num(lastAssMsg?.tokens?.cache?.write);
|
|
288
|
+
dist.apiOutput = num(lastAssMsg?.tokens?.output);
|
|
289
|
+
// 本回合(最后一条有数据消息所在的 parentID 链)的 API 调用次数与末次成本。
|
|
290
|
+
// opencode 将回合内每次工具调用循环拆为独立 assistant 消息(各含 1 个 step-finish),
|
|
291
|
+
// 故按 parentID 链聚合统计,而非单条消息。
|
|
292
|
+
if (lastAssMsg) {
|
|
293
|
+
const roundParent = lastAssMsg.parentID;
|
|
294
|
+
let lastCost;
|
|
295
|
+
for (let i = msgs.length - 1; i >= 0; i--) {
|
|
296
|
+
const m = msgs[i];
|
|
297
|
+
if (m.role !== "assistant")
|
|
298
|
+
continue;
|
|
299
|
+
if (m.parentID !== roundParent)
|
|
300
|
+
break;
|
|
301
|
+
let parts = [];
|
|
302
|
+
try {
|
|
303
|
+
parts = props.api.state.part(m.id);
|
|
304
|
+
}
|
|
305
|
+
catch { }
|
|
306
|
+
for (const p of parts) {
|
|
307
|
+
if (p.type !== "step-finish")
|
|
308
|
+
continue;
|
|
309
|
+
dist.stepCount++;
|
|
310
|
+
const sc = p.cost;
|
|
311
|
+
if (lastCost === undefined && typeof sc === "number" && Number.isFinite(sc))
|
|
312
|
+
lastCost = sc;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (lastCost !== undefined)
|
|
316
|
+
dist.stepCost = lastCost;
|
|
317
|
+
}
|
|
318
|
+
hasDistData = dist.system + dist.user + dist.agent + dist.toolCall + dist.toolResult > 0 || dist.apiOutput > 0 || dist.apiInput > 0 || dist.reasoning > 0;
|
|
319
|
+
}
|
|
320
|
+
catch { }
|
|
321
|
+
const finalDist = hasDistData ? dist : lastDist(), finalHasDist = hasDistData || lastHasDist();
|
|
322
|
+
const skills = [...loadedSkills.values()];
|
|
323
|
+
return { finalDist, finalHasDist, skills };
|
|
324
|
+
});
|
|
325
|
+
setDataSignal({
|
|
326
|
+
hitRate, read, write, freshInput: input, output, cost, saved, model,
|
|
327
|
+
inputRate, cacheReadRate, cacheWriteRate, hasPricing,
|
|
328
|
+
hasData: read > 0 || write > 0 || input > 0 || output > 0 || cost > 0,
|
|
329
|
+
trend, hasTrendData, providerName, sessionHitRate,
|
|
330
|
+
dist: distData.finalDist, hasDistData: distData.finalHasDist,
|
|
331
|
+
skills: distData.skills, hasSkills: distData.skills.length > 0,
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
const data = createMemo(() => {
|
|
335
|
+
return dataSignal();
|
|
336
|
+
});
|
|
337
|
+
// Persist the last valid distribution so that data() can fall back
|
|
338
|
+
// to it while api.state.part() is re-hydrating after a view switch.
|
|
339
|
+
createEffect(() => {
|
|
340
|
+
const d = data();
|
|
341
|
+
if (d.hasDistData) {
|
|
342
|
+
setLastDist({ ...d.dist });
|
|
343
|
+
setLastHasDist(true);
|
|
344
|
+
// Also persist across component remounts (view switches)
|
|
345
|
+
try {
|
|
346
|
+
props.api.kv.set(`${KV_PREFIX}.dist_snapshot`, { ...d.dist });
|
|
347
|
+
}
|
|
348
|
+
catch { }
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
// ── token distribution (in-process via api.state.part) ──
|
|
352
|
+
const [partVersion, setPartVersion] = createSignal(0);
|
|
353
|
+
// Persist fold state to api.kv
|
|
354
|
+
const KV_PREFIX = "cache_panel";
|
|
355
|
+
const persistFold = (key, val) => {
|
|
356
|
+
try {
|
|
357
|
+
props.api.kv.set(`${KV_PREFIX}.${key}`, val);
|
|
358
|
+
}
|
|
359
|
+
catch { }
|
|
360
|
+
};
|
|
361
|
+
onMount(() => {
|
|
362
|
+
// Reset panelWidth on (re)mount so the layout uses a clean
|
|
363
|
+
// default until onSizeChange measures the live box dimensions.
|
|
364
|
+
setPanelWidth(DEFAULT_PANEL_WIDTH);
|
|
365
|
+
// Restore fold state from persisted storage (non-critical — fire and forget)
|
|
366
|
+
try {
|
|
367
|
+
setOpen(Boolean(props.api.kv.get(`${KV_PREFIX}.open`, false)));
|
|
368
|
+
setDetailOpen(Boolean(props.api.kv.get(`${KV_PREFIX}.detail`, true)));
|
|
369
|
+
setModelOpen(Boolean(props.api.kv.get(`${KV_PREFIX}.model`, true)));
|
|
370
|
+
setDistOpen(Boolean(props.api.kv.get(`${KV_PREFIX}.dist`, false)));
|
|
371
|
+
setSkillsOpen(Boolean(props.api.kv.get(`${KV_PREFIX}.skills`, true)));
|
|
372
|
+
}
|
|
373
|
+
catch { }
|
|
374
|
+
// Restore user config (currency, rate, section visibility).
|
|
375
|
+
// Try synchronously first (kv is usually ready on mount), fall back to
|
|
376
|
+
// polling if the module was reloaded and kv hasn't initialised yet.
|
|
377
|
+
const doRestore = () => {
|
|
378
|
+
try {
|
|
379
|
+
const sym = props.api.kv.get(`${KV_PREFIX}.currency`);
|
|
380
|
+
const rate = props.api.kv.get(`${KV_PREFIX}.rate`);
|
|
381
|
+
if (typeof sym === "string")
|
|
382
|
+
setCurrencySymbol(sym);
|
|
383
|
+
if (typeof rate === "number" && rate > 0)
|
|
384
|
+
setExchangeRate(rate);
|
|
385
|
+
const balCur = props.api.kv.get(`${KV_PREFIX}.balance_currency`);
|
|
386
|
+
if (typeof balCur === "string")
|
|
387
|
+
setBalanceCurrency(balCur);
|
|
388
|
+
// Restore balance provider (fall back to default when unknown)
|
|
389
|
+
const savedProvider = props.api.kv.get(`${KV_PREFIX}.balance.provider`);
|
|
390
|
+
if (typeof savedProvider === "string" && balanceProviders.some((p) => p.id === savedProvider)) {
|
|
391
|
+
setBalanceProviderId(savedProvider);
|
|
392
|
+
setBalanceUnsupported(false);
|
|
393
|
+
}
|
|
394
|
+
// Restore auto-switch (default on)
|
|
395
|
+
const savedAuto = props.api.kv.get(`${KV_PREFIX}.balance.auto`);
|
|
396
|
+
if (typeof savedAuto === "boolean")
|
|
397
|
+
setAutoBalance(savedAuto);
|
|
398
|
+
// Migrate legacy DeepSeek key (cache_panel.ds_key → cache_panel.balance.deepseek.key)
|
|
399
|
+
const legacyKey = props.api.kv.get(`${KV_PREFIX}.ds_key`, "");
|
|
400
|
+
if (legacyKey) {
|
|
401
|
+
const dsKey = props.api.kv.get(`${KV_PREFIX}.balance.deepseek.key`, "");
|
|
402
|
+
if (!dsKey)
|
|
403
|
+
props.api.kv.set(`${KV_PREFIX}.balance.deepseek.key`, legacyKey);
|
|
404
|
+
props.api.kv.set(`${KV_PREFIX}.ds_key`, "");
|
|
405
|
+
}
|
|
406
|
+
// 恢复的 provider 可能与默认值不同,强制重新查询
|
|
407
|
+
props.signals.setBalanceRefresh(props.signals.balanceRefresh() + 1);
|
|
408
|
+
setSectionDetail(Boolean(props.api.kv.get(`${KV_PREFIX}.section.detail`, true)));
|
|
409
|
+
setSectionModel(Boolean(props.api.kv.get(`${KV_PREFIX}.section.model`, true)));
|
|
410
|
+
setSectionDist(Boolean(props.api.kv.get(`${KV_PREFIX}.section.dist`, true)));
|
|
411
|
+
setSectionSkills(Boolean(props.api.kv.get(`${KV_PREFIX}.section.skills`, true)));
|
|
412
|
+
setSectionBalance(Boolean(props.api.kv.get(`${KV_PREFIX}.section.balance`, true)));
|
|
413
|
+
const bv = props.api.kv.get(`${KV_PREFIX}.border`, true);
|
|
414
|
+
setBorderVisible(bv !== false);
|
|
415
|
+
// Restore distribution snapshot so the token distribution block
|
|
416
|
+
// doesn't blank out while api.state.part() re-hydrates.
|
|
417
|
+
const cachedDist = props.api.kv.get(`${KV_PREFIX}.dist_snapshot`);
|
|
418
|
+
if (cachedDist) {
|
|
419
|
+
setLastDist(cachedDist);
|
|
420
|
+
setLastHasDist(true);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
// kv read failed — signals stay at defaults
|
|
425
|
+
}
|
|
426
|
+
// Re-measure panel width after config signals have settled
|
|
427
|
+
if (boxEl && typeof boxEl.width === "number" && boxEl.width > 0) {
|
|
428
|
+
setPanelWidth(Math.max(MIN_PANEL_WIDTH, boxEl.width));
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
if (props.api.kv.ready) {
|
|
432
|
+
doRestore();
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
// Poll kv.ready with a 1-second timeout to avoid infinite busy-wait
|
|
436
|
+
// on platforms where kv initialisation may be delayed (Linux single-thread
|
|
437
|
+
// mode, session switch storms, etc.).
|
|
438
|
+
const MAX_POLL = 100;
|
|
439
|
+
let tries = 0;
|
|
440
|
+
const pollRestore = () => {
|
|
441
|
+
if (!props.api.kv.ready) {
|
|
442
|
+
if (++tries > MAX_POLL) {
|
|
443
|
+
doRestore();
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
setTimeout(pollRestore, 10);
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
doRestore();
|
|
450
|
+
};
|
|
451
|
+
pollRestore();
|
|
452
|
+
}
|
|
453
|
+
// Debounce partVersion updates so that event bursts during session
|
|
454
|
+
// switching / streaming don't cause data() to re-compute on every
|
|
455
|
+
// single event (up to hundreds per second on Linux single-thread).
|
|
456
|
+
let partTimer;
|
|
457
|
+
const bumpPartVersion = () => {
|
|
458
|
+
clearTimeout(partTimer);
|
|
459
|
+
partTimer = setTimeout(() => setPartVersion((v) => v + 1), 100);
|
|
460
|
+
};
|
|
461
|
+
const unsubPart = props.api.event.on("message.part.updated", () => { bumpPartVersion(); setRefreshTick(v => v + 1); });
|
|
462
|
+
const unsubMsg = props.api.event.on("message.updated", () => { bumpPartVersion(); setRefreshTick(v => v + 1); });
|
|
463
|
+
const unsubSession = props.api.event.on("session.updated", () => { setRefreshTick(v => v + 1); });
|
|
464
|
+
setRefreshTick(v => v + 1);
|
|
465
|
+
onCleanup(() => { clearTimeout(partTimer); unsubPart(); unsubMsg(); unsubSession(); });
|
|
466
|
+
});
|
|
467
|
+
// ── colours ──
|
|
468
|
+
// Pull from the current theme, auto-desaturate if too punchy,
|
|
469
|
+
// fall back to Morandi when a key is missing from the theme.
|
|
470
|
+
const pal = createMemo(() => {
|
|
471
|
+
const t = props.theme;
|
|
472
|
+
const sat = (k, fb) => desaturateTo(t[k], MAX_SAT, fb);
|
|
473
|
+
return {
|
|
474
|
+
primary: sat("primary", FALLBACK.primary),
|
|
475
|
+
text: sat("text", FALLBACK.text),
|
|
476
|
+
muted: sat("textMuted", FALLBACK.muted),
|
|
477
|
+
success: sat("success", FALLBACK.success),
|
|
478
|
+
warning: sat("warning", FALLBACK.warning),
|
|
479
|
+
error: sat("error", FALLBACK.error),
|
|
480
|
+
border: sat("border", FALLBACK.border),
|
|
481
|
+
};
|
|
482
|
+
});
|
|
483
|
+
const hitColor = createMemo(() => {
|
|
484
|
+
const r = data().hitRate;
|
|
485
|
+
if (r >= 85)
|
|
486
|
+
return pal().success;
|
|
487
|
+
if (r >= 70)
|
|
488
|
+
return pal().warning;
|
|
489
|
+
return pal().error;
|
|
490
|
+
});
|
|
491
|
+
/** Horizontal space eaten by border (1+1 when visible) + padding (2+2 when visible). */
|
|
492
|
+
const gutter = createMemo(() => borderVisible() ? 6 : 0);
|
|
493
|
+
const sep = createMemo(() => "\u2500".repeat(Math.max(1, panelWidth() - gutter())));
|
|
494
|
+
function trendLabel(t) {
|
|
495
|
+
// |t| < 0.05 视为无变化:避免显示 "↑0.0%" 的矛盾(箭头存在但数值截断为零)
|
|
496
|
+
if (Math.abs(t) < 0.05)
|
|
497
|
+
return "-";
|
|
498
|
+
return (t > 0 ? "\u2191" : "\u2193") + Math.abs(t).toFixed(1) + "%";
|
|
499
|
+
}
|
|
500
|
+
const barW = createMemo(() => {
|
|
501
|
+
const trendSpace = data().hasTrendData ? LABEL_GAP + visualWidth(trendLabel(data().trend)) : 0;
|
|
502
|
+
const overhead = visualWidth(t("hit")) + LABEL_GAP + BAR_BRACKETS + BAR_GAP + PCT_FIXED_WIDTH + trendSpace + gutter();
|
|
503
|
+
return Math.max(3, panelWidth() - overhead);
|
|
504
|
+
});
|
|
505
|
+
const bar = createMemo(() => progressBar(data().hitRate, barW()));
|
|
506
|
+
const pct = createMemo(() => (Math.floor(data().hitRate * 10) / 10).toFixed(1) + "%");
|
|
507
|
+
// When border visibility changes the box dimensions shift, which
|
|
508
|
+
// may not reliably trigger onSizeChange across (re)mount cycles.
|
|
509
|
+
// Force panelWidth to resync with the live box after every change.
|
|
510
|
+
createEffect(() => {
|
|
511
|
+
borderVisible();
|
|
512
|
+
if (boxEl && typeof boxEl.width === "number" && boxEl.width > 0) {
|
|
513
|
+
const w = Math.max(MIN_PANEL_WIDTH, boxEl.width);
|
|
514
|
+
setPanelWidth((prev) => (prev === w ? prev : w));
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
// left-align label, right-align value — auto-fill space between
|
|
518
|
+
const justify = (label, value, unit = "") => {
|
|
519
|
+
const gauge = panelWidth() - gutter();
|
|
520
|
+
const used = visualWidth(label) + visualWidth(value) + (unit ? visualWidth(unit) + UNIT_GAP : 0);
|
|
521
|
+
const gap = Math.max(1, gauge - used);
|
|
522
|
+
return label + " ".repeat(gap) + value + (unit ? " " + unit : "");
|
|
523
|
+
};
|
|
524
|
+
return (_jsxs("box", { border: borderVisible(), ...(borderVisible() ? { borderColor: pal().border } : {}), paddingTop: 0, paddingBottom: 0, paddingLeft: borderVisible() ? 2 : 0, paddingRight: borderVisible() ? 2 : 0, flexDirection: "column", gap: 0, ref: boxEl, onSizeChange: () => {
|
|
525
|
+
// boxEl.width may be undefined before the first measurement — guard with 0
|
|
526
|
+
const w = boxEl ? Math.max(MIN_PANEL_WIDTH, boxEl.width ?? 0) : DEFAULT_PANEL_WIDTH;
|
|
527
|
+
setPanelWidth((prev) => (prev === w ? prev : w));
|
|
528
|
+
}, children: [_jsxs("text", { onMouseUp: () => setOpen((o) => { const n = !o; persistFold("open", n); return n; }), children: [_jsx("span", { style: { fg: pal().muted }, children: open() ? "\u25bc " : "\u25b6 " }), _jsxs("span", { style: { fg: pal().primary }, children: [_jsx("b", { children: t("title") }), _jsx(Show, { when: open(), children: _jsxs("span", { style: { fg: dimColor(pal().muted, 0.75) }, children: [" v", PLUGIN_VERSION] }) })] }), _jsxs(Show, { when: !open() && data().hasData, children: [_jsxs(Show, { when: data().hasTrendData, children: [_jsx("span", { children: " ".repeat(Math.max(1, panelWidth() - gutter() - HEADER_PREFIX - visualWidth(t("title")) - visualWidth(pct() + " " + t("hitFolded") + " " + trendLabel(data().trend)))) }), _jsxs("span", { style: { fg: hitColor() }, children: [pct(), " ", t("hitFolded")] }), _jsxs("span", { style: { fg: Math.abs(data().trend) >= 0.05 ? (data().trend > 0 ? pal().success : pal().error) : pal().text }, children: [" ", trendLabel(data().trend)] })] }), _jsxs(Show, { when: !data().hasTrendData, children: [_jsx("span", { children: " ".repeat(Math.max(1, panelWidth() - gutter() - HEADER_PREFIX - visualWidth(t("title")) - visualWidth(pct() + " " + t("hitFolded")))) }), _jsxs("span", { style: { fg: hitColor() }, children: [pct(), " ", t("hitFolded")] })] })] })] }), _jsxs(Show, { when: open(), children: [_jsx(Show, { when: props.signals.overrideSessionId(), children: (() => {
|
|
529
|
+
const prefix = " \u21b3 " + t("subPrefix");
|
|
530
|
+
const maxSidW = Math.max(6, panelWidth() - visualWidth(prefix));
|
|
531
|
+
return (_jsxs("text", { children: [_jsx("span", { style: { fg: pal().muted }, children: prefix }), _jsx("span", { style: { fg: pal().text }, children: truncateVisual(props.signals.overrideSessionId(), maxSidW) })] }));
|
|
532
|
+
})() }), _jsxs(Show, { when: data().hasData, fallback: _jsxs(_Fragment, { children: [_jsx("text", { fg: pal().muted, children: sep() }), _jsxs("text", { children: [_jsx("span", { style: { fg: pal().muted }, children: "> " }), _jsx("span", { style: { fg: pal().muted }, children: t("noData") })] })] }), children: [_jsx("text", { fg: pal().muted, children: sep() }), _jsxs("text", { children: [_jsxs("span", { style: { fg: pal().text }, children: [t("hit"), " "] }), _jsxs("span", { style: { fg: hitColor() }, children: ["[", bar(), "] "] }), _jsx("span", { style: { fg: pal().text }, children: pct() }), _jsx(Show, { when: data().hasTrendData, children: _jsxs("span", { style: { fg: Math.abs(data().trend) >= 0.05 ? (data().trend > 0 ? pal().success : pal().error) : pal().text }, children: [" ", trendLabel(data().trend)] }) })] }), _jsx("text", { fg: pal().muted, children: justify(t("totalHit"), (Math.floor(data().sessionHitRate * 10) / 10).toFixed(1) + "%") }), _jsxs(Show, { when: sectionDetail(), children: [_jsxs("text", { onMouseUp: () => setDetailOpen((o) => { const n = !o; persistFold("detail", n); return n; }), children: [_jsx("span", { style: { fg: pal().muted }, children: detailOpen() ? "\u25bc " : "\u25b6 " }), _jsx("span", { style: { fg: pal().primary }, children: _jsx("b", { children: t("secDetail") }) }), _jsx("span", { style: { fg: pal().muted }, children: sep().slice(visualWidth((detailOpen() ? "\u25bc " : "\u25b6 ") + t("secDetail"))) })] }), _jsxs(Show, { when: detailOpen(), children: [_jsx(Show, { when: data().read > 0, children: _jsx("text", { fg: pal().muted, children: justify(t("read"), fmt(data().read), t("tok")) }) }), _jsx(Show, { when: data().write > 0, children: _jsx("text", { fg: pal().muted, children: justify(t("write"), fmt(data().write), t("tok")) }) }), _jsx("text", { fg: pal().muted, children: justify(t("miss"), fmt(data().freshInput + data().write), t("tok")) }), _jsx("text", { fg: pal().muted, children: justify(t("out"), fmt(data().output), t("tok")) }), _jsx(Show, { when: data().dist.stepCount >= 2, children: _jsx("text", { fg: pal().muted, children: justify(t("stepsCount", { n: data().dist.stepCount }), fmtCost(data().dist.stepCost, currencySymbol(), exchangeRate())) }) }), _jsx(Show, { when: data().saved > 0, children: _jsxs("text", { children: [_jsx("span", { style: { fg: pal().muted }, children: t("saved") }), _jsx("span", { children: " ".repeat(Math.max(1, panelWidth() - gutter() - visualWidth(t("saved")) - visualWidth("~" + fmtCost(data().saved, currencySymbol(), exchangeRate())))) }), _jsxs("span", { style: { fg: pal().success }, children: ["~", fmtCost(data().saved, currencySymbol(), exchangeRate())] })] }) })] })] }), _jsxs(Show, { when: sectionModel(), children: [_jsxs("text", { onMouseUp: () => setModelOpen((o) => { const n = !o; persistFold("model", n); return n; }), children: [_jsx("span", { style: { fg: pal().muted }, children: modelOpen() ? "\u25bc " : "\u25b6 " }), _jsx("span", { style: { fg: pal().primary }, children: _jsx("b", { children: t("secModel") }) }), _jsx("span", { style: { fg: pal().muted }, children: sep().slice(visualWidth((modelOpen() ? "\u25bc " : "\u25b6 ") + t("secModel"))) })] }), _jsxs(Show, { when: modelOpen(), children: [_jsx("text", { fg: pal().text, children: justify(t("cost"), fmtCost(data().cost, currencySymbol(), exchangeRate())) }), _jsx(Show, { when: data().providerName, children: _jsx("text", { fg: pal().muted, children: justify(t("provider"), data().providerName) }) }), _jsx("text", { fg: pal().muted, children: justify(t("model"), data().model) }), _jsxs(Show, { when: data().hasPricing, children: [_jsx("text", { fg: pal().muted, children: justify(t("rate"), currencySymbol() + (data().inputRate * exchangeRate()).toFixed(2) + "/M " + t("inputRate")) }), _jsx(Show, { when: data().cacheReadRate > 0, children: _jsx("text", { fg: pal().muted, children: justify("", currencySymbol() + (data().cacheReadRate * exchangeRate()).toFixed(2) + "/M " + t("cacheRate")) }) }), _jsx(Show, { when: data().cacheWriteRate > 0, children: _jsx("text", { fg: pal().muted, children: justify("", currencySymbol() + (data().cacheWriteRate * exchangeRate()).toFixed(2) + "/M " + t("writeRate")) }) })] })] })] }), _jsx(Show, { when: sectionDist(), children: _jsxs(Show, { when: data().hasDistData, children: [_jsxs("text", { onMouseUp: () => setDistOpen((o) => { const n = !o; persistFold("dist", n); return n; }), children: [_jsx("span", { style: { fg: pal().muted }, children: distOpen() ? "\u25bc " : "\u25b6 " }), _jsx("span", { style: { fg: pal().primary }, children: _jsx("b", { children: t("distTitle") }) }), _jsx("span", { style: { fg: pal().muted }, children: sep().slice(visualWidth((distOpen() ? "\u25bc " : "\u25b6 ") + t("distTitle"))) })] }), _jsxs(Show, { when: distOpen(), children: [_jsx(Show, { when: data().dist.system > 0, children: _jsx("text", { fg: pal().muted, children: justify(t("distSys"), fmt(data().dist.system), t("tok")) }) }), _jsx(Show, { when: data().dist.user > 0, children: _jsx("text", { fg: pal().muted, children: justify(t("distUser"), fmt(data().dist.user), t("tok")) }) }), _jsx(Show, { when: data().dist.agent > 0, children: _jsx("text", { fg: pal().muted, children: justify(t("distAgent"), fmt(data().dist.agent), t("tok")) }) }), _jsx(Show, { when: data().dist.toolCall > 0, children: _jsx("text", { fg: pal().muted, children: justify(t("distTool"), fmt(data().dist.toolCall), t("tok")) }) }), _jsx(Show, { when: data().dist.toolResult > 0, children: _jsx("text", { fg: pal().muted, children: justify(t("distRes"), fmt(data().dist.toolResult), t("tok")) }) }), _jsx(Show, { when: data().dist.reasoning > 0, children: _jsx("text", { fg: pal().muted, children: justify(t("distReason"), fmt(data().dist.reasoning), t("tok")) }) })] })] }) }), _jsx(Show, { when: sectionSkills(), children: _jsxs(Show, { when: data().hasSkills, children: [_jsxs("text", { onMouseUp: () => setSkillsOpen((o) => { const n = !o; persistFold("skills", n); return n; }), children: [_jsx("span", { style: { fg: pal().muted }, children: skillsOpen() ? "\u25bc " : "\u25b6 " }), _jsx("span", { style: { fg: pal().primary }, children: _jsx("b", { children: t("secSkills") }) }), _jsxs("span", { style: { fg: pal().muted }, children: [" (", data().skills.length, ")"] }), _jsx("span", { style: { fg: pal().muted }, children: sep().slice(visualWidth((skillsOpen() ? "\u25bc " : "\u25b6 ") + t("secSkills") + ` (${data().skills.length})`)) })] }), _jsx(Show, { when: skillsOpen(), children: data().skills.map((sk) => {
|
|
533
|
+
const rightW = visualWidth(fmt(sk.tokens)) + UNIT_GAP + visualWidth(t("tok"));
|
|
534
|
+
const maxLabel = Math.max(4, panelWidth() - gutter() - rightW - 1);
|
|
535
|
+
const label = truncateVisual(sk.name, maxLabel);
|
|
536
|
+
return (_jsx("text", { fg: pal().muted, children: justify(label, fmt(sk.tokens), t("tok")) }));
|
|
537
|
+
}) })] }) }), _jsxs(Show, { when: sectionBalance(), children: [_jsx("text", { fg: pal().muted, children: sep() }), _jsx(Show, { when: balanceUnsupported(), children: _jsxs("text", { fg: pal().muted, children: [_jsx("span", { style: { fg: pal().muted }, children: "> " }), _jsx("span", { children: t("balUnsupported") })] }) }), _jsxs(Show, { when: !balanceUnsupported(), children: [_jsx(Show, { when: balanceState().status === "idle", children: _jsxs("text", { fg: pal().muted, children: [_jsx("span", { style: { fg: pal().muted }, children: "> " }), _jsx("span", { children: t("balNoKey", { p: providerName() }) })] }) }), _jsx(Show, { when: balanceState().status === "loading", children: _jsxs("text", { fg: pal().muted, children: [_jsx("span", { style: { fg: pal().muted }, children: "> " }), _jsx("span", { children: t("balLoading") })] }) }), _jsx(Show, { when: balanceState().status === "error", children: _jsxs("text", { fg: pal().error, children: [_jsx("span", { style: { fg: pal().muted }, children: "> " }), _jsx("span", { children: (() => {
|
|
538
|
+
const code = balanceState().error;
|
|
539
|
+
if (code === "401")
|
|
540
|
+
return t("balErr401");
|
|
541
|
+
if (code === "403")
|
|
542
|
+
return t("balErr403");
|
|
543
|
+
if (code === "EMPTY")
|
|
544
|
+
return t("balErrEmpty");
|
|
545
|
+
if (code === "TIMEOUT")
|
|
546
|
+
return t("balErrTimeout");
|
|
547
|
+
return t("balError") + (code ? ` (${code})` : "");
|
|
548
|
+
})() })] }) }), _jsx(Show, { when: balanceState().status === "ok" && balanceState().data, children: _jsx("text", { fg: pal().text, children: justify(t("balTotal"), formatBalanceText(balanceState().data, balanceCurrency(), exchangeRate())) }) })] })] })] })] })] }));
|
|
549
|
+
}
|