@glaicer/supercode-token-usage-panel 0.1.1 → 0.1.3

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.
@@ -1,82 +0,0 @@
1
- /**
2
- * supercode.token-usage — TUI sidebar section showing the cumulative Token
3
- * Usage of the current session family: token totals, cache rate, completed
4
- * step count, generation speed/TTFT, and provisional diagnostics for the
5
- * visible stream.
6
- * Family totals include all subagent descendants; when they contribute the
7
- * section title becomes "Token Usage (including subagents)".
8
- *
9
- * This file is only the View plus slot registration: it computes no numbers
10
- * and formats nothing — all logic lives in ./usage-model.ts (the tested seam).
11
- *
12
- * Colors always come from the live host theme; collapse state is component
13
- * memory, expanded by default and not persisted (spec: Out of Scope).
14
- */
15
- /** @jsxImportSource @opentui/solid */
16
- import { createEffect, createMemo, createSignal, For, onCleanup, Show, untrack } from "solid-js";
17
- import type { TuiPlugin, TuiPluginApi, TuiPluginModule } from "@opencode-ai/plugin/tui";
18
- import {
19
- USAGE_SECTION_TITLE,
20
- USAGE_SECTION_TITLE_WITH_SUBAGENTS,
21
- USAGE_STATUS_TEXT,
22
- createUsageModel,
23
- type SolidRuntime,
24
- } from "./usage-model.ts";
25
-
26
- /**
27
- * The host rewrites this file's "solid-js" import to its own runtime. The
28
- * model builds all of its signals on these exact primitives (see
29
- * SolidRuntime), so the panel stays in the host's reactive graph even when
30
- * installed as an npm package under node_modules.
31
- */
32
- const solid: SolidRuntime = { createSignal, createMemo, createEffect, onCleanup, untrack };
33
-
34
- function Section(props: { api: TuiPluginApi; session_id: string }) {
35
- const theme = () => props.api.theme.current;
36
- const [collapsed, setCollapsed] = createSignal(false);
37
- const model = createUsageModel(props.api, () => props.session_id, solid);
38
-
39
- return (
40
- <box>
41
- <box flexDirection="row" gap={1} onMouseDown={() => setCollapsed(!collapsed())}>
42
- <text fg={theme().text}>{collapsed() ? "▶" : "▼"}</text>
43
- <text fg={theme().text}>
44
- <b>{model.includesSubagents() ? USAGE_SECTION_TITLE_WITH_SUBAGENTS : USAGE_SECTION_TITLE}</b>
45
- </text>
46
- </box>
47
- <Show when={!collapsed()}>
48
- <Show when={model.status() !== "ready"}>
49
- <text fg={theme().textMuted}>{USAGE_STATUS_TEXT[model.status()]}</text>
50
- </Show>
51
- <For each={model.rows()}>
52
- {(row) => (
53
- <box flexDirection="row" justifyContent="space-between">
54
- <text fg={theme().textMuted}>{row.label}</text>
55
- <text fg={theme().text}>{row.value}</text>
56
- </box>
57
- )}
58
- </For>
59
- </Show>
60
- </box>
61
- );
62
- }
63
-
64
- const tui: TuiPlugin = async (api) => {
65
- // Order 150: internal sidebar sections sit at 100/200/300/400/500, so this
66
- // lands right after the first block without moving any existing section.
67
- api.slots.register({
68
- order: 150,
69
- slots: {
70
- sidebar_content(_ctx, props) {
71
- return <Section api={api} session_id={props.session_id} />;
72
- },
73
- },
74
- });
75
- };
76
-
77
- const plugin: TuiPluginModule = {
78
- id: "supercode.token-usage",
79
- tui,
80
- };
81
-
82
- export default plugin;