teapot-coding-agent 0.26.2 → 0.26.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent.js +39 -2
- package/package.json +1 -1
- package/public/assets/{index-R9IBZg9z.js → index-B6nvBQLn.js} +4 -4
- package/public/assets/{index-R9IBZg9z.js.map → index-B6nvBQLn.js.map} +1 -1
- package/public/assets/{index-Orqy6ihl.css → index-CP1dmlDT.css} +1 -1
- package/public/assets/{shiki-DrXpGTVJ.js → shiki-DPtj9Srk.js} +2 -2
- package/public/assets/{shiki-DrXpGTVJ.js.map → shiki-DPtj9Srk.js.map} +1 -1
- package/public/index.html +2 -2
package/dist/agent/agent.js
CHANGED
|
@@ -88,6 +88,24 @@ Most session state is not injected into prompts — fetch it with tools instead:
|
|
|
88
88
|
panel) — do NOT also repeat the same content as a chat message; end the
|
|
89
89
|
turn right after the call (a short "reported." is fine).
|
|
90
90
|
- Be frugal: prefer small precise edits, avoid runaway loops.`;
|
|
91
|
+
/**
|
|
92
|
+
* Placeholder text a provider adapter substitutes for a message with no usable
|
|
93
|
+
* content (`llm.ts`).
|
|
94
|
+
*
|
|
95
|
+
* #94: these are DISPLAY ARTIFACTS. They were reaching the parent inside a
|
|
96
|
+
* sub-agent's final report, where they occupied two of six entries while saying
|
|
97
|
+
* nothing — the parent was told "[assistant] (tool call)" as if it were content.
|
|
98
|
+
*/
|
|
99
|
+
export const PLACEHOLDER_TEXT = /^\((tool call|no content|no output)\)$/i;
|
|
100
|
+
/**
|
|
101
|
+
* Harness acknowledgements — meta-lines about the run itself rather than the
|
|
102
|
+
* work ("decision recorded to decisions.md", "progress recorded", …).
|
|
103
|
+
*
|
|
104
|
+
* #94: these are addressed to the OPERATOR, not to whoever reads the next
|
|
105
|
+
* agent's report, and they consumed slots in a six-deep window that the parent
|
|
106
|
+
* reads as its only account of the work.
|
|
107
|
+
*/
|
|
108
|
+
export const HARNESS_ACK = /^(decision recorded|progress recorded|goal saved|feedback saved|memory saved|todo saved|no skills yet|skills created|read_memory|memory|\(tool call\)|\(no content\)|\(no output\)|true|false|null|none)\b/i;
|
|
91
109
|
export class Agent {
|
|
92
110
|
log;
|
|
93
111
|
toolCtx;
|
|
@@ -2098,10 +2116,29 @@ export class Agent {
|
|
|
2098
2116
|
const m = this.messages[i];
|
|
2099
2117
|
if (m.role === "user")
|
|
2100
2118
|
continue; // prompts/noise — keep agent output only
|
|
2101
|
-
|
|
2119
|
+
const text = String(m.content ?? "").trim();
|
|
2120
|
+
// #94: a message whose text is a PLACEHOLDER carries no information.
|
|
2121
|
+
//
|
|
2122
|
+
// `llm.ts` rewrites any assistant/tool message that has no usable text to
|
|
2123
|
+
// the literal "(tool call)" or "(no content)". Those are display
|
|
2124
|
+
// artifacts, and the parent's report was landing them verbatim — in the
|
|
2125
|
+
// real log, TWO of the six entries in an accepted report were literally
|
|
2126
|
+
// "[assistant] (tool call)", so half of what the parent was told about the
|
|
2127
|
+
// work was a placeholder.
|
|
2128
|
+
//
|
|
2129
|
+
// A tool CALL is real work, but it is represented in the tool RESULT that
|
|
2130
|
+
// follows, so dropping the placeholder loses nothing.
|
|
2131
|
+
if (!text || PLACEHOLDER_TEXT.test(text))
|
|
2132
|
+
continue;
|
|
2133
|
+
// #94: a window this small must not be spent on BOOKKEEPING. The real log
|
|
2134
|
+
// showed a 6-slot window where two 23-char "(tool call)" placeholders and a
|
|
2135
|
+
// 40-char "decision recorded to decisions.md" took half the slots, pushing
|
|
2136
|
+
// out the reasoning a parent would need to judge the work. Harness
|
|
2137
|
+
// acknowledgements carry no findings, so they cost a slot for nothing.
|
|
2138
|
+
if (HARNESS_ACK.test(text))
|
|
2102
2139
|
continue;
|
|
2103
2140
|
const who = m.role === "tool" ? "tool" : m.role;
|
|
2104
|
-
let line = `[${who}] ${
|
|
2141
|
+
let line = `[${who}] ${text}`;
|
|
2105
2142
|
if (m.role === "tool") {
|
|
2106
2143
|
// tool results are prefixed "(failed)" by the logger when they fail —
|
|
2107
2144
|
// the raw content is what matters here, and cap hard: these can be huge
|
package/package.json
CHANGED
|
@@ -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">`),wf=I(`<div class="content mdpreview"style="max-height:40vh;padding:8px 10px">`),Tf=I(`<span class=fsize>`),Ef=I(`<div><span class=ficon></span><span class=fname>`),Df=I(`<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>· `),Of=I(`<div class=filebox>`),kf=I(`<div class=muted style=padding:6px>`),Af=I(`<img>`),jf=I(`<div class=mediapreview><div class="meta muted"> preview`),Mf=I(`<button title="rendered markdown">👁 preview`),Nf=I(`<button title="edit and save back to the workspace">✎ edit`),Pf=I(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),Ff=I(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),If=I(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Lf=I(`<div class="content mdpreview">`),Rf=I(`<video controls>`),zf=I(`<audio controls>`),Bf=I(`<div class=filepreview>`),Vf=I(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),Hf=I(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),Uf=I(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),Wf=I(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),Gf=I(`<span style=color:var(--fg)>`),Kf=I(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),qf=I(`<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">`),Jf=I(`<button type=button>`),Yf=I(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),Xf=I(`<label><input type=number min=0>`),Zf=I(`<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.`),Qf=I(`<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`),$f=I(`<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">✕`),ep=I(`<button type=button>+ `),tp=I(`<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">`),np=I(`<span class=muted>🧩 sub of @`),rp=I(`<div class=cfgrow><b></b><span class=muted>`),ip=new Map;function ap(e){let t=ip.get(e);if(t!==void 0)return t;let n=Fe(e);return ip.set(e,n),ip.size>500&&ip.delete(ip.keys().next().value),n}var op=[`minimal`,`low`,`medium`,`high`],sp=1100,cp={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`}},lp={name:`harness`,icon:`📣`,color:`#3ba55d`},[up,dp]=v(``),fp,Q=e=>{dp(e),clearTimeout(fp),fp=setTimeout(()=>dp(``),3200)},pp=!1,mp=[{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 hp(){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 gp=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`?cp.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:lp}return cp[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},_p=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),vp=new Set([`system_note`]),yp=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 bp=location.hash.match(/[#&]token=([^&]+)/);bp&&(localStorage.setItem(`teapot.token`,decodeURIComponent(bp[1])),history.replaceState(null,``,location.pathname+location.search));var xp=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function Sp(){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<=sp,[ce,A]=v(se());C(()=>{let e=()=>A(se());window.addEventListener(`resize`,e),w(()=>window.removeEventListener(`resize`,e)),e()});let[le,j]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>sp:localStorage.getItem(`teapot.panel`)===`1`),ue=e=>{j(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},de=()=>ue(!le()),fe=()=>{le()&&ue(!1)},[pe,me]=v(!1),[he,ge]=v(localStorage.getItem(`teapot.theme`)??`dark`),[_e,ve]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[ye,be]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[xe,Se]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),I=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[Ce,Oe]=v(I?.matches??!1);C(()=>{let e=e=>Oe(e.matches);I?.addEventListener(`change`,e),w(()=>I?.removeEventListener(`change`,e))}),b(()=>{let e=_e()?Ce()?ye():xe():he();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=mp.find(t=>t.key===e)?.mode??`dark`});let[ke,Ae]=v(``),[je,Me]=v(``),[Ne,Pe]=v(``);b(()=>{let t=n();Pe(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[Ie,Le]=v([]),Re=()=>Object.keys(O().providers??{});async function ze(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);Le(t.models??[])}catch{Le([])}}let Be=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)}`:``},Ye=()=>{let e=je().trim()||H()?.model||``;if(!e)return``;let t=Ie().find(t=>t.id===e);if(!t)return``;let n=[],r=Be(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${Mp(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(` · `)},Ze=null;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||O().defaultProvider||Re()[0]||``;if(r){if(t!==Ze)Ze=t,S(()=>ke())!==i&&(Ae(i),ze(i)),S(()=>je())&&Me(``);else{let e=S(()=>ke());!S(()=>je())&&e!==i&&(Ae(i),ze(i))}}});let[Qe,$e]=v(!1),[et,tt]=v(!0),[it,at]=v(0),[ot,ct]=v(null),ft=()=>gt().startsWith(`[compact] `),pt=()=>ft()?gt().slice(10):gt();b(()=>{ot()||ht(e=>e?.text.startsWith(`[compact] `)?null:e)});let[mt,B]=v(new Map),V=()=>{let e=n();return e?mt().get(e)??null:null},ht=e=>{let t=n();t&&B(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})},[gt,_t]=v(``),[vt,yt]=v(0),bt=()=>vt(),[xt,St]=v(``),Ct;b(()=>{if(!V()){clearTimeout(Ct),Ct=void 0,_t(``),St(``);return}Ct||=setTimeout(()=>{Ct=void 0,_t(V()?.text??``),St(V()?.reasoning??``)},(V()?.text.length??0)>2e4?250:(V()?.text.length??0)>6e3?120:60)}),w(()=>clearTimeout(Ct)),b(()=>{B(t=>Ke(t,t=>e().find(e=>e.id===t)?.status)),yt(0)}),b(()=>{let e=gt(),t=V()?.reasoning??``;!e&&!t||et()&&requestAnimationFrame(()=>{et()&&Jn(!0)})}),b(()=>{let e=H()?.pendingPrompts??0,t=H()?.pendingPromptIds,n=At(),r=jt(n),i=rt(r,e,t);i!==r&&Mt(n,i)}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{qn()&&(tt(!0),at(0),Jn(!0))})};document.addEventListener(`visibilitychange`,e),w(()=>document.removeEventListener(`visibilitychange`,e))});let H=x(()=>e().find(e=>e.id===n())),wt=()=>{let e=H();return e?e.live??(e.status===`running`||e.status===`waiting`):!1},[Tt,Et]=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 Dt=new Map,[Ot,kt]=v([]),At=()=>i()||n()||`?`,jt=e=>Dt.get(e)??[],Mt=(e,t)=>{t.length===0?Dt.delete(e):Dt.set(e,t),At()===e&&kt(t)},[Nt,Pt]=v([]),[Ft,It]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[Lt,Rt]=v(!1),zt=()=>Nt().filter(e=>!e.read).length,Bt=e=>{Pt(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},Vt=t=>{let n=Nt().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Vt(r.id));return n},Ht=0,Ut=e=>{Pt(t=>[{...e,id:`n${++Ht}`,at:Date.now(),read:!1},...t].slice(0,50))},Wt=(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?Ut({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?Ut({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?Ut({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&Ut({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})},Gt=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))},Kt=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of f())if(_p.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}}),[qt,Jt]=v(new Set),Yt=e=>{e&&Jt(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},Xt=()=>Jt(new Set),Zt=x(()=>nt(f(),qt())),Qt=x(()=>{let{consumed:e}=Kt(),t=``;for(let e of f()){if(e._prevKind=t,!_p.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(!_p.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 Ot())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),d[e]=Je(t,Math.max(c.get(n)??0,r??0)||void 0)}return qe(d,Ot().filter(e=>!e.promptId||!(o.has(e.promptId)&&s.has(e.promptId))).map(e=>en(e)))}),$t=new Map;function en(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=$t.get(t);if(n)return n;$t.size>64&&$t.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:H()?.session??``,branch:H()?.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 $t.set(t,r),r}let tn=()=>$(`/api/config`).then(re).catch(()=>{}),[nn,rn]=v(!1);C(()=>{let e=()=>rn(!0);window.addEventListener(`teapot:unauthorized`,e),w(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[an,on]=v(``),[sn,cn]=v(!1),[ln,un]=v(!1),dn=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==dn?(dn=t,un(!1),on(r)):t&&!ln()&&on(r)});let fn=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:an(),notify:e})}),un(!1),cn(!0),Q(`tasks saved${e&&an().trim()?` & notification queued`:``}`),mn()}catch(e){Q(`save failed: ${e.message}`)}},pn=x(()=>{let e=0,t=0;for(let n of an().split(`
|
|
22
22
|
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),mn=()=>$(`/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(()=>{}),hn=()=>$(`/api/metrics`).then(te).catch(()=>{}),[gn,_n]=v([]),vn=()=>$(`/api/tasks`).then(e=>_n(e.tasks)).catch(()=>{}),yn=e=>gn().filter(t=>t.agent===e),[bn,xn]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),Sn=e=>{let t=new Set(bn());t.has(e)?t.delete(e):t.add(e),xn(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},Cn=t=>lt(e(),t),[wn,Tn]=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}})()),En=x(()=>{let e=new Set;for(let t of wn())t.startsWith(`chat:`)&&e.add(t);return e}),U=x(()=>st(e(),bn(),Ft(),En())),Dn=(t,r,i,a)=>{let o=new Set(wn());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||Cn(e().find(e=>e.id===i))===t)&&Q(`hid ${r} — click the header to show it`)}Tn(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},On=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,W=e=>{let t=kn().get(e)??0;return`${t} chat${t===1?``:`s`}`},kn=x(()=>ut(e())),An=x(()=>dt(e(),U(),wn())),jn=2e3,[G,Mn]=v(null),Nn=new Map;function Pn(e){return`${i()||(n()??`?`)}:${e.id}`}function Fn(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=Pn(r),a=Nn.get(i);if(t[n]=a??r,!a&&(Nn.set(i,r),Nn.size>6e3)){let e=Nn.keys().next().value;e!==void 0&&Nn.delete(e)}}return t}let[In,Ln]=v(!1),[Rn,zn]=v(!1),Bn=0,Vn=-1;function Hn(e){p(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of Fn(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function Un(){let e=n();if(!e||Rn()||In())return;if(f().length>=m()){zn(!0);return}let t=()=>{let e=Kn();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!Rn()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(f().length>=m()){zn(!0);return}let i=f().length;if(await Wn(),f().length===i)return;et()&&n()===e&&Jn(!0)}}async function Wn(){let e=n(),t=f()[0];if(!(!e||!t||In()||Rn())){Ln(!0);try{let r=Kn(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=G(),c=i(),l=c&&c!==e?`&session=${encodeURIComponent(c)}`:``,u=(await $(`/api/agents/${e}/events?limit=${jn}&before=${encodeURIComponent(t.id)}${l}${s?`&branch=${encodeURIComponent(s)}&lineage=true`:``}`)).events??[];if(u.length===0){zn(!0);return}if(n()!==e||f()[0]?.id!==t.id)return;Hn(u),requestAnimationFrame(()=>{if(n()===e){let e=Kn();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{Ln(!1)}}}async function Gn(e,t){let r=Bn,a=t??i()??``;try{let t=G(),i=r!==Vn||!g().length,o=a&&a!==e?`&session=${encodeURIComponent(a)}`:``,[s,c,l]=await Promise.all([$(`/api/agents/${e}/events?limit=${jn}${o}${t?`&branch=${encodeURIComponent(t)}&lineage=true`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:g()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(Vn=r),r!==Bn||n()!==e)return;p(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of Fn(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),Jr(l.skills??[])}catch{}}function Kn(){return document.querySelector(`.feed`)}function K(){let e=document.querySelector(`.composer textarea`);return 24+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function qn(){let e=Kn();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<K()}function Jn(e=!1){let t=Kn();t&&(e||et())&&(t.scrollTop=t.scrollHeight,at(0))}let Yn=new Map;function Xn(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 Zn(e,t=!0,o){let s=n(),l=i(),u=f(),g=m();Bn++,c().size||d();let _=Xn(e,o)??e;if(s!==e||_!==l){if(l&&u.length&&(Yn.set(l,{events:u,total:g,at:Date.now()}),Yn.size>6)){let e=[...Yn.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&Yn.delete(e[0])}p([]),Nn.clear(),Xt(),ct(null),at(0),tt(!0),ti=!1,ni=void 0}r(e),a(_),D(T.get(e)??``),Mn(null),zn(!1),Ln(!1),Mt(l||s||`?`,Ot()),kt(jt(_||e)),localStorage.setItem(`teapot.session`,e),sr(_,t);let v=Yn.get(_);v?.events.length&&(Fn(v.events),p(Fn(v.events)),h(v.total),requestAnimationFrame(()=>{n()===e&&Jn(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(mn).catch(()=>{}),await Gn(e,_),n()===e&&(ct(H()?.ctx?.compacting?{phase:String(H().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&Jn(!0)}),Un())}let[Qn,$n]=v(!1),er=null,tr=null;w(()=>er?.close());let nr=!1,rr=null;document.addEventListener(`visibilitychange`,()=>rr?.()),w(()=>{rr=null});let ir=!0;function ar(){let e=location.protocol===`https:`?`wss://`:`ws://`,r=new WebSocket(`${e}${location.host}/api/ws${xp()}`);er=r,r.onopen=()=>{if($n(!0),!ir){ir=!0;return}nr=!0,document.visibilityState===`visible`&&a()},r.onclose=()=>{$n(!1),setTimeout(ar,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`&&Ue(o.event)){B(e=>He(e,o.agentId));return}if(o.kind===`llm-delta`){if(B(e=>Ve(e,o.agentId,o)),o.agentId===n()){let e=String(o.reasoning??``),t=String(o.text??``);e&&!t?vt()||yt(Date.now()):(t||!e&&vt())&&yt(0)}return}if(o.kind===`compaction-progress`){if(o.agentId!==n())return;o.phase===`done`?ct(null):ct({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())&&Mt(At(),Ot().filter(e=>e.promptId!==t.promptId)),i.has(e)&&!vp.has(e)||(Wt(o.agentId,o.event),o.event?.agent!==n()))return}if(document.visibilityState===`hidden`){nr=!0;return}tr||=setTimeout(a,120)}},nr=!1;let a=async()=>{if(tr=null,await mn(),await hn(),n()){let e=f().at(-1)?.id,t=m();if(await Gn(n()),f().at(-1)?.id!==e){let e=V();e&&e.text?We({text:e.text.trim(),reasoning:``,at:e.at},f(),H()?.status)&&ht(null):e&&!e.text&&H()?.status!==`running`&&ht(null),et()?(Jn(!0),Bt(n())):at(it()+Math.max(0,m()-t))}}};rr=()=>{document.visibilityState===`visible`&&nr&&(nr=!1,a())}}let or=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function sr(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=or(),t=o().get(e);t&&(t!==n()||e!==i())&&Zn(t,!1,e||null)}),b(()=>{let e=H(),t=e?`${wt()?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=zt()>0?`(${zt()}) ${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(pe()){me(!1);return}if(Tt()){Et(null);return}if(se()&&le()){fe();return}let e=H();if(e&&wt()){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(mn);return}return}if(!(k()||ae())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)de();else if(e.key===`t`)ur();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=U().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&&Zn(t[i].id)}}});let[cr,lr]=v(localStorage.getItem(`teapot.term`)===`1`),ur=()=>{let e=!cr();lr(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[dr,fr]=v([]),[pr,mr]=v(0),[hr,gr]=v(-1),[_r,vr]=v(!1),[yr,br]=v(0),[xr,Sr]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),Cr=new Map,wr=0,Tr=[null,null],Er=()=>dr()[yr()===0?pr():hr()]??null;function Dr(e){if(!dr()[e])return;let t=yr(),n=t===0?pr():hr(),r=t===0?hr():pr(),i=e=>t===0?mr(e):gr(e),a=e=>t===0?gr(e):mr(e);if(r===e){a(n),i(e);return}n!==e&&i(e)}let Or=()=>kr();function kr(e){let t=e??n();if(!t)return;let r=dr().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}#${++wr}`,agentId:t,title:r===0?t:`${t}·${r+1}`};fr(e=>[...e,i]);let a=dr().length;yr()===0?mr(a):gr(a)}function Ar(e){let t=dr()[e];if(!t)return;let n=Cr.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),Cr.delete(t.key)}let r=dr().filter((t,n)=>n!==e);fr(r);let i=t=>t===e?-1:t>e?t-1:t;mr(e=>Math.min(i(e),r.length-1)),gr(e=>e===-1?-1:Math.min(i(e),r.length-1))}function jr(){for(let[,e]of Cr){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}Cr.clear()}function Mr(e,t){let n=Cr.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 tl({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:hp()}),a=new il;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${xp()}`);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},Cr.set(e.key,n)}return n}function Nr(e){let t=Tr[e];if(!t)return;let n=dr()[e===0?pr():hr()];if(!n){[...Cr.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Mr(n,t);for(let[e,r]of Cr)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(yr()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{dr(),_r(),pr(),hr(),xr(),requestAnimationFrame(()=>{Nr(0),_r()&&Nr(1)})});let Pr=null;b(()=>{if(!cr())return;let e=n();if(e&&e!==Pr){if(Pr=e,!dr().some(t=>t.agentId===e))kr(e);else{let t=-1;dr().forEach((n,r)=>{n.agentId===e&&(t=r)}),t>=0&&Dr(t)}}});let Fr=e=>{e.preventDefault();let t=e.clientY,n=xr(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Sr(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(xr())),requestAnimationFrame(()=>{Nr(0),_r()&&Nr(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},Ir=()=>{let e=!_r();if(vr(e),e){let e=dr().map((e,t)=>t).filter(e=>e!==pr());(hr()<0||hr()===pr()||hr()>=dr().length)&&gr(e[0]??-1)}requestAnimationFrame(()=>{Nr(0),_r()&&Nr(1)})};w(jr);let Lr=e=>t=>{Tr[e]=t,t&&requestAnimationFrame(()=>{Nr(e),_r()&&Nr(1),setTimeout(()=>Nr(e),200)})};C(()=>{tn(),mn().then(async()=>{await d();let t=or(),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&&Zn(r.id,!1,t||null)}),hn(),vn(),Vr(),ar();let t=setInterval(()=>{hn(),vn()},3e4);w(()=>clearInterval(t))});let Rr=[{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`}],[zr,Br]=v([]),Vr=()=>$(`/api/personas`).then(e=>Br(e.personas)).catch(()=>{}),[Hr,Ur]=v(!1),Wr=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},Gr=()=>{let t=Wr();return t===null?[]:[...zr().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))},Kr=new Set([`start`,`stop`,`fork`,`compact`]),[qr,Jr]=v([]),[Yr,Xr]=v(-1),Zr=()=>{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=Rr.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Kr.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=qr().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[]},Qr,$r=()=>{if(!Qr)return;ei=!0;let e=et();Qr.style.height=`auto`,Qr.style.height=Qe()?``:`${Math.min(Qr.scrollHeight,360)}px`,requestAnimationFrame(()=>{let t=Kn();e&&t&&(t.scrollTop=t.scrollHeight),ei=!1})},ei=!1,ti=!1,ni;b(()=>{ne(),$r()});let[ri,ii]=v([]),ai=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=()=>{ii(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},oi=async(e,t)=>{let r=t??n();if(!r)return;let i=ri();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}:{}})});Mt(At(),[...Ot(),{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)}:{}}]),ii([]),requestAnimationFrame(()=>requestAnimationFrame(()=>Jn(!0)))}catch(t){D(e),console.error(`send failed:`,t)}},si=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=zr().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:Hr()?`fork`:`none`})})).id}${Hr()?` (forked context)`:``}`),mn(),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: ${zr().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 ci(t,n)}catch(e){throw D(ne()?`${i}\n${ne()}`:i),e}return}D(``),await oi(i),Qe()&&$e(!1)}},ci=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(mn);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Zn(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 oi(`[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}`)}},li,ui=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!li)return;let e=Math.min(ui,li.scrollHeight);Math.abs(li.scrollTop-e)>1&&(li.scrollTop=e)})})});let di=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(mn),[fi,pi]=v(``),[mi,hi]=v(``),[gi,q]=v(!1),[_i,vi]=v(!0),yi=``;b(()=>{let e=n();e&&(H()?.goal,e!==yi&&(yi=e,q(!1),pi(``),hi(``)))});let bi=async e=>{if(e.preventDefault(),!(!n()||!fi().trim()))try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:fi(),notify:_i(),...mi().trim()?{verify:mi()}:{}})}),pi(``),hi(``),q(!1),mn()}catch(e){Q(`goal save failed: ${e.message}`)}};return[M(P,{get when(){return O()?.needsSetup},fallback:null,get children(){return M(Qp,{onDone:()=>location.reload()})}}),M(P,{get when(){return nn()},get children(){var e=ll();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),M(P,{get when(){return!O()?.needsSetup},get children(){var i=Ll(),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,z(o,M(N,{get each(){return An()},children:t=>[M(P,{get when(){return F(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=Ul(),n=e.firstChild;return e.$$click=()=>Dn(`ws:${t.wsHeader}`,On(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),z(n,()=>t.wsCollapsedGroup?`▸`:`▾`),z(e,()=>On(t.wsHeader),null),z(e,M(P,{get when(){return(kn().get(t.wsHeader)??0)>1||t.wsCollapsedGroup},get children(){var e=Hl();return z(e,()=>kn().get(t.wsHeader)??0),e}}),null),y(()=>L(e,`title`,t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${W(t.wsHeader)} hidden). Click to show.`:(kn().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${W(t.wsHeader)} in this directory`:t.wsHeader||``)),e}}),M(P,{get when(){return F(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=Jl(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>Zn(t.a.id),z(r,M(P,{get when(){return!t.a.parent||e().some(e=>e.parent===t.a.id)},get fallback(){return Yl()},get children(){return(()=>{let e=!t.a.parent,n=e?En().has(`chat:${t.a.id}`):bn().has(t.a.id);return(()=>{var r=Xl();return r.$$click=r=>{r.stopPropagation(),e?Dn(`chat:${t.a.id}`,t.a.id,n):Sn(t.a.id)},z(r,n?`▸`:`▾`),y(()=>L(r,`title`,e?n?`show ${t.a.id}`:`hide ${t.a.id} and its sub-agents`:n?`expand sub-agents`:`collapse sub-agents`)),r})()})()}}),i),z(a,()=>t.a.id),z(r,(()=>{var e=F(()=>!!t.a.workspaceMissing);return()=>e()?Zl():null})(),null),z(r,M(P,{get when(){return Vt(t.a.id)>0},get children(){var e=Wl();return e.firstChild,z(e,()=>Vt(t.a.id),null),y(()=>L(e,`title`,`${Vt(t.a.id)} unread notification${Vt(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),z(r,M(P,{get when(){return bn().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=Ql();return e.firstChild,R(e,`subcount`+(r>0?` live`:``)),z(e,()=>n.length,null),z(e,r>0?` · ▶${r}`:``,null),y(()=>L(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),z(r,M(P,{get when(){return t.a.parent},get children(){return Gl()}}),null),z(r,M(P,{get when(){return yn(t.a.id).length>0},get children(){var e=Kl();return y(()=>L(e,`title`,yn(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
|
|
24
|
-
`))),e}}),null),z(r,M(P,{get when(){return t.a.goal.status===`done`},get children(){return ql()}}),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&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),u!==e.i&&R(a,e.i=u),d!==e.n&&L(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}})]})),z(s,M(P,{get when(){return pe()},get children(){var e=dl(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;ve(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),z(e,M(P,{get when(){return!_e()},get fallback(){return[(()=>{var e=$l(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{be(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(t,M(N,{get each(){return mp.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=tu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ye()),e})(),(()=>{var e=eu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Se(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),z(t,M(N,{get each(){return mp.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=tu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=xe()),e})()]},get children(){var e=ul();return z(e,M(N,{each:mp,children:e=>(()=>{var t=nu(),n=t.firstChild;return t.$$click=()=>{ge(e.key),localStorage.setItem(`teapot.theme`,e.key)},z(n,()=>e.sw.map(e=>(()=>{var t=ru();return Ee(t,`background`,e),t})())),z(t,()=>e.label,null),y(n=>{var r=`themebtn`+(he()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=_e()),e}}),c),l.$$click=e=>{e.stopPropagation(),Rt(!Lt()),Lt()||Pt(e=>e.map(e=>({...e,read:!0})))},z(l,M(P,{get when(){return zt()>0},get children(){var e=fl();return z(e,zt),e}}),null),z(c,M(Fp,{icon:`👻`,get active(){return Ft()},get title(){return Ft()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!Ft();if(It(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&H()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Zn(t.id)}}}),null),z(c,M(Fp,{icon:`+`,title:`new agent`,onClick:()=>{tn(),ie(!0)}}),null),z(c,M(Fp,{icon:`🎨`,title:`themes`,onClick:()=>me(!pe())}),null),z(c,M(Fp,{icon:`⚙`,title:`settings`,onClick:()=>{tn(),oe(!0)}}),null),z(m,`0.26.
|
|
24
|
+
`))),e}}),null),z(r,M(P,{get when(){return t.a.goal.status===`done`},get children(){return ql()}}),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&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),u!==e.i&&R(a,e.i=u),d!==e.n&&L(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}})]})),z(s,M(P,{get when(){return pe()},get children(){var e=dl(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;ve(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),z(e,M(P,{get when(){return!_e()},get fallback(){return[(()=>{var e=$l(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{be(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(t,M(N,{get each(){return mp.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=tu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ye()),e})(),(()=>{var e=eu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{Se(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),z(t,M(N,{get each(){return mp.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=tu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=xe()),e})()]},get children(){var e=ul();return z(e,M(N,{each:mp,children:e=>(()=>{var t=nu(),n=t.firstChild;return t.$$click=()=>{ge(e.key),localStorage.setItem(`teapot.theme`,e.key)},z(n,()=>e.sw.map(e=>(()=>{var t=ru();return Ee(t,`background`,e),t})())),z(t,()=>e.label,null),y(n=>{var r=`themebtn`+(he()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=_e()),e}}),c),l.$$click=e=>{e.stopPropagation(),Rt(!Lt()),Lt()||Pt(e=>e.map(e=>({...e,read:!0})))},z(l,M(P,{get when(){return zt()>0},get children(){var e=fl();return z(e,zt),e}}),null),z(c,M(Fp,{icon:`👻`,get active(){return Ft()},get title(){return Ft()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!Ft();if(It(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&H()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Zn(t.id)}}}),null),z(c,M(Fp,{icon:`+`,title:`new agent`,onClick:()=>{tn(),ie(!0)}}),null),z(c,M(Fp,{icon:`🎨`,title:`themes`,onClick:()=>me(!pe())}),null),z(c,M(Fp,{icon:`⚙`,title:`settings`,onClick:()=>{tn(),oe(!0)}}),null),z(m,`0.26.3`,null),z(v,M(P,{get when(){return ee()},get children(){return[`master rss `,F(()=>ee().rssMb),`MB · heap `,F(()=>ee().heapUsedMb),`MB`,pl(),`load1 `,F(()=>ee().loadavg1),` · up `,F(()=>Math.floor(ee().uptimeSec/60)),`m`]}})),z(S,M(P,{get when(){return H()?.id},keyed:!0,get fallback(){return iu()},get children(){return[(()=>{var e=_l(),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 z(t,()=>H().id),z(n,()=>H().status),z(e,M(P,{get when(){return(H().pendingPrompts??0)>0},get children(){var e=ml(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>H().pendingPrompts,t),z(e,()=>H().status===`stopped`?` (stopped)`:``,null),y(()=>L(e,`title`,H().status===`stopped`?`${H().pendingPrompts} message${(H().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.`:`${H().pendingPrompts??0} message${(H().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),z(e,M(P,{get when(){return yn(H().id).length>0},get children(){var e=hl();return e.firstChild,z(e,()=>yn(H().id).length,null),y(()=>L(e,`title`,`scheduled tasks:\n${yn(H().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
|
|
25
25
|
`)}`)),e}}),r),z(r,()=>H().model,i),z(r,()=>H().session,a),z(r,()=>H().branch,o),z(r,()=>H().stats.turns,s),z(r,()=>H().stats.toolCalls,null),z(c,M(P,{get when(){return H().statusReason},get children(){var e=gl();return y(()=>L(e,`title`,H().statusReason)),e}}),null),z(c,M(Fp,{icon:`⌨`,title:`terminal (t)`,onClick:ur}),null),z(c,M(Fp,{icon:`▤`,title:`toggle details panel (d)`,onClick:de}),null),y(()=>R(n,`badge ${H().status}`)),e})(),(()=>{var e=wl();return e.addEventListener(`scroll`,e=>{if(ei)return;let t=e.currentTarget,r=qn(),i=t.scrollHeight-t.scrollTop-t.clientHeight;if(!r&&ni!==void 0&&i>ni+8&&i>24?ti=!0:r&&(ti=!1),ni=i,t.scrollTop<=4&&n()&&!In()&&!Rn()&&f().length>0&&Wn(),ti&&!r){tt(!1);return}r&&it()&&at(0),tt(r)}),z(e,M(P,{get when(){return ot()},children:e=>(()=>{var t=au();return t.firstChild,z(t,(()=>{var t=F(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Mp(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),z(e,M(P,{get when(){return F(()=>!!Rn())()&&Qt().length>0},get children(){return vl()}}),null),z(e,M(P,{get when(){return In()},get children(){return yl()}}),null),z(e,M(P,{get when(){return Qt().length>0},get fallback(){return ou()},get children(){return[M(N,{get each(){return Qt()},children:(e,t)=>M(Dp,{e,get prev(){return Qt()[t()-1]},get res(){return Kt().resFor.get(e.id)},get orphan(){return Kt().orphanCalls.has(e.id)},onOption:e=>void oi(e),answeredIds:Zt,onAnswered:Yt,get agentActive(){return F(()=>!!wt())()&&Ge(e)},onResize:()=>{et()&&requestAnimationFrame(()=>Jn(!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),Mt(At(),Ot().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?()=>Et({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),M(P,{get when(){return V()},get children(){var e=Cl(),t=e.firstChild.nextSibling;return t.firstChild,z(t,M(P,{get when(){return xt()},get children(){var e=bl(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return z(t,M(wp,{get startedAt(){return bt()}}),null),De(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{xt(),t&&(e.scrollTop=e.scrollHeight)})},n),z(n,xt),e}}),null),z(t,M(P,{get when(){return gt()},get fallback(){return su()},get children(){return M(P,{get when(){return ft()},get fallback(){return(()=>{var e=Sl();return y(()=>e.innerHTML=Fe(gt()+`▍`)),e})()},get children(){return[xl(),(()=>{var e=Sl();return y(()=>e.innerHTML=Fe(pt()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),M(P,{get when(){return cr()},get children(){var t=kl(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Sr(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(xr()))},n.$$pointerdown=Fr,z(i,M(N,{get each(){return dr()},children:(e,t)=>(()=>{var n=cu(),r=n.firstChild.nextSibling;return n.$$click=()=>Dr(t()),z(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Ar(t())},y(r=>{var i=`termtab`+(yr()===0&&pr()===t()?` active`:``)+(_r()&&yr()===1&&hr()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),z(i,M(Fp,{icon:`+`,title:`new shell in this workspace`,onClick:Or}),null),z(o,(()=>{var t=F(()=>!!Er());return()=>t()?e().find(e=>e.id===Er().agentId)?.workspace.split(`/`).filter(Boolean).pop():H()?.workspace})()),z(a,M(Fp,{icon:`◫`,get title(){return _r()?`single pane`:`split panes (50/50)`},onClick:Ir}),null),z(a,M(Fp,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:ur}),null);var l=Lr(0);return typeof l==`function`&&De(l,c),c.$$pointerdown=()=>br(0),z(c,M(P,{get when(){return pr()<0||pr()>=dr().length},get children(){return Tl()}})),z(s,M(P,{get when(){return _r()},get children(){return[El(),(()=>{var e=Ol(),t=Lr(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>br(1),z(e,M(P,{get when(){return hr()<0||hr()>=dr().length},get children(){return Dl()}})),y(()=>e.classList.toggle(`focused`,yr()===1)),e})()]}}),null),y(e=>{var n={height:`${xr()}px`,"--termh":`${xr()}px`},r=!!_r(),i=yr()===0;return e.e=Te(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=Fl(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling,o=t.nextSibling;z(e,M(P,{get when(){return!et()||it()>0},get children(){var e=Al();return e.firstChild,e.$$click=()=>Jn(!0),z(e,(()=>{var e=F(()=>it()>0);return()=>e()?`${it()} new message${it()>1?`s`:``}`:`jump to present`})(),null),e}}),t),z(e,M(P,{get when(){return Zr().length>0},get children(){var e=jl();return z(e,M(N,{get each(){return Zr()},children:(e,t)=>(()=>{var n=lu(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{D(e.insert),Xr(-1)},z(r,()=>e.insert.trim()),z(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===Yr()?` active`:``),a=e.title;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),z(e,M(P,{get when(){return Gr().length>0},get children(){var e=jl();return z(e,M(N,{get each(){return Gr()},children:e=>(()=>{var t=uu(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{D(`@${e.key} `),Xr(-1)},z(n,()=>e.key,null),z(r,()=>e.label),y(()=>L(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,si),z(t,M(P,{get when(){return ri().length>0},get children(){var e=Ml(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,z(e,M(N,{get each(){return ri()},children:(e,t)=>(()=>{var n=du(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>ii(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&L(n,`title`,t.e=i),a!==t.t&&L(r,`src`,t.t=a),o!==t.a&&L(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),z(t,()=>ri().length,n),z(t,()=>ri().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=Zr();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),Xr(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),Xr(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&Yr()>=0&&!pp){e.preventDefault(),D(t[Yr()].insert),Xr(-1);return}if(e.key===`Escape`&&t.length>0){Xr(-1);return}e.key===`Enter`&&!e.shiftKey&&!pp&&(e.preventDefault(),si(e))},n.$$input=e=>{D(e.currentTarget.value),Xr(0),$r()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),ai(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{pp=!1})}),n.addEventListener(`compositionstart`,()=>{pp=!0});var s=Qr;return typeof s==`function`?De(s,n):Qr=n,z(t,M(P,{get when(){return F(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=Nl(),t=e.firstChild;return t.addEventListener(`change`,e=>Ur(e.currentTarget.checked)),y(()=>t.checked=Hr()),e}}),r),r.$$click=()=>{let e=!Qe();$e(e),requestAnimationFrame(()=>$r())},z(r,()=>Qe()?`⤡`:`⤢`),z(t,M(Fp,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),z(t,M(P,{get when(){return ri().length},get children(){var e=Pl();return e.firstChild,z(e,()=>ri().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&ai(e.currentTarget.files),e.currentTarget.value=``}),z(o,()=>up()||`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`+(Qe()?` maximized`:``),a=`message #${H().id} — / for commands · paste or 📎 to attach images`,o=Qe()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&R(e,t.e=i),a!==t.t&&L(n,`placeholder`,t.t=a),o!==t.a&&L(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),y(()=>n.value=ne()),e})()]}})),z(i,M(P,{get when(){return F(()=>!!ce())()&&le()},get children(){var e=Il();return e.$$click=()=>ue(!1),e}}),C),C.addEventListener(`scroll`,e=>{ui=e.currentTarget.scrollTop});var te=li;return typeof te==`function`?De(te,C):li=C,z(w,M(Fp,{icon:`✕`,title:`close details panel (esc)`,onClick:fe}),null),z(C,M(P,{get when(){return H()?.id},keyed:!0,fallback:null,children:i=>[fu(),(()=>{var e=pu(),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 z(n,()=>H().id),z(r,()=>H().status),z(a,()=>H().workspace),z(o,()=>H().session,s),z(o,()=>H().branch,null),y(e=>{var t=`badge ${H().status}`,n=H().workspace;return t!==e.e&&R(r,e.e=t),n!==e.t&&L(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),M(P,{get when(){return H().id},keyed:!0,fallback:null,children:e=>M(Jp,{agentId:e,get workspace(){return H().workspace}})}),mu(),(()=>{var e=_u(),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=>{Ae(e.currentTarget.value),ze(e.currentTarget.value)}),z(t,M(N,{get each(){return Re()},children:e=>(()=>{var t=tu();return t.value=e,z(t,e,null),z(t,()=>e===O().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>Me(e.currentTarget.value),z(a,M(N,{get each(){return Ie()},children:e=>(()=>{var t=tu();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:ke(),model:je().trim()||void 0,contextWindowTokens:Ie().find(e=>e.id===(je().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,mn()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},z(e,M(P,{get when(){return H().effortSupported},get children(){var e=hu(),t=e.firstChild.nextSibling;t.firstChild;var r=t.nextSibling;return t.addEventListener(`change`,e=>Pe(e.currentTarget.value)),z(t,M(N,{each:op,children:e=>(()=>{var t=tu();return t.value=e,z(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:Ne()})}),t.textContent=`✓ applied`,mn()}catch(e){alert(`effort change failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},y(()=>t.value=Ne()),e}}),s),z(s,()=>H().model,null),z(s,M(P,{get when(){return Ie().length},get children(){return[` · `,F(()=>Ie().length),` models loaded`]}}),null),z(e,M(P,{get when(){return Ye()},get children(){var e=gu();return z(e,Ye),e}}),null),y(()=>L(i,`placeholder`,H().model)),y(()=>t.value=ke()),y(()=>i.value=je()),e})(),vu(),(()=>{var i=bu(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling;return we(a,`click`,wt()?di(`/stop`):di(`/start`),!0),z(a,()=>wt()?`■ stop`:`▶ start`),o.$$click=()=>$(`/api/agents/${H().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await d(!0),await Zn(H().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]?Zn(a[0].id):(r(null),p([]))},z(i,M(P,{get when(){return e().some(e=>e.parent===n())},get children(){var e=yu();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),mn())},e}}),null),y(e=>{var t=wt()?`danger`:`runbtn`,n=wt()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&R(a,e.e=t),n!==e.t&&L(a,`title`,e.t=n),e},{e:void 0,t:void 0}),i})(),(()=>{var e=xu(),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(mn)}),y(()=>t.checked=H().autoContinue??!0),e})(),(()=>{var e=Cu();return e.firstChild,z(e,M(P,{get when(){return!!H().goal.text.trim()},get fallback(){return Vu()},get children(){var e=Su();return z(e,()=>H().goal.status),y(()=>R(e,`badge ${H().goal.status===`active`?`running`:H().goal.status}`)),e}}),null),e})(),(()=>{var e=wu();return e.firstChild,z(e,M(N,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Hu();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(mn)},L(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),z(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(H().goal.text.trim()&&H().goal.status===e?` on ${e}`:``),i=!!H().goal.text.trim()&&H().goal.status===e;return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),M(P,{get when(){return H().goal.text},get fallback(){return Uu()},get children(){return[(()=>{var e=Tu(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(H().goal.text))),e})(),M(P,{get when(){return H().goal.verify},get children(){var e=Eu(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(H().goal.verify))),e}}),M(P,{get when(){return H().goal.audit},children:e=>(()=>{var t=Wu(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return z(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),z(r,()=>jp(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=Xe(e().feedback)?Fe(`_the auditor returned a verdict with no detail_`):Fe(e().feedback);return r!==n.e&&R(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),Du(),(()=>{var e=Ou(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,bi),t.$$input=e=>{pi(e.currentTarget.value),q(!0)},n.$$input=e=>{hi(e.currentTarget.value),q(!0)},r.addEventListener(`change`,e=>vi(e.currentTarget.checked)),y(()=>t.value=fi()),y(()=>n.value=mi()),y(()=>r.checked=_i()),e})(),(()=>{var e=Au(),t=e.firstChild.nextSibling;return z(e,M(P,{get when(){return pn().total>0},get children(){var e=ku(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,z(e,()=>pn().done,t),z(e,()=>pn().total,n),y(t=>Te(e,pn().done===pn().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),M(P,{get when(){return pn().total>0},get children(){var e=ju(),t=e.firstChild;return y(e=>{var n=`barfill `+(pn().done===pn().total?``:`warn`),r=`${Math.round(pn().done/pn().total*100)}%`;return n!==e.e&&R(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),M(qp,{get draft(){return an()},get viewMode(){return sn()},onDraft:e=>{on(e),un(!0)}}),(()=>{var e=Mu(),t=e.firstChild,n=t.nextSibling;return z(e,M(Fp,{get icon(){return sn()?`👁`:`✎`},get title(){return sn()?`rendered checklist`:`edit markdown`},onClick:()=>cn(!sn())}),t),n.$$click=fn,e})(),Nu(),M(P,{get when(){return H().latestProgress},get fallback(){return Gu()},children:e=>(()=>{var t=Xu(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return z(t,M(P,{get when(){return e().recent},get children(){var t=Ku(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=ap(e().recent)),t}}),i),z(t,M(P,{get when(){return e().problems},get children(){var t=qu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=ap(e().problems)),t}}),i),z(t,M(P,{get when(){return e().next},get children(){var t=Ju(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=ap(e().next)),t}}),i),z(t,M(P,{get when(){return e().goalStatus},get children(){var t=Yu(),n=t.firstChild.nextSibling;return z(n,()=>e().goalStatus),t}}),i),z(i,()=>jp(e().ts)),y(()=>r.innerHTML=ap(e().doing)),t})()}),Pu(),(()=>{var e=Lu(),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,z(i,()=>H().stats.turns),z(o,()=>H().stats.toolCalls),z(s,()=>H().stats.compactions??0),z(l,()=>Mp(H().stats.inputTokens),u),z(l,()=>Mp(H().stats.outputTokens),d),z(c,M(P,{get when(){return(H().stats.cachedInputTokens??0)>0},get children(){var e=Fu(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>Math.round(H().stats.cachedInputTokens/Math.max(1,H().stats.inputTokens)*1e3)/10,t),y(()=>L(e,`title`,`${Mp(H().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),z(e,M(P,{get when(){return(H().stats.costUsd??0)>0},get children(){var e=Iu(),t=e.firstChild.nextSibling;return t.firstChild,z(t,()=>Np(H().stats.costUsd??0),null),y(()=>L(e,`title`,`≈ ${(H().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),z(e,M(P,{get when(){return H().ctx},keyed:!0,get fallback(){return Zu()},children:e=>{let t=x(()=>{let t=e,n=Ie().find(e=>e.id===H().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=nd(),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,z(a,()=>Mp(r().usedTokens),o),z(t,M(P,{get when(){return r().effectiveWindow},get children(){var e=Qu(),t=e.firstChild;return z(e,()=>i(r().pct),t),z(e,()=>Mp(r().effectiveWindow),null),y(()=>R(e,`pill ${r().cls}`)),e}}),null),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=$u(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),z(c,()=>Mp(r().usingDerived?r().derivedBudget:r().compactAt),l),z(u,()=>r().usingDerived?` (75% of window)`:` (manual override)`),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=ed(),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&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),d),z(e,M(P,{get when(){return ot()||r().compacting},get children(){var e=td(),t=e.firstChild.nextSibling.nextSibling;return z(t,()=>ot()?.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(mn)}),z(p,()=>Mp(r().compactAt),m),y(()=>f.checked=H().autoCompact!==!1),e})()}}),null),e})(),(()=>{var e=zu();return e.firstChild.nextSibling,z(e,M(P,{get when(){return G()},get children(){var e=Ru(),t=e.firstChild.nextSibling;return z(t,G),e}}),null),e})(),M(N,{get each(){return g()},children:e=>(()=>{var t=rd(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=G()===e.branch?null:e.branch,r=t!==G();Mn(t),n()&&(r&&(Bn++,p([]),h(0),zn(!1)),Gn(n()))},z(r,()=>e.branch,null),z(r,()=>e.branch===H().branch?` (current)`:``,null),z(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===H().branch||e.branch===G()?` cur`:``),i=e.branch===G()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Bu(),M(P,{get when(){return gn().length>0},get fallback(){return id()},get children(){return M(N,{get each(){return gn()},children:e=>(()=>{var t=od(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Zn(e.agent),z(i,()=>e.id),z(a,()=>e.agent,null),z(r,M(P,{get when(){return e.forked},get children(){return ad()}}),null),z(o,()=>e.schedule,s),z(o,(()=>{var t=F(()=>!!e.next);return()=>t()?jp(e.next):`—`})(),null),z(o,(()=>{var t=F(()=>!!e.last);return()=>t()?` · last ${jp(e.last)}`:` · never ran`})(),null),z(c,()=>Pp(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Pp(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&R(t,r.e=i),a!==r.t&&L(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var t=`layout`+(le()?``:` right-hidden`),n=`iconbtn notifbtn`+(zt()>0?` has-unread`:``),r=zt()>0?`${zt()} unread notifications`:`notifications`,a=`conn`+(Qn()?` ok`:``),o=Qn()?`live (websocket)`:`reconnecting…`,s=`rightbar`+(le()?` open`:``);return t!==e.e&&R(i,e.e=t),n!==e.t&&R(l,e.t=n),r!==e.a&&L(l,`title`,e.a=r),a!==e.o&&R(_,e.o=a),o!==e.i&&L(_,`title`,e.i=o),s!==e.n&&R(C,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),i}}),M(P,{get when(){return Lt()},get children(){return[(()=>{var e=Rl();return e.$$click=()=>Rt(!1),e})(),(()=>{var t=Vl(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return z(r,M(P,{get when(){return Nt().length>0},get children(){var e=zl();return e.$$click=()=>Pt([]),e}}),i),i.$$click=()=>Rt(!1),z(t,M(P,{get when(){return Nt().length>0},get fallback(){return sd()},get children(){var t=Bl();return z(t,M(N,{get each(){return Nt()},children:t=>(()=>{var r=ld(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{Pt(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&Zn(t.agentId),Rt(!1),t.eventId&&setTimeout(()=>Gt(t.eventId),n()===t.agentId?60:350)},z(i,(()=>{var e=F(()=>t.kind===`finish`);return()=>e()?`✅`:F(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),z(a,()=>t.title),z(o,()=>jp(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),Pt(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},z(s,()=>t.read?`✓`:`○`),z(r,M(P,{get when(){return t.body},get children(){var e=cd();return z(e,()=>Ap(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&R(r,e.e=n),i!==e.t&&L(r,`title`,e.t=i),a!==e.a&&L(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),M(P,{get when(){return k()},get children(){return M(zp,{get providers(){return Object.keys(O().providers??{})},onClose:()=>ie(!1),onCreated:e=>{ie(!1),mn(),Zn(e)}})}}),M(P,{get when(){return ae()},get children(){return M($p,{get cfg(){return O()},onClose:()=>oe(!1),onSaved:()=>{tn(),vn()}})}}),M(P,{get when(){return Tt()},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 M(Rp,{title:`edit prompt — forks the conversation`,onClose:()=>Et(null),get children(){var t=dd(),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()})}),Et(null),mn();let t=n();t&&await Zn(t)}catch(e){alert(`edit failed: ${e.message}`)}}),z(t,M(P,{get when(){return r()>0},get children(){var e=ud(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return z(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>Et(null),y(()=>o.value=e().text),t}})}})]}function Cp(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=()=>Be(Math.max(0,n()-t));return e.inline?(()=>{var t=fd();return t.firstChild,z(t,i,null),z(t,(()=>{var t=F(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=pd(),t=e.firstChild;return z(e,i,t),e})()}function wp(e){let[t,n]=v(Date.now());return C(()=>{let e=setInterval(()=>n(Date.now()),500);w(()=>clearInterval(e))}),(()=>{var n=md();return z(n,()=>Be(Math.max(0,t()-e.startedAt))),n})()}function Tp(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=hd();return z(e,()=>Ap(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=gd();return z(n,()=>Ap(e,t)),n})(),m=(e=4e3)=>n?[F(()=>p(o(),e)),(()=>{var e=_d();return z(e,()=>Be(n.data?.durationMs),null),z(e,()=>a===`bash`?at(it(n.data?.ok,String(n.data?.result??``))):n.data?.ok===!1?` · FAILED`:``,null),z(e,M(Lp,{get text(){return o()}}),null),e})()]:vd();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?`⏳ `:`$ `)+Pp(e,96);let a=u(`timeout_ms`)?Number(u(`timeout_ms`)):void 0,d=it(n?.data?.ok,n?String(n.data?.result??``):``);c=n?t?`background job${r?` ${r}`:``}${a?` · timeout ${Math.round(a/1e3)}s`:``}`:ot({outcome:d,durationMs:n.data?.durationMs,timeoutMs:a,fmtDur:Be}):null,l=[t?(()=>{var e=yd(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,z(t,r||`?`,n),z(e,r?[` · kill with `,bd()]:null,null),e})():null,F(()=>F(()=>e!==s.slice(2))()?p(e,800):null),F(()=>m(6e3))];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${Pp(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=`${Mp(e.length)} bytes`,l=[F(()=>p(e,1500)),F(()=>F(()=>e.length>1500)()?(()=>{var t=xd(),n=t.firstChild;return z(t,()=>Mp(e.length),n),t})():null),n?(()=>{var e=_d();return z(e,()=>Pp(o(),160)),e})():Sd()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=Cd();return z(e,()=>Ap(`- `+u(`old_text`),900)),e})(),(()=>{var e=wd();return z(e,()=>`+ `+Ap(u(`new_text`),900)),e})(),n?(()=>{var e=Td(),t=e.firstChild;return z(e,()=>Pp(o(),120),t),z(e,()=>Be(n.data?.durationMs),null),e})():Ed()];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`:``}: ${Pp(t.join(`, `),80)}`:`patch`;let r=e.slice(0,60);l=[(()=>{var t=Dd();return z(t,()=>r.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Od();return R(n,`pline`+t),z(n,(()=>{var t=F(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),z(t,(()=>{var t=F(()=>e.length>60);return()=>t()?(()=>{var t=kd(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.length-60,n),t})():null})(),null),t})(),n?(()=>{var e=_d();return z(e,()=>Pp(o().split(`
|
|
27
|
-
`)[0]??``,140),null),z(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Ad()];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=Pp(e,70),c=`web`,l=[(()=>{var e=_d();return z(e,M(P,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Md();return z(e,()=>Pp(u(`url`),80)),e})()},get children(){var e=jd();return y(()=>L(e,`href`,u(`url`))),e}})),e})(),F(()=>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=Sl();return y(()=>t.innerHTML=Fe(e)),t})(),(()=>{var e=_d();return z(e,()=>Be(n.data?.durationMs)),e})()]:Nd();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Pp(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[F(()=>F(()=>!!e.length)()?(()=>{var t=Pd();return t.firstChild,z(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Td(),t=e.firstChild;return z(e,()=>Pp(o(),160),t),z(e,()=>Be(n.data?.durationMs),null),e})():Fd()];break}}}catch{}return(()=>{var i=Ld(),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?.()}),L(i,`title`,`${a}${c?` — `+c:``}`),z(p,s,null),z(u,M(P,{get when(){return t.data?.actor},get children(){var e=Id();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),m),z(m,()=>n?c||``:r?`(result missed)`:a===`bash`||f()?M(Cp,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return f()}}):`running…`),z(h,M(Lp,{get text(){return d()},label:`⧉ cmd`,title:`copy the ${a} arguments`}),null),z(h,M(P,{when:n,get children(){return M(Lp,{get text(){return o()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(i,l,null),y(()=>R(i,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),i})()}function Ep(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 Dp(e){let t=e.e,n=gp(t),r=tt(e.prev,t);if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Rd(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=Qe(t.data??{});return(()=>{var t=zd(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=Od();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Bd(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Vd(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Hd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Ud(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Od();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=Wd(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Gd(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var i=Yd(),a=i.firstChild,o=a.nextSibling;return R(a,`avatar avghost`+(r?` ghosted`:``)),z(a,()=>r?``:n.icon),z(o,r&&(()=>{var e=Xd();return y(()=>L(e,`title`,`${yp(t.ts)} · ${t.branch}`)),e})(),null),z(o,M(P,{when:!r,get children(){var r=Jd(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=Id();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:yp(t.ts)})()),z(o,()=>t.branch),z(r,M(P,{get when(){return e.onCancel},get children(){var t=Kd();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(Lp,{get text(){return Ep(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=qd();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(o,M(kp,{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?`${yp(t.ts)} · ${t.branch}`:void 0;return o!==e.e&&R(i,e.e=o),s!==e.t&&L(i,`data-eid`,e.t=s),c!==e.a&&Ee(a,`background`,e.a=c),l!==e.o&&Ee(a,`border`,e.o=l),u!==e.i&&L(a,`title`,e.i=u),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),i})()}function Op(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=Zd(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&L(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function kp(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Sl();return y(()=>e.innerHTML=ap(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=Qd();return z(t,M(N,{each:e,children:e=>(()=>{var t=$d();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=ef(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Mp(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>Ap(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Sl();return y(()=>e.innerHTML=ap(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return tf()}}),M(P,{get when(){return t.data.final},get children(){var e=nf(),n=e.firstChild;return z(e,M(Lp,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(Tp,{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=af(),o=a.firstChild,s=o.firstChild.nextSibling,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(Lp,{text:n}),null),z(c,()=>Ap(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?at(it(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return rf()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=sf(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=of();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=ap(String(t.data?.decision??``)),r=ap(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=uf(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return cf()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=lf();return z(a,M(N,{each:n,children:n=>(()=>{var a=df();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M(Op,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=ap(String(t.data?.question??``));return n!==e.e&&R(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=ff(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=Yu(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=Ku(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=ap(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=qu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=ap(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=Ju(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=ap(String(t.data.next))),e}}),null),y(()=>n.innerHTML=ap(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=pf(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=hf(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>Mp(Number(t.data.tokensBefore??0)),i),z(n,()=>Mp(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[mf(),(()=>{var e=Sl();return y(()=>e.innerHTML=ap(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=gf();return z(e,()=>Ap(JSON.stringify(t.data),200)),e})()}}function Ap(e,t){return e.length>t?e.slice(0,t)+` …`:e}function jp(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 Mp(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 Np(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 Pp(e,t){return Ap(e.replace(/\s+/g,` `).trim(),t)}function Fp(e){return(()=>{var t=_f(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}async function Ip(e){if(!e)return`unsupported`;let t=typeof navigator<`u`?navigator.clipboard?.writeText:void 0;if(typeof t==`function`)try{return await t.call(navigator.clipboard,e),`copied`}catch{}let n=null;try{return n=document.createElement(`textarea`),n.value=e,n.style.position=`fixed`,n.style.opacity=`0`,document.body.appendChild(n),n.select(),document.execCommand(`copy`)?`copied`:`failed`}catch{return`failed`}finally{n?.remove()}}function Lp(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),Ip(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=vf();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function Rp(e){return(()=>{var t=yf(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function zp(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 M(Rp,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=xf(),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(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=Sf();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),C.$$input=e=>o(e.currentTarget.value),ee.addEventListener(`change`,e=>c(e.currentTarget.value)),z(ee,M(N,{get each(){return e.providers},children:e=>(()=>{var t=tu();return z(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=bf();return z(e,d),e}}),T),y(()=>h.value=t()),y(()=>C.value=a()),y(()=>ee.value=s()),y(()=>te.value=l()),i}})}var Bp=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Vp=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Hp=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Up(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Wp(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 Wp(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Bp.has(t)?`image`:Vp.has(t)?`video`:Hp.has(t)?`audio`:null}var Gp=new Map,Kp=e=>{let t=Gp.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Gp.set(e,t)),t};function qp(e){return M(P,{get when(){return e.viewMode},get fallback(){return(()=>{var t=wf();return y(()=>t.innerHTML=ap(e.draft)),t})()},get children(){var t=Cf();return t.$$input=t=>e.onDraft(t.currentTarget.value),y(()=>t.value=e.draft),t}})}function Jp(e){let t=Kp(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(``),[j,ue]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await cl(async()=>{let{highlightChunks:e}=await import(`./shiki-DrXpGTVJ.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};w(()=>{fe++});let me=async(t,n)=>{let r=Wp(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`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(!(!t||j())){ue(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
27
|
+
`)[0]??``,140),null),z(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Ad()];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=Pp(e,70),c=`web`,l=[(()=>{var e=_d();return z(e,M(P,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Md();return z(e,()=>Pp(u(`url`),80)),e})()},get children(){var e=jd();return y(()=>L(e,`href`,u(`url`))),e}})),e})(),F(()=>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=Sl();return y(()=>t.innerHTML=Fe(e)),t})(),(()=>{var e=_d();return z(e,()=>Be(n.data?.durationMs)),e})()]:Nd();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Pp(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[F(()=>F(()=>!!e.length)()?(()=>{var t=Pd();return t.firstChild,z(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Td(),t=e.firstChild;return z(e,()=>Pp(o(),160),t),z(e,()=>Be(n.data?.durationMs),null),e})():Fd()];break}}}catch{}return(()=>{var i=Ld(),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?.()}),L(i,`title`,`${a}${c?` — `+c:``}`),z(p,s,null),z(u,M(P,{get when(){return t.data?.actor},get children(){var e=Id();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),m),z(m,()=>n?c||``:r?`(result missed)`:a===`bash`||f()?M(Cp,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return f()}}):`running…`),z(h,M(Lp,{get text(){return d()},label:`⧉ cmd`,title:`copy the ${a} arguments`}),null),z(h,M(P,{when:n,get children(){return M(Lp,{get text(){return o()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(i,l,null),y(()=>R(i,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),i})()}function Ep(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 Dp(e){let t=e.e,n=gp(t),r=tt(e.prev,t);if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Rd(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=Qe(t.data??{});return(()=>{var t=zd(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=Od();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Bd(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Vd(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Hd(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Ud(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Od();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=Wd(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Gd(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var i=Yd(),a=i.firstChild,o=a.nextSibling;return R(a,`avatar avghost`+(r?` ghosted`:``)),z(a,()=>r?``:n.icon),z(o,r&&(()=>{var e=Xd();return y(()=>L(e,`title`,`${yp(t.ts)} · ${t.branch}`)),e})(),null),z(o,M(P,{when:!r,get children(){var r=Jd(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=Id();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:yp(t.ts)})()),z(o,()=>t.branch),z(r,M(P,{get when(){return e.onCancel},get children(){var t=Kd();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(Lp,{get text(){return Ep(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=qd();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(o,M(kp,{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?`${yp(t.ts)} · ${t.branch}`:void 0;return o!==e.e&&R(i,e.e=o),s!==e.t&&L(i,`data-eid`,e.t=s),c!==e.a&&Ee(a,`background`,e.a=c),l!==e.o&&Ee(a,`border`,e.o=l),u!==e.i&&L(a,`title`,e.i=u),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),i})()}function Op(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=Zd(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&L(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function kp(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Sl();return y(()=>e.innerHTML=ap(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=Qd();return z(t,M(N,{each:e,children:e=>(()=>{var t=$d();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=ef(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Mp(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>Ap(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Sl();return y(()=>e.innerHTML=ap(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return tf()}}),M(P,{get when(){return t.data.final},get children(){var e=nf(),n=e.firstChild;return z(e,M(Lp,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(Tp,{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=af(),o=a.firstChild,s=o.firstChild.nextSibling,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(Lp,{text:n}),null),z(c,()=>Ap(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?at(it(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return rf()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=sf(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=of();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=ap(String(t.data?.decision??``)),r=ap(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=uf(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return cf()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=lf();return z(a,M(N,{each:n,children:n=>(()=>{var a=df();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M(Op,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=ap(String(t.data?.question??``));return n!==e.e&&R(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=ff(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=Yu(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=Ku(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=ap(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=qu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=ap(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=Ju(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=ap(String(t.data.next))),e}}),null),y(()=>n.innerHTML=ap(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=pf(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=hf(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>Mp(Number(t.data.tokensBefore??0)),i),z(n,()=>Mp(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[mf(),(()=>{var e=Sl();return y(()=>e.innerHTML=ap(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=gf();return z(e,()=>Ap(JSON.stringify(t.data),200)),e})()}}function Ap(e,t){return e.length>t?e.slice(0,t)+` …`:e}function jp(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 Mp(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 Np(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 Pp(e,t){return Ap(e.replace(/\s+/g,` `).trim(),t)}function Fp(e){return(()=>{var t=_f(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}async function Ip(e){if(!e)return`unsupported`;let t=typeof navigator<`u`?navigator.clipboard?.writeText:void 0;if(typeof t==`function`)try{return await t.call(navigator.clipboard,e),`copied`}catch{}let n=null;try{return n=document.createElement(`textarea`),n.value=e,n.style.position=`fixed`,n.style.opacity=`0`,document.body.appendChild(n),n.select(),document.execCommand(`copy`)?`copied`:`failed`}catch{return`failed`}finally{n?.remove()}}function Lp(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),Ip(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=vf();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function Rp(e){return(()=>{var t=yf(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function zp(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 M(Rp,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=xf(),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(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=Sf();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),C.$$input=e=>o(e.currentTarget.value),ee.addEventListener(`change`,e=>c(e.currentTarget.value)),z(ee,M(N,{get each(){return e.providers},children:e=>(()=>{var t=tu();return z(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=bf();return z(e,d),e}}),T),y(()=>h.value=t()),y(()=>C.value=a()),y(()=>ee.value=s()),y(()=>te.value=l()),i}})}var Bp=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Vp=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Hp=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Up(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Wp(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 Wp(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Bp.has(t)?`image`:Vp.has(t)?`video`:Hp.has(t)?`audio`:null}var Gp=new Map,Kp=e=>{let t=Gp.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Gp.set(e,t)),t};function qp(e){return M(P,{get when(){return e.viewMode},get fallback(){return(()=>{var t=wf();return y(()=>t.innerHTML=ap(e.draft)),t})()},get children(){var t=Cf();return t.$$input=t=>e.onDraft(t.currentTarget.value),y(()=>t.value=e.draft),t}})}function Jp(e){let t=Kp(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(``),[j,ue]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await cl(async()=>{let{highlightChunks:e}=await import(`./shiki-DPtj9Srk.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};w(()=>{fe++});let me=async(t,n)=>{let r=Wp(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`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(!(!t||j())){ue(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
28
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{ue(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=Ef(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Up(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Tf();return z(t,()=>Mp(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(ee)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await O(e,te())})));for(let{p:e,rows:n}of t)n&&re(e,n)}finally{be(!1)}}};return[(()=>{var e=Df(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(Fp,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(Fp,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:C}),null),z(e,M(Fp,{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=Of();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=kf();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(ee)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(Rp,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=Pf(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=Mf();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=Nf();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return If()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(Yp,{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=Lf();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=Ff(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>Mp(A().length),i),a.$$click=()=>void he(),z(a,()=>j()?`saving…`:`💾 save`),y(()=>a.disabled=j()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=jf(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=zf();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Rf();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Af();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function Yp(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=Hf(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Uf();return z(t,()=>e.content),t})()},get children(){var t=Bf();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return Vf()}})]}var Xp=[{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)`}],Zp={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 Qp(e){let[t,n]=v(Xp[0]),[r,i]=v(Xp[0].url),[a,o]=v(``),[s,c]=v(Xp[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 ${Mp(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=qf(),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),z(u,()=>[...Xp,Zp].map(e=>(()=>{var n=Jf();return n.$$click=()=>S(e),z(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),z(n,M(P,{get when(){return t().hint},get children(){var e=Wf();return z(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),z(b,()=>Xp.map(e=>(()=>{var t=tu();return y(()=>t.value=e.url),t})())),C.$$input=e=>o(e.currentTarget.value),T.$$input=e=>c(e.currentTarget.value),z(ne,()=>l().map(e=>(()=>{var t=tu();return y(()=>t.value=e.id),t})())),z(n,M(P,{get when(){return l().length>0},get fallback(){return Yf()},get children(){var e=Kf(),t=e.firstChild;return z(e,()=>l().length,t),z(e,M(P,{get when(){return ee()},get children(){return[` · `,(()=>{var e=Gf();return z(e,ee),e})()]}}),null),e}}),E),O.$$input=e=>f(e.currentTarget.value),re.$$input=e=>m(e.currentTarget.value),z(n,M(P,{get when(){return _()},get children(){var e=bf();return z(e,_),e}}),k),z(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&&L(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 $p(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=Xf(),a=i.firstChild;return L(i,`title`,r),z(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return M(Rp,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Qf(),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,j=ce.nextSibling;return v.addEventListener(`submit`,te),z(ee,M(ye,{get each(){return t()},children:(e,r)=>(()=>{var i=$f(),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:``}]),z(E,M(N,{each:Xp,children:e=>(()=>{var a=ep();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)},z(a,()=>e.label,null),y(()=>L(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),D.addEventListener(`change`,e=>i(e.currentTarget.value)),z(D,M(N,{get each(){return o()},children:e=>(()=>{var t=tu();return t.value=e,z(t,e),t})()}),null),z(ee,M(P,{get when(){return s()},get children(){var e=Zf(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,s),z(e,()=>s()===a()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,s),e}}),null),z(re,()=>T(`progress interval (min)`,c(),e=>l(e),`how often the harness asks for a progress report`),k),z(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)),z(re,()=>T(`context window (k tok)`,m(),e=>h(e),`model's real window — 0/blank hides the % gauge`),null),z(re,()=>T(`max spawn depth`,g(),e=>_(e),`sub-agent nesting limit (0 = no spawning)`),null),z(ae,M(P,{get when(){return b().length>0},get children(){return M(ye,{get each(){return b()},children:(e,t)=>(()=>{var n=tp(),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:``}]),z(se,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=rp(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=np();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(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.2`&&(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`}},z(v,M(P,{get when(){return S()},get children(){var e=bf();return z(e,S),e}}),j),y(()=>D.value=r()),y(()=>ie.value=f()??``),v}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(Sp,{}),document.getElementById(`root`));export{cl as t};
|
|
30
|
-
//# sourceMappingURL=index-
|
|
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{ue(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=Ef(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Up(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Tf();return z(t,()=>Mp(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(ee)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await O(e,te())})));for(let{p:e,rows:n}of t)n&&re(e,n)}finally{be(!1)}}};return[(()=>{var e=Df(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(Fp,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(Fp,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:C}),null),z(e,M(Fp,{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=Of();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=kf();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(ee)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(Rp,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=Pf(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=Mf();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=Nf();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return If()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(Yp,{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=Lf();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=Ff(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>Mp(A().length),i),a.$$click=()=>void he(),z(a,()=>j()?`saving…`:`💾 save`),y(()=>a.disabled=j()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=jf(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=zf();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Rf();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Af();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function Yp(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=Hf(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Uf();return z(t,()=>e.content),t})()},get children(){var t=Bf();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return Vf()}})]}var Xp=[{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)`}],Zp={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 Qp(e){let[t,n]=v(Xp[0]),[r,i]=v(Xp[0].url),[a,o]=v(``),[s,c]=v(Xp[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 ${Mp(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=qf(),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),z(u,()=>[...Xp,Zp].map(e=>(()=>{var n=Jf();return n.$$click=()=>S(e),z(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),z(n,M(P,{get when(){return t().hint},get children(){var e=Wf();return z(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),z(b,()=>Xp.map(e=>(()=>{var t=tu();return y(()=>t.value=e.url),t})())),C.$$input=e=>o(e.currentTarget.value),T.$$input=e=>c(e.currentTarget.value),z(ne,()=>l().map(e=>(()=>{var t=tu();return y(()=>t.value=e.id),t})())),z(n,M(P,{get when(){return l().length>0},get fallback(){return Yf()},get children(){var e=Kf(),t=e.firstChild;return z(e,()=>l().length,t),z(e,M(P,{get when(){return ee()},get children(){return[` · `,(()=>{var e=Gf();return z(e,ee),e})()]}}),null),e}}),E),O.$$input=e=>f(e.currentTarget.value),re.$$input=e=>m(e.currentTarget.value),z(n,M(P,{get when(){return _()},get children(){var e=bf();return z(e,_),e}}),k),z(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&&L(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 $p(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=Xf(),a=i.firstChild;return L(i,`title`,r),z(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return M(Rp,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Qf(),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,j=ce.nextSibling;return v.addEventListener(`submit`,te),z(ee,M(ye,{get each(){return t()},children:(e,r)=>(()=>{var i=$f(),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:``}]),z(E,M(N,{each:Xp,children:e=>(()=>{var a=ep();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)},z(a,()=>e.label,null),y(()=>L(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),D.addEventListener(`change`,e=>i(e.currentTarget.value)),z(D,M(N,{get each(){return o()},children:e=>(()=>{var t=tu();return t.value=e,z(t,e),t})()}),null),z(ee,M(P,{get when(){return s()},get children(){var e=Zf(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,s),z(e,()=>s()===a()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,s),e}}),null),z(re,()=>T(`progress interval (min)`,c(),e=>l(e),`how often the harness asks for a progress report`),k),z(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)),z(re,()=>T(`context window (k tok)`,m(),e=>h(e),`model's real window — 0/blank hides the % gauge`),null),z(re,()=>T(`max spawn depth`,g(),e=>_(e),`sub-agent nesting limit (0 = no spawning)`),null),z(ae,M(P,{get when(){return b().length>0},get children(){return M(ye,{get each(){return b()},children:(e,t)=>(()=>{var n=tp(),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:``}]),z(se,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=rp(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=np();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(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.3`&&(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`}},z(v,M(P,{get when(){return S()},get children(){var e=bf();return z(e,S),e}}),j),y(()=>D.value=r()),y(()=>ie.value=f()??``),v}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(Sp,{}),document.getElementById(`root`));export{cl as t};
|
|
30
|
+
//# sourceMappingURL=index-B6nvBQLn.js.map
|