teapot-coding-agent 0.36.2 → 0.36.3

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.
@@ -202,6 +202,32 @@ export class ServerAuth {
202
202
  throw new Error("no PKCE verifier — the authorization flow did not start here");
203
203
  return v;
204
204
  }
205
+ /**
206
+ * The SDK's discovery cache — the reason Notion's exchange never completed.
207
+ *
208
+ * The OAuth flow is split across TWO transport instances: the one that hits the 401 and
209
+ * redirects the browser, and the one built after the callback arrives. The SDK's own contract
210
+ * says this state "MUST persist with the same durability as `codeVerifier` (survives the
211
+ * redirect round-trip)", because the issuer recorded at redirect time is what the authorization
212
+ * response's `iss` is validated against (RFC 9207) when the code is redeemed.
213
+ *
214
+ * MEASURED on this machine's real store after a BROWSER-COMPLETED Notion authorization:
215
+ * `codeVerifier` present, `clientInformation.redirect_uris` a real ephemeral port
216
+ * (`http://127.0.0.1:37209/callback`), and no `accessToken` — the redeeming instance had
217
+ * re-discovered a different issuer binding, so the exchange never produced tokens. Both earlier
218
+ * fixes (persist the verifier, re-register on a redirect mismatch) were necessary and neither was
219
+ * sufficient.
220
+ */
221
+ discoveryState() {
222
+ return this.store.discoveryState;
223
+ }
224
+ async saveDiscoveryState(state) {
225
+ if (!state || typeof state !== "object")
226
+ return;
227
+ this.store.discoveryState = state;
228
+ // same durability as the verifier: the instance that redeems the code is not this one
229
+ await this.persist(this.server, this.store);
230
+ }
205
231
  // ---- teapot-facing ----
206
232
  /** the url the browser must open, once `redirectToAuthorization` has been called */
207
233
  pendingUrl() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.36.2",
