teapot-coding-agent 0.37.201 → 0.37.203
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent.js +22 -20
- package/package.json +1 -1
- package/public/assets/{index-DlXjDc6K.js → index-CeTEMDJa.js} +4 -4
- package/public/assets/index-CeTEMDJa.js.map +1 -0
- package/public/assets/{index-lrkXbZYj.css → index-DQ00J4Kn.css} +1 -1
- package/public/index.html +2 -2
- package/public/assets/index-DlXjDc6K.js.map +0 -1
|
@@ -178,14 +178,14 @@ XID_Start XIDS`.split(/\s/).map(e=>[Uy(e),e])),Ib=new Map([[`s`,xb(383)],[xb(383
|
|
|
178
178
|
`).length>1?e:n}catch{return e}}var uS=12e4,dS=6e5,fS=e=>{let t=Number(e);return Math.min(Number.isFinite(t)&&t>0?t:uS,dS)},pS=F(`<div><div class=goalline-label>`),mS=F(`<div>`),hS=F(`<div class=qfree><input type=text><button>reply`),gS=F(`<div class=meta>`),_S=F(`<div class=meta>waiting for output…`),vS=F(`<div class="meta bgjob-note">runs in background — poll with <b>bash_output(job_id="<!>")`),yS=F(`<b>action="kill"`),bS=F(`<div class=meta>writing…`),xS=F(`<pre class="mono toolbody del">`),SS=F(`<pre class="mono toolbody add">`),CS=F(`<div class=meta> · `),wS=F(`<div class=meta>applying…`),TS=F(`<pre class="mono toolbody patch">`),ES=F(`<div class=meta>validating…`),DS=F(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),OS=F(`<span class=muted>`),kS=F(`<div class=content>`),AS=F(`<div class=meta>loading…`),jS=F(`<div class=meta>bundled: `),MS=F(`<div class=meta>saving…`),NS=F(`<div class=meta>found: `),PS=F(`<div class=meta>no matches`),FS=F(`<span class=actor>@`),IS=F(`<details><summary><b></b><span class=meta></span><span class=toolcopy>`),LS=F(`<div class=divider-msg>⑂ forked from <!> → `),RS=F(`<div> → `),zS=F(`<div class=divider-msg>🗜 compacted: <!> → <!> tok (<!>)`),BS=F(`<div class=divider-msg title="compaction is rewriting older history — the agent is not stuck">🗜 compacting: summarizing <!> earlier messages from <!> tok (<!>)…`),VS=F(`<span class=ts>`),HS=F(`<button class=editbtn title="withdraw this message — it has not reached the model yet; the text goes back to the input box">✕ cancel`),US=F(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),WS=F(`<div class=msg-head><span></span><span class=ts>`),GS=F(`<div><div></div><div class=msg-body>`),KS=F(`<span class=grouptime>`),qS=F(`<div class=promptimgs>`),JS=F(`<img class=promptimg alt="tool image"loading=lazy title="click to enlarge">`,!0,!1,!1),YS=F(`<img class=promptimg alt=attachment title="click to enlarge">`),XS=F(`<details class=reasoning><summary>💭 thinking</summary><div class=mono>`),ZS=F(`<div class=interrupted>⚠ interrupted — partial output kept`),QS=F(`<div class=meta>its call is no longer in the loaded events — the run itself finished`),$S=F(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>`),eC=F(`<div class="content muted">Rejected: `),tC=F(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged`),nC=F(`<div class="meta answerdone">✓ answered — continuing below`),rC=F(`<div class=qopts>`),iC=F(`<div><div>❓️ <div class="content inline-md">`),aC=F(`<button class=qopt>`),oC=F(`<div class=progrow><b>goal</b><span>`),sC=F(`<div class=progrow><b>recent</b><span class="content inline-md">`),cC=F(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),lC=F(`<div class=progrow><b>next</b><span class="content inline-md">`),uC=F(`<div class="embed progembed"><div class="meta copyrow"></div><div>📈 <div class="content inline-md">`),dC=F(`<div class="embed fail"><div class=mono>⚠ `),fC=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`),pC=F(`<div class="embed compaction"><b>🗜 context compacted</b><span class=meta> · <!> → <!> tok · `),mC=F(`<div class="vtitle compactkept">what the agent kept`),hC=F(`<details class="embed compaction"><summary><b>🗜 context compacted</b><span class=meta> · <!> → <!> tok · </span></summary><div class="meta copyrow below">`),gC=F(`<div class="content muted">`);function _C(e){return j(N,{get when(){return!e.divider},get fallback(){return(()=>{var t=mS();return R(t,()=>e.label),x(()=>L(t,`divider-msg`+(e.tone===`err`?` err`:``))),t})()},get children(){var t=pS(),n=t.firstChild;return R(n,()=>e.label),R(t,j(N,{get when(){return e.body},get children(){return j($t,{get tone(){return P(()=>e.tone===`err`)()?`warn`:e.tone??`tool`},get markdown(){return e.markdown??!1},get body(){return e.body??``}})}}),null),x(()=>L(t,`goalline `+(e.tone??``))),t}})}function vC(e){let[t,n]=b(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=hS(),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,x(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}),x(()=>a.value=t()),i})()}function yC(e){let t=e.e,n=iS(e.prev,t),r=C(()=>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`?fS(l(`timeout_ms`)):s===`wait_children`?Number(l(`timeout_ms`))||3e5:Number(l(`timeout_ms`))||void 0,f=(e,t,n)=>j(bf,{text:e,lang:n}),p=e=>j(bf,{get text(){return JSON.stringify(e??o.args??{},null,1)},lang:`json`}),m=()=>(()=>{let t=i();return t?[P(()=>P(()=>!!$d(c()))()?j(yf,{get text(){return c()}}):j(bf,{get text(){return lS(c())},get lang(){return cS(c())}})),(()=>{var e=gS();return R(e,()=>en(t.data?.durationMs),null),R(e,()=>s===`bash`?oS(aS(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),e})(),j(SC,{get data(){return t.data},get agentId(){return e.agentId}})]:_S()})(),h=C(()=>{i();let e=s,t=``,n=p(),r=(r,a,o)=>{let s=o??{},c=Object.keys(s);e=c.length?pn(JSON.stringify(s),120):`(no arguments)`,t=i()?en(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?`⏳ `:`$ `)+pn(r,96);let u=l(`timeout_ms`)?Number(l(`timeout_ms`)):void 0,d=i(),f=aS(d?.data?.ok,d?String(d.data?.result??``):``);t=d?a?`background job${s?` ${s}`:``}${u?` · timeout ${Math.round(u/1e3)}s`:``}`:sS({outcome:f,durationMs:d.data?.durationMs,timeoutMs:u,fmtDur:en}):null,n=[a?(()=>{var e=vS(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,R(t,s||`?`,n),R(e,s?[` · kill with `,yS()]:null,null),e})():null,j(bf,{text:r,lang:`shellscript`}),P(m)];break}case`read_file`:{let r=Array.isArray(o.args?.paths)?o.args.paths.map(String):[];e=l(`path`)||(r.length?r.length===1?r[0]:`${r[0]} +${r.length-1} more`:`(no path)`);let i=[];l(`pattern`)&&i.push(`grep /${pn(l(`pattern`),40)}/`),Number(o.args?.offset)<0?i.push(`last ${-Number(o.args.offset)} lines`):o.args?.offset&&i.push(`from L${o.args.offset}`),o.args?.limit&&i.push(`≤${o.args.limit} lines`),t=i.join(` · `),n=m();break}case`write_file`:{let r=String(o.args?.content??``),a=l(`path`);e=a||`(no path)`,t=`${fn(r.length)} bytes`,n=[P(()=>f(r,void 0,Yx(a)??void 0)),P(()=>P(()=>!!i())()?(()=>{var e=gS();return R(e,()=>pn(c(),160)),e})():bS())];break}case`edit_file`:e=l(`path`)||`(no path)`,t=o.args?.replace_all===!0?`replace all`:`unique spot`,n=[(()=>{var e=xS();return R(e,()=>`- `+l(`old_text`)),e})(),(()=>{var e=SS();return R(e,()=>`+ `+l(`new_text`)),e})(),P(()=>P(()=>!!i())()?(()=>{var e=CS(),t=e.firstChild;return R(e,()=>pn(c(),120),t),R(e,()=>en(i().data?.durationMs),null),e})():wS())];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`:``}: ${pn(r.join(`, `),80)}`:`patch`,n=[(()=>{var e=TS();return R(e,()=>t.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=mS();return L(n,`pline`+t),R(n,e),n})()})),e})(),P(()=>P(()=>!!i())()?(()=>{var e=gS();return R(e,()=>pn(c().split(`
|
|
180
180
|
`)[0]??``,140),null),R(e,()=>i().data?.ok===!1?` · FAILED`:``,null),e})():ES())];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=pn(r,70),t=`web`,n=[(()=>{var e=gS();return R(e,j(N,{get when(){return/^https?:/i.test(l(`url`))},get fallback(){return(()=>{var e=OS();return R(e,()=>pn(l(`url`),80)),e})()},get children(){var e=DS();return x(()=>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=kS();return x(()=>e.innerHTML=Re(t)),e})(),(()=>{var e=gS();return R(e,()=>en(i().data?.durationMs)),e})()]:AS();break}case`save_skill`:{e=`skill: ${l(`name`)}`,t=pn(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=jS();return e.firstChild,R(e,()=>r.join(`, `),null),e})():null),P(()=>P(()=>!!i())()?(()=>{var e=CS(),t=e.firstChild;return R(e,()=>pn(c(),160),t),R(e,()=>en(i().data?.durationMs),null),e})():MS())];break}case`search_tools`:{e=`🔎 ${pn(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=NS();return e.firstChild,R(e,()=>r.names.join(`, `),null),e})():PS():null),P(m)];break}case`run_tool`:{let a=rn(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()?en(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()?en(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=IS(),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=FS();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(_f,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return d()}}):`running…`})()),R(p,j(Wd,{get text(){return u()},label:`⧉ cmd`,title:`copy the ${s} arguments`}),null),R(p,j(N,{get when(){return i()},get children(){return j(Wd,{get text(){return P(()=>!!$d(c()))()?Qd(c()):c()},label:`⧉ out`,title:`copy this tool's full output (escapes removed)`})}}),null),R(r,()=>h().body,null),x(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 bC(e){let t;return S(()=>{e.html,queueMicrotask(()=>eS(t))}),(()=>{var n=kS(),r=t;return typeof r==`function`?Ae(r,n):t=n,x(()=>n.innerHTML=e.html),n})()}function xC(e){let t=e.e,n=ln(t),r=()=>iS(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&iS(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=LS(),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=Jt(t.data??{});return(()=>{var t=pS(),n=t.firstChild;return R(n,()=>e.label),R(t,j(N,{get when(){return e.hasCard},get children(){return j($t,{get tone(){return P(()=>e.tone===`ok`)()?`ok`:e.tone===`warn`?`warn`:`tool`},get markdown(){return e.markdown},get body(){return e.detail}})}}),null),x(()=>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`,i=e===`reply`&&!!t.data?.text||e===`tool`&&!!t.data?.args;return j(_C,{label:r,get body(){return i?String(e===`reply`?t.data?.text??``:t.data?.args??``):void 0}})}if(t.type===`todo`){let e=String(t.data?.by??`operator`);return j(_C,{label:`✅ tasks updated (${e===`human`?`operator`:e})`,divider:!1})}if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=RS(),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),x(()=>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 j(_C,{tone:`err`,get label(){return`🛑 runaway: ${String(t.data?.failures)} tool failures in a row (limit ${String(t.data?.limit)})`},get body(){return`last: ${String(t.data?.lastTool)} — ${String(t.data?.lastError??``).slice(0,200)}`}});if(e===`error-retry`)return j(_C,{tone:`warn`,get label(){return`↻ API error — retrying (attempt ${String(t.data?.attempt)}) in ${Math.round(Number(t.data?.waitMs)/1e3)}s…`}});if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return j(_C,{divider:!0,tone:e?`err`:`ok`,get label(){return(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)}})}return e===`context-compacted`?(()=>{var e=zS(),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=BS(),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=GS(),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=KS();return x(()=>I(e,`title`,`${un(t.ts)} · ${t.branch}`)),e})()})(),null),R(s,j(N,{get when(){return!r()},get children(){var r=WS(),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=FS();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),a),R(a,(()=>{var e=P(()=>!(!t.data?.pending||t.data?.queued!==!0||t.data?.sent));return()=>e()?`queued…`:P(()=>!!t.data?.cancelled)()?`withdrawn`:un(t.ts)})()),R(r,j(N,{get when(){return e.showBranch},get children(){var e=VS();return R(e,()=>t.branch),e}}),null),R(r,j(N,{get when(){return e.onCancel},get children(){var t=HS();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(Wd,{get text(){return dn(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),R(r,j(N,{get when(){return P(()=>!!(t.data?.final&&typeof t.data?.reasoning==`string`))()&&String(t.data.reasoning).trim()},get children(){return j(Wd,{get text(){return String(t.data?.content??``)},label:`⧉ summary`,title:`copy just the finished summary (without the reasoning above it)`})}}),null),R(r,j(N,{get when(){return e.onEdit},get children(){var t=US();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),x(()=>L(i,`author tone-${cn(n.color)}`)),r}}),null),R(s,j(CC,{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),x(e=>{var s=`msg`+(r()?` grouped`:``)+(i()?` next-grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``)+` tone-${cn(n.color)}`,c=t.id,l=String(t.session??``),u=`avatar avghost tone-${cn(n.color)}`+(r()?` ghosted`:``),d=r()?`${un(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&&I(a,`data-session`,e.a=l),u!==e.o&&L(o,e.o=u),d!==e.i&&I(o,`title`,e.i=d),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),a})()}function SC(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=>Kf(e.agentId,t));return j(N,{get when(){return t().length},get children(){var e=qS();return R(e,j(M,{get each(){return t()},children:e=>(()=>{var t=JS();return t.$$click=()=>tt(e),I(t,`src`,e),t})()})),e}})}function CC(e){let t=e.e;switch(t.type){case`prompt`:{let n=(t.data?.images??[]).map(e=>typeof e==`string`?e:e?.url).filter(e=>typeof e==`string`&&e.length>0).map(t=>Kf(e.agentId,t));return[j(bC,{get html(){return lt(String(t.data.text??``))}}),j(N,{get when(){return n.length},get children(){var e=qS();return R(e,j(M,{each:n,children:e=>(()=>{var t=YS();return t.$$click=()=>tt(e),I(t,`src`,e),t})()})),e}})]}case`message`:return[j(N,{get when(){return P(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=XS(),n=e.firstChild.nextSibling;return R(n,()=>String(t.data.reasoning)),e}}),j(bC,{get html(){return lt(String(t.data.content??``))}}),j(N,{get when(){return t.data.interrupted},get children(){return ZS()}})];case`tool_call`:return j(yC,{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=$S(),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(Wd,{text:n}),null),R(c,n),R(l,()=>en(t.data.durationMs),null),R(l,()=>r===`bash`?oS(aS(t.data.ok,n)):i?``:` · FAILED`,null),R(a,j(N,{get when(){return e.orphan},get children(){return QS()}}),null),x(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=tC(),r=n.firstChild.firstChild.firstChild.nextSibling;return R(n,j(bC,{get html(){return lt(String(t.data?.rationale??``))}}),null),R(n,j(N,{get when(){return e.length},get children(){var t=eC();return t.firstChild,R(t,()=>e.join(` / `),null),t}}),null),x(()=>r.innerHTML=lt(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=iC(),o=a.firstChild.firstChild.nextSibling;return R(a,j(N,{get when(){return i()},get children(){return nC()}}),null),R(a,j(N,{get when(){return n.length>0},get children(){var a=rC();return R(a,j(M,{each:n,children:n=>(()=>{var a=aC();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?X(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Gf(`→ answered @${String(t.data.actor)}`)).catch(()=>Gf(`answer failed`)):e.onOption?.(n)},R(a,n),x(()=>a.disabled=i()),a})()})),a}}),null),R(a,j(vC,{get answered(){return i()},get onOption(){return e.onOption}}),null),x(e=>{var n=`embed question`+(i()?` answered`:``),r=lt(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=uC(),n=e.firstChild,r=n.nextSibling.firstChild.nextSibling;return R(n,j(Wd,{get text(){return[`doing: ${String(t.data.doing??``)}`,t.data.goalStatus?`goal: ${String(t.data.goalStatus)}`:``,t.data.recent?`recent: ${String(t.data.recent)}`:``,t.data.problems?`problems: ${String(t.data.problems)}`:``,t.data.next?`next: ${String(t.data.next)}`:``].filter(Boolean).join(`
|
|
181
|
-
`)},label:`⧉`,title:`copy this progress report`})),R(e,j(N,{get when(){return t.data.goalStatus},get children(){var e=oC(),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=sC(),n=e.firstChild.nextSibling;return x(()=>n.innerHTML=lt(String(t.data.recent))),e}}),null),R(e,j(N,{get when(){return t.data.problems},get children(){var e=cC(),n=e.firstChild.nextSibling;return x(()=>n.innerHTML=lt(String(t.data.problems))),e}}),null),R(e,j(N,{get when(){return t.data.next},get children(){var e=lC(),n=e.firstChild.nextSibling;return x(()=>n.innerHTML=lt(String(t.data.next))),e}}),null),x(()=>r.innerHTML=lt(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=dC(),n=e.firstChild;return n.firstChild,R(n,()=>String(t.data.message??``),null),e})();case`compaction`:return t.data.summary?(()=>{var e=hC(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling;o.nextSibling;var s=n.nextSibling;return R(r,()=>String(t.data.mode??``),i),R(r,()=>fn(Number(t.data.tokensBefore??0)),a),R(r,()=>fn(Number(t.data.tokensAfter??0)),o),R(r,(()=>{var e=P(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),R(s,j(Wd,{get text(){return String(t.data.summary??``)},label:`⧉ summary`,title:`copy the compaction summary`})),R(e,j(N,{get when(){return t.data.summary},get children(){return[mC(),j(bC,{get html(){return lt(String(t.data.summary))}})]}}),null),e})():(()=>{var e=pC(),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,()=>fn(Number(t.data.tokensBefore??0)),i),R(n,()=>fn(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 fC()}}),null),e})();default:return(()=>{var e=gC();return R(e,()=>tn(JSON.stringify(t.data),200)),e})()}}Ee([`input`,`keydown`,`click`]);var wC=(e,t)=>{let n=String(t??``).trim();return!n||/^\d+$/.test(n)?null:e?.[n]??null},TC=[{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 DC=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`),OC=F(`<div class=muted style="margin:6px 0">`),kC=F(`<b>+ duplicate current`),AC=F(`<div class=cfggrid style=margin-top:8px><label class=trow>name<input type=text maxlength=40 placeholder="theme name"></label><label class=trow>appearance<select><option value=dark>dark</option><option value=light>light`),jC=F(`<div class=paletterows>`),MC=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`),NC=F(`<h4 class=cfgsub>background image`),PC=F(`<img sizes=260px alt="current background"decoding=async loading=lazy>`,!0,!1,!1),FC=F(`<span class=bgpick-hint>🖼 replace…`),IC=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.01><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`),LC=F(`<div class=cfggrid><button type=button></button><input type=file accept=image/* style=display:none>`),RC=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.`),zC=F(`<label class=paletterow><input type=color><span class=paletterow-label></span><input class="mono paletterow-hex">`),BC=F(`<span class=bgpick-empty>🖼 choose a background image…`),VC=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.`),HC=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>`),UC=F(`<div class=skilllist>`),WC=F(`<span style=color:var(--err);font-size:13px>`),GC=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>`),KC=F(`<button type=button><span class=cfgmenu-label>`),qC=F(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="default model"><button type=button class="iconbtn 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`),JC=F(`<button type=button title="remove this key">−`),YC=F(`<div class=cfgkeyrow><input type=password>`),XC=F(`<button type=button>+ `),ZC=F(`<option>`),QC=F(`<div class=cfgsub style=margin-bottom:var(--space-1)>`),$C=F(`<div class=themepick>`),ew=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label> ★`),tw=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label>`),nw=F(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),rw=F(`<input placeholder="command (e.g. npx)">`),iw=F(`<input placeholder="args, space separated">`),aw=F(`<input type=password placeholder="paste the token"title="sent as Authorization: Bearer <token>"style=flex:1>`),ow=F(`<input placeholder="header name"style="flex:0 1 150px">`),sw=F(`<input type=password placeholder=value style=flex:1>`),cw=F(`<div class=cfgrow><textarea class=mono rows=2 placeholder="{"Authorization": "Bearer …", "X-Team": "infra"}"title="static headers for every request. Use the bearer option unless the server needs something unusual."style=flex:1>`),lw=F(`<button type=button class=mcpauthorize title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),uw=F(`<span class="mcpstate connected"title="an OAuth access token is usable — disconnect it under the server's details">🔑 authorized`),dw=F(`<span>`),fw=F(`<div class=muted style=font-size:11px;color:var(--warn)>`),pw=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="iconbtn danger"title="remove this MCP server">✕</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`),mw=F(`<option value=oauth selected>`),hw=F(`<span class=muted> · needs a grant (🔑 authorize)`),gw=F(`<details class=mcptools-wrap><summary>show <!> tool</summary><ul class=mcptools>`),_w=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`),vw=F(`<div><div class=mcpresult-head><b>`),yw=F(`<span class=mcptool-desc>`),bw=F(`<li><code class=mono>`),xw=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="iconbtn danger">✕</button></div><textarea rows=2 placeholder="prompt to send">`),Sw=F(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),Cw=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`),ww=F(`<span class=muted>🧩 sub of @`),Tw=F(`<div class=cfgrow><b></b><span class=muted>`),Ew=F(`<div class=muted>`),Dw=F(`<div class=skillbody>`),Ow=F(`<div class=skillrow><button type=button class=skillhead title="show the playbook"><span class=skillcaret></span><b class=mono></b><span class=muted>`),kw=F(`<div class="muted skillbody">`);function Aw(e){let[t,n]=b(e.themes().some(t=>t.id===e.paintedId)?e.paintedId:e.themes()[0]?.id??``),r=()=>Fr(e.themes(),e.paintedId,t()),[i,a]=b({}),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=Nr(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.paintedId),r=xf.find(t=>t.key===e.paintedId),i=t??r??xf[0],a=getComputedStyle(document.documentElement),o={...Cr};for(let{key:e,cssVar:t}of z){let n=Nr(a.getPropertyValue(t));n&&(o[e]=n)}let s=Ar(e.themes().map(e=>e.id).concat(xf.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))Gf(`that file is ${JSON.stringify(t.type||`unknown`)} — pick an image`);else{Gf(`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){Gf(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),Gf(`background image set`)}catch(e){Gf(`upload failed: ${e.message}`)}}}};return(()=>{var t=DC(),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=OC();return R(t,(()=>{var t=P(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,kC(),` 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 `,kC(),`).`]})()),t})()},children:t=>[(()=>{var e=AC(),t=e.firstChild,n=t.firstChild.nextSibling,i=t.nextSibling.firstChild.nextSibling;return n.$$input=e=>s(t=>({...t,label:e.currentTarget.value})),i.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),x(()=>n.value=r().label),x(()=>i.value=r().mode),e})(),(()=>{var e=jC();return R(e,j(M,{each:z,children:e=>(()=>{var t=zC(),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),x(()=>I(t,`title`,e.cssVar)),x(()=>n.value=Nr(r().palette[e.key])??`#000000`),x(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=MC(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...Cr}})),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})(),NC(),(()=>{var e=LC(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),R(t,j(N,{get when(){return r().backgroundImage},get fallback(){return BC()},get children(){return[(()=>{var e=PC();return x(t=>{var n=Fn(r().backgroundImage),i=Pn(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})(),FC()]}})),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=IC(),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})),x(()=>i.value=r().backgroundDim??.55),x(()=>l.value=r().surfaceAlpha??.82),e}}),null),x(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})(),RC()]}),null),t})()}function jw(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]=b(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=b(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]=b(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=b(e.cfg.progressMinChars??4e3),[p,m]=b(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=b(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,v]=b(e.cfg.maxSpawnDepth??3),[y,C]=b(!!e.cfg.shortContext),[w,ee]=b(``),[T,E]=b(!1),[D,O]=b((e.cfg.tasks??[]).map(e=>({...e}))),[te,ne]=b((e.cfg.mcpServers??[]).map(e=>({...e}))),[re,k]=b(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ie,ae]=b({}),[oe,se]=b(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]=b(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]=b(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]=b({}),pe={},me=async(e,t)=>{if(!te()[e])return;let n=await X(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}).catch(()=>null);te()[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]=b({}),[_e,ve]=b({}),ye=e=>{let t=wC(_e(),e);return t&&(t.required||t.authorized)?t:null},be=async()=>{let e=await X(`/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 X(`/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 X(`/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 X(`/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`}}))};S(()=>{F()===`mcp`&&(be(),te().forEach((e,t)=>{e.name&&xe(e.name)}))});let[we,Te]=b(``),[F,Ee]=b(`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]=b([]),je=async()=>{let e=await X(`/api/archived`).catch(()=>null);Ae(e?.agents??[])},Me=()=>ke().filter(e=>!e.parent);S(()=>{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=b(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=>wr[e]??Cr,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]=b(`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=D().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 te()){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 X(`/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:y(),...T()?{password:w()}:{},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=te().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??``));Gf(`${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(Gd,{title:`settings`,onClose:()=>{Ye(),e.onClose()},get children(){var t=GC(),S=t.firstChild,T=S.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,rt=$e.nextSibling.firstChild,it=Be.nextSibling,at=it.firstChild.nextSibling.nextSibling,ot=it.nextSibling,st=ot.firstChild.nextSibling,ct=ot.nextSibling;ct.firstChild;var ut=ct.nextSibling;ut.firstChild;var dt=ut.nextSibling,ft=dt.firstChild.nextSibling.firstChild;ft.firstChild;var pt=ft.nextSibling,mt=dt.nextSibling;mt.firstChild;var ht=mt.nextSibling,gt=ht.firstChild.nextSibling.firstChild.nextSibling.firstChild,_t=gt.firstChild.nextSibling,vt=gt.nextSibling.firstChild.nextSibling,yt=S.nextSibling,bt=yt.firstChild;return t.addEventListener(`submit`,tt),R(T,j(M,{each:Ne,children:e=>(()=>{var t=KC(),n=t.firstChild;return t.$$click=()=>Ee(e.key),R(n,()=>e.label),x(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=qC(),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=YC(),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=JC();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),x(()=>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)),x(()=>a.value=e().name),x(()=>o.value=e().baseUrl),x(()=>s.value=e().model),i})()}),ve),ve.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),R(be,j(M,{each:TC,children:e=>(()=>{var t=XC();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),x(()=>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=ZC();return t.value=e,R(t,e),t})()}),null),R(ge,j(N,{get when(){return c()},get children(){var e=VC(),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=HC(),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(xf.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=ZC();return R(t,()=>e.label),x(()=>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(xf.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=ZC();return R(t,()=>e.label),x(()=>t.value=e.key),t})()})),x(()=>n.value=We()),x(()=>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(),...xf].some(t=>t.mode===e.mode)},get children(){return[(()=>{var t=QC();return R(t,()=>e.title),t})(),(()=>{var t=$C();return R(t,j(M,{get each(){return Fe().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=ew(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>De(e.id,e.mode),R(n,j(Vf,{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),x(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 xf.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=tw(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>De(e.key,e.mode),R(n,j(Vf,{get palette(){return Xe(e.key)}})),R(r,()=>e.label),x(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(Aw,{themes:Fe,get paintedId(){return e.theme.paintedId()},onChange:e=>{let t=Or(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=Or(t);if(r.ok)n=t,Gf(`storage was full — saved without the background image(s)`);else{Gf(r.error??`could not save theme`);return}}Je(n);let r=e=>n.some(t=>t.id===e)||xf.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??xf.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=>{ee(e.currentTarget.value),E(!0)},R($e,j(Bf,{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(Bf,{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(Bf,{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(Bf,{label:`max spawn depth`,get value(){return _()},onValue:e=>v(e),hint:`sub-agent nesting limit (0 = no spawning)`}),null),rt.addEventListener(`change`,e=>C(e.currentTarget.checked)),R(it,j(N,{get when(){return te().length>0},get fallback(){return nw()},get children(){return j(Se,{get each(){return te()},children:(e,t)=>{let n=()=>he()[e().name],r=e=>ne(te().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=pw(),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,y=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,{...te()[t],url:n})},700))},l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>ne(te().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=rw();return t.$$input=e=>r({command:e.currentTarget.value}),x(()=>t.value=e().command??``),t})(),(()=>{var t=iw();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),x(()=>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=mw();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=aw();return e.$$input=e=>{let n=e.currentTarget.value;le(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},x(()=>e.value=ce()[t]??``),e}}),null),R(h,j(N,{get when(){return oe()[t]===`header`},get children(){return[(()=>{var e=ow();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})},x(()=>e.value=ue()[t]??``),e})(),(()=>{var e=sw();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})},x(()=>e.value=ce()[t]??``),e})()]}}),null),R(i,j(N,{get when(){return oe()[t]===`json`},get children(){var e=cw(),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`}))}},x(()=>n.value=re()[t]??``),e}}),v),y.$$click=async()=>{let e=te()[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 X(`/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(()=>!!wC(_e(),String(e().name??``))?.required)()&&!wC(_e(),String(e().name??``))?.authorized},get children(){var n=lw();return n.$$click=()=>void Ce(t,e()),n}}),null),R(v,j(N,{get when(){return wC(_e(),String(e().name??``))?.authorized},get children(){return uw()}}),null),R(v,j(N,{get when(){return n()},get children(){var e=dw();return R(e,(()=>{var e=P(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:P(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),x(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=fw();return R(e,()=>ie()[t]),e}}),null),R(i,j(N,{get when(){return fe()[t]},children:n=>(()=>{var r=vw(),i=r.firstChild,a=i.firstChild;return R(a,()=>n().text),R(i,j(N,{get when(){return n().needsOAuth},get children(){return hw()}}),null),R(r,j(N,{get when(){return(n().tools?.length??0)>0},get children(){var e=gw(),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=bw(),n=t.firstChild;return R(n,()=>e.name),R(t,j(N,{get when(){return e.description},get children(){var t=yw();return R(t,()=>e.description),t}}),null),x(()=>I(t,`title`,e.description??``)),t})()})),e}}),null),R(r,j(N,{get when(){return wC(_e(),String(e().name??``))?.authorized},get children(){var n=_w(),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 X(`/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),x(()=>L(r,`mcpresult `+(n().kind===`err`?`err`:`ok`))),r})()}),null),x(()=>o.value=e().name),x(()=>s.value=e().url??``),x(()=>l.checked=e().enabled!==!1),x(()=>f.value=e().description??``),x(()=>m.value=e().transport??`http`),x(()=>g.value=ye(String(e().name??``))?`oauth`:oe()[t]??`none`),i})()}})}}),at),at.$$click=()=>ne([...te(),{name:``,url:``,transport:`http`,enabled:!0}]),R(ot,j(N,{get when(){return D().length>0},get children(){return j(Se,{get each(){return D()},children:(e,t)=>(()=>{var n=xw(),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=>O(D().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>O(D().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>O(D().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>O(D().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>O(D().filter((e,n)=>n!==t)),u.$$input=e=>O(D().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),x(()=>i.value=e().id),x(()=>a.value=e().agent),x(()=>o.value=e().schedule),x(()=>c.checked=!!e().forked),x(()=>u.value=e().prompt),n})()})}}),st),st.$$click=()=>O([...D(),{id:``,agent:Pe()[0]??``,schedule:`every 30m`,prompt:``}]),R(ct,j(N,{get when(){return Me().length>0},get fallback(){return Sw()},get children(){return j(M,{get each(){return Me()},children:t=>(()=>{var n=Cw(),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 ${nn(new Date(t.archivedAt).toISOString())}`:``})(),null),R(s,()=>t.workspace),c.$$click=async()=>{let n=await X(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await je(),e.onSaved();let r=(n?.ids?.length??1)-1;Gf((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 X(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await je(),e.onSaved(),Gf(`deleted ${t.id} for good`))},x(()=>I(s,`title`,t.workspace)),n})()})}}),null),R(ut,j(M,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Tw(),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=ww();return t.firstChild,R(t,()=>e.parent,null),t}}),null),t})()}),null),R(ft,()=>e.cfg.version??`unknown`,null),pt.$$click=async e=>{try{Te(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await X(`/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 X(`/api/version`);if(!e.version)continue;r===null&&(r=e.uptimeSeconds??null),(e.version!==`0.37.201`||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(mt,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=UC();return R(t,j(M,{get each(){return e.skills},children:t=>{let[n,r]=b(!1),[i,a]=b(null),[o,s]=b(``),c=async()=>{if(n())return r(!1);if(r(!0),i()===null&&e.agentId)try{let n=await X(`/api/agents/${e.agentId}/skills/${encodeURIComponent(t.name)}`);a(String(n.text??``))}catch(e){s(e.message)}};return(()=>{var e=Ow(),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=kw();return R(e,()=>o()||`loading…`),e})()},get children(){var e=Dw();return x(()=>e.innerHTML=lt(String(i()??``))),e}})}}),null),x(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),R(_t,(()=>{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(vt,(()=>{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(yt,j(N,{get when(){return we()},get children(){var e=WC();return R(e,we),e}}),bt),R(bt,(()=>{var e=P(()=>Qe()===`saving`);return()=>e()?`saving…`:P(()=>Qe()===`saved`)()?`✓ saved`:Qe()===`error`?`✕ failed`:`save settings`})()),x(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&&it.classList.toggle(`hide`,t.i=o),s!==t.n&&ot.classList.toggle(`hide`,t.n=s),c!==t.s&&ct.classList.toggle(`hide`,t.s=c),l!==t.h&&ut.classList.toggle(`hide`,t.h=l),u!==t.r&&dt.classList.toggle(`hide`,t.r=u),d!==t.d&&mt.classList.toggle(`hide`,t.d=d),f!==t.l&&ht.classList.toggle(`hide`,t.l=f),p!==t.u&&bt.classList.toggle(`saved`,t.u=p),m!==t.c&&bt.classList.toggle(`error`,t.c=m),h!==t.w&&(bt.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}),x(()=>ke.value=i()),x(()=>Re.checked=He()),x(()=>Ze.value=w()),x(()=>nt.value=p()??``),x(()=>rt.checked=y()),t}})}Ee([`click`,`input`]);var Mw=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Nw=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Pw=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Fw(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Iw(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 Iw(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Mw.has(t)?`image`:Nw.has(t)?`video`:Pw.has(t)?`audio`:null}var Lw=new Map,Rw=e=>{let t=Lw.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Lw.set(e,t)),t},zw=F(`<span class=fsize>`),Bw=F(`<div><span class=ficon></span><span class=fname>`),Vw=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>· `),Hw=F(`<div class=filebox>`),Uw=F(`<div class=muted style=padding:6px>`),Ww=F(`<img>`),Gw=F(`<div class=mediapreview><div class="meta muted"> preview`),Kw=F(`<button title="rendered markdown">👁 preview`),qw=F(`<button title="edit and save back to the workspace">✎ edit`),Jw=F(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),Yw=F(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Xw=F(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Zw=F(`<div class="content mdpreview shikiwrap">`),Qw=F(`<video controls>`),$w=F(`<audio controls>`);function eT(e){let t=Rw(e.agentId),[n,r]=b(new Map),[i,a]=b(t.expanded),[o,s]=b(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=b(t.media),f=e=>{t.media=e,d(e)},[p,m]=b(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=b(``),[v,y]=b(!0),[C,w]=b(localStorage.getItem(`teapot.ignoreMode`)??`dim`),ee=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(C())+1)%3];w(t),localStorage.setItem(`teapot.ignoreMode`,t)},E=e=>C()!==`hide`||!e.ignored,[D,O]=b(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!D(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await k(t,e)}))).then(t=>{O(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&ie(e,n)})},ne=(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 re(e){return k(e,D())}async function k(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await X(`/api/agents/${e.agentId}/tree?${r.toString()}`);return ne(t,i.entries??[])}catch(e){return _(e.message),null}}let ie=(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}),ae=``;S(()=>{let t=e.agentId;t!==ae&&(ae=t,l(new Set),c(null),f(null),r(new Map),y(!0),re(``).then(e=>{ae===t&&(e&&r(new Map([[``,e]])),y(!1))}))});let oe=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 re(e.path);t&&ie(e.path,t)}},[se,ce]=b(``),[le,ue]=b(!1),[de,fe]=b(``),[A,pe]=b(!1),me=e=>/\.(md|markdown|mdx)$/i.test(e),he=0,ge=async e=>{let t=++he;ce(``),ue(!0);try{let{highlightChunks:n}=await Y(async()=>{let{highlightChunks:e}=await Promise.resolve().then(()=>zx);return{highlightChunks:e}},void 0);for await(let r of n(e.path,e.content)){if(he!==t)return;ce(e=>e+r)}}catch{he===t&&ce(``)}finally{he===t&&ue(!1)}};T(()=>{he++});let _e=async(t,n)=>{let r=Iw(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await X(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),fe(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&ge({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Gf(`open failed: ${e.message}`)}},ve=async()=>{let t=o();if(t&&!A()){pe(!0);try{await X(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:de(),baseContent:t.content})}),c({...t,content:de()}),Gf(`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?Gf(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
181
|
+
`)},label:`⧉`,title:`copy this progress report`})),R(e,j(N,{get when(){return t.data.goalStatus},get children(){var e=oC(),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=sC(),n=e.firstChild.nextSibling;return x(()=>n.innerHTML=lt(String(t.data.recent))),e}}),null),R(e,j(N,{get when(){return t.data.problems},get children(){var e=cC(),n=e.firstChild.nextSibling;return x(()=>n.innerHTML=lt(String(t.data.problems))),e}}),null),R(e,j(N,{get when(){return t.data.next},get children(){var e=lC(),n=e.firstChild.nextSibling;return x(()=>n.innerHTML=lt(String(t.data.next))),e}}),null),x(()=>r.innerHTML=lt(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=dC(),n=e.firstChild;return n.firstChild,R(n,()=>String(t.data.message??``),null),e})();case`compaction`:return t.data.summary?(()=>{var e=hC(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling;o.nextSibling;var s=n.nextSibling;return R(r,()=>String(t.data.mode??``),i),R(r,()=>fn(Number(t.data.tokensBefore??0)),a),R(r,()=>fn(Number(t.data.tokensAfter??0)),o),R(r,(()=>{var e=P(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),R(s,j(Wd,{get text(){return String(t.data.summary??``)},label:`⧉ summary`,title:`copy the compaction summary`})),R(e,j(N,{get when(){return t.data.summary},get children(){return[mC(),j(bC,{get html(){return lt(String(t.data.summary))}})]}}),null),e})():(()=>{var e=pC(),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,()=>fn(Number(t.data.tokensBefore??0)),i),R(n,()=>fn(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 fC()}}),null),e})();default:return(()=>{var e=gC();return R(e,()=>tn(JSON.stringify(t.data),200)),e})()}}Ee([`input`,`keydown`,`click`]);var wC=(e,t)=>{let n=String(t??``).trim();return!n||/^\d+$/.test(n)?null:e?.[n]??null},TC=[{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 DC=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`),OC=F(`<div class=muted style="margin:6px 0">`),kC=F(`<b>+ duplicate current`),AC=F(`<div class=cfggrid style=margin-top:8px><label class=trow>name<input type=text maxlength=40 placeholder="theme name"></label><label class=trow>appearance<select><option value=dark>dark</option><option value=light>light`),jC=F(`<div class=paletterows>`),MC=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`),NC=F(`<h4 class=cfgsub>background image`),PC=F(`<img sizes=260px alt="current background"decoding=async loading=lazy>`,!0,!1,!1),FC=F(`<span class=bgpick-hint>🖼 replace…`),IC=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.01><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`),LC=F(`<div class=cfggrid><button type=button></button><input type=file accept=image/* style=display:none>`),RC=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.`),zC=F(`<label class=paletterow><input type=color><span class=paletterow-label></span><input class="mono paletterow-hex">`),BC=F(`<span class=bgpick-empty>🖼 choose a background image…`),VC=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.`),HC=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>`),UC=F(`<div class=skilllist>`),WC=F(`<span style=color:var(--err);font-size:13px>`),GC=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>`),KC=F(`<button type=button><span class=cfgmenu-label>`),qC=F(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="default model"><button type=button class="iconbtn 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`),JC=F(`<button type=button title="remove this key">−`),YC=F(`<div class=cfgkeyrow><input type=password>`),XC=F(`<button type=button>+ `),ZC=F(`<option>`),QC=F(`<div class=cfgsub style=margin-bottom:var(--space-1)>`),$C=F(`<div class=themepick>`),ew=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label> ★`),tw=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label>`),nw=F(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),rw=F(`<input placeholder="command (e.g. npx)">`),iw=F(`<input placeholder="args, space separated">`),aw=F(`<input type=password placeholder="paste the token"title="sent as Authorization: Bearer <token>"style=flex:1>`),ow=F(`<input placeholder="header name"style="flex:0 1 150px">`),sw=F(`<input type=password placeholder=value style=flex:1>`),cw=F(`<div class=cfgrow><textarea class=mono rows=2 placeholder="{"Authorization": "Bearer …", "X-Team": "infra"}"title="static headers for every request. Use the bearer option unless the server needs something unusual."style=flex:1>`),lw=F(`<button type=button class=mcpauthorize title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),uw=F(`<span class="mcpstate connected"title="an OAuth access token is usable — disconnect it under the server's details">🔑 authorized`),dw=F(`<span>`),fw=F(`<div class=muted style=font-size:11px;color:var(--warn)>`),pw=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="iconbtn danger"title="remove this MCP server">✕</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`),mw=F(`<option value=oauth selected>`),hw=F(`<span class=muted> · needs a grant (🔑 authorize)`),gw=F(`<details class=mcptools-wrap><summary>show <!> tool</summary><ul class=mcptools>`),_w=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`),vw=F(`<div><div class=mcpresult-head><b>`),yw=F(`<span class=mcptool-desc>`),bw=F(`<li><code class=mono>`),xw=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="iconbtn danger">✕</button></div><textarea rows=2 placeholder="prompt to send">`),Sw=F(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),Cw=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`),ww=F(`<span class=muted>🧩 sub of @`),Tw=F(`<div class=cfgrow><b></b><span class=muted>`),Ew=F(`<div class=muted>`),Dw=F(`<div class=skillbody>`),Ow=F(`<div class=skillrow><button type=button class=skillhead title="show the playbook"><span class=skillcaret></span><b class=mono></b><span class=muted>`),kw=F(`<div class="muted skillbody">`);function Aw(e){let[t,n]=b(e.themes().some(t=>t.id===e.paintedId)?e.paintedId:e.themes()[0]?.id??``),r=()=>Fr(e.themes(),e.paintedId,t()),[i,a]=b({}),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=Nr(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.paintedId),r=xf.find(t=>t.key===e.paintedId),i=t??r??xf[0],a=getComputedStyle(document.documentElement),o={...Cr};for(let{key:e,cssVar:t}of z){let n=Nr(a.getPropertyValue(t));n&&(o[e]=n)}let s=Ar(e.themes().map(e=>e.id).concat(xf.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))Gf(`that file is ${JSON.stringify(t.type||`unknown`)} — pick an image`);else{Gf(`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){Gf(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),Gf(`background image set`)}catch(e){Gf(`upload failed: ${e.message}`)}}}};return(()=>{var t=DC(),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=OC();return R(t,(()=>{var t=P(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,kC(),` 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 `,kC(),`).`]})()),t})()},children:t=>[(()=>{var e=AC(),t=e.firstChild,n=t.firstChild.nextSibling,i=t.nextSibling.firstChild.nextSibling;return n.$$input=e=>s(t=>({...t,label:e.currentTarget.value})),i.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),x(()=>n.value=r().label),x(()=>i.value=r().mode),e})(),(()=>{var e=jC();return R(e,j(M,{each:z,children:e=>(()=>{var t=zC(),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),x(()=>I(t,`title`,e.cssVar)),x(()=>n.value=Nr(r().palette[e.key])??`#000000`),x(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=MC(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...Cr}})),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})(),NC(),(()=>{var e=LC(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),R(t,j(N,{get when(){return r().backgroundImage},get fallback(){return BC()},get children(){return[(()=>{var e=PC();return x(t=>{var n=Fn(r().backgroundImage),i=Pn(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})(),FC()]}})),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=IC(),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})),x(()=>i.value=r().backgroundDim??.55),x(()=>l.value=r().surfaceAlpha??.82),e}}),null),x(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})(),RC()]}),null),t})()}function jw(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]=b(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=b(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]=b(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=b(e.cfg.progressMinChars??4e3),[p,m]=b(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=b(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,v]=b(e.cfg.maxSpawnDepth??3),[y,C]=b(!!e.cfg.shortContext),[w,ee]=b(``),[T,E]=b(!1),[D,O]=b((e.cfg.tasks??[]).map(e=>({...e}))),[te,ne]=b((e.cfg.mcpServers??[]).map(e=>({...e}))),[re,k]=b(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ie,ae]=b({}),[oe,se]=b(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]=b(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]=b(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]=b({}),pe={},me=async(e,t)=>{if(!te()[e])return;let n=await X(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)}).catch(()=>null);te()[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]=b({}),[_e,ve]=b({}),ye=e=>{let t=wC(_e(),e);return t&&(t.required||t.authorized)?t:null},be=async()=>{let e=await X(`/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 X(`/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 X(`/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 X(`/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`}}))};S(()=>{F()===`mcp`&&(be(),te().forEach((e,t)=>{e.name&&xe(e.name)}))});let[we,Te]=b(``),[F,Ee]=b(`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]=b([]),je=async()=>{let e=await X(`/api/archived`).catch(()=>null);Ae(e?.agents??[])},Me=()=>ke().filter(e=>!e.parent);S(()=>{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=b(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=>wr[e]??Cr,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]=b(`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=D().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 te()){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 X(`/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:y(),...T()?{password:w()}:{},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=te().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??``));Gf(`${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(Gd,{title:`settings`,onClose:()=>{Ye(),e.onClose()},get children(){var t=GC(),S=t.firstChild,T=S.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,rt=$e.nextSibling.firstChild,it=Be.nextSibling,at=it.firstChild.nextSibling.nextSibling,ot=it.nextSibling,st=ot.firstChild.nextSibling,ct=ot.nextSibling;ct.firstChild;var ut=ct.nextSibling;ut.firstChild;var dt=ut.nextSibling,ft=dt.firstChild.nextSibling.firstChild;ft.firstChild;var pt=ft.nextSibling,mt=dt.nextSibling;mt.firstChild;var ht=mt.nextSibling,gt=ht.firstChild.nextSibling.firstChild.nextSibling.firstChild,_t=gt.firstChild.nextSibling,vt=gt.nextSibling.firstChild.nextSibling,yt=S.nextSibling,bt=yt.firstChild;return t.addEventListener(`submit`,tt),R(T,j(M,{each:Ne,children:e=>(()=>{var t=KC(),n=t.firstChild;return t.$$click=()=>Ee(e.key),R(n,()=>e.label),x(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=qC(),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=YC(),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=JC();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),x(()=>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)),x(()=>a.value=e().name),x(()=>o.value=e().baseUrl),x(()=>s.value=e().model),i})()}),ve),ve.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),R(be,j(M,{each:TC,children:e=>(()=>{var t=XC();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),x(()=>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=ZC();return t.value=e,R(t,e),t})()}),null),R(ge,j(N,{get when(){return c()},get children(){var e=VC(),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=HC(),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(xf.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=ZC();return R(t,()=>e.label),x(()=>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(xf.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=ZC();return R(t,()=>e.label),x(()=>t.value=e.key),t})()})),x(()=>n.value=We()),x(()=>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(),...xf].some(t=>t.mode===e.mode)},get children(){return[(()=>{var t=QC();return R(t,()=>e.title),t})(),(()=>{var t=$C();return R(t,j(M,{get each(){return Fe().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=ew(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>De(e.id,e.mode),R(n,j(Vf,{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),x(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 xf.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=tw(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>De(e.key,e.mode),R(n,j(Vf,{get palette(){return Xe(e.key)}})),R(r,()=>e.label),x(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(Aw,{themes:Fe,get paintedId(){return e.theme.paintedId()},onChange:e=>{let t=Or(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=Or(t);if(r.ok)n=t,Gf(`storage was full — saved without the background image(s)`);else{Gf(r.error??`could not save theme`);return}}Je(n);let r=e=>n.some(t=>t.id===e)||xf.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??xf.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=>{ee(e.currentTarget.value),E(!0)},R($e,j(Bf,{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(Bf,{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(Bf,{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(Bf,{label:`max spawn depth`,get value(){return _()},onValue:e=>v(e),hint:`sub-agent nesting limit (0 = no spawning)`}),null),rt.addEventListener(`change`,e=>C(e.currentTarget.checked)),R(it,j(N,{get when(){return te().length>0},get fallback(){return nw()},get children(){return j(Se,{get each(){return te()},children:(e,t)=>{let n=()=>he()[e().name],r=e=>ne(te().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=pw(),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,y=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,{...te()[t],url:n})},700))},l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>ne(te().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=rw();return t.$$input=e=>r({command:e.currentTarget.value}),x(()=>t.value=e().command??``),t})(),(()=>{var t=iw();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),x(()=>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=mw();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=aw();return e.$$input=e=>{let n=e.currentTarget.value;le(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},x(()=>e.value=ce()[t]??``),e}}),null),R(h,j(N,{get when(){return oe()[t]===`header`},get children(){return[(()=>{var e=ow();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})},x(()=>e.value=ue()[t]??``),e})(),(()=>{var e=sw();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})},x(()=>e.value=ce()[t]??``),e})()]}}),null),R(i,j(N,{get when(){return oe()[t]===`json`},get children(){var e=cw(),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`}))}},x(()=>n.value=re()[t]??``),e}}),v),y.$$click=async()=>{let e=te()[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 X(`/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(()=>!!wC(_e(),String(e().name??``))?.required)()&&!wC(_e(),String(e().name??``))?.authorized},get children(){var n=lw();return n.$$click=()=>void Ce(t,e()),n}}),null),R(v,j(N,{get when(){return wC(_e(),String(e().name??``))?.authorized},get children(){return uw()}}),null),R(v,j(N,{get when(){return n()},get children(){var e=dw();return R(e,(()=>{var e=P(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:P(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),x(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=fw();return R(e,()=>ie()[t]),e}}),null),R(i,j(N,{get when(){return fe()[t]},children:n=>(()=>{var r=vw(),i=r.firstChild,a=i.firstChild;return R(a,()=>n().text),R(i,j(N,{get when(){return n().needsOAuth},get children(){return hw()}}),null),R(r,j(N,{get when(){return(n().tools?.length??0)>0},get children(){var e=gw(),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=bw(),n=t.firstChild;return R(n,()=>e.name),R(t,j(N,{get when(){return e.description},get children(){var t=yw();return R(t,()=>e.description),t}}),null),x(()=>I(t,`title`,e.description??``)),t})()})),e}}),null),R(r,j(N,{get when(){return wC(_e(),String(e().name??``))?.authorized},get children(){var n=_w(),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 X(`/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),x(()=>L(r,`mcpresult `+(n().kind===`err`?`err`:`ok`))),r})()}),null),x(()=>o.value=e().name),x(()=>s.value=e().url??``),x(()=>l.checked=e().enabled!==!1),x(()=>f.value=e().description??``),x(()=>m.value=e().transport??`http`),x(()=>g.value=ye(String(e().name??``))?`oauth`:oe()[t]??`none`),i})()}})}}),at),at.$$click=()=>ne([...te(),{name:``,url:``,transport:`http`,enabled:!0}]),R(ot,j(N,{get when(){return D().length>0},get children(){return j(Se,{get each(){return D()},children:(e,t)=>(()=>{var n=xw(),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=>O(D().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>O(D().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>O(D().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>O(D().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>O(D().filter((e,n)=>n!==t)),u.$$input=e=>O(D().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),x(()=>i.value=e().id),x(()=>a.value=e().agent),x(()=>o.value=e().schedule),x(()=>c.checked=!!e().forked),x(()=>u.value=e().prompt),n})()})}}),st),st.$$click=()=>O([...D(),{id:``,agent:Pe()[0]??``,schedule:`every 30m`,prompt:``}]),R(ct,j(N,{get when(){return Me().length>0},get fallback(){return Sw()},get children(){return j(M,{get each(){return Me()},children:t=>(()=>{var n=Cw(),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 ${nn(new Date(t.archivedAt).toISOString())}`:``})(),null),R(s,()=>t.workspace),c.$$click=async()=>{let n=await X(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await je(),e.onSaved();let r=(n?.ids?.length??1)-1;Gf((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 X(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await je(),e.onSaved(),Gf(`deleted ${t.id} for good`))},x(()=>I(s,`title`,t.workspace)),n})()})}}),null),R(ut,j(M,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Tw(),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=ww();return t.firstChild,R(t,()=>e.parent,null),t}}),null),t})()}),null),R(ft,()=>e.cfg.version??`unknown`,null),pt.$$click=async e=>{try{Te(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await X(`/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 X(`/api/version`);if(!e.version)continue;r===null&&(r=e.uptimeSeconds??null),(e.version!==`0.37.203`||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(mt,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=UC();return R(t,j(M,{get each(){return e.skills},children:t=>{let[n,r]=b(!1),[i,a]=b(null),[o,s]=b(``),c=async()=>{if(n())return r(!1);if(r(!0),i()===null&&e.agentId)try{let n=await X(`/api/agents/${e.agentId}/skills/${encodeURIComponent(t.name)}`);a(String(n.text??``))}catch(e){s(e.message)}};return(()=>{var e=Ow(),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=kw();return R(e,()=>o()||`loading…`),e})()},get children(){var e=Dw();return x(()=>e.innerHTML=lt(String(i()??``))),e}})}}),null),x(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),R(_t,(()=>{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(vt,(()=>{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(yt,j(N,{get when(){return we()},get children(){var e=WC();return R(e,we),e}}),bt),R(bt,(()=>{var e=P(()=>Qe()===`saving`);return()=>e()?`saving…`:P(()=>Qe()===`saved`)()?`✓ saved`:Qe()===`error`?`✕ failed`:`save settings`})()),x(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&&it.classList.toggle(`hide`,t.i=o),s!==t.n&&ot.classList.toggle(`hide`,t.n=s),c!==t.s&&ct.classList.toggle(`hide`,t.s=c),l!==t.h&&ut.classList.toggle(`hide`,t.h=l),u!==t.r&&dt.classList.toggle(`hide`,t.r=u),d!==t.d&&mt.classList.toggle(`hide`,t.d=d),f!==t.l&&ht.classList.toggle(`hide`,t.l=f),p!==t.u&&bt.classList.toggle(`saved`,t.u=p),m!==t.c&&bt.classList.toggle(`error`,t.c=m),h!==t.w&&(bt.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}),x(()=>ke.value=i()),x(()=>Re.checked=He()),x(()=>Ze.value=w()),x(()=>nt.value=p()??``),x(()=>rt.checked=y()),t}})}Ee([`click`,`input`]);var Mw=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Nw=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Pw=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Fw(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Iw(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 Iw(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Mw.has(t)?`image`:Nw.has(t)?`video`:Pw.has(t)?`audio`:null}var Lw=new Map,Rw=e=>{let t=Lw.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Lw.set(e,t)),t},zw=F(`<span class=fsize>`),Bw=F(`<div><span class=ficon></span><span class=fname>`),Vw=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>· `),Hw=F(`<div class=filebox>`),Uw=F(`<div class=muted style=padding:6px>`),Ww=F(`<img>`),Gw=F(`<div class=mediapreview><div class="meta muted"> preview`),Kw=F(`<button title="rendered markdown">👁 preview`),qw=F(`<button title="edit and save back to the workspace">✎ edit`),Jw=F(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),Yw=F(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Xw=F(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Zw=F(`<div class="content mdpreview shikiwrap">`),Qw=F(`<video controls>`),$w=F(`<audio controls>`);function eT(e){let t=Rw(e.agentId),[n,r]=b(new Map),[i,a]=b(t.expanded),[o,s]=b(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=b(t.media),f=e=>{t.media=e,d(e)},[p,m]=b(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=b(``),[v,y]=b(!0),[C,w]=b(localStorage.getItem(`teapot.ignoreMode`)??`dim`),ee=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(C())+1)%3];w(t),localStorage.setItem(`teapot.ignoreMode`,t)},E=e=>C()!==`hide`||!e.ignored,[D,O]=b(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!D(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await k(t,e)}))).then(t=>{O(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&ie(e,n)})},ne=(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 re(e){return k(e,D())}async function k(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await X(`/api/agents/${e.agentId}/tree?${r.toString()}`);return ne(t,i.entries??[])}catch(e){return _(e.message),null}}let ie=(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}),ae=``;S(()=>{let t=e.agentId;t!==ae&&(ae=t,l(new Set),c(null),f(null),r(new Map),y(!0),re(``).then(e=>{ae===t&&(e&&r(new Map([[``,e]])),y(!1))}))});let oe=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 re(e.path);t&&ie(e.path,t)}},[se,ce]=b(``),[le,ue]=b(!1),[de,fe]=b(``),[A,pe]=b(!1),me=e=>/\.(md|markdown|mdx)$/i.test(e),he=0,ge=async e=>{let t=++he;ce(``),ue(!0);try{let{highlightChunks:n}=await Y(async()=>{let{highlightChunks:e}=await Promise.resolve().then(()=>zx);return{highlightChunks:e}},void 0);for await(let r of n(e.path,e.content)){if(he!==t)return;ce(e=>e+r)}}catch{he===t&&ce(``)}finally{he===t&&ue(!1)}};T(()=>{he++});let _e=async(t,n)=>{let r=Iw(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await X(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),fe(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&ge({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Gf(`open failed: ${e.message}`)}},ve=async()=>{let t=o();if(t&&!A()){pe(!0);try{await X(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:de(),baseContent:t.content})}),c({...t,content:de()}),Gf(`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?Gf(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
182
182
|
OK = load the disk version into the editor (your edits are discarded)
|
|
183
|
-
Cancel = keep editing your copy`)?(fe(r.current),c({...t,content:r.current}),Gf(`loaded the current file from disk`)):Gf(`kept your edits — use Save As via bash to force-write`)}finally{pe(!1)}}},ye=e=>!e.binary&&!e.truncated,be=(e,t)=>[(()=>{var n=Bw(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void oe(e):void _e(e,`code`),R(r,(()=>{var t=P(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Fw(e.name)})()),R(a,()=>e.name),R(n,j(N,{get when(){return P(()=>!e.dir)()&&e.size!==void 0},get children(){var t=zw();return R(t,()=>fn(e.size)),t}}),null),x(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&C()===`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(E)},children:e=>be(e,t+1)})}})],xe=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[Se,Ce]=b(!1),we=async()=>{if(!Se()){Ce(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await k(e,D())})));for(let{p:e,rows:n}of t)n&&ie(e,n)}finally{Ce(!1)}}};return[(()=>{var e=Vw(),t=e.firstChild.nextSibling;return t.firstChild,R(t,xe,null),R(e,j(Ud,{class:`filetoggle`,get icon(){return Se()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void we()}),null),R(e,j(Ud,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return P(()=>C()===`hide`)()?`🙈`:C()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${C()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),R(e,j(Ud,{class:`filetoggle`,get icon(){return D()?`◉.`:`○.`},get title(){return D()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:te}),null),e})(),(()=>{var e=Hw();return R(e,j(N,{get when(){return P(()=>!v())()&&(n().get(``)??[]).length>0},get fallback(){return j(N,{get when(){return!v()},get fallback(){return j(Dn,{what:`files`,class:`muted`})},get children(){var e=Uw();return R(e,()=>g()||`empty workspace`),e}})},get children(){return j(M,{get each(){return(n().get(``)??[]).filter(E)},children:e=>be(e,0)})}})),e})(),j(N,{get when(){return o()},children:t=>j(Gd,{get title(){return`🗂 ${t().path}`},onClose:()=>{he++,c(null),f(null)},get children(){return j(N,{get when(){return u()},get fallback(){return[(()=>{var e=Jw(),n=e.firstChild;return R(e,j(N,{get when(){return P(()=>!!me(t().path))()&&!t().binary},get children(){var e=Kw();return e.$$click=()=>h(`md`),x(()=>L(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),se()||ge({path:t().path,content:t().content,truncated:t().truncated})},R(e,j(N,{get when(){return ye(t())},get children(){var e=qw();return e.$$click=()=>h(`edit`),x(()=>L(e,p()===`edit`?`on`:``)),e}}),null),x(()=>L(n,p()===`code`?`on`:``)),e})(),j(N,{get when(){return!t().binary},get fallback(){return Xw()},get children(){return j(N,{get when(){return p()===`edit`},get fallback(){return j(N,{get when(){return P(()=>p()===`md`)()&&me(t().path)},get fallback(){return j(zf,{get path(){return t().path},get content(){return t().content},get html(){return se()},get pending(){return le()},get truncated(){return!!t().truncated}})},get children(){var e=Zw();return x(()=>e.innerHTML=Re(t().content)),e}})},get children(){var e=Yw(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>fe(e.currentTarget.value),I(n,`spellcheck`,!1),R(r,()=>fn(de().length),i),a.$$click=()=>void ve(),R(a,()=>A()?`saving…`:`💾 save`),x(()=>a.disabled=A()||de()===t().content),x(()=>n.value=de()),e}})}})]},get children(){var t=Gw(),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=$w();return x(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Qw();return x(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Ww();return x(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 tT=F(`<details class=reasoning open><summary>💭 thinking </summary><div class="mono thinkscroll">`),nT=F(`<div class=muted style=font-size:11.5px;margin-bottom:4px>🗜 summarizing older context…`),rT=F(`<div class=content>`),iT=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 tone-agent">agent</span><span class=ts>streaming…`),aT=F(`<div class="content muted">thinking…`),oT=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`),sT=F(`<div class=leftbarbackdrop>`),cT=F(`<div class=sidehead><b>agents</b><button class=iconbtn title="close the agent list">✕`),lT=F(`<i class=notifdot>`),uT=F(`<br>`),dT=F(`<button class="iconbtn ham"title="agent list">☰`),fT=F(`<input class="title titleedit">`),pT=F(`<span class="badge queued">⏳ <!> <!> queued`),mT=F(`<button type=button class="badge bgjobs">🐚 `),hT=F(`<span class="badge cron">⏰ `),gT=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>`),_T=F(`<div class=divider-msg>── beginning of log ──`),vT=F(`<div class=divider-msg>loading older events…`),yT=F(`<div class=feedloading><span class=spinner aria-hidden=true></span> loading timeline…`),bT=F(`<div class=feedloading><span class=spinner aria-hidden=true></span> loading newer events…`),xT=F(`<div class=feed>`),ST=F(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),CT=F(`<div class=termsplit>`),wT=F(`<div class="termempty muted">no shell here — click a tab or + to add`),TT=F(`<div class=termpane>`),ET=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>`),DT=F(`<button class=jump>↓ `),OT=F(`<div class=cmds>`),kT=F(`<div class=attachrow><button type=button class=attachclear title="remove every attachment">clear`),AT=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`),jT=F(`<div class="hint flashhint">`),MT=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>`),NT=F(`<div class=rightbarbackdrop>`),PT=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`),FT=F(`<div class=notifbackdrop>`),IT=F(`<button class=editbtn>clear all`),LT=F(`<div class=notiflist>`),RT=F(`<div class=notifpanel><div class=notifhead>notifications<span style=display:flex;gap:8px;align-items:center><button class=iconbtn title="close notifications">✕`),zT=F(`<div class=bgphoto aria-hidden=true><img sizes=100vw alt decoding=async><span class=bgphoto-veil>`),BT=F(`<span class=wscount>`),VT=F(`<div class=wsheader><span class=wscaret></span><span class=wsname>`),HT=F(`<span class=notifbadge>🔔️`),UT=F(`<span class=subtag>🧩`),WT=F(`<span class=mini-cron>⏰`),GT=F(`<span class=goaldone title="goal done">✓`),KT=F(`<div><span></span><span>`),qT=F(`<span class=caret-spacer>`),JT=F(`<span class=caret>`),YT=F(`<span class=ghosttag title="workspace missing">👻`),XT=F(`<span>🧩 `),ZT=F(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),QT=F(`<span class=title>`),$T=F(`<div class="divider-msg compacting"title="the harness is compressing old turns into notes so work can continue within the context window">🗜 `),eE=F(`<div class=muted style=display:grid;place-items:center;height:100%>`),tE=F(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),nE=F(`<div class=lightbox role=dialog aria-modal=true aria-label="enlarged image"title="click to close"><img alt>`),rE=F(`<span>⌨ <button class=tabx title="close this shell">✕`),iE=F(`<div><b class=mono></b><span class=muted>`),aE=F(`<div class=cmdrow><b>@</b><span class=muted>`),oE=F(`<span class=imgchip><img title="click to enlarge"><button type=button class=imgx title=remove>✕`),sE=F(`<span class=muted style=text-transform:none;letter-spacing:0>· <!> models`),cE=F(`<h3 title="switch provider/model live — applies from the agent's next turn">🧦 model`),lE=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`),uE=F(`<div class=meta style=color:var(--fg)>`),dE=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: `),fE=F(`<span>`),pE=F(`<h3 class=goalhead 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<label class=goalauto title="keep looping toward the goal after each round — fires only while the goal is 'working' and the round ended cleanly; ■ stop or marking it done ends it"><input type=checkbox>auto-continue`),mE=F(`<div class=statrow style=margin-bottom:6px><span class=k>status`),hE=F(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px;margin-bottom:6px><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 type=checkbox>notify agent</label><button type=button class=primarybtn>✓ save goal`),gE=F(`<span class=badge>/<!> done`),_E=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`),vE=F(`<div class=bartrack style=margin-bottom:6px><div>`),yE=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`),bE=F(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),xE=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`),SE=F(`<div class=rtcell><span>cost</span><b>$`),CE=F(`<div class=rtcell><span>cached</span><b>%`),wE=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>`),TE=F(`<div class=muted style=font-size:11px;text-transform:none;letter-spacing:0>showing <b></b> and the history it inherited before forking`),EE=F(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),DE=F(`<span class=muted style=text-transform:none;letter-spacing:0>· <!> · all agents`),OE=F(`<h3 title="cron tasks, all agents — click a row to open that agent. Edit them in ⚙️ settings → scheduled tasks.">⏰ schedule`),kE=F(`<option>`),AE=F(`<span class=badge title="no goal set yet">no goal`),jE=F(`<button>`),ME=F(`<div class=muted>none yet`),NE=F(`<div class=progrow><b>recent</b><span class="content inline-md">`),PE=F(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),FE=F(`<div class=progrow><b>next</b><span class="content inline-md">`),IE=F(`<div class=progrow><b>goal</b><span>`),LE=F(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),RE=F(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),zE=F(`<span>% of `),BE=F(`<div class=bartrack><div>`),VE=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)>`),HE=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`),UE=F(`<div><span></span><span> events`),WE=F(`<div class=muted>no scheduled tasks — add them in ⚙️ settings ("scheduled tasks")`),GE=F(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),KE=F(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class=sched-meta> → next </div><div class="sched-prompt muted">`),qE=F(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),JE=F(`<div class=nbody>`),YE=F(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted"></span><button class="iconbtn nreadbtn">`),XE=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.`),ZE=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`),QE=F(`<span style=color:var(--err);font-size:13px>`),$E=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 class=iconbtn 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></div><button type=submit style=align-self:flex-end>create`),eD=F(`<div class=direntry>📁 `),tD=[`minimal`,`low`,`medium`,`high`],nD=1100,[rD,iD]=b(``),aD,oD=e=>{iD(e),clearTimeout(aD),aD=setTimeout(()=>iD(``),3200)},sD=!1,cD=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`audit_step`,`system_note`]),lD=new Set([`system_note`]),uD=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`audit_step`]),dD=new Set([`runaway-detected`,`error-retry`,`background-exit`,`context-compacted`,`context-compaction-started`]),fD=location.hash.match(/[#&]token=([^&]+)/);fD&&(localStorage.setItem(`teapot.token`,decodeURIComponent(fD[1])),history.replaceState(null,``,location.pathname+location.search));var pD=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function mD(){let[e,t]=b([]),[n,r]=b(null),[i,a]=b(``),[o,s]=b(new Map),[c,l]=b(new Map),[u,d]=b(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 X(`/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]=b([]),[_,v]=b(0),[y,E]=b([]),[D,O]=b(null),te=new Map,[ne,re]=b(te.get(n()??``)??``),k=e=>{re(e);let t=n();t&&(e?te.set(t,e):te.delete(t))},[ie,ae]=b({providers:{}}),[oe,se]=b(!1),ce=()=>Pr({want:Ir({preview:jt(),auto:Dt(),prefersLight:Rt(),dark:Ft(),light:kt(),fixed:Tt()}),customIds:Nt().map(e=>e.id),presetIds:xf.map(e=>e.key),fallback:`dark`}),le=()=>ce().active,ue=()=>Nt().find(e=>e.id===le())?.backgroundImage??``,[de,fe]=b(!1),A=!1;S(()=>{!A&&ie()?.needsSetup&&(A=!0,requestAnimationFrame(()=>{hi(),fe(!0)}))}),S(()=>{de()&&!Go()&&X(`/api/features`).then(e=>Ko(e)).catch(()=>Ko(null))});let pe=new Set,me=()=>window.innerWidth<=nD,[he,ge]=b(me());ee(()=>{let e=()=>{let e=me();e!==he()&&(ge(e),(localStorage.getItem(st(e))!==null||!e)&&mt(ct(e)))};window.addEventListener(`resize`,e),T(()=>window.removeEventListener(`resize`,e)),e()});let _e=0,ve=0,ye,be,xe=0,Se=0,Ce=()=>{if(performance.now()<Me){if(performance.now()<Se)return;let e=va();e&&ze(e)}},we=()=>{xe||=requestAnimationFrame(()=>{xe=0,Ce()})},Te,F,Ee=0,je=``,Me=0,Ne=!0,Pe=e=>{Ne=e,sn()!==e&&cn(e)},Fe=0,Ie=()=>{if(Fe=0,performance.now()>=Me)return;if(performance.now()<Se){Fe=requestAnimationFrame(Ie);return}let e=va();e&&We({top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight})>1&&ze(e),Fe=requestAnimationFrame(Ie)},Le=(e=1500)=>{Me=performance.now()+e,Fe||=requestAnimationFrame(Ie)},ze=e=>{e.scrollTop=e.scrollHeight,rs={top:e.scrollTop,height:e.scrollHeight},cn(!0),dn(0),ot(e),ve=performance.now()},Be=0,Ve=()=>{Ee=0;let e=va();if(!e)return;e.scrollHeight,is=e.scrollHeight,as=e.clientHeight;let t=e.clientWidth!==Be;Be=e.clientWidth,!t&&(sn()||performance.now()<Me)?ba():t&&(Ne||performance.now()<Me)?(ba(),gn(W())):(t&&(Ne||performance.now()<Me)&&ba(),gn(W()))},He=()=>{Ee||=requestAnimationFrame(Ve)},Ue=null,Qe=e=>{Ue?.();let t=e=>{mr(e.deltaY)&&(Se=performance.now()+400,Pe(!1))},n=()=>{Se=performance.now()+400,Pe(!1)},r=t=>{let r=t.target;r&&typeof r.closest==`function`&&r.closest(`textarea, input, select, [contenteditable=''], [contenteditable='true']`)||!gr({target:r,insideFeed:!!r&&typeof e.contains==`function`&&e.contains(r),isBackground:!r||r===document.body||r===document.documentElement,editable:!1})||hr(t.key)&&n()};e.addEventListener(`wheel`,t,{passive:!0}),e.addEventListener(`touchmove`,n,{passive:!0}),window.addEventListener(`keydown`,r,{capture:!0}),Ue=()=>{e.removeEventListener(`wheel`,t),e.removeEventListener(`touchmove`,n),window.removeEventListener(`keydown`,r,{capture:!0}),Ue=null}},$e=e=>{e&&(Qe(e),e!==F&&(Te??=new ResizeObserver(e=>{let t=e[0]?.contentRect,n=t?`${Math.round(t.width)}x${Math.round(t.height)}`:``;n!==je&&(je=n,He())}),F&&Te.unobserve(F),F=e,je=``,Te.observe(e),typeof MutationObserver<`u`&&(ye??=new MutationObserver(we),be&&be!==e&&be.removeEventListener(`load`,we,!0),be=e,ye.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),e.addEventListener(`load`,we,!0))))};ee(()=>{window.addEventListener(`resize`,He),T(()=>{window.removeEventListener(`resize`,He),Te?.disconnect(),Te=void 0,F=void 0,ye?.disconnect(),ye=void 0,be&&be.removeEventListener(`load`,we,!0),be=void 0,xe&&cancelAnimationFrame(xe),Ee&&cancelAnimationFrame(Ee)})});let at=e=>`[data-eid="${globalThis.CSS?.escape?.(e)??e.replace(/["\\]/g,`\\$&`)}"]`;function ot(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:at(s),top:r(o).top}:null}let st=e=>e?`teapot.panel.narrow`:`teapot.panel`,ct=e=>{let t=localStorage.getItem(st(e));return t===null?!e:t===`1`},[pt,mt]=b(ct(me())),ht=e=>{mt(e),localStorage.setItem(st(he()),e?`1`:`0`)},gt=()=>ht(!pt()),_t=()=>{pt()&&ht(!1)},[vt,bt]=b(!1),xt=()=>bt(!1),[Tt,Et]=b(localStorage.getItem(`teapot.theme`)??`dark`),[Dt,Ot]=b(localStorage.getItem(`teapot.theme.auto`)===`1`),[kt,At]=b(localStorage.getItem(`teapot.theme.light`)??`light`),[jt,Mt]=b(null),[Nt,Pt]=b(Dr());ee(()=>{kr().then(e=>{if(e===null)return;let t=kn(Nt(),e);Pt(t),Or(t)})});let[Ft,It]=b(localStorage.getItem(`teapot.theme.dark`)??`dark`),Lt=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[Rt,zt]=b(Lt?.matches??!1);ee(()=>{let e=e=>zt(e.matches);Lt?.addEventListener(`change`,e);let t=()=>{if(document.visibilityState!==`visible`)return;let e=Lt?.matches??!1;e!==Rt()&&zt(e)};document.addEventListener(`visibilitychange`,t),T(()=>{Lt?.removeEventListener(`change`,e),document.removeEventListener(`visibilitychange`,t)})}),S(()=>{let{active:e,repaired:t}=ce(),n=Nt().find(t=>t.id===e)??null;t&&(Dt()?localStorage.setItem(Rt()?`teapot.theme.light`:`teapot.theme.dark`,e):localStorage.setItem(`teapot.theme`,e)),document.documentElement.dataset.theme=e,jr(document.documentElement,n),document.documentElement.dataset.appearance=n?.mode??xf.find(t=>t.key===e)?.mode??`dark`});let[Bt,Vt]=b(``),[Ht,Ut]=b(``),[Gt,qt]=b(``);S(()=>{let t=n();qt(w(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[Jt,Yt]=b([]),Xt=()=>Object.keys(ie().providers??{});async function Zt(e){if(e)try{let t=await X(`/api/models?provider=${encodeURIComponent(e)}`);Yt(t.models??[])}catch{Yt([])}}let Qt=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)}`:``},en=()=>{let e=Ht().trim()||z()?.model||``;if(!e)return``;let t=Jt().find(t=>t.id===e);if(!t)return``;let n=[],r=Qt(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${fn(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(` · `)},tn=null,rn=!1;S(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||ie().defaultProvider||Xt()[0]||``;if(r){if(t!==tn)tn=t,rn=!1,w(()=>Bt())!==i&&(Vt(i),Zt(i)),w(()=>Ht())&&Ut(``);else{let e=w(()=>Bt());!w(()=>Ht())&&e!==i&&ur(rn)&&(Vt(i),Zt(i))}}});let[an,on]=b(!1),[sn,cn]=b(!0),ln,[un,dn]=b(0),[mn,hn]=b(-1),gn=e=>hn(e?Xe(e):-1),[_n,vn]=b(null),bn=()=>Mn().startsWith(`[compact] `),xn=()=>{let e=bn()?Mn().slice(10):Mn();return e.length>1200?`…`+e.slice(-1200):e};S(()=>{_n()||En(e=>e?.text.startsWith(`[compact] `)?null:e)}),S(()=>{h().length,_(),_n(),oi().length,aa(),ra(),ta();let e=va();if(!e)return;let t=e.scrollHeight;t!==_e&&(_e=t,requestAnimationFrame(()=>requestAnimationFrame(()=>{sn()&&(ba(),requestAnimationFrame(()=>{if(!sn())return;let t=e.scrollHeight;t!==_e&&(_e=t,ba())}))})))});let[Sn,Cn]=b(new Map),wn=()=>{let e=n();return e?Sn().get(e)??null:null},En=e=>{let t=n();t&&Cn(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})},jn=()=>{let e=wn();if(!e)return;let t=Ct(e,h(),z()?.status);t?(t.text!==e.text||t.reasoning!==e.reasoning)&&En(t):En(null)},[Mn,Nn]=b(``),[Ln,Yn]=b(0),$n=()=>Ln(),[nr,rr]=b(``),sr;S(()=>{wn()?sr||=setTimeout(()=>{sr=void 0,Nn(wn()?.text??``),rr(wn()?.reasoning??``)},(wn()?.text.length??0)>2e4?250:(wn()?.text.length??0)>6e3?120:60):(clearTimeout(sr),sr=void 0,Nn(``),rr(``))}),T(()=>clearTimeout(sr)),S(()=>{let t=e();Cn(e=>St(e,e=>t.find(t=>t.id===e)?.status)),Yn(e=>wt(e,t,n(),wn()))}),S(()=>{let e=Mn(),t=wn()?.reasoning??``;(e||t)&&requestAnimationFrame(()=>{sn()&&ba()})}),S(()=>{let e=z()?.pendingPrompts??0,t=z()?.pendingPromptIds,n=Rr(),r=zr(n),i=Gn(r,e,t);i!==r&&B(n,i)}),S(()=>{let e=z()?.pendingPromptQueue;if(!e?.length)return;let t=z()?.session||Rr();if(wa.size){let t=new Set(e.map(e=>String(e.id??``)));for(let e of[...wa])t.has(e)||wa.delete(e)}let n=Kn(zr(t),e.filter(e=>!wa.has(String(e.id??``))));n!==zr(t)&&B(t,n)}),S(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{ya()&&(cn(!0),dn(0),xa(!0),qr())})};document.addEventListener(`visibilitychange`,e),T(()=>document.removeEventListener(`visibilitychange`,e))});let z=C(()=>e().find(e=>e.id===n()));S(()=>{let e=z()?.pendingQuestionId;e&&(h().some(t=>t.id===e)||(Cr.has(e)||(Cr.add(e),_a(n(),i())),!(aa()||ta())&&(async()=>{for(let t=0;t<8;t++){if(h().some(t=>t.id===e)||aa())return;if(ta()){await new Promise(e=>setTimeout(e,50));continue}let t=h().length;if(await da(),h().length===t)return}})()))});let Sr=``,Cr=new Set;S(()=>{let e=z()?.pendingQuestionId;e&&e!==Sr&&h().some(t=>t.id===e)&&(Sr=e,Qr(e,0))});let wr=()=>xr({sameSession:!(z()?.session!==Rr()&&z()?.session),echoCount:si()}),Tr=()=>{let e=z();return e?e.live??(e.status===`running`||e.status===`waiting`||e.status===`needs_operator`):!1},Er=()=>Qn(z(),i(),Tr()),[Ar,Mr]=b(null);C(()=>{let e=new Set;for(let t of h())t.type===`tool_result`&&(t.data?.name===`ask_operator`||t.data?.name===`ask_user`)&&e.add(String(t.data.callId));return e});let Nr=new Map,[Fr,Lr]=b([]),Rr=()=>i()||n()||`?`,zr=e=>Nr.get(e)??[],B=(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?Nr.delete(e):Nr.set(e,r),Rr()===e&&Lr(r)},[V,Br]=b([]),[Vr,Hr]=b(localStorage.getItem(`teapot.hideGhosts`)===`1`),[Ur,Wr]=b(!1),Gr=()=>V().filter(e=>!e.read).length,Kr=e=>{Br(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},qr=()=>{let e=n();e&&V().some(t=>!t.read&&t.agentId===e)&&Kr(e)},Jr=t=>{let n=V().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Jr(r.id));return n},Yr=0,Xr=e=>{Br(t=>[{...e,id:`n${++Yr}`,at:Date.now(),read:!1},...t].slice(0,50))},Zr=(t,n)=>{if(n.type===`system_note`&&n.data?.event===`background-exit`){let r=e().find(e=>e.id===t)?.id??t,i=n.data.failed===!0;if(!i)return;let a=Math.round(Number(n.data.durationMs??0)/1e3);Xr({agentId:t,kind:i?`error`:`progress`,title:`${r}: ${i?`⚠`:`✓`} background job ${String(n.data.jobId??`?`)} `+(i?`FAILED (exit ${String(n.data.code??`?`)})`:`finished (${a}s)`),body:String(n.data.cmd??``).slice(0,200)});return}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?Xr({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?Xr({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?Xr({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&Xr({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})},Qr=(e,t=0)=>{let n=i(),r=document.querySelector(at(e)),a=!!r&&Ze(r.dataset.session,n);r&&a?(r.scrollIntoView({behavior:`smooth`,block:`center`}),r.classList.add(`flash-target`),setTimeout(()=>r.classList.remove(`flash-target`),1600)):t<30&&requestAnimationFrame(()=>Qr(e,t+1))},$r=C(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of h())if(cD.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}}),[ei,ti]=b(new Set),ni=e=>{e&&ti(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},ri=()=>ti(new Set),ii=C(()=>Wn(h(),ei())),ai=C(()=>Wt({events:h(),consumed:$r().consumed,pending:Fr().map(e=>({...e,promptId:e.promptId??e.id})),serverPendingIds:z()?.pendingPromptIds,echo:mi,feedTypes:cD,renderedTypes:uD,renderedNoteEvents:dD})),oi=()=>ai().rows,si=()=>ai().pendingCount,ci=e=>e.data?.pending===!0,li=()=>oi().some(ci),ui=e=>ci(e)&&oi().find(ci)?.id===e.id,di=C(()=>{let e=new WeakMap;return oi().forEach((t,n)=>e.set(t,n)),e}),fi=(e,t)=>{let n=di().get(e);if(n!==void 0)return oi()[n+t]},pi=new Map;function mi(e){let t=`${e.id}:${e.sent?`s`:`p`}:${e.promptId??``}`,n=pi.get(t);if(n)return n;pi.size>64&&pi.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.queued===!0,queued:!e.sent&&e.queued===!0,...e.images?.length?{images:e.images}:{},...e.promptId?{promptId:e.promptId}:{}}};return pi.set(t,r),r}let hi=()=>X(`/api/config`).then(ae).catch(()=>{}),[gi,_i]=b(!1);ee(()=>{let e=()=>_i(!0);window.addEventListener(`teapot:unauthorized`,e),T(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[vi,yi]=b(``),[bi,xi]=b(!0),[Si,Ci]=b(!1),wi=``;S(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==wi?(wi=t,Ci(!1),yi(r)):t&&!Si()&&yi(r)});let Ti=async()=>{let e=document.getElementById(`todo-notify`)?.checked??!0;if(n())try{await X(`/api/agents/${n()}/todo`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:vi(),notify:e})}),Ci(!1),xi(!0),oD(`tasks saved${e&&vi().trim()?` & notification queued`:``}`),Oi()}catch(e){oD(`save failed: ${e.message}`)}},Ei=C(()=>{let e=0,t=0;for(let n of vi().split(`
|
|
183
|
+
Cancel = keep editing your copy`)?(fe(r.current),c({...t,content:r.current}),Gf(`loaded the current file from disk`)):Gf(`kept your edits — use Save As via bash to force-write`)}finally{pe(!1)}}},ye=e=>!e.binary&&!e.truncated,be=(e,t)=>[(()=>{var n=Bw(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void oe(e):void _e(e,`code`),R(r,(()=>{var t=P(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Fw(e.name)})()),R(a,()=>e.name),R(n,j(N,{get when(){return P(()=>!e.dir)()&&e.size!==void 0},get children(){var t=zw();return R(t,()=>fn(e.size)),t}}),null),x(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&C()===`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(E)},children:e=>be(e,t+1)})}})],xe=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[Se,Ce]=b(!1),we=async()=>{if(!Se()){Ce(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await k(e,D())})));for(let{p:e,rows:n}of t)n&&ie(e,n)}finally{Ce(!1)}}};return[(()=>{var e=Vw(),t=e.firstChild.nextSibling;return t.firstChild,R(t,xe,null),R(e,j(Ud,{class:`filetoggle`,get icon(){return Se()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void we()}),null),R(e,j(Ud,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return P(()=>C()===`hide`)()?`🙈`:C()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${C()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),R(e,j(Ud,{class:`filetoggle`,get icon(){return D()?`◉.`:`○.`},get title(){return D()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:te}),null),e})(),(()=>{var e=Hw();return R(e,j(N,{get when(){return P(()=>!v())()&&(n().get(``)??[]).length>0},get fallback(){return j(N,{get when(){return!v()},get fallback(){return j(Dn,{what:`files`,class:`muted`})},get children(){var e=Uw();return R(e,()=>g()||`empty workspace`),e}})},get children(){return j(M,{get each(){return(n().get(``)??[]).filter(E)},children:e=>be(e,0)})}})),e})(),j(N,{get when(){return o()},children:t=>j(Gd,{get title(){return`🗂 ${t().path}`},onClose:()=>{he++,c(null),f(null)},get children(){return j(N,{get when(){return u()},get fallback(){return[(()=>{var e=Jw(),n=e.firstChild;return R(e,j(N,{get when(){return P(()=>!!me(t().path))()&&!t().binary},get children(){var e=Kw();return e.$$click=()=>h(`md`),x(()=>L(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),se()||ge({path:t().path,content:t().content,truncated:t().truncated})},R(e,j(N,{get when(){return ye(t())},get children(){var e=qw();return e.$$click=()=>h(`edit`),x(()=>L(e,p()===`edit`?`on`:``)),e}}),null),x(()=>L(n,p()===`code`?`on`:``)),e})(),j(N,{get when(){return!t().binary},get fallback(){return Xw()},get children(){return j(N,{get when(){return p()===`edit`},get fallback(){return j(N,{get when(){return P(()=>p()===`md`)()&&me(t().path)},get fallback(){return j(zf,{get path(){return t().path},get content(){return t().content},get html(){return se()},get pending(){return le()},get truncated(){return!!t().truncated}})},get children(){var e=Zw();return x(()=>e.innerHTML=Re(t().content)),e}})},get children(){var e=Yw(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>fe(e.currentTarget.value),I(n,`spellcheck`,!1),R(r,()=>fn(de().length),i),a.$$click=()=>void ve(),R(a,()=>A()?`saving…`:`💾 save`),x(()=>a.disabled=A()||de()===t().content),x(()=>n.value=de()),e}})}})]},get children(){var t=Gw(),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=$w();return x(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Qw();return x(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Ww();return x(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 tT=F(`<details class=reasoning open><summary>💭 thinking </summary><div class="mono thinkscroll">`),nT=F(`<div class=muted style=font-size:11.5px;margin-bottom:4px>🗜 summarizing older context…`),rT=F(`<div class=content>`),iT=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 tone-agent">agent</span><span class=ts>streaming…`),aT=F(`<div class="content muted">thinking…`),oT=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`),sT=F(`<div class=leftbarbackdrop>`),cT=F(`<div class=sidehead><b>agents</b><button class=iconbtn title="close the agent list">✕`),lT=F(`<i class=notifdot>`),uT=F(`<br>`),dT=F(`<button class="iconbtn ham"title="agent list">☰`),fT=F(`<input class="title titleedit">`),pT=F(`<span class="badge queued">⏳ <!> <!> queued`),mT=F(`<button type=button class="badge bgjobs">🐚 `),hT=F(`<span class="badge cron">⏰ `),gT=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>`),_T=F(`<div class=divider-msg>── beginning of log ──`),vT=F(`<div class=divider-msg>loading older events…`),yT=F(`<div class=feedloading><span class=spinner aria-hidden=true></span> loading timeline…`),bT=F(`<div class=feedloading><span class=spinner aria-hidden=true></span> loading newer events…`),xT=F(`<div class=feed>`),ST=F(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),CT=F(`<div class=termsplit>`),wT=F(`<div class="termempty muted">no shell here — click a tab or + to add`),TT=F(`<div class=termpane>`),ET=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>`),DT=F(`<button class=jump>↓ `),OT=F(`<div class=cmds>`),kT=F(`<div class=attachrow><button type=button class=attachclear title="remove every attachment">clear`),AT=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`),jT=F(`<div class="hint flashhint">`),MT=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>`),NT=F(`<div class=rightbarbackdrop>`),PT=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`),FT=F(`<div class=notifbackdrop>`),IT=F(`<button class=editbtn>clear all`),LT=F(`<div class=notiflist>`),RT=F(`<div class=notifpanel><div class=notifhead>notifications<span style=display:flex;gap:8px;align-items:center><button class=iconbtn title="close notifications">✕`),zT=F(`<div class=bgphoto aria-hidden=true><img sizes=100vw alt decoding=async><span class=bgphoto-veil>`),BT=F(`<span class=wscount>`),VT=F(`<div class=wsheader><span class=wscaret></span><span class=wsname>`),HT=F(`<span class=notifbadge>🔔️`),UT=F(`<span class=subtag>🧩`),WT=F(`<span class=mini-cron>⏰`),GT=F(`<span class=goaldone title="goal done">✓`),KT=F(`<div><span></span><span>`),qT=F(`<span class=caret-spacer>`),JT=F(`<span class=caret>`),YT=F(`<span class=ghosttag title="workspace missing">👻`),XT=F(`<span>🧩 `),ZT=F(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),QT=F(`<span class=title>`),$T=F(`<div class="divider-msg compacting"title="the harness is compressing old turns into notes so work can continue within the context window">🗜 `),eE=F(`<div class=muted style=display:grid;place-items:center;height:100%>`),tE=F(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),nE=F(`<div class=lightbox role=dialog aria-modal=true aria-label="enlarged image"title="click to close"><img alt>`),rE=F(`<span>⌨ <button class=tabx title="close this shell">✕`),iE=F(`<div><b class=mono></b><span class=muted>`),aE=F(`<div class=cmdrow><b>@</b><span class=muted>`),oE=F(`<span class=imgchip><img title="click to enlarge"><button type=button class=imgx title=remove>✕`),sE=F(`<span class=muted style=text-transform:none;letter-spacing:0>· <!> models`),cE=F(`<h3 title="switch provider/model live — applies from the agent's next turn">🧦 model`),lE=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`),uE=F(`<div class=meta style=color:var(--fg)>`),dE=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: `),fE=F(`<span>`),pE=F(`<h3 class=goalhead 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<label class=goalauto title="keep looping toward the goal after each round — fires only while the goal is 'working' and the round ended cleanly; ■ stop or marking it done ends it"><input type=checkbox>auto-continue`),mE=F(`<div class=statrow style=margin-bottom:6px><span class=k>status`),hE=F(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px;margin-bottom:6px><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 type=checkbox>notify agent</label><button type=button class=primarybtn>✓ save goal`),gE=F(`<span class=badge>/<!> done`),_E=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`),vE=F(`<div class=bartrack style=margin-bottom:6px><div>`),yE=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`),bE=F(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),xE=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`),SE=F(`<div class=rtcell><span>cost</span><b>$`),CE=F(`<div class=rtcell><span>cached</span><b>%`),wE=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>`),TE=F(`<div class=muted style=font-size:11px;text-transform:none;letter-spacing:0>showing <b></b> and the history it inherited before forking`),EE=F(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),DE=F(`<span class=muted style=text-transform:none;letter-spacing:0>· <!> · all agents`),OE=F(`<h3 title="cron tasks, all agents — click a row to open that agent. Edit them in ⚙️ settings → scheduled tasks.">⏰ schedule`),kE=F(`<option>`),AE=F(`<span class=badge title="no goal set yet">no goal`),jE=F(`<button>`),ME=F(`<div class=muted>none yet`),NE=F(`<div class=progrow><b>recent</b><span class="content inline-md">`),PE=F(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),FE=F(`<div class=progrow><b>next</b><span class="content inline-md">`),IE=F(`<div class=progrow><b>goal</b><span>`),LE=F(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),RE=F(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),zE=F(`<span>% of `),BE=F(`<div class=bartrack><div>`),VE=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)>`),HE=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`),UE=F(`<div><span></span><span> events`),WE=F(`<div class=muted>no scheduled tasks — add them in ⚙️ settings ("scheduled tasks")`),GE=F(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),KE=F(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class=sched-meta> → next </div><div class="sched-prompt muted">`),qE=F(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),JE=F(`<div class=nbody>`),YE=F(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted"></span><button class="iconbtn nreadbtn">`),XE=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.`),ZE=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`),QE=F(`<span style=color:var(--err);font-size:13px>`),$E=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 class=iconbtn 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></div><button type=submit style=align-self:flex-end>create`),eD=F(`<div class=direntry>📁 `),tD=[`minimal`,`low`,`medium`,`high`],nD=1100,[rD,iD]=b(``),aD,oD=e=>{iD(e),clearTimeout(aD),aD=setTimeout(()=>iD(``),3200)},sD=!1,cD=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`audit_step`,`system_note`]),lD=new Set([`system_note`]),uD=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`audit_step`]),dD=new Set([`runaway-detected`,`error-retry`,`background-exit`,`context-compacted`,`context-compaction-started`]),fD=location.hash.match(/[#&]token=([^&]+)/);fD&&(localStorage.setItem(`teapot.token`,decodeURIComponent(fD[1])),history.replaceState(null,``,location.pathname+location.search));var pD=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function mD(){let[e,t]=b([]),[n,r]=b(null),[i,a]=b(``),[o,s]=b(new Map),[c,l]=b(new Map),[u,d]=b(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 X(`/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]=b([]),[_,v]=b(0),[y,E]=b([]),[D,O]=b(null),te=new Map,[ne,re]=b(te.get(n()??``)??``),k=e=>{re(e);let t=n();t&&(e?te.set(t,e):te.delete(t))},[ie,ae]=b({providers:{}}),[oe,se]=b(!1),ce=()=>Pr({want:Ir({preview:jt(),auto:Dt(),prefersLight:Rt(),dark:Ft(),light:kt(),fixed:Tt()}),customIds:Nt().map(e=>e.id),presetIds:xf.map(e=>e.key),fallback:`dark`}),le=()=>ce().active,ue=()=>Nt().find(e=>e.id===le())?.backgroundImage??``,[de,fe]=b(!1),A=!1;S(()=>{!A&&ie()?.needsSetup&&(A=!0,requestAnimationFrame(()=>{hi(),fe(!0)}))}),S(()=>{de()&&!Go()&&X(`/api/features`).then(e=>Ko(e)).catch(()=>Ko(null))});let pe=new Set,me=()=>window.innerWidth<=nD,[he,ge]=b(me());ee(()=>{let e=()=>{let e=me();e!==he()&&(ge(e),(localStorage.getItem(st(e))!==null||!e)&&mt(ct(e)))};window.addEventListener(`resize`,e),T(()=>window.removeEventListener(`resize`,e)),e()});let _e=0,ve=0,ye,be,xe=0,Se=0,Ce=()=>{if(performance.now()<Me){if(!Ne){Me=0;return}if(performance.now()<Se)return;let e=va();e&&ze(e)}else Ne&&Le(400)},we=()=>{xe||=requestAnimationFrame(()=>{xe=0,Ce()})},Te,F,Ee=0,je=``,Me=0,Ne=!0,Pe=e=>{Ne=e,sn()!==e&&cn(e)},Fe=0,Ie=()=>{if(Fe=0,performance.now()>=Me)return;if(!Ne){Me=0;return}if(performance.now()<Se){Fe=requestAnimationFrame(Ie);return}let e=va();e&&We({top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight})>1&&ze(e),Fe=requestAnimationFrame(Ie)},Le=(e=1500)=>{Me=performance.now()+e,Fe||=requestAnimationFrame(Ie)},ze=e=>{e.scrollTop=e.scrollHeight,rs={top:e.scrollTop,height:e.scrollHeight},cn(!0),dn(0),ot(e),ve=performance.now()},Be=0,Ve=()=>{Ee=0;let e=va();if(!e)return;e.scrollHeight,is=e.scrollHeight,as=e.clientHeight;let t=e.clientWidth!==Be;Be=e.clientWidth,!t&&(sn()||performance.now()<Me)?ba():t&&(Ne||performance.now()<Me)?(ba(),gn(W())):(t&&(Ne||performance.now()<Me)&&ba(),gn(W()))},He=()=>{Ee||=requestAnimationFrame(Ve)},Ue=null,Qe=e=>{Ue?.();let t=e=>{mr(e.deltaY)&&(Se=performance.now()+400,Pe(!1))},n=()=>{Se=performance.now()+400,Pe(!1)},r=t=>{let r=t.target;r&&typeof r.closest==`function`&&r.closest(`textarea, input, select, [contenteditable=''], [contenteditable='true']`)||!gr({target:r,insideFeed:!!r&&typeof e.contains==`function`&&e.contains(r),isBackground:!r||r===document.body||r===document.documentElement,editable:!1})||hr(t.key)&&n()};e.addEventListener(`wheel`,t,{passive:!0}),e.addEventListener(`touchmove`,n,{passive:!0}),window.addEventListener(`keydown`,r,{capture:!0}),Ue=()=>{e.removeEventListener(`wheel`,t),e.removeEventListener(`touchmove`,n),window.removeEventListener(`keydown`,r,{capture:!0}),Ue=null}},$e=e=>{e&&(Qe(e),e!==F&&(Te??=new ResizeObserver(e=>{let t=e[0]?.contentRect,n=t?`${Math.round(t.width)}x${Math.round(t.height)}`:``;n!==je&&(je=n,He())}),F&&Te.unobserve(F),F=e,je=``,Te.observe(e),typeof MutationObserver<`u`&&(ye??=new MutationObserver(we),be&&be!==e&&be.removeEventListener(`load`,we,!0),be=e,ye.observe(e,{childList:!0,subtree:!0,attributes:!0,characterData:!0}),e.addEventListener(`load`,we,!0))))};ee(()=>{window.addEventListener(`resize`,He),T(()=>{window.removeEventListener(`resize`,He),Te?.disconnect(),Te=void 0,F=void 0,ye?.disconnect(),ye=void 0,be&&be.removeEventListener(`load`,we,!0),be=void 0,xe&&cancelAnimationFrame(xe),Ee&&cancelAnimationFrame(Ee)})});let at=e=>`[data-eid="${globalThis.CSS?.escape?.(e)??e.replace(/["\\]/g,`\\$&`)}"]`;function ot(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:at(s),top:r(o).top}:null}let st=e=>e?`teapot.panel.narrow`:`teapot.panel`,ct=e=>{let t=localStorage.getItem(st(e));return t===null?!e:t===`1`},[pt,mt]=b(ct(me())),ht=e=>{mt(e),localStorage.setItem(st(he()),e?`1`:`0`)},gt=()=>ht(!pt()),_t=()=>{pt()&&ht(!1)},[vt,bt]=b(!1),xt=()=>bt(!1),[Tt,Et]=b(localStorage.getItem(`teapot.theme`)??`dark`),[Dt,Ot]=b(localStorage.getItem(`teapot.theme.auto`)===`1`),[kt,At]=b(localStorage.getItem(`teapot.theme.light`)??`light`),[jt,Mt]=b(null),[Nt,Pt]=b(Dr());ee(()=>{kr().then(e=>{if(e===null)return;let t=kn(Nt(),e);Pt(t),Or(t)})});let[Ft,It]=b(localStorage.getItem(`teapot.theme.dark`)??`dark`),Lt=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[Rt,zt]=b(Lt?.matches??!1);ee(()=>{let e=e=>zt(e.matches);Lt?.addEventListener(`change`,e);let t=()=>{if(document.visibilityState!==`visible`)return;let e=Lt?.matches??!1;e!==Rt()&&zt(e)};document.addEventListener(`visibilitychange`,t),T(()=>{Lt?.removeEventListener(`change`,e),document.removeEventListener(`visibilitychange`,t)})}),S(()=>{let{active:e,repaired:t}=ce(),n=Nt().find(t=>t.id===e)??null;t&&(Dt()?localStorage.setItem(Rt()?`teapot.theme.light`:`teapot.theme.dark`,e):localStorage.setItem(`teapot.theme`,e)),document.documentElement.dataset.theme=e,jr(document.documentElement,n),document.documentElement.dataset.appearance=n?.mode??xf.find(t=>t.key===e)?.mode??`dark`});let[Bt,Vt]=b(``),[Ht,Ut]=b(``),[Gt,qt]=b(``);S(()=>{let t=n();qt(w(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[Jt,Yt]=b([]),Xt=()=>Object.keys(ie().providers??{});async function Zt(e){if(e)try{let t=await X(`/api/models?provider=${encodeURIComponent(e)}`);Yt(t.models??[])}catch{Yt([])}}let Qt=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)}`:``},en=()=>{let e=Ht().trim()||z()?.model||``;if(!e)return``;let t=Jt().find(t=>t.id===e);if(!t)return``;let n=[],r=Qt(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${fn(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(` · `)},tn=null,rn=!1;S(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||ie().defaultProvider||Xt()[0]||``;if(r){if(t!==tn)tn=t,rn=!1,w(()=>Bt())!==i&&(Vt(i),Zt(i)),w(()=>Ht())&&Ut(``);else{let e=w(()=>Bt());!w(()=>Ht())&&e!==i&&ur(rn)&&(Vt(i),Zt(i))}}});let[an,on]=b(!1),[sn,cn]=b(!0),ln,[un,dn]=b(0),[mn,hn]=b(-1),gn=e=>hn(e?Xe(e):-1),[_n,vn]=b(null),bn=()=>Mn().startsWith(`[compact] `),xn=()=>{let e=bn()?Mn().slice(10):Mn();return e.length>1200?`…`+e.slice(-1200):e};S(()=>{_n()||En(e=>e?.text.startsWith(`[compact] `)?null:e)}),S(()=>{h().length,_(),_n(),oi().length,aa(),ra(),ta();let e=va();if(!e)return;let t=e.scrollHeight;t!==_e&&(_e=t,requestAnimationFrame(()=>requestAnimationFrame(()=>{sn()&&(ba(),requestAnimationFrame(()=>{if(!sn())return;let t=e.scrollHeight;t!==_e&&(_e=t,ba())}))})))});let[Sn,Cn]=b(new Map),wn=()=>{let e=n();return e?Sn().get(e)??null:null},En=e=>{let t=n();t&&Cn(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})},jn=()=>{let e=wn();if(!e)return;let t=Ct(e,h(),z()?.status);t?(t.text!==e.text||t.reasoning!==e.reasoning)&&En(t):En(null)},[Mn,Nn]=b(``),[Ln,Yn]=b(0),$n=()=>Ln(),[nr,rr]=b(``),sr;S(()=>{wn()?sr||=setTimeout(()=>{sr=void 0,Nn(wn()?.text??``),rr(wn()?.reasoning??``)},(wn()?.text.length??0)>2e4?250:(wn()?.text.length??0)>6e3?120:60):(clearTimeout(sr),sr=void 0,Nn(``),rr(``))}),T(()=>clearTimeout(sr)),S(()=>{let t=e();Cn(e=>St(e,e=>t.find(t=>t.id===e)?.status)),Yn(e=>wt(e,t,n(),wn()))}),S(()=>{let e=Mn(),t=wn()?.reasoning??``;(e||t)&&requestAnimationFrame(()=>{sn()&&ba()})}),S(()=>{let e=z()?.pendingPrompts??0,t=z()?.pendingPromptIds,n=Rr(),r=zr(n),i=Gn(r,e,t);i!==r&&B(n,i)}),S(()=>{let e=z()?.pendingPromptQueue;if(!e?.length)return;let t=z()?.session||Rr();if(wa.size){let t=new Set(e.map(e=>String(e.id??``)));for(let e of[...wa])t.has(e)||wa.delete(e)}let n=Kn(zr(t),e.filter(e=>!wa.has(String(e.id??``))));n!==zr(t)&&B(t,n)}),S(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{ya()&&(cn(!0),dn(0),xa(!0),qr())})};document.addEventListener(`visibilitychange`,e),T(()=>document.removeEventListener(`visibilitychange`,e))});let z=C(()=>e().find(e=>e.id===n()));S(()=>{let e=z()?.pendingQuestionId;e&&(h().some(t=>t.id===e)||(Cr.has(e)||(Cr.add(e),_a(n(),i())),!(aa()||ta())&&(async()=>{for(let t=0;t<8;t++){if(h().some(t=>t.id===e)||aa())return;if(ta()){await new Promise(e=>setTimeout(e,50));continue}let t=h().length;if(await da(),h().length===t)return}})()))});let Sr=``,Cr=new Set;S(()=>{let e=z()?.pendingQuestionId;e&&e!==Sr&&h().some(t=>t.id===e)&&(Sr=e,Qr(e,0))});let wr=()=>xr({sameSession:!(z()?.session!==Rr()&&z()?.session),echoCount:si()}),Tr=()=>{let e=z();return e?e.live??(e.status===`running`||e.status===`waiting`||e.status===`needs_operator`):!1},Er=()=>Qn(z(),i(),Tr()),[Ar,Mr]=b(null);C(()=>{let e=new Set;for(let t of h())t.type===`tool_result`&&(t.data?.name===`ask_operator`||t.data?.name===`ask_user`)&&e.add(String(t.data.callId));return e});let Nr=new Map,[Fr,Lr]=b([]),Rr=()=>i()||n()||`?`,zr=e=>Nr.get(e)??[],B=(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?Nr.delete(e):Nr.set(e,r),Rr()===e&&Lr(r)},[V,Br]=b([]),[Vr,Hr]=b(localStorage.getItem(`teapot.hideGhosts`)===`1`),[Ur,Wr]=b(!1),Gr=()=>V().filter(e=>!e.read).length,Kr=e=>{Br(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},qr=()=>{let e=n();e&&V().some(t=>!t.read&&t.agentId===e)&&Kr(e)},Jr=t=>{let n=V().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Jr(r.id));return n},Yr=0,Xr=e=>{Br(t=>[{...e,id:`n${++Yr}`,at:Date.now(),read:!1},...t].slice(0,50))},Zr=(t,n)=>{if(n.type===`system_note`&&n.data?.event===`background-exit`){let r=e().find(e=>e.id===t)?.id??t,i=n.data.failed===!0;if(!i)return;let a=Math.round(Number(n.data.durationMs??0)/1e3);Xr({agentId:t,kind:i?`error`:`progress`,title:`${r}: ${i?`⚠`:`✓`} background job ${String(n.data.jobId??`?`)} `+(i?`FAILED (exit ${String(n.data.code??`?`)})`:`finished (${a}s)`),body:String(n.data.cmd??``).slice(0,200)});return}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?Xr({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?Xr({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?Xr({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&Xr({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})},Qr=(e,t=0)=>{let n=i(),r=document.querySelector(at(e)),a=!!r&&Ze(r.dataset.session,n);r&&a?(r.scrollIntoView({behavior:`smooth`,block:`center`}),r.classList.add(`flash-target`),setTimeout(()=>r.classList.remove(`flash-target`),1600)):t<30&&requestAnimationFrame(()=>Qr(e,t+1))},$r=C(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of h())if(cD.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}}),[ei,ti]=b(new Set),ni=e=>{e&&ti(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},ri=()=>ti(new Set),ii=C(()=>Wn(h(),ei())),ai=C(()=>Wt({events:h(),consumed:$r().consumed,pending:Fr().map(e=>({...e,promptId:e.promptId??e.id})),serverPendingIds:z()?.pendingPromptIds,echo:mi,feedTypes:cD,renderedTypes:uD,renderedNoteEvents:dD})),oi=()=>ai().rows,si=()=>ai().pendingCount,ci=e=>e.data?.pending===!0,li=()=>oi().some(ci),ui=e=>ci(e)&&oi().find(ci)?.id===e.id,di=C(()=>{let e=new WeakMap;return oi().forEach((t,n)=>e.set(t,n)),e}),fi=(e,t)=>{let n=di().get(e);if(n!==void 0)return oi()[n+t]},pi=new Map;function mi(e){let t=`${e.id}:${e.sent?`s`:`p`}:${e.promptId??``}`,n=pi.get(t);if(n)return n;pi.size>64&&pi.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.queued===!0,queued:!e.sent&&e.queued===!0,...e.images?.length?{images:e.images}:{},...e.promptId?{promptId:e.promptId}:{}}};return pi.set(t,r),r}let hi=()=>X(`/api/config`).then(ae).catch(()=>{}),[gi,_i]=b(!1);ee(()=>{let e=()=>_i(!0);window.addEventListener(`teapot:unauthorized`,e),T(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[vi,yi]=b(``),[bi,xi]=b(!0),[Si,Ci]=b(!1),wi=``;S(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==wi?(wi=t,Ci(!1),yi(r)):t&&!Si()&&yi(r)});let Ti=async()=>{let e=document.getElementById(`todo-notify`)?.checked??!0;if(n())try{await X(`/api/agents/${n()}/todo`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:vi(),notify:e})}),Ci(!1),xi(!0),oD(`tasks saved${e&&vi().trim()?` & notification queued`:``}`),Oi()}catch(e){oD(`save failed: ${e.message}`)}},Ei=C(()=>{let e=0,t=0;for(let n of vi().split(`
|
|
184
184
|
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}});function Di(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 Oi=()=>X(`/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),Di(t,e.agents??[]))),n&&m()}).catch(()=>{}),ki=()=>X(`/api/metrics`).then(O).catch(()=>{}),[Ai,ji]=b([]),Mi=()=>X(`/api/tasks`).then(e=>ji(e.tasks)).catch(()=>{}),Ni=e=>Ai().filter(t=>t.agent===e),[Pi,Fi]=b((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.expandedSubs`)??`[]`);return new Set(e.filter(e=>typeof e==`string`))}catch{return new Set}})()),[Ii,Li]=b((()=>{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}})()),Ri=e=>Ii().has(e)||!Pi().has(e),zi=e=>{let t=new Set(Pi());if(t.has(e)?t.delete(e):t.add(e),Fi(t),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...t])),t.has(e)&&Ii().has(e)){let t=new Set(Ii());t.delete(e),Li(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))}},Bi=t=>Vn(e(),t),[Vi,Hi]=b((()=>{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}})()),Ui=C(()=>{let e=new Set;for(let t of Vi())t.startsWith(`chat:`)&&e.add(t);return e}),Wi=C(()=>In(e(),new Set(e().filter(e=>Ri(e.id)).map(e=>e.id)),Vr(),Ui())),Gi=(t,r,i,a)=>{let o=new Set(Vi());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||Bi(e().find(e=>e.id===i))===t)&&oD(`hid ${r} — click the header to show it`)}Hi(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},Ki=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,qi=e=>{let t=Ji().get(e)??0;return`${t} chat${t===1?``:`s`}`},Ji=C(()=>Hn(e())),Yi=C(()=>Un(e(),Wi(),Vi())),[Xi,Zi]=b(null),H=new Map,Qi=()=>{g([]),H.clear(),$i=0},$i=0;function U(e){return`${i()||(n()??`?`)}:${e.id}`}function ea(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=U(r),a=H.get(i);if(t[n]=a??r,!a)for(H.set(i,r),$i+=Da(r);H.size>4e3||$i>8388608;){let e=H.keys().next().value;if(e===void 0)break;let t=H.get(e);t&&($i-=Da(t)),H.delete(e)}}return t}let[ta,na]=b(!1),[ra,ia]=b(!1),[aa,oa]=b(!1),sa=0,ca=-1;function la(e){let t=ea(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 ua(){let e=n();if(!e||aa()||ta()||sn())return;if(h().length>=_()){oa(!0);return}let t=()=>{let e=va();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!aa()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(h().length>=_()){oa(!0);return}let i=h().length;if(await da(),h().length===i)return;Ge(W())&&n()===e&&xa(!0)}}async function da(){let e=n(),t=h()[0];if(e&&t&&!ta()&&!aa()){na(!0);try{let r=va(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=Xi(),c=i(),l=(await X(pa(e,{before:t.id},c,s))).events??[];if(l.length===0){oa(!0);return}if(n()!==e||h()[0]?.id!==t.id)return;la(l),requestAnimationFrame(()=>{if(n()===e){let e=va();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{na(!1)}}}function fa(e,t){return t&&o().has(t)?`&session=${encodeURIComponent(t)}`:``}function pa(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=fa(e,n);return a&&i.push(a),r&&i.push(`&branch=${encodeURIComponent(r)}&lineage=true`),i.join(``)}let ma=!1,[ha,ga]=b(!1);async function _a(e,t){let r=sa,a=t??i()??``;try{let t=Xi(),i=r!==ca||!y().length;h().length||ia(!0),X(`/api/agents/${e}/skills`).then(t=>{r===sa&&n()===e&&Wo(t.skills??[])}).catch(()=>{});let[o,s]=await Promise.all([X(pa(e,{},a,t)),i?X(`/api/agents/${e}/branches`):Promise.resolve({branches:y()})]);if(i&&(ca=r),r!==sa||n()!==e)return;if(ma){ma=!1,H.clear(),g(ea(o.events)),ga(!1);let t=va();t&&((Ca.get(a)??Ca.get(e))||(t.scrollTop=t.scrollHeight))}else g(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of ea(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{ma&&(ma=!1,ga(!1),Qi())}finally{ia(!1)}}function va(){return document.querySelector(`.feed`)}function W(){let e=va();return e?{top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight}:null}function ya(){return Ge(W())}function ba(){let e=va();if(!e)return;let t=()=>e.isConnected?(e.scrollTop=e.scrollHeight,rs={top:e.scrollTop,height:e.scrollHeight},!0):!1;if(!t())return;dn(0);let n=r=>{e.isConnected&&sn()&&(Ye(sn(),{top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight})&&t(),r>0&&requestAnimationFrame(()=>n(r-1)))};requestAnimationFrame(()=>n(2)),ln&&clearTimeout(ln),ln=setTimeout(()=>n(0),250)}function xa(e=!1){(e||sn())&&ba()}let Sa=new Map,Ca=new Map,wa=new Set,Ta=(e,t=0,n=!1)=>{let r=n?e.getBoundingClientRect().top:-1/0,i=[];for(let a of e.querySelectorAll(`[data-eid]`)){let e=a.getBoundingClientRect();if(i.push({eid:a.dataset.eid??``,session:a.dataset.session??``,top:e.top+t,height:e.height}),n&&e.top>r+4)break}return i},Ea=8388608,Da=e=>it(e),Oa=(t,n)=>Jn(c().get(t),e().find(e=>e.id===t)?.session,n);async function ka(e,t=!0,s){let l=n(),u=i(),d=h(),f=_();sa++,c().size||m();let p=Oa(e,s),y=s&&o().has(s)?s:null,b=p??y??``;if(l!==e||b!==u){if(u&&d.length){let e=d.reduce((e,t)=>e+Da(t),0);e<=Ea&&Sa.set(u,{events:d,total:f,at:Date.now(),bytes:e}),rt(Sa,{maxEntries:6,maxBytes:Ea})}{let e=va();if(ga(!0),e){let t=Ta(e,0,!0),n=t.filter(e=>!e.eid.startsWith(`@p`)),r=u||t.find(e=>e.session)?.session||``,i={top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight},a=r?_r(n.length?n:t,e.getBoundingClientRect().top,r):null;a&&We(i)>1?Ca.set(r,a):r&&Ca.delete(r)}}ri(),ma=!0,Sa.get(b)?.events.length||Qi(),ga(!0),vn(null),dn(0),cn(!0),ns=void 0}r(e),a(b),k(te.get(e)??``),Zi(null),oa(!1),na(!1),B(u||l||`?`,Fr()),Lr(zr(b||e)),localStorage.setItem(`teapot.session`,e),Va(b,t);let x=Sa.get(b);if(x?.events.length&&(g(ea(x.events)),v(x.total),ia(!0),requestAnimationFrame(()=>{n()===e&&xa(!0)})),X(`/api/agents/${e}/load`,{method:`POST`}).then(Oi).catch(()=>{}),await _a(e,b),n()!==e)return;Cn(t=>{let n=t.get(e)??null,r=Ct(n,h(),z()?.status);if(r===n)return t;let i=new Map(t);return r?i.set(e,r):i.delete(e),i}),vn(z()?.ctx?.compacting?{phase:String(z().ctx.compacting)}:null),cn(!0);let S=sa;Le(3e3);let C=performance.now()+3e3,w=()=>{if(n()!==e||S!==sa||performance.now()<Se)return;let t=va();t&&ze(t),performance.now()<C&&requestAnimationFrame(w)},ee=()=>{let t=Ca.get(b)??Ca.get(e);if(!t)return`give-up`;let r=va();if(!r)return`wait`;let i=Ta(r,r.scrollTop);if(!i.length||!i.some(e=>e.eid===t.eid))return`wait`;let a=vr(t,i,r.scrollHeight-r.clientHeight);if(a===null)return Ca.delete(b),Ca.delete(e),`give-up`;r.scrollTop=a,cn(!1),Se=performance.now()+400,Me=0,Ca.delete(b),Ca.delete(e);let o=()=>{let e=va();if(!e)return null;for(let n of e.querySelectorAll(`[data-eid]`))if(n.dataset.eid===t.eid&&n.dataset.session===t.session)return n;return null},s=r=>{if(n()!==e)return;let i=va();if(!i)return;let a=o();if(!a)return;let c=i.getBoundingClientRect().top-t.offset,l=a.getBoundingClientRect().top-c;Math.abs(l)<2||r<=0||(i.scrollTop+=l,requestAnimationFrame(()=>s(r-1)))};return requestAnimationFrame(()=>s(6)),`applied`};(async()=>{if(await ua(),n()!==e||S!==sa)return;let t=performance.now()+1500,r=()=>{if(n()!==e||S!==sa)return;let i=ee();i!==`applied`&&(i===`wait`&&performance.now()<t?requestAnimationFrame(r):(i===`give-up`&&(Pe(!0),Se=0),requestAnimationFrame(w)))};requestAnimationFrame(r)})()}let[Aa,ja]=b(!1),Ma=null,Na=null;T(()=>Ma?.close());let Pa=!1,Fa=null;document.addEventListener(`visibilitychange`,()=>Fa?.()),T(()=>{Fa=null});let Ia=!0,La=null;async function Ra(){let e=n(),t=h().at(-1)?.id,r=i(),a=document.visibilityState===`hidden`;if(!e||!t)Pa=!0,a||La?.();else try{let n=Xi(),i=await X(pa(e,{after:t},r,n)),o=i.events??[];i.gap?(g(ea(o)),v(o.length)):o.length&&(la(o),v(e=>e+o.length)),await Oi(),o.length&&!a&&ki()}catch{Pa=!0}}function za(){Ia=!0;let r=location.protocol===`https:`?`wss://`:`ws://`,a=new WebSocket(`${r}${location.host}/api/ws${pD()}`);Ma=a,a.onopen=()=>{ja(!0),Ia?Ia=!1:Ra()},a.onclose=()=>{ja(!1),setTimeout(za,1500)},a.onerror=()=>a.close();let o=new Set([`state`,`usage`,`session_start`]);a.onmessage=r=>{let s=JSON.parse(r.data);if(s.kind===`ping`)try{a.send(JSON.stringify({kind:`pong`}))}catch{}else if(s.kind!==`pong`){if(s.kind===`hello`&&Array.isArray(s.agents)){t(e=>Di(e,s.agents));let n=e();Cn(e=>St(e,e=>n.find(t=>t.id===e)?.status))}else if(s.kind===`event`&&ft(s.event)&&Cn(e=>dt(e,s.agentId)),s.kind===`llm-delta`){if(!Zn(s,n(),i()))return;if(Cn(e=>ut(e,s.agentId,s)),s.agentId===n()){let e=String(s.reasoning??``),t=String(s.text??``);e&&!t?Ln()||Yn(Date.now()):t&&Yn(0)}}else if(s.kind===`terminal-title`&&s.terminalId){let e=String(s.terminalId),t=String(s.title??``),n=String(s.cwd??``);ao(r=>r.map(r=>r.key===e?{...r,title:t||r.title,cwd:n||r.cwd}:r))}else if(s.kind===`terminal-closed`&&s.terminalId)ao(e=>{let t=e.findIndex(e=>e.key===s.terminalId);return t<0?e:(oD(s.reason===`idle`?`a terminal was closed after being idle — open a new shell with +`:`a terminal exited`),e.filter((e,n)=>n!==t))});else if(s.kind===`compaction-progress`){if(s.agentId!==n())return;s.phase===`done`?vn(null):vn({phase:s.phase,summarized:s.summarized})}else if(s.kind===`agent-update`&&s.snapshot){t(e=>{let t=e.findIndex(e=>e.id===s.snapshot.id),n=s.snapshot;return t===-1?[...e,n]:Di(e,e.map((e,n)=>n===t?s.snapshot:e))});let e=s.snapshot;(e.live??e.status===`running`)||(Cn(t=>dt(t,e.id)),e.id===n()&&Yn(0))}else if(s.kind===`metrics`&&s.metrics)O(s.metrics);else if(s.kind===`tasks`&&Array.isArray(s.tasks))ji(s.tasks);else{if(s.kind===`event`){let e=s.event?.type,t=s.event?.data??{};if(e===`system_note`&&(t.event===`prompt-delivered`||t.event===`prompt-cancelled`)){let e=String(t.promptId??``);if(e){let t=String(s.event?.session??``),n=new Set;t&&n.add(t),n.add(Rr());for(let[t,r]of Nr)r.some(t=>t.promptId===e)&&n.add(t);for(let t of n){let n=zr(t);n.some(t=>t.promptId===e)&&B(t,n.filter(t=>t.promptId!==e))}}}if(o.has(e)&&!lD.has(e)||(Zr(s.agentId,s.event),!Xn(s.event,n(),i()))||(la([s.event]),s.event&&jn(),Pa=!0,document.visibilityState!==`visible`))return;c()}document.visibilityState===`hidden`?Pa=!0:c()}}};let s=0;function c(){s||=requestAnimationFrame(()=>{s=0,Na&&=(clearTimeout(Na),null),l()})}Pa=!1;let l=async()=>{if(Na=null,n()){let e=h().at(-1)?.id,t=h().length,r=wn();r&&!Ct(r,h(),z()?.status)&&En(null),h().at(-1)?.id!==e&&(sn()?(ba(),Kr(n())):(dn(e=>e+Math.max(0,h().length-t)),gn(W())))}};La=l;let u=e=>{ga(!0),e().catch(()=>{}).finally(()=>ga(!1))};Fa=()=>{document.visibilityState===`visible`&&(ki(),Mi(),n()&&(Pa?(Pa=!1,u(()=>l())):h().at(-1)?.id?u(()=>Ra()):(Pa=!0,u(()=>l()))))}}let Ba=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function Va(e,t=!0){if(!e)return;let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=Ba(),t=o().get(e);t&&(t!==n()||e!==i())&&ka(t,!1,e||null)}),S(()=>{let e=z(),t=e?`${Tr()?`▶ `:e.status===`error`?`⚠ `:``}${yr(e)} · teapot`:`teapot`;document.title=Gr()>0?`(${Gr()}) ${t}`:t});let Ha=()=>oe()||de()||Ar()!==null||me()&&pt();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(de()){fe(!1);return}if(Ar()){Mr(null);return}if(me()&&pt()){_t();return}let e=z();if(e&&Tr()){X(`/api/agents/${e.id}/stop`,{method:`POST`}).then(Oi);return}}else if(!Ha()){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)gt();else if(e.key===`t`)ro();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=Wi().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&&ka(t[i].id)}}});let[Ua,Wa]=b(localStorage.getItem(`teapot.term`)===`1`),[Ga,Ka]=b([]),[qa,Ja]=b(!1),Ya=async()=>{let e=n();if(!e)return;let t=await X(`/api/agents/${encodeURIComponent(e)}/bg-jobs`).catch(()=>null);t?.jobs&&Ka(t.jobs)};S(()=>{n(),Ya()}),S(()=>{if(!qa())return;let e=setInterval(()=>void Ya(),2e3);T(()=>clearInterval(e))});let[Xa,Za]=b(!1),[Qa,$a]=b(``),eo=()=>{let e=z();e&&($a(yr(e)),Za(!0))},to=async()=>{if(!Xa())return;let e=z();Za(!1);let t=Qa().replace(/\s+/g,` `).trim();if(!e||!t||t===yr(e))return;let n=await X(`/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?oD(`rename failed: ${n.error}`):(d(n=>new Map(n).set(e.session,t)),Oi())},no=async e=>{n()&&(await X(`/api/agents/${encodeURIComponent(n())}/bg-jobs/${encodeURIComponent(e.id)}`,{method:`DELETE`}).catch(()=>{}),await Ya())},ro=()=>{let e=Ne||sn(),t=!Ua();Wa(t),localStorage.setItem(`teapot.term`,t?`1`:`0`),e&&Le(900),t&&Ao()},[io,ao]=b([]),oo=e=>{let t=(e.ptyTitle??``).trim(),n=/^[^@\s]+@[^:\s]+:(.+)$/.exec(t);if(n){let e=(n[1]??``).replace(/[\\/]+$/,``).split(/[\\/]/).pop()??``;if(e)return e.length<=26?e:`${e.slice(0,25)}…`}if(t)return t.length<=26?t:`${t.slice(0,25)}…`;let r=(e.cwd??``).replace(/[\\/]+$/,``).split(/[\\/]/).pop();return r&&r.length<=24?r:e.title},so=async()=>{let e=(await X(`/api/terminals`).catch(()=>null))?.terminals??[];e.length&&ao(t=>t.map(t=>{let n=e.find(e=>e.id===t.key);return n?{...t,title:n.title,cwd:n.cwd,ptyTitle:n.ptyTitle}:t}))},[co,lo]=b(0),[uo,fo]=b(-1),[po,mo]=b(!1),[ho,go]=b(0),[_o,vo]=b(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),yo=new Map,bo=[null,null],xo=()=>io()[ho()===0?co():uo()]??null;function So(e){if(!io()[e])return;let t=ho(),n=t===0?co():uo(),r=t===0?uo():co(),i=e=>t===0?lo(e):fo(e);r===e?((e=>t===0?fo(e):lo(e))(n),i(e)):(n!==e&&i(e),Ao(t))}let Co=()=>wo();async function wo(e){let t=e??n();if(t){if(io().filter(e=>e.agentId===t).length>=10)oD(`max 10 shells per agent (${t}) — that's already a lot`);else try{let e=(await X(`/api/terminals`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agentId:t})})).terminal;if(!e){oD(`could not open a shell`);return}let n=Md(io());ao(t=>[...t,{key:e.id,agentId:e.agentId,title:e.title,cwd:e.cwd}]),ho()===0?lo(n):fo(n),Ao(ho())}catch(e){oD(`could not open a shell: ${e.message}`)}}}function To(e){let t=io()[e];if(!t)return;X(`/api/terminals/${encodeURIComponent(t.key)}`,{method:`DELETE`}).catch(()=>{});let n=yo.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),yo.delete(t.key)}let r=io().filter((t,n)=>n!==e);ao(r),lo(t=>Pd(t,e,r.length)),fo(t=>t===-1?-1:Pd(t,e,r.length))}let Eo=()=>+!ue();S(()=>{Dt(),Tt(),Rt(),kt(),Ft(),ue();let e=Eo();for(let[,t]of yo)tr(t.term,e)});function Do(){for(let[,e]of yo){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}yo.clear()}function Oo(e,t){let n=yo.get(e.key);if(n&&tr(n.term,Eo()),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 Od(ar(er(Eo())));i.onWriteParsed?.(()=>{let e=ir(i.buffer.active.type);i.options.scrollSensitivity!==e&&(i.options.scrollSensitivity=e)}),i.attachCustomKeyEventHandler(e=>{if(e.type!==`keydown`||!(e.ctrlKey&&e.shiftKey)||e.altKey||e.key!==`C`&&e.key!==`c`)return!0;let t=i.getSelection();return t&&navigator.clipboard?.writeText(t).catch(()=>{}),e.preventDefault(),!1});let a=e=>{if(!(e.ctrlKey&&e.shiftKey)||e.altKey||e.key!==`C`&&e.key!==`c`)return;let t=i.getSelection();t&&(navigator.clipboard?.writeText(t).catch(()=>{}),e.preventDefault())};r.addEventListener(`keydown`,a,{capture:!0}),T(()=>r.removeEventListener(`keydown`,a,{capture:!0}));let o=new jd;i.loadAddon(o),i.open(r);let s=location.protocol===`https:`?`wss://`:`ws://`,c=()=>`${s}${location.host}/api/agents/${encodeURIComponent(e.agentId)}/term?terminal=${encodeURIComponent(e.key)}${pD()}`,l=new WebSocket(c()),u,d=!1,f=t=>{t.onmessage=t=>{let n=JSON.parse(t.data);n.kind===`data`?i.write(n.data):n.kind===`ping`||(n.kind===`exit`?(d=!0,i.write(`\r\n\x1b[2m[terminal exited ${n.code??``}]\x1b[0m\r\n`),ao(t=>t.filter(t=>t.key!==e.key)),yo.get(e.key)?.term.dispose(),yo.delete(e.key)):n.kind===`attach`&&n.error&&(d=!0,i.write(`\r\n\x1b[2m[${n.error}]\x1b[0m\r\n`)))},t.onclose=()=>{!d&&yo.has(e.key)&&(u||=(i.write(`\r
|
|
185
185
|
\x1B[2m[connection lost — reconnecting…]\x1B[0m\r
|
|
186
186
|
`),setTimeout(function(){if(u=void 0,!yo.has(e.key))return;let t=new WebSocket(c());l=t,f(t),t.addEventListener(`open`,()=>g())},1500)))}};f(l),i.onData(e=>{l.readyState===WebSocket.OPEN&&l.send(JSON.stringify({kind:`input`,data:e}))});let p={cols:0,rows:0},m,h=[],g=()=>{try{o.fit()}catch{}l.readyState===WebSocket.OPEN?(i.cols!==p.cols||i.rows!==p.rows)&&(p={cols:i.cols,rows:i.rows},l.send(JSON.stringify({kind:`resize`,cols:i.cols,rows:i.rows}))):_()};function _(){m||=setInterval(()=>{yo.has(e.key)?l.readyState===WebSocket.OPEN&&(clearInterval(m),m=void 0,g()):(clearInterval(m),m=void 0)},400)}l.addEventListener(`open`,()=>g());let v=r.parentElement??r,y=new ResizeObserver(()=>{h[0]&&clearTimeout(h[0]),h[0]=setTimeout(g,250)});y.observe(v),v!==r&&y.observe(r),setTimeout(g,60),n={el:r,term:i,fit:o,ws:l,ro:y},yo.set(e.key,n)}return n}function ko(e){let t=bo[e];if(!t)return;let n=io()[e===0?co():uo()];if(!n){[...yo.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Oo(n,t);for(let[e,r]of yo)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}})}let Ao=(e=ho())=>{if(!bo[e===0?0:1])return;let t=io()[e===0?co():uo()];if(!t)return;let n=yo.get(t.key);try{n?.term.focus()}catch{}};S(()=>{io(),po(),co(),uo(),_o(),requestAnimationFrame(()=>{ko(0),po()&&ko(1)})});let jo=null;S(()=>{if(!Ua())return;let e=n();if(!e||e===jo)return;jo=e;let t=io().map((e,t)=>({t:e,i:t})).filter(t=>t.t.agentId===e);t.length&&So(t[t.length-1].i)}),S(()=>{let e=io().length,t=Nd(co(),e);if(t!==co()&&lo(t),po()){let t=Nd(uo(),e);t!==uo()&&fo(t)}});let Mo=e=>{e.preventDefault();let t=e.clientY,n=_o(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));vo(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(_o())),requestAnimationFrame(()=>{ko(0),po()&&ko(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},No=()=>{let e=!po();mo(e),e&&(uo()<0||uo()===co()||uo()>=io().length)&&fo(Fd(co(),io().length)),requestAnimationFrame(()=>{ko(0),po()&&ko(1)})};T(Do);let Po=e=>t=>{bo[e]=t,t&&requestAnimationFrame(()=>{ko(e),po()&&ko(1),setTimeout(()=>ko(e),200)})};ee(()=>{let t=e=>{e.key===`Escape`&&et()&&nt()};window.addEventListener(`keydown`,t),T(()=>window.removeEventListener(`keydown`,t)),hi(),Oi().then(async()=>{await m();let t=Ba(),n=On({agents:e(),urlId:t,ownerOf:e=>o().get(e),lastId:localStorage.getItem(`teapot.session`),hideGhosts:Vr()});n&&ka(n.id,!1,t||null)}),ki(),Mi(),Ro(),za(),X(`/api/terminals`).then(e=>{let t=e.terminals??[];t.length&&(ao(t.map(e=>({key:e.id,agentId:e.agentId,title:e.title,cwd:e.cwd,ptyTitle:e.ptyTitle}))),Ua()&&(lo(0),fo(-1)))}).catch(()=>{}),T(()=>{})});let Fo=[{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`}],[Io,Lo]=b([]),Ro=()=>X(`/api/personas`).then(e=>Lo(e.personas)).catch(()=>{}),[zo,Bo]=b(!1),Vo=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},Ho=()=>{let t=Vo();return t===null?[]:[...Io().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))},Uo=new Set([`start`,`stop`,`fork`,`compact`]),[G,Wo]=b([]),[Go,Ko]=b(null),[qo,Jo]=b(-1),Yo=()=>{let e=ne();if(!e.startsWith(`/`)||e.includes(`
|
|
187
187
|
`))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=Fo.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Uo.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=G().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[]},Xo,Zo,Qo,$o=!1;function es(e){if(!Zo){Zo=document.createElement(`div`),Zo.setAttribute(`aria-hidden`,`true`);let e=Zo.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`,Zo.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`])Zo.style.setProperty(e,t.getPropertyValue(e));if(Zo.style.width=`${e.clientWidth}px`,Zo.setAttribute(`data-mirror-text`,e.value.endsWith(`
|
|
188
188
|
`)?`${e.value} `:e.value),Qo||(Qo=document.createElement(`div`),Qo.setAttribute(`aria-hidden`,`true`),Qo.style.cssText=`position:absolute;left:-9999px;top:0;pointer-events:none`,document.body.appendChild(Qo)),Zo.parentElement!==Qo&&Qo.appendChild(Zo),!$o){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),$o=!0}return Zo.scrollHeight}let ts=()=>{if(!Xo)return;let e=an();if(!Xo.value&&!e){Xo.style.height=``;return}let t=es(Xo),n=e?-1:pr(t,360);Xo.style.height=n===-1?``:`${n}px`},ns,rs=null,is,as;S(()=>{let e=ne();Xo&&dr(sD)&&(fr(Xo.value,e)&&(Xo.value=e),ts())}),ee(()=>{let e=0,t=()=>{e||=requestAnimationFrame(()=>{e=0,ts()})};window.addEventListener(`resize`,t),T(()=>{window.removeEventListener(`resize`,t),e&&cancelAnimationFrame(e)})});let[os,ss]=b([]),cs=e=>{let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));for(let e of t){if(e.size>8e6){oD(`"${e.name}" is over 8 MB — skipped`);continue}let t=new FileReader;t.onload=()=>{ss(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},ls=async(t,r)=>{let i=r??n();if(!i)return;let a=os(),o=e().find(e=>e.id===i)?.session||i,s=sn(),c=qn((z()?.status??``)===`running`),l=`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`;B(o,[...zr(o),{id:l,text:t,at:Date.now(),...c?{queued:!0}:{},...a.length?{images:a.map(e=>e.url)}:{}}]);try{let e=await X(`/api/agents/${i}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t,start:!0,clientId:l,...a.length?{images:a}:{}})}),n=e.promptId,r=e.ahead;(n||typeof r==`number`)&&B(o,zr(o).map(e=>e.id===l?{...e,...n?{promptId:n}:{},...typeof r==`number`?{queued:r>0}:{}}:e)),ss([]),Rd(an())&&on(!1),ts(),s&&(cn(!0),dn(0),Se=0,Le(700))}catch(e){B(o,zr(o).filter(e=>e.id!==l)),k(t),console.error(`send failed:`,e)}},us=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=Io().some(e=>e.key.toLowerCase()===r),s=e().some(e=>e.id.toLowerCase()===r);try{if(o){if(!a){oD(`usage: @${r} <task>`);return}oD(`🧩 spawned ${(await X(`/api/agents/${n()}/spawn`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({persona:r,task:a,context:zo()?`fork`:`none`})})).id}${zo()?` (forked context)`:``}`),Oi(),k(``)}else if(s){if(!a){oD(`usage: @${r} <message>`);return}await X(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),oD(`→ delivered to @${r}`),k(``)}else{oD(`unknown @${r} — personas: ${Io().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){oD(`@${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 ds(t,n)}catch(e){throw k(ne()?`${i}\n${ne()}`:i),e}}else k(``),await ls(i)}},ds=async(e,t)=>{let r=n();if(!r)return;let i=(e,t)=>X(`/api/agents/${r}${e}`,{method:`POST`,headers:{"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}}).then(Oi);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await ka(r);else if(e===`compact`)oD((await i(`/compact`))?.ran?`context compacted`:`nothing to compact yet`);else if(e===`goal`){if(!t){oD(`usage: /goal <text>`);return}await i(`/goal`,{text:t,notify:!0}),oD(`goal saved & notification queued`)}else if(e===`skill`){if(!t){oD(`usage: /skill <name>`);return}await i(`/skill`,{name:t}),oD(`skill "${t}" dispatched`)}else oD(`unknown command "${e}" — /start /stop /fork /goal /skill /compact`)}catch(t){oD(`/${e} failed: ${t.message}`)}},fs,ps=0;S(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!fs)return;let e=Math.min(ps,fs.scrollHeight);Math.abs(fs.scrollTop-e)>1&&(fs.scrollTop=e)})})});let ms=e=>()=>n()&&X(`/api/agents/${n()}${e}`,{method:`POST`}).then(Oi),hs=async()=>{let i=n();if(!i)return;let a=new Set([i,...Bn(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 X(`/api/agents/${i}/archive`,{method:`POST`}).catch(()=>{}),t(e().filter(e=>!a.has(e.id))),m(!0);let s=Id(e(),a);s?ka(s.id):(r(null),Qi())},gs=async()=>{n()&&(oD(`stopped: ${((await X(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),Oi())},_s=()=>X(`/api/agents/${z().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await m(!0),await ka(z().id)}),[vs,ys]=b(``),[bs,xs]=b(``),[Ss,Cs]=b(!1),[ws,Ts]=b(!0),[Es,Ds]=b(!0),Os=``;S(()=>{let e=n();e&&(z()?.goal,e!==Os&&(Os=e,Cs(!1),ys(``),xs(``)))}),S(()=>{let e=z()?.goal;if(ws()||Ss()||!e)return;let t=String(e.text??``),n=String(e.verify??``);t!==vs()&&ys(t),n!==bs()&&xs(n)});let ks=async e=>{if(e.preventDefault?.(),n()&&vs().trim())try{await X(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:vs(),notify:Es(),...bs().trim()?{verify:bs()}:{}})}),ys(``),xs(``),Cs(!1),Ts(!0),Oi()}catch(e){oD(`goal save failed: ${e.message}`)}},As=()=>(()=>{var e=iT(),t=e.firstChild.nextSibling;return t.firstChild,R(t,j(N,{get when(){return nr().trim()!==``},get children(){var e=tT(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return R(t,j(vf,{get startedAt(){return $n()}}),null),Ae(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),S(()=>{nr(),t&&(e.scrollTop=e.scrollHeight)})},n),R(n,nr),e}}),null),R(t,j(N,{get when(){return Mn()},get fallback(){return aT()},get children(){return j(N,{get when(){return bn()},get fallback(){return(()=>{var e=rT();return x(()=>e.innerHTML=Re(Mn()+`▍`)),e})()},get children(){return[nT(),(()=>{var e=rT();return x(()=>e.innerHTML=Re(xn()+`▍`)),e})()]}})}}),null),e})();return[j(N,{get when(){return gi()},get children(){var e=oT();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 ue()},children:e=>(()=>{var t=zT(),n=t.firstChild;return x(t=>{var r=Fn(e(),An[An.length-1]),i=Pn(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=PT(),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(()=>!!he())()&&vt()},get children(){var e=sT();return e.$$click=xt,e}}),r),R(r,j(N,{get when(){return he()},get children(){var e=cT(),t=e.firstChild.nextSibling;return t.$$click=xt,e}}),i),R(i,j(M,{get each(){return Yi()},children:t=>[j(N,{get when(){return P(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=VT(),n=e.firstChild,r=n.nextSibling;return e.$$click=()=>Gi(`ws:${t.wsHeader}`,Ki(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),R(n,()=>t.wsCollapsedGroup?`▸`:`▾`),R(r,()=>Ki(t.wsHeader)),R(e,j(N,{get when(){return t.wsCollapsedGroup},get children(){var e=BT();return R(e,()=>Ji().get(t.wsHeader)??0),e}}),null),x(n=>{var i=t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${qi(t.wsHeader)} hidden). Click to show.`:(Ji().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${qi(t.wsHeader)} in this directory`:t.wsHeader||``,a=t.wsHeader;return i!==n.e&&I(e,`title`,n.e=i),a!==n.t&&I(r,`title`,n.t=a),n},{e:void 0,t:void 0}),e}}),j(N,{get when(){return P(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=KT(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>ka(t.a.id),R(r,j(N,{get when(){return Rn({isSub:!!t.a.parent,collapsed:t.chatCollapsedGroup===!0,hasChildren:e().some(e=>e.parent===t.a.id)})},get fallback(){return qT()},get children(){return(()=>{let e=!t.a.parent,n=e&&Ui().has(`chat:${t.a.id}`)||Ri(t.a.id);return(()=>{var r=JT();return r.$$click=r=>{if(r.stopPropagation(),e){if(n){if(!Pi().has(t.a.id)){let e=new Set(Pi());e.add(t.a.id),Fi(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}if(Ii().has(t.a.id)){let e=new Set(Ii());e.delete(t.a.id),Li(e),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...e]))}}else if(Pi().has(t.a.id)){let e=new Set(Pi());e.delete(t.a.id),Fi(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}Gi(`chat:${t.a.id}`,t.a.id,n)}else zi(t.a.id)},R(r,n?`▸`:`▾`),x(()=>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,()=>yr({id:t.a.id,sessionTitle:t.a.sessionTitle??u().get(t.a.session??``)})),R(r,(()=>{var e=P(()=>!!t.a.workspaceMissing);return()=>e()?YT():null})(),null),R(r,j(N,{get when(){return Jr(t.a.id)>0},get children(){var e=HT();return e.firstChild,R(e,()=>Jr(t.a.id),null),x(()=>I(e,`title`,`${Jr(t.a.id)} unread notification${Jr(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),R(r,j(N,{get when(){return Ri(t.a.id)||t.chatCollapsedGroup===!0&&Ui().has(`chat:${t.a.id}`)},get children(){return(()=>{let n=Bn(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=XT();return e.firstChild,L(e,`subcount`+(r>0?` live`:``)),R(e,()=>n.length,null),R(e,r>0?` · ▶${r}`:``,null),x(()=>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 UT()}}),null),R(r,j(N,{get when(){return Ni(t.a.id).length>0},get children(){var e=WT();return x(()=>I(e,`title`,Ni(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
|
|
189
|
-
`))),e}}),null),R(r,j(N,{get when(){return t.a.goal.status===`done`},get children(){return GT()}}),null),x(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=zn(t.a.id,Io().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`:br({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(),Wr(!Ur()),Ur()||Br(e=>e.map(e=>({...e,read:!0})))},R(o,j(N,{get when(){return Gr()>0},get children(){var e=lT();return R(e,Gr),e}}),null),R(a,j(Ud,{icon:`👻`,get active(){return Vr()},get title(){return Vr()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!Vr();if(Hr(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&z()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&ka(t.id)}}}),null),R(a,j(Ud,{icon:`+`,title:`new agent`,onClick:()=>{hi(),se(!0)}}),null),R(a,j(Ud,{icon:`⚙️`,title:`settings`,onClick:()=>{hi(),fe(!0)}}),null),R(c,`0.37.
|
|
189
|
+
`))),e}}),null),R(r,j(N,{get when(){return t.a.goal.status===`done`},get children(){return GT()}}),null),x(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=zn(t.a.id,Io().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`:br({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(),Wr(!Ur()),Ur()||Br(e=>e.map(e=>({...e,read:!0})))},R(o,j(N,{get when(){return Gr()>0},get children(){var e=lT();return R(e,Gr),e}}),null),R(a,j(Ud,{icon:`👻`,get active(){return Vr()},get title(){return Vr()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!Vr();if(Hr(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&z()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&ka(t.id)}}}),null),R(a,j(Ud,{icon:`+`,title:`new agent`,onClick:()=>{hi(),se(!0)}}),null),R(a,j(Ud,{icon:`⚙️`,title:`settings`,onClick:()=>{hi(),fe(!0)}}),null),R(c,`0.37.203`,null),R(d,j(N,{get when(){return D()},get children(){return[`master rss `,P(()=>D().rssMb),`MB · heap `,P(()=>D().heapUsedMb),`MB`,j(N,{get when(){return D().heapTotalMb!==void 0},get children(){return[` · total `,P(()=>D().heapTotalMb),`MB`]}}),j(N,{get when(){return D().externalMb!==void 0},get children(){return[` · ext `,P(()=>D().externalMb),`MB`]}}),j(N,{get when(){return D().arrayBuffersMb!==void 0},get children(){return[` · buf `,P(()=>D().arrayBuffersMb),`MB`]}}),uT(),j(N,{get when(){return D().messagesInMemory!==void 0},get children(){return[`msgs `,P(()=>D().messagesInMemory),` in `,P(()=>D().loadedSessions),` loaded session(s)`,uT()]}}),`load1 `,P(()=>D().loadavg1),` · up `,P(()=>Math.floor(D().uptimeSec/60)),`m`]}})),R(f,j(N,{get when(){return z()?.id},get fallback(){return ZT()},get children(){return[(()=>{var t=gT(),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 he()},get children(){var e=dT();return e.$$click=()=>bt(!vt()),x(()=>I(e,`aria-expanded`,vt())),e}}),r),r.$$click=()=>eo(),R(t,j(N,{get when(){return Xa()},get fallback(){return(()=>{var e=QT();return e.$$click=()=>eo(),R(e,()=>yr(z())),x(()=>I(e,`title`,`${br(z(),z().session)} — click to rename`)),e})()},get children(){var e=fT();return e.addEventListener(`blur`,()=>void to()),e.$$keydown=e=>{e.key===`Enter`?(e.preventDefault(),to()):e.key===`Escape`&&(e.preventDefault(),Za(!1))},e.$$input=e=>$a(e.currentTarget.value),Ae(e=>{requestAnimationFrame(()=>{e.focus(),e.select()})},e),I(e,`spellcheck`,!1),x(()=>e.value=Qa()),e}}),i),R(i,()=>z().status),R(t,j(N,{get when(){return wr()>0},get children(){var e=pT(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling;return n.nextSibling,R(e,wr,t),R(e,()=>wr()===1?`message`:`messages`,n),R(e,()=>z().status===`stopped`?` (stopped)`:``,null),x(()=>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(z()?.bgRunning??0)>0},get children(){var e=mT();return e.firstChild,e.$$click=()=>{Ja(!qa()),qa()&&Ya()},R(e,()=>z().bgRunning,null),x(t=>{var n=qa(),r=`${z().bgRunning} background shell(s) running — 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 Ni(z().id).length>0},get children(){var e=hT();return e.firstChild,R(e,()=>Ni(z().id).length,null),x(()=>I(e,`title`,`scheduled tasks:\n${Ni(z().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
|
|
190
190
|
`)}`)),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=()=>(Tr()?ms(`/stop`):ms(`/start`))(),R(f,()=>Tr()?`■ stop`:`▶ start`),R(d,j(N,{get when(){return e().some(e=>e.parent===n())},get children(){return j(Ud,{icon:`⏹`,title:`stop every sub-agent this agent spawned (descendants included)`,onClick:gs})}}),p),R(d,j(Ud,{icon:`🗄`,title:`archive this agent — reversible: it leaves the list but keeps its config and history (restore in ⚙️ settings → archive)`,onClick:hs}),null),R(d,j(Ud,{icon:`⑂`,title:`fork: branch off the conversation here — try things without disturbing the main line`,onClick:_s}),null),R(d,j(Ud,{icon:`⌨`,title:`terminal (t)`,onClick:ro}),null),R(d,j(Ud,{icon:`▤`,title:`toggle details panel (d)`,get active(){return pt()},onClick:gt}),null),R(t,j(yn,{get open(){return qa()},get jobs(){return Ga()},onClose:()=>Ja(!1),onKill:no}),null),x(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`+(Tr()?` danger`:``),s=Tr()?`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=xT();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r={top:t.scrollTop,height:t.scrollHeight,viewport:t.clientHeight},i=Ke(r,rs,is,as);rs=null,performance.now();let a=ns?.top,o=ns?.height;is=r.height,as=r.viewport,ns=r,gn(r);let s=sn(),c=performance.now();c-ve>100&&(ve=c,ot(t));let l=o!==void 0&&Math.abs(r.height-o)>.5,u=a!==void 0&&r.top<a-.5&&!l;u&&(Se=performance.now()+400);let d=u?!1:Ge(r)?!0:performance.now()<Se?!1:Je(s,i,r,a);d===s?Ne=d:Pe(d),d&&i!==`reader`?(un()&&dn(0),qr(),qe(d,r)&&We(r)>0&&ba()):d&&Ge(r)&&(un()&&dn(0),qr()),r.top<=4&&n()&&!ta()&&!aa()&&h().length>0&&da()}),Ae(e=>$e(e),e),R(e,j(N,{get when(){return _n()},children:e=>(()=>{var t=$T();return t.firstChild,R(t,(()=>{var t=P(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?fn(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),R(e,j(N,{get when(){return P(()=>!!aa())()&&oi().length>0},get children(){return _T()}}),null),R(e,j(N,{get when(){return ta()},get children(){return vT()}}),null),R(e,j(N,{get when(){return oi().length>0},get fallback(){return P(()=>!!(ra()||ha()))()?(()=>{var e=eE();return R(e,j(Dn,{what:`timeline`})),e})():tE()},get children(){return[j(M,{get each(){return oi()},children:e=>[j(N,{get when(){return P(()=>!!(ui(e)&&Er()))()&&wn()},get children(){return As()}}),j(xC,{e,prev:()=>fi(e,-1),next:()=>fi(e,1),get showBranch(){return y().length>1},res:()=>$r().resFor.get(e.id),get orphan(){return $r().orphanCalls.has(e.id)},onOption:e=>void ls(e),answeredIds:ii,onAnswered:ni,get agentActive(){return P(()=>!!Er())()&&yt(e)},onResize:()=>{sn()&&ba()},get agentId(){return n()??void 0},get onCancel(){return e.data?.source===`user`&&e.data?.pending&&e.data?.sent!==!0?()=>{let t=zr(Rr()).find(t=>t.id===e.id),r=String(t?.promptId??e.data?.promptId??``);if(!r){oD(`still being sent — try again in a moment`);return}let i=sn();X(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:r})}).then(e=>{let t=String(e.text??``);k(ne()?`${t}\n\n${ne()}`:t),wa.add(r),B(Rr(),Fr().filter(e=>e.promptId!==r));let n=va();i?Le(400):n&&(ot(n),ve=performance.now()),oD(`message withdrawn — draft restored`)}).catch(()=>oD(`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()=>{Tr()&&(await X(`/api/agents/${n()}/stop`,{method:`POST`}).catch(()=>{}),await Oi()),Mr({eventId:e.id,text:String(e.data?.text??``)})}:void 0}})]}),j(N,{get when(){return P(()=>!(li()||!Er()))()&&wn()},get children(){return As()}}),j(N,{get when(){return ha()},get children(){return yT()}}),j(N,{get when(){return P(()=>!!ra())()&&!ha()},get children(){return bT()}})]}}),null),e})(),j(N,{get when(){return et()},children:e=>(()=>{var t=nE(),n=t.firstChild;return De(t,`click`,nt,!0),n.$$click=e=>e.stopPropagation(),x(()=>I(n,`src`,e())),t})()}),j(N,{get when(){return Ua()},get children(){var t=ET(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{vo(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(_o()))},n.$$pointerdown=Mo,R(i,j(M,{get each(){return io()},children:(e,t)=>(()=>{var n=rE(),r=n.firstChild.nextSibling;return n.$$click=()=>{So(t()),so()},R(n,()=>oo(e),r),r.$$click=e=>{e.stopPropagation(),To(t())},x(r=>{var i=`termtab`+(ho()===0&&co()===t()?` active`:``)+(po()&&ho()===1&&uo()===t()?` active`:``),a=`${e.cwd?`${e.cwd}\n`:``}${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(Ud,{icon:`+`,title:`new shell in this workspace`,onClick:Co}),null),R(o,(()=>{var t=P(()=>!!xo());return()=>t()?e().find(e=>e.id===xo().agentId)?.workspace.split(`/`).filter(Boolean).pop():z()?.workspace})()),R(a,j(Ud,{icon:`◫`,get title(){return po()?`single pane`:`split panes (50/50)`},onClick:No}),null),R(a,j(Ud,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:ro}),null);var l=Po(0);return typeof l==`function`&&Ae(l,c),c.$$pointerdown=()=>{go(0),Ao(0)},R(c,j(N,{get when(){return co()<0||co()>=io().length},get children(){return ST()}})),R(s,j(N,{get when(){return po()},get children(){return[CT(),(()=>{var e=TT(),t=Po(1);return typeof t==`function`&&Ae(t,e),e.$$pointerdown=()=>{go(1),Ao(1)},R(e,j(N,{get when(){return uo()<0||uo()>=io().length},get children(){return wT()}})),x(()=>e.classList.toggle(`focused`,ho()===1)),e})()]}}),null),x(e=>{var n={height:`${_o()}px`},r=!!po(),i=ho()===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=MT(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling;return R(e,j(N,{get when(){return P(()=>mn()>32)()&&!sn()},get children(){var e=DT();return e.firstChild,e.$$click=()=>{xa(!0),qr()},R(e,(()=>{var e=P(()=>un()>0);return()=>e()?`${un()} new message${un()>1?`s`:``}`:`jump to present`})(),null),e}}),t),R(e,j(N,{get when(){return Yo().length>0},get children(){var e=OT();return R(e,j(M,{get each(){return Yo()},children:(e,t)=>(()=>{var n=iE(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{k(e.insert),Jo(-1)},R(r,()=>e.insert.trim()),R(i,()=>e.title),x(r=>{var i=`cmdrow`+(t()===qo()?` 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 Ho().length>0},get children(){var e=OT();return R(e,j(M,{get each(){return Ho()},children:e=>(()=>{var t=aE(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{k(`@${e.key} `),Jo(-1)},R(n,()=>e.key,null),R(r,()=>e.label),x(()=>I(t,`title`,e.label)),t})()})),e}}),t),R(e,j(N,{get when(){return os().length>0},get children(){var e=kT(),t=e.firstChild;return R(e,j(M,{get each(){return os()},children:(e,t)=>(()=>{var n=oE(),r=n.firstChild,i=r.nextSibling;return r.$$click=()=>tt(e.url),i.$$click=()=>ss(e=>e.filter((e,n)=>n!==t())),x(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),t.$$click=()=>ss([]),e}}),t),t.addEventListener(`submit`,us),n.$$keydown=e=>{let t=Yo();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),Jo(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),Jo(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&qo()>=0&&!sD?(e.preventDefault(),k(t[qo()].insert),Jo(-1)):e.key===`Escape`&&t.length>0?Jo(-1):Ld({key:e.key,shiftKey:e.shiftKey,composing:sD,maximized:an()})&&(e.preventDefault(),us(e))},n.$$input=e=>{k(e.currentTarget.value),Jo(0),ts()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),cs(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{sD=!1}),k(Xo?.value??``)}),n.addEventListener(`compositionstart`,()=>{sD=!0}),Ae(e=>{Xo=e,e.value=ne()},n),R(t,j(N,{get when(){return P(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=AT(),t=e.firstChild;return t.addEventListener(`change`,e=>Bo(e.currentTarget.checked)),x(()=>t.checked=zo()),e}}),r),r.$$click=()=>{let e=Ne||sn(),t=!an();on(t),e&&Le(900),requestAnimationFrame(()=>ts())},R(r,()=>an()?`⤡`:`⤢`),R(t,j(Ud,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&cs(e.currentTarget.files),e.currentTarget.value=``}),R(e,j(N,{get when(){return rD()},get children(){var e=jT();return R(e,rD),e}}),null),x(t=>{var i=`composer`+(an()?` maximized`:``),a=`message #${z().id} — / for commands · paste or 📎 to attach images`,o=an()?`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(()=>!!he())()&&pt()},get children(){var e=NT();return e.$$click=()=>ht(!1),e}}),p),p.addEventListener(`scroll`,e=>{ps=e.currentTarget.scrollTop});var g=fs;return typeof g==`function`?Ae(g,p):fs=p,R(m,j(Ud,{icon:`✕`,title:`close details panel (esc)`,onClick:_t}),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(eT,{agentId:e,get workspace(){return z().workspace}})}),(()=>{var e=cE();return e.firstChild,R(e,j(N,{get when(){return Jt().length},get children(){var e=sE(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>Jt().length,t),e}}),null),e})(),(()=>{var t=dE(),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;rn=!0,Vt(r),Ut(cr(ie().providers,r,e().find(e=>e.id===n()))),Zt(r)}),R(r,j(M,{get each(){return Xt()},children:e=>(()=>{var t=kE();return t.value=e,R(t,e,null),R(t,()=>e===ie().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>Ut(e.currentTarget.value),R(o,j(M,{get each(){return Jt()},children:e=>(()=>{var t=kE();return x(()=>t.value=e.id),t})()})),R(t,j(N,{get when(){return z().effortSupported},get children(){var e=lE(),t=e.firstChild.nextSibling;return t.firstChild,t.addEventListener(`change`,e=>qt(e.currentTarget.value)),R(t,j(M,{get each(){return P(()=>!!z().effortOptions?.length)()?z().effortOptions:tD},children:e=>(()=>{var t=kE();return t.value=e,R(t,e),t})()}),null),x(()=>t.value=Gt()),e}}),s),c.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await X(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:Bt(),model:Ht().trim()||void 0,contextWindowTokens:Jt().find(e=>e.id===(Ht().trim()||void 0))?.contextLength,...z().effortSupported?{reasoningEffort:Gt()}:{}})}),t.textContent=`✓ applied`,Oi()}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 en()},get children(){var e=uE();return R(e,en),e}}),null),x(()=>I(a,`placeholder`,lr(ie().providers,Bt(),z(),or(z(),ie().providers,ie().defaultProvider)))),x(()=>r.value=Bt()),x(()=>a.value=Ht()),t})(),(()=>{var e=pE(),t=e.firstChild.nextSibling,r=t.firstChild;return R(e,j(N,{get when(){return!!z().goal.text.trim()},get fallback(){return AE()},get children(){var e=fE();return R(e,()=>z().goal.status),x(()=>L(e,`badge ${z().goal.status===`active`?`running`:z().goal.status}`)),e}}),t),r.addEventListener(`change`,e=>{n()&&X(`/api/agents/${n()}/auto-continue`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Oi)}),x(()=>r.checked=z().autoContinue??!0),e})(),(()=>{var e=mE();return e.firstChild,R(e,j(M,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=jE();return t.$$click=()=>{n()&&X(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(Oi)},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`),x(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(Tn,{get goal(){return P(()=>!!ws())()?String(z().goal.text??``):vs()},get verify(){return P(()=>!!ws())()?String(z().goal.verify??``):bs()},get preview(){return ws()},onGoal:e=>{ys(e),Cs(!0)},onVerify:e=>{xs(e),Cs(!0)}}),(()=>{var e=hE(),t=e.firstChild,n=t.firstChild,r=t.nextSibling;return R(e,j(Ud,{get icon(){return ws()?`✎`:`👁`},get title(){return ws()?`edit the goal and its verification contract`:`rendered goal`},onClick:()=>{ws()&&(ys(String(z().goal.text??``)),xs(String(z().goal.verify??``)),Cs(!1)),Ts(!ws())}}),t),n.addEventListener(`change`,e=>Ds(e.currentTarget.checked)),r.$$click=e=>void ks(e),x(()=>n.checked=Es()),e})(),j(N,{get when(){return z().goal.audit},children:e=>j($t,{get title(){return e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`},get meta(){return nn(e().at)},get tone(){return e().verdict===`approved`?`ok`:`warn`},get body(){return P(()=>!!Kt(e().feedback))()?`_the auditor returned a verdict with no detail_`:e().feedback}})}),(()=>{var e=_E();return e.firstChild,R(e,j(N,{get when(){return Ei().total>0},get children(){var e=gE(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,R(e,()=>Ei().done,t),R(e,()=>Ei().total,n),x(t=>Oe(e,Ei().done===Ei().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),null),e})(),j(N,{get when(){return Ei().total>0},get children(){var e=vE(),t=e.firstChild;return x(e=>{var n=`barfill `+(Ei().done===Ei().total?``:`warn`),r=`${Math.round(Ei().done/Ei().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(Rf,{get draft(){return vi()},get preview(){return bi()},onDraft:e=>{yi(e),Ci(!0)}}),(()=>{var e=yE(),t=e.firstChild,n=t.nextSibling;return R(e,j(Ud,{get icon(){return bi()?`✎`:`👁`},get title(){return bi()?`edit markdown`:`rendered checklist`},onClick:()=>xi(!bi())}),t),n.$$click=Ti,e})(),bE(),j(N,{get when(){return z().latestProgress},get fallback(){return ME()},children:e=>(()=>{var t=LE(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return R(t,j(N,{get when(){return e().recent},get children(){var t=NE(),n=t.firstChild.nextSibling;return x(()=>n.innerHTML=lt(e().recent)),t}}),i),R(t,j(N,{get when(){return e().problems},get children(){var t=PE(),n=t.firstChild.nextSibling;return x(()=>n.innerHTML=lt(e().problems)),t}}),i),R(t,j(N,{get when(){return e().next},get children(){var t=FE(),n=t.firstChild.nextSibling;return x(()=>n.innerHTML=lt(e().next)),t}}),i),R(t,j(N,{get when(){return e().goalStatus},get children(){var t=IE(),n=t.firstChild.nextSibling;return R(n,()=>e().goalStatus),t}}),i),R(i,()=>nn(e().ts)),x(()=>r.innerHTML=lt(e().doing)),t})()}),xE(),(()=>{var e=wE(),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 RE()},children:e=>{let t=C(()=>{let t=e,n=Jt().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=HE(),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,()=>fn(r().usedTokens),o),R(t,j(N,{get when(){return r().effectiveWindow},get children(){var e=zE(),t=e.firstChild;return R(e,()=>i(r().pct),t),R(e,()=>fn(r().effectiveWindow),null),x(()=>L(e,`pill ${r().cls}`)),e}}),null),R(e,j(N,{get when(){return r().effectiveWindow},get children(){var e=BE(),t=e.firstChild;return x(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,()=>fn(r().usingDerived?r().derivedBudget:r().compactAt),l),R(u,()=>r().usingDerived?`75% of window`:`manual`),R(e,j(N,{get when(){return _n()||r().compacting},get children(){var e=VE(),t=e.firstChild.nextSibling.nextSibling;return R(t,()=>_n()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&X(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Oi)}),x(()=>f.checked=z().autoCompact!==!1),e})()}}),t),R(i,()=>fn(z().stats.inputTokens)),R(o,()=>fn(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=SE(),t=e.firstChild.nextSibling;return t.firstChild,R(t,()=>gD(z().stats.costUsd??0),null),x(()=>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=CE(),t=e.firstChild.nextSibling,n=t.firstChild;return R(t,()=>Math.round(z().stats.cachedInputTokens/Math.max(1,z().stats.inputTokens)*100),n),x(()=>I(e,`title`,`${fn(z().stats.cachedInputTokens)} input tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),x(()=>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=EE();return e.firstChild.nextSibling,R(e,j(N,{get when(){return Xi()},get children(){var e=TE(),t=e.firstChild.nextSibling;return R(t,Xi),e}}),null),e})(),j(M,{get each(){return y()},children:e=>(()=>{var t=UE(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=Xi()===e.branch?null:e.branch,r=t!==Xi();Zi(t),n()&&(r&&(sa++,Qi(),v(0),oa(!1)),_a(n()))},R(r,()=>e.branch,null),R(r,()=>e.branch===z().branch?` (current)`:``,null),R(i,()=>e.events,a),x(n=>{var r=`branch-row`+(e.branch===z().branch||e.branch===Xi()?` cur`:``),i=e.branch===Xi()?`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=OE();return e.firstChild,R(e,j(N,{get when(){return Ai().length>0},get children(){var e=DE(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>Ai().length,t),e}}),null),e})(),j(N,{get when(){return Ai().length>0},get fallback(){return WE()},get children(){return j(M,{get each(){return Ai()},children:e=>(()=>{var t=KE(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>ka(e.agent),R(i,()=>e.id),R(a,()=>e.agent,null),R(r,j(N,{get when(){return e.forked},get children(){return GE()}}),null),R(o,()=>e.schedule,s),R(o,(()=>{var t=P(()=>!!e.next);return()=>t()?nn(e.next):`—`})(),null),R(o,(()=>{var t=P(()=>!!e.last);return()=>t()?` · last ${nn(e.last)}`:` · never ran`})(),null),R(c,()=>pn(e.prompt,90)),x(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${pn(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),x(e=>{var n=`layout`+(pt()?``:` right-hidden`)+(vt()?` left-open`:``),i=`sidebar`+(vt()?` open`:``),a=`iconbtn notifbtn`+(Gr()>0?` has-unread`:``),s=Gr()>0?`${Gr()} unread notifications`:`notifications`,c=`conn`+(Aa()?` ok`:``),u=Aa()?`live (websocket)`:`reconnecting…`,d={"--termh":`${_o()}px`},m=`rightbar`+(pt()?` 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 Ur()},get children(){return[(()=>{var e=FT();return e.$$click=()=>Wr(!1),e})(),(()=>{var t=RT(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return R(r,j(N,{get when(){return V().length>0},get children(){var e=IT();return e.$$click=()=>Br([]),e}}),i),i.$$click=()=>Wr(!1),R(t,j(N,{get when(){return V().length>0},get fallback(){return qE()},get children(){var t=LT();return R(t,j(M,{get each(){return V()},children:t=>(()=>{var r=YE(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{Br(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&ka(t.agentId),Wr(!1),t.eventId&&Qr(t.eventId)},R(i,(()=>{var e=P(()=>t.kind===`finish`);return()=>e()?`✅`:P(()=>t.kind===`question`)()?`❓️`:t.kind===`error`?`⚠️`:`📈`})()),R(a,()=>t.title),R(o,()=>nn(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),Br(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=JE();return R(e,()=>hD(t.body,160)),e}}),null),x(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(_D,{get providers(){return Object.keys(ie().providers??{})},get defaultProvider(){return ie().defaultProvider??``},onClose:()=>se(!1),onCreated:e=>{se(!1),t(t=>Di(t,[e])),ka(e.id)}})}}),j(N,{get when(){return de()},get children(){return j(jw,{get cfg(){return ie()},onClose:()=>fe(!1),announcedOAuth:pe,get skills(){return G()},get hasSelection(){return!!n()},get agentId(){return n()},get features(){return Go()},onSaved:()=>{hi(),Mi()},theme:{themes:Nt,activeId:Tt,paintedId:le,auto:Dt,setAuto:e=>{Ot(e),localStorage.setItem(`teapot.theme.auto`,e?`1`:`0`)},dark:Ft,setDark:It,light:kt,setLight:At,setThemes:Pt,setActive:Et,preview:e=>Mt(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 Ar()},fallback:null,children:e=>{let t=()=>h().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,h().length-t()-1);return j(Gd,{title:`edit prompt — forks the conversation`,onClose:()=>Mr(null),get children(){var t=ZE(),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 X(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value})}),Mr(null),Oi();let t=n();t&&await ka(t)}catch(e){alert(`edit failed: ${e.message}`)}}),R(t,j(N,{get when(){return r()>0},get children(){var e=XE(),t=e.firstChild;return R(e,r,t),e}}),a),o.$$click=()=>Mr(null),x(()=>i.value=e().text),t}})}})]}function hD(e,t){return e.length>t?e.slice(0,t)+` …`:e}function gD(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 _D(e){let[t,n]=b(`~`),[r,i]=b([]),[a,o]=b(``),[s,c]=b(e.defaultProvider||e.providers[0]||``),[l,u]=b(``);async function d(e){let r=await X(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),p(r.parent??``),i(r.entries??[])}ee(()=>d(t()));let[f,p]=b(``),m=async n=>{n.preventDefault(),u(``);try{let n=await X(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,start:!1})});e.onCreated(n.agent)}catch(e){u(String(e.message))}};return j(Gd,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=$E(),u=i.firstChild,p=u.firstChild.nextSibling.firstChild,h=p.nextSibling,g=h.nextSibling,_=u.nextSibling,v=_.nextSibling,y=v.firstChild,b=y.firstChild.nextSibling,S=y.nextSibling.firstChild.nextSibling,C=v.nextSibling;return i.addEventListener(`submit`,m),p.$$input=e=>n(e.currentTarget.value),h.$$click=()=>d(t()),g.$$click=()=>f()?d(f()):d(`..`),R(_,j(M,{get each(){return r()},children:e=>(()=>{var n=eD();return n.firstChild,n.$$click=()=>d(`${t()}/${e}`.replace(/\/+/g,`/`)),R(n,e,null),n})()})),b.$$input=e=>o(e.currentTarget.value),S.addEventListener(`change`,e=>c(e.currentTarget.value)),R(S,j(M,{get each(){return e.providers},children:e=>(()=>{var t=kE();return R(t,e),t})()})),R(i,j(N,{get when(){return l()},get children(){var e=QE();return R(e,l),e}}),C),x(()=>p.value=t()),x(()=>b.value=a()),x(()=>S.value=s()),i}})}Ee([`click`,`input`,`keydown`,`pointerdown`,`dblclick`]),Te(()=>j(mD,{}),document.getElementById(`root`));
|
|
191
|
-
//# sourceMappingURL=index-
|
|
191
|
+
//# sourceMappingURL=index-CeTEMDJa.js.map
|