@openeryc/pi-coding-agent 0.75.23 → 0.75.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/dist/modes/web/web-mode.d.ts.map +1 -1
- package/dist/modes/web/web-mode.js +131 -146
- package/dist/modes/web/web-mode.js.map +1 -1
- package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
- package/examples/extensions/custom-provider-anthropic/package.json +1 -1
- package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
- package/examples/extensions/sandbox/package-lock.json +2 -2
- package/examples/extensions/sandbox/package.json +1 -1
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/npm-shrinkwrap.json +12 -12
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-mode.d.ts","sourceRoot":"","sources":["../../../src/modes/web/web-mode.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAwP/E,wBAAsB,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgJ5E","sourcesContent":["import { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { networkInterfaces } from \"node:os\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.ts\";\nimport type { AgentSessionRuntime } from \"../../core/agent-session-runtime.ts\";\n\nconst PASSWORD = process.env.PI_WEB_PASSWORD;\n\nfunction checkAuth(req: IncomingMessage, res: ServerResponse): boolean {\n\tif (!PASSWORD) return true;\n\n\tconst auth = req.headers.authorization;\n\tif (auth) {\n\t\tconst [scheme, credentials] = auth.split(\" \");\n\t\tif (scheme === \"Basic\" && credentials) {\n\t\t\tconst decoded = Buffer.from(credentials, \"base64\").toString(\"utf-8\");\n\t\t\tconst [, password] = decoded.split(\":\");\n\t\t\tif (password === PASSWORD) return true;\n\t\t}\n\t}\n\n\tres.writeHead(401, {\n\t\t\"www-authenticate\": 'Basic realm=\"pi\", charset=\"UTF-8\"',\n\t\t\"content-type\": \"text/plain\",\n\t});\n\tres.end(\"Unauthorized\");\n\treturn false;\n}\n\nfunction getLocalIP(): string {\n\tconst interfaces = networkInterfaces();\n\tfor (const iface of Object.values(interfaces)) {\n\t\tif (!iface) continue;\n\t\tfor (const addr of iface) {\n\t\t\tif (addr.family === \"IPv4\" && !addr.internal) {\n\t\t\t\treturn addr.address;\n\t\t\t}\n\t\t}\n\t}\n\treturn \"127.0.0.1\";\n}\n\nfunction getPort(): number {\n\tconst env = process.env.PORT;\n\tif (env) {\n\t\tconst p = parseInt(env, 10);\n\t\tif (!Number.isNaN(p) && p > 0 && p < 65536) return p;\n\t}\n\treturn 0;\n}\n\nconst HTML = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no\">\n<title>pi</title>\n<style>\n*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}\nhtml{font-size:14px;-webkit-text-size-adjust:100%}\nbody{font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",system-ui,sans-serif;background:#0b1014;color:#c9d1d9;display:flex;flex-direction:column;height:100dvh;overflow:hidden}\n#header{display:flex;align-items:center;justify-content:space-between;padding:8px 16px;background:#0d121a;border-bottom:1px solid #21262d;flex-shrink:0;gap:10px}\n#header-left{display:flex;align-items:center;gap:10px}\n#header h1{font-size:14px;font-weight:600;color:#e6edf3}\n#session-info{font-size:11px;color:#6e7681;max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n#header-stats{display:flex;gap:12px;font-size:11px;color:#7d8590}\n#msgs{flex:1;overflow-y:auto;padding:16px 20px;scroll-behavior:smooth;display:flex;flex-direction:column;gap:14px}\n#msgs::-webkit-scrollbar{width:6px}\n#msgs::-webkit-scrollbar-track{background:transparent}\n#msgs::-webkit-scrollbar-thumb{background:#30363d;border-radius:3px}\n.msg-group{display:flex;flex-direction:column;gap:2px;animation:fadeIn .15s ease;max-width:86%}\n.msg-group.user{max-width:82%;align-self:flex-end}\n@keyframes fadeIn{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:translateY(0)}}\n.msg-label{font-size:10.5px;font-weight:600;text-transform:uppercase;letter-spacing:.5px;padding:0 2px}\n.msg-group.user .msg-label{color:#7ec9ff;text-align:right}\n.msg-group.assistant .msg-label{color:#7d8590}\n.msg{border-radius:8px;font-size:13.5px;line-height:1.6;overflow-wrap:break-word;padding:10px 14px}\n.msg.user{background:#1b4a8b;color:#e6edf3;border-bottom-right-radius:2px}\n.msg.assistant{background:#1a1f2b;color:#c9d1d9;border-bottom-left-radius:2px;border:1px solid #21262d}\n.msg.system{background:transparent;color:#6e7681;font-size:12px;text-align:center;max-width:100%;padding:4px 0}\n.msg p{margin:0 0 6px}\n.msg p:last-child{margin-bottom:0}\n.msg strong{color:#f2a65a;font-weight:600}\n.msg em{color:#c9d1d9;font-style:italic}\n.msg code{font-family:\"JetBrains Mono\",\"Fira Code\",monospace;font-size:12px;background:#2d333b;color:#c9d1d9;padding:1px 5px;border-radius:3px}\n.msg pre{background:#161b22;border:1px solid #30363d;border-radius:6px;padding:10px 12px;margin:8px 0;overflow-x:auto;font-size:12px;line-height:1.5}\n.msg pre code{background:transparent;padding:0;border-radius:0;font-size:inherit}\n.msg h1,.msg h2,.msg h3{margin:8px 0 4px;font-weight:600;color:#e6edf3}\n.msg h1{font-size:18px;border-bottom:1px solid #21262d;padding-bottom:4px}\n.msg h2{font-size:15px}\n.msg h3{font-size:13.5px;color:#c9d1d9}\n.msg ul,.msg ol{padding-left:20px;margin:4px 0 8px}\n.msg li{margin:2px 0}\n.msg hr{border:none;border-top:1px solid #21262d;margin:10px 0}\n.tool{border:1px solid #21262d;border-radius:8px;overflow:hidden;transition:border-color .2s}\n.tool:hover{border-color:#30363d}\n.tool-header{display:flex;align-items:center;justify-content:space-between;padding:7px 10px;background:#0d121a;cursor:pointer;user-select:none;gap:8px;transition:background .15s}\n.tool-header:hover{background:#161b22}\n.tool-icon{width:7px;height:7px;border-radius:50%;flex-shrink:0}\n.tool-icon.pending{background:#d29922;animation:pulse 1.5s infinite}\n.tool-icon.done{background:#3fb950}\n.tool-icon.error{background:#f85149}\n@keyframes pulse{0%,100%{opacity:.4}50%{opacity:1}}\n.tool-title{flex:1;font-size:12px;font-weight:500;color:#c9d1d9;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n.tool-arrow{color:#6e7681;font-size:9px;transition:transform .2s}\n.tool.expanded .tool-arrow{transform:rotate(90deg)}\n.tool-body{font-family:\"JetBrains Mono\",\"Fira Code\",monospace;font-size:12px;line-height:1.55;padding:8px 10px;background:#0b1014;white-space:pre-wrap;word-break:break-all;overflow-x:auto;max-height:30vh;overflow-y:auto;display:none}\n.tool-body::-webkit-scrollbar{width:4px;height:4px}\n.tool-body::-webkit-scrollbar-thumb{background:#30363d;border-radius:2px}\n.tool.expanded .tool-body{display:block}\n.tool.mini .tool-body{max-height:12vh}\n.thinking{padding:5px 10px;border-left:2px solid #30363d;font-size:11.5px;color:#6e7681;font-style:italic}\n#input-area{background:#0d121a;border-top:1px solid #21262d;padding:12px 16px;flex-shrink:0}\n#input-area form{display:flex;gap:8px;max-width:900px;margin:0 auto}\n#prompt{flex:1;background:#161b22;border:1px solid #30363d;border-radius:8px;padding:9px 12px;color:#c9d1d9;font-size:13.5px;font-family:inherit;outline:none;transition:border-color .2s,box-shadow .2s}\n#prompt:focus{border-color:#4493f8;box-shadow:0 0 0 3px rgba(68,147,248,.15)}\n#prompt::placeholder{color:#484f58}\nbutton{background:#1f6feb;color:#fff;border:none;border-radius:8px;padding:9px 16px;font-size:13px;font-weight:500;cursor:pointer;transition:background .15s;flex-shrink:0}\nbutton:hover{background:#2b83ff}\nbutton:disabled{background:#21262d;color:#6e7681;cursor:not-allowed}\n.btn-mini{font-size:11px;padding:4px 10px;background:#21262d}\n.btn-mini:hover{background:#30363d}\n.spinner{display:none;width:16px;height:16px;border:2px solid #30363d;border-top-color:#4493f8;border-radius:50%;animation:spin .6s linear infinite}\n.spinner.active{display:inline-block}\n@keyframes spin{to{transform:rotate(360deg)}}\n@media(max-width:600px){\nhtml{font-size:13px}\n#msgs{padding:10px;gap:10px}\n.msg-group{max-width:94%}\n.msg-group.user{max-width:92%}\n#input-area{padding:8px 10px}\n#prompt{padding:7px 10px}\nbutton{padding:7px 12px}\n}\n</style>\n</head>\n<body>\n<div id=\"header\">\n<div id=\"header-left\"><h1>pi</h1><span id=\"session-info\"></span></div>\n<div id=\"header-stats\"><span id=\"stat-sessions\"></span><span id=\"stat-cost\"></span></div>\n</div>\n<div id=\"msgs\"></div>\n<div id=\"input-area\">\n<form id=\"f\" autocomplete=\"off\">\n<input id=\"prompt\" type=\"text\" placeholder=\"Message pi...\" autofocus autocomplete=\"off\">\n<button id=\"send\">Send</button>\n<span class=\"spinner\" id=\"spinner\"></span>\n</form>\n</div>\n<script>\nconst msgs=document.getElementById(\"msgs\"),f=document.getElementById(\"f\"),prompt=document.getElementById(\"prompt\"),\nsend=document.getElementById(\"send\"),spinner=document.getElementById(\"spinner\"),\nstatSessions=document.getElementById(\"stat-sessions\"),statCost=document.getElementById(\"stat-cost\"),\nsessionInfo=document.getElementById(\"session-info\");\nlet busy=false,toolEls={},curAssistant=null;\n\nfunction scrollDown(){msgs.scrollTop=msgs.scrollHeight}\nfunction esc(s){if(!s)return\"\";return s.replace(/&/g,\"&\").replace(/</g,\"<\").replace(/>/g,\">\")}\nfunction fmt(n){if(n<1e3)return n;if(n<1e4)return(n/1e3).toFixed(1)+\"k\";return Math.round(n/1e3)+\"k\"}\n\nfunction md(text){\nlet s=esc(text);\nconst blocks=[];\ns=s.replace(/\\`\\`\\`(\\\\w*)\\\\n([\\\\s\\\\S]*?)\\\\n\\`\\`\\`/g,(_,lang,code)=>{blocks.push('<pre><code>'+code+'</code></pre>');return'\\\\x00B'+(blocks.length-1)+'\\\\x00B'});\ns=s.replace(/\\`([^\\`]+)\\`/g,'<code>$1</code>');\ns=s.replace(/\\\\*\\\\*(.+?)\\\\*\\\\*/g,'<strong>$1</strong>');\ns=s.replace(/\\\\*(.+?)\\\\*/g,'<em>$1</em>');\ns=s.replace(/^### (.+$)/gm,'<h3>$1</h3>');\ns=s.replace(/^## (.+$)/gm,'<h2>$1</h2>');\ns=s.replace(/^# (.+$)/gm,'<h1>$1</h1>');\ns=s.replace(/^- (.+$)/gm,'<li>$1</li>');\ns=s.replace(/^> (.+$)/gm,'<blockquote>$1</blockquote>');\ns=s.replace(/((?:<li>.*<\\\\/li>\\\\n?)+)/g,'<ul>$1</ul>');\ns=s.replace(/^(---+|\\\\*\\\\*\\\\*+|___+)$/gm,'<hr>');\ns=s.replace(/\\\\x00B(\\\\d+)\\\\x00B/g,(_,i)=>blocks[parseInt(i)]);\ns=s.replace(/\\\\n\\\\n/g,'<br><br>');\ns=s.replace(/\\\\n/g,'<br>');\nreturn s\n}\n\nfunction addMsg(role,text){\nconst g=document.createElement(\"div\");g.className=\"msg-group \"+role;\nif(role===\"user\"){g.innerHTML='<div class=\"msg-label\">You</div><div class=\"msg user\">'+esc(text)+'</div>'}\nelse if(role===\"assistant\"){g.innerHTML='<div class=\"msg-label\">pi</div><div class=\"msg assistant\"></div>'}\nelse{g.innerHTML='<div class=\"msg system\">'+text+'</div>'}\nmsgs.appendChild(g);scrollDown();return g}\n\nfunction getAssistantDiv(){if(!curAssistant){curAssistant=addMsg(\"assistant\",\"\")}return curAssistant.querySelector(\".msg\")}\n\nfunction startTool(e){\nconst el=document.createElement(\"div\");el.className=\"tool\";el.id=\"t\"+e.toolCallId;\nconst title=esc(e.toolName)+(e.args?' '+esc(String(e.args.command||e.args.path||e.args.file_path||\"\").slice(0,80)):'');\nel.innerHTML='<div class=\"tool-header\"><span class=\"tool-icon pending\"></span><span class=\"tool-title\">'+title+'</span><span class=\"tool-arrow\">▶</span></div><div class=\"tool-body\"></div>';\nel.querySelector(\".tool-header\").onclick=()=>el.classList.toggle(\"expanded\");\nmsgs.appendChild(el);toolEls[e.toolCallId]=el;scrollDown()}\n\nfunction updateTool(id,result,isError){\nconst el=toolEls[id];if(!el)return;\nconst icon=el.querySelector(\".tool-icon\"),body=el.querySelector(\".tool-body\");\nif(isError){icon.className=\"tool-icon error\"}\nconst texts=result&&result.content?result.content.filter(c=>c&&c.type===\"text\").map(c=>c.text):[];\nif(texts.length){body.textContent=texts.join(\"\\\\n\");el.classList.add(\"expanded\",\"mini\")}}\n\nfunction finishTool(id,isError){\nconst el=toolEls[id];if(!el)return;\nconst icon=el.querySelector(\".tool-icon\");icon.className=\"tool-icon \"+(isError?\"error\":\"done\");\nconst body=el.querySelector(\".tool-body\");if(isError&&!body.textContent.trim())body.textContent=\"(no output)\"}\n\nfunction handle(d){\nswitch(d.type){\ncase\"agent_start\":curAssistant=null;break;\ncase\"text_delta\":{const ad=getAssistantDiv();ad.innerHTML+=md(d.delta);scrollDown();break}\ncase\"thinking_delta\":{let th=document.getElementById(\"think\"+d.contentIndex);if(!th){th=document.createElement(\"div\");th.className=\"thinking\";th.id=\"think\"+d.contentIndex;msgs.appendChild(th)}th.textContent+=d.delta;scrollDown();break}\ncase\"tool_execution_start\":startTool(d);break;\ncase\"tool_execution_update\":updateTool(d.toolCallId,d.result,false);break;\ncase\"tool_execution_end\":finishTool(d.toolCallId,d.isError);if(d.result)updateTool(d.toolCallId,d.result,d.isError);break;\ncase\"agent_end\":{let s=\"\";if(d.usage){s=\" · \"+fmt(d.usage.input)+\" in · \"+fmt(d.usage.output)+\" out\";if(d.usage.cost)s+=\" · $\"+d.usage.cost.total.toFixed(4)}addMsg(\"system\",\"Done\"+s);break}\ncase\"compaction\":addMsg(\"system\",\"Compacting...\");break;\ncase\"error\":addMsg(\"system\",\"Error: \"+esc(d.message));break;\ncase\"text_start\":case\"thinking_start\":case\"text_end\":case\"thinking_end\":case\"toolcall_start\":case\"toolcall_end\":case\"toolcall_delta\":break}}\n\nf.onsubmit=async e=>{e.preventDefault();if(busy)return;const text=prompt.value.trim();if(!text)return;prompt.value=\"\";addMsg(\"user\",text);busy=true;send.disabled=true;spinner.className=\"spinner active\";\ntry{const r=await fetch(\"/api/prompt\",{method:\"POST\",headers:{\"content-type\":\"application/json\"},body:JSON.stringify({text})});\nif(!r.ok){addMsg(\"system\",\"Error: \"+r.status);return}\nconst reader=r.body.getReader(),decoder=new TextDecoder();let buf=\"\";\nwhile(true){const{done,value}=await reader.read();if(done)break;buf+=decoder.decode(value,{stream:true});const lines=buf.split(\"\\\\n\");buf=lines.pop()||\"\";\nfor(const line of lines){if(!line.trim())continue;try{handle(JSON.parse(line))}catch{}}}}\ncatch(err){addMsg(\"system\",\"Error: \"+esc(err.message))}finally{busy=false;send.disabled=false;spinner.className=\"spinner\"}};\n\nfetch(\"/api/messages\").then(r=>r.json()).then(events=>{\nfor(const e of events){\nif(e.type===\"user\"){addMsg(\"user\",e.text)}\nelse{handle(e)}\n}\n}).catch(()=>{});\n\nfetch(\"/api/stats\").then(r=>r.json()).then(s=>{\nstatSessions.textContent=s.sessions+\" sessions\";\nstatCost.textContent=\"$\"+s.cost.toFixed(2);\n}).catch(()=>{});\n\nfetch(\"/api/session-info\").then(r=>r.json()).then(s=>{\nsessionInfo.textContent=s.id?(\"session: \"+s.id.slice(0,8)+(s.name?\" | \"+s.name:\"\")):\"\";\n}).catch(()=>{});\n</script>\n</body>\n</html>`;\n\nfunction sendEvent(res: ServerResponse, data: Record<string, unknown>): void {\n\tres.write(`${JSON.stringify(data)}\\n`);\n}\n\nexport async function runWebMode(runtime: AgentSessionRuntime): Promise<void> {\n\tconst session = runtime.session;\n\tconst port = getPort();\n\n\tconst server = createServer(async (req: IncomingMessage, res: ServerResponse) => {\n\t\tif (!checkAuth(req, res)) return;\n\n\t\tconst url = req.url ?? \"/\";\n\n\t\tif (req.method === \"POST\" && url === \"/api/prompt\") {\n\t\t\tconst chunks: Buffer[] = [];\n\t\t\treq.on(\"data\", (chunk: Buffer) => chunks.push(chunk));\n\t\t\tawait new Promise<void>((resolve) => req.on(\"end\", resolve));\n\t\t\tconst body = JSON.parse(Buffer.concat(chunks).toString());\n\t\t\tconst text = String(body.text ?? \"\").trim();\n\t\t\tif (!text) {\n\t\t\t\tres.writeHead(400);\n\t\t\t\tres.end(JSON.stringify({ error: \"missing text\" }));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tres.writeHead(200, { \"content-type\": \"text/plain; charset=utf-8\", \"cache-control\": \"no-cache\" });\n\n\t\t\tconst unsubscribe = session.subscribe((event: AgentSessionEvent) => {\n\t\t\t\tconst events = toSerializableEvents(event);\n\t\t\t\tfor (const evt of events) {\n\t\t\t\t\tsendEvent(res, evt);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tawait session.prompt(text);\n\t\t\t} catch (err) {\n\t\t\t\tsendEvent(res, { type: \"error\", message: String(err) });\n\t\t\t} finally {\n\t\t\t\tunsubscribe();\n\t\t\t\tres.end();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/stats\") {\n\t\t\tconst stats = await session.getUsageStats();\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(\n\t\t\t\tJSON.stringify({ sessions: stats.sessions, cost: stats.cost, input: stats.input, output: stats.output }),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/session-info\") {\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tid: session.sessionId,\n\t\t\t\t\tname: session.sessionManager.getSessionName(),\n\t\t\t\t\tfile: session.sessionFile,\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/messages\") {\n\t\t\tconst entries = session.sessionManager.getEntries();\n\t\t\tconst events: Record<string, unknown>[] = [];\n\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (entry.type !== \"message\") continue;\n\t\t\t\tconst msg = (entry as { message: { role: string; content: unknown; usage?: unknown } }).message;\n\t\t\t\tif (!msg) continue;\n\n\t\t\t\tif (msg.role === \"user\") {\n\t\t\t\t\tconst content = typeof msg.content === \"string\" ? msg.content : \"\";\n\t\t\t\t\tevents.push({ type: \"user\", text: content });\n\t\t\t\t} else if (msg.role === \"assistant\") {\n\t\t\t\t\tconst content = Array.isArray(msg.content) ? msg.content : [];\n\t\t\t\t\tfor (const block of content as Array<{ type: string; text?: string; toolCall?: unknown }>) {\n\t\t\t\t\t\tif (block.type === \"text\" && block.text) {\n\t\t\t\t\t\t\tevents.push({ type: \"text_delta\", delta: block.text });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (block.type === \"toolCall\" && block.toolCall) {\n\t\t\t\t\t\t\tconst tc = block.toolCall as { toolCallId?: string; toolName?: string; input?: unknown };\n\t\t\t\t\t\t\tevents.push({\n\t\t\t\t\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\t\t\t\t\ttoolCallId: tc.toolCallId,\n\t\t\t\t\t\t\t\ttoolName: tc.toolName,\n\t\t\t\t\t\t\t\targs: tc.input,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (msg.role === \"toolResult\") {\n\t\t\t\t\tconst content = (msg as { toolCallId?: string; content?: Array<{ type: string; text?: string }> })\n\t\t\t\t\t\t.content;\n\t\t\t\t\tevents.push({\n\t\t\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\t\t\ttoolCallId: (msg as { toolCallId?: string }).toolCallId,\n\t\t\t\t\t\tresult: { content: content ?? [] },\n\t\t\t\t\t\tisError: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst usage = getSessionTokenCount(session);\n\t\t\tevents.push({ type: \"agent_end\", usage });\n\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(JSON.stringify(events));\n\t\t\treturn;\n\t\t}\n\n\t\tres.writeHead(200, { \"content-type\": \"text/html; charset=utf-8\" });\n\t\tres.end(HTML);\n\t});\n\n\tawait new Promise<void>((resolve, reject) => {\n\t\tserver.listen(port, \"0.0.0.0\", () => resolve());\n\t\tserver.on(\"error\", reject);\n\t});\n\n\tconst addr = server.address();\n\tif (!addr || typeof addr === \"string\") {\n\t\tconsole.error(\"Failed to start web server\");\n\t\treturn;\n\t}\n\n\tconst consolePort = `http://127.0.0.1:${addr.port}`;\n\tconst lan = getLocalIP();\n\tconsole.log(`\\n pi web UI: ${consolePort}`);\n\tif (lan !== \"127.0.0.1\") {\n\t\tconsole.log(` LAN: http://${lan}:${addr.port}`);\n\t}\n\tconsole.log(` session: ${session.sessionId.slice(0, 8)}`);\n\tconsole.log(\" (listening on all interfaces)\");\n\tif (PASSWORD) {\n\t\tconsole.log(` auth: Basic (user \"pi\", password from PI_WEB_PASSWORD)`);\n\t} else {\n\t\tconsole.log(\" auth: none (set PI_WEB_PASSWORD to enable)\");\n\t}\n\tconsole.log();\n\n\t// Keep process alive\n\tawait new Promise(() => {});\n\n\tserver.close();\n}\n\nfunction getSessionTokenCount(session: AgentSessionRuntime[\"session\"]): Record<string, unknown> | undefined {\n\tconst entries = session.sessionManager.getEntries();\n\tlet input = 0;\n\tlet output = 0;\n\tlet costTotal = 0;\n\tlet hasUsage = false;\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tconst msg = (\n\t\t\tentry as { message: { role: string; usage?: { input: number; output: number; cost: { total: number } } } }\n\t\t).message;\n\t\tif (msg?.role === \"assistant\" && msg.usage) {\n\t\t\tinput += msg.usage.input;\n\t\t\toutput += msg.usage.output;\n\t\t\tcostTotal += msg.usage.cost.total;\n\t\t\thasUsage = true;\n\t\t}\n\t}\n\treturn hasUsage ? { input, output, cost: { total: costTotal } } : undefined;\n}\n\nfunction toSerializableEvents(event: AgentSessionEvent): Record<string, unknown>[] {\n\tswitch (event.type) {\n\t\tcase \"agent_start\":\n\t\t\treturn [{ type: \"agent_start\" }];\n\t\tcase \"agent_end\": {\n\t\t\tconst lastAssistant = event.messages.filter((m) => m.role === \"assistant\").at(-1);\n\t\t\tconst usage = lastAssistant && \"usage\" in lastAssistant ? lastAssistant.usage : undefined;\n\t\t\treturn [{ type: \"agent_end\", usage }];\n\t\t}\n\t\tcase \"message_update\": {\n\t\t\tconst ame: Record<string, unknown> = event.assistantMessageEvent;\n\t\t\tconst serialized = serializeAssistantMessageEvent(ame);\n\t\t\treturn serialized;\n\t\t}\n\t\tcase \"tool_execution_start\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"tool_execution_update\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_update\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.partialResult,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"tool_execution_end\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.result,\n\t\t\t\t\tisError: event.isError,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"compaction_start\":\n\t\tcase \"compaction_end\":\n\t\t\treturn [{ type: \"compaction\" }];\n\t\tdefault:\n\t\t\treturn [];\n\t}\n}\n\nfunction serializeAssistantMessageEvent(event: Record<string, unknown>): Record<string, unknown>[] {\n\tconst type = event.type as string;\n\tswitch (type) {\n\t\tcase \"start\":\n\t\t\treturn [{ type: \"agent_start\" }];\n\t\tcase \"text_start\":\n\t\t\treturn [{ type: \"text_start\", contentIndex: event.contentIndex }];\n\t\tcase \"text_delta\":\n\t\t\treturn [{ type: \"text_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"text_end\":\n\t\t\treturn [{ type: \"text_end\", content: event.content, contentIndex: event.contentIndex }];\n\t\tcase \"thinking_start\":\n\t\t\treturn [{ type: \"thinking_start\", contentIndex: event.contentIndex }];\n\t\tcase \"thinking_delta\":\n\t\t\treturn [{ type: \"thinking_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"thinking_end\":\n\t\t\treturn [{ type: \"thinking_end\", content: event.content, contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_start\":\n\t\t\treturn [{ type: \"toolcall_start\", contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_delta\":\n\t\t\treturn [{ type: \"toolcall_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_end\":\n\t\t\treturn [{ type: \"toolcall_end\", toolCall: event.toolCall, contentIndex: event.contentIndex }];\n\t\tcase \"done\":\n\t\t\treturn [{ type: \"done\", reason: event.reason }];\n\t\tcase \"error\":\n\t\t\treturn [{ type: \"error\", reason: event.reason }];\n\t\tdefault:\n\t\t\treturn [];\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web-mode.d.ts","sourceRoot":"","sources":["../../../src/modes/web/web-mode.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAyO/E,wBAAsB,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgJ5E","sourcesContent":["import { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { networkInterfaces } from \"node:os\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.ts\";\nimport type { AgentSessionRuntime } from \"../../core/agent-session-runtime.ts\";\n\nconst PASSWORD = process.env.PI_WEB_PASSWORD;\n\nfunction checkAuth(req: IncomingMessage, res: ServerResponse): boolean {\n\tif (!PASSWORD) return true;\n\n\tconst auth = req.headers.authorization;\n\tif (auth) {\n\t\tconst [scheme, credentials] = auth.split(\" \");\n\t\tif (scheme === \"Basic\" && credentials) {\n\t\t\tconst decoded = Buffer.from(credentials, \"base64\").toString(\"utf-8\");\n\t\t\tconst [, password] = decoded.split(\":\");\n\t\t\tif (password === PASSWORD) return true;\n\t\t}\n\t}\n\n\tres.writeHead(401, {\n\t\t\"www-authenticate\": 'Basic realm=\"pi\", charset=\"UTF-8\"',\n\t\t\"content-type\": \"text/plain\",\n\t});\n\tres.end(\"Unauthorized\");\n\treturn false;\n}\n\nfunction getLocalIP(): string {\n\tconst interfaces = networkInterfaces();\n\tfor (const iface of Object.values(interfaces)) {\n\t\tif (!iface) continue;\n\t\tfor (const addr of iface) {\n\t\t\tif (addr.family === \"IPv4\" && !addr.internal) {\n\t\t\t\treturn addr.address;\n\t\t\t}\n\t\t}\n\t}\n\treturn \"127.0.0.1\";\n}\n\nfunction getPort(): number {\n\tconst env = process.env.PORT;\n\tif (env) {\n\t\tconst p = parseInt(env, 10);\n\t\tif (!Number.isNaN(p) && p > 0 && p < 65536) return p;\n\t}\n\treturn 0;\n}\n\nconst HTML = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no\">\n<title>pi</title>\n<style>\n*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}\nhtml{font-size:15px}\nbody{font-family:\"IBM Plex Mono\",\"JetBrains Mono\",\"Fira Code\",\"SF Mono\",monospace;background:#1a1815;color:#d4b872;display:flex;flex-direction:column;height:100dvh;overflow:hidden}\n#topbar{display:flex;align-items:center;justify-content:space-between;padding:6px 16px;background:#141310;border-bottom:2px solid #3a3528;flex-shrink:0}\n#topbar h1{font-size:13px;font-weight:700;color:#e8cf8a;letter-spacing:1px}\n#topbar h1::before{content:\"[ \";color:#5c5240}#topbar h1::after{content:\" ]\";color:#5c5240}\n#topbar aside{font-size:10px;color:#5c5240}\n#msgs{flex:1;overflow-y:auto;padding:16px 20px;scroll-behavior:smooth;display:flex;flex-direction:column;gap:12px;background:linear-gradient(180deg,#1a1815 0%,#171512 100%)}\n#msgs::-webkit-scrollbar{width:5px}\n#msgs::-webkit-scrollbar-thumb{background:#3a3528;border-radius:0}\n.row{animation:fadeIn .12s ease}\n.row.user{display:flex;flex-direction:column;align-items:flex-end;max-width:82%;align-self:flex-end}\n.row.ast{display:flex;flex-direction:column;align-items:flex-start;max-width:88%;align-self:flex-start;width:100%}\n.row.sys{display:flex;justify-content:center;max-width:100%;align-self:center}\n@keyframes fadeIn{from{opacity:0;transform:translateY(3px)}to{opacity:1;transform:translateY(0)}}\n.rolename{font-size:10px;text-transform:uppercase;letter-spacing:1px;margin-bottom:2px;font-weight:700}\n.row.user .rolename{color:#9e8a5e}\n.row.ast .rolename{color:#5c5240}\n.bubble{border:1px solid #3a3528;padding:10px 14px;font-size:13px;line-height:1.65;overflow-wrap:break-word;word-break:break-word}\n.bubble.user{background:#2a251c;color:#e8cf8a;max-width:100%}\n.bubble.ast{background:#141310;color:#c4a860;max-width:100%}\n.bubble.sys{background:none;border:none;color:#5c5240;font-size:11px;text-align:center;padding:2px 0}\n.bubble code{background:#111;border:1px solid #3a3528;padding:1px 5px;color:#d4b872;font-size:12px}\n.bubble pre{background:#111;border:1px solid #3a3528;padding:10px 12px;overflow-x:auto;font-size:12px;line-height:1.5;color:#c4a860;margin:6px 0}\n.bubble pre code{background:none;border:none;padding:0;font-size:inherit;color:inherit}\n.bubble strong{color:#e8cf8a;font-weight:700}\n.bubble em{color:#c4a860;font-style:italic}\n.bubble h1,.bubble h2,.bubble h3{font-weight:700;color:#e8cf8a;margin:8px 0 3px}\n.bubble h1{font-size:15px;border-bottom:1px solid #3a3528;padding-bottom:3px}\n.bubble h2{font-size:14px}\n.bubble h3{font-size:13px;color:#c4a860}\n.bubble ul,.bubble ol{padding-left:22px;margin:4px 0}\n.bubble li{margin:2px 0}\n.bubble hr{border:none;border-top:1px solid #3a3528;margin:8px 0}\n.bubble blockquote{border-left:3px solid #3a3528;padding:4px 10px;color:#8e8048;margin:4px 0}\n.tool{border:1px solid #3a3528;margin:2px 0}\n.tool.running{border-color:#906820}\n.tool.error{border-color:#6b2020}\n.tool-bar{display:flex;align-items:center;padding:6px 10px;cursor:pointer;gap:8px;font-size:12px;user-select:none;background:#141310}\n.tool-bar:hover{background:#1a1815}\n.tool-dot{width:7px;height:7px;flex-shrink:0;background:#3a3528}\n.tool-dot.running{background:#c48c22;animation:blink 1s step-end infinite}\n.tool-dot.ok{background:#689040}\n.tool-dot.err{background:#b84040}\n@keyframes blink{50%{opacity:.2}}\n.tool-kind{font-weight:700;color:#c4a860}\n.tool-args{color:#5c5240;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n.tool-chev{color:#5c5240;font-size:10px;transition:.12s}\n.tool.open .tool-chev{transform:rotate(90deg)}\n.tool-content{display:none;padding:8px 12px;border-top:1px solid #3a3528;font-size:12px;line-height:1.55;white-space:pre-wrap;word-break:break-all;overflow-x:auto;max-height:32vh;overflow-y:auto;color:#8e8048;background:#111}\n.tool.open .tool-content{display:block}\n.tool-content::-webkit-scrollbar{width:4px;height:4px}\n.tool-content::-webkit-scrollbar-thumb{background:#3a3528}\n#input-area{border-top:2px solid #3a3528;background:#141310;padding:10px 16px;flex-shrink:0}\n#input-area form{display:flex;gap:8px;max-width:900px;margin:0 auto}\n#prompt{flex:1;background:#1a1815;border:1px solid #3a3528;padding:8px 12px;color:#d4b872;font-size:13px;font-family:inherit;outline:none;transition:border .15s}\n#prompt:focus{border-color:#c48c22;box-shadow:0 0 6px rgba(196,140,34,.15)}\n#prompt::placeholder{color:#3a3528}\nbutton{background:#3a3528;color:#c4a860;border:1px solid #5c5240;padding:8px 18px;font-size:12px;font-family:inherit;font-weight:700;cursor:pointer;transition:.1s;flex-shrink:0;text-transform:uppercase;letter-spacing:1px}\nbutton:hover{background:#5c5240;color:#e8cf8a;border-color:#8e8048}\nbutton:disabled{opacity:.3;cursor:not-allowed}\n.spin{display:none;width:14px;height:14px;border:2px solid #3a3528;border-top-color:#c48c22;border-radius:50%;animation:spinner .5s linear infinite}\n.spin.on{display:inline-block}\n@keyframes spinner{to{transform:rotate(360deg)}}\n@media(max-width:600px){\n#msgs{padding:10px;gap:8px}\n.row.user{max-width:94%}.row.ast{max-width:96%}\n#input-area{padding:8px 10px}\n}\n</style>\n</head>\n<body>\n<div id=\"topbar\"><h1>pi</h1><aside><span id=\"sid\"></span> <span id=\"stat-sessions\"></span> <span id=\"stat-cost\"></span></aside></div>\n<div id=\"msgs\"></div>\n<div id=\"input-area\">\n<form id=\"f\" autocomplete=\"off\">\n<input id=\"prompt\" type=\"text\" placeholder=\">_\" autofocus autocomplete=\"off\">\n<button id=\"send\">Send</button>\n<span class=\"spin\" id=\"spin\"></span>\n</form>\n</div>\n<script>\nconst msgs=document.getElementById(\"msgs\"),f=document.getElementById(\"f\"),prompt=document.getElementById(\"prompt\"),\nsend=document.getElementById(\"send\"),spinner=document.getElementById(\"spin\"),\nstatSessions=document.getElementById(\"stat-sessions\"),statCost=document.getElementById(\"stat-cost\"),\nsid=document.getElementById(\"sid\");\nlet busy=false,tools={},curAsst=null;\n\nfunction scroll(){msgs.scrollTop=msgs.scrollHeight}\nfunction esc(s){if(s==null)return\"\";return(\"\"+s).replace(/&/g,\"&\").replace(/</g,\"<\").replace(/>/g,\">\").replace(/\"/g,\""\")}\nfunction fmt(n){if(!n)return\"0\";if(n<1e3)return\"\"+n;if(n<1e4)return(n/1e3).toFixed(1)+\"k\";return Math.round(n/1e3)+\"k\"}\n\nfunction argText(args){if(!args)return\"\";const v=args.command||args.path||args.file_path;return v?\" \"+esc(v).slice(0,80):\"\"}\n\nfunction md(s){\nlet t=esc(s||\"\");\nconst blocks=[];\nt=t.replace(/\\`\\`\\`(\\\\w*)\\\\n([\\\\s\\\\S]*?)\\\\n\\`\\`\\`/g,(_,lang,code)=>{blocks.push('<pre><code>'+code+'</code></pre>');return'\\\\x00B'+(blocks.length-1)+'\\\\x00B'});\nt=t.replace(/\\`([^\\`]+)\\`/g,'<code>$1</code>');\nt=t.replace(/\\\\*\\\\*(.+?)\\\\*\\\\*/g,'<strong>$1</strong>');\nt=t.replace(/\\\\*(.+?)\\\\*/g,'<em>$1</em>');\nt=t.replace(/^### (.+)$/gm,'<h3>$1</h3>');\nt=t.replace(/^## (.+)$/gm,'<h2>$1</h2>');\nt=t.replace(/^# (.+)$/gm,'<h1>$1</h1>');\nt=t.replace(/^- (.+)$/gm,'<li>$1</li>');\nt=t.replace(/^> (.+)$/gm,'<blockquote>$1</blockquote>');\nt=t.replace(/((?:<li>.*<\\\\/li>\\\\n?)+)/g,'<ul>$1</ul>');\nt=t.replace(/^(---+|\\\\*\\\\*\\\\*+|___+)$/gm,'<hr>');\nt=t.replace(/\\\\x00B(\\\\d+)\\\\x00B/g,(_,i)=>blocks[parseInt(i)]);\nt=t.replace(/\\\\n\\\\n/g,'<br><br>');\nt=t.replace(/\\\\n/g,'<br>');\nreturn t\n}\n\nfunction row(role){const d=document.createElement(\"div\");d.className=\"row \"+role;msgs.appendChild(d);return d}\nfunction rol(role,lbl){const d=row(role);const n=document.createElement(\"div\");n.className=\"rolename\";n.textContent=lbl;d.appendChild(n);return d}\nfunction bubble(parent,html){const b=document.createElement(\"div\");b.className=\"bubble \"+parent.classList[1];if(html!==undefined)b.innerHTML=html;parent.appendChild(b);return b}\n\nfunction addUser(txt){const r=rol(\"user\",\"YOU\");bubble(r,esc(txt));scroll()}\nfunction addAst(){const r=rol(\"ast\",\"PI\");const b=bubble(r);scroll();curAsst={row:r,bubble:b};return b}\nfunction addSys(txt){const r=row(\"sys\");bubble(r,txt);scroll()}\nfunction getAsstB(){if(!curAsst)return addAst();return curAsst.bubble}\n\nfunction renderTool(e){\nconst r=row(\"ast\");const w=document.createElement(\"div\");w.className=\"tool-wrapper\";\nw.innerHTML='<div class=\"tool running\" id=\"t'+e.toolCallId+'\"><div class=\"tool-bar\"><span class=\"tool-dot running\"></span><span class=\"tool-kind\">'+esc(e.toolName)+'</span><span class=\"tool-args\">'+argText(e.args)+'</span><span class=\"tool-chev\">▶</span></div><div class=\"tool-content\"></div></div>';\nw.querySelector(\".tool-bar\").onclick=()=>w.querySelector(\".tool\").classList.toggle(\"open\");\nr.appendChild(w);msgs.appendChild(r);tools[e.toolCallId]={el:w.querySelector(\".tool\"),row:r};scroll()}\n\nfunction updateTool(id,result,isError){\nconst t=tools[id];if(!t)return;\nconst ct=t.el.querySelector(\".tool-content\");\nconst texts=result&&result.content?result.content.filter(c=>c&&c.type===\"text\").map(c=>c.text):[];\nif(texts.length){ct.textContent=texts.join(\"\\\\n\");t.el.classList.add(\"open\")}\nif(isError){t.el.querySelector(\".tool-dot\").className=\"tool-dot err\";t.el.classList.add(\"error\");t.el.classList.remove(\"running\")}\n}\n\nfunction doneTool(id,isError){\nconst t=tools[id];if(!t)return;\nt.el.querySelector(\".tool-dot\").className=\"tool-dot \"+(isError?\"err\":\"ok\");\nt.el.classList.remove(\"running\");\nif(isError){t.el.classList.add(\"error\")}\nif(isError&&!t.el.querySelector(\".tool-content\").textContent.trim())t.el.querySelector(\".tool-content\").textContent=\"(no output)\"\n}\n\nfunction handle(d){\nswitch(d.type){\ncase\"agent_start\":curAsst=null;break;\ncase\"text_delta\":{const b=getAsstB();b.innerHTML+=md(d.delta);scroll();break}\ncase\"thinking_delta\":{let th=document.getElementById(\"th\"+d.contentIndex);if(!th){th=document.createElement(\"div\");th.className=\"row ast\";const b=document.createElement(\"div\");b.style.cssText=\"font-size:11px;color:#5c5240;font-style:italic;padding:4px 10px;border-left:2px solid #3a3528\";b.id=\"th\"+d.contentIndex;th.appendChild(b);msgs.appendChild(th)}th.firstChild.textContent+=d.delta;scroll();break}\ncase\"tool_execution_start\":renderTool(d);break;\ncase\"tool_execution_update\":updateTool(d.toolCallId,d.result,false);break;\ncase\"tool_execution_end\":doneTool(d.toolCallId,d.isError);if(d.result)updateTool(d.toolCallId,d.result,d.isError);break;\ncase\"agent_end\":{let s=\"DONE\";if(d.usage){s+=\" \"+fmt(d.usage.input)+\" IN / \"+fmt(d.usage.output)+\" OUT\";if(d.usage.cost)s+=\" $\"+d.usage.cost.total.toFixed(4)}addSys(s);break}\ncase\"compaction\":addSys(\"--- COMPACTING ---\");break;\ncase\"error\":addSys(\"ERR: \"+esc(d.message||\"\"));break;\ndefault:break}}\n\nf.onsubmit=async e=>{e.preventDefault();if(busy)return;const text=prompt.value.trim();if(!text)return;prompt.value=\"\";addUser(text);busy=true;send.disabled=true;spinner.className=\"spin on\";\ntry{const r=await fetch(\"/api/prompt\",{method:\"POST\",headers:{\"content-type\":\"application/json\"},body:JSON.stringify({text})});\nif(!r.ok){addSys(\"HTTP \"+r.status);return}\nconst reader=r.body.getReader(),decoder=new TextDecoder();let buf=\"\";\nwhile(true){const{done,value}=await reader.read();if(done)break;buf+=decoder.decode(value,{stream:true});const lines=buf.split(\"\\\\n\");buf=lines.pop()||\"\";\nfor(const line of lines){if(!line.trim())continue;try{handle(JSON.parse(line))}catch{}}}}\ncatch(err){addSys(\"ERR: \"+esc(err.message||\"\"))}finally{busy=false;send.disabled=false;spinner.className=\"spin\"}};\n\nfetch(\"/api/messages\").then(r=>r.json()).then(events=>{for(const e of events){if(e.type===\"user\")addUser(e.text);else handle(e)}}).catch(()=>{});\n\nfetch(\"/api/stats\").then(r=>r.json()).then(s=>{statSessions.textContent=s.sessions+\" sessions\";statCost.textContent=s.cost.toFixed(2)}).catch(()=>{});\n\nfetch(\"/api/session-info\").then(r=>r.json()).then(s=>{sid.textContent=s.id?s.id.slice(0,8)+(s.name?\" \"+s.name:\"\"):\"\"}).catch(()=>{});\n</script>\n</body>\n</html>`;\n\nfunction sendEvent(res: ServerResponse, data: Record<string, unknown>): void {\n\tres.write(`${JSON.stringify(data)}\\n`);\n}\n\nexport async function runWebMode(runtime: AgentSessionRuntime): Promise<void> {\n\tconst session = runtime.session;\n\tconst port = getPort();\n\n\tconst server = createServer(async (req: IncomingMessage, res: ServerResponse) => {\n\t\tif (!checkAuth(req, res)) return;\n\n\t\tconst url = req.url ?? \"/\";\n\n\t\tif (req.method === \"POST\" && url === \"/api/prompt\") {\n\t\t\tconst chunks: Buffer[] = [];\n\t\t\treq.on(\"data\", (chunk: Buffer) => chunks.push(chunk));\n\t\t\tawait new Promise<void>((resolve) => req.on(\"end\", resolve));\n\t\t\tconst body = JSON.parse(Buffer.concat(chunks).toString());\n\t\t\tconst text = String(body.text ?? \"\").trim();\n\t\t\tif (!text) {\n\t\t\t\tres.writeHead(400);\n\t\t\t\tres.end(JSON.stringify({ error: \"missing text\" }));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tres.writeHead(200, { \"content-type\": \"text/plain; charset=utf-8\", \"cache-control\": \"no-cache\" });\n\n\t\t\tconst unsubscribe = session.subscribe((event: AgentSessionEvent) => {\n\t\t\t\tconst events = toSerializableEvents(event);\n\t\t\t\tfor (const evt of events) {\n\t\t\t\t\tsendEvent(res, evt);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tawait session.prompt(text);\n\t\t\t} catch (err) {\n\t\t\t\tsendEvent(res, { type: \"error\", message: String(err) });\n\t\t\t} finally {\n\t\t\t\tunsubscribe();\n\t\t\t\tres.end();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/stats\") {\n\t\t\tconst stats = await session.getUsageStats();\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(\n\t\t\t\tJSON.stringify({ sessions: stats.sessions, cost: stats.cost, input: stats.input, output: stats.output }),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/session-info\") {\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tid: session.sessionId,\n\t\t\t\t\tname: session.sessionManager.getSessionName(),\n\t\t\t\t\tfile: session.sessionFile,\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/messages\") {\n\t\t\tconst entries = session.sessionManager.getEntries();\n\t\t\tconst events: Record<string, unknown>[] = [];\n\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (entry.type !== \"message\") continue;\n\t\t\t\tconst msg = (entry as { message: { role: string; content: unknown; usage?: unknown } }).message;\n\t\t\t\tif (!msg) continue;\n\n\t\t\t\tif (msg.role === \"user\") {\n\t\t\t\t\tconst content = typeof msg.content === \"string\" ? msg.content : \"\";\n\t\t\t\t\tevents.push({ type: \"user\", text: content });\n\t\t\t\t} else if (msg.role === \"assistant\") {\n\t\t\t\t\tconst content = Array.isArray(msg.content) ? msg.content : [];\n\t\t\t\t\tfor (const block of content as Array<{ type: string; text?: string; toolCall?: unknown }>) {\n\t\t\t\t\t\tif (block.type === \"text\" && block.text) {\n\t\t\t\t\t\t\tevents.push({ type: \"text_delta\", delta: block.text });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (block.type === \"toolCall\" && block.toolCall) {\n\t\t\t\t\t\t\tconst tc = block.toolCall as { toolCallId?: string; toolName?: string; input?: unknown };\n\t\t\t\t\t\t\tevents.push({\n\t\t\t\t\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\t\t\t\t\ttoolCallId: tc.toolCallId,\n\t\t\t\t\t\t\t\ttoolName: tc.toolName,\n\t\t\t\t\t\t\t\targs: tc.input,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (msg.role === \"toolResult\") {\n\t\t\t\t\tconst content = (msg as { toolCallId?: string; content?: Array<{ type: string; text?: string }> })\n\t\t\t\t\t\t.content;\n\t\t\t\t\tevents.push({\n\t\t\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\t\t\ttoolCallId: (msg as { toolCallId?: string }).toolCallId,\n\t\t\t\t\t\tresult: { content: content ?? [] },\n\t\t\t\t\t\tisError: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst usage = getSessionTokenCount(session);\n\t\t\tevents.push({ type: \"agent_end\", usage });\n\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(JSON.stringify(events));\n\t\t\treturn;\n\t\t}\n\n\t\tres.writeHead(200, { \"content-type\": \"text/html; charset=utf-8\" });\n\t\tres.end(HTML);\n\t});\n\n\tawait new Promise<void>((resolve, reject) => {\n\t\tserver.listen(port, \"0.0.0.0\", () => resolve());\n\t\tserver.on(\"error\", reject);\n\t});\n\n\tconst addr = server.address();\n\tif (!addr || typeof addr === \"string\") {\n\t\tconsole.error(\"Failed to start web server\");\n\t\treturn;\n\t}\n\n\tconst consolePort = `http://127.0.0.1:${addr.port}`;\n\tconst lan = getLocalIP();\n\tconsole.log(`\\n pi web UI: ${consolePort}`);\n\tif (lan !== \"127.0.0.1\") {\n\t\tconsole.log(` LAN: http://${lan}:${addr.port}`);\n\t}\n\tconsole.log(` session: ${session.sessionId.slice(0, 8)}`);\n\tconsole.log(\" (listening on all interfaces)\");\n\tif (PASSWORD) {\n\t\tconsole.log(` auth: Basic (user \"pi\", password from PI_WEB_PASSWORD)`);\n\t} else {\n\t\tconsole.log(\" auth: none (set PI_WEB_PASSWORD to enable)\");\n\t}\n\tconsole.log();\n\n\t// Keep process alive\n\tawait new Promise(() => {});\n\n\tserver.close();\n}\n\nfunction getSessionTokenCount(session: AgentSessionRuntime[\"session\"]): Record<string, unknown> | undefined {\n\tconst entries = session.sessionManager.getEntries();\n\tlet input = 0;\n\tlet output = 0;\n\tlet costTotal = 0;\n\tlet hasUsage = false;\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tconst msg = (\n\t\t\tentry as { message: { role: string; usage?: { input: number; output: number; cost: { total: number } } } }\n\t\t).message;\n\t\tif (msg?.role === \"assistant\" && msg.usage) {\n\t\t\tinput += msg.usage.input;\n\t\t\toutput += msg.usage.output;\n\t\t\tcostTotal += msg.usage.cost.total;\n\t\t\thasUsage = true;\n\t\t}\n\t}\n\treturn hasUsage ? { input, output, cost: { total: costTotal } } : undefined;\n}\n\nfunction toSerializableEvents(event: AgentSessionEvent): Record<string, unknown>[] {\n\tswitch (event.type) {\n\t\tcase \"agent_start\":\n\t\t\treturn [{ type: \"agent_start\" }];\n\t\tcase \"agent_end\": {\n\t\t\tconst lastAssistant = event.messages.filter((m) => m.role === \"assistant\").at(-1);\n\t\t\tconst usage = lastAssistant && \"usage\" in lastAssistant ? lastAssistant.usage : undefined;\n\t\t\treturn [{ type: \"agent_end\", usage }];\n\t\t}\n\t\tcase \"message_update\": {\n\t\t\tconst ame: Record<string, unknown> = event.assistantMessageEvent;\n\t\t\tconst serialized = serializeAssistantMessageEvent(ame);\n\t\t\treturn serialized;\n\t\t}\n\t\tcase \"tool_execution_start\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"tool_execution_update\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_update\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.partialResult,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"tool_execution_end\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.result,\n\t\t\t\t\tisError: event.isError,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"compaction_start\":\n\t\tcase \"compaction_end\":\n\t\t\treturn [{ type: \"compaction\" }];\n\t\tdefault:\n\t\t\treturn [];\n\t}\n}\n\nfunction serializeAssistantMessageEvent(event: Record<string, unknown>): Record<string, unknown>[] {\n\tconst type = event.type as string;\n\tswitch (type) {\n\t\tcase \"start\":\n\t\t\treturn [{ type: \"agent_start\" }];\n\t\tcase \"text_start\":\n\t\t\treturn [{ type: \"text_start\", contentIndex: event.contentIndex }];\n\t\tcase \"text_delta\":\n\t\t\treturn [{ type: \"text_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"text_end\":\n\t\t\treturn [{ type: \"text_end\", content: event.content, contentIndex: event.contentIndex }];\n\t\tcase \"thinking_start\":\n\t\t\treturn [{ type: \"thinking_start\", contentIndex: event.contentIndex }];\n\t\tcase \"thinking_delta\":\n\t\t\treturn [{ type: \"thinking_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"thinking_end\":\n\t\t\treturn [{ type: \"thinking_end\", content: event.content, contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_start\":\n\t\t\treturn [{ type: \"toolcall_start\", contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_delta\":\n\t\t\treturn [{ type: \"toolcall_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_end\":\n\t\t\treturn [{ type: \"toolcall_end\", toolCall: event.toolCall, contentIndex: event.contentIndex }];\n\t\tcase \"done\":\n\t\t\treturn [{ type: \"done\", reason: event.reason }];\n\t\tcase \"error\":\n\t\t\treturn [{ type: \"error\", reason: event.reason }];\n\t\tdefault:\n\t\t\treturn [];\n\t}\n}\n"]}
|
|
@@ -51,191 +51,176 @@ const HTML = `<!DOCTYPE html>
|
|
|
51
51
|
<title>pi</title>
|
|
52
52
|
<style>
|
|
53
53
|
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
54
|
-
html{font-size:
|
|
55
|
-
body{font-family
|
|
56
|
-
#
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#msgs{
|
|
62
|
-
#msgs::-webkit-scrollbar{
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
.
|
|
66
|
-
.
|
|
67
|
-
@keyframes fadeIn{from{opacity:0;transform:translateY(
|
|
68
|
-
.
|
|
69
|
-
.
|
|
70
|
-
.
|
|
71
|
-
.
|
|
72
|
-
.
|
|
73
|
-
.
|
|
74
|
-
.
|
|
75
|
-
.
|
|
76
|
-
.
|
|
77
|
-
.
|
|
78
|
-
.
|
|
79
|
-
.
|
|
80
|
-
.
|
|
81
|
-
.
|
|
82
|
-
.
|
|
83
|
-
.
|
|
84
|
-
.
|
|
85
|
-
.
|
|
86
|
-
.
|
|
87
|
-
.
|
|
88
|
-
.
|
|
89
|
-
.tool{border
|
|
90
|
-
.tool
|
|
91
|
-
.tool-
|
|
92
|
-
.tool-
|
|
93
|
-
.tool-
|
|
94
|
-
.tool-
|
|
95
|
-
.tool-
|
|
96
|
-
.tool-
|
|
97
|
-
@keyframes
|
|
98
|
-
.tool-
|
|
99
|
-
.tool-
|
|
100
|
-
.tool
|
|
101
|
-
.tool
|
|
102
|
-
.tool-
|
|
103
|
-
.tool-
|
|
104
|
-
.tool
|
|
105
|
-
.tool
|
|
106
|
-
|
|
107
|
-
#input-area{background:#0d121a;border-top:1px solid #21262d;padding:12px 16px;flex-shrink:0}
|
|
54
|
+
html{font-size:15px}
|
|
55
|
+
body{font-family:"IBM Plex Mono","JetBrains Mono","Fira Code","SF Mono",monospace;background:#1a1815;color:#d4b872;display:flex;flex-direction:column;height:100dvh;overflow:hidden}
|
|
56
|
+
#topbar{display:flex;align-items:center;justify-content:space-between;padding:6px 16px;background:#141310;border-bottom:2px solid #3a3528;flex-shrink:0}
|
|
57
|
+
#topbar h1{font-size:13px;font-weight:700;color:#e8cf8a;letter-spacing:1px}
|
|
58
|
+
#topbar h1::before{content:"[ ";color:#5c5240}#topbar h1::after{content:" ]";color:#5c5240}
|
|
59
|
+
#topbar aside{font-size:10px;color:#5c5240}
|
|
60
|
+
#msgs{flex:1;overflow-y:auto;padding:16px 20px;scroll-behavior:smooth;display:flex;flex-direction:column;gap:12px;background:linear-gradient(180deg,#1a1815 0%,#171512 100%)}
|
|
61
|
+
#msgs::-webkit-scrollbar{width:5px}
|
|
62
|
+
#msgs::-webkit-scrollbar-thumb{background:#3a3528;border-radius:0}
|
|
63
|
+
.row{animation:fadeIn .12s ease}
|
|
64
|
+
.row.user{display:flex;flex-direction:column;align-items:flex-end;max-width:82%;align-self:flex-end}
|
|
65
|
+
.row.ast{display:flex;flex-direction:column;align-items:flex-start;max-width:88%;align-self:flex-start;width:100%}
|
|
66
|
+
.row.sys{display:flex;justify-content:center;max-width:100%;align-self:center}
|
|
67
|
+
@keyframes fadeIn{from{opacity:0;transform:translateY(3px)}to{opacity:1;transform:translateY(0)}}
|
|
68
|
+
.rolename{font-size:10px;text-transform:uppercase;letter-spacing:1px;margin-bottom:2px;font-weight:700}
|
|
69
|
+
.row.user .rolename{color:#9e8a5e}
|
|
70
|
+
.row.ast .rolename{color:#5c5240}
|
|
71
|
+
.bubble{border:1px solid #3a3528;padding:10px 14px;font-size:13px;line-height:1.65;overflow-wrap:break-word;word-break:break-word}
|
|
72
|
+
.bubble.user{background:#2a251c;color:#e8cf8a;max-width:100%}
|
|
73
|
+
.bubble.ast{background:#141310;color:#c4a860;max-width:100%}
|
|
74
|
+
.bubble.sys{background:none;border:none;color:#5c5240;font-size:11px;text-align:center;padding:2px 0}
|
|
75
|
+
.bubble code{background:#111;border:1px solid #3a3528;padding:1px 5px;color:#d4b872;font-size:12px}
|
|
76
|
+
.bubble pre{background:#111;border:1px solid #3a3528;padding:10px 12px;overflow-x:auto;font-size:12px;line-height:1.5;color:#c4a860;margin:6px 0}
|
|
77
|
+
.bubble pre code{background:none;border:none;padding:0;font-size:inherit;color:inherit}
|
|
78
|
+
.bubble strong{color:#e8cf8a;font-weight:700}
|
|
79
|
+
.bubble em{color:#c4a860;font-style:italic}
|
|
80
|
+
.bubble h1,.bubble h2,.bubble h3{font-weight:700;color:#e8cf8a;margin:8px 0 3px}
|
|
81
|
+
.bubble h1{font-size:15px;border-bottom:1px solid #3a3528;padding-bottom:3px}
|
|
82
|
+
.bubble h2{font-size:14px}
|
|
83
|
+
.bubble h3{font-size:13px;color:#c4a860}
|
|
84
|
+
.bubble ul,.bubble ol{padding-left:22px;margin:4px 0}
|
|
85
|
+
.bubble li{margin:2px 0}
|
|
86
|
+
.bubble hr{border:none;border-top:1px solid #3a3528;margin:8px 0}
|
|
87
|
+
.bubble blockquote{border-left:3px solid #3a3528;padding:4px 10px;color:#8e8048;margin:4px 0}
|
|
88
|
+
.tool{border:1px solid #3a3528;margin:2px 0}
|
|
89
|
+
.tool.running{border-color:#906820}
|
|
90
|
+
.tool.error{border-color:#6b2020}
|
|
91
|
+
.tool-bar{display:flex;align-items:center;padding:6px 10px;cursor:pointer;gap:8px;font-size:12px;user-select:none;background:#141310}
|
|
92
|
+
.tool-bar:hover{background:#1a1815}
|
|
93
|
+
.tool-dot{width:7px;height:7px;flex-shrink:0;background:#3a3528}
|
|
94
|
+
.tool-dot.running{background:#c48c22;animation:blink 1s step-end infinite}
|
|
95
|
+
.tool-dot.ok{background:#689040}
|
|
96
|
+
.tool-dot.err{background:#b84040}
|
|
97
|
+
@keyframes blink{50%{opacity:.2}}
|
|
98
|
+
.tool-kind{font-weight:700;color:#c4a860}
|
|
99
|
+
.tool-args{color:#5c5240;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
100
|
+
.tool-chev{color:#5c5240;font-size:10px;transition:.12s}
|
|
101
|
+
.tool.open .tool-chev{transform:rotate(90deg)}
|
|
102
|
+
.tool-content{display:none;padding:8px 12px;border-top:1px solid #3a3528;font-size:12px;line-height:1.55;white-space:pre-wrap;word-break:break-all;overflow-x:auto;max-height:32vh;overflow-y:auto;color:#8e8048;background:#111}
|
|
103
|
+
.tool.open .tool-content{display:block}
|
|
104
|
+
.tool-content::-webkit-scrollbar{width:4px;height:4px}
|
|
105
|
+
.tool-content::-webkit-scrollbar-thumb{background:#3a3528}
|
|
106
|
+
#input-area{border-top:2px solid #3a3528;background:#141310;padding:10px 16px;flex-shrink:0}
|
|
108
107
|
#input-area form{display:flex;gap:8px;max-width:900px;margin:0 auto}
|
|
109
|
-
#prompt{flex:1;background:#
|
|
110
|
-
#prompt:focus{border-color:#
|
|
111
|
-
#prompt::placeholder{color:#
|
|
112
|
-
button{background:#
|
|
113
|
-
button:hover{background:#
|
|
114
|
-
button:disabled{
|
|
115
|
-
.
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
.spinner.active{display:inline-block}
|
|
119
|
-
@keyframes spin{to{transform:rotate(360deg)}}
|
|
108
|
+
#prompt{flex:1;background:#1a1815;border:1px solid #3a3528;padding:8px 12px;color:#d4b872;font-size:13px;font-family:inherit;outline:none;transition:border .15s}
|
|
109
|
+
#prompt:focus{border-color:#c48c22;box-shadow:0 0 6px rgba(196,140,34,.15)}
|
|
110
|
+
#prompt::placeholder{color:#3a3528}
|
|
111
|
+
button{background:#3a3528;color:#c4a860;border:1px solid #5c5240;padding:8px 18px;font-size:12px;font-family:inherit;font-weight:700;cursor:pointer;transition:.1s;flex-shrink:0;text-transform:uppercase;letter-spacing:1px}
|
|
112
|
+
button:hover{background:#5c5240;color:#e8cf8a;border-color:#8e8048}
|
|
113
|
+
button:disabled{opacity:.3;cursor:not-allowed}
|
|
114
|
+
.spin{display:none;width:14px;height:14px;border:2px solid #3a3528;border-top-color:#c48c22;border-radius:50%;animation:spinner .5s linear infinite}
|
|
115
|
+
.spin.on{display:inline-block}
|
|
116
|
+
@keyframes spinner{to{transform:rotate(360deg)}}
|
|
120
117
|
@media(max-width:600px){
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
.msg-group{max-width:94%}
|
|
124
|
-
.msg-group.user{max-width:92%}
|
|
118
|
+
#msgs{padding:10px;gap:8px}
|
|
119
|
+
.row.user{max-width:94%}.row.ast{max-width:96%}
|
|
125
120
|
#input-area{padding:8px 10px}
|
|
126
|
-
#prompt{padding:7px 10px}
|
|
127
|
-
button{padding:7px 12px}
|
|
128
121
|
}
|
|
129
122
|
</style>
|
|
130
123
|
</head>
|
|
131
124
|
<body>
|
|
132
|
-
<div id="
|
|
133
|
-
<div id="header-left"><h1>pi</h1><span id="session-info"></span></div>
|
|
134
|
-
<div id="header-stats"><span id="stat-sessions"></span><span id="stat-cost"></span></div>
|
|
135
|
-
</div>
|
|
125
|
+
<div id="topbar"><h1>pi</h1><aside><span id="sid"></span> <span id="stat-sessions"></span> <span id="stat-cost"></span></aside></div>
|
|
136
126
|
<div id="msgs"></div>
|
|
137
127
|
<div id="input-area">
|
|
138
128
|
<form id="f" autocomplete="off">
|
|
139
|
-
<input id="prompt" type="text" placeholder="
|
|
129
|
+
<input id="prompt" type="text" placeholder=">_" autofocus autocomplete="off">
|
|
140
130
|
<button id="send">Send</button>
|
|
141
|
-
<span class="
|
|
131
|
+
<span class="spin" id="spin"></span>
|
|
142
132
|
</form>
|
|
143
133
|
</div>
|
|
144
134
|
<script>
|
|
145
135
|
const msgs=document.getElementById("msgs"),f=document.getElementById("f"),prompt=document.getElementById("prompt"),
|
|
146
|
-
send=document.getElementById("send"),spinner=document.getElementById("
|
|
136
|
+
send=document.getElementById("send"),spinner=document.getElementById("spin"),
|
|
147
137
|
statSessions=document.getElementById("stat-sessions"),statCost=document.getElementById("stat-cost"),
|
|
148
|
-
|
|
149
|
-
let busy=false,
|
|
138
|
+
sid=document.getElementById("sid");
|
|
139
|
+
let busy=false,tools={},curAsst=null;
|
|
140
|
+
|
|
141
|
+
function scroll(){msgs.scrollTop=msgs.scrollHeight}
|
|
142
|
+
function esc(s){if(s==null)return"";return(""+s).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}
|
|
143
|
+
function fmt(n){if(!n)return"0";if(n<1e3)return""+n;if(n<1e4)return(n/1e3).toFixed(1)+"k";return Math.round(n/1e3)+"k"}
|
|
150
144
|
|
|
151
|
-
function
|
|
152
|
-
function esc(s){if(!s)return"";return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}
|
|
153
|
-
function fmt(n){if(n<1e3)return n;if(n<1e4)return(n/1e3).toFixed(1)+"k";return Math.round(n/1e3)+"k"}
|
|
145
|
+
function argText(args){if(!args)return"";const v=args.command||args.path||args.file_path;return v?" "+esc(v).slice(0,80):""}
|
|
154
146
|
|
|
155
|
-
function md(
|
|
156
|
-
let
|
|
147
|
+
function md(s){
|
|
148
|
+
let t=esc(s||"");
|
|
157
149
|
const blocks=[];
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return
|
|
150
|
+
t=t.replace(/\`\`\`(\\w*)\\n([\\s\\S]*?)\\n\`\`\`/g,(_,lang,code)=>{blocks.push('<pre><code>'+code+'</code></pre>');return'\\x00B'+(blocks.length-1)+'\\x00B'});
|
|
151
|
+
t=t.replace(/\`([^\`]+)\`/g,'<code>$1</code>');
|
|
152
|
+
t=t.replace(/\\*\\*(.+?)\\*\\*/g,'<strong>$1</strong>');
|
|
153
|
+
t=t.replace(/\\*(.+?)\\*/g,'<em>$1</em>');
|
|
154
|
+
t=t.replace(/^### (.+)$/gm,'<h3>$1</h3>');
|
|
155
|
+
t=t.replace(/^## (.+)$/gm,'<h2>$1</h2>');
|
|
156
|
+
t=t.replace(/^# (.+)$/gm,'<h1>$1</h1>');
|
|
157
|
+
t=t.replace(/^- (.+)$/gm,'<li>$1</li>');
|
|
158
|
+
t=t.replace(/^> (.+)$/gm,'<blockquote>$1</blockquote>');
|
|
159
|
+
t=t.replace(/((?:<li>.*<\\/li>\\n?)+)/g,'<ul>$1</ul>');
|
|
160
|
+
t=t.replace(/^(---+|\\*\\*\\*+|___+)$/gm,'<hr>');
|
|
161
|
+
t=t.replace(/\\x00B(\\d+)\\x00B/g,(_,i)=>blocks[parseInt(i)]);
|
|
162
|
+
t=t.replace(/\\n\\n/g,'<br><br>');
|
|
163
|
+
t=t.replace(/\\n/g,'<br>');
|
|
164
|
+
return t
|
|
173
165
|
}
|
|
174
166
|
|
|
175
|
-
function
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
else if(role==="assistant"){g.innerHTML='<div class="msg-label">pi</div><div class="msg assistant"></div>'}
|
|
179
|
-
else{g.innerHTML='<div class="msg system">'+text+'</div>'}
|
|
180
|
-
msgs.appendChild(g);scrollDown();return g}
|
|
167
|
+
function row(role){const d=document.createElement("div");d.className="row "+role;msgs.appendChild(d);return d}
|
|
168
|
+
function rol(role,lbl){const d=row(role);const n=document.createElement("div");n.className="rolename";n.textContent=lbl;d.appendChild(n);return d}
|
|
169
|
+
function bubble(parent,html){const b=document.createElement("div");b.className="bubble "+parent.classList[1];if(html!==undefined)b.innerHTML=html;parent.appendChild(b);return b}
|
|
181
170
|
|
|
182
|
-
function
|
|
171
|
+
function addUser(txt){const r=rol("user","YOU");bubble(r,esc(txt));scroll()}
|
|
172
|
+
function addAst(){const r=rol("ast","PI");const b=bubble(r);scroll();curAsst={row:r,bubble:b};return b}
|
|
173
|
+
function addSys(txt){const r=row("sys");bubble(r,txt);scroll()}
|
|
174
|
+
function getAsstB(){if(!curAsst)return addAst();return curAsst.bubble}
|
|
183
175
|
|
|
184
|
-
function
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
msgs.appendChild(el);toolEls[e.toolCallId]=el;scrollDown()}
|
|
176
|
+
function renderTool(e){
|
|
177
|
+
const r=row("ast");const w=document.createElement("div");w.className="tool-wrapper";
|
|
178
|
+
w.innerHTML='<div class="tool running" id="t'+e.toolCallId+'"><div class="tool-bar"><span class="tool-dot running"></span><span class="tool-kind">'+esc(e.toolName)+'</span><span class="tool-args">'+argText(e.args)+'</span><span class="tool-chev">▶</span></div><div class="tool-content"></div></div>';
|
|
179
|
+
w.querySelector(".tool-bar").onclick=()=>w.querySelector(".tool").classList.toggle("open");
|
|
180
|
+
r.appendChild(w);msgs.appendChild(r);tools[e.toolCallId]={el:w.querySelector(".tool"),row:r};scroll()}
|
|
190
181
|
|
|
191
182
|
function updateTool(id,result,isError){
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
if(isError){icon.className="tool-icon error"}
|
|
183
|
+
const t=tools[id];if(!t)return;
|
|
184
|
+
const ct=t.el.querySelector(".tool-content");
|
|
195
185
|
const texts=result&&result.content?result.content.filter(c=>c&&c.type==="text").map(c=>c.text):[];
|
|
196
|
-
if(texts.length){
|
|
186
|
+
if(texts.length){ct.textContent=texts.join("\\n");t.el.classList.add("open")}
|
|
187
|
+
if(isError){t.el.querySelector(".tool-dot").className="tool-dot err";t.el.classList.add("error");t.el.classList.remove("running")}
|
|
188
|
+
}
|
|
197
189
|
|
|
198
|
-
function
|
|
199
|
-
const
|
|
200
|
-
|
|
201
|
-
|
|
190
|
+
function doneTool(id,isError){
|
|
191
|
+
const t=tools[id];if(!t)return;
|
|
192
|
+
t.el.querySelector(".tool-dot").className="tool-dot "+(isError?"err":"ok");
|
|
193
|
+
t.el.classList.remove("running");
|
|
194
|
+
if(isError){t.el.classList.add("error")}
|
|
195
|
+
if(isError&&!t.el.querySelector(".tool-content").textContent.trim())t.el.querySelector(".tool-content").textContent="(no output)"
|
|
196
|
+
}
|
|
202
197
|
|
|
203
198
|
function handle(d){
|
|
204
199
|
switch(d.type){
|
|
205
|
-
case"agent_start":
|
|
206
|
-
case"text_delta":{const
|
|
207
|
-
case"thinking_delta":{let th=document.getElementById("
|
|
208
|
-
case"tool_execution_start":
|
|
200
|
+
case"agent_start":curAsst=null;break;
|
|
201
|
+
case"text_delta":{const b=getAsstB();b.innerHTML+=md(d.delta);scroll();break}
|
|
202
|
+
case"thinking_delta":{let th=document.getElementById("th"+d.contentIndex);if(!th){th=document.createElement("div");th.className="row ast";const b=document.createElement("div");b.style.cssText="font-size:11px;color:#5c5240;font-style:italic;padding:4px 10px;border-left:2px solid #3a3528";b.id="th"+d.contentIndex;th.appendChild(b);msgs.appendChild(th)}th.firstChild.textContent+=d.delta;scroll();break}
|
|
203
|
+
case"tool_execution_start":renderTool(d);break;
|
|
209
204
|
case"tool_execution_update":updateTool(d.toolCallId,d.result,false);break;
|
|
210
|
-
case"tool_execution_end":
|
|
211
|
-
case"agent_end":{let s="";if(d.usage){s
|
|
212
|
-
case"compaction":
|
|
213
|
-
case"error":
|
|
214
|
-
|
|
205
|
+
case"tool_execution_end":doneTool(d.toolCallId,d.isError);if(d.result)updateTool(d.toolCallId,d.result,d.isError);break;
|
|
206
|
+
case"agent_end":{let s="DONE";if(d.usage){s+=" "+fmt(d.usage.input)+" IN / "+fmt(d.usage.output)+" OUT";if(d.usage.cost)s+=" $"+d.usage.cost.total.toFixed(4)}addSys(s);break}
|
|
207
|
+
case"compaction":addSys("--- COMPACTING ---");break;
|
|
208
|
+
case"error":addSys("ERR: "+esc(d.message||""));break;
|
|
209
|
+
default:break}}
|
|
215
210
|
|
|
216
|
-
f.onsubmit=async e=>{e.preventDefault();if(busy)return;const text=prompt.value.trim();if(!text)return;prompt.value="";
|
|
211
|
+
f.onsubmit=async e=>{e.preventDefault();if(busy)return;const text=prompt.value.trim();if(!text)return;prompt.value="";addUser(text);busy=true;send.disabled=true;spinner.className="spin on";
|
|
217
212
|
try{const r=await fetch("/api/prompt",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({text})});
|
|
218
|
-
if(!r.ok){
|
|
213
|
+
if(!r.ok){addSys("HTTP "+r.status);return}
|
|
219
214
|
const reader=r.body.getReader(),decoder=new TextDecoder();let buf="";
|
|
220
215
|
while(true){const{done,value}=await reader.read();if(done)break;buf+=decoder.decode(value,{stream:true});const lines=buf.split("\\n");buf=lines.pop()||"";
|
|
221
216
|
for(const line of lines){if(!line.trim())continue;try{handle(JSON.parse(line))}catch{}}}}
|
|
222
|
-
catch(err){
|
|
217
|
+
catch(err){addSys("ERR: "+esc(err.message||""))}finally{busy=false;send.disabled=false;spinner.className="spin"}};
|
|
223
218
|
|
|
224
|
-
fetch("/api/messages").then(r=>r.json()).then(events=>{
|
|
225
|
-
for(const e of events){
|
|
226
|
-
if(e.type==="user"){addMsg("user",e.text)}
|
|
227
|
-
else{handle(e)}
|
|
228
|
-
}
|
|
229
|
-
}).catch(()=>{});
|
|
219
|
+
fetch("/api/messages").then(r=>r.json()).then(events=>{for(const e of events){if(e.type==="user")addUser(e.text);else handle(e)}}).catch(()=>{});
|
|
230
220
|
|
|
231
|
-
fetch("/api/stats").then(r=>r.json()).then(s=>{
|
|
232
|
-
statSessions.textContent=s.sessions+" sessions";
|
|
233
|
-
statCost.textContent="$"+s.cost.toFixed(2);
|
|
234
|
-
}).catch(()=>{});
|
|
221
|
+
fetch("/api/stats").then(r=>r.json()).then(s=>{statSessions.textContent=s.sessions+" sessions";statCost.textContent=s.cost.toFixed(2)}).catch(()=>{});
|
|
235
222
|
|
|
236
|
-
fetch("/api/session-info").then(r=>r.json()).then(s=>{
|
|
237
|
-
sessionInfo.textContent=s.id?("session: "+s.id.slice(0,8)+(s.name?" | "+s.name:"")):"";
|
|
238
|
-
}).catch(()=>{});
|
|
223
|
+
fetch("/api/session-info").then(r=>r.json()).then(s=>{sid.textContent=s.id?s.id.slice(0,8)+(s.name?" "+s.name:""):""}).catch(()=>{});
|
|
239
224
|
</script>
|
|
240
225
|
</body>
|
|
241
226
|
</html>`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-mode.js","sourceRoot":"","sources":["../../../src/modes/web/web-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA6C,MAAM,WAAW,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAI5C,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;AAE7C,SAAS,SAAS,CAAC,GAAoB,EAAE,GAAmB,EAAW;IACtE,IAAI,CAAC,Q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sourcesContent":["import { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { networkInterfaces } from \"node:os\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.ts\";\nimport type { AgentSessionRuntime } from \"../../core/agent-session-runtime.ts\";\n\nconst PASSWORD = process.env.PI_WEB_PASSWORD;\n\nfunction checkAuth(req: IncomingMessage, res: ServerResponse): boolean {\n\tif (!PASSWORD) return true;\n\n\tconst auth = req.headers.authorization;\n\tif (auth) {\n\t\tconst [scheme, credentials] = auth.split(\" \");\n\t\tif (scheme === \"Basic\" && credentials) {\n\t\t\tconst decoded = Buffer.from(credentials, \"base64\").toString(\"utf-8\");\n\t\t\tconst [, password] = decoded.split(\":\");\n\t\t\tif (password === PASSWORD) return true;\n\t\t}\n\t}\n\n\tres.writeHead(401, {\n\t\t\"www-authenticate\": 'Basic realm=\"pi\", charset=\"UTF-8\"',\n\t\t\"content-type\": \"text/plain\",\n\t});\n\tres.end(\"Unauthorized\");\n\treturn false;\n}\n\nfunction getLocalIP(): string {\n\tconst interfaces = networkInterfaces();\n\tfor (const iface of Object.values(interfaces)) {\n\t\tif (!iface) continue;\n\t\tfor (const addr of iface) {\n\t\t\tif (addr.family === \"IPv4\" && !addr.internal) {\n\t\t\t\treturn addr.address;\n\t\t\t}\n\t\t}\n\t}\n\treturn \"127.0.0.1\";\n}\n\nfunction getPort(): number {\n\tconst env = process.env.PORT;\n\tif (env) {\n\t\tconst p = parseInt(env, 10);\n\t\tif (!Number.isNaN(p) && p > 0 && p < 65536) return p;\n\t}\n\treturn 0;\n}\n\nconst HTML = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no\">\n<title>pi</title>\n<style>\n*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}\nhtml{font-size:14px;-webkit-text-size-adjust:100%}\nbody{font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",system-ui,sans-serif;background:#0b1014;color:#c9d1d9;display:flex;flex-direction:column;height:100dvh;overflow:hidden}\n#header{display:flex;align-items:center;justify-content:space-between;padding:8px 16px;background:#0d121a;border-bottom:1px solid #21262d;flex-shrink:0;gap:10px}\n#header-left{display:flex;align-items:center;gap:10px}\n#header h1{font-size:14px;font-weight:600;color:#e6edf3}\n#session-info{font-size:11px;color:#6e7681;max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n#header-stats{display:flex;gap:12px;font-size:11px;color:#7d8590}\n#msgs{flex:1;overflow-y:auto;padding:16px 20px;scroll-behavior:smooth;display:flex;flex-direction:column;gap:14px}\n#msgs::-webkit-scrollbar{width:6px}\n#msgs::-webkit-scrollbar-track{background:transparent}\n#msgs::-webkit-scrollbar-thumb{background:#30363d;border-radius:3px}\n.msg-group{display:flex;flex-direction:column;gap:2px;animation:fadeIn .15s ease;max-width:86%}\n.msg-group.user{max-width:82%;align-self:flex-end}\n@keyframes fadeIn{from{opacity:0;transform:translateY(4px)}to{opacity:1;transform:translateY(0)}}\n.msg-label{font-size:10.5px;font-weight:600;text-transform:uppercase;letter-spacing:.5px;padding:0 2px}\n.msg-group.user .msg-label{color:#7ec9ff;text-align:right}\n.msg-group.assistant .msg-label{color:#7d8590}\n.msg{border-radius:8px;font-size:13.5px;line-height:1.6;overflow-wrap:break-word;padding:10px 14px}\n.msg.user{background:#1b4a8b;color:#e6edf3;border-bottom-right-radius:2px}\n.msg.assistant{background:#1a1f2b;color:#c9d1d9;border-bottom-left-radius:2px;border:1px solid #21262d}\n.msg.system{background:transparent;color:#6e7681;font-size:12px;text-align:center;max-width:100%;padding:4px 0}\n.msg p{margin:0 0 6px}\n.msg p:last-child{margin-bottom:0}\n.msg strong{color:#f2a65a;font-weight:600}\n.msg em{color:#c9d1d9;font-style:italic}\n.msg code{font-family:\"JetBrains Mono\",\"Fira Code\",monospace;font-size:12px;background:#2d333b;color:#c9d1d9;padding:1px 5px;border-radius:3px}\n.msg pre{background:#161b22;border:1px solid #30363d;border-radius:6px;padding:10px 12px;margin:8px 0;overflow-x:auto;font-size:12px;line-height:1.5}\n.msg pre code{background:transparent;padding:0;border-radius:0;font-size:inherit}\n.msg h1,.msg h2,.msg h3{margin:8px 0 4px;font-weight:600;color:#e6edf3}\n.msg h1{font-size:18px;border-bottom:1px solid #21262d;padding-bottom:4px}\n.msg h2{font-size:15px}\n.msg h3{font-size:13.5px;color:#c9d1d9}\n.msg ul,.msg ol{padding-left:20px;margin:4px 0 8px}\n.msg li{margin:2px 0}\n.msg hr{border:none;border-top:1px solid #21262d;margin:10px 0}\n.tool{border:1px solid #21262d;border-radius:8px;overflow:hidden;transition:border-color .2s}\n.tool:hover{border-color:#30363d}\n.tool-header{display:flex;align-items:center;justify-content:space-between;padding:7px 10px;background:#0d121a;cursor:pointer;user-select:none;gap:8px;transition:background .15s}\n.tool-header:hover{background:#161b22}\n.tool-icon{width:7px;height:7px;border-radius:50%;flex-shrink:0}\n.tool-icon.pending{background:#d29922;animation:pulse 1.5s infinite}\n.tool-icon.done{background:#3fb950}\n.tool-icon.error{background:#f85149}\n@keyframes pulse{0%,100%{opacity:.4}50%{opacity:1}}\n.tool-title{flex:1;font-size:12px;font-weight:500;color:#c9d1d9;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n.tool-arrow{color:#6e7681;font-size:9px;transition:transform .2s}\n.tool.expanded .tool-arrow{transform:rotate(90deg)}\n.tool-body{font-family:\"JetBrains Mono\",\"Fira Code\",monospace;font-size:12px;line-height:1.55;padding:8px 10px;background:#0b1014;white-space:pre-wrap;word-break:break-all;overflow-x:auto;max-height:30vh;overflow-y:auto;display:none}\n.tool-body::-webkit-scrollbar{width:4px;height:4px}\n.tool-body::-webkit-scrollbar-thumb{background:#30363d;border-radius:2px}\n.tool.expanded .tool-body{display:block}\n.tool.mini .tool-body{max-height:12vh}\n.thinking{padding:5px 10px;border-left:2px solid #30363d;font-size:11.5px;color:#6e7681;font-style:italic}\n#input-area{background:#0d121a;border-top:1px solid #21262d;padding:12px 16px;flex-shrink:0}\n#input-area form{display:flex;gap:8px;max-width:900px;margin:0 auto}\n#prompt{flex:1;background:#161b22;border:1px solid #30363d;border-radius:8px;padding:9px 12px;color:#c9d1d9;font-size:13.5px;font-family:inherit;outline:none;transition:border-color .2s,box-shadow .2s}\n#prompt:focus{border-color:#4493f8;box-shadow:0 0 0 3px rgba(68,147,248,.15)}\n#prompt::placeholder{color:#484f58}\nbutton{background:#1f6feb;color:#fff;border:none;border-radius:8px;padding:9px 16px;font-size:13px;font-weight:500;cursor:pointer;transition:background .15s;flex-shrink:0}\nbutton:hover{background:#2b83ff}\nbutton:disabled{background:#21262d;color:#6e7681;cursor:not-allowed}\n.btn-mini{font-size:11px;padding:4px 10px;background:#21262d}\n.btn-mini:hover{background:#30363d}\n.spinner{display:none;width:16px;height:16px;border:2px solid #30363d;border-top-color:#4493f8;border-radius:50%;animation:spin .6s linear infinite}\n.spinner.active{display:inline-block}\n@keyframes spin{to{transform:rotate(360deg)}}\n@media(max-width:600px){\nhtml{font-size:13px}\n#msgs{padding:10px;gap:10px}\n.msg-group{max-width:94%}\n.msg-group.user{max-width:92%}\n#input-area{padding:8px 10px}\n#prompt{padding:7px 10px}\nbutton{padding:7px 12px}\n}\n</style>\n</head>\n<body>\n<div id=\"header\">\n<div id=\"header-left\"><h1>pi</h1><span id=\"session-info\"></span></div>\n<div id=\"header-stats\"><span id=\"stat-sessions\"></span><span id=\"stat-cost\"></span></div>\n</div>\n<div id=\"msgs\"></div>\n<div id=\"input-area\">\n<form id=\"f\" autocomplete=\"off\">\n<input id=\"prompt\" type=\"text\" placeholder=\"Message pi...\" autofocus autocomplete=\"off\">\n<button id=\"send\">Send</button>\n<span class=\"spinner\" id=\"spinner\"></span>\n</form>\n</div>\n<script>\nconst msgs=document.getElementById(\"msgs\"),f=document.getElementById(\"f\"),prompt=document.getElementById(\"prompt\"),\nsend=document.getElementById(\"send\"),spinner=document.getElementById(\"spinner\"),\nstatSessions=document.getElementById(\"stat-sessions\"),statCost=document.getElementById(\"stat-cost\"),\nsessionInfo=document.getElementById(\"session-info\");\nlet busy=false,toolEls={},curAssistant=null;\n\nfunction scrollDown(){msgs.scrollTop=msgs.scrollHeight}\nfunction esc(s){if(!s)return\"\";return s.replace(/&/g,\"&\").replace(/</g,\"<\").replace(/>/g,\">\")}\nfunction fmt(n){if(n<1e3)return n;if(n<1e4)return(n/1e3).toFixed(1)+\"k\";return Math.round(n/1e3)+\"k\"}\n\nfunction md(text){\nlet s=esc(text);\nconst blocks=[];\ns=s.replace(/\\`\\`\\`(\\\\w*)\\\\n([\\\\s\\\\S]*?)\\\\n\\`\\`\\`/g,(_,lang,code)=>{blocks.push('<pre><code>'+code+'</code></pre>');return'\\\\x00B'+(blocks.length-1)+'\\\\x00B'});\ns=s.replace(/\\`([^\\`]+)\\`/g,'<code>$1</code>');\ns=s.replace(/\\\\*\\\\*(.+?)\\\\*\\\\*/g,'<strong>$1</strong>');\ns=s.replace(/\\\\*(.+?)\\\\*/g,'<em>$1</em>');\ns=s.replace(/^### (.+$)/gm,'<h3>$1</h3>');\ns=s.replace(/^## (.+$)/gm,'<h2>$1</h2>');\ns=s.replace(/^# (.+$)/gm,'<h1>$1</h1>');\ns=s.replace(/^- (.+$)/gm,'<li>$1</li>');\ns=s.replace(/^> (.+$)/gm,'<blockquote>$1</blockquote>');\ns=s.replace(/((?:<li>.*<\\\\/li>\\\\n?)+)/g,'<ul>$1</ul>');\ns=s.replace(/^(---+|\\\\*\\\\*\\\\*+|___+)$/gm,'<hr>');\ns=s.replace(/\\\\x00B(\\\\d+)\\\\x00B/g,(_,i)=>blocks[parseInt(i)]);\ns=s.replace(/\\\\n\\\\n/g,'<br><br>');\ns=s.replace(/\\\\n/g,'<br>');\nreturn s\n}\n\nfunction addMsg(role,text){\nconst g=document.createElement(\"div\");g.className=\"msg-group \"+role;\nif(role===\"user\"){g.innerHTML='<div class=\"msg-label\">You</div><div class=\"msg user\">'+esc(text)+'</div>'}\nelse if(role===\"assistant\"){g.innerHTML='<div class=\"msg-label\">pi</div><div class=\"msg assistant\"></div>'}\nelse{g.innerHTML='<div class=\"msg system\">'+text+'</div>'}\nmsgs.appendChild(g);scrollDown();return g}\n\nfunction getAssistantDiv(){if(!curAssistant){curAssistant=addMsg(\"assistant\",\"\")}return curAssistant.querySelector(\".msg\")}\n\nfunction startTool(e){\nconst el=document.createElement(\"div\");el.className=\"tool\";el.id=\"t\"+e.toolCallId;\nconst title=esc(e.toolName)+(e.args?' '+esc(String(e.args.command||e.args.path||e.args.file_path||\"\").slice(0,80)):'');\nel.innerHTML='<div class=\"tool-header\"><span class=\"tool-icon pending\"></span><span class=\"tool-title\">'+title+'</span><span class=\"tool-arrow\">▶</span></div><div class=\"tool-body\"></div>';\nel.querySelector(\".tool-header\").onclick=()=>el.classList.toggle(\"expanded\");\nmsgs.appendChild(el);toolEls[e.toolCallId]=el;scrollDown()}\n\nfunction updateTool(id,result,isError){\nconst el=toolEls[id];if(!el)return;\nconst icon=el.querySelector(\".tool-icon\"),body=el.querySelector(\".tool-body\");\nif(isError){icon.className=\"tool-icon error\"}\nconst texts=result&&result.content?result.content.filter(c=>c&&c.type===\"text\").map(c=>c.text):[];\nif(texts.length){body.textContent=texts.join(\"\\\\n\");el.classList.add(\"expanded\",\"mini\")}}\n\nfunction finishTool(id,isError){\nconst el=toolEls[id];if(!el)return;\nconst icon=el.querySelector(\".tool-icon\");icon.className=\"tool-icon \"+(isError?\"error\":\"done\");\nconst body=el.querySelector(\".tool-body\");if(isError&&!body.textContent.trim())body.textContent=\"(no output)\"}\n\nfunction handle(d){\nswitch(d.type){\ncase\"agent_start\":curAssistant=null;break;\ncase\"text_delta\":{const ad=getAssistantDiv();ad.innerHTML+=md(d.delta);scrollDown();break}\ncase\"thinking_delta\":{let th=document.getElementById(\"think\"+d.contentIndex);if(!th){th=document.createElement(\"div\");th.className=\"thinking\";th.id=\"think\"+d.contentIndex;msgs.appendChild(th)}th.textContent+=d.delta;scrollDown();break}\ncase\"tool_execution_start\":startTool(d);break;\ncase\"tool_execution_update\":updateTool(d.toolCallId,d.result,false);break;\ncase\"tool_execution_end\":finishTool(d.toolCallId,d.isError);if(d.result)updateTool(d.toolCallId,d.result,d.isError);break;\ncase\"agent_end\":{let s=\"\";if(d.usage){s=\" · \"+fmt(d.usage.input)+\" in · \"+fmt(d.usage.output)+\" out\";if(d.usage.cost)s+=\" · $\"+d.usage.cost.total.toFixed(4)}addMsg(\"system\",\"Done\"+s);break}\ncase\"compaction\":addMsg(\"system\",\"Compacting...\");break;\ncase\"error\":addMsg(\"system\",\"Error: \"+esc(d.message));break;\ncase\"text_start\":case\"thinking_start\":case\"text_end\":case\"thinking_end\":case\"toolcall_start\":case\"toolcall_end\":case\"toolcall_delta\":break}}\n\nf.onsubmit=async e=>{e.preventDefault();if(busy)return;const text=prompt.value.trim();if(!text)return;prompt.value=\"\";addMsg(\"user\",text);busy=true;send.disabled=true;spinner.className=\"spinner active\";\ntry{const r=await fetch(\"/api/prompt\",{method:\"POST\",headers:{\"content-type\":\"application/json\"},body:JSON.stringify({text})});\nif(!r.ok){addMsg(\"system\",\"Error: \"+r.status);return}\nconst reader=r.body.getReader(),decoder=new TextDecoder();let buf=\"\";\nwhile(true){const{done,value}=await reader.read();if(done)break;buf+=decoder.decode(value,{stream:true});const lines=buf.split(\"\\\\n\");buf=lines.pop()||\"\";\nfor(const line of lines){if(!line.trim())continue;try{handle(JSON.parse(line))}catch{}}}}\ncatch(err){addMsg(\"system\",\"Error: \"+esc(err.message))}finally{busy=false;send.disabled=false;spinner.className=\"spinner\"}};\n\nfetch(\"/api/messages\").then(r=>r.json()).then(events=>{\nfor(const e of events){\nif(e.type===\"user\"){addMsg(\"user\",e.text)}\nelse{handle(e)}\n}\n}).catch(()=>{});\n\nfetch(\"/api/stats\").then(r=>r.json()).then(s=>{\nstatSessions.textContent=s.sessions+\" sessions\";\nstatCost.textContent=\"$\"+s.cost.toFixed(2);\n}).catch(()=>{});\n\nfetch(\"/api/session-info\").then(r=>r.json()).then(s=>{\nsessionInfo.textContent=s.id?(\"session: \"+s.id.slice(0,8)+(s.name?\" | \"+s.name:\"\")):\"\";\n}).catch(()=>{});\n</script>\n</body>\n</html>`;\n\nfunction sendEvent(res: ServerResponse, data: Record<string, unknown>): void {\n\tres.write(`${JSON.stringify(data)}\\n`);\n}\n\nexport async function runWebMode(runtime: AgentSessionRuntime): Promise<void> {\n\tconst session = runtime.session;\n\tconst port = getPort();\n\n\tconst server = createServer(async (req: IncomingMessage, res: ServerResponse) => {\n\t\tif (!checkAuth(req, res)) return;\n\n\t\tconst url = req.url ?? \"/\";\n\n\t\tif (req.method === \"POST\" && url === \"/api/prompt\") {\n\t\t\tconst chunks: Buffer[] = [];\n\t\t\treq.on(\"data\", (chunk: Buffer) => chunks.push(chunk));\n\t\t\tawait new Promise<void>((resolve) => req.on(\"end\", resolve));\n\t\t\tconst body = JSON.parse(Buffer.concat(chunks).toString());\n\t\t\tconst text = String(body.text ?? \"\").trim();\n\t\t\tif (!text) {\n\t\t\t\tres.writeHead(400);\n\t\t\t\tres.end(JSON.stringify({ error: \"missing text\" }));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tres.writeHead(200, { \"content-type\": \"text/plain; charset=utf-8\", \"cache-control\": \"no-cache\" });\n\n\t\t\tconst unsubscribe = session.subscribe((event: AgentSessionEvent) => {\n\t\t\t\tconst events = toSerializableEvents(event);\n\t\t\t\tfor (const evt of events) {\n\t\t\t\t\tsendEvent(res, evt);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tawait session.prompt(text);\n\t\t\t} catch (err) {\n\t\t\t\tsendEvent(res, { type: \"error\", message: String(err) });\n\t\t\t} finally {\n\t\t\t\tunsubscribe();\n\t\t\t\tres.end();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/stats\") {\n\t\t\tconst stats = await session.getUsageStats();\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(\n\t\t\t\tJSON.stringify({ sessions: stats.sessions, cost: stats.cost, input: stats.input, output: stats.output }),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/session-info\") {\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tid: session.sessionId,\n\t\t\t\t\tname: session.sessionManager.getSessionName(),\n\t\t\t\t\tfile: session.sessionFile,\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/messages\") {\n\t\t\tconst entries = session.sessionManager.getEntries();\n\t\t\tconst events: Record<string, unknown>[] = [];\n\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (entry.type !== \"message\") continue;\n\t\t\t\tconst msg = (entry as { message: { role: string; content: unknown; usage?: unknown } }).message;\n\t\t\t\tif (!msg) continue;\n\n\t\t\t\tif (msg.role === \"user\") {\n\t\t\t\t\tconst content = typeof msg.content === \"string\" ? msg.content : \"\";\n\t\t\t\t\tevents.push({ type: \"user\", text: content });\n\t\t\t\t} else if (msg.role === \"assistant\") {\n\t\t\t\t\tconst content = Array.isArray(msg.content) ? msg.content : [];\n\t\t\t\t\tfor (const block of content as Array<{ type: string; text?: string; toolCall?: unknown }>) {\n\t\t\t\t\t\tif (block.type === \"text\" && block.text) {\n\t\t\t\t\t\t\tevents.push({ type: \"text_delta\", delta: block.text });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (block.type === \"toolCall\" && block.toolCall) {\n\t\t\t\t\t\t\tconst tc = block.toolCall as { toolCallId?: string; toolName?: string; input?: unknown };\n\t\t\t\t\t\t\tevents.push({\n\t\t\t\t\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\t\t\t\t\ttoolCallId: tc.toolCallId,\n\t\t\t\t\t\t\t\ttoolName: tc.toolName,\n\t\t\t\t\t\t\t\targs: tc.input,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (msg.role === \"toolResult\") {\n\t\t\t\t\tconst content = (msg as { toolCallId?: string; content?: Array<{ type: string; text?: string }> })\n\t\t\t\t\t\t.content;\n\t\t\t\t\tevents.push({\n\t\t\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\t\t\ttoolCallId: (msg as { toolCallId?: string }).toolCallId,\n\t\t\t\t\t\tresult: { content: content ?? [] },\n\t\t\t\t\t\tisError: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst usage = getSessionTokenCount(session);\n\t\t\tevents.push({ type: \"agent_end\", usage });\n\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(JSON.stringify(events));\n\t\t\treturn;\n\t\t}\n\n\t\tres.writeHead(200, { \"content-type\": \"text/html; charset=utf-8\" });\n\t\tres.end(HTML);\n\t});\n\n\tawait new Promise<void>((resolve, reject) => {\n\t\tserver.listen(port, \"0.0.0.0\", () => resolve());\n\t\tserver.on(\"error\", reject);\n\t});\n\n\tconst addr = server.address();\n\tif (!addr || typeof addr === \"string\") {\n\t\tconsole.error(\"Failed to start web server\");\n\t\treturn;\n\t}\n\n\tconst consolePort = `http://127.0.0.1:${addr.port}`;\n\tconst lan = getLocalIP();\n\tconsole.log(`\\n pi web UI: ${consolePort}`);\n\tif (lan !== \"127.0.0.1\") {\n\t\tconsole.log(` LAN: http://${lan}:${addr.port}`);\n\t}\n\tconsole.log(` session: ${session.sessionId.slice(0, 8)}`);\n\tconsole.log(\" (listening on all interfaces)\");\n\tif (PASSWORD) {\n\t\tconsole.log(` auth: Basic (user \"pi\", password from PI_WEB_PASSWORD)`);\n\t} else {\n\t\tconsole.log(\" auth: none (set PI_WEB_PASSWORD to enable)\");\n\t}\n\tconsole.log();\n\n\t// Keep process alive\n\tawait new Promise(() => {});\n\n\tserver.close();\n}\n\nfunction getSessionTokenCount(session: AgentSessionRuntime[\"session\"]): Record<string, unknown> | undefined {\n\tconst entries = session.sessionManager.getEntries();\n\tlet input = 0;\n\tlet output = 0;\n\tlet costTotal = 0;\n\tlet hasUsage = false;\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tconst msg = (\n\t\t\tentry as { message: { role: string; usage?: { input: number; output: number; cost: { total: number } } } }\n\t\t).message;\n\t\tif (msg?.role === \"assistant\" && msg.usage) {\n\t\t\tinput += msg.usage.input;\n\t\t\toutput += msg.usage.output;\n\t\t\tcostTotal += msg.usage.cost.total;\n\t\t\thasUsage = true;\n\t\t}\n\t}\n\treturn hasUsage ? { input, output, cost: { total: costTotal } } : undefined;\n}\n\nfunction toSerializableEvents(event: AgentSessionEvent): Record<string, unknown>[] {\n\tswitch (event.type) {\n\t\tcase \"agent_start\":\n\t\t\treturn [{ type: \"agent_start\" }];\n\t\tcase \"agent_end\": {\n\t\t\tconst lastAssistant = event.messages.filter((m) => m.role === \"assistant\").at(-1);\n\t\t\tconst usage = lastAssistant && \"usage\" in lastAssistant ? lastAssistant.usage : undefined;\n\t\t\treturn [{ type: \"agent_end\", usage }];\n\t\t}\n\t\tcase \"message_update\": {\n\t\t\tconst ame: Record<string, unknown> = event.assistantMessageEvent;\n\t\t\tconst serialized = serializeAssistantMessageEvent(ame);\n\t\t\treturn serialized;\n\t\t}\n\t\tcase \"tool_execution_start\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"tool_execution_update\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_update\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.partialResult,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"tool_execution_end\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.result,\n\t\t\t\t\tisError: event.isError,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"compaction_start\":\n\t\tcase \"compaction_end\":\n\t\t\treturn [{ type: \"compaction\" }];\n\t\tdefault:\n\t\t\treturn [];\n\t}\n}\n\nfunction serializeAssistantMessageEvent(event: Record<string, unknown>): Record<string, unknown>[] {\n\tconst type = event.type as string;\n\tswitch (type) {\n\t\tcase \"start\":\n\t\t\treturn [{ type: \"agent_start\" }];\n\t\tcase \"text_start\":\n\t\t\treturn [{ type: \"text_start\", contentIndex: event.contentIndex }];\n\t\tcase \"text_delta\":\n\t\t\treturn [{ type: \"text_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"text_end\":\n\t\t\treturn [{ type: \"text_end\", content: event.content, contentIndex: event.contentIndex }];\n\t\tcase \"thinking_start\":\n\t\t\treturn [{ type: \"thinking_start\", contentIndex: event.contentIndex }];\n\t\tcase \"thinking_delta\":\n\t\t\treturn [{ type: \"thinking_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"thinking_end\":\n\t\t\treturn [{ type: \"thinking_end\", content: event.content, contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_start\":\n\t\t\treturn [{ type: \"toolcall_start\", contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_delta\":\n\t\t\treturn [{ type: \"toolcall_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_end\":\n\t\t\treturn [{ type: \"toolcall_end\", toolCall: event.toolCall, contentIndex: event.contentIndex }];\n\t\tcase \"done\":\n\t\t\treturn [{ type: \"done\", reason: event.reason }];\n\t\tcase \"error\":\n\t\t\treturn [{ type: \"error\", reason: event.reason }];\n\t\tdefault:\n\t\t\treturn [];\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web-m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,KAAK,MAAM;YACV,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QACjD,KAAK,OAAO;YACX,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAClD;YACC,OAAO,EAAE,CAAC;IACZ,CAAC;AAAA,CACD","sourcesContent":["import { createServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { networkInterfaces } from \"node:os\";\nimport type { AgentSessionEvent } from \"../../core/agent-session.ts\";\nimport type { AgentSessionRuntime } from \"../../core/agent-session-runtime.ts\";\n\nconst PASSWORD = process.env.PI_WEB_PASSWORD;\n\nfunction checkAuth(req: IncomingMessage, res: ServerResponse): boolean {\n\tif (!PASSWORD) return true;\n\n\tconst auth = req.headers.authorization;\n\tif (auth) {\n\t\tconst [scheme, credentials] = auth.split(\" \");\n\t\tif (scheme === \"Basic\" && credentials) {\n\t\t\tconst decoded = Buffer.from(credentials, \"base64\").toString(\"utf-8\");\n\t\t\tconst [, password] = decoded.split(\":\");\n\t\t\tif (password === PASSWORD) return true;\n\t\t}\n\t}\n\n\tres.writeHead(401, {\n\t\t\"www-authenticate\": 'Basic realm=\"pi\", charset=\"UTF-8\"',\n\t\t\"content-type\": \"text/plain\",\n\t});\n\tres.end(\"Unauthorized\");\n\treturn false;\n}\n\nfunction getLocalIP(): string {\n\tconst interfaces = networkInterfaces();\n\tfor (const iface of Object.values(interfaces)) {\n\t\tif (!iface) continue;\n\t\tfor (const addr of iface) {\n\t\t\tif (addr.family === \"IPv4\" && !addr.internal) {\n\t\t\t\treturn addr.address;\n\t\t\t}\n\t\t}\n\t}\n\treturn \"127.0.0.1\";\n}\n\nfunction getPort(): number {\n\tconst env = process.env.PORT;\n\tif (env) {\n\t\tconst p = parseInt(env, 10);\n\t\tif (!Number.isNaN(p) && p > 0 && p < 65536) return p;\n\t}\n\treturn 0;\n}\n\nconst HTML = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"UTF-8\">\n<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no\">\n<title>pi</title>\n<style>\n*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}\nhtml{font-size:15px}\nbody{font-family:\"IBM Plex Mono\",\"JetBrains Mono\",\"Fira Code\",\"SF Mono\",monospace;background:#1a1815;color:#d4b872;display:flex;flex-direction:column;height:100dvh;overflow:hidden}\n#topbar{display:flex;align-items:center;justify-content:space-between;padding:6px 16px;background:#141310;border-bottom:2px solid #3a3528;flex-shrink:0}\n#topbar h1{font-size:13px;font-weight:700;color:#e8cf8a;letter-spacing:1px}\n#topbar h1::before{content:\"[ \";color:#5c5240}#topbar h1::after{content:\" ]\";color:#5c5240}\n#topbar aside{font-size:10px;color:#5c5240}\n#msgs{flex:1;overflow-y:auto;padding:16px 20px;scroll-behavior:smooth;display:flex;flex-direction:column;gap:12px;background:linear-gradient(180deg,#1a1815 0%,#171512 100%)}\n#msgs::-webkit-scrollbar{width:5px}\n#msgs::-webkit-scrollbar-thumb{background:#3a3528;border-radius:0}\n.row{animation:fadeIn .12s ease}\n.row.user{display:flex;flex-direction:column;align-items:flex-end;max-width:82%;align-self:flex-end}\n.row.ast{display:flex;flex-direction:column;align-items:flex-start;max-width:88%;align-self:flex-start;width:100%}\n.row.sys{display:flex;justify-content:center;max-width:100%;align-self:center}\n@keyframes fadeIn{from{opacity:0;transform:translateY(3px)}to{opacity:1;transform:translateY(0)}}\n.rolename{font-size:10px;text-transform:uppercase;letter-spacing:1px;margin-bottom:2px;font-weight:700}\n.row.user .rolename{color:#9e8a5e}\n.row.ast .rolename{color:#5c5240}\n.bubble{border:1px solid #3a3528;padding:10px 14px;font-size:13px;line-height:1.65;overflow-wrap:break-word;word-break:break-word}\n.bubble.user{background:#2a251c;color:#e8cf8a;max-width:100%}\n.bubble.ast{background:#141310;color:#c4a860;max-width:100%}\n.bubble.sys{background:none;border:none;color:#5c5240;font-size:11px;text-align:center;padding:2px 0}\n.bubble code{background:#111;border:1px solid #3a3528;padding:1px 5px;color:#d4b872;font-size:12px}\n.bubble pre{background:#111;border:1px solid #3a3528;padding:10px 12px;overflow-x:auto;font-size:12px;line-height:1.5;color:#c4a860;margin:6px 0}\n.bubble pre code{background:none;border:none;padding:0;font-size:inherit;color:inherit}\n.bubble strong{color:#e8cf8a;font-weight:700}\n.bubble em{color:#c4a860;font-style:italic}\n.bubble h1,.bubble h2,.bubble h3{font-weight:700;color:#e8cf8a;margin:8px 0 3px}\n.bubble h1{font-size:15px;border-bottom:1px solid #3a3528;padding-bottom:3px}\n.bubble h2{font-size:14px}\n.bubble h3{font-size:13px;color:#c4a860}\n.bubble ul,.bubble ol{padding-left:22px;margin:4px 0}\n.bubble li{margin:2px 0}\n.bubble hr{border:none;border-top:1px solid #3a3528;margin:8px 0}\n.bubble blockquote{border-left:3px solid #3a3528;padding:4px 10px;color:#8e8048;margin:4px 0}\n.tool{border:1px solid #3a3528;margin:2px 0}\n.tool.running{border-color:#906820}\n.tool.error{border-color:#6b2020}\n.tool-bar{display:flex;align-items:center;padding:6px 10px;cursor:pointer;gap:8px;font-size:12px;user-select:none;background:#141310}\n.tool-bar:hover{background:#1a1815}\n.tool-dot{width:7px;height:7px;flex-shrink:0;background:#3a3528}\n.tool-dot.running{background:#c48c22;animation:blink 1s step-end infinite}\n.tool-dot.ok{background:#689040}\n.tool-dot.err{background:#b84040}\n@keyframes blink{50%{opacity:.2}}\n.tool-kind{font-weight:700;color:#c4a860}\n.tool-args{color:#5c5240;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}\n.tool-chev{color:#5c5240;font-size:10px;transition:.12s}\n.tool.open .tool-chev{transform:rotate(90deg)}\n.tool-content{display:none;padding:8px 12px;border-top:1px solid #3a3528;font-size:12px;line-height:1.55;white-space:pre-wrap;word-break:break-all;overflow-x:auto;max-height:32vh;overflow-y:auto;color:#8e8048;background:#111}\n.tool.open .tool-content{display:block}\n.tool-content::-webkit-scrollbar{width:4px;height:4px}\n.tool-content::-webkit-scrollbar-thumb{background:#3a3528}\n#input-area{border-top:2px solid #3a3528;background:#141310;padding:10px 16px;flex-shrink:0}\n#input-area form{display:flex;gap:8px;max-width:900px;margin:0 auto}\n#prompt{flex:1;background:#1a1815;border:1px solid #3a3528;padding:8px 12px;color:#d4b872;font-size:13px;font-family:inherit;outline:none;transition:border .15s}\n#prompt:focus{border-color:#c48c22;box-shadow:0 0 6px rgba(196,140,34,.15)}\n#prompt::placeholder{color:#3a3528}\nbutton{background:#3a3528;color:#c4a860;border:1px solid #5c5240;padding:8px 18px;font-size:12px;font-family:inherit;font-weight:700;cursor:pointer;transition:.1s;flex-shrink:0;text-transform:uppercase;letter-spacing:1px}\nbutton:hover{background:#5c5240;color:#e8cf8a;border-color:#8e8048}\nbutton:disabled{opacity:.3;cursor:not-allowed}\n.spin{display:none;width:14px;height:14px;border:2px solid #3a3528;border-top-color:#c48c22;border-radius:50%;animation:spinner .5s linear infinite}\n.spin.on{display:inline-block}\n@keyframes spinner{to{transform:rotate(360deg)}}\n@media(max-width:600px){\n#msgs{padding:10px;gap:8px}\n.row.user{max-width:94%}.row.ast{max-width:96%}\n#input-area{padding:8px 10px}\n}\n</style>\n</head>\n<body>\n<div id=\"topbar\"><h1>pi</h1><aside><span id=\"sid\"></span> <span id=\"stat-sessions\"></span> <span id=\"stat-cost\"></span></aside></div>\n<div id=\"msgs\"></div>\n<div id=\"input-area\">\n<form id=\"f\" autocomplete=\"off\">\n<input id=\"prompt\" type=\"text\" placeholder=\">_\" autofocus autocomplete=\"off\">\n<button id=\"send\">Send</button>\n<span class=\"spin\" id=\"spin\"></span>\n</form>\n</div>\n<script>\nconst msgs=document.getElementById(\"msgs\"),f=document.getElementById(\"f\"),prompt=document.getElementById(\"prompt\"),\nsend=document.getElementById(\"send\"),spinner=document.getElementById(\"spin\"),\nstatSessions=document.getElementById(\"stat-sessions\"),statCost=document.getElementById(\"stat-cost\"),\nsid=document.getElementById(\"sid\");\nlet busy=false,tools={},curAsst=null;\n\nfunction scroll(){msgs.scrollTop=msgs.scrollHeight}\nfunction esc(s){if(s==null)return\"\";return(\"\"+s).replace(/&/g,\"&\").replace(/</g,\"<\").replace(/>/g,\">\").replace(/\"/g,\""\")}\nfunction fmt(n){if(!n)return\"0\";if(n<1e3)return\"\"+n;if(n<1e4)return(n/1e3).toFixed(1)+\"k\";return Math.round(n/1e3)+\"k\"}\n\nfunction argText(args){if(!args)return\"\";const v=args.command||args.path||args.file_path;return v?\" \"+esc(v).slice(0,80):\"\"}\n\nfunction md(s){\nlet t=esc(s||\"\");\nconst blocks=[];\nt=t.replace(/\\`\\`\\`(\\\\w*)\\\\n([\\\\s\\\\S]*?)\\\\n\\`\\`\\`/g,(_,lang,code)=>{blocks.push('<pre><code>'+code+'</code></pre>');return'\\\\x00B'+(blocks.length-1)+'\\\\x00B'});\nt=t.replace(/\\`([^\\`]+)\\`/g,'<code>$1</code>');\nt=t.replace(/\\\\*\\\\*(.+?)\\\\*\\\\*/g,'<strong>$1</strong>');\nt=t.replace(/\\\\*(.+?)\\\\*/g,'<em>$1</em>');\nt=t.replace(/^### (.+)$/gm,'<h3>$1</h3>');\nt=t.replace(/^## (.+)$/gm,'<h2>$1</h2>');\nt=t.replace(/^# (.+)$/gm,'<h1>$1</h1>');\nt=t.replace(/^- (.+)$/gm,'<li>$1</li>');\nt=t.replace(/^> (.+)$/gm,'<blockquote>$1</blockquote>');\nt=t.replace(/((?:<li>.*<\\\\/li>\\\\n?)+)/g,'<ul>$1</ul>');\nt=t.replace(/^(---+|\\\\*\\\\*\\\\*+|___+)$/gm,'<hr>');\nt=t.replace(/\\\\x00B(\\\\d+)\\\\x00B/g,(_,i)=>blocks[parseInt(i)]);\nt=t.replace(/\\\\n\\\\n/g,'<br><br>');\nt=t.replace(/\\\\n/g,'<br>');\nreturn t\n}\n\nfunction row(role){const d=document.createElement(\"div\");d.className=\"row \"+role;msgs.appendChild(d);return d}\nfunction rol(role,lbl){const d=row(role);const n=document.createElement(\"div\");n.className=\"rolename\";n.textContent=lbl;d.appendChild(n);return d}\nfunction bubble(parent,html){const b=document.createElement(\"div\");b.className=\"bubble \"+parent.classList[1];if(html!==undefined)b.innerHTML=html;parent.appendChild(b);return b}\n\nfunction addUser(txt){const r=rol(\"user\",\"YOU\");bubble(r,esc(txt));scroll()}\nfunction addAst(){const r=rol(\"ast\",\"PI\");const b=bubble(r);scroll();curAsst={row:r,bubble:b};return b}\nfunction addSys(txt){const r=row(\"sys\");bubble(r,txt);scroll()}\nfunction getAsstB(){if(!curAsst)return addAst();return curAsst.bubble}\n\nfunction renderTool(e){\nconst r=row(\"ast\");const w=document.createElement(\"div\");w.className=\"tool-wrapper\";\nw.innerHTML='<div class=\"tool running\" id=\"t'+e.toolCallId+'\"><div class=\"tool-bar\"><span class=\"tool-dot running\"></span><span class=\"tool-kind\">'+esc(e.toolName)+'</span><span class=\"tool-args\">'+argText(e.args)+'</span><span class=\"tool-chev\">▶</span></div><div class=\"tool-content\"></div></div>';\nw.querySelector(\".tool-bar\").onclick=()=>w.querySelector(\".tool\").classList.toggle(\"open\");\nr.appendChild(w);msgs.appendChild(r);tools[e.toolCallId]={el:w.querySelector(\".tool\"),row:r};scroll()}\n\nfunction updateTool(id,result,isError){\nconst t=tools[id];if(!t)return;\nconst ct=t.el.querySelector(\".tool-content\");\nconst texts=result&&result.content?result.content.filter(c=>c&&c.type===\"text\").map(c=>c.text):[];\nif(texts.length){ct.textContent=texts.join(\"\\\\n\");t.el.classList.add(\"open\")}\nif(isError){t.el.querySelector(\".tool-dot\").className=\"tool-dot err\";t.el.classList.add(\"error\");t.el.classList.remove(\"running\")}\n}\n\nfunction doneTool(id,isError){\nconst t=tools[id];if(!t)return;\nt.el.querySelector(\".tool-dot\").className=\"tool-dot \"+(isError?\"err\":\"ok\");\nt.el.classList.remove(\"running\");\nif(isError){t.el.classList.add(\"error\")}\nif(isError&&!t.el.querySelector(\".tool-content\").textContent.trim())t.el.querySelector(\".tool-content\").textContent=\"(no output)\"\n}\n\nfunction handle(d){\nswitch(d.type){\ncase\"agent_start\":curAsst=null;break;\ncase\"text_delta\":{const b=getAsstB();b.innerHTML+=md(d.delta);scroll();break}\ncase\"thinking_delta\":{let th=document.getElementById(\"th\"+d.contentIndex);if(!th){th=document.createElement(\"div\");th.className=\"row ast\";const b=document.createElement(\"div\");b.style.cssText=\"font-size:11px;color:#5c5240;font-style:italic;padding:4px 10px;border-left:2px solid #3a3528\";b.id=\"th\"+d.contentIndex;th.appendChild(b);msgs.appendChild(th)}th.firstChild.textContent+=d.delta;scroll();break}\ncase\"tool_execution_start\":renderTool(d);break;\ncase\"tool_execution_update\":updateTool(d.toolCallId,d.result,false);break;\ncase\"tool_execution_end\":doneTool(d.toolCallId,d.isError);if(d.result)updateTool(d.toolCallId,d.result,d.isError);break;\ncase\"agent_end\":{let s=\"DONE\";if(d.usage){s+=\" \"+fmt(d.usage.input)+\" IN / \"+fmt(d.usage.output)+\" OUT\";if(d.usage.cost)s+=\" $\"+d.usage.cost.total.toFixed(4)}addSys(s);break}\ncase\"compaction\":addSys(\"--- COMPACTING ---\");break;\ncase\"error\":addSys(\"ERR: \"+esc(d.message||\"\"));break;\ndefault:break}}\n\nf.onsubmit=async e=>{e.preventDefault();if(busy)return;const text=prompt.value.trim();if(!text)return;prompt.value=\"\";addUser(text);busy=true;send.disabled=true;spinner.className=\"spin on\";\ntry{const r=await fetch(\"/api/prompt\",{method:\"POST\",headers:{\"content-type\":\"application/json\"},body:JSON.stringify({text})});\nif(!r.ok){addSys(\"HTTP \"+r.status);return}\nconst reader=r.body.getReader(),decoder=new TextDecoder();let buf=\"\";\nwhile(true){const{done,value}=await reader.read();if(done)break;buf+=decoder.decode(value,{stream:true});const lines=buf.split(\"\\\\n\");buf=lines.pop()||\"\";\nfor(const line of lines){if(!line.trim())continue;try{handle(JSON.parse(line))}catch{}}}}\ncatch(err){addSys(\"ERR: \"+esc(err.message||\"\"))}finally{busy=false;send.disabled=false;spinner.className=\"spin\"}};\n\nfetch(\"/api/messages\").then(r=>r.json()).then(events=>{for(const e of events){if(e.type===\"user\")addUser(e.text);else handle(e)}}).catch(()=>{});\n\nfetch(\"/api/stats\").then(r=>r.json()).then(s=>{statSessions.textContent=s.sessions+\" sessions\";statCost.textContent=s.cost.toFixed(2)}).catch(()=>{});\n\nfetch(\"/api/session-info\").then(r=>r.json()).then(s=>{sid.textContent=s.id?s.id.slice(0,8)+(s.name?\" \"+s.name:\"\"):\"\"}).catch(()=>{});\n</script>\n</body>\n</html>`;\n\nfunction sendEvent(res: ServerResponse, data: Record<string, unknown>): void {\n\tres.write(`${JSON.stringify(data)}\\n`);\n}\n\nexport async function runWebMode(runtime: AgentSessionRuntime): Promise<void> {\n\tconst session = runtime.session;\n\tconst port = getPort();\n\n\tconst server = createServer(async (req: IncomingMessage, res: ServerResponse) => {\n\t\tif (!checkAuth(req, res)) return;\n\n\t\tconst url = req.url ?? \"/\";\n\n\t\tif (req.method === \"POST\" && url === \"/api/prompt\") {\n\t\t\tconst chunks: Buffer[] = [];\n\t\t\treq.on(\"data\", (chunk: Buffer) => chunks.push(chunk));\n\t\t\tawait new Promise<void>((resolve) => req.on(\"end\", resolve));\n\t\t\tconst body = JSON.parse(Buffer.concat(chunks).toString());\n\t\t\tconst text = String(body.text ?? \"\").trim();\n\t\t\tif (!text) {\n\t\t\t\tres.writeHead(400);\n\t\t\t\tres.end(JSON.stringify({ error: \"missing text\" }));\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tres.writeHead(200, { \"content-type\": \"text/plain; charset=utf-8\", \"cache-control\": \"no-cache\" });\n\n\t\t\tconst unsubscribe = session.subscribe((event: AgentSessionEvent) => {\n\t\t\t\tconst events = toSerializableEvents(event);\n\t\t\t\tfor (const evt of events) {\n\t\t\t\t\tsendEvent(res, evt);\n\t\t\t\t}\n\t\t\t});\n\n\t\t\ttry {\n\t\t\t\tawait session.prompt(text);\n\t\t\t} catch (err) {\n\t\t\t\tsendEvent(res, { type: \"error\", message: String(err) });\n\t\t\t} finally {\n\t\t\t\tunsubscribe();\n\t\t\t\tres.end();\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/stats\") {\n\t\t\tconst stats = await session.getUsageStats();\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(\n\t\t\t\tJSON.stringify({ sessions: stats.sessions, cost: stats.cost, input: stats.input, output: stats.output }),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/session-info\") {\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(\n\t\t\t\tJSON.stringify({\n\t\t\t\t\tid: session.sessionId,\n\t\t\t\t\tname: session.sessionManager.getSessionName(),\n\t\t\t\t\tfile: session.sessionFile,\n\t\t\t\t}),\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tif (req.method === \"GET\" && url === \"/api/messages\") {\n\t\t\tconst entries = session.sessionManager.getEntries();\n\t\t\tconst events: Record<string, unknown>[] = [];\n\n\t\t\tfor (const entry of entries) {\n\t\t\t\tif (entry.type !== \"message\") continue;\n\t\t\t\tconst msg = (entry as { message: { role: string; content: unknown; usage?: unknown } }).message;\n\t\t\t\tif (!msg) continue;\n\n\t\t\t\tif (msg.role === \"user\") {\n\t\t\t\t\tconst content = typeof msg.content === \"string\" ? msg.content : \"\";\n\t\t\t\t\tevents.push({ type: \"user\", text: content });\n\t\t\t\t} else if (msg.role === \"assistant\") {\n\t\t\t\t\tconst content = Array.isArray(msg.content) ? msg.content : [];\n\t\t\t\t\tfor (const block of content as Array<{ type: string; text?: string; toolCall?: unknown }>) {\n\t\t\t\t\t\tif (block.type === \"text\" && block.text) {\n\t\t\t\t\t\t\tevents.push({ type: \"text_delta\", delta: block.text });\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (block.type === \"toolCall\" && block.toolCall) {\n\t\t\t\t\t\t\tconst tc = block.toolCall as { toolCallId?: string; toolName?: string; input?: unknown };\n\t\t\t\t\t\t\tevents.push({\n\t\t\t\t\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\t\t\t\t\ttoolCallId: tc.toolCallId,\n\t\t\t\t\t\t\t\ttoolName: tc.toolName,\n\t\t\t\t\t\t\t\targs: tc.input,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (msg.role === \"toolResult\") {\n\t\t\t\t\tconst content = (msg as { toolCallId?: string; content?: Array<{ type: string; text?: string }> })\n\t\t\t\t\t\t.content;\n\t\t\t\t\tevents.push({\n\t\t\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\t\t\ttoolCallId: (msg as { toolCallId?: string }).toolCallId,\n\t\t\t\t\t\tresult: { content: content ?? [] },\n\t\t\t\t\t\tisError: false,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst usage = getSessionTokenCount(session);\n\t\t\tevents.push({ type: \"agent_end\", usage });\n\n\t\t\tres.writeHead(200, { \"content-type\": \"application/json\" });\n\t\t\tres.end(JSON.stringify(events));\n\t\t\treturn;\n\t\t}\n\n\t\tres.writeHead(200, { \"content-type\": \"text/html; charset=utf-8\" });\n\t\tres.end(HTML);\n\t});\n\n\tawait new Promise<void>((resolve, reject) => {\n\t\tserver.listen(port, \"0.0.0.0\", () => resolve());\n\t\tserver.on(\"error\", reject);\n\t});\n\n\tconst addr = server.address();\n\tif (!addr || typeof addr === \"string\") {\n\t\tconsole.error(\"Failed to start web server\");\n\t\treturn;\n\t}\n\n\tconst consolePort = `http://127.0.0.1:${addr.port}`;\n\tconst lan = getLocalIP();\n\tconsole.log(`\\n pi web UI: ${consolePort}`);\n\tif (lan !== \"127.0.0.1\") {\n\t\tconsole.log(` LAN: http://${lan}:${addr.port}`);\n\t}\n\tconsole.log(` session: ${session.sessionId.slice(0, 8)}`);\n\tconsole.log(\" (listening on all interfaces)\");\n\tif (PASSWORD) {\n\t\tconsole.log(` auth: Basic (user \"pi\", password from PI_WEB_PASSWORD)`);\n\t} else {\n\t\tconsole.log(\" auth: none (set PI_WEB_PASSWORD to enable)\");\n\t}\n\tconsole.log();\n\n\t// Keep process alive\n\tawait new Promise(() => {});\n\n\tserver.close();\n}\n\nfunction getSessionTokenCount(session: AgentSessionRuntime[\"session\"]): Record<string, unknown> | undefined {\n\tconst entries = session.sessionManager.getEntries();\n\tlet input = 0;\n\tlet output = 0;\n\tlet costTotal = 0;\n\tlet hasUsage = false;\n\tfor (const entry of entries) {\n\t\tif (entry.type !== \"message\") continue;\n\t\tconst msg = (\n\t\t\tentry as { message: { role: string; usage?: { input: number; output: number; cost: { total: number } } } }\n\t\t).message;\n\t\tif (msg?.role === \"assistant\" && msg.usage) {\n\t\t\tinput += msg.usage.input;\n\t\t\toutput += msg.usage.output;\n\t\t\tcostTotal += msg.usage.cost.total;\n\t\t\thasUsage = true;\n\t\t}\n\t}\n\treturn hasUsage ? { input, output, cost: { total: costTotal } } : undefined;\n}\n\nfunction toSerializableEvents(event: AgentSessionEvent): Record<string, unknown>[] {\n\tswitch (event.type) {\n\t\tcase \"agent_start\":\n\t\t\treturn [{ type: \"agent_start\" }];\n\t\tcase \"agent_end\": {\n\t\t\tconst lastAssistant = event.messages.filter((m) => m.role === \"assistant\").at(-1);\n\t\t\tconst usage = lastAssistant && \"usage\" in lastAssistant ? lastAssistant.usage : undefined;\n\t\t\treturn [{ type: \"agent_end\", usage }];\n\t\t}\n\t\tcase \"message_update\": {\n\t\t\tconst ame: Record<string, unknown> = event.assistantMessageEvent;\n\t\t\tconst serialized = serializeAssistantMessageEvent(ame);\n\t\t\treturn serialized;\n\t\t}\n\t\tcase \"tool_execution_start\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_start\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\ttoolName: event.toolName,\n\t\t\t\t\targs: event.args,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"tool_execution_update\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_update\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.partialResult,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"tool_execution_end\":\n\t\t\treturn [\n\t\t\t\t{\n\t\t\t\t\ttype: \"tool_execution_end\",\n\t\t\t\t\ttoolCallId: event.toolCallId,\n\t\t\t\t\tresult: event.result,\n\t\t\t\t\tisError: event.isError,\n\t\t\t\t},\n\t\t\t];\n\t\tcase \"compaction_start\":\n\t\tcase \"compaction_end\":\n\t\t\treturn [{ type: \"compaction\" }];\n\t\tdefault:\n\t\t\treturn [];\n\t}\n}\n\nfunction serializeAssistantMessageEvent(event: Record<string, unknown>): Record<string, unknown>[] {\n\tconst type = event.type as string;\n\tswitch (type) {\n\t\tcase \"start\":\n\t\t\treturn [{ type: \"agent_start\" }];\n\t\tcase \"text_start\":\n\t\t\treturn [{ type: \"text_start\", contentIndex: event.contentIndex }];\n\t\tcase \"text_delta\":\n\t\t\treturn [{ type: \"text_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"text_end\":\n\t\t\treturn [{ type: \"text_end\", content: event.content, contentIndex: event.contentIndex }];\n\t\tcase \"thinking_start\":\n\t\t\treturn [{ type: \"thinking_start\", contentIndex: event.contentIndex }];\n\t\tcase \"thinking_delta\":\n\t\t\treturn [{ type: \"thinking_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"thinking_end\":\n\t\t\treturn [{ type: \"thinking_end\", content: event.content, contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_start\":\n\t\t\treturn [{ type: \"toolcall_start\", contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_delta\":\n\t\t\treturn [{ type: \"toolcall_delta\", delta: event.delta, contentIndex: event.contentIndex }];\n\t\tcase \"toolcall_end\":\n\t\t\treturn [{ type: \"toolcall_end\", toolCall: event.toolCall, contentIndex: event.contentIndex }];\n\t\tcase \"done\":\n\t\t\treturn [{ type: \"done\", reason: event.reason }];\n\t\tcase \"error\":\n\t\t\treturn [{ type: \"error\", reason: event.reason }];\n\t\tdefault:\n\t\t\treturn [];\n\t}\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-custom-provider",
|
|
3
|
-
"version": "0.75.
|
|
3
|
+
"version": "0.75.25",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-custom-provider",
|
|
9
|
-
"version": "0.75.
|
|
9
|
+
"version": "0.75.25",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sdk": "^0.52.0"
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-sandbox",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.25",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-sandbox",
|
|
9
|
-
"version": "1.5.
|
|
9
|
+
"version": "1.5.25",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@anthropic-ai/sandbox-runtime": "^0.0.26"
|
|
12
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-extension-with-deps",
|
|
3
|
-
"version": "0.75.
|
|
3
|
+
"version": "0.75.25",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "pi-extension-with-deps",
|
|
9
|
-
"version": "0.75.
|
|
9
|
+
"version": "0.75.25",
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"ms": "^2.1.3"
|
|
12
12
|
},
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openeryc/pi-coding-agent",
|
|
3
|
-
"version": "0.75.
|
|
3
|
+
"version": "0.75.25",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@openeryc/pi-coding-agent",
|
|
9
|
-
"version": "0.75.
|
|
9
|
+
"version": "0.75.25",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@openeryc/pi-agent-core": "^0.75.
|
|
13
|
-
"@openeryc/pi-ai": "^0.75.
|
|
14
|
-
"@openeryc/pi-tui": "^0.75.
|
|
12
|
+
"@openeryc/pi-agent-core": "^0.75.25",
|
|
13
|
+
"@openeryc/pi-ai": "^0.75.25",
|
|
14
|
+
"@openeryc/pi-tui": "^0.75.25",
|
|
15
15
|
"@silvia-odwyer/photon-node": "0.3.4",
|
|
16
16
|
"chalk": "5.6.2",
|
|
17
17
|
"cross-spawn": "7.0.6",
|
|
@@ -699,11 +699,11 @@
|
|
|
699
699
|
]
|
|
700
700
|
},
|
|
701
701
|
"node_modules/@openeryc/pi-agent-core": {
|
|
702
|
-
"version": "0.75.
|
|
703
|
-
"resolved": "https://registry.npmjs.org/@openeryc/pi-agent-core/-/pi-agent-core-0.75.
|
|
702
|
+
"version": "0.75.25",
|
|
703
|
+
"resolved": "https://registry.npmjs.org/@openeryc/pi-agent-core/-/pi-agent-core-0.75.25.tgz",
|
|
704
704
|
"license": "MIT",
|
|
705
705
|
"dependencies": {
|
|
706
|
-
"@openeryc/pi-ai": "^0.75.
|
|
706
|
+
"@openeryc/pi-ai": "^0.75.25",
|
|
707
707
|
"ignore": "7.0.5",
|
|
708
708
|
"typebox": "1.1.38",
|
|
709
709
|
"yaml": "2.9.0"
|
|
@@ -713,8 +713,8 @@
|
|
|
713
713
|
}
|
|
714
714
|
},
|
|
715
715
|
"node_modules/@openeryc/pi-ai": {
|
|
716
|
-
"version": "0.75.
|
|
717
|
-
"resolved": "https://registry.npmjs.org/@openeryc/pi-ai/-/pi-ai-0.75.
|
|
716
|
+
"version": "0.75.25",
|
|
717
|
+
"resolved": "https://registry.npmjs.org/@openeryc/pi-ai/-/pi-ai-0.75.25.tgz",
|
|
718
718
|
"license": "MIT",
|
|
719
719
|
"dependencies": {
|
|
720
720
|
"@anthropic-ai/sdk": "0.91.1",
|
|
@@ -735,8 +735,8 @@
|
|
|
735
735
|
}
|
|
736
736
|
},
|
|
737
737
|
"node_modules/@openeryc/pi-tui": {
|
|
738
|
-
"version": "0.75.
|
|
739
|
-
"resolved": "https://registry.npmjs.org/@openeryc/pi-tui/-/pi-tui-0.75.
|
|
738
|
+
"version": "0.75.25",
|
|
739
|
+
"resolved": "https://registry.npmjs.org/@openeryc/pi-tui/-/pi-tui-0.75.25.tgz",
|
|
740
740
|
"license": "MIT",
|
|
741
741
|
"dependencies": {
|
|
742
742
|
"get-east-asian-width": "1.6.0",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openeryc/pi-coding-agent",
|
|
3
|
-
"version": "0.75.
|
|
3
|
+
"version": "0.75.25",
|
|
4
4
|
"description": "Coding agent CLI with read, bash, edit, write tools and session management",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"piConfig": {
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"prepublishOnly": "npm run clean && npm run build && npm run shrinkwrap"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@openeryc/pi-agent-core": "^0.75.
|
|
43
|
-
"@openeryc/pi-ai": "^0.75.
|
|
44
|
-
"@openeryc/pi-tui": "^0.75.
|
|
42
|
+
"@openeryc/pi-agent-core": "^0.75.25",
|
|
43
|
+
"@openeryc/pi-ai": "^0.75.25",
|
|
44
|
+
"@openeryc/pi-tui": "^0.75.25",
|
|
45
45
|
"@silvia-odwyer/photon-node": "0.3.4",
|
|
46
46
|
"chalk": "5.6.2",
|
|
47
47
|
"cross-spawn": "7.0.6",
|