teapot-coding-agent 0.37.96 → 0.37.97

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.
@@ -177,7 +177,7 @@ XID_Start XIDS`.split(/\s/).map(e=>[ey(e),e])),qy=new Map([[`s`,My(383)],[My(383
177
177
  `),o=n.codeToHast(a,{lang:e,themes:Zb,defaultColor:!1,...i?{grammarState:i}:{}});i=n.getLastGrammarState(o)??void 0,yield __(o)}}var lx=/(?:^|\s)language-([\w+#.-]+)/,ux=`hl`;function dx(e){if(e)for(let t of e.querySelectorAll(`pre`)){if(t.dataset[ux])continue;let e=t.querySelector(`code`);if(!e){t.dataset[ux]=`skip`;continue}let n=lx.exec(e.className)?.[1],r=n?ox(`x.${n}`)??n:void 0,i=e.textContent??``;if(!r||!i.trim()){t.dataset[ux]=`skip`;continue}let a=`${r}::${i.length}::${i}`;t.dataset[ux]=`pending`;let o=md(a);o===void 0?(async()=>{try{let{highlightLangChunks:e}=await J(async()=>{let{highlightLangChunks:e}=await Promise.resolve().then(()=>Xb);return{highlightLangChunks:e}},void 0),n=``;for await(let t of e(r,i))n+=t;if(!n){t.dataset[ux]=`skip`;return}hd(a,n),t.isConnected&&fx(t,n)}catch{t.dataset[ux]=`skip`}})():fx(t,o)}}function fx(e,t){let n=document.createElement(`div`);n.className=`shikiwrap`;let r=document.createElement(`div`);r.className=`shiki`,r.innerHTML=t,n.appendChild(r),e.replaceWith(n)}function px(e){let t=String(e??``).trim();if(!t)return null;if(t.startsWith(`[`)){let e=(()=>{try{return JSON.parse(t)}catch{try{return JSON.parse(t.replace(/'/g,`"`))}catch{return}}})();if(Array.isArray(e)&&e.length>=2)return`${String(e[0])}/${String(e[1])}`}for(let e of[`__`,`/`,`::`]){let n=t.lastIndexOf(e);if(!(n<=0))return`${t.slice(0,n).replace(/^mcp__/,``)}/${t.slice(n+e.length)}`}return t}var mx={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`}},hx={name:`harness`,icon:`📣`,color:`#3ba55d`},gx={"#faa81a":`you`,"#5865f2":`agent`,"#3ba55d":`progress`,"#3ba0c9":`tool`},_x=e=>gx[e]??`agent`,vx=e=>{if(e.data?.actor)return{name:`@${String(e.data.actor)}`,icon:`🧩`,color:`#3ba0c9`};if(e.type===`tool_call`||e.type===`tool_result`){let t=String(e.data?.name??`tool`);if(t===`run_tool`){let t=px(e.data?.args?.tool_id);if(t)return{name:t,icon:`⚙️`,color:`#3ba0c9`}}let n=/^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(t);return n?{name:`${n[1]}/${n[2]}`,icon:`⚙️`,color:`#3ba0c9`}:{name:t,icon:`⚙️`,color:`#3ba0c9`}}if(e.type===`prompt`){let t=String(e.data?.source??`user`);return t===`user`?mx.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:hx}return mx[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},yx=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};function bx(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 xx(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 Sx(e,t){return at(e.replace(/\s+/g,` `).trim(),t)}function Cx(e){return e.type===`prompt`&&e.data?.source===`user`?`you`:e.type===`message`?`agent`:`harness`}function wx(e){let t=e.data??{};if(e.data?.actor)return`sub:${String(e.data.actor)}`;if(e.type===`tool_call`||e.type===`tool_result`){let e=typeof t.name==`string`?t.name:``;return e===`load_skill`?`agent-skill`:`tool:${e}`}return e.type===`prompt`?`src:${String(t.source??`user`)}`:`type:${e.type}`}function Tx(e,t){return!(!e||t.data?.pending||e.data?.pending||t.data?.cancelled||wx(e)!==wx(t)||Cx(e)!==Cx(t)||t.session!==e.session||t.branch!==e.branch)}function Ex(e,t){let n=String(t??``);return/^TIMEOUT after\b/.test(n)?`timeout`:/^ABORTED\b/.test(n)?`aborted`:/^exit=\d+/.test(n)||e===!1?`exit`:n.trim()?`ok`:`empty`}function Dx(e){switch(e){case`timeout`:return` · TIMED OUT`;case`aborted`:return` · ABORTED`;case`exit`:return` · FAILED`;default:return``}}function Ox(e){let t=[];e.outcome!==`empty`&&t.push(e.fmtDur(e.durationMs)),e.timeoutMs&&t.push(`timeout ${Math.round(e.timeoutMs/1e3)}s`);let n=Dx(e.outcome).replace(/^\s*·\s*/,``);return n&&t.push(n),t.join(` · `)}function kx(e){let t=e.trim();if(!t)return;let n=t[0];if(n===`{`||n===`[`||n===`"`)try{let e=JSON.parse(t);return typeof e==`object`&&e?`json`:void 0}catch{return}}function Ax(e){if(kx(e)!==`json`)return e;try{let t=JSON.parse(e.trim()),n=JSON.stringify(t,null,1);return e.trim().split(`
178
178
  `).length>1?e:n}catch{return e}}var jx=12e4,Mx=6e5,Nx=e=>{let t=Number(e);return Math.min(Number.isFinite(t)&&t>0?t:jx,Mx)},Px=F(`<div class=qfree><input type=text><button>reply`),Fx=F(`<div class=meta>`),Ix=F(`<div class=meta>waiting for output…`),Lx=F(`<div class="meta bgjob-note">runs in background — poll with <b>bash_output(job_id=&quot;<!>&quot;)`),Rx=F(`<b>action="kill"`),zx=F(`<div class=meta>writing…`),Bx=F(`<pre class="mono toolbody del">`),Vx=F(`<pre class="mono toolbody add">`),Hx=F(`<div class=meta> · `),Ux=F(`<div class=meta>applying…`),Wx=F(`<pre class="mono toolbody patch">`),Gx=F(`<div>`),Kx=F(`<div class=meta>validating…`),qx=F(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),Jx=F(`<span class=muted>`),Yx=F(`<div class=content>`),Xx=F(`<div class=meta>loading…`),Zx=F(`<div class=meta>bundled: `),Qx=F(`<div class=meta>saving…`),$x=F(`<div class=meta>found: `),eS=F(`<div class=meta>no matches`),tS=F(`<span class=actor>@`),nS=F(`<details><summary><b></b><span class=meta></span><span class=toolcopy>`),rS=F(`<div class=divider-msg>⑂ forked from <!> → `),iS=F(`<div><div class=goalline-label>`),aS=F(`<div class="embed auditstep"><span class=meta>`),oS=F(`<span class="meta muted">`),sS=F(`<pre class="mono toolbody">`),cS=F(`<details class="embed auditstep"><summary><span class=meta>`),lS=F(`<div class=divider-msg>✅ tasks updated (<!>)`),uS=F(`<div> → `),dS=F(`<div class="embed fail"><div class=mono>🛑 runaway: <!> tool failures in a row (limit <!>)</div><div class=meta>last: <!> — `),fS=F(`<div class="embed warn-embed"title="a round-fatal API error occurred; auto-retry is waiting, then a fresh round starts (onError: retry)"><div class=mono>↻ API error — retrying (attempt <!>) in <!>s…`),pS=F(`<div class=divider-msg>🗜 compacted: <!> → <!> tok (<!>)`),mS=F(`<div class=divider-msg title="compaction is rewriting older history — the agent is not stuck">🗜 compacting: summarizing <!> earlier messages from <!> tok (<!>)…`),hS=F(`<span class=ts>`),gS=F(`<button class=editbtn title="withdraw this message — it has not reached the model yet; the text goes back to the input box">✕ cancel`),_S=F(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),vS=F(`<div class=msg-head><span></span><span class=ts>`),yS=F(`<div><div></div><div class=msg-body>`),bS=F(`<span class=grouptime>`),xS=F(`<div class=promptimgs>`),SS=F(`<img class=promptimg alt="tool image"loading=lazy>`,!0,!1,!1),CS=F(`<img class=promptimg alt=attachment>`),wS=F(`<details class=reasoning><summary>💭 thinking</summary><div class=mono>`),TS=F(`<div class=interrupted>⚠ interrupted — partial output kept`),ES=F(`<div class=msgfoot><span>copy summary`),DS=F(`<div class=meta>its call is no longer in the loaded events — the run itself finished`),OS=F(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>`),kS=F(`<div class="content muted">Rejected: `),AS=F(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged`),jS=F(`<div class="meta answerdone">✓ answered — continuing below`),MS=F(`<div class=qopts>`),NS=F(`<div><div>❓️ <div class="content inline-md">`),PS=F(`<button class=qopt>`),FS=F(`<div class=progrow><b>goal</b><span>`),IS=F(`<div class=progrow><b>recent</b><span class="content inline-md">`),LS=F(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),RS=F(`<div class=progrow><b>next</b><span class="content inline-md">`),zS=F(`<div class="embed progembed"><div>📈 <div class="content inline-md">`),BS=F(`<div class="embed fail"><div class=mono>⚠ `),VS=F(`<div class="muted compactnote">the summary pass produced nothing, so the oldest messages were dropped instead — the session continues with the recent tail intact`),HS=F(`<div class="embed compaction"><b>🗜 context compacted</b><span class=meta> · <!> → <!> tok · `),US=F(`<div class="vtitle compactkept">what the agent kept`),WS=F(`<details class="embed compaction"><summary><b>🗜 context compacted</b><span class=meta> · <!> → <!> tok · `),GS=F(`<div class="content muted">`);function KS(e){let[t,n]=y(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=Px(),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,b(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}),b(()=>a.value=t()),i})()}function qS(e){let t=e.e,n=Tx(e.prev,t),r=S(()=>e.res?.(),void 0,{equals:(e,t)=>e?.id===t?.id}),i=()=>r(),a=()=>!e.agentActive&&!i(),o=t.data??{},s=String(o.name??`tool`),c=()=>String(i()?.data?.result??``),l=e=>String(o.args?.[e]??``),u=()=>s===`bash`?l(`command`):l(`path`)||JSON.stringify(o.args??{},null,1),d=()=>s===`bash`?Nx(l(`timeout_ms`)):s===`wait_children`?Number(l(`timeout_ms`))||3e5:Number(l(`timeout_ms`))||void 0,f=(e,t,n)=>j(jd,{text:e,lang:n}),p=e=>j(jd,{get text(){return JSON.stringify(e??o.args??{},null,1)},lang:`json`}),m=()=>(()=>{let t=i();return t?[P(()=>P(()=>!!dd(c()))()?j(Ad,{get text(){return c()}}):j(jd,{get text(){return Ax(c())},get lang(){return kx(c())}})),(()=>{var e=Fx();return R(e,()=>it(t.data?.durationMs),null),R(e,()=>s===`bash`?Dx(Ex(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),R(e,j(nd,{get text(){return P(()=>!!dd(c()))()?ud(c()):Ax(c())}}),null),e})(),j(XS,{get data(){return t.data},get agentId(){return e.agentId}})]:Ix()})(),h=S(()=>{i();let e=s,t=``,n=p(),r=(r,a,o)=>{let s=o??{},c=Object.keys(s);e=c.length?Sx(JSON.stringify(s),120):`(no arguments)`,t=i()?it(i().data?.durationMs):null,n=[P(()=>P(()=>!!c.length)()?p(s):null),P(m)]};try{switch(s){case`bash`:{let r=l(`command`),a=o.args?.background===!0,s=a?String(c()).match(/job (bg\d+)/)?.[1]??``:``;e=(a?`⏳ `:`$ `)+Sx(r,96);let u=l(`timeout_ms`)?Number(l(`timeout_ms`)):void 0,d=i(),f=Ex(d?.data?.ok,d?String(d.data?.result??``):``);t=d?a?`background job${s?` ${s}`:``}${u?` · timeout ${Math.round(u/1e3)}s`:``}`:Ox({outcome:f,durationMs:d.data?.durationMs,timeoutMs:u,fmtDur:it}):null,n=[a?(()=>{var e=Lx(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,R(t,s||`?`,n),R(e,s?[` · kill with `,Rx()]:null,null),e})():null,P(()=>P(()=>r!==e.slice(2))()?j(jd,{text:r,lang:`shellscript`}):null),P(m)];break}case`read_file`:{e=l(`path`)||`(no path)`;let r=[];l(`pattern`)&&r.push(`grep /${Sx(l(`pattern`),40)}/`),Number(o.args?.offset)<0?r.push(`last ${-Number(o.args.offset)} lines`):o.args?.offset&&r.push(`from L${o.args.offset}`),o.args?.limit&&r.push(`≤${o.args.limit} lines`),t=r.join(` · `),n=m();break}case`write_file`:{let r=String(o.args?.content??``);e=l(`path`)||`(no path)`,t=`${xx(r.length)} bytes`,n=[P(()=>f(r)),P(()=>P(()=>!!i())()?(()=>{var e=Fx();return R(e,()=>Sx(c(),160)),e})():zx())];break}case`edit_file`:e=l(`path`)||`(no path)`,t=o.args?.replace_all===!0?`replace all`:`unique spot`,n=[(()=>{var e=Bx();return R(e,()=>`- `+l(`old_text`)),e})(),(()=>{var e=Vx();return R(e,()=>`+ `+l(`new_text`)),e})(),P(()=>P(()=>!!i())()?(()=>{var e=Hx(),t=e.firstChild;return R(e,()=>Sx(c(),120),t),R(e,()=>it(i().data?.durationMs),null),e})():Ux())];break;case`apply_patch`:{let t=l(`patch`).split(`
179
179
  `).filter(e=>e&&!/^---$/.test(e.trim())),r=t.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);e=r.length?`${r.length} file${r.length>1?`s`:``}: ${Sx(r.join(`, `),80)}`:`patch`,n=[(()=>{var e=Wx();return R(e,()=>t.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Gx();return L(n,`pline`+t),R(n,e),n})()})),e})(),P(()=>P(()=>!!i())()?(()=>{var e=Fx();return R(e,()=>Sx(c().split(`
180
- `)[0]??``,140),null),R(e,()=>i().data?.ok===!1?` · FAILED`:``,null),e})():Kx())];break}case`list_dir`:e=l(`path`)||`.`,n=m();break;case`read_url`:{let r=l(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=Sx(r,70),t=`web`,n=[(()=>{var e=Fx();return R(e,j(N,{get when(){return/^https?:/i.test(l(`url`))},get fallback(){return(()=>{var e=Jx();return R(e,()=>Sx(l(`url`),80)),e})()},get children(){var e=qx();return b(()=>I(e,`href`,l(`url`))),e}})),e})(),P(m)];break}case`bash_output`:{let r=l(`action`)||`read`;e=`bash_output ${l(`job_id`)||`(?)`}`,t=r,n=m();break}case`load_skill`:{e=`skill: ${l(`name`)}`;let t=c().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);n=i()?[(()=>{var e=Yx();return b(()=>e.innerHTML=Re(t)),e})(),(()=>{var e=Fx();return R(e,()=>it(i().data?.durationMs)),e})()]:Xx();break}case`save_skill`:{e=`skill: ${l(`name`)}`,t=Sx(l(`description`),60);let r=Array.isArray(o.args?.files)?o.args.files.map(e=>e?.name).filter(Boolean):[];n=[P(()=>P(()=>!!r.length)()?(()=>{var e=Zx();return e.firstChild,R(e,()=>r.join(`, `),null),e})():null),P(()=>P(()=>!!i())()?(()=>{var e=Hx(),t=e.firstChild;return R(e,()=>Sx(c(),160),t),R(e,()=>it(i().data?.durationMs),null),e})():Qx())];break}case`search_tools`:{e=`🔎 ${Sx(l(`query`)||`(browse)`,60)}`;let r=(()=>{try{let e=JSON.parse(c());return{names:(e.tools??[]).map(e=>`${e.server??`?`}/${e.name??`?`}`),total:e.totalMatches??0}}catch{return{names:[],total:0}}})();t=i()?`${r.total} match${r.total===1?``:`es`}`:null,n=[P(p),P(()=>P(()=>!!i())()?P(()=>!!r.names.length)()?(()=>{var e=$x();return e.firstChild,R(e,()=>r.names.join(`, `),null),e})():eS():null),P(m)];break}case`run_tool`:{let a=px(l(`tool_id`)),s=a?.indexOf(`/`)??-1;a&&s>0?r(a.slice(0,s),a.slice(s+1),o.args?.arguments):(e=a||`(no tool_id)`,t=i()?it(i().data?.durationMs):null,n=[P(p),P(m)]);break}default:{let a=/^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(s);if(a){r(a[1],a[2],o.args);break}e=s,t=i()?it(i().data?.durationMs):null,n=[P(p),P(m)];break}}}catch{}return{label:e,hint:t,body:n,key:`${i()?.id??`none`}|${e}|${t??``}`}},void 0,{equals:(e,t)=>e.key===t.key});return(()=>{var r=nS(),o=r.firstChild,l=o.firstChild,f=l.nextSibling,p=f.nextSibling;return r.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),R(l,()=>h().label),R(o,j(N,{get when(){return t.data?.actor},get children(){var e=tS();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),f),R(f,(()=>{var e=P(()=>!!i());return()=>e()?h().hint||``:P(()=>!!a())()?`(result missed)`:P(()=>!!(s===`bash`||d()))()?j(Od,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return d()}}):`running…`})()),R(p,j(nd,{get text(){return u()},label:`⧉ cmd`,title:`copy the ${s} arguments`}),null),R(p,j(N,{get when(){return i()},get children(){return j(nd,{get text(){return P(()=>!!dd(c()))()?ud(c()):c()},label:`⧉ out`,title:`copy this tool's full output (escapes removed)`})}}),null),R(r,()=>h().body,null),b(e=>{var t=`embed`+(n?` grouped`:``)+(i()?i().data?.ok===!1?` fail`:` done`:a()?` done`:` running`),o=`${s}${h().hint?` — `+h().hint:``}`;return t!==e.e&&L(r,e.e=t),o!==e.t&&I(r,`title`,e.t=o),e},{e:void 0,t:void 0}),r})()}function JS(e){let t;return x(()=>{e.html,queueMicrotask(()=>dx(t))}),(()=>{var n=Yx(),r=t;return typeof r==`function`?Ae(r,n):t=n,b(()=>n.innerHTML=e.html),n})()}function YS(e){let t=e.e,n=vx(t),r=()=>Tx(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Tx(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=rS(),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=zt(t.data??{});return(()=>{var t=iS(),n=t.firstChild;return R(n,()=>e.label),R(t,j(N,{get when(){return e.hasCard},get children(){return j(Wt,{get tone(){return P(()=>e.tone===`ok`)()?`ok`:e.tone===`warn`?`warn`:`tool`},get markdown(){return e.markdown},get body(){return e.detail}})}}),null),b(()=>L(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`audit_step`){let e=String(t.data?.step??``),n=String(t.data?.name??``),r=e===`started`?`🔍️ auditor started`:e===`tool`?`🔍️ auditor → ${n}`:e===`tool_done`?`🔍️ auditor ← ${n} ${t.data?.ok===!1?`failed`:`${String(t.data?.chars??0)} chars`}`:e===`reply`?`🔍️ auditor replied`:`🔍️ auditor`;return e===`reply`&&t.data?.text||e===`tool`&&t.data?.args?(()=>{var n=cS(),i=n.firstChild,a=i.firstChild;return R(a,r),R(i,j(N,{get when(){return e===`tool`&&t.data?.args},get children(){var e=oS();return R(e,()=>at(String(t.data?.args??``),120)),e}}),null),R(n,j(N,{get when(){return e===`reply`&&t.data?.text},get children(){var e=sS();return R(e,()=>String(t.data?.text??``)),e}}),null),R(n,j(N,{get when(){return e===`tool`&&t.data?.args},get children(){var e=sS();return R(e,()=>String(t.data?.args??``)),e}}),null),n})():(()=>{var e=aS(),t=e.firstChild;return R(t,r),e})()}if(t.type===`todo`)return(()=>{var e=lS(),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=uS(),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),b(()=>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=dS(),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),b(()=>I(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=fS(),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=Gx();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)`)),b(()=>I(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=pS(),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=mS(),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=yS(),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=bS();return b(()=>I(e,`title`,`${yx(t.ts)} · ${t.branch}`)),e})()})(),null),R(s,j(N,{get when(){return!r()},get children(){var r=vS(),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=tS();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`:yx(t.ts)})()),R(r,j(N,{get when(){return e.showBranch},get children(){var e=hS();return R(e,()=>t.branch),e}}),null),R(r,j(N,{get when(){return e.onCancel},get children(){var t=gS();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(nd,{get text(){return bx(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=_S();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),b(()=>L(i,`author tone-${_x(n.color)}`)),r}}),null),R(s,j(ZS,{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},get agentId(){return e.agentId}}),null),b(e=>{var s=`msg`+(r()?` grouped`:``)+(i()?` next-grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),c=t.id,l=`avatar avghost tone-${_x(n.color)}`+(r()?` ghosted`:``),u=r()?`${yx(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&&I(o,`title`,e.o=u),e},{e:void 0,t:void 0,a:void 0,o:void 0}),a})()}function XS(e){let t=()=>(Array.isArray(e.data?.images)?e.data.images:[]).map(e=>typeof e==`string`?e:e?.url).filter(e=>typeof e==`string`&&e.length>0).map(t=>rf(e.agentId,t));return j(N,{get when(){return t().length},get children(){var e=xS();return R(e,j(M,{get each(){return t()},children:e=>(()=>{var t=SS();return I(t,`src`,e),t})()})),e}})}function ZS(e){let t=e.e;switch(t.type){case`prompt`:{let e=(t.data?.images??[]).map(e=>typeof e==`string`?e:e?.url).filter(e=>typeof e==`string`&&e.length>0);return[j(JS,{get html(){return rt(String(t.data.text??``))}}),j(N,{get when(){return e.length},get children(){var t=xS();return R(t,j(M,{each:e,children:e=>(()=>{var t=CS();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=wS(),n=e.firstChild.nextSibling;return R(n,()=>String(t.data.reasoning)),e}}),j(JS,{get html(){return rt(String(t.data.content??``))}}),j(N,{get when(){return t.data.interrupted},get children(){return TS()}}),j(N,{get when(){return t.data.final},get children(){var e=ES(),n=e.firstChild;return R(e,j(nd,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return j(qS,{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},get agentId(){return e.agentId}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=OS(),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(nd,{text:n}),null),R(c,n),R(l,()=>it(t.data.durationMs),null),R(l,()=>r===`bash`?Dx(Ex(t.data.ok,n)):i?``:` · FAILED`,null),R(a,j(N,{get when(){return e.orphan},get children(){return DS()}}),null),b(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=AS(),r=n.firstChild.firstChild.firstChild.nextSibling;return R(n,j(JS,{get html(){return rt(String(t.data?.rationale??``))}}),null),R(n,j(N,{get when(){return e.length},get children(){var t=kS();return t.firstChild,R(t,()=>e.join(` / `),null),t}}),null),b(()=>r.innerHTML=rt(String(t.data?.decision??``))),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=NS(),o=a.firstChild.firstChild.nextSibling;return R(a,j(N,{get when(){return i()},get children(){return jS()}}),null),R(a,j(N,{get when(){return n.length>0},get children(){var a=MS();return R(a,j(M,{each:n,children:n=>(()=>{var a=PS();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?Y(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>nf(`→ answered @${String(t.data.actor)}`)).catch(()=>nf(`answer failed`)):e.onOption?.(n)},R(a,n),b(()=>a.disabled=i()),a})()})),a}}),null),R(a,j(KS,{get answered(){return i()},get onOption(){return e.onOption}}),null),b(e=>{var n=`embed question`+(i()?` answered`:``),r=rt(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=zS(),n=e.firstChild.firstChild.nextSibling;return R(e,j(N,{get when(){return t.data.goalStatus},get children(){var e=FS(),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=IS(),n=e.firstChild.nextSibling;return b(()=>n.innerHTML=rt(String(t.data.recent))),e}}),null),R(e,j(N,{get when(){return t.data.problems},get children(){var e=LS(),n=e.firstChild.nextSibling;return b(()=>n.innerHTML=rt(String(t.data.problems))),e}}),null),R(e,j(N,{get when(){return t.data.next},get children(){var e=RS(),n=e.firstChild.nextSibling;return b(()=>n.innerHTML=rt(String(t.data.next))),e}}),null),b(()=>n.innerHTML=rt(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=BS(),n=e.firstChild;return n.firstChild,R(n,()=>String(t.data.message??``),null),e})();case`compaction`:return t.data.summary?(()=>{var e=WS(),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,()=>xx(Number(t.data.tokensBefore??0)),i),R(n,()=>xx(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[US(),j(JS,{get html(){return rt(String(t.data.summary))}})]}}),null),e})():(()=>{var e=HS(),n=e.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,R(n,()=>String(t.data.mode??``),r),R(n,()=>xx(Number(t.data.tokensBefore??0)),i),R(n,()=>xx(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(n,()=>String(t.data.mode??``)===`truncate`?` · older history dropped`:``,null),R(e,j(N,{get when(){return String(t.data.mode??``)===`truncate`},get children(){return VS()}}),null),e})();default:return(()=>{var e=GS();return R(e,()=>at(JSON.stringify(t.data),200)),e})()}}Ee([`input`,`keydown`,`click`]);var QS=(e,t)=>{let n=String(t??``).trim();return!n||/^\d+$/.test(n)?null:e?.[n]??null},$S=[{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)`}];function eC(e,t){return e?t===`dark`?{slot:`dark`,key:`teapot.theme.dark`}:{slot:`light`,key:`teapot.theme.light`}:{slot:`fixed`,key:`teapot.theme`}}var tC=F(`<div class=themeeditor><h4 class=cfgsub>your themes</h4><div class=btnrow><button type=button title="copy the theme you are using into a new editable one — presets themselves are never modified">+ duplicate current`),nC=F(`<div class=muted style="margin:6px 0">`),rC=F(`<b>+ duplicate current`),iC=F(`<div class=cfggrid style=margin-top:8px><label class=trow>appearance<select><option value=dark>dark</option><option value=light>light`),aC=F(`<div class=paletterows>`),oC=F(`<div class=btnrow><button type=button title="put every colour back to the palette this theme was created from">↺ reset palette</button><button type=button title="delete this custom theme">🗑 delete`),sC=F(`<h4 class=cfgsub>background image`),cC=F(`<img sizes=260px alt="current background"decoding=async loading=lazy>`,!0,!1,!1),lC=F(`<span class=bgpick-hint>🖼 replace…`),uC=F(`<div class=bgpreview><span class=muted title="this image is served from the server; the theme stores only its URL">✓ image set</span><div class=btnrow><label class=trow title="how much the image is dimmed so text stays readable">dim<input type=range min=0 max=0.9 step=0.05><span class="muted mono">%</span></label><label title="how much of the background shows through code blocks and tool cards — lower is more transparent">surfaces<input type=range min=0.35 max=1 step=0.01><span class="muted mono">%</span></label><button type=button>✕ remove`),dC=F(`<div class=cfggrid><button type=button></button><input type=file accept=image/* style=display:none>`),fC=F(`<div class=muted style=margin-top:6px;font-size:var(--text-xs)>the image is uploaded to the server and sits behind the panels, dimmed so text stays readable. No size limit — it is a file now, not browser storage.`),pC=F(`<label class=paletterow><input type=color><span class=paletterow-label></span><input class="mono paletterow-hex">`),mC=F(`<span class=bgpick-empty>🖼 choose a background image…`),hC=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.`),gC=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>`),_C=F(`<div class=skilllist>`),vC=F(`<span style=color:var(--err);font-size:13px>`),yC=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=cfgrow><label style=flex:1>API password<input type=password class=w100></label><span class=muted style=font-size:11.5px;max-width:34ch>bearer token for /api. empty = loopback only.</span></div><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</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 class=primarybtn>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>skills</legend></fieldset><fieldset><legend>help</legend><div class=helpsec><h4 class=cfgsub>this host</h4><div class=featgrid><div class=featrow><b>image downscaling</b><span class=muted></span></div><div class=featrow><b>terminal pty</b><span class=muted></span></div></div></div><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><span class=kbdgroup><kbd>↑</kbd><kbd>↓</kbd></span><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>`),bC=F(`<button type=button><span class=cfgmenu-label>`),xC=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`),SC=F(`<button type=button title="remove this key">−`),CC=F(`<div class=cfgkeyrow><input type=password>`),wC=F(`<button type=button>+ `),TC=F(`<option>`),EC=F(`<div class=cfgsub style=margin-bottom:var(--space-1)>`),DC=F(`<div class=themepick>`),OC=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label> ★`),kC=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label>`),AC=F(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),jC=F(`<input placeholder="command (e.g. npx)">`),MC=F(`<input placeholder="args, space separated">`),NC=F(`<input type=password placeholder="paste the token"title="sent as Authorization: Bearer <token>"style=flex:1>`),PC=F(`<input placeholder="header name"style="flex:0 1 150px">`),FC=F(`<input type=password placeholder=value style=flex:1>`),IC=F(`<div class=cfgrow><textarea class=mono rows=2 placeholder="{&quot;Authorization&quot;: &quot;Bearer …&quot;, &quot;X-Team&quot;: &quot;infra&quot;}"title="static headers for every request. Use the bearer option unless the server needs something unusual."style=flex:1>`),LC=F(`<button type=button class=mcpauthorize title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),RC=F(`<span class="mcpstate connected"title="an OAuth access token is usable — disconnect it under the server's details">🔑 authorized`),zC=F(`<span>`),BC=F(`<div class=muted style=font-size:11px;color:var(--warn)>`),VC=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><input placeholder="what this server is for — e.g. reverse engineering: decompile, disassemble"title="shown to the model when the MCP catalog is too large to send, so it can search for the right tool instead of guessing keywords"></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><select title="how this server authenticates"><option value=none>no auth</option><option value=bearer>bearer token</option><option value=header>custom header</option><option value=json>headers as JSON (advanced)</option></select></div><div class=cfgrow><button type=button title="connect now and list the tools — nothing is saved">test`),HC=F(`<option value=oauth selected>`),UC=F(`<span class=muted> · needs a grant (🔑 authorize)`),WC=F(`<details class=mcptools-wrap><summary>show <!> tool</summary><ul class=mcptools>`),GC=F(`<div class=mcpdanger><span class=muted>OAuth grant</span><button type=button class=mcpdisconnect title="forget the stored grant (the refresh token is deleted, so authorizing again needs a browser)">disconnect`),KC=F(`<div><div class=mcpresult-head><b>`),qC=F(`<span class=mcptool-desc>`),JC=F(`<li><code class=mono>`),YC=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">`),XC=F(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),ZC=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`),QC=F(`<span class=muted>🧩 sub of @`),$C=F(`<div class=cfgrow><b></b><span class=muted>`),ew=F(`<div class=muted>`),tw=F(`<div class=skillbody>`),nw=F(`<div class=skillrow><button type=button class=skillhead title="show the playbook"><span class=skillcaret></span><b class=mono></b><span class=muted>`),rw=F(`<div class="muted skillbody">`);function iw(e){let[t,n]=y(e.themes().some(t=>t.id===e.activeId)?e.activeId:e.themes()[0]?.id??``),r=()=>z(e.themes(),e.activeId,t()),[i,a]=y({}),o,s=t=>{let n=r()?.id;if(!n)return;let i=e.themes().map(e=>e.id===n?t(e):e);e.onChange(i)},c=(e,t)=>{let n=Kn(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.paintedId),r=Md.find(t=>t.key===e.paintedId),i=t??r??Md[0],a=getComputedStyle(document.documentElement),o={...In};for(let{key:e,cssVar:t}of Pn){let n=Kn(a.getPropertyValue(t));n&&(o[e]=n)}let s=Un(e.themes().map(e=>e.id).concat(Md.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,surfaceAlpha:t.surfaceAlpha}:{}};e.onChange([...e.themes(),c]),n(s),e.onPick(s)},u=async t=>{if(t){if(!/^image\//.test(t.type))nf(`that file is ${JSON.stringify(t.type||`unknown`)} — pick an image`);else{nf(`uploading ${t.name} (${Math.round(t.size/1024)}KB)…`);try{let n=await fetch(`/api/assets`,{method:`POST`,headers:{"content-type":t.type},body:t}).then(async e=>({ok:e.ok,body:await e.json().catch(()=>null)}));if(!n.ok||!n.body?.url){nf(n.body?.error??`upload failed`);return}s(e=>({...e,backgroundImage:n.body.url,backgroundImageBytes:n.body.bytes}));let i=r()?.id;i&&e.onPick(i),nf(`background image set`)}catch(e){nf(`upload failed: ${e.message}`)}}}};return(()=>{var t=tC(),d=t.firstChild.nextSibling.firstChild;return d.$$click=l,R(t,j(N,{get when(){return P(()=>!!(r()&&e.themes().some(t=>t.id===e.activeId)))()?r():null},get fallback(){return(()=>{var t=nC();return R(t,(()=>{var t=P(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,rC(),` to start from the palette you are using.`]:[`the editor shows when one of your themes is ACTIVE — pick one under "your themes" above (or press `,rC(),`).`]})()),t})()},children:t=>[(()=>{var e=iC(),t=e.firstChild.firstChild.nextSibling;return t.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),b(()=>t.value=r().mode),e})(),(()=>{var e=aC();return R(e,j(M,{each:Pn,children:e=>(()=>{var t=pC(),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),b(()=>I(t,`title`,e.cssVar)),b(()=>n.value=Kn(r().palette[e.key])??`#000000`),b(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=oC(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...In}})),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})(),sC(),(()=>{var e=dC(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),R(t,j(N,{get when(){return r().backgroundImage},get fallback(){return mC()},get children(){return[(()=>{var e=cC();return b(t=>{var n=Zt(r().backgroundImage),i=Xt(r().backgroundImage);return n!==t.e&&I(e,`src`,t.e=n),i!==t.t&&I(e,`srcset`,t.t=i),t},{e:void 0,t:void 0}),e})(),lC()]}})),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`?Ae(i,n):o=n,R(e,j(N,{get when(){return r().backgroundImage},get children(){var e=uC(),t=e.firstChild;t.firstChild;var n=t.nextSibling.firstChild,i=n.firstChild.nextSibling,a=i.nextSibling,o=a.firstChild,c=n.nextSibling,l=c.firstChild.nextSibling,u=l.nextSibling,d=u.firstChild,f=c.nextSibling;return R(t,()=>{let e=r()?.backgroundImageBytes;return e?` — ${Math.max(1,Math.round(e/1024))} KB`:``},null),i.$$input=e=>s(t=>({...t,backgroundDim:Number(e.currentTarget.value)})),R(a,()=>Math.round((r().backgroundDim??.55)*100),o),l.$$input=e=>s(t=>({...t,surfaceAlpha:Number(e.currentTarget.value)})),R(u,()=>Math.round((r().surfaceAlpha??.82)*100),d),f.$$click=()=>s(e=>({...e,backgroundImage:void 0})),b(()=>i.value=r().backgroundDim??.55),b(()=>l.value=r().surfaceAlpha??.82),e}}),null),b(e=>{var n=`bgpick`+(r().backgroundImage?` has`:``),i=r().backgroundImage?`click to replace this background image (PNG/JPG/WebP)`:`choose a background image (PNG/JPG/WebP)`;return n!==e.e&&L(t,e.e=n),i!==e.t&&I(t,`title`,e.t=i),e},{e:void 0,t:void 0}),e})(),fC()]}),null),t})()}function aw(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]=y(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=y(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]=y(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=y(e.cfg.progressMinChars??4e3),[p,m]=y(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=y(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,v]=y(e.cfg.maxSpawnDepth??3),[ee,S]=y(!!e.cfg.shortContext),[C,w]=y(``),[T,E]=y(!1),[te,D]=y((e.cfg.tasks??[]).map(e=>({...e}))),[O,ne]=y((e.cfg.mcpServers??[]).map(e=>({...e}))),[re,k]=y(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ie,ae]=y({}),[oe,se]=y(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=e.headers??{},r=Object.keys(n);if(!r.length)return[t,`none`];let i=r.length===1?r[0]:``;return i===`Authorization`&&/^Bearer /i.test(n[i]??``)?[t,`bearer`]:[t,r.length===1?`header`:`json`]}))),[ce,le]=y(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=e.headers??{},r=Object.keys(n);if(r.length!==1)return[t,``];let i=r[0];return[t,i===`Authorization`?(n[i]??``).replace(/^Bearer /i,``):n[i]??``]}))),[ue,de]=y(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=Object.keys(e.headers??{}),r=n.length===1?n[0]:``;return[t,r&&r!==`Authorization`?r:``]}))),[fe,A]=y({}),pe={},me=async(e,t)=>{if(!O()[e])return;let n=await Y(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}).catch(()=>null);O()[e]&&n&&A(t=>({...t,[e]:n.ok?{kind:`ok`,text:`${n.tools?.length??0} tools`}:{kind:`err`,text:n.needsOAuth?`needs authorization — press 🔑`:n.error??`no response`,...n.needsOAuth?{needsOAuth:!0}:{}}}))},[he,ge]=y({}),[_e,ve]=y({}),ye=e=>{let t=QS(_e(),e);return t&&(t.required||t.authorized)?t:null},be=async()=>{let e=await Y(`/api/mcp`).catch(()=>null);ge(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},xe=async e=>{let t=String(e??``).trim();if(!t)return;let n=await Y(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&ve(e=>({...e,[t]:n}))},Ce=async(t,n)=>{if(!n.name){A(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}A(e=>({...e,[t]:{kind:`testing`,text:`discovering the authorization server…`}}));let r=await Y(`/api/mcp/oauth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name,url:n.url})}).catch(()=>null);if(r?.alreadyAuthorized){A(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await xe(n.name),await be();return}if(!r?.ok||!r.url){A(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await xe(n.name);return}window.open(r.url,`_blank`,`noopener`),A(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 Y(`/api/mcp/oauth/status?name=${encodeURIComponent(n.name)}`).catch(()=>null);if(r&&!r.error){if(ve(e=>({...e,[n.name]:r})),r.authorized){A(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await be(),e.onSaved();return}if(r.flow?.phase===`error`){A(e=>({...e,[t]:{kind:`err`,text:r.flow.message??r.lastError??`authorization failed`}}));return}}}A(e=>({...e,[t]:{kind:`err`,text:`authorization timed out`}}))};x(()=>{F()===`mcp`&&(be(),O().forEach((e,t)=>{e.name&&xe(e.name)}))});let[we,Te]=y(``),[F,Ee]=y(`providers`),De=(t,n)=>{let{slot:r}=eC(e.theme.auto(),n);r===`dark`?Ge(t):r===`light`?qe(t):Ve(t)},Oe=t=>e.theme.auto()?t===e.theme.dark()||t===e.theme.light():t===e.theme.activeId(),[ke,Ae]=y([]),je=async()=>{let e=await Y(`/api/archived`).catch(()=>null);Ae(e?.agents??[])},Me=()=>ke().filter(e=>!e.parent);x(()=>{F()===`archive`&&je()});let Ne=[{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:`skills`,label:`🧠 skills`,hint:`reusable playbooks available to the selected session`},{key:`help`,label:`❔️ help`,hint:`keyboard shortcuts and what each toggle does`}],Pe=()=>(e.cfg.agents??[]).map(e=>e.id),Fe=()=>e.theme.themes(),Ie=()=>e.theme.activeId(),Le={auto:localStorage.getItem(`teapot.theme.auto`)===`1`,dark:localStorage.getItem(`teapot.theme.dark`)??`dark`,light:localStorage.getItem(`teapot.theme.light`)??`light`,fixed:localStorage.getItem(`teapot.theme`)??`dark`},Re=y(Le),ze=Re[0],Be=t=>{let n={...ze(),...t};Re[1](n),e.theme.setAuto(n.auto),e.theme.setDark(n.dark),e.theme.setLight(n.light),e.theme.setActive(n.fixed);let r=t.dark??t.light??t.fixed;r&&e.theme.preview(r)},Ve=e=>Be({fixed:e}),He=()=>ze().auto,Ue=e=>Be({auto:e}),We=()=>ze().dark,Ge=e=>Be({dark:e}),Ke=()=>ze().light,qe=e=>Be({light:e}),Je=t=>e.theme.setThemes(t),Ye=()=>{let t=Le;e.theme.setAuto(t.auto),e.theme.setDark(t.dark),e.theme.setLight(t.light),e.theme.setActive(t.fixed),e.theme.preview(null)},Xe=e=>Ln[e]??In,Ze=()=>{let e={};for(let t of n()){if(!t.name.trim())return Te(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return Te(`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},[Qe,$e]=y(`idle`),et=e=>{Te(e),$e(e=>e===`saving`?`idle`:e)},tt=async t=>{t.preventDefault(),Te(``),$e(`saving`);let n=Ze();if(!n)return $e(`idle`);let r=te().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)return et(`task "${e.id}": agent is required`);if(!e.schedule?.trim())return et(`task "${e.id}": schedule is required`)}let a=[],o=new Set;for(let e of O()){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)return et(`MCP: a server needs a name`);if(o.has(t))return et(`MCP: two servers are named "${t}"`);if(o.add(t),r===`stdio`?!i:!n)return et(`MCP "${t}": ${r===`stdio`?`a command is`:`a url is`} required`);a.push({name:t,transport:r,enabled:e.enabled!==!1,...String(e.description??``).trim()?{description:String(e.description).trim()}:{},...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 Y(`/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:ee(),...T()?{password:C()}:{},tasks:r,mcpServers:a})}),await be(),await Promise.all(a.map((e,t)=>e.name?xe(e.name):Promise.resolve())),setTimeout(()=>{be(),a.forEach((e,t)=>{e.name&&xe(e.name)})},1200),e.onSaved();let t=new Set(a.map(e=>e.name).filter(Boolean)),o=O().filter(e=>{let n=String(e.name??``).trim();return t.has(n)&&_e()[n]?.required&&!_e()[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??``));nf(`${o.map(e=>String(e.name??``).trim()).filter(Boolean).join(`, `)||`a saved MCP server`} needs authorization — 🔑 authorize in MCP servers`)}e.theme.commitAppearance(ze()),e.theme.preview(null),$e(`saved`),Object.assign(Le,ze()),setTimeout(()=>{$e(`idle`),e.onClose()},400)}catch(e){Te(e.message),$e(`error`),setTimeout(()=>$e(`idle`),1600)}};return j(rd,{title:`settings`,onClose:()=>{Ye(),e.onClose()},get children(){var t=yC(),x=t.firstChild,T=x.firstChild,ge=T.nextSibling.firstChild,ve=ge.firstChild.nextSibling,be=ve.nextSibling;be.firstChild;var ke=be.nextSibling.firstChild.firstChild.nextSibling;ke.firstChild;var Ae=ge.nextSibling,Le=Ae.firstChild.nextSibling,Re=Le.firstChild.firstChild.nextSibling,ze=Le.nextSibling,Be=Ae.nextSibling,Ye=Be.firstChild.nextSibling,Ze=Ye.firstChild.firstChild.nextSibling,$e=Ye.nextSibling,et=$e.firstChild,nt=et.firstChild.nextSibling,it=$e.nextSibling.firstChild,at=Be.nextSibling,st=at.firstChild.nextSibling.nextSibling,ct=at.nextSibling,lt=ct.firstChild.nextSibling,ut=ct.nextSibling;ut.firstChild;var dt=ut.nextSibling;dt.firstChild;var ft=dt.nextSibling,pt=ft.firstChild.nextSibling.firstChild;pt.firstChild;var mt=pt.nextSibling,ht=ft.nextSibling;ht.firstChild;var gt=ht.nextSibling,_t=gt.firstChild.nextSibling.firstChild.nextSibling.firstChild,vt=_t.firstChild.nextSibling,yt=_t.nextSibling.firstChild.nextSibling,bt=x.nextSibling,xt=bt.firstChild;return t.addEventListener(`submit`,tt),R(T,j(M,{each:Ne,children:e=>(()=>{var t=bC(),n=t.firstChild;return t.$$click=()=>Ee(e.key),R(n,()=>e.label),b(n=>{var r=`cfgmenu-item`+(F()===e.key?` on`:``),i=e.hint,a=F()===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(ge,j(Se,{get each(){return n()},children:(e,t)=>(()=>{var i=xC(),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=CC(),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=SC();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),b(()=>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)),b(()=>a.value=e().name),b(()=>o.value=e().baseUrl),b(()=>s.value=e().model),i})()}),ve),ve.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),R(be,j(M,{each:$S,children:e=>(()=>{var t=wC();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),b(()=>I(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),ke.addEventListener(`change`,e=>a(e.currentTarget.value)),R(ke,j(M,{get each(){return s()},children:e=>(()=>{var t=TC();return t.value=e,R(t,e),t})()}),null),R(ge,j(N,{get when(){return c()},get children(){var e=hC(),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),Re.addEventListener(`change`,e=>{Ue(e.currentTarget.checked)}),R(Ae,j(N,{get when(){return He()},get children(){var e=gC(),t=e.firstChild,n=t.firstChild.nextSibling,r=t.nextSibling.firstChild.nextSibling;return n.addEventListener(`change`,e=>{Ge(e.currentTarget.value)}),R(n,j(M,{get each(){return Fe().filter(e=>e.mode===`dark`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(Md.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=TC();return R(t,()=>e.label),b(()=>t.value=e.key),t})()})),r.addEventListener(`change`,e=>{qe(e.currentTarget.value)}),R(r,j(M,{get each(){return Fe().filter(e=>e.mode===`light`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(Md.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=TC();return R(t,()=>e.label),b(()=>t.value=e.key),t})()})),b(()=>n.value=We()),b(()=>r.value=Ke()),e}}),ze),R(Ae,j(M,{each:[{mode:`dark`,title:`dark themes`},{mode:`light`,title:`light themes`}],children:e=>j(N,{get when(){return[...Fe(),...Md].some(t=>t.mode===e.mode)},get children(){return[(()=>{var t=EC();return R(t,()=>e.title),t})(),(()=>{var t=DC();return R(t,j(M,{get each(){return Fe().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=OC(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>De(e.id,e.mode),R(n,j(Qd,{get palette(){return e.palette},get backgroundImage(){return e.backgroundImage},get surfaceAlpha(){return e.surfaceAlpha},get backgroundDim(){return e.backgroundDim}})),R(r,()=>e.label,i),b(n=>{var r=`themecard`+(Oe(e.id)?` on`:``),i=`${e.label} (custom)${e.backgroundImage?` · with a background image`:``}`,a=Oe(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 Md.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=kC(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>De(e.key,e.mode),R(n,j(Qd,{get palette(){return Xe(e.key)}})),R(r,()=>e.label),b(n=>{var r=`themecard`+(Oe(e.key)?` on`:``),i=`${e.label} (${e.mode})`,a=Oe(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(Ae,j(iw,{themes:Fe,get activeId(){return Ie()},get paintedId(){return e.theme.paintedId()},onChange:e=>{let t=Vn(e),n=e;if(!t.ok){let t=e.map(e=>e.backgroundImage?{...e,backgroundImage:void 0,backgroundDim:void 0,surfaceAlpha:void 0,backgroundImageBytes:void 0}:e),r=Vn(t);if(r.ok)n=t,nf(`storage was full — saved without the background image(s)`);else{nf(r.error??`could not save theme`);return}}Je(n);let r=e=>n.some(t=>t.id===e)||Md.some(t=>t.key===e);r(Ie())||(Ve(`dark`),localStorage.setItem(`teapot.theme`,`dark`)),r(We())||(Ge(`dark`),localStorage.setItem(`teapot.theme.dark`,`dark`)),r(Ke())||(qe(`light`),localStorage.setItem(`teapot.theme.light`,`light`))},onPick:e=>{let t=Fe().find(t=>t.id===e)?.mode??Md.find(t=>t.key===e)?.mode??`dark`,n=eC(He(),t);n.slot===`dark`?Ge(e):n.slot===`light`?qe(e):Ve(e)}}),null),Ze.$$input=e=>{w(e.currentTarget.value),E(!0)},R($e,j(Zd,{label:`progress interval (min)`,get value(){return l()},onValue:e=>u(e),hint:`how often the harness asks for a progress report`}),et),R($e,j(Zd,{label:`progress min chars`,get value(){return d()},onValue:e=>f(e),hint:`progress prompts wait for this much real output`}),et),nt.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),R($e,j(Zd,{label:`context window (k tok)`,get value(){return h()},onValue:e=>g(e),hint:`model's real window — 0/blank hides the % gauge`}),null),R($e,j(Zd,{label:`max spawn depth`,get value(){return _()},onValue:e=>v(e),hint:`sub-agent nesting limit (0 = no spawning)`}),null),it.addEventListener(`change`,e=>S(e.currentTarget.checked)),R(at,j(N,{get when(){return O().length>0},get fallback(){return AC()},get children(){return j(Se,{get each(){return O()},children:(e,t)=>{let n=()=>he()[e().name],r=e=>ne(O().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=VC(),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=p.nextSibling,g=h.firstChild,_=g.firstChild,v=h.nextSibling,ee=v.firstChild;return o.$$input=e=>r({name:e.currentTarget.value}),s.$$input=e=>{r({url:e.currentTarget.value});let n=e.currentTarget.value.trim();clearTimeout(pe[t]),/^https?:\/\//.test(n)&&(pe[t]=setTimeout(()=>{me(t,{...O()[t],url:n})},700))},l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>ne(O().filter((e,n)=>n!==t)),f.$$input=e=>r({description:e.currentTarget.value}),m.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),R(p,j(N,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=jC();return t.$$input=e=>r({command:e.currentTarget.value}),b(()=>t.value=e().command??``),t})(),(()=>{var t=MC();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),b(()=>t.value=(e().args??[]).join(` `)),t})()]}}),null),g.addEventListener(`change`,e=>{let n=e.currentTarget.value;if(se(e=>({...e,[t]:n})),n===`none`)r({headers:void 0});else if(n===`bearer`){let e=ce()[t]??``;r({headers:e?{Authorization:`Bearer ${e}`}:void 0})}else if(n===`header`){let e=ue()[t]??``,n=ce()[t]??``;r({headers:e&&n?{[e]:n}:void 0})}}),R(g,j(N,{get when(){return ye(String(e().name??``))},children:e=>(()=>{var t=HC();return R(t,()=>e().authorized?`OAuth — authorized`:`OAuth — authorization needed`),t})()}),_),R(h,j(N,{get when(){return oe()[t]===`bearer`},get children(){var e=NC();return e.$$input=e=>{let n=e.currentTarget.value;le(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},b(()=>e.value=ce()[t]??``),e}}),null),R(h,j(N,{get when(){return oe()[t]===`header`},get children(){return[(()=>{var e=PC();return e.$$input=e=>{let n=e.currentTarget.value;de(e=>({...e,[t]:n}));let i=ce()[t]??``;r({headers:n&&i?{[n]:i}:void 0})},b(()=>e.value=ue()[t]??``),e})(),(()=>{var e=FC();return e.$$input=e=>{let n=e.currentTarget.value;le(e=>({...e,[t]:n}));let i=ue()[t]??``;r({headers:i&&n?{[i]:n}:void 0})},b(()=>e.value=ce()[t]??``),e})()]}}),null),R(i,j(N,{get when(){return oe()[t]===`json`},get children(){var e=IC(),n=e.firstChild;return n.$$input=e=>{let n=e.currentTarget.value;if(k(e=>({...e,[t]:n})),!n.trim())r({headers:void 0});else try{let e=JSON.parse(n);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`not an object`);r({headers:e}),ae(e=>({...e,[t]:``}))}catch{ae(e=>({...e,[t]:`must be a JSON object — not applied`}))}},b(()=>n.value=re()[t]??``),e}}),v),ee.$$click=async()=>{let e=O()[t];if(!e.name){A(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}A(e=>({...e,[t]:{kind:`testing`,text:`connecting…`}}));let n=await Y(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}).catch(()=>null);A(e=>({...e,[t]:n?.ok?{kind:`ok`,text:`${n.tools?.length??0} tool${n.tools?.length===1?``:`s`}`,tools:n.tools??[]}:{kind:`err`,text:n?.error??`no response`,...n?.needsOAuth?{needsOAuth:!0}:{}}})),n?.ok||await xe(e.name)},R(v,j(N,{get when(){return P(()=>!!QS(_e(),String(e().name??``))?.required)()&&!QS(_e(),String(e().name??``))?.authorized},get children(){var n=LC();return n.$$click=()=>void Ce(t,e()),n}}),null),R(v,j(N,{get when(){return QS(_e(),String(e().name??``))?.authorized},get children(){return RC()}}),null),R(v,j(N,{get when(){return n()},get children(){var e=zC();return R(e,(()=>{var e=P(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:P(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),b(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 ie()[t]},get children(){var e=BC();return R(e,()=>ie()[t]),e}}),null),R(i,j(N,{get when(){return fe()[t]},children:n=>(()=>{var r=KC(),i=r.firstChild,a=i.firstChild;return R(a,()=>n().text),R(i,j(N,{get when(){return n().needsOAuth},get children(){return UC()}}),null),R(r,j(N,{get when(){return(n().tools?.length??0)>0},get children(){var e=WC(),t=e.firstChild,r=t.firstChild.nextSibling;r.nextSibling;var i=t.nextSibling;return R(t,()=>n().tools?.length,r),R(t,()=>n().tools?.length===1?``:`s`,null),R(i,j(M,{get each(){return n().tools??[]},children:e=>(()=>{var t=JC(),n=t.firstChild;return R(n,()=>e.name),R(t,j(N,{get when(){return e.description},get children(){var t=qC();return R(t,()=>e.description),t}}),null),b(()=>I(t,`title`,e.description??``)),t})()})),e}}),null),R(r,j(N,{get when(){return QS(_e(),String(e().name??``))?.authorized},get children(){var n=GC(),r=n.firstChild.nextSibling;return r.$$click=async()=>{confirm(`Disconnect ${e().name}?\n\nThe stored OAuth grant is deleted and you will have to authorize again in a browser.`)&&(await Y(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await xe(e().name),A(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}})))},n}}),null),b(()=>L(r,`mcpresult `+(n().kind===`err`?`err`:`ok`))),r})()}),null),b(()=>o.value=e().name),b(()=>s.value=e().url??``),b(()=>l.checked=e().enabled!==!1),b(()=>f.value=e().description??``),b(()=>m.value=e().transport??`http`),b(()=>g.value=ye(String(e().name??``))?`oauth`:oe()[t]??`none`),i})()}})}}),st),st.$$click=()=>ne([...O(),{name:``,url:``,transport:`http`,enabled:!0}]),R(ct,j(N,{get when(){return te().length>0},get children(){return j(Se,{get each(){return te()},children:(e,t)=>(()=>{var n=YC(),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=>D(te().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>D(te().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>D(te().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>D(te().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>D(te().filter((e,n)=>n!==t)),u.$$input=e=>D(te().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),b(()=>i.value=e().id),b(()=>a.value=e().agent),b(()=>o.value=e().schedule),b(()=>c.checked=!!e().forked),b(()=>u.value=e().prompt),n})()})}}),lt),lt.$$click=()=>D([...te(),{id:``,agent:Pe()[0]??``,schedule:`every 30m`,prompt:``}]),R(ut,j(N,{get when(){return Me().length>0},get fallback(){return XC()},get children(){return j(M,{get each(){return Me()},children:t=>(()=>{var n=ZC(),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 ${ot(new Date(t.archivedAt).toISOString())}`:``})(),null),R(s,()=>t.workspace),c.$$click=async()=>{let n=await Y(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await je(),e.onSaved();let r=(n?.ids?.length??1)-1;nf((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 Y(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await je(),e.onSaved(),nf(`deleted ${t.id} for good`))},b(()=>I(s,`title`,t.workspace)),n})()})}}),null),R(dt,j(M,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=$C(),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=QC();return t.firstChild,R(t,()=>e.parent,null),t}}),null),t})()}),null),R(pt,()=>e.cfg.version??`unknown`,null),mt.$$click=async e=>{try{Te(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await Y(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=null,i=!1;for(let e=0;e<120&&!i;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await Y(`/api/version`);if(!e.version)continue;r===null&&(r=e.uptimeSeconds??null),(e.version!==`0.37.96`||typeof e.uptimeSeconds==`number`&&r!==null&&e.uptimeSeconds<r)&&(i=!0,window.location.reload())}catch{}}if(!i)throw Error(`restart timeout — new server did not come up`)}catch(e){Te(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},R(ht,j(N,{get when(){return e.skills.length>0},get fallback(){return(()=>{var t=ew();return R(t,()=>e.hasSelection?`this session has no skills yet — the agent saves them with save_skill once a procedure proves itself`:`select a session to see the skills available to it`),t})()},get children(){var t=_C();return R(t,j(M,{get each(){return e.skills},children:t=>{let[n,r]=y(!1),[i,a]=y(null),[o,s]=y(``),c=async()=>{if(n())return r(!1);if(r(!0),i()===null&&e.agentId)try{let n=await Y(`/api/agents/${e.agentId}/skills/${encodeURIComponent(t.name)}`);a(String(n.text??``))}catch(e){s(e.message)}};return(()=>{var e=nw(),r=e.firstChild,a=r.firstChild,s=a.nextSibling,l=s.nextSibling;return r.$$click=c,R(a,()=>n()?`▾`:`▸`),R(s,()=>t.name),R(l,()=>t.description),R(e,j(N,{get when(){return n()},get children(){return j(N,{get when(){return i()!==null},get fallback(){return(()=>{var e=rw();return R(e,()=>o()||`loading…`),e})()},get children(){var e=tw();return b(()=>e.innerHTML=rt(String(i()??``))),e}})}}),null),b(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),R(vt,(()=>{var t=P(()=>!!e.features);return()=>t()?P(()=>!!e.features.imageResize.available)()?`on — ${e.features.imageResize.tool}, long edge ≤ ${e.features.imageResize.maxEdge}px`:`off — no ffmpeg / ImageMagick found; uploads are served as-is`:`checking…`})()),R(yt,(()=>{var t=P(()=>!!e.features);return()=>t()?P(()=>!!e.features.pty.available)()?`on — ${e.features.pty.provider}`:`off — no pty provider; terminals run on plain pipes (no resize)`:`checking…`})()),R(bt,j(N,{get when(){return we()},get children(){var e=vC();return R(e,we),e}}),xt),R(xt,(()=>{var e=P(()=>Qe()===`saving`);return()=>e()?`saving…`:P(()=>Qe()===`saved`)()?`✓ saved`:Qe()===`error`?`✕ failed`:`save settings`})()),b(t=>{var n=F()!==`providers`,r=F()!==`appearance`,i=F()!==`runtime`,a=e.cfg.hasPassword?`(unchanged — type to replace)`:`(none — loopback only)`,o=F()!==`mcp`,s=F()!==`tasks`,c=F()!==`archive`,l=F()!==`agents`,u=F()!==`update`,d=F()!==`skills`,f=F()!==`help`,p=Qe()===`saved`,m=Qe()===`error`,h=Qe()===`saving`;return n!==t.e&&ge.classList.toggle(`hide`,t.e=n),r!==t.t&&Ae.classList.toggle(`hide`,t.t=r),i!==t.a&&Be.classList.toggle(`hide`,t.a=i),a!==t.o&&I(Ze,`placeholder`,t.o=a),o!==t.i&&at.classList.toggle(`hide`,t.i=o),s!==t.n&&ct.classList.toggle(`hide`,t.n=s),c!==t.s&&ut.classList.toggle(`hide`,t.s=c),l!==t.h&&dt.classList.toggle(`hide`,t.h=l),u!==t.r&&ft.classList.toggle(`hide`,t.r=u),d!==t.d&&ht.classList.toggle(`hide`,t.d=d),f!==t.l&&gt.classList.toggle(`hide`,t.l=f),p!==t.u&&xt.classList.toggle(`saved`,t.u=p),m!==t.c&&xt.classList.toggle(`error`,t.c=m),h!==t.w&&(xt.disabled=t.w=h),t},{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,c:void 0,w:void 0}),b(()=>ke.value=i()),b(()=>Re.checked=He()),b(()=>Ze.value=C()),b(()=>nt.value=p()??``),b(()=>it.checked=ee()),t}})}Ee([`click`,`input`]);var ow=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),sw=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),cw=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function lw(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=uw(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 uw(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return ow.has(t)?`image`:sw.has(t)?`video`:cw.has(t)?`audio`:null}var dw=new Map,fw=e=>{let t=dw.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},dw.set(e,t)),t},pw=F(`<span class=fsize>`),mw=F(`<div><span class=ficon></span><span class=fname>`),hw=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>· `),gw=F(`<div class=filebox>`),_w=F(`<div class=muted style=padding:6px>`),vw=F(`<img>`),yw=F(`<div class=mediapreview><div class="meta muted"> preview`),bw=F(`<button title="rendered markdown">👁 preview`),xw=F(`<button title="edit and save back to the workspace">✎ edit`),Sw=F(`<div class=filetoolbar><button title="syntax-highlighted source">&lt;/> code`),Cw=F(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),ww=F(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Tw=F(`<div class="content mdpreview shikiwrap">`),Ew=F(`<video controls>`),Dw=F(`<audio controls>`);function Ow(e){let t=fw(e.agentId),[n,r]=y(new Map),[i,a]=y(t.expanded),[o,s]=y(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=y(t.media),f=e=>{t.media=e,d(e)},[p,m]=y(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=y(``),[v,ee]=y(localStorage.getItem(`teapot.ignoreMode`)??`dim`),S=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(v())+1)%3];ee(t),localStorage.setItem(`teapot.ignoreMode`,t)},C=e=>v()!==`hide`||!e.ignored,[w,E]=y(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!w(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await ne(t,e)}))).then(t=>{E(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&re(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 O(e){return ne(e,w())}async function ne(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await Y(`/api/agents/${e.agentId}/tree?${r.toString()}`);return D(t,i.entries??[])}catch(e){return _(e.message),null}}let re=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=new Map(i.map(e=>[e.path,e])),o=n.map(e=>{let t=a.get(e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?t:e}).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=``;x(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),O(``).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 O(e.path);t&&re(e.path,t)}},[ae,oe]=y(``),[se,ce]=y(!1),[le,ue]=y(``),[de,fe]=y(!1),A=e=>/\.(md|markdown|mdx)$/i.test(e),pe=0,me=async e=>{let t=++pe;oe(``),ce(!0);try{let{highlightChunks:n}=await J(async()=>{let{highlightChunks:e}=await Promise.resolve().then(()=>Xb);return{highlightChunks:e}},void 0);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)}};T(()=>{pe++});let he=async(t,n)=>{let r=uw(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await Y(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),ue(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&me({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){nf(`open failed: ${e.message}`)}},ge=async()=>{let t=o();if(t&&!de()){fe(!0);try{await Y(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:le(),baseContent:t.content})}),c({...t,content:le()}),nf(`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?nf(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
180
+ `)[0]??``,140),null),R(e,()=>i().data?.ok===!1?` · FAILED`:``,null),e})():Kx())];break}case`list_dir`:e=l(`path`)||`.`,n=m();break;case`read_url`:{let r=l(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=Sx(r,70),t=`web`,n=[(()=>{var e=Fx();return R(e,j(N,{get when(){return/^https?:/i.test(l(`url`))},get fallback(){return(()=>{var e=Jx();return R(e,()=>Sx(l(`url`),80)),e})()},get children(){var e=qx();return b(()=>I(e,`href`,l(`url`))),e}})),e})(),P(m)];break}case`bash_output`:{let r=l(`action`)||`read`;e=`bash_output ${l(`job_id`)||`(?)`}`,t=r,n=m();break}case`load_skill`:{e=`skill: ${l(`name`)}`;let t=c().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);n=i()?[(()=>{var e=Yx();return b(()=>e.innerHTML=Re(t)),e})(),(()=>{var e=Fx();return R(e,()=>it(i().data?.durationMs)),e})()]:Xx();break}case`save_skill`:{e=`skill: ${l(`name`)}`,t=Sx(l(`description`),60);let r=Array.isArray(o.args?.files)?o.args.files.map(e=>e?.name).filter(Boolean):[];n=[P(()=>P(()=>!!r.length)()?(()=>{var e=Zx();return e.firstChild,R(e,()=>r.join(`, `),null),e})():null),P(()=>P(()=>!!i())()?(()=>{var e=Hx(),t=e.firstChild;return R(e,()=>Sx(c(),160),t),R(e,()=>it(i().data?.durationMs),null),e})():Qx())];break}case`search_tools`:{e=`🔎 ${Sx(l(`query`)||`(browse)`,60)}`;let r=(()=>{try{let e=JSON.parse(c());return{names:(e.tools??[]).map(e=>`${e.server??`?`}/${e.name??`?`}`),total:e.totalMatches??0}}catch{return{names:[],total:0}}})();t=i()?`${r.total} match${r.total===1?``:`es`}`:null,n=[P(p),P(()=>P(()=>!!i())()?P(()=>!!r.names.length)()?(()=>{var e=$x();return e.firstChild,R(e,()=>r.names.join(`, `),null),e})():eS():null),P(m)];break}case`run_tool`:{let a=px(l(`tool_id`)),s=a?.indexOf(`/`)??-1;a&&s>0?r(a.slice(0,s),a.slice(s+1),o.args?.arguments):(e=a||`(no tool_id)`,t=i()?it(i().data?.durationMs):null,n=[P(p),P(m)]);break}default:{let a=/^mcp__([^_]+(?:_[^_]+)*)__(.+)$/.exec(s);if(a){r(a[1],a[2],o.args);break}e=s,t=i()?it(i().data?.durationMs):null,n=[P(p),P(m)];break}}}catch{}return{label:e,hint:t,body:n,key:`${i()?.id??`none`}|${e}|${t??``}`}},void 0,{equals:(e,t)=>e.key===t.key});return(()=>{var r=nS(),o=r.firstChild,l=o.firstChild,f=l.nextSibling,p=f.nextSibling;return r.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),R(l,()=>h().label),R(o,j(N,{get when(){return t.data?.actor},get children(){var e=tS();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),f),R(f,(()=>{var e=P(()=>!!i());return()=>e()?h().hint||``:P(()=>!!a())()?`(result missed)`:P(()=>!!(s===`bash`||d()))()?j(Od,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return d()}}):`running…`})()),R(p,j(nd,{get text(){return u()},label:`⧉ cmd`,title:`copy the ${s} arguments`}),null),R(p,j(N,{get when(){return i()},get children(){return j(nd,{get text(){return P(()=>!!dd(c()))()?ud(c()):c()},label:`⧉ out`,title:`copy this tool's full output (escapes removed)`})}}),null),R(r,()=>h().body,null),b(e=>{var t=`embed`+(n?` grouped`:``)+(i()?i().data?.ok===!1?` fail`:` done`:a()?` done`:` running`),o=`${s}${h().hint?` — `+h().hint:``}`;return t!==e.e&&L(r,e.e=t),o!==e.t&&I(r,`title`,e.t=o),e},{e:void 0,t:void 0}),r})()}function JS(e){let t;return x(()=>{e.html,queueMicrotask(()=>dx(t))}),(()=>{var n=Yx(),r=t;return typeof r==`function`?Ae(r,n):t=n,b(()=>n.innerHTML=e.html),n})()}function YS(e){let t=e.e,n=vx(t),r=()=>Tx(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Tx(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=rS(),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=zt(t.data??{});return(()=>{var t=iS(),n=t.firstChild;return R(n,()=>e.label),R(t,j(N,{get when(){return e.hasCard},get children(){return j(Wt,{get tone(){return P(()=>e.tone===`ok`)()?`ok`:e.tone===`warn`?`warn`:`tool`},get markdown(){return e.markdown},get body(){return e.detail}})}}),null),b(()=>L(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`audit_step`){let e=String(t.data?.step??``),n=String(t.data?.name??``),r=e===`started`?`🔍️ auditor started`:e===`tool`?`🔍️ auditor → ${n}`:e===`tool_done`?`🔍️ auditor ← ${n} ${t.data?.ok===!1?`failed`:`${String(t.data?.chars??0)} chars`}`:e===`reply`?`🔍️ auditor replied`:`🔍️ auditor`;return e===`reply`&&t.data?.text||e===`tool`&&t.data?.args?(()=>{var n=cS(),i=n.firstChild,a=i.firstChild;return R(a,r),R(i,j(N,{get when(){return e===`tool`&&t.data?.args},get children(){var e=oS();return R(e,()=>at(String(t.data?.args??``),120)),e}}),null),R(n,j(N,{get when(){return e===`reply`&&t.data?.text},get children(){var e=sS();return R(e,()=>String(t.data?.text??``)),e}}),null),R(n,j(N,{get when(){return e===`tool`&&t.data?.args},get children(){var e=sS();return R(e,()=>String(t.data?.args??``)),e}}),null),n})():(()=>{var e=aS(),t=e.firstChild;return R(t,r),e})()}if(t.type===`todo`)return(()=>{var e=lS(),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=uS(),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),b(()=>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=dS(),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),b(()=>I(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=fS(),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=Gx();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)`)),b(()=>I(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=pS(),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=mS(),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=yS(),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=bS();return b(()=>I(e,`title`,`${yx(t.ts)} · ${t.branch}`)),e})()})(),null),R(s,j(N,{get when(){return!r()},get children(){var r=vS(),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=tS();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`:yx(t.ts)})()),R(r,j(N,{get when(){return e.showBranch},get children(){var e=hS();return R(e,()=>t.branch),e}}),null),R(r,j(N,{get when(){return e.onCancel},get children(){var t=gS();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(nd,{get text(){return bx(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=_S();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),b(()=>L(i,`author tone-${_x(n.color)}`)),r}}),null),R(s,j(ZS,{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},get agentId(){return e.agentId}}),null),b(e=>{var s=`msg`+(r()?` grouped`:``)+(i()?` next-grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),c=t.id,l=`avatar avghost tone-${_x(n.color)}`+(r()?` ghosted`:``),u=r()?`${yx(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&&I(o,`title`,e.o=u),e},{e:void 0,t:void 0,a:void 0,o:void 0}),a})()}function XS(e){let t=()=>(Array.isArray(e.data?.images)?e.data.images:[]).map(e=>typeof e==`string`?e:e?.url).filter(e=>typeof e==`string`&&e.length>0).map(t=>rf(e.agentId,t));return j(N,{get when(){return t().length},get children(){var e=xS();return R(e,j(M,{get each(){return t()},children:e=>(()=>{var t=SS();return I(t,`src`,e),t})()})),e}})}function ZS(e){let t=e.e;switch(t.type){case`prompt`:{let e=(t.data?.images??[]).map(e=>typeof e==`string`?e:e?.url).filter(e=>typeof e==`string`&&e.length>0);return[j(JS,{get html(){return rt(String(t.data.text??``))}}),j(N,{get when(){return e.length},get children(){var t=xS();return R(t,j(M,{each:e,children:e=>(()=>{var t=CS();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=wS(),n=e.firstChild.nextSibling;return R(n,()=>String(t.data.reasoning)),e}}),j(JS,{get html(){return rt(String(t.data.content??``))}}),j(N,{get when(){return t.data.interrupted},get children(){return TS()}}),j(N,{get when(){return t.data.final},get children(){var e=ES(),n=e.firstChild;return R(e,j(nd,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return j(qS,{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},get agentId(){return e.agentId}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=OS(),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(nd,{text:n}),null),R(c,n),R(l,()=>it(t.data.durationMs),null),R(l,()=>r===`bash`?Dx(Ex(t.data.ok,n)):i?``:` · FAILED`,null),R(a,j(N,{get when(){return e.orphan},get children(){return DS()}}),null),b(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=AS(),r=n.firstChild.firstChild.firstChild.nextSibling;return R(n,j(JS,{get html(){return rt(String(t.data?.rationale??``))}}),null),R(n,j(N,{get when(){return e.length},get children(){var t=kS();return t.firstChild,R(t,()=>e.join(` / `),null),t}}),null),b(()=>r.innerHTML=rt(String(t.data?.decision??``))),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=NS(),o=a.firstChild.firstChild.nextSibling;return R(a,j(N,{get when(){return i()},get children(){return jS()}}),null),R(a,j(N,{get when(){return n.length>0},get children(){var a=MS();return R(a,j(M,{each:n,children:n=>(()=>{var a=PS();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?Y(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>nf(`→ answered @${String(t.data.actor)}`)).catch(()=>nf(`answer failed`)):e.onOption?.(n)},R(a,n),b(()=>a.disabled=i()),a})()})),a}}),null),R(a,j(KS,{get answered(){return i()},get onOption(){return e.onOption}}),null),b(e=>{var n=`embed question`+(i()?` answered`:``),r=rt(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=zS(),n=e.firstChild.firstChild.nextSibling;return R(e,j(N,{get when(){return t.data.goalStatus},get children(){var e=FS(),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=IS(),n=e.firstChild.nextSibling;return b(()=>n.innerHTML=rt(String(t.data.recent))),e}}),null),R(e,j(N,{get when(){return t.data.problems},get children(){var e=LS(),n=e.firstChild.nextSibling;return b(()=>n.innerHTML=rt(String(t.data.problems))),e}}),null),R(e,j(N,{get when(){return t.data.next},get children(){var e=RS(),n=e.firstChild.nextSibling;return b(()=>n.innerHTML=rt(String(t.data.next))),e}}),null),b(()=>n.innerHTML=rt(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=BS(),n=e.firstChild;return n.firstChild,R(n,()=>String(t.data.message??``),null),e})();case`compaction`:return t.data.summary?(()=>{var e=WS(),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,()=>xx(Number(t.data.tokensBefore??0)),i),R(n,()=>xx(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[US(),j(JS,{get html(){return rt(String(t.data.summary))}})]}}),null),e})():(()=>{var e=HS(),n=e.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,R(n,()=>String(t.data.mode??``),r),R(n,()=>xx(Number(t.data.tokensBefore??0)),i),R(n,()=>xx(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(n,()=>String(t.data.mode??``)===`truncate`?` · older history dropped`:``,null),R(e,j(N,{get when(){return String(t.data.mode??``)===`truncate`},get children(){return VS()}}),null),e})();default:return(()=>{var e=GS();return R(e,()=>at(JSON.stringify(t.data),200)),e})()}}Ee([`input`,`keydown`,`click`]);var QS=(e,t)=>{let n=String(t??``).trim();return!n||/^\d+$/.test(n)?null:e?.[n]??null},$S=[{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)`}];function eC(e,t){return e?t===`dark`?{slot:`dark`,key:`teapot.theme.dark`}:{slot:`light`,key:`teapot.theme.light`}:{slot:`fixed`,key:`teapot.theme`}}var tC=F(`<div class=themeeditor><h4 class=cfgsub>your themes</h4><div class=btnrow><button type=button title="copy the theme you are using into a new editable one — presets themselves are never modified">+ duplicate current`),nC=F(`<div class=muted style="margin:6px 0">`),rC=F(`<b>+ duplicate current`),iC=F(`<div class=cfggrid style=margin-top:8px><label class=trow>appearance<select><option value=dark>dark</option><option value=light>light`),aC=F(`<div class=paletterows>`),oC=F(`<div class=btnrow><button type=button title="put every colour back to the palette this theme was created from">↺ reset palette</button><button type=button title="delete this custom theme">🗑 delete`),sC=F(`<h4 class=cfgsub>background image`),cC=F(`<img sizes=260px alt="current background"decoding=async loading=lazy>`,!0,!1,!1),lC=F(`<span class=bgpick-hint>🖼 replace…`),uC=F(`<div class=bgpreview><span class=muted title="this image is served from the server; the theme stores only its URL">✓ image set</span><div class=btnrow><label class=trow title="how much the image is dimmed so text stays readable">dim<input type=range min=0 max=0.9 step=0.05><span class="muted mono">%</span></label><label title="how much of the background shows through code blocks and tool cards — lower is more transparent">surfaces<input type=range min=0.35 max=1 step=0.01><span class="muted mono">%</span></label><button type=button>✕ remove`),dC=F(`<div class=cfggrid><button type=button></button><input type=file accept=image/* style=display:none>`),fC=F(`<div class=muted style=margin-top:6px;font-size:var(--text-xs)>the image is uploaded to the server and sits behind the panels, dimmed so text stays readable. No size limit — it is a file now, not browser storage.`),pC=F(`<label class=paletterow><input type=color><span class=paletterow-label></span><input class="mono paletterow-hex">`),mC=F(`<span class=bgpick-empty>🖼 choose a background image…`),hC=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.`),gC=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>`),_C=F(`<div class=skilllist>`),vC=F(`<span style=color:var(--err);font-size:13px>`),yC=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=cfgrow><label style=flex:1>API password<input type=password class=w100></label><span class=muted style=font-size:11.5px;max-width:34ch>bearer token for /api. empty = loopback only.</span></div><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</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 class=primarybtn>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>skills</legend></fieldset><fieldset><legend>help</legend><div class=helpsec><h4 class=cfgsub>this host</h4><div class=featgrid><div class=featrow><b>image downscaling</b><span class=muted></span></div><div class=featrow><b>terminal pty</b><span class=muted></span></div></div></div><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><span class=kbdgroup><kbd>↑</kbd><kbd>↓</kbd></span><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>`),bC=F(`<button type=button><span class=cfgmenu-label>`),xC=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`),SC=F(`<button type=button title="remove this key">−`),CC=F(`<div class=cfgkeyrow><input type=password>`),wC=F(`<button type=button>+ `),TC=F(`<option>`),EC=F(`<div class=cfgsub style=margin-bottom:var(--space-1)>`),DC=F(`<div class=themepick>`),OC=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label> ★`),kC=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label>`),AC=F(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),jC=F(`<input placeholder="command (e.g. npx)">`),MC=F(`<input placeholder="args, space separated">`),NC=F(`<input type=password placeholder="paste the token"title="sent as Authorization: Bearer <token>"style=flex:1>`),PC=F(`<input placeholder="header name"style="flex:0 1 150px">`),FC=F(`<input type=password placeholder=value style=flex:1>`),IC=F(`<div class=cfgrow><textarea class=mono rows=2 placeholder="{&quot;Authorization&quot;: &quot;Bearer …&quot;, &quot;X-Team&quot;: &quot;infra&quot;}"title="static headers for every request. Use the bearer option unless the server needs something unusual."style=flex:1>`),LC=F(`<button type=button class=mcpauthorize title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),RC=F(`<span class="mcpstate connected"title="an OAuth access token is usable — disconnect it under the server's details">🔑 authorized`),zC=F(`<span>`),BC=F(`<div class=muted style=font-size:11px;color:var(--warn)>`),VC=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><input placeholder="what this server is for — e.g. reverse engineering: decompile, disassemble"title="shown to the model when the MCP catalog is too large to send, so it can search for the right tool instead of guessing keywords"></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><select title="how this server authenticates"><option value=none>no auth</option><option value=bearer>bearer token</option><option value=header>custom header</option><option value=json>headers as JSON (advanced)</option></select></div><div class=cfgrow><button type=button title="connect now and list the tools — nothing is saved">test`),HC=F(`<option value=oauth selected>`),UC=F(`<span class=muted> · needs a grant (🔑 authorize)`),WC=F(`<details class=mcptools-wrap><summary>show <!> tool</summary><ul class=mcptools>`),GC=F(`<div class=mcpdanger><span class=muted>OAuth grant</span><button type=button class=mcpdisconnect title="forget the stored grant (the refresh token is deleted, so authorizing again needs a browser)">disconnect`),KC=F(`<div><div class=mcpresult-head><b>`),qC=F(`<span class=mcptool-desc>`),JC=F(`<li><code class=mono>`),YC=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">`),XC=F(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),ZC=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`),QC=F(`<span class=muted>🧩 sub of @`),$C=F(`<div class=cfgrow><b></b><span class=muted>`),ew=F(`<div class=muted>`),tw=F(`<div class=skillbody>`),nw=F(`<div class=skillrow><button type=button class=skillhead title="show the playbook"><span class=skillcaret></span><b class=mono></b><span class=muted>`),rw=F(`<div class="muted skillbody">`);function iw(e){let[t,n]=y(e.themes().some(t=>t.id===e.paintedId)?e.paintedId:e.themes()[0]?.id??``),r=()=>z(e.themes(),e.paintedId,t()),[i,a]=y({}),o,s=t=>{let n=r()?.id;if(!n)return;let i=e.themes().map(e=>e.id===n?t(e):e);e.onChange(i)},c=(e,t)=>{let n=Kn(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.paintedId),r=Md.find(t=>t.key===e.paintedId),i=t??r??Md[0],a=getComputedStyle(document.documentElement),o={...In};for(let{key:e,cssVar:t}of Pn){let n=Kn(a.getPropertyValue(t));n&&(o[e]=n)}let s=Un(e.themes().map(e=>e.id).concat(Md.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,surfaceAlpha:t.surfaceAlpha}:{}};e.onChange([...e.themes(),c]),n(s),e.onPick(s)},u=async t=>{if(t){if(!/^image\//.test(t.type))nf(`that file is ${JSON.stringify(t.type||`unknown`)} — pick an image`);else{nf(`uploading ${t.name} (${Math.round(t.size/1024)}KB)…`);try{let n=await fetch(`/api/assets`,{method:`POST`,headers:{"content-type":t.type},body:t}).then(async e=>({ok:e.ok,body:await e.json().catch(()=>null)}));if(!n.ok||!n.body?.url){nf(n.body?.error??`upload failed`);return}s(e=>({...e,backgroundImage:n.body.url,backgroundImageBytes:n.body.bytes}));let i=r()?.id;i&&e.onPick(i),nf(`background image set`)}catch(e){nf(`upload failed: ${e.message}`)}}}};return(()=>{var t=tC(),d=t.firstChild.nextSibling.firstChild;return d.$$click=l,R(t,j(N,{get when(){return P(()=>!!(r()&&e.themes().some(t=>t.id===e.paintedId)))()?r():null},get fallback(){return(()=>{var t=nC();return R(t,(()=>{var t=P(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,rC(),` to start from the palette you are using.`]:[`the editor shows when one of your themes is the one on screen — pick one under "your themes" above (or press `,rC(),`).`]})()),t})()},children:t=>[(()=>{var e=iC(),t=e.firstChild.firstChild.nextSibling;return t.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),b(()=>t.value=r().mode),e})(),(()=>{var e=aC();return R(e,j(M,{each:Pn,children:e=>(()=>{var t=pC(),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),b(()=>I(t,`title`,e.cssVar)),b(()=>n.value=Kn(r().palette[e.key])??`#000000`),b(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=oC(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...In}})),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})(),sC(),(()=>{var e=dC(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),R(t,j(N,{get when(){return r().backgroundImage},get fallback(){return mC()},get children(){return[(()=>{var e=cC();return b(t=>{var n=Zt(r().backgroundImage),i=Xt(r().backgroundImage);return n!==t.e&&I(e,`src`,t.e=n),i!==t.t&&I(e,`srcset`,t.t=i),t},{e:void 0,t:void 0}),e})(),lC()]}})),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`?Ae(i,n):o=n,R(e,j(N,{get when(){return r().backgroundImage},get children(){var e=uC(),t=e.firstChild;t.firstChild;var n=t.nextSibling.firstChild,i=n.firstChild.nextSibling,a=i.nextSibling,o=a.firstChild,c=n.nextSibling,l=c.firstChild.nextSibling,u=l.nextSibling,d=u.firstChild,f=c.nextSibling;return R(t,()=>{let e=r()?.backgroundImageBytes;return e?` — ${Math.max(1,Math.round(e/1024))} KB`:``},null),i.$$input=e=>s(t=>({...t,backgroundDim:Number(e.currentTarget.value)})),R(a,()=>Math.round((r().backgroundDim??.55)*100),o),l.$$input=e=>s(t=>({...t,surfaceAlpha:Number(e.currentTarget.value)})),R(u,()=>Math.round((r().surfaceAlpha??.82)*100),d),f.$$click=()=>s(e=>({...e,backgroundImage:void 0})),b(()=>i.value=r().backgroundDim??.55),b(()=>l.value=r().surfaceAlpha??.82),e}}),null),b(e=>{var n=`bgpick`+(r().backgroundImage?` has`:``),i=r().backgroundImage?`click to replace this background image (PNG/JPG/WebP)`:`choose a background image (PNG/JPG/WebP)`;return n!==e.e&&L(t,e.e=n),i!==e.t&&I(t,`title`,e.t=i),e},{e:void 0,t:void 0}),e})(),fC()]}),null),t})()}function aw(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]=y(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=y(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]=y(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=y(e.cfg.progressMinChars??4e3),[p,m]=y(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=y(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,v]=y(e.cfg.maxSpawnDepth??3),[ee,S]=y(!!e.cfg.shortContext),[C,w]=y(``),[T,E]=y(!1),[te,D]=y((e.cfg.tasks??[]).map(e=>({...e}))),[O,ne]=y((e.cfg.mcpServers??[]).map(e=>({...e}))),[re,k]=y(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ie,ae]=y({}),[oe,se]=y(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=e.headers??{},r=Object.keys(n);if(!r.length)return[t,`none`];let i=r.length===1?r[0]:``;return i===`Authorization`&&/^Bearer /i.test(n[i]??``)?[t,`bearer`]:[t,r.length===1?`header`:`json`]}))),[ce,le]=y(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=e.headers??{},r=Object.keys(n);if(r.length!==1)return[t,``];let i=r[0];return[t,i===`Authorization`?(n[i]??``).replace(/^Bearer /i,``):n[i]??``]}))),[ue,de]=y(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=Object.keys(e.headers??{}),r=n.length===1?n[0]:``;return[t,r&&r!==`Authorization`?r:``]}))),[fe,A]=y({}),pe={},me=async(e,t)=>{if(!O()[e])return;let n=await Y(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}).catch(()=>null);O()[e]&&n&&A(t=>({...t,[e]:n.ok?{kind:`ok`,text:`${n.tools?.length??0} tools`}:{kind:`err`,text:n.needsOAuth?`needs authorization — press 🔑`:n.error??`no response`,...n.needsOAuth?{needsOAuth:!0}:{}}}))},[he,ge]=y({}),[_e,ve]=y({}),ye=e=>{let t=QS(_e(),e);return t&&(t.required||t.authorized)?t:null},be=async()=>{let e=await Y(`/api/mcp`).catch(()=>null);ge(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},xe=async e=>{let t=String(e??``).trim();if(!t)return;let n=await Y(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&ve(e=>({...e,[t]:n}))},Ce=async(t,n)=>{if(!n.name){A(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}A(e=>({...e,[t]:{kind:`testing`,text:`discovering the authorization server…`}}));let r=await Y(`/api/mcp/oauth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name,url:n.url})}).catch(()=>null);if(r?.alreadyAuthorized){A(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await xe(n.name),await be();return}if(!r?.ok||!r.url){A(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await xe(n.name);return}window.open(r.url,`_blank`,`noopener`),A(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 Y(`/api/mcp/oauth/status?name=${encodeURIComponent(n.name)}`).catch(()=>null);if(r&&!r.error){if(ve(e=>({...e,[n.name]:r})),r.authorized){A(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await be(),e.onSaved();return}if(r.flow?.phase===`error`){A(e=>({...e,[t]:{kind:`err`,text:r.flow.message??r.lastError??`authorization failed`}}));return}}}A(e=>({...e,[t]:{kind:`err`,text:`authorization timed out`}}))};x(()=>{F()===`mcp`&&(be(),O().forEach((e,t)=>{e.name&&xe(e.name)}))});let[we,Te]=y(``),[F,Ee]=y(`providers`),De=(t,n)=>{let{slot:r}=eC(e.theme.auto(),n);r===`dark`?Ge(t):r===`light`?qe(t):Ve(t)},Oe=t=>e.theme.auto()?t===e.theme.dark()||t===e.theme.light():t===e.theme.activeId(),[ke,Ae]=y([]),je=async()=>{let e=await Y(`/api/archived`).catch(()=>null);Ae(e?.agents??[])},Me=()=>ke().filter(e=>!e.parent);x(()=>{F()===`archive`&&je()});let Ne=[{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:`skills`,label:`🧠 skills`,hint:`reusable playbooks available to the selected session`},{key:`help`,label:`❔️ help`,hint:`keyboard shortcuts and what each toggle does`}],Pe=()=>(e.cfg.agents??[]).map(e=>e.id),Fe=()=>e.theme.themes(),Ie=()=>e.theme.activeId(),Le={auto:localStorage.getItem(`teapot.theme.auto`)===`1`,dark:localStorage.getItem(`teapot.theme.dark`)??`dark`,light:localStorage.getItem(`teapot.theme.light`)??`light`,fixed:localStorage.getItem(`teapot.theme`)??`dark`},Re=y(Le),ze=Re[0],Be=t=>{let n={...ze(),...t};Re[1](n),e.theme.setAuto(n.auto),e.theme.setDark(n.dark),e.theme.setLight(n.light),e.theme.setActive(n.fixed);let r=t.dark??t.light??t.fixed;r&&e.theme.preview(r)},Ve=e=>Be({fixed:e}),He=()=>ze().auto,Ue=e=>Be({auto:e}),We=()=>ze().dark,Ge=e=>Be({dark:e}),Ke=()=>ze().light,qe=e=>Be({light:e}),Je=t=>e.theme.setThemes(t),Ye=()=>{let t=Le;e.theme.setAuto(t.auto),e.theme.setDark(t.dark),e.theme.setLight(t.light),e.theme.setActive(t.fixed),e.theme.preview(null)},Xe=e=>Ln[e]??In,Ze=()=>{let e={};for(let t of n()){if(!t.name.trim())return Te(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return Te(`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},[Qe,$e]=y(`idle`),et=e=>{Te(e),$e(e=>e===`saving`?`idle`:e)},tt=async t=>{t.preventDefault(),Te(``),$e(`saving`);let n=Ze();if(!n)return $e(`idle`);let r=te().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)return et(`task "${e.id}": agent is required`);if(!e.schedule?.trim())return et(`task "${e.id}": schedule is required`)}let a=[],o=new Set;for(let e of O()){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)return et(`MCP: a server needs a name`);if(o.has(t))return et(`MCP: two servers are named "${t}"`);if(o.add(t),r===`stdio`?!i:!n)return et(`MCP "${t}": ${r===`stdio`?`a command is`:`a url is`} required`);a.push({name:t,transport:r,enabled:e.enabled!==!1,...String(e.description??``).trim()?{description:String(e.description).trim()}:{},...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 Y(`/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:ee(),...T()?{password:C()}:{},tasks:r,mcpServers:a})}),await be(),await Promise.all(a.map((e,t)=>e.name?xe(e.name):Promise.resolve())),setTimeout(()=>{be(),a.forEach((e,t)=>{e.name&&xe(e.name)})},1200),e.onSaved();let t=new Set(a.map(e=>e.name).filter(Boolean)),o=O().filter(e=>{let n=String(e.name??``).trim();return t.has(n)&&_e()[n]?.required&&!_e()[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??``));nf(`${o.map(e=>String(e.name??``).trim()).filter(Boolean).join(`, `)||`a saved MCP server`} needs authorization — 🔑 authorize in MCP servers`)}e.theme.commitAppearance(ze()),e.theme.preview(null),$e(`saved`),Object.assign(Le,ze()),setTimeout(()=>{$e(`idle`),e.onClose()},400)}catch(e){Te(e.message),$e(`error`),setTimeout(()=>$e(`idle`),1600)}};return j(rd,{title:`settings`,onClose:()=>{Ye(),e.onClose()},get children(){var t=yC(),x=t.firstChild,T=x.firstChild,ge=T.nextSibling.firstChild,ve=ge.firstChild.nextSibling,be=ve.nextSibling;be.firstChild;var ke=be.nextSibling.firstChild.firstChild.nextSibling;ke.firstChild;var Ae=ge.nextSibling,Le=Ae.firstChild.nextSibling,Re=Le.firstChild.firstChild.nextSibling,ze=Le.nextSibling,Be=Ae.nextSibling,Ye=Be.firstChild.nextSibling,Ze=Ye.firstChild.firstChild.nextSibling,$e=Ye.nextSibling,et=$e.firstChild,nt=et.firstChild.nextSibling,it=$e.nextSibling.firstChild,at=Be.nextSibling,st=at.firstChild.nextSibling.nextSibling,ct=at.nextSibling,lt=ct.firstChild.nextSibling,ut=ct.nextSibling;ut.firstChild;var dt=ut.nextSibling;dt.firstChild;var ft=dt.nextSibling,pt=ft.firstChild.nextSibling.firstChild;pt.firstChild;var mt=pt.nextSibling,ht=ft.nextSibling;ht.firstChild;var gt=ht.nextSibling,_t=gt.firstChild.nextSibling.firstChild.nextSibling.firstChild,vt=_t.firstChild.nextSibling,yt=_t.nextSibling.firstChild.nextSibling,bt=x.nextSibling,xt=bt.firstChild;return t.addEventListener(`submit`,tt),R(T,j(M,{each:Ne,children:e=>(()=>{var t=bC(),n=t.firstChild;return t.$$click=()=>Ee(e.key),R(n,()=>e.label),b(n=>{var r=`cfgmenu-item`+(F()===e.key?` on`:``),i=e.hint,a=F()===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(ge,j(Se,{get each(){return n()},children:(e,t)=>(()=>{var i=xC(),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=CC(),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=SC();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),b(()=>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)),b(()=>a.value=e().name),b(()=>o.value=e().baseUrl),b(()=>s.value=e().model),i})()}),ve),ve.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),R(be,j(M,{each:$S,children:e=>(()=>{var t=wC();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),b(()=>I(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),ke.addEventListener(`change`,e=>a(e.currentTarget.value)),R(ke,j(M,{get each(){return s()},children:e=>(()=>{var t=TC();return t.value=e,R(t,e),t})()}),null),R(ge,j(N,{get when(){return c()},get children(){var e=hC(),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),Re.addEventListener(`change`,e=>{Ue(e.currentTarget.checked)}),R(Ae,j(N,{get when(){return He()},get children(){var e=gC(),t=e.firstChild,n=t.firstChild.nextSibling,r=t.nextSibling.firstChild.nextSibling;return n.addEventListener(`change`,e=>{Ge(e.currentTarget.value)}),R(n,j(M,{get each(){return Fe().filter(e=>e.mode===`dark`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(Md.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=TC();return R(t,()=>e.label),b(()=>t.value=e.key),t})()})),r.addEventListener(`change`,e=>{qe(e.currentTarget.value)}),R(r,j(M,{get each(){return Fe().filter(e=>e.mode===`light`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(Md.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=TC();return R(t,()=>e.label),b(()=>t.value=e.key),t})()})),b(()=>n.value=We()),b(()=>r.value=Ke()),e}}),ze),R(Ae,j(M,{each:[{mode:`dark`,title:`dark themes`},{mode:`light`,title:`light themes`}],children:e=>j(N,{get when(){return[...Fe(),...Md].some(t=>t.mode===e.mode)},get children(){return[(()=>{var t=EC();return R(t,()=>e.title),t})(),(()=>{var t=DC();return R(t,j(M,{get each(){return Fe().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=OC(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>De(e.id,e.mode),R(n,j(Qd,{get palette(){return e.palette},get backgroundImage(){return e.backgroundImage},get surfaceAlpha(){return e.surfaceAlpha},get backgroundDim(){return e.backgroundDim}})),R(r,()=>e.label,i),b(n=>{var r=`themecard`+(Oe(e.id)?` on`:``),i=`${e.label} (custom)${e.backgroundImage?` · with a background image`:``}`,a=Oe(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 Md.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=kC(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>De(e.key,e.mode),R(n,j(Qd,{get palette(){return Xe(e.key)}})),R(r,()=>e.label),b(n=>{var r=`themecard`+(Oe(e.key)?` on`:``),i=`${e.label} (${e.mode})`,a=Oe(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(Ae,j(iw,{themes:Fe,get paintedId(){return e.theme.paintedId()},onChange:e=>{let t=Vn(e),n=e;if(!t.ok){let t=e.map(e=>e.backgroundImage?{...e,backgroundImage:void 0,backgroundDim:void 0,surfaceAlpha:void 0,backgroundImageBytes:void 0}:e),r=Vn(t);if(r.ok)n=t,nf(`storage was full — saved without the background image(s)`);else{nf(r.error??`could not save theme`);return}}Je(n);let r=e=>n.some(t=>t.id===e)||Md.some(t=>t.key===e);r(Ie())||(Ve(`dark`),localStorage.setItem(`teapot.theme`,`dark`)),r(We())||(Ge(`dark`),localStorage.setItem(`teapot.theme.dark`,`dark`)),r(Ke())||(qe(`light`),localStorage.setItem(`teapot.theme.light`,`light`))},onPick:e=>{let t=Fe().find(t=>t.id===e)?.mode??Md.find(t=>t.key===e)?.mode??`dark`,n=eC(He(),t);n.slot===`dark`?Ge(e):n.slot===`light`?qe(e):Ve(e)}}),null),Ze.$$input=e=>{w(e.currentTarget.value),E(!0)},R($e,j(Zd,{label:`progress interval (min)`,get value(){return l()},onValue:e=>u(e),hint:`how often the harness asks for a progress report`}),et),R($e,j(Zd,{label:`progress min chars`,get value(){return d()},onValue:e=>f(e),hint:`progress prompts wait for this much real output`}),et),nt.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),R($e,j(Zd,{label:`context window (k tok)`,get value(){return h()},onValue:e=>g(e),hint:`model's real window — 0/blank hides the % gauge`}),null),R($e,j(Zd,{label:`max spawn depth`,get value(){return _()},onValue:e=>v(e),hint:`sub-agent nesting limit (0 = no spawning)`}),null),it.addEventListener(`change`,e=>S(e.currentTarget.checked)),R(at,j(N,{get when(){return O().length>0},get fallback(){return AC()},get children(){return j(Se,{get each(){return O()},children:(e,t)=>{let n=()=>he()[e().name],r=e=>ne(O().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=VC(),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=p.nextSibling,g=h.firstChild,_=g.firstChild,v=h.nextSibling,ee=v.firstChild;return o.$$input=e=>r({name:e.currentTarget.value}),s.$$input=e=>{r({url:e.currentTarget.value});let n=e.currentTarget.value.trim();clearTimeout(pe[t]),/^https?:\/\//.test(n)&&(pe[t]=setTimeout(()=>{me(t,{...O()[t],url:n})},700))},l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>ne(O().filter((e,n)=>n!==t)),f.$$input=e=>r({description:e.currentTarget.value}),m.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),R(p,j(N,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=jC();return t.$$input=e=>r({command:e.currentTarget.value}),b(()=>t.value=e().command??``),t})(),(()=>{var t=MC();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),b(()=>t.value=(e().args??[]).join(` `)),t})()]}}),null),g.addEventListener(`change`,e=>{let n=e.currentTarget.value;if(se(e=>({...e,[t]:n})),n===`none`)r({headers:void 0});else if(n===`bearer`){let e=ce()[t]??``;r({headers:e?{Authorization:`Bearer ${e}`}:void 0})}else if(n===`header`){let e=ue()[t]??``,n=ce()[t]??``;r({headers:e&&n?{[e]:n}:void 0})}}),R(g,j(N,{get when(){return ye(String(e().name??``))},children:e=>(()=>{var t=HC();return R(t,()=>e().authorized?`OAuth — authorized`:`OAuth — authorization needed`),t})()}),_),R(h,j(N,{get when(){return oe()[t]===`bearer`},get children(){var e=NC();return e.$$input=e=>{let n=e.currentTarget.value;le(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},b(()=>e.value=ce()[t]??``),e}}),null),R(h,j(N,{get when(){return oe()[t]===`header`},get children(){return[(()=>{var e=PC();return e.$$input=e=>{let n=e.currentTarget.value;de(e=>({...e,[t]:n}));let i=ce()[t]??``;r({headers:n&&i?{[n]:i}:void 0})},b(()=>e.value=ue()[t]??``),e})(),(()=>{var e=FC();return e.$$input=e=>{let n=e.currentTarget.value;le(e=>({...e,[t]:n}));let i=ue()[t]??``;r({headers:i&&n?{[i]:n}:void 0})},b(()=>e.value=ce()[t]??``),e})()]}}),null),R(i,j(N,{get when(){return oe()[t]===`json`},get children(){var e=IC(),n=e.firstChild;return n.$$input=e=>{let n=e.currentTarget.value;if(k(e=>({...e,[t]:n})),!n.trim())r({headers:void 0});else try{let e=JSON.parse(n);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`not an object`);r({headers:e}),ae(e=>({...e,[t]:``}))}catch{ae(e=>({...e,[t]:`must be a JSON object — not applied`}))}},b(()=>n.value=re()[t]??``),e}}),v),ee.$$click=async()=>{let e=O()[t];if(!e.name){A(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}A(e=>({...e,[t]:{kind:`testing`,text:`connecting…`}}));let n=await Y(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}).catch(()=>null);A(e=>({...e,[t]:n?.ok?{kind:`ok`,text:`${n.tools?.length??0} tool${n.tools?.length===1?``:`s`}`,tools:n.tools??[]}:{kind:`err`,text:n?.error??`no response`,...n?.needsOAuth?{needsOAuth:!0}:{}}})),n?.ok||await xe(e.name)},R(v,j(N,{get when(){return P(()=>!!QS(_e(),String(e().name??``))?.required)()&&!QS(_e(),String(e().name??``))?.authorized},get children(){var n=LC();return n.$$click=()=>void Ce(t,e()),n}}),null),R(v,j(N,{get when(){return QS(_e(),String(e().name??``))?.authorized},get children(){return RC()}}),null),R(v,j(N,{get when(){return n()},get children(){var e=zC();return R(e,(()=>{var e=P(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:P(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),b(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 ie()[t]},get children(){var e=BC();return R(e,()=>ie()[t]),e}}),null),R(i,j(N,{get when(){return fe()[t]},children:n=>(()=>{var r=KC(),i=r.firstChild,a=i.firstChild;return R(a,()=>n().text),R(i,j(N,{get when(){return n().needsOAuth},get children(){return UC()}}),null),R(r,j(N,{get when(){return(n().tools?.length??0)>0},get children(){var e=WC(),t=e.firstChild,r=t.firstChild.nextSibling;r.nextSibling;var i=t.nextSibling;return R(t,()=>n().tools?.length,r),R(t,()=>n().tools?.length===1?``:`s`,null),R(i,j(M,{get each(){return n().tools??[]},children:e=>(()=>{var t=JC(),n=t.firstChild;return R(n,()=>e.name),R(t,j(N,{get when(){return e.description},get children(){var t=qC();return R(t,()=>e.description),t}}),null),b(()=>I(t,`title`,e.description??``)),t})()})),e}}),null),R(r,j(N,{get when(){return QS(_e(),String(e().name??``))?.authorized},get children(){var n=GC(),r=n.firstChild.nextSibling;return r.$$click=async()=>{confirm(`Disconnect ${e().name}?\n\nThe stored OAuth grant is deleted and you will have to authorize again in a browser.`)&&(await Y(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await xe(e().name),A(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}})))},n}}),null),b(()=>L(r,`mcpresult `+(n().kind===`err`?`err`:`ok`))),r})()}),null),b(()=>o.value=e().name),b(()=>s.value=e().url??``),b(()=>l.checked=e().enabled!==!1),b(()=>f.value=e().description??``),b(()=>m.value=e().transport??`http`),b(()=>g.value=ye(String(e().name??``))?`oauth`:oe()[t]??`none`),i})()}})}}),st),st.$$click=()=>ne([...O(),{name:``,url:``,transport:`http`,enabled:!0}]),R(ct,j(N,{get when(){return te().length>0},get children(){return j(Se,{get each(){return te()},children:(e,t)=>(()=>{var n=YC(),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=>D(te().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>D(te().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>D(te().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>D(te().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>D(te().filter((e,n)=>n!==t)),u.$$input=e=>D(te().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),b(()=>i.value=e().id),b(()=>a.value=e().agent),b(()=>o.value=e().schedule),b(()=>c.checked=!!e().forked),b(()=>u.value=e().prompt),n})()})}}),lt),lt.$$click=()=>D([...te(),{id:``,agent:Pe()[0]??``,schedule:`every 30m`,prompt:``}]),R(ut,j(N,{get when(){return Me().length>0},get fallback(){return XC()},get children(){return j(M,{get each(){return Me()},children:t=>(()=>{var n=ZC(),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 ${ot(new Date(t.archivedAt).toISOString())}`:``})(),null),R(s,()=>t.workspace),c.$$click=async()=>{let n=await Y(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await je(),e.onSaved();let r=(n?.ids?.length??1)-1;nf((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 Y(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await je(),e.onSaved(),nf(`deleted ${t.id} for good`))},b(()=>I(s,`title`,t.workspace)),n})()})}}),null),R(dt,j(M,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=$C(),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=QC();return t.firstChild,R(t,()=>e.parent,null),t}}),null),t})()}),null),R(pt,()=>e.cfg.version??`unknown`,null),mt.$$click=async e=>{try{Te(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await Y(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=null,i=!1;for(let e=0;e<120&&!i;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await Y(`/api/version`);if(!e.version)continue;r===null&&(r=e.uptimeSeconds??null),(e.version!==`0.37.97`||typeof e.uptimeSeconds==`number`&&r!==null&&e.uptimeSeconds<r)&&(i=!0,window.location.reload())}catch{}}if(!i)throw Error(`restart timeout — new server did not come up`)}catch(e){Te(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},R(ht,j(N,{get when(){return e.skills.length>0},get fallback(){return(()=>{var t=ew();return R(t,()=>e.hasSelection?`this session has no skills yet — the agent saves them with save_skill once a procedure proves itself`:`select a session to see the skills available to it`),t})()},get children(){var t=_C();return R(t,j(M,{get each(){return e.skills},children:t=>{let[n,r]=y(!1),[i,a]=y(null),[o,s]=y(``),c=async()=>{if(n())return r(!1);if(r(!0),i()===null&&e.agentId)try{let n=await Y(`/api/agents/${e.agentId}/skills/${encodeURIComponent(t.name)}`);a(String(n.text??``))}catch(e){s(e.message)}};return(()=>{var e=nw(),r=e.firstChild,a=r.firstChild,s=a.nextSibling,l=s.nextSibling;return r.$$click=c,R(a,()=>n()?`▾`:`▸`),R(s,()=>t.name),R(l,()=>t.description),R(e,j(N,{get when(){return n()},get children(){return j(N,{get when(){return i()!==null},get fallback(){return(()=>{var e=rw();return R(e,()=>o()||`loading…`),e})()},get children(){var e=tw();return b(()=>e.innerHTML=rt(String(i()??``))),e}})}}),null),b(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),R(vt,(()=>{var t=P(()=>!!e.features);return()=>t()?P(()=>!!e.features.imageResize.available)()?`on — ${e.features.imageResize.tool}, long edge ≤ ${e.features.imageResize.maxEdge}px`:`off — no ffmpeg / ImageMagick found; uploads are served as-is`:`checking…`})()),R(yt,(()=>{var t=P(()=>!!e.features);return()=>t()?P(()=>!!e.features.pty.available)()?`on — ${e.features.pty.provider}`:`off — no pty provider; terminals run on plain pipes (no resize)`:`checking…`})()),R(bt,j(N,{get when(){return we()},get children(){var e=vC();return R(e,we),e}}),xt),R(xt,(()=>{var e=P(()=>Qe()===`saving`);return()=>e()?`saving…`:P(()=>Qe()===`saved`)()?`✓ saved`:Qe()===`error`?`✕ failed`:`save settings`})()),b(t=>{var n=F()!==`providers`,r=F()!==`appearance`,i=F()!==`runtime`,a=e.cfg.hasPassword?`(unchanged — type to replace)`:`(none — loopback only)`,o=F()!==`mcp`,s=F()!==`tasks`,c=F()!==`archive`,l=F()!==`agents`,u=F()!==`update`,d=F()!==`skills`,f=F()!==`help`,p=Qe()===`saved`,m=Qe()===`error`,h=Qe()===`saving`;return n!==t.e&&ge.classList.toggle(`hide`,t.e=n),r!==t.t&&Ae.classList.toggle(`hide`,t.t=r),i!==t.a&&Be.classList.toggle(`hide`,t.a=i),a!==t.o&&I(Ze,`placeholder`,t.o=a),o!==t.i&&at.classList.toggle(`hide`,t.i=o),s!==t.n&&ct.classList.toggle(`hide`,t.n=s),c!==t.s&&ut.classList.toggle(`hide`,t.s=c),l!==t.h&&dt.classList.toggle(`hide`,t.h=l),u!==t.r&&ft.classList.toggle(`hide`,t.r=u),d!==t.d&&ht.classList.toggle(`hide`,t.d=d),f!==t.l&&gt.classList.toggle(`hide`,t.l=f),p!==t.u&&xt.classList.toggle(`saved`,t.u=p),m!==t.c&&xt.classList.toggle(`error`,t.c=m),h!==t.w&&(xt.disabled=t.w=h),t},{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,c:void 0,w:void 0}),b(()=>ke.value=i()),b(()=>Re.checked=He()),b(()=>Ze.value=C()),b(()=>nt.value=p()??``),b(()=>it.checked=ee()),t}})}Ee([`click`,`input`]);var ow=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),sw=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),cw=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function lw(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=uw(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 uw(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return ow.has(t)?`image`:sw.has(t)?`video`:cw.has(t)?`audio`:null}var dw=new Map,fw=e=>{let t=dw.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},dw.set(e,t)),t},pw=F(`<span class=fsize>`),mw=F(`<div><span class=ficon></span><span class=fname>`),hw=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>· `),gw=F(`<div class=filebox>`),_w=F(`<div class=muted style=padding:6px>`),vw=F(`<img>`),yw=F(`<div class=mediapreview><div class="meta muted"> preview`),bw=F(`<button title="rendered markdown">👁 preview`),xw=F(`<button title="edit and save back to the workspace">✎ edit`),Sw=F(`<div class=filetoolbar><button title="syntax-highlighted source">&lt;/> code`),Cw=F(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),ww=F(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Tw=F(`<div class="content mdpreview shikiwrap">`),Ew=F(`<video controls>`),Dw=F(`<audio controls>`);function Ow(e){let t=fw(e.agentId),[n,r]=y(new Map),[i,a]=y(t.expanded),[o,s]=y(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=y(t.media),f=e=>{t.media=e,d(e)},[p,m]=y(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=y(``),[v,ee]=y(localStorage.getItem(`teapot.ignoreMode`)??`dim`),S=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(v())+1)%3];ee(t),localStorage.setItem(`teapot.ignoreMode`,t)},C=e=>v()!==`hide`||!e.ignored,[w,E]=y(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!w(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await ne(t,e)}))).then(t=>{E(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&re(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 O(e){return ne(e,w())}async function ne(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await Y(`/api/agents/${e.agentId}/tree?${r.toString()}`);return D(t,i.entries??[])}catch(e){return _(e.message),null}}let re=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=new Map(i.map(e=>[e.path,e])),o=n.map(e=>{let t=a.get(e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?t:e}).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=``;x(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),O(``).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 O(e.path);t&&re(e.path,t)}},[ae,oe]=y(``),[se,ce]=y(!1),[le,ue]=y(``),[de,fe]=y(!1),A=e=>/\.(md|markdown|mdx)$/i.test(e),pe=0,me=async e=>{let t=++pe;oe(``),ce(!0);try{let{highlightChunks:n}=await J(async()=>{let{highlightChunks:e}=await Promise.resolve().then(()=>Xb);return{highlightChunks:e}},void 0);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)}};T(()=>{pe++});let he=async(t,n)=>{let r=uw(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await Y(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),ue(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&me({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){nf(`open failed: ${e.message}`)}},ge=async()=>{let t=o();if(t&&!de()){fe(!0);try{await Y(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:le(),baseContent:t.content})}),c({...t,content:le()}),nf(`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?nf(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
181
181
  OK = load the disk version into the editor (your edits are discarded)
182
182
  Cancel = keep editing your copy`)?(ue(r.current),c({...t,content:r.current}),nf(`loaded the current file from disk`)):nf(`kept your edits — use Save As via bash to force-write`)}finally{fe(!1)}}},_e=e=>!e.binary&&!e.truncated,ve=(e,t)=>[(()=>{var n=mw(),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)?`▾`:`▸`:lw(e.name)})()),R(a,()=>e.name),R(n,j(N,{get when(){return P(()=>!e.dir)()&&e.size!==void 0},get children(){var t=pw();return R(t,()=>xx(e.size)),t}}),null),b(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&v()===`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=Oe(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(C)},children:e=>ve(e,t+1)})}})],ye=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[be,xe]=y(!1),Se=async()=>{if(!be()){xe(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await ne(e,w())})));for(let{p:e,rows:n}of t)n&&re(e,n)}finally{xe(!1)}}};return[(()=>{var e=hw(),t=e.firstChild.nextSibling;return t.firstChild,R(t,ye,null),R(e,j(td,{class:`filetoggle`,get icon(){return be()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void Se()}),null),R(e,j(td,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return P(()=>v()===`hide`)()?`🙈`:v()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${v()} — click to cycle (dim → hidden → shown)`},onClick:S}),null),R(e,j(td,{class:`filetoggle`,get icon(){return w()?`◉.`:`○.`},get title(){return w()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:te}),null),e})(),(()=>{var e=gw();return R(e,j(N,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=_w();return R(e,()=>g()||`empty workspace`),e})()},get children(){return j(M,{get each(){return(n().get(``)??[]).filter(C)},children:e=>ve(e,0)})}})),e})(),j(N,{get when(){return o()},children:t=>j(rd,{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=Sw(),n=e.firstChild;return R(e,j(N,{get when(){return P(()=>!!A(t().path))()&&!t().binary},get children(){var e=bw();return e.$$click=()=>h(`md`),b(()=>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=xw();return e.$$click=()=>h(`edit`),b(()=>L(e,p()===`edit`?`on`:``)),e}}),null),b(()=>L(n,p()===`code`?`on`:``)),e})(),j(N,{get when(){return!t().binary},get fallback(){return ww()},get children(){return j(N,{get when(){return p()===`edit`},get fallback(){return j(N,{get when(){return P(()=>p()===`md`)()&&A(t().path)},get fallback(){return j(Xd,{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=Tw();return b(()=>e.innerHTML=Re(t().content)),e}})},get children(){var e=Cw(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>ue(e.currentTarget.value),I(n,`spellcheck`,!1),R(r,()=>xx(le().length),i),a.$$click=()=>void ge(),R(a,()=>de()?`saving…`:`💾 save`),b(()=>a.disabled=de()||le()===t().content),b(()=>n.value=le()),e}})}})]},get children(){var t=yw(),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=Dw();return b(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Ew();return b(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=vw();return b(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}})}})})]}Ee([`click`,`input`]);var kw=F(`<div class=overlay><div class=modal style=max-width:360px><div class=modal-head><b>🔒️ sign in</b><span></span></div><form style=display:flex;flex-direction:column;gap:10px><input id=pw-input type=password placeholder=password autofocus><button type=submit class=primarybtn>unlock</button><span class=muted style=font-size:11px>the token is stored locally and sent as Bearer to this server only`),Aw=F(`<div class=leftbarbackdrop>`),jw=F(`<div class=sidehead><b>agents</b><button class=iconbtn title="close the agent list">✕`),Mw=F(`<i class=notifdot>`),Nw=F(`<br>`),Pw=F(`<button class="iconbtn ham"title="agent list">☰`),Fw=F(`<input class="title titleedit">`),Iw=F(`<span class="badge queued">⏳ <!> <!> queued`),Lw=F(`<button type=button class="badge bgjobs">⚙️ `),Rw=F(`<span class="badge cron">⏰ `),zw=F(`<div class=bgjobs-pop role=dialog aria-label="background shells"><div class=bgjobs-head><span>background shells</span><button type=button class=iconbtn title=close>✕`),Bw=F(`<header class=chan-head><span class=hash title="rename this chat">#</span><span></span><span class=sub> · <!>/<!> · <!>↻ <!>⚙️</span><span class=head-actions><button></button><span class=head-sep aria-hidden=true>`),Vw=F(`<div class=divider-msg>── beginning of log ──`),Hw=F(`<div class=divider-msg>loading older events…`),Uw=F(`<div class=feedloading><span class=spinner aria-hidden=true></span> loading newer events…`),Ww=F(`<details class=reasoning open><summary>💭 thinking </summary><div class="mono thinkscroll">`),Gw=F(`<div class=muted style=font-size:11.5px;margin-bottom:4px>🗜 summarizing older context…`),Kw=F(`<div class=content>`),qw=F(`<div class="msg live"><div class=avatar style="background:#5865f233;border:1px solid #5865f266">🫖</div><div class=msg-body><div class=msg-head><span class=author style=color:var(--acc)>agent</span><span class=ts>streaming…`),Jw=F(`<div class=feed>`),Yw=F(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),Xw=F(`<div class=termsplit>`),Zw=F(`<div class="termempty muted">no shell here — click a tab or + to add`),Qw=F(`<div class=termpane>`),$w=F(`<div class=termdrawer><div class=termgrip title="drag to resize · double-click to reset"></div><div class=termbar><div class=termtabs></div><div style=display:flex;gap:4px;align-items:center><span class="muted mono"style=flex:1;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span></div></div><div class=termbody><div class=termpane>`),eT=F(`<button class=jump>↓ `),tT=F(`<div class=cmds>`),nT=F(`<div class=imgstage><span class=muted style=font-size:11px;align-self:center> image<!> attached`),rT=F(`<label class=forkchip title="inherit the conversation prefix byte-exactly — the sub-agent's provider prefix cache starts warm"><input type=checkbox>fork ctx`),iT=F(`<span class=muted style=font-size:11.5px;white-space:nowrap>🖼 `),aT=F(`<div class="hint flashhint">`),oT=F(`<div><form><textarea rows=1></textarea><button type=button class="iconbtn maxbtn"></button><button type=submit>send</button><input id=composer-file type=file accept=image/* multiple style=display:none>`),sT=F(`<div class=rightbarbackdrop>`),cT=F(`<div><nav><div class=agent-list></div><div class=sidebar-footer><div class=footer-row style=justify-content:flex-end><button>🔔️</button></div><div class=brand-row><div class=brand>🫖 teapot <span class=version>v</span><span></span></div></div><div class=metrics></div></div></nav><section class=channel></section><aside><div class=rightbarhead><span class=muted>details`),lT=F(`<div class=notifbackdrop>`),uT=F(`<button class=editbtn>clear all`),dT=F(`<div class=notiflist>`),fT=F(`<div class=notifpanel><div class=notifhead>notifications<span style=display:flex;gap:8px;align-items:center><button class=iconbtn title="close notifications">✕`),pT=F(`<div class=bgphoto aria-hidden=true><img sizes=100vw alt decoding=async><span class=bgphoto-veil>`),mT=F(`<span class=wscount>`),hT=F(`<div class=wsheader><span class=wscaret>`),gT=F(`<span class=notifbadge>🔔️`),_T=F(`<span class=subtag>🧩`),vT=F(`<span class=mini-cron>⏰`),yT=F(`<span class=goaldone title="goal done">✓`),bT=F(`<div><span></span><span>`),xT=F(`<span class=caret-spacer>`),ST=F(`<span class=caret>`),CT=F(`<span class=ghosttag title="workspace missing">👻`),wT=F(`<span>🧩 `),TT=F(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),ET=F(`<span class=title>`),DT=F(`<div class="muted bgjobs-empty">no background jobs for this agent`),OT=F(`<pre class="mono bgjob-tail">`),kT=F(`<div class=bgjob><div class=bgjob-line><span></span><code class="mono bgjob-cmd"></code><span class="muted bgjob-meta"></span><button type=button class=bgjob-kill>`),AT=F(`<div class="muted bgjob-detached">this job outlived a harness restart, so its output is no longer captured here. it is still running as pid <!> — read its own log, or stop it yourself.`),jT=F(`<div class="divider-msg compacting"title="the harness is compressing old turns into notes so work can continue within the context window">🗜 `),MT=F(`<div class=muted style=display:grid;place-items:center;height:100%><span><span class=spinner aria-hidden=true></span> loading timeline…`),NT=F(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),PT=F(`<div class="content muted">thinking…`),FT=F(`<span>⌨ <button class=tabx title="close this shell">✕`),IT=F(`<div><b class=mono></b><span class=muted>`),LT=F(`<div class=cmdrow><b>@</b><span class=muted>`),RT=F(`<span class=imgchip><img><button type=button class=imgx title=remove>✕`),zT=F(`<span class=muted style=text-transform:none;letter-spacing:0>· <!> models`),BT=F(`<h3 title="switch provider/model live — applies from the agent's next turn">🧦 model`),VT=F(`<div style=display:flex;gap:6px;align-items:center;margin-top:6px><label class=muted style=font-size:11.5px;white-space:nowrap>effort</label><select style=flex:1;min-width:0><option value>provider default`),HT=F(`<div class=meta style=color:var(--fg)>`),UT=F(`<div class=modelbox><select title="provider (OpenAI-compatible endpoint)"></select><div style=display:flex;gap:4px><input type=text list=model-list style=flex:1;min-width:0><datalist id=model-list></datalist></div><div style=display:flex;gap:6px;align-items:center;margin-top:6px><button title="apply the provider, model and effort above to this session — takes effect from the agent's next turn"style=flex:1>apply</button></div><div class=meta>current: `),WT=F(`<div class=ctrlrow><label title="auto-continue fires after a round ONLY when all hold: ① this toggle is on ② a goal is set and its status is 'active' ③ the round ended cleanly (no error / not stopped). It stops when the goal is marked done, or if you press ■ stop. Sending any prompt also starts an idle agent regardless."><input type=checkbox>auto-continue`),GT=F(`<span>`),KT=F(`<h3 title="what the agent is working toward. Stored with the session; the agent reads it via get_goal(). Auto-continue keeps looping while the status is 'active' and stops when marked done.">🎯 goal`),qT=F(`<div class=statrow style=margin-bottom:6px><span class=k>status`),JT=F(`<div class="card goalcard"><div class=content>`),YT=F(`<form style=display:flex;flex-direction:column;gap:6px;margin-top:8px;margin-bottom:6px><textarea id=goal-input rows=3 placeholder="set new goal…"title="drag the bottom edge to make this taller — the height is remembered"style="background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;width:100%;resize:vertical"></textarea><textarea id=goal-verify-input rows=2 placeholder="verification contract (optional) — e.g. 'npm test passes; endpoint documented'. finish(goalComplete=true) is then audited against this."title="pi-goal-x-style verification contract — an independent reviewer checks the agent's finish against these requirements"style="background:var(--bg-darkest);border:1px solid var(--bg-light);border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;font-size:12.5px;width:100%;resize:vertical"></textarea><div style=display:flex;justify-content:flex-end;align-items:center;gap:10px><label class=muted title="queue a harness prompt telling the agent about the new goal at its next turn boundary"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=goal-notify type=checkbox> notify agent</label><button type=submit class=primarybtn>✓ save goal`),XT=F(`<span class=badge>/<!> done`),ZT=F(`<h3 title="todo.md — a shared checklist in the session dir. Write tasks like '- [ ] fix login'; the agent ticks them off via set_todo, you edit here. With notify on, it's told at its next turn boundary.">✅ tasks`),QT=F(`<div class=bartrack style=margin-bottom:6px><div>`),$T=F(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><label class=muted title="queue a harness prompt telling the agent the task list changed"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=todo-notify type=checkbox checked> notify agent</label><button class=okbtn>✓ save tasks`),eE=F(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),tE=F(`<h3 title="context is how much of the model's window the live conversation occupies. Past the threshold, the oldest turns are summarized into notes so work can continue.">📊 runtime`),nE=F(`<div class=rtcell><span>cost</span><b>$`),rE=F(`<div class=rtcell><span>cached</span><b>%`),iE=F(`<div class="card runcard"><div class=rtgrid><div class=rtcell title="prompt tokens billed this session"><span>tokens in</span><b></b></div><div class=rtcell title="completion tokens billed this session"><span>tokens out</span><b></b></div><div class=rtcell title="assistant turns this session"><span>turns</span><b></b></div><div class=rtcell title="tool calls this session"><span>tools</span><b></b></div><div class=rtcell><span>compacted</span><b>`),aE=F(`<div class=muted style=font-size:11px;text-transform:none;letter-spacing:0>showing <b></b> and the history it inherited before forking`),oE=F(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),sE=F(`<span class=muted style=text-transform:none;letter-spacing:0>· <!> · all agents`),cE=F(`<h3 title="cron tasks, all agents — click a row to open that agent. Edit them in ⚙️ settings → scheduled tasks.">⏰ schedule`),lE=F(`<option>`),uE=F(`<span class=badge title="no goal set yet">no goal`),dE=F(`<button>`),fE=F(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),pE=F(`<div class=muted>none yet`),mE=F(`<div class=progrow><b>recent</b><span class="content inline-md">`),hE=F(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),gE=F(`<div class=progrow><b>next</b><span class="content inline-md">`),_E=F(`<div class=progrow><b>goal</b><span>`),vE=F(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),yE=F(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),bE=F(`<span>% of `),xE=F(`<div class=bartrack><div>`),SE=F(`<div class=statrow title="a compaction pass is running right now — the summarizer's output streams in the timeline"><span class=k>🗜</span><b>compacting…</b><span class=muted style=font-size:11px;color:var(--acc)>`),CE=F(`<div class=ctxblock title="estimated live context vs the model's real window. Past the window, old turns are summarized into notes (compaction); the compact line below shows where that starts."><div class=statrow><span class=k>context</span><b>~<!> tok</b></div><div class=statrow style=margin-top:4px><span class=k>compact at</span><b> tok</b><span class=muted style=color:var(--dim)></span></div><div class=ctrlrow style=margin-top:6px><label title="when on, older turns are automatically summarized when context exceeds the budget"><input type=checkbox>auto-compact`),wE=F(`<div><span></span><span> events`),TE=F(`<div class=muted>no scheduled tasks — add them in ⚙️ settings ("scheduled tasks")`),EE=F(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),DE=F(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class=sched-meta> → next </div><div class="sched-prompt muted">`),OE=F(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),kE=F(`<div class=nbody>`),AE=F(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted"></span><button class="iconbtn nreadbtn">`),jE=F(`<div style=font-size:12.5px;color:var(--dim)> event(s) came after this prompt and will be discarded — the new branch starts from your edited text.`),ME=F(`<form style=display:flex;flex-direction:column;gap:10px><textarea id=edit-text class="mono w100"rows=6></textarea><div style=display:flex;justify-content:flex-end;gap:8px><button type=button>cancel</button><button type=submit class=primarybtn>⑂ fork & resend`),NE=F(`<span style=color:var(--err);font-size:13px>`),PE=F(`<form style=display:flex;flex-direction:column;gap:10px><label>workspace directory<div style=display:flex;gap:6px><input type=text class="w100 mono"><button type=button>go</button><button type=button title="parent directory">↑</button></div></label><div class=dirlist></div><div style=display:flex;gap:10px><label style=flex:1>agent name <input type=text placeholder="(directory name)"></label><label style="flex:0 1 auto;min-width:0">provider<select></select></label><label style=flex:1>model <input type=text placeholder="(provider default)"></label></div><button type=submit style=align-self:flex-end>create`),FE=F(`<div class=direntry>📁 `),IE=[`minimal`,`low`,`medium`,`high`],LE=1100,[RE,zE]=y(``),BE,VE=e=>{zE(e),clearTimeout(BE),BE=setTimeout(()=>zE(``),3200)},HE=!1,UE=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`audit_step`,`system_note`]),WE=new Set([`system_note`]),GE=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`audit_step`]),KE=new Set([`runaway-detected`,`error-retry`,`background-exit`,`context-compacted`,`context-compaction-started`]),qE=location.hash.match(/[#&]token=([^&]+)/);qE&&(localStorage.setItem(`teapot.token`,decodeURIComponent(qE[1])),history.replaceState(null,``,location.pathname+location.search));var JE=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function YE(){let[e,t]=y([]),[n,r]=y(null),[i,a]=y(``),[o,s]=y(new Map),[c,l]=y(new Map),[u,d]=y(new Map),f=!1,p=null;async function m(e=!1){if(p)return p;if(f&&!e)return;let t=(async()=>{try{let e=await Y(`/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),f=!0}catch{}})();p=t;try{await t}finally{p===t&&(p=null)}}let[h,g]=y([]),[_,v]=y(0),[ee,E]=y([]),[te,D]=y(null),O=new Map,[ne,re]=y(O.get(n()??``)??``),k=e=>{re(e);let t=n();t&&(e?O.set(t,e):O.delete(t))},[ie,ae]=y({providers:{}}),[oe,se]=y(!1),ce=()=>{let e=et()??(Ve()?pt()?Ue():ut():ze());return nt().find(t=>t.id===e)?.backgroundImage??``},le=()=>{let e=Ve()?pt()?Ue():ut():ze();return nt().some(t=>t.id===e)||Md.some(t=>t.key===e)?e:`dark`},[ue,de]=y(!1),fe=!1;x(()=>{!fe&&ie()?.needsSetup&&(fe=!0,requestAnimationFrame(()=>{jr(),de(!0)}))}),x(()=>{ue()&&!Za()&&Y(`/api/features`).then(e=>Qa(e)).catch(()=>Qa(null))});let A=new Set,pe=()=>window.innerWidth<=LE,[me,he]=y(pe());w(()=>{let e=()=>he(pe());window.addEventListener(`resize`,e),T(()=>window.removeEventListener(`resize`,e)),e()});let ge=0,_e=null,ve=0,ye,be,xe=0,Se=``,Ce=()=>{xe=0;let e=U();if(!e)return;if(lo=e.scrollHeight,po=e.clientHeight,It()){Ni();return}let t=_e;if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;r&&(e.scrollTop+=r,co={top:e.scrollTop,height:e.scrollHeight}),qt(ji())};function we(e,t){if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;Math.abs(r)<1||Math.abs(r)>uo||(e.scrollTop+=r,co={top:e.scrollTop,height:e.scrollHeight})}let Te=()=>{xe||=requestAnimationFrame(Ce)},F=e=>{e&&e!==be&&(ye??=new ResizeObserver(e=>{let t=e[0]?.contentRect,n=t?`${Math.round(t.width)}x${Math.round(t.height)}`:``;n!==Se&&(Se=n,Te())}),be&&ye.unobserve(be),be=e,Se=``,ye.observe(e))};w(()=>{window.addEventListener(`resize`,Te),T(()=>{window.removeEventListener(`resize`,Te),ye?.disconnect(),ye=void 0,be=void 0,xe&&cancelAnimationFrame(xe)})});function Ee(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[De,je]=y(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>LE:localStorage.getItem(`teapot.panel`)===`1`),Me=e=>{je(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},Ne=()=>Me(!De()),Pe=()=>{De()&&Me(!1)},[Fe,Ie]=y(!1),Le=()=>Ie(!1),[ze,Be]=y(localStorage.getItem(`teapot.theme`)??`dark`),[Ve,He]=y(localStorage.getItem(`teapot.theme.auto`)===`1`),[Ue,$e]=y(localStorage.getItem(`teapot.theme.light`)??`light`),[et,tt]=y(null),[nt,at]=y(Bn());w(()=>{Hn().then(e=>{if(e===null)return;let t=Gt(nt(),e);at(t),Vn(t)})});let[ut,dt]=y(localStorage.getItem(`teapot.theme.dark`)??`dark`),ft=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[pt,mt]=y(ft?.matches??!1);w(()=>{let e=e=>mt(e.matches);ft?.addEventListener(`change`,e),T(()=>ft?.removeEventListener(`change`,e))}),x(()=>{let e=qn({want:et()??(Ve()?pt()?Ue():ut():ze()),customIds:nt().map(e=>e.id),presetIds:Md.map(e=>e.key),fallback:`dark`}),t=e.active,n=nt().find(e=>e.id===t)??null;e.repaired&&(Ve()?localStorage.setItem(pt()?`teapot.theme.light`:`teapot.theme.dark`,t):localStorage.setItem(`teapot.theme`,t)),document.documentElement.dataset.theme=t,Wn(document.documentElement,n),document.documentElement.dataset.appearance=n?.mode??Md.find(e=>e.key===t)?.mode??`dark`});let[ht,bt]=y(``),[xt,St]=y(``),[Ct,wt]=y(``);x(()=>{let t=n();wt(C(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[Tt,Et]=y([]),Dt=()=>Object.keys(ie().providers??{});async function Ot(e){if(e)try{let t=await Y(`/api/models?provider=${encodeURIComponent(e)}`);Et(t.models??[])}catch{Et([])}}let kt=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)}`:``},At=()=>{let e=xt().trim()||z()?.model||``;if(!e)return``;let t=Tt().find(t=>t.id===e);if(!t)return``;let n=[],r=kt(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${xx(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(` · `)},jt=null,Mt=!1;x(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||ie().defaultProvider||Dt()[0]||``;if(r){if(t!==jt)jt=t,Mt=!1,C(()=>ht())!==i&&(bt(i),Ot(i)),C(()=>xt())&&St(``);else{let e=C(()=>ht());!C(()=>xt())&&e!==i&&En(Mt)&&(bt(i),Ot(i))}}});let[Nt,Pt]=y(!1),[It,Rt]=y(!0),zt,[Bt,Vt]=y(0),[Ht,Ut]=y(-1),qt=e=>Ut(e?Xe(e):-1),[Jt,Yt]=y(null),$t=()=>Fn().startsWith(`[compact] `),dn=()=>{let e=$t()?Fn().slice(10):Fn();return e.length>1200?`…`+e.slice(-1200):e};x(()=>{Jt()||Mn(e=>e?.text.startsWith(`[compact] `)?null:e)}),x(()=>{h().length,_(),Jt(),Tr().length,xi(),yi(),_i();let e=U();if(!e)return;let t=e.scrollHeight;t!==ge&&(ge=t,requestAnimationFrame(()=>requestAnimationFrame(()=>{It()&&(Ni(),requestAnimationFrame(()=>{if(!It())return;let t=e.scrollHeight;t!==ge&&(ge=t,Ni())}))})))});let[hn,xn]=y(new Map),Cn=()=>{let e=n();return e?hn().get(e)??null:null},Mn=e=>{let t=n();t&&xn(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})},Pn=()=>{let e=Cn();if(!e)return;let t=vt(e,h(),z()?.status);t?(t.text!==e.text||t.reasoning!==e.reasoning)&&Mn(t):Mn(null)},[Fn,In]=y(``),[Ln,Rn]=y(0),zn=()=>Ln(),[Un,Gn]=y(``),Kn;x(()=>{Cn()?Kn||=setTimeout(()=>{Kn=void 0,In(Cn()?.text??``),Gn(Cn()?.reasoning??``)},(Cn()?.text.length??0)>2e4?250:(Cn()?.text.length??0)>6e3?120:60):(clearTimeout(Kn),Kn=void 0,In(``),Gn(``))}),T(()=>clearTimeout(Kn)),x(()=>{let t=e();xn(e=>_t(e,e=>t.find(t=>t.id===e)?.status)),Rn(e=>yt(e,t,n(),Cn()))}),x(()=>{let e=Fn(),t=Cn()?.reasoning??``;(e||t)&&requestAnimationFrame(()=>{It()&&Ni()})}),x(()=>{let e=z()?.pendingPrompts??0,t=z()?.pendingPromptIds,n=tr(),r=nr(n),i=cn(r,e,t);i!==r&&rr(n,i)}),x(()=>{let e=z()?.pendingPromptQueue;if(!e?.length)return;let t=z()?.session||tr(),n=new Set(nr(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&rr(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}:{}})),...nr(t)])}),x(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{Mi()&&(Rt(!0),Vt(0),Pi(!0),fr())})};document.addEventListener(`visibilitychange`,e),T(()=>document.removeEventListener(`visibilitychange`,e))});let z=S(()=>e().find(e=>e.id===n())),Jn=()=>Nn({sameSession:!(z()?.session!==tr()&&z()?.session),agent:z(),echoCount:Er()}),Yn=()=>{let e=z();return e?e.live??(e.status===`running`||e.status===`waiting`||e.status===`needs_operator`):!1},Xn=()=>vn(z(),i(),Yn()),[Zn,B]=y(null);S(()=>{let e=new Set;for(let t of h())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let Qn=new Map,[$n,er]=y([]),tr=()=>i()||n()||`?`,nr=e=>Qn.get(e)??[],rr=(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?Qn.delete(e):Qn.set(e,r),tr()===e&&er(r)},[ir,ar]=y([]),[or,sr]=y(localStorage.getItem(`teapot.hideGhosts`)===`1`),[cr,lr]=y(!1),ur=()=>ir().filter(e=>!e.read).length,dr=e=>{ar(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},fr=()=>{let e=n();e&&ir().some(t=>!t.read&&t.agentId===e)&&dr(e)},pr=t=>{let n=ir().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=pr(r.id));return n},mr=0,hr=e=>{ar(t=>[{...e,id:`n${++mr}`,at:Date.now(),read:!1},...t].slice(0,50))},gr=(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?hr({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?hr({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?hr({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&hr({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})},_r=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))},vr=S(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of h())if(UE.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}}),[yr,br]=y(new Set),xr=e=>{e&&br(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},Sr=()=>br(new Set),Cr=S(()=>sn(h(),yr())),wr=S(()=>Ft({events:h(),consumed:vr().consumed,pending:$n(),echo:Ar,feedTypes:UE,renderedTypes:GE,renderedNoteEvents:KE})),Tr=()=>wr().rows,Er=()=>wr().pendingCount,Dr=S(()=>{let e=new WeakMap;return Tr().forEach((t,n)=>e.set(t,n)),e}),Or=(e,t)=>{let n=Dr().get(e);if(n!==void 0)return Tr()[n+t]},kr=new Map;function Ar(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=kr.get(t);if(n)return n;kr.size>64&&kr.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 kr.set(t,r),r}let jr=()=>Y(`/api/config`).then(ae).catch(()=>{}),[Mr,Nr]=y(!1);w(()=>{let e=()=>Nr(!0);window.addEventListener(`teapot:unauthorized`,e),T(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[Pr,Fr]=y(``),[Ir,Lr]=y(!0),[Rr,zr]=y(!1),Br=``;x(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==Br?(Br=t,zr(!1),Fr(r)):t&&!Rr()&&Fr(r)});let Vr=async()=>{let e=document.getElementById(`todo-notify`)?.checked??!0;if(n())try{await Y(`/api/agents/${n()}/todo`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:Pr(),notify:e})}),zr(!1),Lr(!0),VE(`tasks saved${e&&Pr().trim()?` & notification queued`:``}`),Wr()}catch(e){VE(`save failed: ${e.message}`)}},Hr=S(()=>{let e=0,t=0;for(let n of Pr().split(`
183
183
  `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}});function Ur(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 Wr=()=>Y(`/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),Ur(t,e.agents??[]))),n&&m()}).catch(()=>{}),Gr=()=>Y(`/api/metrics`).then(D).catch(()=>{}),[Kr,qr]=y([]),Jr=()=>Y(`/api/tasks`).then(e=>qr(e.tasks)).catch(()=>{}),Yr=e=>Kr().filter(t=>t.agent===e),[Xr,Zr]=y((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.expandedSubs`)??`[]`);return new Set(e.filter(e=>typeof e==`string`))}catch{return new Set}})()),[Qr,$r]=y((()=>{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}})()),ei=e=>Qr().has(e)||!Xr().has(e),ti=e=>{let t=new Set(Xr());if(t.has(e)?t.delete(e):t.add(e),Zr(t),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...t])),t.has(e)&&Qr().has(e)){let t=new Set(Qr());t.delete(e),$r(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))}},ni=t=>rn(e(),t),[ri,ii]=y((()=>{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}})()),ai=S(()=>{let e=new Set;for(let t of ri())t.startsWith(`chat:`)&&e.add(t);return e}),oi=S(()=>Qt(e(),new Set(e().filter(e=>ei(e.id)).map(e=>e.id)),or(),ai())),si=(t,r,i,a)=>{let o=new Set(ri());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||ni(e().find(e=>e.id===i))===t)&&VE(`hid ${r} — click the header to show it`)}ii(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},ci=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,li=e=>{let t=V().get(e)??0;return`${t} chat${t===1?``:`s`}`},V=S(()=>an(e())),ui=S(()=>on(e(),oi(),ri())),[di,H]=y(null),fi=new Map,pi=()=>{g([]),fi.clear(),mi=0},mi=0;function hi(e){return`${i()||(n()??`?`)}:${e.id}`}function gi(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=hi(r),a=fi.get(i);if(t[n]=a??r,!a)for(fi.set(i,r),mi+=Ri(r);fi.size>4e3||mi>8388608;){let e=fi.keys().next().value;if(e===void 0)break;let t=fi.get(e);t&&(mi-=Ri(t)),fi.delete(e)}}return t}let[_i,vi]=y(!1),[yi,bi]=y(!1),[xi,Si]=y(!1),Ci=0,wi=-1;function Ti(e){let t=gi(e);g(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 Ei(){let e=n();if(!e||xi()||_i()||It())return;if(h().length>=_()){Si(!0);return}let t=()=>{let e=U();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!xi()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(h().length>=_()){Si(!0);return}let i=h().length;if(await Di(),h().length===i)return;Ge(ji())&&n()===e&&Pi(!0)}}async function Di(){let e=n(),t=h()[0];if(e&&t&&!_i()&&!xi()){vi(!0);try{let r=U(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=di(),c=i(),l=(await Y(ki(e,{before:t.id},c,s))).events??[];if(l.length===0){Si(!0);return}if(n()!==e||h()[0]?.id!==t.id)return;Ti(l),requestAnimationFrame(()=>{if(n()===e){let e=U();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{vi(!1)}}}function Oi(e,t){return t&&o().has(t)?`&session=${encodeURIComponent(t)}`:``}function ki(e,t,n,r){let i=[`/api/agents/${encodeURIComponent(e)}/events?limit=2000`];t.before&&i.push(`&before=${encodeURIComponent(t.before)}`),t.after&&i.push(`&after=${encodeURIComponent(t.after)}`);let a=Oi(e,n);return a&&i.push(a),r&&i.push(`&branch=${encodeURIComponent(r)}&lineage=true`),i.join(``)}async function Ai(e,t){let r=Ci,a=t??i()??``;try{let t=di(),i=r!==wi||!ee().length;h().length||bi(!0),Y(`/api/agents/${e}/skills`).then(t=>{r===Ci&&n()===e&&Xa(t.skills??[])}).catch(()=>{});let[o,s]=await Promise.all([Y(ki(e,{},a,t)),i?Y(`/api/agents/${e}/branches`):Promise.resolve({branches:ee()})]);if(i&&(wi=r),r!==Ci||n()!==e)return;g(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of gi(o.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),v(o.total??o.events.length),E(s.branches)}catch{}finally{bi(!1)}}function U(){return document.querySelector(`.feed`)}function ji(){let e=U();return e?{top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight}:null}function Mi(){return Ge(ji())}function Ni(){let e=U();if(!e)return;let t=()=>e.isConnected?(e.scrollTop=e.scrollHeight,co={top:e.scrollTop,height:e.scrollHeight},!0):!1;if(!t())return;Vt(0);let n=r=>{e.isConnected&&It()&&(Ye(It(),{top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight})&&t(),r>0&&requestAnimationFrame(()=>n(r-1)))};requestAnimationFrame(()=>n(2)),zt&&clearTimeout(zt),zt=setTimeout(()=>n(0),250)}function Pi(e=!1){(e||It())&&Ni()}let Fi=new Map,Ii=new Map,Li=8388608,Ri=e=>Qe(e),zi=(t,n)=>ln(c().get(t),e().find(e=>e.id===t)?.session,n);async function Bi(e,t=!0,s){let l=n(),u=i(),d=h(),f=_();Ci++,c().size||m();let p=zi(e,s),ee=s&&o().has(s)?s:null,y=p??ee??e;if(l!==e||y!==u){{let e=U(),t=e?Ee(e):null,n=u||l;if(e&&n&&t){let r=e.querySelector(t.sel)?.dataset.eid??``,i=e.scrollHeight-e.scrollTop-e.clientHeight<=24;for(r&&Ii.set(n,{eid:r,delta:e.getBoundingClientRect().top-t.top,atTail:i});Ii.size>24;){let e=Ii.keys().next().value;if(e===void 0)break;Ii.delete(e)}}}if(u&&d.length){let e=d.reduce((e,t)=>e+Ri(t),0);e<=Li&&Fi.set(u,{events:d,total:f,at:Date.now(),bytes:e}),Ze(Fi,{maxEntries:6,maxBytes:Li})}pi(),Sr(),Yt(null),Vt(0),Rt(Ii.get(y)?.atTail??!0),so=void 0}r(e),a(y),k(O.get(e)??``),H(null),Si(!1),vi(!1),rr(u||l||`?`,$n()),er(nr(y||e)),localStorage.setItem(`teapot.session`,e),Qi(y,t);let b=Fi.get(y);if(b?.events.length&&(g(gi(b.events)),v(b.total),bi(!0),Ii.has(y)||requestAnimationFrame(()=>{n()===e&&Pi(!0)})),Y(`/api/agents/${e}/load`,{method:`POST`}).then(Wr).catch(()=>{}),await Ai(e,y),n()!==e)return;xn(t=>{let n=t.get(e)??null,r=vt(n,h(),z()?.status);if(r===n)return t;let i=new Map(t);return r?i.set(e,r):i.delete(e),i}),Yt(z()?.ctx?.compacting?{phase:String(z().ctx.compacting)}:null);let x=Ii.get(y);Rt(!x||x.atTail),requestAnimationFrame(()=>{if(n()===e){if(x){let e=U(),t=e?.querySelector(`[data-eid="${CSS.escape(x.eid)}"]`);if(e&&t){e.scrollTop+=t.getBoundingClientRect().top-e.getBoundingClientRect().top+x.delta,co={top:e.scrollTop,height:e.scrollHeight},x.atTail&&Pi(!0);return}x.atTail&&Pi(!0)}else Pi(!0)}}),Ei()}let[Vi,Hi]=y(!1),Ui=null,Wi=null;T(()=>Ui?.close());let Gi=!1,Ki=null;document.addEventListener(`visibilitychange`,()=>Ki?.()),T(()=>{Ki=null});let qi=!0,Ji=null;async function Yi(){let e=n(),t=h().at(-1)?.id,r=i(),a=document.visibilityState===`hidden`;if(!e||!t)Gi=!0,a||Ji?.();else try{let n=di(),i=await Y(ki(e,{after:t},r,n)),o=i.events??[];i.gap?(g(gi(o)),v(o.length)):o.length&&(Ti(o),v(e=>e+o.length)),await Wr(),o.length&&!a&&Gr()}catch{Gi=!0}}function Xi(){qi=!0;let r=location.protocol===`https:`?`wss://`:`ws://`,a=new WebSocket(`${r}${location.host}/api/ws${JE()}`);Ui=a,a.onopen=()=>{Hi(!0),qi?qi=!1:Yi()},a.onclose=()=>{Hi(!1),setTimeout(Xi,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=>Ur(e,c.agents));let n=e();xn(e=>_t(e,e=>n.find(t=>t.id===e)?.status))}else if(c.kind===`event`&&lt(c.event))xn(e=>ct(e,c.agentId));else if(c.kind===`llm-delta`){if(!_n(c,n(),i()))return;if(xn(e=>st(e,c.agentId,c)),c.agentId===n()){let e=String(c.reasoning??``),t=String(c.text??``);e&&!t?Ln()||Rn(Date.now()):t&&Rn(0)}}else if(c.kind===`compaction-progress`){if(c.agentId!==n())return;c.phase===`done`?Yt(null):Yt({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]:Ur(e,e.map((e,n)=>n===t?c.snapshot:e))});else if(c.kind===`metrics`&&c.metrics)D(c.metrics);else if(c.kind===`tasks`&&Array.isArray(c.tasks))qr(c.tasks);else{if(c.kind===`event`){let e=c.event?.type,t=c.event?.data??{};if(e===`system_note`&&(t.event===`prompt-delivered`||t.event===`prompt-cancelled`)){let e=String(t.promptId??``);if(e){let t=String(c.event?.session??``),n=new Set;t&&n.add(t),n.add(tr());for(let[t,r]of Qn)r.some(t=>t.promptId===e)&&n.add(t);for(let t of n){let n=nr(t);n.some(t=>t.promptId===e)&&rr(t,n.filter(t=>t.promptId!==e))}}}if(o.has(e)&&!WE.has(e)||(gr(c.agentId,c.event),c.event?.agent!==n())||!gn(c.event,n(),i())||(Ti([c.event]),c.event&&Pn(),Gi=!0,document.visibilityState!==`visible`)||Wi)return;Wi=setTimeout(s,60)}document.visibilityState===`hidden`?Gi=!0:Wi||=setTimeout(s,120)}}},Gi=!1;let s=async()=>{if(Wi=null,n()){let e=h().at(-1)?.id,t=h().length,r=Cn();r&&!vt(r,h(),z()?.status)&&Mn(null),h().at(-1)?.id!==e&&(It()?(Ni(),dr(n())):(Vt(e=>e+Math.max(0,h().length-t)),qt(ji())))}};Ji=s,Ki=()=>{document.visibilityState===`visible`&&(Gr(),Jr(),n()&&(Gi?(Gi=!1,s()):h().at(-1)?.id?Yi():(Gi=!0,s())))}}let Zi=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function Qi(t,n=!0){let r=un(t,o(),e().map(e=>e.id));if(!r)return;let i=`/session/${encodeURIComponent(r)}`;n?history.pushState(null,``,i):history.replaceState(null,``,i)}window.addEventListener(`popstate`,()=>{let e=Zi(),t=o().get(e);t&&(t!==n()||e!==i())&&Bi(t,!1,e||null)}),x(()=>{let e=z(),t=e?`${Yn()?`▶ `:e.status===`error`?`⚠ `:``}${An(e)} · teapot`:`teapot`;document.title=ur()>0?`(${ur()}) ${t}`:t});let $i=()=>oe()||ue()||Zn()!==null||pe()&&De();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(oe()){se(!1);return}if(ue()){de(!1);return}if(Zn()){B(null);return}if(pe()&&De()){Pe();return}let e=z();if(e&&Yn()){Y(`/api/agents/${e.id}/stop`,{method:`POST`}).then(Wr);return}}else if(!$i()){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)Ne();else if(e.key===`t`)pa();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=oi().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&&Bi(t[i].id)}}});let[ea,ta]=y(localStorage.getItem(`teapot.term`)===`1`),[na,ra]=y([]),[ia,aa]=y(!1),oa=async()=>{let e=n();if(!e)return;let t=await Y(`/api/agents/${encodeURIComponent(e)}/bg-jobs`).catch(()=>null);t?.jobs&&ra(t.jobs)};x(()=>{n(),oa()}),x(()=>{if(!ia())return;let e=setInterval(()=>void oa(),2e3);T(()=>clearInterval(e))});let[sa,ca]=y(!1),[la,ua]=y(``),da=()=>{let e=z();e&&(ua(An(e)),ca(!0))},fa=async()=>{if(!sa())return;let e=z();ca(!1);let t=la().replace(/\s+/g,` `).trim();if(!e||!t||t===An(e))return;let n=await Y(`/api/agents/${encodeURIComponent(e.id)}/session-title?session=${encodeURIComponent(e.session)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({title:t})}).catch(e=>({error:String(e)}));n?.error?VE(`rename failed: ${n.error}`):(d(n=>new Map(n).set(e.session,t)),Wr())},pa=()=>{let e=!ea();ta(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[ma,ha]=y([]),[ga,_a]=y(0),[va,ya]=y(-1),[ba,xa]=y(!1),[Sa,Ca]=y(0),[wa,Ta]=y(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),Ea=new Map,Da=[null,null],Oa=()=>ma()[Sa()===0?ga():va()]??null;function ka(e){if(!ma()[e])return;let t=Sa(),n=t===0?ga():va(),r=t===0?va():ga(),i=e=>t===0?_a(e):ya(e);r===e?((e=>t===0?ya(e):_a(e))(n),i(e)):n!==e&&i(e)}let Aa=()=>ja();async function ja(e){let t=e??n();if(t){if(ma().filter(e=>e.agentId===t).length>=10)VE(`max 10 shells per agent (${t}) — that's already a lot`);else try{let e=(await Y(`/api/terminals`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agentId:t})})).terminal;if(!e){VE(`could not open a shell`);return}let n=Wu(ma());ha(t=>[...t,{key:e.id,agentId:e.agentId,title:e.title}]),Sa()===0?_a(n):ya(n)}catch(e){VE(`could not open a shell: ${e.message}`)}}}function Ma(e){let t=ma()[e];if(!t)return;Y(`/api/terminals/${encodeURIComponent(t.key)}`,{method:`DELETE`}).catch(()=>{});let n=Ea.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),Ea.delete(t.key)}let r=ma().filter((t,n)=>n!==e);ha(r),_a(t=>Ku(t,e,r.length)),ya(t=>t===-1?-1:Ku(t,e,r.length))}x(()=>{Ve(),ze(),pt(),Ue(),ut();for(let[,e]of Ea)bn(e.term)});function Na(){for(let[,e]of Ea){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}Ea.clear()}function Pa(e,t){let n=Ea.get(e.key);if(n&&bn(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 Bu({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:yn()}),a=new Uu;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=()=>`${o}${location.host}/api/agents/${encodeURIComponent(e.agentId)}/term?terminal=${encodeURIComponent(e.key)}${JE()}`,c=new WebSocket(s()),l,u=!1,d=t=>{t.onmessage=t=>{let n=JSON.parse(t.data);n.kind===`data`?i.write(n.data):n.kind===`ping`||(n.kind===`exit`?(u=!0,i.write(`\r\n\x1b[2m[terminal exited ${n.code??``}]\x1b[0m\r\n`),ha(t=>t.filter(t=>t.key!==e.key)),Ea.get(e.key)?.term.dispose(),Ea.delete(e.key)):n.kind===`attach`&&n.error&&(u=!0,i.write(`\r\n\x1b[2m[${n.error}]\x1b[0m\r\n`)))},t.onclose=()=>{!u&&Ea.has(e.key)&&(l||=(i.write(`\r
@@ -185,6 +185,6 @@ Cancel = keep editing your copy`)?(ue(r.current),c({...t,content:r.current}),nf(
185
185
  `),setTimeout(function(){if(l=void 0,!Ea.has(e.key))return;let t=new WebSocket(s());c=t,d(t),t.addEventListener(`open`,()=>h())},1500)))}};d(c),i.onData(e=>{c.readyState===WebSocket.OPEN&&c.send(JSON.stringify({kind:`input`,data:e}))});let f={cols:0,rows:0},p,m=[],h=()=>{try{a.fit()}catch{}c.readyState===WebSocket.OPEN?(i.cols!==f.cols||i.rows!==f.rows)&&(f={cols:i.cols,rows:i.rows},c.send(JSON.stringify({kind:`resize`,cols:i.cols,rows:i.rows}))):g()};function g(){p||=setInterval(()=>{Ea.has(e.key)?c.readyState===WebSocket.OPEN&&(clearInterval(p),p=void 0,h()):(clearInterval(p),p=void 0)},400)}c.addEventListener(`open`,()=>h());let _=r.parentElement??r,v=new ResizeObserver(()=>{m[0]&&clearTimeout(m[0]),m[0]=setTimeout(h,250)});v.observe(_),_!==r&&v.observe(r),setTimeout(h,60),n={el:r,term:i,fit:a,ws:c,ro:v},Ea.set(e.key,n)}return n}function Fa(e){let t=Da[e];if(!t)return;let n=ma()[e===0?ga():va()];if(!n){[...Ea.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Pa(n,t);for(let[e,r]of Ea)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(Sa()===(e===0?0:1))try{r.term.focus()}catch{}})}x(()=>{ma(),ba(),ga(),va(),wa(),requestAnimationFrame(()=>{Fa(0),ba()&&Fa(1)})});let Ia=null;x(()=>{if(!ea())return;let e=n();if(!e||e===Ia)return;Ia=e;let t=ma().map((e,t)=>({t:e,i:t})).filter(t=>t.t.agentId===e);t.length&&ka(t[t.length-1].i)}),x(()=>{let e=ma().length,t=Gu(ga(),e);if(t!==ga()&&_a(t),ba()){let t=Gu(va(),e);t!==va()&&ya(t)}});let La=e=>{e.preventDefault();let t=e.clientY,n=wa(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Ta(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(wa())),requestAnimationFrame(()=>{Fa(0),ba()&&Fa(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},Ra=()=>{let e=!ba();xa(e),e&&(va()<0||va()===ga()||va()>=ma().length)&&ya(qu(ga(),ma().length)),requestAnimationFrame(()=>{Fa(0),ba()&&Fa(1)})};T(Na);let za=e=>t=>{Da[e]=t,t&&requestAnimationFrame(()=>{Fa(e),ba()&&Fa(1),setTimeout(()=>Fa(e),200)})};w(()=>{jr(),Wr().then(async()=>{await m();let t=Zi(),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&&Bi(r.id,!1,t||null)}),Gr(),Jr(),Ua(),Xi(),Y(`/api/terminals`).then(e=>{let t=e.terminals??[];t.length&&(ha(t.map(e=>({key:e.id,agentId:e.agentId,title:e.title}))),ea()&&(_a(0),ya(-1)))}).catch(()=>{}),T(()=>{})});let Ba=[{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`}],[Va,Ha]=y([]),Ua=()=>Y(`/api/personas`).then(e=>Ha(e.personas)).catch(()=>{}),[Wa,Ga]=y(!1),Ka=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},qa=()=>{let t=Ka();return t===null?[]:[...Va().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))},Ja=new Set([`start`,`stop`,`fork`,`compact`]),[Ya,Xa]=y([]),[Za,Qa]=y(null),[$a,eo]=y(-1),W=()=>{let e=ne();if(!e.startsWith(`/`)||e.includes(`
186
186
  `))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=Ba.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Ja.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=Ya().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[]},to,no,ro,io=!1;function ao(e){if(!no){no=document.createElement(`div`),no.setAttribute(`aria-hidden`,`true`);let e=no.style;e.position=`absolute`,e.visibility=`hidden`,e.pointerEvents=`none`,e.top=`0`,e.left=`-9999px`,e.whiteSpace=`pre-wrap`,e.overflowWrap=`anywhere`,e.wordBreak=`break-word`,no.dataset.mirror=``}let t=getComputedStyle(e);for(let e of[`font-family`,`font-size`,`font-weight`,`line-height`,`letter-spacing`,`padding-top`,`padding-bottom`,`padding-left`,`padding-right`,`border-top-width`,`border-bottom-width`,`box-sizing`])no.style.setProperty(e,t.getPropertyValue(e));if(no.style.width=`${e.clientWidth}px`,no.setAttribute(`data-mirror-text`,e.value.endsWith(`
187
187
  `)?`${e.value} `:e.value),ro||(ro=document.createElement(`div`),ro.setAttribute(`aria-hidden`,`true`),ro.style.cssText=`position:absolute;left:-9999px;top:0;pointer-events:none`,document.body.appendChild(ro)),no.parentElement!==ro&&ro.appendChild(no),!io){let e=document.createElement(`style`);e.textContent=`[data-mirror]::after{content:attr(data-mirror-text);white-space:pre-wrap;display:block}`,document.head.appendChild(e),io=!0}return no.scrollHeight}let oo=()=>{if(!to)return;let e=Nt();if(!to.value&&!e){to.style.height=``;return}let t=ao(to),n=e?-1:kn(t,360);to.style.height=n===-1?``:`${n}px`},so,co=null,lo,uo=240,fo=4,po;x(()=>{let e=ne();to&&Dn(HE)&&(On(to.value,e)&&(to.value=e),oo())}),w(()=>{let e=0,t=()=>{e||=requestAnimationFrame(()=>{e=0,oo()})};window.addEventListener(`resize`,t),T(()=>{window.removeEventListener(`resize`,t),e&&cancelAnimationFrame(e)})});let[mo,ho]=y([]),go=e=>{let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));for(let e of t){if(e.size>8e6){VE(`"${e.name}" is over 8 MB — skipped`);continue}let t=new FileReader;t.onload=()=>{ho(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},_o=async(t,r,i)=>{let a=r??n();if(!a)return;let o=mo(),s=e().find(e=>e.id===a)?.session||a;try{let e=await Y(`/api/agents/${a}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t,start:!0,...i?{source:i}:{},...o.length?{images:o}:{}})});rr(s,[...nr(s),{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:t,at:Date.now(),promptId:e.promptId,...o.length?{images:o.map(e=>e.url)}:{}}]),ho([]),Xu(Nt())&&Pt(!1),oo(),It()&&requestAnimationFrame(()=>{It()&&Ni()})}catch(e){k(t),console.error(`send failed:`,e)}},vo=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=Va().some(e=>e.key.toLowerCase()===r),s=e().some(e=>e.id.toLowerCase()===r);try{if(o){if(!a){VE(`usage: @${r} <task>`);return}VE(`🧩 spawned ${(await Y(`/api/agents/${n()}/spawn`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({persona:r,task:a,context:Wa()?`fork`:`none`})})).id}${Wa()?` (forked context)`:``}`),Wr(),k(``)}else if(s){if(!a){VE(`usage: @${r} <message>`);return}await Y(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),VE(`→ delivered to @${r}`),k(``)}else{VE(`unknown @${r} — personas: ${Va().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){VE(`@${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){k(`/goal `);return}if(t===`skill`&&!n){k(`/skill `);return}k(``);try{await yo(t,n)}catch(e){throw k(ne()?`${i}\n${ne()}`:i),e}}else k(``),await _o(i)}},yo=async(e,t)=>{let r=n();if(!r)return;let i=(e,t)=>Y(`/api/agents/${r}${e}`,{method:`POST`,headers:{"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}}).then(Wr);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Bi(r);else if(e===`compact`)VE((await i(`/compact`))?.ran?`context compacted`:`nothing to compact yet`);else if(e===`goal`){if(!t){VE(`usage: /goal <text>`);return}await i(`/goal`,{text:t,notify:!0}),VE(`goal saved & notification queued`)}else if(e===`skill`){if(!t){VE(`usage: /skill <name>`);return}await _o(`[harness] Force-load and follow the skill "${t}" now: call load_skill("${t}") and execute its playbook for the current task.`,void 0,`harness`),VE(`skill "${t}" dispatched`)}else VE(`unknown command "${e}" — /start /stop /fork /goal /skill /compact`)}catch(t){VE(`/${e} failed: ${t.message}`)}},bo,xo=0;x(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!bo)return;let e=Math.min(xo,bo.scrollHeight);Math.abs(bo.scrollTop-e)>1&&(bo.scrollTop=e)})})});let So=e=>()=>n()&&Y(`/api/agents/${n()}${e}`,{method:`POST`}).then(Wr),Co=async()=>{let i=n();if(!i)return;let a=new Set([i,...nn(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 Y(`/api/agents/${i}/archive`,{method:`POST`}).catch(()=>{}),t(e().filter(e=>!a.has(e.id))),m(!0);let s=Ju(e(),a);s?Bi(s.id):(r(null),pi())},wo=async()=>{n()&&(VE(`stopped: ${((await Y(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),Wr())},To=()=>Y(`/api/agents/${z().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await m(!0),await Bi(z().id)}),[Eo,Do]=y(``),[Oo,ko]=y(fn(`goal`)),[Ao,jo]=y(fn(`goalPreview`)),Mo=()=>{let e={"max-height":`none`,"overflow-y":`auto`,resize:`vertical`};return Ao()>0&&(e.height=`${Ao()}px`),e},No=e=>{T(mn(e,e=>{jo(t=>Math.abs(t-e)<1?t:(pn(`goalPreview`,e),e))}))},Po=()=>Oo()>0?{height:`${Oo()}px`}:void 0,Fo=e=>{T(mn(e,e=>{ko(t=>Math.abs(t-e)<1?t:(pn(`goal`,e),e))}))},[Io,Lo]=y(``),[Ro,zo]=y(!1),[Bo,Vo]=y(!0),Ho=``;x(()=>{let e=n();e&&(z()?.goal,e!==Ho&&(Ho=e,zo(!1),Do(``),Lo(``)))});let Uo=async e=>{if(e.preventDefault(),n()&&Eo().trim())try{await Y(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:Eo(),notify:Bo(),...Io().trim()?{verify:Io()}:{}})}),Do(``),Lo(``),zo(!1),Wr()}catch(e){VE(`goal save failed: ${e.message}`)}};return[j(N,{get when(){return Mr()},get children(){var e=kw();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 ce()},children:e=>(()=>{var t=pT(),n=t.firstChild;return b(t=>{var r=Zt(e(),Kt[Kt.length-1]),i=Xt(e());return r!==t.e&&I(n,`src`,t.e=r),i!==t.t&&I(n,`srcset`,t.t=i),t},{e:void 0,t:void 0}),t})()}),(()=>{var t=cT(),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,m=p.firstChild;m.firstChild,R(t,j(N,{get when(){return P(()=>!!me())()&&Fe()},get children(){var e=Aw();return e.$$click=Le,e}}),r),R(r,j(N,{get when(){return me()},get children(){var e=jw(),t=e.firstChild.nextSibling;return t.$$click=Le,e}}),i),R(i,j(M,{get each(){return ui()},children:t=>[j(N,{get when(){return P(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=hT(),n=e.firstChild;return e.$$click=()=>si(`ws:${t.wsHeader}`,ci(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),R(n,()=>t.wsCollapsedGroup?`▸`:`▾`),R(e,()=>ci(t.wsHeader),null),R(e,j(N,{get when(){return(V().get(t.wsHeader)??0)>1||t.wsCollapsedGroup},get children(){var e=mT();return R(e,()=>V().get(t.wsHeader)??0),e}}),null),b(()=>I(e,`title`,t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${li(t.wsHeader)} hidden). Click to show.`:(V().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${li(t.wsHeader)} in this directory`:t.wsHeader||``)),e}}),j(N,{get when(){return P(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=bT(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>Bi(t.a.id),R(r,j(N,{get when(){return en({isSub:!!t.a.parent,collapsed:t.chatCollapsedGroup===!0,hasChildren:e().some(e=>e.parent===t.a.id)})},get fallback(){return xT()},get children(){return(()=>{let e=!t.a.parent,n=e&&ai().has(`chat:${t.a.id}`)||ei(t.a.id);return(()=>{var r=ST();return r.$$click=r=>{if(r.stopPropagation(),e){if(n){if(!Xr().has(t.a.id)){let e=new Set(Xr());e.add(t.a.id),Zr(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}if(Qr().has(t.a.id)){let e=new Set(Qr());e.delete(t.a.id),$r(e),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...e]))}}else if(Xr().has(t.a.id)){let e=new Set(Xr());e.delete(t.a.id),Zr(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}si(`chat:${t.a.id}`,t.a.id,n)}else ti(t.a.id)},R(r,n?`▸`:`▾`),b(()=>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,()=>An({id:t.a.id,sessionTitle:t.a.sessionTitle??u().get(t.a.session??``)})),R(r,(()=>{var e=P(()=>!!t.a.workspaceMissing);return()=>e()?CT():null})(),null),R(r,j(N,{get when(){return pr(t.a.id)>0},get children(){var e=gT();return e.firstChild,R(e,()=>pr(t.a.id),null),b(()=>I(e,`title`,`${pr(t.a.id)} unread notification${pr(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),R(r,j(N,{get when(){return ei(t.a.id)||t.chatCollapsedGroup===!0&&ai().has(`chat:${t.a.id}`)},get children(){return(()=>{let n=nn(e(),t.a.id),r=n.filter(e=>e.live??(e.status===`running`||e.status===`waiting`||e.status===`needs_operator`)).length;return n.length>0?(()=>{var e=wT();return e.firstChild,L(e,`subcount`+(r>0?` live`:``)),R(e,()=>n.length,null),R(e,r>0?` · ▶${r}`:``,null),b(()=>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 _T()}}),null),R(r,j(N,{get when(){return Yr(t.a.id).length>0},get children(){var e=vT();return b(()=>I(e,`title`,Yr(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
188
- `))),e}}),null),R(r,j(N,{get when(){return t.a.goal.status===`done`},get children(){return yT()}}),null),b(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=tn(t.a.id,Va().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.status===`needs_operator`?`waiting for your answer`:t.a.status===`waiting`?`waiting on its own work — resumes by itself`:t.a.status,f=t.a.workspaceMissing?` ghost`:``,p=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:jn({id:t.a.id,sessionTitle:t.a.sessionTitle??u().get(t.a.session??``)});return o!==e.e&&L(r,e.e=o),e.t=Oe(r,s,e.t),c!==e.a&&I(r,`title`,e.a=c),l!==e.o&&L(i,e.o=l),d!==e.i&&I(i,`title`,e.i=d),f!==e.n&&L(a,e.n=f),p!==e.s&&I(a,`title`,e.s=p),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),r}})]})),o.$$click=e=>{e.stopPropagation(),lr(!cr()),cr()||ar(e=>e.map(e=>({...e,read:!0})))},R(o,j(N,{get when(){return ur()>0},get children(){var e=Mw();return R(e,ur),e}}),null),R(a,j(td,{icon:`👻`,get active(){return or()},get title(){return or()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!or();if(sr(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&z()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Bi(t.id)}}}),null),R(a,j(td,{icon:`+`,title:`new agent`,onClick:()=>{jr(),se(!0)}}),null),R(a,j(td,{icon:`⚙️`,title:`settings`,onClick:()=>{jr(),de(!0)}}),null),R(c,`0.37.96`,null),R(d,j(N,{get when(){return te()},get children(){return[`master rss `,P(()=>te().rssMb),`MB · heap `,P(()=>te().heapUsedMb),`MB`,j(N,{get when(){return te().heapTotalMb!==void 0},get children(){return[` · total `,P(()=>te().heapTotalMb),`MB`]}}),j(N,{get when(){return te().externalMb!==void 0},get children(){return[` · ext `,P(()=>te().externalMb),`MB`]}}),Nw(),`load1 `,P(()=>te().loadavg1),` · up `,P(()=>Math.floor(te().uptimeSec/60)),`m`]}})),R(f,j(N,{get when(){return z()?.id},keyed:!0,get fallback(){return TT()},get children(){return[(()=>{var t=Bw(),r=t.firstChild,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(t,j(N,{get when(){return me()},get children(){var e=Pw();return e.$$click=()=>Ie(!Fe()),b(()=>I(e,`aria-expanded`,Fe())),e}}),r),r.$$click=()=>da(),R(t,j(N,{get when(){return sa()},get fallback(){return(()=>{var e=ET();return e.$$click=()=>da(),R(e,()=>An(z())),b(()=>I(e,`title`,`${jn(z(),z().session)} — click to rename`)),e})()},get children(){var e=Fw();return e.addEventListener(`blur`,()=>void fa()),e.$$keydown=e=>{e.key===`Enter`?(e.preventDefault(),fa()):e.key===`Escape`&&(e.preventDefault(),ca(!1))},e.$$input=e=>ua(e.currentTarget.value),Ae(e=>{requestAnimationFrame(()=>{e.focus(),e.select()})},e),I(e,`spellcheck`,!1),b(()=>e.value=la()),e}}),i),R(i,()=>z().status),R(t,j(N,{get when(){return Jn()>0},get children(){var e=Iw(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling;return n.nextSibling,R(e,Jn,t),R(e,()=>Jn()===1?`message`:`messages`,n),R(e,()=>z().status===`stopped`?` (stopped)`:``,null),b(()=>I(e,`title`,(()=>{let e=z().pendingPromptQueue??[],t=e.length||z().pendingPromptIds?.length||z().pendingPrompts||0,n=e.length?e.filter(e=>(e.source??`user`)===`user`).length:t,r=t-n;return`${`${t} message${t>1?`s`:``} queued${r?` — ${n} from you, ${r} from the harness`:` from you`}`}. ${z().status===`stopped`?`This agent is STOPPED, so nothing will run until you press start (or it is resumed).`:`They are handed to the model at its next turn boundary — the timeline shows them as queued… until then.`}`+(n?` Yours can be withdrawn with ✕ cancel while still queued.`:``)})())),e}}),a),R(t,j(N,{get when(){return na().length>0},get children(){var e=Lw();return e.firstChild,e.$$click=()=>{aa(!ia()),ia()&&oa()},R(e,()=>na().filter(e=>e.running).length||na().length,null),R(e,()=>na().some(e=>e.running)?` running`:` done`,null),b(t=>{var n=ia(),r=`background shells — ${na().filter(e=>e.running).length} running, ${na().length} total (click to inspect)`;return n!==t.e&&I(e,`aria-expanded`,t.e=n),r!==t.t&&I(e,`title`,t.t=r),t},{e:void 0,t:void 0}),e}}),a),R(t,j(N,{get when(){return Yr(z().id).length>0},get children(){var e=Rw();return e.firstChild,R(e,()=>Yr(z().id).length,null),b(()=>I(e,`title`,`scheduled tasks:\n${Yr(z().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
188
+ `))),e}}),null),R(r,j(N,{get when(){return t.a.goal.status===`done`},get children(){return yT()}}),null),b(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=tn(t.a.id,Va().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.status===`needs_operator`?`waiting for your answer`:t.a.status===`waiting`?`waiting on its own work — resumes by itself`:t.a.status,f=t.a.workspaceMissing?` ghost`:``,p=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:jn({id:t.a.id,sessionTitle:t.a.sessionTitle??u().get(t.a.session??``)});return o!==e.e&&L(r,e.e=o),e.t=Oe(r,s,e.t),c!==e.a&&I(r,`title`,e.a=c),l!==e.o&&L(i,e.o=l),d!==e.i&&I(i,`title`,e.i=d),f!==e.n&&L(a,e.n=f),p!==e.s&&I(a,`title`,e.s=p),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),r}})]})),o.$$click=e=>{e.stopPropagation(),lr(!cr()),cr()||ar(e=>e.map(e=>({...e,read:!0})))},R(o,j(N,{get when(){return ur()>0},get children(){var e=Mw();return R(e,ur),e}}),null),R(a,j(td,{icon:`👻`,get active(){return or()},get title(){return or()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!or();if(sr(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&z()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Bi(t.id)}}}),null),R(a,j(td,{icon:`+`,title:`new agent`,onClick:()=>{jr(),se(!0)}}),null),R(a,j(td,{icon:`⚙️`,title:`settings`,onClick:()=>{jr(),de(!0)}}),null),R(c,`0.37.97`,null),R(d,j(N,{get when(){return te()},get children(){return[`master rss `,P(()=>te().rssMb),`MB · heap `,P(()=>te().heapUsedMb),`MB`,j(N,{get when(){return te().heapTotalMb!==void 0},get children(){return[` · total `,P(()=>te().heapTotalMb),`MB`]}}),j(N,{get when(){return te().externalMb!==void 0},get children(){return[` · ext `,P(()=>te().externalMb),`MB`]}}),Nw(),`load1 `,P(()=>te().loadavg1),` · up `,P(()=>Math.floor(te().uptimeSec/60)),`m`]}})),R(f,j(N,{get when(){return z()?.id},keyed:!0,get fallback(){return TT()},get children(){return[(()=>{var t=Bw(),r=t.firstChild,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(t,j(N,{get when(){return me()},get children(){var e=Pw();return e.$$click=()=>Ie(!Fe()),b(()=>I(e,`aria-expanded`,Fe())),e}}),r),r.$$click=()=>da(),R(t,j(N,{get when(){return sa()},get fallback(){return(()=>{var e=ET();return e.$$click=()=>da(),R(e,()=>An(z())),b(()=>I(e,`title`,`${jn(z(),z().session)} — click to rename`)),e})()},get children(){var e=Fw();return e.addEventListener(`blur`,()=>void fa()),e.$$keydown=e=>{e.key===`Enter`?(e.preventDefault(),fa()):e.key===`Escape`&&(e.preventDefault(),ca(!1))},e.$$input=e=>ua(e.currentTarget.value),Ae(e=>{requestAnimationFrame(()=>{e.focus(),e.select()})},e),I(e,`spellcheck`,!1),b(()=>e.value=la()),e}}),i),R(i,()=>z().status),R(t,j(N,{get when(){return Jn()>0},get children(){var e=Iw(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling;return n.nextSibling,R(e,Jn,t),R(e,()=>Jn()===1?`message`:`messages`,n),R(e,()=>z().status===`stopped`?` (stopped)`:``,null),b(()=>I(e,`title`,(()=>{let e=z().pendingPromptQueue??[],t=e.length||z().pendingPromptIds?.length||z().pendingPrompts||0,n=e.length?e.filter(e=>(e.source??`user`)===`user`).length:t,r=t-n;return`${`${t} message${t>1?`s`:``} queued${r?` — ${n} from you, ${r} from the harness`:` from you`}`}. ${z().status===`stopped`?`This agent is STOPPED, so nothing will run until you press start (or it is resumed).`:`They are handed to the model at its next turn boundary — the timeline shows them as queued… until then.`}`+(n?` Yours can be withdrawn with ✕ cancel while still queued.`:``)})())),e}}),a),R(t,j(N,{get when(){return na().length>0},get children(){var e=Lw();return e.firstChild,e.$$click=()=>{aa(!ia()),ia()&&oa()},R(e,()=>na().filter(e=>e.running).length||na().length,null),R(e,()=>na().some(e=>e.running)?` running`:` done`,null),b(t=>{var n=ia(),r=`background shells — ${na().filter(e=>e.running).length} running, ${na().length} total (click to inspect)`;return n!==t.e&&I(e,`aria-expanded`,t.e=n),r!==t.t&&I(e,`title`,t.t=r),t},{e:void 0,t:void 0}),e}}),a),R(t,j(N,{get when(){return Yr(z().id).length>0},get children(){var e=Rw();return e.firstChild,R(e,()=>Yr(z().id).length,null),b(()=>I(e,`title`,`scheduled tasks:\n${Yr(z().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
189
189
  `)}`)),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=()=>(Yn()?So(`/stop`):So(`/start`))(),R(f,()=>Yn()?`■ stop`:`▶ start`),R(d,j(N,{get when(){return e().some(e=>e.parent===n())},get children(){return j(td,{icon:`⏹`,title:`stop every sub-agent this agent spawned (descendants included)`,onClick:wo})}}),p),R(d,j(td,{icon:`🗄`,title:`archive this agent — reversible: it leaves the list but keeps its config and history (restore in ⚙️ settings → archive)`,onClick:Co}),null),R(d,j(td,{icon:`⑂`,title:`fork: branch off the conversation here — try things without disturbing the main line`,onClick:To}),null),R(d,j(td,{icon:`⌨`,title:`terminal (t)`,onClick:pa}),null),R(d,j(td,{icon:`▤`,title:`toggle details panel (d)`,get active(){return De()},onClick:Ne}),null),R(t,j(N,{get when(){return ia()},get children(){var e=zw(),t=e.firstChild.firstChild.nextSibling;return t.$$click=()=>aa(!1),R(e,j(N,{get when(){return na().length>0},get fallback(){return DT()},get children(){return j(M,{get each(){return na()},children:e=>(()=>{var t=kT(),n=t.firstChild.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling;return R(r,()=>Sx(e.cmd,80)),R(i,(()=>{var t=P(()=>!!e.detached);return()=>t()?`detached · pid ${e.pid??`?`}`:P(()=>!!e.running)()?it(Date.now()-e.startedAt):`exit ${e.code??`?`}`})(),null),R(i,()=>e.truncated?` · truncated`:``,null),a.$$click=async()=>{await Y(`/api/agents/${encodeURIComponent(z().id)}/bg-jobs/${encodeURIComponent(e.id)}`,{method:`DELETE`}).catch(()=>{}),await oa()},R(a,(()=>{var t=P(()=>!!e.detached);return()=>t()?`forget`:e.running?`kill`:`clear`})()),R(t,j(N,{get when(){return e.tail.trim()},get fallback(){return j(N,{get when(){return e.detached},get children(){var t=AT(),n=t.firstChild.nextSibling;return n.nextSibling,R(t,()=>e.pid??`?`,n),t}})},get children(){var t=OT();return R(t,()=>e.tail),t}}),null),b(t=>{var i=`bgjob-dot `+(e.running?`running`:`done`),o=e.running?`running`:`finished`,s=e.cmd,c=e.detached?`this job survived a harness restart (pid ${e.pid??`?`}) — its output can no longer be read here; stop it yourself if needed`:e.running?`kill this job (whole process group)`:`forget this finished job`;return i!==t.e&&L(n,t.e=i),o!==t.t&&I(n,`title`,t.t=o),s!==t.a&&I(r,`title`,t.a=s),c!==t.o&&I(a,`title`,t.o=c),t},{e:void 0,t:void 0,a:void 0,o:void 0}),t})()})}}),null),e}}),null),b(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`+(Yn()?` danger`:``),s=Yn()?`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=Jw();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r={top:t.scrollTop,height:t.scrollHeight,viewport:t.clientHeight},i=Ke(r,co,lo,po);i===`layout`&&!It()&&fo>0&&Math.abs(r.height-(lo??r.height))>1&&(fo--,we(t,_e)),co=null,lo=r.height,po=r.viewport,so=r,qt(r);let a=It(),o=performance.now();o-ve>100&&(ve=o,_e=Ee(t));let s=Je(a,i,r,so?.top);s!==a&&Rt(s),i===`reader`&&(fo=4),s&&i!==`reader`?(Bt()&&Vt(0),fr(),qe(s,r)&&We(r)>0&&Ni()):s&&Ge(r)&&(Bt()&&Vt(0),fr()),r.top<=4&&n()&&!_i()&&!xi()&&h().length>0&&Di()}),Ae(e=>F(e),e),R(e,j(N,{get when(){return Jt()},children:e=>(()=>{var t=jT();return t.firstChild,R(t,(()=>{var t=P(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?xx(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),R(e,j(N,{get when(){return P(()=>!!xi())()&&Tr().length>0},get children(){return Vw()}}),null),R(e,j(N,{get when(){return _i()},get children(){return Hw()}}),null),R(e,j(N,{get when(){return Tr().length>0},get fallback(){return P(()=>!!yi())()?MT():NT()},get children(){return[j(M,{get each(){return Tr()},children:e=>j(YS,{e,prev:()=>Or(e,-1),next:()=>Or(e,1),get showBranch(){return ee().length>1},res:()=>vr().resFor.get(e.id),get orphan(){return vr().orphanCalls.has(e.id)},onOption:e=>void _o(e),answeredIds:Cr,onAnswered:xr,get agentActive(){return P(()=>!!Xn())()&&gt(e)},onResize:()=>{It()&&Ni()},get agentId(){return n()??void 0},get onCancel(){return e.data?.source===`user`&&e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);Y(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);k(ne()?`${n}\n\n${ne()}`:n),rr(tr(),$n().filter(e=>e.promptId!==t)),VE(`message withdrawn — draft restored`)}).catch(()=>VE(`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?async()=>{Yn()&&(await Y(`/api/agents/${n()}/stop`,{method:`POST`}).catch(()=>{}),await Wr()),B({eventId:e.id,text:String(e.data?.text??``)})}:void 0}})}),j(N,{get when(){return yi()},get children(){return Uw()}}),j(N,{get when(){return P(()=>!!Xn())()&&Cn()},get children(){var e=qw(),t=e.firstChild.nextSibling;return t.firstChild,R(t,j(N,{get when(){return Un().trim()!==``},get children(){var e=Ww(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return R(t,j(kd,{get startedAt(){return zn()}}),null),Ae(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),x(()=>{Un(),t&&(e.scrollTop=e.scrollHeight)})},n),R(n,Un),e}}),null),R(t,j(N,{get when(){return Fn()},get fallback(){return PT()},get children(){return j(N,{get when(){return $t()},get fallback(){return(()=>{var e=Kw();return b(()=>e.innerHTML=Re(Fn()+`▍`)),e})()},get children(){return[Gw(),(()=>{var e=Kw();return b(()=>e.innerHTML=Re(dn()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),j(N,{get when(){return ea()},get children(){var t=$w(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Ta(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(wa()))},n.$$pointerdown=La,R(i,j(M,{get each(){return ma()},children:(e,t)=>(()=>{var n=FT(),r=n.firstChild.nextSibling;return n.$$click=()=>ka(t()),R(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Ma(t())},b(r=>{var i=`termtab`+(Sa()===0&&ga()===t()?` active`:``)+(ba()&&Sa()===1&&va()===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(td,{icon:`+`,title:`new shell in this workspace`,onClick:Aa}),null),R(o,(()=>{var t=P(()=>!!Oa());return()=>t()?e().find(e=>e.id===Oa().agentId)?.workspace.split(`/`).filter(Boolean).pop():z()?.workspace})()),R(a,j(td,{icon:`◫`,get title(){return ba()?`single pane`:`split panes (50/50)`},onClick:Ra}),null),R(a,j(td,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:pa}),null);var l=za(0);return typeof l==`function`&&Ae(l,c),c.$$pointerdown=()=>Ca(0),R(c,j(N,{get when(){return ga()<0||ga()>=ma().length},get children(){return Yw()}})),R(s,j(N,{get when(){return ba()},get children(){return[Xw(),(()=>{var e=Qw(),t=za(1);return typeof t==`function`&&Ae(t,e),e.$$pointerdown=()=>Ca(1),R(e,j(N,{get when(){return va()<0||va()>=ma().length},get children(){return Zw()}})),b(()=>e.classList.toggle(`focused`,Sa()===1)),e})()]}}),null),b(e=>{var n={height:`${wa()}px`},r=!!ba(),i=Sa()===0;return e.e=Oe(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=oT(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling;return R(e,j(N,{get when(){return P(()=>Ht()>32)()&&!It()},get children(){var e=eT();return e.firstChild,e.$$click=()=>{Pi(!0),fr()},R(e,(()=>{var e=P(()=>Bt()>0);return()=>e()?`${Bt()} new message${Bt()>1?`s`:``}`:`jump to present`})(),null),e}}),t),R(e,j(N,{get when(){return W().length>0},get children(){var e=tT();return R(e,j(M,{get each(){return W()},children:(e,t)=>(()=>{var n=IT(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{k(e.insert),eo(-1)},R(r,()=>e.insert.trim()),R(i,()=>e.title),b(r=>{var i=`cmdrow`+(t()===$a()?` 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 qa().length>0},get children(){var e=tT();return R(e,j(M,{get each(){return qa()},children:e=>(()=>{var t=LT(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{k(`@${e.key} `),eo(-1)},R(n,()=>e.key,null),R(r,()=>e.label),b(()=>I(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,vo),R(t,j(N,{get when(){return mo().length>0},get children(){var e=nT(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,R(e,j(M,{get each(){return mo()},children:(e,t)=>(()=>{var n=RT(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>ho(e=>e.filter((e,n)=>n!==t())),b(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,()=>mo().length,n),R(t,()=>mo().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=W();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),eo(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),eo(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&$a()>=0&&!HE?(e.preventDefault(),k(t[$a()].insert),eo(-1)):e.key===`Escape`&&t.length>0?eo(-1):Yu({key:e.key,shiftKey:e.shiftKey,composing:HE,maximized:Nt()})&&(e.preventDefault(),vo(e))},n.$$input=e=>{k(e.currentTarget.value),eo(0),oo()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),go(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{HE=!1}),k(to?.value??``)}),n.addEventListener(`compositionstart`,()=>{HE=!0}),Ae(e=>{to=e,e.value=ne()},n),R(t,j(N,{get when(){return P(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=rT(),t=e.firstChild;return t.addEventListener(`change`,e=>Ga(e.currentTarget.checked)),b(()=>t.checked=Wa()),e}}),r),r.$$click=()=>{let e=!Nt();Pt(e),requestAnimationFrame(()=>oo())},R(r,()=>Nt()?`⤡`:`⤢`),R(t,j(td,{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 mo().length},get children(){var e=iT();return e.firstChild,R(e,()=>mo().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&go(e.currentTarget.files),e.currentTarget.value=``}),R(e,j(N,{get when(){return RE()},get children(){var e=aT();return R(e,RE),e}}),null),b(t=>{var i=`composer`+(Nt()?` maximized`:``),a=`message #${z().id} — / for commands · paste or 📎 to attach images`,o=Nt()?`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(()=>!!me())()&&De()},get children(){var e=sT();return e.$$click=()=>Me(!1),e}}),p),p.addEventListener(`scroll`,e=>{xo=e.currentTarget.scrollTop});var g=bo;return typeof g==`function`?Ae(g,p):bo=p,R(m,j(td,{icon:`✕`,title:`close details panel (esc)`,onClick:Pe}),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(Ow,{agentId:e,get workspace(){return z().workspace}})}),(()=>{var e=BT();return e.firstChild,R(e,j(N,{get when(){return Tt().length},get children(){var e=zT(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>Tt().length,t),e}}),null),e})(),(()=>{var t=UT(),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;Mt=!0,bt(r),St(wn(ie().providers,r,e().find(e=>e.id===n()))),Ot(r)}),R(r,j(M,{get each(){return Dt()},children:e=>(()=>{var t=lE();return t.value=e,R(t,e,null),R(t,()=>e===ie().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>St(e.currentTarget.value),R(o,j(M,{get each(){return Tt()},children:e=>(()=>{var t=lE();return b(()=>t.value=e.id),t})()})),R(t,j(N,{get when(){return z().effortSupported},get children(){var e=VT(),t=e.firstChild.nextSibling;return t.firstChild,t.addEventListener(`change`,e=>wt(e.currentTarget.value)),R(t,j(M,{get each(){return P(()=>!!z().effortOptions?.length)()?z().effortOptions:IE},children:e=>(()=>{var t=lE();return t.value=e,R(t,e),t})()}),null),b(()=>t.value=Ct()),e}}),s),c.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await Y(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:ht(),model:xt().trim()||void 0,contextWindowTokens:Tt().find(e=>e.id===(xt().trim()||void 0))?.contextLength,...z().effortSupported?{reasoningEffort:Ct()}:{}})}),t.textContent=`✓ applied`,Wr()}catch(e){alert(`apply failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},R(l,()=>z().model,null),R(t,j(N,{get when(){return At()},get children(){var e=HT();return R(e,At),e}}),null),b(()=>I(a,`placeholder`,Tn(ie().providers,ht(),z(),Sn(z(),ie().providers,ie().defaultProvider)))),b(()=>r.value=ht()),b(()=>a.value=xt()),t})(),(()=>{var e=WT(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{n()&&Y(`/api/agents/${n()}/auto-continue`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Wr)}),b(()=>t.checked=z().autoContinue??!0),e})(),(()=>{var e=KT();return e.firstChild,R(e,j(N,{get when(){return!!z().goal.text.trim()},get fallback(){return uE()},get children(){var e=GT();return R(e,()=>z().goal.status),b(()=>L(e,`badge ${z().goal.status===`active`?`running`:z().goal.status}`)),e}}),null),e})(),(()=>{var e=qT();return e.firstChild,R(e,j(M,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=dE();return t.$$click=()=>{n()&&Y(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(Wr)},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`),b(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 fE()},get children(){return[(()=>{var e=JT(),t=e.firstChild;return Ae(No,e),b(n=>{var r=Mo(),i=Re(String(z().goal.text));return n.e=Oe(e,r,n.e),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),e})(),j(N,{get when(){return z().goal.verify},get children(){return j(Wt,{title:`🔍️ verification contract`,tone:`tool`,get body(){return String(z().goal.verify)}})}}),j(N,{get when(){return z().goal.audit},children:e=>j(Wt,{get title(){return e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`},get meta(){return ot(e().at)},get tone(){return e().verdict===`approved`?`ok`:`warn`},get body(){return P(()=>!!Lt(e().feedback))()?`_the auditor returned a verdict with no detail_`:e().feedback}})})]}}),(()=>{var e=YT(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,Uo),t.$$input=e=>{Do(e.currentTarget.value),zo(!0)},Ae(Fo,t),n.$$input=e=>{Lo(e.currentTarget.value),zo(!0)},r.addEventListener(`change`,e=>Vo(e.currentTarget.checked)),b(e=>Oe(t,{...Po()??{}},e)),b(()=>t.value=Eo()),b(()=>n.value=Io()),b(()=>r.checked=Bo()),e})(),(()=>{var e=ZT();return e.firstChild,R(e,j(N,{get when(){return Hr().total>0},get children(){var e=XT(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,R(e,()=>Hr().done,t),R(e,()=>Hr().total,n),b(t=>Oe(e,Hr().done===Hr().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),null),e})(),j(N,{get when(){return Hr().total>0},get children(){var e=QT(),t=e.firstChild;return b(e=>{var n=`barfill `+(Hr().done===Hr().total?``:`warn`),r=`${Math.round(Hr().done/Hr().total*100)}%`;return n!==e.e&&L(t,e.e=n),r!==e.t&&ke(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),j(Yd,{get draft(){return Pr()},get preview(){return Ir()},onDraft:e=>{Fr(e),zr(!0)}}),(()=>{var e=$T(),t=e.firstChild,n=t.nextSibling;return R(e,j(td,{get icon(){return Ir()?`✎`:`👁`},get title(){return Ir()?`edit markdown`:`rendered checklist`},onClick:()=>Lr(!Ir())}),t),n.$$click=Vr,e})(),eE(),j(N,{get when(){return z().latestProgress},get fallback(){return pE()},children:e=>(()=>{var t=vE(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return R(t,j(N,{get when(){return e().recent},get children(){var t=mE(),n=t.firstChild.nextSibling;return b(()=>n.innerHTML=rt(e().recent)),t}}),i),R(t,j(N,{get when(){return e().problems},get children(){var t=hE(),n=t.firstChild.nextSibling;return b(()=>n.innerHTML=rt(e().problems)),t}}),i),R(t,j(N,{get when(){return e().next},get children(){var t=gE(),n=t.firstChild.nextSibling;return b(()=>n.innerHTML=rt(e().next)),t}}),i),R(t,j(N,{get when(){return e().goalStatus},get children(){var t=_E(),n=t.firstChild.nextSibling;return R(n,()=>e().goalStatus),t}}),i),R(i,()=>ot(e().ts)),b(()=>r.innerHTML=rt(e().doing)),t})()}),tE(),(()=>{var e=iE(),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;return R(e,j(N,{get when(){return z().ctx},keyed:!0,get fallback(){return yE()},children:e=>{let t=S(()=>{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=CE(),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,()=>xx(r().usedTokens),o),R(t,j(N,{get when(){return r().effectiveWindow},get children(){var e=bE(),t=e.firstChild;return R(e,()=>i(r().pct),t),R(e,()=>xx(r().effectiveWindow),null),b(()=>L(e,`pill ${r().cls}`)),e}}),null),R(e,j(N,{get when(){return r().effectiveWindow},get children(){var e=xE(),t=e.firstChild;return b(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&L(t,e.e=n),i!==e.t&&ke(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),R(c,()=>xx(r().usingDerived?r().derivedBudget:r().compactAt),l),R(u,()=>r().usingDerived?`75% of window`:`manual`),R(e,j(N,{get when(){return Jt()||r().compacting},get children(){var e=SE(),t=e.firstChild.nextSibling.nextSibling;return R(t,()=>Jt()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&Y(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Wr)}),b(()=>f.checked=z().autoCompact!==!1),e})()}}),t),R(i,()=>xx(z().stats.inputTokens)),R(o,()=>xx(z().stats.outputTokens)),R(c,()=>z().stats.turns),R(u,()=>z().stats.toolCalls),R(f,()=>z().stats.compactions??0),R(t,j(N,{get when(){return(z().stats.costUsd??0)>0},get children(){var e=nE(),t=e.firstChild.nextSibling;return t.firstChild,R(t,()=>ZE(z().stats.costUsd??0),null),b(()=>I(e,`title`,`≈ ${(z().stats.costUsd??0).toFixed(4)} this session, from the model's per-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=rE(),t=e.firstChild.nextSibling,n=t.firstChild;return R(t,()=>Math.round(z().stats.cachedInputTokens/Math.max(1,z().stats.inputTokens)*100),n),b(()=>I(e,`title`,`${xx(z().stats.cachedInputTokens)} input tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),b(()=>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=oE();return e.firstChild.nextSibling,R(e,j(N,{get when(){return di()},get children(){var e=aE(),t=e.firstChild.nextSibling;return R(t,di),e}}),null),e})(),j(M,{get each(){return ee()},children:e=>(()=>{var t=wE(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=di()===e.branch?null:e.branch,r=t!==di();H(t),n()&&(r&&(Ci++,pi(),v(0),Si(!1)),Ai(n()))},R(r,()=>e.branch,null),R(r,()=>e.branch===z().branch?` (current)`:``,null),R(i,()=>e.events,a),b(n=>{var r=`branch-row`+(e.branch===z().branch||e.branch===di()?` cur`:``),i=e.branch===di()?`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=cE();return e.firstChild,R(e,j(N,{get when(){return Kr().length>0},get children(){var e=sE(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>Kr().length,t),e}}),null),e})(),j(N,{get when(){return Kr().length>0},get fallback(){return TE()},get children(){return j(M,{get each(){return Kr()},children:e=>(()=>{var t=DE(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Bi(e.agent),R(i,()=>e.id),R(a,()=>e.agent,null),R(r,j(N,{get when(){return e.forked},get children(){return EE()}}),null),R(o,()=>e.schedule,s),R(o,(()=>{var t=P(()=>!!e.next);return()=>t()?ot(e.next):`—`})(),null),R(o,(()=>{var t=P(()=>!!e.last);return()=>t()?` · last ${ot(e.last)}`:` · never ran`})(),null),R(c,()=>Sx(e.prompt,90)),b(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Sx(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),b(e=>{var n=`layout`+(De()?``:` right-hidden`)+(Fe()?` left-open`:``),i=`sidebar`+(Fe()?` open`:``),a=`iconbtn notifbtn`+(ur()>0?` has-unread`:``),s=ur()>0?`${ur()} unread notifications`:`notifications`,c=`conn`+(Vi()?` ok`:``),u=Vi()?`live (websocket)`:`reconnecting…`,d={"--termh":`${wa()}px`},m=`rightbar`+(De()?` open`:``);return n!==e.e&&L(t,e.e=n),i!==e.t&&L(r,e.t=i),a!==e.a&&L(o,e.a=a),s!==e.o&&I(o,`title`,e.o=s),c!==e.i&&L(l,e.i=c),u!==e.n&&I(l,`title`,e.n=u),e.s=Oe(f,d,e.s),m!==e.h&&L(p,e.h=m),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}),t})(),j(N,{get when(){return cr()},get children(){return[(()=>{var e=lT();return e.$$click=()=>lr(!1),e})(),(()=>{var t=fT(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return R(r,j(N,{get when(){return ir().length>0},get children(){var e=uT();return e.$$click=()=>ar([]),e}}),i),i.$$click=()=>lr(!1),R(t,j(N,{get when(){return ir().length>0},get fallback(){return OE()},get children(){var t=dT();return R(t,j(M,{get each(){return ir()},children:t=>(()=>{var r=AE(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{ar(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&Bi(t.agentId),lr(!1),t.eventId&&setTimeout(()=>_r(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,()=>ot(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),ar(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=kE();return R(e,()=>XE(t.body,160)),e}}),null),b(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 oe()},get children(){return j(QE,{get providers(){return Object.keys(ie().providers??{})},onClose:()=>se(!1),onCreated:e=>{se(!1),Wr(),Bi(e)}})}}),j(N,{get when(){return ue()},get children(){return j(aw,{get cfg(){return ie()},onClose:()=>de(!1),announcedOAuth:A,get skills(){return Ya()},get hasSelection(){return!!n()},get agentId(){return n()},get features(){return Za()},onSaved:()=>{jr(),Jr()},theme:{themes:nt,activeId:ze,paintedId:le,auto:Ve,setAuto:e=>{He(e),localStorage.setItem(`teapot.theme.auto`,e?`1`:`0`)},dark:ut,setDark:dt,light:Ue,setLight:$e,setThemes:at,setActive:Be,preview:e=>tt(e),commitAppearance:e=>{localStorage.setItem(`teapot.theme.auto`,e.auto?`1`:`0`),localStorage.setItem(`teapot.theme.dark`,e.dark),localStorage.setItem(`teapot.theme.light`,e.light),localStorage.setItem(`teapot.theme`,e.fixed)}}})}}),j(N,{get when(){return Zn()},fallback:null,children:e=>{let t=()=>h().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,h().length-t()-1);return j(rd,{title:`edit prompt — forks the conversation`,onClose:()=>B(null),get children(){var t=ME(),i=t.firstChild,a=i.nextSibling,o=a.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await Y(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value})}),B(null),Wr();let t=n();t&&await Bi(t)}catch(e){alert(`edit failed: ${e.message}`)}}),R(t,j(N,{get when(){return r()>0},get children(){var e=jE(),t=e.firstChild;return R(e,r,t),e}}),a),o.$$click=()=>B(null),b(()=>i.value=e().text),t}})}})]}function XE(e,t){return e.length>t?e.slice(0,t)+` …`:e}function ZE(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 QE(e){let[t,n]=y(`~`),[r,i]=y([]),[a,o]=y(``),[s,c]=y(e.providers[0]??``),[l,u]=y(``),[d,f]=y(``);async function p(e){let r=await Y(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}w(()=>p(t()));let[m,h]=y(``),g=async n=>{n.preventDefault(),f(``);try{let n=await Y(`/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(rd,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=PE(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,ee=f.nextSibling,y=ee.nextSibling,x=y.firstChild,S=x.firstChild.nextSibling,C=x.nextSibling,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=y.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),R(ee,j(M,{get each(){return r()},children:e=>(()=>{var n=FE();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),R(n,e,null),n})()})),S.$$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=lE();return R(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),R(i,j(N,{get when(){return d()},get children(){var e=NE();return R(e,d),e}}),E),b(()=>h.value=t()),b(()=>S.value=a()),b(()=>w.value=s()),b(()=>T.value=l()),i}})}Ee([`click`,`input`,`keydown`,`pointerdown`,`dblclick`]),Te(()=>j(YE,{}),document.getElementById(`root`));
190
- //# sourceMappingURL=index-BEbEcUgx.js.map
190
+ //# sourceMappingURL=index-CWMSn0wv.js.map