3
+ "version": "0.36.3",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",
@@ -22,10 +22,10 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
22
22
  `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}});function hr(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 gr=()=>$(`/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),hr(t,e.agents??[]))),n&&p()}).catch(()=>{}),_r=()=>$(`/api/metrics`).then(te).catch(()=>{}),[vr,yr]=v([]),br=()=>$(`/api/tasks`).then(e=>yr(e.tasks)).catch(()=>{}),xr=e=>vr().filter(t=>t.agent===e),[Sr,Cr]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.expandedSubs`)??`[]`);return new Set(e.filter(e=>typeof e==`string`))}catch{return new Set}})()),[wr,Tr]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`);return new Set(e.filter(e=>typeof e==`string`&&!e.startsWith(`chat:`)))}catch{return new Set}})()),Er=e=>wr().has(e)||!Sr().has(e),Dr=e=>{let t=new Set(Sr());if(t.has(e)?t.delete(e):t.add(e),Cr(t),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...t])),t.has(e)&&wr().has(e)){let t=new Set(wr());t.delete(e),Tr(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))}},Or=t=>wt(e(),t),[kr,Ar]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.wsCollapsed`)??`[]`),t=Array.isArray(e)?e.filter(e=>typeof e==`string`):[];if(Number(localStorage.getItem(`teapot.wsCollapsed.v`)??`0`)<2){let e=t.filter(e=>!e.startsWith(`chat:`));return t.length-e.length>0&&localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify(e)),localStorage.setItem(`teapot.wsCollapsed.v`,`2`),new Set(e)}return new Set(t)}catch{return new Set}})()),jr=x(()=>{let e=new Set;for(let t of kr())t.startsWith(`chat:`)&&e.add(t);return e}),Mr=x(()=>yt(e(),new Set(e().filter(e=>Er(e.id)).map(e=>e.id)),Pn(),jr())),Nr=(t,r,i,a)=>{let o=new Set(kr());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||Or(e().find(e=>e.id===i))===t)&&Q(`hid ${r} — click the header to show it`)}Ar(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},H=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,Pr=e=>{let t=Fr().get(e)??0;return`${t} chat${t===1?``:`s`}`},Fr=x(()=>Tt(e())),U=x(()=>Et(e(),Mr(),kr())),Ir=2e3,[Lr,Rr]=v(null),W=new Map;function zr(e){return`${i()||(n()??`?`)}:${e.id}`}function Br(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=zr(r),a=W.get(i);if(t[n]=a??r,!a&&(W.set(i,r),W.size>6e3)){let e=W.keys().next().value;e!==void 0&&W.delete(e)}}return t}let[Vr,Hr]=v(!1),[Ur,Wr]=v(!1),[Gr,Kr]=v(!1),qr=0,Jr=-1;function Yr(e){let t=Br(e);h(e=>{if(t.length>0&&e.length>0){let n=e[e.length-1],r=t.every(e=>e.seq>n.seq),i=new Set(e.map(e=>e.id));if(r&&t.every(e=>!i.has(e.id)))return[...e,...t]}let n=new Map;for(let t of e)n.set(t.id,t);let r=!1;for(let e of t)n.has(e.id)||(n.set(e.id,e),r=!0);return r?[...n.values()].sort((e,t)=>e.seq-t.seq):e})}async function Xr(){let e=n();if(!e||Gr()||Vr()||Dt())return;if(m().length>=g()){Kr(!0);return}let t=()=>{let e=$r();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!Gr()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(m().length>=g()){Kr(!0);return}let i=m().length;if(await Zr(),m().length===i)return;Qt(G())&&n()===e&&ni(!0)}}async function Zr(){let e=n(),t=m()[0];if(e&&t&&!Vr()&&!Gr()){Hr(!0);try{let r=$r(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=Lr(),c=i(),l=c&&c!==e?`&session=${encodeURIComponent(c)}`:``,u=(await $(`/api/agents/${e}/events?limit=${Ir}&before=${encodeURIComponent(t.id)}${l}${s?`&branch=${encodeURIComponent(s)}&lineage=true`:``}`)).events??[];if(u.length===0){Kr(!0);return}if(n()!==e||m()[0]?.id!==t.id)return;Yr(u),requestAnimationFrame(()=>{if(n()===e){let e=$r();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{Hr(!1)}}}async function Qr(e,t){let r=qr,a=t??i()??``;try{let t=Lr(),i=r!==Jr||!w().length;m().length||Wr(!0);let o=a&&a!==e?`&session=${encodeURIComponent(a)}`:``;$(`/api/agents/${e}/skills`).then(t=>{r===qr&&n()===e&&ia(t.skills??[])}).catch(()=>{});let[s,c]=await Promise.all([$(`/api/agents/${e}/events?limit=${Ir}${o}${t?`&branch=${encodeURIComponent(t)}&lineage=true`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:w()})]);if(i&&(Jr=r),r!==qr||n()!==e)return;h(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of Br(s.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),_(s.total??s.events.length),T(c.branches)}catch{}finally{Wr(!1)}}function $r(){return document.querySelector(`.feed`)}function G(){let e=$r();return e?{top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight}:null}function ei(){return Qt(G())}function ti(){let e=$r();e&&(e.scrollTop=e.scrollHeight,_a={top:e.scrollTop,height:e.scrollHeight},At(0))}function ni(e=!1){(e||Dt())&&ti()}let ri=new Map,ii=(t,n)=>Nt(c().get(t),e().find(e=>e.id===t)?.session,n);async function ai(e,t=!0,o){let s=n(),l=i(),u=m(),d=g();qr++,c().size||p();let f=ii(e,o)??e;if(s!==e||f!==l){if(l&&u.length&&(ri.set(l,{events:u,total:d,at:Date.now()}),ri.size>6)){let e=[...ri.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&ri.delete(e[0])}h([]),W.clear(),Xn(),Wt(null),At(0),Ot(!0),ga=void 0}r(e),a(f),O(D.get(e)??``),Rr(null),Kr(!1),Hr(!1),jn(l||s||`?`,Dn()),On(An(f||e)),localStorage.setItem(`teapot.session`,e),_i(f,t);let v=ri.get(f);v?.events.length&&(Br(v.events),h(Br(v.events)),_(v.total),requestAnimationFrame(()=>{n()===e&&ni(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(gr).catch(()=>{}),await Qr(e,f),n()===e&&(sn(t=>{let n=t.get(e)??null,r=Ye(n,m(),V()?.status);if(r===n)return t;let i=new Map(t);return r?i.set(e,r):i.delete(e),i}),Wt(V()?.ctx?.compacting?{phase:String(V().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&ni(!0)}),Xr())}let[oi,si]=v(!1),ci=null,li=null;C(()=>ci?.close());let ui=!1,di=null;document.addEventListener(`visibilitychange`,()=>di?.()),C(()=>{di=null});let fi=!0,pi=null;async function mi(){let e=n(),t=m().at(-1)?.id,r=i(),a=document.visibilityState===`hidden`;if(!e||!t)ui=!0,a||pi?.();else try{let n=r&&r!==e?`&session=${encodeURIComponent(r)}`:``,i=Lr(),o=await $(`/api/agents/${e}/events?after=${encodeURIComponent(t)}${n}${i?`&branch=${encodeURIComponent(i)}&lineage=true`:``}`),s=o.events??[];o.gap?(h(Br(s)),_(s.length)):s.length&&(Yr(s),_(e=>e+s.length)),await gr(),s.length&&!a&&_r()}catch{ui=!0}}function hi(){fi=!0;let r=location.protocol===`https:`?`wss://`:`ws://`,a=new WebSocket(`${r}${location.host}/api/ws${gh()}`);ci=a,a.onopen=()=>{si(!0),fi?fi=!1:mi()},a.onclose=()=>{si(!1),setTimeout(hi,1500)},a.onerror=()=>a.close();let o=new Set([`state`,`usage`,`session_start`]);a.onmessage=r=>{let c=JSON.parse(r.data);if(c.kind===`ping`)try{a.send(JSON.stringify({kind:`pong`}))}catch{}else if(c.kind!==`pong`){if(c.kind===`hello`&&Array.isArray(c.agents)){t(e=>hr(e,c.agents));let n=e();sn(e=>Je(e,e=>n.find(t=>t.id===e)?.status))}else if(c.kind===`event`&&Ue(c.event))sn(e=>He(e,c.agentId));else if(c.kind===`llm-delta`){if(!It(c,n(),i()))return;if(sn(e=>Ve(e,c.agentId,c)),c.agentId===n()){let e=String(c.reasoning??``),t=String(c.text??``);e&&!t?gn()||_n(Date.now()):t&&_n(0)}}else if(c.kind===`compaction-progress`){if(c.agentId!==n())return;c.phase===`done`?Wt(null):Wt({phase:c.phase,summarized:c.summarized})}else if(c.kind===`agent-update`&&c.snapshot)t(e=>{let t=e.findIndex(e=>e.id===c.snapshot.id),n=c.snapshot;return t===-1?[...e,n]:hr(e,e.map((e,n)=>n===t?c.snapshot:e))});else{if(c.kind===`event`){let e=c.event?.type,t=c.event?.data??{};if((e===`system_note`&&t.event===`prompt-delivered`&&c.agentId===n()||e===`system_note`&&t.event===`prompt-cancelled`&&c.agentId===n())&&jn(kn(),Dn().filter(e=>e.promptId!==t.promptId)),o.has(e)&&!dh.has(e)||(Wn(c.agentId,c.event),c.event?.agent!==n())||!Ft(c.event,n(),i()))return;if(Yr([c.event]),c.event?.type===`message`&&c.event.data?.role===`assistant`){let e=cn();e&&Ge(e,m(),V()?.status)&&ln(null)}if(ui=!0,document.visibilityState!==`visible`||li)return;li=setTimeout(s,60)}document.visibilityState===`hidden`?ui=!0:li||=setTimeout(s,120)}}},ui=!1;let s=async()=>{if(li=null,await gr(),await _r(),n()){let e=m().at(-1)?.id,t=m().length;await Qr(n());let r=cn();r&&!Ye(r,m(),V()?.status)&&ln(null),m().at(-1)?.id!==e&&(Dt()?(ti(),zn(n())):(At(e=>e+Math.max(0,m().length-t)),Vt(G())))}};pi=s,di=()=>{document.visibilityState===`visible`&&n()&&(ui?(ui=!1,s()):m().at(-1)?.id?mi():(ui=!0,s()))}}let gi=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function _i(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=gi(),t=o().get(e);t&&(t!==n()||e!==i())&&ai(t,!1,e||null)}),b(()=>{let e=V(),t=e?`${Sn()?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=Rn()>0?`(${Rn()}) ${t}`:t});let vi=()=>ae()||le()||wn()!==null||fe()&&Ce();window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable))e.key===`Escape`&&t.blur();else if(e.key===`Escape`){if(ae()){oe(!1);return}if(le()){j(!1);return}if(wn()){Tn(null);return}if(fe()&&Ce()){Ae();return}let e=V();if(e&&Sn()){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(gr);return}}else if(!vi()){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)ke();else if(e.key===`t`)xi();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=Mr().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&&ai(t[i].id)}}});let[yi,bi]=v(localStorage.getItem(`teapot.term`)===`1`),xi=()=>{let e=!yi();bi(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[Si,Ci]=v([]),[wi,Ti]=v(0),[Ei,Di]=v(-1),[Oi,ki]=v(!1),[Ai,ji]=v(0),[Mi,Ni]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),Pi=new Map,Fi=[null,null],Ii=()=>Si()[Ai()===0?wi():Ei()]??null;function Li(e){if(!Si()[e])return;let t=Ai(),n=t===0?wi():Ei(),r=t===0?Ei():wi(),i=e=>t===0?Ti(e):Di(e);r===e?((e=>t===0?Di(e):Ti(e))(n),i(e)):n!==e&&i(e)}let Ri=()=>zi();async function zi(e){let t=e??n();if(t){if(Si().filter(e=>e.agentId===t).length>=10)Q(`max 10 shells per agent (${t}) — that's already a lot`);else try{let e=(await $(`/api/terminals`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agentId:t})})).terminal;if(!e){Q(`could not open a shell`);return}let n=du(Si());Ci(t=>[...t,{key:e.id,agentId:e.agentId,title:e.title}]),Ai()===0?Ti(n):Di(n)}catch(e){Q(`could not open a shell: ${e.message}`)}}}function Bi(e){let t=Si()[e];if(!t)return;$(`/api/terminals/${encodeURIComponent(t.key)}`,{method:`DELETE`}).catch(()=>{});let n=Pi.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),Pi.delete(t.key)}let r=Si().filter((t,n)=>n!==e);Ci(r),Ti(t=>pu(t,e,r.length)),Di(t=>t===-1?-1:pu(t,e,r.length))}b(()=>{Le(),Pe(),et(),ze(),Ze();for(let[,e]of Pi)zt(e.term)});function Vi(){for(let[,e]of Pi){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}Pi.clear()}function Hi(e,t){let n=Pi.get(e.key);if(n&&zt(n.term),n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new su({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:Rt()}),a=new uu;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${encodeURIComponent(e.agentId)}/term?terminal=${encodeURIComponent(e.key)}${gh()}`);s.onmessage=t=>{let n=JSON.parse(t.data);n.kind===`data`?i.write(n.data):n.kind===`exit`?(i.write(`\r\n\x1b[2m[terminal exited ${n.code??``}]\x1b[0m\r\n`),Ci(t=>t.filter(t=>t.key!==e.key)),Pi.get(e.key)?.term.dispose(),Pi.delete(e.key)):n.kind===`attach`&&n.error&&i.write(`\r\n\x1b[2m[${n.error}]\x1b[0m\r\n`)},i.onData(e=>{s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({kind:`input`,data:e}))});let c={cols:0,rows:0},l,u=[],d=()=>{try{a.fit()}catch{}s.readyState===WebSocket.OPEN?(i.cols!==c.cols||i.rows!==c.rows)&&(c={cols:i.cols,rows:i.rows},s.send(JSON.stringify({kind:`resize`,cols:i.cols,rows:i.rows}))):f()};function f(){l||=setInterval(()=>{Pi.has(e.key)?s.readyState===WebSocket.OPEN&&(clearInterval(l),l=void 0,d()):(clearInterval(l),l=void 0)},400)}s.addEventListener(`open`,()=>d());let p=r.parentElement??r,m=new ResizeObserver(()=>{u[0]&&clearTimeout(u[0]),u[0]=setTimeout(d,250)});m.observe(p),p!==r&&m.observe(r),setTimeout(d,60),n={el:r,term:i,fit:a,ws:s,ro:m},Pi.set(e.key,n)}return n}function Ui(e){let t=Fi[e];if(!t)return;let n=Si()[e===0?wi():Ei()];if(!n){[...Pi.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Hi(n,t);for(let[e,r]of Pi)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(Ai()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{Si(),Oi(),wi(),Ei(),Mi(),requestAnimationFrame(()=>{Ui(0),Oi()&&Ui(1)})});let Wi=null;b(()=>{if(!yi())return;let e=n();if(!e||e===Wi)return;Wi=e;let t=Si().map((e,t)=>({t:e,i:t})).filter(t=>t.t.agentId===e);t.length&&Li(t[t.length-1].i)}),b(()=>{let e=Si().length,t=fu(wi(),e);if(t!==wi()&&Ti(t),Oi()){let t=fu(Ei(),e);t!==Ei()&&Di(t)}});let Gi=e=>{e.preventDefault();let t=e.clientY,n=Mi(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Ni(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(Mi())),requestAnimationFrame(()=>{Ui(0),Oi()&&Ui(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},Ki=()=>{let e=!Oi();ki(e),e&&(Ei()<0||Ei()===wi()||Ei()>=Si().length)&&Di(mu(wi(),Si().length)),requestAnimationFrame(()=>{Ui(0),Oi()&&Ui(1)})};C(Vi);let qi=e=>t=>{Fi[e]=t,t&&requestAnimationFrame(()=>{Ui(e),Oi()&&Ui(1),setTimeout(()=>Ui(e),200)})};ee(()=>{rr(),gr().then(async()=>{await p();let t=gi(),n=t?o().get(t):void 0,r=(n?e().find(e=>e.id===n):void 0)??e().find(e=>e.id===t&&!o().has(t))??e().find(e=>e.id===localStorage.getItem(`teapot.session`))??e()[0];r&&ai(r.id,!1,t||null)}),_r(),br(),Zi(),hi(),$(`/api/terminals`).then(e=>{let t=e.terminals??[];t.length&&(Ci(t.map(e=>({key:e.id,agentId:e.agentId,title:e.title}))),yi()&&(Ti(0),Di(-1)))}).catch(()=>{});let t=setInterval(()=>{_r(),br()},3e4);C(()=>clearInterval(t))});let Ji=[{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`}],[Yi,Xi]=v([]),Zi=()=>$(`/api/personas`).then(e=>Xi(e.personas)).catch(()=>{}),[Qi,$i]=v(!1),ea=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},ta=()=>{let t=ea();return t===null?[]:[...Yi().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))},na=new Set([`start`,`stop`,`fork`,`compact`]),[ra,ia]=v([]),[aa,oa]=v(null),[sa,ca]=v(-1),la=()=>{let e=ne();if(!e.startsWith(`/`)||e.includes(`
23
23
  `))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[2]??``).trim();if(!r&&n!==`skill`){let e=Ji.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&na.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=ra().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[]},ua,da,fa,pa=!1;function ma(e){if(!da){da=document.createElement(`div`),da.setAttribute(`aria-hidden`,`true`);let e=da.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`,da.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`])da.style.setProperty(e,t.getPropertyValue(e));if(da.style.width=`${e.clientWidth}px`,da.setAttribute(`data-mirror-text`,e.value.endsWith(`
24
24
  `)?`${e.value} `:e.value),fa||(fa=document.createElement(`div`),fa.setAttribute(`aria-hidden`,`true`),fa.style.cssText=`position:absolute;left:-9999px;top:0;pointer-events:none`,document.body.appendChild(fa)),da.parentElement!==fa&&fa.appendChild(da),!pa){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),pa=!0}return da.scrollHeight}let ha=()=>{if(!ua)return;let e=vt();if(!ua.value&&!e){ua.style.height=``;return}let t=ma(ua),n=e?-1:rn(t,360);ua.style.height=n===-1?``:`${n}px`},ga,_a=null,va,ya=null,ba=0,xa=240,Sa=4,Ca;b(()=>{let e=ne();ua&&Jt(sh)&&(Yt(ua.value,e)&&(ua.value=e),ha())}),ee(()=>{let e=0,t=()=>{e||=requestAnimationFrame(()=>{e=0,ha()})};window.addEventListener(`resize`,t),C(()=>{window.removeEventListener(`resize`,t),e&&cancelAnimationFrame(e)})});let[K,wa]=v([]),Ta=e=>{let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));for(let e of t){if(e.size>8e6){Q(`"${e.name}" is over 8 MB — skipped`);continue}let t=new FileReader;t.onload=()=>{wa(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},Ea=async(e,t)=>{let r=t??n();if(!r)return;let i=K();try{let t=await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0,...i.length?{images:i}:{}})});jn(kn(),[...Dn(),{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now(),promptId:t.promptId,...i.length?{images:i.map(e=>e.url)}:{}}]),wa([]),vt()&&bt(!1),ha(),Dt()&&requestAnimationFrame(()=>{Dt()&&ti()})}catch(t){O(e),console.error(`send failed:`,t)}},Da=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=Yi().some(e=>e.key.toLowerCase()===r),s=e().some(e=>e.id.toLowerCase()===r);try{if(o){if(!a){Q(`usage: @${r} <task>`);return}Q(`🧩 spawned ${(await $(`/api/agents/${n()}/spawn`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({persona:r,task:a,context:Qi()?`fork`:`none`})})).id}${Qi()?` (forked context)`:``}`),gr(),O(``)}else if(s){if(!a){Q(`usage: @${r} <message>`);return}await $(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),Q(`→ delivered to @${r}`),O(``)}else{Q(`unknown @${r} — personas: ${Yi().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}}else if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim();if(t===`goal`&&!n){O(`/goal `);return}if(t===`skill`&&!n){O(`/skill `);return}O(``);try{await Oa(t,n)}catch(e){throw O(ne()?`${i}\n${ne()}`:i),e}}else O(``),await Ea(i)}},Oa=async(e,t)=>{let r=n();if(!r)return;let i=(e,t)=>$(`/api/agents/${r}${e}`,{method:`POST`,headers:{"content-type":`application/json`},...t===void 0?{}:{body:JSON.stringify(t)}}).then(gr);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await ai(r);else if(e===`compact`)Q((await i(`/compact`))?.ran?`context compacted`:`nothing to compact yet`);else if(e===`goal`){if(!t){Q(`usage: /goal <text>`);return}await i(`/goal`,{text:t,notify:!0}),Q(`goal saved & notification queued`)}else if(e===`skill`){if(!t){Q(`usage: /skill <name>`);return}await Ea(`[harness] Force-load and follow the skill "${t}" now: call load_skill("${t}") and execute its playbook for the current task.`),Q(`skill "${t}" dispatched`)}else Q(`unknown command "${e}" — /start /stop /fork /goal /skill /compact`)}catch(t){Q(`/${e} failed: ${t.message}`)}},ka,Aa=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!ka)return;let e=Math.min(Aa,ka.scrollHeight);Math.abs(ka.scrollTop-e)>1&&(ka.scrollTop=e)})})});let ja=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(gr),Ma=async()=>{let i=n();if(!i)return;let a=new Set([i,...Ct(e(),i).map(e=>e.id)]),o=a.size-1;if(!confirm(`archive agent ${i}?\n\n`+(o>0?`Its ${o} sub-agent${o===1?``:`s`} will be archived too.\n\n`:``)+`They stop running and leave the list, but the config and full session history are KEPT — restore any of them from ⚙ settings → archive.`))return;await $(`/api/agents/${i}/archive`,{method:`POST`}).catch(()=>{}),t(e().filter(e=>!a.has(e.id))),p(!0);let s=hu(e(),a);s?ai(s.id):(r(null),h([]))},Na=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),gr())},Pa=()=>$(`/api/agents/${V().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await p(!0),await ai(V().id)}),[Fa,Ia]=v(``),[La,Ra]=v(``),[za,Ba]=v(!1),[Va,Ha]=v(!0),Ua=``;b(()=>{let e=n();e&&(V()?.goal,e!==Ua&&(Ua=e,Ba(!1),Ia(``),Ra(``)))});let Wa=async e=>{if(e.preventDefault(),n()&&Fa().trim())try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:Fa(),notify:Va(),...La().trim()?{verify:La()}:{}})}),Ia(``),Ra(``),Ba(!1),gr()}catch(e){Q(`goal save failed: ${e.message}`)}};return[M(P,{get when(){return ir()},get children(){var e=Su();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),M(P,{get when(){return ce()},children:e=>(()=>{var t=nd(),n=t.firstChild;return y(t=>{var r=e(),i=se.map(t=>`${e()}?w=${t} ${t}w`).join(`, `);return r!==t.e&&L(n,`src`,t.e=r),i!==t.t&&L(n,`srcset`,t.t=i),t},{e:void 0,t:void 0}),t})()}),(()=>{var t=Zu(),r=t.firstChild,i=r.firstChild,a=i.nextSibling.firstChild,o=a.firstChild;o.firstChild;var s=a.nextSibling,c=s.firstChild.firstChild.nextSibling;c.firstChild;var l=c.nextSibling,d=s.nextSibling,f=r.nextSibling,p=f.nextSibling,g=p.firstChild;g.firstChild,z(t,M(P,{get when(){return F(()=>!!pe())()&&je()},get children(){var e=Cu();return e.$$click=Ne,e}}),r),z(r,M(P,{get when(){return pe()},get children(){var e=wu(),t=e.firstChild.nextSibling;return t.$$click=Ne,e}}),i),z(i,M(N,{get each(){return U()},children:t=>[M(P,{get when(){return F(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=id(),n=e.firstChild;return e.$$click=()=>Nr(`ws:${t.wsHeader}`,H(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),z(n,()=>t.wsCollapsedGroup?`▸`:`▾`),z(e,()=>H(t.wsHeader),null),z(e,M(P,{get when(){return(Fr().get(t.wsHeader)??0)>1||t.wsCollapsedGroup},get children(){var e=rd();return z(e,()=>Fr().get(t.wsHeader)??0),e}}),null),y(()=>L(e,`title`,t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${Pr(t.wsHeader)} hidden). Click to show.`:(Fr().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${Pr(t.wsHeader)} in this directory`:t.wsHeader||``)),e}}),M(P,{get when(){return F(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=ld(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>ai(t.a.id),z(r,M(P,{get when(){return xt({isSub:!!t.a.parent,collapsed:t.chatCollapsedGroup===!0,hasChildren:e().some(e=>e.parent===t.a.id)})},get fallback(){return ud()},get children(){return(()=>{let e=!t.a.parent,n=e&&jr().has(`chat:${t.a.id}`)||Er(t.a.id);return(()=>{var r=dd();return r.$$click=r=>{if(r.stopPropagation(),e){if(n){if(!Sr().has(t.a.id)){let e=new Set(Sr());e.add(t.a.id),Cr(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}if(wr().has(t.a.id)){let e=new Set(wr());e.delete(t.a.id),Tr(e),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...e]))}}else if(Sr().has(t.a.id)){let e=new Set(Sr());e.delete(t.a.id),Cr(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}Nr(`chat:${t.a.id}`,t.a.id,n)}else Dr(t.a.id)},z(r,n?`▸`:`▾`),y(()=>L(r,`title`,e?n?`show ${t.a.id}`:`hide ${t.a.id} and its sub-agents`:n?`expand sub-agents`:`collapse sub-agents`)),r})()})()}}),i),z(a,()=>t.a.sessionTitle??u().get(t.a.session??``)??t.a.id),z(r,(()=>{var e=F(()=>!!t.a.workspaceMissing);return()=>e()?fd():null})(),null),z(r,M(P,{get when(){return Vn(t.a.id)>0},get children(){var e=ad();return e.firstChild,z(e,()=>Vn(t.a.id),null),y(()=>L(e,`title`,`${Vn(t.a.id)} unread notification${Vn(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),z(r,M(P,{get when(){return Er(t.a.id)||t.chatCollapsedGroup===!0&&jr().has(`chat:${t.a.id}`)},get children(){return(()=>{let n=Ct(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=pd();return e.firstChild,R(e,`subcount`+(r>0?` live`:``)),z(e,()=>n.length,null),z(e,r>0?` · ▶${r}`:``,null),y(()=>L(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),z(r,M(P,{get when(){return t.a.parent},get children(){return od()}}),null),z(r,M(P,{get when(){return xr(t.a.id).length>0},get children(){var e=sd();return y(()=>L(e,`title`,xr(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
25
- `))),e}}),null),z(r,M(P,{get when(){return t.a.goal.status===`done`},get children(){return cd()}}),null),y(e=>{var o=`agent-item`+(t.a.id===n()?` sel`:``)+(t.depth>0?` sub-row`:``)+(t.chatCollapsedGroup?` collapsed`:``),s=t.depth>0?`padding-left:${10+t.depth*14}px`:``,c=t.a.parent?(()=>{let e=St(t.a.id,Yi().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`:t.a.sessionTitle??u().get(t.a.session??``)?`${t.a.sessionTitle??u().get(t.a.session??``)} — ${t.a.id}`:t.a.id;return o!==e.e&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),d!==e.i&&L(i,`title`,e.i=d),f!==e.n&&R(a,e.n=f),p!==e.s&&L(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(),Ln(!In()),In()||Nn(e=>e.map(e=>({...e,read:!0})))},z(o,M(P,{get when(){return Rn()>0},get children(){var e=Tu();return z(e,Rn),e}}),null),z(a,M(jh,{icon:`👻`,get active(){return Pn()},get title(){return Pn()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!Pn();if(Fn(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&V()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&ai(t.id)}}}),null),z(a,M(jh,{icon:`+`,title:`new agent`,onClick:()=>{rr(),oe(!0)}}),null),z(a,M(jh,{icon:`⚙`,title:`settings`,onClick:()=>{rr(),j(!0)}}),null),z(c,`0.36.2`,null),z(d,M(P,{get when(){return E()},get children(){return[`master rss `,F(()=>E().rssMb),`MB · heap `,F(()=>E().heapUsedMb),`MB`,Eu(),`load1 `,F(()=>E().loadavg1),` · up `,F(()=>Math.floor(E().uptimeSec/60)),`m`]}})),z(f,M(P,{get when(){return V()?.id},keyed:!0,get fallback(){return md()},get children(){return[(()=>{var t=Au(),r=t.firstChild,i=r.nextSibling,a=i.nextSibling,o=a.nextSibling,s=o.firstChild,c=s.nextSibling,l=c.nextSibling.nextSibling,u=l.nextSibling.nextSibling,d=u.nextSibling.nextSibling;d.nextSibling;var f=o.nextSibling,p=f.firstChild,m=p.nextSibling;return z(t,M(P,{get when(){return pe()},get children(){var e=Du();return e.$$click=()=>Me(!je()),y(()=>L(e,`aria-expanded`,je())),e}}),r),z(i,()=>V().id),z(a,()=>V().status),z(t,M(P,{get when(){return(V().pendingPromptIds?.length??V().pendingPrompts??0)>0},get children(){var e=Ou(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>V().pendingPromptIds?.length??V().pendingPrompts,t),z(e,()=>V().status===`stopped`?` (stopped)`:``,null),y(()=>L(e,`title`,V().status===`stopped`?`${V().pendingPromptIds?.length??V().pendingPrompts??0} message${(V().pendingPromptIds?.length??V().pendingPrompts??0)>1?`s`:``} from you are still queued, but this agent is STOPPED — nothing will run until you press start (or it is resumed). Each can be withdrawn with ✕ cancel while it is still queued.`:`${V().pendingPromptIds?.length??V().pendingPrompts??0} message${(V().pendingPromptIds?.length??V().pendingPrompts??0)>1?`s`:``} from you waiting in the queue. They will be handed to the model at its next turn boundary — the timeline shows them as "pending (queued)…" until then, and each can be withdrawn with ✕ cancel while it's still queued.`)),e}}),o),z(t,M(P,{get when(){return xr(V().id).length>0},get children(){var e=ku();return e.firstChild,z(e,()=>xr(V().id).length,null),y(()=>L(e,`title`,`scheduled tasks:\n${xr(V().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
26
- `)}`)),e}}),o),z(o,()=>V().model,s),z(o,()=>V().session,c),z(o,()=>V().branch,l),z(o,()=>V().stats.turns,u),z(o,()=>V().stats.toolCalls,d),p.$$click=()=>(Sn()?ja(`/stop`):ja(`/start`))(),z(p,()=>Sn()?`■ stop`:`▶ start`),z(f,M(P,{get when(){return e().some(e=>e.parent===n())},get children(){return M(jh,{icon:`⏹`,title:`stop every sub-agent this agent spawned (descendants included)`,onClick:Na})}}),m),z(f,M(jh,{icon:`🗄`,title:`archive this agent — reversible: it leaves the list but keeps its config and history (restore in ⚙ settings → archive)`,onClick:Ma}),null),z(f,M(jh,{icon:`⑂`,title:`fork: branch off the conversation here — try things without disturbing the main line`,onClick:Pa}),null),z(f,M(jh,{icon:`⌨`,title:`terminal (t)`,onClick:xi}),null),z(f,M(jh,{icon:`▤`,title:`toggle details panel (d)`,get active(){return Ce()},onClick:ke}),null),y(e=>{var t=`badge ${V().status}`,n=V().statusReason&&!/^(round complete|prompt|api start|goal set|created via web|start)$/.test(V().statusReason)?`${V().status} — ${V().statusReason}`:void 0,r=`${V().model} · ${V().session}/${V().branch} · turns ${V().stats.turns} · tools ${V().stats.toolCalls}`,i=`runbtn`+(Sn()?` danger`:``),s=Sn()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&R(a,e.e=t),n!==e.t&&L(a,`title`,e.t=n),r!==e.a&&L(o,`title`,e.a=r),i!==e.o&&R(p,e.o=i),s!==e.i&&L(p,`title`,e.i=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),t})(),(()=>{var e=Lu();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r={top:t.scrollTop,height:t.scrollHeight,viewport:t.clientHeight},i=$t(r,_a,va,Ca);i===`layout`&&!Dt()&&Sa>0&&Math.abs(r.height-(va??r.height))>1&&(Sa--,be(t,ya)),_a=null,va=r.height,Ca=r.viewport,Vt(r);let a=Dt(),o=performance.now();o-ba>100&&(ba=o,ya=I(t));let s=tn(a,i,r);s!==a&&Ot(s),i===`reader`&&(Sa=4),s&&i!==`reader`?(kt()&&At(0),Bn(),en(s,r)&&Zt(r)>0&&ti()):s&&Qt(r)&&(kt()&&At(0),Bn()),r.top<=4&&n()&&!Vr()&&!Gr()&&m().length>0&&Zr()}),De(e=>Se(e),e),z(e,M(P,{get when(){return Ht()},children:e=>(()=>{var t=hd();return t.firstChild,z(t,(()=>{var t=F(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Oh(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),z(e,M(P,{get when(){return F(()=>!!Gr())()&&Qn().length>0},get children(){return ju()}}),null),z(e,M(P,{get when(){return Vr()},get children(){return Mu()}}),null),z(e,M(P,{get when(){return Qn().length>0},get fallback(){return F(()=>!!Ur())()?gd():_d()},get children(){return[M(N,{get each(){return Qn()},children:e=>M(Ch,{e,prev:()=>er(e,-1),next:()=>er(e,1),get showBranch(){return w().length>1},res:()=>Kn().resFor.get(e.id),get orphan(){return Kn().orphanCalls.has(e.id)},onOption:e=>void Ea(e),answeredIds:Zn,onAnswered:Yn,get agentActive(){return F(()=>!!Cn())()&&qe(e)},onResize:()=>{Dt()&&ti()},get onCancel(){return e.data?.source===`user`&&e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);O(ne()?`${n}\n\n${ne()}`:n),jn(kn(),Dn().filter(e=>e.promptId!==t)),Q(`message withdrawn — draft restored`)}).catch(()=>Q(`withdraw failed — it may have already been sent`))}:void 0},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`&&!(e.data?.pending&&e.data?.sent!==!0)&&!e.data?.cancelled&&!Sn()?()=>Tn({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),M(P,{get when(){return F(()=>!!Cn())()&&cn()},get children(){var e=Iu(),t=e.firstChild.nextSibling;return t.firstChild,z(t,M(P,{get when(){return bn().trim()!==``},get children(){var e=Nu(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return z(t,M(yh,{get startedAt(){return yn()}}),null),De(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{bn(),t&&(e.scrollTop=e.scrollHeight)})},n),z(n,bn),e}}),null),z(t,M(P,{get when(){return un()},get fallback(){return vd()},get children(){return M(P,{get when(){return Xt()},get fallback(){return(()=>{var e=Fu();return y(()=>e.innerHTML=Fe(un()+`▍`)),e})()},get children(){return[Pu(),(()=>{var e=Fu();return y(()=>e.innerHTML=Fe(an()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),M(P,{get when(){return yi()},get children(){var t=Hu(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Ni(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Mi()))},n.$$pointerdown=Gi,z(i,M(N,{get each(){return Si()},children:(e,t)=>(()=>{var n=yd(),r=n.firstChild.nextSibling;return n.$$click=()=>Li(t()),z(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Bi(t())},y(r=>{var i=`termtab`+(Ai()===0&&wi()===t()?` active`:``)+(Oi()&&Ai()===1&&Ei()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),z(i,M(jh,{icon:`+`,title:`new shell in this workspace`,onClick:Ri}),null),z(o,(()=>{var t=F(()=>!!Ii());return()=>t()?e().find(e=>e.id===Ii().agentId)?.workspace.split(`/`).filter(Boolean).pop():V()?.workspace})()),z(a,M(jh,{icon:`◫`,get title(){return Oi()?`single pane`:`split panes (50/50)`},onClick:Ki}),null),z(a,M(jh,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:xi}),null);var l=qi(0);return typeof l==`function`&&De(l,c),c.$$pointerdown=()=>ji(0),z(c,M(P,{get when(){return wi()<0||wi()>=Si().length},get children(){return Ru()}})),z(s,M(P,{get when(){return Oi()},get children(){return[zu(),(()=>{var e=Vu(),t=qi(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>ji(1),z(e,M(P,{get when(){return Ei()<0||Ei()>=Si().length},get children(){return Bu()}})),y(()=>e.classList.toggle(`focused`,Ai()===1)),e})()]}}),null),y(e=>{var n={height:`${Mi()}px`},r=!!Oi(),i=Ai()===0;return e.e=Te(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=Yu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling;return z(e,M(P,{get when(){return F(()=>Pt()>32)()&&!Dt()},get children(){var e=Uu();return e.firstChild,e.$$click=()=>{ni(!0),Bn()},z(e,(()=>{var e=F(()=>kt()>0);return()=>e()?`${kt()} new message${kt()>1?`s`:``}`:`jump to present`})(),null),e}}),t),z(e,M(P,{get when(){return la().length>0},get children(){var e=Wu();return z(e,M(N,{get each(){return la()},children:(e,t)=>(()=>{var n=bd(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{O(e.insert),ca(-1)},z(r,()=>e.insert.trim()),z(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===sa()?` active`:``),a=e.title;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),z(e,M(P,{get when(){return ta().length>0},get children(){var e=Wu();return z(e,M(N,{get each(){return ta()},children:e=>(()=>{var t=xd(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{O(`@${e.key} `),ca(-1)},z(n,()=>e.key,null),z(r,()=>e.label),y(()=>L(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Da),z(t,M(P,{get when(){return K().length>0},get children(){var e=Gu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,z(e,M(N,{get each(){return K()},children:(e,t)=>(()=>{var n=Sd(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>wa(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&L(n,`title`,t.e=i),a!==t.t&&L(r,`src`,t.t=a),o!==t.a&&L(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),z(t,()=>K().length,n),z(t,()=>K().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=la();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),ca(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),ca(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&sa()>=0&&!sh?(e.preventDefault(),O(t[sa()].insert),ca(-1)):e.key===`Escape`&&t.length>0?ca(-1):e.key===`Enter`&&!e.shiftKey&&!sh&&!vt()&&(e.preventDefault(),Da(e))},n.$$input=e=>{O(e.currentTarget.value),ca(0),ha()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),Ta(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{sh=!1}),O(ua?.value??``)}),n.addEventListener(`compositionstart`,()=>{sh=!0}),De(e=>{ua=e,e.value=ne()},n),z(t,M(P,{get when(){return F(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=Ku(),t=e.firstChild;return t.addEventListener(`change`,e=>$i(e.currentTarget.checked)),y(()=>t.checked=Qi()),e}}),r),r.$$click=()=>{let e=!vt();bt(e),requestAnimationFrame(()=>ha())},z(r,()=>vt()?`⤡`:`⤢`),z(t,M(jh,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),z(t,M(P,{get when(){return K().length},get children(){var e=qu();return e.firstChild,z(e,()=>K().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&Ta(e.currentTarget.files),e.currentTarget.value=``}),z(e,M(P,{get when(){return ih()},get children(){var e=Ju();return z(e,ih),e}}),null),y(t=>{var i=`composer`+(vt()?` maximized`:``),a=`message #${V().id} — / for commands · paste or 📎 to attach images`,o=vt()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&R(e,t.e=i),a!==t.t&&L(n,`placeholder`,t.t=a),o!==t.a&&L(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()]}})),z(t,M(P,{get when(){return F(()=>!!pe())()&&Ce()},get children(){var e=Xu();return e.$$click=()=>Oe(!1),e}}),p),p.addEventListener(`scroll`,e=>{Aa=e.currentTarget.scrollTop});var v=ka;return typeof v==`function`?De(v,p):ka=p,z(g,M(jh,{icon:`✕`,title:`close details panel (esc)`,onClick:Ae}),null),z(p,M(P,{get when(){return V()?.id},keyed:!0,fallback:null,children:t=>[M(P,{get when(){return V().id},keyed:!0,fallback:null,children:e=>M(Gh,{agentId:e,get workspace(){return V().workspace}})}),Cd(),(()=>{var t=Ed(),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;_t=!0,rt(r),at(Gt(k().providers,r,e().find(e=>e.id===n()))),dt(r)}),z(r,M(N,{get each(){return ut()},children:e=>(()=>{var t=qd();return t.value=e,z(t,e,null),z(t,()=>e===k().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>at(e.currentTarget.value),z(o,M(N,{get each(){return ct()},children:e=>(()=>{var t=qd();return y(()=>t.value=e.id),t})()})),z(t,M(P,{get when(){return V().effortSupported},get children(){var e=wd(),t=e.firstChild.nextSibling;return t.firstChild,t.addEventListener(`change`,e=>st(e.currentTarget.value)),z(t,M(N,{get each(){return F(()=>!!V().effortOptions?.length)()?V().effortOptions:eh},children:e=>(()=>{var t=qd();return t.value=e,z(t,e),t})()}),null),y(()=>t.value=ot()),e}}),s),c.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:nt(),model:it().trim()||void 0,contextWindowTokens:ct().find(e=>e.id===(it().trim()||void 0))?.contextLength,...V().effortSupported?{reasoningEffort:ot()}:{}})}),t.textContent=`✓ applied`,gr()}catch(e){alert(`apply failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},z(l,()=>V().model,null),z(l,M(P,{get when(){return ct().length},get children(){return[` · `,F(()=>ct().length),` models loaded`]}}),null),z(t,M(P,{get when(){return ht()},get children(){var e=Td();return z(e,ht),e}}),null),y(()=>L(a,`placeholder`,Kt(k().providers,nt(),V(),Ut(V(),k().providers,k().defaultProvider)))),y(()=>r.value=nt()),y(()=>a.value=it()),t})(),(()=>{var e=Dd(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-continue`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(gr)}),y(()=>t.checked=V().autoContinue??!0),e})(),(()=>{var e=kd();return e.firstChild,z(e,M(P,{get when(){return!!V().goal.text.trim()},get fallback(){return Jd()},get children(){var e=Od();return z(e,()=>V().goal.status),y(()=>R(e,`badge ${V().goal.status===`active`?`running`:V().goal.status}`)),e}}),null),e})(),(()=>{var e=Ad();return e.firstChild,z(e,M(N,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Yd();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(gr)},L(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),z(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(V().goal.text.trim()&&V().goal.status===e?` on ${e}`:``),i=!!V().goal.text.trim()&&V().goal.status===e;return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),M(P,{get when(){return V().goal.text},get fallback(){return Xd()},get children(){return[(()=>{var e=jd(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(V().goal.text))),e})(),M(P,{get when(){return V().goal.verify},get children(){var e=Md(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(V().goal.verify))),e}}),M(P,{get when(){return V().goal.audit},children:e=>(()=>{var t=Zd(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return z(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),z(r,()=>Dh(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=mt(e().feedback)?Fe(`_the auditor returned a verdict with no detail_`):Fe(e().feedback);return r!==n.e&&R(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),(()=>{var e=Nd(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,Wa),t.$$input=e=>{Ia(e.currentTarget.value),Ba(!0)},n.$$input=e=>{Ra(e.currentTarget.value),Ba(!0)},r.addEventListener(`change`,e=>Ha(e.currentTarget.checked)),y(()=>t.value=Fa()),y(()=>n.value=La()),y(()=>r.checked=Va()),e})(),(()=>{var e=Fd(),t=e.firstChild.nextSibling;return z(e,M(P,{get when(){return mr().total>0},get children(){var e=Pd(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,z(e,()=>mr().done,t),z(e,()=>mr().total,n),y(t=>Te(e,mr().done===mr().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),M(P,{get when(){return mr().total>0},get children(){var e=Id(),t=e.firstChild;return y(e=>{var n=`barfill `+(mr().done===mr().total?``:`warn`),r=`${Math.round(mr().done/mr().total*100)}%`;return n!==e.e&&R(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),M(Wh,{get draft(){return or()},get preview(){return cr()},onDraft:e=>{sr(e),dr(!0)}}),(()=>{var e=Ld(),t=e.firstChild,n=t.nextSibling;return z(e,M(jh,{get icon(){return cr()?`✎`:`👁`},get title(){return cr()?`edit markdown`:`rendered checklist`},onClick:()=>lr(!cr())}),t),n.$$click=pr,e})(),Rd(),M(P,{get when(){return V().latestProgress},get fallback(){return Qd()},children:e=>(()=>{var t=rf(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return z(t,M(P,{get when(){return e().recent},get children(){var t=$d(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=$m(e().recent)),t}}),i),z(t,M(P,{get when(){return e().problems},get children(){var t=ef(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=$m(e().problems)),t}}),i),z(t,M(P,{get when(){return e().next},get children(){var t=tf(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=$m(e().next)),t}}),i),z(t,M(P,{get when(){return e().goalStatus},get children(){var t=nf(),n=t.firstChild.nextSibling;return z(n,()=>e().goalStatus),t}}),i),z(i,()=>Dh(e().ts)),y(()=>r.innerHTML=$m(e().doing)),t})()}),zd(),(()=>{var e=Hd(),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 z(e,M(P,{get when(){return V().ctx},keyed:!0,get fallback(){return af()},children:e=>{let t=x(()=>{let t=e,n=ct().find(e=>e.id===V().model),r=t.window||n?.contextLength||0,i=r?Math.min(999,t.usedTokens/r*100):0;return{usedTokens:t.usedTokens,compactAt:t.compactAt,compacting:t.compacting,window:t.window,effectiveWindow:r,pct:i,cls:r?i>=85?`crit`:i>=70?`warn`:`ok`:``,derivedBudget:r?Math.round(r*.75):0,usingDerived:t.compactAtIsManual!==!0}}),r=()=>t(),i=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)};return(()=>{var e=lf(),t=e.firstChild,a=t.firstChild.nextSibling,o=a.firstChild.nextSibling;o.nextSibling;var s=t.nextSibling,c=s.firstChild.nextSibling,l=c.firstChild,u=c.nextSibling,d=s.nextSibling,f=d.firstChild.firstChild;return z(a,()=>Oh(r().usedTokens),o),z(t,M(P,{get when(){return r().effectiveWindow},get children(){var e=of(),t=e.firstChild;return z(e,()=>i(r().pct),t),z(e,()=>Oh(r().effectiveWindow),null),y(()=>R(e,`pill ${r().cls}`)),e}}),null),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=sf(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),z(c,()=>Oh(r().usingDerived?r().derivedBudget:r().compactAt),l),z(u,()=>r().usingDerived?`75% of window`:`manual`),z(e,M(P,{get when(){return Ht()||r().compacting},get children(){var e=cf(),t=e.firstChild.nextSibling.nextSibling;return z(t,()=>Ht()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(gr)}),y(()=>f.checked=V().autoCompact!==!1),e})()}}),t),z(i,()=>Oh(V().stats.inputTokens)),z(o,()=>Oh(V().stats.outputTokens)),z(c,()=>V().stats.turns),z(u,()=>V().stats.toolCalls),z(f,()=>V().stats.compactions??0),z(t,M(P,{get when(){return(V().stats.costUsd??0)>0},get children(){var e=Bd(),t=e.firstChild.nextSibling;return t.firstChild,z(t,()=>kh(V().stats.costUsd??0),null),y(()=>L(e,`title`,`≈ ${(V().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),z(t,M(P,{get when(){return(V().stats.cachedInputTokens??0)>0},get children(){var e=Vd(),t=e.firstChild.nextSibling,n=t.firstChild;return z(t,()=>Math.round(V().stats.cachedInputTokens/Math.max(1,V().stats.inputTokens)*100),n),y(()=>L(e,`title`,`${Oh(V().stats.cachedInputTokens)} input tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),y(()=>L(d,`title`,`how many times old turns were summarized into notes to make room. ${V().stats.compactions?`Each one keeps the recent stretch verbatim.`:`Not yet — the context has fit so far.`}`)),e})(),(()=>{var e=Wd();return e.firstChild.nextSibling,z(e,M(P,{get when(){return Lr()},get children(){var e=Ud(),t=e.firstChild.nextSibling;return z(t,Lr),e}}),null),e})(),M(N,{get each(){return w()},children:e=>(()=>{var t=uf(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=Lr()===e.branch?null:e.branch,r=t!==Lr();Rr(t),n()&&(r&&(qr++,h([]),_(0),Kr(!1)),Qr(n()))},z(r,()=>e.branch,null),z(r,()=>e.branch===V().branch?` (current)`:``,null),z(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===V().branch||e.branch===Lr()?` cur`:``),i=e.branch===Lr()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),(()=>{var e=Kd();return e.firstChild,z(e,M(P,{get when(){return vr().length>0},get children(){var e=Gd(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>vr().length,t),e}}),null),e})(),M(P,{get when(){return vr().length>0},get fallback(){return df()},get children(){return M(N,{get each(){return vr()},children:e=>(()=>{var t=pf(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>ai(e.agent),z(i,()=>e.id),z(a,()=>e.agent,null),z(r,M(P,{get when(){return e.forked},get children(){return ff()}}),null),z(o,()=>e.schedule,s),z(o,(()=>{var t=F(()=>!!e.next);return()=>t()?Dh(e.next):`—`})(),null),z(o,(()=>{var t=F(()=>!!e.last);return()=>t()?` · last ${Dh(e.last)}`:` · never ran`})(),null),z(c,()=>Ah(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Ah(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&R(t,r.e=i),a!==r.t&&L(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var n=`layout`+(Ce()?``:` right-hidden`)+(je()?` left-open`:``),i=`sidebar`+(je()?` open`:``),a=`iconbtn notifbtn`+(Rn()>0?` has-unread`:``),s=Rn()>0?`${Rn()} unread notifications`:`notifications`,c=`conn`+(oi()?` ok`:``),u=oi()?`live (websocket)`:`reconnecting…`,d={"--termh":`${Mi()}px`},m=`rightbar`+(Ce()?` open`:``);return n!==e.e&&R(t,e.e=n),i!==e.t&&R(r,e.t=i),a!==e.a&&R(o,e.a=a),s!==e.o&&L(o,`title`,e.o=s),c!==e.i&&R(l,e.i=c),u!==e.n&&L(l,`title`,e.n=u),e.s=Te(f,d,e.s),m!==e.h&&R(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})(),M(P,{get when(){return In()},get children(){return[(()=>{var e=Qu();return e.$$click=()=>Ln(!1),e})(),(()=>{var t=td(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return z(r,M(P,{get when(){return Mn().length>0},get children(){var e=$u();return e.$$click=()=>Nn([]),e}}),i),i.$$click=()=>Ln(!1),z(t,M(P,{get when(){return Mn().length>0},get fallback(){return mf()},get children(){var t=ed();return z(t,M(N,{get each(){return Mn()},children:t=>(()=>{var r=gf(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{Nn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&ai(t.agentId),Ln(!1),t.eventId&&setTimeout(()=>Gn(t.eventId),n()===t.agentId?60:350)},z(i,(()=>{var e=F(()=>t.kind===`finish`);return()=>e()?`✅`:F(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),z(a,()=>t.title),z(o,()=>Dh(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),Nn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},z(s,()=>t.read?`✓`:`○`),z(r,M(P,{get when(){return t.body},get children(){var e=hf();return z(e,()=>Eh(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&R(r,e.e=n),i!==e.t&&L(r,`title`,e.t=i),a!==e.a&&L(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),M(P,{get when(){return ae()},get children(){return M(Ph,{get providers(){return Object.keys(k().providers??{})},onClose:()=>oe(!1),onCreated:e=>{oe(!1),gr(),ai(e)}})}}),M(P,{get when(){return le()},get children(){return M(Yh,{get cfg(){return k()},onClose:()=>j(!1),announcedOAuth:de,get skills(){return ra()},get hasSelection(){return!!n()},get agentId(){return n()},get features(){return aa()},onSaved:()=>{rr(),br()},theme:{themes:We,activeId:Pe,paintedId:A,auto:Le,setAuto:Re,dark:Ze,setDark:Qe,light:ze,setLight:Be,setThemes:Ke,setActive:Ie}})}}),M(P,{get when(){return wn()},fallback:null,children:e=>{let t=()=>m().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,m().length-t()-1),[i,a]=v(r()>0?`summarize`:`discard`);return M(Nh,{title:`edit prompt — forks the conversation`,onClose:()=>Tn(null),get children(){var t=vf(),o=t.firstChild,s=o.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:i()})}),Tn(null),gr();let t=n();t&&await ai(t)}catch(e){alert(`edit failed: ${e.message}`)}}),z(t,M(P,{get when(){return r()>0},get children(){var e=_f(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return z(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>Tn(null),y(()=>o.value=e().text),t}})}})]}function vh(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>Be(Math.max(0,n()-t));return e.inline?(()=>{var t=yf();return t.firstChild,z(t,i,null),z(t,(()=>{var t=F(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=bf(),t=e.firstChild;return z(e,i,t),e})()}function yh(e){let[t,n]=v(Date.now());return ee(()=>{let e=setInterval(()=>n(Date.now()),500);C(()=>clearInterval(e))}),e.startedAt?(()=>{var n=xf();return z(n,()=>Be(Math.max(0,t()-e.startedAt))),n})():null}function bh(e){let[t,n]=v(``),r=0;return b(()=>{let t=e.text,i=e.lang,a=++r;n(``),i&&t.trim()&&(async()=>{try{let{highlightLangChunks:e}=await xu(async()=>{let{highlightLangChunks:e}=await import(`./shiki-DC0sHidz.js`);return{highlightLangChunks:e}},[]),o=``;for await(let s of e(i,t)){if(r!==a)return;o+=s,n(o)}}catch{r===a&&n(``)}})()}),C(()=>{r++}),M(P,{get when(){return!!t()},get fallback(){return(()=>{var t=Cf();return z(t,()=>e.text),t})()},get children(){var e=Sf();return y(()=>e.innerHTML=t()),e}})}function xh(e){let t=e.e,n=At(e.prev,t),r=()=>e.res?.(),i=()=>!e.agentActive&&!r(),a=t.data??{},o=String(a.name??`tool`),s=()=>String(r()?.data?.result??``),c=e=>String(a.args?.[e]??``),l=()=>o===`bash`?c(`command`):c(`path`)||JSON.stringify(a.args??{},null,1),u=()=>o===`bash`?Number(c(`timeout_ms`))||void 0:o===`wait_children`?Number(c(`timeout_ms`))||3e5:Number(c(`timeout_ms`))||void 0,d=(e,t=1500,n)=>M(bh,{get text(){return Eh(e,t)},lang:n}),f=(e=2e3)=>M(bh,{get text(){return Eh(JSON.stringify(a.args??{},null,1),e)},lang:`json`}),p=(e=4e3)=>(()=>{let t=r();return t?[F(()=>d(s(),e)),(()=>{var e=wf();return z(e,()=>Be(t.data?.durationMs),null),z(e,()=>o===`bash`?Vt(Bt(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),z(e,M(Mh,{get text(){return s()}}),null),e})()]:Tf()})(),m=x(()=>{r();let e=o,t=``,n=f(2e3);try{switch(o){case`bash`:{let i=c(`command`),o=a.args?.background===!0,l=o?String(s()).match(/job (bg\d+)/)?.[1]??``:``;e=(o?`⏳ `:`$ `)+Ah(i,96);let u=c(`timeout_ms`)?Number(c(`timeout_ms`)):void 0,f=r(),m=Bt(f?.data?.ok,f?String(f.data?.result??``):``);t=f?o?`background job${l?` ${l}`:``}${u?` · timeout ${Math.round(u/1e3)}s`:``}`:Ht({outcome:m,durationMs:f.data?.durationMs,timeoutMs:u,fmtDur:Be}):null,n=[o?(()=>{var e=Ef(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,z(t,l||`?`,n),z(e,l?[` · kill with `,Df()]:null,null),e})():null,F(()=>F(()=>i!==e.slice(2))()?d(i,800,`shellscript`):null),F(()=>p(6e3))];break}case`read_file`:{e=c(`path`)||`(no path)`;let r=[];c(`pattern`)&&r.push(`grep /${Ah(c(`pattern`),40)}/`),Number(a.args?.offset)<0?r.push(`last ${-Number(a.args.offset)} lines`):a.args?.offset&&r.push(`from L${a.args.offset}`),a.args?.limit&&r.push(`≤${a.args.limit} lines`),t=r.join(` · `),n=p(6e3);break}case`write_file`:{let i=String(a.args?.content??``);e=c(`path`)||`(no path)`,t=`${Oh(i.length)} bytes`,n=[F(()=>d(i,1500)),F(()=>F(()=>i.length>1500)()?(()=>{var e=Of(),t=e.firstChild;return z(e,()=>Oh(i.length),t),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=wf();return z(e,()=>Ah(s(),160)),e})():kf())];break}case`edit_file`:e=c(`path`)||`(no path)`,t=a.args?.replace_all===!0?`replace all`:`unique spot`,n=[(()=>{var e=Af();return z(e,()=>Eh(`- `+c(`old_text`),900)),e})(),(()=>{var e=jf();return z(e,()=>`+ `+Eh(c(`new_text`),900)),e})(),F(()=>F(()=>!!r())()?(()=>{var e=Mf(),t=e.firstChild;return z(e,()=>Ah(s(),120),t),z(e,()=>Be(r().data?.durationMs),null),e})():Nf())];break;case`apply_patch`:{let t=c(`patch`).split(`
25
+ `))),e}}),null),z(r,M(P,{get when(){return t.a.goal.status===`done`},get children(){return cd()}}),null),y(e=>{var o=`agent-item`+(t.a.id===n()?` sel`:``)+(t.depth>0?` sub-row`:``)+(t.chatCollapsedGroup?` collapsed`:``),s=t.depth>0?`padding-left:${10+t.depth*14}px`:``,c=t.a.parent?(()=>{let e=St(t.a.id,Yi().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`:t.a.sessionTitle??u().get(t.a.session??``)?`${t.a.sessionTitle??u().get(t.a.session??``)} — ${t.a.id}`:t.a.id;return o!==e.e&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),d!==e.i&&L(i,`title`,e.i=d),f!==e.n&&R(a,e.n=f),p!==e.s&&L(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(),Ln(!In()),In()||Nn(e=>e.map(e=>({...e,read:!0})))},z(o,M(P,{get when(){return Rn()>0},get children(){var e=Tu();return z(e,Rn),e}}),null),z(a,M(jh,{icon:`👻`,get active(){return Pn()},get title(){return Pn()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!Pn();if(Fn(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&V()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&ai(t.id)}}}),null),z(a,M(jh,{icon:`+`,title:`new agent`,onClick:()=>{rr(),oe(!0)}}),null),z(a,M(jh,{icon:`⚙`,title:`settings`,onClick:()=>{rr(),j(!0)}}),null),z(c,`0.36.3`,null),z(d,M(P,{get when(){return E()},get children(){return[`master rss `,F(()=>E().rssMb),`MB · heap `,F(()=>E().heapUsedMb),`MB`,Eu(),`load1 `,F(()=>E().loadavg1),` · up `,F(()=>Math.floor(E().uptimeSec/60)),`m`]}})),z(f,M(P,{get when(){return V()?.id},keyed:!0,get fallback(){return md()},get children(){return[(()=>{var t=Au(),r=t.firstChild,i=r.nextSibling,a=i.nextSibling,o=a.nextSibling,s=o.firstChild,c=s.nextSibling,l=c.nextSibling.nextSibling,u=l.nextSibling.nextSibling,d=u.nextSibling.nextSibling;d.nextSibling;var f=o.nextSibling,p=f.firstChild,m=p.nextSibling;return z(t,M(P,{get when(){return pe()},get children(){var e=Du();return e.$$click=()=>Me(!je()),y(()=>L(e,`aria-expanded`,je())),e}}),r),z(i,()=>V().id),z(a,()=>V().status),z(t,M(P,{get when(){return(V().pendingPromptIds?.length??V().pendingPrompts??0)>0},get children(){var e=Ou(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>V().pendingPromptIds?.length??V().pendingPrompts,t),z(e,()=>V().status===`stopped`?` (stopped)`:``,null),y(()=>L(e,`title`,V().status===`stopped`?`${V().pendingPromptIds?.length??V().pendingPrompts??0} message${(V().pendingPromptIds?.length??V().pendingPrompts??0)>1?`s`:``} from you are still queued, but this agent is STOPPED — nothing will run until you press start (or it is resumed). Each can be withdrawn with ✕ cancel while it is still queued.`:`${V().pendingPromptIds?.length??V().pendingPrompts??0} message${(V().pendingPromptIds?.length??V().pendingPrompts??0)>1?`s`:``} from you waiting in the queue. They will be handed to the model at its next turn boundary — the timeline shows them as "pending (queued)…" until then, and each can be withdrawn with ✕ cancel while it's still queued.`)),e}}),o),z(t,M(P,{get when(){return xr(V().id).length>0},get children(){var e=ku();return e.firstChild,z(e,()=>xr(V().id).length,null),y(()=>L(e,`title`,`scheduled tasks:\n${xr(V().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
26
+ `)}`)),e}}),o),z(o,()=>V().model,s),z(o,()=>V().session,c),z(o,()=>V().branch,l),z(o,()=>V().stats.turns,u),z(o,()=>V().stats.toolCalls,d),p.$$click=()=>(Sn()?ja(`/stop`):ja(`/start`))(),z(p,()=>Sn()?`■ stop`:`▶ start`),z(f,M(P,{get when(){return e().some(e=>e.parent===n())},get children(){return M(jh,{icon:`⏹`,title:`stop every sub-agent this agent spawned (descendants included)`,onClick:Na})}}),m),z(f,M(jh,{icon:`🗄`,title:`archive this agent — reversible: it leaves the list but keeps its config and history (restore in ⚙ settings → archive)`,onClick:Ma}),null),z(f,M(jh,{icon:`⑂`,title:`fork: branch off the conversation here — try things without disturbing the main line`,onClick:Pa}),null),z(f,M(jh,{icon:`⌨`,title:`terminal (t)`,onClick:xi}),null),z(f,M(jh,{icon:`▤`,title:`toggle details panel (d)`,get active(){return Ce()},onClick:ke}),null),y(e=>{var t=`badge ${V().status}`,n=V().statusReason&&!/^(round complete|prompt|api start|goal set|created via web|start)$/.test(V().statusReason)?`${V().status} — ${V().statusReason}`:void 0,r=`${V().model} · ${V().session}/${V().branch} · turns ${V().stats.turns} · tools ${V().stats.toolCalls}`,i=`runbtn`+(Sn()?` danger`:``),s=Sn()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&R(a,e.e=t),n!==e.t&&L(a,`title`,e.t=n),r!==e.a&&L(o,`title`,e.a=r),i!==e.o&&R(p,e.o=i),s!==e.i&&L(p,`title`,e.i=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),t})(),(()=>{var e=Lu();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r={top:t.scrollTop,height:t.scrollHeight,viewport:t.clientHeight},i=$t(r,_a,va,Ca);i===`layout`&&!Dt()&&Sa>0&&Math.abs(r.height-(va??r.height))>1&&(Sa--,be(t,ya)),_a=null,va=r.height,Ca=r.viewport,Vt(r);let a=Dt(),o=performance.now();o-ba>100&&(ba=o,ya=I(t));let s=tn(a,i,r);s!==a&&Ot(s),i===`reader`&&(Sa=4),s&&i!==`reader`?(kt()&&At(0),Bn(),en(s,r)&&Zt(r)>0&&ti()):s&&Qt(r)&&(kt()&&At(0),Bn()),r.top<=4&&n()&&!Vr()&&!Gr()&&m().length>0&&Zr()}),De(e=>Se(e),e),z(e,M(P,{get when(){return Ht()},children:e=>(()=>{var t=hd();return t.firstChild,z(t,(()=>{var t=F(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Oh(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),z(e,M(P,{get when(){return F(()=>!!Gr())()&&Qn().length>0},get children(){return ju()}}),null),z(e,M(P,{get when(){return Vr()},get children(){return Mu()}}),null),z(e,M(P,{get when(){return Qn().length>0},get fallback(){return F(()=>!!Ur())()?gd():_d()},get children(){return[M(N,{get each(){return Qn()},children:e=>M(Ch,{e,prev:()=>er(e,-1),next:()=>er(e,1),get showBranch(){return w().length>1},res:()=>Kn().resFor.get(e.id),get orphan(){return Kn().orphanCalls.has(e.id)},onOption:e=>void Ea(e),answeredIds:Zn,onAnswered:Yn,get agentActive(){return F(()=>!!Cn())()&&qe(e)},onResize:()=>{Dt()&&ti()},get onCancel(){return e.data?.source===`user`&&e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);O(ne()?`${n}\n\n${ne()}`:n),jn(kn(),Dn().filter(e=>e.promptId!==t)),Q(`message withdrawn — draft restored`)}).catch(()=>Q(`withdraw failed — it may have already been sent`))}:void 0},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`&&!(e.data?.pending&&e.data?.sent!==!0)&&!e.data?.cancelled&&!Sn()?()=>Tn({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),M(P,{get when(){return F(()=>!!Cn())()&&cn()},get children(){var e=Iu(),t=e.firstChild.nextSibling;return t.firstChild,z(t,M(P,{get when(){return bn().trim()!==``},get children(){var e=Nu(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return z(t,M(yh,{get startedAt(){return yn()}}),null),De(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{bn(),t&&(e.scrollTop=e.scrollHeight)})},n),z(n,bn),e}}),null),z(t,M(P,{get when(){return un()},get fallback(){return vd()},get children(){return M(P,{get when(){return Xt()},get fallback(){return(()=>{var e=Fu();return y(()=>e.innerHTML=Fe(un()+`▍`)),e})()},get children(){return[Pu(),(()=>{var e=Fu();return y(()=>e.innerHTML=Fe(an()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),M(P,{get when(){return yi()},get children(){var t=Hu(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Ni(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Mi()))},n.$$pointerdown=Gi,z(i,M(N,{get each(){return Si()},children:(e,t)=>(()=>{var n=yd(),r=n.firstChild.nextSibling;return n.$$click=()=>Li(t()),z(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Bi(t())},y(r=>{var i=`termtab`+(Ai()===0&&wi()===t()?` active`:``)+(Oi()&&Ai()===1&&Ei()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),z(i,M(jh,{icon:`+`,title:`new shell in this workspace`,onClick:Ri}),null),z(o,(()=>{var t=F(()=>!!Ii());return()=>t()?e().find(e=>e.id===Ii().agentId)?.workspace.split(`/`).filter(Boolean).pop():V()?.workspace})()),z(a,M(jh,{icon:`◫`,get title(){return Oi()?`single pane`:`split panes (50/50)`},onClick:Ki}),null),z(a,M(jh,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:xi}),null);var l=qi(0);return typeof l==`function`&&De(l,c),c.$$pointerdown=()=>ji(0),z(c,M(P,{get when(){return wi()<0||wi()>=Si().length},get children(){return Ru()}})),z(s,M(P,{get when(){return Oi()},get children(){return[zu(),(()=>{var e=Vu(),t=qi(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>ji(1),z(e,M(P,{get when(){return Ei()<0||Ei()>=Si().length},get children(){return Bu()}})),y(()=>e.classList.toggle(`focused`,Ai()===1)),e})()]}}),null),y(e=>{var n={height:`${Mi()}px`},r=!!Oi(),i=Ai()===0;return e.e=Te(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=Yu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling;return z(e,M(P,{get when(){return F(()=>Pt()>32)()&&!Dt()},get children(){var e=Uu();return e.firstChild,e.$$click=()=>{ni(!0),Bn()},z(e,(()=>{var e=F(()=>kt()>0);return()=>e()?`${kt()} new message${kt()>1?`s`:``}`:`jump to present`})(),null),e}}),t),z(e,M(P,{get when(){return la().length>0},get children(){var e=Wu();return z(e,M(N,{get each(){return la()},children:(e,t)=>(()=>{var n=bd(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{O(e.insert),ca(-1)},z(r,()=>e.insert.trim()),z(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===sa()?` active`:``),a=e.title;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),z(e,M(P,{get when(){return ta().length>0},get children(){var e=Wu();return z(e,M(N,{get each(){return ta()},children:e=>(()=>{var t=xd(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{O(`@${e.key} `),ca(-1)},z(n,()=>e.key,null),z(r,()=>e.label),y(()=>L(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Da),z(t,M(P,{get when(){return K().length>0},get children(){var e=Gu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,z(e,M(N,{get each(){return K()},children:(e,t)=>(()=>{var n=Sd(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>wa(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&L(n,`title`,t.e=i),a!==t.t&&L(r,`src`,t.t=a),o!==t.a&&L(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),z(t,()=>K().length,n),z(t,()=>K().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=la();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),ca(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),ca(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&sa()>=0&&!sh?(e.preventDefault(),O(t[sa()].insert),ca(-1)):e.key===`Escape`&&t.length>0?ca(-1):e.key===`Enter`&&!e.shiftKey&&!sh&&!vt()&&(e.preventDefault(),Da(e))},n.$$input=e=>{O(e.currentTarget.value),ca(0),ha()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),Ta(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{sh=!1}),O(ua?.value??``)}),n.addEventListener(`compositionstart`,()=>{sh=!0}),De(e=>{ua=e,e.value=ne()},n),z(t,M(P,{get when(){return F(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=Ku(),t=e.firstChild;return t.addEventListener(`change`,e=>$i(e.currentTarget.checked)),y(()=>t.checked=Qi()),e}}),r),r.$$click=()=>{let e=!vt();bt(e),requestAnimationFrame(()=>ha())},z(r,()=>vt()?`⤡`:`⤢`),z(t,M(jh,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),z(t,M(P,{get when(){return K().length},get children(){var e=qu();return e.firstChild,z(e,()=>K().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&Ta(e.currentTarget.files),e.currentTarget.value=``}),z(e,M(P,{get when(){return ih()},get children(){var e=Ju();return z(e,ih),e}}),null),y(t=>{var i=`composer`+(vt()?` maximized`:``),a=`message #${V().id} — / for commands · paste or 📎 to attach images`,o=vt()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&R(e,t.e=i),a!==t.t&&L(n,`placeholder`,t.t=a),o!==t.a&&L(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()]}})),z(t,M(P,{get when(){return F(()=>!!pe())()&&Ce()},get children(){var e=Xu();return e.$$click=()=>Oe(!1),e}}),p),p.addEventListener(`scroll`,e=>{Aa=e.currentTarget.scrollTop});var v=ka;return typeof v==`function`?De(v,p):ka=p,z(g,M(jh,{icon:`✕`,title:`close details panel (esc)`,onClick:Ae}),null),z(p,M(P,{get when(){return V()?.id},keyed:!0,fallback:null,children:t=>[M(P,{get when(){return V().id},keyed:!0,fallback:null,children:e=>M(Gh,{agentId:e,get workspace(){return V().workspace}})}),Cd(),(()=>{var t=Ed(),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;_t=!0,rt(r),at(Gt(k().providers,r,e().find(e=>e.id===n()))),dt(r)}),z(r,M(N,{get each(){return ut()},children:e=>(()=>{var t=qd();return t.value=e,z(t,e,null),z(t,()=>e===k().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>at(e.currentTarget.value),z(o,M(N,{get each(){return ct()},children:e=>(()=>{var t=qd();return y(()=>t.value=e.id),t})()})),z(t,M(P,{get when(){return V().effortSupported},get children(){var e=wd(),t=e.firstChild.nextSibling;return t.firstChild,t.addEventListener(`change`,e=>st(e.currentTarget.value)),z(t,M(N,{get each(){return F(()=>!!V().effortOptions?.length)()?V().effortOptions:eh},children:e=>(()=>{var t=qd();return t.value=e,z(t,e),t})()}),null),y(()=>t.value=ot()),e}}),s),c.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:nt(),model:it().trim()||void 0,contextWindowTokens:ct().find(e=>e.id===(it().trim()||void 0))?.contextLength,...V().effortSupported?{reasoningEffort:ot()}:{}})}),t.textContent=`✓ applied`,gr()}catch(e){alert(`apply failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},z(l,()=>V().model,null),z(l,M(P,{get when(){return ct().length},get children(){return[` · `,F(()=>ct().length),` models loaded`]}}),null),z(t,M(P,{get when(){return ht()},get children(){var e=Td();return z(e,ht),e}}),null),y(()=>L(a,`placeholder`,Kt(k().providers,nt(),V(),Ut(V(),k().providers,k().defaultProvider)))),y(()=>r.value=nt()),y(()=>a.value=it()),t})(),(()=>{var e=Dd(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-continue`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(gr)}),y(()=>t.checked=V().autoContinue??!0),e})(),(()=>{var e=kd();return e.firstChild,z(e,M(P,{get when(){return!!V().goal.text.trim()},get fallback(){return Jd()},get children(){var e=Od();return z(e,()=>V().goal.status),y(()=>R(e,`badge ${V().goal.status===`active`?`running`:V().goal.status}`)),e}}),null),e})(),(()=>{var e=Ad();return e.firstChild,z(e,M(N,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Yd();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(gr)},L(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),z(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(V().goal.text.trim()&&V().goal.status===e?` on ${e}`:``),i=!!V().goal.text.trim()&&V().goal.status===e;return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),M(P,{get when(){return V().goal.text},get fallback(){return Xd()},get children(){return[(()=>{var e=jd(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(V().goal.text))),e})(),M(P,{get when(){return V().goal.verify},get children(){var e=Md(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(V().goal.verify))),e}}),M(P,{get when(){return V().goal.audit},children:e=>(()=>{var t=Zd(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return z(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),z(r,()=>Dh(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=mt(e().feedback)?Fe(`_the auditor returned a verdict with no detail_`):Fe(e().feedback);return r!==n.e&&R(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),(()=>{var e=Nd(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,Wa),t.$$input=e=>{Ia(e.currentTarget.value),Ba(!0)},n.$$input=e=>{Ra(e.currentTarget.value),Ba(!0)},r.addEventListener(`change`,e=>Ha(e.currentTarget.checked)),y(()=>t.value=Fa()),y(()=>n.value=La()),y(()=>r.checked=Va()),e})(),(()=>{var e=Fd(),t=e.firstChild.nextSibling;return z(e,M(P,{get when(){return mr().total>0},get children(){var e=Pd(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,z(e,()=>mr().done,t),z(e,()=>mr().total,n),y(t=>Te(e,mr().done===mr().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),M(P,{get when(){return mr().total>0},get children(){var e=Id(),t=e.firstChild;return y(e=>{var n=`barfill `+(mr().done===mr().total?``:`warn`),r=`${Math.round(mr().done/mr().total*100)}%`;return n!==e.e&&R(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),M(Wh,{get draft(){return or()},get preview(){return cr()},onDraft:e=>{sr(e),dr(!0)}}),(()=>{var e=Ld(),t=e.firstChild,n=t.nextSibling;return z(e,M(jh,{get icon(){return cr()?`✎`:`👁`},get title(){return cr()?`edit markdown`:`rendered checklist`},onClick:()=>lr(!cr())}),t),n.$$click=pr,e})(),Rd(),M(P,{get when(){return V().latestProgress},get fallback(){return Qd()},children:e=>(()=>{var t=rf(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return z(t,M(P,{get when(){return e().recent},get children(){var t=$d(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=$m(e().recent)),t}}),i),z(t,M(P,{get when(){return e().problems},get children(){var t=ef(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=$m(e().problems)),t}}),i),z(t,M(P,{get when(){return e().next},get children(){var t=tf(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=$m(e().next)),t}}),i),z(t,M(P,{get when(){return e().goalStatus},get children(){var t=nf(),n=t.firstChild.nextSibling;return z(n,()=>e().goalStatus),t}}),i),z(i,()=>Dh(e().ts)),y(()=>r.innerHTML=$m(e().doing)),t})()}),zd(),(()=>{var e=Hd(),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 z(e,M(P,{get when(){return V().ctx},keyed:!0,get fallback(){return af()},children:e=>{let t=x(()=>{let t=e,n=ct().find(e=>e.id===V().model),r=t.window||n?.contextLength||0,i=r?Math.min(999,t.usedTokens/r*100):0;return{usedTokens:t.usedTokens,compactAt:t.compactAt,compacting:t.compacting,window:t.window,effectiveWindow:r,pct:i,cls:r?i>=85?`crit`:i>=70?`warn`:`ok`:``,derivedBudget:r?Math.round(r*.75):0,usingDerived:t.compactAtIsManual!==!0}}),r=()=>t(),i=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)};return(()=>{var e=lf(),t=e.firstChild,a=t.firstChild.nextSibling,o=a.firstChild.nextSibling;o.nextSibling;var s=t.nextSibling,c=s.firstChild.nextSibling,l=c.firstChild,u=c.nextSibling,d=s.nextSibling,f=d.firstChild.firstChild;return z(a,()=>Oh(r().usedTokens),o),z(t,M(P,{get when(){return r().effectiveWindow},get children(){var e=of(),t=e.firstChild;return z(e,()=>i(r().pct),t),z(e,()=>Oh(r().effectiveWindow),null),y(()=>R(e,`pill ${r().cls}`)),e}}),null),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=sf(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),z(c,()=>Oh(r().usingDerived?r().derivedBudget:r().compactAt),l),z(u,()=>r().usingDerived?`75% of window`:`manual`),z(e,M(P,{get when(){return Ht()||r().compacting},get children(){var e=cf(),t=e.firstChild.nextSibling.nextSibling;return z(t,()=>Ht()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(gr)}),y(()=>f.checked=V().autoCompact!==!1),e})()}}),t),z(i,()=>Oh(V().stats.inputTokens)),z(o,()=>Oh(V().stats.outputTokens)),z(c,()=>V().stats.turns),z(u,()=>V().stats.toolCalls),z(f,()=>V().stats.compactions??0),z(t,M(P,{get when(){return(V().stats.costUsd??0)>0},get children(){var e=Bd(),t=e.firstChild.nextSibling;return t.firstChild,z(t,()=>kh(V().stats.costUsd??0),null),y(()=>L(e,`title`,`≈ ${(V().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),z(t,M(P,{get when(){return(V().stats.cachedInputTokens??0)>0},get children(){var e=Vd(),t=e.firstChild.nextSibling,n=t.firstChild;return z(t,()=>Math.round(V().stats.cachedInputTokens/Math.max(1,V().stats.inputTokens)*100),n),y(()=>L(e,`title`,`${Oh(V().stats.cachedInputTokens)} input tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),y(()=>L(d,`title`,`how many times old turns were summarized into notes to make room. ${V().stats.compactions?`Each one keeps the recent stretch verbatim.`:`Not yet — the context has fit so far.`}`)),e})(),(()=>{var e=Wd();return e.firstChild.nextSibling,z(e,M(P,{get when(){return Lr()},get children(){var e=Ud(),t=e.firstChild.nextSibling;return z(t,Lr),e}}),null),e})(),M(N,{get each(){return w()},children:e=>(()=>{var t=uf(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=Lr()===e.branch?null:e.branch,r=t!==Lr();Rr(t),n()&&(r&&(qr++,h([]),_(0),Kr(!1)),Qr(n()))},z(r,()=>e.branch,null),z(r,()=>e.branch===V().branch?` (current)`:``,null),z(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===V().branch||e.branch===Lr()?` cur`:``),i=e.branch===Lr()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),(()=>{var e=Kd();return e.firstChild,z(e,M(P,{get when(){return vr().length>0},get children(){var e=Gd(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>vr().length,t),e}}),null),e})(),M(P,{get when(){return vr().length>0},get fallback(){return df()},get children(){return M(N,{get each(){return vr()},children:e=>(()=>{var t=pf(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>ai(e.agent),z(i,()=>e.id),z(a,()=>e.agent,null),z(r,M(P,{get when(){return e.forked},get children(){return ff()}}),null),z(o,()=>e.schedule,s),z(o,(()=>{var t=F(()=>!!e.next);return()=>t()?Dh(e.next):`—`})(),null),z(o,(()=>{var t=F(()=>!!e.last);return()=>t()?` · last ${Dh(e.last)}`:` · never ran`})(),null),z(c,()=>Ah(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Ah(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&R(t,r.e=i),a!==r.t&&L(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var n=`layout`+(Ce()?``:` right-hidden`)+(je()?` left-open`:``),i=`sidebar`+(je()?` open`:``),a=`iconbtn notifbtn`+(Rn()>0?` has-unread`:``),s=Rn()>0?`${Rn()} unread notifications`:`notifications`,c=`conn`+(oi()?` ok`:``),u=oi()?`live (websocket)`:`reconnecting…`,d={"--termh":`${Mi()}px`},m=`rightbar`+(Ce()?` open`:``);return n!==e.e&&R(t,e.e=n),i!==e.t&&R(r,e.t=i),a!==e.a&&R(o,e.a=a),s!==e.o&&L(o,`title`,e.o=s),c!==e.i&&R(l,e.i=c),u!==e.n&&L(l,`title`,e.n=u),e.s=Te(f,d,e.s),m!==e.h&&R(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})(),M(P,{get when(){return In()},get children(){return[(()=>{var e=Qu();return e.$$click=()=>Ln(!1),e})(),(()=>{var t=td(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return z(r,M(P,{get when(){return Mn().length>0},get children(){var e=$u();return e.$$click=()=>Nn([]),e}}),i),i.$$click=()=>Ln(!1),z(t,M(P,{get when(){return Mn().length>0},get fallback(){return mf()},get children(){var t=ed();return z(t,M(N,{get each(){return Mn()},children:t=>(()=>{var r=gf(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{Nn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&ai(t.agentId),Ln(!1),t.eventId&&setTimeout(()=>Gn(t.eventId),n()===t.agentId?60:350)},z(i,(()=>{var e=F(()=>t.kind===`finish`);return()=>e()?`✅`:F(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),z(a,()=>t.title),z(o,()=>Dh(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),Nn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},z(s,()=>t.read?`✓`:`○`),z(r,M(P,{get when(){return t.body},get children(){var e=hf();return z(e,()=>Eh(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&R(r,e.e=n),i!==e.t&&L(r,`title`,e.t=i),a!==e.a&&L(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),M(P,{get when(){return ae()},get children(){return M(Ph,{get providers(){return Object.keys(k().providers??{})},onClose:()=>oe(!1),onCreated:e=>{oe(!1),gr(),ai(e)}})}}),M(P,{get when(){return le()},get children(){return M(Yh,{get cfg(){return k()},onClose:()=>j(!1),announcedOAuth:de,get skills(){return ra()},get hasSelection(){return!!n()},get agentId(){return n()},get features(){return aa()},onSaved:()=>{rr(),br()},theme:{themes:We,activeId:Pe,paintedId:A,auto:Le,setAuto:Re,dark:Ze,setDark:Qe,light:ze,setLight:Be,setThemes:Ke,setActive:Ie}})}}),M(P,{get when(){return wn()},fallback:null,children:e=>{let t=()=>m().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,m().length-t()-1),[i,a]=v(r()>0?`summarize`:`discard`);return M(Nh,{title:`edit prompt — forks the conversation`,onClose:()=>Tn(null),get children(){var t=vf(),o=t.firstChild,s=o.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:i()})}),Tn(null),gr();let t=n();t&&await ai(t)}catch(e){alert(`edit failed: ${e.message}`)}}),z(t,M(P,{get when(){return r()>0},get children(){var e=_f(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return z(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>Tn(null),y(()=>o.value=e().text),t}})}})]}function vh(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>Be(Math.max(0,n()-t));return e.inline?(()=>{var t=yf();return t.firstChild,z(t,i,null),z(t,(()=>{var t=F(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=bf(),t=e.firstChild;return z(e,i,t),e})()}function yh(e){let[t,n]=v(Date.now());return ee(()=>{let e=setInterval(()=>n(Date.now()),500);C(()=>clearInterval(e))}),e.startedAt?(()=>{var n=xf();return z(n,()=>Be(Math.max(0,t()-e.startedAt))),n})():null}function bh(e){let[t,n]=v(``),r=0;return b(()=>{let t=e.text,i=e.lang,a=++r;n(``),i&&t.trim()&&(async()=>{try{let{highlightLangChunks:e}=await xu(async()=>{let{highlightLangChunks:e}=await import(`./shiki-IGL6jZ0v.js`);return{highlightLangChunks:e}},[]),o=``;for await(let s of e(i,t)){if(r!==a)return;o+=s,n(o)}}catch{r===a&&n(``)}})()}),C(()=>{r++}),M(P,{get when(){return!!t()},get fallback(){return(()=>{var t=Cf();return z(t,()=>e.text),t})()},get children(){var e=Sf();return y(()=>e.innerHTML=t()),e}})}function xh(e){let t=e.e,n=At(e.prev,t),r=()=>e.res?.(),i=()=>!e.agentActive&&!r(),a=t.data??{},o=String(a.name??`tool`),s=()=>String(r()?.data?.result??``),c=e=>String(a.args?.[e]??``),l=()=>o===`bash`?c(`command`):c(`path`)||JSON.stringify(a.args??{},null,1),u=()=>o===`bash`?Number(c(`timeout_ms`))||void 0:o===`wait_children`?Number(c(`timeout_ms`))||3e5:Number(c(`timeout_ms`))||void 0,d=(e,t=1500,n)=>M(bh,{get text(){return Eh(e,t)},lang:n}),f=(e=2e3)=>M(bh,{get text(){return Eh(JSON.stringify(a.args??{},null,1),e)},lang:`json`}),p=(e=4e3)=>(()=>{let t=r();return t?[F(()=>d(s(),e)),(()=>{var e=wf();return z(e,()=>Be(t.data?.durationMs),null),z(e,()=>o===`bash`?Vt(Bt(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),z(e,M(Mh,{get text(){return s()}}),null),e})()]:Tf()})(),m=x(()=>{r();let e=o,t=``,n=f(2e3);try{switch(o){case`bash`:{let i=c(`command`),o=a.args?.background===!0,l=o?String(s()).match(/job (bg\d+)/)?.[1]??``:``;e=(o?`⏳ `:`$ `)+Ah(i,96);let u=c(`timeout_ms`)?Number(c(`timeout_ms`)):void 0,f=r(),m=Bt(f?.data?.ok,f?String(f.data?.result??``):``);t=f?o?`background job${l?` ${l}`:``}${u?` · timeout ${Math.round(u/1e3)}s`:``}`:Ht({outcome:m,durationMs:f.data?.durationMs,timeoutMs:u,fmtDur:Be}):null,n=[o?(()=>{var e=Ef(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,z(t,l||`?`,n),z(e,l?[` · kill with `,Df()]:null,null),e})():null,F(()=>F(()=>i!==e.slice(2))()?d(i,800,`shellscript`):null),F(()=>p(6e3))];break}case`read_file`:{e=c(`path`)||`(no path)`;let r=[];c(`pattern`)&&r.push(`grep /${Ah(c(`pattern`),40)}/`),Number(a.args?.offset)<0?r.push(`last ${-Number(a.args.offset)} lines`):a.args?.offset&&r.push(`from L${a.args.offset}`),a.args?.limit&&r.push(`≤${a.args.limit} lines`),t=r.join(` · `),n=p(6e3);break}case`write_file`:{let i=String(a.args?.content??``);e=c(`path`)||`(no path)`,t=`${Oh(i.length)} bytes`,n=[F(()=>d(i,1500)),F(()=>F(()=>i.length>1500)()?(()=>{var e=Of(),t=e.firstChild;return z(e,()=>Oh(i.length),t),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=wf();return z(e,()=>Ah(s(),160)),e})():kf())];break}case`edit_file`:e=c(`path`)||`(no path)`,t=a.args?.replace_all===!0?`replace all`:`unique spot`,n=[(()=>{var e=Af();return z(e,()=>Eh(`- `+c(`old_text`),900)),e})(),(()=>{var e=jf();return z(e,()=>`+ `+Eh(c(`new_text`),900)),e})(),F(()=>F(()=>!!r())()?(()=>{var e=Mf(),t=e.firstChild;return z(e,()=>Ah(s(),120),t),z(e,()=>Be(r().data?.durationMs),null),e})():Nf())];break;case`apply_patch`:{let t=c(`patch`).split(`
27
27
  `).filter(e=>e&&!/^---$/.test(e.trim())),i=t.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);e=i.length?`${i.length} file${i.length>1?`s`:``}: ${Ah(i.join(`, `),80)}`:`patch`;let a=t.slice(0,60);n=[(()=>{var e=Pf();return z(e,()=>a.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Ff();return R(n,`pline`+t),z(n,(()=>{var t=F(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),z(e,(()=>{var e=F(()=>t.length>60);return()=>e()?(()=>{var e=If(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>t.length-60,n),e})():null})(),null),e})(),F(()=>F(()=>!!r())()?(()=>{var e=wf();return z(e,()=>Ah(s().split(`
28
- `)[0]??``,140),null),z(e,()=>r().data?.ok===!1?` · FAILED`:``,null),e})():Lf())];break}case`list_dir`:e=c(`path`)||`.`,n=p(4e3);break;case`read_url`:{let r=c(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=Ah(r,70),t=`web`,n=[(()=>{var e=wf();return z(e,M(P,{get when(){return/^https?:/i.test(c(`url`))},get fallback(){return(()=>{var e=zf();return z(e,()=>Ah(c(`url`),80)),e})()},get children(){var e=Rf();return y(()=>L(e,`href`,c(`url`))),e}})),e})(),F(()=>p(3e3))];break}case`bash_output`:{let r=c(`action`)||`read`;e=`bash_output ${c(`job_id`)||`(?)`}`,t=r,n=p(4e3);break}case`load_skill`:{e=`skill: ${c(`name`)}`;let t=s().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);n=r()?[(()=>{var e=Fu();return y(()=>e.innerHTML=Fe(t)),e})(),(()=>{var e=wf();return z(e,()=>Be(r().data?.durationMs)),e})()]:Bf();break}case`save_skill`:{e=`skill: ${c(`name`)}`,t=Ah(c(`description`),60);let i=Array.isArray(a.args?.files)?a.args.files.map(e=>e?.name).filter(Boolean):[];n=[F(()=>F(()=>!!i.length)()?(()=>{var e=Vf();return e.firstChild,z(e,()=>i.join(`, `),null),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=Mf(),t=e.firstChild;return z(e,()=>Ah(s(),160),t),z(e,()=>Be(r().data?.durationMs),null),e})():Hf())];break}default:e=o,t=r()?Be(r().data?.durationMs):null,n=[F(()=>f(2e3)),F(()=>p(4e3))]}}catch{}return{label:e,hint:t,body:n,key:`${r()?.id??`none`}|${e}|${t??``}`}},void 0,{equals:(e,t)=>e.key===t.key});return(()=>{var a=Wf(),c=a.firstChild,d=c.firstChild,f=d.nextSibling,p=f.nextSibling;return a.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),z(d,()=>m().label),z(c,M(P,{get when(){return t.data?.actor},get children(){var e=Uf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),f),z(f,(()=>{var e=F(()=>!!r());return()=>e()?m().hint||``:F(()=>!!i())()?`(result missed)`:F(()=>!!(o===`bash`||u()))()?M(vh,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return u()}}):`running…`})()),z(p,M(Mh,{get text(){return l()},label:`⧉ cmd`,title:`copy the ${o} arguments`}),null),z(p,M(P,{get when(){return r()},get children(){return M(Mh,{get text(){return s()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(a,()=>m().body,null),y(e=>{var t=`embed`+(n?` grouped`:``)+(r()?r().data?.ok===!1?` fail`:` done`:i()?` done`:` running`),s=`${o}${m().hint?` — `+m().hint:``}`;return t!==e.e&&R(a,e.e=t),s!==e.t&&L(a,`title`,e.t=s),e},{e:void 0,t:void 0}),a})()}function Sh(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function Ch(e){let t=e.e,n=lh(t),r=()=>At(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&At(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Gf(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=gt(t.data??{});return(()=>{var t=Kf(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=Ff();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=qf(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Jf(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Yf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Xf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Ff();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=Zf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Qf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=rp(),o=a.firstChild,s=o.nextSibling;return z(o,(()=>{var e=F(()=>!!r());return()=>e()?``:n.icon})()),z(s,(()=>{var e=F(()=>!!r());return()=>e()&&(()=>{var e=ip();return y(()=>L(e,`title`,`${mh(t.ts)} · ${t.branch}`)),e})()})(),null),z(s,M(P,{get when(){return!r()},get children(){var r=np(),i=r.firstChild,a=i.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=Uf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:mh(t.ts)})()),z(r,M(P,{get when(){return e.showBranch},get children(){var e=$f();return z(e,()=>t.branch),e}}),null),z(r,M(P,{get when(){return e.onCancel},get children(){var t=ep();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(Mh,{get text(){return Sh(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=tp();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(s,M(Th,{e:t,get prev(){return e.prev?.()},get res(){return e.res},get orphan(){return e.orphan},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get onAnswered(){return e.onAnswered},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var s=`msg`+(r()?` grouped`:``)+(i()?` next-grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),c=t.id,l=`avatar avghost`+(r()?` ghosted`:``),u=r()?`transparent`:n.color+`33`,d=r()?`1px solid transparent`:`1px solid ${n.color}66`,f=r()?`${mh(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&R(a,e.e=s),c!==e.t&&L(a,`data-eid`,e.t=c),l!==e.a&&R(o,e.a=l),u!==e.o&&Ee(o,`background`,e.o=u),d!==e.i&&Ee(o,`border`,e.i=d),f!==e.n&&L(o,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),a})()}function wh(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=ap(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&L(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function Th(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Fu();return y(()=>e.innerHTML=$m(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=op();return z(t,M(N,{each:e,children:e=>(()=>{var t=sp();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=cp(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Oh(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>Eh(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Fu();return y(()=>e.innerHTML=$m(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return lp()}}),M(P,{get when(){return t.data.final},get children(){var e=up(),n=e.firstChild;return z(e,M(Mh,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(xh,{e:t,get prev(){return e.prev},get res(){return e.res},get orphan(){return e.orphan},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=fp(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(Mh,{text:n}),null),z(c,()=>Eh(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?Vt(Bt(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return dp()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=mp(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=pp();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=$m(String(t.data?.decision??``)),r=$m(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=()=>e.answeredIds?.().has(r)??!1;return(()=>{var a=_p(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return hp()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=gp();return z(a,M(N,{each:n,children:n=>(()=>{var a=vp();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M(wh,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=$m(String(t.data?.question??``));return n!==e.e&&R(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=yp(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=nf(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=$d(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=ef(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=tf(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.next))),e}}),null),y(()=>n.innerHTML=$m(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=bp(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=Sp(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>Oh(Number(t.data.tokensBefore??0)),i),z(n,()=>Oh(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[xp(),(()=>{var e=Fu();return y(()=>e.innerHTML=$m(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Cp();return z(e,()=>Eh(JSON.stringify(t.data),200)),e})()}}function Eh(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Dh(e){let t=new Date(e).getTime()-Date.now(),n=Math.abs(t),r=n<9e4?`${Math.round(n/1e3)}s`:n<54e5?`${Math.round(n/6e4)}m`:`${(n/36e5).toFixed(1)}h`;return t>=0?`in ${r}`:`${r} ago`}function Oh(e){return e>=1e9?`${+(e/1e9).toFixed(1)}b`:e>=1e6?`${+(e/1e6).toFixed(1)}m`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function kh(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 Ah(e,t){return Eh(e.replace(/\s+/g,` `).trim(),t)}function jh(e){return(()=>{var t=wp(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Mh(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),Dt(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=Tp();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function Nh(e){return(()=>{var t=Ep(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function Ph(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}ee(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return M(Nh,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Op(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=kp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),z(w,M(N,{get each(){return e.providers},children:e=>(()=>{var t=qd();return z(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=Dp();return z(e,d),e}}),E),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>T.value=l()),i}})}var Fh=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Ih=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Lh=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Rh(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=zh(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 zh(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Fh.has(t)?`image`:Ih.has(t)?`video`:Lh.has(t)?`audio`:null}var Bh=new Map,Vh=e=>{let t=Bh.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Bh.set(e,t)),t};function Hh(e){let t=()=>e.palette;return(()=>{var n=jp(),r=n.firstChild,i=r.nextSibling,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.nextSibling,d=u.nextSibling,f=d.nextSibling,p=f.nextSibling;return z(n,M(P,{get when(){return e.backgroundImage},get children(){var t=Ap();return y(n=>Ee(t,`background-image`,e.backgroundImage)),t}}),r),y(e=>{var m=t().bgDark,h=t().bgDarkest,g=t().bgDarkest,_=t().bgMid,v=t().fg,y=t().acc,b=t().dim,x=t().acc,S=t().dim,ee=t().ok,C=t().warn,w=t().err;return m!==e.e&&Ee(n,`background`,e.e=m),h!==e.t&&Ee(r,`background`,e.t=h),g!==e.a&&Ee(i,`background`,e.a=g),_!==e.o&&Ee(a,`background`,e.o=_),v!==e.i&&Ee(o,`background`,e.i=v),y!==e.n&&Ee(s,`background`,e.n=y),b!==e.s&&Ee(c,`background`,e.s=b),x!==e.h&&Ee(l,`background`,e.h=x),S!==e.r&&Ee(u,`background`,e.r=S),ee!==e.d&&Ee(d,`background`,e.d=ee),C!==e.l&&Ee(f,`background`,e.l=C),w!==e.u&&Ee(p,`background`,e.u=w),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0}),n})()}function Uh(e){let[t,n]=v(e.themes().some(t=>t.id===e.activeId)?e.activeId:e.themes()[0]?.id??``),r=()=>{let n=e.themes();return n.find(e=>e.id===t())??n.find(t=>t.id===e.activeId)??n[0]},[i,a]=v({}),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=_n(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.paintedId),r=ch.find(t=>t.key===e.paintedId),i=t??r??ch[0],a=getComputedStyle(document.documentElement),o={...sn};for(let{key:e,cssVar:t}of an){let n=_n(a.getPropertyValue(t));n&&(o[e]=n)}let s=mn(e.themes().map(e=>e.id).concat(ch.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))Q(`that file is ${JSON.stringify(t.type||`unknown`)} — pick an image`);else{Q(`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){Q(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),Q(`background image set`)}catch(e){Q(`upload failed: ${e.message}`)}}}};return(()=>{var d=Np(),f=d.firstChild.nextSibling,p=f.firstChild;return p.$$click=l,z(f,M(P,{get when(){return e.themes().length>0},get children(){var r=Mp();return r.addEventListener(`change`,t=>{n(t.currentTarget.value),e.onPick(t.currentTarget.value)}),z(r,M(N,{get each(){return e.themes()},children:e=>(()=>{var t=qd();return z(t,()=>e.label),y(()=>t.value=e.id),t})()})),y(()=>r.value=t()),r}}),null),z(d,M(P,{get when(){return F(()=>!!(r()&&e.themes().some(t=>t.id===e.activeId)))()?r():null},get fallback(){return(()=>{var t=Pp();return z(t,(()=>{var t=F(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,Fp(),` to start from the palette you are using.`]:[`the editor shows when one of your themes is ACTIVE — pick one under "your themes" above (or press `,Fp(),`).`]})()),t})()},children:t=>[(()=>{var e=Ip(),t=e.firstChild.firstChild.nextSibling;return t.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),y(()=>t.value=r().mode),e})(),(()=>{var e=Lp();return z(e,M(N,{each:an,children:e=>(()=>{var t=Up(),n=t.firstChild,o=n.nextSibling,s=o.nextSibling;return n.$$input=t=>c(e.key,t.currentTarget.value),z(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)},L(s,`spellcheck`,!1),y(()=>L(t,`title`,e.cssVar)),y(()=>n.value=_n(r().palette[e.key])??`#000000`),y(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=Rp(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...sn}})),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})(),zp(),(()=>{var e=Vp(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),z(t,()=>r().backgroundImage?`🖼 replace image…`:`🖼 choose image…`),n.addEventListener(`change`,e=>{e.stopPropagation(),u(e.currentTarget.files?.[0]),e.currentTarget.value=``}),n.$$input=e=>e.stopPropagation();var i=o;return typeof i==`function`?De(i,n):o=n,z(e,M(P,{get when(){return r().backgroundImage},get children(){var e=Bp(),t=e.firstChild,n=t.nextSibling;n.firstChild;var i=n.nextSibling.firstChild,a=i.firstChild.nextSibling,o=a.nextSibling,c=o.firstChild,l=i.nextSibling,u=l.firstChild.nextSibling,d=u.nextSibling,f=d.firstChild,p=l.nextSibling;return z(n,()=>{let e=r()?.backgroundImageBytes;return e?` — ${Math.max(1,Math.round(e/1024))} KB`:``},null),a.$$input=e=>s(t=>({...t,backgroundDim:Number(e.currentTarget.value)})),z(o,()=>Math.round((r().backgroundDim??.55)*100),c),u.$$input=e=>s(t=>({...t,surfaceAlpha:Number(e.currentTarget.value)})),z(d,()=>Math.round((r().surfaceAlpha??.82)*100),f),p.$$click=()=>s(e=>({...e,backgroundImage:void 0})),y(()=>L(t,`src`,r().backgroundImage)),y(()=>a.value=r().backgroundDim??.55),y(()=>u.value=r().surfaceAlpha??.82),e}}),null),e})(),Hp()]}),null),d})()}function Wh(e){let t=Number(localStorage.getItem(`teapot.todoH`)??``),[n,r]=v(Number.isFinite(t)&&t>0?t:0),i=()=>n()>0?{height:`${n()}px`}:void 0,a=e=>{let t=new ResizeObserver(()=>{let t=e.offsetHeight;t<=0||r(e=>Math.abs(e-t)<1?e:(localStorage.setItem(`teapot.todoH`,String(t)),t))});t.observe(e),C(()=>t.disconnect())};return M(P,{get when(){return e.preview},get fallback(){return(()=>{var t=Gp();return t.$$input=t=>e.onDraft(t.currentTarget.value),De(a,t),y(e=>Te(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=Wp();return De(a,t),y(n=>{var r=i(),a=$m(e.draft);return n.e=Te(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function Gh(e){let t=Vh(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),ee=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},w=e=>x()!==`hide`||!e.ignored,[T,E]=v(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!T(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await re(t,e)}))).then(t=>{E(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&O(e,n)})},D=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function ne(e){return re(e,T())}async function re(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return D(t,i.entries??[])}catch(e){return _(e.message),null}}let O=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),k=``;b(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),ne(``).then(e=>{e&&k===t&&r(new Map([[``,e]]))}))});let ie=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await ne(e.path);t&&O(e.path,t)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[j,ue]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await xu(async()=>{let{highlightChunks:e}=await import(`./shiki-DC0sHidz.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};C(()=>{fe++});let me=async(t,n)=>{let r=zh(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(t&&!j()){ue(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
28
+ `)[0]??``,140),null),z(e,()=>r().data?.ok===!1?` · FAILED`:``,null),e})():Lf())];break}case`list_dir`:e=c(`path`)||`.`,n=p(4e3);break;case`read_url`:{let r=c(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=Ah(r,70),t=`web`,n=[(()=>{var e=wf();return z(e,M(P,{get when(){return/^https?:/i.test(c(`url`))},get fallback(){return(()=>{var e=zf();return z(e,()=>Ah(c(`url`),80)),e})()},get children(){var e=Rf();return y(()=>L(e,`href`,c(`url`))),e}})),e})(),F(()=>p(3e3))];break}case`bash_output`:{let r=c(`action`)||`read`;e=`bash_output ${c(`job_id`)||`(?)`}`,t=r,n=p(4e3);break}case`load_skill`:{e=`skill: ${c(`name`)}`;let t=s().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);n=r()?[(()=>{var e=Fu();return y(()=>e.innerHTML=Fe(t)),e})(),(()=>{var e=wf();return z(e,()=>Be(r().data?.durationMs)),e})()]:Bf();break}case`save_skill`:{e=`skill: ${c(`name`)}`,t=Ah(c(`description`),60);let i=Array.isArray(a.args?.files)?a.args.files.map(e=>e?.name).filter(Boolean):[];n=[F(()=>F(()=>!!i.length)()?(()=>{var e=Vf();return e.firstChild,z(e,()=>i.join(`, `),null),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=Mf(),t=e.firstChild;return z(e,()=>Ah(s(),160),t),z(e,()=>Be(r().data?.durationMs),null),e})():Hf())];break}default:e=o,t=r()?Be(r().data?.durationMs):null,n=[F(()=>f(2e3)),F(()=>p(4e3))]}}catch{}return{label:e,hint:t,body:n,key:`${r()?.id??`none`}|${e}|${t??``}`}},void 0,{equals:(e,t)=>e.key===t.key});return(()=>{var a=Wf(),c=a.firstChild,d=c.firstChild,f=d.nextSibling,p=f.nextSibling;return a.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),z(d,()=>m().label),z(c,M(P,{get when(){return t.data?.actor},get children(){var e=Uf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),f),z(f,(()=>{var e=F(()=>!!r());return()=>e()?m().hint||``:F(()=>!!i())()?`(result missed)`:F(()=>!!(o===`bash`||u()))()?M(vh,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return u()}}):`running…`})()),z(p,M(Mh,{get text(){return l()},label:`⧉ cmd`,title:`copy the ${o} arguments`}),null),z(p,M(P,{get when(){return r()},get children(){return M(Mh,{get text(){return s()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(a,()=>m().body,null),y(e=>{var t=`embed`+(n?` grouped`:``)+(r()?r().data?.ok===!1?` fail`:` done`:i()?` done`:` running`),s=`${o}${m().hint?` — `+m().hint:``}`;return t!==e.e&&R(a,e.e=t),s!==e.t&&L(a,`title`,e.t=s),e},{e:void 0,t:void 0}),a})()}function Sh(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function Ch(e){let t=e.e,n=lh(t),r=()=>At(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&At(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Gf(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=gt(t.data??{});return(()=>{var t=Kf(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=Ff();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=qf(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Jf(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Yf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Xf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Ff();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=Zf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Qf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=rp(),o=a.firstChild,s=o.nextSibling;return z(o,(()=>{var e=F(()=>!!r());return()=>e()?``:n.icon})()),z(s,(()=>{var e=F(()=>!!r());return()=>e()&&(()=>{var e=ip();return y(()=>L(e,`title`,`${mh(t.ts)} · ${t.branch}`)),e})()})(),null),z(s,M(P,{get when(){return!r()},get children(){var r=np(),i=r.firstChild,a=i.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=Uf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:mh(t.ts)})()),z(r,M(P,{get when(){return e.showBranch},get children(){var e=$f();return z(e,()=>t.branch),e}}),null),z(r,M(P,{get when(){return e.onCancel},get children(){var t=ep();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(Mh,{get text(){return Sh(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=tp();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(s,M(Th,{e:t,get prev(){return e.prev?.()},get res(){return e.res},get orphan(){return e.orphan},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get onAnswered(){return e.onAnswered},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var s=`msg`+(r()?` grouped`:``)+(i()?` next-grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),c=t.id,l=`avatar avghost`+(r()?` ghosted`:``),u=r()?`transparent`:n.color+`33`,d=r()?`1px solid transparent`:`1px solid ${n.color}66`,f=r()?`${mh(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&R(a,e.e=s),c!==e.t&&L(a,`data-eid`,e.t=c),l!==e.a&&R(o,e.a=l),u!==e.o&&Ee(o,`background`,e.o=u),d!==e.i&&Ee(o,`border`,e.i=d),f!==e.n&&L(o,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),a})()}function wh(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=ap(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&L(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function Th(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Fu();return y(()=>e.innerHTML=$m(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=op();return z(t,M(N,{each:e,children:e=>(()=>{var t=sp();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=cp(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Oh(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>Eh(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Fu();return y(()=>e.innerHTML=$m(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return lp()}}),M(P,{get when(){return t.data.final},get children(){var e=up(),n=e.firstChild;return z(e,M(Mh,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(xh,{e:t,get prev(){return e.prev},get res(){return e.res},get orphan(){return e.orphan},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=fp(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(Mh,{text:n}),null),z(c,()=>Eh(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?Vt(Bt(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return dp()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=mp(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=pp();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=$m(String(t.data?.decision??``)),r=$m(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=()=>e.answeredIds?.().has(r)??!1;return(()=>{var a=_p(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return hp()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=gp();return z(a,M(N,{each:n,children:n=>(()=>{var a=vp();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M(wh,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=$m(String(t.data?.question??``));return n!==e.e&&R(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=yp(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=nf(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=$d(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=ef(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=tf(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.next))),e}}),null),y(()=>n.innerHTML=$m(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=bp(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=Sp(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>Oh(Number(t.data.tokensBefore??0)),i),z(n,()=>Oh(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[xp(),(()=>{var e=Fu();return y(()=>e.innerHTML=$m(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Cp();return z(e,()=>Eh(JSON.stringify(t.data),200)),e})()}}function Eh(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Dh(e){let t=new Date(e).getTime()-Date.now(),n=Math.abs(t),r=n<9e4?`${Math.round(n/1e3)}s`:n<54e5?`${Math.round(n/6e4)}m`:`${(n/36e5).toFixed(1)}h`;return t>=0?`in ${r}`:`${r} ago`}function Oh(e){return e>=1e9?`${+(e/1e9).toFixed(1)}b`:e>=1e6?`${+(e/1e6).toFixed(1)}m`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function kh(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 Ah(e,t){return Eh(e.replace(/\s+/g,` `).trim(),t)}function jh(e){return(()=>{var t=wp(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Mh(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),Dt(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=Tp();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function Nh(e){return(()=>{var t=Ep(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function Ph(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}ee(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return M(Nh,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Op(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=kp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),z(w,M(N,{get each(){return e.providers},children:e=>(()=>{var t=qd();return z(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=Dp();return z(e,d),e}}),E),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>T.value=l()),i}})}var Fh=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Ih=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Lh=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Rh(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=zh(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 zh(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Fh.has(t)?`image`:Ih.has(t)?`video`:Lh.has(t)?`audio`:null}var Bh=new Map,Vh=e=>{let t=Bh.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Bh.set(e,t)),t};function Hh(e){let t=()=>e.palette;return(()=>{var n=jp(),r=n.firstChild,i=r.nextSibling,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.nextSibling,d=u.nextSibling,f=d.nextSibling,p=f.nextSibling;return z(n,M(P,{get when(){return e.backgroundImage},get children(){var t=Ap();return y(n=>Ee(t,`background-image`,e.backgroundImage)),t}}),r),y(e=>{var m=t().bgDark,h=t().bgDarkest,g=t().bgDarkest,_=t().bgMid,v=t().fg,y=t().acc,b=t().dim,x=t().acc,S=t().dim,ee=t().ok,C=t().warn,w=t().err;return m!==e.e&&Ee(n,`background`,e.e=m),h!==e.t&&Ee(r,`background`,e.t=h),g!==e.a&&Ee(i,`background`,e.a=g),_!==e.o&&Ee(a,`background`,e.o=_),v!==e.i&&Ee(o,`background`,e.i=v),y!==e.n&&Ee(s,`background`,e.n=y),b!==e.s&&Ee(c,`background`,e.s=b),x!==e.h&&Ee(l,`background`,e.h=x),S!==e.r&&Ee(u,`background`,e.r=S),ee!==e.d&&Ee(d,`background`,e.d=ee),C!==e.l&&Ee(f,`background`,e.l=C),w!==e.u&&Ee(p,`background`,e.u=w),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0}),n})()}function Uh(e){let[t,n]=v(e.themes().some(t=>t.id===e.activeId)?e.activeId:e.themes()[0]?.id??``),r=()=>{let n=e.themes();return n.find(e=>e.id===t())??n.find(t=>t.id===e.activeId)??n[0]},[i,a]=v({}),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=_n(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.paintedId),r=ch.find(t=>t.key===e.paintedId),i=t??r??ch[0],a=getComputedStyle(document.documentElement),o={...sn};for(let{key:e,cssVar:t}of an){let n=_n(a.getPropertyValue(t));n&&(o[e]=n)}let s=mn(e.themes().map(e=>e.id).concat(ch.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))Q(`that file is ${JSON.stringify(t.type||`unknown`)} — pick an image`);else{Q(`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){Q(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),Q(`background image set`)}catch(e){Q(`upload failed: ${e.message}`)}}}};return(()=>{var d=Np(),f=d.firstChild.nextSibling,p=f.firstChild;return p.$$click=l,z(f,M(P,{get when(){return e.themes().length>0},get children(){var r=Mp();return r.addEventListener(`change`,t=>{n(t.currentTarget.value),e.onPick(t.currentTarget.value)}),z(r,M(N,{get each(){return e.themes()},children:e=>(()=>{var t=qd();return z(t,()=>e.label),y(()=>t.value=e.id),t})()})),y(()=>r.value=t()),r}}),null),z(d,M(P,{get when(){return F(()=>!!(r()&&e.themes().some(t=>t.id===e.activeId)))()?r():null},get fallback(){return(()=>{var t=Pp();return z(t,(()=>{var t=F(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,Fp(),` to start from the palette you are using.`]:[`the editor shows when one of your themes is ACTIVE — pick one under "your themes" above (or press `,Fp(),`).`]})()),t})()},children:t=>[(()=>{var e=Ip(),t=e.firstChild.firstChild.nextSibling;return t.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),y(()=>t.value=r().mode),e})(),(()=>{var e=Lp();return z(e,M(N,{each:an,children:e=>(()=>{var t=Up(),n=t.firstChild,o=n.nextSibling,s=o.nextSibling;return n.$$input=t=>c(e.key,t.currentTarget.value),z(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)},L(s,`spellcheck`,!1),y(()=>L(t,`title`,e.cssVar)),y(()=>n.value=_n(r().palette[e.key])??`#000000`),y(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=Rp(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...sn}})),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})(),zp(),(()=>{var e=Vp(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),z(t,()=>r().backgroundImage?`🖼 replace image…`:`🖼 choose image…`),n.addEventListener(`change`,e=>{e.stopPropagation(),u(e.currentTarget.files?.[0]),e.currentTarget.value=``}),n.$$input=e=>e.stopPropagation();var i=o;return typeof i==`function`?De(i,n):o=n,z(e,M(P,{get when(){return r().backgroundImage},get children(){var e=Bp(),t=e.firstChild,n=t.nextSibling;n.firstChild;var i=n.nextSibling.firstChild,a=i.firstChild.nextSibling,o=a.nextSibling,c=o.firstChild,l=i.nextSibling,u=l.firstChild.nextSibling,d=u.nextSibling,f=d.firstChild,p=l.nextSibling;return z(n,()=>{let e=r()?.backgroundImageBytes;return e?` — ${Math.max(1,Math.round(e/1024))} KB`:``},null),a.$$input=e=>s(t=>({...t,backgroundDim:Number(e.currentTarget.value)})),z(o,()=>Math.round((r().backgroundDim??.55)*100),c),u.$$input=e=>s(t=>({...t,surfaceAlpha:Number(e.currentTarget.value)})),z(d,()=>Math.round((r().surfaceAlpha??.82)*100),f),p.$$click=()=>s(e=>({...e,backgroundImage:void 0})),y(()=>L(t,`src`,r().backgroundImage)),y(()=>a.value=r().backgroundDim??.55),y(()=>u.value=r().surfaceAlpha??.82),e}}),null),e})(),Hp()]}),null),d})()}function Wh(e){let t=Number(localStorage.getItem(`teapot.todoH`)??``),[n,r]=v(Number.isFinite(t)&&t>0?t:0),i=()=>n()>0?{height:`${n()}px`}:void 0,a=e=>{let t=new ResizeObserver(()=>{let t=e.offsetHeight;t<=0||r(e=>Math.abs(e-t)<1?e:(localStorage.setItem(`teapot.todoH`,String(t)),t))});t.observe(e),C(()=>t.disconnect())};return M(P,{get when(){return e.preview},get fallback(){return(()=>{var t=Gp();return t.$$input=t=>e.onDraft(t.currentTarget.value),De(a,t),y(e=>Te(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=Wp();return De(a,t),y(n=>{var r=i(),a=$m(e.draft);return n.e=Te(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function Gh(e){let t=Vh(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),ee=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},w=e=>x()!==`hide`||!e.ignored,[T,E]=v(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!T(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await re(t,e)}))).then(t=>{E(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&O(e,n)})},D=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function ne(e){return re(e,T())}async function re(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return D(t,i.entries??[])}catch(e){return _(e.message),null}}let O=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),k=``;b(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),ne(``).then(e=>{e&&k===t&&r(new Map([[``,e]]))}))});let ie=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await ne(e.path);t&&O(e.path,t)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[j,ue]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await xu(async()=>{let{highlightChunks:e}=await import(`./shiki-IGL6jZ0v.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};C(()=>{fe++});let me=async(t,n)=>{let r=zh(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(t&&!j()){ue(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
29
29
  OK = load the disk version into the editor (your edits are discarded)
30
- Cancel = keep editing your copy`)?(le(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{ue(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=qp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Rh(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Kp();return z(t,()=>Oh(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(w)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await re(e,T())})));for(let{p:e,rows:n}of t)n&&O(e,n)}finally{be(!1)}}};return[(()=>{var e=Jp(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(jh,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(jh,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),z(e,M(jh,{class:`filetoggle`,get icon(){return T()?`◉.`:`○.`},get title(){return T()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:te}),null),e})(),(()=>{var e=Yp();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=Xp();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(w)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(Nh,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=tm(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=$p();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=em();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return rm()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(Kh,{get path(){return t().path},get content(){return t().content},get html(){return ae()},get pending(){return se()},get truncated(){return!!t().truncated}})},get children(){var e=im();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=nm(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>Oh(A().length),i),a.$$click=()=>void he(),z(a,()=>j()?`saving…`:`💾 save`),y(()=>a.disabled=j()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=Qp(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=om();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=am();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Zp();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function Kh(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=lm(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=um();return z(t,()=>e.content),t})()},get children(){var t=sm();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return cm()}})]}var qh=[{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 Jh(e){return(()=>{var t=dm(),n=t.firstChild;return z(t,()=>e.label,n),n.$$input=t=>e.onValue(Number(t.currentTarget.value)),y(()=>L(t,`title`,e.hint)),y(()=>n.value=e.value),t})()}function Yh(e){let t=(e,t)=>{let n=Array.isArray(t?.apiKeys)&&t.apiKeys.length?t.apiKeys.filter(e=>typeof e==`string`&&e.trim()):t?.apiKey?[String(t.apiKey)]:[``];return{name:e,baseUrl:t?.baseUrl??``,apiKeys:n.length?n:[``],model:t?.model??``}},[n,r]=v(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=v(e.cfg.defaultProvider??``),o=()=>e.cfg.defaultProvider??``,s=()=>{let e=[...new Set(n().map(e=>e.name.trim()).filter(Boolean))],t=i();return t&&!e.includes(t)&&e.push(t),e},c=()=>{let e=i();return e?n().some(t=>t.name.trim()===e)?``:e:``},[l,u]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=v(e.cfg.progressMinChars??4e3),[p,m]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,x]=v(e.cfg.maxSpawnDepth??3),[S,ee]=v(!!e.cfg.shortContext),[C,w]=v((e.cfg.tasks??[]).map(e=>({...e}))),[T,E]=v((e.cfg.mcpServers??[]).map(e=>({...e}))),[te,D]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ne,re]=v({}),[O,k]=v(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`]}))),[ie,ae]=v(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]??``]}))),[oe,se]=v(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:``]}))),[ce,A]=v({}),[le,j]=v({}),[ue,de]=v({}),fe=e=>{let t=String(e??``).trim();if(!t)return null;let n=ue()[t];return n&&(n.required||n.authorized)?n:null},pe=async()=>{let e=await $(`/api/mcp`).catch(()=>null);j(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},me=async e=>{let t=String(e??``).trim();if(!t)return;let n=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&de(e=>({...e,[t]:n}))},he=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 $(`/api/mcp/oauth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name})}).catch(()=>null);if(r?.alreadyAuthorized){A(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await me(n.name),await pe();return}if(!r?.ok||!r.url){A(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await me(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 $(`/api/mcp/oauth/status?name=${encodeURIComponent(n.name)}`).catch(()=>null);if(r&&!r.error){if(de(e=>({...e,[t]:r})),r.authorized){A(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await pe(),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`}}))};b(()=>{ve()===`mcp`&&(pe(),T().forEach((e,t)=>{e.name&&me(e.name)}))});let[ge,_e]=v(``),[ve,be]=v(`providers`),xe=(t,n)=>{let{slot:r}=_t(e.theme.auto(),n);r===`dark`?e.theme.setDark(t):r===`light`?e.theme.setLight(t):e.theme.setActive(t)},Se=t=>vt({auto:e.theme.auto(),fixed:e.theme.activeId(),dark:e.theme.dark(),light:e.theme.light(),prefersLight:typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-color-scheme: light)`).matches})===t,[I,Ce]=v([]),we=async()=>{let e=await $(`/api/archived`).catch(()=>null);Ce(e?.agents??[])},Te=()=>I().filter(e=>!e.parent);b(()=>{ve()===`archive`&&we()});let Ee=[{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`}],De=()=>(e.cfg.agents??[]).map(e=>e.id),Oe=()=>e.theme.themes(),ke=()=>e.theme.activeId(),Ae=()=>{let t=e.theme.activeId();return e.theme.themes().find(e=>e.id===t)?.mode??ch.find(e=>e.key===t)?.mode??`dark`},je=t=>e.theme.setActive(t),Me=()=>e.theme.auto(),Ne=t=>e.theme.setAuto(t),Pe=()=>e.theme.dark(),Fe=t=>e.theme.setDark(t),Ie=()=>e.theme.light(),Le=t=>e.theme.setLight(t),Re=t=>e.theme.setThemes(t),ze=e=>cn[e]??sn,Be=()=>{let e={};for(let t of n()){if(!t.name.trim())return _e(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return _e(`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},[Ve,He]=v(`idle`),Ue=e=>{_e(e),He(e=>e===`saving`?`idle`:e)},We=async t=>{t.preventDefault(),_e(``),He(`saving`);let n=Be();if(!n)return He(`idle`);let r=C().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of r){if(!e.agent)return Ue(`task "${e.id}": agent is required`);if(!e.schedule?.trim())return Ue(`task "${e.id}": schedule is required`)}let a=[],o=new Set;for(let e of T()){let t=String(e.name??``).trim(),n=String(e.url??``).trim(),r=e.transport??`http`,i=String(e.command??``).trim();if(t||n||i){if(!t)return Ue(`MCP: a server needs a name`);if(o.has(t))return Ue(`MCP: two servers are named "${t}"`);if(o.add(t),r===`stdio`?!i:!n)return Ue(`MCP "${t}": ${r===`stdio`?`a command is`:`a url is`} required`);a.push({name:t,transport:r,enabled:e.enabled!==!1,...n?{url:n}:{},...r===`stdio`?{command:i,...e.args?.length?{args:e.args}:{}}:{},...e.headers&&Object.keys(e.headers).length?{headers:e.headers}:{}})}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:i()||void 0,progressIntervalMs:Math.max(1,l())*6e4,progressMinChars:Math.max(100,d()),...p()==null?{}:{contextTokenBudget:Math.max(1,p())*1e3},...h()>0?{contextWindowTokens:h()*1e3}:{},maxSpawnDepth:Math.max(0,_()),shortContext:S(),tasks:r,mcpServers:a})}),await pe(),await Promise.all(a.map((e,t)=>e.name?me(e.name):Promise.resolve())),setTimeout(()=>{pe(),a.forEach((e,t)=>{e.name&&me(e.name)})},1200),e.onSaved();let t=new Set(a.map(e=>e.name).filter(Boolean)),o=T().filter(e=>{let n=String(e.name??``).trim();return t.has(n)&&ue()[n]?.required&&!ue()[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??``));Q(`${o.map(e=>String(e.name??``).trim()).filter(Boolean).join(`, `)||`a saved MCP server`} needs authorization — 🔑 authorize in MCP servers`)}He(`saved`),setTimeout(()=>{He(`idle`),e.onClose()},400)}catch(e){_e(e.message),He(`error`),setTimeout(()=>He(`idle`),1600)}};return M(Nh,{title:`settings`,get onClose(){return e.onClose},get children(){var t=hm(),b=t.firstChild,j=b.firstChild,de=j.nextSibling.firstChild,pe=de.firstChild.nextSibling,I=pe.nextSibling;I.firstChild;var Ce=I.nextSibling.firstChild.firstChild.nextSibling;Ce.firstChild;var Be=de.nextSibling,He=Be.firstChild.nextSibling,Ue=He.firstChild.firstChild.nextSibling,Ge=He.nextSibling,Ke=Be.nextSibling,qe=Ke.firstChild.nextSibling,Je=qe.firstChild,Ye=Je.firstChild.nextSibling,Xe=qe.nextSibling.firstChild,Ze=Ke.nextSibling,Qe=Ze.firstChild.nextSibling.nextSibling,$e=Ze.nextSibling,et=$e.firstChild.nextSibling,tt=$e.nextSibling;tt.firstChild;var nt=tt.nextSibling;nt.firstChild;var rt=nt.nextSibling,it=rt.firstChild.nextSibling.firstChild;it.firstChild;var at=it.nextSibling,ot=rt.nextSibling,st=ot.firstChild.nextSibling.firstChild,ct=st.firstChild.nextSibling,lt=st.nextSibling.firstChild.nextSibling,ut=ot.nextSibling,dt=b.nextSibling,ft=dt.firstChild;return t.addEventListener(`submit`,We),z(j,M(N,{each:Ee,children:e=>(()=>{var t=gm(),n=t.firstChild;return t.$$click=()=>be(e.key),z(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(ve()===e.key?` on`:``),i=e.hint,a=ve()===e.key?`page`:void 0;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),z(de,M(ye,{get each(){return n()},children:(e,t)=>(()=>{var i=_m(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.firstChild;return a.$$input=e=>r(n().map((n,r)=>r===t?{...n,name:e.currentTarget.value}:n)),o.$$input=e=>r(n().map((n,r)=>r===t?{...n,baseUrl:e.currentTarget.value}:n)),s.$$input=e=>r(n().map((n,r)=>r===t?{...n,model:e.currentTarget.value}:n)),c.$$click=()=>r(n().filter((e,n)=>n!==t)),z(l,M(N,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=ym(),s=o.firstChild;return s.$$input=e=>r(n().map((n,r)=>r===t?{...n,apiKeys:n.apiKeys.map((t,n)=>n===a()?e.currentTarget.value:t)}:n)),s.value=i,z(o,M(P,{get when(){return e().apiKeys.length>1},get children(){var e=vm();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>L(s,`placeholder`,a()===0?`api key`:`api key (backup)`)),o})()}),u),u.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:[...e.apiKeys,``]}:e)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().model),i})()}),pe),pe.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),z(I,M(N,{each:qh,children:e=>(()=>{var t=bm();return t.firstChild,t.$$click=()=>{let t=n().filter(t=>t.name!==e.key);r([...t,{name:e.key,baseUrl:e.url,apiKeys:[``],model:e.model}]),i()||a(e.key)},z(t,()=>e.label,null),y(()=>L(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),Ce.addEventListener(`change`,e=>a(e.currentTarget.value)),z(Ce,M(N,{get each(){return s()},children:e=>(()=>{var t=qd();return t.value=e,z(t,e),t})()}),null),z(de,M(P,{get when(){return c()},get children(){var e=fm(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,c),z(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,c),e}}),null),Ue.addEventListener(`change`,e=>{Ne(e.currentTarget.checked),localStorage.setItem(`teapot.theme.auto`,e.currentTarget.checked?`1`:`0`)}),z(Be,M(P,{get when(){return Me()},get children(){var e=pm(),t=e.firstChild,n=t.firstChild.nextSibling,r=t.nextSibling.firstChild.nextSibling;return n.addEventListener(`change`,e=>{Fe(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),z(n,M(N,{get each(){return Oe().filter(e=>e.mode===`dark`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(ch.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=qd();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),r.addEventListener(`change`,e=>{Le(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(r,M(N,{get each(){return Oe().filter(e=>e.mode===`light`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(ch.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=qd();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>n.value=Pe()),y(()=>r.value=Ie()),e}}),Ge),z(Be,M(N,{each:[{mode:`dark`,title:`dark themes`},{mode:`light`,title:`light themes`}],children:e=>M(P,{get when(){return F(()=>!![...Oe(),...ch].some(t=>t.mode===e.mode))()&&(Me()||Ae()===e.mode)},get children(){return[(()=>{var t=xm();return z(t,()=>e.title),t})(),(()=>{var t=Sm();return z(t,M(N,{get each(){return Oe().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=Cm(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>xe(e.id,e.mode),z(n,M(Hh,{get palette(){return e.palette},get backgroundImage(){return e.backgroundImage}})),z(r,()=>e.label,i),y(n=>{var r=`themecard`+(Se(e.id)?` on`:``),i=`${e.label} (custom)${e.backgroundImage?` · with a background image`:``}`,a=Se(e.id);return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),z(t,M(N,{get each(){return ch.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=wm(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>xe(e.key,e.mode),z(n,M(Hh,{get palette(){return ze(e.key)}})),z(r,()=>e.label),y(n=>{var r=`themecard`+(Se(e.key)?` on`:``),i=`${e.label} (${e.mode})`,a=Se(e.key);return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),t})()]}})}),null),z(Be,M(Uh,{themes:Oe,get activeId(){return ke()},get paintedId(){return e.theme.paintedId()},onChange:e=>{let t=fn(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=fn(t);if(r.ok)n=t,Q(`storage was full — saved without the background image(s)`);else{Q(r.error??`could not save theme`);return}}Re(n);let r=e=>n.some(t=>t.id===e)||ch.some(t=>t.key===e);r(ke())||(je(`dark`),localStorage.setItem(`teapot.theme`,`dark`)),r(Pe())||(Fe(`dark`),localStorage.setItem(`teapot.theme.dark`,`dark`)),r(Ie())||(Le(`light`),localStorage.setItem(`teapot.theme.light`,`light`))},onPick:e=>{let t=Oe().find(t=>t.id===e)?.mode??ch.find(t=>t.key===e)?.mode??`dark`,n=_t(Me(),t);n.slot===`dark`?Fe(e):n.slot===`light`?Le(e):je(e),localStorage.setItem(n.key,e)}}),null),z(qe,M(Jh,{label:`progress interval (min)`,get value(){return l()},onValue:e=>u(e),hint:`how often the harness asks for a progress report`}),Je),z(qe,M(Jh,{label:`progress min chars`,get value(){return d()},onValue:e=>f(e),hint:`progress prompts wait for this much real output`}),Je),Ye.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),z(qe,M(Jh,{label:`context window (k tok)`,get value(){return h()},onValue:e=>g(e),hint:`model's real window — 0/blank hides the % gauge`}),null),z(qe,M(Jh,{label:`max spawn depth`,get value(){return _()},onValue:e=>x(e),hint:`sub-agent nesting limit (0 = no spawning)`}),null),Xe.addEventListener(`change`,e=>ee(e.currentTarget.checked)),z(Ze,M(P,{get when(){return T().length>0},get fallback(){return Tm()},get children(){return M(ye,{get each(){return T()},children:(e,t)=>{let n=()=>le()[e().name],r=e=>E(T().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=Im(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.nextSibling,l=c.firstChild,u=c.nextSibling,d=a.nextSibling,f=d.firstChild,p=d.nextSibling,m=p.firstChild,h=m.firstChild,g=p.nextSibling,_=g.firstChild;return o.$$input=e=>r({name:e.currentTarget.value}),s.$$input=e=>r({url:e.currentTarget.value}),l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>E(T().filter((e,n)=>n!==t)),f.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),z(d,M(P,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=Em();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=Dm();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),y(()=>t.value=(e().args??[]).join(` `)),t})()]}}),null),m.addEventListener(`change`,e=>{let n=e.currentTarget.value;if(k(e=>({...e,[t]:n})),n===`none`)r({headers:void 0});else if(n===`bearer`){let e=ie()[t]??``;r({headers:e?{Authorization:`Bearer ${e}`}:void 0})}else if(n===`header`){let e=oe()[t]??``,n=ie()[t]??``;r({headers:e&&n?{[e]:n}:void 0})}}),z(m,M(P,{get when(){return fe(String(e().name??``))},children:e=>(()=>{var t=Lm();return z(t,()=>e().authorized?`OAuth — authorized`:`OAuth — authorization needed`),t})()}),h),z(p,M(P,{get when(){return O()[t]===`bearer`},get children(){var e=Om();return e.$$input=e=>{let n=e.currentTarget.value;ae(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},y(()=>e.value=ie()[t]??``),e}}),null),z(p,M(P,{get when(){return O()[t]===`header`},get children(){return[(()=>{var e=km();return e.$$input=e=>{let n=e.currentTarget.value;se(e=>({...e,[t]:n}));let i=ie()[t]??``;r({headers:n&&i?{[n]:i}:void 0})},y(()=>e.value=oe()[t]??``),e})(),(()=>{var e=Am();return e.$$input=e=>{let n=e.currentTarget.value;ae(e=>({...e,[t]:n}));let i=oe()[t]??``;r({headers:i&&n?{[i]:n}:void 0})},y(()=>e.value=ie()[t]??``),e})()]}}),null),z(i,M(P,{get when(){return O()[t]===`json`},get children(){var e=jm(),n=e.firstChild;return n.$$input=e=>{let n=e.currentTarget.value;if(D(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}),re(e=>({...e,[t]:``}))}catch{re(e=>({...e,[t]:`must be a JSON object — not applied`}))}},y(()=>n.value=te()[t]??``),e}}),g),_.$$click=async()=>{let e=T()[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 $(`/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 me(e.name)},z(g,M(P,{get when(){return F(()=>!!ue()[String(e().name??``).trim()]?.required)()&&!ue()[String(e().name??``).trim()]?.authorized},get children(){var n=Mm();return n.$$click=()=>void he(t,e()),n}}),null),z(g,M(P,{get when(){return ue()[String(e().name??``).trim()]?.authorized},get children(){return[Nm(),(()=>{var n=Pm();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await me(e().name),A(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),z(g,M(P,{get when(){return n()},get children(){var e=Od();return z(e,(()=>{var e=F(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:F(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&R(e,t.e=r),i!==t.t&&L(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),z(i,M(P,{get when(){return ne()[t]},get children(){var e=Fm();return z(e,()=>ne()[t]),e}}),null),z(i,M(P,{get when(){return ce()[t]},children:e=>(()=>{var t=Bm(),n=t.firstChild,r=n.firstChild;return z(r,()=>e().text),z(n,M(P,{get when(){return e().needsOAuth},get children(){return Rm()}}),null),z(t,M(P,{get when(){return(e().tools?.length??0)>0},get children(){var t=zm();return z(t,M(N,{get each(){return e().tools??[]},children:e=>(()=>{var t=Hm(),n=t.firstChild;return z(n,()=>e.name),z(t,M(P,{get when(){return e.description},get children(){var t=Vm();return z(t,()=>e.description),t}}),null),y(()=>L(t,`title`,e.description??``)),t})()})),t}}),null),y(()=>R(t,`mcpresult `+(e().kind===`err`?`err`:`ok`))),t})()}),null),y(()=>o.value=e().name),y(()=>s.value=e().url??``),y(()=>l.checked=e().enabled!==!1),y(()=>f.value=e().transport??`http`),y(()=>m.value=fe(String(e().name??``))?`oauth`:O()[t]??`none`),i})()}})}}),Qe),Qe.$$click=()=>E([...T(),{name:``,url:``,transport:`http`,enabled:!0}]),z($e,M(P,{get when(){return C().length>0},get children(){return M(ye,{get each(){return C()},children:(e,t)=>(()=>{var n=Um(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>w(C().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>w(C().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>w(C().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>w(C().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>w(C().filter((e,n)=>n!==t)),u.$$input=e=>w(C().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e().id),y(()=>a.value=e().agent),y(()=>o.value=e().schedule),y(()=>c.checked=!!e().forked),y(()=>u.value=e().prompt),n})()})}}),et),et.$$click=()=>w([...C(),{id:``,agent:De()[0]??``,schedule:`every 30m`,prompt:``}]),z(tt,M(P,{get when(){return Te().length>0},get fallback(){return Wm()},get children(){return M(N,{get each(){return Te()},children:t=>(()=>{var n=Gm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return z(i,()=>t.id),z(a,()=>t.sessions,o),z(a,()=>t.sessions===1?``:`s`,null),z(a,(()=>{var e=F(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),z(a,(()=>{var e=F(()=>!!t.archivedAt);return()=>e()?` · archived ${Dh(new Date(t.archivedAt).toISOString())}`:``})(),null),z(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await we(),e.onSaved();let r=(n?.ids?.length??1)-1;Q((n?.live===!1?`restored ${t.id} — it could not be started (check its provider)`:`restored ${t.id}`)+(r>0?` + ${r} sub-agent${r===1?``:`s`}`:``))},l.$$click=async()=>{confirm(`PERMANENTLY DELETE ${t.id}?\n\n${t.sessions} session${t.sessions===1?``:`s`} of history will be erased from disk along with the config entry. This cannot be undone — archiving was the reversible option.`)&&(await $(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await we(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>L(s,`title`,t.workspace)),n})()})}}),null),z(nt,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=qm(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=Km();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(it,()=>e.cfg.version??`unknown`,null),at.$$click=async e=>{try{_e(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await $(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=!1;for(let e=0;e<90&&!r;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await $(`/api/version`);e.version&&e.version!==`0.36.2`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){_e(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},z(ct,(()=>{var t=F(()=>!!e.features);return()=>t()?F(()=>!!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…`})()),z(lt,(()=>{var t=F(()=>!!e.features);return()=>t()?F(()=>!!e.features.pty.available)()?`on — ${e.features.pty.provider}`:`off — no pty provider; terminals run on plain pipes (no resize)`:`checking…`})()),z(ot,M(P,{get when(){return e.skills.length>0},get fallback(){return(()=>{var t=Jm();return z(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=mm();return z(t,M(N,{get each(){return e.skills},children:t=>{let[n,r]=v(!1),[i,a]=v(null),[o,s]=v(``),c=async()=>{if(n())return r(!1);if(r(!0),i()===null&&e.agentId)try{let n=await $(`/api/agents/${e.agentId}/skills/${encodeURIComponent(t.name)}`);a(String(n.text??``))}catch(e){s(e.message)}};return(()=>{var e=Xm(),r=e.firstChild,a=r.firstChild,s=a.nextSibling,l=s.nextSibling;return r.$$click=c,z(a,()=>n()?`▾`:`▸`),z(s,()=>t.name),z(l,()=>t.description),z(e,M(P,{get when(){return n()},get children(){return M(P,{get when(){return i()!==null},get fallback(){return(()=>{var e=Zm();return z(e,()=>o()||`loading…`),e})()},get children(){var e=Ym();return y(()=>e.innerHTML=$m(String(i()??``))),e}})}}),null),y(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),z(dt,M(P,{get when(){return ge()},get children(){var e=Dp();return z(e,ge),e}}),ft),z(ft,(()=>{var e=F(()=>Ve()===`saving`);return()=>e()?`saving…`:F(()=>Ve()===`saved`)()?`✓ saved`:Ve()===`error`?`✕ failed`:`save settings`})()),y(e=>{var t=ve()!==`providers`,n=ve()!==`appearance`,r=ve()!==`runtime`,i=ve()!==`mcp`,a=ve()!==`tasks`,o=ve()!==`archive`,s=ve()!==`agents`,c=ve()!==`update`,l=ve()!==`skills`,u=ve()!==`help`,d=Ve()===`saved`,f=Ve()===`error`,p=Ve()===`saving`;return t!==e.e&&de.classList.toggle(`hide`,e.e=t),n!==e.t&&Be.classList.toggle(`hide`,e.t=n),r!==e.a&&Ke.classList.toggle(`hide`,e.a=r),i!==e.o&&Ze.classList.toggle(`hide`,e.o=i),a!==e.i&&$e.classList.toggle(`hide`,e.i=a),o!==e.n&&tt.classList.toggle(`hide`,e.n=o),s!==e.s&&nt.classList.toggle(`hide`,e.s=s),c!==e.h&&rt.classList.toggle(`hide`,e.h=c),l!==e.r&&ot.classList.toggle(`hide`,e.r=l),u!==e.d&&ut.classList.toggle(`hide`,e.d=u),d!==e.l&&ft.classList.toggle(`saved`,e.l=d),f!==e.u&&ft.classList.toggle(`error`,e.u=f),p!==e.c&&(ft.disabled=e.c=p),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0,c:void 0}),y(()=>Ce.value=i()),y(()=>Ue.checked=Me()),y(()=>Ye.value=p()??``),y(()=>Xe.checked=S()),t}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(_h,{}),document.getElementById(`root`));export{xu as t};
31
- //# sourceMappingURL=index-B1hbtMwZ.js.map
30
+ Cancel = keep editing your copy`)?(le(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{ue(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=qp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Rh(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Kp();return z(t,()=>Oh(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(w)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await re(e,T())})));for(let{p:e,rows:n}of t)n&&O(e,n)}finally{be(!1)}}};return[(()=>{var e=Jp(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(jh,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(jh,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),z(e,M(jh,{class:`filetoggle`,get icon(){return T()?`◉.`:`○.`},get title(){return T()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:te}),null),e})(),(()=>{var e=Yp();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=Xp();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(w)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(Nh,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=tm(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=$p();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=em();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return rm()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(Kh,{get path(){return t().path},get content(){return t().content},get html(){return ae()},get pending(){return se()},get truncated(){return!!t().truncated}})},get children(){var e=im();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=nm(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>Oh(A().length),i),a.$$click=()=>void he(),z(a,()=>j()?`saving…`:`💾 save`),y(()=>a.disabled=j()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=Qp(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=om();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=am();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Zp();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function Kh(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=lm(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=um();return z(t,()=>e.content),t})()},get children(){var t=sm();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return cm()}})]}var qh=[{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 Jh(e){return(()=>{var t=dm(),n=t.firstChild;return z(t,()=>e.label,n),n.$$input=t=>e.onValue(Number(t.currentTarget.value)),y(()=>L(t,`title`,e.hint)),y(()=>n.value=e.value),t})()}function Yh(e){let t=(e,t)=>{let n=Array.isArray(t?.apiKeys)&&t.apiKeys.length?t.apiKeys.filter(e=>typeof e==`string`&&e.trim()):t?.apiKey?[String(t.apiKey)]:[``];return{name:e,baseUrl:t?.baseUrl??``,apiKeys:n.length?n:[``],model:t?.model??``}},[n,r]=v(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=v(e.cfg.defaultProvider??``),o=()=>e.cfg.defaultProvider??``,s=()=>{let e=[...new Set(n().map(e=>e.name.trim()).filter(Boolean))],t=i();return t&&!e.includes(t)&&e.push(t),e},c=()=>{let e=i();return e?n().some(t=>t.name.trim()===e)?``:e:``},[l,u]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=v(e.cfg.progressMinChars??4e3),[p,m]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,x]=v(e.cfg.maxSpawnDepth??3),[S,ee]=v(!!e.cfg.shortContext),[C,w]=v((e.cfg.tasks??[]).map(e=>({...e}))),[T,E]=v((e.cfg.mcpServers??[]).map(e=>({...e}))),[te,D]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ne,re]=v({}),[O,k]=v(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`]}))),[ie,ae]=v(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]??``]}))),[oe,se]=v(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:``]}))),[ce,A]=v({}),[le,j]=v({}),[ue,de]=v({}),fe=e=>{let t=String(e??``).trim();if(!t)return null;let n=ue()[t];return n&&(n.required||n.authorized)?n:null},pe=async()=>{let e=await $(`/api/mcp`).catch(()=>null);j(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},me=async e=>{let t=String(e??``).trim();if(!t)return;let n=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&de(e=>({...e,[t]:n}))},he=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 $(`/api/mcp/oauth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name})}).catch(()=>null);if(r?.alreadyAuthorized){A(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await me(n.name),await pe();return}if(!r?.ok||!r.url){A(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await me(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 $(`/api/mcp/oauth/status?name=${encodeURIComponent(n.name)}`).catch(()=>null);if(r&&!r.error){if(de(e=>({...e,[t]:r})),r.authorized){A(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await pe(),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`}}))};b(()=>{ve()===`mcp`&&(pe(),T().forEach((e,t)=>{e.name&&me(e.name)}))});let[ge,_e]=v(``),[ve,be]=v(`providers`),xe=(t,n)=>{let{slot:r}=_t(e.theme.auto(),n);r===`dark`?e.theme.setDark(t):r===`light`?e.theme.setLight(t):e.theme.setActive(t)},Se=t=>vt({auto:e.theme.auto(),fixed:e.theme.activeId(),dark:e.theme.dark(),light:e.theme.light(),prefersLight:typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-color-scheme: light)`).matches})===t,[I,Ce]=v([]),we=async()=>{let e=await $(`/api/archived`).catch(()=>null);Ce(e?.agents??[])},Te=()=>I().filter(e=>!e.parent);b(()=>{ve()===`archive`&&we()});let Ee=[{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`}],De=()=>(e.cfg.agents??[]).map(e=>e.id),Oe=()=>e.theme.themes(),ke=()=>e.theme.activeId(),Ae=()=>{let t=e.theme.activeId();return e.theme.themes().find(e=>e.id===t)?.mode??ch.find(e=>e.key===t)?.mode??`dark`},je=t=>e.theme.setActive(t),Me=()=>e.theme.auto(),Ne=t=>e.theme.setAuto(t),Pe=()=>e.theme.dark(),Fe=t=>e.theme.setDark(t),Ie=()=>e.theme.light(),Le=t=>e.theme.setLight(t),Re=t=>e.theme.setThemes(t),ze=e=>cn[e]??sn,Be=()=>{let e={};for(let t of n()){if(!t.name.trim())return _e(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return _e(`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},[Ve,He]=v(`idle`),Ue=e=>{_e(e),He(e=>e===`saving`?`idle`:e)},We=async t=>{t.preventDefault(),_e(``),He(`saving`);let n=Be();if(!n)return He(`idle`);let r=C().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of r){if(!e.agent)return Ue(`task "${e.id}": agent is required`);if(!e.schedule?.trim())return Ue(`task "${e.id}": schedule is required`)}let a=[],o=new Set;for(let e of T()){let t=String(e.name??``).trim(),n=String(e.url??``).trim(),r=e.transport??`http`,i=String(e.command??``).trim();if(t||n||i){if(!t)return Ue(`MCP: a server needs a name`);if(o.has(t))return Ue(`MCP: two servers are named "${t}"`);if(o.add(t),r===`stdio`?!i:!n)return Ue(`MCP "${t}": ${r===`stdio`?`a command is`:`a url is`} required`);a.push({name:t,transport:r,enabled:e.enabled!==!1,...n?{url:n}:{},...r===`stdio`?{command:i,...e.args?.length?{args:e.args}:{}}:{},...e.headers&&Object.keys(e.headers).length?{headers:e.headers}:{}})}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:i()||void 0,progressIntervalMs:Math.max(1,l())*6e4,progressMinChars:Math.max(100,d()),...p()==null?{}:{contextTokenBudget:Math.max(1,p())*1e3},...h()>0?{contextWindowTokens:h()*1e3}:{},maxSpawnDepth:Math.max(0,_()),shortContext:S(),tasks:r,mcpServers:a})}),await pe(),await Promise.all(a.map((e,t)=>e.name?me(e.name):Promise.resolve())),setTimeout(()=>{pe(),a.forEach((e,t)=>{e.name&&me(e.name)})},1200),e.onSaved();let t=new Set(a.map(e=>e.name).filter(Boolean)),o=T().filter(e=>{let n=String(e.name??``).trim();return t.has(n)&&ue()[n]?.required&&!ue()[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??``));Q(`${o.map(e=>String(e.name??``).trim()).filter(Boolean).join(`, `)||`a saved MCP server`} needs authorization — 🔑 authorize in MCP servers`)}He(`saved`),setTimeout(()=>{He(`idle`),e.onClose()},400)}catch(e){_e(e.message),He(`error`),setTimeout(()=>He(`idle`),1600)}};return M(Nh,{title:`settings`,get onClose(){return e.onClose},get children(){var t=hm(),b=t.firstChild,j=b.firstChild,de=j.nextSibling.firstChild,pe=de.firstChild.nextSibling,I=pe.nextSibling;I.firstChild;var Ce=I.nextSibling.firstChild.firstChild.nextSibling;Ce.firstChild;var Be=de.nextSibling,He=Be.firstChild.nextSibling,Ue=He.firstChild.firstChild.nextSibling,Ge=He.nextSibling,Ke=Be.nextSibling,qe=Ke.firstChild.nextSibling,Je=qe.firstChild,Ye=Je.firstChild.nextSibling,Xe=qe.nextSibling.firstChild,Ze=Ke.nextSibling,Qe=Ze.firstChild.nextSibling.nextSibling,$e=Ze.nextSibling,et=$e.firstChild.nextSibling,tt=$e.nextSibling;tt.firstChild;var nt=tt.nextSibling;nt.firstChild;var rt=nt.nextSibling,it=rt.firstChild.nextSibling.firstChild;it.firstChild;var at=it.nextSibling,ot=rt.nextSibling,st=ot.firstChild.nextSibling.firstChild,ct=st.firstChild.nextSibling,lt=st.nextSibling.firstChild.nextSibling,ut=ot.nextSibling,dt=b.nextSibling,ft=dt.firstChild;return t.addEventListener(`submit`,We),z(j,M(N,{each:Ee,children:e=>(()=>{var t=gm(),n=t.firstChild;return t.$$click=()=>be(e.key),z(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(ve()===e.key?` on`:``),i=e.hint,a=ve()===e.key?`page`:void 0;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),z(de,M(ye,{get each(){return n()},children:(e,t)=>(()=>{var i=_m(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.firstChild;return a.$$input=e=>r(n().map((n,r)=>r===t?{...n,name:e.currentTarget.value}:n)),o.$$input=e=>r(n().map((n,r)=>r===t?{...n,baseUrl:e.currentTarget.value}:n)),s.$$input=e=>r(n().map((n,r)=>r===t?{...n,model:e.currentTarget.value}:n)),c.$$click=()=>r(n().filter((e,n)=>n!==t)),z(l,M(N,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=ym(),s=o.firstChild;return s.$$input=e=>r(n().map((n,r)=>r===t?{...n,apiKeys:n.apiKeys.map((t,n)=>n===a()?e.currentTarget.value:t)}:n)),s.value=i,z(o,M(P,{get when(){return e().apiKeys.length>1},get children(){var e=vm();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>L(s,`placeholder`,a()===0?`api key`:`api key (backup)`)),o})()}),u),u.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:[...e.apiKeys,``]}:e)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().model),i})()}),pe),pe.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),z(I,M(N,{each:qh,children:e=>(()=>{var t=bm();return t.firstChild,t.$$click=()=>{let t=n().filter(t=>t.name!==e.key);r([...t,{name:e.key,baseUrl:e.url,apiKeys:[``],model:e.model}]),i()||a(e.key)},z(t,()=>e.label,null),y(()=>L(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),Ce.addEventListener(`change`,e=>a(e.currentTarget.value)),z(Ce,M(N,{get each(){return s()},children:e=>(()=>{var t=qd();return t.value=e,z(t,e),t})()}),null),z(de,M(P,{get when(){return c()},get children(){var e=fm(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,c),z(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,c),e}}),null),Ue.addEventListener(`change`,e=>{Ne(e.currentTarget.checked),localStorage.setItem(`teapot.theme.auto`,e.currentTarget.checked?`1`:`0`)}),z(Be,M(P,{get when(){return Me()},get children(){var e=pm(),t=e.firstChild,n=t.firstChild.nextSibling,r=t.nextSibling.firstChild.nextSibling;return n.addEventListener(`change`,e=>{Fe(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),z(n,M(N,{get each(){return Oe().filter(e=>e.mode===`dark`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(ch.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=qd();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),r.addEventListener(`change`,e=>{Le(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(r,M(N,{get each(){return Oe().filter(e=>e.mode===`light`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(ch.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=qd();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>n.value=Pe()),y(()=>r.value=Ie()),e}}),Ge),z(Be,M(N,{each:[{mode:`dark`,title:`dark themes`},{mode:`light`,title:`light themes`}],children:e=>M(P,{get when(){return F(()=>!![...Oe(),...ch].some(t=>t.mode===e.mode))()&&(Me()||Ae()===e.mode)},get children(){return[(()=>{var t=xm();return z(t,()=>e.title),t})(),(()=>{var t=Sm();return z(t,M(N,{get each(){return Oe().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=Cm(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>xe(e.id,e.mode),z(n,M(Hh,{get palette(){return e.palette},get backgroundImage(){return e.backgroundImage}})),z(r,()=>e.label,i),y(n=>{var r=`themecard`+(Se(e.id)?` on`:``),i=`${e.label} (custom)${e.backgroundImage?` · with a background image`:``}`,a=Se(e.id);return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),z(t,M(N,{get each(){return ch.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=wm(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>xe(e.key,e.mode),z(n,M(Hh,{get palette(){return ze(e.key)}})),z(r,()=>e.label),y(n=>{var r=`themecard`+(Se(e.key)?` on`:``),i=`${e.label} (${e.mode})`,a=Se(e.key);return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),t})()]}})}),null),z(Be,M(Uh,{themes:Oe,get activeId(){return ke()},get paintedId(){return e.theme.paintedId()},onChange:e=>{let t=fn(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=fn(t);if(r.ok)n=t,Q(`storage was full — saved without the background image(s)`);else{Q(r.error??`could not save theme`);return}}Re(n);let r=e=>n.some(t=>t.id===e)||ch.some(t=>t.key===e);r(ke())||(je(`dark`),localStorage.setItem(`teapot.theme`,`dark`)),r(Pe())||(Fe(`dark`),localStorage.setItem(`teapot.theme.dark`,`dark`)),r(Ie())||(Le(`light`),localStorage.setItem(`teapot.theme.light`,`light`))},onPick:e=>{let t=Oe().find(t=>t.id===e)?.mode??ch.find(t=>t.key===e)?.mode??`dark`,n=_t(Me(),t);n.slot===`dark`?Fe(e):n.slot===`light`?Le(e):je(e),localStorage.setItem(n.key,e)}}),null),z(qe,M(Jh,{label:`progress interval (min)`,get value(){return l()},onValue:e=>u(e),hint:`how often the harness asks for a progress report`}),Je),z(qe,M(Jh,{label:`progress min chars`,get value(){return d()},onValue:e=>f(e),hint:`progress prompts wait for this much real output`}),Je),Ye.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),z(qe,M(Jh,{label:`context window (k tok)`,get value(){return h()},onValue:e=>g(e),hint:`model's real window — 0/blank hides the % gauge`}),null),z(qe,M(Jh,{label:`max spawn depth`,get value(){return _()},onValue:e=>x(e),hint:`sub-agent nesting limit (0 = no spawning)`}),null),Xe.addEventListener(`change`,e=>ee(e.currentTarget.checked)),z(Ze,M(P,{get when(){return T().length>0},get fallback(){return Tm()},get children(){return M(ye,{get each(){return T()},children:(e,t)=>{let n=()=>le()[e().name],r=e=>E(T().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=Im(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.nextSibling,l=c.firstChild,u=c.nextSibling,d=a.nextSibling,f=d.firstChild,p=d.nextSibling,m=p.firstChild,h=m.firstChild,g=p.nextSibling,_=g.firstChild;return o.$$input=e=>r({name:e.currentTarget.value}),s.$$input=e=>r({url:e.currentTarget.value}),l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>E(T().filter((e,n)=>n!==t)),f.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),z(d,M(P,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=Em();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=Dm();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),y(()=>t.value=(e().args??[]).join(` `)),t})()]}}),null),m.addEventListener(`change`,e=>{let n=e.currentTarget.value;if(k(e=>({...e,[t]:n})),n===`none`)r({headers:void 0});else if(n===`bearer`){let e=ie()[t]??``;r({headers:e?{Authorization:`Bearer ${e}`}:void 0})}else if(n===`header`){let e=oe()[t]??``,n=ie()[t]??``;r({headers:e&&n?{[e]:n}:void 0})}}),z(m,M(P,{get when(){return fe(String(e().name??``))},children:e=>(()=>{var t=Lm();return z(t,()=>e().authorized?`OAuth — authorized`:`OAuth — authorization needed`),t})()}),h),z(p,M(P,{get when(){return O()[t]===`bearer`},get children(){var e=Om();return e.$$input=e=>{let n=e.currentTarget.value;ae(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},y(()=>e.value=ie()[t]??``),e}}),null),z(p,M(P,{get when(){return O()[t]===`header`},get children(){return[(()=>{var e=km();return e.$$input=e=>{let n=e.currentTarget.value;se(e=>({...e,[t]:n}));let i=ie()[t]??``;r({headers:n&&i?{[n]:i}:void 0})},y(()=>e.value=oe()[t]??``),e})(),(()=>{var e=Am();return e.$$input=e=>{let n=e.currentTarget.value;ae(e=>({...e,[t]:n}));let i=oe()[t]??``;r({headers:i&&n?{[i]:n}:void 0})},y(()=>e.value=ie()[t]??``),e})()]}}),null),z(i,M(P,{get when(){return O()[t]===`json`},get children(){var e=jm(),n=e.firstChild;return n.$$input=e=>{let n=e.currentTarget.value;if(D(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}),re(e=>({...e,[t]:``}))}catch{re(e=>({...e,[t]:`must be a JSON object — not applied`}))}},y(()=>n.value=te()[t]??``),e}}),g),_.$$click=async()=>{let e=T()[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 $(`/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 me(e.name)},z(g,M(P,{get when(){return F(()=>!!ue()[String(e().name??``).trim()]?.required)()&&!ue()[String(e().name??``).trim()]?.authorized},get children(){var n=Mm();return n.$$click=()=>void he(t,e()),n}}),null),z(g,M(P,{get when(){return ue()[String(e().name??``).trim()]?.authorized},get children(){return[Nm(),(()=>{var n=Pm();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await me(e().name),A(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),z(g,M(P,{get when(){return n()},get children(){var e=Od();return z(e,(()=>{var e=F(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:F(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&R(e,t.e=r),i!==t.t&&L(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),z(i,M(P,{get when(){return ne()[t]},get children(){var e=Fm();return z(e,()=>ne()[t]),e}}),null),z(i,M(P,{get when(){return ce()[t]},children:e=>(()=>{var t=Bm(),n=t.firstChild,r=n.firstChild;return z(r,()=>e().text),z(n,M(P,{get when(){return e().needsOAuth},get children(){return Rm()}}),null),z(t,M(P,{get when(){return(e().tools?.length??0)>0},get children(){var t=zm();return z(t,M(N,{get each(){return e().tools??[]},children:e=>(()=>{var t=Hm(),n=t.firstChild;return z(n,()=>e.name),z(t,M(P,{get when(){return e.description},get children(){var t=Vm();return z(t,()=>e.description),t}}),null),y(()=>L(t,`title`,e.description??``)),t})()})),t}}),null),y(()=>R(t,`mcpresult `+(e().kind===`err`?`err`:`ok`))),t})()}),null),y(()=>o.value=e().name),y(()=>s.value=e().url??``),y(()=>l.checked=e().enabled!==!1),y(()=>f.value=e().transport??`http`),y(()=>m.value=fe(String(e().name??``))?`oauth`:O()[t]??`none`),i})()}})}}),Qe),Qe.$$click=()=>E([...T(),{name:``,url:``,transport:`http`,enabled:!0}]),z($e,M(P,{get when(){return C().length>0},get children(){return M(ye,{get each(){return C()},children:(e,t)=>(()=>{var n=Um(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>w(C().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>w(C().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>w(C().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>w(C().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>w(C().filter((e,n)=>n!==t)),u.$$input=e=>w(C().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e().id),y(()=>a.value=e().agent),y(()=>o.value=e().schedule),y(()=>c.checked=!!e().forked),y(()=>u.value=e().prompt),n})()})}}),et),et.$$click=()=>w([...C(),{id:``,agent:De()[0]??``,schedule:`every 30m`,prompt:``}]),z(tt,M(P,{get when(){return Te().length>0},get fallback(){return Wm()},get children(){return M(N,{get each(){return Te()},children:t=>(()=>{var n=Gm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return z(i,()=>t.id),z(a,()=>t.sessions,o),z(a,()=>t.sessions===1?``:`s`,null),z(a,(()=>{var e=F(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),z(a,(()=>{var e=F(()=>!!t.archivedAt);return()=>e()?` · archived ${Dh(new Date(t.archivedAt).toISOString())}`:``})(),null),z(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await we(),e.onSaved();let r=(n?.ids?.length??1)-1;Q((n?.live===!1?`restored ${t.id} — it could not be started (check its provider)`:`restored ${t.id}`)+(r>0?` + ${r} sub-agent${r===1?``:`s`}`:``))},l.$$click=async()=>{confirm(`PERMANENTLY DELETE ${t.id}?\n\n${t.sessions} session${t.sessions===1?``:`s`} of history will be erased from disk along with the config entry. This cannot be undone — archiving was the reversible option.`)&&(await $(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await we(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>L(s,`title`,t.workspace)),n})()})}}),null),z(nt,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=qm(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=Km();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(it,()=>e.cfg.version??`unknown`,null),at.$$click=async e=>{try{_e(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await $(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=!1;for(let e=0;e<90&&!r;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await $(`/api/version`);e.version&&e.version!==`0.36.3`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){_e(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},z(ct,(()=>{var t=F(()=>!!e.features);return()=>t()?F(()=>!!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…`})()),z(lt,(()=>{var t=F(()=>!!e.features);return()=>t()?F(()=>!!e.features.pty.available)()?`on — ${e.features.pty.provider}`:`off — no pty provider; terminals run on plain pipes (no resize)`:`checking…`})()),z(ot,M(P,{get when(){return e.skills.length>0},get fallback(){return(()=>{var t=Jm();return z(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=mm();return z(t,M(N,{get each(){return e.skills},children:t=>{let[n,r]=v(!1),[i,a]=v(null),[o,s]=v(``),c=async()=>{if(n())return r(!1);if(r(!0),i()===null&&e.agentId)try{let n=await $(`/api/agents/${e.agentId}/skills/${encodeURIComponent(t.name)}`);a(String(n.text??``))}catch(e){s(e.message)}};return(()=>{var e=Xm(),r=e.firstChild,a=r.firstChild,s=a.nextSibling,l=s.nextSibling;return r.$$click=c,z(a,()=>n()?`▾`:`▸`),z(s,()=>t.name),z(l,()=>t.description),z(e,M(P,{get when(){return n()},get children(){return M(P,{get when(){return i()!==null},get fallback(){return(()=>{var e=Zm();return z(e,()=>o()||`loading…`),e})()},get children(){var e=Ym();return y(()=>e.innerHTML=$m(String(i()??``))),e}})}}),null),y(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),z(dt,M(P,{get when(){return ge()},get children(){var e=Dp();return z(e,ge),e}}),ft),z(ft,(()=>{var e=F(()=>Ve()===`saving`);return()=>e()?`saving…`:F(()=>Ve()===`saved`)()?`✓ saved`:Ve()===`error`?`✕ failed`:`save settings`})()),y(e=>{var t=ve()!==`providers`,n=ve()!==`appearance`,r=ve()!==`runtime`,i=ve()!==`mcp`,a=ve()!==`tasks`,o=ve()!==`archive`,s=ve()!==`agents`,c=ve()!==`update`,l=ve()!==`skills`,u=ve()!==`help`,d=Ve()===`saved`,f=Ve()===`error`,p=Ve()===`saving`;return t!==e.e&&de.classList.toggle(`hide`,e.e=t),n!==e.t&&Be.classList.toggle(`hide`,e.t=n),r!==e.a&&Ke.classList.toggle(`hide`,e.a=r),i!==e.o&&Ze.classList.toggle(`hide`,e.o=i),a!==e.i&&$e.classList.toggle(`hide`,e.i=a),o!==e.n&&tt.classList.toggle(`hide`,e.n=o),s!==e.s&&nt.classList.toggle(`hide`,e.s=s),c!==e.h&&rt.classList.toggle(`hide`,e.h=c),l!==e.r&&ot.classList.toggle(`hide`,e.r=l),u!==e.d&&ut.classList.toggle(`hide`,e.d=u),d!==e.l&&ft.classList.toggle(`saved`,e.l=d),f!==e.u&&ft.classList.toggle(`error`,e.u=f),p!==e.c&&(ft.disabled=e.c=p),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0,c:void 0}),y(()=>Ce.value=i()),y(()=>Ue.checked=Me()),y(()=>Ye.value=p()??``),y(()=>Xe.checked=S()),t}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(_h,{}),document.getElementById(`root`));export{xu as t};
31
+ //# sourceMappingURL=index-eI8D6ykk.js.map