teapot-coding-agent 0.14.6 → 0.14.7
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 +11 -4
- package/package.json +1 -1
- package/public/assets/{index-BjELe1k2.js → index-BNT60fyY.js} +3 -3
- package/public/assets/{index-BjELe1k2.js.map → index-BNT60fyY.js.map} +1 -1
- package/public/assets/{shiki-BLFDwcS0.js → shiki-BDkPMeXc.js} +2 -2
- package/public/assets/{shiki-BLFDwcS0.js.map → shiki-BDkPMeXc.js.map} +1 -1
- package/public/index.html +1 -1
package/dist/agent/agent.js
CHANGED
|
@@ -595,15 +595,22 @@ export class Agent {
|
|
|
595
595
|
});
|
|
596
596
|
}
|
|
597
597
|
setStatus(s, reason = "") {
|
|
598
|
-
|
|
598
|
+
// Update the field FIRST. log.append fires onEvent synchronously, and the
|
|
599
|
+
// master's child-event hook wakes parked wait_children callers — those
|
|
600
|
+
// re-check agent.status at that instant. Updating after the append made
|
|
601
|
+
// every waiter observe the OLD status ("running"), conclude "someone is
|
|
602
|
+
// still working", and stay parked until timeout even though the child had
|
|
603
|
+
// just settled.
|
|
604
|
+
const prev = this.status;
|
|
605
|
+
this.status = s;
|
|
606
|
+
this.statusReason = reason;
|
|
607
|
+
if (prev !== s) {
|
|
599
608
|
void this.log.append("state", this.currentSession, this.currentBranch, {
|
|
600
|
-
from:
|
|
609
|
+
from: prev,
|
|
601
610
|
to: s,
|
|
602
611
|
reason,
|
|
603
612
|
});
|
|
604
613
|
}
|
|
605
|
-
this.status = s;
|
|
606
|
-
this.statusReason = reason;
|
|
607
614
|
bus.emit("update", { kind: "agent-update", agentId: this.opts.id });
|
|
608
615
|
}
|
|
609
616
|
/** Main auto-run loop: turn -> tools -> turn ... -> done/idle/stop. */
|
package/package.json
CHANGED
|
@@ -21,8 +21,8 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
|
|
|
21
21
|
- task two"title="shared with the agent — 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">`),wl=M(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><label class=muted title="queue a harness prompt telling the agent the task list changed"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=todo-notify type=checkbox checked> notify agent</label><button style="background:var(--ok);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save tasks`),Tl=M(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),El=M(`<h3 title="cumulative billed totals · the cached pill counts tokens served from the provider's prompt cache (far cheaper) · context bar turns orange ≥70% and red ≥85% of the model window">📊 runtime`),Dl=M(`<span class="pill ok">⚡ <!>% cached`),Ol=M(`<div class="card runcard"><div class=statgrid><div class=stat title="LLM turns taken this session"><span>turns</span><b></b></div><div class=stat title="tool calls executed"><span>tools</span><b></b></div><div class=stat title="times old turns were summarized to free context"><span>compacted</span><b></b></div></div><div class=statrow><span class=k>tokens</span><b> in / <!> out`),kl=M(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),Al=M(`<h3>⏰ schedule <span class=muted style=text-transform:none;letter-spacing:0>· cron tasks, all agents · edit in settings`),jl=M(`<div><nav class=sidebar><div class=agent-list></div><div class=sidebar-footer><div class=footer-row><span></span><div class=brand>🫖 teapot <span class=version>v</span></div><span style=margin-left:auto;display:flex;gap:4px;align-items:center><button class=iconbtn title="new agent">+</button><button class=iconbtn title=themes>🎨</button><button class=iconbtn title=settings>⚙</button></span></div><div class=metrics></div></div></nav><section class=channel></section><aside>`),Ml=M(`<span class=caret>`),Nl=M(`<span class=subtag>🧩`),Pl=M(`<span class=mini-cron>⏰`),Fl=M(`<span title="goal done">✓`),Il=M(`<div><span></span><span>`),Ll=M(`<span class=caret-spacer>`),Rl=M(`<label class=trow>system light →<select class=w100>`),zl=M(`<label class=trow>system dark →<select class=w100>`),Bl=M(`<option>`),Vl=M(`<button><span class=swdots>`),Hl=M(`<i>`),Ul=M(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),Wl=M(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),Gl=M(`<div class="content muted">thinking…`),Kl=M(`<span>⌨ <button class=tabx title="close this shell">✕`),ql=M(`<div><b class=mono></b><span class=muted>`),Jl=M(`<div class=cmdrow><b>@</b><span class=muted>`),Yl=M(`<button class=runbtn title="run toward the goal (starts the loop)">▶ start`),Xl=M(`<span class=badge title="no goal set yet">no goal`),Zl=M(`<button>`),Ql=M(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),$l=M(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),eu=M(`<div class=progrow><b>recent</b><span>`),tu=M(`<div class="progrow warn"><b>⚠ problems</b><span>`),nu=M(`<div class=progrow><b>next</b><span>`),ru=M(`<div class=progrow><b>goal</b><span>`),iu=M(`<div class="card prog"><div class=progrow><b>doing</b><span></span></div><div class="meta muted">`),au=M(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),ou=M(`<span>% of `),su=M(`<div class=bartrack><div>`),cu=M(`<div class=bartrack style=margin-top:4px><div>`),lu=M(`<div class=ctxblock title="estimated live context vs the model's real window. Past the window, old turns are summarized into notes (compaction); the compact line below shows where that starts."><div class=statrow><span class=k>context</span><b>~<!> tok</b></div><div class=statrow style=margin-top:4px><span class=k>compact</span><b> tok</b><span class=muted style=font-size:11px;color:var(--dim)></span></div><div class=ctrlrow style=margin-top:6px><label title="when on, older turns are automatically summarized when context exceeds the budget"><input type=checkbox>auto-compact</label><span class=muted style=font-size:11.5px>summarizes old turns when budget exceeded</span></div><div class=muted style=font-size:11px;margin-top:4px>compaction starts around ~<!> tok — older turns get summarized, recent ones stay intact`),uu=M(`<div><span></span><span> events`),du=M(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),fu=M(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),pu=M(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class="sched-meta mono"> → next </div><div class="sched-prompt muted">`),mu=M(`<div><div style=font-size:12.5px;margin-bottom:4px> event(s) came after this prompt — what should happen to them on the new branch?</div><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>summarize them into a note the agent can still read</label><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>discard them entirely (clean timeline)`),hu=M(`<form style=display:flex;flex-direction:column;gap:10px><textarea id=edit-text class="mono w100"rows=6></textarea><div style=display:flex;justify-content:flex-end;gap:8px><button type=button>cancel</button><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 12px;cursor:pointer">⑂ fork & resend`),gu=M(`<span class=bashelapsed> elapsed`),_u=M(`<div class=mono>`),vu=M(`<pre class="mono toolbody">`),yu=M(`<div class=meta>ms`),bu=M(`<div class=meta>waiting for output…`),xu=M(`<div class=meta>`),Su=M(`<div class=meta>writing…`),Cu=M(`<pre class="mono toolbody del">`),wu=M(`<pre class="mono toolbody add">`),Tu=M(`<div class=meta> · <!>ms`),Eu=M(`<div class=meta>applying…`),Du=M(`<pre class="mono toolbody patch">`),Ou=M(`<div>`),ku=M(`<div class=meta>validating…`),Au=M(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),ju=M(`<span class=muted>`),Mu=M(`<div class=meta>loading…`),Nu=M(`<div class=meta>bundled: `),Pu=M(`<div class=meta>saving…`),Fu=M(`<span class=actor>@`),Iu=M(`<details><summary><b>⚙ </b><span class=meta>`),Lu=M(`<div class=divider-msg>⑂ forked from <!> → `),Ru=M(`<div class=divider-msg>🎯 goal <!>: `),zu=M(`<div class=divider-msg>✅ tasks updated (<!>)`),Bu=M(`<div> → `),Vu=M(`<div class=avatar>`),Hu=M(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),Uu=M(`<div class=msg-head><span class=author></span><span class=ts></span><span class=ts>`),Wu=M(`<div><div class=msg-body>`),Gu=M(`<span style=width:38px>`),Ku=M(`<div class=qfree><input type=text><button>reply`),qu=M(`<div class=interrupted>⚠ interrupted — partial output kept`),Ju=M(`<div class=msgfoot><span>copy summary`),Yu=M(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>ms`),Xu=M(`<div class="content muted">Rejected: `),Zu=M(`<details class="embed decision"><summary><b>📌 </b><span class=meta>decision logged</span></summary><div class=content><b>Why:`),Qu=M(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),$u=M(`<div class=qopts>`),ed=M(`<div><div>❓ `),td=M(`<button class=qopt>`),nd=M(`<div class=progrow><b>recent</b><span class="content inline-md">`),rd=M(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),id=M(`<div class=progrow><b>next</b><span class="content inline-md">`),ad=M(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),od=M(`<div class="embed fail"><div class=mono>⚠ `),sd=M(`<div class="content muted">`),cd=M(`<button class=copybtn title="copy to clipboard">`),ld=M(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),ud=M(`<span style=color:var(--err);font-size:13px>`),dd=M(`<form style=display:flex;flex-direction:column;gap:10px><label>workspace directory<div style=display:flex;gap:6px><input type=text class="w100 mono"><button type=button>go</button><button type=button>↑</button></div></label><div class=dirlist></div><div style=display:flex;gap:10px><label style=flex:1>agent name <input type=text placeholder="(directory name)"></label><label>provider<select></select></label><label style=flex:1>model <input type=text placeholder="(provider default)"></label></div><button type=submit style=align-self:flex-end>create`),fd=M(`<div class=direntry>📁 `),pd=M(`<span class=fsize>`),md=M(`<div><span class=ficon></span><span class=fname>`),hd=M(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview">🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),gd=M(`<div class=filebox>`),_d=M(`<div class=muted style=padding:6px>`),vd=M(`<button title="rendered markdown">👁 preview`),yd=M(`<button title="edit and save back to the workspace">✎ edit`),bd=M(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),xd=M(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Sd=M(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Cd=M(`<div class="content mdpreview">`),wd=M(`<div class=filepreview>`),Td=M(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),Ed=M(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),Dd=M(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),Od=M(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),kd=M(`<span style=color:var(--fg)>`),Ad=M(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),jd=M(`<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">`),Md=M(`<button type=button>`),Nd=M(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),Pd=M(`<label><input type=number min=0>`),Fd=M(`<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></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><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`),Id=M(`<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">✕`),Ld=M(`<button type=button>+ `),Rd=M(`<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">`),zd=M(`<span class=muted>🧩 sub of @`),Bd=M(`<div class=cfgrow><b></b><span class=muted>`),Vd=new Map;function Hd(e){let t=Vd.get(e);if(t!==void 0)return t;let n=Le(e);return Vd.set(e,n),Vd.size>500&&Vd.delete(Vd.keys().next().value),n}var Ud={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`}},Wd={name:`harness`,icon:`📣`,color:`#3ba55d`},[Gd,Kd]=v(``),qd,Q=e=>{Kd(e),clearTimeout(qd),qd=setTimeout(()=>Kd(``),3200)},Jd=[{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 Yd(){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 Xd=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`?Ud.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:Wd}return Ud[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},Zd=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`]),Qd=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=``;try{t=(await i.json())?.error??``}catch{}throw Error(t||`${e}: HTTP ${i.status}`)}return i.json()}var $d=location.hash.match(/[#&]token=([^&]+)/);$d&&(localStorage.setItem(`teapot.token`,decodeURIComponent($d[1])),history.replaceState(null,``,location.pathname+location.search));var ef=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function tf(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v([]),[o,s]=v(0),[c,l]=v([]),[u,d]=v(null),f=new Map,[p,m]=v(f.get(n()??``)??``),h=e=>{m(e);let t=n();t&&(e?f.set(t,e):f.delete(t))},[g,_]=v({providers:{}}),[S,te]=v(!1),[ne,w]=v(!1),[re,T]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>1100:localStorage.getItem(`teapot.panel`)===`1`),ie=()=>{let e=!re();T(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},[ae,oe]=v(!1),[E,se]=v(localStorage.getItem(`teapot.theme`)??`dark`),[ce,le]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[ue,de]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[fe,pe]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),D=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[me,he]=v(D?.matches??!1);ee(()=>{let e=e=>he(e.matches);D?.addEventListener(`change`,e),C(()=>D?.removeEventListener(`change`,e))}),b(()=>{let e=ce()?me()?ue():fe():E();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=Jd.find(t=>t.key===e)?.mode??`dark`});let[ge,_e]=v(``),[ve,ye]=v(``),[be,xe]=v([]),Se=()=>Object.keys(g().providers??{});async function Ce(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);xe(t.models??[])}catch{xe([])}}let we=()=>{let e=ve().trim()||I()?.model||``;if(!e)return``;let t=be().find(t=>t.id===e);if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${uf(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(` · `)};b(()=>{let t=n(),r=e().find(e=>e.id===t),i=r?.provider||g().defaultProvider||Se()[0]||``;r&&(ge()!==i&&(_e(i),Ce(i)),ve()&&ye(``))});let[M,Te]=v(!0),[Ae,je]=v(0),[Me,Ne]=v(null),[Pe,Fe]=v(``),Ie;b(()=>{if(!Me()){clearTimeout(Ie),Ie=void 0,Fe(``);return}Ie||=setTimeout(()=>{Ie=void 0,Fe(Me()?.text??``)},(Me()?.text.length??0)>2e4?250:(Me()?.text.length??0)>6e3?120:60)}),C(()=>clearTimeout(Ie)),b(()=>{Pe()&&M()&&requestAnimationFrame(()=>{xt()&&St(!0)})}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{xt()&&(Te(!0),je(0),St(!0))})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let I=x(()=>e().find(e=>e.id===n())),[Re,ze]=v(null);x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let[Be,Ve]=v([]),He=x(()=>{let e=new Map,t=new Set,n=new Map;for(let r of i())if(Zd.has(r.type)){if(r.type===`tool_call`){let e=n.get(r.data.callId)??[];e.push(r),n.set(r.data.callId,e)}else if(r.type===`tool_result`){let i=n.get(r.data.callId)?.shift();i&&(e.set(i.id,r),t.add(r.id))}}return{resFor:e,consumed:t}}),Ue=x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&t.data?.callId&&e.add(String(t.data.callId));return e}),L=x(()=>{let{consumed:e}=He(),t=i().filter(t=>!Zd.has(t.type)||t.type===`tool_call`&&t.data?.name===`report_progress`||t.type===`tool_result`&&t.data?.name===`report_progress`?!1:t.type===`tool_result`?!e.has(t.id):t.type===`message`?t.data?.progressEcho?!1:String(t.data?.content??``).trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final:!0),n=[];for(let e of t)if(e.type===`sub`){let t=e.data,r=String(t?.type??`message`);if(r===`state`)continue;n.push({...e,type:r,data:{...t?.data,actor:t?.sub}})}else n.push(e);let r=e=>String(e??``).replace(/\s+/g,` `).trim().toLowerCase(),a=[];for(let e=0;e<n.length;e++){let t=n[e];if(t.type===`message`&&t.data?.role===`assistant`&&n[e-1]?.type===`progress`){let i=n[e-1].data,a=r(t.data.content);if((a.includes(r(i.doing))||i.recent&&a.includes(r(i.recent)))&&a.length<=Math.max(200,r(i.doing).length*3))continue}a.push(t)}let o=Be().filter(e=>!a.some(t=>t.type===`prompt`&&t.data?.source===`user`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)).map(e=>({id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:I()?.session??``,branch:I()?.branch??`br0`,parent:null,type:`prompt`,data:{source:`user`,text:e.text,pending:!0}}));return[...a,...o]}),R=()=>$(`/api/config`).then(_).catch(()=>{}),[We,Ge]=v(!1);ee(()=>{let e=()=>Ge(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[Ke,qe]=v(``),[Je,Ye]=v(!1),Xe=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==Xe?(Xe=t,Ye(!1),qe(r)):t&&!Je()&&qe(r)});let Ze=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:Ke(),notify:e})}),Ye(!1),Q(`tasks saved${e&&Ke().trim()?` & notification queued`:``}`),$e()}catch(e){Q(`save failed: ${e.message}`)}},Qe=x(()=>{let e=0,t=0;for(let n of Ke().split(`
|
|
22
22
|
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),$e=()=>$(`/api/agents`).then(e=>t(t=>{let n=new Map(t.map(e=>[e.id,e]));return(e.agents??[]).map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})})).catch(()=>{}),et=()=>$(`/api/metrics`).then(d).catch(()=>{}),[tt,nt]=v([]),rt=()=>$(`/api/tasks`).then(e=>nt(e.tasks)).catch(()=>{}),it=e=>tt().filter(t=>t.agent===e),[at,ot]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),st=e=>{let t=new Set(at());t.has(e)?t.delete(e):t.add(e),ot(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},ct=x(()=>{let t=e(),n=new Map,r=[];for(let e of t)e.parent&&t.some(t=>t.id===e.parent)?(n.has(e.parent)||n.set(e.parent,[]),n.get(e.parent).push(e)):r.push(e);let i=[],a=(e,t)=>{for(let r of e){i.push({a:r,depth:t});let e=n.get(r.id);e?.length&&!at().has(r.id)&&a(e,t+1)}};return a(r,0),i}),[lt,ut]=v(null),dt=new Map;function ft(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=dt.get(r.id);if(t[n]=i??r,!i&&(dt.set(r.id,r),dt.size>3e3)){let e=dt.keys().next().value;e!==void 0&&dt.delete(e)}}return t}let[pt,z]=v(!1),[mt,ht]=v(!1),gt=0;function _t(e){a(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of ft(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function vt(){let e=n(),t=i()[0];if(!(!e||!t||pt()||mt())){z(!0);try{let r=bt(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=lt(),c=(await $(`/api/agents/${e}/events?limit=300&before=${encodeURIComponent(t.id)}${s?`&branch=${encodeURIComponent(s)}`:``}`)).events??[];if(c.length===0){ht(!0);return}if(n()!==e||i()[0]?.id!==t.id)return;_t(c),requestAnimationFrame(()=>{if(n()===e){let e=bt();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{z(!1)}}}async function yt(e){let t=++gt;try{let r=lt(),[i,o,c]=await Promise.all([$(`/api/agents/${e}/events?limit=300${r?`&branch=${encodeURIComponent(r)}`:``}`),$(`/api/agents/${e}/branches`),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(t!==gt||n()!==e)return;a(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of ft(i.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),s(i.total??i.events.length),l(o.branches),pn(c.skills??[])}catch{}}function bt(){return document.querySelector(`.feed`)}function xt(){let e=bt();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<80}function St(e=!1){let t=bt();t&&(e||M())&&(t.scrollTop=t.scrollHeight,je(0))}async function Ct(e,t=!0){let i=n();gt++,i!==e&&(a([]),dt.clear(),Ne(null),je(0)),r(e),h(f.get(e)??``),ut(null),ht(!1),z(!1),Ve([]),localStorage.setItem(`teapot.session`,e),At(e,t),$(`/api/agents/${e}/load`,{method:`POST`}).then($e).catch(()=>{}),await yt(e),n()===e&&requestAnimationFrame(()=>{n()===e&&St(!0)})}let[wt,Tt]=v(!1),Et=null,Dt=null;C(()=>Et?.close());function Ot(){let e=location.protocol===`https:`?`wss://`:`ws://`;Et=new WebSocket(`${e}${location.host}/api/ws${ef()}`),Et.onopen=()=>Tt(!0),Et.onclose=()=>{Tt(!1),setTimeout(Ot,1500)},Et.onerror=()=>Et?.close();let t=new Set([`state`,`usage`,`session_start`]),r=null;Et.onmessage=e=>{let i=JSON.parse(e.data);if(i.kind!==`ping`&&i.kind!==`pong`){if(i.kind===`llm-delta`){r={id:i.agentId,at:Date.now()},i.agentId===n()&&Ne({text:i.text??``,reasoning:i.reasoning??``});return}if(!(i.kind===`event`&&t.has(i.event?.type))){if(document.visibilityState===`hidden`){a=!0,Dt||=setTimeout(s,2e3);return}Dt||=setTimeout(s,400)}}};let a=!1,s=async()=>{if(Dt=null,await $e(),await et(),n()){let e=i().at(-1)?.id,t=o(),a=Date.now();await yt(n()),i().at(-1)?.id!==e&&(r?.id===n()&&r.at>=a||Ne(null),xt()?St(!0):je(Ae()+Math.max(0,o()-t))),Ve(e=>e.filter(e=>!i().some(t=>t.type===`prompt`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)))}},c=()=>{document.visibilityState===`visible`&&a&&(a=!1,Dt||=setTimeout(s,150))};document.addEventListener(`visibilitychange`,c),C(()=>document.removeEventListener(`visibilitychange`,c))}let kt=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function At(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let t=kt();t&&e().some(e=>e.id===t)&&t!==n()&&Ct(t,!1)}),b(()=>{let e=I();document.title=e?`${e.status===`running`?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`}),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(S()){te(!1);return}if(ne()){w(!1);return}if(Re()){ze(null);return}if(ae()){oe(!1);return}let e=I();if(e?.status===`running`){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then($e);return}re()&&window.innerWidth<=1100&&T(!1);return}if(!(S()||ne())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)ie();else if(e.key===`t`)Nt();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=ct().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&&Ct(t[i].id)}}});let[jt,Mt]=v(localStorage.getItem(`teapot.term`)===`1`),Nt=()=>{let e=!jt();Mt(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[Pt,Ft]=v([]),[It,Lt]=v(0),[Rt,zt]=v(-1),[Bt,Vt]=v(!1),[Ht,Ut]=v(0),[Wt,Gt]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),Kt=new Map,qt=[null,null],Jt=()=>Pt()[Ht()===0?It():Rt()]??null;function Yt(e){if(!Pt()[e])return;let t=Ht()===0?It:Rt;(Ht()===0?Rt:It)()===e&&(Ht()===0?zt(t()):Lt(t())),t()===e||(Ht()===0?Lt(e):zt(e))}let Xt=()=>Zt();function Zt(e){let t=e??n();if(!t)return;let r=Pt().filter(e=>e.agentId===t).length;if(r>=2){Q(`max 2 shells per agent (${t})`);return}Pt().length+1;let i=r===0?{key:`${t}`,agentId:t,title:t}:{key:`${t}#${r+1}`,agentId:t,title:`${t}·${r+1}`};Ft(e=>[...e,i]),Ht()===0?Lt(Pt().length):zt(Pt().length)}function Qt(e){let t=Pt()[e];if(!t)return;let n=Kt.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),Kt.delete(t.key)}let r=Pt().filter((t,n)=>n!==e);Ft(r);let i=t=>t===e?-1:t>e?t-1:t;Lt(e=>Math.min(i(e),r.length-1)),zt(e=>e===-1?-1:Math.min(i(e),r.length-1))}function $t(){for(let[,e]of Kt){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}Kt.clear()}function en(e,t){let n=Kt.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 Dc({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:Yd()}),a=new Ac;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${ef()}`);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},Kt.set(e.key,n)}return n}function B(e){let t=qt[e];if(!t)return;let n=Pt()[e===0?It():Rt()];if(!n){t.replaceChildren();return}let r=en(n,t);Ht()===(e===0?0:1)&&requestAnimationFrame(()=>{try{r.fit(),r.term.focus()}catch{}})}b(()=>{Pt(),Bt(),It(),Rt(),Wt(),requestAnimationFrame(()=>{B(0),Bt()&&B(1)})}),b(()=>{if(!jt())return;let e=n();if(e){if(!Pt().some(t=>t.agentId===e)&&Pt().length===0)Zt(e);else if(!Pt().some(t=>t.agentId===e)){let t=Pt().findIndex(t=>t.agentId===e);t>=0&&Yt(t)}}});let tn=e=>{e.preventDefault();let t=e.clientY,n=Wt(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Gt(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(Wt())),requestAnimationFrame(()=>{B(0),Bt()&&B(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},nn=()=>{let e=!Bt();if(Vt(e),e&&Rt()===-1){let e=Pt().findIndex((e,t)=>t!==It());zt(e>=0?e:-1)}};C($t);let V=e=>t=>{qt[e]=t};ee(()=>{R(),$e().then(()=>{let t=kt()||localStorage.getItem(`teapot.session`)||``,n=e().find(e=>e.id===t)??e()[0];n&&Ct(n.id,!1)}),et(),rt(),H(),Ot();let t=setInterval(()=>{et(),rt()},3e4);C(()=>clearInterval(t))});let rn=[{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`}],[an,on]=v([]),H=()=>$(`/api/personas`).then(e=>on(e.personas)).catch(()=>{}),[sn,cn]=v(!1),ln=()=>{let e=p().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},un=()=>{let t=ln();return t===null?[]:[...an().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))},dn=new Set([`start`,`stop`,`fork`,`compact`]),[fn,pn]=v([]),[mn,hn]=v(-1),gn=()=>{let e=p();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[3]??``).trim();if(!r&&n!==`skill`){let e=rn.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&dn.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=fn().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[]},_n,vn=()=>{_n&&(_n.style.height=`auto`,_n.style.height=`${Math.min(_n.scrollHeight,160)}px`)};b(()=>{p(),vn()});let yn=async(e,t)=>{let r=t??n();if(r)try{await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0})}),Ve(t=>[...t,{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now()}]),requestAnimationFrame(()=>St(!0))}catch(t){h(e),console.error(`send failed:`,t)}},bn=async t=>{t.preventDefault();let r=n(),i=p().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=an().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:sn()?`fork`:`none`})})).id}${sn()?` (forked context)`:``}`),$e(),h(``)}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}`),h(``)}else{Q(`unknown @${r} — personas: ${an().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){h(`/goal `);return}if(t===`skill`&&!n){h(`/skill `);return}h(``),await xn(t,n);return}h(``),await yn(i)}},xn=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($e);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Ct(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 yn(`[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}`)}},U,Sn=0;b(()=>{e(),requestAnimationFrame(()=>{U&&(Sn=Math.min(Sn,U.scrollHeight),U.scrollTop=Sn)})});let Cn=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then($e),wn=async e=>{e.preventDefault();let t=document.getElementById(`goal-input`),r=document.getElementById(`goal-notify`)?.checked??!0;!n()||!t.value.trim()||(await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t.value,notify:r})}),t.value=``,$e())};return[O(A,{get when(){return g()?.needsSetup},fallback:null,get children(){return O(yf,{onDone:()=>location.reload()})}}),O(A,{get when(){return We()},get children(){var e=Fc();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}}),O(A,{get when(){return!g()?.needsSetup},get children(){var o=jl(),s=o.firstChild,l=s.firstChild,d=l.nextSibling,f=d.firstChild,m=f.firstChild,_=m.nextSibling,v=_.firstChild.nextSibling;v.firstChild;var b=_.nextSibling.firstChild,x=b.nextSibling,S=x.nextSibling,ee=f.nextSibling,C=s.nextSibling,ne=C.nextSibling;F(l,O(k,{get each(){return ct()},children:({a:t,depth:r})=>(()=>{var i=Il(),a=i.firstChild,o=a.nextSibling;return i.$$click=()=>Ct(t.id),F(i,O(A,{get when(){return e().some(e=>e.parent===t.id)},get fallback(){return Ll()},get children(){var e=Ml();return e.$$click=e=>{e.stopPropagation(),st(t.id)},F(e,()=>at().has(t.id)?`▸`:`▾`),y(()=>N(e,`title`,at().has(t.id)?`expand sub-agents`:`collapse sub-agents`)),e}}),a),F(o,()=>t.id),F(i,O(A,{get when(){return t.parent},get children(){return Nl()}}),null),F(i,O(A,{get when(){return it(t.id).length>0},get children(){var e=Pl();return y(()=>N(e,`title`,it(t.id).map(e=>`${e.id}: ${e.schedule}`).join(`
|
|
24
|
-
`))),e}}),null),F(i,O(A,{get when(){return t.goal.status===`done`},get children(){return Fl()}}),null),y(e=>{var o=`agent-item`+(t.id===n()?` sel`:``)+(r>0?` sub-row`:``),s=r>0?`padding-left:${10+r*14}px`:``,c=t.parent?`sub-agent of @${t.parent}`:void 0,l=`dot ${t.status}`;return o!==e.e&&P(i,e.e=o),e.t=De(i,s,e.t),c!==e.a&&N(i,`title`,e.a=c),l!==e.o&&P(a,e.o=l),e},{e:void 0,t:void 0,a:void 0,o:void 0}),i})()})),F(d,O(A,{get when(){return ae()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;le(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),F(e,O(A,{get when(){return!ce()},get fallback(){return[(()=>{var e=Rl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),F(t,O(k,{get each(){return Jd.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=Bl();return F(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ue()),e})(),(()=>{var e=zl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{pe(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),F(t,O(k,{get each(){return Jd.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=Bl();return F(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=fe()),e})()]},get children(){var e=Ic();return F(e,O(k,{each:Jd,children:e=>(()=>{var t=Vl(),n=t.firstChild;return t.$$click=()=>{se(e.key),localStorage.setItem(`teapot.theme`,e.key)},F(n,()=>e.sw.map(e=>(()=>{var t=Hl();return Oe(t,`background`,e),t})())),F(t,()=>e.label,null),y(n=>{var r=`themebtn`+(E()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&P(t,n.e=r),i!==n.t&&N(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ce()),e}}),f),F(v,`0.14.
|
|
24
|
+
`))),e}}),null),F(i,O(A,{get when(){return t.goal.status===`done`},get children(){return Fl()}}),null),y(e=>{var o=`agent-item`+(t.id===n()?` sel`:``)+(r>0?` sub-row`:``),s=r>0?`padding-left:${10+r*14}px`:``,c=t.parent?`sub-agent of @${t.parent}`:void 0,l=`dot ${t.status}`;return o!==e.e&&P(i,e.e=o),e.t=De(i,s,e.t),c!==e.a&&N(i,`title`,e.a=c),l!==e.o&&P(a,e.o=l),e},{e:void 0,t:void 0,a:void 0,o:void 0}),i})()})),F(d,O(A,{get when(){return ae()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;le(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),F(e,O(A,{get when(){return!ce()},get fallback(){return[(()=>{var e=Rl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),F(t,O(k,{get each(){return Jd.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=Bl();return F(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ue()),e})(),(()=>{var e=zl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{pe(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),F(t,O(k,{get each(){return Jd.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=Bl();return F(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=fe()),e})()]},get children(){var e=Ic();return F(e,O(k,{each:Jd,children:e=>(()=>{var t=Vl(),n=t.firstChild;return t.$$click=()=>{se(e.key),localStorage.setItem(`teapot.theme`,e.key)},F(n,()=>e.sw.map(e=>(()=>{var t=Hl();return Oe(t,`background`,e),t})())),F(t,()=>e.label,null),y(n=>{var r=`themebtn`+(E()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&P(t,n.e=r),i!==n.t&&N(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ce()),e}}),f),F(v,`0.14.7`,null),b.$$click=()=>{R(),te(!0)},x.$$click=()=>oe(!ae()),S.$$click=()=>{R(),w(!0)},F(ee,O(A,{get when(){return u()},get children(){return[`master rss `,j(()=>u().rssMb),`MB · heap `,j(()=>u().heapUsedMb),`MB`,Rc(),`load1 `,j(()=>u().loadavg1),` · up `,j(()=>Math.floor(u().uptimeSec/60)),`m`]}})),F(C,O(A,{get when(){return I()},get fallback(){return Ul()},get children(){return[(()=>{var e=Hc(),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,l=c.firstChild,u=l.nextSibling;return F(t,()=>I().id),F(n,()=>I().status),F(e,O(A,{get when(){return(I().pendingPrompts??0)>0},get children(){var e=zc(),t=e.firstChild.nextSibling;return t.nextSibling,F(e,()=>I().pendingPrompts,t),y(()=>N(e,`title`,`${I().pendingPrompts} prompt(s) waiting — the agent picks them up at the next turn boundary`)),e}}),r),F(e,O(A,{get when(){return it(I().id).length>0},get children(){var e=Bc();return e.firstChild,F(e,()=>it(I().id).length,null),y(()=>N(e,`title`,`scheduled tasks:\n${it(I().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
|
|
25
25
|
`)}`)),e}}),r),F(r,()=>I().model,i),F(r,()=>I().session,a),F(r,()=>I().branch,o),F(r,()=>I().stats.turns,s),F(r,()=>I().stats.toolCalls,null),F(c,O(A,{get when(){return I().statusReason},get children(){var e=Vc();return y(()=>N(e,`title`,I().statusReason)),e}}),l),l.$$click=Nt,u.$$click=ie,y(()=>P(n,`badge ${I().status}`)),e})(),(()=>{var e=Jc();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r=xt();r&&Ae()&&je(0),Te(r),t.scrollTop<=4&&n()&&!pt()&&!mt()&&i().length>0&&vt()}),F(e,O(A,{get when(){return j(()=>!!mt())()&&L().length>0},get children(){return Uc()}}),null),F(e,O(A,{get when(){return pt()},get children(){return Wc()}}),null),F(e,O(A,{get when(){return L().length>0},get fallback(){return Wl()},get children(){return[O(k,{get each(){return L()},children:(e,t)=>O(af,{e,get prev(){return L()[t()-1]},get res(){return He().resFor.get(e.id)},onOption:e=>void yn(e),get answeredIds(){return Ue()},get agentActive(){return I()?.status===`running`||I()?.status===`waiting`},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`?()=>ze({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),O(A,{get when(){return Me()},get children(){var e=qc(),t=e.firstChild.nextSibling;return t.firstChild,F(t,O(A,{get when(){return Me().reasoning},get children(){var e=Gc(),t=e.firstChild.nextSibling;return F(t,()=>Me().reasoning),e}}),null),F(t,O(A,{get when(){return Pe()},get fallback(){return Gl()},get children(){var e=Kc();return y(()=>e.innerHTML=Le(Pe()+`▍`)),e}}),null),e}})]}}),null),e})(),O(A,{get when(){return jt()},get children(){var t=$c(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.firstChild,o=i.nextSibling.firstChild,s=o.nextSibling,c=s.nextSibling,l=r.nextSibling,u=l.firstChild;n.$$dblclick=()=>{Gt(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Wt()))},n.$$pointerdown=tn,F(i,O(k,{get each(){return Pt()},children:(e,t)=>(()=>{var n=Kl(),r=n.firstChild.nextSibling;return n.$$click=()=>Yt(t()),F(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Qt(t())},y(r=>{var i=`termtab`+(Ht()===0&&It()===t()?` active`:``)+(Bt()&&Ht()===1&&Rt()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),a),a.$$click=Xt,F(o,(()=>{var t=j(()=>!!Jt());return()=>t()?e().find(e=>e.id===Jt().agentId)?.workspace.split(`/`).filter(Boolean).pop():I()?.workspace})()),s.$$click=nn,c.$$click=Nt;var d=V(0);return typeof d==`function`&&ke(d,u),u.$$pointerdown=()=>Ut(0),F(u,O(A,{get when(){return!Jt()||Ht()===0&&It()===-1},get children(){return Yc()}})),F(l,O(A,{get when(){return Bt()},get children(){return[Xc(),(()=>{var e=Qc(),t=V(1);return typeof t==`function`&&ke(t,e),e.$$pointerdown=()=>Ut(1),F(e,O(A,{get when(){return Rt()===-1||Pt().length<=Rt()},get children(){return Zc()}})),y(()=>e.classList.toggle(`focused`,Ht()===1)),e})()]}}),null),y(e=>{var n=`${Wt()}px`,r=Bt()?`single pane`:`split panes (50/50)`,i=!!Bt(),a=Ht()===0;return n!==e.e&&Oe(t,`height`,e.e=n),r!==e.t&&N(s,`title`,e.t=r),i!==e.a&&l.classList.toggle(`split`,e.a=i),a!==e.o&&u.classList.toggle(`focused`,e.o=a),e},{e:void 0,t:void 0,a:void 0,o:void 0}),t}}),(()=>{var e=rl(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=t.nextSibling;F(e,O(A,{get when(){return!M()||Ae()>0},get children(){var e=el();return e.firstChild,e.$$click=()=>St(!0),F(e,(()=>{var e=j(()=>Ae()>0);return()=>e()?`${Ae()} new message${Ae()>1?`s`:``}`:`jump to present`})(),null),e}}),t),F(e,O(A,{get when(){return gn().length>0},get children(){var e=tl();return F(e,O(k,{get each(){return gn()},children:(e,t)=>(()=>{var n=ql(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{h(e.insert),hn(-1)},F(r,()=>e.insert.trim()),F(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===mn()?` active`:``),a=e.title;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),F(e,O(A,{get when(){return un().length>0},get children(){var e=tl();return F(e,O(k,{get each(){return un()},children:e=>(()=>{var t=Jl(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{h(`@${e.key} `),hn(-1)},F(n,()=>e.key,null),F(r,()=>e.label),y(()=>N(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,bn),n.$$keydown=e=>{let t=gn();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),hn(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),hn(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&mn()>=0){e.preventDefault(),h(t[mn()].insert),hn(-1);return}if(e.key===`Escape`&&t.length>0){hn(-1);return}e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),bn(e))},n.$$input=e=>{h(e.currentTarget.value),hn(0),vn()};var a=_n;return typeof a==`function`?ke(a,n):_n=n,F(t,O(A,{get when(){return j(()=>!!p().startsWith(`@`))()&&p().includes(` `)},get children(){var e=nl(),t=e.firstChild;return t.addEventListener(`change`,e=>cn(e.currentTarget.checked)),y(()=>t.checked=sn()),e}}),r),F(i,()=>Gd()||`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(()=>N(n,`placeholder`,`message #${I().id} — / for commands`)),y(()=>n.value=p()),e})()]}})),ne.addEventListener(`scroll`,e=>{Sn=e.currentTarget.scrollTop});var T=U;return typeof T==`function`?ke(T,ne):U=ne,F(ne,O(A,{get when(){return I()},get children(){return[il(),(()=>{var e=al(),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 F(n,()=>I().id),F(r,()=>I().status),F(a,()=>I().workspace),F(o,()=>I().session,s),F(o,()=>I().branch,null),y(e=>{var t=`badge ${I().status}`,n=I().workspace;return t!==e.e&&P(r,e.e=t),n!==e.t&&N(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),O(hf,{get agentId(){return I().id},get workspace(){return I().workspace}}),ol(),(()=>{var e=cl(),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=>{_e(e.currentTarget.value),Ce(e.currentTarget.value)}),F(t,O(k,{get each(){return Se()},children:e=>(()=>{var t=Bl();return t.value=e,F(t,e,null),F(t,()=>e===g().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>ye(e.currentTarget.value),F(a,O(k,{get each(){return be()},children:e=>(()=>{var t=Bl();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:ge(),model:ve().trim()||void 0,contextWindowTokens:be().find(e=>e.id===(ve().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,$e()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},F(s,()=>I().model,null),F(s,O(A,{get when(){return be().length},get children(){return[` · `,j(()=>be().length),` models loaded`]}}),null),F(e,O(A,{get when(){return we()},get children(){var e=sl();return F(e,we),e}}),null),y(()=>N(i,`placeholder`,I().model)),y(()=>t.value=ge()),y(()=>i.value=ve()),e})(),ll(),(()=>{var i=fl(),o=i.firstChild,s=o.nextSibling;return F(i,O(A,{get when(){return I().status===`running`},get fallback(){return(()=>{var e=Yl();return Ee(e,`click`,Cn(`/start`),!0),e})()},get children(){var e=ul();return Ee(e,`click`,Cn(`/stop`),!0),e}}),o),o.$$click=()=>$(`/api/agents/${I().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>Ct(I().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 o=e().filter(e=>e.id!==i);t(o),o[0]?Ct(o[0].id):(r(null),a([]))},F(i,O(A,{get when(){return e().some(e=>e.parent===n())},get children(){var e=dl();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),$e())},e}}),null),i})(),(()=>{var e=pl(),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($e)}),y(()=>t.checked=I().autoContinue??!0),e})(),(()=>{var e=hl();return e.firstChild,F(e,O(A,{get when(){return!!I().goal.text.trim()},get fallback(){return Xl()},get children(){var e=ml();return F(e,()=>I().goal.status),y(()=>P(e,`badge ${I().goal.status===`active`?`running`:I().goal.status}`)),e}}),null),e})(),(()=>{var e=gl();return e.firstChild,F(e,O(k,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Zl();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then($e)},N(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`),F(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(I().goal.text.trim()&&I().goal.status===e?` on ${e}`:``),i=!!I().goal.text.trim()&&I().goal.status===e;return r!==n.e&&P(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),O(A,{get when(){return I().goal.text},get fallback(){return Ql()},get children(){var e=_l(),t=e.firstChild;return y(()=>t.innerHTML=Le(String(I().goal.text))),e}}),vl(),(()=>{var e=yl();return e.addEventListener(`submit`,wn),e})(),(()=>{var e=xl(),t=e.firstChild.nextSibling;return F(e,O(A,{get when(){return Qe().total>0},get children(){var e=bl(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,F(e,()=>Qe().done,t),F(e,()=>Qe().total,n),y(t=>De(e,Qe().done===Qe().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),O(A,{get when(){return Qe().total>0},get children(){var e=Sl(),t=e.firstChild;return y(e=>{var n=`barfill `+(Qe().done===Qe().total?``:`warn`),r=`${Math.round(Qe().done/Qe().total*100)}%`;return n!==e.e&&P(t,e.e=n),r!==e.t&&Oe(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),(()=>{var e=Cl();return e.$$input=e=>{qe(e.currentTarget.value),Ye(!0)},y(()=>e.value=Ke()),e})(),(()=>{var e=wl(),t=e.firstChild.nextSibling;return t.$$click=Ze,e})(),Tl(),O(A,{get when(){return I().latestProgress},get fallback(){return $l()},children:e=>(()=>{var t=iu(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return F(r,()=>e().doing),F(t,O(A,{get when(){return e().recent},get children(){var t=eu(),n=t.firstChild.nextSibling;return F(n,()=>e().recent),t}}),i),F(t,O(A,{get when(){return e().problems},get children(){var t=tu(),n=t.firstChild.nextSibling;return F(n,()=>e().problems),t}}),i),F(t,O(A,{get when(){return e().next},get children(){var t=nu(),n=t.firstChild.nextSibling;return F(n,()=>e().next),t}}),i),F(t,O(A,{get when(){return e().goalStatus},get children(){var t=ru(),n=t.firstChild.nextSibling;return F(n,()=>e().goalStatus),t}}),i),F(i,()=>lf(e().ts)),t})()}),El(),(()=>{var e=Ol(),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,F(i,()=>I().stats.turns),F(o,()=>I().stats.toolCalls),F(s,()=>I().stats.compactions??0),F(l,()=>uf(I().stats.inputTokens),u),F(l,()=>uf(I().stats.outputTokens),d),F(c,O(A,{get when(){return(I().stats.cachedInputTokens??0)>0},get children(){var e=Dl(),t=e.firstChild.nextSibling;return t.nextSibling,F(e,()=>Math.round(I().stats.cachedInputTokens/Math.max(1,I().stats.inputTokens)*1e3)/10,t),y(()=>N(e,`title`,`${uf(I().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),F(e,O(A,{get when(){return I().ctx},get fallback(){return au()},children:e=>{let t=be().find(e=>e.id===I().model),r=e().window||t?.contextLength||0,i=r?Math.min(999,e().usedTokens/r*100):0,a=r?i>=85?`crit`:i>=70?`warn`:`ok`:``,o=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)},s=r?Math.round(r*.75):0,c=e().compactAt,l=e().compactAtIsManual===!0?!1:!c||c>=r;return(()=>{var t=lu(),u=t.firstChild,d=u.firstChild.nextSibling,f=d.firstChild.nextSibling;f.nextSibling;var p=u.nextSibling,m=p.firstChild.nextSibling,h=m.firstChild,g=m.nextSibling,_=p.nextSibling,v=_.firstChild.firstChild,b=_.nextSibling,x=b.firstChild.nextSibling;return x.nextSibling,F(d,()=>uf(e().usedTokens),f),F(u,O(A,{when:r,get children(){var e=ou(),t=e.firstChild;return P(e,`pill ${a}`),F(e,()=>o(i),t),F(e,()=>uf(r),null),e}}),null),F(t,O(A,{when:r,get children(){var e=su(),t=e.firstChild;return P(t,`barfill ${a}`),y(e=>Oe(t,`width`,`${Math.min(100,i)}%`)),e}}),p),F(m,()=>uf(l?s:c),h),F(g,l?` (75% of window)`:` (manual override)`),F(t,O(A,{when:r,get children(){var t=cu(),n=t.firstChild;return P(n,`barfill ${a}`),y(t=>Oe(n,`width`,`${Math.min(100,Math.round(e().usedTokens/s*100))}%`)),t}}),_),v.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then($e)}),F(b,()=>uf(e().compactAt),x),y(()=>v.checked=I().autoCompact!==!1),t})()}}),null),e})(),kl(),O(k,{get each(){return c()},children:e=>(()=>{var t=uu(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=lt()===e.branch?null:e.branch;ut(t),n()&&yt(n())},F(r,()=>e.branch,null),F(r,()=>e.branch===I().branch?` (current)`:``,null),F(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===I().branch||e.branch===lt()?` cur`:``),i=e.branch===lt()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&P(t,n.e=r),i!==n.t&&N(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Al(),O(A,{get when(){return tt().length>0},get fallback(){return du()},get children(){return O(k,{get each(){return tt()},children:e=>(()=>{var t=pu(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Ct(e.agent),F(i,()=>e.id),F(a,()=>e.agent,null),F(r,O(A,{get when(){return e.forked},get children(){return fu()}}),null),F(o,()=>e.schedule,s),F(o,(()=>{var t=j(()=>!!e.next);return()=>t()?lf(e.next):`—`})(),null),F(o,(()=>{var t=j(()=>!!e.last);return()=>t()?` · last ${lf(e.last)}`:` · never ran`})(),null),F(c,()=>df(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${df(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&P(t,r.e=i),a!==r.t&&N(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(re()?``:` right-hidden`),n=`conn`+(wt()?` ok`:``),r=wt()?`live (websocket)`:`reconnecting…`,i=`rightbar`+(re()?` open`:``);return t!==e.e&&P(o,e.e=t),n!==e.t&&P(m,e.t=n),r!==e.a&&N(m,`title`,e.a=r),i!==e.o&&P(ne,e.o=i),e},{e:void 0,t:void 0,a:void 0,o:void 0}),o}}),O(A,{get when(){return S()},get children(){return O(mf,{get providers(){return Object.keys(g().providers??{})},onClose:()=>te(!1),onCreated:e=>{te(!1),$e(),Ct(e)}})}}),O(A,{get when(){return ne()},get children(){return O(bf,{get cfg(){return g()},onClose:()=>w(!1),onSaved:()=>{R(),rt()}})}}),O(A,{get when(){return Re()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return O(pf,{title:`edit prompt — forks the conversation`,onClose:()=>ze(null),get children(){var t=hu(),i=t.firstChild,s=i.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:a()})}),ze(null),$e();let t=n();t&&await Ct(t)}catch(e){alert(`edit failed: ${e.message}`)}}),F(t,O(A,{get when(){return r()>0},get children(){var e=mu(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return F(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>ze(null),y(()=>i.value=e().text),t}})}})]}function nf(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>Math.max(0,(n()-t)/1e3);return(()=>{var e=gu(),t=e.firstChild;return F(e,(()=>{var e=j(()=>i()<60);return()=>e()?`${i().toFixed(1)}s`:`${Math.floor(i()/60)}m ${Math.round(i()%60)}s`})(),t),e})()}function rf(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=_u();return F(e,()=>cf(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=(e,t=1500)=>(()=>{var n=vu();return F(n,()=>cf(e,t)),n})(),f=(e=4e3)=>n?[j(()=>d(o(),e)),(()=>{var e=yu(),t=e.firstChild;return F(e,()=>n.data?.durationMs,t),F(e,()=>n.data?.ok===!1?` · FAILED`:``,null),F(e,O(ff,{get text(){return o()}}),null),e})()]:bu();try{switch(a){case`bash`:{let e=u(`command`);s=`$ `+df(e,96);let r=u(`timeout_ms`)?` · timeout ${Math.round(Number(u(`timeout_ms`))/1e3)}s`:``;c=n?`${n.data?.durationMs??`?`}ms${r}`:`running${r}`,l=[j(()=>j(()=>e!==s.slice(2))()?d(e,800):null),j(()=>f(6e3)),!n&&O(nf,{get startedAt(){return t.ts}})];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${df(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=f(6e3);break}case`write_file`:{let e=String(i.args?.content??``);s=u(`path`)||`(no path)`,c=`${e.length} bytes`,l=[j(()=>d(e)),n?(()=>{var e=xu();return F(e,()=>df(o(),160)),e})():Su()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=Cu();return F(e,()=>cf(`- `+u(`old_text`),900)),e})(),(()=>{var e=wu();return F(e,()=>`+ `+cf(u(`new_text`),900)),e})(),n?(()=>{var e=Tu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,F(e,()=>df(o(),120),t),F(e,()=>n.data?.durationMs,r),e})():Eu()];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`:``}: ${df(t.join(`, `),80)}`:`patch`,l=[(()=>{var t=Du();return F(t,()=>e.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Ou();return P(n,`pline`+t),F(n,(()=>{var t=j(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()})),t})(),n?(()=>{var e=xu();return F(e,()=>df(o().split(`
|
|
27
|
-
`)[0]??``,140),null),F(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():ku()];break}case`list_dir`:s=u(`path`)||`.`,l=f(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=df(e,70),c=`web`,l=[(()=>{var e=xu();return F(e,O(A,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=ju();return F(e,()=>df(u(`url`),80)),e})()},get children(){var e=Au();return y(()=>N(e,`href`,u(`url`))),e}})),e})(),j(()=>f(3e3))];break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=Kc();return y(()=>t.innerHTML=Le(e)),t})(),(()=>{var e=yu(),t=e.firstChild;return F(e,()=>n.data?.durationMs,t),e})()]:Mu();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=df(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[j(()=>j(()=>!!e.length)()?(()=>{var t=Nu();return t.firstChild,F(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Tu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,F(e,()=>df(o(),160),t),F(e,()=>n.data?.durationMs,r),e})():Pu()];break}}}catch{}return(()=>{var e=Iu(),i=e.firstChild,o=i.firstChild;o.firstChild;var u=o.nextSibling;return N(e,`title`,`${a}${c?` — `+c:``}`),F(o,s,null),F(i,O(A,{get when(){return t.data?.actor},get children(){var e=Fu();return e.firstChild,F(e,()=>String(t.data.actor),null),e}}),u),F(u,n?c||``:r?`(result missed)`:`running…`),F(e,l,null),y(()=>P(e,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),e})()}function af(e){let t=e.e,n=Xd(t),r=e.prev&&e.prev.type===t.type&&Xd(e.prev).name===n.name&&t.session===e.prev.session&&t.branch===e.prev.branch;if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Lu(),r=n.firstChild.nextSibling;return r.nextSibling,F(n,()=>String(e.fromBranch??`?`),r),F(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:df(String(e.text??``),80);return(()=>{var t=Ru(),r=t.firstChild.nextSibling;return r.nextSibling,F(t,()=>String(e.event??``),r),F(t,n,null),t})()}return t.type===`todo`?(()=>{var e=zu(),n=e.firstChild.nextSibling;return n.nextSibling,F(e,()=>String(t.data?.by??`human`),n),e})():t.type===`state`?t.data.from===t.data.to?null:(()=>{var e=Bu(),n=e.firstChild;return F(e,()=>t.data.from,n),F(e,()=>t.data.to,null),F(e,(()=>{var e=j(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>P(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})():(()=>{var i=Wu(),a=i.firstChild;return F(i,O(A,{when:!r,get fallback(){return Gu()},get children(){var e=Vu();return F(e,()=>n.icon),y(t=>{var r=n.color+`33`,i=`1px solid ${n.color}66`;return r!==t.e&&Oe(e,`background`,t.e=r),i!==t.t&&Oe(e,`border`,t.t=i),t},{e:void 0,t:void 0}),e}}),a),F(a,O(A,{when:!r,get children(){var r=Uu(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return F(i,()=>n.name),F(r,O(A,{get when(){return t.data?.actor},get children(){var e=Fu();return e.firstChild,F(e,()=>String(t.data.actor),null),e}}),a),F(a,(()=>{var e=j(()=>!!t.data?.pending);return()=>e()?`pending…`:Qd(t.ts)})()),F(o,()=>t.branch),F(r,O(A,{get when(){return e.onEdit},get children(){var t=Hu();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Oe(i,`color`,n.color)),r}}),null),F(a,O(sf,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive}}),null),y(()=>P(i,`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``))),i})()}function of(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=Ku(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&(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&&N(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 sf(e){let t=e.e;switch(t.type){case`prompt`:return(()=>{var e=Kc();return y(()=>e.innerHTML=Hd(String(t.data.text??``))),e})();case`message`:return[O(A,{get when(){return j(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Gc(),n=e.firstChild.nextSibling;return F(n,()=>String(t.data.reasoning)),e}}),(()=>{var e=Kc();return y(()=>e.innerHTML=Hd(String(t.data.content??``))),e})(),O(A,{get when(){return t.data.interrupted},get children(){return qu()}}),O(A,{get when(){return t.data.final},get children(){var e=Ju(),n=e.firstChild;return F(e,O(ff,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return O(rf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=Yu(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return F(i,()=>df(e,120)),F(r,O(ff,{text:e}),null),F(a,()=>cf(e,4e3)),F(o,()=>t.data.durationMs,s),F(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>P(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=Zu(),r=n.firstChild,i=r.firstChild;i.firstChild;var a=r.nextSibling;return a.firstChild,F(i,()=>df(String(t.data?.decision??``),90),null),F(a,()=>String(t.data?.rationale??``),null),F(n,O(A,{get when(){return e.length},get children(){var t=Xu();return t.firstChild,F(t,()=>e.join(` / `),null),t}}),null),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 r=ed(),a=r.firstChild;return a.firstChild,P(r,`embed question`+(i?` answered`:``)),F(a,()=>String(t.data?.question??``),null),F(r,O(A,{when:i,get children(){return Qu()}}),null),F(r,O(A,{get when(){return n.length>0},get children(){var r=$u();return F(r,O(k,{each:n,children:n=>(()=>{var r=td();return r.$$click=()=>{let r=t.data?.actor;r?$(`/api/agents/${encodeURIComponent(String(r))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},r.disabled=i,F(r,n),r})()})),r}}),null),F(r,O(of,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=ad(),n=e.firstChild.firstChild.nextSibling;return F(e,O(A,{get when(){return t.data.goalStatus},get children(){var e=ru(),n=e.firstChild.nextSibling;return F(n,()=>String(t.data.goalStatus)),e}}),null),F(e,O(A,{get when(){return t.data.recent},get children(){var e=nd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(String(t.data.recent))),e}}),null),F(e,O(A,{get when(){return t.data.problems},get children(){var e=rd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(String(t.data.problems))),e}}),null),F(e,O(A,{get when(){return t.data.next},get children(){var e=id(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(String(t.data.next))),e}}),null),y(()=>n.innerHTML=Hd(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=od(),n=e.firstChild;return n.firstChild,F(n,()=>String(t.data.message??``),null),e})();default:return(()=>{var e=sd();return F(e,()=>cf(JSON.stringify(t.data),200)),e})()}}function cf(e,t){return e.length>t?e.slice(0,t)+` …`:e}function lf(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 uf(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 df(e,t){return cf(e.replace(/\s+/g,` `).trim(),t)}function ff(e){let[t,n]=v(!1);return(()=>{var r=cd();return r.$$click=t=>{t.stopPropagation(),navigator.clipboard.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),900)})},F(r,()=>t()?`✓`:`⧉`),r})()}function pf(e){return(()=>{var t=ld(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),F(r,()=>e.title),Ee(i,`click`,e.onClose,!0),F(n,()=>e.children,null),t})()}function mf(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 t=await $(`/api/fs${e?`?path=${encodeURIComponent(e)}`:``}`);n(t.path),i(t.entries)}ee(()=>p(t()));let m=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 O(pf,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=dd(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,g=h.nextSibling,_=g.nextSibling,v=f.nextSibling,b=v.nextSibling,x=b.firstChild,S=x.firstChild.nextSibling,ee=x.nextSibling,C=ee.firstChild.nextSibling,te=ee.nextSibling.firstChild.nextSibling,ne=b.nextSibling;return i.addEventListener(`submit`,m),h.$$input=e=>n(e.currentTarget.value),g.$$click=()=>p(t()),_.$$click=()=>p(`..`),F(v,O(k,{get each(){return r()},children:e=>(()=>{var n=fd();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),F(n,e,null),n})()})),S.$$input=e=>o(e.currentTarget.value),C.addEventListener(`change`,e=>c(e.currentTarget.value)),F(C,O(k,{get each(){return e.providers},children:e=>(()=>{var t=Bl();return F(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),F(i,O(A,{get when(){return d()},get children(){var e=ud();return F(e,d),e}}),ne),y(()=>h.value=t()),y(()=>S.value=a()),y(()=>C.value=s()),y(()=>te.value=l()),i}})}function hf(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),l=(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}:{}}));async function u(t){try{let n=await $(`/api/agents/${e.agentId}/tree${t?`?path=${encodeURIComponent(t)}`:``}`);return l(t,n.entries??[])}catch(e){return c(e.message),null}}b(()=>{e.agentId,i(new Set),n(new Map),u(``).then(e=>{e&&n(new Map([[``,e]]))})});let d=async e=>{let a=new Set(r());if(a.has(e.path)){a.delete(e.path),i(a);return}if(a.add(e.path),i(a),!t().has(e.path)){let t=await u(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[f,p]=v(``),[m,h]=v(!1),[g,_]=v(`code`),[x,S]=v(``),[ee,te]=v(!1),ne=e=>/\.(md|markdown|mdx)$/i.test(e),w=0,re=async e=>{let t=++w;p(``),h(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-BLFDwcS0.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(w!==t)return;p(e=>e+r)}}catch{w===t&&p(``)}finally{w===t&&h(!1)}};C(()=>{w++});let T=async(t,n)=>{try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),S(r.content??``),_(r.binary?`code`:n),!r.binary&&n!==`md`&&re({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ie=async()=>{let t=a();if(!(!t||ee())){te(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:x(),baseContent:t.content})}),o({...t,content:x()}),Q(`saved ${t.path}`)}catch(e){let t=e.message;t.includes(`409`)||t.includes(`changed on disk`)?Q(`file changed on disk — reopen to see the current version`):Q(`save failed: ${t}`)}finally{te(!1)}}},ae=e=>!e.binary&&!e.truncated,oe=(e,n)=>[(()=>{var t=md(),i=t.firstChild,a=i.nextSibling;return t.$$click=()=>e.dir?void d(e):void T(e,`code`),F(i,(()=>{var t=j(()=>!!e.dir);return()=>t()?r().has(e.path)?`▾`:`▸`:`·`})()),F(a,()=>e.name),F(t,O(A,{get when(){return j(()=>!e.dir)()&&e.size!==void 0},get children(){var t=pd();return F(t,()=>uf(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``),a=`padding-left:${n*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&P(t,r.e=i),r.t=De(t,a,r.t),o!==r.a&&N(t,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),t})(),O(A,{get when(){return j(()=>!!e.dir)()&&r().has(e.path)},get children(){return O(k,{get each(){return t().get(e.path)??[]},children:e=>oe(e,n+1)})}})],E=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace;return[(()=>{var e=hd(),t=e.firstChild.nextSibling;return t.firstChild,F(t,E,null),e})(),(()=>{var e=gd();return F(e,O(A,{get when(){return(t().get(``)??[]).length>0},get fallback(){return(()=>{var e=_d();return F(e,()=>s()||`empty workspace`),e})()},get children(){return O(k,{get each(){return t().get(``)??[]},children:e=>oe(e,0)})}})),e})(),O(A,{get when(){return a()},children:e=>O(pf,{get title(){return`🗂 ${e().path}`},onClose:()=>{w++,o(null)},get children(){return[(()=>{var t=bd(),n=t.firstChild;return F(t,O(A,{get when(){return j(()=>!!ne(e().path))()&&!e().binary},get children(){var e=vd();return e.$$click=()=>_(`md`),y(()=>P(e,g()===`md`?`on`:``)),e}}),n),n.$$click=()=>{_(`code`),f()||re({path:e().path,content:e().content,truncated:e().truncated})},F(t,O(A,{get when(){return ae(e())},get children(){var e=yd();return e.$$click=()=>_(`edit`),y(()=>P(e,g()===`edit`?`on`:``)),e}}),null),y(()=>P(n,g()===`code`?`on`:``)),t})(),O(A,{get when(){return!e().binary},get fallback(){return Sd()},get children(){return O(A,{get when(){return g()===`edit`},get fallback(){return O(A,{get when(){return j(()=>g()===`md`)()&&ne(e().path)},get fallback(){return O(gf,{get path(){return e().path},get content(){return e().content},get html(){return f()},get pending(){return m()},get truncated(){return!!e().truncated}})},get children(){var t=Cd();return y(()=>t.innerHTML=Le(e().content)),t}})},get children(){var t=xd(),n=t.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>S(e.currentTarget.value),N(n,`spellcheck`,!1),F(r,()=>uf(x().length),i),a.$$click=()=>void ie(),F(a,()=>ee()?`saving…`:`💾 save`),y(()=>a.disabled=ee()||x()===e().content),y(()=>n.value=x()),t}})}})]}})})]}function gf(e){return[O(A,{get when(){return e.html},get fallback(){return j(()=>!!e.pending)()?(()=>{var t=Ed(),n=t.firstChild.nextSibling;return n.nextSibling,F(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Dd();return F(t,()=>e.content),t})()},get children(){var t=wd();return y(()=>t.innerHTML=e.html),t}}),O(A,{get when(){return e.truncated},get children(){return Td()}})]}var _f=[{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)`}],vf={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 yf(e){let[t,n]=v(_f[0]),[r,i]=v(_f[0].url),[a,o]=v(``),[s,c]=v(_f[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);C(()=>clearTimeout(n))});let ee=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${uf(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(` · `)},te=()=>ee(s()),ne=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=jd(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,ee=x.firstChild.nextSibling,C=x.nextSibling,w=C.firstChild.nextSibling,re=w.nextSibling,T=C.nextSibling,ie=T.firstChild.nextSibling,ae=ie.firstChild.nextSibling,oe=ie.nextSibling.firstChild.nextSibling,E=T.nextSibling;return n.addEventListener(`submit`,ne),F(u,()=>[..._f,vf].map(e=>(()=>{var n=Md();return n.$$click=()=>S(e),F(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),F(n,O(A,{get when(){return t().hint},get children(){var e=Od();return F(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),F(b,()=>_f.map(e=>(()=>{var t=Bl();return y(()=>t.value=e.url),t})())),ee.$$input=e=>o(e.currentTarget.value),w.$$input=e=>c(e.currentTarget.value),F(re,()=>l().map(e=>(()=>{var t=Bl();return y(()=>t.value=e.id),t})())),F(n,O(A,{get when(){return l().length>0},get fallback(){return Nd()},get children(){var e=Ad(),t=e.firstChild;return F(e,()=>l().length,t),F(e,O(A,{get when(){return te()},get children(){return[` · `,(()=>{var e=kd();return F(e,te),e})()]}}),null),e}}),T),ae.$$input=e=>f(e.currentTarget.value),oe.$$input=e=>m(e.currentTarget.value),F(n,O(A,{get when(){return _()},get children(){var e=ud();return F(e,_),e}}),E),F(E,()=>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&&N(w,`placeholder`,e.e=n),r!==e.t&&(E.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>ae.value=d()),y(()=>oe.value=p()),e})()}function bf(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,o]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[s,c]=v(e.cfg.progressMinChars??4e3),[l,u]=v(Math.round((e.cfg.contextTokenBudget??96e3)/1e3)),[d,f]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[p,m]=v(e.cfg.maxSpawnDepth??3),[h,g]=v((e.cfg.tasks??[]).map(e=>({...e}))),[_,b]=v(``),x=()=>(e.cfg.agents??[]).map(e=>e.id),S=()=>{let e={};for(let n of t()){if(!n.name.trim())return b(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return b(`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},ee=async t=>{t.preventDefault(),b(``);let n=S();if(!n)return;let i=h().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){b(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){b(`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,a())*6e4,progressMinChars:Math.max(100,s()),contextTokenBudget:Math.max(1e3,l())*1e3,...d()>0?{contextWindowTokens:d()*1e3}:{},maxSpawnDepth:Math.max(0,p()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){b(e.message)}},C=(e,t,n,r)=>(()=>{var i=Pd(),a=i.firstChild;return N(i,`title`,r),F(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return O(pf,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Fd(),b=v.firstChild,S=b.firstChild.nextSibling,te=S.nextSibling;te.firstChild;var ne=te.nextSibling.firstChild.firstChild.nextSibling;ne.firstChild;var w=b.nextSibling,re=w.firstChild.nextSibling,T=w.nextSibling,ie=T.firstChild.nextSibling,ae=T.nextSibling;ae.firstChild;var oe=ae.nextSibling;return v.addEventListener(`submit`,ee),F(b,O(k,{get each(){return t()},children:(e,r)=>(()=>{var i=Id(),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})()}),S),S.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),F(te,O(k,{each:_f,children:e=>(()=>{var a=Ld();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)},F(a,()=>e.label,null),y(()=>N(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),ne.addEventListener(`change`,e=>i(e.currentTarget.value)),F(ne,O(k,{get each(){return[...new Set(t().map(e=>e.name.trim()).filter(Boolean))]},children:e=>(()=>{var t=Bl();return t.value=e,F(t,e),t})()}),null),F(re,()=>C(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),null),F(re,()=>C(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),null),F(re,()=>C(`compact budget (k tok)`,l(),e=>u(e),`auto-compact threshold — defaults to 75% of context window when empty; manual override in k tokens`),null),F(re,()=>C(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),F(re,()=>C(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),F(T,O(A,{get when(){return h().length>0},get children(){return O(k,{get each(){return h()},children:(e,t)=>(()=>{var n=Rd(),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=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().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})()})}}),ie),ie.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),F(ae,O(k,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Bd(),n=t.firstChild,r=n.nextSibling;return F(n,()=>e.id),F(r,()=>e.workspace),F(t,O(A,{get when(){return e.parent},get children(){var t=zd();return t.firstChild,F(t,()=>e.parent,null),t}}),null),t})()}),null),F(v,O(A,{get when(){return _()},get children(){var e=ud();return F(e,_),e}}),oe),y(()=>ne.value=r()),v}})}Te([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),we(()=>O(tf,{}),document.getElementById(`root`));export{Pc as t};
|
|
28
|
-
//# sourceMappingURL=index-
|
|
27
|
+
`)[0]??``,140),null),F(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():ku()];break}case`list_dir`:s=u(`path`)||`.`,l=f(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=df(e,70),c=`web`,l=[(()=>{var e=xu();return F(e,O(A,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=ju();return F(e,()=>df(u(`url`),80)),e})()},get children(){var e=Au();return y(()=>N(e,`href`,u(`url`))),e}})),e})(),j(()=>f(3e3))];break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=Kc();return y(()=>t.innerHTML=Le(e)),t})(),(()=>{var e=yu(),t=e.firstChild;return F(e,()=>n.data?.durationMs,t),e})()]:Mu();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=df(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[j(()=>j(()=>!!e.length)()?(()=>{var t=Nu();return t.firstChild,F(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Tu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,F(e,()=>df(o(),160),t),F(e,()=>n.data?.durationMs,r),e})():Pu()];break}}}catch{}return(()=>{var e=Iu(),i=e.firstChild,o=i.firstChild;o.firstChild;var u=o.nextSibling;return N(e,`title`,`${a}${c?` — `+c:``}`),F(o,s,null),F(i,O(A,{get when(){return t.data?.actor},get children(){var e=Fu();return e.firstChild,F(e,()=>String(t.data.actor),null),e}}),u),F(u,n?c||``:r?`(result missed)`:`running…`),F(e,l,null),y(()=>P(e,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),e})()}function af(e){let t=e.e,n=Xd(t),r=e.prev&&e.prev.type===t.type&&Xd(e.prev).name===n.name&&t.session===e.prev.session&&t.branch===e.prev.branch;if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Lu(),r=n.firstChild.nextSibling;return r.nextSibling,F(n,()=>String(e.fromBranch??`?`),r),F(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:df(String(e.text??``),80);return(()=>{var t=Ru(),r=t.firstChild.nextSibling;return r.nextSibling,F(t,()=>String(e.event??``),r),F(t,n,null),t})()}return t.type===`todo`?(()=>{var e=zu(),n=e.firstChild.nextSibling;return n.nextSibling,F(e,()=>String(t.data?.by??`human`),n),e})():t.type===`state`?t.data.from===t.data.to?null:(()=>{var e=Bu(),n=e.firstChild;return F(e,()=>t.data.from,n),F(e,()=>t.data.to,null),F(e,(()=>{var e=j(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>P(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})():(()=>{var i=Wu(),a=i.firstChild;return F(i,O(A,{when:!r,get fallback(){return Gu()},get children(){var e=Vu();return F(e,()=>n.icon),y(t=>{var r=n.color+`33`,i=`1px solid ${n.color}66`;return r!==t.e&&Oe(e,`background`,t.e=r),i!==t.t&&Oe(e,`border`,t.t=i),t},{e:void 0,t:void 0}),e}}),a),F(a,O(A,{when:!r,get children(){var r=Uu(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return F(i,()=>n.name),F(r,O(A,{get when(){return t.data?.actor},get children(){var e=Fu();return e.firstChild,F(e,()=>String(t.data.actor),null),e}}),a),F(a,(()=>{var e=j(()=>!!t.data?.pending);return()=>e()?`pending…`:Qd(t.ts)})()),F(o,()=>t.branch),F(r,O(A,{get when(){return e.onEdit},get children(){var t=Hu();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Oe(i,`color`,n.color)),r}}),null),F(a,O(sf,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive}}),null),y(()=>P(i,`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``))),i})()}function of(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=Ku(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&(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&&N(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 sf(e){let t=e.e;switch(t.type){case`prompt`:return(()=>{var e=Kc();return y(()=>e.innerHTML=Hd(String(t.data.text??``))),e})();case`message`:return[O(A,{get when(){return j(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Gc(),n=e.firstChild.nextSibling;return F(n,()=>String(t.data.reasoning)),e}}),(()=>{var e=Kc();return y(()=>e.innerHTML=Hd(String(t.data.content??``))),e})(),O(A,{get when(){return t.data.interrupted},get children(){return qu()}}),O(A,{get when(){return t.data.final},get children(){var e=Ju(),n=e.firstChild;return F(e,O(ff,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return O(rf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=Yu(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return F(i,()=>df(e,120)),F(r,O(ff,{text:e}),null),F(a,()=>cf(e,4e3)),F(o,()=>t.data.durationMs,s),F(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>P(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=Zu(),r=n.firstChild,i=r.firstChild;i.firstChild;var a=r.nextSibling;return a.firstChild,F(i,()=>df(String(t.data?.decision??``),90),null),F(a,()=>String(t.data?.rationale??``),null),F(n,O(A,{get when(){return e.length},get children(){var t=Xu();return t.firstChild,F(t,()=>e.join(` / `),null),t}}),null),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 r=ed(),a=r.firstChild;return a.firstChild,P(r,`embed question`+(i?` answered`:``)),F(a,()=>String(t.data?.question??``),null),F(r,O(A,{when:i,get children(){return Qu()}}),null),F(r,O(A,{get when(){return n.length>0},get children(){var r=$u();return F(r,O(k,{each:n,children:n=>(()=>{var r=td();return r.$$click=()=>{let r=t.data?.actor;r?$(`/api/agents/${encodeURIComponent(String(r))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},r.disabled=i,F(r,n),r})()})),r}}),null),F(r,O(of,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=ad(),n=e.firstChild.firstChild.nextSibling;return F(e,O(A,{get when(){return t.data.goalStatus},get children(){var e=ru(),n=e.firstChild.nextSibling;return F(n,()=>String(t.data.goalStatus)),e}}),null),F(e,O(A,{get when(){return t.data.recent},get children(){var e=nd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(String(t.data.recent))),e}}),null),F(e,O(A,{get when(){return t.data.problems},get children(){var e=rd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(String(t.data.problems))),e}}),null),F(e,O(A,{get when(){return t.data.next},get children(){var e=id(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(String(t.data.next))),e}}),null),y(()=>n.innerHTML=Hd(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=od(),n=e.firstChild;return n.firstChild,F(n,()=>String(t.data.message??``),null),e})();default:return(()=>{var e=sd();return F(e,()=>cf(JSON.stringify(t.data),200)),e})()}}function cf(e,t){return e.length>t?e.slice(0,t)+` …`:e}function lf(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 uf(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 df(e,t){return cf(e.replace(/\s+/g,` `).trim(),t)}function ff(e){let[t,n]=v(!1);return(()=>{var r=cd();return r.$$click=t=>{t.stopPropagation(),navigator.clipboard.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),900)})},F(r,()=>t()?`✓`:`⧉`),r})()}function pf(e){return(()=>{var t=ld(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),F(r,()=>e.title),Ee(i,`click`,e.onClose,!0),F(n,()=>e.children,null),t})()}function mf(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 t=await $(`/api/fs${e?`?path=${encodeURIComponent(e)}`:``}`);n(t.path),i(t.entries)}ee(()=>p(t()));let m=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 O(pf,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=dd(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,g=h.nextSibling,_=g.nextSibling,v=f.nextSibling,b=v.nextSibling,x=b.firstChild,S=x.firstChild.nextSibling,ee=x.nextSibling,C=ee.firstChild.nextSibling,te=ee.nextSibling.firstChild.nextSibling,ne=b.nextSibling;return i.addEventListener(`submit`,m),h.$$input=e=>n(e.currentTarget.value),g.$$click=()=>p(t()),_.$$click=()=>p(`..`),F(v,O(k,{get each(){return r()},children:e=>(()=>{var n=fd();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),F(n,e,null),n})()})),S.$$input=e=>o(e.currentTarget.value),C.addEventListener(`change`,e=>c(e.currentTarget.value)),F(C,O(k,{get each(){return e.providers},children:e=>(()=>{var t=Bl();return F(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),F(i,O(A,{get when(){return d()},get children(){var e=ud();return F(e,d),e}}),ne),y(()=>h.value=t()),y(()=>S.value=a()),y(()=>C.value=s()),y(()=>te.value=l()),i}})}function hf(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),l=(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}:{}}));async function u(t){try{let n=await $(`/api/agents/${e.agentId}/tree${t?`?path=${encodeURIComponent(t)}`:``}`);return l(t,n.entries??[])}catch(e){return c(e.message),null}}b(()=>{e.agentId,i(new Set),n(new Map),u(``).then(e=>{e&&n(new Map([[``,e]]))})});let d=async e=>{let a=new Set(r());if(a.has(e.path)){a.delete(e.path),i(a);return}if(a.add(e.path),i(a),!t().has(e.path)){let t=await u(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[f,p]=v(``),[m,h]=v(!1),[g,_]=v(`code`),[x,S]=v(``),[ee,te]=v(!1),ne=e=>/\.(md|markdown|mdx)$/i.test(e),w=0,re=async e=>{let t=++w;p(``),h(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-BDkPMeXc.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(w!==t)return;p(e=>e+r)}}catch{w===t&&p(``)}finally{w===t&&h(!1)}};C(()=>{w++});let T=async(t,n)=>{try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),S(r.content??``),_(r.binary?`code`:n),!r.binary&&n!==`md`&&re({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ie=async()=>{let t=a();if(!(!t||ee())){te(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:x(),baseContent:t.content})}),o({...t,content:x()}),Q(`saved ${t.path}`)}catch(e){let t=e.message;t.includes(`409`)||t.includes(`changed on disk`)?Q(`file changed on disk — reopen to see the current version`):Q(`save failed: ${t}`)}finally{te(!1)}}},ae=e=>!e.binary&&!e.truncated,oe=(e,n)=>[(()=>{var t=md(),i=t.firstChild,a=i.nextSibling;return t.$$click=()=>e.dir?void d(e):void T(e,`code`),F(i,(()=>{var t=j(()=>!!e.dir);return()=>t()?r().has(e.path)?`▾`:`▸`:`·`})()),F(a,()=>e.name),F(t,O(A,{get when(){return j(()=>!e.dir)()&&e.size!==void 0},get children(){var t=pd();return F(t,()=>uf(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``),a=`padding-left:${n*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&P(t,r.e=i),r.t=De(t,a,r.t),o!==r.a&&N(t,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),t})(),O(A,{get when(){return j(()=>!!e.dir)()&&r().has(e.path)},get children(){return O(k,{get each(){return t().get(e.path)??[]},children:e=>oe(e,n+1)})}})],E=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace;return[(()=>{var e=hd(),t=e.firstChild.nextSibling;return t.firstChild,F(t,E,null),e})(),(()=>{var e=gd();return F(e,O(A,{get when(){return(t().get(``)??[]).length>0},get fallback(){return(()=>{var e=_d();return F(e,()=>s()||`empty workspace`),e})()},get children(){return O(k,{get each(){return t().get(``)??[]},children:e=>oe(e,0)})}})),e})(),O(A,{get when(){return a()},children:e=>O(pf,{get title(){return`🗂 ${e().path}`},onClose:()=>{w++,o(null)},get children(){return[(()=>{var t=bd(),n=t.firstChild;return F(t,O(A,{get when(){return j(()=>!!ne(e().path))()&&!e().binary},get children(){var e=vd();return e.$$click=()=>_(`md`),y(()=>P(e,g()===`md`?`on`:``)),e}}),n),n.$$click=()=>{_(`code`),f()||re({path:e().path,content:e().content,truncated:e().truncated})},F(t,O(A,{get when(){return ae(e())},get children(){var e=yd();return e.$$click=()=>_(`edit`),y(()=>P(e,g()===`edit`?`on`:``)),e}}),null),y(()=>P(n,g()===`code`?`on`:``)),t})(),O(A,{get when(){return!e().binary},get fallback(){return Sd()},get children(){return O(A,{get when(){return g()===`edit`},get fallback(){return O(A,{get when(){return j(()=>g()===`md`)()&&ne(e().path)},get fallback(){return O(gf,{get path(){return e().path},get content(){return e().content},get html(){return f()},get pending(){return m()},get truncated(){return!!e().truncated}})},get children(){var t=Cd();return y(()=>t.innerHTML=Le(e().content)),t}})},get children(){var t=xd(),n=t.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>S(e.currentTarget.value),N(n,`spellcheck`,!1),F(r,()=>uf(x().length),i),a.$$click=()=>void ie(),F(a,()=>ee()?`saving…`:`💾 save`),y(()=>a.disabled=ee()||x()===e().content),y(()=>n.value=x()),t}})}})]}})})]}function gf(e){return[O(A,{get when(){return e.html},get fallback(){return j(()=>!!e.pending)()?(()=>{var t=Ed(),n=t.firstChild.nextSibling;return n.nextSibling,F(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Dd();return F(t,()=>e.content),t})()},get children(){var t=wd();return y(()=>t.innerHTML=e.html),t}}),O(A,{get when(){return e.truncated},get children(){return Td()}})]}var _f=[{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)`}],vf={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 yf(e){let[t,n]=v(_f[0]),[r,i]=v(_f[0].url),[a,o]=v(``),[s,c]=v(_f[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);C(()=>clearTimeout(n))});let ee=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${uf(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(` · `)},te=()=>ee(s()),ne=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=jd(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,ee=x.firstChild.nextSibling,C=x.nextSibling,w=C.firstChild.nextSibling,re=w.nextSibling,T=C.nextSibling,ie=T.firstChild.nextSibling,ae=ie.firstChild.nextSibling,oe=ie.nextSibling.firstChild.nextSibling,E=T.nextSibling;return n.addEventListener(`submit`,ne),F(u,()=>[..._f,vf].map(e=>(()=>{var n=Md();return n.$$click=()=>S(e),F(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),F(n,O(A,{get when(){return t().hint},get children(){var e=Od();return F(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),F(b,()=>_f.map(e=>(()=>{var t=Bl();return y(()=>t.value=e.url),t})())),ee.$$input=e=>o(e.currentTarget.value),w.$$input=e=>c(e.currentTarget.value),F(re,()=>l().map(e=>(()=>{var t=Bl();return y(()=>t.value=e.id),t})())),F(n,O(A,{get when(){return l().length>0},get fallback(){return Nd()},get children(){var e=Ad(),t=e.firstChild;return F(e,()=>l().length,t),F(e,O(A,{get when(){return te()},get children(){return[` · `,(()=>{var e=kd();return F(e,te),e})()]}}),null),e}}),T),ae.$$input=e=>f(e.currentTarget.value),oe.$$input=e=>m(e.currentTarget.value),F(n,O(A,{get when(){return _()},get children(){var e=ud();return F(e,_),e}}),E),F(E,()=>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&&N(w,`placeholder`,e.e=n),r!==e.t&&(E.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>ae.value=d()),y(()=>oe.value=p()),e})()}function bf(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,o]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[s,c]=v(e.cfg.progressMinChars??4e3),[l,u]=v(Math.round((e.cfg.contextTokenBudget??96e3)/1e3)),[d,f]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[p,m]=v(e.cfg.maxSpawnDepth??3),[h,g]=v((e.cfg.tasks??[]).map(e=>({...e}))),[_,b]=v(``),x=()=>(e.cfg.agents??[]).map(e=>e.id),S=()=>{let e={};for(let n of t()){if(!n.name.trim())return b(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return b(`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},ee=async t=>{t.preventDefault(),b(``);let n=S();if(!n)return;let i=h().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){b(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){b(`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,a())*6e4,progressMinChars:Math.max(100,s()),contextTokenBudget:Math.max(1e3,l())*1e3,...d()>0?{contextWindowTokens:d()*1e3}:{},maxSpawnDepth:Math.max(0,p()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){b(e.message)}},C=(e,t,n,r)=>(()=>{var i=Pd(),a=i.firstChild;return N(i,`title`,r),F(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return O(pf,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Fd(),b=v.firstChild,S=b.firstChild.nextSibling,te=S.nextSibling;te.firstChild;var ne=te.nextSibling.firstChild.firstChild.nextSibling;ne.firstChild;var w=b.nextSibling,re=w.firstChild.nextSibling,T=w.nextSibling,ie=T.firstChild.nextSibling,ae=T.nextSibling;ae.firstChild;var oe=ae.nextSibling;return v.addEventListener(`submit`,ee),F(b,O(k,{get each(){return t()},children:(e,r)=>(()=>{var i=Id(),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})()}),S),S.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),F(te,O(k,{each:_f,children:e=>(()=>{var a=Ld();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)},F(a,()=>e.label,null),y(()=>N(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),ne.addEventListener(`change`,e=>i(e.currentTarget.value)),F(ne,O(k,{get each(){return[...new Set(t().map(e=>e.name.trim()).filter(Boolean))]},children:e=>(()=>{var t=Bl();return t.value=e,F(t,e),t})()}),null),F(re,()=>C(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),null),F(re,()=>C(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),null),F(re,()=>C(`compact budget (k tok)`,l(),e=>u(e),`auto-compact threshold — defaults to 75% of context window when empty; manual override in k tokens`),null),F(re,()=>C(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),F(re,()=>C(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),F(T,O(A,{get when(){return h().length>0},get children(){return O(k,{get each(){return h()},children:(e,t)=>(()=>{var n=Rd(),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=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().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})()})}}),ie),ie.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),F(ae,O(k,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Bd(),n=t.firstChild,r=n.nextSibling;return F(n,()=>e.id),F(r,()=>e.workspace),F(t,O(A,{get when(){return e.parent},get children(){var t=zd();return t.firstChild,F(t,()=>e.parent,null),t}}),null),t})()}),null),F(v,O(A,{get when(){return _()},get children(){var e=ud();return F(e,_),e}}),oe),y(()=>ne.value=r()),v}})}Te([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),we(()=>O(tf,{}),document.getElementById(`root`));export{Pc as t};
|
|
28
|
+
//# sourceMappingURL=index-BNT60fyY.js.map
|