m64_0f5b8210b0a4 / human/index.html
219 lines, 10.4 KBraw
1<!doctype html>2<html lang="en">3<meta charset="utf-8">4<meta name="viewport" content="width=device-width, initial-scale=1">5<title>pi coding agent · Qwen3.8-Flash-Next on Strata (local)</title>6<style>7 :root { color-scheme: light dark; --fg: #1d1d1f; --bg: #f6f5f2; --card: #fff; --muted: #6b6b70; --line: #d8d6d0; --accent: #0f766e; --code: #efede8; }8 @media (prefers-color-scheme: dark) { :root { --fg: #ecebe8; --bg: #161616; --card: #1f1f1f; --muted: #9a9a9f; --line: #333; --accent: #2dd4bf; --code: #262626; } }9 * { box-sizing: border-box; }10 body { margin: 0; padding: 24px 16px; font: 15px/1.45 system-ui, sans-serif; color: var(--fg); background: var(--bg); }11 main { max-width: 820px; margin: 0 auto; }12 h1 { font-size: 20px; margin: 0 0 4px; }13 .sub { color: var(--muted); margin: 0 0 16px; font-size: 13px; }14 a { color: var(--accent); }15 .bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; font-size: 13px; color: var(--muted); }16 .bar code { color: var(--fg); }17 #log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }18 .msg { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }19 .msg.user { border-left: 3px solid var(--muted); }20 .msg.agent { border-left: 3px solid var(--accent); }21 .msg.err { border-left: 3px solid #dc2626; color: #dc2626; }22 .meta { color: var(--muted); font-size: 12px; margin-top: 6px; white-space: normal; }23 details { margin-top: 6px; font-size: 13px; white-space: normal; }24 summary { cursor: pointer; color: var(--muted); }25 pre { background: var(--code); border-radius: 6px; padding: 8px; overflow-x: auto; font-size: 12px; margin: 4px 0; white-space: pre-wrap; }26 form { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }27 @media (max-width: 560px) { form { grid-template-columns: 1fr 1fr; } textarea { grid-column: 1 / -1; } }28 textarea, button { font: inherit; color: inherit; background: transparent; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }29 textarea { resize: vertical; min-height: 44px; }30 button { cursor: pointer; }31 button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }32 @media (prefers-color-scheme: dark) { button.primary { color: #0b1f1d; } }33 button:disabled { opacity: .5; cursor: progress; }34 #status { margin: 10px 0; color: var(--muted); font-size: 13px; min-height: 1.4em; }35 #status.err { color: #dc2626; }36 h2 { font-size: 15px; margin: 20px 0 6px; }37 #files { list-style: none; padding: 0; margin: 0; font-size: 14px; }38 #files li { padding: 3px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }39 #files .size { color: var(--muted); font-size: 12px; }40 button.link { border: 0; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }41 [hidden] { display: none !important; }42 .open { display: block; margin: 8px 0 20px; padding: 16px 18px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 18px; font-weight: 600; text-decoration: none; text-align: center; }43 @media (prefers-color-scheme: dark) { .open { color: #0b1f1d; } }44 .open small { display: block; font-weight: 400; font-size: 12px; opacity: .85; margin-top: 2px; overflow-wrap: anywhere; }45 .cmd { display: flex; gap: 8px; align-items: stretch; margin: 4px 0 10px; }46 .cmd pre { flex: 1; margin: 0; font-size: 13px; }47 .note { color: var(--muted); font-size: 13px; margin: 6px 0; }48 details.quick { margin-top: 24px; border-top: 1px solid var(--line); padding-top: 8px; }49 details.quick > summary { font-weight: 600; color: var(--fg); }50</style>51<main>52 <h1>pi coding agent</h1>53 <p class="sub">Qwen3.8-Flash-Next IQ3_S on Strata in the same container (256K context), in a sandbox with no network by default. API: <a href="../agent">/agent</a></p>5455 <section>56 <p class="note">Each session gets an empty folder. A turn runs the agent until it is done: seconds to minutes.</p>57 <div class="bar">Session: <code id="sid">none yet</code> <button id="new" type="button">New session</button></div>58 <div id="log"></div>59 <form id="f">60 <textarea id="text" rows="2" required>write hello.py that prints hi and run it</textarea>61 <button id="go" class="primary" type="submit">Send</button>62 <button id="stop" type="button" disabled>Stop</button>63 </form>64 <div id="status"></div>65 <h2>Files <button id="refresh" type="button" style="font-size:12px;padding:2px 8px">refresh</button></h2>66 <ul id="files"><li><span class="size">no session yet</span></li></ul>67 <section id="viewer" hidden>68 <h2><span id="viewer-name"></span> <button id="viewer-close" type="button" style="font-size:12px;padding:2px 8px">close</button></h2>69 <pre id="viewer-text"></pre>70 </section>71 </section>72</main>73<script>74const $ = (id) => document.getElementById(id);75let sid = null;76let timer = null;7778function say(text, err) { $("status").textContent = text; $("status").className = err ? "err" : ""; }79function el(tag, cls, text) { const e = document.createElement(tag); if (cls) e.className = cls; if (text != null) e.textContent = text; return e; }80function errText(d, r) {81 if (typeof d.error === "string") return d.error;82 if (d.error) return JSON.stringify(d.error);83 if (d.detail) return typeof d.detail === "string" ? d.detail : JSON.stringify(d.detail);84 return "HTTP " + r.status;85}8687async function waitReady() {88 for (;;) {89 let s;90 try { s = await (await fetch("../status")).json(); } catch (e) { s = { phase: "unreachable" }; }91 if (s.phase === "ready") { say(""); return true; }92 if (s.phase === "error" || s.phase === "stopped") { say("Service " + s.phase + ": " + (s.detail || ""), true); return false; }93 say("Starting: " + s.phase + (s.detail ? " (" + s.detail + ")" : ""));94 await new Promise((r) => setTimeout(r, 3000));95 }96}9798async function newSession() {99 if (!(await waitReady())) return false;100 const r = await fetch("../v1/sessions", { method: "POST", headers: { "Content-Type": "application/json" }, body: "{}" });101 const d = await r.json().catch(() => ({}));102 if (!r.ok) { say("Could not create a session: " + errText(d, r), true); return false; }103 sid = d.id;104 $("sid").textContent = sid;105 $("log").replaceChildren();106 await listFiles();107 return true;108}109110async function listFiles() {111 const ul = $("files");112 if (!sid) return;113 const r = await fetch("../v1/sessions/" + sid + "/files");114 const d = await r.json().catch(() => ({}));115 ul.replaceChildren();116 if (!r.ok) { ul.append(el("li", "size", errText(d, r))); return; }117 if (!d.entries.length) { ul.append(el("li", "size", "(empty)")); return; }118 for (const e of d.entries) {119 const li = el("li");120 if (e.type === "file") {121 // Agent-written bytes: offer a download, or show them as text in this page (never rendered).122 const url = "../v1/sessions/" + sid + "/files?path=" + encodeURIComponent(e.name);123 const name = el("span", null, e.name + " ");124 const view = el("button", "link", "view");125 view.type = "button";126 view.addEventListener("click", () => viewText(e.name, url));127 const a = el("a", null, "download");128 a.href = url;129 a.download = e.name;130 const left = el("span");131 left.append(name, view, " · ", a);132 li.append(left, el("span", "size", e.size + " B"));133 } else if (e.type === "dir") {134 li.append(el("span", null, e.name + "/"), el("span", "size", "dir"));135 } else {136 li.append(el("span", null, e.name), el("span", "size", e.type));137 }138 ul.append(li);139 }140}141142async function viewText(name, url) {143 const r = await fetch(url);144 const buf = await r.arrayBuffer();145 const text = r.ok ? new TextDecoder().decode(buf.slice(0, 200000)) : "HTTP " + r.status;146 $("viewer-name").textContent = name + (buf.byteLength > 200000 ? " (first 200 KB)" : "");147 $("viewer-text").textContent = text;148 $("viewer").hidden = false;149}150151function showReply(d) {152 const box = el("div", "msg agent", d.text || "(no text)");153 if (d.error) box.append(el("div", "meta", "error: " + JSON.stringify(d.error)));154 for (const t of d.tools || []) {155 const det = el("details");156 det.append(el("summary", null, t.tool + " · " + t.status));157 det.append(el("pre", null, JSON.stringify(t.input, null, 2)));158 if (t.output) det.append(el("pre", null, t.output));159 box.append(det);160 }161 box.append(el("div", "meta", (d.tools || []).length + " tool calls · " + d.elapsed_s + " s"));162 $("log").append(box);163}164165$("f").addEventListener("submit", async (ev) => {166 ev.preventDefault();167 const text = $("text").value.trim();168 if (!text) return;169 $("go").disabled = true;170 try {171 if (!sid && !(await newSession())) return;172 $("log").append(el("div", "msg user", text));173 $("text").value = "";174 $("stop").disabled = false;175 const t0 = performance.now();176 timer = setInterval(() => say("Agent working… " + ((performance.now() - t0) / 1000).toFixed(0) + " s"), 500);177 const r = await fetch("../v1/sessions/" + sid + "/messages", {178 method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text }),179 });180 const d = await r.json().catch(() => ({}));181 clearInterval(timer);182 if (!r.ok) { $("log").append(el("div", "msg err", errText(d, r))); say(""); return; }183 showReply(d);184 say("");185 await listFiles();186 } catch (e) {187 clearInterval(timer);188 say("Request failed: " + e, true);189 } finally {190 $("go").disabled = false;191 $("stop").disabled = true;192 }193});194195$("stop").addEventListener("click", async () => {196 if (sid) await fetch("../v1/sessions/" + sid + "/abort", { method: "POST" });197});198$("new").addEventListener("click", () => newSession());199$("refresh").addEventListener("click", () => listFiles());200$("viewer-close").addEventListener("click", () => { $("viewer").hidden = true; });201202for (const b of document.querySelectorAll("[data-copy]")) {203 b.addEventListener("click", async () => {204 const text = $(b.dataset.copy).textContent;205 try { await navigator.clipboard.writeText(text); }206 catch (e) { // plain http is not a secure context: select and copy the old way207 const range = document.createRange();208 range.selectNodeContents($(b.dataset.copy));209 getSelection().removeAllRanges();210 getSelection().addRange(range);211 document.execCommand("copy");212 }213 b.textContent = "copied";214 setTimeout(() => { b.textContent = "copy"; }, 1500);215 });216}217waitReady();218</script>219</html>