teapot-coding-agent 0.30.0 → 0.30.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",
@@ -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">`),_p=I(`<span class=fsize>`),vp=I(`<div><span class=ficon></span><span class=fname>`),yp=I(`<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>· `),bp=I(`<div class=filebox>`),xp=I(`<div class=muted style=padding:6px>`),Sp=I(`<img>`),Cp=I(`<div class=mediapreview><div class="meta muted"> preview`),wp=I(`<button title="rendered markdown">👁 preview`),Tp=I(`<button title="edit and save back to the workspace">✎ edit`),Ep=I(`<div class=filetoolbar><button title="syntax-highlighted source">&lt;/> code`),Dp=I(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Op=I(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),kp=I(`<div class="content mdpreview">`),Ap=I(`<video controls>`),jp=I(`<audio controls>`),Mp=I(`<div class=filepreview>`),Np=I(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),Pp=I(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),Fp=I(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),Ip=I(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),Lp=I(`<div class=wizmodels>`),Rp=I(`<span style=color:var(--fg)>`),zp=I(`<div class=muted style=font-size:11.5px;margin-top:-6px> model`),Bp=I(`<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">`),Vp=I(`<button type=button>`),Hp=I(`<div class=muted style=font-size:11.5px;margin-top:-8px>`),Up=I(`<button type=button><span class=mono>`),Wp=I(`<label><input type=number min=0>`),Gp=I(`<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.`),Kp=I(`<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`),qp=I(`<button type=button><span class=cfgmenu-label>`),Jp=I(`<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`),Yp=I(`<button type=button title="remove this key">−`),Xp=I(`<div class=cfgkeyrow><input type=password>`),Zp=I(`<button type=button>+ `),Qp=I(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),$p=I(`<input placeholder="command (e.g. npx)">`),em=I(`<input placeholder="args, space separated">`),tm=I(`<button type=button class=archrestore title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),nm=I(`<span class="mcpstate connected"title="an OAuth access token is usable">🔑 authorized`),rm=I(`<button type=button title="forget the stored grant (the refresh token is deleted)">disconnect`),im=I(`<div class=muted style=font-size:11px;color:var(--warn)>`),am=I(`<div class=mcpresult>`),om=I(`<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. {&quot;Authorization&quot;:&quot;Bearer …&quot;}"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`),sm=I(`<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">`),cm=I(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),lm=I(`<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`),um=I(`<span class=muted>🧩 sub of @`),dm=I(`<div class=cfgrow><b></b><span class=muted>`),fm=new Map;function pm(e){let t=fm.get(e);if(t!==void 0)return t;let n=Fe(e);return fm.set(e,n),fm.size>500&&fm.delete(fm.keys().next().value),n}var mm=[`minimal`,`low`,`medium`,`high`],hm=1100,gm={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`}},_m={name:`harness`,icon:`📣`,color:`#3ba55d`},[vm,ym]=v(``),bm,Q=e=>{ym(e),clearTimeout(bm),bm=setTimeout(()=>ym(``),3200)},xm=!1,Sm=[{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`]}],Cm=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`?gm.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:_m}return gm[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},wm=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),Tm=new Set([`system_note`]),Em=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`]),Dm=new Set([`runaway-detected`,`error-retry`,`background-exit`,`context-compacted`,`context-compaction-started`]),Om=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 km=location.hash.match(/[#&]token=([^&]+)/);km&&(localStorage.setItem(`teapot.token`,decodeURIComponent(km[1])),history.replaceState(null,``,location.pathname+location.search));var Am=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function jm(){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),[ee,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:{}}),[ae,oe]=v(!1),[se,ce]=v(!1),A=()=>window.innerWidth<=hm,[le,ue]=v(A());C(()=>{let e=()=>ue(A());window.addEventListener(`resize`,e),w(()=>window.removeEventListener(`resize`,e)),e()});let j,de,fe=0,pe=``,me=()=>{fe=0;let e=Ar();if(!e)return;if(lt()){G();return}let t=_e(e);if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;r&&(e.scrollTop+=r),vt(jr())},he=()=>{fe||=requestAnimationFrame(me)},ge=e=>{e&&e!==de&&(j??=new ResizeObserver(e=>{let t=e[0]?.contentRect,n=t?`${Math.round(t.width)}x${Math.round(t.height)}`:``;n!==pe&&(pe=n,he())}),de&&j.unobserve(de),de=e,pe=``,j.observe(e))};C(()=>{window.addEventListener(`resize`,he),w(()=>{window.removeEventListener(`resize`,he),j?.disconnect(),j=void 0,de=void 0,fe&&cancelAnimationFrame(fe)})});function _e(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[ve,ye]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>hm:localStorage.getItem(`teapot.panel`)===`1`),be=e=>{ye(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},xe=()=>be(!ve()),Se=()=>{ve()&&be(!1)},[I,Ce]=v(!1),[we,Oe]=v(localStorage.getItem(`teapot.theme`)??`dark`),[ke,Ae]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[je,Me]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[Ne,Pe]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),Ie=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[Le,Re]=v(Ie?.matches??!1);C(()=>{let e=e=>Re(e.matches);Ie?.addEventListener(`change`,e),w(()=>Ie?.removeEventListener(`change`,e))}),b(()=>{let e=ke()?Le()?je():Ne():we();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=Sm.find(t=>t.key===e)?.mode??`dark`}),b(()=>{localStorage.getItem(`teapot.feedCv`)===`0`?delete document.documentElement.dataset.feedcv:document.documentElement.dataset.feedcv=`on`});let[ze,Be]=v(``),[We,Ke]=v(``),[Ze,Qe]=v(``);b(()=>{let t=n();Qe(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[$e,et]=v([]),tt=()=>Object.keys(k().providers??{});async function nt(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);et(t.models??[])}catch{et([])}}let rt=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)}`:``},it=()=>{let e=We().trim()||V()?.model||``;if(!e)return``;let t=$e().find(t=>t.id===e);if(!t)return``;let n=[],r=rt(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${Vm(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(` · `)},at=null,ot=!1;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||k().defaultProvider||tt()[0]||``;if(r){if(t!==at)at=t,ot=!1,S(()=>ze())!==i&&(Be(i),nt(i)),S(()=>We())&&Ke(``);else{let e=S(()=>ze());!S(()=>We())&&e!==i&&Gt(ot)&&(Be(i),nt(i))}}});let[st,ct]=v(!1),[lt,ut]=v(!0),[dt,pt]=v(0),[ht,gt]=v(-1),vt=e=>gt(e?Jt(e):-1),[Tt,Et]=v(null),Dt=()=>Ht().startsWith(`[compact] `),Ot=()=>Dt()?Ht().slice(10):Ht();b(()=>{Tt()||Bt(e=>e?.text.startsWith(`[compact] `)?null:e)}),b(()=>{Tt(),requestAnimationFrame(()=>requestAnimationFrame(()=>{lt()&&G()}))});let[Mt,Rt]=v(new Map),zt=()=>{let e=n();return e?Mt().get(e)??null:null},Bt=e=>{let t=n();t&&Rt(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})},[Ht,Zt]=v(``),[Qt,$t]=v(0),en=()=>Qt(),[B,tn]=v(``),nn;b(()=>{zt()?nn||=setTimeout(()=>{nn=void 0,Zt(zt()?.text??``),tn(zt()?.reasoning??``)},(zt()?.text.length??0)>2e4?250:(zt()?.text.length??0)>6e3?120:60):(clearTimeout(nn),nn=void 0,Zt(``),tn(``))}),w(()=>clearTimeout(nn)),b(()=>{let t=e();Rt(e=>Je(e,e=>t.find(t=>t.id===e)?.status)),$t(e=>Xe(e,t,n(),zt()))}),b(()=>{let e=Ht(),t=zt()?.reasoning??``;(e||t)&&requestAnimationFrame(()=>{lt()&&G()})}),b(()=>{let e=V()?.pendingPrompts??0,t=V()?.pendingPromptIds,n=dn(),r=fn(n),i=At(r,e,t);i!==r&&pn(n,i)}),b(()=>{let e=V()?.pendingPromptQueue;if(!e?.length)return;let t=dn(),n=new Set(fn(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&pn(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}:{}})),...fn(t)])}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{Mr()&&(ut(!0),pt(0),Nr(!0),Sn())})};document.addEventListener(`visibilitychange`,e),w(()=>document.removeEventListener(`visibilitychange`,e))});let V=x(()=>e().find(e=>e.id===n())),rn=()=>{let e=V();return e?e.live??(e.status===`running`||e.status===`waiting`):!1},an=()=>Ft(V(),i(),rn()),[on,sn]=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 cn=new Map,[ln,un]=v([]),dn=()=>i()||n()||`?`,fn=e=>cn.get(e)??[],pn=(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?cn.delete(e):cn.set(e,r),dn()===e&&un(r)},[mn,hn]=v([]),[gn,_n]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[vn,yn]=v(!1),bn=()=>mn().filter(e=>!e.read).length,xn=e=>{hn(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},Sn=()=>{let e=n();e&&mn().some(t=>!t.read&&t.agentId===e)&&xn(e)},Cn=t=>{let n=mn().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Cn(r.id));return n},wn=0,Tn=e=>{hn(t=>[{...e,id:`n${++wn}`,at:Date.now(),read:!1},...t].slice(0,50))},En=(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?Tn({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?Tn({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?Tn({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&Tn({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})},Dn=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))},On=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of m())if(wm.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}}),[kn,An]=v(new Set),jn=e=>{e&&An(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},Mn=()=>An(new Set),Nn=x(()=>kt(m(),kn())),Pn=x(()=>ft({events:m(),consumed:On().consumed,pending:ln(),echo:Rn,feedTypes:wm,renderedTypes:Em,renderedNoteEvents:Dm})),Fn=x(()=>{let e=new WeakMap;return Pn().forEach((t,n)=>e.set(t,n)),e}),In=(e,t)=>{let n=Fn().get(e);if(n!==void 0)return Pn()[n+t]},Ln=new Map;function Rn(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=Ln.get(t);if(n)return n;Ln.size>64&&Ln.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:V()?.session??``,branch:V()?.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 Ln.set(t,r),r}let zn=()=>$(`/api/config`).then(ie).catch(()=>{}),[Bn,Vn]=v(!1);C(()=>{let e=()=>Vn(!0);window.addEventListener(`teapot:unauthorized`,e),w(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[Hn,Un]=v(``),[Wn,Gn]=v(!0),[Kn,qn]=v(!1),Jn=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==Jn?(Jn=t,qn(!1),Un(r)):t&&!Kn()&&Un(r)});let Yn=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:Hn(),notify:e})}),qn(!1),Gn(!0),Q(`tasks saved${e&&Hn().trim()?` & notification queued`:``}`),Qn()}catch(e){Q(`save failed: ${e.message}`)}},Xn=x(()=>{let e=0,t=0;for(let n of Hn().split(`
22
22
  `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}});function Zn(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 Qn=()=>$(`/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),Zn(t,e.agents??[]))),n&&p()}).catch(()=>{}),$n=()=>$(`/api/metrics`).then(te).catch(()=>{}),[er,tr]=v([]),nr=()=>$(`/api/tasks`).then(e=>tr(e.tasks)).catch(()=>{}),rr=e=>er().filter(t=>t.agent===e),[ir,ar]=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}})()),or=e=>{let t=new Set(ir());t.has(e)?t.delete(e):t.add(e),ar(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},sr=t=>St(e(),t),[cr,lr]=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}})()),ur=x(()=>{let e=new Set;for(let t of cr())t.startsWith(`chat:`)&&e.add(t);return e}),dr=x(()=>_t(e(),ir(),gn(),ur())),fr=(t,r,i,a)=>{let o=new Set(cr());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||sr(e().find(e=>e.id===i))===t)&&Q(`hid ${r} — click the header to show it`)}lr(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},H=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,pr=e=>{let t=mr().get(e)??0;return`${t} chat${t===1?``:`s`}`},mr=x(()=>Ct(e())),U=x(()=>wt(e(),dr(),cr())),hr=2e3,[gr,_r]=v(null),W=new Map;function vr(e){return`${i()||(n()??`?`)}:${e.id}`}function yr(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=vr(r),a=W.get(i);if(t[n]=a??r,!a&&(W.set(i,r),W.size>6e3)){let e=W.keys().next().value;e!==void 0&&W.delete(e)}}return t}let[br,xr]=v(!1),[Sr,Cr]=v(!1),wr=0,Tr=-1;function Er(e){let t=yr(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 Dr(){let e=n();if(!e||Sr()||br())return;if(m().length>=g()){Cr(!0);return}let t=()=>{let e=Ar();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!Sr()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(m().length>=g()){Cr(!0);return}let i=m().length;if(await Or(),m().length===i)return;Yt(jr())&&n()===e&&Nr(!0)}}async function Or(){let e=n(),t=m()[0];if(e&&t&&!br()&&!Sr()){xr(!0);try{let r=Ar(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=gr(),c=i(),l=c&&c!==e?`&session=${encodeURIComponent(c)}`:``,u=(await $(`/api/agents/${e}/events?limit=${hr}&before=${encodeURIComponent(t.id)}${l}${s?`&branch=${encodeURIComponent(s)}&lineage=true`:``}`)).events??[];if(u.length===0){Cr(!0);return}if(n()!==e||m()[0]?.id!==t.id)return;Er(u),requestAnimationFrame(()=>{if(n()===e){let e=Ar();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{xr(!1)}}}async function kr(e,t){let r=wr,a=t??i()??``;try{let t=gr(),i=r!==Tr||!ee().length,o=a&&a!==e?`&session=${encodeURIComponent(a)}`:``,[s,c,l]=await Promise.all([$(`/api/agents/${e}/events?limit=${hr}${o}${t?`&branch=${encodeURIComponent(t)}&lineage=true`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:ee()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(Tr=r),r!==wr||n()!==e)return;h(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of yr(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),Fi(l.skills??[])}catch{}}function Ar(){return document.querySelector(`.feed`)}function jr(){let e=Ar();return e?{top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight}:null}function Mr(){return Yt(jr())}function G(){let e=Ar();e&&(e.scrollTop=e.scrollHeight,pt(0))}function Nr(e=!1){(e||lt())&&G()}let Pr=new Map,Fr=(t,n)=>jt(c().get(t),e().find(e=>e.id===t)?.session,n);async function Ir(e,t=!0,o){let s=n(),l=i(),u=m(),d=g();wr++,c().size||p();let f=Fr(e,o)??e;if(s!==e||f!==l){if(l&&u.length&&(Pr.set(l,{events:u,total:d,at:Date.now()}),Pr.size>6)){let e=[...Pr.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&Pr.delete(e[0])}h([]),W.clear(),Mn(),Et(null),pt(0),ut(!0),Vi=void 0}r(e),a(f),O(D.get(e)??``),_r(null),Cr(!1),xr(!1),pn(l||s||`?`,ln()),un(fn(f||e)),localStorage.setItem(`teapot.session`,e),Jr(f,t);let v=Pr.get(f);v?.events.length&&(yr(v.events),h(yr(v.events)),_(v.total),requestAnimationFrame(()=>{n()===e&&Nr(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(Qn).catch(()=>{}),await kr(e,f),n()===e&&(Rt(t=>{let n=t.get(e)??null,r=Ye(n,m(),V()?.status);if(r===n)return t;let i=new Map(t);return r?i.set(e,r):i.delete(e),i}),Et(V()?.ctx?.compacting?{phase:String(V().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&Nr(!0)}),Dr())}let[Lr,Rr]=v(!1),zr=null,Br=null;w(()=>zr?.close());let Vr=!1,Hr=null;document.addEventListener(`visibilitychange`,()=>Hr?.()),w(()=>{Hr=null});let Ur=!0,Wr=null;async function Gr(){let e=n(),t=m().at(-1)?.id,r=i(),a=document.visibilityState===`hidden`;if(!e||!t)Vr=!0,a||Wr?.();else try{let n=r&&r!==e?`&session=${encodeURIComponent(r)}`:``,i=gr(),o=await $(`/api/agents/${e}/events?after=${encodeURIComponent(t)}${n}${i?`&branch=${encodeURIComponent(i)}&lineage=true`:``}`),s=o.events??[];o.gap?(h(yr(s)),_(s.length)):s.length&&(Er(s),_(e=>e+s.length)),await Qn(),s.length&&!a&&$n()}catch{Vr=!0}}function Kr(){Ur=!0;let r=location.protocol===`https:`?`wss://`:`ws://`,a=new WebSocket(`${r}${location.host}/api/ws${Am()}`);zr=a,a.onopen=()=>{Rr(!0),Ur?Ur=!1:Gr()},a.onclose=()=>{Rr(!1),setTimeout(Kr,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=>Zn(e,c.agents));let n=e();Rt(e=>Je(e,e=>n.find(t=>t.id===e)?.status))}else if(c.kind===`event`&&Ue(c.event))Rt(e=>He(e,c.agentId));else if(c.kind===`llm-delta`){if(!Pt(c,n(),i()))return;if(Rt(e=>Ve(e,c.agentId,c)),c.agentId===n()){let e=String(c.reasoning??``),t=String(c.text??``);e&&!t?Qt()||$t(Date.now()):t&&$t(0)}}else if(c.kind===`compaction-progress`){if(c.agentId!==n())return;c.phase===`done`?Et(null):Et({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]:Zn(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())&&pn(dn(),ln().filter(e=>e.promptId!==t.promptId)),o.has(e)&&!Tm.has(e)||(En(c.agentId,c.event),c.event?.agent!==n())||!Nt(c.event,n(),i()))return;if(Er([c.event]),c.event?.type===`message`&&c.event.data?.role===`assistant`){let e=zt();e&&Ge(e,m(),V()?.status)&&Bt(null)}if(Vr=!0,document.visibilityState!==`visible`||Br)return;Br=setTimeout(s,60)}document.visibilityState===`hidden`?Vr=!0:Br||=setTimeout(s,120)}}},Vr=!1;let s=async()=>{if(Br=null,await Qn(),await $n(),n()){let e=m().at(-1)?.id,t=m().length;await kr(n());let r=zt();r&&!Ye(r,m(),V()?.status)&&Bt(null),m().at(-1)?.id!==e&&(lt()?(G(),xn(n())):(pt(e=>e+Math.max(0,m().length-t)),vt(jr())))}};Wr=s,Hr=()=>{document.visibilityState===`visible`&&n()&&(Vr?(Vr=!1,s()):m().at(-1)?.id?Gr():(Vr=!0,s()))}}let qr=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function Jr(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=qr(),t=o().get(e);t&&(t!==n()||e!==i())&&Ir(t,!1,e||null)}),b(()=>{let e=V(),t=e?`${rn()?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=bn()>0?`(${bn()}) ${t}`:t});let Yr=()=>ae()||se()||I()||on()!==null||A()&&ve();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(ae()){oe(!1);return}if(se()){ce(!1);return}if(I()){Ce(!1);return}if(on()){sn(null);return}if(A()&&ve()){Se();return}let e=V();if(e&&rn()){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(Qn);return}}else if(!Yr()){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)xe();else if(e.key===`t`)Qr();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=dr().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&&Ir(t[i].id)}}});let[Xr,Zr]=v(localStorage.getItem(`teapot.term`)===`1`),Qr=()=>{let e=!Xr();Zr(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[K,$r]=v([]),[ei,ti]=v(0),[ni,ri]=v(-1),[ii,ai]=v(!1),[oi,si]=v(0),[ci,li]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),ui=new Map,di=0,fi=[null,null],pi=()=>K()[oi()===0?ei():ni()]??null;function mi(e){if(!K()[e])return;let t=oi(),n=t===0?ei():ni(),r=t===0?ni():ei(),i=e=>t===0?ti(e):ri(e);r===e?((e=>t===0?ri(e):ti(e))(n),i(e)):n!==e&&i(e)}let hi=()=>gi();function gi(e){let t=e??n();if(!t)return;let r=K().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}#${++di}`,agentId:t,title:r===0?t:`${t}·${r+1}`},a=Wl(K());$r(e=>[...e,i]),oi()===0?ti(a):ri(a)}function _i(e){let t=K()[e];if(!t)return;let n=ui.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),ui.delete(t.key)}let r=K().filter((t,n)=>n!==e);$r(r),ti(t=>Kl(t,e,r.length)),ri(t=>t===-1?-1:Kl(t,e,r.length))}b(()=>{ke(),we(),Le(),je(),Ne();for(let[,e]of ui)Lt(e.term)});function vi(){for(let[,e]of ui){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}ui.clear()}function yi(e,t){let n=ui.get(e.key);if(n&&Lt(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:It()}),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${Am()}`);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},ui.set(e.key,n)}return n}function bi(e){let t=fi[e];if(!t)return;let n=K()[e===0?ei():ni()];if(!n){[...ui.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=yi(n,t);for(let[e,r]of ui)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(oi()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{K(),ii(),ei(),ni(),ci(),requestAnimationFrame(()=>{bi(0),ii()&&bi(1)})});let xi=null;b(()=>{if(!Xr())return;let e=n();if(e&&e!==xi){if(xi=e,!K().some(t=>t.agentId===e))gi(e);else{let t=-1;K().forEach((n,r)=>{n.agentId===e&&(t=r)}),t>=0&&mi(t)}}});let Si=e=>{e.preventDefault();let t=e.clientY,n=ci(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));li(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(ci())),requestAnimationFrame(()=>{bi(0),ii()&&bi(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},Ci=()=>{let e=!ii();ai(e),e&&(ni()<0||ni()===ei()||ni()>=K().length)&&ri(ql(ei(),K().length)),requestAnimationFrame(()=>{bi(0),ii()&&bi(1)})};w(vi);let wi=e=>t=>{fi[e]=t,t&&requestAnimationFrame(()=>{bi(e),ii()&&bi(1),setTimeout(()=>bi(e),200)})};C(()=>{zn(),Qn().then(async()=>{await p();let t=qr(),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&&Ir(r.id,!1,t||null)}),$n(),nr(),Oi(),Kr();let t=setInterval(()=>{$n(),nr()},3e4);w(()=>clearInterval(t))});let Ti=[{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`}],[Ei,Di]=v([]),Oi=()=>$(`/api/personas`).then(e=>Di(e.personas)).catch(()=>{}),[ki,Ai]=v(!1),ji=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},Mi=()=>{let t=ji();return t===null?[]:[...Ei().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))},Ni=new Set([`start`,`stop`,`fork`,`compact`]),[Pi,Fi]=v([]),[Ii,Li]=v(-1),Ri=()=>{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=Ti.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Ni.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=Pi().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[]},zi,Bi=()=>{if(!zi)return;let e=st();zi.style.height=`auto`;let t=e?-1:Math.min(zi.scrollHeight,360);zi.style.height=t===-1?``:`${t}px`},Vi;b(()=>{let e=ne();zi&&Kt(xm)&&(qt(zi.value,e)&&(zi.value=e),Bi())});let[Hi,Ui]=v([]),Wi=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=()=>{Ui(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},Gi=async(e,t)=>{let r=t??n();if(!r)return;let i=Hi();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}:{}})});pn(dn(),[...ln(),{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)}:{}}]),Ui([]),st()&&ct(!1),requestAnimationFrame(()=>Bi())}catch(t){O(e),console.error(`send failed:`,t)}},Ki=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=Ei().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:ki()?`fork`:`none`})})).id}${ki()?` (forked context)`:``}`),Qn(),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: ${Ei().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 qi(t,n)}catch(e){throw O(ne()?`${i}\n${ne()}`:i),e}}else O(``),await Gi(i)}},qi=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(Qn);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Ir(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 Gi(`[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}`)}},Ji,Yi=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Ji)return;let e=Math.min(Yi,Ji.scrollHeight);Math.abs(Ji.scrollTop-e)>1&&(Ji.scrollTop=e)})})});let Xi=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(Qn),[Zi,Qi]=v(``),[$i,ea]=v(``),[ta,q]=v(!1),[na,ra]=v(!0),ia=``;b(()=>{let e=n();e&&(V()?.goal,e!==ia&&(ia=e,q(!1),Qi(``),ea(``)))});let aa=async e=>{if(e.preventDefault(),n()&&Zi().trim())try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:Zi(),notify:na(),...$i().trim()?{verify:$i()}:{}})}),Qi(``),ea(``),q(!1),Qn()}catch(e){Q(`goal save failed: ${e.message}`)}};return[M(P,{get when(){return k()?.needsSetup},fallback:null,get children(){return M(oh,{onDone:()=>location.reload()})}}),M(P,{get when(){return Bn()},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}}),M(P,{get when(){return!k()?.needsSetup},get children(){var i=ku(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.firstChild,l=c.firstChild;l.firstChild;var d=c.nextSibling,f=d.firstChild.firstChild.nextSibling;f.firstChild;var g=f.nextSibling,v=d.nextSibling,S=a.nextSibling,C=S.nextSibling,w=C.firstChild;w.firstChild,z(o,M(N,{get each(){return U()},children:t=>[M(P,{get when(){return F(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=Fu(),n=e.firstChild;return e.$$click=()=>fr(`ws:${t.wsHeader}`,H(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),z(n,()=>t.wsCollapsedGroup?`▸`:`▾`),z(e,()=>H(t.wsHeader),null),z(e,M(P,{get when(){return(mr().get(t.wsHeader)??0)>1||t.wsCollapsedGroup},get children(){var e=Pu();return z(e,()=>mr().get(t.wsHeader)??0),e}}),null),y(()=>L(e,`title`,t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${pr(t.wsHeader)} hidden). Click to show.`:(mr().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${pr(t.wsHeader)} in this directory`:t.wsHeader||``)),e}}),M(P,{get when(){return F(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=Bu(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>Ir(t.a.id),z(r,M(P,{get when(){return yt({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&&ur().has(`chat:${t.a.id}`)||ir().has(t.a.id);return(()=>{var r=Hu();return r.$$click=r=>{if(r.stopPropagation(),e){if(ir().has(t.a.id)){let e=new Set(ir());e.delete(t.a.id),ar(e),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...e]))}fr(`chat:${t.a.id}`,t.a.id,n)}else or(t.a.id)},z(r,n?`▸`:`▾`),y(()=>L(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),z(a,()=>t.a.sessionTitle??u().get(t.a.session??``)??t.a.id),z(r,(()=>{var e=F(()=>!!t.a.workspaceMissing);return()=>e()?Uu():null})(),null),z(r,M(P,{get when(){return Cn(t.a.id)>0},get children(){var e=Iu();return e.firstChild,z(e,()=>Cn(t.a.id),null),y(()=>L(e,`title`,`${Cn(t.a.id)} unread notification${Cn(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),z(r,M(P,{get when(){return ir().has(t.a.id)||t.chatCollapsedGroup===!0&&ur().has(`chat:${t.a.id}`)},get children(){return(()=>{let n=xt(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,R(e,`subcount`+(r>0?` live`:``)),z(e,()=>n.length,null),z(e,r>0?` · ▶${r}`:``,null),y(()=>L(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),z(r,M(P,{get when(){return t.a.parent},get children(){return Lu()}}),null),z(r,M(P,{get when(){return rr(t.a.id).length>0},get children(){var e=Ru();return y(()=>L(e,`title`,rr(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
24
- `))),e}}),null),z(r,M(P,{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=bt(t.a.id,Ei().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&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),d!==e.i&&R(a,e.i=d),f!==e.n&&L(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}})]})),z(s,M(P,{get when(){return I()},get children(){var e=ru(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;Ae(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),z(e,M(P,{get when(){return!ke()},get fallback(){return[(()=>{var e=Gu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Me(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(t,M(N,{get each(){return Sm.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=qu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=je()),e})(),(()=>{var e=Ku(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Pe(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),z(t,M(N,{get each(){return Sm.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=qu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=Ne()),e})()]},get children(){var e=nu();return z(e,M(N,{each:Sm,children:e=>(()=>{var t=Ju(),n=t.firstChild;return t.$$click=()=>{Oe(e.key),localStorage.setItem(`teapot.theme`,e.key)},z(n,()=>e.sw.map(e=>(()=>{var t=Yu();return Ee(t,`background`,e),t})())),z(t,()=>e.label,null),y(n=>{var r=`themebtn`+(we()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ke()),e}}),c),l.$$click=e=>{e.stopPropagation(),yn(!vn()),vn()||hn(e=>e.map(e=>({...e,read:!0})))},z(l,M(P,{get when(){return bn()>0},get children(){var e=iu();return z(e,bn),e}}),null),z(c,M(Wm,{icon:`👻`,get active(){return gn()},get title(){return gn()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!gn();if(_n(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&V()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Ir(t.id)}}}),null),z(c,M(Wm,{icon:`+`,title:`new agent`,onClick:()=>{zn(),oe(!0)}}),null),z(c,M(Wm,{icon:`🎨`,title:`themes`,onClick:()=>Ce(!I())}),null),z(c,M(Wm,{icon:`⚙`,title:`settings`,onClick:()=>{zn(),ce(!0)}}),null),z(f,`0.30.0`,null),z(v,M(P,{get when(){return E()},get children(){return[`master rss `,F(()=>E().rssMb),`MB · heap `,F(()=>E().heapUsedMb),`MB`,au(),`load1 `,F(()=>E().loadavg1),` · up `,F(()=>Math.floor(E().uptimeSec/60)),`m`]}})),z(S,M(P,{get when(){return V()?.id},keyed:!0,get fallback(){return Xu()},get children(){return[(()=>{var e=lu(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling,c=s.nextSibling.nextSibling;c.nextSibling;var l=r.nextSibling,u=l.firstChild;return z(t,()=>V().id),z(n,()=>V().status),z(e,M(P,{get when(){return(V().pendingPromptIds?.length??V().pendingPrompts??0)>0},get children(){var e=ou(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>V().pendingPromptIds?.length??V().pendingPrompts,t),z(e,()=>V().status===`stopped`?` (stopped)`:``,null),y(()=>L(e,`title`,V().status===`stopped`?`${V().pendingPromptIds?.length??V().pendingPrompts??0} message${(V().pendingPromptIds?.length??V().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.`:`${V().pendingPromptIds?.length??V().pendingPrompts??0} message${(V().pendingPromptIds?.length??V().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}}),r),z(e,M(P,{get when(){return rr(V().id).length>0},get children(){var e=su();return e.firstChild,z(e,()=>rr(V().id).length,null),y(()=>L(e,`title`,`scheduled tasks:\n${rr(V().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
24
+ `))),e}}),null),z(r,M(P,{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=bt(t.a.id,Ei().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&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),d!==e.i&&R(a,e.i=d),f!==e.n&&L(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}})]})),z(s,M(P,{get when(){return I()},get children(){var e=ru(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;Ae(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),z(e,M(P,{get when(){return!ke()},get fallback(){return[(()=>{var e=Gu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Me(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(t,M(N,{get each(){return Sm.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=qu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=je()),e})(),(()=>{var e=Ku(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Pe(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),z(t,M(N,{get each(){return Sm.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=qu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=Ne()),e})()]},get children(){var e=nu();return z(e,M(N,{each:Sm,children:e=>(()=>{var t=Ju(),n=t.firstChild;return t.$$click=()=>{Oe(e.key),localStorage.setItem(`teapot.theme`,e.key)},z(n,()=>e.sw.map(e=>(()=>{var t=Yu();return Ee(t,`background`,e),t})())),z(t,()=>e.label,null),y(n=>{var r=`themebtn`+(we()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ke()),e}}),c),l.$$click=e=>{e.stopPropagation(),yn(!vn()),vn()||hn(e=>e.map(e=>({...e,read:!0})))},z(l,M(P,{get when(){return bn()>0},get children(){var e=iu();return z(e,bn),e}}),null),z(c,M(Wm,{icon:`👻`,get active(){return gn()},get title(){return gn()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!gn();if(_n(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&V()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Ir(t.id)}}}),null),z(c,M(Wm,{icon:`+`,title:`new agent`,onClick:()=>{zn(),oe(!0)}}),null),z(c,M(Wm,{icon:`🎨`,title:`themes`,onClick:()=>Ce(!I())}),null),z(c,M(Wm,{icon:`⚙`,title:`settings`,onClick:()=>{zn(),ce(!0)}}),null),z(f,`0.30.1`,null),z(v,M(P,{get when(){return E()},get children(){return[`master rss `,F(()=>E().rssMb),`MB · heap `,F(()=>E().heapUsedMb),`MB`,au(),`load1 `,F(()=>E().loadavg1),` · up `,F(()=>Math.floor(E().uptimeSec/60)),`m`]}})),z(S,M(P,{get when(){return V()?.id},keyed:!0,get fallback(){return Xu()},get children(){return[(()=>{var e=lu(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling,c=s.nextSibling.nextSibling;c.nextSibling;var l=r.nextSibling,u=l.firstChild;return z(t,()=>V().id),z(n,()=>V().status),z(e,M(P,{get when(){return(V().pendingPromptIds?.length??V().pendingPrompts??0)>0},get children(){var e=ou(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>V().pendingPromptIds?.length??V().pendingPrompts,t),z(e,()=>V().status===`stopped`?` (stopped)`:``,null),y(()=>L(e,`title`,V().status===`stopped`?`${V().pendingPromptIds?.length??V().pendingPrompts??0} message${(V().pendingPromptIds?.length??V().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.`:`${V().pendingPromptIds?.length??V().pendingPrompts??0} message${(V().pendingPromptIds?.length??V().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}}),r),z(e,M(P,{get when(){return rr(V().id).length>0},get children(){var e=su();return e.firstChild,z(e,()=>rr(V().id).length,null),y(()=>L(e,`title`,`scheduled tasks:\n${rr(V().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
25
25
  `)}`)),e}}),r),z(r,()=>V().model,i),z(r,()=>V().session,a),z(r,()=>V().branch,o),z(r,()=>V().stats.turns,s),z(r,()=>V().stats.toolCalls,c),z(l,M(P,{get when(){return V().statusReason},get children(){var e=cu();return y(()=>L(e,`title`,V().statusReason)),e}}),u),u.$$click=()=>(rn()?Xi(`/stop`):Xi(`/start`))(),z(u,()=>rn()?`■`:`▶`),z(l,M(Wm,{icon:`⌨`,title:`terminal (t)`,onClick:Qr}),null),z(l,M(Wm,{icon:`▤`,title:`toggle details panel (d)`,onClick:xe}),null),y(e=>{var t=`badge ${V().status}`,i=`${V().model} · ${V().session}/${V().branch} · turns ${V().stats.turns} · tools ${V().stats.toolCalls}`,a=`runbtn`+(rn()?` danger`:``),o=rn()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&R(n,e.e=t),i!==e.t&&L(r,`title`,e.t=i),a!==e.a&&R(u,e.a=a),o!==e.o&&L(u,`title`,e.o=o),e},{e:void 0,t:void 0,a:void 0,o:void 0}),e})(),(()=>{var e=gu();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r={top:t.scrollTop,height:t.scrollHeight,viewport:t.clientHeight},i=Xt(r,Vi),a=Vi===void 0;Vi=r,vt(r),Yt(r)?(ut(!0),dt()&&pt(0),Sn()):(i||a)&&ut(!1),r.top<=4&&n()&&!br()&&!Sr()&&m().length>0&&Or()}),De(e=>ge(e),e),z(e,M(P,{get when(){return Tt()},children:e=>(()=>{var t=Zu();return t.firstChild,z(t,(()=>{var t=F(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Vm(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),z(e,M(P,{get when(){return F(()=>!!Sr())()&&Pn().length>0},get children(){return uu()}}),null),z(e,M(P,{get when(){return br()},get children(){return du()}}),null),z(e,M(P,{get when(){return Pn().length>0},get fallback(){return Qu()},get children(){return[M(N,{get each(){return Pn()},children:e=>M(Im,{e,prev:()=>In(e,-1),next:()=>In(e,1),get showBranch(){return ee().length>1},get res(){return On().resFor.get(e.id)},get orphan(){return On().orphanCalls.has(e.id)},onOption:e=>void Gi(e),answeredIds:Nn,onAnswered:jn,get agentActive(){return F(()=>!!an())()&&qe(e)},onResize:()=>{lt()&&G()},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),pn(dn(),ln().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&&!rn()?()=>sn({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),M(P,{get when(){return F(()=>!!an())()&&zt()},get children(){var e=hu(),t=e.firstChild.nextSibling;return t.firstChild,z(t,M(P,{get when(){return B().trim()!==``},get children(){var e=fu(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return z(t,M(Nm,{get startedAt(){return en()}}),null),De(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{B(),t&&(e.scrollTop=e.scrollHeight)})},n),z(n,B),e}}),null),z(t,M(P,{get when(){return Ht()},get fallback(){return $u()},get children(){return M(P,{get when(){return Dt()},get fallback(){return(()=>{var e=mu();return y(()=>e.innerHTML=Fe(Ht()+`▍`)),e})()},get children(){return[pu(),(()=>{var e=mu();return y(()=>e.innerHTML=Fe(Ot()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),M(P,{get when(){return Xr()},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=()=>{li(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(ci()))},n.$$pointerdown=Si,z(i,M(N,{get each(){return K()},children:(e,t)=>(()=>{var n=ed(),r=n.firstChild.nextSibling;return n.$$click=()=>mi(t()),z(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),_i(t())},y(r=>{var i=`termtab`+(oi()===0&&ei()===t()?` active`:``)+(ii()&&oi()===1&&ni()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),z(i,M(Wm,{icon:`+`,title:`new shell in this workspace`,onClick:hi}),null),z(o,(()=>{var t=F(()=>!!pi());return()=>t()?e().find(e=>e.id===pi().agentId)?.workspace.split(`/`).filter(Boolean).pop():V()?.workspace})()),z(a,M(Wm,{icon:`◫`,get title(){return ii()?`single pane`:`split panes (50/50)`},onClick:Ci}),null),z(a,M(Wm,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:Qr}),null);var l=wi(0);return typeof l==`function`&&De(l,c),c.$$pointerdown=()=>si(0),z(c,M(P,{get when(){return ei()<0||ei()>=K().length},get children(){return _u()}})),z(s,M(P,{get when(){return ii()},get children(){return[vu(),(()=>{var e=bu(),t=wi(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>si(1),z(e,M(P,{get when(){return ni()<0||ni()>=K().length},get children(){return yu()}})),y(()=>e.classList.toggle(`focused`,oi()===1)),e})()]}}),null),y(e=>{var n={height:`${ci()}px`},r=!!ii(),i=oi()===0;return e.e=Te(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 z(e,M(P,{get when(){return F(()=>ht()>32)()&&!lt()},get children(){var e=Su();return e.firstChild,e.$$click=()=>{Nr(!0),Sn()},z(e,(()=>{var e=F(()=>dt()>0);return()=>e()?`${dt()} new message${dt()>1?`s`:``}`:`jump to present`})(),null),e}}),t),z(e,M(P,{get when(){return Ri().length>0},get children(){var e=Cu();return z(e,M(N,{get each(){return Ri()},children:(e,t)=>(()=>{var n=td(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{O(e.insert),Li(-1)},z(r,()=>e.insert.trim()),z(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===Ii()?` active`:``),a=e.title;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),z(e,M(P,{get when(){return Mi().length>0},get children(){var e=Cu();return z(e,M(N,{get each(){return Mi()},children:e=>(()=>{var t=nd(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{O(`@${e.key} `),Li(-1)},z(n,()=>e.key,null),z(r,()=>e.label),y(()=>L(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Ki),z(t,M(P,{get when(){return Hi().length>0},get children(){var e=wu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,z(e,M(N,{get each(){return Hi()},children:(e,t)=>(()=>{var n=rd(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>Ui(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&L(n,`title`,t.e=i),a!==t.t&&L(r,`src`,t.t=a),o!==t.a&&L(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),z(t,()=>Hi().length,n),z(t,()=>Hi().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=Ri();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),Li(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),Li(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&Ii()>=0&&!xm?(e.preventDefault(),O(t[Ii()].insert),Li(-1)):e.key===`Escape`&&t.length>0?Li(-1):e.key===`Enter`&&!e.shiftKey&&!xm&&!st()&&(e.preventDefault(),Ki(e))},n.$$input=e=>{O(e.currentTarget.value),Li(0),Bi()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),Wi(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{xm=!1}),O(zi?.value??``)}),n.addEventListener(`compositionstart`,()=>{xm=!0}),De(e=>{zi=e,e.value=ne()},n),z(t,M(P,{get when(){return F(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=Tu(),t=e.firstChild;return t.addEventListener(`change`,e=>Ai(e.currentTarget.checked)),y(()=>t.checked=ki()),e}}),r),r.$$click=()=>{let e=!st();ct(e),requestAnimationFrame(()=>Bi())},z(r,()=>st()?`⤡`:`⤢`),z(t,M(Wm,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),z(t,M(P,{get when(){return Hi().length},get children(){var e=Eu();return e.firstChild,z(e,()=>Hi().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&Wi(e.currentTarget.files),e.currentTarget.value=``}),z(o,()=>vm()||`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`+(st()?` maximized`:``),a=`message #${V().id} — / for commands · paste or 📎 to attach images`,o=st()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&R(e,t.e=i),a!==t.t&&L(n,`placeholder`,t.t=a),o!==t.a&&L(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()]}})),z(i,M(P,{get when(){return F(()=>!!le())()&&ve()},get children(){var e=Ou();return e.$$click=()=>be(!1),e}}),C),C.addEventListener(`scroll`,e=>{Yi=e.currentTarget.scrollTop});var T=Ji;return typeof T==`function`?De(T,C):Ji=C,z(w,M(Wm,{icon:`✕`,title:`close details panel (esc)`,onClick:Se}),null),z(C,M(P,{get when(){return V()?.id},keyed:!0,fallback:null,children:i=>[id(),(()=>{var e=ad(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return z(n,()=>V().id),z(r,()=>V().status),z(a,()=>V().workspace),z(o,()=>V().session,s),z(o,()=>V().branch,null),y(e=>{var t=`badge ${V().status}`,n=V().workspace;return t!==e.e&&R(r,e.e=t),n!==e.t&&L(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),M(P,{get when(){return V().id},keyed:!0,fallback:null,children:e=>M(nh,{agentId:e,get workspace(){return V().workspace}})}),od(),(()=>{var t=ld(),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;ot=!0,Be(r),Ke(Ut(k().providers,r,e().find(e=>e.id===n()))),nt(r)}),z(r,M(N,{get each(){return tt()},children:e=>(()=>{var t=qu();return t.value=e,z(t,e,null),z(t,()=>e===k().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>Ke(e.currentTarget.value),z(o,M(N,{get each(){return $e()},children:e=>(()=>{var t=qu();return y(()=>t.value=e.id),t})()})),z(t,M(P,{get when(){return V().effortSupported},get children(){var e=sd(),t=e.firstChild.nextSibling;return t.firstChild,t.addEventListener(`change`,e=>Qe(e.currentTarget.value)),z(t,M(N,{get each(){return F(()=>!!V().effortOptions?.length)()?V().effortOptions:mm},children:e=>(()=>{var t=qu();return t.value=e,z(t,e),t})()}),null),y(()=>t.value=Ze()),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:ze(),model:We().trim()||void 0,contextWindowTokens:$e().find(e=>e.id===(We().trim()||void 0))?.contextLength,...V().effortSupported?{reasoningEffort:Ze()}:{}})}),t.textContent=`✓ applied`,Qn()}catch(e){alert(`apply failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},z(l,()=>V().model,null),z(l,M(P,{get when(){return $e().length},get children(){return[` · `,F(()=>$e().length),` models loaded`]}}),null),z(t,M(P,{get when(){return it()},get children(){var e=cd();return z(e,it),e}}),null),y(()=>L(a,`placeholder`,Wt(k().providers,ze(),V(),Vt(V(),k().providers,k().defaultProvider)))),y(()=>r.value=ze()),y(()=>a.value=We()),t})(),ud(),(()=>{var i=fd(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling;return a.$$click=()=>(rn()?Xi(`/stop`):Xi(`/start`))(),z(a,()=>rn()?`■ stop`:`▶ start`),o.$$click=()=>$(`/api/agents/${V().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await p(!0),await Ir(V().id)}),s.$$click=async()=>{let i=n();if(!i)return;let a=new Set([i,...xt(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(()=>{});let s=e().filter(e=>!a.has(e.id));t(s),p(!0);let c=Jl(e(),a);c?Ir(c.id):(r(null),h([]))},z(i,M(P,{get when(){return e().some(e=>e.parent===n())},get children(){var e=dd();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),Qn())},e}}),null),y(e=>{var t=rn()?`danger`:`runbtn`,n=rn()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&R(a,e.e=t),n!==e.t&&L(a,`title`,e.t=n),e},{e:void 0,t:void 0}),i})(),(()=>{var e=pd(),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(Qn)}),y(()=>t.checked=V().autoContinue??!0),e})(),(()=>{var e=hd();return e.firstChild,z(e,M(P,{get when(){return!!V().goal.text.trim()},get fallback(){return Nd()},get children(){var e=md();return z(e,()=>V().goal.status),y(()=>R(e,`badge ${V().goal.status===`active`?`running`:V().goal.status}`)),e}}),null),e})(),(()=>{var e=gd();return e.firstChild,z(e,M(N,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Pd();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(Qn)},L(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`),z(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(V().goal.text.trim()&&V().goal.status===e?` on ${e}`:``),i=!!V().goal.text.trim()&&V().goal.status===e;return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),M(P,{get when(){return V().goal.text},get fallback(){return Fd()},get children(){return[(()=>{var e=_d(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(V().goal.text))),e})(),M(P,{get when(){return V().goal.verify},get children(){var e=vd(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(V().goal.verify))),e}}),M(P,{get when(){return V().goal.audit},children:e=>(()=>{var t=Id(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return z(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),z(r,()=>Bm(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=mt(e().feedback)?Fe(`_the auditor returned a verdict with no detail_`):Fe(e().feedback);return r!==n.e&&R(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),yd(),(()=>{var e=bd(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,aa),t.$$input=e=>{Qi(e.currentTarget.value),q(!0)},n.$$input=e=>{ea(e.currentTarget.value),q(!0)},r.addEventListener(`change`,e=>ra(e.currentTarget.checked)),y(()=>t.value=Zi()),y(()=>n.value=$i()),y(()=>r.checked=na()),e})(),(()=>{var e=Sd(),t=e.firstChild.nextSibling;return z(e,M(P,{get when(){return Xn().total>0},get children(){var e=xd(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,z(e,()=>Xn().done,t),z(e,()=>Xn().total,n),y(t=>Te(e,Xn().done===Xn().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),M(P,{get when(){return Xn().total>0},get children(){var e=Cd(),t=e.firstChild;return y(e=>{var n=`barfill `+(Xn().done===Xn().total?``:`warn`),r=`${Math.round(Xn().done/Xn().total*100)}%`;return n!==e.e&&R(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),M(th,{get draft(){return Hn()},get preview(){return Wn()},onDraft:e=>{Un(e),qn(!0)}}),(()=>{var e=wd(),t=e.firstChild,n=t.nextSibling;return z(e,M(Wm,{get icon(){return Wn()?`✎`:`👁`},get title(){return Wn()?`edit markdown`:`rendered checklist`},onClick:()=>Gn(!Wn())}),t),n.$$click=Yn,e})(),Td(),M(P,{get when(){return V().latestProgress},get fallback(){return Ld()},children:e=>(()=>{var t=Hd(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return z(t,M(P,{get when(){return e().recent},get children(){var t=Rd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=pm(e().recent)),t}}),i),z(t,M(P,{get when(){return e().problems},get children(){var t=zd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=pm(e().problems)),t}}),i),z(t,M(P,{get when(){return e().next},get children(){var t=Bd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=pm(e().next)),t}}),i),z(t,M(P,{get when(){return e().goalStatus},get children(){var t=Vd(),n=t.firstChild.nextSibling;return z(n,()=>e().goalStatus),t}}),i),z(i,()=>Bm(e().ts)),y(()=>r.innerHTML=pm(e().doing)),t})()}),Ed(),(()=>{var e=kd(),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 z(i,()=>Vm(V().stats.inputTokens),a),z(i,()=>Vm(V().stats.outputTokens),o),z(r,M(P,{get when(){return(V().stats.cachedInputTokens??0)>0},get children(){var e=Dd(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>Math.round(V().stats.cachedInputTokens/Math.max(1,V().stats.inputTokens)*1e3)/10,t),y(()=>L(e,`title`,`${Vm(V().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),z(s,()=>V().stats.turns),z(c,()=>V().stats.toolCalls),z(l,()=>V().stats.compactions??0),z(t,M(P,{get when(){return(V().stats.costUsd??0)>0},get children(){var e=Od(),t=e.firstChild.nextSibling;return t.firstChild,z(t,()=>Hm(V().stats.costUsd??0),null),y(()=>L(e,`title`,`≈ ${(V().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),z(e,M(P,{get when(){return V().ctx},keyed:!0,get fallback(){return Ud()},children:e=>{let t=x(()=>{let t=e,n=$e().find(e=>e.id===V().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=qd(),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 z(a,()=>Vm(r().usedTokens),o),z(t,M(P,{get when(){return r().effectiveWindow},get children(){var e=Wd(),t=e.firstChild;return z(e,()=>i(r().pct),t),z(e,()=>Vm(r().effectiveWindow),null),y(()=>R(e,`pill ${r().cls}`)),e}}),null),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=Gd(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),z(c,()=>Vm(r().usingDerived?r().derivedBudget:r().compactAt),l),z(u,()=>r().usingDerived?`75% of window`:`manual`),z(e,M(P,{get when(){return Tt()||r().compacting},get children(){var e=Kd(),t=e.firstChild.nextSibling.nextSibling;return z(t,()=>Tt()?.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(Qn)}),y(()=>f.checked=V().autoCompact!==!1),e})()}}),null),e})(),(()=>{var e=jd();return e.firstChild.nextSibling,z(e,M(P,{get when(){return gr()},get children(){var e=Ad(),t=e.firstChild.nextSibling;return z(t,gr),e}}),null),e})(),M(N,{get each(){return ee()},children:e=>(()=>{var t=Jd(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=gr()===e.branch?null:e.branch,r=t!==gr();_r(t),n()&&(r&&(wr++,h([]),_(0),Cr(!1)),kr(n()))},z(r,()=>e.branch,null),z(r,()=>e.branch===V().branch?` (current)`:``,null),z(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===V().branch||e.branch===gr()?` cur`:``),i=e.branch===gr()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Md(),M(P,{get when(){return er().length>0},get fallback(){return Yd()},get children(){return M(N,{get each(){return er()},children:e=>(()=>{var t=Zd(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Ir(e.agent),z(i,()=>e.id),z(a,()=>e.agent,null),z(r,M(P,{get when(){return e.forked},get children(){return Xd()}}),null),z(o,()=>e.schedule,s),z(o,(()=>{var t=F(()=>!!e.next);return()=>t()?Bm(e.next):`—`})(),null),z(o,(()=>{var t=F(()=>!!e.last);return()=>t()?` · last ${Bm(e.last)}`:` · never ran`})(),null),z(c,()=>Um(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Um(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&R(t,r.e=i),a!==r.t&&L(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var t=`layout`+(ve()?``:` right-hidden`),n=`iconbtn notifbtn`+(bn()>0?` has-unread`:``),r=bn()>0?`${bn()} unread notifications`:`notifications`,a=`conn`+(Lr()?` ok`:``),o=Lr()?`live (websocket)`:`reconnecting…`,s={"--termh":`${ci()}px`},c=`rightbar`+(ve()?` open`:``);return t!==e.e&&R(i,e.e=t),n!==e.t&&R(l,e.t=n),r!==e.a&&L(l,`title`,e.a=r),a!==e.o&&R(g,e.o=a),o!==e.i&&L(g,`title`,e.i=o),e.n=Te(S,s,e.n),c!==e.s&&R(C,e.s=c),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),i}}),M(P,{get when(){return vn()},get children(){return[(()=>{var e=Au();return e.$$click=()=>yn(!1),e})(),(()=>{var t=Nu(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return z(r,M(P,{get when(){return mn().length>0},get children(){var e=ju();return e.$$click=()=>hn([]),e}}),i),i.$$click=()=>yn(!1),z(t,M(P,{get when(){return mn().length>0},get fallback(){return Qd()},get children(){var t=Mu();return z(t,M(N,{get each(){return mn()},children:t=>(()=>{var r=ef(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{hn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&Ir(t.agentId),yn(!1),t.eventId&&setTimeout(()=>Dn(t.eventId),n()===t.agentId?60:350)},z(i,(()=>{var e=F(()=>t.kind===`finish`);return()=>e()?`✅`:F(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),z(a,()=>t.title),z(o,()=>Bm(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),hn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},z(s,()=>t.read?`✓`:`○`),z(r,M(P,{get when(){return t.body},get children(){var e=$d();return z(e,()=>zm(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&&R(r,e.e=n),i!==e.t&&L(r,`title`,e.t=i),a!==e.a&&L(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),M(P,{get when(){return ae()},get children(){return M(qm,{get providers(){return Object.keys(k().providers??{})},onClose:()=>oe(!1),onCreated:e=>{oe(!1),Qn(),Ir(e)}})}}),M(P,{get when(){return se()},get children(){return M(sh,{get cfg(){return k()},onClose:()=>ce(!1),onSaved:()=>{zn(),nr()}})}}),M(P,{get when(){return on()},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 M(Km,{title:`edit prompt — forks the conversation`,onClose:()=>sn(null),get children(){var t=nf(),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()})}),sn(null),Qn();let t=n();t&&await Ir(t)}catch(e){alert(`edit failed: ${e.message}`)}}),z(t,M(P,{get when(){return r()>0},get children(){var e=tf(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return z(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=()=>sn(null),y(()=>o.value=e().text),t}})}})]}function Mm(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());C(()=>{let e=setInterval(()=>r(Date.now()),500);w(()=>clearInterval(e))});let i=()=>Be(Math.max(0,n()-t));return e.inline?(()=>{var t=rf();return t.firstChild,z(t,i,null),z(t,(()=>{var t=F(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=af(),t=e.firstChild;return z(e,i,t),e})()}function Nm(e){let[t,n]=v(Date.now());return C(()=>{let e=setInterval(()=>n(Date.now()),500);w(()=>clearInterval(e))}),e.startedAt?(()=>{var n=of();return z(n,()=>Be(Math.max(0,t()-e.startedAt))),n})():null}function Pm(e){let t=e.e,n=Ot(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=sf();return z(n,()=>zm(e,t)),n})(),f=(e=4e3)=>(()=>{let t=r();return t?[F(()=>d(s(),e)),(()=>{var e=cf();return z(e,()=>Be(t.data?.durationMs),null),z(e,()=>o===`bash`?zt(Rt(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),z(e,M(Gm,{get text(){return s()}}),null),e})()]:lf()})(),p=x(()=>{let e=o,t=``,n=(()=>{var e=uf();return z(e,()=>zm(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?`⏳ `:`$ `)+Um(i,96);let u=c(`timeout_ms`)?Number(c(`timeout_ms`)):void 0,p=r(),m=Rt(p?.data?.ok,p?String(p.data?.result??``):``);t=p?o?`background job${l?` ${l}`:``}${u?` · timeout ${Math.round(u/1e3)}s`:``}`:Bt({outcome:m,durationMs:p.data?.durationMs,timeoutMs:u,fmtDur:Be}):null,n=[o?(()=>{var e=df(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,z(t,l||`?`,n),z(e,l?[` · kill with `,ff()]:null,null),e})():null,F(()=>F(()=>i!==e.slice(2))()?d(i,800):null),F(()=>f(6e3))];break}case`read_file`:{e=c(`path`)||`(no path)`;let r=[];c(`pattern`)&&r.push(`grep /${Um(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=`${Vm(i.length)} bytes`,n=[F(()=>d(i,1500)),F(()=>F(()=>i.length>1500)()?(()=>{var e=pf(),t=e.firstChild;return z(e,()=>Vm(i.length),t),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=cf();return z(e,()=>Um(s(),160)),e})():mf())];break}case`edit_file`:e=c(`path`)||`(no path)`,t=a.args?.replace_all===!0?`replace all`:`unique spot`,n=[(()=>{var e=hf();return z(e,()=>zm(`- `+c(`old_text`),900)),e})(),(()=>{var e=gf();return z(e,()=>`+ `+zm(c(`new_text`),900)),e})(),F(()=>F(()=>!!r())()?(()=>{var e=_f(),t=e.firstChild;return z(e,()=>Um(s(),120),t),z(e,()=>Be(r().data?.durationMs),null),e})():vf())];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`:``}: ${Um(i.join(`, `),80)}`:`patch`;let a=t.slice(0,60);n=[(()=>{var e=yf();return z(e,()=>a.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=bf();return R(n,`pline`+t),z(n,(()=>{var t=F(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),z(e,(()=>{var e=F(()=>t.length>60);return()=>e()?(()=>{var e=xf(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>t.length-60,n),e})():null})(),null),e})(),F(()=>F(()=>!!r())()?(()=>{var e=cf();return z(e,()=>Um(s().split(`
27
- `)[0]??``,140),null),z(e,()=>r().data?.ok===!1?` · FAILED`:``,null),e})():Sf())];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=Um(r,70),t=`web`,n=[(()=>{var e=cf();return z(e,M(P,{get when(){return/^https?:/i.test(c(`url`))},get fallback(){return(()=>{var e=wf();return z(e,()=>Um(c(`url`),80)),e})()},get children(){var e=Cf();return y(()=>L(e,`href`,c(`url`))),e}})),e})(),F(()=>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=Fe(t)),e})(),(()=>{var e=cf();return z(e,()=>Be(r().data?.durationMs)),e})()]:Tf();break}case`save_skill`:{e=`skill: ${c(`name`)}`,t=Um(c(`description`),60);let i=Array.isArray(a.args?.files)?a.args.files.map(e=>e?.name).filter(Boolean):[];n=[F(()=>F(()=>!!i.length)()?(()=>{var e=Ef();return e.firstChild,z(e,()=>i.join(`, `),null),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=_f(),t=e.firstChild;return z(e,()=>Um(s(),160),t),z(e,()=>Be(r().data?.durationMs),null),e})():Df())];break}}}catch{}return{label:e,hint:t,body:n}});return(()=>{var a=kf(),c=a.firstChild,d=c.firstChild,f=d.nextSibling,m=f.nextSibling;return a.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),z(d,()=>p().label),z(c,M(P,{get when(){return t.data?.actor},get children(){var e=Of();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),f),z(f,(()=>{var e=F(()=>!!r());return()=>e()?p().hint||``:F(()=>!!i())()?`(result missed)`:F(()=>!!(o===`bash`||u()))()?M(Mm,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return u()}}):`running…`})()),z(m,M(Gm,{get text(){return l()},label:`⧉ cmd`,title:`copy the ${o} arguments`}),null),z(m,M(P,{get when(){return r()},get children(){return M(Gm,{get text(){return s()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(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&&R(a,e.e=t),s!==e.t&&L(a,`title`,e.t=s),e},{e:void 0,t:void 0}),a})()}function Fm(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 Im(e){let t=e.e,n=Cm(t),r=()=>Ot(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Ot(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Af(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=gt(t.data??{});return(()=>{var t=jf(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=bf();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Mf(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Nf(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(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=Pf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Ff(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(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=bf();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=If(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Lf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=Hf(),o=a.firstChild,s=o.nextSibling;return z(o,(()=>{var e=F(()=>!!r());return()=>e()?``:n.icon})()),z(s,(()=>{var e=F(()=>!!r());return()=>e()&&(()=>{var e=Uf();return y(()=>L(e,`title`,`${Om(t.ts)} · ${t.branch}`)),e})()})(),null),z(s,M(P,{get when(){return!r()},get children(){var r=Vf(),i=r.firstChild,a=i.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=Of();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:Om(t.ts)})()),z(r,M(P,{get when(){return e.showBranch},get children(){var e=Rf();return z(e,()=>t.branch),e}}),null),z(r,M(P,{get when(){return e.onCancel},get children(){var t=zf();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(Gm,{get text(){return Fm(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=Bf();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(s,M(Rm,{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()?`${Om(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&R(a,e.e=s),c!==e.t&&L(a,`data-eid`,e.t=c),l!==e.a&&R(o,e.a=l),u!==e.o&&Ee(o,`background`,e.o=u),d!==e.i&&Ee(o,`border`,e.i=d),f!==e.n&&L(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 Lm(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=Wf(),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&&L(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 Rm(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=mu();return y(()=>e.innerHTML=pm(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=Gf();return z(t,M(N,{each:e,children:e=>(()=>{var t=Kf();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=qf(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Vm(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>zm(String(t.data.reasoning),8e3)),e}}),(()=>{var e=mu();return y(()=>e.innerHTML=pm(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return Jf()}}),M(P,{get when(){return t.data.final},get children(){var e=Yf(),n=e.firstChild;return z(e,M(Gm,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(Pm,{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=Zf(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(Gm,{text:n}),null),z(c,()=>zm(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?zt(Rt(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return Xf()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=$f(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=Qf();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=pm(String(t.data?.decision??``)),r=pm(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=np(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return ep()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=tp();return z(a,M(N,{each:n,children:n=>(()=>{var a=rp();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)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M(Lm,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=pm(String(t.data?.question??``));return n!==e.e&&R(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=ip(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=Vd(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=Rd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=pm(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=zd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=pm(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=Bd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=pm(String(t.data.next))),e}}),null),y(()=>n.innerHTML=pm(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=ap(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=sp(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>Vm(Number(t.data.tokensBefore??0)),i),z(n,()=>Vm(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[op(),(()=>{var e=mu();return y(()=>e.innerHTML=pm(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=cp();return z(e,()=>zm(JSON.stringify(t.data),200)),e})()}}function zm(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Bm(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 Vm(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 Hm(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 Um(e,t){return zm(e.replace(/\s+/g,` `).trim(),t)}function Wm(e){return(()=>{var t=lp(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(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&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Gm(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),Tt(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=up();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function Km(e){return(()=>{var t=dp(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function qm(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??[])}C(()=>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 M(Km,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=pp(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,C=S.firstChild.nextSibling,w=S.nextSibling,ee=w.firstChild.nextSibling,T=w.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(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=mp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),C.$$input=e=>o(e.currentTarget.value),ee.addEventListener(`change`,e=>c(e.currentTarget.value)),z(ee,M(N,{get each(){return e.providers},children:e=>(()=>{var t=qu();return z(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=fp();return z(e,d),e}}),E),y(()=>h.value=t()),y(()=>C.value=a()),y(()=>ee.value=s()),y(()=>T.value=l()),i}})}var Jm=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Ym=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Xm=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Zm(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 Jm.has(t)?`image`:Ym.has(t)?`video`:Xm.has(t)?`audio`:null}var $m=new Map,eh=e=>{let t=$m.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},$m.set(e,t)),t};function th(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),w(()=>t.disconnect())};return M(P,{get when(){return e.preview},get fallback(){return(()=>{var t=gp();return t.$$input=t=>e.onDraft(t.currentTarget.value),De(a,t),y(e=>Te(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=hp();return De(a,t),y(n=>{var r=i(),a=pm(e.draft);return n.e=Te(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function nh(e){let t=eh(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`),C=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},ee=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)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[ue,j]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await eu(async()=>{let{highlightChunks:e}=await import(`./shiki-DwJMDO32.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};w(()=>{fe++});let me=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}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(t&&!ue()){j(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),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),z(e,()=>r().data?.ok===!1?` · FAILED`:``,null),e})():Sf())];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=Um(r,70),t=`web`,n=[(()=>{var e=cf();return z(e,M(P,{get when(){return/^https?:/i.test(c(`url`))},get fallback(){return(()=>{var e=wf();return z(e,()=>Um(c(`url`),80)),e})()},get children(){var e=Cf();return y(()=>L(e,`href`,c(`url`))),e}})),e})(),F(()=>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=Fe(t)),e})(),(()=>{var e=cf();return z(e,()=>Be(r().data?.durationMs)),e})()]:Tf();break}case`save_skill`:{e=`skill: ${c(`name`)}`,t=Um(c(`description`),60);let i=Array.isArray(a.args?.files)?a.args.files.map(e=>e?.name).filter(Boolean):[];n=[F(()=>F(()=>!!i.length)()?(()=>{var e=Ef();return e.firstChild,z(e,()=>i.join(`, `),null),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=_f(),t=e.firstChild;return z(e,()=>Um(s(),160),t),z(e,()=>Be(r().data?.durationMs),null),e})():Df())];break}}}catch{}return{label:e,hint:t,body:n}});return(()=>{var a=kf(),c=a.firstChild,d=c.firstChild,f=d.nextSibling,m=f.nextSibling;return a.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),z(d,()=>p().label),z(c,M(P,{get when(){return t.data?.actor},get children(){var e=Of();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),f),z(f,(()=>{var e=F(()=>!!r());return()=>e()?p().hint||``:F(()=>!!i())()?`(result missed)`:F(()=>!!(o===`bash`||u()))()?M(Mm,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return u()}}):`running…`})()),z(m,M(Gm,{get text(){return l()},label:`⧉ cmd`,title:`copy the ${o} arguments`}),null),z(m,M(P,{get when(){return r()},get children(){return M(Gm,{get text(){return s()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(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&&R(a,e.e=t),s!==e.t&&L(a,`title`,e.t=s),e},{e:void 0,t:void 0}),a})()}function Fm(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 Im(e){let t=e.e,n=Cm(t),r=()=>Ot(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Ot(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Af(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=gt(t.data??{});return(()=>{var t=jf(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=bf();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Mf(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Nf(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(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=Pf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Ff(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(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=bf();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=If(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Lf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=Hf(),o=a.firstChild,s=o.nextSibling;return z(o,(()=>{var e=F(()=>!!r());return()=>e()?``:n.icon})()),z(s,(()=>{var e=F(()=>!!r());return()=>e()&&(()=>{var e=Uf();return y(()=>L(e,`title`,`${Om(t.ts)} · ${t.branch}`)),e})()})(),null),z(s,M(P,{get when(){return!r()},get children(){var r=Vf(),i=r.firstChild,a=i.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=Of();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:Om(t.ts)})()),z(r,M(P,{get when(){return e.showBranch},get children(){var e=Rf();return z(e,()=>t.branch),e}}),null),z(r,M(P,{get when(){return e.onCancel},get children(){var t=zf();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(Gm,{get text(){return Fm(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=Bf();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(s,M(Rm,{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()?`${Om(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&R(a,e.e=s),c!==e.t&&L(a,`data-eid`,e.t=c),l!==e.a&&R(o,e.a=l),u!==e.o&&Ee(o,`background`,e.o=u),d!==e.i&&Ee(o,`border`,e.i=d),f!==e.n&&L(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 Lm(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=Wf(),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&&L(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 Rm(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=mu();return y(()=>e.innerHTML=pm(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=Gf();return z(t,M(N,{each:e,children:e=>(()=>{var t=Kf();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=qf(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Vm(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>zm(String(t.data.reasoning),8e3)),e}}),(()=>{var e=mu();return y(()=>e.innerHTML=pm(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return Jf()}}),M(P,{get when(){return t.data.final},get children(){var e=Yf(),n=e.firstChild;return z(e,M(Gm,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(Pm,{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=Zf(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(Gm,{text:n}),null),z(c,()=>zm(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?zt(Rt(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return Xf()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=$f(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=Qf();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=pm(String(t.data?.decision??``)),r=pm(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=np(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return ep()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=tp();return z(a,M(N,{each:n,children:n=>(()=>{var a=rp();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)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M(Lm,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=pm(String(t.data?.question??``));return n!==e.e&&R(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=ip(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=Vd(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=Rd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=pm(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=zd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=pm(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=Bd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=pm(String(t.data.next))),e}}),null),y(()=>n.innerHTML=pm(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=ap(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=sp(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>Vm(Number(t.data.tokensBefore??0)),i),z(n,()=>Vm(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[op(),(()=>{var e=mu();return y(()=>e.innerHTML=pm(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=cp();return z(e,()=>zm(JSON.stringify(t.data),200)),e})()}}function zm(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Bm(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 Vm(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 Hm(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 Um(e,t){return zm(e.replace(/\s+/g,` `).trim(),t)}function Wm(e){return(()=>{var t=lp(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(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&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Gm(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),Tt(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=up();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function Km(e){return(()=>{var t=dp(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function qm(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??[])}C(()=>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 M(Km,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=pp(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,C=S.firstChild.nextSibling,w=S.nextSibling,ee=w.firstChild.nextSibling,T=w.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(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=mp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),C.$$input=e=>o(e.currentTarget.value),ee.addEventListener(`change`,e=>c(e.currentTarget.value)),z(ee,M(N,{get each(){return e.providers},children:e=>(()=>{var t=qu();return z(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=fp();return z(e,d),e}}),E),y(()=>h.value=t()),y(()=>C.value=a()),y(()=>ee.value=s()),y(()=>T.value=l()),i}})}var Jm=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Ym=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Xm=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Zm(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 Jm.has(t)?`image`:Ym.has(t)?`video`:Xm.has(t)?`audio`:null}var $m=new Map,eh=e=>{let t=$m.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},$m.set(e,t)),t};function th(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),w(()=>t.disconnect())};return M(P,{get when(){return e.preview},get fallback(){return(()=>{var t=gp();return t.$$input=t=>e.onDraft(t.currentTarget.value),De(a,t),y(e=>Te(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=hp();return De(a,t),y(n=>{var r=i(),a=pm(e.draft);return n.e=Te(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function nh(e){let t=eh(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`),C=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},ee=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)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[ue,j]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await eu(async()=>{let{highlightChunks:e}=await import(`./shiki-BMrIxi5v.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};w(()=>{fe++});let me=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}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(t&&!ue()){j(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),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`)?(le(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{j(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=vp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Zm(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=_p();return z(t,()=>Vm(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&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(ee)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!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{be(!1)}}};return[(()=>{var e=yp(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(Wm,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(Wm,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:C}),null),z(e,M(Wm,{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=bp();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=xp();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(ee)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(Km,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=Ep(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=wp();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=Tp();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return Op()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(rh,{get path(){return t().path},get content(){return t().content},get html(){return ae()},get pending(){return se()},get truncated(){return!!t().truncated}})},get children(){var e=kp();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=Dp(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>Vm(A().length),i),a.$$click=()=>void he(),z(a,()=>ue()?`saving…`:`💾 save`),y(()=>a.disabled=ue()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=Cp(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=jp();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Ap();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Sp();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function rh(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=Pp(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Fp();return z(t,()=>e.content),t})()},get children(){var t=Mp();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return Np()}})]}var ih=[{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)`}],ah={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 oh(e){let[t,n]=v(ih[0]),[r,i]=v(ih[0].url),[a,o]=v(``),[s,c]=v(ih[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);w(()=>clearTimeout(n))});let C=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Vm(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(` · `)},ee=()=>C(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=Bp(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,w=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,ae=re.nextSibling;return n.addEventListener(`submit`,E),z(u,()=>[...ih,ah].map(e=>(()=>{var n=Vp();return n.$$click=()=>S(e),z(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),z(n,M(P,{get when(){return t().hint},get children(){var e=Ip();return z(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),z(b,()=>ih.map(e=>(()=>{var t=qu();return y(()=>t.value=e.url),t})())),w.$$input=e=>o(e.currentTarget.value),D.$$input=e=>c(e.currentTarget.value),z(ne,()=>l().map(e=>(()=>{var t=qu();return y(()=>t.value=e.id),t})())),z(n,M(P,{get when(){return T().length>0},get fallback(){return(()=>{var e=Hp();return z(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=Lp();return z(e,()=>T().slice(0,40).map(e=>(()=>{var t=Up(),n=t.firstChild;return t.$$click=()=>c(e.id),z(n,()=>e.id),z(t,M(P,{get when(){return C(e.id)},get children(){var t=wf();return z(t,()=>C(e.id)),t}}),null),y(n=>{var r=`wizmodel`+(s()===e.id?` active`:``),i=C(e.id)||e.id;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})())),e})(),(()=>{var e=zp(),t=e.firstChild;return z(e,()=>T().length,t),z(e,()=>T().length>1?`s`:``,null),z(e,M(P,{get when(){return T().length>40},children:` (showing the first 40 — keep typing to narrow)`}),null),z(e,M(P,{get when(){return ee()},get children(){return[` · selected: `,(()=>{var e=Rp();return z(e,ee),e})()]}}),null),e})()]}}),re),k.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),z(n,M(P,{get when(){return _()},get children(){var e=fp();return z(e,_),e}}),ae),z(ae,()=>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&&L(D,`placeholder`,e.e=n),r!==e.t&&(ae.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>w.value=a()),y(()=>D.value=s()),y(()=>k.value=d()),y(()=>ie.value=p()),e})()}function sh(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,C]=v(!!e.cfg.shortContext),[w,ee]=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,ae]=v({}),[oe,se]=v({}),ce=async()=>{let e=await $(`/api/mcp`).catch(()=>null);ae(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},A=async(e,t)=>{if(!t)return;let n=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&se(t=>({...t,[e]:n}))},le=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 A(t,n.name),await ce();return}if(!r?.ok||!r.url){k(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await A(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(se(e=>({...e,[t]:r})),r.authorized){k(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await ce(),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(()=>{de()===`mcp`&&(ce(),T().forEach((e,t)=>{e.name&&A(t,e.name)}))});let[ue,j]=v(``),[de,fe]=v(`providers`),[pe,me]=v([]),he=async()=>{let e=await $(`/api/archived`).catch(()=>null);me(e?.agents??[])},ge=()=>pe().filter(e=>!e.parent);b(()=>{de()===`archive`&&he()});let _e=[{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`}],ve=()=>(e.cfg.agents??[]).map(e=>e.id),be=()=>{let e={};for(let t of n()){if(!t.name.trim())return j(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return j(`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},xe=async t=>{t.preventDefault(),j(``);let n=be();if(!n)return;let r=w().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){j(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){j(`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){j(`MCP: a server needs a name`);return}if(o.has(t)){j(`MCP: two servers are named "${t}"`);return}if(o.add(t),r===`stdio`?!i:!n){j(`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 ce(),await Promise.all(a.map((e,t)=>e.name?A(t,e.name):Promise.resolve())),setTimeout(()=>{ce(),a.forEach((e,t)=>{e.name&&A(t,e.name)})},1200),e.onSaved(),T().some((e,t)=>oe()[t]?.required&&!oe()[t]?.authorized)?(fe(`mcp`),Q(`a saved MCP server needs authorization — see 🔑 authorize`)):e.onClose()}catch(e){j(e.message)}},Se=(e,t,n,r)=>(()=>{var i=Wp(),a=i.firstChild;return L(i,`title`,r),z(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return M(Km,{title:`settings`,get onClose(){return e.onClose},get children(){var t=Kp(),v=t.firstChild,b=v.firstChild,ae=b.nextSibling.firstChild,se=ae.firstChild.nextSibling,ce=se.nextSibling;ce.firstChild;var pe=ce.nextSibling.firstChild.firstChild.nextSibling;pe.firstChild;var me=ae.nextSibling,be=me.firstChild.nextSibling,I=be.firstChild,Ce=I.firstChild.nextSibling,we=be.nextSibling.firstChild,Ee=me.nextSibling,De=Ee.firstChild.nextSibling.nextSibling,Oe=Ee.nextSibling,ke=Oe.firstChild.nextSibling,Ae=Oe.nextSibling;Ae.firstChild;var je=Ae.nextSibling;je.firstChild;var Me=je.nextSibling,Ne=Me.firstChild.nextSibling.firstChild;Ne.firstChild;var Pe=Ne.nextSibling,Fe=v.nextSibling,Ie=Fe.firstChild;return t.addEventListener(`submit`,xe),z(b,M(N,{each:_e,children:e=>(()=>{var t=qp(),n=t.firstChild;return t.$$click=()=>fe(e.key),z(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(de()===e.key?` on`:``),i=e.hint,a=de()===e.key?`page`:void 0;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),z(ae,M(ye,{get each(){return n()},children:(e,t)=>(()=>{var i=Jp(),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)),z(l,M(N,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=Xp(),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,z(o,M(P,{get when(){return e().apiKeys.length>1},get children(){var e=Yp();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>L(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})()}),se),se.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),z(ce,M(N,{each:ih,children:e=>(()=>{var t=Zp();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)},z(t,()=>e.label,null),y(()=>L(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),pe.addEventListener(`change`,e=>a(e.currentTarget.value)),z(pe,M(N,{get each(){return s()},children:e=>(()=>{var t=qu();return t.value=e,z(t,e),t})()}),null),z(ae,M(P,{get when(){return c()},get children(){var e=Gp(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,c),z(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,c),e}}),null),z(be,()=>Se(`progress interval (min)`,l(),e=>u(e),`how often the harness asks for a progress report`),I),z(be,()=>Se(`progress min chars`,d(),e=>f(e),`progress prompts wait for this much real output`),I),Ce.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),z(be,()=>Se(`context window (k tok)`,h(),e=>g(e),`model's real window — 0/blank hides the % gauge`),null),z(be,()=>Se(`max spawn depth`,_(),e=>x(e),`sub-agent nesting limit (0 = no spawning)`),null),we.addEventListener(`change`,e=>C(e.currentTarget.checked)),z(Ee,M(P,{get when(){return T().length>0},get fallback(){return Qp()},get children(){return M(ye,{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=om(),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})),z(d,M(P,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=$p();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=em();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 A(t,e.name)},z(p,M(P,{get when(){return F(()=>!!oe()[t]?.required)()&&!oe()[t]?.authorized},get children(){var n=tm();return n.$$click=()=>void le(t,e()),n}}),null),z(p,M(P,{get when(){return oe()[t]?.authorized},get children(){return[nm(),(()=>{var n=rm();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await A(t,e().name),k(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),z(p,M(P,{get when(){return n()},get children(){var e=md();return z(e,(()=>{var e=F(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:F(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&R(e,t.e=r),i!==t.t&&L(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),z(i,M(P,{get when(){return ne()[t]},get children(){var e=im();return z(e,()=>ne()[t]),e}}),null),z(i,M(P,{get when(){return O()[t]},get children(){var e=am();return z(e,()=>O()[t]?.text),y(n=>Te(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})()}})}}),De),De.$$click=()=>E([...T(),{name:``,url:``,transport:`http`,enabled:!0}]),z(Oe,M(P,{get when(){return w().length>0},get children(){return M(ye,{get each(){return w()},children:(e,t)=>(()=>{var n=sm(),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=>ee(w().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>ee(w().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>ee(w().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>ee(w().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>ee(w().filter((e,n)=>n!==t)),u.$$input=e=>ee(w().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})()})}}),ke),ke.$$click=()=>ee([...w(),{id:``,agent:ve()[0]??``,schedule:`every 30m`,prompt:``}]),z(Ae,M(P,{get when(){return ge().length>0},get fallback(){return cm()},get children(){return M(N,{get each(){return ge()},children:t=>(()=>{var n=lm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return z(i,()=>t.id),z(a,()=>t.sessions,o),z(a,()=>t.sessions===1?``:`s`,null),z(a,(()=>{var e=F(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),z(a,(()=>{var e=F(()=>!!t.archivedAt);return()=>e()?` · archived ${Bm(new Date(t.archivedAt).toISOString())}`:``})(),null),z(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await he(),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 he(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>L(s,`title`,t.workspace)),n})()})}}),null),z(je,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=dm(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=um();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(Ne,()=>e.cfg.version??`unknown`,null),Pe.$$click=async e=>{try{j(``);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.30.0`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){j(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},z(Fe,M(P,{get when(){return ue()},get children(){var e=fp();return z(e,ue),e}}),Ie),y(e=>{var t=de()!==`providers`,n=de()!==`runtime`,r=de()!==`mcp`,i=de()!==`tasks`,a=de()!==`archive`,o=de()!==`agents`,s=de()!==`update`;return t!==e.e&&ae.classList.toggle(`hide`,e.e=t),n!==e.t&&me.classList.toggle(`hide`,e.t=n),r!==e.a&&Ee.classList.toggle(`hide`,e.a=r),i!==e.o&&Oe.classList.toggle(`hide`,e.o=i),a!==e.i&&Ae.classList.toggle(`hide`,e.i=a),o!==e.n&&je.classList.toggle(`hide`,e.n=o),s!==e.s&&Me.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(()=>pe.value=i()),y(()=>Ce.value=p()??``),y(()=>we.checked=S()),t}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(jm,{}),document.getElementById(`root`));export{eu as t};
30
- //# sourceMappingURL=index-inDX-RrS.js.map
29
+ Cancel = keep editing your copy`)?(le(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{j(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=vp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Zm(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=_p();return z(t,()=>Vm(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&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(ee)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!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{be(!1)}}};return[(()=>{var e=yp(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(Wm,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(Wm,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:C}),null),z(e,M(Wm,{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=bp();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=xp();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(ee)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(Km,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=Ep(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=wp();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=Tp();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return Op()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(rh,{get path(){return t().path},get content(){return t().content},get html(){return ae()},get pending(){return se()},get truncated(){return!!t().truncated}})},get children(){var e=kp();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=Dp(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>Vm(A().length),i),a.$$click=()=>void he(),z(a,()=>ue()?`saving…`:`💾 save`),y(()=>a.disabled=ue()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=Cp(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=jp();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Ap();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Sp();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function rh(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=Pp(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Fp();return z(t,()=>e.content),t})()},get children(){var t=Mp();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return Np()}})]}var ih=[{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)`}],ah={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 oh(e){let[t,n]=v(ih[0]),[r,i]=v(ih[0].url),[a,o]=v(``),[s,c]=v(ih[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);w(()=>clearTimeout(n))});let C=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Vm(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(` · `)},ee=()=>C(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=Bp(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,w=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,ae=re.nextSibling;return n.addEventListener(`submit`,E),z(u,()=>[...ih,ah].map(e=>(()=>{var n=Vp();return n.$$click=()=>S(e),z(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),z(n,M(P,{get when(){return t().hint},get children(){var e=Ip();return z(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),z(b,()=>ih.map(e=>(()=>{var t=qu();return y(()=>t.value=e.url),t})())),w.$$input=e=>o(e.currentTarget.value),D.$$input=e=>c(e.currentTarget.value),z(ne,()=>l().map(e=>(()=>{var t=qu();return y(()=>t.value=e.id),t})())),z(n,M(P,{get when(){return T().length>0},get fallback(){return(()=>{var e=Hp();return z(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=Lp();return z(e,()=>T().slice(0,40).map(e=>(()=>{var t=Up(),n=t.firstChild;return t.$$click=()=>c(e.id),z(n,()=>e.id),z(t,M(P,{get when(){return C(e.id)},get children(){var t=wf();return z(t,()=>C(e.id)),t}}),null),y(n=>{var r=`wizmodel`+(s()===e.id?` active`:``),i=C(e.id)||e.id;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})())),e})(),(()=>{var e=zp(),t=e.firstChild;return z(e,()=>T().length,t),z(e,()=>T().length>1?`s`:``,null),z(e,M(P,{get when(){return T().length>40},children:` (showing the first 40 — keep typing to narrow)`}),null),z(e,M(P,{get when(){return ee()},get children(){return[` · selected: `,(()=>{var e=Rp();return z(e,ee),e})()]}}),null),e})()]}}),re),k.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),z(n,M(P,{get when(){return _()},get children(){var e=fp();return z(e,_),e}}),ae),z(ae,()=>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&&L(D,`placeholder`,e.e=n),r!==e.t&&(ae.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>w.value=a()),y(()=>D.value=s()),y(()=>k.value=d()),y(()=>ie.value=p()),e})()}function sh(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,C]=v(!!e.cfg.shortContext),[w,ee]=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,ae]=v({}),[oe,se]=v({}),ce=async()=>{let e=await $(`/api/mcp`).catch(()=>null);ae(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},A=async(e,t)=>{if(!t)return;let n=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&se(t=>({...t,[e]:n}))},le=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 A(t,n.name),await ce();return}if(!r?.ok||!r.url){k(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await A(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(se(e=>({...e,[t]:r})),r.authorized){k(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await ce(),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(()=>{de()===`mcp`&&(ce(),T().forEach((e,t)=>{e.name&&A(t,e.name)}))});let[ue,j]=v(``),[de,fe]=v(`providers`),[pe,me]=v([]),he=async()=>{let e=await $(`/api/archived`).catch(()=>null);me(e?.agents??[])},ge=()=>pe().filter(e=>!e.parent);b(()=>{de()===`archive`&&he()});let _e=[{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`}],ve=()=>(e.cfg.agents??[]).map(e=>e.id),be=()=>{let e={};for(let t of n()){if(!t.name.trim())return j(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return j(`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},xe=async t=>{t.preventDefault(),j(``);let n=be();if(!n)return;let r=w().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){j(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){j(`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){j(`MCP: a server needs a name`);return}if(o.has(t)){j(`MCP: two servers are named "${t}"`);return}if(o.add(t),r===`stdio`?!i:!n){j(`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 ce(),await Promise.all(a.map((e,t)=>e.name?A(t,e.name):Promise.resolve())),setTimeout(()=>{ce(),a.forEach((e,t)=>{e.name&&A(t,e.name)})},1200),e.onSaved(),T().some((e,t)=>oe()[t]?.required&&!oe()[t]?.authorized)?(fe(`mcp`),Q(`a saved MCP server needs authorization — see 🔑 authorize`)):e.onClose()}catch(e){j(e.message)}},Se=(e,t,n,r)=>(()=>{var i=Wp(),a=i.firstChild;return L(i,`title`,r),z(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return M(Km,{title:`settings`,get onClose(){return e.onClose},get children(){var t=Kp(),v=t.firstChild,b=v.firstChild,ae=b.nextSibling.firstChild,se=ae.firstChild.nextSibling,ce=se.nextSibling;ce.firstChild;var pe=ce.nextSibling.firstChild.firstChild.nextSibling;pe.firstChild;var me=ae.nextSibling,be=me.firstChild.nextSibling,I=be.firstChild,Ce=I.firstChild.nextSibling,we=be.nextSibling.firstChild,Ee=me.nextSibling,De=Ee.firstChild.nextSibling.nextSibling,Oe=Ee.nextSibling,ke=Oe.firstChild.nextSibling,Ae=Oe.nextSibling;Ae.firstChild;var je=Ae.nextSibling;je.firstChild;var Me=je.nextSibling,Ne=Me.firstChild.nextSibling.firstChild;Ne.firstChild;var Pe=Ne.nextSibling,Fe=v.nextSibling,Ie=Fe.firstChild;return t.addEventListener(`submit`,xe),z(b,M(N,{each:_e,children:e=>(()=>{var t=qp(),n=t.firstChild;return t.$$click=()=>fe(e.key),z(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(de()===e.key?` on`:``),i=e.hint,a=de()===e.key?`page`:void 0;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),z(ae,M(ye,{get each(){return n()},children:(e,t)=>(()=>{var i=Jp(),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)),z(l,M(N,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=Xp(),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,z(o,M(P,{get when(){return e().apiKeys.length>1},get children(){var e=Yp();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>L(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})()}),se),se.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),z(ce,M(N,{each:ih,children:e=>(()=>{var t=Zp();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)},z(t,()=>e.label,null),y(()=>L(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),pe.addEventListener(`change`,e=>a(e.currentTarget.value)),z(pe,M(N,{get each(){return s()},children:e=>(()=>{var t=qu();return t.value=e,z(t,e),t})()}),null),z(ae,M(P,{get when(){return c()},get children(){var e=Gp(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,c),z(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,c),e}}),null),z(be,()=>Se(`progress interval (min)`,l(),e=>u(e),`how often the harness asks for a progress report`),I),z(be,()=>Se(`progress min chars`,d(),e=>f(e),`progress prompts wait for this much real output`),I),Ce.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),z(be,()=>Se(`context window (k tok)`,h(),e=>g(e),`model's real window — 0/blank hides the % gauge`),null),z(be,()=>Se(`max spawn depth`,_(),e=>x(e),`sub-agent nesting limit (0 = no spawning)`),null),we.addEventListener(`change`,e=>C(e.currentTarget.checked)),z(Ee,M(P,{get when(){return T().length>0},get fallback(){return Qp()},get children(){return M(ye,{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=om(),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})),z(d,M(P,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=$p();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=em();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 A(t,e.name)},z(p,M(P,{get when(){return F(()=>!!oe()[t]?.required)()&&!oe()[t]?.authorized},get children(){var n=tm();return n.$$click=()=>void le(t,e()),n}}),null),z(p,M(P,{get when(){return oe()[t]?.authorized},get children(){return[nm(),(()=>{var n=rm();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await A(t,e().name),k(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),z(p,M(P,{get when(){return n()},get children(){var e=md();return z(e,(()=>{var e=F(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:F(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&R(e,t.e=r),i!==t.t&&L(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),z(i,M(P,{get when(){return ne()[t]},get children(){var e=im();return z(e,()=>ne()[t]),e}}),null),z(i,M(P,{get when(){return O()[t]},get children(){var e=am();return z(e,()=>O()[t]?.text),y(n=>Te(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})()}})}}),De),De.$$click=()=>E([...T(),{name:``,url:``,transport:`http`,enabled:!0}]),z(Oe,M(P,{get when(){return w().length>0},get children(){return M(ye,{get each(){return w()},children:(e,t)=>(()=>{var n=sm(),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=>ee(w().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>ee(w().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>ee(w().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>ee(w().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>ee(w().filter((e,n)=>n!==t)),u.$$input=e=>ee(w().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})()})}}),ke),ke.$$click=()=>ee([...w(),{id:``,agent:ve()[0]??``,schedule:`every 30m`,prompt:``}]),z(Ae,M(P,{get when(){return ge().length>0},get fallback(){return cm()},get children(){return M(N,{get each(){return ge()},children:t=>(()=>{var n=lm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return z(i,()=>t.id),z(a,()=>t.sessions,o),z(a,()=>t.sessions===1?``:`s`,null),z(a,(()=>{var e=F(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),z(a,(()=>{var e=F(()=>!!t.archivedAt);return()=>e()?` · archived ${Bm(new Date(t.archivedAt).toISOString())}`:``})(),null),z(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await he(),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 he(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>L(s,`title`,t.workspace)),n})()})}}),null),z(je,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=dm(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=um();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(Ne,()=>e.cfg.version??`unknown`,null),Pe.$$click=async e=>{try{j(``);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.30.1`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){j(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},z(Fe,M(P,{get when(){return ue()},get children(){var e=fp();return z(e,ue),e}}),Ie),y(e=>{var t=de()!==`providers`,n=de()!==`runtime`,r=de()!==`mcp`,i=de()!==`tasks`,a=de()!==`archive`,o=de()!==`agents`,s=de()!==`update`;return t!==e.e&&ae.classList.toggle(`hide`,e.e=t),n!==e.t&&me.classList.toggle(`hide`,e.t=n),r!==e.a&&Ee.classList.toggle(`hide`,e.a=r),i!==e.o&&Oe.classList.toggle(`hide`,e.o=i),a!==e.i&&Ae.classList.toggle(`hide`,e.i=a),o!==e.n&&je.classList.toggle(`hide`,e.n=o),s!==e.s&&Me.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(()=>pe.value=i()),y(()=>Ce.value=p()??``),y(()=>we.checked=S()),t}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(jm,{}),document.getElementById(`root`));export{eu as t};
30
+ //# sourceMappingURL=index-CbgAwKXj.js.map