80 lines
4.7 KiB
HTML
80 lines
4.7 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Background shell state</title>
|
|
<style>
|
|
:root { color-scheme: light dark; }
|
|
* { box-sizing: border-box; }
|
|
html, body { margin: 0; padding: 0; background: transparent; overflow: hidden; }
|
|
body { font: 11px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
color: hsl(var(--muted-foreground)); -webkit-font-smoothing: antialiased; }
|
|
.strip { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
|
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; flex-shrink: 0; }
|
|
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
|
|
.pill { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; white-space: nowrap;
|
|
border-radius: 999px; border: 1px solid hsl(var(--border)); background: hsl(var(--muted) / .5);
|
|
color: hsl(var(--muted-foreground)); padding: 0 6px;
|
|
font: 10px/16px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
.pill.amber { border-color: rgb(245 158 11 / .4); background: rgb(245 158 11 / .1); color: #d97706; }
|
|
html.dark .pill.amber { color: #fbbf24; }
|
|
.pill.green { border-color: rgb(16 185 129 / .4); background: rgb(16 185 129 / .1); color: #059669; }
|
|
html.dark .pill.green { color: #34d399; }
|
|
.pill.red { border-color: rgb(239 68 68 / .4); background: rgb(239 68 68 / .1); color: #dc2626; }
|
|
html.dark .pill.red { color: #f87171; }
|
|
.pill .dot { width: 6px; height: 6px; border-radius: 999px; background: currentColor; animation: pulse 1.5s ease-in-out infinite; }
|
|
@keyframes pulse { 50% { opacity: .4; } }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="root"></div>
|
|
<script>
|
|
(function () {
|
|
"use strict";
|
|
var P = window.aiAgentPlugin || {};
|
|
var init = P.init || {};
|
|
var root = document.getElementById("root");
|
|
var LANG = String(init.lang || "en").slice(0, 2).toLowerCase() === "fr" ? "fr" : "en";
|
|
var FR = { "exit {code}": "code {code}", "done · exit {code}": "fini · code {code}", "done": "fini", "failed": "échec", "killed": "tué", "stopped": "arrêté", "in background": "en arrière-plan" };
|
|
function t(s, v) { return (LANG === "fr" && FR[s] ? FR[s] : s).replace(/\{(\w+)\}/g, function (m, k) { return v && v[k] != null ? String(v[k]) : m; }); }
|
|
function esc(s) { return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]; }); }
|
|
function clock(iso) { var n = Date.parse(iso); return isNaN(n) ? null : new Date(n).toLocaleTimeString(LANG === "fr" ? "fr-FR" : "en-US", { hour: "2-digit", minute: "2-digit" }); }
|
|
|
|
var item = { taskId: init.taskId || null, taskState: init.taskState || null, taskExitCode: init.taskExitCode, taskEvents: init.taskEvents || [] };
|
|
function chipOf() {
|
|
var st = item.taskState, code = item.taskExitCode;
|
|
if (st === "completed") return code != null && code !== 0 ? { label: t("exit {code}", { code: code }), tone: "red" } : { label: code != null ? t("done · exit {code}", { code: code }) : t("done"), tone: "green" };
|
|
if (st === "failed" || st === "killed") return { label: t(st), tone: "red" };
|
|
if (st === "stopped") return { label: t("stopped"), tone: "muted" };
|
|
return { label: t("in background"), tone: "amber", pulse: true };
|
|
}
|
|
var lastH = -1;
|
|
function fit() { var h = root.firstChild ? Math.ceil(root.getBoundingClientRect().height) : 0; if (h !== lastH) { lastH = h; if (P.setEmpty) P.setEmpty(h === 0); if (P.resize) P.resize(h); } }
|
|
if (window.ResizeObserver) new ResizeObserver(fit).observe(root);
|
|
|
|
function render() {
|
|
if (!item.taskId) { root.innerHTML = ""; return fit(); }
|
|
var chip = chipOf();
|
|
var end = null, evs = item.taskEvents || [];
|
|
for (var i = evs.length - 1; i >= 0; i--) if (evs[i].kind !== "event") { end = evs[i]; break; }
|
|
var at = end && end.ts ? clock(end.ts) : null;
|
|
root.innerHTML = '<div class="strip"><span class="pill ' + esc(chip.tone) + '">' + (chip.pulse ? '<span class="dot"></span>' : "") + esc(chip.label) + '</span><span class="mono">' + esc(item.taskId) + "</span>" +
|
|
(at ? "<span>· " + esc(at) + "</span>" : "") +
|
|
(end && end.kind !== "ended" && end.text ? '<span class="trunc">· ' + esc(end.text) + "</span>" : "") + "</div>";
|
|
fit();
|
|
}
|
|
render();
|
|
if (P.onUpdate) P.onUpdate(function (u) {
|
|
if (!u || typeof u !== "object") return;
|
|
if (u.taskId !== undefined) item.taskId = u.taskId;
|
|
if (u.taskState !== undefined) item.taskState = u.taskState;
|
|
if (u.taskExitCode !== undefined) item.taskExitCode = u.taskExitCode;
|
|
if (Array.isArray(u.taskEvents)) item.taskEvents = u.taskEvents;
|
|
render();
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|