aboutsummaryrefslogtreecommitdiffstats
path: root/static/modules
diff options
context:
space:
mode:
Diffstat (limited to 'static/modules')
-rw-r--r--static/modules/k1c.js31
-rw-r--r--static/modules/llm.js125
-rw-r--r--static/modules/obs.js20
-rw-r--r--static/modules/sbbuilder.js95
-rw-r--r--static/modules/stats.js79
-rw-r--r--static/modules/tablet.js77
6 files changed, 72 insertions, 355 deletions
diff --git a/static/modules/k1c.js b/static/modules/k1c.js
index d8211fa..261ef4d 100644
--- a/static/modules/k1c.js
+++ b/static/modules/k1c.js
@@ -86,6 +86,37 @@ function armHold(btn) {
btn.style.setProperty("--hold", `${HOLD_MS}ms`);
}
+// The dashboard's running slot: file, percent, time left, layer and
+// temperatures, the press-and-hold stop and a progress bar. Wide slots show
+// the slicer thumbnail in place of the icon (deck.css container query).
+export const busy = (st) => !st.offline && (st.state === "printing" || st.state === "paused");
+
+export function slot(st, el) {
+ if (!el.firstChild) {
+ el.innerHTML = `<i class="nf sic"></i><img class="sthumb" alt="" hidden>
+ <span class="what"><span></span></span><span class="pct num"></span>
+ <span class="meta"><span></span></span>
+ <button class="estop act" aria-label="Emergency stop: press and hold">
+ <span class="estop-label">Emergency stop</span><span class="estop-hint">hold</span>
+ </button>
+ <div class="bar"><i></i></div>`;
+ armHold(el.querySelector(".estop"));
+ }
+ const p = st.progress ?? 0;
+ const name = (st.file ?? "").split("/").pop();
+ el.querySelector(".what > span").textContent = st.state === "paused" ? `Paused · ${name}` : name;
+ el.querySelector(".pct").textContent = `${Math.round(p * 100)}%`;
+ el.querySelector(".meta > span").textContent = [
+ `${dur(st.remaining)} left`,
+ st.layers ? `layer ${st.layer ?? "?"}/${st.layers}` : null,
+ `${temp(st.extruder)} / ${temp(st.bed)}`,
+ ].filter(Boolean).join(" · ");
+ el.querySelector(".bar i").style.width = `${p * 100}%`;
+ const thumb = el.querySelector(".sthumb");
+ thumb.hidden = !st.thumbnail;
+ if (st.thumbnail && thumb.getAttribute("src") !== st.thumbnail) thumb.src = st.thumbnail;
+}
+
export default {
title: "K1C",
tab: "K1C",
diff --git a/static/modules/llm.js b/static/modules/llm.js
deleted file mode 100644
index 1bbbcce..0000000
--- a/static/modules/llm.js
+++ /dev/null
@@ -1,125 +0,0 @@
-// deck-it - llm panel
-// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as
-// published by the Free Software Foundation.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-import { offline } from "../offline.js";
-
-const num = (v) => (v == null ? null : Number(v));
-const money = (v) => (num(v) == null ? "—" : `$${num(v).toFixed(2)}`);
-const tokens = (n) => {
- if (n == null) return "—";
- if (n >= 1e9) return `${(n / 1e9).toFixed(1)}B`;
- if (n >= 1e6) return `${(n / 1e6).toFixed(1)}M`;
- if (n >= 1e3) return `${(n / 1e3).toFixed(1)}k`;
- return String(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");
- sec.className = "llm-sec";
- const head = document.createElement("header");
- head.className = "llm-head";
- head.innerHTML = `${icon}<h3></h3><span class="model"></span>`;
- head.querySelector("h3").textContent = title;
- head.querySelector(".model").textContent = model || "—";
- sec.append(head);
- return sec;
-}
-
-function gauge(label, value) {
- const d = document.createElement("div");
- d.className = "gauge";
- const l = document.createElement("span");
- l.className = "glabel";
- l.textContent = label;
- const v = document.createElement("span");
- v.className = "gvalue num";
- v.textContent = value == null ? "—" : `${Math.round(value)}%`;
- const bar = document.createElement("div");
- bar.className = "gbar";
- const fill = document.createElement("i");
- fill.style.width = `${Math.max(0, Math.min(100, value || 0))}%`;
- bar.append(fill);
- d.append(l, v, bar);
- return d;
-}
-
-function stat(label, value, sub) {
- const d = document.createElement("div");
- d.className = "lbig";
- const l = document.createElement("span");
- l.className = "mlabel";
- l.textContent = label;
- const v = document.createElement("span");
- v.className = "mvalue num";
- v.textContent = value;
- const s = document.createElement("span");
- s.className = "msub";
- s.textContent = sub || "";
- d.append(l, v, s);
- return d;
-}
-
-export default {
- title: "LLM usage",
- interval: 5,
-
- mount(el) {
- el.innerHTML = `<div class="llm"></div>`;
- },
-
- update(state, el) {
- const box = el.querySelector(".llm");
- if (state.offline) {
- offline(box, {
- icon: "/logos/claude.svg",
- title: "Usage dashboard is off",
- detail: "Start llm-cost-dashboard and Claude, opencode and assistant usage appear here.",
- });
- return;
- }
- box.textContent = "";
- const c = state.claude ?? {};
- const o = state.opencode ?? {};
-
- const claude = section(CLAUDE_ICON, "Claude Code", c.model);
- const gauges = document.createElement("div");
- gauges.className = "gauges";
- gauges.append(
- gauge("Context", c.context_pct),
- gauge("5h", c.five_hour_pct),
- gauge("7d", c.seven_day_pct),
- );
- claude.append(gauges);
- box.append(claude);
-
- 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/static/modules/obs.js b/static/modules/obs.js
index 6842522..bcf237b 100644
--- a/static/modules/obs.js
+++ b/static/modules/obs.js
@@ -54,6 +54,26 @@ async function post(action, body = {}) {
}
}
+// The dashboard's running slot: what is live, the scene and the elapsed
+// time, and a stop for it.
+export const busy = (st) => Boolean(st.connected && (st.recording || st.streaming));
+
+export function slot(st, el) {
+ if (!el.firstChild) {
+ el.innerHTML = `<i class="nf sic rec"></i>
+ <span class="what"><span></span></span><span class="pct num"></span>
+ <span class="meta"><span></span></span>
+ <button class="act">Stop</button>`;
+ }
+ const what = st.recording ? (st.paused ? "Recording paused" : "Recording") : "Streaming";
+ el.querySelector(".what > span").textContent = `${what} · ${st.currentScene ?? ""}`;
+ el.querySelector(".pct").textContent = st.recording ? clock(st.recordingTime) : "live";
+ el.querySelector(".meta > span").textContent =
+ [st.recording ? "recording" : null, st.streaming ? "streaming" : null].filter(Boolean).join(" + ");
+ el.querySelector(".act").onclick = () =>
+ post(st.recording ? "record" : "stream", { on: false });
+}
+
function bigButton(kind, name, label, on, times) {
const b = document.createElement("button");
b.className = `deck-btn ${kind}${on ? " on" : ""}`;
diff --git a/static/modules/sbbuilder.js b/static/modules/sbbuilder.js
index 6285dd5..357133f 100644
--- a/static/modules/sbbuilder.js
+++ b/static/modules/sbbuilder.js
@@ -1,4 +1,4 @@
-// deck-it - sbbuilder panel
+// deck-it - the build VM's running slot
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
@@ -14,80 +14,27 @@
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-import { offline } from "../offline.js";
+// The build VM has no tab: on the Dashboard it is a running slot while a job
+// is active, and nothing otherwise.
-const gib = (b) => (b == null ? "?" : (b / 1073741824).toFixed(1));
-const pct = (n) => (n == null ? "?" : `${Math.round(n)}%`);
-const ago = (ts) => {
- if (!ts) return "—";
- const d = Math.max(0, Math.floor(Date.now() / 1000 - ts));
- if (d < 3600) return `${Math.floor(d / 60)}m`;
- if (d < 86400) return `${Math.floor(d / 3600)}h`;
- return `${Math.floor(d / 86400)}d`;
-};
+export const interval = 10; // each poll is an ssh round trip
const ACTIVE = ["running", "busy", "starting"];
-
-function tile(label, value, sub) {
- const d = document.createElement("div");
- d.className = "mtile";
- const l = document.createElement("span");
- l.className = "mlabel";
- l.textContent = label;
- const v = document.createElement("span");
- v.className = "mvalue num";
- v.textContent = value;
- const s = document.createElement("span");
- s.className = "msub";
- s.textContent = sub || "";
- d.append(l, v, s);
- return d;
+const active = (st) => (st.jobs ?? []).filter((j) => ACTIVE.includes(j.status));
+
+export const busy = (st) => !st.offline && active(st).length > 0;
+
+export function slot(st, el) {
+ if (!el.firstChild) {
+ el.innerHTML = `<i class="nf sic"></i>
+ <span class="what"><span></span></span><span class="pct num"></span>
+ <span class="meta"><span></span></span>
+ <div class="bar busy"><i></i></div>`;
+ }
+ const jobs = active(st);
+ const load = st.stats?.load;
+ el.querySelector(".what > span").textContent = `Build VM · ${jobs[0]?.kind || "job"}`;
+ el.querySelector(".pct").textContent = jobs.length > 1 ? `${jobs.length} jobs` : "";
+ el.querySelector(".meta > span").textContent =
+ [jobs[0]?.status, load ? `load ${load[0].toFixed(2)}` : null].filter(Boolean).join(" · ");
}
-
-export default {
- title: "Build VM",
- interval: 10,
-
- mount(el) {
- el.innerHTML = `<div class="sbb"></div>`;
- },
-
- update(state, el) {
- const box = el.querySelector(".sbb");
- if (state.offline) {
- offline(box, {
- icon: "/icons/virt-manager.svg",
- title: "Build VM is off",
- detail: "Start the VM and its jobs and package counts appear here.",
- });
- return;
- }
- box.textContent = "";
- const s = state.stats ?? {};
- const p = s.packages ?? {};
- const sr = s.slackrepo ?? {};
- const results = sr.results ?? {};
- const jobs = state.jobs ?? [];
- const running = jobs.find((j) => ACTIVE.includes(j.status));
-
- const now = document.createElement("div");
- now.className = "sbb-now";
- now.textContent = running ? `● ${running.kind || "job"}` : "idle";
- now.classList.toggle("warn", Boolean(running));
- box.append(now);
-
- const overlays = Object.entries(p).filter(([k]) => k !== "total" && k !== "shadowed");
- box.append(
- tile("Packages", String(p.total ?? "?"), overlays.map(([k, v]) => `${k} ${v}`).join(" · ")),
- tile("Failed", String(results.failed ?? 0), `${sr.built ?? "?"} built`),
- tile("Disk free", `${gib(s.disk?.free)}`, `of ${gib(s.disk?.total)} GiB`),
- tile("CPU", pct(s.cpu), `load ${s.load ? s.load[0].toFixed(2) : "?"}`),
- );
-
- const foot = document.createElement("div");
- foot.className = "mfoot";
- foot.textContent = `orphans ${s.orphans ?? "?"} · ${
- Object.entries(s.sync ?? {}).map(([k, v]) => `${k} ${ago(v)}`).join(" · ") || "no pulls"}`;
- box.append(foot);
- },
-};
diff --git a/static/modules/stats.js b/static/modules/stats.js
deleted file mode 100644
index 0e35a91..0000000
--- a/static/modules/stats.js
+++ /dev/null
@@ -1,79 +0,0 @@
-// deck-it - stats panel
-// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as
-// published by the Free Software Foundation.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-const gib = (kb) => (kb / 1048576).toFixed(1);
-const bytes = (b) => (b == null ? "?" : (b / 1073741824).toFixed(1));
-const rate = (b) => (b >= 1048576 ? `${(b / 1048576).toFixed(1)}M` : `${Math.round(b / 1024)}k`);
-const uptime = (s) => {
- const d = Math.floor(s / 86400);
- const h = Math.floor((s % 86400) / 3600);
- return d ? `${d}d ${h}h` : `${h}h`;
-};
-
-// Nerd Font distro logos; anything else gets Tux.
-const DISTRO = {
- slackware: "\uf318", arch: "\uf303", debian: "\uf306", fedora: "\uf30a",
- ubuntu: "\uf31b", gentoo: "\uf30d", opensuse: "\uf314", void: "\uf32e",
-};
-
-function tile(label, value, sub) {
- const d = document.createElement("div");
- d.className = "mtile";
- const l = document.createElement("span");
- l.className = "mlabel";
- l.textContent = label;
- const v = document.createElement("span");
- v.className = "mvalue num";
- v.textContent = value;
- const s = document.createElement("span");
- s.className = "msub";
- s.textContent = sub || "";
- d.append(l, v, s);
- return d;
-}
-
-export default {
- title: "System",
- interval: 1,
-
- mount(el) {
- el.innerHTML = `<div class="stats"></div>`;
- },
-
- update(st, el) {
- const box = el.querySelector(".stats");
- box.textContent = "";
- const g = st.gpu;
- box.append(
- tile(st.cpuName ?? "CPU", `${st.cpu}%`, st.cpuTemp != null ? `${st.cpuTemp}°C` : "—"),
- tile("Memory", gib(st.memUsed), `/ ${gib(st.memTotal)} GiB`),
- tile(g?.name ?? "GPU", g?.temp != null ? `${g.temp}°` : "—",
- g ? `${bytes(g.memUsed)} / ${bytes(g.memTotal)} GiB` : "no GPU"),
- tile("Network", `↓${rate(st.net.down)} ↑${rate(st.net.up)}`),
- );
- const os = st.os ?? {};
- const sys = document.createElement("div");
- sys.className = "mtile msys";
- sys.innerHTML = `<i class="nf"></i><div><span class="mvalue"></span><span class="msub"></span></div>
- <div class="mup"><span class="mlabel">uptime</span><span class="mvalue num"></span></div>`;
- sys.querySelector("i").textContent = DISTRO[os.id] ?? "\uf17c";
- sys.querySelector("div .mvalue").textContent = os.name ?? "Linux";
- sys.querySelector(".msub").textContent =
- [os.codename, `Linux ${os.kernel ?? ""}`].filter(Boolean).join(" · ");
- sys.querySelector(".mup .mvalue").textContent = uptime(st.uptime);
- box.append(sys);
- },
-};
diff --git a/static/modules/tablet.js b/static/modules/tablet.js
deleted file mode 100644
index cb38416..0000000
--- a/static/modules/tablet.js
+++ /dev/null
@@ -1,77 +0,0 @@
-// deck-it - tablet panel
-// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License version 2 as
-// published by the Free Software Foundation.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License along
-// with this program; if not, write to the Free Software Foundation, Inc.,
-// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-// The tablet's battery and Wi-Fi, in the System card's tile style.
-
-import { offline } from "../offline.js";
-
-function tile(label, value, sub, cls = "", badge = "") {
- const d = document.createElement("div");
- d.className = "mtile";
- d.innerHTML = `<span class="mlabel"></span><span class="mvalue num ${cls}"></span><span class="msub"></span>`;
- d.children[0].textContent = label;
- d.children[0].insertAdjacentHTML("beforeend", badge);
- d.children[1].textContent = value;
- d.children[2].textContent = sub || "";
- return d;
-}
-
-// Four bars in the label, lit by Android's thresholds: -55 dBm and up is full.
-function bars(rssi) {
- const n = rssi == null ? 0 : rssi >= -55 ? 4 : rssi >= -66 ? 3 : rssi >= -77 ? 2 : 1;
- const rects = [0, 1, 2, 3].map((i) =>
- `<rect x="${i * 4}" y="${9 - i * 3}" width="3" height="${3 + i * 3}" rx="1"${i < n ? ' class="lit"' : ""}/>`);
- return `<svg class="bars" viewBox="0 0 15 12" aria-hidden="true">${rects.join("")}</svg>`;
-}
-
-export default {
- title: "Tablet",
- interval: 10,
-
- mount(el) {
- el.innerHTML = `<div class="tablet"><div class="stats"></div></div>`;
- },
-
- update(st, el) {
- const box = el.querySelector(".stats");
- if (!st.connected) {
- offline(box, {
- icon: "/icons/smartphone.svg",
- title: "Tablet not reachable over adb",
- detail: "Its battery and Wi-Fi show here once deck-it's tunnel is up.",
- reason: st.error,
- });
- return;
- }
- box.textContent = "";
- const b = st.battery;
- const w = st.wifi;
- const low = b.level <= 20 && b.status !== "charging";
- box.append(
- tile("Battery", `${b.level}%`,
- [b.status, b.plug, b.temp != null ? `${b.temp}°C` : ""].filter(Boolean).join(" · "),
- low ? "bad" : b.status === "charging" ? "good" : ""),
- w.connected
- ? tile("Wi-Fi", `${w.rssi ?? "?"} dBm`,
- [w.ssid, w.band, w.speed ? `${w.speed} Mbps` : ""].filter(Boolean).join(" · "), "", bars(w.rssi))
- : tile("Wi-Fi", "off", "not connected", "warn"),
- );
- const foot = document.createElement("div");
- foot.className = "mfoot";
- foot.textContent = `linked over ${st.link}`;
- box.append(foot);
- },
-};