diff options
| author | Danilo M. <danix@danix.xyz> | 2026-11-09 18:18:10 +0100 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-11-09 18:18:10 +0100 |
| commit | 2e86bcdc2132e7772e20e9f4426e3f079a07e5e0 (patch) | |
| tree | 6ad406071097fee9b7347c1b8605188d17de99a7 /static/modules/llm.js | |
| parent | e2ddaeb9a9271069a36b77112110fa8e646ab02f (diff) | |
| download | deck-it-2e86bcdc2132e7772e20e9f4426e3f079a07e5e0.tar.gz deck-it-2e86bcdc2132e7772e20e9f4426e3f079a07e5e0.zip | |
feat: llm usage panel
Diffstat (limited to 'static/modules/llm.js')
| -rw-r--r-- | static/modules/llm.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/static/modules/llm.js b/static/modules/llm.js new file mode 100644 index 0000000..093c27c --- /dev/null +++ b/static/modules/llm.js @@ -0,0 +1,55 @@ +const num = (v) => (v == null ? null : Number(v)); +const pct = (v) => (num(v) == null ? "—" : `${Math.round(num(v))}%`); +const money = (v, cur) => (num(v) == null ? "—" : `${num(v).toFixed(2)}${cur ? " " + cur : ""}`); +const clock = (sec) => (sec ? new Date(sec * 1000).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) : ""); + +function line(label, value, percent) { + const row = document.createElement("div"); + row.className = "row"; + const name = document.createElement("span"); + name.textContent = label; + const val = document.createElement("span"); + val.className = "num"; + val.textContent = value; + row.append(name, val); + const wrap = document.createElement("div"); + wrap.append(row); + if (percent != null) { + const meter = document.createElement("div"); + meter.className = "meter"; + const fill = document.createElement("i"); + fill.style.width = `${Math.max(0, Math.min(100, Number(percent)))}%`; + meter.append(fill); + wrap.append(meter); + } + return wrap; +} + +export default { + title: "LLM usage", + interval: 5, + + mount(el) { + const box = document.createElement("div"); + box.className = "llm"; + el.append(box); + }, + + update(state, el) { + const box = el.querySelector(".llm"); + box.textContent = ""; + if (state.offline) { + box.textContent = "llm-cost-dashboard offline"; + return; + } + const c = state.claude ?? {}; + const o = state.opencode ?? {}; + box.append( + line("Context", pct(c.context_pct), c.context_pct), + line(`5h window ${clock(c.five_hour_resets_at)}`, pct(c.five_hour_pct), c.five_hour_pct), + line(`7d window ${clock(c.seven_day_resets_at)}`, pct(c.seven_day_pct), c.seven_day_pct), + line("Month", money(c.extra_used, c.extra_currency)), + line("opencode spend", money(o.total_cost)), + ); + }, +}; |
