195 lines
9.1 KiB
HTML
195 lines
9.1 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<!--
|
|
conversation.details — the conversation's lifecycle checks (the core's old
|
|
LifecycleChecks → StatusChecks row): Committed, Pushed, Merged, Deployed,
|
|
Notified — green once stamped, "· 5m ago" on hover — then Completed, green
|
|
once the run reached `finished`. Read through the `checks` action
|
|
(conversations.checks); the cached answer paints at once. Live: a `meta`
|
|
event for this session, a `transcript` one for this conversation (at most
|
|
one read per 10 s), the run starting or stopping. A conversation the hub
|
|
doesn't know (yet): empty, 0 px.
|
|
-->
|
|
<style>
|
|
:root { color-scheme: light dark; }
|
|
* { box-sizing: border-box; }
|
|
html, body { margin: 0; padding: 0; background: transparent; overflow: hidden; }
|
|
body { font: 12px/1 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
color: hsl(var(--foreground, 222 47% 11%)); }
|
|
#root:empty { display: none; }
|
|
.row { display: flex; align-items: center; gap: 4px; }
|
|
.chk { display: inline-flex; align-items: center; border-radius: 4px; padding: 2px;
|
|
color: hsl(var(--muted-foreground, 215 16% 47%) / .3); }
|
|
.chk.lit { color: #10b981; }
|
|
.chk svg { width: 14px; height: 14px; display: block; }
|
|
</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 first = init.update || {};
|
|
// reuseFrame: the host keeps this frame across conversation switches; the
|
|
// ids come in init.update / onUpdate (init.* on older hosts).
|
|
var sessionId = String(first.sessionId || init.sessionId || "");
|
|
var conversationId = String(first.conversationId || init.conversationId || "");
|
|
var running = !!first.running;
|
|
|
|
var LANG = "en";
|
|
function setLang(l) {
|
|
LANG = String(l || document.documentElement.lang || navigator.language || "en").slice(0, 2).toLowerCase() === "fr" ? "fr" : "en";
|
|
}
|
|
setLang(init.lang || first.lang);
|
|
var FR = {
|
|
"Lifecycle checks": "Étapes du cycle de vie",
|
|
"Committed": "Commité", "Pushed": "Pushé", "Merged": "Mergé", "Deployed": "Déployé",
|
|
"Notified": "Notifié", "Completed": "Terminé",
|
|
"{label} · {when}": "{label} · {when}", "{label}: not yet": "{label} : pas encore",
|
|
"just now": "à l'instant", "{n}m ago": "il y a {n} min", "{n}h ago": "il y a {n} h",
|
|
"{n}d ago": "il y a {n} j", "{n}mo ago": "il y a {n} mois"
|
|
};
|
|
function t(s, vars) {
|
|
var out = LANG === "fr" && FR[s] ? FR[s] : s;
|
|
return out.replace(/\{(\w+)\}/g, function (m, k) { return vars && vars[k] != null ? String(vars[k]) : m; });
|
|
}
|
|
function esc(s) {
|
|
return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
|
|
return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c];
|
|
});
|
|
}
|
|
// The app's relTime (lib/utils.ts).
|
|
function relTime(iso) {
|
|
var then = new Date(iso).getTime();
|
|
if (isNaN(then)) return "—";
|
|
var s = Math.max(0, (Date.now() - then) / 1000);
|
|
if (s < 60) return t("just now");
|
|
var m = s / 60;
|
|
if (m < 60) return t("{n}m ago", { n: Math.round(m) });
|
|
var h = m / 60;
|
|
if (h < 24) return t("{n}h ago", { n: Math.round(h) });
|
|
var d = h / 24;
|
|
if (d < 30) return t("{n}d ago", { n: Math.round(d) });
|
|
return t("{n}mo ago", { n: Math.round(d / 30) });
|
|
}
|
|
|
|
// The app's lucide glyphs (GitCommit, ArrowUpFromLine, GitMerge, Rocket,
|
|
// Bell, CircleCheck — lucide 0.469), drawn in currentColor.
|
|
function svg(body) {
|
|
return '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' + body + "</svg>";
|
|
}
|
|
var STAGES = [
|
|
["committed", "Committed", svg('<circle cx="12" cy="12" r="3"/><line x1="3" x2="9" y1="12" y2="12"/><line x1="15" x2="21" y1="12" y2="12"/>')],
|
|
["pushed", "Pushed", svg('<path d="m18 9-6-6-6 6"/><path d="M12 3v14"/><path d="M5 21h14"/>')],
|
|
["merged", "Merged", svg('<circle cx="18" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><path d="M6 21V9a9 9 0 0 0 9 9"/>')],
|
|
["deployed", "Deployed", svg('<path d="M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"/><path d="m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"/><path d="M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"/><path d="M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"/>')],
|
|
["notified", "Notified", svg('<path d="M10.268 21a2 2 0 0 0 3.464 0"/><path d="M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326"/>')],
|
|
["completed", "Completed", svg('<circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/>')]
|
|
];
|
|
|
|
var data = null; // the last answer: {found, state, committed, …}
|
|
var shownH = -1;
|
|
function fit() {
|
|
// 18 px: the row's height, when the frame can't measure (not laid out yet)
|
|
var h = root.innerHTML ? Math.ceil(root.getBoundingClientRect().height) || 18 : 0;
|
|
if (h === shownH) return;
|
|
shownH = h;
|
|
if (P.setEmpty) P.setEmpty(h === 0);
|
|
if (P.resize) P.resize(h);
|
|
}
|
|
function render() {
|
|
if (!data || !data.found) { root.innerHTML = ""; return fit(); }
|
|
var h = '<div class="row" role="group" aria-label="' + esc(t("Lifecycle checks")) + '">';
|
|
STAGES.forEach(function (s) {
|
|
var key = s[0], label = t(s[1]);
|
|
// Completed isn't a stamp: it lights when the run reached `finished`.
|
|
var at = key === "completed" ? (data.state === "finished" ? "" : null) : (data[key] || null);
|
|
var lit = at != null;
|
|
var title = lit ? (at ? t("{label} · {when}", { label: label, when: relTime(at) }) : label)
|
|
: t("{label}: not yet", { label: label });
|
|
h += '<span class="chk' + (lit ? " lit" : "") + '" data-check="' + key + '" title="' + esc(title) + '">' + s[2] + "</span>";
|
|
});
|
|
root.innerHTML = h + "</div>";
|
|
fit();
|
|
}
|
|
|
|
// {conversationId, sessionId} is the manifest's slot "query" payload to the
|
|
// key, so the host's batched Details preload answers it with no request.
|
|
function read(payload, cb) {
|
|
if (P.query) return P.query("checks", payload, cb);
|
|
var stopped = false;
|
|
function go() {
|
|
if (stopped || !P.action) return Promise.resolve();
|
|
return P.action("checks", payload).then(
|
|
function (d) { if (!stopped) cb(d, { fromCache: false, fetching: false, at: Date.now() }); },
|
|
function (e) { if (!stopped) cb(null, { error: String((e && e.message) || e), fromCache: false, fetching: false, at: Date.now() }); });
|
|
}
|
|
go();
|
|
return { stop: function () { stopped = true; }, refresh: go };
|
|
}
|
|
var q = null;
|
|
function start() {
|
|
if (q && q.stop) q.stop();
|
|
q = null;
|
|
if (!conversationId && !sessionId) { fit(); return; }
|
|
var payload = conversationId ? { conversationId: conversationId, sessionId: sessionId } : { sessionId: sessionId };
|
|
q = read(payload, function (d, meta) {
|
|
if (meta && meta.error && !d) return; // keep what's shown
|
|
if (d && typeof d === "object") { data = d; render(); }
|
|
});
|
|
}
|
|
|
|
// A refresh soon: the soonest asked wins, one at a time.
|
|
var timer = null, settle = null, due = 0, lastRead = Date.now();
|
|
function soon(ms) {
|
|
if (!q) return;
|
|
var at = Date.now() + ms;
|
|
if (timer && due <= at) return;
|
|
clearTimeout(timer);
|
|
due = at;
|
|
timer = setTimeout(function () { timer = null; lastRead = Date.now(); if (q) q.refresh(); }, ms);
|
|
}
|
|
if (P.onEvent) P.onEvent(function (ev) {
|
|
if (!ev || !ev.type) return;
|
|
if (ev.type === "meta" && (!ev.id || ev.id === sessionId)) soon(400);
|
|
else if (ev.type === "transcript" && conversationId && (ev.ids || []).indexOf(conversationId) >= 0)
|
|
soon(Math.max(500, 10000 - (Date.now() - lastRead))); // a stamp the transcript shows (a git commit)
|
|
});
|
|
if (P.onUpdate) P.onUpdate(function (u) {
|
|
if (!u || typeof u !== "object") return;
|
|
if (u.lang) { var was = LANG; setLang(u.lang); if (LANG !== was) render(); }
|
|
var ncid = u.conversationId !== undefined ? String(u.conversationId || "") : conversationId;
|
|
var nsid = u.sessionId !== undefined ? String(u.sessionId || "") : sessionId;
|
|
if (ncid !== conversationId || nsid !== sessionId) {
|
|
// Another conversation in the same frame: drop the last one's checks.
|
|
if (q && q.stop) q.stop();
|
|
q = null;
|
|
clearTimeout(timer); clearTimeout(settle); timer = null; settle = null; due = 0;
|
|
conversationId = ncid; sessionId = nsid;
|
|
running = typeof u.running === "boolean" ? u.running : false;
|
|
data = null; lastRead = Date.now();
|
|
render();
|
|
start();
|
|
return;
|
|
}
|
|
if (typeof u.running === "boolean" && u.running !== running) {
|
|
running = u.running;
|
|
soon(400); // finished (Completed) — or started again
|
|
clearTimeout(settle);
|
|
if (!running) settle = setTimeout(function () { settle = null; soon(0); }, 4000); // the state settles a moment after
|
|
}
|
|
});
|
|
start();
|
|
// "5m ago" moves on.
|
|
setInterval(function () { if (data && data.found) render(); }, 60000);
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|