teapot-coding-agent 0.26.4 → 0.26.5

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.
@@ -536,6 +536,43 @@ export class Agent {
536
536
  async load() {
537
537
  await this.ensureReady();
538
538
  }
539
+ /**
540
+ * Answer tool_calls in a RESTORED history that have no tool_result (#54).
541
+ *
542
+ * The ordinary backstop (`answerUnansweredToolCalls`) works on an assistant
543
+ * turn inside a live loop. After a restart there is no loop: the call is in
544
+ * the log, the process that was running it is gone, and nothing else will ever
545
+ * write its result.
546
+ */
547
+ async answerUnansweredRestoredCalls() {
548
+ const seen = new Set();
549
+ for (const ev of await readEvents(this.log.filePath)) {
550
+ const d = (ev.data ?? {});
551
+ const id = d.callId ? String(d.callId) : null;
552
+ if (!id)
553
+ continue;
554
+ if (ev.type === "tool_call")
555
+ seen.add(id);
556
+ else if (ev.type === "tool_result")
557
+ seen.delete(id);
558
+ }
559
+ for (const id of seen) {
560
+ await this.log.append("tool_result", this.currentSession, this.currentBranch, {
561
+ callId: id,
562
+ name: "unknown",
563
+ ok: false,
564
+ durationMs: 0,
565
+ result: "not completed — the agent restarted while this tool was running",
566
+ synthesized: true,
567
+ });
568
+ }
569
+ if (seen.size)
570
+ await this.log.append("system_note", this.currentSession, this.currentBranch, {
571
+ event: "unfinished-tools-closed",
572
+ count: seen.size,
573
+ detail: "a restart left these tool calls without a result; they are marked not completed (#54)",
574
+ });
575
+ }
539
576
  /** harness-managed files inside the session directory */
540
577
  get goalFile() {
541
578
  return path.join(this.opts.sessionDir, "goal.md");
@@ -705,6 +742,24 @@ export class Agent {
705
742
  // seen and acted on that output, and the pruned form keeps the head plus
706
743
  // a marker, exactly as it did live.
707
744
  this.maybePrune();
745
+ // #54: answer tool_calls the log says are still open.
746
+ //
747
+ // The restore path rebuilds `msgs` straight from the log, so a call whose
748
+ // process died mid-command comes back as an assistant turn with
749
+ // `tool_calls` and NO matching `tool_result`. Nothing ever answers it —
750
+ // not `stop()` (there is no turn to stop) and not `dispose()` (the process
751
+ // is already gone). The row then renders as still running for good.
752
+ //
753
+ // Measured across every session log: 43,483 tool_calls, and 4 unanswered —
754
+ // every one a `bash`, each followed immediately by
755
+ // `session-restored` / `idle->stopped disposed`. The shape is a restart
756
+ // (or a crash) landing while a long command was in flight, which is
757
+ // precisely when a human is most likely to notice "it never finished".
758
+ //
759
+ // So close them ON RESTORE, before the restored history is used. This is
760
+ // the same backstop as the mid-turn paths, reached from the one place
761
+ // those could not: after the process is gone.
762
+ await this.answerUnansweredRestoredCalls();
708
763
  await this.log.append("system_note", this.currentSession, this.currentBranch, {
709
764
  event: "session-restored",
710
765
  branch: last.branch,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teapot-coding-agent",
3
- "version": "0.26.4",
3
+ "version": "0.26.5",
4
4
  "description": "A lightweight, always-on multi-agent harness for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",
@@ -21,10 +21,10 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
21
21
  - task two"title="shared with the agent \\u2014 it may check items off via set_todo; your unsaved edits win until you save"style="width:100%;background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font-family:ui-monospace,Menlo,monospace;font-size:12.5px;resize:vertical">`),Ef=F(`<div class="content mdpreview"style="max-height:40vh;padding:8px 10px">`),Df=F(`<span class=fsize>`),Of=F(`<div><span class=ficon></span><span class=fname>`),kf=F(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview"style=display:flex;align-items:center;gap:6px>🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),Af=F(`<div class=filebox>`),jf=F(`<div class=muted style=padding:6px>`),Mf=F(`<img>`),Nf=F(`<div class=mediapreview><div class="meta muted"> preview`),Pf=F(`<button title="rendered markdown">👁 preview`),Ff=F(`<button title="edit and save back to the workspace">✎ edit`),If=F(`<div class=filetoolbar><button title="syntax-highlighted source">&lt;/> code`),Lf=F(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Rf=F(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),zf=F(`<div class="content mdpreview">`),Bf=F(`<video controls>`),Vf=F(`<audio controls>`),Hf=F(`<div class=filepreview>`),Uf=F(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),Wf=F(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),Gf=F(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),Kf=F(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),qf=F(`<span style=color:var(--fg)>`),Jf=F(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),Yf=F(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>default model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),Xf=F(`<button type=button>`),Zf=F(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),Qf=F(`<label><input type=number min=0>`),$f=F(`<div class=muted style=font-size:11.5px;margin-top:4px>⚠ configured default provider <code></code> has no provider row here<!> Add a provider named <code></code> or pick a default below; otherwise agents fall back to the first provider.`),ep=F(`<form style=display:flex;flex-direction:column;gap:14px><fieldset><legend>providers</legend><button type=button>+ add custom</button><div style=display:flex;gap:6px;flex-wrap:wrap;margin-top:6px><span class=muted style=font-size:11.5px>quick-add:</span></div><div><label title="agents without an explicit provider use this one"style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<select><option value>(none — first provider wins)</option></select></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid><label title="auto-compact threshold in k tokens. Leave EMPTY to derive per model (75% of its context window) — recommended, since models differ wildly in window size. Set only to force an absolute cap across all models.">compact budget (k tok)<input type=number min=0 placeholder="(derive: 75% of window)"></label></div></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><fieldset><legend>live update</legend><div class=cfgrow><span class=muted>current version: </span><button type=button style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">update & restart</button><span class=muted style=margin-left:8px;font-size:12px>gracefully stops all agents, spawns new process, then reloads this page</span></div></fieldset><button type=submit style="align-self:flex-end;background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">save settings`),tp=F(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="api key"type=password><input placeholder="default model"><button type=button class=danger title="remove provider">✕`),np=F(`<button type=button>+ `),rp=F(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),ip=F(`<span class=muted>🧩 sub of @`),ap=F(`<div class=cfgrow><b></b><span class=muted>`),op=new Map;function sp(e){let t=op.get(e);if(t!==void 0)return t;let n=Ie(e);return op.set(e,n),op.size>500&&op.delete(op.keys().next().value),n}var cp=[`minimal`,`low`,`medium`,`high`],lp=1100,up={prompt:{name:`you`,icon:`🟧`,color:`#faa81a`},user:{name:`you`,icon:`🟧`,color:`#faa81a`},message:{name:`agent`,icon:`🫖`,color:`#5865f2`},progress:{name:`progress`,icon:`📈`,color:`#3ba55d`},question:{name:`agent`,icon:`❓`,color:`#5865f2`}},dp={name:`harness`,icon:`📣`,color:`#3ba55d`},[fp,pp]=v(``),mp,Q=e=>{pp(e),clearTimeout(mp),mp=setTimeout(()=>pp(``),3200)},hp=!1,gp=[{key:`dark`,label:`Dark`,mode:`dark`,sw:[`#1a1c22`,`#2b2e39`,`#5865f2`]},{key:`midnight`,label:`Midnight`,mode:`dark`,sw:[`#0d0f18`,`#252a42`,`#8b7cf7`]},{key:`tea`,label:`Milk Tea`,mode:`dark`,sw:[`#241c16`,`#493b2d`,`#d98e32`]},{key:`coffee`,label:`Coffee`,mode:`dark`,sw:[`#191410`,`#403527`,`#c68a4b`]},{key:`matcha`,label:`Matcha`,mode:`dark`,sw:[`#1b2217`,`#3c4a33`,`#8db64e`]},{key:`matrix`,label:`Matrix`,mode:`dark`,sw:[`#060a06`,`#18301d`,`#2fd558`]},{key:`sunset`,label:`Sunset`,mode:`dark`,sw:[`#1c1422`,`#452f52`,`#f2784b`]},{key:`light`,label:`Light`,mode:`light`,sw:[`#eceef4`,`#ffffff`,`#4757d8`]},{key:`strawberry`,label:`Strawberry`,mode:`light`,sw:[`#fbe4ea`,`#fffafb`,`#e05575`]},{key:`ramune`,label:`Ramune`,mode:`light`,sw:[`#ddeff7`,`#fbfeff`,`#1d86ae`]}];function _p(){let e=``,t=``;try{let n=getComputedStyle(document.documentElement);e=n.getPropertyValue(`--term-bg`).trim(),t=n.getPropertyValue(`--term-fg`).trim()}catch{}return{background:e||`#0d0e12`,foreground:t||`#dcdee4`}}var vp=e=>{if(e.data?.actor)return{name:`@${String(e.data.actor)}`,icon:`🧩`,color:`#3ba0c9`};if(e.type===`tool_call`||e.type===`tool_result`)return{name:String(e.data?.name??`tool`),icon:`⚙`,color:`#3ba0c9`};if(e.type===`prompt`){let t=String(e.data?.source??`user`);return t===`user`?up.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:dp}return up[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},yp=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),bp=new Set([`system_note`]),xp=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=null;try{t=await i.json()}catch{}let n=(t&&typeof t==`object`&&`error`in t?String(t.error):``)||`${e}: HTTP ${i.status}`;throw Object.assign(Error(n),{payload:t})}return i.json()}var Sp=location.hash.match(/[#&]token=([^&]+)/);Sp&&(localStorage.setItem(`teapot.token`,decodeURIComponent(Sp[1])),history.replaceState(null,``,location.pathname+location.search));var Cp=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function wp(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v(``),[o,s]=v(new Map),[c,l]=v(new Map),u=!1;async function d(e=!1){if(!(u&&!e)){u=!0;try{let e=await $(`/api/sessions`),t=new Map,n=new Map;for(let r of e.sessions??[]){t.set(r.id,r.agentId);let e=n.get(r.agentId)??[];e.push(r.id),n.set(r.agentId,e)}s(t),l(n)}catch{}}}let[f,p]=v([]),[m,h]=v(0),[g,_]=v([]),[ee,te]=v(null),T=new Map,[ne,E]=v(T.get(n()??``)??``),D=e=>{E(e);let t=n();t&&(e?T.set(t,e):T.delete(t))},[O,re]=v({providers:{}}),[k,ie]=v(!1),[ae,oe]=v(!1),se=()=>window.innerWidth<=lp,[ce,A]=v(se());C(()=>{let e=()=>A(se());window.addEventListener(`resize`,e),w(()=>window.removeEventListener(`resize`,e)),e()});let[le,ue]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>lp:localStorage.getItem(`teapot.panel`)===`1`),de=e=>{ue(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},fe=()=>de(!le()),pe=()=>{le()&&de(!1)},[me,he]=v(!1),[ge,_e]=v(localStorage.getItem(`teapot.theme`)??`dark`),[ve,ye]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[be,xe]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[Se,Ce]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),F=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[we,ke]=v(F?.matches??!1);C(()=>{let e=e=>ke(e.matches);F?.addEventListener(`change`,e),w(()=>F?.removeEventListener(`change`,e))}),b(()=>{let e=ve()?we()?be():Se():ge();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=gp.find(t=>t.key===e)?.mode??`dark`});let[Ae,je]=v(``),[Me,Ne]=v(``),[Pe,Fe]=v(``);b(()=>{let t=n();Fe(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[Le,Re]=v([]),ze=()=>Object.keys(O().providers??{});async function Be(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);Re(t.models??[])}catch{Re([])}}let Ve=e=>{let t={text:`📄`,image:`🖼️`,audio:`🔊`,video:`🎬`,file:`📎`},n=e=>(e??[`text`]).map(e=>t[e]??e).join(``);return e?.modalities?`${n(e.modalities.input)} → ${n(e.modalities.output)}`:``},Ze=()=>{let e=Me().trim()||V()?.model||``;if(!e)return``;let t=Le().find(t=>t.id===e);if(!t)return``;let n=[],r=Ve(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${Pp(t.contextLength)} tok`);let i=e=>e===void 0?``:`${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=i(t.pricing.prompt),r=i(t.pricing.completion);e&&r?n.push(`${e} in · ${r} out`):(e||r)&&n.push(i(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},$e=null;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||O().defaultProvider||ze()[0]||``;if(r){if(t!==$e)$e=t,S(()=>Ae())!==i&&(je(i),Be(i)),S(()=>Me())&&Ne(``);else{let e=S(()=>Ae());!S(()=>Me())&&e!==i&&(je(i),Be(i))}}});let[et,tt]=v(!1),[nt,rt]=v(!0),[it,st]=v(0),[ct,lt]=v(null),dt=()=>vt().startsWith(`[compact] `),ht=()=>dt()?vt().slice(10):vt();b(()=>{ct()||B(e=>e?.text.startsWith(`[compact] `)?null:e)});let[gt,_t]=v(new Map),z=()=>{let e=n();return e?gt().get(e)??null:null},B=e=>{let t=n();t&&_t(n=>{let r=new Map(n),i=typeof e==`function`?e(n.get(t)??null):e;return i?r.set(t,{...i,at:Date.now()}):r.delete(t),r})},[vt,yt]=v(``),[bt,xt]=v(0),St=()=>bt(),[Ct,wt]=v(``),Tt;b(()=>{if(!z()){clearTimeout(Tt),Tt=void 0,yt(``),wt(``);return}Tt||=setTimeout(()=>{Tt=void 0,yt(z()?.text??``),wt(z()?.reasoning??``)},(z()?.text.length??0)>2e4?250:(z()?.text.length??0)>6e3?120:60)}),w(()=>clearTimeout(Tt)),b(()=>{let t=e();_t(e=>qe(e,e=>t.find(t=>t.id===e)?.status)),xt(0)}),b(()=>{let e=vt(),t=z()?.reasoning??``;!e&&!t||nt()&&requestAnimationFrame(()=>{nt()&&Yn(!0)})}),b(()=>{let e=V()?.pendingPrompts??0,t=V()?.pendingPromptIds,n=Mt(),r=Nt(n),i=ot(r,e,t);i!==r&&Pt(n,i)}),b(()=>{let e=V()?.pendingPromptQueue;if(!e?.length)return;let t=Mt(),n=new Set(Nt(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&Pt(t,[...r.map(e=>({id:`p${e.id}`,text:e.text,at:Number(e.at)||Date.now(),promptId:e.id,images:e.images?.map(e=>e.url)})),...Nt(t)])}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{K()&&(rt(!0),st(0),Yn(!0))})};document.addEventListener(`visibilitychange`,e),w(()=>document.removeEventListener(`visibilitychange`,e))});let V=x(()=>e().find(e=>e.id===n())),Et=()=>{let e=V();return e?e.live??(e.status===`running`||e.status===`waiting`):!1},[Dt,Ot]=v(null);x(()=>{let e=new Set;for(let t of f())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let kt=new Map,[At,jt]=v([]),Mt=()=>i()||n()||`?`,Nt=e=>kt.get(e)??[],Pt=(e,t)=>{t.length===0?kt.delete(e):kt.set(e,t),Mt()===e&&jt(t)},[Ft,It]=v([]),[Lt,Rt]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[zt,Bt]=v(!1),H=()=>Ft().filter(e=>!e.read).length,Vt=e=>{It(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},Ht=t=>{let n=Ft().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Ht(r.id));return n},Ut=0,Wt=e=>{It(t=>[{...e,id:`n${++Ut}`,at:Date.now(),read:!1},...t].slice(0,50))},Gt=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t,i=typeof n.id==`string`?n.id:void 0;n.type===`message`&&n.data?.final===!0?Wt({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?Wt({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?Wt({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&Wt({agentId:t,kind:`progress`,title:`${r}: ${String(n.data.doing??`progress`)}`.slice(0,120),body:[n.data.recent&&`recent: ${n.data.recent}`,n.data.next&&`next: ${n.data.next}`].filter(Boolean).join(` · `).slice(0,300),eventId:i})},Kt=e=>{let t=document.querySelector(`[data-eid="${e}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`flash-target`),setTimeout(()=>t.classList.remove(`flash-target`),1600))},qt=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of f())if(yp.has(i.type)){if(i.type===`tool_call`){let e=n.get(i.data.callId)??[];e.push(i),n.set(i.data.callId,e)}else if(i.type===`tool_result`){let a=n.get(i.data.callId)?.shift();a?(e.set(a.id,i),t.add(i.id)):r.set(i.id,i)}}return{resFor:e,consumed:t,orphanCalls:r}}),[Jt,Yt]=v(new Set),Xt=e=>{e&&Yt(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},Zt=()=>Yt(new Set),Qt=x(()=>at(f(),Jt())),$t=x(()=>{let{consumed:e}=qt(),t=``;for(let e of f()){if(e._prevKind=t,!yp.has(e.type))continue;let n=e.data??{};(e.type!==`message`||String(n.content??``).trim()!==``||String(n.reasoning??``).trim()===``)&&(t=e.type===`tool_result`?`tool`:e.type)}let n=f().filter(t=>{if(t.type===`sub`)return!0;if(!yp.has(t.type))return!1;let n=t.type===`tool_call`||t.type===`tool_result`?String(t.data?.name??``):``;if(n===`report_progress`||n===`ask_user`)return!1;if(t.type===`tool_result`)return!e.has(t.id);if(t.type===`message`){let e=String(t.data?.content??``);return e.trim()===``&&String(t.data?.reasoning??``).trim()!==``&&t._prevKind===`tool`||t.data?.progressEcho||!t.data?.final&&e.trim()===`(tool call)`?!1:e.trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final}return!0}),r=[];for(let e of n)if(e.type===`sub`){let t=e.data,n=String(t?.type??`message`);if(n===`state`)continue;r.push({...e,type:n,data:{...t?.data,actor:t?.sub}})}else r.push(e);let i=e=>String(e??``).replace(/\s+/g,` `).trim().toLowerCase(),a=[];for(let e=0;e<r.length;e++){let t=r[e];if(t.type===`message`&&t.data?.role===`assistant`){let n=r[e-1],a=i(t.data.content);if(n?.type===`progress`){let e=n.data;if((a.includes(i(e.doing))||e.recent&&a.includes(i(e.recent)))&&a.length<=Math.max(200,i(e.doing).length*3))continue}if(n?.type===`decision`){let e=n.data,t=i(e.decision);if(t&&a.includes(t)&&a.length<=Math.max(300,t.length*3))continue}}a.push(t)}let o=new Set,s=new Set,c=new Map,l=new Map;for(let e of a){let t=e.data?.promptId;t&&(e.type===`prompt`&&e.data?.source===`user`&&s.add(String(t)),e.type===`system_note`&&e.data?.event===`prompt-delivered`&&(o.add(String(t)),c.set(String(t),e.seq)),e.type===`system_note`&&e.data?.event===`prompt-cancelled`&&l.set(String(t),e.seq))}let u=new Set;for(let e of At())e.promptId&&!o.has(e.promptId)&&u.add(e.promptId);let d=a.filter(e=>{if(e.type!==`prompt`||e.data?.source!==`user`)return!0;let t=String(e.data?.promptId??``);return t===``||!u.has(t)});for(let e=0;e<d.length;e++){let t=d[e];if(t.type!==`prompt`||t.data?.source!==`user`)continue;let n=String(t.data?.promptId??``),r=l.get(n);r!==void 0&&t.data&&(t.data.cancelled=!0);let i=c.get(n)??0,a=Math.max(i,r??0)||void 0;d[e]=a===void 0?{...t,seq:Xe(d)}:Ye(t,a)}return Je(d,At().filter(e=>!e.promptId||!(o.has(e.promptId)&&s.has(e.promptId))).map(e=>tn(e)))}),en=new Map;function tn(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=en.get(t);if(n)return n;en.size>64&&en.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:V()?.session??``,branch:V()?.branch??`br0`,parent:null,type:`prompt`,data:{source:`user`,text:e.text,pending:!e.sent,...e.images?.length?{images:e.images}:{},...e.promptId?{promptId:e.promptId}:{}}};return en.set(t,r),r}let nn=()=>$(`/api/config`).then(re).catch(()=>{}),[rn,an]=v(!1);C(()=>{let e=()=>an(!0);window.addEventListener(`teapot:unauthorized`,e),w(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[on,sn]=v(``),[cn,ln]=v(!1),[un,dn]=v(!1),fn=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==fn?(fn=t,dn(!1),sn(r)):t&&!un()&&sn(r)});let pn=async()=>{let e=document.getElementById(`todo-notify`)?.checked??!0;if(n())try{await $(`/api/agents/${n()}/todo`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:on(),notify:e})}),dn(!1),ln(!0),Q(`tasks saved${e&&on().trim()?` & notification queued`:``}`),hn()}catch(e){Q(`save failed: ${e.message}`)}},mn=x(()=>{let e=0,t=0;for(let n of on().split(`
22
22
  `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),hn=()=>$(`/api/agents`).then(e=>{let n=!1;t(t=>{let r=new Map(t.map(e=>[e.id,e]));return t.length!==(e.agents??[]).length&&(n=!0),(e.agents??[]).map(e=>{let t=r.get(e.id);return t||(n=!0),t&&JSON.stringify(t)===JSON.stringify(e)?t:e})}),n&&d()}).catch(()=>{}),gn=()=>$(`/api/metrics`).then(te).catch(()=>{}),[_n,vn]=v([]),yn=()=>$(`/api/tasks`).then(e=>vn(e.tasks)).catch(()=>{}),bn=e=>_n().filter(t=>t.agent===e),[xn,Sn]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),Cn=e=>{let t=new Set(xn());t.has(e)?t.delete(e):t.add(e),Sn(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},wn=t=>ft(e(),t),[Tn,En]=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}})()),Dn=x(()=>{let e=new Set;for(let t of Tn())t.startsWith(`chat:`)&&e.add(t);return e}),On=x(()=>ut(e(),xn(),Lt(),Dn())),U=(t,r,i,a)=>{let o=new Set(Tn());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||wn(e().find(e=>e.id===i))===t)&&Q(`hid ${r} — click the header to show it`)}En(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},kn=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,An=e=>{let t=W().get(e)??0;return`${t} chat${t===1?``:`s`}`},W=x(()=>pt(e())),jn=x(()=>mt(e(),On(),Tn())),Mn=2e3,[Nn,G]=v(null),Pn=new Map;function Fn(e){return`${i()||(n()??`?`)}:${e.id}`}function In(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=Fn(r),a=Pn.get(i);if(t[n]=a??r,!a&&(Pn.set(i,r),Pn.size>6e3)){let e=Pn.keys().next().value;e!==void 0&&Pn.delete(e)}}return t}let[Ln,Rn]=v(!1),[zn,Bn]=v(!1),Vn=0,Hn=-1;function Un(e){p(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of In(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function Wn(){let e=n();if(!e||zn()||Ln())return;if(f().length>=m()){Bn(!0);return}let t=()=>{let e=qn();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!zn()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(f().length>=m()){Bn(!0);return}let i=f().length;if(await Gn(),f().length===i)return;nt()&&n()===e&&Yn(!0)}}async function Gn(){let e=n(),t=f()[0];if(!(!e||!t||Ln()||zn())){Rn(!0);try{let r=qn(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=Nn(),c=i(),l=c&&c!==e?`&session=${encodeURIComponent(c)}`:``,u=(await $(`/api/agents/${e}/events?limit=${Mn}&before=${encodeURIComponent(t.id)}${l}${s?`&branch=${encodeURIComponent(s)}&lineage=true`:``}`)).events??[];if(u.length===0){Bn(!0);return}if(n()!==e||f()[0]?.id!==t.id)return;Un(u),requestAnimationFrame(()=>{if(n()===e){let e=qn();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{Rn(!1)}}}async function Kn(e,t){let r=Vn,a=t??i()??``;try{let t=Nn(),i=r!==Hn||!g().length,o=a&&a!==e?`&session=${encodeURIComponent(a)}`:``,[s,c,l]=await Promise.all([$(`/api/agents/${e}/events?limit=${Mn}${o}${t?`&branch=${encodeURIComponent(t)}&lineage=true`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:g()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(Hn=r),r!==Vn||n()!==e)return;p(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of In(s.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),h(s.total??s.events.length),_(c.branches),Yr(l.skills??[])}catch{}}function qn(){return document.querySelector(`.feed`)}function Jn(){let e=document.querySelector(`.composer textarea`);return 24+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function K(){let e=qn();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<Jn()}function Yn(e=!1){let t=qn();t&&(e||nt())&&(t.scrollTop=t.scrollHeight,st(0))}let Xn=new Map;function Zn(t,n){if(n&&c().get(t)?.includes(n))return n;let r=e().find(e=>e.id===t)?.session;return r&&c().get(t)?.includes(r)?r:c().get(t)?.[0]??null}async function Qn(e,t=!0,o){let s=n(),l=i(),u=f(),g=m();Vn++,c().size||d();let _=Zn(e,o)??e;if(s!==e||_!==l){if(l&&u.length&&(Xn.set(l,{events:u,total:g,at:Date.now()}),Xn.size>6)){let e=[...Xn.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&Xn.delete(e[0])}p([]),Pn.clear(),Zt(),lt(null),st(0),rt(!0),ni=!1,ri=void 0}r(e),a(_),D(T.get(e)??``),G(null),Bn(!1),Rn(!1),Pt(l||s||`?`,At()),jt(Nt(_||e)),localStorage.setItem(`teapot.session`,e),cr(_,t);let v=Xn.get(_);v?.events.length&&(In(v.events),p(In(v.events)),h(v.total),requestAnimationFrame(()=>{n()===e&&Yn(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(hn).catch(()=>{}),await Kn(e,_),n()===e&&(lt(V()?.ctx?.compacting?{phase:String(V().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&Yn(!0)}),Wn())}let[$n,er]=v(!1),tr=null,nr=null;w(()=>tr?.close());let rr=!1,ir=null;document.addEventListener(`visibilitychange`,()=>ir?.()),w(()=>{ir=null});let ar=!0;function or(){let e=location.protocol===`https:`?`wss://`:`ws://`,r=new WebSocket(`${e}${location.host}/api/ws${Cp()}`);tr=r,r.onopen=()=>{if(er(!0),!ar){ar=!0;return}rr=!0,document.visibilityState===`visible`&&a()},r.onclose=()=>{er(!1),setTimeout(or,1500)},r.onerror=()=>r.close();let i=new Set([`state`,`usage`,`session_start`]);r.onmessage=e=>{let o=JSON.parse(e.data);if(o.kind===`ping`){try{r.send(JSON.stringify({kind:`pong`}))}catch{}return}if(o.kind!==`pong`){if(o.kind===`event`&&We(o.event)){_t(e=>Ue(e,o.agentId));return}if(o.kind===`llm-delta`){if(_t(e=>He(e,o.agentId,o)),o.agentId===n()){let e=String(o.reasoning??``),t=String(o.text??``);e&&!t?bt()||xt(Date.now()):(t||!e&&bt())&&xt(0)}return}if(o.kind===`compaction-progress`){if(o.agentId!==n())return;o.phase===`done`?lt(null):lt({phase:o.phase,summarized:o.summarized});return}if(o.kind===`agent-update`&&o.snapshot){t(e=>{let t=e.findIndex(e=>e.id===o.snapshot.id),n=o.snapshot;if(t===-1)return[...e,n];let r=e[t];return JSON.stringify(r)===JSON.stringify(n)?e:e.map((e,r)=>r===t?n:e)});return}if(o.kind===`event`){let e=o.event?.type,t=o.event?.data??{};if((e===`system_note`&&t.event===`prompt-delivered`&&o.agentId===n()||e===`system_note`&&t.event===`prompt-cancelled`&&o.agentId===n())&&Pt(Mt(),At().filter(e=>e.promptId!==t.promptId)),i.has(e)&&!bp.has(e)||(Gt(o.agentId,o.event),o.event?.agent!==n()))return}if(document.visibilityState===`hidden`){rr=!0;return}nr||=setTimeout(a,120)}},rr=!1;let a=async()=>{if(nr=null,await hn(),await gn(),n()){let e=f().at(-1)?.id,t=m();if(await Kn(n()),f().at(-1)?.id!==e){let e=z();e&&e.text?Ge({text:e.text.trim(),reasoning:``,at:e.at},f(),V()?.status)&&B(null):e&&!e.text&&V()?.status!==`running`&&B(null),nt()?(Yn(!0),Vt(n())):st(it()+Math.max(0,m()-t))}}};ir=()=>{document.visibilityState===`visible`&&rr&&(rr=!1,a())}}let sr=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function cr(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=sr(),t=o().get(e);t&&(t!==n()||e!==i())&&Qn(t,!1,e||null)}),b(()=>{let e=V(),t=e?`${Et()?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=H()>0?`(${H()}) ${t}`:t}),window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)){e.key===`Escape`&&t.blur();return}if(e.key===`Escape`){if(k()){ie(!1);return}if(ae()){oe(!1);return}if(me()){he(!1);return}if(Dt()){Ot(null);return}if(se()&&le()){pe();return}let e=V();if(e&&Et()){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(hn);return}return}if(!(k()||ae())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)fe();else if(e.key===`t`)dr();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=On().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&&Qn(t[i].id)}}});let[lr,ur]=v(localStorage.getItem(`teapot.term`)===`1`),dr=()=>{let e=!lr();ur(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[fr,pr]=v([]),[mr,hr]=v(0),[gr,_r]=v(-1),[vr,yr]=v(!1),[br,xr]=v(0),[Sr,Cr]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),wr=new Map,Tr=0,Er=[null,null],Dr=()=>fr()[br()===0?mr():gr()]??null;function Or(e){if(!fr()[e])return;let t=br(),n=t===0?mr():gr(),r=t===0?gr():mr(),i=e=>t===0?hr(e):_r(e),a=e=>t===0?_r(e):hr(e);if(r===e){a(n),i(e);return}n!==e&&i(e)}let kr=()=>Ar();function Ar(e){let t=e??n();if(!t)return;let r=fr().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}let i={key:`${t}#${++Tr}`,agentId:t,title:r===0?t:`${t}·${r+1}`};pr(e=>[...e,i]);let a=fr().length;br()===0?hr(a):_r(a)}function jr(e){let t=fr()[e];if(!t)return;let n=wr.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),wr.delete(t.key)}let r=fr().filter((t,n)=>n!==e);pr(r);let i=t=>t===e?-1:t>e?t-1:t;hr(e=>Math.min(i(e),r.length-1)),_r(e=>e===-1?-1:Math.min(i(e),r.length-1))}function Mr(){for(let[,e]of wr){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}wr.clear()}function Nr(e,t){let n=wr.get(e.key);if(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 rl({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:_p()}),a=new ol;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${Cp()}`);s.onmessage=e=>{let t=JSON.parse(e.data);t.kind===`data`?i.write(t.data):t.kind===`exit`&&i.write(`\r\n\x1b[2m[terminal exited ${t.code??``}]\x1b[0m\r\n`)},i.onData(e=>{s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({kind:`input`,data:e}))});let c={cols:0,rows:0},l=[],u=()=>{try{a.fit()}catch{}(i.cols!==c.cols||i.rows!==c.rows)&&s.readyState===WebSocket.OPEN&&(c={cols:i.cols,rows:i.rows},s.send(JSON.stringify({kind:`resize`,cols:i.cols,rows:i.rows})))},d=new ResizeObserver(()=>{l[0]&&clearTimeout(l[0]),l[0]=setTimeout(u,250)});d.observe(r),setTimeout(u,60),n={el:r,term:i,fit:a,ws:s,ro:d},wr.set(e.key,n)}return n}function Pr(e){let t=Er[e];if(!t)return;let n=fr()[e===0?mr():gr()];if(!n){[...wr.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Nr(n,t);for(let[e,r]of wr)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(br()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{fr(),vr(),mr(),gr(),Sr(),requestAnimationFrame(()=>{Pr(0),vr()&&Pr(1)})});let Fr=null;b(()=>{if(!lr())return;let e=n();if(e&&e!==Fr){if(Fr=e,!fr().some(t=>t.agentId===e))Ar(e);else{let t=-1;fr().forEach((n,r)=>{n.agentId===e&&(t=r)}),t>=0&&Or(t)}}});let Ir=e=>{e.preventDefault();let t=e.clientY,n=Sr(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Cr(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(Sr())),requestAnimationFrame(()=>{Pr(0),vr()&&Pr(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},Lr=()=>{let e=!vr();if(yr(e),e){let e=fr().map((e,t)=>t).filter(e=>e!==mr());(gr()<0||gr()===mr()||gr()>=fr().length)&&_r(e[0]??-1)}requestAnimationFrame(()=>{Pr(0),vr()&&Pr(1)})};w(Mr);let Rr=e=>t=>{Er[e]=t,t&&requestAnimationFrame(()=>{Pr(e),vr()&&Pr(1),setTimeout(()=>Pr(e),200)})};C(()=>{nn(),hn().then(async()=>{await d();let t=sr(),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&&Qn(r.id,!1,t||null)}),gn(),yn(),Hr(),or();let t=setInterval(()=>{gn(),yn()},3e4);w(()=>clearInterval(t))});let zr=[{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`}],[Br,Vr]=v([]),Hr=()=>$(`/api/personas`).then(e=>Vr(e.personas)).catch(()=>{}),[Ur,Wr]=v(!1),Gr=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},Kr=()=>{let t=Gr();return t===null?[]:[...Br().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))},qr=new Set([`start`,`stop`,`fork`,`compact`]),[Jr,Yr]=v([]),[Xr,Zr]=v(-1),Qr=()=>{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=zr.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&qr.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=Jr().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[]},$r,ei=()=>{if(!$r)return;ti=!0;let e=nt();$r.style.height=`auto`,$r.style.height=et()?``:`${Math.min($r.scrollHeight,360)}px`,requestAnimationFrame(()=>{let t=qn();e&&t&&(t.scrollTop=t.scrollHeight),ti=!1})},ti=!1,ni=!1,ri;b(()=>{ne(),ei()});let[ii,ai]=v([]),oi=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=()=>{ai(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},si=async(e,t)=>{let r=t??n();if(!r)return;let i=ii();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}:{}})});Pt(Mt(),[...At(),{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)}:{}}]),ai([]),requestAnimationFrame(()=>requestAnimationFrame(()=>Yn(!0)))}catch(t){D(e),console.error(`send failed:`,t)}},ci=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=Br().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:Ur()?`fork`:`none`})})).id}${Ur()?` (forked context)`:``}`),hn(),D(``)}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}`),D(``)}else{Q(`unknown @${r} — personas: ${Br().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}return}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){D(`/goal `);return}if(t===`skill`&&!n){D(`/skill `);return}D(``);try{await li(t,n)}catch(e){throw D(ne()?`${i}\n${ne()}`:i),e}return}D(``),await si(i),et()&&tt(!1)}},li=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(hn);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Qn(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 si(`[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}`)}},ui,di=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!ui)return;let e=Math.min(di,ui.scrollHeight);Math.abs(ui.scrollTop-e)>1&&(ui.scrollTop=e)})})});let fi=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(hn),[pi,mi]=v(``),[hi,gi]=v(``),[_i,vi]=v(!1),[q,yi]=v(!0),bi=``;b(()=>{let e=n();e&&(V()?.goal,e!==bi&&(bi=e,vi(!1),mi(``),gi(``)))});let xi=async e=>{if(e.preventDefault(),!(!n()||!pi().trim()))try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:pi(),notify:q(),...hi().trim()?{verify:hi()}:{}})}),mi(``),gi(``),vi(!1),hn()}catch(e){Q(`goal save failed: ${e.message}`)}};return[j(N,{get when(){return O()?.needsSetup},fallback:null,get children(){return j($p,{onDone:()=>location.reload()})}}),j(N,{get when(){return rn()},get children(){var e=dl();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),j(N,{get when(){return!O()?.needsSetup},get children(){var i=zl(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.firstChild,l=c.firstChild;l.firstChild;var u=c.nextSibling,m=u.firstChild.firstChild.nextSibling;m.firstChild;var _=m.nextSibling,v=u.nextSibling,S=a.nextSibling,C=S.nextSibling,w=C.firstChild;w.firstChild,R(o,j(M,{get each(){return jn()},children:t=>[j(N,{get when(){return P(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=Gl(),n=e.firstChild;return e.$$click=()=>U(`ws:${t.wsHeader}`,kn(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),R(n,()=>t.wsCollapsedGroup?`▸`:`▾`),R(e,()=>kn(t.wsHeader),null),R(e,j(N,{get when(){return(W().get(t.wsHeader)??0)>1||t.wsCollapsedGroup},get children(){var e=Wl();return R(e,()=>W().get(t.wsHeader)??0),e}}),null),y(()=>I(e,`title`,t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${An(t.wsHeader)} hidden). Click to show.`:(W().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${An(t.wsHeader)} in this directory`:t.wsHeader||``)),e}}),j(N,{get when(){return P(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=Xl(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>Qn(t.a.id),R(r,j(N,{get when(){return!t.a.parent||e().some(e=>e.parent===t.a.id)},get fallback(){return Zl()},get children(){return(()=>{let e=!t.a.parent,n=e?Dn().has(`chat:${t.a.id}`):xn().has(t.a.id);return(()=>{var r=Ql();return r.$$click=r=>{r.stopPropagation(),e?U(`chat:${t.a.id}`,t.a.id,n):Cn(t.a.id)},R(r,n?`▸`:`▾`),y(()=>I(r,`title`,e?n?`show ${t.a.id}`:`hide ${t.a.id} and its sub-agents`:n?`expand sub-agents`:`collapse sub-agents`)),r})()})()}}),i),R(a,()=>t.a.id),R(r,(()=>{var e=P(()=>!!t.a.workspaceMissing);return()=>e()?$l():null})(),null),R(r,j(N,{get when(){return Ht(t.a.id)>0},get children(){var e=Kl();return e.firstChild,R(e,()=>Ht(t.a.id),null),y(()=>I(e,`title`,`${Ht(t.a.id)} unread notification${Ht(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),R(r,j(N,{get when(){return xn().has(t.a.id)},get children(){return(()=>{let n=e().filter(e=>e.parent===t.a.id),r=n.filter(e=>e.live??(e.status===`running`||e.status===`waiting`)).length;return n.length>0?(()=>{var e=eu();return e.firstChild,L(e,`subcount`+(r>0?` live`:``)),R(e,()=>n.length,null),R(e,r>0?` · ▶${r}`:``,null),y(()=>I(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),R(r,j(N,{get when(){return t.a.parent},get children(){return ql()}}),null),R(r,j(N,{get when(){return bn(t.a.id).length>0},get children(){var e=Jl();return y(()=>I(e,`title`,bn(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
24
- `))),e}}),null),R(r,j(N,{get when(){return t.a.goal.status===`done`},get children(){return Yl()}}),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?`sub-agent of @${t.a.parent}`:void 0,l=`dot ${t.a.status}`,u=t.a.workspaceMissing?` ghost`:``,d=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:void 0;return o!==e.e&&L(r,e.e=o),e.t=Ee(r,s,e.t),c!==e.a&&I(r,`title`,e.a=c),l!==e.o&&L(i,e.o=l),u!==e.i&&L(a,e.i=u),d!==e.n&&I(a,`title`,e.n=d),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),r}})]})),R(s,j(N,{get when(){return me()},get children(){var e=pl(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;ye(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),R(e,j(N,{get when(){return!ve()},get fallback(){return[(()=>{var e=tu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{xe(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),R(t,j(M,{get each(){return gp.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=ru();return R(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=be()),e})(),(()=>{var e=nu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Ce(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),R(t,j(M,{get each(){return gp.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=ru();return R(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=Se()),e})()]},get children(){var e=fl();return R(e,j(M,{each:gp,children:e=>(()=>{var t=iu(),n=t.firstChild;return t.$$click=()=>{_e(e.key),localStorage.setItem(`teapot.theme`,e.key)},R(n,()=>e.sw.map(e=>(()=>{var t=au();return De(t,`background`,e),t})())),R(t,()=>e.label,null),y(n=>{var r=`themebtn`+(ge()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ve()),e}}),c),l.$$click=e=>{e.stopPropagation(),Bt(!zt()),zt()||It(e=>e.map(e=>({...e,read:!0})))},R(l,j(N,{get when(){return H()>0},get children(){var e=ml();return R(e,H),e}}),null),R(c,j(Lp,{icon:`👻`,get active(){return Lt()},get title(){return Lt()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!Lt();if(Rt(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&V()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Qn(t.id)}}}),null),R(c,j(Lp,{icon:`+`,title:`new agent`,onClick:()=>{nn(),ie(!0)}}),null),R(c,j(Lp,{icon:`🎨`,title:`themes`,onClick:()=>he(!me())}),null),R(c,j(Lp,{icon:`⚙`,title:`settings`,onClick:()=>{nn(),oe(!0)}}),null),R(m,`0.26.4`,null),R(v,j(N,{get when(){return ee()},get children(){return[`master rss `,P(()=>ee().rssMb),`MB · heap `,P(()=>ee().heapUsedMb),`MB`,hl(),`load1 `,P(()=>ee().loadavg1),` · up `,P(()=>Math.floor(ee().uptimeSec/60)),`m`]}})),R(S,j(N,{get when(){return V()?.id},keyed:!0,get fallback(){return ou()},get children(){return[(()=>{var e=yl(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling;s.nextSibling;var c=r.nextSibling;return R(t,()=>V().id),R(n,()=>V().status),R(e,j(N,{get when(){return(V().pendingPrompts??0)>0},get children(){var e=gl(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>V().pendingPrompts,t),R(e,()=>V().status===`stopped`?` (stopped)`:``,null),y(()=>I(e,`title`,V().status===`stopped`?`${V().pendingPrompts} message${(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().pendingPrompts??0} message${(V().pendingPrompts??0)>1?`s`:``} from you waiting in the queue. They will be handed to the model at its next turn boundary — the timeline shows them as "pending (queued)…" until then, and each can be withdrawn with ✕ cancel while it's still queued.`)),e}}),r),R(e,j(N,{get when(){return bn(V().id).length>0},get children(){var e=_l();return e.firstChild,R(e,()=>bn(V().id).length,null),y(()=>I(e,`title`,`scheduled tasks:\n${bn(V().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
24
+ `))),e}}),null),R(r,j(N,{get when(){return t.a.goal.status===`done`},get children(){return Yl()}}),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?`sub-agent of @${t.a.parent}`:void 0,l=`dot ${t.a.status}`,u=t.a.workspaceMissing?` ghost`:``,d=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:void 0;return o!==e.e&&L(r,e.e=o),e.t=Ee(r,s,e.t),c!==e.a&&I(r,`title`,e.a=c),l!==e.o&&L(i,e.o=l),u!==e.i&&L(a,e.i=u),d!==e.n&&I(a,`title`,e.n=d),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),r}})]})),R(s,j(N,{get when(){return me()},get children(){var e=pl(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;ye(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),R(e,j(N,{get when(){return!ve()},get fallback(){return[(()=>{var e=tu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{xe(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),R(t,j(M,{get each(){return gp.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=ru();return R(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=be()),e})(),(()=>{var e=nu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Ce(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),R(t,j(M,{get each(){return gp.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=ru();return R(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=Se()),e})()]},get children(){var e=fl();return R(e,j(M,{each:gp,children:e=>(()=>{var t=iu(),n=t.firstChild;return t.$$click=()=>{_e(e.key),localStorage.setItem(`teapot.theme`,e.key)},R(n,()=>e.sw.map(e=>(()=>{var t=au();return De(t,`background`,e),t})())),R(t,()=>e.label,null),y(n=>{var r=`themebtn`+(ge()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ve()),e}}),c),l.$$click=e=>{e.stopPropagation(),Bt(!zt()),zt()||It(e=>e.map(e=>({...e,read:!0})))},R(l,j(N,{get when(){return H()>0},get children(){var e=ml();return R(e,H),e}}),null),R(c,j(Lp,{icon:`👻`,get active(){return Lt()},get title(){return Lt()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!Lt();if(Rt(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&V()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Qn(t.id)}}}),null),R(c,j(Lp,{icon:`+`,title:`new agent`,onClick:()=>{nn(),ie(!0)}}),null),R(c,j(Lp,{icon:`🎨`,title:`themes`,onClick:()=>he(!me())}),null),R(c,j(Lp,{icon:`⚙`,title:`settings`,onClick:()=>{nn(),oe(!0)}}),null),R(m,`0.26.5`,null),R(v,j(N,{get when(){return ee()},get children(){return[`master rss `,P(()=>ee().rssMb),`MB · heap `,P(()=>ee().heapUsedMb),`MB`,hl(),`load1 `,P(()=>ee().loadavg1),` · up `,P(()=>Math.floor(ee().uptimeSec/60)),`m`]}})),R(S,j(N,{get when(){return V()?.id},keyed:!0,get fallback(){return ou()},get children(){return[(()=>{var e=yl(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling;s.nextSibling;var c=r.nextSibling;return R(t,()=>V().id),R(n,()=>V().status),R(e,j(N,{get when(){return(V().pendingPrompts??0)>0},get children(){var e=gl(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>V().pendingPrompts,t),R(e,()=>V().status===`stopped`?` (stopped)`:``,null),y(()=>I(e,`title`,V().status===`stopped`?`${V().pendingPrompts} message${(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().pendingPrompts??0} message${(V().pendingPrompts??0)>1?`s`:``} from you waiting in the queue. They will be handed to the model at its next turn boundary — the timeline shows them as "pending (queued)…" until then, and each can be withdrawn with ✕ cancel while it's still queued.`)),e}}),r),R(e,j(N,{get when(){return bn(V().id).length>0},get children(){var e=_l();return e.firstChild,R(e,()=>bn(V().id).length,null),y(()=>I(e,`title`,`scheduled tasks:\n${bn(V().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
25
25
  `)}`)),e}}),r),R(r,()=>V().model,i),R(r,()=>V().session,a),R(r,()=>V().branch,o),R(r,()=>V().stats.turns,s),R(r,()=>V().stats.toolCalls,null),R(c,j(N,{get when(){return V().statusReason},get children(){var e=vl();return y(()=>I(e,`title`,V().statusReason)),e}}),null),R(c,j(Lp,{icon:`⌨`,title:`terminal (t)`,onClick:dr}),null),R(c,j(Lp,{icon:`▤`,title:`toggle details panel (d)`,onClick:fe}),null),y(()=>L(n,`badge ${V().status}`)),e})(),(()=>{var e=El();return e.addEventListener(`scroll`,e=>{if(ti)return;let t=e.currentTarget,r=K(),i=t.scrollHeight-t.scrollTop-t.clientHeight;if(!r&&ri!==void 0&&i>ri+8&&i>24?ni=!0:r&&(ni=!1),ri=i,t.scrollTop<=4&&n()&&!Ln()&&!zn()&&f().length>0&&Gn(),ni&&!r){rt(!1);return}r&&it()&&st(0),rt(r)}),R(e,j(N,{get when(){return ct()},children:e=>(()=>{var t=su();return t.firstChild,R(t,(()=>{var t=P(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Pp(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),R(e,j(N,{get when(){return P(()=>!!zn())()&&$t().length>0},get children(){return bl()}}),null),R(e,j(N,{get when(){return Ln()},get children(){return xl()}}),null),R(e,j(N,{get when(){return $t().length>0},get fallback(){return cu()},get children(){return[j(M,{get each(){return $t()},children:(e,t)=>j(kp,{e,get prev(){return $t()[t()-1]},get res(){return qt().resFor.get(e.id)},get orphan(){return qt().orphanCalls.has(e.id)},onOption:e=>void si(e),answeredIds:Qt,onAnswered:Xt,get agentActive(){return P(()=>!!Et())()&&Ke(e)},onResize:()=>{nt()&&requestAnimationFrame(()=>Yn(!0))},get onCancel(){return 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??``);D(ne()?`${n}\n\n${ne()}`:n),Pt(Mt(),At().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?()=>Ot({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),j(N,{get when(){return z()},get children(){var e=Tl(),t=e.firstChild.nextSibling;return t.firstChild,R(t,j(N,{get when(){return Ct()},get children(){var e=Sl(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return R(t,j(Ep,{get startedAt(){return St()}}),null),Oe(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{Ct(),t&&(e.scrollTop=e.scrollHeight)})},n),R(n,Ct),e}}),null),R(t,j(N,{get when(){return vt()},get fallback(){return lu()},get children(){return j(N,{get when(){return dt()},get fallback(){return(()=>{var e=wl();return y(()=>e.innerHTML=Ie(vt()+`▍`)),e})()},get children(){return[Cl(),(()=>{var e=wl();return y(()=>e.innerHTML=Ie(ht()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),j(N,{get when(){return lr()},get children(){var t=jl(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Cr(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Sr()))},n.$$pointerdown=Ir,R(i,j(M,{get each(){return fr()},children:(e,t)=>(()=>{var n=uu(),r=n.firstChild.nextSibling;return n.$$click=()=>Or(t()),R(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),jr(t())},y(r=>{var i=`termtab`+(br()===0&&mr()===t()?` active`:``)+(vr()&&br()===1&&gr()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&L(n,r.e=i),a!==r.t&&I(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),R(i,j(Lp,{icon:`+`,title:`new shell in this workspace`,onClick:kr}),null),R(o,(()=>{var t=P(()=>!!Dr());return()=>t()?e().find(e=>e.id===Dr().agentId)?.workspace.split(`/`).filter(Boolean).pop():V()?.workspace})()),R(a,j(Lp,{icon:`◫`,get title(){return vr()?`single pane`:`split panes (50/50)`},onClick:Lr}),null),R(a,j(Lp,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:dr}),null);var l=Rr(0);return typeof l==`function`&&Oe(l,c),c.$$pointerdown=()=>xr(0),R(c,j(N,{get when(){return mr()<0||mr()>=fr().length},get children(){return Dl()}})),R(s,j(N,{get when(){return vr()},get children(){return[Ol(),(()=>{var e=Al(),t=Rr(1);return typeof t==`function`&&Oe(t,e),e.$$pointerdown=()=>xr(1),R(e,j(N,{get when(){return gr()<0||gr()>=fr().length},get children(){return kl()}})),y(()=>e.classList.toggle(`focused`,br()===1)),e})()]}}),null),y(e=>{var n={height:`${Sr()}px`,"--termh":`${Sr()}px`},r=!!vr(),i=br()===0;return e.e=Ee(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=Ll(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling,o=t.nextSibling;R(e,j(N,{get when(){return!nt()||it()>0},get children(){var e=Ml();return e.firstChild,e.$$click=()=>Yn(!0),R(e,(()=>{var e=P(()=>it()>0);return()=>e()?`${it()} new message${it()>1?`s`:``}`:`jump to present`})(),null),e}}),t),R(e,j(N,{get when(){return Qr().length>0},get children(){var e=Nl();return R(e,j(M,{get each(){return Qr()},children:(e,t)=>(()=>{var n=du(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{D(e.insert),Zr(-1)},R(r,()=>e.insert.trim()),R(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===Xr()?` active`:``),a=e.title;return i!==r.e&&L(n,r.e=i),a!==r.t&&I(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),R(e,j(N,{get when(){return Kr().length>0},get children(){var e=Nl();return R(e,j(M,{get each(){return Kr()},children:e=>(()=>{var t=fu(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{D(`@${e.key} `),Zr(-1)},R(n,()=>e.key,null),R(r,()=>e.label),y(()=>I(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,ci),R(t,j(N,{get when(){return ii().length>0},get children(){var e=Pl(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,R(e,j(M,{get each(){return ii()},children:(e,t)=>(()=>{var n=pu(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>ai(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&I(n,`title`,t.e=i),a!==t.t&&I(r,`src`,t.t=a),o!==t.a&&I(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),R(t,()=>ii().length,n),R(t,()=>ii().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=Qr();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),Zr(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),Zr(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&Xr()>=0&&!hp){e.preventDefault(),D(t[Xr()].insert),Zr(-1);return}if(e.key===`Escape`&&t.length>0){Zr(-1);return}e.key===`Enter`&&!e.shiftKey&&!hp&&(e.preventDefault(),ci(e))},n.$$input=e=>{D(e.currentTarget.value),Zr(0),ei()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),oi(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{hp=!1})}),n.addEventListener(`compositionstart`,()=>{hp=!0});var s=$r;return typeof s==`function`?Oe(s,n):$r=n,R(t,j(N,{get when(){return P(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=Fl(),t=e.firstChild;return t.addEventListener(`change`,e=>Wr(e.currentTarget.checked)),y(()=>t.checked=Ur()),e}}),r),r.$$click=()=>{let e=!et();tt(e),requestAnimationFrame(()=>ei())},R(r,()=>et()?`⤡`:`⤢`),R(t,j(Lp,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),R(t,j(N,{get when(){return ii().length},get children(){var e=Il();return e.firstChild,R(e,()=>ii().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&oi(e.currentTarget.files),e.currentTarget.value=``}),R(o,()=>fp()||`enter send · shift+enter newline · ↑↓ sessions · / commands & focus · t terminal · d panel · esc interrupt · messages sent while the agent works queue up and land at the next turn boundary`),y(t=>{var i=`composer`+(et()?` maximized`:``),a=`message #${V().id} — / for commands · paste or 📎 to attach images`,o=et()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&L(e,t.e=i),a!==t.t&&I(n,`placeholder`,t.t=a),o!==t.a&&I(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),y(()=>n.value=ne()),e})()]}})),R(i,j(N,{get when(){return P(()=>!!ce())()&&le()},get children(){var e=Rl();return e.$$click=()=>de(!1),e}}),C),C.addEventListener(`scroll`,e=>{di=e.currentTarget.scrollTop});var te=ui;return typeof te==`function`?Oe(te,C):ui=C,R(w,j(Lp,{icon:`✕`,title:`close details panel (esc)`,onClick:pe}),null),R(C,j(N,{get when(){return V()?.id},keyed:!0,fallback:null,children:i=>[mu(),(()=>{var e=hu(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return R(n,()=>V().id),R(r,()=>V().status),R(a,()=>V().workspace),R(o,()=>V().session,s),R(o,()=>V().branch,null),y(e=>{var t=`badge ${V().status}`,n=V().workspace;return t!==e.e&&L(r,e.e=t),n!==e.t&&I(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),j(N,{get when(){return V().id},keyed:!0,fallback:null,children:e=>j(Yp,{agentId:e,get workspace(){return V().workspace}})}),gu(),(()=>{var e=yu(),t=e.firstChild,r=t.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=r.nextSibling;return s.firstChild,t.addEventListener(`change`,e=>{je(e.currentTarget.value),Be(e.currentTarget.value)}),R(t,j(M,{get each(){return ze()},children:e=>(()=>{var t=ru();return t.value=e,R(t,e,null),R(t,()=>e===O().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>Ne(e.currentTarget.value),R(a,j(M,{get each(){return Le()},children:e=>(()=>{var t=ru();return y(()=>t.value=e.id),t})()})),o.$$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:Ae(),model:Me().trim()||void 0,contextWindowTokens:Le().find(e=>e.id===(Me().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,hn()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},R(e,j(N,{get when(){return V().effortSupported},get children(){var e=_u(),t=e.firstChild.nextSibling;t.firstChild;var r=t.nextSibling;return t.addEventListener(`change`,e=>Fe(e.currentTarget.value)),R(t,j(M,{each:cp,children:e=>(()=>{var t=ru();return t.value=e,R(t,e),t})()}),null),r.$$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({reasoningEffort:Pe()})}),t.textContent=`✓ applied`,hn()}catch(e){alert(`effort change failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},y(()=>t.value=Pe()),e}}),s),R(s,()=>V().model,null),R(s,j(N,{get when(){return Le().length},get children(){return[` · `,P(()=>Le().length),` models loaded`]}}),null),R(e,j(N,{get when(){return Ze()},get children(){var e=vu();return R(e,Ze),e}}),null),y(()=>I(i,`placeholder`,V().model)),y(()=>t.value=Ae()),y(()=>i.value=Me()),e})(),bu(),(()=>{var i=Su(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling;return Te(a,`click`,Et()?fi(`/stop`):fi(`/start`),!0),R(a,()=>Et()?`■ stop`:`▶ start`),o.$$click=()=>$(`/api/agents/${V().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await d(!0),await Qn(V().id)}),s.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await $(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let a=e().filter(e=>e.id!==i);t(a),d(!0),a[0]?Qn(a[0].id):(r(null),p([]))},R(i,j(N,{get when(){return e().some(e=>e.parent===n())},get children(){var e=xu();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),hn())},e}}),null),y(e=>{var t=Et()?`danger`:`runbtn`,n=Et()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&L(a,e.e=t),n!==e.t&&I(a,`title`,e.t=n),e},{e:void 0,t:void 0}),i})(),(()=>{var e=Cu(),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(hn)}),y(()=>t.checked=V().autoContinue??!0),e})(),(()=>{var e=Tu();return e.firstChild,R(e,j(N,{get when(){return!!V().goal.text.trim()},get fallback(){return Uu()},get children(){var e=wu();return R(e,()=>V().goal.status),y(()=>L(e,`badge ${V().goal.status===`active`?`running`:V().goal.status}`)),e}}),null),e})(),(()=>{var e=Eu();return e.firstChild,R(e,j(M,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Wu();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(hn)},I(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),R(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(V().goal.text.trim()&&V().goal.status===e?` on ${e}`:``),i=!!V().goal.text.trim()&&V().goal.status===e;return r!==n.e&&L(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),j(N,{get when(){return V().goal.text},get fallback(){return Gu()},get children(){return[(()=>{var e=Du(),t=e.firstChild;return y(()=>t.innerHTML=Ie(String(V().goal.text))),e})(),j(N,{get when(){return V().goal.verify},get children(){var e=Ou(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Ie(String(V().goal.verify))),e}}),j(N,{get when(){return V().goal.audit},children:e=>(()=>{var t=Ku(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return R(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),R(r,()=>Np(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=Qe(e().feedback)?Ie(`_the auditor returned a verdict with no detail_`):Ie(e().feedback);return r!==n.e&&L(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),ku(),(()=>{var e=Au(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,xi),t.$$input=e=>{mi(e.currentTarget.value),vi(!0)},n.$$input=e=>{gi(e.currentTarget.value),vi(!0)},r.addEventListener(`change`,e=>yi(e.currentTarget.checked)),y(()=>t.value=pi()),y(()=>n.value=hi()),y(()=>r.checked=q()),e})(),(()=>{var e=Mu(),t=e.firstChild.nextSibling;return R(e,j(N,{get when(){return mn().total>0},get children(){var e=ju(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,R(e,()=>mn().done,t),R(e,()=>mn().total,n),y(t=>Ee(e,mn().done===mn().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),j(N,{get when(){return mn().total>0},get children(){var e=Nu(),t=e.firstChild;return y(e=>{var n=`barfill `+(mn().done===mn().total?``:`warn`),r=`${Math.round(mn().done/mn().total*100)}%`;return n!==e.e&&L(t,e.e=n),r!==e.t&&De(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),j(Jp,{get draft(){return on()},get viewMode(){return cn()},onDraft:e=>{sn(e),dn(!0)}}),(()=>{var e=Pu(),t=e.firstChild,n=t.nextSibling;return R(e,j(Lp,{get icon(){return cn()?`👁`:`✎`},get title(){return cn()?`rendered checklist`:`edit markdown`},onClick:()=>ln(!cn())}),t),n.$$click=pn,e})(),Fu(),j(N,{get when(){return V().latestProgress},get fallback(){return qu()},children:e=>(()=>{var t=Qu(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return R(t,j(N,{get when(){return e().recent},get children(){var t=Ju(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=sp(e().recent)),t}}),i),R(t,j(N,{get when(){return e().problems},get children(){var t=Yu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=sp(e().problems)),t}}),i),R(t,j(N,{get when(){return e().next},get children(){var t=Xu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=sp(e().next)),t}}),i),R(t,j(N,{get when(){return e().goalStatus},get children(){var t=Zu(),n=t.firstChild.nextSibling;return R(n,()=>e().goalStatus),t}}),i),R(i,()=>Np(e().ts)),y(()=>r.innerHTML=sp(e().doing)),t})()}),Iu(),(()=>{var e=zu(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=t.nextSibling,l=c.firstChild.nextSibling,u=l.firstChild,d=u.nextSibling;return d.nextSibling,R(i,()=>V().stats.turns),R(o,()=>V().stats.toolCalls),R(s,()=>V().stats.compactions??0),R(l,()=>Pp(V().stats.inputTokens),u),R(l,()=>Pp(V().stats.outputTokens),d),R(c,j(N,{get when(){return(V().stats.cachedInputTokens??0)>0},get children(){var e=Lu(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>Math.round(V().stats.cachedInputTokens/Math.max(1,V().stats.inputTokens)*1e3)/10,t),y(()=>I(e,`title`,`${Pp(V().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),R(e,j(N,{get when(){return(V().stats.costUsd??0)>0},get children(){var e=Ru(),t=e.firstChild.nextSibling;return t.firstChild,R(t,()=>Fp(V().stats.costUsd??0),null),y(()=>I(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),R(e,j(N,{get when(){return V().ctx},keyed:!0,get fallback(){return $u()},children:e=>{let t=x(()=>{let t=e,n=Le().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=id(),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,p=d.nextSibling,m=p.firstChild.nextSibling;return m.nextSibling,R(a,()=>Pp(r().usedTokens),o),R(t,j(N,{get when(){return r().effectiveWindow},get children(){var e=ed(),t=e.firstChild;return R(e,()=>i(r().pct),t),R(e,()=>Pp(r().effectiveWindow),null),y(()=>L(e,`pill ${r().cls}`)),e}}),null),R(e,j(N,{get when(){return r().effectiveWindow},get children(){var e=td(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&L(t,e.e=n),i!==e.t&&De(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),R(c,()=>Pp(r().usingDerived?r().derivedBudget:r().compactAt),l),R(u,()=>r().usingDerived?` (75% of window)`:` (manual override)`),R(e,j(N,{get when(){return r().effectiveWindow},get children(){var e=nd(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,Math.round(r().usedTokens/r().derivedBudget*100))}%`;return n!==e.e&&L(t,e.e=n),i!==e.t&&De(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),d),R(e,j(N,{get when(){return ct()||r().compacting},get children(){var e=rd(),t=e.firstChild.nextSibling.nextSibling;return R(t,()=>ct()?.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(hn)}),R(p,()=>Pp(r().compactAt),m),y(()=>f.checked=V().autoCompact!==!1),e})()}}),null),e})(),(()=>{var e=Vu();return e.firstChild.nextSibling,R(e,j(N,{get when(){return Nn()},get children(){var e=Bu(),t=e.firstChild.nextSibling;return R(t,Nn),e}}),null),e})(),j(M,{get each(){return g()},children:e=>(()=>{var t=ad(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=Nn()===e.branch?null:e.branch,r=t!==Nn();G(t),n()&&(r&&(Vn++,p([]),h(0),Bn(!1)),Kn(n()))},R(r,()=>e.branch,null),R(r,()=>e.branch===V().branch?` (current)`:``,null),R(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===V().branch||e.branch===Nn()?` cur`:``),i=e.branch===Nn()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Hu(),j(N,{get when(){return _n().length>0},get fallback(){return od()},get children(){return j(M,{get each(){return _n()},children:e=>(()=>{var t=cd(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Qn(e.agent),R(i,()=>e.id),R(a,()=>e.agent,null),R(r,j(N,{get when(){return e.forked},get children(){return sd()}}),null),R(o,()=>e.schedule,s),R(o,(()=>{var t=P(()=>!!e.next);return()=>t()?Np(e.next):`—`})(),null),R(o,(()=>{var t=P(()=>!!e.last);return()=>t()?` · last ${Np(e.last)}`:` · never ran`})(),null),R(c,()=>Ip(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Ip(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&L(t,r.e=i),a!==r.t&&I(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var t=`layout`+(le()?``:` right-hidden`),n=`iconbtn notifbtn`+(H()>0?` has-unread`:``),r=H()>0?`${H()} unread notifications`:`notifications`,a=`conn`+($n()?` ok`:``),o=$n()?`live (websocket)`:`reconnecting…`,s=`rightbar`+(le()?` open`:``);return t!==e.e&&L(i,e.e=t),n!==e.t&&L(l,e.t=n),r!==e.a&&I(l,`title`,e.a=r),a!==e.o&&L(_,e.o=a),o!==e.i&&I(_,`title`,e.i=o),s!==e.n&&L(C,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),i}}),j(N,{get when(){return zt()},get children(){return[(()=>{var e=Bl();return e.$$click=()=>Bt(!1),e})(),(()=>{var t=Ul(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return R(r,j(N,{get when(){return Ft().length>0},get children(){var e=Vl();return e.$$click=()=>It([]),e}}),i),i.$$click=()=>Bt(!1),R(t,j(N,{get when(){return Ft().length>0},get fallback(){return ld()},get children(){var t=Hl();return R(t,j(M,{get each(){return Ft()},children:t=>(()=>{var r=dd(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{It(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&Qn(t.agentId),Bt(!1),t.eventId&&setTimeout(()=>Kt(t.eventId),n()===t.agentId?60:350)},R(i,(()=>{var e=P(()=>t.kind===`finish`);return()=>e()?`✅`:P(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),R(a,()=>t.title),R(o,()=>Np(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),It(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},R(s,()=>t.read?`✓`:`○`),R(r,j(N,{get when(){return t.body},get children(){var e=ud();return R(e,()=>Mp(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&L(r,e.e=n),i!==e.t&&I(r,`title`,e.t=i),a!==e.a&&I(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),j(N,{get when(){return k()},get children(){return j(Bp,{get providers(){return Object.keys(O().providers??{})},onClose:()=>ie(!1),onCreated:e=>{ie(!1),hn(),Qn(e)}})}}),j(N,{get when(){return ae()},get children(){return j(em,{get cfg(){return O()},onClose:()=>oe(!1),onSaved:()=>{nn(),yn()}})}}),j(N,{get when(){return Dt()},fallback:null,children:e=>{let t=()=>f().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,f().length-t()-1),[i,a]=v(r()>0?`summarize`:`discard`);return j(zp,{title:`edit prompt — forks the conversation`,onClose:()=>Ot(null),get children(){var t=pd(),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()})}),Ot(null),hn();let t=n();t&&await Qn(t)}catch(e){alert(`edit failed: ${e.message}`)}}),R(t,j(N,{get when(){return r()>0},get children(){var e=fd(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return R(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>Ot(null),y(()=>o.value=e().text),t}})}})]}function Tp(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());C(()=>{let e=setInterval(()=>r(Date.now()),500);w(()=>clearInterval(e))});let i=()=>Ve(Math.max(0,n()-t));return e.inline?(()=>{var t=md();return t.firstChild,R(t,i,null),R(t,(()=>{var t=P(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=hd(),t=e.firstChild;return R(e,i,t),e})()}function Ep(e){let[t,n]=v(Date.now());return C(()=>{let e=setInterval(()=>n(Date.now()),500);w(()=>clearInterval(e))}),(()=>{var n=gd();return R(n,()=>Ve(Math.max(0,t()-e.startedAt))),n})()}function Dp(e){let t=e.e,n=e.res,r=!e.agentActive&&!n,i=t.data??{},a=String(i.name??`tool`),o=()=>n?String(n.data?.result??``):``,s=a,c=``,l=(()=>{var e=_d();return R(e,()=>Mp(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=()=>a===`bash`?u(`command`):u(`path`)||JSON.stringify(i.args??{},null,1),f=()=>a===`bash`?Number(u(`timeout_ms`))||void 0:a===`wait_children`?Number(u(`timeout_ms`))||3e5:Number(u(`timeout_ms`))||void 0,p=(e,t=1500)=>(()=>{var n=vd();return R(n,()=>Mp(e,t)),n})(),m=(e=4e3)=>n?[P(()=>p(o(),e)),(()=>{var e=yd();return R(e,()=>Ve(n.data?.durationMs),null),R(e,()=>a===`bash`?ct(st(n.data?.ok,String(n.data?.result??``))):n.data?.ok===!1?` · FAILED`:``,null),R(e,j(Rp,{get text(){return o()}}),null),e})()]:bd();try{switch(a){case`bash`:{let e=u(`command`),t=i.args?.background===!0,r=t?String(o()).match(/job (bg\d+)/)?.[1]??``:``;s=(t?`⏳ `:`$ `)+Ip(e,96);let a=u(`timeout_ms`)?Number(u(`timeout_ms`)):void 0,d=st(n?.data?.ok,n?String(n.data?.result??``):``);c=n?t?`background job${r?` ${r}`:``}${a?` · timeout ${Math.round(a/1e3)}s`:``}`:lt({outcome:d,durationMs:n.data?.durationMs,timeoutMs:a,fmtDur:Ve}):null,l=[t?(()=>{var e=xd(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,R(t,r||`?`,n),R(e,r?[` · kill with `,Sd()]:null,null),e})():null,P(()=>P(()=>e!==s.slice(2))()?p(e,800):null),P(()=>m(6e3))];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${Ip(u(`pattern`),40)}/`),Number(i.args?.offset)<0?e.push(`last ${-Number(i.args.offset)} lines`):i.args?.offset&&e.push(`from L${i.args.offset}`),i.args?.limit&&e.push(`≤${i.args.limit} lines`),c=e.join(` · `),l=m(6e3);break}case`write_file`:{let e=String(i.args?.content??``);s=u(`path`)||`(no path)`,c=`${Pp(e.length)} bytes`,l=[P(()=>p(e,1500)),P(()=>P(()=>e.length>1500)()?(()=>{var t=Cd(),n=t.firstChild;return R(t,()=>Pp(e.length),n),t})():null),n?(()=>{var e=yd();return R(e,()=>Ip(o(),160)),e})():wd()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=Td();return R(e,()=>Mp(`- `+u(`old_text`),900)),e})(),(()=>{var e=Ed();return R(e,()=>`+ `+Mp(u(`new_text`),900)),e})(),n?(()=>{var e=Dd(),t=e.firstChild;return R(e,()=>Ip(o(),120),t),R(e,()=>Ve(n.data?.durationMs),null),e})():Od()];break;case`apply_patch`:{let e=u(`patch`).split(`
26
26
  `).filter(e=>e&&!/^---$/.test(e.trim())),t=e.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);s=t.length?`${t.length} file${t.length>1?`s`:``}: ${Ip(t.join(`, `),80)}`:`patch`;let r=e.slice(0,60);l=[(()=>{var t=kd();return R(t,()=>r.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Ad();return L(n,`pline`+t),R(n,(()=>{var t=P(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),R(t,(()=>{var t=P(()=>e.length>60);return()=>t()?(()=>{var t=jd(),n=t.firstChild.nextSibling;return n.nextSibling,R(t,()=>e.length-60,n),t})():null})(),null),t})(),n?(()=>{var e=yd();return R(e,()=>Ip(o().split(`
27
- `)[0]??``,140),null),R(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Md()];break}case`list_dir`:s=u(`path`)||`.`,l=m(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=Ip(e,70),c=`web`,l=[(()=>{var e=yd();return R(e,j(N,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Pd();return R(e,()=>Ip(u(`url`),80)),e})()},get children(){var e=Nd();return y(()=>I(e,`href`,u(`url`))),e}})),e})(),P(()=>m(3e3))];break}case`bash_output`:{let e=u(`action`)||`read`;s=`bash_output ${u(`job_id`)||`(?)`}`,c=e,l=m(4e3);break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=wl();return y(()=>t.innerHTML=Ie(e)),t})(),(()=>{var e=yd();return R(e,()=>Ve(n.data?.durationMs)),e})()]:Fd();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Ip(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[P(()=>P(()=>!!e.length)()?(()=>{var t=Id();return t.firstChild,R(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Dd(),t=e.firstChild;return R(e,()=>Ip(o(),160),t),R(e,()=>Ve(n.data?.durationMs),null),e})():Ld()];break}}}catch{}return(()=>{var i=zd(),u=i.firstChild,p=u.firstChild;p.firstChild;var m=p.nextSibling,h=m.nextSibling;return i.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),I(i,`title`,`${a}${c?` — `+c:``}`),R(p,s,null),R(u,j(N,{get when(){return t.data?.actor},get children(){var e=Rd();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),m),R(m,()=>n?c||``:r?`(result missed)`:a===`bash`||f()?j(Tp,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return f()}}):`running…`),R(h,j(Rp,{get text(){return d()},label:`⧉ cmd`,title:`copy the ${a} arguments`}),null),R(h,j(N,{when:n,get children(){return j(Rp,{get text(){return o()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),R(i,l,null),y(()=>L(i,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),i})()}function Op(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 kp(e){let t=e.e,n=vp(t),r=it(e.prev,t);if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Bd(),r=n.firstChild.nextSibling;return r.nextSibling,R(n,()=>String(e.fromBranch??`?`),r),R(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=et(t.data??{});return(()=>{var t=Vd(),n=t.firstChild;return R(n,()=>e.label),R(t,j(N,{get when(){return e.hasCard},get children(){var t=Ad();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Ie(e.detail):Ie(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&L(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>L(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Hd(),n=e.firstChild.nextSibling;return n.nextSibling,R(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Ud(),n=e.firstChild;return R(e,()=>t.data.from,n),R(e,()=>t.data.to,null),R(e,(()=>{var e=P(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>L(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Wd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,R(n,()=>String(t.data?.failures),r),R(n,()=>String(t.data?.limit),i),R(a,()=>String(t.data?.lastTool),o),R(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>I(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Gd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(n,()=>String(t.data?.attempt),r),R(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Ad();return L(r,`divider-msg`+(e?` err`:``)),R(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>I(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=Kd(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(e,()=>String(t.data?.tokensBefore??`?`),n),R(e,()=>String(t.data?.tokensAfter??`?`),r),R(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=qd(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(e,()=>String(t.data?.messages??`?`),n),R(e,()=>String(t.data?.tokensBefore??`?`),r),R(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var i=Zd(),a=i.firstChild,o=a.nextSibling;return L(a,`avatar avghost`+(r?` ghosted`:``)),R(a,()=>r?``:n.icon),R(o,r&&(()=>{var e=Qd();return y(()=>I(e,`title`,`${xp(t.ts)} · ${t.branch}`)),e})(),null),R(o,j(N,{when:!r,get children(){var r=Xd(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return R(i,()=>n.name),R(r,j(N,{get when(){return t.data?.actor},get children(){var e=Rd();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),a),R(a,(()=>{var e=P(()=>!!t.data?.pending);return()=>e()?`queued…`:P(()=>!!t.data?.cancelled)()?`withdrawn`:xp(t.ts)})()),R(o,()=>t.branch),R(r,j(N,{get when(){return e.onCancel},get children(){var t=Jd();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),R(r,j(N,{get when(){return t.type!==`tool_call`},get children(){return j(Rp,{get text(){return Op(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),R(r,j(N,{get when(){return e.onEdit},get children(){var t=Yd();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>De(i,`color`,n.color)),r}}),null),R(o,j(jp,{e:t,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 o=`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),s=t.id,c=r?`transparent`:n.color+`33`,l=r?`1px solid transparent`:`1px solid ${n.color}66`,u=r?`${xp(t.ts)} · ${t.branch}`:void 0;return o!==e.e&&L(i,e.e=o),s!==e.t&&I(i,`data-eid`,e.t=s),c!==e.a&&De(a,`background`,e.a=c),l!==e.o&&De(a,`border`,e.o=l),u!==e.i&&I(a,`title`,e.i=u),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),i})()}function Ap(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=$d(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&I(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function jp(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=wl();return y(()=>e.innerHTML=sp(String(t.data.text??``))),e})(),j(N,{get when(){return e.length},get children(){var t=ef();return R(t,j(M,{each:e,children:e=>(()=>{var t=tf();return I(t,`src`,e),t})()})),t}})]}case`message`:return[j(N,{get when(){return P(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=nf(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return R(n,(()=>{var e=P(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Pp(String(t.data.reasoning).length)} — truncated)`:``})(),null),R(r,()=>Mp(String(t.data.reasoning),8e3)),e}}),(()=>{var e=wl();return y(()=>e.innerHTML=sp(String(t.data.content??``))),e})(),j(N,{get when(){return t.data.interrupted},get children(){return rf()}}),j(N,{get when(){return t.data.final},get children(){var e=af(),n=e.firstChild;return R(e,j(Rp,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return j(Dp,{e:t,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=sf(),o=a.firstChild,s=o.firstChild.nextSibling,c=o.nextSibling,l=c.nextSibling;return L(a,`embed `+(i?``:`fail`)),R(s,r===`bash`?`$ (bash, call evicted)`:r),R(o,j(Rp,{text:n}),null),R(c,()=>Mp(n,4e3)),R(l,()=>Ve(t.data.durationMs),null),R(l,()=>r===`bash`?ct(st(t.data.ok,n)):i?``:` · FAILED`,null),R(a,j(N,{get when(){return e.orphan},get children(){return of()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=lf(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return R(n,j(N,{get when(){return e.length},get children(){var t=cf();return t.firstChild,R(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=sp(String(t.data?.decision??``)),r=sp(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=ff(),o=a.firstChild.firstChild.nextSibling;return R(a,j(N,{get when(){return i()},get children(){return uf()}}),null),R(a,j(N,{get when(){return n.length>0},get children(){var a=df();return R(a,j(M,{each:n,children:n=>(()=>{var a=pf();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},R(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),R(a,j(Ap,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=sp(String(t.data?.question??``));return n!==e.e&&L(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=mf(),n=e.firstChild.firstChild.nextSibling;return R(e,j(N,{get when(){return t.data.goalStatus},get children(){var e=Zu(),n=e.firstChild.nextSibling;return R(n,()=>String(t.data.goalStatus)),e}}),null),R(e,j(N,{get when(){return t.data.recent},get children(){var e=Ju(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=sp(String(t.data.recent))),e}}),null),R(e,j(N,{get when(){return t.data.problems},get children(){var e=Yu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=sp(String(t.data.problems))),e}}),null),R(e,j(N,{get when(){return t.data.next},get children(){var e=Xu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=sp(String(t.data.next))),e}}),null),y(()=>n.innerHTML=sp(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=hf(),n=e.firstChild;return n.firstChild,R(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=_f(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,R(n,()=>String(t.data.mode??``),r),R(n,()=>Pp(Number(t.data.tokensBefore??0)),i),R(n,()=>Pp(Number(t.data.tokensAfter??0)),a),R(n,(()=>{var e=P(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),R(e,j(N,{get when(){return t.data.summary},get children(){return[gf(),(()=>{var e=wl();return y(()=>e.innerHTML=sp(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=vf();return R(e,()=>Mp(JSON.stringify(t.data),200)),e})()}}function Mp(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Np(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 Pp(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 Fp(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 Ip(e,t){return Mp(e.replace(/\s+/g,` `).trim(),t)}function Lp(e){return(()=>{var t=yf(),n=t.firstChild;return Te(t,`click`,e.onClick,!0),R(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),n.a=Ee(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Rp(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),tt(e.text??``).then(e=>{if(e===`unsupported`||e===`failed`){i(!0),setTimeout(()=>i(!1),1200);return}n(!0),setTimeout(()=>n(!1),900)})};return(()=>{var n=bf();return n.$$click=a,R(n,(()=>{var n=P(()=>!!t());return()=>n()?`✓`:P(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>I(n,`title`,e.title??`copy to clipboard`)),n})()}function zp(e){return(()=>{var t=xf(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),R(r,()=>e.title),Te(i,`click`,e.onClose,!0),R(n,()=>e.children,null),t})()}function Bp(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}C(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return j(zp,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Cf(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,C=S.firstChild.nextSibling,w=S.nextSibling,ee=w.firstChild.nextSibling,te=w.nextSibling.firstChild.nextSibling,T=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),R(b,j(M,{get each(){return r()},children:e=>(()=>{var n=wf();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),R(n,e,null),n})()})),C.$$input=e=>o(e.currentTarget.value),ee.addEventListener(`change`,e=>c(e.currentTarget.value)),R(ee,j(M,{get each(){return e.providers},children:e=>(()=>{var t=ru();return R(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),R(i,j(N,{get when(){return d()},get children(){var e=Sf();return R(e,d),e}}),T),y(()=>h.value=t()),y(()=>C.value=a()),y(()=>ee.value=s()),y(()=>te.value=l()),i}})}var Vp=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Hp=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Up=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Wp(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Gp(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 Gp(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Vp.has(t)?`image`:Hp.has(t)?`video`:Up.has(t)?`audio`:null}var Kp=new Map,qp=e=>{let t=Kp.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Kp.set(e,t)),t};function Jp(e){return j(N,{get when(){return e.viewMode},get fallback(){return(()=>{var t=Ef();return y(()=>t.innerHTML=sp(e.draft)),t})()},get children(){var t=Tf();return t.$$input=t=>e.onDraft(t.currentTarget.value),y(()=>t.value=e.draft),t}})}function Yp(e){let t=qp(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),C=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},ee=e=>x()!==`hide`||!e.ignored,[te,T]=v(localStorage.getItem(`teapot.showHidden`)===`1`),ne=()=>{let e=!te(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await O(t,e)}))).then(t=>{T(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&re(e,n)})},E=(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 D(e){return O(e,te())}async function O(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 E(t,i.entries??[])}catch(e){return _(e.message),null}}let re=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=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),D(``).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);return}if(t.add(e.path),l(t),!n().has(e.path)){let t=await D(e.path);t&&re(e.path,t)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[ue,de]=v(!1),fe=e=>/\.(md|markdown|mdx)$/i.test(e),pe=0,me=async e=>{let t=++pe;oe(``),ce(!0);try{let{highlightChunks:n}=await ul(async()=>{let{highlightChunks:e}=await import(`./shiki-Cy1X9klC.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(pe!==t)return;oe(e=>e+r)}}catch{pe===t&&oe(``)}finally{pe===t&&ce(!1)}};w(()=>{pe++});let he=async(t,n)=>{let r=Gp(t.path);if(r){c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);return}try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&me({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ge=async()=>{let t=o();if(!(!t||ue())){de(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
27
+ `)[0]??``,140),null),R(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Md()];break}case`list_dir`:s=u(`path`)||`.`,l=m(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=Ip(e,70),c=`web`,l=[(()=>{var e=yd();return R(e,j(N,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Pd();return R(e,()=>Ip(u(`url`),80)),e})()},get children(){var e=Nd();return y(()=>I(e,`href`,u(`url`))),e}})),e})(),P(()=>m(3e3))];break}case`bash_output`:{let e=u(`action`)||`read`;s=`bash_output ${u(`job_id`)||`(?)`}`,c=e,l=m(4e3);break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=wl();return y(()=>t.innerHTML=Ie(e)),t})(),(()=>{var e=yd();return R(e,()=>Ve(n.data?.durationMs)),e})()]:Fd();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Ip(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[P(()=>P(()=>!!e.length)()?(()=>{var t=Id();return t.firstChild,R(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Dd(),t=e.firstChild;return R(e,()=>Ip(o(),160),t),R(e,()=>Ve(n.data?.durationMs),null),e})():Ld()];break}}}catch{}return(()=>{var i=zd(),u=i.firstChild,p=u.firstChild;p.firstChild;var m=p.nextSibling,h=m.nextSibling;return i.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),I(i,`title`,`${a}${c?` — `+c:``}`),R(p,s,null),R(u,j(N,{get when(){return t.data?.actor},get children(){var e=Rd();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),m),R(m,()=>n?c||``:r?`(result missed)`:a===`bash`||f()?j(Tp,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return f()}}):`running…`),R(h,j(Rp,{get text(){return d()},label:`⧉ cmd`,title:`copy the ${a} arguments`}),null),R(h,j(N,{when:n,get children(){return j(Rp,{get text(){return o()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),R(i,l,null),y(()=>L(i,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),i})()}function Op(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 kp(e){let t=e.e,n=vp(t),r=it(e.prev,t);if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Bd(),r=n.firstChild.nextSibling;return r.nextSibling,R(n,()=>String(e.fromBranch??`?`),r),R(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=et(t.data??{});return(()=>{var t=Vd(),n=t.firstChild;return R(n,()=>e.label),R(t,j(N,{get when(){return e.hasCard},get children(){var t=Ad();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Ie(e.detail):Ie(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&L(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>L(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Hd(),n=e.firstChild.nextSibling;return n.nextSibling,R(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Ud(),n=e.firstChild;return R(e,()=>t.data.from,n),R(e,()=>t.data.to,null),R(e,(()=>{var e=P(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>L(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Wd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,R(n,()=>String(t.data?.failures),r),R(n,()=>String(t.data?.limit),i),R(a,()=>String(t.data?.lastTool),o),R(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>I(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Gd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(n,()=>String(t.data?.attempt),r),R(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Ad();return L(r,`divider-msg`+(e?` err`:``)),R(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>I(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=Kd(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(e,()=>String(t.data?.tokensBefore??`?`),n),R(e,()=>String(t.data?.tokensAfter??`?`),r),R(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=qd(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(e,()=>String(t.data?.messages??`?`),n),R(e,()=>String(t.data?.tokensBefore??`?`),r),R(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var i=Zd(),a=i.firstChild,o=a.nextSibling;return L(a,`avatar avghost`+(r?` ghosted`:``)),R(a,()=>r?``:n.icon),R(o,r&&(()=>{var e=Qd();return y(()=>I(e,`title`,`${xp(t.ts)} · ${t.branch}`)),e})(),null),R(o,j(N,{when:!r,get children(){var r=Xd(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return R(i,()=>n.name),R(r,j(N,{get when(){return t.data?.actor},get children(){var e=Rd();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),a),R(a,(()=>{var e=P(()=>!!t.data?.pending);return()=>e()?`queued…`:P(()=>!!t.data?.cancelled)()?`withdrawn`:xp(t.ts)})()),R(o,()=>t.branch),R(r,j(N,{get when(){return e.onCancel},get children(){var t=Jd();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),R(r,j(N,{get when(){return t.type!==`tool_call`},get children(){return j(Rp,{get text(){return Op(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),R(r,j(N,{get when(){return e.onEdit},get children(){var t=Yd();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>De(i,`color`,n.color)),r}}),null),R(o,j(jp,{e:t,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 o=`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),s=t.id,c=r?`transparent`:n.color+`33`,l=r?`1px solid transparent`:`1px solid ${n.color}66`,u=r?`${xp(t.ts)} · ${t.branch}`:void 0;return o!==e.e&&L(i,e.e=o),s!==e.t&&I(i,`data-eid`,e.t=s),c!==e.a&&De(a,`background`,e.a=c),l!==e.o&&De(a,`border`,e.o=l),u!==e.i&&I(a,`title`,e.i=u),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),i})()}function Ap(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=$d(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&I(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function jp(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=wl();return y(()=>e.innerHTML=sp(String(t.data.text??``))),e})(),j(N,{get when(){return e.length},get children(){var t=ef();return R(t,j(M,{each:e,children:e=>(()=>{var t=tf();return I(t,`src`,e),t})()})),t}})]}case`message`:return[j(N,{get when(){return P(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=nf(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return R(n,(()=>{var e=P(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Pp(String(t.data.reasoning).length)} — truncated)`:``})(),null),R(r,()=>Mp(String(t.data.reasoning),8e3)),e}}),(()=>{var e=wl();return y(()=>e.innerHTML=sp(String(t.data.content??``))),e})(),j(N,{get when(){return t.data.interrupted},get children(){return rf()}}),j(N,{get when(){return t.data.final},get children(){var e=af(),n=e.firstChild;return R(e,j(Rp,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return j(Dp,{e:t,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=sf(),o=a.firstChild,s=o.firstChild.nextSibling,c=o.nextSibling,l=c.nextSibling;return L(a,`embed `+(i?``:`fail`)),R(s,r===`bash`?`$ (bash, call evicted)`:r),R(o,j(Rp,{text:n}),null),R(c,()=>Mp(n,4e3)),R(l,()=>Ve(t.data.durationMs),null),R(l,()=>r===`bash`?ct(st(t.data.ok,n)):i?``:` · FAILED`,null),R(a,j(N,{get when(){return e.orphan},get children(){return of()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=lf(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return R(n,j(N,{get when(){return e.length},get children(){var t=cf();return t.firstChild,R(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=sp(String(t.data?.decision??``)),r=sp(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=ff(),o=a.firstChild.firstChild.nextSibling;return R(a,j(N,{get when(){return i()},get children(){return uf()}}),null),R(a,j(N,{get when(){return n.length>0},get children(){var a=df();return R(a,j(M,{each:n,children:n=>(()=>{var a=pf();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},R(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),R(a,j(Ap,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=sp(String(t.data?.question??``));return n!==e.e&&L(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=mf(),n=e.firstChild.firstChild.nextSibling;return R(e,j(N,{get when(){return t.data.goalStatus},get children(){var e=Zu(),n=e.firstChild.nextSibling;return R(n,()=>String(t.data.goalStatus)),e}}),null),R(e,j(N,{get when(){return t.data.recent},get children(){var e=Ju(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=sp(String(t.data.recent))),e}}),null),R(e,j(N,{get when(){return t.data.problems},get children(){var e=Yu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=sp(String(t.data.problems))),e}}),null),R(e,j(N,{get when(){return t.data.next},get children(){var e=Xu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=sp(String(t.data.next))),e}}),null),y(()=>n.innerHTML=sp(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=hf(),n=e.firstChild;return n.firstChild,R(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=_f(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,R(n,()=>String(t.data.mode??``),r),R(n,()=>Pp(Number(t.data.tokensBefore??0)),i),R(n,()=>Pp(Number(t.data.tokensAfter??0)),a),R(n,(()=>{var e=P(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),R(e,j(N,{get when(){return t.data.summary},get children(){return[gf(),(()=>{var e=wl();return y(()=>e.innerHTML=sp(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=vf();return R(e,()=>Mp(JSON.stringify(t.data),200)),e})()}}function Mp(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Np(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 Pp(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 Fp(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 Ip(e,t){return Mp(e.replace(/\s+/g,` `).trim(),t)}function Lp(e){return(()=>{var t=yf(),n=t.firstChild;return Te(t,`click`,e.onClick,!0),R(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),n.a=Ee(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Rp(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),tt(e.text??``).then(e=>{if(e===`unsupported`||e===`failed`){i(!0),setTimeout(()=>i(!1),1200);return}n(!0),setTimeout(()=>n(!1),900)})};return(()=>{var n=bf();return n.$$click=a,R(n,(()=>{var n=P(()=>!!t());return()=>n()?`✓`:P(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>I(n,`title`,e.title??`copy to clipboard`)),n})()}function zp(e){return(()=>{var t=xf(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),R(r,()=>e.title),Te(i,`click`,e.onClose,!0),R(n,()=>e.children,null),t})()}function Bp(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}C(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return j(zp,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Cf(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,C=S.firstChild.nextSibling,w=S.nextSibling,ee=w.firstChild.nextSibling,te=w.nextSibling.firstChild.nextSibling,T=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),R(b,j(M,{get each(){return r()},children:e=>(()=>{var n=wf();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),R(n,e,null),n})()})),C.$$input=e=>o(e.currentTarget.value),ee.addEventListener(`change`,e=>c(e.currentTarget.value)),R(ee,j(M,{get each(){return e.providers},children:e=>(()=>{var t=ru();return R(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),R(i,j(N,{get when(){return d()},get children(){var e=Sf();return R(e,d),e}}),T),y(()=>h.value=t()),y(()=>C.value=a()),y(()=>ee.value=s()),y(()=>te.value=l()),i}})}var Vp=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Hp=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Up=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Wp(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Gp(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 Gp(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Vp.has(t)?`image`:Hp.has(t)?`video`:Up.has(t)?`audio`:null}var Kp=new Map,qp=e=>{let t=Kp.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Kp.set(e,t)),t};function Jp(e){return j(N,{get when(){return e.viewMode},get fallback(){return(()=>{var t=Ef();return y(()=>t.innerHTML=sp(e.draft)),t})()},get children(){var t=Tf();return t.$$input=t=>e.onDraft(t.currentTarget.value),y(()=>t.value=e.draft),t}})}function Yp(e){let t=qp(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),C=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},ee=e=>x()!==`hide`||!e.ignored,[te,T]=v(localStorage.getItem(`teapot.showHidden`)===`1`),ne=()=>{let e=!te(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await O(t,e)}))).then(t=>{T(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&re(e,n)})},E=(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 D(e){return O(e,te())}async function O(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 E(t,i.entries??[])}catch(e){return _(e.message),null}}let re=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=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),D(``).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);return}if(t.add(e.path),l(t),!n().has(e.path)){let t=await D(e.path);t&&re(e.path,t)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[ue,de]=v(!1),fe=e=>/\.(md|markdown|mdx)$/i.test(e),pe=0,me=async e=>{let t=++pe;oe(``),ce(!0);try{let{highlightChunks:n}=await ul(async()=>{let{highlightChunks:e}=await import(`./shiki-CAu4ne7J.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(pe!==t)return;oe(e=>e+r)}}catch{pe===t&&oe(``)}finally{pe===t&&ce(!1)}};w(()=>{pe++});let he=async(t,n)=>{let r=Gp(t.path);if(r){c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);return}try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&me({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ge=async()=>{let t=o();if(!(!t||ue())){de(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
28
28
  OK = load the disk version into the editor (your edits are discarded)
29
- Cancel = keep editing your copy`)?(le(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{de(!1)}}},_e=e=>!e.binary&&!e.truncated,ve=(e,t)=>[(()=>{var n=Of(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void he(e,`code`),R(r,(()=>{var t=P(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Wp(e.name)})()),R(a,()=>e.name),R(n,j(N,{get when(){return P(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Df();return R(t,()=>Pp(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&L(n,r.e=i),r.t=Ee(n,a,r.t),o!==r.a&&I(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),j(N,{get when(){return P(()=>!!e.dir)()&&i().has(e.path)},get children(){return j(M,{get each(){return(n().get(e.path)??[]).filter(ee)},children:e=>ve(e,t+1)})}})],ye=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[be,xe]=v(!1),Se=async()=>{if(!be()){xe(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await O(e,te())})));for(let{p:e,rows:n}of t)n&&re(e,n)}finally{xe(!1)}}};return[(()=>{var e=kf(),t=e.firstChild.nextSibling;return t.firstChild,R(t,ye,null),R(e,j(Lp,{class:`filetoggle`,get icon(){return be()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void Se()}),null),R(e,j(Lp,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return P(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:C}),null),R(e,j(Lp,{class:`filetoggle`,get icon(){return te()?`◉.`:`○.`},get title(){return te()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:ne}),null),e})(),(()=>{var e=Af();return R(e,j(N,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=jf();return R(e,()=>g()||`empty workspace`),e})()},get children(){return j(M,{get each(){return(n().get(``)??[]).filter(ee)},children:e=>ve(e,0)})}})),e})(),j(N,{get when(){return o()},children:t=>j(zp,{get title(){return`🗂 ${t().path}`},onClose:()=>{pe++,c(null),f(null)},get children(){return j(N,{get when(){return u()},get fallback(){return[(()=>{var e=If(),n=e.firstChild;return R(e,j(N,{get when(){return P(()=>!!fe(t().path))()&&!t().binary},get children(){var e=Pf();return e.$$click=()=>h(`md`),y(()=>L(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||me({path:t().path,content:t().content,truncated:t().truncated})},R(e,j(N,{get when(){return _e(t())},get children(){var e=Ff();return e.$$click=()=>h(`edit`),y(()=>L(e,p()===`edit`?`on`:``)),e}}),null),y(()=>L(n,p()===`code`?`on`:``)),e})(),j(N,{get when(){return!t().binary},get fallback(){return Rf()},get children(){return j(N,{get when(){return p()===`edit`},get fallback(){return j(N,{get when(){return P(()=>p()===`md`)()&&fe(t().path)},get fallback(){return j(Xp,{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=zf();return y(()=>e.innerHTML=Ie(t().content)),e}})},get children(){var e=Lf(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),I(n,`spellcheck`,!1),R(r,()=>Pp(A().length),i),a.$$click=()=>void ge(),R(a,()=>ue()?`saving…`:`💾 save`),y(()=>a.disabled=ue()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=Nf(),n=t.firstChild,r=n.firstChild;return R(t,j(N,{get when(){return u().kind===`image`},get fallback(){return j(N,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=Vf();return y(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Bf();return y(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Mf();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&I(t,`src`,n.e=r),i!==n.t&&I(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),R(n,()=>u().kind,r),t}})}})})]}function Xp(e){return[j(N,{get when(){return e.html},get fallback(){return P(()=>!!e.pending)()?(()=>{var t=Wf(),n=t.firstChild.nextSibling;return n.nextSibling,R(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Gf();return R(t,()=>e.content),t})()},get children(){var t=Hf();return y(()=>t.innerHTML=e.html),t}}),j(N,{get when(){return e.truncated},get children(){return Uf()}})]}var Zp=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:`anthropic/claude-sonnet-4`,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:`orcarouter/auto`,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:`gpt-4o-mini`},{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)`}],Qp={key:`custom`,label:`Custom`,url:``,model:``,hint:`any OpenAI-compatible /v1 endpoint — vLLM, LM Studio, llama.cpp, a company gateway… fill the fields below`};function $p(e){let[t,n]=v(Zp[0]),[r,i]=v(Zp[0].url),[a,o]=v(``),[s,c]=v(Zp[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);w(()=>clearTimeout(n))});let C=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Pp(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},ee=()=>C(s()),te=async t=>{t.preventDefault(),x(``),g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}};return(()=>{var e=Yf(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,C=x.firstChild.nextSibling,w=x.nextSibling,T=w.firstChild.nextSibling,ne=T.nextSibling,E=w.nextSibling,D=E.firstChild.nextSibling,O=D.firstChild.nextSibling,re=D.nextSibling.firstChild.nextSibling,k=E.nextSibling;return n.addEventListener(`submit`,te),R(u,()=>[...Zp,Qp].map(e=>(()=>{var n=Xf();return n.$$click=()=>S(e),R(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&L(n,r.e=i),a!==r.t&&I(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),R(n,j(N,{get when(){return t().hint},get children(){var e=Kf();return R(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),R(b,()=>Zp.map(e=>(()=>{var t=ru();return y(()=>t.value=e.url),t})())),C.$$input=e=>o(e.currentTarget.value),T.$$input=e=>c(e.currentTarget.value),R(ne,()=>l().map(e=>(()=>{var t=ru();return y(()=>t.value=e.id),t})())),R(n,j(N,{get when(){return l().length>0},get fallback(){return Zf()},get children(){var e=Jf(),t=e.firstChild;return R(e,()=>l().length,t),R(e,j(N,{get when(){return ee()},get children(){return[` · `,(()=>{var e=qf();return R(e,ee),e})()]}}),null),e}}),E),O.$$input=e=>f(e.currentTarget.value),re.$$input=e=>m(e.currentTarget.value),R(n,j(N,{get when(){return _()},get children(){var e=Sf();return R(e,_),e}}),k),R(k,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(type to filter models from the endpoint)`,r=h();return n!==e.e&&I(T,`placeholder`,e.e=n),r!==e.t&&(k.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>C.value=a()),y(()=>T.value=s()),y(()=>O.value=d()),y(()=>re.value=p()),e})()}function em(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),a=()=>e.cfg.defaultProvider??``,o=()=>{let e=[...new Set(t().map(e=>e.name.trim()).filter(Boolean))],n=r();return n&&!e.includes(n)&&e.push(n),e},s=()=>{let e=r();return e?t().some(t=>t.name.trim()===e)?``:e:``},[c,l]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[u,d]=v(e.cfg.progressMinChars??4e3),[f,p]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[m,h]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[g,_]=v(e.cfg.maxSpawnDepth??3),[b,x]=v((e.cfg.tasks??[]).map(e=>({...e}))),[S,C]=v(``),w=()=>(e.cfg.agents??[]).map(e=>e.id),ee=()=>{let e={};for(let n of t()){if(!n.name.trim())return C(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return C(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},te=async t=>{t.preventDefault(),C(``);let n=ee();if(!n)return;let i=b().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 i){if(!e.agent){C(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){C(`task "${e.id}": schedule is required`);return}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,c())*6e4,progressMinChars:Math.max(100,u()),...f()==null?{}:{contextTokenBudget:Math.max(1,f())*1e3},...m()>0?{contextWindowTokens:m()*1e3}:{},maxSpawnDepth:Math.max(0,g()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){C(e.message)}},T=(e,t,n,r)=>(()=>{var i=Qf(),a=i.firstChild;return I(i,`title`,r),R(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return j(zp,{title:`settings`,get onClose(){return e.onClose},get children(){var v=ep(),ee=v.firstChild,ne=ee.firstChild.nextSibling,E=ne.nextSibling;E.firstChild;var D=E.nextSibling.firstChild.firstChild.nextSibling;D.firstChild;var O=ee.nextSibling,re=O.firstChild.nextSibling,k=re.firstChild,ie=k.firstChild.nextSibling,ae=O.nextSibling,oe=ae.firstChild.nextSibling,se=ae.nextSibling;se.firstChild;var ce=se.nextSibling,A=ce.firstChild.nextSibling.firstChild;A.firstChild;var le=A.nextSibling,ue=ce.nextSibling;return v.addEventListener(`submit`,te),R(ee,j(be,{get each(){return t()},children:(e,r)=>(()=>{var i=tp(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().apiKey),y(()=>c.value=e().model),i})()}),ne),ne.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),R(E,j(M,{each:Zp,children:e=>(()=>{var a=np();return a.firstChild,a.$$click=()=>{let a=t().filter(t=>t.name!==e.key);n([...a,{name:e.key,baseUrl:e.url,apiKey:``,model:e.model}]),r()||i(e.key)},R(a,()=>e.label,null),y(()=>I(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),D.addEventListener(`change`,e=>i(e.currentTarget.value)),R(D,j(M,{get each(){return o()},children:e=>(()=>{var t=ru();return t.value=e,R(t,e),t})()}),null),R(ee,j(N,{get when(){return s()},get children(){var e=$f(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return R(t,s),R(e,()=>s()===a()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),R(r,s),e}}),null),R(re,()=>T(`progress interval (min)`,c(),e=>l(e),`how often the harness asks for a progress report`),k),R(re,()=>T(`progress min chars`,u(),e=>d(e),`progress prompts wait for this much real output`),k),ie.$$input=e=>p(e.currentTarget.value===``?null:Number(e.currentTarget.value)),R(re,()=>T(`context window (k tok)`,m(),e=>h(e),`model's real window — 0/blank hides the % gauge`),null),R(re,()=>T(`max spawn depth`,g(),e=>_(e),`sub-agent nesting limit (0 = no spawning)`),null),R(ae,j(N,{get when(){return b().length>0},get children(){return j(be,{get each(){return b()},children:(e,t)=>(()=>{var n=rp(),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=>x(b().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>x(b().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>x(b().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>x(b().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>x(b().filter((e,n)=>n!==t)),u.$$input=e=>x(b().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})()})}}),oe),oe.$$click=()=>x([...b(),{id:``,agent:w()[0]??``,schedule:`every 30m`,prompt:``}]),R(se,j(M,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=ap(),n=t.firstChild,r=n.nextSibling;return R(n,()=>e.id),R(r,()=>e.workspace),R(t,j(N,{get when(){return e.parent},get children(){var t=ip();return t.firstChild,R(t,()=>e.parent,null),t}}),null),t})()}),null),R(A,()=>e.cfg.version??`unknown`,null),le.$$click=async e=>{try{C(``);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.26.4`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){C(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},R(v,j(N,{get when(){return S()},get children(){var e=Sf();return R(e,S),e}}),ue),y(()=>D.value=r()),y(()=>ie.value=f()??``),v}})}we([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Ce(()=>j(wp,{}),document.getElementById(`root`));export{ul as t};
30
- //# sourceMappingURL=index-CfHZpzkw.js.map
29
+ Cancel = keep editing your copy`)?(le(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{de(!1)}}},_e=e=>!e.binary&&!e.truncated,ve=(e,t)=>[(()=>{var n=Of(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void he(e,`code`),R(r,(()=>{var t=P(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Wp(e.name)})()),R(a,()=>e.name),R(n,j(N,{get when(){return P(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Df();return R(t,()=>Pp(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&L(n,r.e=i),r.t=Ee(n,a,r.t),o!==r.a&&I(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),j(N,{get when(){return P(()=>!!e.dir)()&&i().has(e.path)},get children(){return j(M,{get each(){return(n().get(e.path)??[]).filter(ee)},children:e=>ve(e,t+1)})}})],ye=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[be,xe]=v(!1),Se=async()=>{if(!be()){xe(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await O(e,te())})));for(let{p:e,rows:n}of t)n&&re(e,n)}finally{xe(!1)}}};return[(()=>{var e=kf(),t=e.firstChild.nextSibling;return t.firstChild,R(t,ye,null),R(e,j(Lp,{class:`filetoggle`,get icon(){return be()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void Se()}),null),R(e,j(Lp,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return P(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:C}),null),R(e,j(Lp,{class:`filetoggle`,get icon(){return te()?`◉.`:`○.`},get title(){return te()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:ne}),null),e})(),(()=>{var e=Af();return R(e,j(N,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=jf();return R(e,()=>g()||`empty workspace`),e})()},get children(){return j(M,{get each(){return(n().get(``)??[]).filter(ee)},children:e=>ve(e,0)})}})),e})(),j(N,{get when(){return o()},children:t=>j(zp,{get title(){return`🗂 ${t().path}`},onClose:()=>{pe++,c(null),f(null)},get children(){return j(N,{get when(){return u()},get fallback(){return[(()=>{var e=If(),n=e.firstChild;return R(e,j(N,{get when(){return P(()=>!!fe(t().path))()&&!t().binary},get children(){var e=Pf();return e.$$click=()=>h(`md`),y(()=>L(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||me({path:t().path,content:t().content,truncated:t().truncated})},R(e,j(N,{get when(){return _e(t())},get children(){var e=Ff();return e.$$click=()=>h(`edit`),y(()=>L(e,p()===`edit`?`on`:``)),e}}),null),y(()=>L(n,p()===`code`?`on`:``)),e})(),j(N,{get when(){return!t().binary},get fallback(){return Rf()},get children(){return j(N,{get when(){return p()===`edit`},get fallback(){return j(N,{get when(){return P(()=>p()===`md`)()&&fe(t().path)},get fallback(){return j(Xp,{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=zf();return y(()=>e.innerHTML=Ie(t().content)),e}})},get children(){var e=Lf(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),I(n,`spellcheck`,!1),R(r,()=>Pp(A().length),i),a.$$click=()=>void ge(),R(a,()=>ue()?`saving…`:`💾 save`),y(()=>a.disabled=ue()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=Nf(),n=t.firstChild,r=n.firstChild;return R(t,j(N,{get when(){return u().kind===`image`},get fallback(){return j(N,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=Vf();return y(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Bf();return y(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Mf();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&I(t,`src`,n.e=r),i!==n.t&&I(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),R(n,()=>u().kind,r),t}})}})})]}function Xp(e){return[j(N,{get when(){return e.html},get fallback(){return P(()=>!!e.pending)()?(()=>{var t=Wf(),n=t.firstChild.nextSibling;return n.nextSibling,R(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Gf();return R(t,()=>e.content),t})()},get children(){var t=Hf();return y(()=>t.innerHTML=e.html),t}}),j(N,{get when(){return e.truncated},get children(){return Uf()}})]}var Zp=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:`anthropic/claude-sonnet-4`,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:`orcarouter/auto`,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:`gpt-4o-mini`},{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)`}],Qp={key:`custom`,label:`Custom`,url:``,model:``,hint:`any OpenAI-compatible /v1 endpoint — vLLM, LM Studio, llama.cpp, a company gateway… fill the fields below`};function $p(e){let[t,n]=v(Zp[0]),[r,i]=v(Zp[0].url),[a,o]=v(``),[s,c]=v(Zp[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);w(()=>clearTimeout(n))});let C=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Pp(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},ee=()=>C(s()),te=async t=>{t.preventDefault(),x(``),g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}};return(()=>{var e=Yf(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,C=x.firstChild.nextSibling,w=x.nextSibling,T=w.firstChild.nextSibling,ne=T.nextSibling,E=w.nextSibling,D=E.firstChild.nextSibling,O=D.firstChild.nextSibling,re=D.nextSibling.firstChild.nextSibling,k=E.nextSibling;return n.addEventListener(`submit`,te),R(u,()=>[...Zp,Qp].map(e=>(()=>{var n=Xf();return n.$$click=()=>S(e),R(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&L(n,r.e=i),a!==r.t&&I(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),R(n,j(N,{get when(){return t().hint},get children(){var e=Kf();return R(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),R(b,()=>Zp.map(e=>(()=>{var t=ru();return y(()=>t.value=e.url),t})())),C.$$input=e=>o(e.currentTarget.value),T.$$input=e=>c(e.currentTarget.value),R(ne,()=>l().map(e=>(()=>{var t=ru();return y(()=>t.value=e.id),t})())),R(n,j(N,{get when(){return l().length>0},get fallback(){return Zf()},get children(){var e=Jf(),t=e.firstChild;return R(e,()=>l().length,t),R(e,j(N,{get when(){return ee()},get children(){return[` · `,(()=>{var e=qf();return R(e,ee),e})()]}}),null),e}}),E),O.$$input=e=>f(e.currentTarget.value),re.$$input=e=>m(e.currentTarget.value),R(n,j(N,{get when(){return _()},get children(){var e=Sf();return R(e,_),e}}),k),R(k,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(type to filter models from the endpoint)`,r=h();return n!==e.e&&I(T,`placeholder`,e.e=n),r!==e.t&&(k.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>C.value=a()),y(()=>T.value=s()),y(()=>O.value=d()),y(()=>re.value=p()),e})()}function em(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),a=()=>e.cfg.defaultProvider??``,o=()=>{let e=[...new Set(t().map(e=>e.name.trim()).filter(Boolean))],n=r();return n&&!e.includes(n)&&e.push(n),e},s=()=>{let e=r();return e?t().some(t=>t.name.trim()===e)?``:e:``},[c,l]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[u,d]=v(e.cfg.progressMinChars??4e3),[f,p]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[m,h]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[g,_]=v(e.cfg.maxSpawnDepth??3),[b,x]=v((e.cfg.tasks??[]).map(e=>({...e}))),[S,C]=v(``),w=()=>(e.cfg.agents??[]).map(e=>e.id),ee=()=>{let e={};for(let n of t()){if(!n.name.trim())return C(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return C(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},te=async t=>{t.preventDefault(),C(``);let n=ee();if(!n)return;let i=b().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 i){if(!e.agent){C(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){C(`task "${e.id}": schedule is required`);return}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,c())*6e4,progressMinChars:Math.max(100,u()),...f()==null?{}:{contextTokenBudget:Math.max(1,f())*1e3},...m()>0?{contextWindowTokens:m()*1e3}:{},maxSpawnDepth:Math.max(0,g()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){C(e.message)}},T=(e,t,n,r)=>(()=>{var i=Qf(),a=i.firstChild;return I(i,`title`,r),R(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return j(zp,{title:`settings`,get onClose(){return e.onClose},get children(){var v=ep(),ee=v.firstChild,ne=ee.firstChild.nextSibling,E=ne.nextSibling;E.firstChild;var D=E.nextSibling.firstChild.firstChild.nextSibling;D.firstChild;var O=ee.nextSibling,re=O.firstChild.nextSibling,k=re.firstChild,ie=k.firstChild.nextSibling,ae=O.nextSibling,oe=ae.firstChild.nextSibling,se=ae.nextSibling;se.firstChild;var ce=se.nextSibling,A=ce.firstChild.nextSibling.firstChild;A.firstChild;var le=A.nextSibling,ue=ce.nextSibling;return v.addEventListener(`submit`,te),R(ee,j(be,{get each(){return t()},children:(e,r)=>(()=>{var i=tp(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().apiKey),y(()=>c.value=e().model),i})()}),ne),ne.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),R(E,j(M,{each:Zp,children:e=>(()=>{var a=np();return a.firstChild,a.$$click=()=>{let a=t().filter(t=>t.name!==e.key);n([...a,{name:e.key,baseUrl:e.url,apiKey:``,model:e.model}]),r()||i(e.key)},R(a,()=>e.label,null),y(()=>I(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),D.addEventListener(`change`,e=>i(e.currentTarget.value)),R(D,j(M,{get each(){return o()},children:e=>(()=>{var t=ru();return t.value=e,R(t,e),t})()}),null),R(ee,j(N,{get when(){return s()},get children(){var e=$f(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return R(t,s),R(e,()=>s()===a()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),R(r,s),e}}),null),R(re,()=>T(`progress interval (min)`,c(),e=>l(e),`how often the harness asks for a progress report`),k),R(re,()=>T(`progress min chars`,u(),e=>d(e),`progress prompts wait for this much real output`),k),ie.$$input=e=>p(e.currentTarget.value===``?null:Number(e.currentTarget.value)),R(re,()=>T(`context window (k tok)`,m(),e=>h(e),`model's real window — 0/blank hides the % gauge`),null),R(re,()=>T(`max spawn depth`,g(),e=>_(e),`sub-agent nesting limit (0 = no spawning)`),null),R(ae,j(N,{get when(){return b().length>0},get children(){return j(be,{get each(){return b()},children:(e,t)=>(()=>{var n=rp(),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=>x(b().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>x(b().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>x(b().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>x(b().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>x(b().filter((e,n)=>n!==t)),u.$$input=e=>x(b().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})()})}}),oe),oe.$$click=()=>x([...b(),{id:``,agent:w()[0]??``,schedule:`every 30m`,prompt:``}]),R(se,j(M,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=ap(),n=t.firstChild,r=n.nextSibling;return R(n,()=>e.id),R(r,()=>e.workspace),R(t,j(N,{get when(){return e.parent},get children(){var t=ip();return t.firstChild,R(t,()=>e.parent,null),t}}),null),t})()}),null),R(A,()=>e.cfg.version??`unknown`,null),le.$$click=async e=>{try{C(``);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.26.5`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){C(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},R(v,j(N,{get when(){return S()},get children(){var e=Sf();return R(e,S),e}}),ue),y(()=>D.value=r()),y(()=>ie.value=f()??``),v}})}we([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Ce(()=>j(wp,{}),document.getElementById(`root`));export{ul as t};
30
+ //# sourceMappingURL=index-BmEVNR_F.js.map