127 lines
8.2 KiB
HTML
127 lines
8.2 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
<title>Task output</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; }
|
|
.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.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; }
|
|
.more { border: 0; background: transparent; padding: 0; margin-bottom: 2px; font-size: 10.5px; color: hsl(var(--muted-foreground)); cursor: pointer; }
|
|
.more:hover { color: hsl(var(--foreground)); }
|
|
pre.out { margin: 0; max-height: 380px; overflow: auto; border-radius: 6px; background: #171717; color: #e5e5e5;
|
|
padding: 8px 12px; font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
|
|
pre.raw { margin: 0; max-height: 240px; overflow: auto; border-radius: 6px; border: 1px solid hsl(var(--border));
|
|
background: hsl(var(--muted) / .15); padding: 8px 12px; font: 12px/1.45 inherit; color: hsl(var(--muted-foreground)); white-space: pre-wrap; }
|
|
</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 = {
|
|
"output of": "sortie de", "task": "tâche", "blocked up to {dur}": "attente jusqu'à {dur}",
|
|
"{n} earlier line": "{n} ligne précédente", "{n} earlier lines": "{n} lignes précédentes",
|
|
"error": "erreur", "still running · timed out": "toujours en cours · délai dépassé", "running": "en cours",
|
|
"completed · exit {code}": "terminé · code {code}", "completed": "terminé"
|
|
};
|
|
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 tn(n, a, b) { return t(n === 1 ? a : b, { n: n }); }
|
|
function esc(s) { return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) { return { "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]; }); }
|
|
function fmtDur(ms) { var s = Math.max(0, Math.round(ms / 1000)); if (s < 60) return s + "s"; var m = Math.floor(s / 60), r = s % 60; return r ? m + "m " + r + "s" : m + "m"; }
|
|
function tag(s, name) { var m = new RegExp("<" + name + ">([\\s\\S]*?)(?:</" + name + ">|$)").exec(s); return m ? m[1].trim() : ""; }
|
|
// agy's manage_task status: "Task: <id>\nStatus: RUNNING|DONE\nLog: file://…\nLog output:\n…"
|
|
function parseAgy(res) {
|
|
var m = /^Task: (\S+)\nStatus: (\w+)(?:\nLog: [^\n]*)?(?:\nLog output:\n?([\s\S]*))?\s*$/.exec(res);
|
|
if (!m) return null;
|
|
var st = m[2].toLowerCase(), out = (m[3] || "").replace(/\r/g, "").replace(/\s+$/, "");
|
|
var ex = /^Command exited with code (-?\d+)/m.exec(out);
|
|
return { retrieval: "", taskId: m[1], taskType: "", status: st === "done" ? "completed" : st,
|
|
exitCode: ex ? Number(ex[1]) : null, output: out };
|
|
}
|
|
function parse(res) {
|
|
if (/^Task: \S+\nStatus: /.test(res)) return parseAgy(res);
|
|
if (!/<retrieval_status>|<status>/.test(res)) return null;
|
|
var code = tag(res, "exit_code");
|
|
return { retrieval: tag(res, "retrieval_status"), taskId: tag(res, "task_id"), taskType: tag(res, "task_type"),
|
|
status: tag(res, "status"), exitCode: /^-?\d+$/.test(code) ? Number(code) : null, output: tag(res, "output") };
|
|
}
|
|
function chipOf(r, isError) {
|
|
if (isError) return { label: t("error"), tone: "red" };
|
|
if (!r) return null;
|
|
if (r.status === "running" || r.retrieval === "timeout") return { label: t(r.retrieval === "timeout" ? "still running · timed out" : "running"), tone: "amber" };
|
|
if (r.status === "completed") {
|
|
return r.exitCode != null && r.exitCode !== 0
|
|
? { label: t("completed · exit {code}", { code: r.exitCode }), tone: "red" }
|
|
: { label: r.exitCode != null ? t("completed · exit {code}", { code: r.exitCode }) : t("completed"), tone: "green" };
|
|
}
|
|
return r.status ? { label: r.status, tone: (r.status === "failed" || r.status === "killed") ? "red" : "muted" } : null;
|
|
}
|
|
|
|
var item = { input: init.input || {}, result: init.result || "", isError: !!init.isError, taskRef: init.taskRef || null, showOut: init.toolOutputVisible !== false };
|
|
var showAll = false, 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 || {}, res = item.showOut ? item.result : "", r = parse(res), ref = item.taskRef;
|
|
var chip = chipOf(r, item.isError);
|
|
var refName = (ref && (ref.native || String(ref.name || "").replace(/^[^:]+:/, ""))) || (r && r.taskType) || t("task");
|
|
var timeout = typeof inp.timeout === "number" ? inp.timeout : null;
|
|
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("output of")) + '</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 (inp.block !== false && timeout) h += "<span>· " + esc(t("blocked up to {dur}", { dur: fmtDur(timeout) })) + "</span>";
|
|
if (chip) h += '<span class="pill ' + esc(chip.tone) + '">' + esc(chip.label) + "</span>";
|
|
h += "</div>";
|
|
if (r && r.output) {
|
|
var lines = r.output.split("\n"), TAIL = 40;
|
|
var shown = showAll || lines.length <= TAIL ? lines : lines.slice(-TAIL);
|
|
h += "<div>";
|
|
if (shown.length < lines.length) h += '<button type="button" class="more" data-more="1">… ' + esc(tn(lines.length - shown.length, "{n} earlier line", "{n} earlier lines")) + "</button>";
|
|
h += '<pre class="out">' + esc(shown.join("\n")) + "</pre></div>";
|
|
} else if (!r && res) {
|
|
h += '<pre class="raw">' + esc(res) + "</pre>";
|
|
}
|
|
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") });
|
|
if (e.target.closest("[data-more]")) { showAll = true; render(); }
|
|
});
|
|
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;
|
|
if (u.toolOutputVisible !== undefined) item.showOut = !!u.toolOutputVisible;
|
|
render();
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|