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