80 lines
4.8 KiB
HTML
80 lines
4.8 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Task stop</title>
|
|
<style>
|
|
:root { color-scheme: light dark; }
|
|
* { box-sizing: border-box; }
|
|
html, body { margin: 0; padding: 0; background: transparent; overflow: hidden; }
|
|
body { font: 12px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: hsl(var(--foreground)); -webkit-font-smoothing: antialiased; }
|
|
.wrap { display: flex; flex-direction: column; gap: 6px; }
|
|
.ref { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11.5px; color: hsl(var(--muted-foreground)); }
|
|
.ref svg { width: 12px; height: 12px; flex-shrink: 0; }
|
|
.ref-btn { border: 0; background: transparent; padding: 0; color: hsl(var(--foreground)); font: inherit; font-weight: 500; cursor: pointer; text-align: left; }
|
|
.ref-btn:hover { text-decoration: underline; }
|
|
.ref-btn:disabled { cursor: default; text-decoration: none; }
|
|
.tid { font: 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; opacity: .7; }
|
|
.pill { display: inline-flex; align-items: center; 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.red { border-color: rgb(239 68 68 / .4); background: rgb(239 68 68 / .1); color: #dc2626; }
|
|
html.dark .pill.red { color: #f87171; }
|
|
pre.cmd { margin: 0; overflow: auto; border-radius: 6px; background: #171717; color: #e5e5e5; padding: 8px 10px;
|
|
font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
|
|
.msg { font-size: 12px; color: hsl(var(--muted-foreground)); }
|
|
.msg.err { color: #dc2626; }
|
|
html.dark .msg.err { color: #f87171; }
|
|
</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 = { "started by": "lancé par", "task": "tâche", "stopped": "arrêté", "failed": "échec" };
|
|
function t(s) { return LANG === "fr" && FR[s] ? FR[s] : s; }
|
|
function esc(s) { return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]; }); }
|
|
function parse(res) { try { var d = JSON.parse(res); return d && typeof d === "object" ? { message: String(d.message || ""), command: String(d.command || ""), taskType: String(d.task_type || "") } : null; } catch (e) { return null; } }
|
|
|
|
var item = { input: init.input || {}, result: init.result || "", isError: !!init.isError, taskRef: init.taskRef || null };
|
|
var lastH = -1;
|
|
function fit() { var h = Math.ceil(root.getBoundingClientRect().height); if (h && h !== lastH) { lastH = h; if (P.resize) P.resize(h); } }
|
|
if (window.ResizeObserver) new ResizeObserver(fit).observe(root);
|
|
|
|
function render() {
|
|
var inp = item.input || {}, r = parse(item.result), ref = item.taskRef;
|
|
var refName = (ref && (ref.native || String(ref.name || "").replace(/^[^:]+:/, ""))) || (r && r.taskType) || t("task");
|
|
var tid = String(inp.task_id || inp.shell_id || "");
|
|
var h = '<div class="wrap"><div class="ref"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="9 14 4 9 9 4"/><path d="M20 20v-7a4 4 0 0 0-4-4H4"/></svg><span>' + esc(t("started by")) + '</span><button type="button" class="ref-btn"' + (ref && ref.toolUseId ? ' data-jump="' + esc(ref.toolUseId) + '"' : " disabled") + ">" + esc(refName) + (ref && ref.label ? " · " + esc(ref.label) : "") + "</button>";
|
|
if (tid) h += '<span class="tid">' + esc(tid) + "</span>";
|
|
if (item.isError) h += '<span class="pill red">' + esc(t("failed")) + "</span>";
|
|
else if (item.result) h += '<span class="pill">' + esc(t("stopped")) + "</span>";
|
|
h += "</div>";
|
|
if (r && r.command) h += '<pre class="cmd">' + esc(r.command) + "</pre>";
|
|
else if (!r && item.result) h += '<div class="msg' + (item.isError ? " err" : "") + '">' + esc(item.result) + "</div>";
|
|
root.innerHTML = h + "</div>";
|
|
fit();
|
|
}
|
|
root.addEventListener("click", function (e) {
|
|
var j = e.target.closest("[data-jump]");
|
|
if (j && P.scrollTo) P.scrollTo({ toolUseId: j.getAttribute("data-jump") });
|
|
});
|
|
render();
|
|
if (P.onUpdate) P.onUpdate(function (u) {
|
|
if (!u || typeof u !== "object") return;
|
|
if (u.result !== undefined) item.result = u.result || "";
|
|
if (u.isError !== undefined) item.isError = !!u.isError;
|
|
if (u.taskRef !== undefined) item.taskRef = u.taskRef;
|
|
render();
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|