diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-10 18:16:32 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-10 18:16:32 +0100 |
| commit | b22003b6a86f16f3de6f77093fb94d8b89203dc2 (patch) | |
| tree | 4ebd032f6c92751d2749f6a7bc78d1f3c1ab23e8 | |
| parent | 9f6f909d696c2f8b1e1e8261431e3d815baf277e (diff) | |
| download | deck-it-b22003b6a86f16f3de6f77093fb94d8b89203dc2.tar.gz deck-it-b22003b6a86f16f3de6f77093fb94d8b89203dc2.zip | |
feat(llm): desktop-assistant usage as Local Agent
The LLM usage card gets a third section, the desktop-assistant
program from llm-cost-dashboard, with the same session and total
stats as opencode. The per-program aggregation now takes the program.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| -rw-r--r-- | deckit/modules/llm.py | 18 | ||||
| -rw-r--r-- | static/deck.css | 1 | ||||
| -rw-r--r-- | static/modules/llm.js | 24 | ||||
| -rw-r--r-- | tests/test_llm.py | 5 |
4 files changed, 28 insertions, 20 deletions
diff --git a/deckit/modules/llm.py b/deckit/modules/llm.py index 7856603..2d697bf 100644 --- a/deckit/modules/llm.py +++ b/deckit/modules/llm.py @@ -14,7 +14,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -"""Claude Code and opencode usage, relayed from llm-cost-dashboard's API. +"""Claude Code, opencode and desktop-assistant usage, relayed from llm-cost-dashboard's API. Everything here is read-only. The dashboard stays the owner of the data and the pricing; deck-it only renders it. @@ -35,9 +35,9 @@ def _fetch_for(base): return fetch -def _opencode(rows) -> dict: - """Aggregate /api/summary's per-model rows into opencode's cost and tokens.""" - picked = [r for r in rows if isinstance(r, dict) and r.get("program") == "opencode"] +def _program(rows, program) -> dict: + """Aggregate /api/summary's per-model rows into one program's cost and tokens.""" + picked = [r for r in rows if isinstance(r, dict) and r.get("program") == program] models = [ {"provider": r.get("provider") or "", "model": r.get("model") or "", "cost": r.get("total_cost_usd") or 0, "tokens": r.get("tokens") or 0, @@ -58,10 +58,10 @@ def _claude_model(session) -> str | None: return models[0].get("model") if models else None -def _opencode_session(sessions) -> dict: - """The latest opencode session's dominant model from /api/last_session.""" +def _session(sessions, program) -> dict: + """A program's latest session and its dominant model from /api/last_session.""" for block in sessions or []: - if not isinstance(block, dict) or block.get("program") != "opencode": + if not isinstance(block, dict) or block.get("program") != program: continue rows = block.get("rows") or [] top = max(rows, key=lambda r: r.get("calls") or 0) if rows else {} @@ -108,8 +108,8 @@ def make(cfg: dict) -> Module: "extra_currency": latest.get("extra_currency"), "model": _claude_model(claude_session), }, - "opencode": {**_opencode(data.get("/api/summary") or []), - **_opencode_session(sessions)}, + **{p: {**_program(data.get("/api/summary") or [], p), **_session(sessions, p)} + for p in ("opencode", "assistant")}, } return Module(name="llm", title="LLM usage", state=state) diff --git a/static/deck.css b/static/deck.css index b322a11..4e9b753 100644 --- a/static/deck.css +++ b/static/deck.css @@ -375,6 +375,7 @@ select { } .brand.claude { -webkit-mask-image: url(/logos/claude.svg); mask-image: url(/logos/claude.svg); } .brand.opencode { -webkit-mask-image: url(/logos/opencode.svg); mask-image: url(/logos/opencode.svg); } +.brand-nf { width: 18px; flex: none; font-size: 18px; line-height: 1; text-align: center; color: var(--udt-accent); } .llm-head h3 { font-size: 0.857rem; text-transform: uppercase; diff --git a/static/modules/llm.js b/static/modules/llm.js index 9ee28e1..1bbbcce 100644 --- a/static/modules/llm.js +++ b/static/modules/llm.js @@ -28,6 +28,7 @@ const tokens = (n) => { const CLAUDE_ICON = '<span class="brand claude"></span>'; const OPENCODE_ICON = '<span class="brand opencode"></span>'; +const AGENT_ICON = '<i class="nf brand-nf">\uf086</i>'; function section(icon, title, model) { const sec = document.createElement("section"); @@ -89,7 +90,7 @@ export default { offline(box, { icon: "/logos/claude.svg", title: "Usage dashboard is off", - detail: "Start llm-cost-dashboard and Claude and opencode usage appear here.", + detail: "Start llm-cost-dashboard and Claude, opencode and assistant usage appear here.", }); return; } @@ -108,14 +109,17 @@ export default { claude.append(gauges); box.append(claude); - const opencode = section(OPENCODE_ICON, "opencode", o.model); - const pair = document.createElement("div"); - pair.className = "lpair"; - pair.append( - stat("session", money(o.session_cost), `${tokens(o.session_tokens)} · ${o.session_calls ?? 0} calls`), - stat("total", money(o.cost), `${tokens(o.tokens)} · ${o.calls ?? 0} calls`), - ); - opencode.append(pair); - box.append(opencode); + for (const [icon, title, p] of [[OPENCODE_ICON, "opencode", o], + [AGENT_ICON, "Local Agent", state.assistant ?? {}]]) { + const sec = section(icon, title, p.model); + const pair = document.createElement("div"); + pair.className = "lpair"; + pair.append( + stat("session", money(p.session_cost), `${tokens(p.session_tokens)} · ${p.session_calls ?? 0} calls`), + stat("total", money(p.cost), `${tokens(p.tokens)} · ${p.calls ?? 0} calls`), + ); + sec.append(pair); + box.append(sec); + } }, }; diff --git a/tests/test_llm.py b/tests/test_llm.py index 48e49fe..3820249 100644 --- a/tests/test_llm.py +++ b/tests/test_llm.py @@ -33,7 +33,7 @@ class Down(unittest.TestCase): class Up(unittest.TestCase): - def test_aggregates_opencode_and_ignores_other_programs(self): + def test_aggregates_opencode_and_assistant_apart(self): data = {"/api/claude_limits": [{"context_pct": 12}], "/api/claude_session": {"session": {"models": [{"model": "claude-opus-4"}]}}, "/api/summary": [ @@ -64,6 +64,9 @@ class Up(unittest.TestCase): self.assertEqual(st["opencode"]["session_cost"], 0.5) self.assertEqual(st["opencode"]["session_calls"], 4) self.assertEqual(st["opencode"]["session_tokens"], 500) + self.assertEqual(st["assistant"]["cost"], 9.0) + self.assertEqual(st["assistant"]["calls"], 9) + self.assertIsNone(st["assistant"]["model"]) def test_handles_the_real_latest_shape(self): data = {"/api/claude_limits": {"latest": {"context_pct": 42, "five_hour_pct": 10}}, |
