teapot-coding-agent 0.31.1 → 0.31.2
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/dist/agent/agent.js +13 -2
- package/dist/agent/tools.js +25 -0
- package/package.json +1 -1
- package/public/assets/{index-BvL4IfaA.js → index-B8WP_cfK.js} +4 -4
- package/public/assets/{index-BvL4IfaA.js.map → index-B8WP_cfK.js.map} +1 -1
- package/public/assets/{shiki-B0FmuYpl.js → shiki-BSrXDQx7.js} +2 -2
- package/public/assets/{shiki-B0FmuYpl.js.map → shiki-BSrXDQx7.js.map} +1 -1
- package/public/index.html +1 -1
package/dist/agent/agent.js
CHANGED
|
@@ -10,7 +10,7 @@ import { promises as fs, existsSync, readFileSync, readdirSync, statSync } from
|
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import { EventLog, readEvents } from "../log/events.js";
|
|
12
12
|
import { chat, chatStream } from "./llm.js";
|
|
13
|
-
import { executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, hasRunningBgShells, killBgShells } from "./tools.js";
|
|
13
|
+
import { executeTool, toolSpecs, currentSkills, safeJoin, isContextOverflow, hasRunningBgShells, hasRunningBgShellsFor, killBgShells } from "./tools.js";
|
|
14
14
|
import { effortChoosable } from "./llm.js";
|
|
15
15
|
import { sessionTitleFrom } from "../session-title.js";
|
|
16
16
|
import { mcp } from "./mcp-registry.js";
|
|
@@ -542,6 +542,9 @@ export class Agent {
|
|
|
542
542
|
];
|
|
543
543
|
this.toolCtx = {
|
|
544
544
|
cwd: opts.workspace,
|
|
545
|
+
// so a background job records WHICH agent started it: sibling agents share a workspace,
|
|
546
|
+
// and `isLive()` must not count their jobs as this one's work in flight
|
|
547
|
+
agentId: opts.id,
|
|
545
548
|
defaultTimeoutMs: 120_000,
|
|
546
549
|
maxOutputBytes: 60_000,
|
|
547
550
|
skillRoots: this.skillRoots,
|
|
@@ -799,7 +802,15 @@ export class Agent {
|
|
|
799
802
|
// the operator most needs to stop. Note this is checked AFTER stopRequested:
|
|
800
803
|
// once stopped, the jobs are already dead, so `live` must go false or the
|
|
801
804
|
// button would offer stop forever (#133).
|
|
802
|
-
|
|
805
|
+
// OWNER-SCOPED, not directory-scoped. Sub-agents inherit their parent's workspace, so
|
|
806
|
+
// asking "does this DIRECTORY have background shells?" made every stopped sibling of a
|
|
807
|
+
// busy agent report `live: true`. MEASURED: four STOPPED sub-agents in one workspace
|
|
808
|
+
// showed `· ▶4` in the sidebar because the parent had background jobs, and their stop
|
|
809
|
+
// buttons offered to stop work that was already gone.
|
|
810
|
+
//
|
|
811
|
+
// `hasRunningBgShells(cwd)` is still the right question where the caller wants the
|
|
812
|
+
// DIRECTORY (parking a round, killing a workspace's jobs) — just not for `isLive()`.
|
|
813
|
+
hasRunningBgShellsFor(this.toolCtx.cwd, this.opts.id) ||
|
|
803
814
|
// ask_user: the loop is parked on the operator's answer — stoppable work
|
|
804
815
|
// in flight, not idleness. Without this the UI offered "start", and
|
|
805
816
|
// pressing it cleared awaitingUser, silently discarding the open question
|
package/dist/agent/tools.js
CHANGED
|
@@ -239,6 +239,7 @@ function startBackgroundShell(cmd, ctx) {
|
|
|
239
239
|
id, cmd, child,
|
|
240
240
|
out: "", truncated: false,
|
|
241
241
|
startedAt: Date.now(), exited: false, code: null,
|
|
242
|
+
owner: ctx.agentId ?? "",
|
|
242
243
|
};
|
|
243
244
|
const collect = (chunk) => {
|
|
244
245
|
if (sh.out.length < 200_000)
|
|
@@ -319,6 +320,30 @@ export function hasRunningBgShells(cwd) {
|
|
|
319
320
|
}
|
|
320
321
|
return false;
|
|
321
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* Does THIS agent have a background job still running?
|
|
325
|
+
*
|
|
326
|
+
* `hasRunningBgShells(cwd)` answers for a DIRECTORY, which is the right question for
|
|
327
|
+
* `killBgShells` and the wrong one for "is this agent busy". Sub-agents inherit their parent's
|
|
328
|
+
* workspace, so a shared directory made every sibling of a busy agent report `live: true` —
|
|
329
|
+
* MEASURED: four STOPPED sub-agents showed `· ▶4` because the parent had background jobs, and
|
|
330
|
+
* their stop buttons offered to stop work that was already gone.
|
|
331
|
+
*
|
|
332
|
+
* An empty owner means a job started before owners were recorded; those are treated as
|
|
333
|
+
* belonging to nobody, so they cannot make an unrelated agent look busy.
|
|
334
|
+
*/
|
|
335
|
+
export function hasRunningBgShellsFor(cwd, owner) {
|
|
336
|
+
const m = bgShellsByWs.get(cwd);
|
|
337
|
+
if (!m || !owner)
|
|
338
|
+
return false;
|
|
339
|
+
for (const sh of m.values()) {
|
|
340
|
+
if (sh.exited)
|
|
341
|
+
continue;
|
|
342
|
+
if (sh.owner === owner)
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
return false;
|
|
346
|
+
}
|
|
322
347
|
/**
|
|
323
348
|
* Kill every background shell for one workspace and forget the jobs (#158).
|
|
324
349
|
*
|
package/package.json
CHANGED
|
@@ -21,10 +21,10 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
|
|
|
21
21
|
- task two"title="shared with the agent \\u2014 it may check items off via set_todo; your unsaved edits win until you save">`),fp=L(`<span class=fsize>`),pp=L(`<div><span class=ficon></span><span class=fname>`),mp=L(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview"style=display:flex;align-items:center;gap:6px>🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),hp=L(`<div class=filebox>`),gp=L(`<div class=muted style=padding:6px>`),_p=L(`<img>`),vp=L(`<div class=mediapreview><div class="meta muted"> preview`),yp=L(`<button title="rendered markdown">👁 preview`),bp=L(`<button title="edit and save back to the workspace">✎ edit`),xp=L(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),Sp=L(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Cp=L(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),wp=L(`<div class="content mdpreview">`),Tp=L(`<video controls>`),Ep=L(`<audio controls>`),Dp=L(`<div class=filepreview>`),Op=L(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),kp=L(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),Ap=L(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),jp=L(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),Mp=L(`<div class=wizmodels>`),Np=L(`<span style=color:var(--fg)>`),Pp=L(`<div class=muted style=font-size:11.5px;margin-top:-6px> model`),Fp=L(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),Ip=L(`<button type=button>`),Lp=L(`<div class=muted style=font-size:11.5px;margin-top:-8px>`),Rp=L(`<button type=button><span class=mono>`),zp=L(`<label><input type=number min=0>`),Bp=L(`<div class=muted style=font-size:11.5px;margin-top:4px>⚠ configured default provider <code></code> has no provider row here<!> Add a provider named <code></code> or pick a default below; otherwise agents fall back to the first provider.`),Vp=L(`<form style=display:flex;flex-direction:column;gap:12px;min-height:0><div class=cfgbody><nav class=cfgmenu aria-label="settings sections"></nav><div class=cfgpanel><fieldset><legend>providers</legend><button type=button>+ add custom</button><div style=display:flex;gap:6px;flex-wrap:wrap;margin-top:6px><span class=muted style=font-size:11.5px>quick-add:</span></div><div><label title="agents without an explicit provider use this one"style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<select><option value>(none — first provider wins)</option></select></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid><label title="auto-compact threshold in k tokens. Leave EMPTY to derive per model (75% of its context window) — recommended, since models differ wildly in window size. Set only to force an absolute cap across all models.">compact budget (k tok)<input type=number min=0 placeholder="(derive: 75% of window)"></label></div><label class=cfgtoggle title="prune old tool output early (at 60% of the budget) instead of waiting for the window to fill. Meant for small-window models — on a large window it throws away context you had room for."><input type=checkbox>short-context mode (#161)<span class=muted style=font-size:11px>— prune old tool output early; for 32k–262k windows, not large ones</span></label></fieldset><fieldset><legend>MCP servers — external tools, shared by every agent</legend><div class=muted style=font-size:11.5px;margin-bottom:8px>each tool becomes <code class=mono>mcp__server__tool</code> for every agent. saving connects them; the status shown here is live.</div><button type=button>+ add MCP server</button></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>archived agents — restore, or delete for good</legend></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><fieldset><legend>live update</legend><div class=cfgrow><span class=muted>current version: </span><button type=button style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">update & restart</button><span class=muted style=margin-left:8px;font-size:12px>gracefully stops all agents, spawns new process, then reloads this page</span></div></fieldset></div></div><div class=cfgfoot><button type=submit class=cfgsave>save settings`),Hp=L(`<button type=button><span class=cfgmenu-label>`),Up=L(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="default model"><button type=button class=danger title="remove provider">✕</button><div class=cfgkeys><button type=button title="add another key for this provider — they are rotated round-robin, and a rate-limited key is skipped for a minute">+ key`),Wp=L(`<button type=button title="remove this key">−`),Gp=L(`<div class=cfgkeyrow><input type=password>`),Kp=L(`<button type=button>+ `),qp=L(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),Jp=L(`<input placeholder="command (e.g. npx)">`),Yp=L(`<input placeholder="args, space separated">`),Xp=L(`<button type=button class=archrestore title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),Zp=L(`<span class="mcpstate connected"title="an OAuth access token is usable">🔑 authorized`),Qp=L(`<button type=button title="forget the stored grant (the refresh token is deleted)">disconnect`),$p=L(`<div class=muted style=font-size:11px;color:var(--warn)>`),em=L(`<div class=mcpresult>`),tm=L(`<div class="cfgcol mcpcard"><div class=cfgrow><input class=cfgname placeholder=name title="the name that appears inside mcp__<name>__ in tool names"><input placeholder="https://example.com/mcp (or leave empty for a stdio command)"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>on</label><button type=button class=danger>✕</button></div><div class=cfgrow><select title="streamable HTTP is the current spec; legacy SSE is the 2024-11-05 handshake; stdio spawns a local process"><option value=http>streamable http</option><option value=sse>legacy http+sse</option><option value=stdio>stdio (local command)</option></select></div><div class=cfgrow><input placeholder="headers as JSON, e.g. {"Authorization":"Bearer …"}"title="static headers for every request — the local equivalent of a token store"><button type=button title="connect now and list the tools — nothing is saved">test`),nm=L(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),rm=L(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),im=L(`<div class="cfgrow archrow"><div class=archmain><b></b><span class=muted> session</span><span class="muted mono ellip"></span></div><button type=button class=archrestore title="bring it back and start it again — its history was never touched">↩ restore</button><button type=button class=danger title="erase the config entry AND every session directory — irreversible">🗑 delete`),am=L(`<span class=muted>🧩 sub of @`),om=L(`<div class=cfgrow><b></b><span class=muted>`),sm=new Map;function cm(e){let t=sm.get(e);if(t!==void 0)return t;let n=Pe(e);return sm.set(e,n),sm.size>500&&sm.delete(sm.keys().next().value),n}var lm=[`minimal`,`low`,`medium`,`high`],um=1100,dm={prompt:{name:`you`,icon:`🟧`,color:`#faa81a`},user:{name:`you`,icon:`🟧`,color:`#faa81a`},message:{name:`agent`,icon:`🫖`,color:`#5865f2`},progress:{name:`progress`,icon:`📈`,color:`#3ba55d`},question:{name:`agent`,icon:`❓`,color:`#5865f2`}},fm={name:`harness`,icon:`📣`,color:`#3ba55d`},[pm,mm]=v(``),hm,Q=e=>{mm(e),clearTimeout(hm),hm=setTimeout(()=>mm(``),3200)},gm=!1,_m=[{key:`dark`,label:`Dark`,mode:`dark`,sw:[`#1a1c22`,`#2b2e39`,`#5865f2`]},{key:`midnight`,label:`Midnight`,mode:`dark`,sw:[`#0d0f18`,`#252a42`,`#8b7cf7`]},{key:`tea`,label:`Milk Tea`,mode:`dark`,sw:[`#241c16`,`#493b2d`,`#d98e32`]},{key:`coffee`,label:`Coffee`,mode:`dark`,sw:[`#191410`,`#403527`,`#c68a4b`]},{key:`matcha`,label:`Matcha`,mode:`dark`,sw:[`#1b2217`,`#3c4a33`,`#8db64e`]},{key:`matrix`,label:`Matrix`,mode:`dark`,sw:[`#060a06`,`#18301d`,`#2fd558`]},{key:`sunset`,label:`Sunset`,mode:`dark`,sw:[`#1c1422`,`#452f52`,`#f2784b`]},{key:`light`,label:`Light`,mode:`light`,sw:[`#eceef4`,`#ffffff`,`#4757d8`]},{key:`strawberry`,label:`Strawberry`,mode:`light`,sw:[`#fbe4ea`,`#fffafb`,`#e05575`]},{key:`ramune`,label:`Ramune`,mode:`light`,sw:[`#ddeff7`,`#fbfeff`,`#1d86ae`]}],vm=e=>{if(e.data?.actor)return{name:`@${String(e.data.actor)}`,icon:`🧩`,color:`#3ba0c9`};if(e.type===`tool_call`||e.type===`tool_result`)return{name:String(e.data?.name??`tool`),icon:`⚙`,color:`#3ba0c9`};if(e.type===`prompt`){let t=String(e.data?.source??`user`);return t===`user`?dm.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:fm}return dm[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},ym=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),bm=new Set([`system_note`]),xm=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`]),Sm=new Set([`runaway-detected`,`error-retry`,`background-exit`,`context-compacted`,`context-compaction-started`]),Cm=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=null;try{t=await i.json()}catch{}let n=(t&&typeof t==`object`&&`error`in t?String(t.error):``)||`${e}: HTTP ${i.status}`;throw Object.assign(Error(n),{payload:t})}return i.json()}var wm=location.hash.match(/[#&]token=([^&]+)/);wm&&(localStorage.setItem(`teapot.token`,decodeURIComponent(wm[1])),history.replaceState(null,``,location.pathname+location.search));var Tm=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function Em(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v(``),[o,s]=v(new Map),[c,l]=v(new Map),[u,d]=v(new Map),f=!1;async function p(e=!1){if(!f||e){f=!0;try{let e=await $(`/api/sessions`),t=new Map,n=new Map,r=new Map;for(let i of e.sessions??[]){t.set(i.id,i.agentId),typeof i.title==`string`&&i.title&&r.set(i.id,i.title);let e=n.get(i.agentId)??[];e.push(i.id),n.set(i.agentId,e)}s(t),l(n),d(r)}catch{}}}let[m,h]=v([]),[g,_]=v(0),[w,T]=v([]),[E,te]=v(null),D=new Map,[ne,re]=v(D.get(n()??``)??``),O=e=>{re(e);let t=n();t&&(e?D.set(t,e):D.delete(t))},[k,ie]=v({providers:{}}),[A,ae]=v(!1),[oe,se]=v(!1),j=()=>window.innerWidth<=um,[ce,le]=v(j());ee(()=>{let e=()=>le(j());window.addEventListener(`resize`,e),C(()=>window.removeEventListener(`resize`,e)),e()});let M,ue,de=0,fe=``,pe=()=>{de=0;let e=K();if(!e)return;if(ct()){Pr();return}let t=ge(e);if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;r&&(e.scrollTop+=r),_t(Mr())},me=()=>{de||=requestAnimationFrame(pe)},he=e=>{e&&e!==ue&&(M??=new ResizeObserver(e=>{let t=e[0]?.contentRect,n=t?`${Math.round(t.width)}x${Math.round(t.height)}`:``;n!==fe&&(fe=n,me())}),ue&&M.unobserve(ue),ue=e,fe=``,M.observe(e))};ee(()=>{window.addEventListener(`resize`,me),C(()=>{window.removeEventListener(`resize`,me),M?.disconnect(),M=void 0,ue=void 0,de&&cancelAnimationFrame(de)})});function ge(e){let t=e.querySelectorAll(`[data-eid]`);if(!t.length)return null;let n=e.getBoundingClientRect().top,r=e=>t[e].getBoundingClientRect(),i=0,a=t.length-1,o=-1;for(;i<=a;){let e=i+a>>1;r(e).bottom>n?(o=e,a=e-1):i=e+1}if(o<0)return null;let s=t[o].dataset.eid??``;return s?{sel:`[data-eid="${CSS.escape(s)}"]`,top:r(o).top}:null}let[_e,ve]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>um:localStorage.getItem(`teapot.panel`)===`1`),ye=e=>{ve(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},be=()=>ye(!_e()),xe=()=>{_e()&&ye(!1)},[L,Se]=v(!1),[Ce,De]=v(localStorage.getItem(`teapot.theme`)??`dark`),[Oe,ke]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[Ae,je]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[Me,Ne]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),Fe=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[Ie,Le]=v(Fe?.matches??!1);ee(()=>{let e=e=>Le(e.matches);Fe?.addEventListener(`change`,e),C(()=>Fe?.removeEventListener(`change`,e))}),b(()=>{let e=Oe()?Ie()?Ae():Me():Ce();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=_m.find(t=>t.key===e)?.mode??`dark`}),b(()=>{localStorage.getItem(`teapot.feedCv`)===`0`?delete document.documentElement.dataset.feedcv:document.documentElement.dataset.feedcv=`on`});let[Re,ze]=v(``),[Ue,Ge]=v(``),[Xe,Ze]=v(``);b(()=>{let t=n();Ze(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[Qe,$e]=v([]),et=()=>Object.keys(k().providers??{});async function tt(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);$e(t.models??[])}catch{$e([])}}let nt=e=>{let t={text:`📄`,image:`🖼️`,audio:`🔊`,video:`🎬`,file:`📎`},n=e=>(e??[`text`]).map(e=>t[e]??e).join(``);return e?.modalities?`${n(e.modalities.input)} → ${n(e.modalities.output)}`:``},rt=()=>{let e=Ue().trim()||H()?.model||``;if(!e)return``;let t=Qe().find(t=>t.id===e);if(!t)return``;let n=[],r=nt(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${Im(t.contextLength)} tok`);let i=e=>e===void 0?``:`${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=i(t.pricing.prompt),r=i(t.pricing.completion);e&&r?n.push(`${e} in · ${r} out`):(e||r)&&n.push(i(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},it=null,at=!1;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||k().defaultProvider||et()[0]||``;if(r){if(t!==it)it=t,at=!1,S(()=>Re())!==i&&(ze(i),tt(i)),S(()=>Ue())&&Ge(``);else{let e=S(()=>Re());!S(()=>Ue())&&e!==i&&Wt(at)&&(ze(i),tt(i))}}});let[ot,st]=v(!1),[ct,lt]=v(!0),[ut,ft]=v(0),[mt,ht]=v(-1),_t=e=>ht(e?qt(e):-1),[wt,Tt]=v(null),Et=()=>Vt().startsWith(`[compact] `),Dt=()=>Et()?Vt().slice(10):Vt();b(()=>{wt()||zt(e=>e?.text.startsWith(`[compact] `)?null:e)}),b(()=>{wt(),requestAnimationFrame(()=>requestAnimationFrame(()=>{ct()&&Pr()}))});let[jt,Lt]=v(new Map),Rt=()=>{let e=n();return e?jt().get(e)??null:null},zt=e=>{let t=n();t&&Lt(n=>{let r=new Map(n),i=typeof e==`function`?e(n.get(t)??null):e;return i?r.set(t,{...i,at:Date.now()}):r.delete(t),r})},[Vt,Xt]=v(``),[Zt,Qt]=v(0),$t=()=>Zt(),[V,en]=v(``),tn;b(()=>{Rt()?tn||=setTimeout(()=>{tn=void 0,Xt(Rt()?.text??``),en(Rt()?.reasoning??``)},(Rt()?.text.length??0)>2e4?250:(Rt()?.text.length??0)>6e3?120:60):(clearTimeout(tn),tn=void 0,Xt(``),en(``))}),C(()=>clearTimeout(tn)),b(()=>{let t=e();Lt(e=>qe(e,e=>t.find(t=>t.id===e)?.status)),Qt(e=>Ye(e,t,n(),Rt()))}),b(()=>{let e=Vt(),t=Rt()?.reasoning??``;(e||t)&&requestAnimationFrame(()=>{ct()&&Pr()})}),b(()=>{let e=H()?.pendingPrompts??0,t=H()?.pendingPromptIds,n=un(),r=dn(n),i=kt(r,e,t);i!==r&&fn(n,i)}),b(()=>{let e=H()?.pendingPromptQueue;if(!e?.length)return;let t=un(),n=new Set(dn(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&fn(t,[...r.map(e=>({id:`p${e.id}`,text:e.text,at:Number(e.at)||Date.now(),promptId:e.id,images:e.images?.map(e=>e.url),...e.source?{source:e.source}:{}})),...dn(t)])}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{Nr()&&(lt(!0),ft(0),Fr(!0),xn())})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let H=x(()=>e().find(e=>e.id===n())),nn=()=>{let e=H();return e?e.live??(e.status===`running`||e.status===`waiting`):!1},rn=()=>Pt(H(),i(),nn()),[an,on]=v(null);x(()=>{let e=new Set;for(let t of m())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let sn=new Map,[cn,ln]=v([]),un=()=>i()||n()||`?`,dn=e=>sn.get(e)??[],fn=(e,t)=>{let n=new Set,r=[];for(let e=t.length-1;e>=0;e--){let i=t[e],a=i.promptId;a?n.has(a)||(n.add(a),r.push(i)):r.push(i)}r.reverse(),r.length===0?sn.delete(e):sn.set(e,r),un()===e&&ln(r)},[pn,mn]=v([]),[hn,gn]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[_n,vn]=v(!1),yn=()=>pn().filter(e=>!e.read).length,bn=e=>{mn(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},xn=()=>{let e=n();e&&pn().some(t=>!t.read&&t.agentId===e)&&bn(e)},Sn=t=>{let n=pn().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Sn(r.id));return n},Cn=0,wn=e=>{mn(t=>[{...e,id:`n${++Cn}`,at:Date.now(),read:!1},...t].slice(0,50))},Tn=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t,i=typeof n.id==`string`?n.id:void 0;n.type===`message`&&n.data?.final===!0?wn({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?wn({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?wn({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&wn({agentId:t,kind:`progress`,title:`${r}: ${String(n.data.doing??`progress`)}`.slice(0,120),body:[n.data.recent&&`recent: ${n.data.recent}`,n.data.next&&`next: ${n.data.next}`].filter(Boolean).join(` · `).slice(0,300),eventId:i})},En=e=>{let t=document.querySelector(`[data-eid="${e}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`flash-target`),setTimeout(()=>t.classList.remove(`flash-target`),1600))},Dn=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of m())if(ym.has(i.type)){if(i.type===`tool_call`){let e=n.get(i.data.callId)??[];e.push(i),n.set(i.data.callId,e)}else if(i.type===`tool_result`){let a=n.get(i.data.callId)?.shift();a?(e.set(a.id,i),t.add(i.id)):r.set(i.id,i)}}return{resFor:e,consumed:t,orphanCalls:r}}),[On,kn]=v(new Set),An=e=>{e&&kn(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},jn=()=>kn(new Set),Mn=x(()=>Ot(m(),On())),Nn=x(()=>dt({events:m(),consumed:Dn().consumed,pending:cn(),echo:Ln,feedTypes:ym,renderedTypes:xm,renderedNoteEvents:Sm})),Pn=x(()=>{let e=new WeakMap;return Nn().forEach((t,n)=>e.set(t,n)),e}),Fn=(e,t)=>{let n=Pn().get(e);if(n!==void 0)return Nn()[n+t]},In=new Map;function Ln(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=In.get(t);if(n)return n;In.size>64&&In.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:H()?.session??``,branch:H()?.branch??`br0`,parent:null,type:`prompt`,data:{source:e.source??`user`,text:e.text,pending:!e.sent,...e.images?.length?{images:e.images}:{},...e.promptId?{promptId:e.promptId}:{}}};return In.set(t,r),r}let Rn=()=>$(`/api/config`).then(ie).catch(()=>{}),[zn,Bn]=v(!1);ee(()=>{let e=()=>Bn(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[Vn,Hn]=v(``),[Un,Wn]=v(!0),[Gn,Kn]=v(!1),qn=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==qn?(qn=t,Kn(!1),Hn(r)):t&&!Gn()&&Hn(r)});let Jn=async()=>{let e=document.getElementById(`todo-notify`)?.checked??!0;if(n())try{await $(`/api/agents/${n()}/todo`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:Vn(),notify:e})}),Kn(!1),Wn(!0),Q(`tasks saved${e&&Vn().trim()?` & notification queued`:``}`),Zn()}catch(e){Q(`save failed: ${e.message}`)}},Yn=x(()=>{let e=0,t=0;for(let n of Vn().split(`
|
|
22
22
|
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}});function Xn(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})}let Zn=()=>$(`/api/agents`).then(e=>{let n=!1;t(t=>(t.length!==(e.agents??[]).length&&(n=!0),(e.agents??[]).some(e=>!t.some(t=>t.id===e.id))&&(n=!0),Xn(t,e.agents??[]))),n&&p()}).catch(()=>{}),Qn=()=>$(`/api/metrics`).then(te).catch(()=>{}),[$n,er]=v([]),tr=()=>$(`/api/tasks`).then(e=>er(e.tasks)).catch(()=>{}),nr=e=>$n().filter(t=>t.agent===e),[rr,ir]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.expandedSubs`)??`[]`);return new Set(e.filter(e=>typeof e==`string`))}catch{return new Set}})()),[ar,or]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`);return new Set(e.filter(e=>typeof e==`string`&&!e.startsWith(`chat:`)))}catch{return new Set}})()),sr=e=>ar().has(e)||!rr().has(e),cr=e=>{let t=new Set(rr());if(t.has(e)?t.delete(e):t.add(e),ir(t),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...t])),t.has(e)&&ar().has(e)){let t=new Set(ar());t.delete(e),or(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))}},lr=t=>xt(e(),t),[ur,dr]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.wsCollapsed`)??`[]`),t=Array.isArray(e)?e.filter(e=>typeof e==`string`):[];if(Number(localStorage.getItem(`teapot.wsCollapsed.v`)??`0`)<2){let e=t.filter(e=>!e.startsWith(`chat:`));return t.length-e.length>0&&localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify(e)),localStorage.setItem(`teapot.wsCollapsed.v`,`2`),new Set(e)}return new Set(t)}catch{return new Set}})()),U=x(()=>{let e=new Set;for(let t of ur())t.startsWith(`chat:`)&&e.add(t);return e}),fr=x(()=>gt(e(),new Set(e().filter(e=>sr(e.id)).map(e=>e.id)),hn(),U())),pr=(t,r,i,a)=>{let o=new Set(ur());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||lr(e().find(e=>e.id===i))===t)&&Q(`hid ${r} — click the header to show it`)}dr(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},W=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,mr=e=>{let t=hr().get(e)??0;return`${t} chat${t===1?``:`s`}`},hr=x(()=>St(e())),gr=x(()=>Ct(e(),fr(),ur())),G=2e3,[_r,vr]=v(null),yr=new Map;function br(e){return`${i()||(n()??`?`)}:${e.id}`}function xr(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=br(r),a=yr.get(i);if(t[n]=a??r,!a&&(yr.set(i,r),yr.size>6e3)){let e=yr.keys().next().value;e!==void 0&&yr.delete(e)}}return t}let[Sr,Cr]=v(!1),[wr,Tr]=v(!1),Er=0,Dr=-1;function Or(e){let t=xr(e);h(e=>{if(t.length>0&&e.length>0){let n=e[e.length-1],r=t.every(e=>e.seq>n.seq),i=new Set(e.map(e=>e.id));if(r&&t.every(e=>!i.has(e.id)))return[...e,...t]}let n=new Map;for(let t of e)n.set(t.id,t);let r=!1;for(let e of t)n.has(e.id)||(n.set(e.id,e),r=!0);return r?[...n.values()].sort((e,t)=>e.seq-t.seq):e})}async function kr(){let e=n();if(!e||wr()||Sr())return;if(m().length>=g()){Tr(!0);return}let t=()=>{let e=K();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!wr()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(m().length>=g()){Tr(!0);return}let i=m().length;if(await Ar(),m().length===i)return;Jt(Mr())&&n()===e&&Fr(!0)}}async function Ar(){let e=n(),t=m()[0];if(e&&t&&!Sr()&&!wr()){Cr(!0);try{let r=K(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=_r(),c=i(),l=c&&c!==e?`&session=${encodeURIComponent(c)}`:``,u=(await $(`/api/agents/${e}/events?limit=${G}&before=${encodeURIComponent(t.id)}${l}${s?`&branch=${encodeURIComponent(s)}&lineage=true`:``}`)).events??[];if(u.length===0){Tr(!0);return}if(n()!==e||m()[0]?.id!==t.id)return;Or(u),requestAnimationFrame(()=>{if(n()===e){let e=K();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{Cr(!1)}}}async function jr(e,t){let r=Er,a=t??i()??``;try{let t=_r(),i=r!==Dr||!w().length,o=a&&a!==e?`&session=${encodeURIComponent(a)}`:``,[s,c,l]=await Promise.all([$(`/api/agents/${e}/events?limit=${G}${o}${t?`&branch=${encodeURIComponent(t)}&lineage=true`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:w()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(Dr=r),r!==Er||n()!==e)return;h(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of xr(s.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),_(s.total??s.events.length),T(c.branches),Ri(l.skills??[])}catch{}}function K(){return document.querySelector(`.feed`)}function Mr(){let e=K();return e?{top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight}:null}function Nr(){return Jt(Mr())}function Pr(){let e=K();e&&(e.scrollTop=e.scrollHeight,ft(0))}function Fr(e=!1){(e||ct())&&Pr()}let Ir=new Map,Lr=(t,n)=>At(c().get(t),e().find(e=>e.id===t)?.session,n);async function Rr(e,t=!0,o){let s=n(),l=i(),u=m(),d=g();Er++,c().size||p();let f=Lr(e,o)??e;if(s!==e||f!==l){if(l&&u.length&&(Ir.set(l,{events:u,total:d,at:Date.now()}),Ir.size>6)){let e=[...Ir.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&Ir.delete(e[0])}h([]),yr.clear(),jn(),Tt(null),ft(0),lt(!0),Wi=void 0}r(e),a(f),O(D.get(e)??``),vr(null),Tr(!1),Cr(!1),fn(l||s||`?`,cn()),ln(dn(f||e)),localStorage.setItem(`teapot.session`,e),Xr(f,t);let v=Ir.get(f);v?.events.length&&(xr(v.events),h(xr(v.events)),_(v.total),requestAnimationFrame(()=>{n()===e&&Fr(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(Zn).catch(()=>{}),await jr(e,f),n()===e&&(Lt(t=>{let n=t.get(e)??null,r=Je(n,m(),H()?.status);if(r===n)return t;let i=new Map(t);return r?i.set(e,r):i.delete(e),i}),Tt(H()?.ctx?.compacting?{phase:String(H().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&Fr(!0)}),kr())}let[zr,Br]=v(!1),Vr=null,Hr=null;C(()=>Vr?.close());let Ur=!1,Wr=null;document.addEventListener(`visibilitychange`,()=>Wr?.()),C(()=>{Wr=null});let Gr=!0,Kr=null;async function qr(){let e=n(),t=m().at(-1)?.id,r=i(),a=document.visibilityState===`hidden`;if(!e||!t)Ur=!0,a||Kr?.();else try{let n=r&&r!==e?`&session=${encodeURIComponent(r)}`:``,i=_r(),o=await $(`/api/agents/${e}/events?after=${encodeURIComponent(t)}${n}${i?`&branch=${encodeURIComponent(i)}&lineage=true`:``}`),s=o.events??[];o.gap?(h(xr(s)),_(s.length)):s.length&&(Or(s),_(e=>e+s.length)),await Zn(),s.length&&!a&&Qn()}catch{Ur=!0}}function Jr(){Gr=!0;let r=location.protocol===`https:`?`wss://`:`ws://`,a=new WebSocket(`${r}${location.host}/api/ws${Tm()}`);Vr=a,a.onopen=()=>{Br(!0),Gr?Gr=!1:qr()},a.onclose=()=>{Br(!1),setTimeout(Jr,1500)},a.onerror=()=>a.close();let o=new Set([`state`,`usage`,`session_start`]);a.onmessage=r=>{let c=JSON.parse(r.data);if(c.kind===`ping`)try{a.send(JSON.stringify({kind:`pong`}))}catch{}else if(c.kind!==`pong`){if(c.kind===`hello`&&Array.isArray(c.agents)){t(e=>Xn(e,c.agents));let n=e();Lt(e=>qe(e,e=>n.find(t=>t.id===e)?.status))}else if(c.kind===`event`&&He(c.event))Lt(e=>Ve(e,c.agentId));else if(c.kind===`llm-delta`){if(!Nt(c,n(),i()))return;if(Lt(e=>Be(e,c.agentId,c)),c.agentId===n()){let e=String(c.reasoning??``),t=String(c.text??``);e&&!t?Zt()||Qt(Date.now()):t&&Qt(0)}}else if(c.kind===`compaction-progress`){if(c.agentId!==n())return;c.phase===`done`?Tt(null):Tt({phase:c.phase,summarized:c.summarized})}else if(c.kind===`agent-update`&&c.snapshot)t(e=>{let t=e.findIndex(e=>e.id===c.snapshot.id),n=c.snapshot;return t===-1?[...e,n]:Xn(e,e.map((e,n)=>n===t?c.snapshot:e))});else{if(c.kind===`event`){let e=c.event?.type,t=c.event?.data??{};if((e===`system_note`&&t.event===`prompt-delivered`&&c.agentId===n()||e===`system_note`&&t.event===`prompt-cancelled`&&c.agentId===n())&&fn(un(),cn().filter(e=>e.promptId!==t.promptId)),o.has(e)&&!bm.has(e)||(Tn(c.agentId,c.event),c.event?.agent!==n())||!Mt(c.event,n(),i()))return;if(Or([c.event]),c.event?.type===`message`&&c.event.data?.role===`assistant`){let e=Rt();e&&We(e,m(),H()?.status)&&zt(null)}if(Ur=!0,document.visibilityState!==`visible`||Hr)return;Hr=setTimeout(s,60)}document.visibilityState===`hidden`?Ur=!0:Hr||=setTimeout(s,120)}}},Ur=!1;let s=async()=>{if(Hr=null,await Zn(),await Qn(),n()){let e=m().at(-1)?.id,t=m().length;await jr(n());let r=Rt();r&&!Je(r,m(),H()?.status)&&zt(null),m().at(-1)?.id!==e&&(ct()?(Pr(),bn(n())):(ft(e=>e+Math.max(0,m().length-t)),_t(Mr())))}};Kr=s,Wr=()=>{document.visibilityState===`visible`&&n()&&(Ur?(Ur=!1,s()):m().at(-1)?.id?qr():(Ur=!0,s()))}}let Yr=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function Xr(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=Yr(),t=o().get(e);t&&(t!==n()||e!==i())&&Rr(t,!1,e||null)}),b(()=>{let e=H(),t=e?`${nn()?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=yn()>0?`(${yn()}) ${t}`:t});let Zr=()=>A()||oe()||L()||an()!==null||j()&&_e();window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable))e.key===`Escape`&&t.blur();else if(e.key===`Escape`){if(A()){ae(!1);return}if(oe()){se(!1);return}if(L()){Se(!1);return}if(an()){on(null);return}if(j()&&_e()){xe();return}let e=H();if(e&&nn()){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(Zn);return}}else if(!Zr()){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)be();else if(e.key===`t`)ei();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=fr().map(e=>e.a);if(t.length===0)return;e.preventDefault();let r=t.findIndex(e=>e.id===n()),i=e.key===`ArrowDown`?Math.min(r+1,t.length-1):Math.max(r-1,0);i!==r&&Rr(t[i].id)}}});let[Qr,$r]=v(localStorage.getItem(`teapot.term`)===`1`),ei=()=>{let e=!Qr();$r(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[ti,ni]=v([]),[ri,ii]=v(0),[ai,oi]=v(-1),[si,ci]=v(!1),[li,ui]=v(0),[di,fi]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),pi=new Map,mi=0,hi=[null,null],gi=()=>ti()[li()===0?ri():ai()]??null;function _i(e){if(!ti()[e])return;let t=li(),n=t===0?ri():ai(),r=t===0?ai():ri(),i=e=>t===0?ii(e):oi(e);r===e?((e=>t===0?oi(e):ii(e))(n),i(e)):n!==e&&i(e)}let vi=()=>yi();function yi(e){let t=e??n();if(!t)return;let r=ti().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}let i={key:`${t}#${++mi}`,agentId:t,title:r===0?t:`${t}·${r+1}`},a=Wl(ti());ni(e=>[...e,i]),li()===0?ii(a):oi(a)}function bi(e){let t=ti()[e];if(!t)return;let n=pi.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),pi.delete(t.key)}let r=ti().filter((t,n)=>n!==e);ni(r),ii(t=>Kl(t,e,r.length)),oi(t=>t===-1?-1:Kl(t,e,r.length))}b(()=>{Oe(),Ce(),Ie(),Ae(),Me();for(let[,e]of pi)It(e.term)});function xi(){for(let[,e]of pi){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}pi.clear()}function Si(e,t){let n=pi.get(e.key);if(n&&It(n.term),n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new Bl({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:Ft()}),a=new Ul;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${Tm()}`);s.onmessage=e=>{let t=JSON.parse(e.data);t.kind===`data`?i.write(t.data):t.kind===`exit`&&i.write(`\r\n\x1b[2m[terminal exited ${t.code??``}]\x1b[0m\r\n`)},i.onData(e=>{s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({kind:`input`,data:e}))});let c={cols:0,rows:0},l=[],u=()=>{try{a.fit()}catch{}(i.cols!==c.cols||i.rows!==c.rows)&&s.readyState===WebSocket.OPEN&&(c={cols:i.cols,rows:i.rows},s.send(JSON.stringify({kind:`resize`,cols:i.cols,rows:i.rows})))},d=new ResizeObserver(()=>{l[0]&&clearTimeout(l[0]),l[0]=setTimeout(u,250)});d.observe(r),setTimeout(u,60),n={el:r,term:i,fit:a,ws:s,ro:d},pi.set(e.key,n)}return n}function Ci(e){let t=hi[e];if(!t)return;let n=ti()[e===0?ri():ai()];if(!n){[...pi.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Si(n,t);for(let[e,r]of pi)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(li()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{ti(),si(),ri(),ai(),di(),requestAnimationFrame(()=>{Ci(0),si()&&Ci(1)})});let wi=null;b(()=>{if(!Qr())return;let e=n();if(e&&e!==wi){if(wi=e,!ti().some(t=>t.agentId===e))yi(e);else{let t=-1;ti().forEach((n,r)=>{n.agentId===e&&(t=r)}),t>=0&&_i(t)}}});let Ti=e=>{e.preventDefault();let t=e.clientY,n=di(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));fi(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(di())),requestAnimationFrame(()=>{Ci(0),si()&&Ci(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},Ei=()=>{let e=!si();ci(e),e&&(ai()<0||ai()===ri()||ai()>=ti().length)&&oi(ql(ri(),ti().length)),requestAnimationFrame(()=>{Ci(0),si()&&Ci(1)})};C(xi);let Di=e=>t=>{hi[e]=t,t&&requestAnimationFrame(()=>{Ci(e),si()&&Ci(1),setTimeout(()=>Ci(e),200)})};ee(()=>{Rn(),Zn().then(async()=>{await p();let t=Yr(),n=t?o().get(t):void 0,r=(n?e().find(e=>e.id===n):void 0)??e().find(e=>e.id===t&&!o().has(t))??e().find(e=>e.id===localStorage.getItem(`teapot.session`))??e()[0];r&&Rr(r.id,!1,t||null)}),Qn(),tr(),ji(),Jr();let t=setInterval(()=>{Qn(),tr()},3e4);C(()=>clearInterval(t))});let Oi=[{cmd:`/start`,desc:`start working toward the goal`},{cmd:`/stop`,desc:`interrupt the running agent`},{cmd:`/fork`,desc:`branch the conversation here`},{cmd:`/goal`,desc:`/goal <text> — set goal & notify the agent`},{cmd:`/compact`,desc:`force a context compaction now`},{cmd:`/skill`,desc:`/skill <name> — force-load a skill and follow it`}],[ki,Ai]=v([]),ji=()=>$(`/api/personas`).then(e=>Ai(e.personas)).catch(()=>{}),[Mi,Ni]=v(!1),Pi=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},Fi=()=>{let t=Pi();return t===null?[]:[...ki().map(e=>({key:e.key,label:`${e.label} — spawns a sub-agent`,kind:`persona`})),...e().filter(e=>e.id!==n()).map(e=>({key:e.id,label:`${e.status} — send directly`,kind:`agent`}))].filter(e=>e.key.toLowerCase().startsWith(t))},Ii=new Set([`start`,`stop`,`fork`,`compact`]),[Li,Ri]=v([]),[zi,Bi]=v(-1),Vi=()=>{let e=ne();if(!e.startsWith(`/`)||e.includes(`
|
|
23
23
|
`))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[2]??``).trim();if(!r&&n!==`skill`){let e=Oi.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Ii.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=Li().filter(e=>e.name.toLowerCase().startsWith(r.toLowerCase()));return e.length===1&&e[0].name.toLowerCase()===r.toLowerCase()?[]:e.map(e=>({insert:`/skill ${e.name} `,title:e.description||`(bundled skill)`}))}return[]},Hi,Ui=()=>{if(!Hi)return;let e=ot();Hi.style.height=`auto`;let t=e?-1:Math.min(Hi.scrollHeight,360);Hi.style.height=t===-1?``:`${t}px`},Wi;b(()=>{let e=ne();Hi&&Gt(gm)&&(Kt(Hi.value,e)&&(Hi.value=e),Ui())});let[Gi,Ki]=v([]),qi=e=>{let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));for(let e of t){if(e.size>8e6){Q(`"${e.name}" is over 8 MB — skipped`);continue}let t=new FileReader;t.onload=()=>{Ki(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},Ji=async(e,t)=>{let r=t??n();if(!r)return;let i=Gi();try{let t=await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0,...i.length?{images:i}:{}})});fn(un(),[...cn(),{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now(),promptId:t.promptId,...i.length?{images:i.map(e=>e.url)}:{}}]),Ki([]),ot()&&st(!1),requestAnimationFrame(()=>Ui())}catch(t){O(e),console.error(`send failed:`,t)}},Yi=async t=>{t.preventDefault();let r=n(),i=ne().trim();if(r&&i){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=ki().some(e=>e.key.toLowerCase()===r),s=e().some(e=>e.id.toLowerCase()===r);try{if(o){if(!a){Q(`usage: @${r} <task>`);return}Q(`🧩 spawned ${(await $(`/api/agents/${n()}/spawn`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({persona:r,task:a,context:Mi()?`fork`:`none`})})).id}${Mi()?` (forked context)`:``}`),Zn(),O(``)}else if(s){if(!a){Q(`usage: @${r} <message>`);return}await $(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),Q(`→ delivered to @${r}`),O(``)}else{Q(`unknown @${r} — personas: ${ki().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}}else if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim();if(t===`goal`&&!n){O(`/goal `);return}if(t===`skill`&&!n){O(`/skill `);return}O(``);try{await Xi(t,n)}catch(e){throw O(ne()?`${i}\n${ne()}`:i),e}}else O(``),await Ji(i)}},Xi=async(e,t)=>{let r=n();if(!r)return;let i=(e,t)=>$(`/api/agents/${r}${e}`,{method:`POST`,headers:{"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}}).then(Zn);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Rr(r);else if(e===`compact`)Q((await i(`/compact`))?.ran?`context compacted`:`nothing to compact yet`);else if(e===`goal`){if(!t){Q(`usage: /goal <text>`);return}await i(`/goal`,{text:t,notify:!0}),Q(`goal saved & notification queued`)}else if(e===`skill`){if(!t){Q(`usage: /skill <name>`);return}await Ji(`[harness] Force-load and follow the skill "${t}" now: call load_skill("${t}") and execute its playbook for the current task.`),Q(`skill "${t}" dispatched`)}else Q(`unknown command "${e}" — /start /stop /fork /goal /skill /compact`)}catch(t){Q(`/${e} failed: ${t.message}`)}},Zi,Qi=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Zi)return;let e=Math.min(Qi,Zi.scrollHeight);Math.abs(Zi.scrollTop-e)>1&&(Zi.scrollTop=e)})})});let $i=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(Zn),ea=async()=>{let i=n();if(!i)return;let a=new Set([i,...bt(e(),i).map(e=>e.id)]),o=a.size-1;if(!confirm(`archive agent ${i}?\n\n`+(o>0?`Its ${o} sub-agent${o===1?``:`s`} will be archived too.\n\n`:``)+`They stop running and leave the list, but the config and full session history are KEPT — restore any of them from ⚙ settings → archive.`))return;await $(`/api/agents/${i}/archive`,{method:`POST`}).catch(()=>{}),t(e().filter(e=>!a.has(e.id))),p(!0);let s=Jl(e(),a);s?Rr(s.id):(r(null),h([]))},ta=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),Zn())},q=()=>$(`/api/agents/${H().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await p(!0),await Rr(H().id)}),[na,ra]=v(``),[ia,aa]=v(``),[oa,sa]=v(!1),[ca,la]=v(!0),ua=``;b(()=>{let e=n();e&&(H()?.goal,e!==ua&&(ua=e,sa(!1),ra(``),aa(``)))});let da=async e=>{if(e.preventDefault(),n()&&na().trim())try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:na(),notify:ca(),...ia().trim()?{verify:ia()}:{}})}),ra(``),aa(``),sa(!1),Zn()}catch(e){Q(`goal save failed: ${e.message}`)}};return[N(F,{get when(){return k()?.needsSetup},fallback:null,get children(){return N(th,{onDone:()=>location.reload()})}}),N(F,{get when(){return zn()},get children(){var e=tu();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),N(F,{get when(){return!k()?.needsSetup},get children(){var t=ku(),r=t.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=o.firstChild;s.firstChild;var c=o.nextSibling,l=c.firstChild.firstChild.nextSibling;l.firstChild;var d=l.nextSibling,f=c.nextSibling,p=r.nextSibling,g=p.nextSibling,v=g.firstChild;v.firstChild,B(i,N(P,{get each(){return gr()},children:t=>[N(F,{get when(){return I(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=Fu(),n=e.firstChild;return e.$$click=()=>pr(`ws:${t.wsHeader}`,W(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),B(n,()=>t.wsCollapsedGroup?`▸`:`▾`),B(e,()=>W(t.wsHeader),null),B(e,N(F,{get when(){return(hr().get(t.wsHeader)??0)>1||t.wsCollapsedGroup},get children(){var e=Pu();return B(e,()=>hr().get(t.wsHeader)??0),e}}),null),y(()=>R(e,`title`,t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${mr(t.wsHeader)} hidden). Click to show.`:(hr().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${mr(t.wsHeader)} in this directory`:t.wsHeader||``)),e}}),N(F,{get when(){return I(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=Bu(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>Rr(t.a.id),B(r,N(F,{get when(){return vt({isSub:!!t.a.parent,collapsed:t.chatCollapsedGroup===!0,hasChildren:e().some(e=>e.parent===t.a.id)})},get fallback(){return Vu()},get children(){return(()=>{let e=!t.a.parent,n=e&&U().has(`chat:${t.a.id}`)||sr(t.a.id);return(()=>{var r=Hu();return r.$$click=r=>{if(r.stopPropagation(),e){if(n){if(!rr().has(t.a.id)){let e=new Set(rr());e.add(t.a.id),ir(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}if(ar().has(t.a.id)){let e=new Set(ar());e.delete(t.a.id),or(e),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...e]))}}else if(rr().has(t.a.id)){let e=new Set(rr());e.delete(t.a.id),ir(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}pr(`chat:${t.a.id}`,t.a.id,n)}else cr(t.a.id)},B(r,n?`▸`:`▾`),y(()=>R(r,`title`,e?n?`show ${t.a.id}`:`hide ${t.a.id} and its sub-agents`:n?`expand sub-agents`:`collapse sub-agents`)),r})()})()}}),i),B(a,()=>t.a.sessionTitle??u().get(t.a.session??``)??t.a.id),B(r,(()=>{var e=I(()=>!!t.a.workspaceMissing);return()=>e()?Uu():null})(),null),B(r,N(F,{get when(){return Sn(t.a.id)>0},get children(){var e=Iu();return e.firstChild,B(e,()=>Sn(t.a.id),null),y(()=>R(e,`title`,`${Sn(t.a.id)} unread notification${Sn(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),B(r,N(F,{get when(){return sr(t.a.id)||t.chatCollapsedGroup===!0&&U().has(`chat:${t.a.id}`)},get children(){return(()=>{let n=bt(e(),t.a.id),r=n.filter(e=>e.live??(e.status===`running`||e.status===`waiting`)).length;return n.length>0?(()=>{var e=Wu();return e.firstChild,z(e,`subcount`+(r>0?` live`:``)),B(e,()=>n.length,null),B(e,r>0?` · ▶${r}`:``,null),y(()=>R(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),B(r,N(F,{get when(){return t.a.parent},get children(){return Lu()}}),null),B(r,N(F,{get when(){return nr(t.a.id).length>0},get children(){var e=Ru();return y(()=>R(e,`title`,nr(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
|
|
24
|
-
`))),e}}),null),B(r,N(F,{get when(){return t.a.goal.status===`done`},get children(){return zu()}}),null),y(e=>{var o=`agent-item`+(t.a.id===n()?` sel`:``)+(t.depth>0?` sub-row`:``)+(t.chatCollapsedGroup?` collapsed`:``),s=t.depth>0?`padding-left:${10+t.depth*14}px`:``,c=t.a.parent?(()=>{let e=yt(t.a.id,ki().map(e=>e.key));return e?`sub-agent of @${t.a.parent} — "${e}"`:`sub-agent of @${t.a.parent}`})():void 0,l=`dot ${t.a.status}`,d=t.a.workspaceMissing?` ghost`:``,f=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:t.a.sessionTitle??u().get(t.a.session??``)?`${t.a.sessionTitle??u().get(t.a.session??``)} — ${t.a.id}`:t.a.id;return o!==e.e&&z(r,e.e=o),e.t=we(r,s,e.t),c!==e.a&&R(r,`title`,e.a=c),l!==e.o&&z(i,e.o=l),d!==e.i&&z(a,e.i=d),f!==e.n&&R(a,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),r}})]})),B(a,N(F,{get when(){return L()},get children(){var e=ru(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;ke(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),B(e,N(F,{get when(){return!Oe()},get fallback(){return[(()=>{var e=Gu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{je(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),B(t,N(P,{get each(){return _m.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=qu();return B(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=Ae()),e})(),(()=>{var e=Ku(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Ne(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),B(t,N(P,{get each(){return _m.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=qu();return B(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=Me()),e})()]},get children(){var e=nu();return B(e,N(P,{each:_m,children:e=>(()=>{var t=Ju(),n=t.firstChild;return t.$$click=()=>{De(e.key),localStorage.setItem(`teapot.theme`,e.key)},B(n,()=>e.sw.map(e=>(()=>{var t=Yu();return Te(t,`background`,e),t})())),B(t,()=>e.label,null),y(n=>{var r=`themebtn`+(Ce()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&z(t,n.e=r),i!==n.t&&R(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=Oe()),e}}),o),s.$$click=e=>{e.stopPropagation(),vn(!_n()),_n()||mn(e=>e.map(e=>({...e,read:!0})))},B(s,N(F,{get when(){return yn()>0},get children(){var e=iu();return B(e,yn),e}}),null),B(o,N(zm,{icon:`👻`,get active(){return hn()},get title(){return hn()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!hn();if(gn(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&H()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Rr(t.id)}}}),null),B(o,N(zm,{icon:`+`,title:`new agent`,onClick:()=>{Rn(),ae(!0)}}),null),B(o,N(zm,{icon:`🎨`,title:`themes`,onClick:()=>Se(!L())}),null),B(o,N(zm,{icon:`⚙`,title:`settings`,onClick:()=>{Rn(),se(!0)}}),null),B(l,`0.31.
|
|
24
|
+
`))),e}}),null),B(r,N(F,{get when(){return t.a.goal.status===`done`},get children(){return zu()}}),null),y(e=>{var o=`agent-item`+(t.a.id===n()?` sel`:``)+(t.depth>0?` sub-row`:``)+(t.chatCollapsedGroup?` collapsed`:``),s=t.depth>0?`padding-left:${10+t.depth*14}px`:``,c=t.a.parent?(()=>{let e=yt(t.a.id,ki().map(e=>e.key));return e?`sub-agent of @${t.a.parent} — "${e}"`:`sub-agent of @${t.a.parent}`})():void 0,l=`dot ${t.a.status}`,d=t.a.workspaceMissing?` ghost`:``,f=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:t.a.sessionTitle??u().get(t.a.session??``)?`${t.a.sessionTitle??u().get(t.a.session??``)} — ${t.a.id}`:t.a.id;return o!==e.e&&z(r,e.e=o),e.t=we(r,s,e.t),c!==e.a&&R(r,`title`,e.a=c),l!==e.o&&z(i,e.o=l),d!==e.i&&z(a,e.i=d),f!==e.n&&R(a,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),r}})]})),B(a,N(F,{get when(){return L()},get children(){var e=ru(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;ke(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),B(e,N(F,{get when(){return!Oe()},get fallback(){return[(()=>{var e=Gu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{je(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),B(t,N(P,{get each(){return _m.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=qu();return B(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=Ae()),e})(),(()=>{var e=Ku(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Ne(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),B(t,N(P,{get each(){return _m.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=qu();return B(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=Me()),e})()]},get children(){var e=nu();return B(e,N(P,{each:_m,children:e=>(()=>{var t=Ju(),n=t.firstChild;return t.$$click=()=>{De(e.key),localStorage.setItem(`teapot.theme`,e.key)},B(n,()=>e.sw.map(e=>(()=>{var t=Yu();return Te(t,`background`,e),t})())),B(t,()=>e.label,null),y(n=>{var r=`themebtn`+(Ce()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&z(t,n.e=r),i!==n.t&&R(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=Oe()),e}}),o),s.$$click=e=>{e.stopPropagation(),vn(!_n()),_n()||mn(e=>e.map(e=>({...e,read:!0})))},B(s,N(F,{get when(){return yn()>0},get children(){var e=iu();return B(e,yn),e}}),null),B(o,N(zm,{icon:`👻`,get active(){return hn()},get title(){return hn()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!hn();if(gn(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&H()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Rr(t.id)}}}),null),B(o,N(zm,{icon:`+`,title:`new agent`,onClick:()=>{Rn(),ae(!0)}}),null),B(o,N(zm,{icon:`🎨`,title:`themes`,onClick:()=>Se(!L())}),null),B(o,N(zm,{icon:`⚙`,title:`settings`,onClick:()=>{Rn(),se(!0)}}),null),B(l,`0.31.2`,null),B(f,N(F,{get when(){return E()},get children(){return[`master rss `,I(()=>E().rssMb),`MB · heap `,I(()=>E().heapUsedMb),`MB`,au(),`load1 `,I(()=>E().loadavg1),` · up `,I(()=>Math.floor(E().uptimeSec/60)),`m`]}})),B(p,N(F,{get when(){return H()?.id},keyed:!0,get fallback(){return Xu()},get children(){return[(()=>{var t=lu(),r=t.firstChild.nextSibling,i=r.nextSibling,a=i.nextSibling,o=a.firstChild,s=o.nextSibling,c=s.nextSibling.nextSibling,l=c.nextSibling.nextSibling,u=l.nextSibling.nextSibling;u.nextSibling;var d=a.nextSibling,f=d.firstChild;return B(r,()=>H().id),B(i,()=>H().status),B(t,N(F,{get when(){return(H().pendingPromptIds?.length??H().pendingPrompts??0)>0},get children(){var e=ou(),t=e.firstChild.nextSibling;return t.nextSibling,B(e,()=>H().pendingPromptIds?.length??H().pendingPrompts,t),B(e,()=>H().status===`stopped`?` (stopped)`:``,null),y(()=>R(e,`title`,H().status===`stopped`?`${H().pendingPromptIds?.length??H().pendingPrompts??0} message${(H().pendingPromptIds?.length??H().pendingPrompts??0)>1?`s`:``} from you are still queued, but this agent is STOPPED — nothing will run until you press start (or it is resumed). Each can be withdrawn with ✕ cancel while it is still queued.`:`${H().pendingPromptIds?.length??H().pendingPrompts??0} message${(H().pendingPromptIds?.length??H().pendingPrompts??0)>1?`s`:``} from you waiting in the queue. They will be handed to the model at its next turn boundary — the timeline shows them as "pending (queued)…" until then, and each can be withdrawn with ✕ cancel while it's still queued.`)),e}}),a),B(t,N(F,{get when(){return nr(H().id).length>0},get children(){var e=su();return e.firstChild,B(e,()=>nr(H().id).length,null),y(()=>R(e,`title`,`scheduled tasks:\n${nr(H().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
|
|
25
25
|
`)}`)),e}}),a),B(a,()=>H().model,o),B(a,()=>H().session,s),B(a,()=>H().branch,c),B(a,()=>H().stats.turns,l),B(a,()=>H().stats.toolCalls,u),B(d,N(F,{get when(){return H().statusReason},get children(){var e=cu();return y(()=>R(e,`title`,H().statusReason)),e}}),f),f.$$click=()=>(nn()?$i(`/stop`):$i(`/start`))(),B(f,()=>nn()?`■`:`▶`),B(d,N(zm,{icon:`⌨`,title:`terminal (t)`,onClick:ei}),null),B(d,N(zm,{icon:`⑂`,title:`fork: branch off the conversation here — try things without disturbing the main line`,onClick:q}),null),B(d,N(F,{get when(){return e().some(e=>e.parent===n())},get children(){return N(zm,{icon:`⏹`,title:`stop every sub-agent this agent spawned (descendants included)`,onClick:ta})}}),null),B(d,N(zm,{icon:`🗄`,title:`archive this agent — reversible: it leaves the list but keeps its config and history (restore in ⚙ settings → archive)`,onClick:ea}),null),B(d,N(zm,{icon:`▤`,title:`toggle details panel (d)`,get active(){return _e()},onClick:be}),null),y(e=>{var t=`badge ${H().status}`,n=`${H().model} · ${H().session}/${H().branch} · turns ${H().stats.turns} · tools ${H().stats.toolCalls}`,r=`runbtn`+(nn()?` danger`:``),o=nn()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&z(i,e.e=t),n!==e.t&&R(a,`title`,e.t=n),r!==e.a&&z(f,e.a=r),o!==e.o&&R(f,`title`,e.o=o),e},{e:void 0,t:void 0,a:void 0,o:void 0}),t})(),(()=>{var e=gu();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r={top:t.scrollTop,height:t.scrollHeight,viewport:t.clientHeight},i=Yt(r,Wi),a=Wi===void 0;Wi=r,_t(r),Jt(r)?(lt(!0),ut()&&ft(0),xn()):(i||a)&<(!1),r.top<=4&&n()&&!Sr()&&!wr()&&m().length>0&&Ar()}),Ee(e=>he(e),e),B(e,N(F,{get when(){return wt()},children:e=>(()=>{var t=Zu();return t.firstChild,B(t,(()=>{var t=I(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Im(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),B(e,N(F,{get when(){return I(()=>!!wr())()&&Nn().length>0},get children(){return uu()}}),null),B(e,N(F,{get when(){return Sr()},get children(){return du()}}),null),B(e,N(F,{get when(){return Nn().length>0},get fallback(){return Qu()},get children(){return[N(P,{get each(){return Nn()},children:e=>N(jm,{e,prev:()=>Fn(e,-1),next:()=>Fn(e,1),get showBranch(){return w().length>1},res:()=>Dn().resFor.get(e.id),get orphan(){return Dn().orphanCalls.has(e.id)},onOption:e=>void Ji(e),answeredIds:Mn,onAnswered:An,get agentActive(){return I(()=>!!rn())()&&Ke(e)},onResize:()=>{ct()&&Pr()},get onCancel(){return e.data?.source===`user`&&e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);O(ne()?`${n}\n\n${ne()}`:n),fn(un(),cn().filter(e=>e.promptId!==t)),Q(`message withdrawn — draft restored`)}).catch(()=>Q(`withdraw failed — it may have already been sent`))}:void 0},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`&&!(e.data?.pending&&e.data?.sent!==!0)&&!e.data?.cancelled&&!nn()?()=>on({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),N(F,{get when(){return I(()=>!!rn())()&&Rt()},get children(){var e=hu(),t=e.firstChild.nextSibling;return t.firstChild,B(t,N(F,{get when(){return V().trim()!==``},get children(){var e=fu(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return B(t,N(Om,{get startedAt(){return $t()}}),null),Ee(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{V(),t&&(e.scrollTop=e.scrollHeight)})},n),B(n,V),e}}),null),B(t,N(F,{get when(){return Vt()},get fallback(){return $u()},get children(){return N(F,{get when(){return Et()},get fallback(){return(()=>{var e=mu();return y(()=>e.innerHTML=Pe(Vt()+`▍`)),e})()},get children(){return[pu(),(()=>{var e=mu();return y(()=>e.innerHTML=Pe(Dt()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),N(F,{get when(){return Qr()},get children(){var t=xu(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{fi(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(di()))},n.$$pointerdown=Ti,B(i,N(P,{get each(){return ti()},children:(e,t)=>(()=>{var n=ed(),r=n.firstChild.nextSibling;return n.$$click=()=>_i(t()),B(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),bi(t())},y(r=>{var i=`termtab`+(li()===0&&ri()===t()?` active`:``)+(si()&&li()===1&&ai()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&z(n,r.e=i),a!==r.t&&R(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),B(i,N(zm,{icon:`+`,title:`new shell in this workspace`,onClick:vi}),null),B(o,(()=>{var t=I(()=>!!gi());return()=>t()?e().find(e=>e.id===gi().agentId)?.workspace.split(`/`).filter(Boolean).pop():H()?.workspace})()),B(a,N(zm,{icon:`◫`,get title(){return si()?`single pane`:`split panes (50/50)`},onClick:Ei}),null),B(a,N(zm,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:ei}),null);var l=Di(0);return typeof l==`function`&&Ee(l,c),c.$$pointerdown=()=>ui(0),B(c,N(F,{get when(){return ri()<0||ri()>=ti().length},get children(){return _u()}})),B(s,N(F,{get when(){return si()},get children(){return[vu(),(()=>{var e=bu(),t=Di(1);return typeof t==`function`&&Ee(t,e),e.$$pointerdown=()=>ui(1),B(e,N(F,{get when(){return ai()<0||ai()>=ti().length},get children(){return yu()}})),y(()=>e.classList.toggle(`focused`,li()===1)),e})()]}}),null),y(e=>{var n={height:`${di()}px`},r=!!si(),i=li()===0;return e.e=we(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=Du(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling,o=t.nextSibling;return B(e,N(F,{get when(){return I(()=>mt()>32)()&&!ct()},get children(){var e=Su();return e.firstChild,e.$$click=()=>{Fr(!0),xn()},B(e,(()=>{var e=I(()=>ut()>0);return()=>e()?`${ut()} new message${ut()>1?`s`:``}`:`jump to present`})(),null),e}}),t),B(e,N(F,{get when(){return Vi().length>0},get children(){var e=Cu();return B(e,N(P,{get each(){return Vi()},children:(e,t)=>(()=>{var n=td(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{O(e.insert),Bi(-1)},B(r,()=>e.insert.trim()),B(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===zi()?` active`:``),a=e.title;return i!==r.e&&z(n,r.e=i),a!==r.t&&R(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),B(e,N(F,{get when(){return Fi().length>0},get children(){var e=Cu();return B(e,N(P,{get each(){return Fi()},children:e=>(()=>{var t=nd(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{O(`@${e.key} `),Bi(-1)},B(n,()=>e.key,null),B(r,()=>e.label),y(()=>R(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Yi),B(t,N(F,{get when(){return Gi().length>0},get children(){var e=wu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,B(e,N(P,{get each(){return Gi()},children:(e,t)=>(()=>{var n=rd(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>Ki(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&R(n,`title`,t.e=i),a!==t.t&&R(r,`src`,t.t=a),o!==t.a&&R(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),B(t,()=>Gi().length,n),B(t,()=>Gi().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=Vi();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),Bi(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),Bi(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&zi()>=0&&!gm?(e.preventDefault(),O(t[zi()].insert),Bi(-1)):e.key===`Escape`&&t.length>0?Bi(-1):e.key===`Enter`&&!e.shiftKey&&!gm&&!ot()&&(e.preventDefault(),Yi(e))},n.$$input=e=>{O(e.currentTarget.value),Bi(0),Ui()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),qi(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{gm=!1}),O(Hi?.value??``)}),n.addEventListener(`compositionstart`,()=>{gm=!0}),Ee(e=>{Hi=e,e.value=ne()},n),B(t,N(F,{get when(){return I(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=Tu(),t=e.firstChild;return t.addEventListener(`change`,e=>Ni(e.currentTarget.checked)),y(()=>t.checked=Mi()),e}}),r),r.$$click=()=>{let e=!ot();st(e),requestAnimationFrame(()=>Ui())},B(r,()=>ot()?`⤡`:`⤢`),B(t,N(zm,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),B(t,N(F,{get when(){return Gi().length},get children(){var e=Eu();return e.firstChild,B(e,()=>Gi().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&qi(e.currentTarget.files),e.currentTarget.value=``}),B(o,()=>pm()||`enter send · shift+enter newline · ↑↓ sessions · / commands & focus · t terminal · d panel · esc interrupt · messages sent while the agent works queue up and land at the next turn boundary`),y(t=>{var i=`composer`+(ot()?` maximized`:``),a=`message #${H().id} — / for commands · paste or 📎 to attach images`,o=ot()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&z(e,t.e=i),a!==t.t&&R(n,`placeholder`,t.t=a),o!==t.a&&R(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()]}})),B(t,N(F,{get when(){return I(()=>!!ce())()&&_e()},get children(){var e=Ou();return e.$$click=()=>ye(!1),e}}),g),g.addEventListener(`scroll`,e=>{Qi=e.currentTarget.scrollTop});var S=Zi;return typeof S==`function`?Ee(S,g):Zi=g,B(v,N(zm,{icon:`✕`,title:`close details panel (esc)`,onClick:xe}),null),B(g,N(F,{get when(){return H()?.id},keyed:!0,fallback:null,children:t=>[N(F,{get when(){return H().id},keyed:!0,fallback:null,children:e=>N(Zm,{agentId:e,get workspace(){return H().workspace}})}),id(),(()=>{var t=sd(),r=t.firstChild,i=r.nextSibling,a=i.firstChild,o=a.nextSibling,s=i.nextSibling,c=s.firstChild,l=s.nextSibling;return l.firstChild,r.addEventListener(`change`,t=>{let r=t.currentTarget.value;at=!0,ze(r),Ge(Ht(k().providers,r,e().find(e=>e.id===n()))),tt(r)}),B(r,N(P,{get each(){return et()},children:e=>(()=>{var t=qu();return t.value=e,B(t,e,null),B(t,()=>e===k().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>Ge(e.currentTarget.value),B(o,N(P,{get each(){return Qe()},children:e=>(()=>{var t=qu();return y(()=>t.value=e.id),t})()})),B(t,N(F,{get when(){return H().effortSupported},get children(){var e=ad(),t=e.firstChild.nextSibling;return t.firstChild,t.addEventListener(`change`,e=>Ze(e.currentTarget.value)),B(t,N(P,{get each(){return I(()=>!!H().effortOptions?.length)()?H().effortOptions:lm},children:e=>(()=>{var t=qu();return t.value=e,B(t,e),t})()}),null),y(()=>t.value=Xe()),e}}),s),c.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:Re(),model:Ue().trim()||void 0,contextWindowTokens:Qe().find(e=>e.id===(Ue().trim()||void 0))?.contextLength,...H().effortSupported?{reasoningEffort:Xe()}:{}})}),t.textContent=`✓ applied`,Zn()}catch(e){alert(`apply failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},B(l,()=>H().model,null),B(l,N(F,{get when(){return Qe().length},get children(){return[` · `,I(()=>Qe().length),` models loaded`]}}),null),B(t,N(F,{get when(){return rt()},get children(){var e=od();return B(e,rt),e}}),null),y(()=>R(a,`placeholder`,Ut(k().providers,Re(),H(),Bt(H(),k().providers,k().defaultProvider)))),y(()=>r.value=Re()),y(()=>a.value=Ue()),t})(),(()=>{var e=cd(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-continue`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Zn)}),y(()=>t.checked=H().autoContinue??!0),e})(),(()=>{var e=ud();return e.firstChild,B(e,N(F,{get when(){return!!H().goal.text.trim()},get fallback(){return Od()},get children(){var e=ld();return B(e,()=>H().goal.status),y(()=>z(e,`badge ${H().goal.status===`active`?`running`:H().goal.status}`)),e}}),null),e})(),(()=>{var e=dd();return e.firstChild,B(e,N(P,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=kd();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(Zn)},R(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),B(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(H().goal.text.trim()&&H().goal.status===e?` on ${e}`:``),i=!!H().goal.text.trim()&&H().goal.status===e;return r!==n.e&&z(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),N(F,{get when(){return H().goal.text},get fallback(){return Ad()},get children(){return[(()=>{var e=fd(),t=e.firstChild;return y(()=>t.innerHTML=Pe(String(H().goal.text))),e})(),N(F,{get when(){return H().goal.verify},get children(){var e=pd(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Pe(String(H().goal.verify))),e}}),N(F,{get when(){return H().goal.audit},children:e=>(()=>{var t=jd(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return B(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),B(r,()=>Fm(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=pt(e().feedback)?Pe(`_the auditor returned a verdict with no detail_`):Pe(e().feedback);return r!==n.e&&z(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),md(),(()=>{var e=hd(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,da),t.$$input=e=>{ra(e.currentTarget.value),sa(!0)},n.$$input=e=>{aa(e.currentTarget.value),sa(!0)},r.addEventListener(`change`,e=>la(e.currentTarget.checked)),y(()=>t.value=na()),y(()=>n.value=ia()),y(()=>r.checked=ca()),e})(),(()=>{var e=_d(),t=e.firstChild.nextSibling;return B(e,N(F,{get when(){return Yn().total>0},get children(){var e=gd(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,B(e,()=>Yn().done,t),B(e,()=>Yn().total,n),y(t=>we(e,Yn().done===Yn().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),N(F,{get when(){return Yn().total>0},get children(){var e=vd(),t=e.firstChild;return y(e=>{var n=`barfill `+(Yn().done===Yn().total?``:`warn`),r=`${Math.round(Yn().done/Yn().total*100)}%`;return n!==e.e&&z(t,e.e=n),r!==e.t&&Te(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),N(Xm,{get draft(){return Vn()},get preview(){return Un()},onDraft:e=>{Hn(e),Kn(!0)}}),(()=>{var e=yd(),t=e.firstChild,n=t.nextSibling;return B(e,N(zm,{get icon(){return Un()?`✎`:`👁`},get title(){return Un()?`edit markdown`:`rendered checklist`},onClick:()=>Wn(!Un())}),t),n.$$click=Jn,e})(),bd(),N(F,{get when(){return H().latestProgress},get fallback(){return Md()},children:e=>(()=>{var t=Ld(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return B(t,N(F,{get when(){return e().recent},get children(){var t=Nd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=cm(e().recent)),t}}),i),B(t,N(F,{get when(){return e().problems},get children(){var t=Pd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=cm(e().problems)),t}}),i),B(t,N(F,{get when(){return e().next},get children(){var t=Fd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=cm(e().next)),t}}),i),B(t,N(F,{get when(){return e().goalStatus},get children(){var t=Id(),n=t.firstChild.nextSibling;return B(n,()=>e().goalStatus),t}}),i),B(i,()=>Fm(e().ts)),y(()=>r.innerHTML=cm(e().doing)),t})()}),xd(),(()=>{var e=wd(),t=e.firstChild,r=t.firstChild.nextSibling,i=r.firstChild.nextSibling,a=i.firstChild,o=a.nextSibling;o.nextSibling;var s=r.nextSibling.firstChild.nextSibling,c=s.nextSibling.nextSibling,l=c.nextSibling.nextSibling;return B(i,()=>Im(H().stats.inputTokens),a),B(i,()=>Im(H().stats.outputTokens),o),B(r,N(F,{get when(){return(H().stats.cachedInputTokens??0)>0},get children(){var e=Sd(),t=e.firstChild.nextSibling;return t.nextSibling,B(e,()=>Math.round(H().stats.cachedInputTokens/Math.max(1,H().stats.inputTokens)*1e3)/10,t),y(()=>R(e,`title`,`${Im(H().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),B(s,()=>H().stats.turns),B(c,()=>H().stats.toolCalls),B(l,()=>H().stats.compactions??0),B(t,N(F,{get when(){return(H().stats.costUsd??0)>0},get children(){var e=Cd(),t=e.firstChild.nextSibling;return t.firstChild,B(t,()=>Lm(H().stats.costUsd??0),null),y(()=>R(e,`title`,`≈ ${(H().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),B(e,N(F,{get when(){return H().ctx},keyed:!0,get fallback(){return Rd()},children:e=>{let t=x(()=>{let t=e,n=Qe().find(e=>e.id===H().model),r=t.window||n?.contextLength||0,i=r?Math.min(999,t.usedTokens/r*100):0;return{usedTokens:t.usedTokens,compactAt:t.compactAt,compacting:t.compacting,window:t.window,effectiveWindow:r,pct:i,cls:r?i>=85?`crit`:i>=70?`warn`:`ok`:``,derivedBudget:r?Math.round(r*.75):0,usingDerived:t.compactAtIsManual!==!0}}),r=()=>t(),i=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)};return(()=>{var e=Hd(),t=e.firstChild,a=t.firstChild.nextSibling,o=a.firstChild.nextSibling;o.nextSibling;var s=t.nextSibling,c=s.firstChild.nextSibling,l=c.firstChild,u=c.nextSibling,d=s.nextSibling,f=d.firstChild.firstChild;return B(a,()=>Im(r().usedTokens),o),B(t,N(F,{get when(){return r().effectiveWindow},get children(){var e=zd(),t=e.firstChild;return B(e,()=>i(r().pct),t),B(e,()=>Im(r().effectiveWindow),null),y(()=>z(e,`pill ${r().cls}`)),e}}),null),B(e,N(F,{get when(){return r().effectiveWindow},get children(){var e=Bd(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&z(t,e.e=n),i!==e.t&&Te(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),B(c,()=>Im(r().usingDerived?r().derivedBudget:r().compactAt),l),B(u,()=>r().usingDerived?`75% of window`:`manual`),B(e,N(F,{get when(){return wt()||r().compacting},get children(){var e=Vd(),t=e.firstChild.nextSibling.nextSibling;return B(t,()=>wt()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Zn)}),y(()=>f.checked=H().autoCompact!==!1),e})()}}),null),e})(),(()=>{var e=Ed();return e.firstChild.nextSibling,B(e,N(F,{get when(){return _r()},get children(){var e=Td(),t=e.firstChild.nextSibling;return B(t,_r),e}}),null),e})(),N(P,{get each(){return w()},children:e=>(()=>{var t=Ud(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=_r()===e.branch?null:e.branch,r=t!==_r();vr(t),n()&&(r&&(Er++,h([]),_(0),Tr(!1)),jr(n()))},B(r,()=>e.branch,null),B(r,()=>e.branch===H().branch?` (current)`:``,null),B(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===H().branch||e.branch===_r()?` cur`:``),i=e.branch===_r()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&z(t,n.e=r),i!==n.t&&R(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),(()=>{var e=Dd();return e.firstChild,B(e,N(F,{get when(){return $n().length>0},get fallback(){return Wd()},get children(){return N(P,{get each(){return $n()},children:e=>(()=>{var t=Kd(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Rr(e.agent),B(i,()=>e.id),B(a,()=>e.agent,null),B(r,N(F,{get when(){return e.forked},get children(){return Gd()}}),null),B(o,()=>e.schedule,s),B(o,(()=>{var t=I(()=>!!e.next);return()=>t()?Fm(e.next):`—`})(),null),B(o,(()=>{var t=I(()=>!!e.last);return()=>t()?` · last ${Fm(e.last)}`:` · never ran`})(),null),B(c,()=>Rm(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Rm(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&z(t,r.e=i),a!==r.t&&R(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}}),null),e})()]}),null),y(e=>{var n=`layout`+(_e()?``:` right-hidden`),r=`iconbtn notifbtn`+(yn()>0?` has-unread`:``),i=yn()>0?`${yn()} unread notifications`:`notifications`,a=`conn`+(zr()?` ok`:``),o=zr()?`live (websocket)`:`reconnecting…`,c={"--termh":`${di()}px`},l=`rightbar`+(_e()?` open`:``);return n!==e.e&&z(t,e.e=n),r!==e.t&&z(s,e.t=r),i!==e.a&&R(s,`title`,e.a=i),a!==e.o&&z(d,e.o=a),o!==e.i&&R(d,`title`,e.i=o),e.n=we(p,c,e.n),l!==e.s&&z(g,e.s=l),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),t}}),N(F,{get when(){return _n()},get children(){return[(()=>{var e=Au();return e.$$click=()=>vn(!1),e})(),(()=>{var t=Nu(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return B(r,N(F,{get when(){return pn().length>0},get children(){var e=ju();return e.$$click=()=>mn([]),e}}),i),i.$$click=()=>vn(!1),B(t,N(F,{get when(){return pn().length>0},get fallback(){return qd()},get children(){var t=Mu();return B(t,N(P,{get each(){return pn()},children:t=>(()=>{var r=Yd(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{mn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&Rr(t.agentId),vn(!1),t.eventId&&setTimeout(()=>En(t.eventId),n()===t.agentId?60:350)},B(i,(()=>{var e=I(()=>t.kind===`finish`);return()=>e()?`✅`:I(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),B(a,()=>t.title),B(o,()=>Fm(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),mn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},B(s,()=>t.read?`✓`:`○`),B(r,N(F,{get when(){return t.body},get children(){var e=Jd();return B(e,()=>Pm(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&z(r,e.e=n),i!==e.t&&R(r,`title`,e.t=i),a!==e.a&&R(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),N(F,{get when(){return A()},get children(){return N(Hm,{get providers(){return Object.keys(k().providers??{})},onClose:()=>ae(!1),onCreated:e=>{ae(!1),Zn(),Rr(e)}})}}),N(F,{get when(){return oe()},get children(){return N(nh,{get cfg(){return k()},onClose:()=>se(!1),onSaved:()=>{Rn(),tr()}})}}),N(F,{get when(){return an()},fallback:null,children:e=>{let t=()=>m().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,m().length-t()-1),[i,a]=v(r()>0?`summarize`:`discard`);return N(Vm,{title:`edit prompt — forks the conversation`,onClose:()=>on(null),get children(){var t=Zd(),o=t.firstChild,s=o.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:i()})}),on(null),Zn();let t=n();t&&await Rr(t)}catch(e){alert(`edit failed: ${e.message}`)}}),B(t,N(F,{get when(){return r()>0},get children(){var e=Xd(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return B(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>on(null),y(()=>o.value=e().text),t}})}})]}function Dm(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>ze(Math.max(0,n()-t));return e.inline?(()=>{var t=Qd();return t.firstChild,B(t,i,null),B(t,(()=>{var t=I(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=$d(),t=e.firstChild;return B(e,i,t),e})()}function Om(e){let[t,n]=v(Date.now());return ee(()=>{let e=setInterval(()=>n(Date.now()),500);C(()=>clearInterval(e))}),e.startedAt?(()=>{var n=ef();return B(n,()=>ze(Math.max(0,t()-e.startedAt))),n})():null}function km(e){let t=e.e,n=Dt(e.prev,t),r=()=>e.res?.(),i=()=>!e.agentActive&&!r(),a=t.data??{},o=String(a.name??`tool`),s=()=>String(r()?.data?.result??``),c=e=>String(a.args?.[e]??``),l=()=>o===`bash`?c(`command`):c(`path`)||JSON.stringify(a.args??{},null,1),u=()=>o===`bash`?Number(c(`timeout_ms`))||void 0:o===`wait_children`?Number(c(`timeout_ms`))||3e5:Number(c(`timeout_ms`))||void 0,d=(e,t=1500)=>(()=>{var n=tf();return B(n,()=>Pm(e,t)),n})(),f=(e=4e3)=>(()=>{let t=r();return t?[I(()=>d(s(),e)),(()=>{var e=nf();return B(e,()=>ze(t.data?.durationMs),null),B(e,()=>o===`bash`?Rt(Lt(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),B(e,N(Bm,{get text(){return s()}}),null),e})()]:rf()})(),p=x(()=>{r();let e=o,t=``,n=(()=>{var e=af();return B(e,()=>Pm(JSON.stringify(a.args??{},null,1),2e3)),e})();try{switch(o){case`bash`:{let i=c(`command`),o=a.args?.background===!0,l=o?String(s()).match(/job (bg\d+)/)?.[1]??``:``;e=(o?`⏳ `:`$ `)+Rm(i,96);let u=c(`timeout_ms`)?Number(c(`timeout_ms`)):void 0,p=r(),m=Lt(p?.data?.ok,p?String(p.data?.result??``):``);t=p?o?`background job${l?` ${l}`:``}${u?` · timeout ${Math.round(u/1e3)}s`:``}`:zt({outcome:m,durationMs:p.data?.durationMs,timeoutMs:u,fmtDur:ze}):null,n=[o?(()=>{var e=of(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,B(t,l||`?`,n),B(e,l?[` · kill with `,sf()]:null,null),e})():null,I(()=>I(()=>i!==e.slice(2))()?d(i,800):null),I(()=>f(6e3))];break}case`read_file`:{e=c(`path`)||`(no path)`;let r=[];c(`pattern`)&&r.push(`grep /${Rm(c(`pattern`),40)}/`),Number(a.args?.offset)<0?r.push(`last ${-Number(a.args.offset)} lines`):a.args?.offset&&r.push(`from L${a.args.offset}`),a.args?.limit&&r.push(`≤${a.args.limit} lines`),t=r.join(` · `),n=f(6e3);break}case`write_file`:{let i=String(a.args?.content??``);e=c(`path`)||`(no path)`,t=`${Im(i.length)} bytes`,n=[I(()=>d(i,1500)),I(()=>I(()=>i.length>1500)()?(()=>{var e=cf(),t=e.firstChild;return B(e,()=>Im(i.length),t),e})():null),I(()=>I(()=>!!r())()?(()=>{var e=nf();return B(e,()=>Rm(s(),160)),e})():lf())];break}case`edit_file`:e=c(`path`)||`(no path)`,t=a.args?.replace_all===!0?`replace all`:`unique spot`,n=[(()=>{var e=uf();return B(e,()=>Pm(`- `+c(`old_text`),900)),e})(),(()=>{var e=df();return B(e,()=>`+ `+Pm(c(`new_text`),900)),e})(),I(()=>I(()=>!!r())()?(()=>{var e=ff(),t=e.firstChild;return B(e,()=>Rm(s(),120),t),B(e,()=>ze(r().data?.durationMs),null),e})():pf())];break;case`apply_patch`:{let t=c(`patch`).split(`
|
|
26
26
|
`).filter(e=>e&&!/^---$/.test(e.trim())),i=t.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);e=i.length?`${i.length} file${i.length>1?`s`:``}: ${Rm(i.join(`, `),80)}`:`patch`;let a=t.slice(0,60);n=[(()=>{var e=mf();return B(e,()=>a.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=hf();return z(n,`pline`+t),B(n,(()=>{var t=I(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),B(e,(()=>{var e=I(()=>t.length>60);return()=>e()?(()=>{var e=gf(),n=e.firstChild.nextSibling;return n.nextSibling,B(e,()=>t.length-60,n),e})():null})(),null),e})(),I(()=>I(()=>!!r())()?(()=>{var e=nf();return B(e,()=>Rm(s().split(`
|
|
27
|
-
`)[0]??``,140),null),B(e,()=>r().data?.ok===!1?` · FAILED`:``,null),e})():_f())];break}case`list_dir`:e=c(`path`)||`.`,n=f(4e3);break;case`read_url`:{let r=c(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=Rm(r,70),t=`web`,n=[(()=>{var e=nf();return B(e,N(F,{get when(){return/^https?:/i.test(c(`url`))},get fallback(){return(()=>{var e=yf();return B(e,()=>Rm(c(`url`),80)),e})()},get children(){var e=vf();return y(()=>R(e,`href`,c(`url`))),e}})),e})(),I(()=>f(3e3))];break}case`bash_output`:{let r=c(`action`)||`read`;e=`bash_output ${c(`job_id`)||`(?)`}`,t=r,n=f(4e3);break}case`load_skill`:{e=`skill: ${c(`name`)}`;let t=s().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);n=r()?[(()=>{var e=mu();return y(()=>e.innerHTML=Pe(t)),e})(),(()=>{var e=nf();return B(e,()=>ze(r().data?.durationMs)),e})()]:bf();break}case`save_skill`:{e=`skill: ${c(`name`)}`,t=Rm(c(`description`),60);let i=Array.isArray(a.args?.files)?a.args.files.map(e=>e?.name).filter(Boolean):[];n=[I(()=>I(()=>!!i.length)()?(()=>{var e=xf();return e.firstChild,B(e,()=>i.join(`, `),null),e})():null),I(()=>I(()=>!!r())()?(()=>{var e=ff(),t=e.firstChild;return B(e,()=>Rm(s(),160),t),B(e,()=>ze(r().data?.durationMs),null),e})():Sf())];break}}}catch{}return{label:e,hint:t,body:n,key:`${r()?.id??`none`}|${e}|${t??``}`}},void 0,{equals:(e,t)=>e.key===t.key});return(()=>{var a=wf(),c=a.firstChild,d=c.firstChild,f=d.nextSibling,m=f.nextSibling;return a.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),B(d,()=>p().label),B(c,N(F,{get when(){return t.data?.actor},get children(){var e=Cf();return e.firstChild,B(e,()=>String(t.data.actor),null),e}}),f),B(f,(()=>{var e=I(()=>!!r());return()=>e()?p().hint||``:I(()=>!!i())()?`(result missed)`:I(()=>!!(o===`bash`||u()))()?N(Dm,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return u()}}):`running…`})()),B(m,N(Bm,{get text(){return l()},label:`⧉ cmd`,title:`copy the ${o} arguments`}),null),B(m,N(F,{get when(){return r()},get children(){return N(Bm,{get text(){return s()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),B(a,()=>p().body,null),y(e=>{var t=`embed`+(n?` grouped`:``)+(r()?r().data?.ok===!1?` fail`:` done`:i()?` done`:` running`),s=`${o}${p().hint?` — `+p().hint:``}`;return t!==e.e&&z(a,e.e=t),s!==e.t&&R(a,`title`,e.t=s),e},{e:void 0,t:void 0}),a})()}function Am(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function jm(e){let t=e.e,n=vm(t),r=()=>Dt(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Dt(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Tf(),r=n.firstChild.nextSibling;return r.nextSibling,B(n,()=>String(e.fromBranch??`?`),r),B(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=ht(t.data??{});return(()=>{var t=Ef(),n=t.firstChild;return B(n,()=>e.label),B(t,N(F,{get when(){return e.hasCard},get children(){var t=hf();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Pe(e.detail):Pe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&z(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>z(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Df(),n=e.firstChild.nextSibling;return n.nextSibling,B(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Of(),n=e.firstChild;return B(e,()=>t.data.from,n),B(e,()=>t.data.to,null),B(e,(()=>{var e=I(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>z(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=kf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,B(n,()=>String(t.data?.failures),r),B(n,()=>String(t.data?.limit),i),B(a,()=>String(t.data?.lastTool),o),B(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>R(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Af(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,B(n,()=>String(t.data?.attempt),r),B(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=hf();return z(r,`divider-msg`+(e?` err`:``)),B(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>R(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=jf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,B(e,()=>String(t.data?.tokensBefore??`?`),n),B(e,()=>String(t.data?.tokensAfter??`?`),r),B(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Mf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,B(e,()=>String(t.data?.messages??`?`),n),B(e,()=>String(t.data?.tokensBefore??`?`),r),B(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=Lf(),o=a.firstChild,s=o.nextSibling;return B(o,(()=>{var e=I(()=>!!r());return()=>e()?``:n.icon})()),B(s,(()=>{var e=I(()=>!!r());return()=>e()&&(()=>{var e=Rf();return y(()=>R(e,`title`,`${Cm(t.ts)} · ${t.branch}`)),e})()})(),null),B(s,N(F,{get when(){return!r()},get children(){var r=If(),i=r.firstChild,a=i.nextSibling;return B(i,()=>n.name),B(r,N(F,{get when(){return t.data?.actor},get children(){var e=Cf();return e.firstChild,B(e,()=>String(t.data.actor),null),e}}),a),B(a,(()=>{var e=I(()=>!!t.data?.pending);return()=>e()?`queued…`:I(()=>!!t.data?.cancelled)()?`withdrawn`:Cm(t.ts)})()),B(r,N(F,{get when(){return e.showBranch},get children(){var e=Nf();return B(e,()=>t.branch),e}}),null),B(r,N(F,{get when(){return e.onCancel},get children(){var t=Pf();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),B(r,N(F,{get when(){return t.type!==`tool_call`},get children(){return N(Bm,{get text(){return Am(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),B(r,N(F,{get when(){return e.onEdit},get children(){var t=Ff();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Te(i,`color`,n.color)),r}}),null),B(s,N(Nm,{e:t,get prev(){return e.prev?.()},get res(){return e.res},get orphan(){return e.orphan},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get onAnswered(){return e.onAnswered},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var s=`msg`+(r()?` grouped`:``)+(i()?` next-grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),c=t.id,l=`avatar avghost`+(r()?` ghosted`:``),u=r()?`transparent`:n.color+`33`,d=r()?`1px solid transparent`:`1px solid ${n.color}66`,f=r()?`${Cm(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&z(a,e.e=s),c!==e.t&&R(a,`data-eid`,e.t=c),l!==e.a&&z(o,e.a=l),u!==e.o&&Te(o,`background`,e.o=u),d!==e.i&&Te(o,`border`,e.i=d),f!==e.n&&R(o,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),a})()}function Mm(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=zf(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&R(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function Nm(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=mu();return y(()=>e.innerHTML=cm(String(t.data.text??``))),e})(),N(F,{get when(){return e.length},get children(){var t=Bf();return B(t,N(P,{each:e,children:e=>(()=>{var t=Vf();return R(t,`src`,e),t})()})),t}})]}case`message`:return[N(F,{get when(){return I(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Hf(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return B(n,(()=>{var e=I(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Im(String(t.data.reasoning).length)} — truncated)`:``})(),null),B(r,()=>Pm(String(t.data.reasoning),8e3)),e}}),(()=>{var e=mu();return y(()=>e.innerHTML=cm(String(t.data.content??``))),e})(),N(F,{get when(){return t.data.interrupted},get children(){return Uf()}}),N(F,{get when(){return t.data.final},get children(){var e=Wf(),n=e.firstChild;return B(e,N(Bm,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return N(km,{e:t,get prev(){return e.prev},get res(){return e.res},get orphan(){return e.orphan},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=Kf(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return z(a,`embed `+(i?``:`fail`)),B(s,r===`bash`?`$ (bash, call evicted)`:r),B(o,N(Bm,{text:n}),null),B(c,()=>Pm(n,4e3)),B(l,()=>ze(t.data.durationMs),null),B(l,()=>r===`bash`?Rt(Lt(t.data.ok,n)):i?``:` · FAILED`,null),B(a,N(F,{get when(){return e.orphan},get children(){return Gf()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=Jf(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return B(n,N(F,{get when(){return e.length},get children(){var t=qf();return t.firstChild,B(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=cm(String(t.data?.decision??``)),r=cm(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=()=>e.answeredIds?.().has(r)??!1;return(()=>{var a=Zf(),o=a.firstChild.firstChild.nextSibling;return B(a,N(F,{get when(){return i()},get children(){return Yf()}}),null),B(a,N(F,{get when(){return n.length>0},get children(){var a=Xf();return B(a,N(P,{each:n,children:n=>(()=>{var a=Qf();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},B(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),B(a,N(Mm,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=cm(String(t.data?.question??``));return n!==e.e&&z(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=$f(),n=e.firstChild.firstChild.nextSibling;return B(e,N(F,{get when(){return t.data.goalStatus},get children(){var e=Id(),n=e.firstChild.nextSibling;return B(n,()=>String(t.data.goalStatus)),e}}),null),B(e,N(F,{get when(){return t.data.recent},get children(){var e=Nd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=cm(String(t.data.recent))),e}}),null),B(e,N(F,{get when(){return t.data.problems},get children(){var e=Pd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=cm(String(t.data.problems))),e}}),null),B(e,N(F,{get when(){return t.data.next},get children(){var e=Fd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=cm(String(t.data.next))),e}}),null),y(()=>n.innerHTML=cm(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=ep(),n=e.firstChild;return n.firstChild,B(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=np(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,B(n,()=>String(t.data.mode??``),r),B(n,()=>Im(Number(t.data.tokensBefore??0)),i),B(n,()=>Im(Number(t.data.tokensAfter??0)),a),B(n,(()=>{var e=I(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),B(e,N(F,{get when(){return t.data.summary},get children(){return[tp(),(()=>{var e=mu();return y(()=>e.innerHTML=cm(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=rp();return B(e,()=>Pm(JSON.stringify(t.data),200)),e})()}}function Pm(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Fm(e){let t=new Date(e).getTime()-Date.now(),n=Math.abs(t),r=n<9e4?`${Math.round(n/1e3)}s`:n<54e5?`${Math.round(n/6e4)}m`:`${(n/36e5).toFixed(1)}h`;return t>=0?`in ${r}`:`${r} ago`}function Im(e){return e>=1e9?`${+(e/1e9).toFixed(1)}b`:e>=1e6?`${+(e/1e6).toFixed(1)}m`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Lm(e){return e>=100?Math.round(e).toLocaleString():e>=10?e.toFixed(1):e>=1?e.toFixed(2):e>=.01?e.toFixed(3):e.toFixed(4)}function Rm(e,t){return Pm(e.replace(/\s+/g,` `).trim(),t)}function zm(e){return(()=>{var t=ip(),n=t.firstChild;return Ce(t,`click`,e.onClick,!0),B(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&z(t,n.e=r),i!==n.t&&R(t,`title`,n.t=i),n.a=we(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Bm(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),wt(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=ap();return n.$$click=a,B(n,(()=>{var n=I(()=>!!t());return()=>n()?`✓`:I(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>R(n,`title`,e.title??`copy to clipboard`)),n})()}function Vm(e){return(()=>{var t=op(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),B(r,()=>e.title),Ce(i,`click`,e.onClose,!0),B(n,()=>e.children,null),t})()}function Hm(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}ee(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return N(Vm,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=cp(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),B(b,N(P,{get each(){return r()},children:e=>(()=>{var n=lp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),B(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),B(w,N(P,{get each(){return e.providers},children:e=>(()=>{var t=qu();return B(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),B(i,N(F,{get when(){return d()},get children(){var e=sp();return B(e,d),e}}),E),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>T.value=l()),i}})}var Um=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Wm=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Gm=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Km(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=qm(e);return n===`image`?`🖼`:n===`video`?`🎬`:n===`audio`?`🎵`:[`ts`,`tsx`,`mts`,`cts`].includes(t)?`🟦`:[`js`,`mjs`,`cjs`,`jsx`].includes(t)?`🟨`:t===`json`||t===`jsonc`?`🧾`:t===`md`||t===`mdx`||t===`markdown`?`📝`:t===`css`||t===`scss`||t===`less`?`🎨`:t===`html`||t===`htm`||t===`svg`?`🌐`:[`py`,`pyi`].includes(t)?`🐍`:t===`rs`?`🦀`:t===`go`?`🐹`:t===`java`||t===`kt`||t===`kts`?`☕`:t===`rb`?`💎`:t===`php`?`🐘`:t===`c`||t===`h`||t===`cpp`||t===`hpp`||t===`cc`?`🧩`:t===`sh`||t===`bash`||t===`zsh`||t===`fish`?`🐚`:t===`sql`?`🗄`:t===`yml`||t===`yaml`||t===`toml`||t===`ini`||t===`conf`?`⚙`:t===`lock`?`🔒`:e===`Dockerfile`||t===`dockerfile`?`🐳`:t===`zip`||t===`gz`||t===`tar`||t===`tgz`||t===`bz2`?`📦`:t===`pdf`?`📕`:t===`txt`||t===`log`?`📄`:`·`}function qm(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Um.has(t)?`image`:Wm.has(t)?`video`:Gm.has(t)?`audio`:null}var Jm=new Map,Ym=e=>{let t=Jm.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Jm.set(e,t)),t};function Xm(e){let t=Number(localStorage.getItem(`teapot.todoH`)??``),[n,r]=v(Number.isFinite(t)&&t>0?t:0),i=()=>n()>0?{height:`${n()}px`}:void 0,a=e=>{let t=new ResizeObserver(()=>{let t=e.offsetHeight;t<=0||r(e=>Math.abs(e-t)<1?e:(localStorage.setItem(`teapot.todoH`,String(t)),t))});t.observe(e),C(()=>t.disconnect())};return N(F,{get when(){return e.preview},get fallback(){return(()=>{var t=dp();return t.$$input=t=>e.onDraft(t.currentTarget.value),Ee(a,t),y(e=>we(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=up();return Ee(a,t),y(n=>{var r=i(),a=cm(e.draft);return n.e=we(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function Zm(e){let t=Ym(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),ee=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},w=e=>x()!==`hide`||!e.ignored,[T,E]=v(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!T(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await re(t,e)}))).then(t=>{E(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&O(e,n)})},D=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function ne(e){return re(e,T())}async function re(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return D(t,i.entries??[])}catch(e){return _(e.message),null}}let O=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),k=``;b(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),ne(``).then(e=>{e&&k===t&&r(new Map([[``,e]]))}))});let ie=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await ne(e.path);t&&O(e.path,t)}},[A,ae]=v(``),[oe,se]=v(!1),[j,ce]=v(``),[le,M]=v(!1),ue=e=>/\.(md|markdown|mdx)$/i.test(e),de=0,fe=async e=>{let t=++de;ae(``),se(!0);try{let{highlightChunks:n}=await eu(async()=>{let{highlightChunks:e}=await import(`./shiki-B0FmuYpl.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(de!==t)return;ae(e=>e+r)}}catch{de===t&&ae(``)}finally{de===t&&se(!1)}};C(()=>{de++});let pe=async(t,n)=>{let r=qm(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),ce(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&fe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},me=async()=>{let t=o();if(t&&!le()){M(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:j(),baseContent:t.content})}),c({...t,content:j()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
27
|
+
`)[0]??``,140),null),B(e,()=>r().data?.ok===!1?` · FAILED`:``,null),e})():_f())];break}case`list_dir`:e=c(`path`)||`.`,n=f(4e3);break;case`read_url`:{let r=c(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=Rm(r,70),t=`web`,n=[(()=>{var e=nf();return B(e,N(F,{get when(){return/^https?:/i.test(c(`url`))},get fallback(){return(()=>{var e=yf();return B(e,()=>Rm(c(`url`),80)),e})()},get children(){var e=vf();return y(()=>R(e,`href`,c(`url`))),e}})),e})(),I(()=>f(3e3))];break}case`bash_output`:{let r=c(`action`)||`read`;e=`bash_output ${c(`job_id`)||`(?)`}`,t=r,n=f(4e3);break}case`load_skill`:{e=`skill: ${c(`name`)}`;let t=s().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);n=r()?[(()=>{var e=mu();return y(()=>e.innerHTML=Pe(t)),e})(),(()=>{var e=nf();return B(e,()=>ze(r().data?.durationMs)),e})()]:bf();break}case`save_skill`:{e=`skill: ${c(`name`)}`,t=Rm(c(`description`),60);let i=Array.isArray(a.args?.files)?a.args.files.map(e=>e?.name).filter(Boolean):[];n=[I(()=>I(()=>!!i.length)()?(()=>{var e=xf();return e.firstChild,B(e,()=>i.join(`, `),null),e})():null),I(()=>I(()=>!!r())()?(()=>{var e=ff(),t=e.firstChild;return B(e,()=>Rm(s(),160),t),B(e,()=>ze(r().data?.durationMs),null),e})():Sf())];break}}}catch{}return{label:e,hint:t,body:n,key:`${r()?.id??`none`}|${e}|${t??``}`}},void 0,{equals:(e,t)=>e.key===t.key});return(()=>{var a=wf(),c=a.firstChild,d=c.firstChild,f=d.nextSibling,m=f.nextSibling;return a.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),B(d,()=>p().label),B(c,N(F,{get when(){return t.data?.actor},get children(){var e=Cf();return e.firstChild,B(e,()=>String(t.data.actor),null),e}}),f),B(f,(()=>{var e=I(()=>!!r());return()=>e()?p().hint||``:I(()=>!!i())()?`(result missed)`:I(()=>!!(o===`bash`||u()))()?N(Dm,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return u()}}):`running…`})()),B(m,N(Bm,{get text(){return l()},label:`⧉ cmd`,title:`copy the ${o} arguments`}),null),B(m,N(F,{get when(){return r()},get children(){return N(Bm,{get text(){return s()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),B(a,()=>p().body,null),y(e=>{var t=`embed`+(n?` grouped`:``)+(r()?r().data?.ok===!1?` fail`:` done`:i()?` done`:` running`),s=`${o}${p().hint?` — `+p().hint:``}`;return t!==e.e&&z(a,e.e=t),s!==e.t&&R(a,`title`,e.t=s),e},{e:void 0,t:void 0}),a})()}function Am(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function jm(e){let t=e.e,n=vm(t),r=()=>Dt(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Dt(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Tf(),r=n.firstChild.nextSibling;return r.nextSibling,B(n,()=>String(e.fromBranch??`?`),r),B(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=ht(t.data??{});return(()=>{var t=Ef(),n=t.firstChild;return B(n,()=>e.label),B(t,N(F,{get when(){return e.hasCard},get children(){var t=hf();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Pe(e.detail):Pe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&z(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>z(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Df(),n=e.firstChild.nextSibling;return n.nextSibling,B(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Of(),n=e.firstChild;return B(e,()=>t.data.from,n),B(e,()=>t.data.to,null),B(e,(()=>{var e=I(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>z(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=kf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,B(n,()=>String(t.data?.failures),r),B(n,()=>String(t.data?.limit),i),B(a,()=>String(t.data?.lastTool),o),B(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>R(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Af(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,B(n,()=>String(t.data?.attempt),r),B(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=hf();return z(r,`divider-msg`+(e?` err`:``)),B(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>R(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=jf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,B(e,()=>String(t.data?.tokensBefore??`?`),n),B(e,()=>String(t.data?.tokensAfter??`?`),r),B(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Mf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,B(e,()=>String(t.data?.messages??`?`),n),B(e,()=>String(t.data?.tokensBefore??`?`),r),B(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=Lf(),o=a.firstChild,s=o.nextSibling;return B(o,(()=>{var e=I(()=>!!r());return()=>e()?``:n.icon})()),B(s,(()=>{var e=I(()=>!!r());return()=>e()&&(()=>{var e=Rf();return y(()=>R(e,`title`,`${Cm(t.ts)} · ${t.branch}`)),e})()})(),null),B(s,N(F,{get when(){return!r()},get children(){var r=If(),i=r.firstChild,a=i.nextSibling;return B(i,()=>n.name),B(r,N(F,{get when(){return t.data?.actor},get children(){var e=Cf();return e.firstChild,B(e,()=>String(t.data.actor),null),e}}),a),B(a,(()=>{var e=I(()=>!!t.data?.pending);return()=>e()?`queued…`:I(()=>!!t.data?.cancelled)()?`withdrawn`:Cm(t.ts)})()),B(r,N(F,{get when(){return e.showBranch},get children(){var e=Nf();return B(e,()=>t.branch),e}}),null),B(r,N(F,{get when(){return e.onCancel},get children(){var t=Pf();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),B(r,N(F,{get when(){return t.type!==`tool_call`},get children(){return N(Bm,{get text(){return Am(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),B(r,N(F,{get when(){return e.onEdit},get children(){var t=Ff();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Te(i,`color`,n.color)),r}}),null),B(s,N(Nm,{e:t,get prev(){return e.prev?.()},get res(){return e.res},get orphan(){return e.orphan},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get onAnswered(){return e.onAnswered},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var s=`msg`+(r()?` grouped`:``)+(i()?` next-grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),c=t.id,l=`avatar avghost`+(r()?` ghosted`:``),u=r()?`transparent`:n.color+`33`,d=r()?`1px solid transparent`:`1px solid ${n.color}66`,f=r()?`${Cm(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&z(a,e.e=s),c!==e.t&&R(a,`data-eid`,e.t=c),l!==e.a&&z(o,e.a=l),u!==e.o&&Te(o,`background`,e.o=u),d!==e.i&&Te(o,`border`,e.i=d),f!==e.n&&R(o,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),a})()}function Mm(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=zf(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&R(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function Nm(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=mu();return y(()=>e.innerHTML=cm(String(t.data.text??``))),e})(),N(F,{get when(){return e.length},get children(){var t=Bf();return B(t,N(P,{each:e,children:e=>(()=>{var t=Vf();return R(t,`src`,e),t})()})),t}})]}case`message`:return[N(F,{get when(){return I(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Hf(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return B(n,(()=>{var e=I(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Im(String(t.data.reasoning).length)} — truncated)`:``})(),null),B(r,()=>Pm(String(t.data.reasoning),8e3)),e}}),(()=>{var e=mu();return y(()=>e.innerHTML=cm(String(t.data.content??``))),e})(),N(F,{get when(){return t.data.interrupted},get children(){return Uf()}}),N(F,{get when(){return t.data.final},get children(){var e=Wf(),n=e.firstChild;return B(e,N(Bm,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return N(km,{e:t,get prev(){return e.prev},get res(){return e.res},get orphan(){return e.orphan},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=Kf(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return z(a,`embed `+(i?``:`fail`)),B(s,r===`bash`?`$ (bash, call evicted)`:r),B(o,N(Bm,{text:n}),null),B(c,()=>Pm(n,4e3)),B(l,()=>ze(t.data.durationMs),null),B(l,()=>r===`bash`?Rt(Lt(t.data.ok,n)):i?``:` · FAILED`,null),B(a,N(F,{get when(){return e.orphan},get children(){return Gf()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=Jf(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return B(n,N(F,{get when(){return e.length},get children(){var t=qf();return t.firstChild,B(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=cm(String(t.data?.decision??``)),r=cm(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=()=>e.answeredIds?.().has(r)??!1;return(()=>{var a=Zf(),o=a.firstChild.firstChild.nextSibling;return B(a,N(F,{get when(){return i()},get children(){return Yf()}}),null),B(a,N(F,{get when(){return n.length>0},get children(){var a=Xf();return B(a,N(P,{each:n,children:n=>(()=>{var a=Qf();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},B(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),B(a,N(Mm,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=cm(String(t.data?.question??``));return n!==e.e&&z(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=$f(),n=e.firstChild.firstChild.nextSibling;return B(e,N(F,{get when(){return t.data.goalStatus},get children(){var e=Id(),n=e.firstChild.nextSibling;return B(n,()=>String(t.data.goalStatus)),e}}),null),B(e,N(F,{get when(){return t.data.recent},get children(){var e=Nd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=cm(String(t.data.recent))),e}}),null),B(e,N(F,{get when(){return t.data.problems},get children(){var e=Pd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=cm(String(t.data.problems))),e}}),null),B(e,N(F,{get when(){return t.data.next},get children(){var e=Fd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=cm(String(t.data.next))),e}}),null),y(()=>n.innerHTML=cm(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=ep(),n=e.firstChild;return n.firstChild,B(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=np(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,B(n,()=>String(t.data.mode??``),r),B(n,()=>Im(Number(t.data.tokensBefore??0)),i),B(n,()=>Im(Number(t.data.tokensAfter??0)),a),B(n,(()=>{var e=I(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),B(e,N(F,{get when(){return t.data.summary},get children(){return[tp(),(()=>{var e=mu();return y(()=>e.innerHTML=cm(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=rp();return B(e,()=>Pm(JSON.stringify(t.data),200)),e})()}}function Pm(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Fm(e){let t=new Date(e).getTime()-Date.now(),n=Math.abs(t),r=n<9e4?`${Math.round(n/1e3)}s`:n<54e5?`${Math.round(n/6e4)}m`:`${(n/36e5).toFixed(1)}h`;return t>=0?`in ${r}`:`${r} ago`}function Im(e){return e>=1e9?`${+(e/1e9).toFixed(1)}b`:e>=1e6?`${+(e/1e6).toFixed(1)}m`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Lm(e){return e>=100?Math.round(e).toLocaleString():e>=10?e.toFixed(1):e>=1?e.toFixed(2):e>=.01?e.toFixed(3):e.toFixed(4)}function Rm(e,t){return Pm(e.replace(/\s+/g,` `).trim(),t)}function zm(e){return(()=>{var t=ip(),n=t.firstChild;return Ce(t,`click`,e.onClick,!0),B(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&z(t,n.e=r),i!==n.t&&R(t,`title`,n.t=i),n.a=we(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Bm(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),wt(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=ap();return n.$$click=a,B(n,(()=>{var n=I(()=>!!t());return()=>n()?`✓`:I(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>R(n,`title`,e.title??`copy to clipboard`)),n})()}function Vm(e){return(()=>{var t=op(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),B(r,()=>e.title),Ce(i,`click`,e.onClose,!0),B(n,()=>e.children,null),t})()}function Hm(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}ee(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return N(Vm,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=cp(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),B(b,N(P,{get each(){return r()},children:e=>(()=>{var n=lp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),B(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),B(w,N(P,{get each(){return e.providers},children:e=>(()=>{var t=qu();return B(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),B(i,N(F,{get when(){return d()},get children(){var e=sp();return B(e,d),e}}),E),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>T.value=l()),i}})}var Um=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Wm=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Gm=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Km(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=qm(e);return n===`image`?`🖼`:n===`video`?`🎬`:n===`audio`?`🎵`:[`ts`,`tsx`,`mts`,`cts`].includes(t)?`🟦`:[`js`,`mjs`,`cjs`,`jsx`].includes(t)?`🟨`:t===`json`||t===`jsonc`?`🧾`:t===`md`||t===`mdx`||t===`markdown`?`📝`:t===`css`||t===`scss`||t===`less`?`🎨`:t===`html`||t===`htm`||t===`svg`?`🌐`:[`py`,`pyi`].includes(t)?`🐍`:t===`rs`?`🦀`:t===`go`?`🐹`:t===`java`||t===`kt`||t===`kts`?`☕`:t===`rb`?`💎`:t===`php`?`🐘`:t===`c`||t===`h`||t===`cpp`||t===`hpp`||t===`cc`?`🧩`:t===`sh`||t===`bash`||t===`zsh`||t===`fish`?`🐚`:t===`sql`?`🗄`:t===`yml`||t===`yaml`||t===`toml`||t===`ini`||t===`conf`?`⚙`:t===`lock`?`🔒`:e===`Dockerfile`||t===`dockerfile`?`🐳`:t===`zip`||t===`gz`||t===`tar`||t===`tgz`||t===`bz2`?`📦`:t===`pdf`?`📕`:t===`txt`||t===`log`?`📄`:`·`}function qm(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Um.has(t)?`image`:Wm.has(t)?`video`:Gm.has(t)?`audio`:null}var Jm=new Map,Ym=e=>{let t=Jm.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Jm.set(e,t)),t};function Xm(e){let t=Number(localStorage.getItem(`teapot.todoH`)??``),[n,r]=v(Number.isFinite(t)&&t>0?t:0),i=()=>n()>0?{height:`${n()}px`}:void 0,a=e=>{let t=new ResizeObserver(()=>{let t=e.offsetHeight;t<=0||r(e=>Math.abs(e-t)<1?e:(localStorage.setItem(`teapot.todoH`,String(t)),t))});t.observe(e),C(()=>t.disconnect())};return N(F,{get when(){return e.preview},get fallback(){return(()=>{var t=dp();return t.$$input=t=>e.onDraft(t.currentTarget.value),Ee(a,t),y(e=>we(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=up();return Ee(a,t),y(n=>{var r=i(),a=cm(e.draft);return n.e=we(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function Zm(e){let t=Ym(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),ee=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},w=e=>x()!==`hide`||!e.ignored,[T,E]=v(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!T(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await re(t,e)}))).then(t=>{E(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&O(e,n)})},D=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function ne(e){return re(e,T())}async function re(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return D(t,i.entries??[])}catch(e){return _(e.message),null}}let O=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),k=``;b(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),ne(``).then(e=>{e&&k===t&&r(new Map([[``,e]]))}))});let ie=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await ne(e.path);t&&O(e.path,t)}},[A,ae]=v(``),[oe,se]=v(!1),[j,ce]=v(``),[le,M]=v(!1),ue=e=>/\.(md|markdown|mdx)$/i.test(e),de=0,fe=async e=>{let t=++de;ae(``),se(!0);try{let{highlightChunks:n}=await eu(async()=>{let{highlightChunks:e}=await import(`./shiki-BSrXDQx7.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(de!==t)return;ae(e=>e+r)}}catch{de===t&&ae(``)}finally{de===t&&se(!1)}};C(()=>{de++});let pe=async(t,n)=>{let r=qm(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),ce(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&fe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},me=async()=>{let t=o();if(t&&!le()){M(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:j(),baseContent:t.content})}),c({...t,content:j()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
28
28
|
OK = load the disk version into the editor (your edits are discarded)
|
|
29
|
-
Cancel = keep editing your copy`)?(ce(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{M(!1)}}},he=e=>!e.binary&&!e.truncated,ge=(e,t)=>[(()=>{var n=pp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void pe(e,`code`),B(r,(()=>{var t=I(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Km(e.name)})()),B(a,()=>e.name),B(n,N(F,{get when(){return I(()=>!e.dir)()&&e.size!==void 0},get children(){var t=fp();return B(t,()=>Im(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&z(n,r.e=i),r.t=we(n,a,r.t),o!==r.a&&R(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),N(F,{get when(){return I(()=>!!e.dir)()&&i().has(e.path)},get children(){return N(P,{get each(){return(n().get(e.path)??[]).filter(w)},children:e=>ge(e,t+1)})}})],_e=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ve,ye]=v(!1),be=async()=>{if(!ve()){ye(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await re(e,T())})));for(let{p:e,rows:n}of t)n&&O(e,n)}finally{ye(!1)}}};return[(()=>{var e=mp(),t=e.firstChild.nextSibling;return t.firstChild,B(t,_e,null),B(e,N(zm,{class:`filetoggle`,get icon(){return ve()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void be()}),null),B(e,N(zm,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return I(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),B(e,N(zm,{class:`filetoggle`,get icon(){return T()?`◉.`:`○.`},get title(){return T()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:te}),null),e})(),(()=>{var e=hp();return B(e,N(F,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=gp();return B(e,()=>g()||`empty workspace`),e})()},get children(){return N(P,{get each(){return(n().get(``)??[]).filter(w)},children:e=>ge(e,0)})}})),e})(),N(F,{get when(){return o()},children:t=>N(Vm,{get title(){return`🗂 ${t().path}`},onClose:()=>{de++,c(null),f(null)},get children(){return N(F,{get when(){return u()},get fallback(){return[(()=>{var e=xp(),n=e.firstChild;return B(e,N(F,{get when(){return I(()=>!!ue(t().path))()&&!t().binary},get children(){var e=yp();return e.$$click=()=>h(`md`),y(()=>z(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),A()||fe({path:t().path,content:t().content,truncated:t().truncated})},B(e,N(F,{get when(){return he(t())},get children(){var e=bp();return e.$$click=()=>h(`edit`),y(()=>z(e,p()===`edit`?`on`:``)),e}}),null),y(()=>z(n,p()===`code`?`on`:``)),e})(),N(F,{get when(){return!t().binary},get fallback(){return Cp()},get children(){return N(F,{get when(){return p()===`edit`},get fallback(){return N(F,{get when(){return I(()=>p()===`md`)()&&ue(t().path)},get fallback(){return N(Qm,{get path(){return t().path},get content(){return t().content},get html(){return A()},get pending(){return oe()},get truncated(){return!!t().truncated}})},get children(){var e=wp();return y(()=>e.innerHTML=Pe(t().content)),e}})},get children(){var e=Sp(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>ce(e.currentTarget.value),R(n,`spellcheck`,!1),B(r,()=>Im(j().length),i),a.$$click=()=>void me(),B(a,()=>le()?`saving…`:`💾 save`),y(()=>a.disabled=le()||j()===t().content),y(()=>n.value=j()),e}})}})]},get children(){var t=vp(),n=t.firstChild,r=n.firstChild;return B(t,N(F,{get when(){return u().kind===`image`},get fallback(){return N(F,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=Ep();return y(()=>R(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Tp();return y(()=>R(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=_p();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&R(t,`src`,n.e=r),i!==n.t&&R(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),B(n,()=>u().kind,r),t}})}})})]}function Qm(e){return[N(F,{get when(){return e.html},get fallback(){return I(()=>!!e.pending)()?(()=>{var t=kp(),n=t.firstChild.nextSibling;return n.nextSibling,B(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Ap();return B(t,()=>e.content),t})()},get children(){var t=Dp();return y(()=>t.innerHTML=e.html),t}}),N(F,{get when(){return e.truncated},get children(){return Op()}})]}var $m=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:``,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:``,hint:`zero-markup routing gateway — 'orcarouter/auto' grades each prompt and picks the model`},{key:`openai`,label:`OpenAI`,url:`https://api.openai.com/v1`,model:``,hint:`your account's models — pick from the list once the endpoint answers`},{key:`opencode-go`,label:`OpenCode Go`,url:`https://opencode.ai/zen/go/v1`,model:``,hint:`OpenCode's open-model subscription — teapot sends the required x-opencode-session header; choose a chat/completions model`},{key:`llamacpp`,label:`llama.cpp server`,url:`http://localhost:8080/v1`,model:``,hint:`free & local — start it with: llama-server -m ./model.gguf (any model name works)`}],eh={key:`custom`,label:`Custom`,url:``,model:``,hint:`any OpenAI-compatible /v1 endpoint — vLLM, LM Studio, llama.cpp, a company gateway… fill the fields below`};function th(e){let[t,n]=v($m[0]),[r,i]=v($m[0].url),[a,o]=v(``),[s,c]=v($m[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);C(()=>clearTimeout(n))});let ee=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Im(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},w=()=>ee(s()),T=()=>{let e=s().trim().toLowerCase();return e?l().filter(t=>t.id.toLowerCase().includes(e)):l()},E=async t=>{if(t.preventDefault(),x(``),!s().trim())x(l().length?`pick a model — choose one from the list, or type its id`:`pick a model — type its id (the endpoint has not listed any yet)`);else{g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}}};return(()=>{var e=Fp(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,C=x.firstChild.nextSibling,te=x.nextSibling,D=te.firstChild.nextSibling,ne=D.nextSibling,re=te.nextSibling,O=re.firstChild.nextSibling,k=O.firstChild.nextSibling,ie=O.nextSibling.firstChild.nextSibling,A=re.nextSibling;return n.addEventListener(`submit`,E),B(u,()=>[...$m,eh].map(e=>(()=>{var n=Ip();return n.$$click=()=>S(e),B(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&z(n,r.e=i),a!==r.t&&R(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),B(n,N(F,{get when(){return t().hint},get children(){var e=jp();return B(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),B(b,()=>$m.map(e=>(()=>{var t=qu();return y(()=>t.value=e.url),t})())),C.$$input=e=>o(e.currentTarget.value),D.$$input=e=>c(e.currentTarget.value),B(ne,()=>l().map(e=>(()=>{var t=qu();return y(()=>t.value=e.id),t})())),B(n,N(F,{get when(){return T().length>0},get fallback(){return(()=>{var e=Lp();return B(e,()=>l().length?`no model matches that — clear the field to see them all`:`models appear here automatically once the endpoint answers GET /models`),e})()},get children(){return[(()=>{var e=Mp();return B(e,()=>T().slice(0,40).map(e=>(()=>{var t=Rp(),n=t.firstChild;return t.$$click=()=>c(e.id),B(n,()=>e.id),B(t,N(F,{get when(){return ee(e.id)},get children(){var t=yf();return B(t,()=>ee(e.id)),t}}),null),y(n=>{var r=`wizmodel`+(s()===e.id?` active`:``),i=ee(e.id)||e.id;return r!==n.e&&z(t,n.e=r),i!==n.t&&R(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})())),e})(),(()=>{var e=Pp(),t=e.firstChild;return B(e,()=>T().length,t),B(e,()=>T().length>1?`s`:``,null),B(e,N(F,{get when(){return T().length>40},children:` (showing the first 40 — keep typing to narrow)`}),null),B(e,N(F,{get when(){return w()},get children(){return[` · selected: `,(()=>{var e=Np();return B(e,w),e})()]}}),null),e})()]}}),re),k.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),B(n,N(F,{get when(){return _()},get children(){var e=sp();return B(e,_),e}}),A),B(A,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(pick from the list below, or type an id)`,r=h();return n!==e.e&&R(D,`placeholder`,e.e=n),r!==e.t&&(A.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>C.value=a()),y(()=>D.value=s()),y(()=>k.value=d()),y(()=>ie.value=p()),e})()}function nh(e){let t=(e,t)=>{let n=Array.isArray(t?.apiKeys)&&t.apiKeys.length?t.apiKeys.filter(e=>typeof e==`string`&&e.trim()):t?.apiKey?[String(t.apiKey)]:[``];return{name:e,baseUrl:t?.baseUrl??``,apiKeys:n.length?n:[``],model:t?.model??``}},[n,r]=v(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=v(e.cfg.defaultProvider??``),o=()=>e.cfg.defaultProvider??``,s=()=>{let e=[...new Set(n().map(e=>e.name.trim()).filter(Boolean))],t=i();return t&&!e.includes(t)&&e.push(t),e},c=()=>{let e=i();return e?n().some(t=>t.name.trim()===e)?``:e:``},[l,u]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=v(e.cfg.progressMinChars??4e3),[p,m]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,x]=v(e.cfg.maxSpawnDepth??3),[S,ee]=v(!!e.cfg.shortContext),[C,w]=v((e.cfg.tasks??[]).map(e=>({...e}))),[T,E]=v((e.cfg.mcpServers??[]).map(e=>({...e}))),[te,D]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ne,re]=v({}),[O,k]=v({}),[ie,A]=v({}),[ae,oe]=v({}),se=async()=>{let e=await $(`/api/mcp`).catch(()=>null);A(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},j=async(e,t)=>{if(!t)return;let n=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&oe(t=>({...t,[e]:n}))},ce=async(t,n)=>{if(!n.name){k(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}k(e=>({...e,[t]:{kind:`testing`,text:`discovering the authorization server…`}}));let r=await $(`/api/mcp/oauth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name})}).catch(()=>null);if(r?.alreadyAuthorized){k(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await j(t,n.name),await se();return}if(!r?.ok||!r.url){k(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await j(t,n.name);return}window.open(r.url,`_blank`,`noopener`),k(e=>({...e,[t]:{kind:`testing`,text:`waiting for you to finish in the browser…`}}));let i=Date.now()+3e5;for(;Date.now()<i;){await new Promise(e=>setTimeout(e,1e3));let r=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(n.name)}`).catch(()=>null);if(r&&!r.error){if(oe(e=>({...e,[t]:r})),r.authorized){k(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await se(),e.onSaved();return}if(r.flow?.phase===`error`){k(e=>({...e,[t]:{kind:`err`,text:r.flow.message??r.lastError??`authorization failed`}}));return}}}k(e=>({...e,[t]:{kind:`err`,text:`authorization timed out`}}))};b(()=>{ue()===`mcp`&&(se(),T().forEach((e,t)=>{e.name&&j(t,e.name)}))});let[le,M]=v(``),[ue,de]=v(`providers`),[fe,pe]=v([]),me=async()=>{let e=await $(`/api/archived`).catch(()=>null);pe(e?.agents??[])},he=()=>fe().filter(e=>!e.parent);b(()=>{ue()===`archive`&&me()});let ge=[{key:`providers`,label:`🧦 providers`,hint:`endpoints, API keys, default models`},{key:`runtime`,label:`⚙️ runtime`,hint:`context budget, retries, spawn depth`},{key:`tasks`,label:`⏰ scheduled tasks`,hint:`cron prompts run against an agent`},{key:`mcp`,label:`🔌 MCP servers`,hint:`external tool servers exposed to every agent`},{key:`archive`,label:`🗄 archive`,hint:`agents you put away — restore or delete for good`},{key:`agents`,label:`👥 agents`,hint:`what exists (read-only)`},{key:`update`,label:`⬆️ live update`,hint:`restart onto a newer build`}],_e=()=>(e.cfg.agents??[]).map(e=>e.id),ye=()=>{let e={};for(let t of n()){if(!t.name.trim())return M(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return M(`provider ${t.name}: baseUrl must start with http(s)://`),null;let n=t.apiKeys.map(e=>e.trim()).filter(Boolean);e[t.name.trim()]={baseUrl:t.baseUrl,...n.length?{apiKeys:n,apiKey:n[0]}:{},...t.model?{model:t.model}:{}}}return e},be=async t=>{t.preventDefault(),M(``);let n=ye();if(!n)return;let r=C().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of r){if(!e.agent){M(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){M(`task "${e.id}": schedule is required`);return}}let a=[],o=new Set;for(let e of T()){let t=String(e.name??``).trim(),n=String(e.url??``).trim(),r=e.transport??`http`,i=String(e.command??``).trim();if(t||n||i){if(!t){M(`MCP: a server needs a name`);return}if(o.has(t)){M(`MCP: two servers are named "${t}"`);return}if(o.add(t),r===`stdio`?!i:!n){M(`MCP "${t}": ${r===`stdio`?`a command is`:`a url is`} required`);return}a.push({name:t,transport:r,enabled:e.enabled!==!1,...n?{url:n}:{},...r===`stdio`?{command:i,...e.args?.length?{args:e.args}:{}}:{},...e.headers&&Object.keys(e.headers).length?{headers:e.headers}:{}})}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:i()||void 0,progressIntervalMs:Math.max(1,l())*6e4,progressMinChars:Math.max(100,d()),...p()==null?{}:{contextTokenBudget:Math.max(1,p())*1e3},...h()>0?{contextWindowTokens:h()*1e3}:{},maxSpawnDepth:Math.max(0,_()),shortContext:S(),tasks:r,mcpServers:a})}),await se(),await Promise.all(a.map((e,t)=>e.name?j(t,e.name):Promise.resolve())),setTimeout(()=>{se(),a.forEach((e,t)=>{e.name&&j(t,e.name)})},1200),e.onSaved(),T().some((e,t)=>ae()[t]?.required&&!ae()[t]?.authorized)?(de(`mcp`),Q(`a saved MCP server needs authorization — see 🔑 authorize`)):e.onClose()}catch(e){M(e.message)}},xe=(e,t,n,r)=>(()=>{var i=zp(),a=i.firstChild;return R(i,`title`,r),B(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return N(Vm,{title:`settings`,get onClose(){return e.onClose},get children(){var t=Vp(),v=t.firstChild,b=v.firstChild,A=b.nextSibling.firstChild,oe=A.firstChild.nextSibling,se=oe.nextSibling;se.firstChild;var fe=se.nextSibling.firstChild.firstChild.nextSibling;fe.firstChild;var pe=A.nextSibling,ye=pe.firstChild.nextSibling,L=ye.firstChild,Se=L.firstChild.nextSibling,Ce=ye.nextSibling.firstChild,Te=pe.nextSibling,Ee=Te.firstChild.nextSibling.nextSibling,De=Te.nextSibling,Oe=De.firstChild.nextSibling,ke=De.nextSibling;ke.firstChild;var Ae=ke.nextSibling;Ae.firstChild;var je=Ae.nextSibling,Me=je.firstChild.nextSibling.firstChild;Me.firstChild;var Ne=Me.nextSibling,Pe=v.nextSibling,Fe=Pe.firstChild;return t.addEventListener(`submit`,be),B(b,N(P,{each:ge,children:e=>(()=>{var t=Hp(),n=t.firstChild;return t.$$click=()=>de(e.key),B(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(ue()===e.key?` on`:``),i=e.hint,a=ue()===e.key?`page`:void 0;return r!==n.e&&z(t,n.e=r),i!==n.t&&R(t,`title`,n.t=i),a!==n.a&&R(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),B(A,N(ve,{get each(){return n()},children:(e,t)=>(()=>{var i=Up(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.firstChild;return a.$$input=e=>r(n().map((n,r)=>r===t?{...n,name:e.currentTarget.value}:n)),o.$$input=e=>r(n().map((n,r)=>r===t?{...n,baseUrl:e.currentTarget.value}:n)),s.$$input=e=>r(n().map((n,r)=>r===t?{...n,model:e.currentTarget.value}:n)),c.$$click=()=>r(n().filter((e,n)=>n!==t)),B(l,N(P,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=Gp(),s=o.firstChild;return s.$$input=e=>r(n().map((n,r)=>r===t?{...n,apiKeys:n.apiKeys.map((t,n)=>n===a()?e.currentTarget.value:t)}:n)),s.value=i,B(o,N(F,{get when(){return e().apiKeys.length>1},get children(){var e=Wp();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>R(s,`placeholder`,a()===0?`api key`:`api key (backup)`)),o})()}),u),u.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:[...e.apiKeys,``]}:e)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().model),i})()}),oe),oe.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),B(se,N(P,{each:$m,children:e=>(()=>{var t=Kp();return t.firstChild,t.$$click=()=>{let t=n().filter(t=>t.name!==e.key);r([...t,{name:e.key,baseUrl:e.url,apiKeys:[``],model:e.model}]),i()||a(e.key)},B(t,()=>e.label,null),y(()=>R(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),fe.addEventListener(`change`,e=>a(e.currentTarget.value)),B(fe,N(P,{get each(){return s()},children:e=>(()=>{var t=qu();return t.value=e,B(t,e),t})()}),null),B(A,N(F,{get when(){return c()},get children(){var e=Bp(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return B(t,c),B(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),B(r,c),e}}),null),B(ye,()=>xe(`progress interval (min)`,l(),e=>u(e),`how often the harness asks for a progress report`),L),B(ye,()=>xe(`progress min chars`,d(),e=>f(e),`progress prompts wait for this much real output`),L),Se.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),B(ye,()=>xe(`context window (k tok)`,h(),e=>g(e),`model's real window — 0/blank hides the % gauge`),null),B(ye,()=>xe(`max spawn depth`,_(),e=>x(e),`sub-agent nesting limit (0 = no spawning)`),null),Ce.addEventListener(`change`,e=>ee(e.currentTarget.checked)),B(Te,N(F,{get when(){return T().length>0},get fallback(){return qp()},get children(){return N(ve,{get each(){return T()},children:(e,t)=>{let n=()=>ie()[e().name],r=e=>E(T().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=tm(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.nextSibling,l=c.firstChild,u=c.nextSibling,d=a.nextSibling,f=d.firstChild,p=d.nextSibling,m=p.firstChild,h=m.nextSibling;return o.$$input=e=>r({name:e.currentTarget.value}),s.$$input=e=>r({url:e.currentTarget.value}),l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>E(T().filter((e,n)=>n!==t)),f.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),B(d,N(F,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=Jp();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=Yp();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),y(()=>t.value=(e().args??[]).join(` `)),t})()]}}),null),m.$$input=e=>{let n=e.currentTarget.value;if(D(e=>({...e,[t]:n})),!n.trim())r({headers:void 0});else try{r({headers:JSON.parse(n)}),re(e=>({...e,[t]:``}))}catch{re(e=>({...e,[t]:`not valid JSON — not applied`}))}},h.$$click=async()=>{let e=T()[t];if(!e.name){k(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}k(e=>({...e,[t]:{kind:`testing`,text:`connecting…`}}));let n=await $(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}).catch(()=>null);k(e=>({...e,[t]:n?.ok?{kind:`ok`,text:`${n.tools?.length??0} tools`}:{kind:`err`,text:n?.error??`no response`}})),n?.ok||await j(t,e.name)},B(p,N(F,{get when(){return I(()=>!!ae()[t]?.required)()&&!ae()[t]?.authorized},get children(){var n=Xp();return n.$$click=()=>void ce(t,e()),n}}),null),B(p,N(F,{get when(){return ae()[t]?.authorized},get children(){return[Zp(),(()=>{var n=Qp();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await j(t,e().name),k(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),B(p,N(F,{get when(){return n()},get children(){var e=ld();return B(e,(()=>{var e=I(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:I(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&z(e,t.e=r),i!==t.t&&R(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),B(i,N(F,{get when(){return ne()[t]},get children(){var e=$p();return B(e,()=>ne()[t]),e}}),null),B(i,N(F,{get when(){return O()[t]},get children(){var e=em();return B(e,()=>O()[t]?.text),y(n=>we(e,O()[t]?.kind===`err`?`color:var(--err)`:`color:var(--ok)`,n)),e}}),null),y(()=>o.value=e().name),y(()=>s.value=e().url??``),y(()=>l.checked=e().enabled!==!1),y(()=>f.value=e().transport??`http`),y(()=>m.value=te()[t]??``),i})()}})}}),Ee),Ee.$$click=()=>E([...T(),{name:``,url:``,transport:`http`,enabled:!0}]),B(De,N(F,{get when(){return C().length>0},get children(){return N(ve,{get each(){return C()},children:(e,t)=>(()=>{var n=nm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>w(C().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>w(C().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>w(C().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>w(C().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>w(C().filter((e,n)=>n!==t)),u.$$input=e=>w(C().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e().id),y(()=>a.value=e().agent),y(()=>o.value=e().schedule),y(()=>c.checked=!!e().forked),y(()=>u.value=e().prompt),n})()})}}),Oe),Oe.$$click=()=>w([...C(),{id:``,agent:_e()[0]??``,schedule:`every 30m`,prompt:``}]),B(ke,N(F,{get when(){return he().length>0},get fallback(){return rm()},get children(){return N(P,{get each(){return he()},children:t=>(()=>{var n=im(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return B(i,()=>t.id),B(a,()=>t.sessions,o),B(a,()=>t.sessions===1?``:`s`,null),B(a,(()=>{var e=I(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),B(a,(()=>{var e=I(()=>!!t.archivedAt);return()=>e()?` · archived ${Fm(new Date(t.archivedAt).toISOString())}`:``})(),null),B(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await me(),e.onSaved();let r=(n?.ids?.length??1)-1;Q((n?.live===!1?`restored ${t.id} — it could not be started (check its provider)`:`restored ${t.id}`)+(r>0?` + ${r} sub-agent${r===1?``:`s`}`:``))},l.$$click=async()=>{confirm(`PERMANENTLY DELETE ${t.id}?\n\n${t.sessions} session${t.sessions===1?``:`s`} of history will be erased from disk along with the config entry. This cannot be undone — archiving was the reversible option.`)&&(await $(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await me(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>R(s,`title`,t.workspace)),n})()})}}),null),B(Ae,N(P,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=om(),n=t.firstChild,r=n.nextSibling;return B(n,()=>e.id),B(r,()=>e.workspace),B(t,N(F,{get when(){return e.parent},get children(){var t=am();return t.firstChild,B(t,()=>e.parent,null),t}}),null),t})()}),null),B(Me,()=>e.cfg.version??`unknown`,null),Ne.$$click=async e=>{try{M(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await $(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=!1;for(let e=0;e<90&&!r;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await $(`/api/version`);e.version&&e.version!==`0.31.1`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){M(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},B(Pe,N(F,{get when(){return le()},get children(){var e=sp();return B(e,le),e}}),Fe),y(e=>{var t=ue()!==`providers`,n=ue()!==`runtime`,r=ue()!==`mcp`,i=ue()!==`tasks`,a=ue()!==`archive`,o=ue()!==`agents`,s=ue()!==`update`;return t!==e.e&&A.classList.toggle(`hide`,e.e=t),n!==e.t&&pe.classList.toggle(`hide`,e.t=n),r!==e.a&&Te.classList.toggle(`hide`,e.a=r),i!==e.o&&De.classList.toggle(`hide`,e.o=i),a!==e.i&&ke.classList.toggle(`hide`,e.i=a),o!==e.n&&Ae.classList.toggle(`hide`,e.n=o),s!==e.s&&je.classList.toggle(`hide`,e.s=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),y(()=>fe.value=i()),y(()=>Se.value=p()??``),y(()=>Ce.checked=S()),t}})}Se([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),xe(()=>N(Em,{}),document.getElementById(`root`));export{eu as t};
|
|
30
|
-
//# sourceMappingURL=index-
|
|
29
|
+
Cancel = keep editing your copy`)?(ce(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{M(!1)}}},he=e=>!e.binary&&!e.truncated,ge=(e,t)=>[(()=>{var n=pp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void pe(e,`code`),B(r,(()=>{var t=I(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Km(e.name)})()),B(a,()=>e.name),B(n,N(F,{get when(){return I(()=>!e.dir)()&&e.size!==void 0},get children(){var t=fp();return B(t,()=>Im(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&z(n,r.e=i),r.t=we(n,a,r.t),o!==r.a&&R(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),N(F,{get when(){return I(()=>!!e.dir)()&&i().has(e.path)},get children(){return N(P,{get each(){return(n().get(e.path)??[]).filter(w)},children:e=>ge(e,t+1)})}})],_e=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ve,ye]=v(!1),be=async()=>{if(!ve()){ye(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await re(e,T())})));for(let{p:e,rows:n}of t)n&&O(e,n)}finally{ye(!1)}}};return[(()=>{var e=mp(),t=e.firstChild.nextSibling;return t.firstChild,B(t,_e,null),B(e,N(zm,{class:`filetoggle`,get icon(){return ve()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void be()}),null),B(e,N(zm,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return I(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),B(e,N(zm,{class:`filetoggle`,get icon(){return T()?`◉.`:`○.`},get title(){return T()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:te}),null),e})(),(()=>{var e=hp();return B(e,N(F,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=gp();return B(e,()=>g()||`empty workspace`),e})()},get children(){return N(P,{get each(){return(n().get(``)??[]).filter(w)},children:e=>ge(e,0)})}})),e})(),N(F,{get when(){return o()},children:t=>N(Vm,{get title(){return`🗂 ${t().path}`},onClose:()=>{de++,c(null),f(null)},get children(){return N(F,{get when(){return u()},get fallback(){return[(()=>{var e=xp(),n=e.firstChild;return B(e,N(F,{get when(){return I(()=>!!ue(t().path))()&&!t().binary},get children(){var e=yp();return e.$$click=()=>h(`md`),y(()=>z(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),A()||fe({path:t().path,content:t().content,truncated:t().truncated})},B(e,N(F,{get when(){return he(t())},get children(){var e=bp();return e.$$click=()=>h(`edit`),y(()=>z(e,p()===`edit`?`on`:``)),e}}),null),y(()=>z(n,p()===`code`?`on`:``)),e})(),N(F,{get when(){return!t().binary},get fallback(){return Cp()},get children(){return N(F,{get when(){return p()===`edit`},get fallback(){return N(F,{get when(){return I(()=>p()===`md`)()&&ue(t().path)},get fallback(){return N(Qm,{get path(){return t().path},get content(){return t().content},get html(){return A()},get pending(){return oe()},get truncated(){return!!t().truncated}})},get children(){var e=wp();return y(()=>e.innerHTML=Pe(t().content)),e}})},get children(){var e=Sp(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>ce(e.currentTarget.value),R(n,`spellcheck`,!1),B(r,()=>Im(j().length),i),a.$$click=()=>void me(),B(a,()=>le()?`saving…`:`💾 save`),y(()=>a.disabled=le()||j()===t().content),y(()=>n.value=j()),e}})}})]},get children(){var t=vp(),n=t.firstChild,r=n.firstChild;return B(t,N(F,{get when(){return u().kind===`image`},get fallback(){return N(F,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=Ep();return y(()=>R(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Tp();return y(()=>R(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=_p();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&R(t,`src`,n.e=r),i!==n.t&&R(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),B(n,()=>u().kind,r),t}})}})})]}function Qm(e){return[N(F,{get when(){return e.html},get fallback(){return I(()=>!!e.pending)()?(()=>{var t=kp(),n=t.firstChild.nextSibling;return n.nextSibling,B(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Ap();return B(t,()=>e.content),t})()},get children(){var t=Dp();return y(()=>t.innerHTML=e.html),t}}),N(F,{get when(){return e.truncated},get children(){return Op()}})]}var $m=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:``,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:``,hint:`zero-markup routing gateway — 'orcarouter/auto' grades each prompt and picks the model`},{key:`openai`,label:`OpenAI`,url:`https://api.openai.com/v1`,model:``,hint:`your account's models — pick from the list once the endpoint answers`},{key:`opencode-go`,label:`OpenCode Go`,url:`https://opencode.ai/zen/go/v1`,model:``,hint:`OpenCode's open-model subscription — teapot sends the required x-opencode-session header; choose a chat/completions model`},{key:`llamacpp`,label:`llama.cpp server`,url:`http://localhost:8080/v1`,model:``,hint:`free & local — start it with: llama-server -m ./model.gguf (any model name works)`}],eh={key:`custom`,label:`Custom`,url:``,model:``,hint:`any OpenAI-compatible /v1 endpoint — vLLM, LM Studio, llama.cpp, a company gateway… fill the fields below`};function th(e){let[t,n]=v($m[0]),[r,i]=v($m[0].url),[a,o]=v(``),[s,c]=v($m[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);C(()=>clearTimeout(n))});let ee=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Im(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},w=()=>ee(s()),T=()=>{let e=s().trim().toLowerCase();return e?l().filter(t=>t.id.toLowerCase().includes(e)):l()},E=async t=>{if(t.preventDefault(),x(``),!s().trim())x(l().length?`pick a model — choose one from the list, or type its id`:`pick a model — type its id (the endpoint has not listed any yet)`);else{g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}}};return(()=>{var e=Fp(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,C=x.firstChild.nextSibling,te=x.nextSibling,D=te.firstChild.nextSibling,ne=D.nextSibling,re=te.nextSibling,O=re.firstChild.nextSibling,k=O.firstChild.nextSibling,ie=O.nextSibling.firstChild.nextSibling,A=re.nextSibling;return n.addEventListener(`submit`,E),B(u,()=>[...$m,eh].map(e=>(()=>{var n=Ip();return n.$$click=()=>S(e),B(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&z(n,r.e=i),a!==r.t&&R(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),B(n,N(F,{get when(){return t().hint},get children(){var e=jp();return B(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),B(b,()=>$m.map(e=>(()=>{var t=qu();return y(()=>t.value=e.url),t})())),C.$$input=e=>o(e.currentTarget.value),D.$$input=e=>c(e.currentTarget.value),B(ne,()=>l().map(e=>(()=>{var t=qu();return y(()=>t.value=e.id),t})())),B(n,N(F,{get when(){return T().length>0},get fallback(){return(()=>{var e=Lp();return B(e,()=>l().length?`no model matches that — clear the field to see them all`:`models appear here automatically once the endpoint answers GET /models`),e})()},get children(){return[(()=>{var e=Mp();return B(e,()=>T().slice(0,40).map(e=>(()=>{var t=Rp(),n=t.firstChild;return t.$$click=()=>c(e.id),B(n,()=>e.id),B(t,N(F,{get when(){return ee(e.id)},get children(){var t=yf();return B(t,()=>ee(e.id)),t}}),null),y(n=>{var r=`wizmodel`+(s()===e.id?` active`:``),i=ee(e.id)||e.id;return r!==n.e&&z(t,n.e=r),i!==n.t&&R(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})())),e})(),(()=>{var e=Pp(),t=e.firstChild;return B(e,()=>T().length,t),B(e,()=>T().length>1?`s`:``,null),B(e,N(F,{get when(){return T().length>40},children:` (showing the first 40 — keep typing to narrow)`}),null),B(e,N(F,{get when(){return w()},get children(){return[` · selected: `,(()=>{var e=Np();return B(e,w),e})()]}}),null),e})()]}}),re),k.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),B(n,N(F,{get when(){return _()},get children(){var e=sp();return B(e,_),e}}),A),B(A,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(pick from the list below, or type an id)`,r=h();return n!==e.e&&R(D,`placeholder`,e.e=n),r!==e.t&&(A.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>C.value=a()),y(()=>D.value=s()),y(()=>k.value=d()),y(()=>ie.value=p()),e})()}function nh(e){let t=(e,t)=>{let n=Array.isArray(t?.apiKeys)&&t.apiKeys.length?t.apiKeys.filter(e=>typeof e==`string`&&e.trim()):t?.apiKey?[String(t.apiKey)]:[``];return{name:e,baseUrl:t?.baseUrl??``,apiKeys:n.length?n:[``],model:t?.model??``}},[n,r]=v(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=v(e.cfg.defaultProvider??``),o=()=>e.cfg.defaultProvider??``,s=()=>{let e=[...new Set(n().map(e=>e.name.trim()).filter(Boolean))],t=i();return t&&!e.includes(t)&&e.push(t),e},c=()=>{let e=i();return e?n().some(t=>t.name.trim()===e)?``:e:``},[l,u]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=v(e.cfg.progressMinChars??4e3),[p,m]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,x]=v(e.cfg.maxSpawnDepth??3),[S,ee]=v(!!e.cfg.shortContext),[C,w]=v((e.cfg.tasks??[]).map(e=>({...e}))),[T,E]=v((e.cfg.mcpServers??[]).map(e=>({...e}))),[te,D]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ne,re]=v({}),[O,k]=v({}),[ie,A]=v({}),[ae,oe]=v({}),se=async()=>{let e=await $(`/api/mcp`).catch(()=>null);A(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},j=async(e,t)=>{if(!t)return;let n=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&oe(t=>({...t,[e]:n}))},ce=async(t,n)=>{if(!n.name){k(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}k(e=>({...e,[t]:{kind:`testing`,text:`discovering the authorization server…`}}));let r=await $(`/api/mcp/oauth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name})}).catch(()=>null);if(r?.alreadyAuthorized){k(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await j(t,n.name),await se();return}if(!r?.ok||!r.url){k(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await j(t,n.name);return}window.open(r.url,`_blank`,`noopener`),k(e=>({...e,[t]:{kind:`testing`,text:`waiting for you to finish in the browser…`}}));let i=Date.now()+3e5;for(;Date.now()<i;){await new Promise(e=>setTimeout(e,1e3));let r=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(n.name)}`).catch(()=>null);if(r&&!r.error){if(oe(e=>({...e,[t]:r})),r.authorized){k(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await se(),e.onSaved();return}if(r.flow?.phase===`error`){k(e=>({...e,[t]:{kind:`err`,text:r.flow.message??r.lastError??`authorization failed`}}));return}}}k(e=>({...e,[t]:{kind:`err`,text:`authorization timed out`}}))};b(()=>{ue()===`mcp`&&(se(),T().forEach((e,t)=>{e.name&&j(t,e.name)}))});let[le,M]=v(``),[ue,de]=v(`providers`),[fe,pe]=v([]),me=async()=>{let e=await $(`/api/archived`).catch(()=>null);pe(e?.agents??[])},he=()=>fe().filter(e=>!e.parent);b(()=>{ue()===`archive`&&me()});let ge=[{key:`providers`,label:`🧦 providers`,hint:`endpoints, API keys, default models`},{key:`runtime`,label:`⚙️ runtime`,hint:`context budget, retries, spawn depth`},{key:`tasks`,label:`⏰ scheduled tasks`,hint:`cron prompts run against an agent`},{key:`mcp`,label:`🔌 MCP servers`,hint:`external tool servers exposed to every agent`},{key:`archive`,label:`🗄 archive`,hint:`agents you put away — restore or delete for good`},{key:`agents`,label:`👥 agents`,hint:`what exists (read-only)`},{key:`update`,label:`⬆️ live update`,hint:`restart onto a newer build`}],_e=()=>(e.cfg.agents??[]).map(e=>e.id),ye=()=>{let e={};for(let t of n()){if(!t.name.trim())return M(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return M(`provider ${t.name}: baseUrl must start with http(s)://`),null;let n=t.apiKeys.map(e=>e.trim()).filter(Boolean);e[t.name.trim()]={baseUrl:t.baseUrl,...n.length?{apiKeys:n,apiKey:n[0]}:{},...t.model?{model:t.model}:{}}}return e},be=async t=>{t.preventDefault(),M(``);let n=ye();if(!n)return;let r=C().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of r){if(!e.agent){M(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){M(`task "${e.id}": schedule is required`);return}}let a=[],o=new Set;for(let e of T()){let t=String(e.name??``).trim(),n=String(e.url??``).trim(),r=e.transport??`http`,i=String(e.command??``).trim();if(t||n||i){if(!t){M(`MCP: a server needs a name`);return}if(o.has(t)){M(`MCP: two servers are named "${t}"`);return}if(o.add(t),r===`stdio`?!i:!n){M(`MCP "${t}": ${r===`stdio`?`a command is`:`a url is`} required`);return}a.push({name:t,transport:r,enabled:e.enabled!==!1,...n?{url:n}:{},...r===`stdio`?{command:i,...e.args?.length?{args:e.args}:{}}:{},...e.headers&&Object.keys(e.headers).length?{headers:e.headers}:{}})}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:i()||void 0,progressIntervalMs:Math.max(1,l())*6e4,progressMinChars:Math.max(100,d()),...p()==null?{}:{contextTokenBudget:Math.max(1,p())*1e3},...h()>0?{contextWindowTokens:h()*1e3}:{},maxSpawnDepth:Math.max(0,_()),shortContext:S(),tasks:r,mcpServers:a})}),await se(),await Promise.all(a.map((e,t)=>e.name?j(t,e.name):Promise.resolve())),setTimeout(()=>{se(),a.forEach((e,t)=>{e.name&&j(t,e.name)})},1200),e.onSaved(),T().some((e,t)=>ae()[t]?.required&&!ae()[t]?.authorized)?(de(`mcp`),Q(`a saved MCP server needs authorization — see 🔑 authorize`)):e.onClose()}catch(e){M(e.message)}},xe=(e,t,n,r)=>(()=>{var i=zp(),a=i.firstChild;return R(i,`title`,r),B(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return N(Vm,{title:`settings`,get onClose(){return e.onClose},get children(){var t=Vp(),v=t.firstChild,b=v.firstChild,A=b.nextSibling.firstChild,oe=A.firstChild.nextSibling,se=oe.nextSibling;se.firstChild;var fe=se.nextSibling.firstChild.firstChild.nextSibling;fe.firstChild;var pe=A.nextSibling,ye=pe.firstChild.nextSibling,L=ye.firstChild,Se=L.firstChild.nextSibling,Ce=ye.nextSibling.firstChild,Te=pe.nextSibling,Ee=Te.firstChild.nextSibling.nextSibling,De=Te.nextSibling,Oe=De.firstChild.nextSibling,ke=De.nextSibling;ke.firstChild;var Ae=ke.nextSibling;Ae.firstChild;var je=Ae.nextSibling,Me=je.firstChild.nextSibling.firstChild;Me.firstChild;var Ne=Me.nextSibling,Pe=v.nextSibling,Fe=Pe.firstChild;return t.addEventListener(`submit`,be),B(b,N(P,{each:ge,children:e=>(()=>{var t=Hp(),n=t.firstChild;return t.$$click=()=>de(e.key),B(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(ue()===e.key?` on`:``),i=e.hint,a=ue()===e.key?`page`:void 0;return r!==n.e&&z(t,n.e=r),i!==n.t&&R(t,`title`,n.t=i),a!==n.a&&R(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),B(A,N(ve,{get each(){return n()},children:(e,t)=>(()=>{var i=Up(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.firstChild;return a.$$input=e=>r(n().map((n,r)=>r===t?{...n,name:e.currentTarget.value}:n)),o.$$input=e=>r(n().map((n,r)=>r===t?{...n,baseUrl:e.currentTarget.value}:n)),s.$$input=e=>r(n().map((n,r)=>r===t?{...n,model:e.currentTarget.value}:n)),c.$$click=()=>r(n().filter((e,n)=>n!==t)),B(l,N(P,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=Gp(),s=o.firstChild;return s.$$input=e=>r(n().map((n,r)=>r===t?{...n,apiKeys:n.apiKeys.map((t,n)=>n===a()?e.currentTarget.value:t)}:n)),s.value=i,B(o,N(F,{get when(){return e().apiKeys.length>1},get children(){var e=Wp();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>R(s,`placeholder`,a()===0?`api key`:`api key (backup)`)),o})()}),u),u.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:[...e.apiKeys,``]}:e)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().model),i})()}),oe),oe.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),B(se,N(P,{each:$m,children:e=>(()=>{var t=Kp();return t.firstChild,t.$$click=()=>{let t=n().filter(t=>t.name!==e.key);r([...t,{name:e.key,baseUrl:e.url,apiKeys:[``],model:e.model}]),i()||a(e.key)},B(t,()=>e.label,null),y(()=>R(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),fe.addEventListener(`change`,e=>a(e.currentTarget.value)),B(fe,N(P,{get each(){return s()},children:e=>(()=>{var t=qu();return t.value=e,B(t,e),t})()}),null),B(A,N(F,{get when(){return c()},get children(){var e=Bp(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return B(t,c),B(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),B(r,c),e}}),null),B(ye,()=>xe(`progress interval (min)`,l(),e=>u(e),`how often the harness asks for a progress report`),L),B(ye,()=>xe(`progress min chars`,d(),e=>f(e),`progress prompts wait for this much real output`),L),Se.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),B(ye,()=>xe(`context window (k tok)`,h(),e=>g(e),`model's real window — 0/blank hides the % gauge`),null),B(ye,()=>xe(`max spawn depth`,_(),e=>x(e),`sub-agent nesting limit (0 = no spawning)`),null),Ce.addEventListener(`change`,e=>ee(e.currentTarget.checked)),B(Te,N(F,{get when(){return T().length>0},get fallback(){return qp()},get children(){return N(ve,{get each(){return T()},children:(e,t)=>{let n=()=>ie()[e().name],r=e=>E(T().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=tm(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.nextSibling,l=c.firstChild,u=c.nextSibling,d=a.nextSibling,f=d.firstChild,p=d.nextSibling,m=p.firstChild,h=m.nextSibling;return o.$$input=e=>r({name:e.currentTarget.value}),s.$$input=e=>r({url:e.currentTarget.value}),l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>E(T().filter((e,n)=>n!==t)),f.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),B(d,N(F,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=Jp();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=Yp();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),y(()=>t.value=(e().args??[]).join(` `)),t})()]}}),null),m.$$input=e=>{let n=e.currentTarget.value;if(D(e=>({...e,[t]:n})),!n.trim())r({headers:void 0});else try{r({headers:JSON.parse(n)}),re(e=>({...e,[t]:``}))}catch{re(e=>({...e,[t]:`not valid JSON — not applied`}))}},h.$$click=async()=>{let e=T()[t];if(!e.name){k(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}k(e=>({...e,[t]:{kind:`testing`,text:`connecting…`}}));let n=await $(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}).catch(()=>null);k(e=>({...e,[t]:n?.ok?{kind:`ok`,text:`${n.tools?.length??0} tools`}:{kind:`err`,text:n?.error??`no response`}})),n?.ok||await j(t,e.name)},B(p,N(F,{get when(){return I(()=>!!ae()[t]?.required)()&&!ae()[t]?.authorized},get children(){var n=Xp();return n.$$click=()=>void ce(t,e()),n}}),null),B(p,N(F,{get when(){return ae()[t]?.authorized},get children(){return[Zp(),(()=>{var n=Qp();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await j(t,e().name),k(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),B(p,N(F,{get when(){return n()},get children(){var e=ld();return B(e,(()=>{var e=I(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:I(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&z(e,t.e=r),i!==t.t&&R(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),B(i,N(F,{get when(){return ne()[t]},get children(){var e=$p();return B(e,()=>ne()[t]),e}}),null),B(i,N(F,{get when(){return O()[t]},get children(){var e=em();return B(e,()=>O()[t]?.text),y(n=>we(e,O()[t]?.kind===`err`?`color:var(--err)`:`color:var(--ok)`,n)),e}}),null),y(()=>o.value=e().name),y(()=>s.value=e().url??``),y(()=>l.checked=e().enabled!==!1),y(()=>f.value=e().transport??`http`),y(()=>m.value=te()[t]??``),i})()}})}}),Ee),Ee.$$click=()=>E([...T(),{name:``,url:``,transport:`http`,enabled:!0}]),B(De,N(F,{get when(){return C().length>0},get children(){return N(ve,{get each(){return C()},children:(e,t)=>(()=>{var n=nm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>w(C().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>w(C().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>w(C().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>w(C().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>w(C().filter((e,n)=>n!==t)),u.$$input=e=>w(C().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e().id),y(()=>a.value=e().agent),y(()=>o.value=e().schedule),y(()=>c.checked=!!e().forked),y(()=>u.value=e().prompt),n})()})}}),Oe),Oe.$$click=()=>w([...C(),{id:``,agent:_e()[0]??``,schedule:`every 30m`,prompt:``}]),B(ke,N(F,{get when(){return he().length>0},get fallback(){return rm()},get children(){return N(P,{get each(){return he()},children:t=>(()=>{var n=im(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return B(i,()=>t.id),B(a,()=>t.sessions,o),B(a,()=>t.sessions===1?``:`s`,null),B(a,(()=>{var e=I(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),B(a,(()=>{var e=I(()=>!!t.archivedAt);return()=>e()?` · archived ${Fm(new Date(t.archivedAt).toISOString())}`:``})(),null),B(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await me(),e.onSaved();let r=(n?.ids?.length??1)-1;Q((n?.live===!1?`restored ${t.id} — it could not be started (check its provider)`:`restored ${t.id}`)+(r>0?` + ${r} sub-agent${r===1?``:`s`}`:``))},l.$$click=async()=>{confirm(`PERMANENTLY DELETE ${t.id}?\n\n${t.sessions} session${t.sessions===1?``:`s`} of history will be erased from disk along with the config entry. This cannot be undone — archiving was the reversible option.`)&&(await $(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await me(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>R(s,`title`,t.workspace)),n})()})}}),null),B(Ae,N(P,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=om(),n=t.firstChild,r=n.nextSibling;return B(n,()=>e.id),B(r,()=>e.workspace),B(t,N(F,{get when(){return e.parent},get children(){var t=am();return t.firstChild,B(t,()=>e.parent,null),t}}),null),t})()}),null),B(Me,()=>e.cfg.version??`unknown`,null),Ne.$$click=async e=>{try{M(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await $(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=!1;for(let e=0;e<90&&!r;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await $(`/api/version`);e.version&&e.version!==`0.31.2`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){M(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},B(Pe,N(F,{get when(){return le()},get children(){var e=sp();return B(e,le),e}}),Fe),y(e=>{var t=ue()!==`providers`,n=ue()!==`runtime`,r=ue()!==`mcp`,i=ue()!==`tasks`,a=ue()!==`archive`,o=ue()!==`agents`,s=ue()!==`update`;return t!==e.e&&A.classList.toggle(`hide`,e.e=t),n!==e.t&&pe.classList.toggle(`hide`,e.t=n),r!==e.a&&Te.classList.toggle(`hide`,e.a=r),i!==e.o&&De.classList.toggle(`hide`,e.o=i),a!==e.i&&ke.classList.toggle(`hide`,e.i=a),o!==e.n&&Ae.classList.toggle(`hide`,e.n=o),s!==e.s&&je.classList.toggle(`hide`,e.s=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),y(()=>fe.value=i()),y(()=>Se.value=p()??``),y(()=>Ce.checked=S()),t}})}Se([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),xe(()=>N(Em,{}),document.getElementById(`root`));export{eu as t};
|
|
30
|
+
//# sourceMappingURL=index-B8WP_cfK.js.map
|