@nandoblanco/opencode-local-tokens 0.0.0-stage → 0.1.1
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 +51 -0
- package/HANDOFF-MEASUREMENT.md +45 -0
- package/LICENSE +21 -0
- package/README.md +195 -3
- package/cli.js +9 -0
- package/dist/gui-experimental.cjs +1 -0
- package/package.json +82 -6
- package/src/gui.css +1007 -0
- package/src/gui.tsx +1311 -0
- package/src/handoff.ts +103 -0
- package/src/index.ts +4 -0
- package/src/measurement.ts +86 -0
- package/src/prepare-handoff.ts +39 -0
- package/src/rpc.ts +179 -0
- package/src/server.ts +223 -0
- package/src/summary.ts +208 -0
- package/src/tokens.ts +2286 -0
- package/src/tui.ts +919 -0
package/src/gui.tsx
ADDED
|
@@ -0,0 +1,1311 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Command,
|
|
3
|
+
MenuItem,
|
|
4
|
+
Panel,
|
|
5
|
+
Plugin,
|
|
6
|
+
Slot,
|
|
7
|
+
Style,
|
|
8
|
+
type MenuEntry,
|
|
9
|
+
type PanelTab,
|
|
10
|
+
type PluginContext,
|
|
11
|
+
} from "@opencode/plugin/gui";
|
|
12
|
+
import { For, Show, createEffect, createMemo, createSignal, onCleanup } from "solid-js";
|
|
13
|
+
import css from "./gui.css?inline";
|
|
14
|
+
import {
|
|
15
|
+
TokensRpc,
|
|
16
|
+
type MatchedSessionRow,
|
|
17
|
+
type SessionStepStatus,
|
|
18
|
+
type TagTokenStats,
|
|
19
|
+
type TokenCounters,
|
|
20
|
+
type TokensReport,
|
|
21
|
+
} from "./rpc.ts";
|
|
22
|
+
import type { TokenSummary } from "./summary.ts";
|
|
23
|
+
|
|
24
|
+
export type TokenSortMode =
|
|
25
|
+
| "billed"
|
|
26
|
+
| "total"
|
|
27
|
+
| "steps"
|
|
28
|
+
| "updated"
|
|
29
|
+
| "newest"
|
|
30
|
+
| "oldest"
|
|
31
|
+
| "title"
|
|
32
|
+
| "relevance";
|
|
33
|
+
|
|
34
|
+
const TOKEN_SORT_LABELS: Record<TokenSortMode, string> = {
|
|
35
|
+
billed: "Billed tokens",
|
|
36
|
+
total: "Total w/ cache",
|
|
37
|
+
steps: "Most steps",
|
|
38
|
+
updated: "Recently updated",
|
|
39
|
+
newest: "Newest created",
|
|
40
|
+
oldest: "Oldest created",
|
|
41
|
+
title: "Title (A-Z)",
|
|
42
|
+
relevance: "Best match",
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const COINS_ICON_SVG =
|
|
46
|
+
'<svg data-slot="icon-svg" width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" class="shrink-0" aria-hidden="true">' +
|
|
47
|
+
'<ellipse cx="6.5" cy="4.25" rx="4.25" ry="1.85" stroke="currentColor" stroke-width="1.25"/>' +
|
|
48
|
+
'<path d="M2.25 4.25v3.1c0 1.02 1.9 1.85 4.25 1.85s4.25-.83 4.25-1.85v-3.1" stroke="currentColor" stroke-width="1.25"/>' +
|
|
49
|
+
'<path d="M2.25 7.35v3.1c0 1.02 1.9 1.85 4.25 1.85 1.05 0 2.01-.16 2.75-.43" stroke="currentColor" stroke-width="1.25" stroke-linecap="round"/>' +
|
|
50
|
+
'<ellipse cx="10.75" cy="9.15" rx="3.25" ry="1.5" stroke="currentColor" stroke-width="1.25"/>' +
|
|
51
|
+
'<path d="M7.5 9.15v2.7c0 .83 1.46 1.5 3.25 1.5s3.25-.67 3.25-1.5v-2.7" stroke="currentColor" stroke-width="1.25"/>' +
|
|
52
|
+
"</svg>";
|
|
53
|
+
function fmtCompact(n: number): string {
|
|
54
|
+
if (!n || n <= 0) return "0";
|
|
55
|
+
if (n >= 1_000_000_000) return `${(n / 1_000_000_000).toFixed(2)}B`;
|
|
56
|
+
if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
|
|
57
|
+
if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`;
|
|
58
|
+
return String(n);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function billedTokens(t: TokenCounters): number {
|
|
62
|
+
return (t.input || 0) + (t.output || 0) + (t.reasoning || 0);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function totalTokensWithCache(t: TokenCounters): number {
|
|
66
|
+
return billedTokens(t) + (t.cacheRead || 0) + (t.cacheWrite || 0);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function formatDate(ts: number): string {
|
|
70
|
+
if (!ts) return "";
|
|
71
|
+
const d = new Date(ts);
|
|
72
|
+
const yyyy = d.getFullYear();
|
|
73
|
+
const mm = String(d.getMonth() + 1).padStart(2, "0");
|
|
74
|
+
const dd = String(d.getDate()).padStart(2, "0");
|
|
75
|
+
const hh = String(d.getHours()).padStart(2, "0");
|
|
76
|
+
const min = String(d.getMinutes()).padStart(2, "0");
|
|
77
|
+
return `${yyyy}-${mm}-${dd} ${hh}:${min}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function resolveServerId(ctx: PluginContext): string {
|
|
81
|
+
const active = ctx.sessions.current();
|
|
82
|
+
if (active?.server?.id) return active.server.id;
|
|
83
|
+
const list = ctx.servers.list();
|
|
84
|
+
for (const id of list) {
|
|
85
|
+
if (ctx.servers.get(id)?.builtin) return id;
|
|
86
|
+
}
|
|
87
|
+
return list[0] ?? "sidecar";
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function getRpcClient(ctx: PluginContext) {
|
|
91
|
+
const activeSession = ctx.sessions.current();
|
|
92
|
+
if (activeSession?.server?.client) {
|
|
93
|
+
return activeSession.server.client.rpc(TokensRpc);
|
|
94
|
+
}
|
|
95
|
+
const serverIds = ctx.servers?.list?.() ?? [];
|
|
96
|
+
const server =
|
|
97
|
+
serverIds.map((id) => ctx.servers.get(id)).find((s) => s?.builtin) ??
|
|
98
|
+
serverIds.map((id) => ctx.servers.get(id)).find((s) => s?.local) ??
|
|
99
|
+
serverIds.map((id) => ctx.servers.get(id)).find((s) => s !== undefined);
|
|
100
|
+
const client = server?.client ?? ctx.client;
|
|
101
|
+
return client.rpc(TokensRpc);
|
|
102
|
+
}
|
|
103
|
+
interface TokensSurfaceProps { ctx: PluginContext; initialTokensInput?: string; variant: "panel" | "modal"; onClose?: () => void; }
|
|
104
|
+
const [oltPanelTokensInput, setOltPanelTokensInput] = createSignal("");
|
|
105
|
+
let tokensFallbackDialog: { close(): void } | undefined;
|
|
106
|
+
|
|
107
|
+
function openTokensPanel(ctx: PluginContext, tokensInput = "") {
|
|
108
|
+
setOltPanelTokensInput(tokensInput);
|
|
109
|
+
const session = ctx.sessions.current();
|
|
110
|
+
if (!session) {
|
|
111
|
+
if (tokensFallbackDialog) return;
|
|
112
|
+
const ui = ctx.ui;
|
|
113
|
+
tokensFallbackDialog = ctx.dialogs.open((dialog) => {
|
|
114
|
+
onCleanup(() => { tokensFallbackDialog = undefined; });
|
|
115
|
+
return (
|
|
116
|
+
<ui.Dialog title="Token Audit" size="x-large">
|
|
117
|
+
<TokensSurface ctx={ctx} variant="modal" initialTokensInput={tokensInput} onClose={dialog.close} />
|
|
118
|
+
</ui.Dialog>
|
|
119
|
+
);
|
|
120
|
+
});
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
tokensFallbackDialog?.close();
|
|
124
|
+
try {
|
|
125
|
+
// Always select the tab so it becomes the focused panel even if another
|
|
126
|
+
// panel (search, memory, backups) is already open.
|
|
127
|
+
ctx.layout.open(`${ctx.id}:tokens`, session);
|
|
128
|
+
} catch {
|
|
129
|
+
// Layout not ready; the auto-open effect will surface it.
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function TokensSurface(props: TokensSurfaceProps) {
|
|
133
|
+
const ui = props.ctx.ui;
|
|
134
|
+
|
|
135
|
+
const [tokensInput, setTokensInput] = createSignal(props.initialTokensInput ?? "");
|
|
136
|
+
const [likedOnly, setLikedOnly] = createSignal(false);
|
|
137
|
+
const [sortMode, setSortMode] = createSignal<TokenSortMode>("billed");
|
|
138
|
+
const [lowerViewTab, setLowerViewTab] = createSignal<"sessions" | "tags">("sessions");
|
|
139
|
+
const [selectedTagIndex, setSelectedTagIndex] = createSignal(0);
|
|
140
|
+
const [newTagInput, setNewTagInput] = createSignal("");
|
|
141
|
+
const [mutatingTag, setMutatingTag] = createSignal(false);
|
|
142
|
+
const [report, setReport] = createSignal<TokensReport | null>(null);
|
|
143
|
+
const [loadingTokens, setLoadingTokens] = createSignal(false);
|
|
144
|
+
const [selectedIndex, setSelectedIndex] = createSignal(0);
|
|
145
|
+
const [summary, setSummary] = createSignal<{ local30d: TokenSummary; localAllTime: TokenSummary }>();
|
|
146
|
+
const [range, setRange] = createSignal<"local30d" | "localAllTime">("local30d");
|
|
147
|
+
const [view, setView] = createSignal<"list" | "detail">("list");
|
|
148
|
+
void getRpcClient(props.ctx).summary({}).then(setSummary).catch(error => {
|
|
149
|
+
props.ctx.toast.show({ title: "Failed to load token totals", description: String(error), variant: "error" });
|
|
150
|
+
});
|
|
151
|
+
createEffect(() => {
|
|
152
|
+
const input = oltPanelTokensInput();
|
|
153
|
+
if (input) setTokensInput(input);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
let debounceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
157
|
+
async function loadTokensReport() {
|
|
158
|
+
setLoadingTokens(true);
|
|
159
|
+
try {
|
|
160
|
+
const raw = tokensInput().trim();
|
|
161
|
+
const effectiveRaw = likedOnly() && !/\bliked\b|\*/i.test(raw) ? `${raw} liked`.trim() : raw;
|
|
162
|
+
const res = await getRpcClient(props.ctx).tokens({
|
|
163
|
+
rawInput: effectiveRaw,
|
|
164
|
+
limit: 80,
|
|
165
|
+
});
|
|
166
|
+
if (res && Array.isArray(res.sessions)) {
|
|
167
|
+
setReport({
|
|
168
|
+
...res,
|
|
169
|
+
sessions: res.sessions.map((s) => ({
|
|
170
|
+
...s,
|
|
171
|
+
tags: [...(s.tags || [])],
|
|
172
|
+
customTags: [...(s.customTags || [])],
|
|
173
|
+
})),
|
|
174
|
+
});
|
|
175
|
+
setSelectedIndex((prev) =>
|
|
176
|
+
Math.max(0, Math.min(prev, Math.max(0, res.sessions.length - 1)))
|
|
177
|
+
);
|
|
178
|
+
setSelectedTagIndex((prev) =>
|
|
179
|
+
Math.max(0, Math.min(prev, Math.max(0, (res.topTags?.length ?? 1) - 1)))
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
} catch {
|
|
183
|
+
// Ignore transient errors
|
|
184
|
+
} finally {
|
|
185
|
+
setLoadingTokens(false);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
createEffect(() => {
|
|
189
|
+
void tokensInput();
|
|
190
|
+
void likedOnly();
|
|
191
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
192
|
+
debounceTimer = setTimeout(() => {
|
|
193
|
+
void loadTokensReport();
|
|
194
|
+
}, 35);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
onCleanup(() => {
|
|
198
|
+
if (debounceTimer) clearTimeout(debounceTimer);
|
|
199
|
+
});
|
|
200
|
+
const matchedSessions = createMemo<MatchedSessionRow[]>(() => {
|
|
201
|
+
const rows = [...(report()?.sessions ?? [])];
|
|
202
|
+
const mode = sortMode();
|
|
203
|
+
rows.sort((a, b) => {
|
|
204
|
+
if (mode === "billed") {
|
|
205
|
+
const diff = billedTokens(b.tokens) - billedTokens(a.tokens);
|
|
206
|
+
if (diff !== 0) return diff;
|
|
207
|
+
} else if (mode === "total") {
|
|
208
|
+
const diff = totalTokensWithCache(b.tokens) - totalTokensWithCache(a.tokens);
|
|
209
|
+
if (diff !== 0) return diff;
|
|
210
|
+
} else if (mode === "steps") {
|
|
211
|
+
const diff = (b.steps || b.turns || 0) - (a.steps || a.turns || 0);
|
|
212
|
+
if (diff !== 0) return diff;
|
|
213
|
+
} else if (mode === "updated") {
|
|
214
|
+
const diff = (b.timeUpdated || 0) - (a.timeUpdated || 0);
|
|
215
|
+
if (diff !== 0) return diff;
|
|
216
|
+
} else if (mode === "newest") {
|
|
217
|
+
const diff = (b.timeCreated || b.timeUpdated || 0) - (a.timeCreated || a.timeUpdated || 0);
|
|
218
|
+
if (diff !== 0) return diff;
|
|
219
|
+
} else if (mode === "oldest") {
|
|
220
|
+
const diff = (a.timeCreated || a.timeUpdated || 0) - (b.timeCreated || b.timeUpdated || 0);
|
|
221
|
+
if (diff !== 0) return diff;
|
|
222
|
+
} else if (mode === "title") {
|
|
223
|
+
const cmp = (a.smartTitle || "").localeCompare(b.smartTitle || "", undefined, {
|
|
224
|
+
sensitivity: "base",
|
|
225
|
+
});
|
|
226
|
+
if (cmp !== 0) return cmp;
|
|
227
|
+
} else if (mode === "relevance") {
|
|
228
|
+
const diff = (b.score || 0) - (a.score || 0);
|
|
229
|
+
if (Math.abs(diff) > 0.01) return diff;
|
|
230
|
+
}
|
|
231
|
+
return billedTokens(b.tokens) - billedTokens(a.tokens);
|
|
232
|
+
});
|
|
233
|
+
return rows;
|
|
234
|
+
});
|
|
235
|
+
const selectedSession = createMemo<MatchedSessionRow | undefined>(
|
|
236
|
+
() => matchedSessions()[selectedIndex()] ?? matchedSessions()[0]
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const tagRows = createMemo<Array<{ tag: string; info: TagTokenStats }>>(() =>
|
|
240
|
+
(report()?.topTags ?? []).map(([tag, info]) => ({ tag, info }))
|
|
241
|
+
);
|
|
242
|
+
const selectedTag = createMemo<{ tag: string; info: TagTokenStats } | undefined>(
|
|
243
|
+
() => tagRows()[selectedTagIndex()] ?? tagRows()[0]
|
|
244
|
+
);
|
|
245
|
+
const selectedTagSessions = createMemo<MatchedSessionRow[]>(() => {
|
|
246
|
+
const cur = selectedTag();
|
|
247
|
+
if (!cur) return [];
|
|
248
|
+
const target = cur.tag.toLowerCase();
|
|
249
|
+
return matchedSessions().filter((s) =>
|
|
250
|
+
(s.tags || []).some((t) => t.toLowerCase() === target)
|
|
251
|
+
);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const sortMenuItems = createMemo<MenuEntry[]>(() => {
|
|
255
|
+
const active = sortMode();
|
|
256
|
+
const modes: TokenSortMode[] = [
|
|
257
|
+
"billed",
|
|
258
|
+
"total",
|
|
259
|
+
"steps",
|
|
260
|
+
"updated",
|
|
261
|
+
"newest",
|
|
262
|
+
"oldest",
|
|
263
|
+
"title",
|
|
264
|
+
"relevance",
|
|
265
|
+
];
|
|
266
|
+
return modes.map((mode) => ({
|
|
267
|
+
id: `sort-${mode}`,
|
|
268
|
+
label: TOKEN_SORT_LABELS[mode],
|
|
269
|
+
checked: active === mode,
|
|
270
|
+
onSelect: () => {
|
|
271
|
+
setSortMode(mode);
|
|
272
|
+
setSelectedIndex(0);
|
|
273
|
+
},
|
|
274
|
+
}));
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
async function addSessionTag(s: MatchedSessionRow | undefined, rawTag: string) {
|
|
278
|
+
const cleaned = rawTag.replace(/^#/, "").trim().toLowerCase();
|
|
279
|
+
if (!s || !cleaned || mutatingTag()) return;
|
|
280
|
+
setMutatingTag(true);
|
|
281
|
+
try {
|
|
282
|
+
const res = await getRpcClient(props.ctx).mutateSession({
|
|
283
|
+
action: "tag",
|
|
284
|
+
sessionPrefix: s.id,
|
|
285
|
+
value: cleaned,
|
|
286
|
+
});
|
|
287
|
+
if (res.ok) {
|
|
288
|
+
setNewTagInput("");
|
|
289
|
+
await loadTokensReport();
|
|
290
|
+
} else if (res.error) {
|
|
291
|
+
props.ctx.toast.show({ title: "Tag failed", description: res.error, variant: "error" });
|
|
292
|
+
}
|
|
293
|
+
} catch (err) {
|
|
294
|
+
props.ctx.toast.show({ title: "Tag failed", description: String(err), variant: "error" });
|
|
295
|
+
} finally {
|
|
296
|
+
setMutatingTag(false);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
async function removeSessionTag(s: MatchedSessionRow | undefined, tag: string) {
|
|
301
|
+
if (!s || !tag || mutatingTag()) return;
|
|
302
|
+
setMutatingTag(true);
|
|
303
|
+
try {
|
|
304
|
+
const res = await getRpcClient(props.ctx).mutateSession({
|
|
305
|
+
action: "untag",
|
|
306
|
+
sessionPrefix: s.id,
|
|
307
|
+
value: tag,
|
|
308
|
+
});
|
|
309
|
+
if (res.ok) {
|
|
310
|
+
await loadTokensReport();
|
|
311
|
+
}
|
|
312
|
+
} catch {} finally {
|
|
313
|
+
setMutatingTag(false);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function applyQuickTokenFilter(token: string) {
|
|
318
|
+
const cur = tokensInput().trim();
|
|
319
|
+
if (cur.toLowerCase().includes(token.toLowerCase())) {
|
|
320
|
+
setTokensInput(
|
|
321
|
+
cur
|
|
322
|
+
.split(/\s+/)
|
|
323
|
+
.filter((t) => t.toLowerCase() !== token.toLowerCase())
|
|
324
|
+
.join(" ")
|
|
325
|
+
);
|
|
326
|
+
} else {
|
|
327
|
+
setTokensInput(cur ? `${cur} ${token}` : token);
|
|
328
|
+
}
|
|
329
|
+
setSelectedIndex(0);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async function toggleLikeSession(s: MatchedSessionRow | undefined) {
|
|
333
|
+
if (!s) return;
|
|
334
|
+
try {
|
|
335
|
+
const res = await getRpcClient(props.ctx).mutateSession({
|
|
336
|
+
action: s.liked ? "unlike" : "like",
|
|
337
|
+
sessionPrefix: s.id,
|
|
338
|
+
});
|
|
339
|
+
if (res.ok) {
|
|
340
|
+
void loadTokensReport();
|
|
341
|
+
}
|
|
342
|
+
} catch {}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function openSession(s: MatchedSessionRow | undefined) {
|
|
346
|
+
if (!s) return;
|
|
347
|
+
if (s.id.startsWith("claude_") || s.id.startsWith("codex_")) {
|
|
348
|
+
props.ctx.toast.show({
|
|
349
|
+
title: `External CLI session (${s.shortId})`,
|
|
350
|
+
variant: "info",
|
|
351
|
+
});
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
const serverId = resolveServerId(props.ctx);
|
|
355
|
+
props.ctx.tabs.open({ server: serverId, id: s.id }, { focus: true });
|
|
356
|
+
props.onClose?.();
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
360
|
+
const target = e.target as HTMLElement | null;
|
|
361
|
+
const inInput =
|
|
362
|
+
target?.tagName === "INPUT" ||
|
|
363
|
+
target?.tagName === "TEXTAREA" ||
|
|
364
|
+
target?.isContentEditable;
|
|
365
|
+
|
|
366
|
+
{
|
|
367
|
+
const rows = matchedSessions();
|
|
368
|
+
if (e.key === "Escape" && view() === "detail") {
|
|
369
|
+
e.preventDefault();
|
|
370
|
+
e.stopPropagation();
|
|
371
|
+
setView("list");
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
const down = e.key === "ArrowDown" || (e.ctrlKey && e.key.toLowerCase() === "n");
|
|
375
|
+
const up = e.key === "ArrowUp" || (e.ctrlKey && e.key.toLowerCase() === "p");
|
|
376
|
+
if (down || up) {
|
|
377
|
+
e.preventDefault();
|
|
378
|
+
if (rows.length > 0) setSelectedIndex((i) => (down ? Math.min(rows.length - 1, i + 1) : Math.max(0, i - 1)));
|
|
379
|
+
const root = e.currentTarget as HTMLElement;
|
|
380
|
+
requestAnimationFrame(() => root.querySelector(".olu-session-row--selected")?.scrollIntoView({ block: "nearest" }));
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
if (e.key === "Enter" && (e.ctrlKey || e.metaKey)) {
|
|
384
|
+
const picked = selectedSession();
|
|
385
|
+
if (picked) {
|
|
386
|
+
e.preventDefault();
|
|
387
|
+
e.stopPropagation();
|
|
388
|
+
openSession(picked);
|
|
389
|
+
}
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
if (e.key === "Enter" && !e.shiftKey) {
|
|
393
|
+
if (target?.classList?.contains("olu-tag-add-input")) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
e.preventDefault();
|
|
397
|
+
e.stopPropagation();
|
|
398
|
+
if (inInput) {
|
|
399
|
+
if (target && "value" in target && typeof (target as HTMLInputElement).value === "string") {
|
|
400
|
+
setTokensInput((target as HTMLInputElement).value);
|
|
401
|
+
}
|
|
402
|
+
if (debounceTimer) {
|
|
403
|
+
clearTimeout(debounceTimer);
|
|
404
|
+
debounceTimer = undefined;
|
|
405
|
+
}
|
|
406
|
+
setSelectedIndex(0);
|
|
407
|
+
void loadTokensReport();
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const picked = selectedSession();
|
|
411
|
+
if (picked) {
|
|
412
|
+
openSession(picked);
|
|
413
|
+
}
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "l") {
|
|
417
|
+
e.preventDefault();
|
|
418
|
+
void toggleLikeSession(selectedSession());
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if ((e.ctrlKey || e.metaKey) && e.key.toLowerCase() === "u") {
|
|
422
|
+
e.preventDefault();
|
|
423
|
+
setTokensInput("");
|
|
424
|
+
setLikedOnly(false);
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return (
|
|
430
|
+
<div class={`olt-scope olu-root olu-root--${props.variant}${view() === "detail" ? " is-detail" : ""}`} onKeyDown={handleKeyDown}>
|
|
431
|
+
<div class="olu-top-bar"><strong>Totals</strong><div class="olu-segmented" role="group" aria-label="Token totals range"><button type="button" class="olu-segment" aria-pressed={range() === "local30d"} onClick={() => setRange("local30d")}>30 Days</button><button type="button" class="olu-segment" aria-pressed={range() === "localAllTime"} onClick={() => setRange("localAllTime")}>All-Time</button></div></div>
|
|
432
|
+
<Show when={summary()}>{data => <div class="olu-kpi-row" aria-live="polite"><div class="olu-kpi-card"><span class="olu-kpi-label">Sessions</span><span class="olu-kpi-value">{data()[range()].sessions}</span></div><div class="olu-kpi-card"><span class="olu-kpi-label">Turns</span><span class="olu-kpi-value">{data()[range()].turns.toLocaleString()}</span></div><div class="olu-kpi-card"><span class="olu-kpi-label">Billed Tokens</span><span class="olu-kpi-value">{fmtCompact(data()[range()].billed)}</span></div><div class="olu-kpi-card"><span class="olu-kpi-label">Total w/ Cache</span><span class="olu-kpi-value">{fmtCompact(data()[range()].withCache)}</span></div></div>}</Show>
|
|
433
|
+
<div class="olu-tokens-layout">
|
|
434
|
+
<div class="olu-filter-bar">
|
|
435
|
+
<div class="olu-filter-input">
|
|
436
|
+
<ui.TextInput
|
|
437
|
+
autofocus
|
|
438
|
+
size="small"
|
|
439
|
+
type="search"
|
|
440
|
+
placeholder="Search topics or filter: project:cms model:claude #playwright * ..."
|
|
441
|
+
value={tokensInput()}
|
|
442
|
+
onInput={(val) => {
|
|
443
|
+
const next =
|
|
444
|
+
typeof val === "string"
|
|
445
|
+
? val
|
|
446
|
+
: (val as unknown as { currentTarget?: { value?: string } })?.currentTarget
|
|
447
|
+
?.value ?? "";
|
|
448
|
+
setTokensInput(next);
|
|
449
|
+
setSelectedIndex(0);
|
|
450
|
+
}}
|
|
451
|
+
/>
|
|
452
|
+
</div>
|
|
453
|
+
<ui.Menu
|
|
454
|
+
label={`Sort: ${TOKEN_SORT_LABELS[sortMode()]}`}
|
|
455
|
+
trigger="button"
|
|
456
|
+
items={sortMenuItems()}
|
|
457
|
+
/>
|
|
458
|
+
<button
|
|
459
|
+
type="button"
|
|
460
|
+
class={`olu-chip ${likedOnly() ? "olu-chip--active" : ""}`}
|
|
461
|
+
onClick={() => setLikedOnly((v) => !v)}
|
|
462
|
+
>
|
|
463
|
+
<span>★ Liked</span>
|
|
464
|
+
</button>
|
|
465
|
+
<Show when={tokensInput().trim().length > 0 || likedOnly()}>
|
|
466
|
+
<ui.Button
|
|
467
|
+
variant="ghost"
|
|
468
|
+
size="small"
|
|
469
|
+
onClick={() => {
|
|
470
|
+
setTokensInput("");
|
|
471
|
+
setLikedOnly(false);
|
|
472
|
+
}}
|
|
473
|
+
>
|
|
474
|
+
Clear
|
|
475
|
+
</ui.Button>
|
|
476
|
+
</Show>
|
|
477
|
+
</div>
|
|
478
|
+
|
|
479
|
+
<Show when={report()}>
|
|
480
|
+
{(r) => (
|
|
481
|
+
<div class="olu-chip-row">
|
|
482
|
+
<div class="olu-chips">
|
|
483
|
+
<For each={r().sortedProjects.slice(0, 4)}>
|
|
484
|
+
{([proj, info]) => (
|
|
485
|
+
<button
|
|
486
|
+
type="button"
|
|
487
|
+
class="olu-chip"
|
|
488
|
+
onClick={() => applyQuickTokenFilter(`project:${proj}`)}
|
|
489
|
+
>
|
|
490
|
+
<span>{proj}</span>
|
|
491
|
+
<span>({fmtCompact(info.billed)})</span>
|
|
492
|
+
</button>
|
|
493
|
+
)}
|
|
494
|
+
</For>
|
|
495
|
+
<For each={r().topTags.slice(0, 5)}>
|
|
496
|
+
{([tag, info]) => (
|
|
497
|
+
<button
|
|
498
|
+
type="button"
|
|
499
|
+
class="olu-chip"
|
|
500
|
+
onClick={() => applyQuickTokenFilter(`#${tag}`)}
|
|
501
|
+
>
|
|
502
|
+
<span>#{tag}</span>
|
|
503
|
+
<span>({fmtCompact(info.billed)})</span>
|
|
504
|
+
</button>
|
|
505
|
+
)}
|
|
506
|
+
</For>
|
|
507
|
+
</div>
|
|
508
|
+
<div class="olu-lower-tabs-right">
|
|
509
|
+
<span class="olu-updated-label">
|
|
510
|
+
{loadingTokens()
|
|
511
|
+
? "Filtering..."
|
|
512
|
+
: `All time: ${r().totalSessionsMatched} sessions · ${r().totals.turns.toLocaleString()} turns · Billed: ${fmtCompact(
|
|
513
|
+
billedTokens(r().totals)
|
|
514
|
+
)} · w/Cache: ${fmtCompact(totalTokensWithCache(r().totals))}`}
|
|
515
|
+
</span>
|
|
516
|
+
<div class="olu-segmented" role="tablist" aria-label="Lower breakdown view">
|
|
517
|
+
<button
|
|
518
|
+
type="button"
|
|
519
|
+
role="tab"
|
|
520
|
+
aria-selected={lowerViewTab() === "sessions"}
|
|
521
|
+
class={`olu-segment ${lowerViewTab() === "sessions" ? "olu-segment--active" : ""}`}
|
|
522
|
+
onClick={() => {
|
|
523
|
+
setLowerViewTab("sessions");
|
|
524
|
+
setView("list");
|
|
525
|
+
}}
|
|
526
|
+
>
|
|
527
|
+
Per Session ({matchedSessions().length})
|
|
528
|
+
</button>
|
|
529
|
+
<button
|
|
530
|
+
type="button"
|
|
531
|
+
role="tab"
|
|
532
|
+
aria-selected={lowerViewTab() === "tags"}
|
|
533
|
+
class={`olu-segment ${lowerViewTab() === "tags" ? "olu-segment--active" : ""}`}
|
|
534
|
+
onClick={() => {
|
|
535
|
+
setLowerViewTab("tags");
|
|
536
|
+
setView("list");
|
|
537
|
+
}}
|
|
538
|
+
>
|
|
539
|
+
Per Tag ({tagRows().length})
|
|
540
|
+
</button>
|
|
541
|
+
</div>
|
|
542
|
+
</div>
|
|
543
|
+
</div>
|
|
544
|
+
)}
|
|
545
|
+
</Show>
|
|
546
|
+
|
|
547
|
+
<Show
|
|
548
|
+
when={lowerViewTab() === "sessions"}
|
|
549
|
+
fallback={
|
|
550
|
+
<div class="olu-split" data-view="per-tag">
|
|
551
|
+
<div class="olu-col olu-col--list">
|
|
552
|
+
<div class="olu-scroll">
|
|
553
|
+
<Show
|
|
554
|
+
when={tagRows().length > 0}
|
|
555
|
+
fallback={<div class="olu-empty">No tags matched the current filter.</div>}
|
|
556
|
+
>
|
|
557
|
+
<div class="olu-session-list">
|
|
558
|
+
<For each={tagRows()}>
|
|
559
|
+
{(row, idx) => {
|
|
560
|
+
const sharePct = () => {
|
|
561
|
+
const grand = billedTokens(report()?.totals ?? { input: 0, output: 0, reasoning: 0, cacheRead: 0, cacheWrite: 0 });
|
|
562
|
+
if (!grand || grand <= 0) return 0;
|
|
563
|
+
return Math.min(100, Math.round((row.info.billed / grand) * 100));
|
|
564
|
+
};
|
|
565
|
+
return (
|
|
566
|
+
<button
|
|
567
|
+
type="button"
|
|
568
|
+
class={`olu-session-row ${
|
|
569
|
+
idx() === selectedTagIndex() ? "olu-session-row--selected" : ""
|
|
570
|
+
}`}
|
|
571
|
+
onClick={() => {
|
|
572
|
+
setSelectedTagIndex(idx());
|
|
573
|
+
setView("detail");
|
|
574
|
+
}}
|
|
575
|
+
>
|
|
576
|
+
<div class="olu-session-top">
|
|
577
|
+
<div class="olu-session-title-wrap">
|
|
578
|
+
<span class="olu-session-title">#{row.tag}</span>
|
|
579
|
+
<span class="olu-badge">{sharePct()}%</span>
|
|
580
|
+
</div>
|
|
581
|
+
<span class="olu-session-billed">
|
|
582
|
+
{fmtCompact(row.info.billed)}
|
|
583
|
+
</span>
|
|
584
|
+
</div>
|
|
585
|
+
<div class="olu-session-sub">
|
|
586
|
+
<span>
|
|
587
|
+
{row.info.count} {row.info.count === 1 ? "session" : "sessions"} ·{" "}
|
|
588
|
+
{(row.info.steps ?? 0).toLocaleString()} steps
|
|
589
|
+
</span>
|
|
590
|
+
<span>
|
|
591
|
+
w/Cache {fmtCompact(row.info.total ?? row.info.billed)}
|
|
592
|
+
</span>
|
|
593
|
+
</div>
|
|
594
|
+
</button>
|
|
595
|
+
);
|
|
596
|
+
}}
|
|
597
|
+
</For>
|
|
598
|
+
</div>
|
|
599
|
+
</Show>
|
|
600
|
+
</div>
|
|
601
|
+
</div>
|
|
602
|
+
|
|
603
|
+
<div class="olu-col">
|
|
604
|
+
<div class="olu-scroll">
|
|
605
|
+
<Show
|
|
606
|
+
when={selectedTag()}
|
|
607
|
+
fallback={<div class="olu-empty">Select a tag to inspect its token breakdown.</div>}
|
|
608
|
+
>
|
|
609
|
+
{(selTag) => (
|
|
610
|
+
<div class="olu-detail-pane">
|
|
611
|
+
<div class="olu-detail-header">
|
|
612
|
+
<button type="button" class="olu-back" onClick={() => setView("list")}>← Back</button>
|
|
613
|
+
<div>
|
|
614
|
+
<h4 class="olu-detail-title">#{selTag().tag}</h4>
|
|
615
|
+
<div class="olu-detail-meta">
|
|
616
|
+
{selTag().info.count} tagged sessions · {(selTag().info.steps ?? 0).toLocaleString()} steps
|
|
617
|
+
</div>
|
|
618
|
+
</div>
|
|
619
|
+
<div class="olu-detail-actions">
|
|
620
|
+
<ui.Button
|
|
621
|
+
variant="neutral"
|
|
622
|
+
size="small"
|
|
623
|
+
onClick={() => {
|
|
624
|
+
applyQuickTokenFilter(`#${selTag().tag}`);
|
|
625
|
+
setLowerViewTab("sessions");
|
|
626
|
+
}}
|
|
627
|
+
>
|
|
628
|
+
Filter Per Session (#{selTag().tag})
|
|
629
|
+
</ui.Button>
|
|
630
|
+
</div>
|
|
631
|
+
</div>
|
|
632
|
+
|
|
633
|
+
<div class="olu-kpi-row">
|
|
634
|
+
<div class="olu-kpi-card">
|
|
635
|
+
<span class="olu-kpi-label">Billed Tokens</span>
|
|
636
|
+
<span class="olu-kpi-value">{fmtCompact(selTag().info.billed)}</span>
|
|
637
|
+
</div>
|
|
638
|
+
<div class="olu-kpi-card">
|
|
639
|
+
<span class="olu-kpi-label">Total w/ Cache</span>
|
|
640
|
+
<span class="olu-kpi-value">
|
|
641
|
+
{fmtCompact(selTag().info.total ?? selTag().info.billed)}
|
|
642
|
+
</span>
|
|
643
|
+
</div>
|
|
644
|
+
<div class="olu-kpi-card">
|
|
645
|
+
<span class="olu-kpi-label">Sessions / Steps</span>
|
|
646
|
+
<span class="olu-kpi-value">
|
|
647
|
+
{selTag().info.count} / {(selTag().info.steps ?? 0).toLocaleString()}
|
|
648
|
+
</span>
|
|
649
|
+
</div>
|
|
650
|
+
<div class="olu-kpi-card">
|
|
651
|
+
<span class="olu-kpi-label">Input / Output</span>
|
|
652
|
+
<span class="olu-kpi-value">
|
|
653
|
+
{fmtCompact(selTag().info.input ?? 0)} / {fmtCompact(selTag().info.output ?? 0)}
|
|
654
|
+
</span>
|
|
655
|
+
</div>
|
|
656
|
+
</div>
|
|
657
|
+
|
|
658
|
+
<div class="olu-section-card">
|
|
659
|
+
<span class="olu-section-title">
|
|
660
|
+
Sessions Tagged #{selTag().tag} ({selectedTagSessions().length})
|
|
661
|
+
</span>
|
|
662
|
+
<Show
|
|
663
|
+
when={selectedTagSessions().length > 0}
|
|
664
|
+
fallback={
|
|
665
|
+
<div class="olu-empty">
|
|
666
|
+
None of the {matchedSessions().length} loaded sessions carry this tag. Use Filter Per Session to list all {selTag().info.count}.
|
|
667
|
+
</div>
|
|
668
|
+
}
|
|
669
|
+
>
|
|
670
|
+
<div class="olu-table-wrap">
|
|
671
|
+
<table class="olu-table">
|
|
672
|
+
<thead>
|
|
673
|
+
<tr>
|
|
674
|
+
<th>Session</th>
|
|
675
|
+
<th>Project</th>
|
|
676
|
+
<th>Steps</th>
|
|
677
|
+
<th>Billed</th>
|
|
678
|
+
<th>w/Cache</th>
|
|
679
|
+
</tr>
|
|
680
|
+
</thead>
|
|
681
|
+
<tbody>
|
|
682
|
+
<For each={selectedTagSessions()}>
|
|
683
|
+
{(s) => (
|
|
684
|
+
<tr
|
|
685
|
+
class="olu-clickable-row"
|
|
686
|
+
onClick={() => {
|
|
687
|
+
const idx = matchedSessions().findIndex((m) => m.id === s.id);
|
|
688
|
+
if (idx >= 0) setSelectedIndex(idx);
|
|
689
|
+
setLowerViewTab("sessions");
|
|
690
|
+
}}
|
|
691
|
+
onDblClick={() => openSession(s)}
|
|
692
|
+
>
|
|
693
|
+
<td class="olu-model-cell" title={s.smartTitle}>
|
|
694
|
+
{s.smartTitle}
|
|
695
|
+
</td>
|
|
696
|
+
<td>{s.project}</td>
|
|
697
|
+
<td>{s.steps || s.turns}</td>
|
|
698
|
+
<td>{fmtCompact(billedTokens(s.tokens))}</td>
|
|
699
|
+
<td>{fmtCompact(totalTokensWithCache(s.tokens))}</td>
|
|
700
|
+
</tr>
|
|
701
|
+
)}
|
|
702
|
+
</For>
|
|
703
|
+
</tbody>
|
|
704
|
+
</table>
|
|
705
|
+
</div>
|
|
706
|
+
</Show>
|
|
707
|
+
</div>
|
|
708
|
+
</div>
|
|
709
|
+
)}
|
|
710
|
+
</Show>
|
|
711
|
+
</div>
|
|
712
|
+
</div>
|
|
713
|
+
</div>
|
|
714
|
+
}
|
|
715
|
+
>
|
|
716
|
+
<div class="olu-split" data-view="per-session">
|
|
717
|
+
<div class="olu-col olu-col--list">
|
|
718
|
+
<div class="olu-scroll">
|
|
719
|
+
<Show
|
|
720
|
+
when={matchedSessions().length > 0}
|
|
721
|
+
fallback={
|
|
722
|
+
<div class="olu-empty">No sessions matched the current filter.</div>
|
|
723
|
+
}
|
|
724
|
+
>
|
|
725
|
+
<div class="olu-session-list">
|
|
726
|
+
<For each={matchedSessions()}>
|
|
727
|
+
{(s, idx) => (
|
|
728
|
+
<button
|
|
729
|
+
type="button"
|
|
730
|
+
class={`olu-session-row ${
|
|
731
|
+
idx() === selectedIndex() ? "olu-session-row--selected" : ""
|
|
732
|
+
}`}
|
|
733
|
+
onClick={() => {
|
|
734
|
+
setSelectedIndex(idx());
|
|
735
|
+
setView("detail");
|
|
736
|
+
}}
|
|
737
|
+
onDblClick={() => openSession(s)}
|
|
738
|
+
>
|
|
739
|
+
<div class="olu-session-top">
|
|
740
|
+
<div class="olu-session-title-wrap">
|
|
741
|
+
<Show when={s.liked}>
|
|
742
|
+
<span class="olu-star">★</span>
|
|
743
|
+
</Show>
|
|
744
|
+
<span class="olu-session-title">{s.smartTitle}</span>
|
|
745
|
+
</div>
|
|
746
|
+
<span class="olu-session-billed">
|
|
747
|
+
{fmtCompact(billedTokens(s.tokens))}
|
|
748
|
+
</span>
|
|
749
|
+
</div>
|
|
750
|
+
<div class="olu-session-sub">
|
|
751
|
+
<span>
|
|
752
|
+
{s.shortId} · {s.project}
|
|
753
|
+
</span>
|
|
754
|
+
<span>
|
|
755
|
+
{s.turnScoped
|
|
756
|
+
? `${s.turns}/${s.totalSessionTurns} turns`
|
|
757
|
+
: `${s.steps || s.turns} steps`}{" "}
|
|
758
|
+
· w/Cache {fmtCompact(totalTokensWithCache(s.tokens))}
|
|
759
|
+
</span>
|
|
760
|
+
</div>
|
|
761
|
+
</button>
|
|
762
|
+
)}
|
|
763
|
+
</For>
|
|
764
|
+
</div>
|
|
765
|
+
</Show>
|
|
766
|
+
</div>
|
|
767
|
+
</div>
|
|
768
|
+
|
|
769
|
+
<div class="olu-col">
|
|
770
|
+
<div class="olu-scroll">
|
|
771
|
+
<Show
|
|
772
|
+
when={selectedSession()}
|
|
773
|
+
fallback={
|
|
774
|
+
<div class="olu-empty">Select a session to inspect token breakdown.</div>
|
|
775
|
+
}
|
|
776
|
+
>
|
|
777
|
+
{(sel) => (
|
|
778
|
+
<div class="olu-detail-pane">
|
|
779
|
+
<div class="olu-detail-header">
|
|
780
|
+
<button type="button" class="olu-back" onClick={() => setView("list")}>← Back</button>
|
|
781
|
+
<div>
|
|
782
|
+
<h4 class="olu-detail-title">{sel().smartTitle}</h4>
|
|
783
|
+
<div class="olu-detail-meta">
|
|
784
|
+
{sel().shortId} · {sel().project} · {formatDate(sel().timeUpdated)}
|
|
785
|
+
</div>
|
|
786
|
+
</div>
|
|
787
|
+
<div class="olu-detail-actions">
|
|
788
|
+
<ui.Button
|
|
789
|
+
variant="neutral"
|
|
790
|
+
size="small"
|
|
791
|
+
onClick={() => void toggleLikeSession(sel())}
|
|
792
|
+
>
|
|
793
|
+
{sel().liked ? "★ Liked" : "☆ Like"}
|
|
794
|
+
</ui.Button>
|
|
795
|
+
<ui.Button
|
|
796
|
+
variant="contrast"
|
|
797
|
+
size="small"
|
|
798
|
+
onClick={() => openSession(sel())}
|
|
799
|
+
>
|
|
800
|
+
Open Session
|
|
801
|
+
</ui.Button>
|
|
802
|
+
</div>
|
|
803
|
+
</div>
|
|
804
|
+
|
|
805
|
+
<div class="olu-kpi-row">
|
|
806
|
+
<div class="olu-kpi-card">
|
|
807
|
+
<span class="olu-kpi-label">Billed Tokens</span>
|
|
808
|
+
<span class="olu-kpi-value">
|
|
809
|
+
{fmtCompact(billedTokens(sel().tokens))}
|
|
810
|
+
</span>
|
|
811
|
+
</div>
|
|
812
|
+
<div class="olu-kpi-card">
|
|
813
|
+
<span class="olu-kpi-label">Total w/ Cache</span>
|
|
814
|
+
<span class="olu-kpi-value">
|
|
815
|
+
{fmtCompact(totalTokensWithCache(sel().tokens))}
|
|
816
|
+
</span>
|
|
817
|
+
</div>
|
|
818
|
+
<div class="olu-kpi-card">
|
|
819
|
+
<span class="olu-kpi-label">Steps / Turns</span>
|
|
820
|
+
<span class="olu-kpi-value">
|
|
821
|
+
{(sel().steps || 0).toLocaleString()} /{" "}
|
|
822
|
+
{sel().turnScoped
|
|
823
|
+
? `${sel().turns} of ${sel().totalSessionTurns}`
|
|
824
|
+
: sel().turns}
|
|
825
|
+
</span>
|
|
826
|
+
</div>
|
|
827
|
+
<div class="olu-kpi-card">
|
|
828
|
+
<span class="olu-kpi-label">Input / Output</span>
|
|
829
|
+
<span class="olu-kpi-value">
|
|
830
|
+
{fmtCompact(sel().tokens.input)} / {fmtCompact(sel().tokens.output)}
|
|
831
|
+
</span>
|
|
832
|
+
</div>
|
|
833
|
+
</div>
|
|
834
|
+
|
|
835
|
+
<div class="olu-session-tags-bar">
|
|
836
|
+
<div class="olu-chips">
|
|
837
|
+
<For each={sel().tags}>
|
|
838
|
+
{(t) => (
|
|
839
|
+
<span class="olu-tag-pill">
|
|
840
|
+
<button
|
|
841
|
+
type="button"
|
|
842
|
+
class="olu-tag-pill-label"
|
|
843
|
+
title={`Filter by #${t}`}
|
|
844
|
+
onClick={() => applyQuickTokenFilter(`#${t}`)}
|
|
845
|
+
>
|
|
846
|
+
#{t}
|
|
847
|
+
</button>
|
|
848
|
+
<button
|
|
849
|
+
type="button"
|
|
850
|
+
class="olu-tag-pill-remove"
|
|
851
|
+
aria-label={`Remove tag ${t}`}
|
|
852
|
+
title={`Remove #${t}`}
|
|
853
|
+
disabled={mutatingTag()}
|
|
854
|
+
onClick={(e) => {
|
|
855
|
+
e.stopPropagation();
|
|
856
|
+
void removeSessionTag(sel(), t);
|
|
857
|
+
}}
|
|
858
|
+
>
|
|
859
|
+
×
|
|
860
|
+
</button>
|
|
861
|
+
</span>
|
|
862
|
+
)}
|
|
863
|
+
</For>
|
|
864
|
+
</div>
|
|
865
|
+
<form
|
|
866
|
+
class="olu-tag-add-form"
|
|
867
|
+
onSubmit={(e) => {
|
|
868
|
+
e.preventDefault();
|
|
869
|
+
void addSessionTag(sel(), newTagInput());
|
|
870
|
+
}}
|
|
871
|
+
>
|
|
872
|
+
<input
|
|
873
|
+
type="text"
|
|
874
|
+
class="olu-tag-add-input"
|
|
875
|
+
placeholder="Add tag..."
|
|
876
|
+
aria-label="Add session tag"
|
|
877
|
+
value={newTagInput()}
|
|
878
|
+
onInput={(e) => setNewTagInput(e.currentTarget.value)}
|
|
879
|
+
onKeyDown={(e) => {
|
|
880
|
+
if (e.key === "Enter") {
|
|
881
|
+
e.preventDefault();
|
|
882
|
+
e.stopPropagation();
|
|
883
|
+
void addSessionTag(sel(), newTagInput());
|
|
884
|
+
}
|
|
885
|
+
}}
|
|
886
|
+
/>
|
|
887
|
+
<button
|
|
888
|
+
type="submit"
|
|
889
|
+
class="olu-chip olu-tag-add-btn"
|
|
890
|
+
disabled={mutatingTag() || !newTagInput().trim()}
|
|
891
|
+
>
|
|
892
|
+
+ Tag
|
|
893
|
+
</button>
|
|
894
|
+
</form>
|
|
895
|
+
</div>
|
|
896
|
+
|
|
897
|
+
<div class="olu-section-card">
|
|
898
|
+
<span class="olu-section-title">Session Model Breakdown</span>
|
|
899
|
+
<div class="olu-table-wrap">
|
|
900
|
+
<table class="olu-table">
|
|
901
|
+
<thead>
|
|
902
|
+
<tr>
|
|
903
|
+
<th>Model</th>
|
|
904
|
+
<th>Steps</th>
|
|
905
|
+
<th>Input</th>
|
|
906
|
+
<th>Output</th>
|
|
907
|
+
<th>Cache Read</th>
|
|
908
|
+
</tr>
|
|
909
|
+
</thead>
|
|
910
|
+
<tbody>
|
|
911
|
+
<For each={Object.entries(sel().modelBreakdown)}>
|
|
912
|
+
{([modelName, mb]) => (
|
|
913
|
+
<tr>
|
|
914
|
+
<td class="olu-model-cell" title={modelName}>
|
|
915
|
+
{modelName}
|
|
916
|
+
</td>
|
|
917
|
+
<td>{mb.turns}</td>
|
|
918
|
+
<td>{fmtCompact(mb.input)}</td>
|
|
919
|
+
<td>{fmtCompact(mb.output)}</td>
|
|
920
|
+
<td>{fmtCompact(mb.cacheRead)}</td>
|
|
921
|
+
</tr>
|
|
922
|
+
)}
|
|
923
|
+
</For>
|
|
924
|
+
</tbody>
|
|
925
|
+
</table>
|
|
926
|
+
</div>
|
|
927
|
+
</div>
|
|
928
|
+
</div>
|
|
929
|
+
)}
|
|
930
|
+
</Show>
|
|
931
|
+
</div>
|
|
932
|
+
</div>
|
|
933
|
+
</div>
|
|
934
|
+
</Show>
|
|
935
|
+
</div>
|
|
936
|
+
</div>
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
const CACHE_TTL_MS = 5 * 60 * 1000;
|
|
943
|
+
const CACHE_EXPIRING_IDLE_MS = 4 * 60 * 1000;
|
|
944
|
+
const CACHE_HEAVY_CONTEXT_TOKENS = 30_000;
|
|
945
|
+
|
|
946
|
+
function fmtDurationShort(ms: number): string {
|
|
947
|
+
if (!ms || ms <= 0) return "0s";
|
|
948
|
+
if (ms < 60_000) return `${Math.max(1, Math.ceil(ms / 1000))}s`;
|
|
949
|
+
if (ms < 3_600_000) {
|
|
950
|
+
const m = Math.floor(ms / 60_000);
|
|
951
|
+
const s = Math.floor((ms % 60_000) / 1000);
|
|
952
|
+
return s > 0 && m < 10 ? `${m}m ${s}s` : `${m}m`;
|
|
953
|
+
}
|
|
954
|
+
const h = Math.floor(ms / 3_600_000);
|
|
955
|
+
const m = Math.floor((ms % 3_600_000) / 60_000);
|
|
956
|
+
return m > 0 ? `${h}h ${m}m` : `${h}h`;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
const [guiStepStatus, setGuiStepStatus] = createSignal<SessionStepStatus | null>(null);
|
|
960
|
+
const [guiNow, setGuiNow] = createSignal(Date.now());
|
|
961
|
+
const [guiDismissedCacheKeys, setGuiDismissedCacheKeys] = createSignal<Set<string>>(new Set());
|
|
962
|
+
const guiWarnedSessions = new Set<string>();
|
|
963
|
+
const guiPromptedOverLimitTurnKeys = new Set<string>();
|
|
964
|
+
const guiPreparingHandoffs = new Set<string>();
|
|
965
|
+
|
|
966
|
+
async function startGuiSessionHandoff(ctx: PluginContext, explicitSessionId?: string) {
|
|
967
|
+
const active = ctx.sessions.current();
|
|
968
|
+
const sessionId = explicitSessionId || active?.id;
|
|
969
|
+
if (!sessionId || guiPreparingHandoffs.has(sessionId)) return;
|
|
970
|
+
guiPreparingHandoffs.add(sessionId);
|
|
971
|
+
try {
|
|
972
|
+
ctx.toast.show({ title: "Preparing handoff with AI", description: "Saving a fresh checkpoint before export. This uses model tokens.", variant: "success" });
|
|
973
|
+
const rpc = getRpcClient(ctx);
|
|
974
|
+
const result = await rpc.createHandoff({ sessionId });
|
|
975
|
+
const handoff = result.ok ? result.handoff : undefined;
|
|
976
|
+
if (!handoff) {
|
|
977
|
+
ctx.toast.show({
|
|
978
|
+
title: "Handoff unavailable",
|
|
979
|
+
description: result.error || "No active session found to generate a handoff.",
|
|
980
|
+
variant: "warning",
|
|
981
|
+
});
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
await ctx.system.copy(handoff.handoffPrompt);
|
|
986
|
+
ctx.toast.show({
|
|
987
|
+
title: "Handoff saved and copied",
|
|
988
|
+
description: `Saved ${handoff.shortId} (${handoff.count} steps) to ${handoff.checkpointPath}. Open a new chat, paste, and send.`,
|
|
989
|
+
variant: "success",
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
} catch (err) {
|
|
993
|
+
ctx.toast.show({
|
|
994
|
+
title: "Failed to create handoff",
|
|
995
|
+
description: String(err),
|
|
996
|
+
variant: "error",
|
|
997
|
+
});
|
|
998
|
+
} finally {
|
|
999
|
+
guiPreparingHandoffs.delete(sessionId);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
async function pollGuiSessionSteps(ctx: PluginContext) {
|
|
1003
|
+
const active = ctx.sessions.current();
|
|
1004
|
+
if (!active?.id) {
|
|
1005
|
+
setGuiStepStatus(null);
|
|
1006
|
+
return;
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
try {
|
|
1010
|
+
const rpc = getRpcClient(ctx);
|
|
1011
|
+
const st = await rpc.sessionStatus({ sessionId: active.id });
|
|
1012
|
+
setGuiStepStatus(st);
|
|
1013
|
+
setGuiNow(Date.now());
|
|
1014
|
+
} catch {}
|
|
1015
|
+
}
|
|
1016
|
+
export default Plugin.define({
|
|
1017
|
+
i18n: { en: {
|
|
1018
|
+
"tokens.command.title": "Token Audit...",
|
|
1019
|
+
"tokens.command.description": "Search sessions by topic, project, model, and token consumption",
|
|
1020
|
+
"handoff.command.title": "Save & Copy Session Handoff...",
|
|
1021
|
+
"handoff.command.description": "Save a checkpoint and copy continuation text to paste into a new chat",
|
|
1022
|
+
"tokens.panel": "Token Audit", "tokens.panel.toggle": "Open Token Audit Panel"
|
|
1023
|
+
} },
|
|
1024
|
+
setup(ctx) {
|
|
1025
|
+
ctx.add(Style, css);
|
|
1026
|
+
ctx.add(Command, () => ({
|
|
1027
|
+
id: "tokens",
|
|
1028
|
+
title: ctx.t("tokens.command.title"),
|
|
1029
|
+
description: ctx.t("tokens.command.description"),
|
|
1030
|
+
keywords: "tokens analytics sessions models projects tags search",
|
|
1031
|
+
group: "Session",
|
|
1032
|
+
section: "session",
|
|
1033
|
+
bind: "mod+shift+y",
|
|
1034
|
+
slash: {
|
|
1035
|
+
name: "tokens",
|
|
1036
|
+
arguments: true,
|
|
1037
|
+
},
|
|
1038
|
+
featured: true,
|
|
1039
|
+
run(input) {
|
|
1040
|
+
openTokensPanel(ctx, input ?? "");
|
|
1041
|
+
},
|
|
1042
|
+
}));
|
|
1043
|
+
|
|
1044
|
+
ctx.add(Command, () => ({
|
|
1045
|
+
id: "handoff",
|
|
1046
|
+
title: ctx.t("handoff.command.title"),
|
|
1047
|
+
description: ctx.t("handoff.command.description"),
|
|
1048
|
+
keywords: "handoff checkpoint new session context uncached steps limit",
|
|
1049
|
+
group: "Session",
|
|
1050
|
+
section: "session",
|
|
1051
|
+
slash: {
|
|
1052
|
+
name: "handoff",
|
|
1053
|
+
},
|
|
1054
|
+
featured: true,
|
|
1055
|
+
run() {
|
|
1056
|
+
void startGuiSessionHandoff(ctx);
|
|
1057
|
+
},
|
|
1058
|
+
}));
|
|
1059
|
+
const panelTabKey = `${ctx.id}:tokens`;
|
|
1060
|
+
const tokensTab: PanelTab = {
|
|
1061
|
+
id: "tokens",
|
|
1062
|
+
get title() {
|
|
1063
|
+
return ctx.t("tokens.panel");
|
|
1064
|
+
},
|
|
1065
|
+
closable: "compact",
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
const contextHeader = {
|
|
1069
|
+
at: "session.header",
|
|
1070
|
+
order: 16,
|
|
1071
|
+
render: () => {
|
|
1072
|
+
const ui = ctx.ui;
|
|
1073
|
+
const st = createMemo(() => {
|
|
1074
|
+
const cur = guiStepStatus();
|
|
1075
|
+
const active = ctx.sessions.current();
|
|
1076
|
+
if (!cur || !active || cur.sessionId !== active.id) return null;
|
|
1077
|
+
return cur;
|
|
1078
|
+
});
|
|
1079
|
+
return (
|
|
1080
|
+
<div class="olt-scope olu-header-slot-group">
|
|
1081
|
+
<Show when={st()}>
|
|
1082
|
+
{(s) => {
|
|
1083
|
+
const pct = () => Math.max(0, Math.min(100, s().handoffPct ?? 0));
|
|
1084
|
+
const status = () => (s().overLimit ? "bad" : s().approaching ? "warn" : "good");
|
|
1085
|
+
return (
|
|
1086
|
+
<button
|
|
1087
|
+
type="button"
|
|
1088
|
+
class={`olu-step-pill olu-usage-pill olu-step-pill--${status()}`}
|
|
1089
|
+
title={`Latest recorded request: ${s().statusReason}. Percentage of configured model context, not a required handoff limit. Click for Token Analytics.`}
|
|
1090
|
+
onClick={() => {
|
|
1091
|
+
openTokensPanel(ctx);
|
|
1092
|
+
}}
|
|
1093
|
+
>
|
|
1094
|
+
<span>
|
|
1095
|
+
Context
|
|
1096
|
+
</span>
|
|
1097
|
+
<span class="olu-usage-pill-pct">{s().modelContextLimit > 0 ? `${pct()}%` : "unknown"}</span>
|
|
1098
|
+
<span class="olu-usage-pill-bar">
|
|
1099
|
+
<span
|
|
1100
|
+
class={`olu-usage-pill-bar-fill olu-progress-fill--${status()}`}
|
|
1101
|
+
style={{ width: `${pct()}%` }}
|
|
1102
|
+
/>
|
|
1103
|
+
</span>
|
|
1104
|
+
</button>
|
|
1105
|
+
);
|
|
1106
|
+
}}
|
|
1107
|
+
</Show>
|
|
1108
|
+
</div>
|
|
1109
|
+
);
|
|
1110
|
+
},
|
|
1111
|
+
};
|
|
1112
|
+
|
|
1113
|
+
const contextNotice = {
|
|
1114
|
+
at: "session.composer.top",
|
|
1115
|
+
order: 5,
|
|
1116
|
+
render: () => {
|
|
1117
|
+
const info = createMemo(() => {
|
|
1118
|
+
const cur = guiStepStatus();
|
|
1119
|
+
const active = ctx.sessions.current();
|
|
1120
|
+
if (!cur || !active || cur.sessionId !== active.id) return null;
|
|
1121
|
+
if ((cur.liveContextTokens ?? 0) < CACHE_HEAVY_CONTEXT_TOKENS) return null;
|
|
1122
|
+
const refTime = cur.lastReplyAt || cur.timeUpdated || 0;
|
|
1123
|
+
if (refTime <= 0) return null;
|
|
1124
|
+
const dismissKey = `${cur.sessionId}:${refTime}`;
|
|
1125
|
+
if (guiDismissedCacheKeys().has(dismissKey)) return null;
|
|
1126
|
+
const ttlMs = cur.cacheTtlMs || CACHE_TTL_MS;
|
|
1127
|
+
const idleMs = Math.max(cur.idleMs ?? 0, guiNow() - refTime);
|
|
1128
|
+
if (idleMs < CACHE_EXPIRING_IDLE_MS) return null;
|
|
1129
|
+
const remMs = Math.max(0, ttlMs - idleMs);
|
|
1130
|
+
const state: "expiring" | "expired" = idleMs >= ttlMs ? "expired" : "expiring";
|
|
1131
|
+
return { status: cur, idleMs, remMs, state, dismissKey };
|
|
1132
|
+
});
|
|
1133
|
+
return (
|
|
1134
|
+
<Show when={info()}>
|
|
1135
|
+
{(item) => (
|
|
1136
|
+
<div
|
|
1137
|
+
class={`olt-scope olu-composer-alert ${
|
|
1138
|
+
item().state === "expired" ? "olu-composer-alert--bad" : "olu-composer-alert--warn"
|
|
1139
|
+
}`}
|
|
1140
|
+
>
|
|
1141
|
+
<div class="olu-composer-alert-text">
|
|
1142
|
+
<strong>
|
|
1143
|
+
{item().state === "expired"
|
|
1144
|
+
? `Prompt cache likely expired (idle ${fmtDurationShort(item().idleMs)}) · ${item().status.statusReason}`
|
|
1145
|
+
: `Prompt cache expiring (${fmtDurationShort(item().remMs)} left) · ${item().status.statusReason}`}
|
|
1146
|
+
</strong>
|
|
1147
|
+
<span>
|
|
1148
|
+
{item().state === "expired"
|
|
1149
|
+
? `5m cache window passed. Replying now may re-send ${fmtCompact(item().status.liveContextTokens)} uncached tokens (${item().status.steps} steps).`
|
|
1150
|
+
: `Idle ${fmtDurationShort(item().idleMs)} since last reply. Reply within ${fmtDurationShort(item().remMs)} while ${fmtCompact(item().status.liveContextTokens)} context is still cached, or start a handoff.`}
|
|
1151
|
+
</span>
|
|
1152
|
+
</div>
|
|
1153
|
+
<div class="olu-composer-alert-actions">
|
|
1154
|
+
<button
|
|
1155
|
+
type="button"
|
|
1156
|
+
class="olu-composer-alert-btn"
|
|
1157
|
+
onClick={() => void startGuiSessionHandoff(ctx, item().status.sessionId)}
|
|
1158
|
+
>
|
|
1159
|
+
Save & Copy Handoff
|
|
1160
|
+
</button>
|
|
1161
|
+
<button
|
|
1162
|
+
type="button"
|
|
1163
|
+
class="olu-composer-alert-dismiss"
|
|
1164
|
+
aria-label="Dismiss cache alert"
|
|
1165
|
+
title="Dismiss for this turn"
|
|
1166
|
+
onClick={() => {
|
|
1167
|
+
const next = new Set(guiDismissedCacheKeys());
|
|
1168
|
+
next.add(item().dismissKey);
|
|
1169
|
+
setGuiDismissedCacheKeys(next);
|
|
1170
|
+
}}
|
|
1171
|
+
>
|
|
1172
|
+
×
|
|
1173
|
+
</button>
|
|
1174
|
+
</div>
|
|
1175
|
+
</div>
|
|
1176
|
+
)}
|
|
1177
|
+
</Show>
|
|
1178
|
+
);
|
|
1179
|
+
},
|
|
1180
|
+
};
|
|
1181
|
+
if (ctx.options.cacheAlerts === true) ctx.add(Slot, contextNotice);
|
|
1182
|
+
createEffect(() => {
|
|
1183
|
+
const activeId = ctx.sessions.current()?.id;
|
|
1184
|
+
if (activeId) {
|
|
1185
|
+
void pollGuiSessionSteps(ctx);
|
|
1186
|
+
} else {
|
|
1187
|
+
setGuiStepStatus(null);
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
const stepPollTimer = setInterval(() => {
|
|
1191
|
+
void pollGuiSessionSteps(ctx);
|
|
1192
|
+
}, 5000);
|
|
1193
|
+
const clockTimer = ctx.options.cacheAlerts === true ? setInterval(() => {
|
|
1194
|
+
if (guiStepStatus()) {
|
|
1195
|
+
setGuiNow(Date.now());
|
|
1196
|
+
}
|
|
1197
|
+
}, 1000) : undefined;
|
|
1198
|
+
onCleanup(() => {
|
|
1199
|
+
clearInterval(stepPollTimer);
|
|
1200
|
+
clearInterval(clockTimer);
|
|
1201
|
+
});
|
|
1202
|
+
|
|
1203
|
+
ctx.add(Command, () => ({
|
|
1204
|
+
id: "tokens-panel",
|
|
1205
|
+
title: ctx.t("tokens.panel.toggle"),
|
|
1206
|
+
description: "Toggle the persistent Token Analytics side panel",
|
|
1207
|
+
keywords: "tokens analytics panel sidebar sessions",
|
|
1208
|
+
group: "Session",
|
|
1209
|
+
section: "session",
|
|
1210
|
+
bind: "mod+alt+y",
|
|
1211
|
+
run() {
|
|
1212
|
+
openTokensPanel(ctx);
|
|
1213
|
+
},
|
|
1214
|
+
}));
|
|
1215
|
+
|
|
1216
|
+
ctx.add(MenuItem, () => {
|
|
1217
|
+
const session = ctx.sessions.current();
|
|
1218
|
+
return {
|
|
1219
|
+
menu: "session.panel",
|
|
1220
|
+
id: "tokens",
|
|
1221
|
+
title: ctx.t("tokens.panel"),
|
|
1222
|
+
description: ctx.t("tokens.command.description"),
|
|
1223
|
+
icon: "models",
|
|
1224
|
+
keybind: `${ctx.id}.tokens-panel`,
|
|
1225
|
+
opened: !!session && ctx.layout.state(panelTabKey, session) !== "closed",
|
|
1226
|
+
run() {
|
|
1227
|
+
openTokensPanel(ctx);
|
|
1228
|
+
},
|
|
1229
|
+
};
|
|
1230
|
+
});
|
|
1231
|
+
if (typeof document !== "undefined") {
|
|
1232
|
+
const ensureTopLeftUsageButton = () => {
|
|
1233
|
+
const searchBtn = document.querySelector<HTMLButtonElement>(
|
|
1234
|
+
'header[data-slot="titlebar-v2"] button[aria-label*="Search"]'
|
|
1235
|
+
);
|
|
1236
|
+
if (searchBtn && searchBtn.parentElement) {
|
|
1237
|
+
const container = searchBtn.parentElement;
|
|
1238
|
+
if (!container.querySelector('[data-action="titlebar-tokens"]')) {
|
|
1239
|
+
const btn = document.createElement("button");
|
|
1240
|
+
btn.type = "button";
|
|
1241
|
+
btn.setAttribute("data-action", "titlebar-tokens");
|
|
1242
|
+
btn.setAttribute("aria-label", "Token Audit (Ctrl+Shift+Y)");
|
|
1243
|
+
btn.setAttribute("title", "Token Audit (Ctrl+Shift+Y)");
|
|
1244
|
+
btn.className = "olt-scope olu-titlebar-quick-btn";
|
|
1245
|
+
btn.innerHTML = COINS_ICON_SVG;
|
|
1246
|
+
btn.addEventListener("click", (e) => {
|
|
1247
|
+
e.preventDefault();
|
|
1248
|
+
e.stopPropagation();
|
|
1249
|
+
openTokensPanel(ctx);
|
|
1250
|
+
});
|
|
1251
|
+
container.appendChild(btn);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
const vertAnchor =
|
|
1256
|
+
document.querySelector<HTMLButtonElement>('button[data-action="vertical-tabs-usage"]') ??
|
|
1257
|
+
document.querySelector<HTMLButtonElement>('button[data-action="vertical-tabs-memories"]') ??
|
|
1258
|
+
document.querySelector<HTMLButtonElement>('button[data-action="vertical-tabs-search"]');
|
|
1259
|
+
if (vertAnchor && vertAnchor.parentElement) {
|
|
1260
|
+
const vertContainer = vertAnchor.parentElement;
|
|
1261
|
+
const existingTokensBtn = vertContainer.querySelector<HTMLButtonElement>('[data-action="vertical-tabs-tokens"]');
|
|
1262
|
+
if (!existingTokensBtn) {
|
|
1263
|
+
const vBtn = document.createElement("button");
|
|
1264
|
+
vBtn.type = "button";
|
|
1265
|
+
vBtn.setAttribute("data-titlebar-tab-action", "");
|
|
1266
|
+
vBtn.setAttribute("data-action", "vertical-tabs-tokens");
|
|
1267
|
+
vBtn.setAttribute("aria-label", "Token Audit (Ctrl+Shift+Y)");
|
|
1268
|
+
vBtn.className =
|
|
1269
|
+
"group flex h-7 w-full shrink-0 items-center gap-1.5 rounded-[6px] ps-1.5 pe-2 text-[13px] leading-4 text-v2-text-text-faint hover:text-v2-text-text-base";
|
|
1270
|
+
vBtn.innerHTML =
|
|
1271
|
+
COINS_ICON_SVG +
|
|
1272
|
+
'<span class="min-w-0 truncate whitespace-nowrap">Token Audit</span>';
|
|
1273
|
+
vBtn.addEventListener("click", (e) => {
|
|
1274
|
+
e.preventDefault();
|
|
1275
|
+
e.stopPropagation();
|
|
1276
|
+
openTokensPanel(ctx);
|
|
1277
|
+
});
|
|
1278
|
+
vertAnchor.insertAdjacentElement("afterend", vBtn);
|
|
1279
|
+
} else if (
|
|
1280
|
+
vertAnchor.getAttribute("data-action") === "vertical-tabs-usage" &&
|
|
1281
|
+
existingTokensBtn.nextElementSibling === vertAnchor
|
|
1282
|
+
) {
|
|
1283
|
+
vertAnchor.insertAdjacentElement("afterend", existingTokensBtn);
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
};
|
|
1287
|
+
|
|
1288
|
+
ensureTopLeftUsageButton();
|
|
1289
|
+
const observer = new MutationObserver(() => {
|
|
1290
|
+
ensureTopLeftUsageButton();
|
|
1291
|
+
});
|
|
1292
|
+
if (document.body) {
|
|
1293
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
1294
|
+
}
|
|
1295
|
+
onCleanup(() => {
|
|
1296
|
+
observer.disconnect();
|
|
1297
|
+
document
|
|
1298
|
+
.querySelectorAll('[data-action="titlebar-tokens"], [data-action="vertical-tabs-tokens"]')
|
|
1299
|
+
.forEach((el) => el.remove());
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
|
|
1304
|
+
ctx.add(Panel, {
|
|
1305
|
+
id: "tokens",
|
|
1306
|
+
region: "side",
|
|
1307
|
+
list: (input) => (input.open.includes("tokens") ? [tokensTab] : []),
|
|
1308
|
+
render: () => <TokensSurface ctx={ctx} variant="panel" />,
|
|
1309
|
+
});
|
|
1310
|
+
},
|
|
1311
|
+
});
|