teapot-coding-agent 0.29.3 → 0.29.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/log/events.js +146 -8
- package/dist/master.js +68 -8
- package/dist/model-meta.js +22 -1
- package/package.json +1 -1
- package/public/assets/{index-B7AHe2fu.css → index-CnX2G_Uc.css} +1 -1
- package/public/assets/{index-Da7DVjHE.js → index-DIjwa8pX.js} +10 -10
- package/public/assets/index-DIjwa8pX.js.map +1 -0
- package/public/assets/{shiki-yJJUtwxS.js → shiki-C_RJDjY3.js} +2 -2
- package/public/assets/{shiki-yJJUtwxS.js.map → shiki-C_RJDjY3.js.map} +1 -1
- package/public/index.html +2 -2
- package/public/assets/index-Da7DVjHE.js.map +0 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
`)).split(`
|
|
3
3
|
`))}function Ie(e){let t=[],n=0;for(;n<e.length;){let o=e[n];if(/^```[^\n]*$/.test(o)&&!/^```.+\`\`\`/.test(o)){let r=[];for(n++;n<e.length&&!/^```\s*$/.test(e[n]);)r.push(e[n++]);n++,t.push(`<pre><code>${r.join(`
|
|
4
4
|
`)}</code></pre>`);continue}if(/^ {0,3}(?:-{3,}|\*{3,}|_{3,})\s*$/.test(o)){t.push(`<hr>`),n++;continue}let s=o.match(/^(#{1,6})\s+(.*)$/);if(s){t.push(`<h${s[1].length}>${a(s[2])}</h${s[1].length}>`),n++;continue}if(/^\s*>/.test(o)){let r=[];for(;n<e.length&&/^\s*>/.test(e[n]);)r.push(e[n++].replace(/^\s*>\s?/,``));t.push(`<blockquote>${Ie(r)}</blockquote>`);continue}if(o.includes(`|`)&&n+1<e.length&&Re(e[n+1])){let r=Le(e[n+1]).map(e=>e.startsWith(`:`)&&e.endsWith(`:`)?`center`:e.endsWith(`:`)?`right`:`left`),i=Le(o);n+=2;let s=[];for(;n<e.length&&/\S/.test(e[n])&&e[n].includes(`|`);)s.push(Le(e[n])),n++;let c=(e,t,n)=>{let i=r[t];return`<${n}${i&&i!==`left`?` style="text-align:${i}"`:``}>${a(e)}</${n}>`},l=i.some(e=>e!==``);t.push(`<div class="tbl"><table>`+(l?`<thead><tr>${i.map((e,t)=>c(e,t,`th`)).join(``)}</tr></thead>`:``)+`<tbody>${s.map(e=>`<tr>${e.map((e,t)=>c(e,t,`td`)).join(``)}</tr>`).join(``)}</tbody></table></div>`);continue}if(Pe.test(o)){t.push(i(r(o.match(Pe)[1])));continue}if(/^\s*$/.test(o)){n++;continue}let c=n,l=[];for(;n<e.length&&!/^\s*$/.test(e[n])&&!/^#{1,6}\s/.test(e[n])&&!e[n].startsWith("```")&&!/^ {0,3}(?:-{3,}|\*{3,}|_{3,})\s*$/.test(e[n])&&!/^\s*>/.test(e[n])&&!Pe.test(e[n])&&!(e[n].includes(`|`)&&n+1<e.length&&Re(e[n+1]));)l.push(e[n++]);n===c&&l.push(e[n++]),t.push(`<p>${l.map(a).join(`<br>`)}</p>`)}return t.join(`
|
|
5
|
-
`);function r(e){return e.replace(/\t/g,` `).length}function i(t){let o=null,s=[];for(;n<e.length;){let c=e[n].match(Pe);if(!c)break;let l=r(c[1]);if(l<t)break;let u=/^\d/.test(c[2]);if(o===null)o=u;else if(u!==o)break;n++;let d=c[3];for(;n<e.length&&/\S/.test(e[n])&&!Pe.test(e[n])&&!/^#{1,6}\s/.test(e[n])&&!e[n].startsWith("```")&&!/^\s*>/.test(e[n]);)d+=` `+e[n].trim(),n++;let f=``,p=e[n]?.match(Pe);p&&r(p[1])>l&&(f=i(r(p[1])));let m=d.match(/^\[( |x|X)\]\s+(.*)$/),h=m?`<input type="checkbox" disabled${m[1].toLowerCase()===`x`?` checked`:``}> `:``;s.push(`<li>${h}${a(m?m[2]:d)}${f}</li>`)}return o?`<ol>${s.join(``)}</ol>`:`<ul>${s.join(``)}</ul>`}function a(e){let t=[];return e=e.replace(/\u0000/g,``),e=e.replace(/`([^`]+)`/g,(e,n)=>(t.push(`<code>${n}</code>`),`\ue000${t.length-1}\uE001`)),e=e.replace(/!\[([^\]]*)\]\((https?:\/\/[^)\s]+)(?:\s+"[^)]*")?\)/g,`<img src="$2" alt="$1" loading="lazy">`),e=e.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)(?:\s+"[^)]*")?\)/g,`<a href="$2" rel="noopener noreferrer" target="_blank">$1</a>`),e=e.replace(/(?<!["'=\w])(https?:\/\/[^\s<>"')\]]*[^\s<>"')\].,;:!?"')\]])/g,`<a href="$1">$1</a>`),e=e.replace(/\*\*\*([\s\S]+?)\*\*\*/g,`<strong><em>$1</em></strong>`),e=e.replace(/\*\*([\s\S]+?)\*\*/g,`<strong>$1</strong>`),e=e.replace(/(^|[^\w])__(?=\S)([\s\S]*?\S)__(?!\w)/g,`$1<strong>$2</strong>`),e=e.replace(/(^|[^\w*])\*(?!\s)([^*\n]+?)\*(?![\w*])/g,`$1<em>$2</em>`),e=e.replace(/(^|[^\w])_(?!\s)([^_\n]+?)_(?!\w)/g,`$1<em>$2</em>`),e=e.replace(/~~([\s\S]+?)~~/g,`<del>$1</del>`),e.replace(/\ue000(\d+)\ue001/g,(e,n)=>t[+n]??``)}}function Le(e){let t=e.trim();t.startsWith(`|`)&&(t=t.slice(1));let n=[],r=``;for(let e=0;e<t.length;e++){let i=t[e];if(i===`\\`&&t[e+1]===`|`)r+=`|`,e++;else if(i==="`"){let n=t.indexOf("`",e+1);if(n!==-1){r+=t.slice(e,n+1),e=n;continue}r+=i}else{if(i===`|`&&e===t.length-1)break;i===`|`?(n.push(r.trim()),r=``):r+=i}}return n.push(r.trim()),n.filter((e,r)=>!(e===``&&r===n.length-1&&t.endsWith(`|`)))}function Re(e){let t=e.trim();if(!t.includes(`|`)||!t.includes(`-`))return!1;let n=Le(t);return n.every(e=>/^:?-+:?$/.test(e))&&n.some(e=>e!==``)}function ze(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function Be(e){if(e==null||!Number.isFinite(e))return`?`;let t=Math.max(0,e);if(t<1e3)return`${Math.round(t)}ms`;if(t<6e4)return`${(t/1e3).toFixed(1)}s`;if(t<36e5){let e=Math.floor(t/6e4),n=Math.round(t%6e4/1e3);return n?`${e}m ${n}s`:`${e}m`}let n=Math.floor(t/36e5),r=Math.round(t%36e5/6e4);return r?`${n}h ${r}m`:`${n}h`}function Ve(e,t,n,r=Date.now()){let i=new Map(e);return i.set(t,{text:n.text??``,reasoning:n.reasoning??``,at:r}),i}function He(e,t){if(!e.has(t))return e;let n=new Map(e);return n.delete(t),n}function Ue(e){let t=e;return t?.type===`state`&&t.data?.detail===`llm turn start`}function We(e){return e===`running`||e===`waiting`}function Ge(e,t,n){if(!e)return!1;if(!e.text)return!We(n);if(!We(n))return!0;let r=e.text.trim();return t.some(e=>e.type===`message`&&e.data?.role===`assistant`&&String(e.data.content??``).trim()===r)}function Ke(e){if(!e)return!1;let t=e.data?.actor;return!(typeof t==`string`&&t.length>0)}function qe(e,t){let n=[];for(let r of e.keys()){let e=t(r);e!==void 0&&(We(e)||n.push(r))}if(n.length===0)return e;let r=new Map(e);for(let e of n)r.delete(e);return r}function Je(e,t,n){return!e||!We(n)||Ge(e,t,n)?null:e}function Ye(e,t){if(!t.length)return e;let n=e.reduce((e,t)=>Math.max(e,t.seq),0),r=t.map((e,t)=>({...e,seq:n+1+t}));return[...e,...r]}function Xe(e,t){return t===void 0||t<=e.seq?e:{...e,seq:t}}function Ze(e){return e.reduce((e,t)=>Math.max(e,t.seq),0)+1}function Qe(e){let t=e.event;return t===`status`||t===`audit-started`||t===`audit`||t===`audit-failed`?t:`other`}function $e(e){let t=e.trim().toLowerCase();return t===``||t===`(no detail)`||t===`no detail`||t===`(none)`||t===`(empty)`}function et(e,t){let n=String(e??``).trim();return $e(n)?$e(t)?``:t:n}function tt(e){switch(Qe(e)){case`audit-started`:return{label:`🔍 completion audit started`,detail:String(e.verify??``).trim()||`checking the verification contract…`,tone:``,markdown:!1,hasCard:!0};case`audit`:{let t=!$e(String(e.feedback??``));return e.verdict===`approved`?{label:`✅ audit: approved`,detail:et(e.feedback??``,``),tone:`ok`,markdown:!0,hasCard:t}:{label:`⚠ audit: changes required`,detail:et(e.feedback??``,``),tone:`warn`,markdown:!0,hasCard:t}}case`audit-failed`:return{label:`🔍 audit unavailable — finish accepted`,detail:String(e.detail??``).trim()||`the auditor could not be reached`,tone:`err`,markdown:!1,hasCard:!0};case`status`:{let t=String(e.status??``).trim();return t?t===`done`?{label:`🏁 finish claimed — pending audit`,detail:`the agent called finish(goalComplete=true); the verification contract is now being audited`,tone:``,markdown:!1,hasCard:!0}:t===`active`?{label:`▶ goal reopened`,detail:`the audit rejected the finish — work continues on the same goal`,tone:`warn`,markdown:!1,hasCard:!0}:{label:`🎯 goal ${t||`updated`}`,detail:String(e.text??``).trim()||`the goal is now ${t}`,tone:``,markdown:!1,hasCard:!0}:{label:`🎯 goal status updated`,detail:String(e.text??``).trim()||`no status recorded`,tone:``,markdown:!1,hasCard:!0}}default:{let t=String(e.text??``).trim(),n=String(e.event??``).trim();return{label:n?`🎯 goal ${n}`:`🎯 goal updated`,detail:t||`the "${n||`goal`}" event carried no further detail`,tone:``,markdown:!1,hasCard:!0}}}}function nt(e,t=new Set,n=!1,r=new Set){let i=n?e.filter(t=>{if(!t.workspaceMissing)return!0;let n=[t.id],r=new Set;for(;n.length;){let t=n.pop();if(!r.has(t)){r.add(t);for(let i of e)i.parent===t&&!r.has(i.id)&&n.push(i.id)}}for(let t of r){let n=e.find(e=>e.id===t);if(n&&!n.workspaceMissing)return!0}return!1}):e,a=new Map,o=[];for(let e of i)e.parent&&i.some(t=>t.id===e.parent)?(a.has(e.parent)||a.set(e.parent,[]),a.get(e.parent).unshift(e)):o.push(e);let s=[],c=(e,n)=>{for(let o of e){let e=n===0&&r.has(st(i,o));if(s.push({a:o,depth:n}),e)continue;let l=a.get(o.id);l?.length&&!t.has(o.id)&&c(l,n+1)}},l=[],u=new Map;for(let e of o){if(e.parent)continue;let t=rt(i,e.id),n=u.get(t);n?n.push(e):(u.set(t,[e]),l.push(t))}for(let t of o){if(!t.parent)continue;let n=rt(e,t.id)||``,r=u.get(n);r?r.push(t):(u.set(n,[t]),l.push(n))}for(let e of l)c(u.get(e),0);return s}function rt(e,t,n=new Set){let r=e.find(e=>e.id===t);return r?!r.parent||n.has(t)?r.workspace||``:(n.add(t),rt(e,r.parent,n)||r.workspace||``):``}function it(e){return e.isSub?e.hasChildren:e.collapsed||e.hasChildren}function at(e,t=[]){let n=e.indexOf(`-sub`);if(n===-1)return null;let r=e.slice(n+4).replace(/^-+/,``);if(!r)return null;let i=r.split(`-`);return(t.includes(i[0]??``)?i.slice(1).join(`-`):r).replace(/_/g,` `).trim()||null}function ot(e,t,n=new Set){let r=[],i=new Set(n);for(let n of e)n.parent===t&&(i.has(n.id)||(i.add(n.id),r.push(n,...ot(e,n.id,i))));return r}function st(e,t){let n=t.id,r=new Set;for(;;){let t=e.find(e=>e.id===n);if(!t?.parent||r.has(n))break;r.add(n),n=t.parent}return`chat:${n||t.id}`}function ct(e){let t=new Map;for(let n of e){if(n.parent)continue;let r=rt(e,n.id);r&&t.set(r,(t.get(r)??0)+1)}return t}function lt(e,t,n=new Set){let r=[],i=null;for(let a of t){let t=rt(e,a.a.id);t?(t!==i&&(i=t,r.push({a:a.a,depth:0,headerOnly:!0,wsHeader:t,wsCollapsedGroup:n.has(`ws:${t}`)})),!n.has(`ws:${t}`)&&(n.has(st(e,a.a))?r.push({a:a.a,depth:a.depth,chatCollapsedGroup:!0}):r.push({a:a.a,depth:a.depth}))):r.push({a:a.a,depth:a.depth})}return r}async function ut(e,t={}){if(!e)return`unsupported`;let n=t.clipboard===void 0?typeof navigator<`u`?navigator.clipboard??null:null:t.clipboard,r=t.execCommand??(typeof document<`u`?document.execCommand.bind(document):void 0),i=t.makeTextarea??(()=>{let e=document.createElement(`textarea`);return document.body.appendChild(e),{set value(t){e.value=t},get value(){return e.value},style:{get position(){return e.style.position},set position(t){e.style.position=t},get opacity(){return e.style.opacity},set opacity(t){e.style.opacity=t}},select:()=>e.select(),remove:()=>e.remove()}}),a=n?.writeText;if(typeof a==`function`)try{return await a.call(n,e),`copied`}catch{}let o=null;try{let t=i();return o=t,t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,t.select(),r&&r(`copy`)?`copied`:`failed`}catch{return`failed`}finally{o?.remove()}}function dt(e){return e.type===`prompt`&&e.data?.source===`user`?{name:`you`}:e.type===`message`?{name:`agent`}:{name:`harness`}}function ft(e){let t=e.data??{};return e.data?.actor?`sub:${String(e.data.actor)}`:e.type===`tool_call`||e.type===`tool_result`?`agent-tools`:e.type===`prompt`?`src:${String(t.source??`user`)}`:`type:${e.type}`}function pt(e,t){return!(!e||t.data?.pending||e.data?.pending||t.data?.cancelled||ft(e)!==ft(t)||dt(e).name!==dt(t).name||t.session!==e.session||t.branch!==e.branch)}function mt(e,t=new Set){let n=new Set,r=-1,i=-1;for(let t of e)t.type===`question`?r=t.seq:t.type===`prompt`&&t.data?.source===`user`?i=t.seq:t.type===`system_note`&&t.data?.event===`prompt-delivered`&&(i=Math.max(i,t.seq));if(r>=0&&i>r)for(let t of e)t.type===`question`&&t.seq<=i&&n.add(String(t.data?.callId??``));for(let e of t)n.add(e);return n}var ht=(e,t,n)=>{if(t>=e.length)return e;if(n?.length){let r=new Set(n),i=e.filter(e=>e.promptId&&r.has(e.promptId));if(i.length){let n=e.filter(e=>!e.promptId);return n.length?[...i,...n].slice(0,t):i}}return e.slice(0,t)};function gt(e,t,n){let r=e??[];return n&&r.includes(n)?n:t&&r.includes(t)||!n&&t&&r.length===0?t:r[0]??null}function _t(e,t,n){return!t||n&&t===n?!0:typeof e==`string`&&e===t}function vt(e,t,n){return!e||!t||e.agent!==t?!1:_t(e.session,n,t)}function yt(e,t,n){return!e||!t||e.agentId!==t||!e.sessionId?!1:_t(e.sessionId,n,t)}function bt(e,t,n){return n?!e||!t||t===e.id||!e.session||e.session===t:!1}function xt(){let e=``,t=``,n=``,r=``;try{let i=getComputedStyle(document.documentElement);e=i.getPropertyValue(`--term-bg`).trim(),t=i.getPropertyValue(`--term-fg`).trim(),n=i.getPropertyValue(`--term-cursor`).trim(),r=i.getPropertyValue(`--term-cursor-accent`).trim()}catch{}return{background:e||`#0d0e12`,foreground:t||`#dcdee4`,cursor:n||t||`#dcdee4`,cursorAccent:r||e||`#0d0e12`}}function St(e){let t=xt(),n=e.options.theme;n&&n.background===t.background&&n.foreground===t.foreground&&n.cursor===t.cursor&&n.cursorAccent===t.cursorAccent||(e.options.theme=t)}function Ct(e,t){let n=String(t??``);return/^TIMEOUT after\b/.test(n)?`timeout`:/^ABORTED\b/.test(n)?`aborted`:/^exit=\d+/.test(n)||e===!1?`exit`:n.trim()?`ok`:`empty`}function wt(e){switch(e){case`timeout`:return` · TIMED OUT`;case`aborted`:return` · ABORTED`;case`exit`:return` · FAILED`;default:return``}}function Tt(e){let t=[];e.outcome!==`empty`&&t.push(e.fmtDur(e.durationMs)),e.timeoutMs&&t.push(`timeout ${Math.round(e.timeoutMs/1e3)}s`);let n=wt(e.outcome);return n&&t.push(n.trim()),t.join(` · `)}function Et(e,t,n){return e?.provider||n||Object.keys(t??{})[0]||``}function Dt(e,t){return t?String(e?.[t]?.model??``).trim():``}function Ot(e,t,n){return Dt(e,t)||(n&&t===(n.provider??``)?n.model??``:``)}function kt(e,t,n,r){return n?.model&&t===r?n.model:Dt(e,t)||n?.model||``}function At(e){return!e}function jt(e){return!e}function Mt(e,t){return e!==t}function Nt(e,t,n=24){return!t||e.gap<=n?!1:e.top<t.top}var Pt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,It=(e,t)=>{for(var n in t)Pt(e,n,{get:t[n],enumerable:!0})},B=(e,t,n,r)=>{for(var i=r>1?void 0:r?Ft(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&Pt(t,n,i),i},V=(e,t)=>(n,r)=>t(n,r,e),Lt=`Terminal input`,Rt={get:()=>Lt,set:e=>Lt=e},zt=`Too much output to announce, navigate to rows manually to read`,Bt={get:()=>zt,set:e=>zt=e};function Vt(e){return e.replace(/\r?\n/g,`\r`)}function Ht(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function H(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function Ut(e,t,n,r){e.stopPropagation(),e.clipboardData&&Wt(e.clipboardData.getData(`text/plain`),t,n,r)}function Wt(e,t,n,r){e=Vt(e),e=Ht(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function Gt(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function Kt(e,t,n,r,i){Gt(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function qt(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function Jt(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var Yt=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o)}else i!==65279&&(t[r++]=i)}return r}},Xt=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128||(c=(i&31)<<6|a&63,c<128)){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},Zt=``,Qt=` `,$t=class e{constructor(){this.fg=0,this.bg=0,this.extended=new en}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return!(this.fg&50331648)}isBgDefault(){return!(this.bg&50331648)}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?!(this.extended.underlineColor&50331648):this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},en=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},tn=class e extends $t{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new en,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?qt(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},nn=`di$target`,rn=`di$dependencies`,an=new Map;function on(e){return e[rn]||[]}function sn(e){if(an.has(e))return an.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);cn(t,e,r)};return t._id=e,an.set(e,t),t}function cn(e,t,n){t[nn]===t?t[rn].push({id:e,index:n}):(t[rn]=[{id:e,index:n}],t[nn]=t)}var ln=sn(`BufferService`),un=sn(`CoreMouseService`),dn=sn(`CoreService`),fn=sn(`CharsetService`),pn=sn(`InstantiationService`),mn=sn(`LogService`),hn=sn(`OptionsService`),gn=sn(`OscLinkService`),_n=sn(`UnicodeService`),vn=sn(`DecorationService`),yn=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new tn,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(c!==-1||n.hasContent(t)){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId){if(c===-1){c=t,s=a.extended.urlId;continue}l=a.extended.urlId!==s}else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):bn(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};yn=B([V(0,ln),V(1,hn),V(2,gn)],yn);function bn(e,t){if(confirm(`Do you want to navigate to ${t}?
|
|
5
|
+
`);function r(e){return e.replace(/\t/g,` `).length}function i(t){let o=null,s=[];for(;n<e.length;){let c=e[n].match(Pe);if(!c)break;let l=r(c[1]);if(l<t)break;let u=/^\d/.test(c[2]);if(o===null)o=u;else if(u!==o)break;n++;let d=c[3];for(;n<e.length&&/\S/.test(e[n])&&!Pe.test(e[n])&&!/^#{1,6}\s/.test(e[n])&&!e[n].startsWith("```")&&!/^\s*>/.test(e[n]);)d+=` `+e[n].trim(),n++;let f=``,p=e[n]?.match(Pe);p&&r(p[1])>l&&(f=i(r(p[1])));let m=d.match(/^\[( |x|X)\]\s+(.*)$/),h=m?`<input type="checkbox" disabled${m[1].toLowerCase()===`x`?` checked`:``}> `:``;s.push(`<li>${h}${a(m?m[2]:d)}${f}</li>`)}return o?`<ol>${s.join(``)}</ol>`:`<ul>${s.join(``)}</ul>`}function a(e){let t=[];return e=e.replace(/\u0000/g,``),e=e.replace(/`([^`]+)`/g,(e,n)=>(t.push(`<code>${n}</code>`),`\ue000${t.length-1}\uE001`)),e=e.replace(/!\[([^\]]*)\]\((https?:\/\/[^)\s]+)(?:\s+"[^)]*")?\)/g,`<img src="$2" alt="$1" loading="lazy">`),e=e.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)(?:\s+"[^)]*")?\)/g,`<a href="$2" rel="noopener noreferrer" target="_blank">$1</a>`),e=e.replace(/(?<!["'=\w])(https?:\/\/[^\s<>"')\]]*[^\s<>"')\].,;:!?"')\]])/g,`<a href="$1">$1</a>`),e=e.replace(/\*\*\*([\s\S]+?)\*\*\*/g,`<strong><em>$1</em></strong>`),e=e.replace(/\*\*([\s\S]+?)\*\*/g,`<strong>$1</strong>`),e=e.replace(/(^|[^\w])__(?=\S)([\s\S]*?\S)__(?!\w)/g,`$1<strong>$2</strong>`),e=e.replace(/(^|[^\w*])\*(?!\s)([^*\n]+?)\*(?![\w*])/g,`$1<em>$2</em>`),e=e.replace(/(^|[^\w])_(?!\s)([^_\n]+?)_(?!\w)/g,`$1<em>$2</em>`),e=e.replace(/~~([\s\S]+?)~~/g,`<del>$1</del>`),e.replace(/\ue000(\d+)\ue001/g,(e,n)=>t[+n]??``)}}function Le(e){let t=e.trim();t.startsWith(`|`)&&(t=t.slice(1));let n=[],r=``;for(let e=0;e<t.length;e++){let i=t[e];if(i===`\\`&&t[e+1]===`|`)r+=`|`,e++;else if(i==="`"){let n=t.indexOf("`",e+1);if(n!==-1){r+=t.slice(e,n+1),e=n;continue}r+=i}else{if(i===`|`&&e===t.length-1)break;i===`|`?(n.push(r.trim()),r=``):r+=i}}return n.push(r.trim()),n.filter((e,r)=>!(e===``&&r===n.length-1&&t.endsWith(`|`)))}function Re(e){let t=e.trim();if(!t.includes(`|`)||!t.includes(`-`))return!1;let n=Le(t);return n.every(e=>/^:?-+:?$/.test(e))&&n.some(e=>e!==``)}function ze(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`)}function Be(e){if(e==null||!Number.isFinite(e))return`?`;let t=Math.max(0,e);if(t<1e3)return`${Math.round(t)}ms`;if(t<6e4)return`${(t/1e3).toFixed(1)}s`;if(t<36e5){let e=Math.floor(t/6e4),n=Math.round(t%6e4/1e3);return n?`${e}m ${n}s`:`${e}m`}let n=Math.floor(t/36e5),r=Math.round(t%36e5/6e4);return r?`${n}h ${r}m`:`${n}h`}function Ve(e,t,n,r=Date.now()){let i=new Map(e);return i.set(t,{text:n.text??``,reasoning:n.reasoning??``,at:r}),i}function He(e,t){if(!e.has(t))return e;let n=new Map(e);return n.delete(t),n}function Ue(e){let t=e;return t?.type===`state`&&t.data?.detail===`llm turn start`}function We(e){return e===`running`||e===`waiting`}function Ge(e,t,n){if(!e)return!1;if(!e.text)return!We(n);if(!We(n))return!0;let r=e.text.trim();return t.some(e=>e.type===`message`&&e.data?.role===`assistant`&&String(e.data.content??``).trim()===r)}function Ke(e){if(!e)return!1;let t=e.data?.actor;return!(typeof t==`string`&&t.length>0)}function qe(e,t){let n=[];for(let r of e.keys()){let e=t(r);e!==void 0&&(We(e)||n.push(r))}if(n.length===0)return e;let r=new Map(e);for(let e of n)r.delete(e);return r}function Je(e,t,n){return!e||!We(n)||Ge(e,t,n)?null:e}function Ye(e,t){if(!t.length)return[...e].sort((e,t)=>e.seq-t.seq);let n=e.reduce((e,t)=>Math.max(e,t.seq),0),r=t.map((e,t)=>({...e,seq:n+1+t}));return[...e,...r].sort((e,t)=>e.seq-t.seq)}function Xe(e,t){return t===void 0||t<=e.seq?e:{...e,seq:t}}function Ze(e){return e.reduce((e,t)=>Math.max(e,t.seq),0)+1}function Qe(e){let t=e.event;return t===`status`||t===`audit-started`||t===`audit`||t===`audit-failed`?t:`other`}function $e(e){let t=e.trim().toLowerCase();return t===``||t===`(no detail)`||t===`no detail`||t===`(none)`||t===`(empty)`}function et(e,t){let n=String(e??``).trim();return $e(n)?$e(t)?``:t:n}function tt(e){switch(Qe(e)){case`audit-started`:return{label:`🔍 completion audit started`,detail:String(e.verify??``).trim()||`checking the verification contract…`,tone:``,markdown:!1,hasCard:!0};case`audit`:{let t=!$e(String(e.feedback??``));return e.verdict===`approved`?{label:`✅ audit: approved`,detail:et(e.feedback??``,``),tone:`ok`,markdown:!0,hasCard:t}:{label:`⚠ audit: changes required`,detail:et(e.feedback??``,``),tone:`warn`,markdown:!0,hasCard:t}}case`audit-failed`:return{label:`🔍 audit unavailable — finish accepted`,detail:String(e.detail??``).trim()||`the auditor could not be reached`,tone:`err`,markdown:!1,hasCard:!0};case`status`:{let t=String(e.status??``).trim();return t?t===`done`?{label:`🏁 finish claimed — pending audit`,detail:`the agent called finish(goalComplete=true); the verification contract is now being audited`,tone:``,markdown:!1,hasCard:!0}:t===`active`?{label:`▶ goal reopened`,detail:`the audit rejected the finish — work continues on the same goal`,tone:`warn`,markdown:!1,hasCard:!0}:{label:`🎯 goal ${t||`updated`}`,detail:String(e.text??``).trim()||`the goal is now ${t}`,tone:``,markdown:!1,hasCard:!0}:{label:`🎯 goal status updated`,detail:String(e.text??``).trim()||`no status recorded`,tone:``,markdown:!1,hasCard:!0}}default:{let t=String(e.text??``).trim(),n=String(e.event??``).trim();return{label:n?`🎯 goal ${n}`:`🎯 goal updated`,detail:t||`the "${n||`goal`}" event carried no further detail`,tone:``,markdown:!1,hasCard:!0}}}}function nt(e,t=new Set,n=!1,r=new Set){let i=n?e.filter(t=>{if(!t.workspaceMissing)return!0;let n=[t.id],r=new Set;for(;n.length;){let t=n.pop();if(!r.has(t)){r.add(t);for(let i of e)i.parent===t&&!r.has(i.id)&&n.push(i.id)}}for(let t of r){let n=e.find(e=>e.id===t);if(n&&!n.workspaceMissing)return!0}return!1}):e,a=new Map,o=[];for(let e of i)e.parent&&i.some(t=>t.id===e.parent)?(a.has(e.parent)||a.set(e.parent,[]),a.get(e.parent).unshift(e)):o.push(e);let s=[],c=(e,n)=>{for(let o of e){let e=n===0&&r.has(st(i,o));if(s.push({a:o,depth:n}),e)continue;let l=a.get(o.id);l?.length&&!t.has(o.id)&&c(l,n+1)}},l=[],u=new Map;for(let e of o){if(e.parent)continue;let t=rt(i,e.id),n=u.get(t);n?n.push(e):(u.set(t,[e]),l.push(t))}for(let t of o){if(!t.parent)continue;let n=rt(e,t.id)||``,r=u.get(n);r?r.push(t):(u.set(n,[t]),l.push(n))}for(let e of l)c(u.get(e),0);return s}function rt(e,t,n=new Set){let r=e.find(e=>e.id===t);return r?!r.parent||n.has(t)?r.workspace||``:(n.add(t),rt(e,r.parent,n)||r.workspace||``):``}function it(e){return e.isSub?e.hasChildren:e.collapsed||e.hasChildren}function at(e,t=[]){let n=e.indexOf(`-sub`);if(n===-1)return null;let r=e.slice(n+4).replace(/^-+/,``);if(!r)return null;let i=r.split(`-`);return(t.includes(i[0]??``)?i.slice(1).join(`-`):r).replace(/_/g,` `).trim()||null}function ot(e,t,n=new Set){let r=[],i=new Set(n);for(let n of e)n.parent===t&&(i.has(n.id)||(i.add(n.id),r.push(n,...ot(e,n.id,i))));return r}function st(e,t){let n=t.id,r=new Set;for(;;){let t=e.find(e=>e.id===n);if(!t?.parent||r.has(n))break;r.add(n),n=t.parent}return`chat:${n||t.id}`}function ct(e){let t=new Map;for(let n of e){if(n.parent)continue;let r=rt(e,n.id);r&&t.set(r,(t.get(r)??0)+1)}return t}function lt(e,t,n=new Set){let r=[],i=null;for(let a of t){let t=rt(e,a.a.id);t?(t!==i&&(i=t,r.push({a:a.a,depth:0,headerOnly:!0,wsHeader:t,wsCollapsedGroup:n.has(`ws:${t}`)})),!n.has(`ws:${t}`)&&(n.has(st(e,a.a))?r.push({a:a.a,depth:a.depth,chatCollapsedGroup:!0}):r.push({a:a.a,depth:a.depth}))):r.push({a:a.a,depth:a.depth})}return r}async function ut(e,t={}){if(!e)return`unsupported`;let n=t.clipboard===void 0?typeof navigator<`u`?navigator.clipboard??null:null:t.clipboard,r=t.execCommand??(typeof document<`u`?document.execCommand.bind(document):void 0),i=t.makeTextarea??(()=>{let e=document.createElement(`textarea`);return document.body.appendChild(e),{set value(t){e.value=t},get value(){return e.value},style:{get position(){return e.style.position},set position(t){e.style.position=t},get opacity(){return e.style.opacity},set opacity(t){e.style.opacity=t}},select:()=>e.select(),remove:()=>e.remove()}}),a=n?.writeText;if(typeof a==`function`)try{return await a.call(n,e),`copied`}catch{}let o=null;try{let t=i();return o=t,t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,t.select(),r&&r(`copy`)?`copied`:`failed`}catch{return`failed`}finally{o?.remove()}}function dt(e){return e.type===`prompt`&&e.data?.source===`user`?{name:`you`}:e.type===`message`?{name:`agent`}:{name:`harness`}}function ft(e){let t=e.data??{};return e.data?.actor?`sub:${String(e.data.actor)}`:e.type===`tool_call`||e.type===`tool_result`?`agent-tools`:e.type===`prompt`?`src:${String(t.source??`user`)}`:`type:${e.type}`}function pt(e,t){return!(!e||t.data?.pending||e.data?.pending||t.data?.cancelled||ft(e)!==ft(t)||dt(e).name!==dt(t).name||t.session!==e.session||t.branch!==e.branch)}function mt(e,t=new Set){let n=new Set,r=-1,i=-1;for(let t of e)t.type===`question`?r=t.seq:t.type===`prompt`&&t.data?.source===`user`?i=t.seq:t.type===`system_note`&&t.data?.event===`prompt-delivered`&&(i=Math.max(i,t.seq));if(r>=0&&i>r)for(let t of e)t.type===`question`&&t.seq<=i&&n.add(String(t.data?.callId??``));for(let e of t)n.add(e);return n}var ht=(e,t,n)=>{if(t>=e.length)return e;if(n?.length){let r=new Set(n),i=e.filter(e=>e.promptId&&r.has(e.promptId));if(i.length){let n=e.filter(e=>!e.promptId);return n.length?[...i,...n].slice(0,t):i}}return e.slice(0,t)};function gt(e,t,n){let r=e??[];return n&&r.includes(n)?n:t&&r.includes(t)||!n&&t&&r.length===0?t:r[0]??null}function _t(e,t,n){return!t||n&&t===n?!0:typeof e==`string`&&e===t}function vt(e,t,n){return!e||!t||e.agent!==t?!1:_t(e.session,n,t)}function yt(e,t,n){return!e||!t||e.agentId!==t||!e.sessionId?!1:_t(e.sessionId,n,t)}function bt(e,t,n){return n?!e||!t||t===e.id||!e.session||e.session===t:!1}function xt(){let e=``,t=``,n=``,r=``;try{let i=getComputedStyle(document.documentElement);e=i.getPropertyValue(`--term-bg`).trim(),t=i.getPropertyValue(`--term-fg`).trim(),n=i.getPropertyValue(`--term-cursor`).trim(),r=i.getPropertyValue(`--term-cursor-accent`).trim()}catch{}return{background:e||`#0d0e12`,foreground:t||`#dcdee4`,cursor:n||t||`#dcdee4`,cursorAccent:r||e||`#0d0e12`}}function St(e){let t=xt(),n=e.options.theme;n&&n.background===t.background&&n.foreground===t.foreground&&n.cursor===t.cursor&&n.cursorAccent===t.cursorAccent||(e.options.theme=t)}function Ct(e,t){let n=String(t??``);return/^TIMEOUT after\b/.test(n)?`timeout`:/^ABORTED\b/.test(n)?`aborted`:/^exit=\d+/.test(n)||e===!1?`exit`:n.trim()?`ok`:`empty`}function wt(e){switch(e){case`timeout`:return` · TIMED OUT`;case`aborted`:return` · ABORTED`;case`exit`:return` · FAILED`;default:return``}}function Tt(e){let t=[];e.outcome!==`empty`&&t.push(e.fmtDur(e.durationMs)),e.timeoutMs&&t.push(`timeout ${Math.round(e.timeoutMs/1e3)}s`);let n=wt(e.outcome);return n&&t.push(n.trim()),t.join(` · `)}function Et(e,t,n){return e?.provider||n||Object.keys(t??{})[0]||``}function Dt(e,t){return t?String(e?.[t]?.model??``).trim():``}function Ot(e,t,n){return Dt(e,t)||(n&&t===(n.provider??``)?n.model??``:``)}function kt(e,t,n,r){return n?.model&&t===r?n.model:Dt(e,t)||n?.model||``}function At(e){return!e}function jt(e){return!e}function Mt(e,t){return e!==t}function Nt(e,t,n=24){return!t||e.gap<=n?!1:e.top<t.top}var Pt=Object.defineProperty,Ft=Object.getOwnPropertyDescriptor,It=(e,t)=>{for(var n in t)Pt(e,n,{get:t[n],enumerable:!0})},B=(e,t,n,r)=>{for(var i=r>1?void 0:r?Ft(t,n):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(r?o(t,n,i):o(i))||i);return r&&i&&Pt(t,n,i),i},V=(e,t)=>(n,r)=>t(n,r,e),Lt=`Terminal input`,Rt={get:()=>Lt,set:e=>Lt=e},zt=`Too much output to announce, navigate to rows manually to read`,Bt={get:()=>zt,set:e=>zt=e};function Vt(e){return e.replace(/\r?\n/g,`\r`)}function Ht(e,t){return t?`\x1B[200~`+e+`\x1B[201~`:e}function H(e,t){e.clipboardData&&e.clipboardData.setData(`text/plain`,t.selectionText),e.preventDefault()}function Ut(e,t,n,r){e.stopPropagation(),e.clipboardData&&Wt(e.clipboardData.getData(`text/plain`),t,n,r)}function Wt(e,t,n,r){e=Vt(e),e=Ht(e,n.decPrivateModes.bracketedPasteMode&&r.rawOptions.ignoreBracketedPasteMode!==!0),n.triggerDataEvent(e,!0),t.value=``}function Gt(e,t,n){let r=n.getBoundingClientRect(),i=e.clientX-r.left-10,a=e.clientY-r.top-10;t.style.width=`20px`,t.style.height=`20px`,t.style.left=`${i}px`,t.style.top=`${a}px`,t.style.zIndex=`1000`,t.focus()}function Kt(e,t,n,r,i){Gt(e,t,n),i&&r.rightClickSelect(e),t.value=r.selectionText,t.select()}function qt(e){return e>65535?(e-=65536,String.fromCharCode((e>>10)+55296)+String.fromCharCode(e%1024+56320)):String.fromCharCode(e)}function Jt(e,t=0,n=e.length){let r=``;for(let i=t;i<n;++i){let t=e[i];t>65535?(t-=65536,r+=String.fromCharCode((t>>10)+55296)+String.fromCharCode(t%1024+56320)):r+=String.fromCharCode(t)}return r}var Yt=class{constructor(){this._interim=0}clear(){this._interim=0}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i=0;if(this._interim){let n=e.charCodeAt(i++);56320<=n&&n<=57343?t[r++]=(this._interim-55296)*1024+n-56320+65536:(t[r++]=this._interim,t[r++]=n),this._interim=0}for(let a=i;a<n;++a){let i=e.charCodeAt(a);if(55296<=i&&i<=56319){if(++a>=n)return this._interim=i,r;let o=e.charCodeAt(a);56320<=o&&o<=57343?t[r++]=(i-55296)*1024+o-56320+65536:(t[r++]=i,t[r++]=o)}else i!==65279&&(t[r++]=i)}return r}},Xt=class{constructor(){this.interim=new Uint8Array(3)}clear(){this.interim.fill(0)}decode(e,t){let n=e.length;if(!n)return 0;let r=0,i,a,o,s,c=0,l=0;if(this.interim[0]){let i=!1,a=this.interim[0];a&=(a&224)==192?31:(a&240)==224?15:7;let o=0,s;for(;(s=this.interim[++o]&63)&&o<4;)a<<=6,a|=s;let c=(this.interim[0]&224)==192?2:(this.interim[0]&240)==224?3:4,u=c-o;for(;l<u;){if(l>=n)return 0;if(s=e[l++],(s&192)!=128){l--,i=!0;break}this.interim[o++]=s,a<<=6,a|=s&63}i||(c===2?a<128?l--:t[r++]=a:c===3?a<2048||a>=55296&&a<=57343||a===65279||(t[r++]=a):a<65536||a>1114111||(t[r++]=a)),this.interim.fill(0)}let u=n-4,d=l;for(;d<n;){for(;d<u&&!((i=e[d])&128)&&!((a=e[d+1])&128)&&!((o=e[d+2])&128)&&!((s=e[d+3])&128);)t[r++]=i,t[r++]=a,t[r++]=o,t[r++]=s,d+=4;if(i=e[d++],i<128)t[r++]=i;else if((i&224)==192){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128||(c=(i&31)<<6|a&63,c<128)){d--;continue}t[r++]=c}else if((i&240)==224){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(c=(i&15)<<12|(a&63)<<6|o&63,c<2048||c>=55296&&c<=57343||c===65279)continue;t[r++]=c}else if((i&248)==240){if(d>=n)return this.interim[0]=i,r;if(a=e[d++],(a&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,r;if(o=e[d++],(o&192)!=128){d--;continue}if(d>=n)return this.interim[0]=i,this.interim[1]=a,this.interim[2]=o,r;if(s=e[d++],(s&192)!=128){d--;continue}if(c=(i&7)<<18|(a&63)<<12|(o&63)<<6|s&63,c<65536||c>1114111)continue;t[r++]=c}}return r}},Zt=``,Qt=` `,$t=class e{constructor(){this.fg=0,this.bg=0,this.extended=new en}static toColorRGB(e){return[e>>>16&255,e>>>8&255,e&255]}static fromColorRGB(e){return(e[0]&255)<<16|(e[1]&255)<<8|e[2]&255}clone(){let t=new e;return t.fg=this.fg,t.bg=this.bg,t.extended=this.extended.clone(),t}isInverse(){return this.fg&67108864}isBold(){return this.fg&134217728}isUnderline(){return this.hasExtendedAttrs()&&this.extended.underlineStyle!==0?1:this.fg&268435456}isBlink(){return this.fg&536870912}isInvisible(){return this.fg&1073741824}isItalic(){return this.bg&67108864}isDim(){return this.bg&134217728}isStrikethrough(){return this.fg&2147483648}isProtected(){return this.bg&536870912}isOverline(){return this.bg&1073741824}getFgColorMode(){return this.fg&50331648}getBgColorMode(){return this.bg&50331648}isFgRGB(){return(this.fg&50331648)==50331648}isBgRGB(){return(this.bg&50331648)==50331648}isFgPalette(){return(this.fg&50331648)==16777216||(this.fg&50331648)==33554432}isBgPalette(){return(this.bg&50331648)==16777216||(this.bg&50331648)==33554432}isFgDefault(){return!(this.fg&50331648)}isBgDefault(){return!(this.bg&50331648)}isAttributeDefault(){return this.fg===0&&this.bg===0}getFgColor(){switch(this.fg&50331648){case 16777216:case 33554432:return this.fg&255;case 50331648:return this.fg&16777215;default:return-1}}getBgColor(){switch(this.bg&50331648){case 16777216:case 33554432:return this.bg&255;case 50331648:return this.bg&16777215;default:return-1}}hasExtendedAttrs(){return this.bg&268435456}updateExtended(){this.extended.isEmpty()?this.bg&=-268435457:this.bg|=268435456}getUnderlineColor(){if(this.bg&268435456&&~this.extended.underlineColor)switch(this.extended.underlineColor&50331648){case 16777216:case 33554432:return this.extended.underlineColor&255;case 50331648:return this.extended.underlineColor&16777215;default:return this.getFgColor()}return this.getFgColor()}getUnderlineColorMode(){return this.bg&268435456&&~this.extended.underlineColor?this.extended.underlineColor&50331648:this.getFgColorMode()}isUnderlineColorRGB(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==50331648:this.isFgRGB()}isUnderlineColorPalette(){return this.bg&268435456&&~this.extended.underlineColor?(this.extended.underlineColor&50331648)==16777216||(this.extended.underlineColor&50331648)==33554432:this.isFgPalette()}isUnderlineColorDefault(){return this.bg&268435456&&~this.extended.underlineColor?!(this.extended.underlineColor&50331648):this.isFgDefault()}getUnderlineStyle(){return this.fg&268435456?this.bg&268435456?this.extended.underlineStyle:1:0}getUnderlineVariantOffset(){return this.extended.underlineVariantOffset}},en=class e{constructor(e=0,t=0){this._ext=0,this._urlId=0,this._ext=e,this._urlId=t}get ext(){return this._urlId?this._ext&-469762049|this.underlineStyle<<26:this._ext}set ext(e){this._ext=e}get underlineStyle(){return this._urlId?5:(this._ext&469762048)>>26}set underlineStyle(e){this._ext&=-469762049,this._ext|=e<<26&469762048}get underlineColor(){return this._ext&67108863}set underlineColor(e){this._ext&=-67108864,this._ext|=e&67108863}get urlId(){return this._urlId}set urlId(e){this._urlId=e}get underlineVariantOffset(){let e=(this._ext&3758096384)>>29;return e<0?e^4294967288:e}set underlineVariantOffset(e){this._ext&=536870911,this._ext|=e<<29&3758096384}clone(){return new e(this._ext,this._urlId)}isEmpty(){return this.underlineStyle===0&&this._urlId===0}},tn=class e extends $t{constructor(){super(...arguments),this.content=0,this.fg=0,this.bg=0,this.extended=new en,this.combinedData=``}static fromCharData(t){let n=new e;return n.setFromCharData(t),n}isCombined(){return this.content&2097152}getWidth(){return this.content>>22}getChars(){return this.content&2097152?this.combinedData:this.content&2097151?qt(this.content&2097151):``}getCode(){return this.isCombined()?this.combinedData.charCodeAt(this.combinedData.length-1):this.content&2097151}setFromCharData(e){this.fg=e[0],this.bg=0;let t=!1;if(e[1].length>2)t=!0;else if(e[1].length===2){let n=e[1].charCodeAt(0);if(55296<=n&&n<=56319){let r=e[1].charCodeAt(1);56320<=r&&r<=57343?this.content=(n-55296)*1024+r-56320+65536|e[2]<<22:t=!0}else t=!0}else this.content=e[1].charCodeAt(0)|e[2]<<22;t&&(this.combinedData=e[1],this.content=2097152|e[2]<<22)}getAsCharData(){return[this.fg,this.getChars(),this.getWidth(),this.getCode()]}},nn=`di$target`,rn=`di$dependencies`,an=new Map;function on(e){return e[rn]||[]}function sn(e){if(an.has(e))return an.get(e);let t=function(e,n,r){if(arguments.length!==3)throw Error(`@IServiceName-decorator can only be used to decorate a parameter`);cn(t,e,r)};return t._id=e,an.set(e,t),t}function cn(e,t,n){t[nn]===t?t[rn].push({id:e,index:n}):(t[rn]=[{id:e,index:n}],t[nn]=t)}var ln=sn(`BufferService`),un=sn(`CoreMouseService`),dn=sn(`CoreService`),fn=sn(`CharsetService`),pn=sn(`InstantiationService`),mn=sn(`LogService`),hn=sn(`OptionsService`),gn=sn(`OscLinkService`),_n=sn(`UnicodeService`),vn=sn(`DecorationService`),yn=class{constructor(e,t,n){this._bufferService=e,this._optionsService=t,this._oscLinkService=n}provideLinks(e,t){let n=this._bufferService.buffer.lines.get(e-1);if(!n){t(void 0);return}let r=[],i=this._optionsService.rawOptions.linkHandler,a=new tn,o=n.getTrimmedLength(),s=-1,c=-1,l=!1;for(let t=0;t<o;t++)if(c!==-1||n.hasContent(t)){if(n.loadCell(t,a),a.hasExtendedAttrs()&&a.extended.urlId){if(c===-1){c=t,s=a.extended.urlId;continue}l=a.extended.urlId!==s}else c!==-1&&(l=!0);if(l||c!==-1&&t===o-1){let n=this._oscLinkService.getLinkData(s)?.uri;if(n){let a={start:{x:c+1,y:e},end:{x:t+ +(!l&&t===o-1),y:e}},s=!1;if(!i?.allowNonHttpProtocols)try{let e=new URL(n);[`http:`,`https:`].includes(e.protocol)||(s=!0)}catch{s=!0}s||r.push({text:n,range:a,activate:(e,t)=>i?i.activate(e,t,a):bn(e,t),hover:(e,t)=>i?.hover?.(e,t,a),leave:(e,t)=>i?.leave?.(e,t,a)})}l=!1,a.hasExtendedAttrs()&&a.extended.urlId?(c=t,s=a.extended.urlId):(c=-1,s=-1)}}t(r)}};yn=B([V(0,ln),V(1,hn),V(2,gn)],yn);function bn(e,t){if(confirm(`Do you want to navigate to ${t}?
|
|
6
6
|
|
|
7
7
|
WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){try{e.opener=null}catch{}e.location.href=t}else console.warn(`Opening link blocked as opener could not be cleared`)}}var xn=sn(`CharSizeService`),Sn=sn(`CoreBrowserService`),Cn=sn(`MouseService`),wn=sn(`RenderService`),Tn=sn(`SelectionService`),En=sn(`CharacterJoinerService`),Dn=sn(`ThemeService`),On=sn(`LinkProviderService`),kn=new class{constructor(){this.listeners=[],this.unexpectedErrorHandler=function(e){setTimeout(()=>{throw e.stack?Fn.isErrorNoTelemetry(e)?new Fn(e.message+`
|
|
8
8
|
|
|
@@ -18,13 +18,13 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
|
|
|
18
18
|
`))),this._register(this._terminal.onA11yTab(e=>this._handleTab(e))),this._register(this._terminal.onKey(e=>this._handleKey(e.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(q(i,`selectionchange`,()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(U(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<ll+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
|
|
19
19
|
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===ll+1&&(this._liveRegion.textContent+=Bt.get())))}_clearLiveRegion(){this._liveRegion.textContent=``,this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),/\p{Control}/u.test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let n=this._terminal.buffer,r=n.lines.length.toString();for(let i=e;i<=t;i++){let e=n.lines.get(n.ydisp+i),t=[],a=e?.translateToString(!0,void 0,void 0,t)||``,o=(n.ydisp+i+1).toString(),s=this._rowElements[i];s&&(a.length===0?(s.textContent=`\xA0`,this._rowColumns.set(s,[0,1])):(s.textContent=a,this._rowColumns.set(s,t)),s.setAttribute(`aria-posinset`,o),s.setAttribute(`aria-setsize`,r),this._alignRowWidth(s))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce=``)}_handleBoundaryFocus(e,t){let n=e.target,r=this._rowElements[t===0?1:this._rowElements.length-2];if(n.getAttribute(`aria-posinset`)===(t===0?`1`:`${this._terminal.buffer.lines.length}`)||e.relatedTarget!==r)return;let i,a;if(t===0?(i=n,a=this._rowElements.pop(),this._rowContainer.removeChild(a)):(i=this._rowElements.shift(),a=n,this._rowContainer.removeChild(i)),i.removeEventListener(`focus`,this._topBoundaryFocusListener),a.removeEventListener(`focus`,this._bottomBoundaryFocusListener),t===0){let e=this._createAccessibilityTreeNode();this._rowElements.unshift(e),this._rowContainer.insertAdjacentElement(`afterbegin`,e)}else{let e=this._createAccessibilityTreeNode();this._rowElements.push(e),this._rowContainer.appendChild(e)}this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error(`anchorNode and/or focusNode are null`);return}let t={node:e.anchorNode,offset:e.anchorOffset},n={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(n.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===n.node&&t.offset>n.offset)&&([t,n]=[n,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let r=this._rowElements.slice(-1)[0];if(n.node.compareDocumentPosition(r)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(n={node:r,offset:r.textContent?.length??0}),!this._rowContainer.contains(n.node))return;let i=({node:e,offset:t})=>{let n=e instanceof Text?e.parentNode:e,r=parseInt(n?.getAttribute(`aria-posinset`),10)-1;if(isNaN(r))return console.warn(`row is invalid. Race condition?`),null;let i=this._rowColumns.get(n);if(!i)return console.warn(`columns is null. Race condition?`),null;let a=t<i.length?i[t]:i.slice(-1)[0]+1;return a>=this._terminal.cols&&(++r,a=0),{row:r,column:a}},a=i(t),o=i(n);if(a&&o){if(a.row>o.row||a.row===o.row&&a.column>=o.column)throw Error(`invalid range`);this._terminal.select(a.column,a.row,(o.row-a.row)*this._terminal.cols-a.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener(`focus`,this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement(`div`);return e.setAttribute(`role`,`listitem`),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){e.style.transform=``;let t=e.getBoundingClientRect().width,n=this._rowColumns.get(e)?.slice(-1)?.[0];if(!n)return;let r=n*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${r/t})`}};ul=B([V(1,pn),V(2,Sn),V(3,wn)],ul);var dl=class extends W{constructor(e,t,n,r,i){super(),this._element=e,this._mouseService=t,this._renderService=n,this._bufferService=r,this._linkProviderService=i,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new K),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new K),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(U(()=>{qn(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(q(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(q(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(q(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(q(this._element,`mouseup`,this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){this._activeLine!==e.y||this._wasResized?(this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1):this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){(!this._activeProviderReplies||!t)&&(this._activeProviderReplies?.forEach(e=>{e?.forEach(e=>{e.link.dispose&&e.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,t=>{if(this._isMouseOut)return;let i=t?.map(e=>({link:e}));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)(!this._activeProviderReplies.has(t)||this._activeProviderReplies.get(t))&&(i=!0);if(!i&&r){let e=r.find(e=>this._linkAtPosition(e.link,t));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find(e=>this._linkAtPosition(e.link,t));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&fl(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,qn(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0||e.link.decorations.underline,pointerCursor:e.link.decorations===void 0||e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:e=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==e&&(this._currentLink.state.decorations.pointerCursor=e,this._currentLink.state.isHovered&&this._element.classList.toggle(`xterm-cursor-pointer`,e))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:t=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==t&&(this._currentLink.state.decorations.underline=t,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,t))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e=>{if(!this._currentLink)return;let t=e.start===0?0:e.start+1+this._bufferService.buffer.ydisp,n=this._bufferService.buffer.ydisp+1+e.end;if(this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(t,n),this._lastMouseEvent)){let e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._askForLink(e,!1)}})))}_linkHover(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add(`xterm-cursor-pointer`)),t.hover&&t.hover(n,t.text)}_fireUnderlineEvent(e,t){let n=e.range,r=this._bufferService.buffer.ydisp,i=this._createLinkUnderlineEvent(n.start.x-1,n.start.y-r-1,n.end.x,n.end.y-r-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(i)}_linkLeave(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove(`xterm-cursor-pointer`)),t.leave&&t.leave(n,t.text)}_linkAtPosition(e,t){let n=e.range.start.y*this._bufferService.cols+e.range.start.x,r=e.range.end.y*this._bufferService.cols+e.range.end.x,i=t.y*this._bufferService.cols+t.x;return n<=i&&i<=r}_positionFromMouseEvent(e,t,n){let r=n.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(r)return{x:r[0],y:r[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,n,r,i){return{x1:e,y1:t,x2:n,y2:r,cols:this._bufferService.cols,fg:i}}};dl=B([V(1,Cn),V(2,wn),V(3,ln),V(4,On)],dl);function fl(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var pl=class extends Qc{constructor(e={}){super(e),this._linkifier=this._register(new Zn),this.browser=Do,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new Zn),this._onCursorMove=this._register(new K),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new K),this.onKey=this._onKey.event,this._onRender=this._register(new K),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new K),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new K),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new K),this.onBell=this._onBell.event,this._onFocus=this._register(new K),this._onBlur=this._register(new K),this._onA11yCharEmitter=this._register(new K),this._onA11yTabEmitter=this._register(new K),this._onWillOpen=this._register(new K),this._setup(),this._decorationService=this._instantiationService.createInstance(al),this._instantiationService.setService(vn,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(So),this._instantiationService.setService(On,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(yn)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(e=>this.refresh(e?.start??0,e?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(e=>this._reportWindowsOptions(e))),this._register(this._inputHandler.onColor(e=>this._handleColorEvent(e))),this._register(rr.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(rr.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(rr.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(rr.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(U(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let e,n=``;switch(t.index){case 256:e=`foreground`,n=`10`;break;case 257:e=`background`,n=`11`;break;case 258:e=`cursor`,n=`12`;break;default:e=`ansi`,n=`4;`+t.index}switch(t.type){case 0:let r=Y.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${J.ESC}]${n};${Ic(r)}${Ia.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=Ua.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=Ua.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index)}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(ul,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(J.ESC+`[I`),this.element.classList.add(`focus`),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value=``,this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(J.ESC+`[O`),this.element.classList.remove(`focus`),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let n=Math.min(this.buffer.x,this.cols-1),r=this._renderService.dimensions.css.cell.height,i=t.getWidth(n),a=this._renderService.dimensions.css.cell.width*i,o=this.buffer.y*this._renderService.dimensions.css.cell.height,s=n*this._renderService.dimensions.css.cell.width;this.textarea.style.left=s+`px`,this.textarea.style.top=o+`px`,this.textarea.style.width=a+`px`,this.textarea.style.height=r+`px`,this.textarea.style.lineHeight=r+`px`,this.textarea.style.zIndex=`-5`}_initGlobal(){this._bindKeys(),this._register(q(this.element,`copy`,e=>{this.hasSelection()&&H(e,this._selectionService)}));let e=e=>Ut(e,this.textarea,this.coreService,this.optionsService);this._register(q(this.textarea,`paste`,e)),this._register(q(this.element,`paste`,e)),jo?this._register(q(this.element,`mousedown`,e=>{e.button===2&&Kt(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(q(this.element,`contextmenu`,e=>{Kt(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),zo&&this._register(q(this.element,`auxclick`,e=>{e.button===1&&Gt(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(q(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(q(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(q(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(q(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(q(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(q(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(q(this.textarea,`input`,e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw Error(`Terminal requires a parent element.`);if(e.isConnected||this._logService.debug(`Terminal.open was called on an element that was not attached to the DOM`),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement(`div`),this.element.dir=`ltr`,this.element.classList.add(`terminal`),this.element.classList.add(`xterm`),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement(`div`),this._viewportElement.classList.add(`xterm-viewport`),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement(`div`),this.screenElement.classList.add(`xterm-screen`),this._register(q(this.screenElement,`mousemove`,e=>this.updateCursorStyle(e))),this._helperContainer=this._document.createElement(`div`),this._helperContainer.classList.add(`xterm-helpers`),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let n=this.textarea=this._document.createElement(`textarea`);this.textarea.classList.add(`xterm-helper-textarea`),this.textarea.setAttribute(`aria-label`,Rt.get()),Bo||this.textarea.setAttribute(`aria-multiline`,`false`),this.textarea.setAttribute(`autocorrect`,`off`),this.textarea.setAttribute(`autocapitalize`,`off`),this.textarea.setAttribute(`spellcheck`,`false`),this.textarea.tabIndex=0,this._register(this.optionsService.onSpecificOptionChange(`disableStdin`,()=>n.readOnly=this.optionsService.rawOptions.disableStdin)),this.textarea.readOnly=this.optionsService.rawOptions.disableStdin,this._coreBrowserService=this._register(this._instantiationService.createInstance(bo,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(Sn,this._coreBrowserService),this._register(q(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(q(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(go,this._document,this._helperContainer),this._instantiationService.setService(xn,this._charSizeService),this._themeService=this._instantiationService.createInstance(ws),this._instantiationService.setService(Dn,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(Xa),this._instantiationService.setService(En,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Ko,this.rows,this.screenElement)),this._instantiationService.setService(wn,this._renderService),this._register(this._renderService.onRenderedViewportChange(e=>this._onRender.fire(e))),this.onResize(e=>this._renderService.resize(e.cols,e.rows)),this._compositionView=this._document.createElement(`div`),this._compositionView.classList.add(`composition-view`),this._compositionHelper=this._instantiationService.createInstance(La,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(To),this._instantiationService.setService(Cn,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(dl,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(Oa,this.element,this.screenElement)),this._register(this._viewport.onRequestScrollLines(e=>{super.scrollLines(e,!1),this.refresh(0,this.rows-1)})),this._selectionService=this._register(this._instantiationService.createInstance(ms,this.element,this.screenElement,r)),this._instantiationService.setService(Tn,this._selectionService),this._register(this._selectionService.onRequestScrollLines(e=>this.scrollLines(e.amount,e.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()})),this._register(rr.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(ka,this.screenElement)),this._register(q(this.element,`mousedown`,e=>this._selectionService.handleMouseDown(e))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add(`enable-mouse-events`)):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(ul,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Pa,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Pa,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(ho,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function n(t){let n=e._mouseService.getMouseReportCoords(t,e.screenElement);if(!n)return!1;let r,i;switch(t.overrideType||t.type){case`mousemove`:i=32,t.buttons===void 0?(r=3,t.button!==void 0&&(r=t.button<3?t.button:3)):r=t.buttons&1?0:t.buttons&4?1:t.buttons&2?2:3;break;case`mouseup`:i=0,r=t.button<3?t.button:3;break;case`mousedown`:i=1,r=t.button<3?t.button:3;break;case`wheel`:if(e._customWheelEventHandler&&e._customWheelEventHandler(t)===!1)return!1;let n=t.deltaY;if(n===0||e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return!1;i=n<0?0:1,r=4;break;default:return!1}return i===void 0||r===void 0||r>4?!1:e.coreMouseService.triggerMouseEvent({col:n.col,row:n.row,x:n.x,y:n.y,button:r,action:i,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey})}let r={mouseup:null,wheel:null,mousedrag:null,mousemove:null},i={mouseup:e=>(n(e),e.buttons||(this._document.removeEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.removeEventListener(`mousemove`,r.mousedrag)),this.cancel(e)),wheel:e=>(n(e),this.cancel(e,!0)),mousedrag:e=>{e.buttons&&n(e)},mousemove:e=>{e.buttons||n(e)}};this._register(this.coreMouseService.onProtocolChange(e=>{e?(this.optionsService.rawOptions.logLevel===`debug`&&this._logService.debug(`Binding to mouse events:`,this.coreMouseService.explainEvents(e)),this.element.classList.add(`enable-mouse-events`),this._selectionService.disable()):(this._logService.debug(`Unbinding from mouse events.`),this.element.classList.remove(`enable-mouse-events`),this._selectionService.enable()),e&8?r.mousemove||=(t.addEventListener(`mousemove`,i.mousemove),i.mousemove):(t.removeEventListener(`mousemove`,r.mousemove),r.mousemove=null),e&16?r.wheel||=(t.addEventListener(`wheel`,i.wheel,{passive:!1}),i.wheel):(t.removeEventListener(`wheel`,r.wheel),r.wheel=null),e&2?r.mouseup||=i.mouseup:(this._document.removeEventListener(`mouseup`,r.mouseup),r.mouseup=null),e&4?r.mousedrag||=i.mousedrag:(this._document.removeEventListener(`mousemove`,r.mousedrag),r.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(q(t,`mousedown`,e=>{if(e.preventDefault(),this.focus(),this.coreMouseService.areMouseEventsActive&&!this._selectionService.shouldForceSelection(e))return n(e),r.mouseup&&this._document.addEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.addEventListener(`mousemove`,r.mousedrag),this.cancel(e)})),this._register(q(t,`wheel`,t=>{if(!r.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(t)===!1)return!1;if(!this.buffer.hasScrollback){if(t.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return this.cancel(t,!0);let n=J.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?`O`:`[`)+(t.deltaY<0?`A`:`B`);return this.coreService.triggerDataEvent(n,!0),this.cancel(t,!0)}}},{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add(`column-select`):this.element.classList.remove(`column-select`)}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){Wt(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,n){this._selectionService.setSelection(e,t,n)}getSelection(){return this._selectionService?this._selectionService.selectionText:``}getSelectionPosition(){if(this._selectionService&&this._selectionService.hasSelection)return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key===`Dead`||e.key===`AltGraph`)&&(this._unprocessedDeadKey=!0);let n=el(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),n.type===3||n.type===2){let t=this.rows-1;return this.scrollLines(n.type===2?-t:t),this.cancel(e,!0)}if(n.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(n.cancel&&this.cancel(e,!0),!n.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((n.key===J.ETX||n.key===J.CR)&&(this.textarea.value=``),this._onKey.fire({key:n.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(n.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let n=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState(`AltGraph`);return t.type===`keypress`?n:n&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(ml(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType===`insertText`&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){e===this.cols&&t===this.rows?this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure():super.resize(e,t)}_afterResize(e,t){this._charSizeService?.measure()}clear(){if(this.buffer.ybase!==0||this.buffer.y!==0){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(Ms));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),this._selectionService?.reset(),this._decorationService.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){this._renderService?.clearTextureAtlas()}_reportFocus(){this.element?.classList.contains(`focus`)?this.coreService.triggerDataEvent(J.ESC+`[I`):this.coreService.triggerDataEvent(J.ESC+`[O`)}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let e=this._renderService.dimensions.css.canvas.width.toFixed(0),t=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${J.ESC}[4;${t};${e}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${J.ESC}[6;${r};${n}t`)}}cancel(e,t){if(this.options.cancelEvents||t)return e.preventDefault(),e.stopPropagation(),!1}};function ml(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var hl=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let n={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(n),t.dispose=()=>this._wrappedAddonDispose(n),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let n=0;n<this._addons.length;n++)if(this._addons[n]===e){t=n;break}if(t===-1)throw Error(`Could not dispose an addon that has not been loaded`);e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},gl=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new tn)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},_l=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new gl(t)}getNullCell(){return new tn}},vl=class extends W{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new K),this.onBufferChange=this._onBufferChange.event,this._normal=new _l(this._core.buffers.normal,`normal`),this._alternate=new _l(this._core.buffers.alt,`alternate`),this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw Error(`Active buffer is neither normal nor alternate`)}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},yl=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,e=>t(e.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(e,n)=>t(e,n.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},bl=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},xl=[`cols`,`rows`],Sl=0,Cl=class extends W{constructor(e){super(),this._core=this._register(new pl(e)),this._addonManager=this._register(new hl),this._publicOptions={...this._core.options};let t=e=>this._core.options[e],n=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(let e in this._core.options){let r={get:t.bind(this,e),set:n.bind(this,e)};Object.defineProperty(this._publicOptions,e,r)}}_checkReadonlyOptions(e){if(xl.includes(e))throw Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw Error(`You must set the allowProposedApi option to true to use proposed API`)}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||=new yl(this._core),this._parser}get unicode(){return this._checkProposedApi(),new bl(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||=this._register(new vl(this._core)),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t=`none`;switch(this._core.coreMouseService.activeProtocol){case`X10`:t=`x10`;break;case`VT200`:t=`vt200`;break;case`DRAG`:t=`drag`;break;case`ANY`:t=`any`}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,n){this._verifyIntegers(e,t,n),this._core.select(e,t,n)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
|
|
20
20
|
`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return Rt.get()},set promptLabel(e){Rt.set(e)},get tooMuchOutput(){return Bt.get()},set tooMuchOutput(e){Bt.set(e)}}}_verifyIntegers(...e){for(Sl of e)if(Sl===1/0||isNaN(Sl)||Sl%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(Sl of e)if(Sl&&(Sl===1/0||isNaN(Sl)||Sl%1!=0||Sl<0))throw Error(`This API only accepts positive integers`)}},wl=2,Tl=1,El=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(wl,Math.floor(u/e.css.cell.width)),rows:Math.max(Tl,Math.floor(l/e.css.cell.height))}}},Dl=`modulepreload`,Ol=function(e){return`/`+e},kl={},Al=function(e){return e.pathname.endsWith(`.css`)},jl=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},Ml=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=Ol(t,n);let r=s(t),i=Al(r);return jl(kl,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:Dl,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Nl=I(`<div class=overlay><div class=modal style=max-width:360px><div class=modal-head><b>🔒 sign in</b><span></span></div><form style=display:flex;flex-direction:column;gap:10px><input id=pw-input type=password placeholder=password autofocus><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:7px 12px;cursor:pointer">unlock</button><span class=muted style=font-size:11px>the token is stored locally and sent as Bearer to this server only`),Pl=I(`<div class=themegrid>`),Fl=I(`<div class=themepop><label class=trow title="switch automatically when the OS switches appearance — pick which theme to use for each"><input type=checkbox>follow system`),Il=I(`<i class=notifdot>`),Ll=I(`<br>`),Rl=I(`<span class="badge queued">⏳ <!> of yours queued`),zl=I(`<span class="badge cron">⏰ `),Bl=I(`<span class=sub>ℹ`),Vl=I(`<header class=chan-head><span class=hash>#</span><span class=title></span><span></span><span class=sub> · <!>/<!> · turns <!> · tools </span><span style=margin-left:auto;display:flex;gap:4px>`),Hl=I(`<div class=divider-msg>── beginning of log ──`),Ul=I(`<div class=divider-msg>loading older events…`),Wl=I(`<details class=reasoning open><summary>💭 thinking </summary><div class="mono thinkscroll">`),Gl=I(`<div class=muted style=font-size:11.5px;margin-bottom:4px>🗜 summarizing older context…`),Kl=I(`<div class=content>`),ql=I(`<div class="msg live"><div class=avatar style="background:#5865f233;border:1px solid #5865f266">🫖</div><div class=msg-body><div class=msg-head><span class=author style=color:var(--acc)>agent</span><span class=ts>streaming…`),Jl=I(`<div class=feed>`),Yl=I(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),Xl=I(`<div class=termsplit>`),Zl=I(`<div class="termempty muted">no shell here — click a tab or + to add`),Ql=I(`<div class=termpane>`),$l=I(`<div class=termdrawer><div class=termgrip title="drag to resize · double-click to reset"></div><div class=termbar><div class=termtabs></div><div style=display:flex;gap:4px;align-items:center><span class="muted mono"style=flex:1;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span></div></div><div class=termbody><div class=termpane>`),eu=I(`<button class=jump>↓ `),tu=I(`<div class=cmds>`),nu=I(`<div class=imgstage><span class=muted style=font-size:11px;align-self:center> image<!> attached`),ru=I(`<label class=forkchip title="inherit the conversation prefix byte-exactly — the sub-agent's provider prefix cache starts warm"><input type=checkbox>fork ctx`),iu=I(`<span class=muted style=font-size:11.5px;white-space:nowrap>🖼 `),au=I(`<div><form><textarea rows=1></textarea><button type=button class="iconbtn maxbtn"></button><button type=submit>send</button><input id=composer-file type=file accept=image/* multiple style=display:none></form><div class=hint>`),ou=I(`<div class=rightbarbackdrop>`),su=I(`<div><nav class=sidebar><div class=agent-list></div><div class=sidebar-footer><div class=footer-row style=justify-content:flex-end><button>🔔</button></div><div class=brand-row><div class=brand>🫖 teapot <span class=version>v</span><span></span></div></div><div class=metrics></div></div></nav><section class=channel></section><aside><div class=rightbarhead><span class=muted>details`),cu=I(`<div class=notifbackdrop>`),lu=I(`<button class=editbtn>clear all`),uu=I(`<div class=notiflist>`),du=I(`<div class=notifpanel><div class=notifhead>notifications<span style=display:flex;gap:8px;align-items:center><button class=iconbtn title="close notifications">✕`),fu=I(`<span class=wscount>`),pu=I(`<div class=wsheader><span class=wscaret>`),mu=I(`<span class=notifbadge>🔔`),hu=I(`<span class=subtag>🧩`),gu=I(`<span class=mini-cron>⏰`),_u=I(`<span class=goaldone title="goal done">✓`),vu=I(`<div><span></span><span>`),yu=I(`<span class=caret-spacer>`),bu=I(`<span class=caret>`),xu=I(`<span class=ghosttag title="workspace missing">👻`),Su=I(`<span>🧩 `),Cu=I(`<label class=trow>system light →<select class=w100>`),wu=I(`<label class=trow>system dark →<select class=w100>`),Tu=I(`<option>`),Eu=I(`<button><span class=swdots>`),Du=I(`<i>`),Ou=I(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),ku=I(`<div class="divider-msg compacting"title="the harness is compressing old turns into notes so work can continue within the context window">🗜 `),Au=I(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),ju=I(`<div class="content muted">thinking…`),Mu=I(`<span>⌨ <button class=tabx title="close this shell">✕`),Nu=I(`<div><b class=mono></b><span class=muted>`),Pu=I(`<div class=cmdrow><b>@</b><span class=muted>`),Fu=I(`<span class=imgchip><img><button type=button class=imgx title=remove>✕`),Iu=I(`<h3 title="identity + storage locations for this agent">🎛 session`),Lu=I(`<div class="card sesscard"><div class=sessrow><span class=k>agent</span><b></b><span></span></div><div class=sessrow><span class=k>workspace</span><span class="mono ellip"></span></div><div class=sessrow><span class=k>session</span><span class=mono>/`),Ru=I(`<h3 title="switch provider/model live — applies from the agent's next turn; the list shows context window & pricing from the provider">🧦 model`),zu=I(`<div style=display:flex;gap:6px;align-items:center;margin-top:6px><label class=muted style=font-size:11.5px;white-space:nowrap>effort</label><select style=flex:1;min-width:0><option value>provider default</option></select><button title="apply to this session — takes effect from the agent's next turn">apply`),Bu=I(`<div class=meta style=color:var(--fg)>`),Vu=I(`<div class=modelbox><select title="provider (OpenAI-compatible endpoint)"></select><div style=display:flex;gap:4px><input type=text list=model-list style=flex:1;min-width:0><datalist id=model-list></datalist><button title="apply to this session — takes effect from the agent's next turn">apply</button></div><div class=meta>current: `),Hu=I(`<h3>⏯ controls`),Uu=I(`<button title="stop every sub-agent this agent spawned (descendants included)">⏹ subs`),Wu=I(`<div class=btnrow><button></button><button title="branch off the conversation here — try things without disturbing the main line">⑂ fork</button><button title="remove agent from teapot (session log stays on disk)">🗑 remove`),Gu=I(`<div class=ctrlrow><label title="auto-continue fires after a round ONLY when all hold: ① this toggle is on ② a goal is set and its status is 'active' ③ the round ended cleanly (no error / not stopped). It stops when the goal is marked done, or if you press ■ stop. Sending any prompt also starts an idle agent regardless."><input type=checkbox>auto-continue</label><span class=muted>loops while goal is active · stops on done / stop`),Ku=I(`<span>`),qu=I(`<h3 title="what the agent is working toward — auto-continue keeps looping while the status is 'active'">🎯 goal`),Ju=I(`<div class=statrow style=margin-bottom:6px><span class=k>status`),Yu=I(`<div class=card><div class=content>`),Xu=I(`<div class="card verifycard"title="verification contract — finish(goalComplete=true) is audited against these requirements by an independent reviewer before the goal counts as done"><div class=vtitle>🔍 verification contract</div><div class=content>`),Zu=I(`<div class=muted style=font-size:11px;margin-top:4px>stored with the session · the agent reads it via get_goal() · auto-continue loops while status is "working" and stops when marked done`),Qu=I(`<form style=display:flex;flex-direction:column;gap:6px;margin-top:8px;margin-bottom:6px><textarea id=goal-input rows=3 placeholder="set new goal…"style="background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;width:100%;resize:vertical"></textarea><textarea id=goal-verify-input rows=2 placeholder="verification contract (optional) — e.g. 'npm test passes; endpoint documented'. finish(goalComplete=true) is then audited against this."title="pi-goal-x-style verification contract — an independent reviewer checks the agent's finish against these requirements"style="background:var(--bg-darkest);border:1px solid var(--bg-light);border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;font-size:12.5px;width:100%;resize:vertical"></textarea><div style=display:flex;justify-content:flex-end;align-items:center;gap:10px><label class=muted title="queue a harness prompt telling the agent about the new goal at its next turn boundary"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=goal-notify type=checkbox> notify agent</label><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save goal`),$u=I(`<span class=badge>/<!> done`),ed=I(`<h3 title="todo.md — a shared checklist in the session dir. Write tasks like '- [ ] fix login'; the agent ticks them off via set_todo, you edit here. With notify on, it's told at its next turn boundary.">✅ tasks<span class=muted style=text-transform:none;letter-spacing:0>· shared checklist (you + agent)`),td=I(`<div class=bartrack style=margin-bottom:6px><div>`),nd=I(`<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`),rd=I(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),id=I(`<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`),ad=I(`<span class="pill ok">⚡ <!>% cached`),od=I(`<div class=statrow><span class=k>cost</span><b>$`),sd=I(`<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`),cd=I(`<div class=muted style=font-size:11px;text-transform:none;letter-spacing:0>showing <b></b> and the history it inherited before forking`),ld=I(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),ud=I(`<h3>⏰ schedule <span class=muted style=text-transform:none;letter-spacing:0>· cron tasks, all agents · edit in settings`),dd=I(`<span class=badge title="no goal set yet">no goal`),fd=I(`<button>`),pd=I(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),md=I(`<div><div class=vtitle><span class="meta muted"style=margin-left:auto></span></div><div class=content>`),hd=I(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),gd=I(`<div class=progrow><b>recent</b><span class="content inline-md">`),_d=I(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),vd=I(`<div class=progrow><b>next</b><span class="content inline-md">`),yd=I(`<div class=progrow><b>goal</b><span>`),bd=I(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),xd=I(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),Sd=I(`<span>% of `),Cd=I(`<div class=bartrack><div>`),wd=I(`<div class=bartrack style=margin-top:4px><div>`),Td=I(`<div class=statrow title="a compaction pass is running right now — the summarizer's output streams in the timeline"><span class=k>🗜</span><b>compacting…</b><span class=muted style=font-size:11px;color:var(--acc)>`),Ed=I(`<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`),Dd=I(`<div><span></span><span> events`),Od=I(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),kd=I(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),Ad=I(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class="sched-meta mono"> → next </div><div class="sched-prompt muted">`),jd=I(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),Md=I(`<div class=nbody>`),Nd=I(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted"></span><button class="iconbtn nreadbtn">`),Pd=I(`<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)`),Fd=I(`<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`),Id=I(`<span class=bashelapsed>running… `),Ld=I(`<span class=bashelapsed> elapsed`),Rd=I(`<span class=thinktimer>`),zd=I(`<pre class="mono toolbody">`),Bd=I(`<div class=meta>`),Vd=I(`<div class=meta>waiting for output…`),Hd=I(`<div class=mono>`),Ud=I(`<div class="meta bgjob-note">runs in background — poll with <b>bash_output(job_id="<!>")`),Wd=I(`<b>action="kill"`),Gd=I(`<div class="meta muted"> bytes — open it from 🗂 files for the full view`),Kd=I(`<div class=meta>writing…`),qd=I(`<pre class="mono toolbody del">`),Jd=I(`<pre class="mono toolbody add">`),Yd=I(`<div class=meta> · `),Xd=I(`<div class=meta>applying…`),Zd=I(`<pre class="mono toolbody patch">`),Qd=I(`<div>`),$d=I(`<div class="pline meta">… <!> more lines`),ef=I(`<div class=meta>validating…`),tf=I(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),nf=I(`<span class=muted>`),rf=I(`<div class=meta>loading…`),af=I(`<div class=meta>bundled: `),of=I(`<div class=meta>saving…`),sf=I(`<span class=actor>@`),cf=I(`<details><summary><b> </b><span class=meta></span><span class=toolcopy>`),lf=I(`<div class=divider-msg>⑂ forked from <!> → `),uf=I(`<div><div class=goalline-label>`),df=I(`<div class=divider-msg>✅ tasks updated (<!>)`),ff=I(`<div> → `),pf=I(`<div class="embed fail"><div class=mono>🛑 runaway: <!> tool failures in a row (limit <!>)</div><div class=meta>last: <!> — `),mf=I(`<div class="embed warn-embed"title="a round-fatal API error occurred; auto-retry is waiting, then a fresh round starts (onError: retry)"><div class=mono>↻ API error — retrying (attempt <!>) in <!>s…`),hf=I(`<div class=divider-msg>🗜 compacted: <!> → <!> tok (<!>)`),gf=I(`<div class=divider-msg title="compaction is rewriting older history — the agent is not stuck">🗜 compacting: summarizing <!> earlier messages from <!> tok (<!>)…`),_f=I(`<button class=editbtn title="withdraw this message — it has not reached the model yet; the text goes back to the input box">✕ cancel`),vf=I(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),yf=I(`<div class=msg-head><span class=author></span><span class=ts></span><span class=ts>`),bf=I(`<div><div></div><div class=msg-body>`),xf=I(`<span class=grouptime>`),Sf=I(`<div class=qfree><input type=text><button>reply`),Cf=I(`<div class=promptimgs>`),wf=I(`<img class=promptimg alt=attachment>`),Tf=I(`<details class=reasoning><summary>💭 reasoning</summary><div class=mono>`),Ef=I(`<div class=interrupted>⚠ interrupted — partial output kept`),Df=I(`<div class=msgfoot><span>copy summary`),Of=I(`<div class=meta>its call is no longer in the loaded events — the run itself finished`),kf=I(`<details><summary><span class=iconmeta>⚙</span><span class=meta></span></summary><div class=mono></div><div class=meta>`),Af=I(`<div class="content muted">Rejected: `),jf=I(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged</span></summary><div class=content>`),Mf=I(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),Nf=I(`<div class=qopts>`),Pf=I(`<div><div>❓ <div class="content inline-md">`),Ff=I(`<button class=qopt>`),If=I(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),Lf=I(`<div class="embed fail"><div class=mono>⚠ `),Rf=I(`<div class=vtitle style=margin-top:6px>what the agent kept`),zf=I(`<details class="embed compaction"><summary><b>🗜 context compacted</b><span class=meta> · <!> → <!> tok · `),Bf=I(`<div class="content muted">`),Vf=I(`<button type=button><span class=iconbtn-glyph>`),Hf=I(`<button class=copybtn>`),Uf=I(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),Wf=I(`<span style=color:var(--err);font-size:13px>`),Gf=I(`<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 title="parent directory">↑</button></div></label><div class=dirlist></div><div style=display:flex;gap:10px><label style=flex:1>agent name <input type=text placeholder="(directory name)"></label><label style="flex:0 1 auto;min-width:0">provider<select></select></label><label style=flex:1>model <input type=text placeholder="(provider default)"></label></div><button type=submit style=align-self:flex-end>create`),Kf=I(`<div class=direntry>📁 `),qf=I(`<div class="content mdpreview todopane">`),Jf=I(`<textarea id=todo-input class="mono todopane-edit"rows=5 placeholder="- task one
|
|
21
|
-
- task two"title="shared with the agent \\u2014 it may check items off via set_todo; your unsaved edits win until you save">`),Yf=I(`<span class=fsize>`),Xf=I(`<div><span class=ficon></span><span class=fname>`),Zf=I(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview"style=display:flex;align-items:center;gap:6px>🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),Qf=I(`<div class=filebox>`),$f=I(`<div class=muted style=padding:6px>`),ep=I(`<img>`),tp=I(`<div class=mediapreview><div class="meta muted"> preview`),np=I(`<button title="rendered markdown">👁 preview`),rp=I(`<button title="edit and save back to the workspace">✎ edit`),ip=I(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),ap=I(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),op=I(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),sp=I(`<div class="content mdpreview">`),cp=I(`<video controls>`),lp=I(`<audio controls>`),up=I(`<div class=filepreview>`),dp=I(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),fp=I(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),pp=I(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),mp=I(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),hp=I(`<span style=color:var(--fg)>`),gp=I(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),_p=I(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>default model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),vp=I(`<button type=button>`),yp=I(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),bp=I(`<label><input type=number min=0>`),xp=I(`<div class=muted style=font-size:11.5px;margin-top:4px>⚠ configured default provider <code></code> has no provider row here<!> Add a provider named <code></code> or pick a default below; otherwise agents fall back to the first provider.`),Sp=I(`<form style=display:flex;flex-direction:column;gap:14px><fieldset><legend>providers</legend><button type=button>+ add custom</button><div style=display:flex;gap:6px;flex-wrap:wrap;margin-top:6px><span class=muted style=font-size:11.5px>quick-add:</span></div><div><label title="agents without an explicit provider use this one"style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<select><option value>(none — first provider wins)</option></select></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid><label title="auto-compact threshold in k tokens. Leave EMPTY to derive per model (75% of its context window) — recommended, since models differ wildly in window size. Set only to force an absolute cap across all models.">compact budget (k tok)<input type=number min=0 placeholder="(derive: 75% of window)"></label></div></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><fieldset><legend>live update</legend><div class=cfgrow><span class=muted>current version: </span><button type=button style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">update & restart</button><span class=muted style=margin-left:8px;font-size:12px>gracefully stops all agents, spawns new process, then reloads this page</span></div></fieldset><button type=submit style="align-self:flex-end;background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">save settings`),Cp=I(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="api key"type=password><input placeholder="default model"><button type=button class=danger title="remove provider">✕`),wp=I(`<button type=button>+ `),Tp=I(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),Ep=I(`<span class=muted>🧩 sub of @`),Dp=I(`<div class=cfgrow><b></b><span class=muted>`),Op=new Map;function kp(e){let t=Op.get(e);if(t!==void 0)return t;let n=Fe(e);return Op.set(e,n),Op.size>500&&Op.delete(Op.keys().next().value),n}var Ap=[`minimal`,`low`,`medium`,`high`],jp=1100,Mp={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`}},Np={name:`harness`,icon:`📣`,color:`#3ba55d`},[Pp,Fp]=v(``),Ip,Q=e=>{Fp(e),clearTimeout(Ip),Ip=setTimeout(()=>Fp(``),3200)},Lp=!1,Rp=[{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`]}],zp=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`?Mp.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:Np}return Mp[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},Bp=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),Vp=new Set([`system_note`]),Hp=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=null;try{t=await i.json()}catch{}let n=(t&&typeof t==`object`&&`error`in t?String(t.error):``)||`${e}: HTTP ${i.status}`;throw Object.assign(Error(n),{payload:t})}return i.json()}var Up=location.hash.match(/[#&]token=([^&]+)/);Up&&(localStorage.setItem(`teapot.token`,decodeURIComponent(Up[1])),history.replaceState(null,``,location.pathname+location.search));var Wp=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function Gp(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v(``),[o,s]=v(new Map),[c,l]=v(new Map),u=!1;async function d(e=!1){if(!u||e){u=!0;try{let e=await $(`/api/sessions`),t=new Map,n=new Map;for(let r of e.sessions??[]){t.set(r.id,r.agentId);let e=n.get(r.agentId)??[];e.push(r.id),n.set(r.agentId,e)}s(t),l(n)}catch{}}}let[f,p]=v([]),[m,h]=v(0),[g,_]=v([]),[ee,te]=v(null),T=new Map,[ne,E]=v(T.get(n()??``)??``),D=e=>{E(e);let t=n();t&&(e?T.set(t,e):T.delete(t))},[O,re]=v({providers:{}}),[k,ie]=v(!1),[ae,oe]=v(!1),se=()=>window.innerWidth<=jp,[ce,A]=v(se());C(()=>{let e=()=>A(se());window.addEventListener(`resize`,e),w(()=>window.removeEventListener(`resize`,e)),e()}),C(()=>{let e=0,t=()=>{e||=requestAnimationFrame(()=>{e=0;let t=pr();if(!t)return;let n=ut(),r=n||!t.scrollHeight?null:le(t);(n||r)&&requestAnimationFrame(()=>{if(!t.isConnected)return;if(n){t.scrollTop=t.scrollHeight,pt(0);return}let e=r&&t.querySelector(r.sel);if(e){let n=e.getBoundingClientRect().top-r.top;n&&(t.scrollTop+=n)}})})};window.addEventListener(`resize`,t),w(()=>{window.removeEventListener(`resize`,t),e&&cancelAnimationFrame(e)})});function le(e){let t=e.querySelectorAll(`[data-eid]`),n=e.getBoundingClientRect().top;for(let e of t){let t=e.getBoundingClientRect();if(t.bottom>n){let n=e.dataset.eid??``;return n?{sel:`[data-eid="${CSS.escape(n)}"]`,top:t.top}:null}}return null}let[j,ue]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>jp:localStorage.getItem(`teapot.panel`)===`1`),de=e=>{ue(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},fe=()=>de(!j()),pe=()=>{j()&&de(!1)},[me,he]=v(!1),[ge,_e]=v(localStorage.getItem(`teapot.theme`)??`dark`),[ve,ye]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[be,xe]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[Se,I]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),Ce=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[Oe,ke]=v(Ce?.matches??!1);C(()=>{let e=e=>ke(e.matches);Ce?.addEventListener(`change`,e),w(()=>Ce?.removeEventListener(`change`,e))}),b(()=>{let e=ve()?Oe()?be():Se():ge();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=Rp.find(t=>t.key===e)?.mode??`dark`});let[Ae,je]=v(``),[Me,Ne]=v(``),[Pe,Ie]=v(``);b(()=>{let t=n();Ie(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[Le,Re]=v([]),ze=()=>Object.keys(O().providers??{});async function Be(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);Re(t.models??[])}catch{Re([])}}let We=e=>{let t={text:`📄`,image:`🖼️`,audio:`🔊`,video:`🎬`,file:`📎`},n=e=>(e??[`text`]).map(e=>t[e]??e).join(``);return e?.modalities?`${n(e.modalities.input)} → ${n(e.modalities.output)}`:``},Ge=()=>{let e=Me().trim()||H()?.model||``;if(!e)return``;let t=Le().find(t=>t.id===e);if(!t)return``;let n=[],r=We(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${tm(t.contextLength)} tok`);let i=e=>e===void 0?``:`${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=i(t.pricing.prompt),r=i(t.pricing.completion);e&&r?n.push(`${e} in · ${r} out`):(e||r)&&n.push(i(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},Qe=null,et=!1;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||O().defaultProvider||ze()[0]||``;if(r){if(t!==Qe)Qe=t,et=!1,S(()=>Ae())!==i&&(je(i),Be(i)),S(()=>Me())&&Ne(``);else{let e=S(()=>Ae());!S(()=>Me())&&e!==i&&At(et)&&(je(i),Be(i))}}});let[tt,rt]=v(!1),[ut,dt]=v(!0),[ft,pt]=v(0),[_t,Ct]=v(null),wt=()=>B().startsWith(`[compact] `),Tt=()=>wt()?B().slice(10):B();b(()=>{_t()||It(e=>e?.text.startsWith(`[compact] `)?null:e)}),b(()=>{_t(),ut()&&requestAnimationFrame(()=>requestAnimationFrame(()=>{ut()&&hr(!0)}))});let[Dt,Pt]=v(new Map),Ft=()=>{let e=n();return e?Dt().get(e)??null:null},It=e=>{let t=n();t&&Pt(n=>{let r=new Map(n),i=typeof e==`function`?e(n.get(t)??null):e;return i?r.set(t,{...i,at:Date.now()}):r.delete(t),r})},[B,V]=v(``),[Lt,Rt]=v(0),zt=()=>Lt(),[Bt,Vt]=v(``),Ht;b(()=>{Ft()?Ht||=setTimeout(()=>{Ht=void 0,V(Ft()?.text??``),Vt(Ft()?.reasoning??``)},(Ft()?.text.length??0)>2e4?250:(Ft()?.text.length??0)>6e3?120:60):(clearTimeout(Ht),Ht=void 0,V(``),Vt(``))}),w(()=>clearTimeout(Ht)),b(()=>{let t=e();Pt(e=>qe(e,e=>t.find(t=>t.id===e)?.status)),Rt(0)}),b(()=>{let e=B(),t=Ft()?.reasoning??``;(e||t)&&ut()&&requestAnimationFrame(()=>{ut()&&hr(!0)})}),b(()=>{let e=H()?.pendingPrompts??0,t=H()?.pendingPromptIds,n=Xt(),r=Zt(n),i=ht(r,e,t);i!==r&&Qt(n,i)}),b(()=>{let e=H()?.pendingPromptQueue;if(!e?.length)return;let t=Xt(),n=new Set(Zt(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&Qt(t,[...r.map(e=>({id:`p${e.id}`,text:e.text,at:Number(e.at)||Date.now(),promptId:e.id,images:e.images?.map(e=>e.url),...e.source?{source:e.source}:{}})),...Zt(t)])}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{K()&&(dt(!0),pt(0),hr(!0))})};document.addEventListener(`visibilitychange`,e),w(()=>document.removeEventListener(`visibilitychange`,e))});let H=x(()=>e().find(e=>e.id===n())),Ut=()=>{let e=H();return e?e.live??(e.status===`running`||e.status===`waiting`):!1},Wt=()=>bt(H(),i(),Ut()),[Gt,Kt]=v(null);x(()=>{let e=new Set;for(let t of f())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let qt=new Map,[Jt,Yt]=v([]),Xt=()=>i()||n()||`?`,Zt=e=>qt.get(e)??[],Qt=(e,t)=>{let n=new Set,r=[];for(let e=t.length-1;e>=0;e--){let i=t[e],a=i.promptId;a?n.has(a)||(n.add(a),r.push(i)):r.push(i)}r.reverse(),r.length===0?qt.delete(e):qt.set(e,r),Xt()===e&&Yt(r)},[$t,en]=v([]),[tn,nn]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[rn,an]=v(!1),on=()=>$t().filter(e=>!e.read).length,sn=e=>{en(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},cn=t=>{let n=$t().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=cn(r.id));return n},ln=0,un=e=>{en(t=>[{...e,id:`n${++ln}`,at:Date.now(),read:!1},...t].slice(0,50))},dn=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t,i=typeof n.id==`string`?n.id:void 0;n.type===`message`&&n.data?.final===!0?un({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?un({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?un({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&un({agentId:t,kind:`progress`,title:`${r}: ${String(n.data.doing??`progress`)}`.slice(0,120),body:[n.data.recent&&`recent: ${n.data.recent}`,n.data.next&&`next: ${n.data.next}`].filter(Boolean).join(` · `).slice(0,300),eventId:i})},fn=e=>{let t=document.querySelector(`[data-eid="${e}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`flash-target`),setTimeout(()=>t.classList.remove(`flash-target`),1600))},pn=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of f())if(Bp.has(i.type)){if(i.type===`tool_call`){let e=n.get(i.data.callId)??[];e.push(i),n.set(i.data.callId,e)}else if(i.type===`tool_result`){let a=n.get(i.data.callId)?.shift();a?(e.set(a.id,i),t.add(i.id)):r.set(i.id,i)}}return{resFor:e,consumed:t,orphanCalls:r}}),[mn,hn]=v(new Set),gn=e=>{e&&hn(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},_n=()=>hn(new Set),vn=x(()=>mt(f(),mn())),yn=x(()=>{let{consumed:e}=pn(),t=``;for(let e of f()){if(e._prevKind=t,!Bp.has(e.type))continue;let n=e.data??{};(e.type!==`message`||String(n.content??``).trim()!==``||String(n.reasoning??``).trim()===``)&&(t=e.type===`tool_result`?`tool`:e.type)}let n=f().filter(t=>{if(t.type===`sub`)return!0;if(!Bp.has(t.type))return!1;let n=t.type===`tool_call`||t.type===`tool_result`?String(t.data?.name??``):``;if(n===`report_progress`||n===`ask_user`||n===`record_decision`)return!1;if(t.type===`tool_result`)return!e.has(t.id);if(t.type===`message`){let e=String(t.data?.content??``);return e.trim()===``&&String(t.data?.reasoning??``).trim()!==``&&t._prevKind===`tool`||t.data?.progressEcho||!t.data?.final&&e.trim()===`(tool call)`?!1:e.trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final}return!0}),r=[];for(let e of n)if(e.type===`sub`){let t=e.data,n=String(t?.type??`message`);if(n===`state`)continue;r.push({...e,type:n,data:{...t?.data,actor:t?.sub}})}else r.push(e);let i=e=>String(e??``).replace(/\s+/g,` `).trim().toLowerCase(),a=[];for(let e=0;e<r.length;e++){let t=r[e];if(t.type===`message`&&t.data?.role===`assistant`){let n=r[e-1],a=i(t.data.content);if(n?.type===`progress`){let e=n.data;if((a.includes(i(e.doing))||e.recent&&a.includes(i(e.recent)))&&a.length<=Math.max(200,i(e.doing).length*3))continue}if(n?.type===`decision`){let e=n.data,t=i(e.decision);if(t&&a.includes(t)&&a.length<=Math.max(300,t.length*3))continue}}a.push(t)}let o=new Set,s=new Set,c=new Map,l=new Map;for(let e of a){let t=e.data?.promptId;t&&(e.type===`prompt`&&e.data?.source===`user`&&s.add(String(t)),e.type===`system_note`&&e.data?.event===`prompt-delivered`&&(o.add(String(t)),c.set(String(t),e.seq)),e.type===`system_note`&&e.data?.event===`prompt-cancelled`&&l.set(String(t),e.seq))}let u=new Set;for(let e of Jt())e.promptId&&!o.has(e.promptId)&&u.add(e.promptId);let d=a.filter(e=>{if(e.type!==`prompt`||e.data?.source!==`user`)return!0;let t=String(e.data?.promptId??``);return t===``||!u.has(t)});for(let e=0;e<d.length;e++){let t=d[e];if(t.type!==`prompt`||t.data?.source!==`user`)continue;let n=String(t.data?.promptId??``),r=l.get(n);r!==void 0&&t.data&&(t.data.cancelled=!0);let i=c.get(n)??0,a=Math.max(i,r??0)||void 0;d[e]=a===void 0?{...t,seq:Ze(d)}:Xe(t,a)}return Ye(d,Jt().filter(e=>!e.promptId||!(o.has(e.promptId)&&s.has(e.promptId))).map(e=>xn(e)))}),bn=new Map;function xn(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=bn.get(t);if(n)return n;bn.size>64&&bn.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:H()?.session??``,branch:H()?.branch??`br0`,parent:null,type:`prompt`,data:{source:e.source??`user`,text:e.text,pending:!e.sent,...e.images?.length?{images:e.images}:{},...e.promptId?{promptId:e.promptId}:{}}};return bn.set(t,r),r}let Sn=()=>$(`/api/config`).then(re).catch(()=>{}),[Cn,wn]=v(!1);C(()=>{let e=()=>wn(!0);window.addEventListener(`teapot:unauthorized`,e),w(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[Tn,En]=v(``),[Dn,On]=v(!1),[kn,An]=v(!1),jn=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==jn?(jn=t,An(!1),En(r)):t&&!kn()&&En(r)});let Mn=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:Tn(),notify:e})}),An(!1),On(!0),Q(`tasks saved${e&&Tn().trim()?` & notification queued`:``}`),Fn()}catch(e){Q(`save failed: ${e.message}`)}},Nn=x(()=>{let e=0,t=0;for(let n of Tn().split(`
|
|
22
|
-
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}});function Pn(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})}let Fn=()=>$(`/api/agents`).then(e=>{let n=!1;t(t=>(t.length!==(e.agents??[]).length&&(n=!0),(e.agents??[]).some(e=>!t.some(t=>t.id===e.id))&&(n=!0),Pn(t,e.agents??[]))),n&&d()}).catch(()=>{}),In=()=>$(`/api/metrics`).then(te).catch(()=>{}),[Ln,Rn]=v([]),zn=()=>$(`/api/tasks`).then(e=>Rn(e.tasks)).catch(()=>{}),Bn=e=>Ln().filter(t=>t.agent===e),[Vn,Hn]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`);return new Set(e.filter(e=>typeof e==`string`&&!e.startsWith(`chat:`)))}catch{return new Set}})()),Un=e=>{let t=new Set(Vn());t.has(e)?t.delete(e):t.add(e),Hn(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},Wn=t=>st(e(),t),[Gn,Kn]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.wsCollapsed`)??`[]`),t=Array.isArray(e)?e.filter(e=>typeof e==`string`):[];if(Number(localStorage.getItem(`teapot.wsCollapsed.v`)??`0`)<2){let e=t.filter(e=>!e.startsWith(`chat:`));return t.length-e.length>0&&localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify(e)),localStorage.setItem(`teapot.wsCollapsed.v`,`2`),new Set(e)}return new Set(t)}catch{return new Set}})()),qn=x(()=>{let e=new Set;for(let t of Gn())t.startsWith(`chat:`)&&e.add(t);return e}),Jn=x(()=>nt(e(),Vn(),tn(),qn())),U=(t,r,i,a)=>{let o=new Set(Gn());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||Wn(e().find(e=>e.id===i))===t)&&Q(`hid ${r} — click the header to show it`)}Kn(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},Yn=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,Xn=e=>{let t=W().get(e)??0;return`${t} chat${t===1?``:`s`}`},W=x(()=>ct(e())),Zn=x(()=>lt(e(),Jn(),Gn())),Qn=2e3,[$n,G]=v(null),er=new Map;function tr(e){return`${i()||(n()??`?`)}:${e.id}`}function nr(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=tr(r),a=er.get(i);if(t[n]=a??r,!a&&(er.set(i,r),er.size>6e3)){let e=er.keys().next().value;e!==void 0&&er.delete(e)}}return t}let[rr,ir]=v(!1),[ar,or]=v(!1),sr=0,cr=-1;function lr(e){p(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of nr(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function ur(){let e=n();if(!e||ar()||rr())return;if(f().length>=m()){or(!0);return}let t=()=>{let e=pr();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!ar()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(f().length>=m()){or(!0);return}let i=f().length;if(await dr(),f().length===i)return;ut()&&n()===e&&hr(!0)}}async function dr(){let e=n(),t=f()[0];if(e&&t&&!rr()&&!ar()){ir(!0);try{let r=pr(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=$n(),c=i(),l=c&&c!==e?`&session=${encodeURIComponent(c)}`:``,u=(await $(`/api/agents/${e}/events?limit=${Qn}&before=${encodeURIComponent(t.id)}${l}${s?`&branch=${encodeURIComponent(s)}&lineage=true`:``}`)).events??[];if(u.length===0){or(!0);return}if(n()!==e||f()[0]?.id!==t.id)return;lr(u),requestAnimationFrame(()=>{if(n()===e){let e=pr();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{ir(!1)}}}async function fr(e,t){let r=sr,a=t??i()??``;try{let t=$n(),i=r!==cr||!g().length,o=a&&a!==e?`&session=${encodeURIComponent(a)}`:``,[s,c,l]=await Promise.all([$(`/api/agents/${e}/events?limit=${Qn}${o}${t?`&branch=${encodeURIComponent(t)}&lineage=true`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:g()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(cr=r),r!==sr||n()!==e)return;p(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of nr(s.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),h(s.total??s.events.length),_(c.branches),vi(l.skills??[])}catch{}}function pr(){return document.querySelector(`.feed`)}function mr(){let e=document.querySelector(`.composer textarea`);return 24+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function K(){let e=pr();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<mr()}function hr(e=!1){let t=pr();t&&(e||ut())&&(t.scrollTop=t.scrollHeight,pt(0))}let gr=new Map,_r=(t,n)=>gt(c().get(t),e().find(e=>e.id===t)?.session,n);async function vr(e,t=!0,o){let s=n(),l=i(),u=f(),g=m();sr++,c().size||d();let _=_r(e,o)??e;if(s!==e||_!==l){if(l&&u.length&&(gr.set(l,{events:u,total:g,at:Date.now()}),gr.size>6)){let e=[...gr.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&gr.delete(e[0])}p([]),er.clear(),_n(),Ct(null),pt(0),dt(!0),Ti=!1,Ei=void 0}r(e),a(_),D(T.get(e)??``),G(null),or(!1),ir(!1),Qt(l||s||`?`,Jt()),Yt(Zt(_||e)),localStorage.setItem(`teapot.session`,e),Ar(_,t);let v=gr.get(_);v?.events.length&&(nr(v.events),p(nr(v.events)),h(v.total),requestAnimationFrame(()=>{n()===e&&hr(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(Fn).catch(()=>{}),await fr(e,_),n()===e&&(Pt(t=>{let n=t.get(e)??null,r=Je(n,f(),H()?.status);if(r===n)return t;let i=new Map(t);return r?i.set(e,r):i.delete(e),i}),Ct(H()?.ctx?.compacting?{phase:String(H().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&hr(!0)}),ur())}let[yr,br]=v(!1),xr=null,Sr=null;w(()=>xr?.close());let Cr=!1,wr=null;document.addEventListener(`visibilitychange`,()=>wr?.()),w(()=>{wr=null});let Tr=!0,Er=null;async function Dr(){let e=n(),t=f().at(-1)?.id,r=i(),a=document.visibilityState===`hidden`;if(!e||!t)Cr=!0,a||Er?.();else try{let n=r&&r!==e?`&session=${encodeURIComponent(r)}`:``,i=$n(),o=await $(`/api/agents/${e}/events?after=${encodeURIComponent(t)}${n}${i?`&branch=${encodeURIComponent(i)}&lineage=true`:``}`),s=o.events??[];o.gap?(p(nr(s)),h(s.length)):s.length&&(lr(s),h(e=>e+s.length)),await Fn(),s.length&&!a&&In()}catch{Cr=!0}}function Or(){Tr=!0;let r=location.protocol===`https:`?`wss://`:`ws://`,a=new WebSocket(`${r}${location.host}/api/ws${Wp()}`);xr=a,a.onopen=()=>{br(!0),Tr?Tr=!1:Dr()},a.onclose=()=>{br(!1),setTimeout(Or,1500)},a.onerror=()=>a.close();let o=new Set([`state`,`usage`,`session_start`]);a.onmessage=r=>{let c=JSON.parse(r.data);if(c.kind===`ping`)try{a.send(JSON.stringify({kind:`pong`}))}catch{}else if(c.kind!==`pong`){if(c.kind===`hello`&&Array.isArray(c.agents)){t(e=>Pn(e,c.agents));let n=e();Pt(e=>qe(e,e=>n.find(t=>t.id===e)?.status))}else if(c.kind===`event`&&Ue(c.event))Pt(e=>He(e,c.agentId));else if(c.kind===`llm-delta`){if(!yt(c,n(),i()))return;if(Pt(e=>Ve(e,c.agentId,c)),c.agentId===n()){let e=String(c.reasoning??``),t=String(c.text??``);e&&!t?Lt()||Rt(Date.now()):t&&Rt(0)}}else if(c.kind===`compaction-progress`){if(c.agentId!==n())return;c.phase===`done`?Ct(null):Ct({phase:c.phase,summarized:c.summarized})}else if(c.kind===`agent-update`&&c.snapshot)t(e=>{let t=e.findIndex(e=>e.id===c.snapshot.id),n=c.snapshot;return t===-1?[...e,n]:Pn(e,e.map((e,n)=>n===t?c.snapshot:e))});else{if(c.kind===`event`){let e=c.event?.type,t=c.event?.data??{};if((e===`system_note`&&t.event===`prompt-delivered`&&c.agentId===n()||e===`system_note`&&t.event===`prompt-cancelled`&&c.agentId===n())&&Qt(Xt(),Jt().filter(e=>e.promptId!==t.promptId)),o.has(e)&&!Vp.has(e)||(dn(c.agentId,c.event),c.event?.agent!==n())||!vt(c.event,n(),i())||(lr([c.event]),Cr=!0,document.visibilityState!==`visible`)||Sr)return;Sr=setTimeout(s,60)}document.visibilityState===`hidden`?Cr=!0:Sr||=setTimeout(s,120)}}},Cr=!1;let s=async()=>{if(Sr=null,await Fn(),await In(),n()){let e=f().at(-1)?.id,t=m();await fr(n());let r=Ft();r&&!Je(r,f(),H()?.status)&&It(null),f().at(-1)?.id!==e&&(ut()?(hr(!0),sn(n())):pt(ft()+Math.max(0,m()-t)))}};Er=s,wr=()=>{document.visibilityState===`visible`&&n()&&(Cr?(Cr=!1,s()):f().at(-1)?.id?Dr():(Cr=!0,s()))}}let kr=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function Ar(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=kr(),t=o().get(e);t&&(t!==n()||e!==i())&&vr(t,!1,e||null)}),b(()=>{let e=H(),t=e?`${Ut()?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=on()>0?`(${on()}) ${t}`:t});let jr=()=>k()||ae()||me()||Gt()!==null||se()&&j();window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable))e.key===`Escape`&&t.blur();else if(e.key===`Escape`){if(k()){ie(!1);return}if(ae()){oe(!1);return}if(me()){he(!1);return}if(Gt()){Kt(null);return}if(se()&&j()){pe();return}let e=H();if(e&&Ut()){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(Fn);return}}else if(!jr()){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)fe();else if(e.key===`t`)Pr();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=Jn().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&&vr(t[i].id)}}});let[Mr,Nr]=v(localStorage.getItem(`teapot.term`)===`1`),Pr=()=>{let e=!Mr();Nr(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[Fr,Ir]=v([]),[Lr,Rr]=v(0),[zr,Br]=v(-1),[Vr,Hr]=v(!1),[Ur,Wr]=v(0),[Gr,Kr]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),qr=new Map,Jr=0,Yr=[null,null],Xr=()=>Fr()[Ur()===0?Lr():zr()]??null;function Zr(e){if(!Fr()[e])return;let t=Ur(),n=t===0?Lr():zr(),r=t===0?zr():Lr(),i=e=>t===0?Rr(e):Br(e);r===e?((e=>t===0?Br(e):Rr(e))(n),i(e)):n!==e&&i(e)}let Qr=()=>$r();function $r(e){let t=e??n();if(!t)return;let r=Fr().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}let i={key:`${t}#${++Jr}`,agentId:t,title:r===0?t:`${t}·${r+1}`};Ir(e=>[...e,i]);let a=Fr().length;Ur()===0?Rr(a):Br(a)}function ei(e){let t=Fr()[e];if(!t)return;let n=qr.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),qr.delete(t.key)}let r=Fr().filter((t,n)=>n!==e);Ir(r);let i=t=>t===e?-1:t>e?t-1:t;Rr(e=>Math.min(i(e),r.length-1)),Br(e=>e===-1?-1:Math.min(i(e),r.length-1))}b(()=>{ve(),ge(),Oe(),be(),Se();for(let[,e]of qr)St(e.term)});function ti(){for(let[,e]of qr){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}qr.clear()}function ni(e,t){let n=qr.get(e.key);if(n&&St(n.term),n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new Cl({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:xt()}),a=new El;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${Wp()}`);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},qr.set(e.key,n)}return n}function ri(e){let t=Yr[e];if(!t)return;let n=Fr()[e===0?Lr():zr()];if(!n){[...qr.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=ni(n,t);for(let[e,r]of qr)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(Ur()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{Fr(),Vr(),Lr(),zr(),Gr(),requestAnimationFrame(()=>{ri(0),Vr()&&ri(1)})});let ii=null;b(()=>{if(!Mr())return;let e=n();if(e&&e!==ii){if(ii=e,!Fr().some(t=>t.agentId===e))$r(e);else{let t=-1;Fr().forEach((n,r)=>{n.agentId===e&&(t=r)}),t>=0&&Zr(t)}}});let ai=e=>{e.preventDefault();let t=e.clientY,n=Gr(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Kr(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(Gr())),requestAnimationFrame(()=>{ri(0),Vr()&&ri(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},oi=()=>{let e=!Vr();if(Hr(e),e){let e=Fr().map((e,t)=>t).filter(e=>e!==Lr());(zr()<0||zr()===Lr()||zr()>=Fr().length)&&Br(e[0]??-1)}requestAnimationFrame(()=>{ri(0),Vr()&&ri(1)})};w(ti);let si=e=>t=>{Yr[e]=t,t&&requestAnimationFrame(()=>{ri(e),Vr()&&ri(1),setTimeout(()=>ri(e),200)})};C(()=>{Sn(),Fn().then(async()=>{await d();let t=kr(),n=t?o().get(t):void 0,r=(n?e().find(e=>e.id===n):void 0)??e().find(e=>e.id===t&&!o().has(t))??e().find(e=>e.id===localStorage.getItem(`teapot.session`))??e()[0];r&&vr(r.id,!1,t||null)}),In(),zn(),di(),Or();let t=setInterval(()=>{In(),zn()},3e4);w(()=>clearInterval(t))});let ci=[{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`}],[li,ui]=v([]),di=()=>$(`/api/personas`).then(e=>ui(e.personas)).catch(()=>{}),[fi,pi]=v(!1),mi=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},hi=()=>{let t=mi();return t===null?[]:[...li().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))},gi=new Set([`start`,`stop`,`fork`,`compact`]),[_i,vi]=v([]),[yi,bi]=v(-1),xi=()=>{let e=ne();if(!e.startsWith(`/`)||e.includes(`
|
|
23
|
-
`))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[2]??``).trim();if(!r&&n!==`skill`){let e=ci.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&gi.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=_i().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[]},Si,Ci=()=>{if(!Si)return;wi=!0;let e=ut();Si.style.height=`auto`,Si.style.height=tt()?``:`${Math.min(Si.scrollHeight,360)}px`,requestAnimationFrame(()=>{let t=pr();e&&t&&(t.scrollTop=t.scrollHeight),wi=!1})},wi=!1,Ti=!1,Ei;b(()=>{
|
|
24
|
-
`))),e}}),null),z(r,M(P,{get when(){return t.a.goal.status===`done`},get children(){return _u()}}),null),y(e=>{var o=`agent-item`+(t.a.id===n()?` sel`:``)+(t.depth>0?` sub-row`:``)+(t.chatCollapsedGroup?` collapsed`:``),s=t.depth>0?`padding-left:${10+t.depth*14}px`:``,c=t.a.parent?(()=>{let e=at(t.a.id,li().map(e=>e.key));return e?`sub-agent of @${t.a.parent} — "${e}"`:`sub-agent of @${t.a.parent}`})():void 0,l=`dot ${t.a.status}`,u=t.a.workspaceMissing?` ghost`:``,d=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:void 0;return o!==e.e&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),u!==e.i&&R(a,e.i=u),d!==e.n&&L(a,`title`,e.n=d),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),r}})]})),z(s,M(P,{get when(){return me()},get children(){var e=Fl(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;ye(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),z(e,M(P,{get when(){return!ve()},get fallback(){return[(()=>{var e=Cu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{xe(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(t,M(N,{get each(){return
|
|
25
|
-
`)}`)),e}}),r),z(r,()=>H().model,i),z(r,()=>H().session,a),z(r,()=>H().branch,o),z(r,()=>H().stats.turns,s),z(r,()=>H().stats.toolCalls,null),z(c,M(P,{get when(){return H().statusReason},get children(){var e=Bl();return y(()=>L(e,`title`,H().statusReason)),e}}),null),z(c,M(im,{icon:`⌨`,title:`terminal (t)`,onClick:Pr}),null),z(c,M(im,{icon:`▤`,title:`toggle details panel (d)`,onClick:fe}),null),y(()=>R(n,`badge ${H().status}`)),e})(),(()=>{var e=Jl();return e.addEventListener(`scroll`,e=>{if(wi)return;let t=e.currentTarget,r=K(),i=t.scrollHeight-t.scrollTop-t.clientHeight,a=t.scrollTop,o=Nt({gap:i,top:a},Ei);Ei={gap:i,top:a},r?Ti=!1:o&&(Ti=!0),a<=4&&n()&&!rr()&&!ar()&&f().length>0&&dr(),Ti&&!r?dt(!1):(r&&ft()&&pt(0),r?dt(!0):o&&dt(!1))}),z(e,M(P,{get when(){return _t()},children:e=>(()=>{var t=ku();return t.firstChild,z(t,(()=>{var t=F(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?tm(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),z(e,M(P,{get when(){return F(()=>!!ar())()&&yn().length>0},get children(){return Hl()}}),null),z(e,M(P,{get when(){return rr()},get children(){return Ul()}}),null),z(e,M(P,{get when(){return yn().length>0},get fallback(){return Au()},get children(){return[M(N,{get each(){return yn()},children:(e,t)=>M(Xp,{e,get prev(){return yn()[t()-1]},get res(){return pn().resFor.get(e.id)},get orphan(){return pn().orphanCalls.has(e.id)},onOption:e=>void Ai(e),answeredIds:vn,onAnswered:gn,get agentActive(){return F(()=>!!Wt())()&&Ke(e)},onResize:()=>{ut()&&requestAnimationFrame(()=>hr(!0))},get onCancel(){return e.data?.source===`user`&&e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);D(ne()?`${n}\n\n${ne()}`:n),Qt(Xt(),Jt().filter(e=>e.promptId!==t)),Q(`message withdrawn — draft restored`)}).catch(()=>Q(`withdraw failed — it may have already been sent`))}:void 0},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`&&!(e.data?.pending&&e.data?.sent!==!0)&&!e.data?.cancelled&&!Ut()?()=>Kt({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),M(P,{get when(){return F(()=>!!Wt())()&&Ft()},get children(){var e=ql(),t=e.firstChild.nextSibling;return t.firstChild,z(t,M(P,{get when(){return Bt()},get children(){var e=Wl(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return z(t,M(qp,{get startedAt(){return zt()}}),null),De(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{Bt(),t&&(e.scrollTop=e.scrollHeight)})},n),z(n,Bt),e}}),null),z(t,M(P,{get when(){return B()},get fallback(){return ju()},get children(){return M(P,{get when(){return wt()},get fallback(){return(()=>{var e=Kl();return y(()=>e.innerHTML=Fe(B()+`▍`)),e})()},get children(){return[Gl(),(()=>{var e=Kl();return y(()=>e.innerHTML=Fe(Tt()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),M(P,{get when(){return Mr()},get children(){var t=$l(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Kr(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Gr()))},n.$$pointerdown=ai,z(i,M(N,{get each(){return Fr()},children:(e,t)=>(()=>{var n=Mu(),r=n.firstChild.nextSibling;return n.$$click=()=>Zr(t()),z(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),ei(t())},y(r=>{var i=`termtab`+(Ur()===0&&Lr()===t()?` active`:``)+(Vr()&&Ur()===1&&zr()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),z(i,M(im,{icon:`+`,title:`new shell in this workspace`,onClick:Qr}),null),z(o,(()=>{var t=F(()=>!!Xr());return()=>t()?e().find(e=>e.id===Xr().agentId)?.workspace.split(`/`).filter(Boolean).pop():H()?.workspace})()),z(a,M(im,{icon:`◫`,get title(){return Vr()?`single pane`:`split panes (50/50)`},onClick:oi}),null),z(a,M(im,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:Pr}),null);var l=si(0);return typeof l==`function`&&De(l,c),c.$$pointerdown=()=>Wr(0),z(c,M(P,{get when(){return Lr()<0||Lr()>=Fr().length},get children(){return Yl()}})),z(s,M(P,{get when(){return Vr()},get children(){return[Xl(),(()=>{var e=Ql(),t=si(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>Wr(1),z(e,M(P,{get when(){return zr()<0||zr()>=Fr().length},get children(){return Zl()}})),y(()=>e.classList.toggle(`focused`,Ur()===1)),e})()]}}),null),y(e=>{var n={height:`${Gr()}px`},r=!!Vr(),i=Ur()===0;return e.e=Te(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=au(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling,o=t.nextSibling;return z(e,M(P,{get when(){return!ut()||ft()>0},get children(){var e=eu();return e.firstChild,e.$$click=()=>hr(!0),z(e,(()=>{var e=F(()=>ft()>0);return()=>e()?`${ft()} new message${ft()>1?`s`:``}`:`jump to present`})(),null),e}}),t),z(e,M(P,{get when(){return xi().length>0},get children(){var e=tu();return z(e,M(N,{get each(){return xi()},children:(e,t)=>(()=>{var n=Nu(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{D(e.insert),bi(-1)},z(r,()=>e.insert.trim()),z(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===yi()?` active`:``),a=e.title;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),z(e,M(P,{get when(){return hi().length>0},get children(){var e=tu();return z(e,M(N,{get each(){return hi()},children:e=>(()=>{var t=Pu(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{D(`@${e.key} `),bi(-1)},z(n,()=>e.key,null),z(r,()=>e.label),y(()=>L(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,ji),z(t,M(P,{get when(){return Di().length>0},get children(){var e=nu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,z(e,M(N,{get each(){return Di()},children:(e,t)=>(()=>{var n=Fu(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>Oi(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&L(n,`title`,t.e=i),a!==t.t&&L(r,`src`,t.t=a),o!==t.a&&L(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),z(t,()=>Di().length,n),z(t,()=>Di().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=xi();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),bi(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),bi(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&yi()>=0&&!Lp?(e.preventDefault(),D(t[yi()].insert),bi(-1)):e.key===`Escape`&&t.length>0?bi(-1):e.key===`Enter`&&!e.shiftKey&&!Lp&&!tt()&&(e.preventDefault(),ji(e))},n.$$input=e=>{D(e.currentTarget.value),bi(0),Ci()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),ki(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{Lp=!1}),D(Si?.value??``)}),n.addEventListener(`compositionstart`,()=>{Lp=!0}),De(e=>{Si=e,e.value=ne()},n),z(t,M(P,{get when(){return F(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=ru(),t=e.firstChild;return t.addEventListener(`change`,e=>pi(e.currentTarget.checked)),y(()=>t.checked=fi()),e}}),r),r.$$click=()=>{let e=!tt();rt(e),requestAnimationFrame(()=>Ci())},z(r,()=>tt()?`⤡`:`⤢`),z(t,M(im,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),z(t,M(P,{get when(){return Di().length},get children(){var e=iu();return e.firstChild,z(e,()=>Di().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&ki(e.currentTarget.files),e.currentTarget.value=``}),z(o,()=>Pp()||`enter send · shift+enter newline · ↑↓ sessions · / commands & focus · t terminal · d panel · esc interrupt · messages sent while the agent works queue up and land at the next turn boundary`),y(t=>{var i=`composer`+(tt()?` maximized`:``),a=`message #${H().id} — / for commands · paste or 📎 to attach images`,o=tt()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&R(e,t.e=i),a!==t.t&&L(n,`placeholder`,t.t=a),o!==t.a&&L(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()]}})),z(i,M(P,{get when(){return F(()=>!!ce())()&&j()},get children(){var e=ou();return e.$$click=()=>de(!1),e}}),C),C.addEventListener(`scroll`,e=>{Pi=e.currentTarget.scrollTop});var te=Ni;return typeof te==`function`?De(te,C):Ni=C,z(w,M(im,{icon:`✕`,title:`close details panel (esc)`,onClick:pe}),null),z(C,M(P,{get when(){return H()?.id},keyed:!0,fallback:null,children:i=>[Iu(),(()=>{var e=Lu(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return z(n,()=>H().id),z(r,()=>H().status),z(a,()=>H().workspace),z(o,()=>H().session,s),z(o,()=>H().branch,null),y(e=>{var t=`badge ${H().status}`,n=H().workspace;return t!==e.e&&R(r,e.e=t),n!==e.t&&L(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),M(P,{get when(){return H().id},keyed:!0,fallback:null,children:e=>M(gm,{agentId:e,get workspace(){return H().workspace}})}),Ru(),(()=>{var t=Vu(),r=t.firstChild,i=r.nextSibling,a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=i.nextSibling;return c.firstChild,r.addEventListener(`change`,t=>{let r=t.currentTarget.value;et=!0,je(r),Ne(Ot(O().providers,r,e().find(e=>e.id===n()))),Be(r)}),z(r,M(N,{get each(){return ze()},children:e=>(()=>{var t=Tu();return t.value=e,z(t,e,null),z(t,()=>e===O().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>Ne(e.currentTarget.value),z(o,M(N,{get each(){return Le()},children:e=>(()=>{var t=Tu();return y(()=>t.value=e.id),t})()})),s.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:Ae(),model:Me().trim()||void 0,contextWindowTokens:Le().find(e=>e.id===(Me().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,Fn()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},z(t,M(P,{get when(){return H().effortSupported},get children(){var e=zu(),t=e.firstChild.nextSibling;t.firstChild;var r=t.nextSibling;return t.addEventListener(`change`,e=>Ie(e.currentTarget.value)),z(t,M(N,{each:Ap,children:e=>(()=>{var t=Tu();return t.value=e,z(t,e),t})()}),null),r.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({reasoningEffort:Pe()})}),t.textContent=`✓ applied`,Fn()}catch(e){alert(`effort change failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},y(()=>t.value=Pe()),e}}),c),z(c,()=>H().model,null),z(c,M(P,{get when(){return Le().length},get children(){return[` · `,F(()=>Le().length),` models loaded`]}}),null),z(t,M(P,{get when(){return Ge()},get children(){var e=Bu();return z(e,Ge),e}}),null),y(()=>L(a,`placeholder`,kt(O().providers,Ae(),H(),Et(H(),O().providers,O().defaultProvider)))),y(()=>r.value=Ae()),y(()=>a.value=Me()),t})(),Hu(),(()=>{var i=Wu(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling;return we(a,`click`,Ut()?Fi(`/stop`):Fi(`/start`),!0),z(a,()=>Ut()?`■ stop`:`▶ start`),o.$$click=()=>$(`/api/agents/${H().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await d(!0),await vr(H().id)}),s.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await $(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let a=e().filter(e=>e.id!==i);t(a),d(!0),a[0]?vr(a[0].id):(r(null),p([]))},z(i,M(P,{get when(){return e().some(e=>e.parent===n())},get children(){var e=Uu();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),Fn())},e}}),null),y(e=>{var t=Ut()?`danger`:`runbtn`,n=Ut()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&R(a,e.e=t),n!==e.t&&L(a,`title`,e.t=n),e},{e:void 0,t:void 0}),i})(),(()=>{var e=Gu(),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(Fn)}),y(()=>t.checked=H().autoContinue??!0),e})(),(()=>{var e=qu();return e.firstChild,z(e,M(P,{get when(){return!!H().goal.text.trim()},get fallback(){return dd()},get children(){var e=Ku();return z(e,()=>H().goal.status),y(()=>R(e,`badge ${H().goal.status===`active`?`running`:H().goal.status}`)),e}}),null),e})(),(()=>{var e=Ju();return e.firstChild,z(e,M(N,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=fd();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(Fn)},L(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),z(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(H().goal.text.trim()&&H().goal.status===e?` on ${e}`:``),i=!!H().goal.text.trim()&&H().goal.status===e;return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),M(P,{get when(){return H().goal.text},get fallback(){return pd()},get children(){return[(()=>{var e=Yu(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(H().goal.text))),e})(),M(P,{get when(){return H().goal.verify},get children(){var e=Xu(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(H().goal.verify))),e}}),M(P,{get when(){return H().goal.audit},children:e=>(()=>{var t=md(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return z(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),z(r,()=>em(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=$e(e().feedback)?Fe(`_the auditor returned a verdict with no detail_`):Fe(e().feedback);return r!==n.e&&R(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),Zu(),(()=>{var e=Qu(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,Wi),t.$$input=e=>{Li(e.currentTarget.value),Bi(!0)},n.$$input=e=>{q(e.currentTarget.value),Bi(!0)},r.addEventListener(`change`,e=>Hi(e.currentTarget.checked)),y(()=>t.value=Ii()),y(()=>n.value=Ri()),y(()=>r.checked=Vi()),e})(),(()=>{var e=ed(),t=e.firstChild.nextSibling;return z(e,M(P,{get when(){return Nn().total>0},get children(){var e=$u(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,z(e,()=>Nn().done,t),z(e,()=>Nn().total,n),y(t=>Te(e,Nn().done===Nn().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),M(P,{get when(){return Nn().total>0},get children(){var e=td(),t=e.firstChild;return y(e=>{var n=`barfill `+(Nn().done===Nn().total?``:`warn`),r=`${Math.round(Nn().done/Nn().total*100)}%`;return n!==e.e&&R(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),M(hm,{get draft(){return Tn()},get preview(){return Dn()},onDraft:e=>{En(e),An(!0)}}),(()=>{var e=nd(),t=e.firstChild,n=t.nextSibling;return z(e,M(im,{get icon(){return Dn()?`✎`:`👁`},get title(){return Dn()?`edit markdown`:`rendered checklist`},onClick:()=>On(!Dn())}),t),n.$$click=Mn,e})(),rd(),M(P,{get when(){return H().latestProgress},get fallback(){return hd()},children:e=>(()=>{var t=bd(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return z(t,M(P,{get when(){return e().recent},get children(){var t=gd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=kp(e().recent)),t}}),i),z(t,M(P,{get when(){return e().problems},get children(){var t=_d(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=kp(e().problems)),t}}),i),z(t,M(P,{get when(){return e().next},get children(){var t=vd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=kp(e().next)),t}}),i),z(t,M(P,{get when(){return e().goalStatus},get children(){var t=yd(),n=t.firstChild.nextSibling;return z(n,()=>e().goalStatus),t}}),i),z(i,()=>em(e().ts)),y(()=>r.innerHTML=kp(e().doing)),t})()}),id(),(()=>{var e=sd(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=t.nextSibling,l=c.firstChild.nextSibling,u=l.firstChild,d=u.nextSibling;return d.nextSibling,z(i,()=>H().stats.turns),z(o,()=>H().stats.toolCalls),z(s,()=>H().stats.compactions??0),z(l,()=>tm(H().stats.inputTokens),u),z(l,()=>tm(H().stats.outputTokens),d),z(c,M(P,{get when(){return(H().stats.cachedInputTokens??0)>0},get children(){var e=ad(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>Math.round(H().stats.cachedInputTokens/Math.max(1,H().stats.inputTokens)*1e3)/10,t),y(()=>L(e,`title`,`${tm(H().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),z(e,M(P,{get when(){return(H().stats.costUsd??0)>0},get children(){var e=od(),t=e.firstChild.nextSibling;return t.firstChild,z(t,()=>nm(H().stats.costUsd??0),null),y(()=>L(e,`title`,`≈ ${(H().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),z(e,M(P,{get when(){return H().ctx},keyed:!0,get fallback(){return xd()},children:e=>{let t=x(()=>{let t=e,n=Le().find(e=>e.id===H().model),r=t.window||n?.contextLength||0,i=r?Math.min(999,t.usedTokens/r*100):0;return{usedTokens:t.usedTokens,compactAt:t.compactAt,compacting:t.compacting,window:t.window,effectiveWindow:r,pct:i,cls:r?i>=85?`crit`:i>=70?`warn`:`ok`:``,derivedBudget:r?Math.round(r*.75):0,usingDerived:t.compactAtIsManual!==!0}}),r=()=>t(),i=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)};return(()=>{var e=Ed(),t=e.firstChild,a=t.firstChild.nextSibling,o=a.firstChild.nextSibling;o.nextSibling;var s=t.nextSibling,c=s.firstChild.nextSibling,l=c.firstChild,u=c.nextSibling,d=s.nextSibling,f=d.firstChild.firstChild,p=d.nextSibling,m=p.firstChild.nextSibling;return m.nextSibling,z(a,()=>tm(r().usedTokens),o),z(t,M(P,{get when(){return r().effectiveWindow},get children(){var e=Sd(),t=e.firstChild;return z(e,()=>i(r().pct),t),z(e,()=>tm(r().effectiveWindow),null),y(()=>R(e,`pill ${r().cls}`)),e}}),null),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=Cd(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),z(c,()=>tm(r().usingDerived?r().derivedBudget:r().compactAt),l),z(u,()=>r().usingDerived?` (75% of window)`:` (manual override)`),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=wd(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,Math.round(r().usedTokens/r().derivedBudget*100))}%`;return n!==e.e&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),d),z(e,M(P,{get when(){return _t()||r().compacting},get children(){var e=Td(),t=e.firstChild.nextSibling.nextSibling;return z(t,()=>_t()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Fn)}),z(p,()=>tm(r().compactAt),m),y(()=>f.checked=H().autoCompact!==!1),e})()}}),null),e})(),(()=>{var e=ld();return e.firstChild.nextSibling,z(e,M(P,{get when(){return $n()},get children(){var e=cd(),t=e.firstChild.nextSibling;return z(t,$n),e}}),null),e})(),M(N,{get each(){return g()},children:e=>(()=>{var t=Dd(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=$n()===e.branch?null:e.branch,r=t!==$n();G(t),n()&&(r&&(sr++,p([]),h(0),or(!1)),fr(n()))},z(r,()=>e.branch,null),z(r,()=>e.branch===H().branch?` (current)`:``,null),z(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===H().branch||e.branch===$n()?` cur`:``),i=e.branch===$n()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),ud(),M(P,{get when(){return Ln().length>0},get fallback(){return Od()},get children(){return M(N,{get each(){return Ln()},children:e=>(()=>{var t=Ad(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>vr(e.agent),z(i,()=>e.id),z(a,()=>e.agent,null),z(r,M(P,{get when(){return e.forked},get children(){return kd()}}),null),z(o,()=>e.schedule,s),z(o,(()=>{var t=F(()=>!!e.next);return()=>t()?em(e.next):`—`})(),null),z(o,(()=>{var t=F(()=>!!e.last);return()=>t()?` · last ${em(e.last)}`:` · never ran`})(),null),z(c,()=>rm(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${rm(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&R(t,r.e=i),a!==r.t&&L(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var t=`layout`+(j()?``:` right-hidden`),n=`iconbtn notifbtn`+(on()>0?` has-unread`:``),r=on()>0?`${on()} unread notifications`:`notifications`,a=`conn`+(yr()?` ok`:``),o=yr()?`live (websocket)`:`reconnecting…`,s={"--termh":`${Gr()}px`},c=`rightbar`+(j()?` open`:``);return t!==e.e&&R(i,e.e=t),n!==e.t&&R(l,e.t=n),r!==e.a&&L(l,`title`,e.a=r),a!==e.o&&R(_,e.o=a),o!==e.i&&L(_,`title`,e.i=o),e.n=Te(S,s,e.n),c!==e.s&&R(C,e.s=c),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),i}}),M(P,{get when(){return rn()},get children(){return[(()=>{var e=cu();return e.$$click=()=>an(!1),e})(),(()=>{var t=du(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return z(r,M(P,{get when(){return $t().length>0},get children(){var e=lu();return e.$$click=()=>en([]),e}}),i),i.$$click=()=>an(!1),z(t,M(P,{get when(){return $t().length>0},get fallback(){return jd()},get children(){var t=uu();return z(t,M(N,{get each(){return $t()},children:t=>(()=>{var r=Nd(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{en(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&vr(t.agentId),an(!1),t.eventId&&setTimeout(()=>fn(t.eventId),n()===t.agentId?60:350)},z(i,(()=>{var e=F(()=>t.kind===`finish`);return()=>e()?`✅`:F(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),z(a,()=>t.title),z(o,()=>em(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),en(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},z(s,()=>t.read?`✓`:`○`),z(r,M(P,{get when(){return t.body},get children(){var e=Md();return z(e,()=>$p(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&R(r,e.e=n),i!==e.t&&L(r,`title`,e.t=i),a!==e.a&&L(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),M(P,{get when(){return k()},get children(){return M(sm,{get providers(){return Object.keys(O().providers??{})},onClose:()=>ie(!1),onCreated:e=>{ie(!1),Fn(),vr(e)}})}}),M(P,{get when(){return ae()},get children(){return M(xm,{get cfg(){return O()},onClose:()=>oe(!1),onSaved:()=>{Sn(),zn()}})}}),M(P,{get when(){return Gt()},fallback:null,children:e=>{let t=()=>f().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,f().length-t()-1),[i,a]=v(r()>0?`summarize`:`discard`);return M(om,{title:`edit prompt — forks the conversation`,onClose:()=>Kt(null),get children(){var t=Fd(),o=t.firstChild,s=o.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:i()})}),Kt(null),Fn();let t=n();t&&await vr(t)}catch(e){alert(`edit failed: ${e.message}`)}}),z(t,M(P,{get when(){return r()>0},get children(){var e=Pd(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return z(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>Kt(null),y(()=>o.value=e().text),t}})}})]}function Kp(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());C(()=>{let e=setInterval(()=>r(Date.now()),500);w(()=>clearInterval(e))});let i=()=>Be(Math.max(0,n()-t));return e.inline?(()=>{var t=Id();return t.firstChild,z(t,i,null),z(t,(()=>{var t=F(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=Ld(),t=e.firstChild;return z(e,i,t),e})()}function qp(e){let[t,n]=v(Date.now());return C(()=>{let e=setInterval(()=>n(Date.now()),500);w(()=>clearInterval(e))}),e.startedAt?(()=>{var n=Rd();return z(n,()=>Be(Math.max(0,t()-e.startedAt))),n})():null}function Jp(e){let t=e.e,n=()=>e.res,r=()=>!e.agentActive&&!n(),i=t.data??{},a=String(i.name??`tool`),o=()=>String(n()?.data?.result??``),s=e=>String(i.args?.[e]??``),c=()=>a===`bash`?s(`command`):s(`path`)||JSON.stringify(i.args??{},null,1),l=()=>a===`bash`?Number(s(`timeout_ms`))||void 0:a===`wait_children`?Number(s(`timeout_ms`))||3e5:Number(s(`timeout_ms`))||void 0,u=(e,t=1500)=>(()=>{var n=zd();return z(n,()=>$p(e,t)),n})(),d=(e=4e3)=>(()=>{let t=n();return t?[F(()=>u(o(),e)),(()=>{var e=Bd();return z(e,()=>Be(t.data?.durationMs),null),z(e,()=>a===`bash`?wt(Ct(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),z(e,M(am,{get text(){return o()}}),null),e})()]:Vd()})(),f=x(()=>{let e=a,t=``,r=(()=>{var e=Hd();return z(e,()=>$p(JSON.stringify(i.args??{},null,1),2e3)),e})();try{switch(a){case`bash`:{let a=s(`command`),c=i.args?.background===!0,l=c?String(o()).match(/job (bg\d+)/)?.[1]??``:``;e=(c?`⏳ `:`$ `)+rm(a,96);let f=s(`timeout_ms`)?Number(s(`timeout_ms`)):void 0,p=n(),m=Ct(p?.data?.ok,p?String(p.data?.result??``):``);t=p?c?`background job${l?` ${l}`:``}${f?` · timeout ${Math.round(f/1e3)}s`:``}`:Tt({outcome:m,durationMs:p.data?.durationMs,timeoutMs:f,fmtDur:Be}):null,r=[c?(()=>{var e=Ud(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,z(t,l||`?`,n),z(e,l?[` · kill with `,Wd()]:null,null),e})():null,F(()=>F(()=>a!==e.slice(2))()?u(a,800):null),F(()=>d(6e3))];break}case`read_file`:{e=s(`path`)||`(no path)`;let n=[];s(`pattern`)&&n.push(`grep /${rm(s(`pattern`),40)}/`),Number(i.args?.offset)<0?n.push(`last ${-Number(i.args.offset)} lines`):i.args?.offset&&n.push(`from L${i.args.offset}`),i.args?.limit&&n.push(`≤${i.args.limit} lines`),t=n.join(` · `),r=d(6e3);break}case`write_file`:{let a=String(i.args?.content??``);e=s(`path`)||`(no path)`,t=`${tm(a.length)} bytes`,r=[F(()=>u(a,1500)),F(()=>F(()=>a.length>1500)()?(()=>{var e=Gd(),t=e.firstChild;return z(e,()=>tm(a.length),t),e})():null),F(()=>F(()=>!!n())()?(()=>{var e=Bd();return z(e,()=>rm(o(),160)),e})():Kd())];break}case`edit_file`:e=s(`path`)||`(no path)`,t=i.args?.replace_all===!0?`replace all`:`unique spot`,r=[(()=>{var e=qd();return z(e,()=>$p(`- `+s(`old_text`),900)),e})(),(()=>{var e=Jd();return z(e,()=>`+ `+$p(s(`new_text`),900)),e})(),F(()=>F(()=>!!n())()?(()=>{var e=Yd(),t=e.firstChild;return z(e,()=>rm(o(),120),t),z(e,()=>Be(n().data?.durationMs),null),e})():Xd())];break;case`apply_patch`:{let t=s(`patch`).split(`
|
|
26
|
-
`).filter(e=>e&&!/^---$/.test(e.trim())),i=t.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);e=i.length?`${i.length} file${i.length>1?`s`:``}: ${
|
|
27
|
-
`)[0]??``,140),null),z(e,()=>n().data?.ok===!1?` · FAILED`:``,null),e})():ef())];break}case`list_dir`:e=s(`path`)||`.`,r=d(4e3);break;case`read_url`:{let n=s(`url`);try{let e=new URL(n);n=e.host+e.pathname}catch{}e=rm(n,70),t=`web`,r=[(()=>{var e=Bd();return z(e,M(P,{get when(){return/^https?:/i.test(s(`url`))},get fallback(){return(()=>{var e=nf();return z(e,()=>rm(s(`url`),80)),e})()},get children(){var e=tf();return y(()=>L(e,`href`,s(`url`))),e}})),e})(),F(()=>d(3e3))];break}case`bash_output`:{let n=s(`action`)||`read`;e=`bash_output ${s(`job_id`)||`(?)`}`,t=n,r=d(4e3);break}case`load_skill`:{e=`skill: ${s(`name`)}`;let t=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);r=n()?[(()=>{var e=Kl();return y(()=>e.innerHTML=Fe(t)),e})(),(()=>{var e=Bd();return z(e,()=>Be(n().data?.durationMs)),e})()]:rf();break}case`save_skill`:{e=`skill: ${s(`name`)}`,t=rm(s(`description`),60);let a=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];r=[F(()=>F(()=>!!a.length)()?(()=>{var e=af();return e.firstChild,z(e,()=>a.join(`, `),null),e})():null),F(()=>F(()=>!!n())()?(()=>{var e=Yd(),t=e.firstChild;return z(e,()=>rm(o(),160),t),z(e,()=>Be(n().data?.durationMs),null),e})():of())];break}}}catch{}return{icon:`⚙`,label:e,hint:t,body:r}});return(()=>{var i=cf(),s=i.firstChild,u=s.firstChild,d=u.firstChild,p=u.nextSibling,m=p.nextSibling;return i.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),z(u,()=>f().icon,d),z(u,()=>f().label,null),z(s,M(P,{get when(){return t.data?.actor},get children(){var e=sf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),p),z(p,(()=>{var e=F(()=>!!n());return()=>e()?f().hint||``:F(()=>!!r())()?`(result missed)`:F(()=>!!(a===`bash`||l()))()?M(Kp,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return l()}}):`running…`})()),z(m,M(am,{get text(){return c()},label:`⧉ cmd`,title:`copy the ${a} arguments`}),null),z(m,M(P,{get when(){return n()},get children(){return M(am,{get text(){return o()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(i,()=>f().body,null),y(e=>{var t=`embed`+(n()?n().data?.ok===!1?` fail`:` done`:r()?` done`:` running`),o=`${a}${f().hint?` — `+f().hint:``}`;return t!==e.e&&R(i,e.e=t),o!==e.t&&L(i,`title`,e.t=o),e},{e:void 0,t:void 0}),i})()}function Yp(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function Xp(e){let t=e.e,n=zp(t),r=pt(e.prev,t);if(t.type===`fork`){let e=t.data??{};return(()=>{var n=lf(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=tt(t.data??{});return(()=>{var t=uf(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=Qd();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=df(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=ff(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=pf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=mf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Qd();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=hf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=gf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var i=bf(),a=i.firstChild,o=a.nextSibling;return R(a,`avatar avghost`+(r?` ghosted`:``)),z(a,()=>r?``:n.icon),z(o,r&&(()=>{var e=xf();return y(()=>L(e,`title`,`${Hp(t.ts)} · ${t.branch}`)),e})(),null),z(o,M(P,{when:!r,get children(){var r=yf(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=sf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:Hp(t.ts)})()),z(o,()=>t.branch),z(r,M(P,{get when(){return e.onCancel},get children(){var t=_f();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(am,{get text(){return Yp(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=vf();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(o,M(Qp,{e:t,get res(){return e.res},get orphan(){return e.orphan},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get onAnswered(){return e.onAnswered},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var o=`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),s=t.id,c=r?`transparent`:n.color+`33`,l=r?`1px solid transparent`:`1px solid ${n.color}66`,u=r?`${Hp(t.ts)} · ${t.branch}`:void 0;return o!==e.e&&R(i,e.e=o),s!==e.t&&L(i,`data-eid`,e.t=s),c!==e.a&&Ee(a,`background`,e.a=c),l!==e.o&&Ee(a,`border`,e.o=l),u!==e.i&&L(a,`title`,e.i=u),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),i})()}function Zp(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=Sf(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&L(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function Qp(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Kl();return y(()=>e.innerHTML=kp(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=Cf();return z(t,M(N,{each:e,children:e=>(()=>{var t=wf();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Tf(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${tm(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>$p(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Kl();return y(()=>e.innerHTML=kp(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return Ef()}}),M(P,{get when(){return t.data.final},get children(){var e=Df(),n=e.firstChild;return z(e,M(am,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(Jp,{e:t,get res(){return e.res},get orphan(){return e.orphan},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=kf(),o=a.firstChild,s=o.firstChild.nextSibling,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(am,{text:n}),null),z(c,()=>$p(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?wt(Ct(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return Of()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=jf(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=Af();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=kp(String(t.data?.decision??``)),r=kp(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=()=>e.answeredIds?.().has(r)??!1;return(()=>{var a=Pf(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return Mf()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=Nf();return z(a,M(N,{each:n,children:n=>(()=>{var a=Ff();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M(Zp,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=kp(String(t.data?.question??``));return n!==e.e&&R(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=If(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=yd(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=gd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=kp(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=_d(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=kp(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=vd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=kp(String(t.data.next))),e}}),null),y(()=>n.innerHTML=kp(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=Lf(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=zf(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>tm(Number(t.data.tokensBefore??0)),i),z(n,()=>tm(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[Rf(),(()=>{var e=Kl();return y(()=>e.innerHTML=kp(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Bf();return z(e,()=>$p(JSON.stringify(t.data),200)),e})()}}function $p(e,t){return e.length>t?e.slice(0,t)+` …`:e}function em(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 tm(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 nm(e){return e>=100?Math.round(e).toLocaleString():e>=10?e.toFixed(1):e>=1?e.toFixed(2):e>=.01?e.toFixed(3):e.toFixed(4)}function rm(e,t){return $p(e.replace(/\s+/g,` `).trim(),t)}function im(e){return(()=>{var t=Vf(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function am(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),ut(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=Hf();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function om(e){return(()=>{var t=Uf(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function sm(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}C(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return M(om,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Gf(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,C=S.firstChild.nextSibling,w=S.nextSibling,ee=w.firstChild.nextSibling,te=w.nextSibling.firstChild.nextSibling,T=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=Kf();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),C.$$input=e=>o(e.currentTarget.value),ee.addEventListener(`change`,e=>c(e.currentTarget.value)),z(ee,M(N,{get each(){return e.providers},children:e=>(()=>{var t=Tu();return z(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=Wf();return z(e,d),e}}),T),y(()=>h.value=t()),y(()=>C.value=a()),y(()=>ee.value=s()),y(()=>te.value=l()),i}})}var cm=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),lm=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),um=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function dm(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=fm(e);return n===`image`?`🖼`:n===`video`?`🎬`:n===`audio`?`🎵`:[`ts`,`tsx`,`mts`,`cts`].includes(t)?`🟦`:[`js`,`mjs`,`cjs`,`jsx`].includes(t)?`🟨`:t===`json`||t===`jsonc`?`🧾`:t===`md`||t===`mdx`||t===`markdown`?`📝`:t===`css`||t===`scss`||t===`less`?`🎨`:t===`html`||t===`htm`||t===`svg`?`🌐`:[`py`,`pyi`].includes(t)?`🐍`:t===`rs`?`🦀`:t===`go`?`🐹`:t===`java`||t===`kt`||t===`kts`?`☕`:t===`rb`?`💎`:t===`php`?`🐘`:t===`c`||t===`h`||t===`cpp`||t===`hpp`||t===`cc`?`🧩`:t===`sh`||t===`bash`||t===`zsh`||t===`fish`?`🐚`:t===`sql`?`🗄`:t===`yml`||t===`yaml`||t===`toml`||t===`ini`||t===`conf`?`⚙`:t===`lock`?`🔒`:e===`Dockerfile`||t===`dockerfile`?`🐳`:t===`zip`||t===`gz`||t===`tar`||t===`tgz`||t===`bz2`?`📦`:t===`pdf`?`📕`:t===`txt`||t===`log`?`📄`:`·`}function fm(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return cm.has(t)?`image`:lm.has(t)?`video`:um.has(t)?`audio`:null}var pm=new Map,mm=e=>{let t=pm.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},pm.set(e,t)),t};function hm(e){return M(P,{get when(){return e.preview},get fallback(){return(()=>{var t=Jf();return t.$$input=t=>e.onDraft(t.currentTarget.value),y(()=>t.value=e.draft),t})()},get children(){var t=qf();return y(()=>t.innerHTML=kp(e.draft)),t}})}function gm(e){let t=mm(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),C=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},ee=e=>x()!==`hide`||!e.ignored,[te,T]=v(localStorage.getItem(`teapot.showHidden`)===`1`),ne=()=>{let e=!te(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await O(t,e)}))).then(t=>{T(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&re(e,n)})},E=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function D(e){return O(e,te())}async function O(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return E(t,i.entries??[])}catch(e){return _(e.message),null}}let re=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),k=``;b(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),D(``).then(e=>{e&&k===t&&r(new Map([[``,e]]))}))});let ie=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await D(e.path);t&&re(e.path,t)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[j,ue]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await Ml(async()=>{let{highlightChunks:e}=await import(`./shiki-yJJUtwxS.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};w(()=>{fe++});let me=async(t,n)=>{let r=fm(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(t&&!j()){ue(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
21
|
+
- task two"title="shared with the agent \\u2014 it may check items off via set_todo; your unsaved edits win until you save">`),Yf=I(`<span class=fsize>`),Xf=I(`<div><span class=ficon></span><span class=fname>`),Zf=I(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview"style=display:flex;align-items:center;gap:6px>🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),Qf=I(`<div class=filebox>`),$f=I(`<div class=muted style=padding:6px>`),ep=I(`<img>`),tp=I(`<div class=mediapreview><div class="meta muted"> preview`),np=I(`<button title="rendered markdown">👁 preview`),rp=I(`<button title="edit and save back to the workspace">✎ edit`),ip=I(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),ap=I(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),op=I(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),sp=I(`<div class="content mdpreview">`),cp=I(`<video controls>`),lp=I(`<audio controls>`),up=I(`<div class=filepreview>`),dp=I(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),fp=I(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),pp=I(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),mp=I(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),hp=I(`<div class=wizmodels>`),gp=I(`<span style=color:var(--fg)>`),_p=I(`<div class=muted style=font-size:11.5px;margin-top:-6px> model`),vp=I(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>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">`),yp=I(`<button type=button>`),bp=I(`<div class=muted style=font-size:11.5px;margin-top:-8px>`),xp=I(`<button type=button><span class=mono>`),Sp=I(`<label><input type=number min=0>`),Cp=I(`<div class=muted style=font-size:11.5px;margin-top:4px>⚠ configured default provider <code></code> has no provider row here<!> Add a provider named <code></code> or pick a default below; otherwise agents fall back to the first provider.`),wp=I(`<form style=display:flex;flex-direction:column;gap:14px><fieldset><legend>providers</legend><button type=button>+ add custom</button><div style=display:flex;gap:6px;flex-wrap:wrap;margin-top:6px><span class=muted style=font-size:11.5px>quick-add:</span></div><div><label title="agents without an explicit provider use this one"style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<select><option value>(none — first provider wins)</option></select></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid><label title="auto-compact threshold in k tokens. Leave EMPTY to derive per model (75% of its context window) — recommended, since models differ wildly in window size. Set only to force an absolute cap across all models.">compact budget (k tok)<input type=number min=0 placeholder="(derive: 75% of window)"></label></div></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><fieldset><legend>live update</legend><div class=cfgrow><span class=muted>current version: </span><button type=button style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">update & restart</button><span class=muted style=margin-left:8px;font-size:12px>gracefully stops all agents, spawns new process, then reloads this page</span></div></fieldset><button type=submit style="align-self:flex-end;background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">save settings`),Tp=I(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="api key"type=password><input placeholder="default model"><button type=button class=danger title="remove provider">✕`),Ep=I(`<button type=button>+ `),Dp=I(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),Op=I(`<span class=muted>🧩 sub of @`),kp=I(`<div class=cfgrow><b></b><span class=muted>`),Ap=new Map;function jp(e){let t=Ap.get(e);if(t!==void 0)return t;let n=Fe(e);return Ap.set(e,n),Ap.size>500&&Ap.delete(Ap.keys().next().value),n}var Mp=[`minimal`,`low`,`medium`,`high`],Np=1100,Pp={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`}},Fp={name:`harness`,icon:`📣`,color:`#3ba55d`},[Ip,Lp]=v(``),Rp,Q=e=>{Lp(e),clearTimeout(Rp),Rp=setTimeout(()=>Lp(``),3200)},zp=!1,Bp=[{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`]}],Vp=e=>{if(e.data?.actor)return{name:`@${String(e.data.actor)}`,icon:`🧩`,color:`#3ba0c9`};if(e.type===`tool_call`||e.type===`tool_result`)return{name:String(e.data?.name??`tool`),icon:`⚙`,color:`#3ba0c9`};if(e.type===`prompt`){let t=String(e.data?.source??`user`);return t===`user`?Pp.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:Fp}return Pp[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},Hp=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),Up=new Set([`system_note`]),Wp=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=null;try{t=await i.json()}catch{}let n=(t&&typeof t==`object`&&`error`in t?String(t.error):``)||`${e}: HTTP ${i.status}`;throw Object.assign(Error(n),{payload:t})}return i.json()}var Gp=location.hash.match(/[#&]token=([^&]+)/);Gp&&(localStorage.setItem(`teapot.token`,decodeURIComponent(Gp[1])),history.replaceState(null,``,location.pathname+location.search));var Kp=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function qp(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v(``),[o,s]=v(new Map),[c,l]=v(new Map),u=!1;async function d(e=!1){if(!u||e){u=!0;try{let e=await $(`/api/sessions`),t=new Map,n=new Map;for(let r of e.sessions??[]){t.set(r.id,r.agentId);let e=n.get(r.agentId)??[];e.push(r.id),n.set(r.agentId,e)}s(t),l(n)}catch{}}}let[f,p]=v([]),[m,h]=v(0),[g,_]=v([]),[ee,te]=v(null),T=new Map,[ne,E]=v(T.get(n()??``)??``),D=e=>{E(e);let t=n();t&&(e?T.set(t,e):T.delete(t))},[O,re]=v({providers:{}}),[k,ie]=v(!1),[ae,oe]=v(!1),se=()=>window.innerWidth<=Np,[ce,A]=v(se());C(()=>{let e=()=>A(se());window.addEventListener(`resize`,e),w(()=>window.removeEventListener(`resize`,e)),e()}),C(()=>{let e=0,t=()=>{e||=requestAnimationFrame(()=>{e=0;let t=pr();if(!t)return;let n=ut(),r=n||!t.scrollHeight?null:le(t);(n||r)&&requestAnimationFrame(()=>{if(!t.isConnected)return;if(n){t.scrollTop=t.scrollHeight,pt(0);return}let e=r&&t.querySelector(r.sel);if(e){let n=e.getBoundingClientRect().top-r.top;n&&(t.scrollTop+=n)}})})};window.addEventListener(`resize`,t),w(()=>{window.removeEventListener(`resize`,t),e&&cancelAnimationFrame(e)})});function le(e){let t=e.querySelectorAll(`[data-eid]`),n=e.getBoundingClientRect().top;for(let e of t){let t=e.getBoundingClientRect();if(t.bottom>n){let n=e.dataset.eid??``;return n?{sel:`[data-eid="${CSS.escape(n)}"]`,top:t.top}:null}}return null}let[j,ue]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>Np:localStorage.getItem(`teapot.panel`)===`1`),de=e=>{ue(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},fe=()=>de(!j()),pe=()=>{j()&&de(!1)},[me,he]=v(!1),[ge,_e]=v(localStorage.getItem(`teapot.theme`)??`dark`),[ve,ye]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[be,xe]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[Se,I]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),Ce=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[Oe,ke]=v(Ce?.matches??!1);C(()=>{let e=e=>ke(e.matches);Ce?.addEventListener(`change`,e),w(()=>Ce?.removeEventListener(`change`,e))}),b(()=>{let e=ve()?Oe()?be():Se():ge();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=Bp.find(t=>t.key===e)?.mode??`dark`});let[Ae,je]=v(``),[Me,Ne]=v(``),[Pe,Ie]=v(``);b(()=>{let t=n();Ie(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[Le,Re]=v([]),ze=()=>Object.keys(O().providers??{});async function Be(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);Re(t.models??[])}catch{Re([])}}let We=e=>{let t={text:`📄`,image:`🖼️`,audio:`🔊`,video:`🎬`,file:`📎`},n=e=>(e??[`text`]).map(e=>t[e]??e).join(``);return e?.modalities?`${n(e.modalities.input)} → ${n(e.modalities.output)}`:``},Ge=()=>{let e=Me().trim()||H()?.model||``;if(!e)return``;let t=Le().find(t=>t.id===e);if(!t)return``;let n=[],r=We(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${rm(t.contextLength)} tok`);let i=e=>e===void 0?``:`${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=i(t.pricing.prompt),r=i(t.pricing.completion);e&&r?n.push(`${e} in · ${r} out`):(e||r)&&n.push(i(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},Qe=null,et=!1;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||O().defaultProvider||ze()[0]||``;if(r){if(t!==Qe)Qe=t,et=!1,S(()=>Ae())!==i&&(je(i),Be(i)),S(()=>Me())&&Ne(``);else{let e=S(()=>Ae());!S(()=>Me())&&e!==i&&At(et)&&(je(i),Be(i))}}});let[tt,rt]=v(!1),[ut,dt]=v(!0),[ft,pt]=v(0),[_t,Ct]=v(null),wt=()=>B().startsWith(`[compact] `),Tt=()=>wt()?B().slice(10):B();b(()=>{_t()||It(e=>e?.text.startsWith(`[compact] `)?null:e)}),b(()=>{_t(),ut()&&requestAnimationFrame(()=>requestAnimationFrame(()=>{ut()&&hr(!0)}))});let[Dt,Pt]=v(new Map),Ft=()=>{let e=n();return e?Dt().get(e)??null:null},It=e=>{let t=n();t&&Pt(n=>{let r=new Map(n),i=typeof e==`function`?e(n.get(t)??null):e;return i?r.set(t,{...i,at:Date.now()}):r.delete(t),r})},[B,V]=v(``),[Lt,Rt]=v(0),zt=()=>Lt(),[Bt,Vt]=v(``),Ht;b(()=>{Ft()?Ht||=setTimeout(()=>{Ht=void 0,V(Ft()?.text??``),Vt(Ft()?.reasoning??``)},(Ft()?.text.length??0)>2e4?250:(Ft()?.text.length??0)>6e3?120:60):(clearTimeout(Ht),Ht=void 0,V(``),Vt(``))}),w(()=>clearTimeout(Ht)),b(()=>{let t=e();Pt(e=>qe(e,e=>t.find(t=>t.id===e)?.status)),Rt(0)}),b(()=>{let e=B(),t=Ft()?.reasoning??``;(e||t)&&ut()&&requestAnimationFrame(()=>{ut()&&hr(!0)})}),b(()=>{let e=H()?.pendingPrompts??0,t=H()?.pendingPromptIds,n=Xt(),r=Zt(n),i=ht(r,e,t);i!==r&&Qt(n,i)}),b(()=>{let e=H()?.pendingPromptQueue;if(!e?.length)return;let t=Xt(),n=new Set(Zt(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&Qt(t,[...r.map(e=>({id:`p${e.id}`,text:e.text,at:Number(e.at)||Date.now(),promptId:e.id,images:e.images?.map(e=>e.url),...e.source?{source:e.source}:{}})),...Zt(t)])}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{K()&&(dt(!0),pt(0),hr(!0))})};document.addEventListener(`visibilitychange`,e),w(()=>document.removeEventListener(`visibilitychange`,e))});let H=x(()=>e().find(e=>e.id===n())),Ut=()=>{let e=H();return e?e.live??(e.status===`running`||e.status===`waiting`):!1},Wt=()=>bt(H(),i(),Ut()),[Gt,Kt]=v(null);x(()=>{let e=new Set;for(let t of f())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let qt=new Map,[Jt,Yt]=v([]),Xt=()=>i()||n()||`?`,Zt=e=>qt.get(e)??[],Qt=(e,t)=>{let n=new Set,r=[];for(let e=t.length-1;e>=0;e--){let i=t[e],a=i.promptId;a?n.has(a)||(n.add(a),r.push(i)):r.push(i)}r.reverse(),r.length===0?qt.delete(e):qt.set(e,r),Xt()===e&&Yt(r)},[$t,en]=v([]),[tn,nn]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[rn,an]=v(!1),on=()=>$t().filter(e=>!e.read).length,sn=e=>{en(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},cn=t=>{let n=$t().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=cn(r.id));return n},ln=0,un=e=>{en(t=>[{...e,id:`n${++ln}`,at:Date.now(),read:!1},...t].slice(0,50))},dn=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t,i=typeof n.id==`string`?n.id:void 0;n.type===`message`&&n.data?.final===!0?un({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?un({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?un({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&un({agentId:t,kind:`progress`,title:`${r}: ${String(n.data.doing??`progress`)}`.slice(0,120),body:[n.data.recent&&`recent: ${n.data.recent}`,n.data.next&&`next: ${n.data.next}`].filter(Boolean).join(` · `).slice(0,300),eventId:i})},fn=e=>{let t=document.querySelector(`[data-eid="${e}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`flash-target`),setTimeout(()=>t.classList.remove(`flash-target`),1600))},pn=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of f())if(Hp.has(i.type)){if(i.type===`tool_call`){let e=n.get(i.data.callId)??[];e.push(i),n.set(i.data.callId,e)}else if(i.type===`tool_result`){let a=n.get(i.data.callId)?.shift();a?(e.set(a.id,i),t.add(i.id)):r.set(i.id,i)}}return{resFor:e,consumed:t,orphanCalls:r}}),[mn,hn]=v(new Set),gn=e=>{e&&hn(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},_n=()=>hn(new Set),vn=x(()=>mt(f(),mn())),yn=x(()=>{let{consumed:e}=pn(),t=``;for(let e of f()){if(e._prevKind=t,!Hp.has(e.type))continue;let n=e.data??{};(e.type!==`message`||String(n.content??``).trim()!==``||String(n.reasoning??``).trim()===``)&&(t=e.type===`tool_result`?`tool`:e.type)}let n=f().filter(t=>{if(t.type===`sub`)return!0;if(!Hp.has(t.type))return!1;let n=t.type===`tool_call`||t.type===`tool_result`?String(t.data?.name??``):``;if(n===`report_progress`||n===`ask_user`||n===`record_decision`)return!1;if(t.type===`tool_result`)return!e.has(t.id);if(t.type===`message`){let e=String(t.data?.content??``);return e.trim()===``&&String(t.data?.reasoning??``).trim()!==``&&t._prevKind===`tool`||t.data?.progressEcho||!t.data?.final&&e.trim()===`(tool call)`?!1:e.trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final}return!0}),r=[];for(let e of n)if(e.type===`sub`){let t=e.data,n=String(t?.type??`message`);if(n===`state`)continue;r.push({...e,type:n,data:{...t?.data,actor:t?.sub}})}else r.push(e);let i=e=>String(e??``).replace(/\s+/g,` `).trim().toLowerCase(),a=[];for(let e=0;e<r.length;e++){let t=r[e];if(t.type===`message`&&t.data?.role===`assistant`){let n=r[e-1],a=i(t.data.content);if(n?.type===`progress`){let e=n.data;if((a.includes(i(e.doing))||e.recent&&a.includes(i(e.recent)))&&a.length<=Math.max(200,i(e.doing).length*3))continue}if(n?.type===`decision`){let e=n.data,t=i(e.decision);if(t&&a.includes(t)&&a.length<=Math.max(300,t.length*3))continue}}a.push(t)}let o=new Set,s=new Set,c=new Map,l=new Map;for(let e of a){let t=e.data?.promptId;t&&(e.type===`prompt`&&e.data?.source===`user`&&s.add(String(t)),e.type===`system_note`&&e.data?.event===`prompt-delivered`&&(o.add(String(t)),c.set(String(t),e.seq)),e.type===`system_note`&&e.data?.event===`prompt-cancelled`&&l.set(String(t),e.seq))}let u=new Set;for(let e of Jt())e.promptId&&!o.has(e.promptId)&&u.add(e.promptId);let d=a.filter(e=>{if(e.type!==`prompt`||e.data?.source!==`user`)return!0;let t=String(e.data?.promptId??``);return t===``||!u.has(t)});for(let e=0;e<d.length;e++){let t=d[e];if(t.type!==`prompt`||t.data?.source!==`user`)continue;let n=String(t.data?.promptId??``),r=l.get(n);r!==void 0&&t.data&&(t.data.cancelled=!0);let i=c.get(n)??0,a=Math.max(i,r??0)||void 0;d[e]=a===void 0?{...t,seq:Ze(d)}:Xe(t,a)}return Ye(d,Jt().filter(e=>!e.promptId||!(o.has(e.promptId)&&s.has(e.promptId))).map(e=>xn(e)))}),bn=new Map;function xn(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=bn.get(t);if(n)return n;bn.size>64&&bn.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:H()?.session??``,branch:H()?.branch??`br0`,parent:null,type:`prompt`,data:{source:e.source??`user`,text:e.text,pending:!e.sent,...e.images?.length?{images:e.images}:{},...e.promptId?{promptId:e.promptId}:{}}};return bn.set(t,r),r}let Sn=()=>$(`/api/config`).then(re).catch(()=>{}),[Cn,wn]=v(!1);C(()=>{let e=()=>wn(!0);window.addEventListener(`teapot:unauthorized`,e),w(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[Tn,En]=v(``),[Dn,On]=v(!0),[kn,An]=v(!1),jn=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==jn?(jn=t,An(!1),En(r)):t&&!kn()&&En(r)});let Mn=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:Tn(),notify:e})}),An(!1),On(!0),Q(`tasks saved${e&&Tn().trim()?` & notification queued`:``}`),Fn()}catch(e){Q(`save failed: ${e.message}`)}},Nn=x(()=>{let e=0,t=0;for(let n of Tn().split(`
|
|
22
|
+
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}});function Pn(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})}let Fn=()=>$(`/api/agents`).then(e=>{let n=!1;t(t=>(t.length!==(e.agents??[]).length&&(n=!0),(e.agents??[]).some(e=>!t.some(t=>t.id===e.id))&&(n=!0),Pn(t,e.agents??[]))),n&&d()}).catch(()=>{}),In=()=>$(`/api/metrics`).then(te).catch(()=>{}),[Ln,Rn]=v([]),zn=()=>$(`/api/tasks`).then(e=>Rn(e.tasks)).catch(()=>{}),Bn=e=>Ln().filter(t=>t.agent===e),[Vn,Hn]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`);return new Set(e.filter(e=>typeof e==`string`&&!e.startsWith(`chat:`)))}catch{return new Set}})()),Un=e=>{let t=new Set(Vn());t.has(e)?t.delete(e):t.add(e),Hn(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},Wn=t=>st(e(),t),[Gn,Kn]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.wsCollapsed`)??`[]`),t=Array.isArray(e)?e.filter(e=>typeof e==`string`):[];if(Number(localStorage.getItem(`teapot.wsCollapsed.v`)??`0`)<2){let e=t.filter(e=>!e.startsWith(`chat:`));return t.length-e.length>0&&localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify(e)),localStorage.setItem(`teapot.wsCollapsed.v`,`2`),new Set(e)}return new Set(t)}catch{return new Set}})()),qn=x(()=>{let e=new Set;for(let t of Gn())t.startsWith(`chat:`)&&e.add(t);return e}),Jn=x(()=>nt(e(),Vn(),tn(),qn())),U=(t,r,i,a)=>{let o=new Set(Gn());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||Wn(e().find(e=>e.id===i))===t)&&Q(`hid ${r} — click the header to show it`)}Kn(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},Yn=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,Xn=e=>{let t=W().get(e)??0;return`${t} chat${t===1?``:`s`}`},W=x(()=>ct(e())),Zn=x(()=>lt(e(),Jn(),Gn())),Qn=2e3,[$n,G]=v(null),er=new Map;function tr(e){return`${i()||(n()??`?`)}:${e.id}`}function nr(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=tr(r),a=er.get(i);if(t[n]=a??r,!a&&(er.set(i,r),er.size>6e3)){let e=er.keys().next().value;e!==void 0&&er.delete(e)}}return t}let[rr,ir]=v(!1),[ar,or]=v(!1),sr=0,cr=-1;function lr(e){p(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of nr(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function ur(){let e=n();if(!e||ar()||rr())return;if(f().length>=m()){or(!0);return}let t=()=>{let e=pr();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!ar()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(f().length>=m()){or(!0);return}let i=f().length;if(await dr(),f().length===i)return;ut()&&n()===e&&hr(!0)}}async function dr(){let e=n(),t=f()[0];if(e&&t&&!rr()&&!ar()){ir(!0);try{let r=pr(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=$n(),c=i(),l=c&&c!==e?`&session=${encodeURIComponent(c)}`:``,u=(await $(`/api/agents/${e}/events?limit=${Qn}&before=${encodeURIComponent(t.id)}${l}${s?`&branch=${encodeURIComponent(s)}&lineage=true`:``}`)).events??[];if(u.length===0){or(!0);return}if(n()!==e||f()[0]?.id!==t.id)return;lr(u),requestAnimationFrame(()=>{if(n()===e){let e=pr();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{ir(!1)}}}async function fr(e,t){let r=sr,a=t??i()??``;try{let t=$n(),i=r!==cr||!g().length,o=a&&a!==e?`&session=${encodeURIComponent(a)}`:``,[s,c,l]=await Promise.all([$(`/api/agents/${e}/events?limit=${Qn}${o}${t?`&branch=${encodeURIComponent(t)}&lineage=true`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:g()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(cr=r),r!==sr||n()!==e)return;p(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of nr(s.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),h(s.total??s.events.length),_(c.branches),vi(l.skills??[])}catch{}}function pr(){return document.querySelector(`.feed`)}function mr(){let e=document.querySelector(`.composer textarea`);return 24+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function K(){let e=pr();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<mr()}function hr(e=!1){let t=pr();t&&(e||ut())&&(t.scrollTop=t.scrollHeight,pt(0))}let gr=new Map,_r=(t,n)=>gt(c().get(t),e().find(e=>e.id===t)?.session,n);async function vr(e,t=!0,o){let s=n(),l=i(),u=f(),g=m();sr++,c().size||d();let _=_r(e,o)??e;if(s!==e||_!==l){if(l&&u.length&&(gr.set(l,{events:u,total:g,at:Date.now()}),gr.size>6)){let e=[...gr.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&gr.delete(e[0])}p([]),er.clear(),_n(),Ct(null),pt(0),dt(!0),Ti=!1,Ei=void 0}r(e),a(_),D(T.get(e)??``),G(null),or(!1),ir(!1),Qt(l||s||`?`,Jt()),Yt(Zt(_||e)),localStorage.setItem(`teapot.session`,e),Ar(_,t);let v=gr.get(_);v?.events.length&&(nr(v.events),p(nr(v.events)),h(v.total),requestAnimationFrame(()=>{n()===e&&hr(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(Fn).catch(()=>{}),await fr(e,_),n()===e&&(Pt(t=>{let n=t.get(e)??null,r=Je(n,f(),H()?.status);if(r===n)return t;let i=new Map(t);return r?i.set(e,r):i.delete(e),i}),Ct(H()?.ctx?.compacting?{phase:String(H().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&hr(!0)}),ur())}let[yr,br]=v(!1),xr=null,Sr=null;w(()=>xr?.close());let Cr=!1,wr=null;document.addEventListener(`visibilitychange`,()=>wr?.()),w(()=>{wr=null});let Tr=!0,Er=null;async function Dr(){let e=n(),t=f().at(-1)?.id,r=i(),a=document.visibilityState===`hidden`;if(!e||!t)Cr=!0,a||Er?.();else try{let n=r&&r!==e?`&session=${encodeURIComponent(r)}`:``,i=$n(),o=await $(`/api/agents/${e}/events?after=${encodeURIComponent(t)}${n}${i?`&branch=${encodeURIComponent(i)}&lineage=true`:``}`),s=o.events??[];o.gap?(p(nr(s)),h(s.length)):s.length&&(lr(s),h(e=>e+s.length)),await Fn(),s.length&&!a&&In()}catch{Cr=!0}}function Or(){Tr=!0;let r=location.protocol===`https:`?`wss://`:`ws://`,a=new WebSocket(`${r}${location.host}/api/ws${Kp()}`);xr=a,a.onopen=()=>{br(!0),Tr?Tr=!1:Dr()},a.onclose=()=>{br(!1),setTimeout(Or,1500)},a.onerror=()=>a.close();let o=new Set([`state`,`usage`,`session_start`]);a.onmessage=r=>{let c=JSON.parse(r.data);if(c.kind===`ping`)try{a.send(JSON.stringify({kind:`pong`}))}catch{}else if(c.kind!==`pong`){if(c.kind===`hello`&&Array.isArray(c.agents)){t(e=>Pn(e,c.agents));let n=e();Pt(e=>qe(e,e=>n.find(t=>t.id===e)?.status))}else if(c.kind===`event`&&Ue(c.event))Pt(e=>He(e,c.agentId));else if(c.kind===`llm-delta`){if(!yt(c,n(),i()))return;if(Pt(e=>Ve(e,c.agentId,c)),c.agentId===n()){let e=String(c.reasoning??``),t=String(c.text??``);e&&!t?Lt()||Rt(Date.now()):t&&Rt(0)}}else if(c.kind===`compaction-progress`){if(c.agentId!==n())return;c.phase===`done`?Ct(null):Ct({phase:c.phase,summarized:c.summarized})}else if(c.kind===`agent-update`&&c.snapshot)t(e=>{let t=e.findIndex(e=>e.id===c.snapshot.id),n=c.snapshot;return t===-1?[...e,n]:Pn(e,e.map((e,n)=>n===t?c.snapshot:e))});else{if(c.kind===`event`){let e=c.event?.type,t=c.event?.data??{};if((e===`system_note`&&t.event===`prompt-delivered`&&c.agentId===n()||e===`system_note`&&t.event===`prompt-cancelled`&&c.agentId===n())&&Qt(Xt(),Jt().filter(e=>e.promptId!==t.promptId)),o.has(e)&&!Up.has(e)||(dn(c.agentId,c.event),c.event?.agent!==n())||!vt(c.event,n(),i())||(lr([c.event]),Cr=!0,document.visibilityState!==`visible`)||Sr)return;Sr=setTimeout(s,60)}document.visibilityState===`hidden`?Cr=!0:Sr||=setTimeout(s,120)}}},Cr=!1;let s=async()=>{if(Sr=null,await Fn(),await In(),n()){let e=f().at(-1)?.id,t=m();await fr(n());let r=Ft();r&&!Je(r,f(),H()?.status)&&It(null),f().at(-1)?.id!==e&&(ut()?(hr(!0),sn(n())):pt(ft()+Math.max(0,m()-t)))}};Er=s,wr=()=>{document.visibilityState===`visible`&&n()&&(Cr?(Cr=!1,s()):f().at(-1)?.id?Dr():(Cr=!0,s()))}}let kr=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function Ar(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=kr(),t=o().get(e);t&&(t!==n()||e!==i())&&vr(t,!1,e||null)}),b(()=>{let e=H(),t=e?`${Ut()?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=on()>0?`(${on()}) ${t}`:t});let jr=()=>k()||ae()||me()||Gt()!==null||se()&&j();window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable))e.key===`Escape`&&t.blur();else if(e.key===`Escape`){if(k()){ie(!1);return}if(ae()){oe(!1);return}if(me()){he(!1);return}if(Gt()){Kt(null);return}if(se()&&j()){pe();return}let e=H();if(e&&Ut()){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(Fn);return}}else if(!jr()){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)fe();else if(e.key===`t`)Pr();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=Jn().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&&vr(t[i].id)}}});let[Mr,Nr]=v(localStorage.getItem(`teapot.term`)===`1`),Pr=()=>{let e=!Mr();Nr(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[Fr,Ir]=v([]),[Lr,Rr]=v(0),[zr,Br]=v(-1),[Vr,Hr]=v(!1),[Ur,Wr]=v(0),[Gr,Kr]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),qr=new Map,Jr=0,Yr=[null,null],Xr=()=>Fr()[Ur()===0?Lr():zr()]??null;function Zr(e){if(!Fr()[e])return;let t=Ur(),n=t===0?Lr():zr(),r=t===0?zr():Lr(),i=e=>t===0?Rr(e):Br(e);r===e?((e=>t===0?Br(e):Rr(e))(n),i(e)):n!==e&&i(e)}let Qr=()=>$r();function $r(e){let t=e??n();if(!t)return;let r=Fr().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}let i={key:`${t}#${++Jr}`,agentId:t,title:r===0?t:`${t}·${r+1}`};Ir(e=>[...e,i]);let a=Fr().length;Ur()===0?Rr(a):Br(a)}function ei(e){let t=Fr()[e];if(!t)return;let n=qr.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),qr.delete(t.key)}let r=Fr().filter((t,n)=>n!==e);Ir(r);let i=t=>t===e?-1:t>e?t-1:t;Rr(e=>Math.min(i(e),r.length-1)),Br(e=>e===-1?-1:Math.min(i(e),r.length-1))}b(()=>{ve(),ge(),Oe(),be(),Se();for(let[,e]of qr)St(e.term)});function ti(){for(let[,e]of qr){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}qr.clear()}function ni(e,t){let n=qr.get(e.key);if(n&&St(n.term),n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new Cl({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:xt()}),a=new El;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${Kp()}`);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},qr.set(e.key,n)}return n}function ri(e){let t=Yr[e];if(!t)return;let n=Fr()[e===0?Lr():zr()];if(!n){[...qr.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=ni(n,t);for(let[e,r]of qr)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(Ur()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{Fr(),Vr(),Lr(),zr(),Gr(),requestAnimationFrame(()=>{ri(0),Vr()&&ri(1)})});let ii=null;b(()=>{if(!Mr())return;let e=n();if(e&&e!==ii){if(ii=e,!Fr().some(t=>t.agentId===e))$r(e);else{let t=-1;Fr().forEach((n,r)=>{n.agentId===e&&(t=r)}),t>=0&&Zr(t)}}});let ai=e=>{e.preventDefault();let t=e.clientY,n=Gr(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Kr(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(Gr())),requestAnimationFrame(()=>{ri(0),Vr()&&ri(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},oi=()=>{let e=!Vr();if(Hr(e),e){let e=Fr().map((e,t)=>t).filter(e=>e!==Lr());(zr()<0||zr()===Lr()||zr()>=Fr().length)&&Br(e[0]??-1)}requestAnimationFrame(()=>{ri(0),Vr()&&ri(1)})};w(ti);let si=e=>t=>{Yr[e]=t,t&&requestAnimationFrame(()=>{ri(e),Vr()&&ri(1),setTimeout(()=>ri(e),200)})};C(()=>{Sn(),Fn().then(async()=>{await d();let t=kr(),n=t?o().get(t):void 0,r=(n?e().find(e=>e.id===n):void 0)??e().find(e=>e.id===t&&!o().has(t))??e().find(e=>e.id===localStorage.getItem(`teapot.session`))??e()[0];r&&vr(r.id,!1,t||null)}),In(),zn(),di(),Or();let t=setInterval(()=>{In(),zn()},3e4);w(()=>clearInterval(t))});let ci=[{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`}],[li,ui]=v([]),di=()=>$(`/api/personas`).then(e=>ui(e.personas)).catch(()=>{}),[fi,pi]=v(!1),mi=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},hi=()=>{let t=mi();return t===null?[]:[...li().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))},gi=new Set([`start`,`stop`,`fork`,`compact`]),[_i,vi]=v([]),[yi,bi]=v(-1),xi=()=>{let e=ne();if(!e.startsWith(`/`)||e.includes(`
|
|
23
|
+
`))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[2]??``).trim();if(!r&&n!==`skill`){let e=ci.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&gi.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=_i().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[]},Si,Ci=()=>{if(!Si)return;wi=!0;let e=ut();Si.style.height=`auto`,Si.style.height=tt()?``:`${Math.min(Si.scrollHeight,360)}px`,requestAnimationFrame(()=>{let t=pr();e&&t&&(t.scrollTop=t.scrollHeight),wi=!1})},wi=!1,Ti=!1,Ei;b(()=>{let e=ne();Si&&jt(zp)&&(Mt(Si.value,e)&&(Si.value=e),Ci())});let[Di,Oi]=v([]),ki=e=>{let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));for(let e of t){if(e.size>8e6){Q(`"${e.name}" is over 8 MB — skipped`);continue}let t=new FileReader;t.onload=()=>{Oi(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},Ai=async(e,t)=>{let r=t??n();if(!r)return;let i=Di();try{let t=await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0,...i.length?{images:i}:{}})});Qt(Xt(),[...Jt(),{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now(),promptId:t.promptId,...i.length?{images:i.map(e=>e.url)}:{}}]),Oi([]),tt()&&(rt(!1),requestAnimationFrame(()=>Ci())),requestAnimationFrame(()=>requestAnimationFrame(()=>hr(!0)))}catch(t){D(e),console.error(`send failed:`,t)}},ji=async t=>{t.preventDefault();let r=n(),i=ne().trim();if(r&&i){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=li().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:fi()?`fork`:`none`})})).id}${fi()?` (forked context)`:``}`),Fn(),D(``)}else if(s){if(!a){Q(`usage: @${r} <message>`);return}await $(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),Q(`→ delivered to @${r}`),D(``)}else{Q(`unknown @${r} — personas: ${li().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}}else if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim();if(t===`goal`&&!n){D(`/goal `);return}if(t===`skill`&&!n){D(`/skill `);return}D(``);try{await Mi(t,n)}catch(e){throw D(ne()?`${i}\n${ne()}`:i),e}}else D(``),await Ai(i)}},Mi=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(Fn);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await vr(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 Ai(`[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}`)}},Ni,Pi=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Ni)return;let e=Math.min(Pi,Ni.scrollHeight);Math.abs(Ni.scrollTop-e)>1&&(Ni.scrollTop=e)})})});let Fi=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(Fn),[Ii,Li]=v(``),[Ri,q]=v(``),[zi,Bi]=v(!1),[Vi,Hi]=v(!0),Ui=``;b(()=>{let e=n();e&&(H()?.goal,e!==Ui&&(Ui=e,Bi(!1),Li(``),q(``)))});let Wi=async e=>{if(e.preventDefault(),n()&&Ii().trim())try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:Ii(),notify:Vi(),...Ri().trim()?{verify:Ri()}:{}})}),Li(``),q(``),Bi(!1),Fn()}catch(e){Q(`goal save failed: ${e.message}`)}};return[M(P,{get when(){return O()?.needsSetup},fallback:null,get children(){return M(Sm,{onDone:()=>location.reload()})}}),M(P,{get when(){return Cn()},get children(){var e=Nl();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),M(P,{get when(){return!O()?.needsSetup},get children(){var i=su(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.firstChild,l=c.firstChild;l.firstChild;var u=c.nextSibling,m=u.firstChild.firstChild.nextSibling;m.firstChild;var _=m.nextSibling,v=u.nextSibling,S=a.nextSibling,C=S.nextSibling,w=C.firstChild;w.firstChild,z(o,M(N,{get each(){return Zn()},children:t=>[M(P,{get when(){return F(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=pu(),n=e.firstChild;return e.$$click=()=>U(`ws:${t.wsHeader}`,Yn(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),z(n,()=>t.wsCollapsedGroup?`▸`:`▾`),z(e,()=>Yn(t.wsHeader),null),z(e,M(P,{get when(){return(W().get(t.wsHeader)??0)>1||t.wsCollapsedGroup},get children(){var e=fu();return z(e,()=>W().get(t.wsHeader)??0),e}}),null),y(()=>L(e,`title`,t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${Xn(t.wsHeader)} hidden). Click to show.`:(W().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${Xn(t.wsHeader)} in this directory`:t.wsHeader||``)),e}}),M(P,{get when(){return F(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=vu(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>vr(t.a.id),z(r,M(P,{get when(){return it({isSub:!!t.a.parent,collapsed:t.chatCollapsedGroup===!0,hasChildren:e().some(e=>e.parent===t.a.id)})},get fallback(){return yu()},get children(){return(()=>{let e=!t.a.parent,n=e&&qn().has(`chat:${t.a.id}`)||Vn().has(t.a.id);return(()=>{var r=bu();return r.$$click=r=>{if(r.stopPropagation(),e){if(Vn().has(t.a.id)){let e=new Set(Vn());e.delete(t.a.id),Hn(e),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...e]))}U(`chat:${t.a.id}`,t.a.id,n)}else Un(t.a.id)},z(r,n?`▸`:`▾`),y(()=>L(r,`title`,e?n?`show ${t.a.id}`:`hide ${t.a.id} and its sub-agents`:n?`expand sub-agents`:`collapse sub-agents`)),r})()})()}}),i),z(a,()=>t.a.id),z(r,(()=>{var e=F(()=>!!t.a.workspaceMissing);return()=>e()?xu():null})(),null),z(r,M(P,{get when(){return cn(t.a.id)>0},get children(){var e=mu();return e.firstChild,z(e,()=>cn(t.a.id),null),y(()=>L(e,`title`,`${cn(t.a.id)} unread notification${cn(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),z(r,M(P,{get when(){return Vn().has(t.a.id)||t.chatCollapsedGroup===!0&&qn().has(`chat:${t.a.id}`)},get children(){return(()=>{let n=ot(e(),t.a.id),r=n.filter(e=>e.live??(e.status===`running`||e.status===`waiting`)).length;return n.length>0?(()=>{var e=Su();return e.firstChild,R(e,`subcount`+(r>0?` live`:``)),z(e,()=>n.length,null),z(e,r>0?` · ▶${r}`:``,null),y(()=>L(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),z(r,M(P,{get when(){return t.a.parent},get children(){return hu()}}),null),z(r,M(P,{get when(){return Bn(t.a.id).length>0},get children(){var e=gu();return y(()=>L(e,`title`,Bn(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
|
|
24
|
+
`))),e}}),null),z(r,M(P,{get when(){return t.a.goal.status===`done`},get children(){return _u()}}),null),y(e=>{var o=`agent-item`+(t.a.id===n()?` sel`:``)+(t.depth>0?` sub-row`:``)+(t.chatCollapsedGroup?` collapsed`:``),s=t.depth>0?`padding-left:${10+t.depth*14}px`:``,c=t.a.parent?(()=>{let e=at(t.a.id,li().map(e=>e.key));return e?`sub-agent of @${t.a.parent} — "${e}"`:`sub-agent of @${t.a.parent}`})():void 0,l=`dot ${t.a.status}`,u=t.a.workspaceMissing?` ghost`:``,d=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:void 0;return o!==e.e&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),u!==e.i&&R(a,e.i=u),d!==e.n&&L(a,`title`,e.n=d),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),r}})]})),z(s,M(P,{get when(){return me()},get children(){var e=Fl(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;ye(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),z(e,M(P,{get when(){return!ve()},get fallback(){return[(()=>{var e=Cu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{xe(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(t,M(N,{get each(){return Bp.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=Tu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=be()),e})(),(()=>{var e=wu(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{I(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),z(t,M(N,{get each(){return Bp.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=Tu();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=Se()),e})()]},get children(){var e=Pl();return z(e,M(N,{each:Bp,children:e=>(()=>{var t=Eu(),n=t.firstChild;return t.$$click=()=>{_e(e.key),localStorage.setItem(`teapot.theme`,e.key)},z(n,()=>e.sw.map(e=>(()=>{var t=Du();return Ee(t,`background`,e),t})())),z(t,()=>e.label,null),y(n=>{var r=`themebtn`+(ge()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ve()),e}}),c),l.$$click=e=>{e.stopPropagation(),an(!rn()),rn()||en(e=>e.map(e=>({...e,read:!0})))},z(l,M(P,{get when(){return on()>0},get children(){var e=Il();return z(e,on),e}}),null),z(c,M(om,{icon:`👻`,get active(){return tn()},get title(){return tn()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!tn();if(nn(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&H()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&vr(t.id)}}}),null),z(c,M(om,{icon:`+`,title:`new agent`,onClick:()=>{Sn(),ie(!0)}}),null),z(c,M(om,{icon:`🎨`,title:`themes`,onClick:()=>he(!me())}),null),z(c,M(om,{icon:`⚙`,title:`settings`,onClick:()=>{Sn(),oe(!0)}}),null),z(m,`0.29.5`,null),z(v,M(P,{get when(){return ee()},get children(){return[`master rss `,F(()=>ee().rssMb),`MB · heap `,F(()=>ee().heapUsedMb),`MB`,Ll(),`load1 `,F(()=>ee().loadavg1),` · up `,F(()=>Math.floor(ee().uptimeSec/60)),`m`]}})),z(S,M(P,{get when(){return H()?.id},keyed:!0,get fallback(){return Ou()},get children(){return[(()=>{var e=Vl(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling;s.nextSibling;var c=r.nextSibling;return z(t,()=>H().id),z(n,()=>H().status),z(e,M(P,{get when(){return(H().pendingPromptIds?.length??H().pendingPrompts??0)>0},get children(){var e=Rl(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>H().pendingPromptIds?.length??H().pendingPrompts,t),z(e,()=>H().status===`stopped`?` (stopped)`:``,null),y(()=>L(e,`title`,H().status===`stopped`?`${H().pendingPromptIds?.length??H().pendingPrompts??0} message${(H().pendingPromptIds?.length??H().pendingPrompts??0)>1?`s`:``} from you are still queued, but this agent is STOPPED — nothing will run until you press start (or it is resumed). Each can be withdrawn with ✕ cancel while it is still queued.`:`${H().pendingPromptIds?.length??H().pendingPrompts??0} message${(H().pendingPromptIds?.length??H().pendingPrompts??0)>1?`s`:``} from you waiting in the queue. They will be handed to the model at its next turn boundary — the timeline shows them as "pending (queued)…" until then, and each can be withdrawn with ✕ cancel while it's still queued.`)),e}}),r),z(e,M(P,{get when(){return Bn(H().id).length>0},get children(){var e=zl();return e.firstChild,z(e,()=>Bn(H().id).length,null),y(()=>L(e,`title`,`scheduled tasks:\n${Bn(H().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
|
|
25
|
+
`)}`)),e}}),r),z(r,()=>H().model,i),z(r,()=>H().session,a),z(r,()=>H().branch,o),z(r,()=>H().stats.turns,s),z(r,()=>H().stats.toolCalls,null),z(c,M(P,{get when(){return H().statusReason},get children(){var e=Bl();return y(()=>L(e,`title`,H().statusReason)),e}}),null),z(c,M(om,{icon:`⌨`,title:`terminal (t)`,onClick:Pr}),null),z(c,M(om,{icon:`▤`,title:`toggle details panel (d)`,onClick:fe}),null),y(()=>R(n,`badge ${H().status}`)),e})(),(()=>{var e=Jl();return e.addEventListener(`scroll`,e=>{if(wi)return;let t=e.currentTarget,r=K(),i=t.scrollHeight-t.scrollTop-t.clientHeight,a=t.scrollTop,o=Nt({gap:i,top:a},Ei);Ei={gap:i,top:a},r?Ti=!1:o&&(Ti=!0),a<=4&&n()&&!rr()&&!ar()&&f().length>0&&dr(),Ti&&!r?dt(!1):(r&&ft()&&pt(0),r?dt(!0):o&&dt(!1))}),z(e,M(P,{get when(){return _t()},children:e=>(()=>{var t=ku();return t.firstChild,z(t,(()=>{var t=F(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?rm(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),z(e,M(P,{get when(){return F(()=>!!ar())()&&yn().length>0},get children(){return Hl()}}),null),z(e,M(P,{get when(){return rr()},get children(){return Ul()}}),null),z(e,M(P,{get when(){return yn().length>0},get fallback(){return Au()},get children(){return[M(N,{get each(){return yn()},children:(e,t)=>M(Qp,{e,get prev(){return yn()[t()-1]},get res(){return pn().resFor.get(e.id)},get orphan(){return pn().orphanCalls.has(e.id)},onOption:e=>void Ai(e),answeredIds:vn,onAnswered:gn,get agentActive(){return F(()=>!!Wt())()&&Ke(e)},onResize:()=>{ut()&&requestAnimationFrame(()=>hr(!0))},get onCancel(){return e.data?.source===`user`&&e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);D(ne()?`${n}\n\n${ne()}`:n),Qt(Xt(),Jt().filter(e=>e.promptId!==t)),Q(`message withdrawn — draft restored`)}).catch(()=>Q(`withdraw failed — it may have already been sent`))}:void 0},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`&&!(e.data?.pending&&e.data?.sent!==!0)&&!e.data?.cancelled&&!Ut()?()=>Kt({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),M(P,{get when(){return F(()=>!!Wt())()&&Ft()},get children(){var e=ql(),t=e.firstChild.nextSibling;return t.firstChild,z(t,M(P,{get when(){return Bt()},get children(){var e=Wl(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return z(t,M(Yp,{get startedAt(){return zt()}}),null),De(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{Bt(),t&&(e.scrollTop=e.scrollHeight)})},n),z(n,Bt),e}}),null),z(t,M(P,{get when(){return B()},get fallback(){return ju()},get children(){return M(P,{get when(){return wt()},get fallback(){return(()=>{var e=Kl();return y(()=>e.innerHTML=Fe(B()+`▍`)),e})()},get children(){return[Gl(),(()=>{var e=Kl();return y(()=>e.innerHTML=Fe(Tt()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),M(P,{get when(){return Mr()},get children(){var t=$l(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Kr(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Gr()))},n.$$pointerdown=ai,z(i,M(N,{get each(){return Fr()},children:(e,t)=>(()=>{var n=Mu(),r=n.firstChild.nextSibling;return n.$$click=()=>Zr(t()),z(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),ei(t())},y(r=>{var i=`termtab`+(Ur()===0&&Lr()===t()?` active`:``)+(Vr()&&Ur()===1&&zr()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),z(i,M(om,{icon:`+`,title:`new shell in this workspace`,onClick:Qr}),null),z(o,(()=>{var t=F(()=>!!Xr());return()=>t()?e().find(e=>e.id===Xr().agentId)?.workspace.split(`/`).filter(Boolean).pop():H()?.workspace})()),z(a,M(om,{icon:`◫`,get title(){return Vr()?`single pane`:`split panes (50/50)`},onClick:oi}),null),z(a,M(om,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:Pr}),null);var l=si(0);return typeof l==`function`&&De(l,c),c.$$pointerdown=()=>Wr(0),z(c,M(P,{get when(){return Lr()<0||Lr()>=Fr().length},get children(){return Yl()}})),z(s,M(P,{get when(){return Vr()},get children(){return[Xl(),(()=>{var e=Ql(),t=si(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>Wr(1),z(e,M(P,{get when(){return zr()<0||zr()>=Fr().length},get children(){return Zl()}})),y(()=>e.classList.toggle(`focused`,Ur()===1)),e})()]}}),null),y(e=>{var n={height:`${Gr()}px`},r=!!Vr(),i=Ur()===0;return e.e=Te(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=au(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling,o=t.nextSibling;return z(e,M(P,{get when(){return!ut()||ft()>0},get children(){var e=eu();return e.firstChild,e.$$click=()=>hr(!0),z(e,(()=>{var e=F(()=>ft()>0);return()=>e()?`${ft()} new message${ft()>1?`s`:``}`:`jump to present`})(),null),e}}),t),z(e,M(P,{get when(){return xi().length>0},get children(){var e=tu();return z(e,M(N,{get each(){return xi()},children:(e,t)=>(()=>{var n=Nu(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{D(e.insert),bi(-1)},z(r,()=>e.insert.trim()),z(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===yi()?` active`:``),a=e.title;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),z(e,M(P,{get when(){return hi().length>0},get children(){var e=tu();return z(e,M(N,{get each(){return hi()},children:e=>(()=>{var t=Pu(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{D(`@${e.key} `),bi(-1)},z(n,()=>e.key,null),z(r,()=>e.label),y(()=>L(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,ji),z(t,M(P,{get when(){return Di().length>0},get children(){var e=nu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,z(e,M(N,{get each(){return Di()},children:(e,t)=>(()=>{var n=Fu(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>Oi(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&L(n,`title`,t.e=i),a!==t.t&&L(r,`src`,t.t=a),o!==t.a&&L(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),z(t,()=>Di().length,n),z(t,()=>Di().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=xi();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),bi(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),bi(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&yi()>=0&&!zp?(e.preventDefault(),D(t[yi()].insert),bi(-1)):e.key===`Escape`&&t.length>0?bi(-1):e.key===`Enter`&&!e.shiftKey&&!zp&&!tt()&&(e.preventDefault(),ji(e))},n.$$input=e=>{D(e.currentTarget.value),bi(0),Ci()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),ki(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{zp=!1}),D(Si?.value??``)}),n.addEventListener(`compositionstart`,()=>{zp=!0}),De(e=>{Si=e,e.value=ne()},n),z(t,M(P,{get when(){return F(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=ru(),t=e.firstChild;return t.addEventListener(`change`,e=>pi(e.currentTarget.checked)),y(()=>t.checked=fi()),e}}),r),r.$$click=()=>{let e=!tt();rt(e),requestAnimationFrame(()=>Ci())},z(r,()=>tt()?`⤡`:`⤢`),z(t,M(om,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),z(t,M(P,{get when(){return Di().length},get children(){var e=iu();return e.firstChild,z(e,()=>Di().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&ki(e.currentTarget.files),e.currentTarget.value=``}),z(o,()=>Ip()||`enter send · shift+enter newline · ↑↓ sessions · / commands & focus · t terminal · d panel · esc interrupt · messages sent while the agent works queue up and land at the next turn boundary`),y(t=>{var i=`composer`+(tt()?` maximized`:``),a=`message #${H().id} — / for commands · paste or 📎 to attach images`,o=tt()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&R(e,t.e=i),a!==t.t&&L(n,`placeholder`,t.t=a),o!==t.a&&L(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()]}})),z(i,M(P,{get when(){return F(()=>!!ce())()&&j()},get children(){var e=ou();return e.$$click=()=>de(!1),e}}),C),C.addEventListener(`scroll`,e=>{Pi=e.currentTarget.scrollTop});var te=Ni;return typeof te==`function`?De(te,C):Ni=C,z(w,M(om,{icon:`✕`,title:`close details panel (esc)`,onClick:pe}),null),z(C,M(P,{get when(){return H()?.id},keyed:!0,fallback:null,children:i=>[Iu(),(()=>{var e=Lu(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return z(n,()=>H().id),z(r,()=>H().status),z(a,()=>H().workspace),z(o,()=>H().session,s),z(o,()=>H().branch,null),y(e=>{var t=`badge ${H().status}`,n=H().workspace;return t!==e.e&&R(r,e.e=t),n!==e.t&&L(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),M(P,{get when(){return H().id},keyed:!0,fallback:null,children:e=>M(vm,{agentId:e,get workspace(){return H().workspace}})}),Ru(),(()=>{var t=Vu(),r=t.firstChild,i=r.nextSibling,a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=i.nextSibling;return c.firstChild,r.addEventListener(`change`,t=>{let r=t.currentTarget.value;et=!0,je(r),Ne(Ot(O().providers,r,e().find(e=>e.id===n()))),Be(r)}),z(r,M(N,{get each(){return ze()},children:e=>(()=>{var t=Tu();return t.value=e,z(t,e,null),z(t,()=>e===O().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>Ne(e.currentTarget.value),z(o,M(N,{get each(){return Le()},children:e=>(()=>{var t=Tu();return y(()=>t.value=e.id),t})()})),s.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:Ae(),model:Me().trim()||void 0,contextWindowTokens:Le().find(e=>e.id===(Me().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,Fn()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},z(t,M(P,{get when(){return H().effortSupported},get children(){var e=zu(),t=e.firstChild.nextSibling;t.firstChild;var r=t.nextSibling;return t.addEventListener(`change`,e=>Ie(e.currentTarget.value)),z(t,M(N,{each:Mp,children:e=>(()=>{var t=Tu();return t.value=e,z(t,e),t})()}),null),r.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({reasoningEffort:Pe()})}),t.textContent=`✓ applied`,Fn()}catch(e){alert(`effort change failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},y(()=>t.value=Pe()),e}}),c),z(c,()=>H().model,null),z(c,M(P,{get when(){return Le().length},get children(){return[` · `,F(()=>Le().length),` models loaded`]}}),null),z(t,M(P,{get when(){return Ge()},get children(){var e=Bu();return z(e,Ge),e}}),null),y(()=>L(a,`placeholder`,kt(O().providers,Ae(),H(),Et(H(),O().providers,O().defaultProvider)))),y(()=>r.value=Ae()),y(()=>a.value=Me()),t})(),Hu(),(()=>{var i=Wu(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling;return we(a,`click`,Ut()?Fi(`/stop`):Fi(`/start`),!0),z(a,()=>Ut()?`■ stop`:`▶ start`),o.$$click=()=>$(`/api/agents/${H().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await d(!0),await vr(H().id)}),s.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await $(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let a=e().filter(e=>e.id!==i);t(a),d(!0),a[0]?vr(a[0].id):(r(null),p([]))},z(i,M(P,{get when(){return e().some(e=>e.parent===n())},get children(){var e=Uu();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),Fn())},e}}),null),y(e=>{var t=Ut()?`danger`:`runbtn`,n=Ut()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&R(a,e.e=t),n!==e.t&&L(a,`title`,e.t=n),e},{e:void 0,t:void 0}),i})(),(()=>{var e=Gu(),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(Fn)}),y(()=>t.checked=H().autoContinue??!0),e})(),(()=>{var e=qu();return e.firstChild,z(e,M(P,{get when(){return!!H().goal.text.trim()},get fallback(){return dd()},get children(){var e=Ku();return z(e,()=>H().goal.status),y(()=>R(e,`badge ${H().goal.status===`active`?`running`:H().goal.status}`)),e}}),null),e})(),(()=>{var e=Ju();return e.firstChild,z(e,M(N,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=fd();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(Fn)},L(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),z(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(H().goal.text.trim()&&H().goal.status===e?` on ${e}`:``),i=!!H().goal.text.trim()&&H().goal.status===e;return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),M(P,{get when(){return H().goal.text},get fallback(){return pd()},get children(){return[(()=>{var e=Yu(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(H().goal.text))),e})(),M(P,{get when(){return H().goal.verify},get children(){var e=Xu(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(H().goal.verify))),e}}),M(P,{get when(){return H().goal.audit},children:e=>(()=>{var t=md(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return z(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),z(r,()=>nm(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=$e(e().feedback)?Fe(`_the auditor returned a verdict with no detail_`):Fe(e().feedback);return r!==n.e&&R(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),Zu(),(()=>{var e=Qu(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,Wi),t.$$input=e=>{Li(e.currentTarget.value),Bi(!0)},n.$$input=e=>{q(e.currentTarget.value),Bi(!0)},r.addEventListener(`change`,e=>Hi(e.currentTarget.checked)),y(()=>t.value=Ii()),y(()=>n.value=Ri()),y(()=>r.checked=Vi()),e})(),(()=>{var e=ed(),t=e.firstChild.nextSibling;return z(e,M(P,{get when(){return Nn().total>0},get children(){var e=$u(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,z(e,()=>Nn().done,t),z(e,()=>Nn().total,n),y(t=>Te(e,Nn().done===Nn().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),M(P,{get when(){return Nn().total>0},get children(){var e=td(),t=e.firstChild;return y(e=>{var n=`barfill `+(Nn().done===Nn().total?``:`warn`),r=`${Math.round(Nn().done/Nn().total*100)}%`;return n!==e.e&&R(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),M(_m,{get draft(){return Tn()},get preview(){return Dn()},onDraft:e=>{En(e),An(!0)}}),(()=>{var e=nd(),t=e.firstChild,n=t.nextSibling;return z(e,M(om,{get icon(){return Dn()?`✎`:`👁`},get title(){return Dn()?`edit markdown`:`rendered checklist`},onClick:()=>On(!Dn())}),t),n.$$click=Mn,e})(),rd(),M(P,{get when(){return H().latestProgress},get fallback(){return hd()},children:e=>(()=>{var t=bd(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return z(t,M(P,{get when(){return e().recent},get children(){var t=gd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=jp(e().recent)),t}}),i),z(t,M(P,{get when(){return e().problems},get children(){var t=_d(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=jp(e().problems)),t}}),i),z(t,M(P,{get when(){return e().next},get children(){var t=vd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=jp(e().next)),t}}),i),z(t,M(P,{get when(){return e().goalStatus},get children(){var t=yd(),n=t.firstChild.nextSibling;return z(n,()=>e().goalStatus),t}}),i),z(i,()=>nm(e().ts)),y(()=>r.innerHTML=jp(e().doing)),t})()}),id(),(()=>{var e=sd(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=t.nextSibling,l=c.firstChild.nextSibling,u=l.firstChild,d=u.nextSibling;return d.nextSibling,z(i,()=>H().stats.turns),z(o,()=>H().stats.toolCalls),z(s,()=>H().stats.compactions??0),z(l,()=>rm(H().stats.inputTokens),u),z(l,()=>rm(H().stats.outputTokens),d),z(c,M(P,{get when(){return(H().stats.cachedInputTokens??0)>0},get children(){var e=ad(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>Math.round(H().stats.cachedInputTokens/Math.max(1,H().stats.inputTokens)*1e3)/10,t),y(()=>L(e,`title`,`${rm(H().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),z(e,M(P,{get when(){return(H().stats.costUsd??0)>0},get children(){var e=od(),t=e.firstChild.nextSibling;return t.firstChild,z(t,()=>im(H().stats.costUsd??0),null),y(()=>L(e,`title`,`≈ ${(H().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),z(e,M(P,{get when(){return H().ctx},keyed:!0,get fallback(){return xd()},children:e=>{let t=x(()=>{let t=e,n=Le().find(e=>e.id===H().model),r=t.window||n?.contextLength||0,i=r?Math.min(999,t.usedTokens/r*100):0;return{usedTokens:t.usedTokens,compactAt:t.compactAt,compacting:t.compacting,window:t.window,effectiveWindow:r,pct:i,cls:r?i>=85?`crit`:i>=70?`warn`:`ok`:``,derivedBudget:r?Math.round(r*.75):0,usingDerived:t.compactAtIsManual!==!0}}),r=()=>t(),i=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)};return(()=>{var e=Ed(),t=e.firstChild,a=t.firstChild.nextSibling,o=a.firstChild.nextSibling;o.nextSibling;var s=t.nextSibling,c=s.firstChild.nextSibling,l=c.firstChild,u=c.nextSibling,d=s.nextSibling,f=d.firstChild.firstChild,p=d.nextSibling,m=p.firstChild.nextSibling;return m.nextSibling,z(a,()=>rm(r().usedTokens),o),z(t,M(P,{get when(){return r().effectiveWindow},get children(){var e=Sd(),t=e.firstChild;return z(e,()=>i(r().pct),t),z(e,()=>rm(r().effectiveWindow),null),y(()=>R(e,`pill ${r().cls}`)),e}}),null),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=Cd(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),z(c,()=>rm(r().usingDerived?r().derivedBudget:r().compactAt),l),z(u,()=>r().usingDerived?` (75% of window)`:` (manual override)`),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=wd(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,Math.round(r().usedTokens/r().derivedBudget*100))}%`;return n!==e.e&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),d),z(e,M(P,{get when(){return _t()||r().compacting},get children(){var e=Td(),t=e.firstChild.nextSibling.nextSibling;return z(t,()=>_t()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(Fn)}),z(p,()=>rm(r().compactAt),m),y(()=>f.checked=H().autoCompact!==!1),e})()}}),null),e})(),(()=>{var e=ld();return e.firstChild.nextSibling,z(e,M(P,{get when(){return $n()},get children(){var e=cd(),t=e.firstChild.nextSibling;return z(t,$n),e}}),null),e})(),M(N,{get each(){return g()},children:e=>(()=>{var t=Dd(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=$n()===e.branch?null:e.branch,r=t!==$n();G(t),n()&&(r&&(sr++,p([]),h(0),or(!1)),fr(n()))},z(r,()=>e.branch,null),z(r,()=>e.branch===H().branch?` (current)`:``,null),z(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===H().branch||e.branch===$n()?` cur`:``),i=e.branch===$n()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),ud(),M(P,{get when(){return Ln().length>0},get fallback(){return Od()},get children(){return M(N,{get each(){return Ln()},children:e=>(()=>{var t=Ad(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>vr(e.agent),z(i,()=>e.id),z(a,()=>e.agent,null),z(r,M(P,{get when(){return e.forked},get children(){return kd()}}),null),z(o,()=>e.schedule,s),z(o,(()=>{var t=F(()=>!!e.next);return()=>t()?nm(e.next):`—`})(),null),z(o,(()=>{var t=F(()=>!!e.last);return()=>t()?` · last ${nm(e.last)}`:` · never ran`})(),null),z(c,()=>am(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${am(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&R(t,r.e=i),a!==r.t&&L(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var t=`layout`+(j()?``:` right-hidden`),n=`iconbtn notifbtn`+(on()>0?` has-unread`:``),r=on()>0?`${on()} unread notifications`:`notifications`,a=`conn`+(yr()?` ok`:``),o=yr()?`live (websocket)`:`reconnecting…`,s={"--termh":`${Gr()}px`},c=`rightbar`+(j()?` open`:``);return t!==e.e&&R(i,e.e=t),n!==e.t&&R(l,e.t=n),r!==e.a&&L(l,`title`,e.a=r),a!==e.o&&R(_,e.o=a),o!==e.i&&L(_,`title`,e.i=o),e.n=Te(S,s,e.n),c!==e.s&&R(C,e.s=c),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),i}}),M(P,{get when(){return rn()},get children(){return[(()=>{var e=cu();return e.$$click=()=>an(!1),e})(),(()=>{var t=du(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return z(r,M(P,{get when(){return $t().length>0},get children(){var e=lu();return e.$$click=()=>en([]),e}}),i),i.$$click=()=>an(!1),z(t,M(P,{get when(){return $t().length>0},get fallback(){return jd()},get children(){var t=uu();return z(t,M(N,{get each(){return $t()},children:t=>(()=>{var r=Nd(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{en(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&vr(t.agentId),an(!1),t.eventId&&setTimeout(()=>fn(t.eventId),n()===t.agentId?60:350)},z(i,(()=>{var e=F(()=>t.kind===`finish`);return()=>e()?`✅`:F(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),z(a,()=>t.title),z(o,()=>nm(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),en(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},z(s,()=>t.read?`✓`:`○`),z(r,M(P,{get when(){return t.body},get children(){var e=Md();return z(e,()=>tm(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&R(r,e.e=n),i!==e.t&&L(r,`title`,e.t=i),a!==e.a&&L(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),M(P,{get when(){return k()},get children(){return M(lm,{get providers(){return Object.keys(O().providers??{})},onClose:()=>ie(!1),onCreated:e=>{ie(!1),Fn(),vr(e)}})}}),M(P,{get when(){return ae()},get children(){return M(Cm,{get cfg(){return O()},onClose:()=>oe(!1),onSaved:()=>{Sn(),zn()}})}}),M(P,{get when(){return Gt()},fallback:null,children:e=>{let t=()=>f().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,f().length-t()-1),[i,a]=v(r()>0?`summarize`:`discard`);return M(cm,{title:`edit prompt — forks the conversation`,onClose:()=>Kt(null),get children(){var t=Fd(),o=t.firstChild,s=o.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:i()})}),Kt(null),Fn();let t=n();t&&await vr(t)}catch(e){alert(`edit failed: ${e.message}`)}}),z(t,M(P,{get when(){return r()>0},get children(){var e=Pd(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return z(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>Kt(null),y(()=>o.value=e().text),t}})}})]}function Jp(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());C(()=>{let e=setInterval(()=>r(Date.now()),500);w(()=>clearInterval(e))});let i=()=>Be(Math.max(0,n()-t));return e.inline?(()=>{var t=Id();return t.firstChild,z(t,i,null),z(t,(()=>{var t=F(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=Ld(),t=e.firstChild;return z(e,i,t),e})()}function Yp(e){let[t,n]=v(Date.now());return C(()=>{let e=setInterval(()=>n(Date.now()),500);w(()=>clearInterval(e))}),e.startedAt?(()=>{var n=Rd();return z(n,()=>Be(Math.max(0,t()-e.startedAt))),n})():null}function Xp(e){let t=e.e,n=()=>e.res,r=()=>!e.agentActive&&!n(),i=t.data??{},a=String(i.name??`tool`),o=()=>String(n()?.data?.result??``),s=e=>String(i.args?.[e]??``),c=()=>a===`bash`?s(`command`):s(`path`)||JSON.stringify(i.args??{},null,1),l=()=>a===`bash`?Number(s(`timeout_ms`))||void 0:a===`wait_children`?Number(s(`timeout_ms`))||3e5:Number(s(`timeout_ms`))||void 0,u=(e,t=1500)=>(()=>{var n=zd();return z(n,()=>tm(e,t)),n})(),d=(e=4e3)=>(()=>{let t=n();return t?[F(()=>u(o(),e)),(()=>{var e=Bd();return z(e,()=>Be(t.data?.durationMs),null),z(e,()=>a===`bash`?wt(Ct(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),z(e,M(sm,{get text(){return o()}}),null),e})()]:Vd()})(),f=x(()=>{let e=a,t=``,r=(()=>{var e=Hd();return z(e,()=>tm(JSON.stringify(i.args??{},null,1),2e3)),e})();try{switch(a){case`bash`:{let a=s(`command`),c=i.args?.background===!0,l=c?String(o()).match(/job (bg\d+)/)?.[1]??``:``;e=(c?`⏳ `:`$ `)+am(a,96);let f=s(`timeout_ms`)?Number(s(`timeout_ms`)):void 0,p=n(),m=Ct(p?.data?.ok,p?String(p.data?.result??``):``);t=p?c?`background job${l?` ${l}`:``}${f?` · timeout ${Math.round(f/1e3)}s`:``}`:Tt({outcome:m,durationMs:p.data?.durationMs,timeoutMs:f,fmtDur:Be}):null,r=[c?(()=>{var e=Ud(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,z(t,l||`?`,n),z(e,l?[` · kill with `,Wd()]:null,null),e})():null,F(()=>F(()=>a!==e.slice(2))()?u(a,800):null),F(()=>d(6e3))];break}case`read_file`:{e=s(`path`)||`(no path)`;let n=[];s(`pattern`)&&n.push(`grep /${am(s(`pattern`),40)}/`),Number(i.args?.offset)<0?n.push(`last ${-Number(i.args.offset)} lines`):i.args?.offset&&n.push(`from L${i.args.offset}`),i.args?.limit&&n.push(`≤${i.args.limit} lines`),t=n.join(` · `),r=d(6e3);break}case`write_file`:{let a=String(i.args?.content??``);e=s(`path`)||`(no path)`,t=`${rm(a.length)} bytes`,r=[F(()=>u(a,1500)),F(()=>F(()=>a.length>1500)()?(()=>{var e=Gd(),t=e.firstChild;return z(e,()=>rm(a.length),t),e})():null),F(()=>F(()=>!!n())()?(()=>{var e=Bd();return z(e,()=>am(o(),160)),e})():Kd())];break}case`edit_file`:e=s(`path`)||`(no path)`,t=i.args?.replace_all===!0?`replace all`:`unique spot`,r=[(()=>{var e=qd();return z(e,()=>tm(`- `+s(`old_text`),900)),e})(),(()=>{var e=Jd();return z(e,()=>`+ `+tm(s(`new_text`),900)),e})(),F(()=>F(()=>!!n())()?(()=>{var e=Yd(),t=e.firstChild;return z(e,()=>am(o(),120),t),z(e,()=>Be(n().data?.durationMs),null),e})():Xd())];break;case`apply_patch`:{let t=s(`patch`).split(`
|
|
26
|
+
`).filter(e=>e&&!/^---$/.test(e.trim())),i=t.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);e=i.length?`${i.length} file${i.length>1?`s`:``}: ${am(i.join(`, `),80)}`:`patch`;let a=t.slice(0,60);r=[(()=>{var e=Zd();return z(e,()=>a.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Qd();return R(n,`pline`+t),z(n,(()=>{var t=F(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),z(e,(()=>{var e=F(()=>t.length>60);return()=>e()?(()=>{var e=$d(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>t.length-60,n),e})():null})(),null),e})(),F(()=>F(()=>!!n())()?(()=>{var e=Bd();return z(e,()=>am(o().split(`
|
|
27
|
+
`)[0]??``,140),null),z(e,()=>n().data?.ok===!1?` · FAILED`:``,null),e})():ef())];break}case`list_dir`:e=s(`path`)||`.`,r=d(4e3);break;case`read_url`:{let n=s(`url`);try{let e=new URL(n);n=e.host+e.pathname}catch{}e=am(n,70),t=`web`,r=[(()=>{var e=Bd();return z(e,M(P,{get when(){return/^https?:/i.test(s(`url`))},get fallback(){return(()=>{var e=nf();return z(e,()=>am(s(`url`),80)),e})()},get children(){var e=tf();return y(()=>L(e,`href`,s(`url`))),e}})),e})(),F(()=>d(3e3))];break}case`bash_output`:{let n=s(`action`)||`read`;e=`bash_output ${s(`job_id`)||`(?)`}`,t=n,r=d(4e3);break}case`load_skill`:{e=`skill: ${s(`name`)}`;let t=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);r=n()?[(()=>{var e=Kl();return y(()=>e.innerHTML=Fe(t)),e})(),(()=>{var e=Bd();return z(e,()=>Be(n().data?.durationMs)),e})()]:rf();break}case`save_skill`:{e=`skill: ${s(`name`)}`,t=am(s(`description`),60);let a=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];r=[F(()=>F(()=>!!a.length)()?(()=>{var e=af();return e.firstChild,z(e,()=>a.join(`, `),null),e})():null),F(()=>F(()=>!!n())()?(()=>{var e=Yd(),t=e.firstChild;return z(e,()=>am(o(),160),t),z(e,()=>Be(n().data?.durationMs),null),e})():of())];break}}}catch{}return{icon:`⚙`,label:e,hint:t,body:r}});return(()=>{var i=cf(),s=i.firstChild,u=s.firstChild,d=u.firstChild,p=u.nextSibling,m=p.nextSibling;return i.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),z(u,()=>f().icon,d),z(u,()=>f().label,null),z(s,M(P,{get when(){return t.data?.actor},get children(){var e=sf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),p),z(p,(()=>{var e=F(()=>!!n());return()=>e()?f().hint||``:F(()=>!!r())()?`(result missed)`:F(()=>!!(a===`bash`||l()))()?M(Jp,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return l()}}):`running…`})()),z(m,M(sm,{get text(){return c()},label:`⧉ cmd`,title:`copy the ${a} arguments`}),null),z(m,M(P,{get when(){return n()},get children(){return M(sm,{get text(){return o()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(i,()=>f().body,null),y(e=>{var t=`embed`+(n()?n().data?.ok===!1?` fail`:` done`:r()?` done`:` running`),o=`${a}${f().hint?` — `+f().hint:``}`;return t!==e.e&&R(i,e.e=t),o!==e.t&&L(i,`title`,e.t=o),e},{e:void 0,t:void 0}),i})()}function Zp(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function Qp(e){let t=e.e,n=Vp(t),r=pt(e.prev,t);if(t.type===`fork`){let e=t.data??{};return(()=>{var n=lf(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=tt(t.data??{});return(()=>{var t=uf(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=Qd();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=df(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=ff(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=pf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=mf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Qd();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=hf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=gf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var i=bf(),a=i.firstChild,o=a.nextSibling;return R(a,`avatar avghost`+(r?` ghosted`:``)),z(a,()=>r?``:n.icon),z(o,r&&(()=>{var e=xf();return y(()=>L(e,`title`,`${Wp(t.ts)} · ${t.branch}`)),e})(),null),z(o,M(P,{when:!r,get children(){var r=yf(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=sf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:Wp(t.ts)})()),z(o,()=>t.branch),z(r,M(P,{get when(){return e.onCancel},get children(){var t=_f();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(sm,{get text(){return Zp(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=vf();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(o,M(em,{e:t,get res(){return e.res},get orphan(){return e.orphan},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get onAnswered(){return e.onAnswered},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var o=`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),s=t.id,c=r?`transparent`:n.color+`33`,l=r?`1px solid transparent`:`1px solid ${n.color}66`,u=r?`${Wp(t.ts)} · ${t.branch}`:void 0;return o!==e.e&&R(i,e.e=o),s!==e.t&&L(i,`data-eid`,e.t=s),c!==e.a&&Ee(a,`background`,e.a=c),l!==e.o&&Ee(a,`border`,e.o=l),u!==e.i&&L(a,`title`,e.i=u),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),i})()}function $p(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=Sf(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&L(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function em(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Kl();return y(()=>e.innerHTML=jp(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=Cf();return z(t,M(N,{each:e,children:e=>(()=>{var t=wf();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Tf(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${rm(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>tm(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Kl();return y(()=>e.innerHTML=jp(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return Ef()}}),M(P,{get when(){return t.data.final},get children(){var e=Df(),n=e.firstChild;return z(e,M(sm,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(Xp,{e:t,get res(){return e.res},get orphan(){return e.orphan},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=kf(),o=a.firstChild,s=o.firstChild.nextSibling,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(sm,{text:n}),null),z(c,()=>tm(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?wt(Ct(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return Of()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=jf(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=Af();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=jp(String(t.data?.decision??``)),r=jp(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=()=>e.answeredIds?.().has(r)??!1;return(()=>{var a=Pf(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return Mf()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=Nf();return z(a,M(N,{each:n,children:n=>(()=>{var a=Ff();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M($p,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=jp(String(t.data?.question??``));return n!==e.e&&R(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=If(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=yd(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=gd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=jp(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=_d(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=jp(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=vd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=jp(String(t.data.next))),e}}),null),y(()=>n.innerHTML=jp(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=Lf(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=zf(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>rm(Number(t.data.tokensBefore??0)),i),z(n,()=>rm(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[Rf(),(()=>{var e=Kl();return y(()=>e.innerHTML=jp(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Bf();return z(e,()=>tm(JSON.stringify(t.data),200)),e})()}}function tm(e,t){return e.length>t?e.slice(0,t)+` …`:e}function nm(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 rm(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 im(e){return e>=100?Math.round(e).toLocaleString():e>=10?e.toFixed(1):e>=1?e.toFixed(2):e>=.01?e.toFixed(3):e.toFixed(4)}function am(e,t){return tm(e.replace(/\s+/g,` `).trim(),t)}function om(e){return(()=>{var t=Vf(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function sm(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),ut(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=Hf();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function cm(e){return(()=>{var t=Uf(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function lm(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}C(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return M(cm,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Gf(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,C=S.firstChild.nextSibling,w=S.nextSibling,ee=w.firstChild.nextSibling,te=w.nextSibling.firstChild.nextSibling,T=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=Kf();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),C.$$input=e=>o(e.currentTarget.value),ee.addEventListener(`change`,e=>c(e.currentTarget.value)),z(ee,M(N,{get each(){return e.providers},children:e=>(()=>{var t=Tu();return z(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=Wf();return z(e,d),e}}),T),y(()=>h.value=t()),y(()=>C.value=a()),y(()=>ee.value=s()),y(()=>te.value=l()),i}})}var um=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),dm=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),fm=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function pm(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=mm(e);return n===`image`?`🖼`:n===`video`?`🎬`:n===`audio`?`🎵`:[`ts`,`tsx`,`mts`,`cts`].includes(t)?`🟦`:[`js`,`mjs`,`cjs`,`jsx`].includes(t)?`🟨`:t===`json`||t===`jsonc`?`🧾`:t===`md`||t===`mdx`||t===`markdown`?`📝`:t===`css`||t===`scss`||t===`less`?`🎨`:t===`html`||t===`htm`||t===`svg`?`🌐`:[`py`,`pyi`].includes(t)?`🐍`:t===`rs`?`🦀`:t===`go`?`🐹`:t===`java`||t===`kt`||t===`kts`?`☕`:t===`rb`?`💎`:t===`php`?`🐘`:t===`c`||t===`h`||t===`cpp`||t===`hpp`||t===`cc`?`🧩`:t===`sh`||t===`bash`||t===`zsh`||t===`fish`?`🐚`:t===`sql`?`🗄`:t===`yml`||t===`yaml`||t===`toml`||t===`ini`||t===`conf`?`⚙`:t===`lock`?`🔒`:e===`Dockerfile`||t===`dockerfile`?`🐳`:t===`zip`||t===`gz`||t===`tar`||t===`tgz`||t===`bz2`?`📦`:t===`pdf`?`📕`:t===`txt`||t===`log`?`📄`:`·`}function mm(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return um.has(t)?`image`:dm.has(t)?`video`:fm.has(t)?`audio`:null}var hm=new Map,gm=e=>{let t=hm.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},hm.set(e,t)),t};function _m(e){return M(P,{get when(){return e.preview},get fallback(){return(()=>{var t=Jf();return t.$$input=t=>e.onDraft(t.currentTarget.value),y(()=>t.value=e.draft),t})()},get children(){var t=qf();return y(()=>t.innerHTML=jp(e.draft)),t}})}function vm(e){let t=gm(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),C=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},ee=e=>x()!==`hide`||!e.ignored,[te,T]=v(localStorage.getItem(`teapot.showHidden`)===`1`),ne=()=>{let e=!te(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await O(t,e)}))).then(t=>{T(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&re(e,n)})},E=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function D(e){return O(e,te())}async function O(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return E(t,i.entries??[])}catch(e){return _(e.message),null}}let re=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),k=``;b(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),D(``).then(e=>{e&&k===t&&r(new Map([[``,e]]))}))});let ie=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await D(e.path);t&&re(e.path,t)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[j,ue]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await Ml(async()=>{let{highlightChunks:e}=await import(`./shiki-C_RJDjY3.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};w(()=>{fe++});let me=async(t,n)=>{let r=mm(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(t&&!j()){ue(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
28
28
|
OK = load the disk version into the editor (your edits are discarded)
|
|
29
|
-
Cancel = keep editing your copy`)?(le(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{ue(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=Xf(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:dm(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Yf();return z(t,()=>tm(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(ee)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await O(e,te())})));for(let{p:e,rows:n}of t)n&&re(e,n)}finally{be(!1)}}};return[(()=>{var e=Zf(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(im,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(im,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:C}),null),z(e,M(im,{class:`filetoggle`,get icon(){return te()?`◉.`:`○.`},get title(){return te()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:ne}),null),e})(),(()=>{var e=Qf();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=$f();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(ee)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(om,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=ip(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=np();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=rp();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return op()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(_m,{get path(){return t().path},get content(){return t().content},get html(){return ae()},get pending(){return se()},get truncated(){return!!t().truncated}})},get children(){var e=sp();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=ap(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>tm(A().length),i),a.$$click=()=>void he(),z(a,()=>j()?`saving…`:`💾 save`),y(()=>a.disabled=j()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=tp(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=lp();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=cp();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=ep();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function _m(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=fp(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=pp();return z(t,()=>e.content),t})()},get children(){var t=up();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return dp()}})]}var vm=[{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)`}],ym={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 bm(e){let[t,n]=v(vm[0]),[r,i]=v(vm[0].url),[a,o]=v(``),[s,c]=v(vm[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);w(()=>clearTimeout(n))});let C=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${tm(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},ee=()=>C(s()),te=async t=>{t.preventDefault(),x(``),g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}};return(()=>{var e=_p(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,C=x.firstChild.nextSibling,w=x.nextSibling,T=w.firstChild.nextSibling,ne=T.nextSibling,E=w.nextSibling,D=E.firstChild.nextSibling,O=D.firstChild.nextSibling,re=D.nextSibling.firstChild.nextSibling,k=E.nextSibling;return n.addEventListener(`submit`,te),z(u,()=>[...vm,ym].map(e=>(()=>{var n=vp();return n.$$click=()=>S(e),z(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),z(n,M(P,{get when(){return t().hint},get children(){var e=mp();return z(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),z(b,()=>vm.map(e=>(()=>{var t=Tu();return y(()=>t.value=e.url),t})())),C.$$input=e=>o(e.currentTarget.value),T.$$input=e=>c(e.currentTarget.value),z(ne,()=>l().map(e=>(()=>{var t=Tu();return y(()=>t.value=e.id),t})())),z(n,M(P,{get when(){return l().length>0},get fallback(){return yp()},get children(){var e=gp(),t=e.firstChild;return z(e,()=>l().length,t),z(e,M(P,{get when(){return ee()},get children(){return[` · `,(()=>{var e=hp();return z(e,ee),e})()]}}),null),e}}),E),O.$$input=e=>f(e.currentTarget.value),re.$$input=e=>m(e.currentTarget.value),z(n,M(P,{get when(){return _()},get children(){var e=Wf();return z(e,_),e}}),k),z(k,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(type to filter models from the endpoint)`,r=h();return n!==e.e&&L(T,`placeholder`,e.e=n),r!==e.t&&(k.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>C.value=a()),y(()=>T.value=s()),y(()=>O.value=d()),y(()=>re.value=p()),e})()}function xm(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),a=()=>e.cfg.defaultProvider??``,o=()=>{let e=[...new Set(t().map(e=>e.name.trim()).filter(Boolean))],n=r();return n&&!e.includes(n)&&e.push(n),e},s=()=>{let e=r();return e?t().some(t=>t.name.trim()===e)?``:e:``},[c,l]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[u,d]=v(e.cfg.progressMinChars??4e3),[f,p]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[m,h]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[g,_]=v(e.cfg.maxSpawnDepth??3),[b,x]=v((e.cfg.tasks??[]).map(e=>({...e}))),[S,C]=v(``),w=()=>(e.cfg.agents??[]).map(e=>e.id),ee=()=>{let e={};for(let n of t()){if(!n.name.trim())return C(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return C(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},te=async t=>{t.preventDefault(),C(``);let n=ee();if(!n)return;let i=b().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of i){if(!e.agent){C(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){C(`task "${e.id}": schedule is required`);return}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,c())*6e4,progressMinChars:Math.max(100,u()),...f()==null?{}:{contextTokenBudget:Math.max(1,f())*1e3},...m()>0?{contextWindowTokens:m()*1e3}:{},maxSpawnDepth:Math.max(0,g()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){C(e.message)}},T=(e,t,n,r)=>(()=>{var i=bp(),a=i.firstChild;return L(i,`title`,r),z(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return M(om,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Sp(),ee=v.firstChild,ne=ee.firstChild.nextSibling,E=ne.nextSibling;E.firstChild;var D=E.nextSibling.firstChild.firstChild.nextSibling;D.firstChild;var O=ee.nextSibling,re=O.firstChild.nextSibling,k=re.firstChild,ie=k.firstChild.nextSibling,ae=O.nextSibling,oe=ae.firstChild.nextSibling,se=ae.nextSibling;se.firstChild;var ce=se.nextSibling,A=ce.firstChild.nextSibling.firstChild;A.firstChild;var le=A.nextSibling,j=ce.nextSibling;return v.addEventListener(`submit`,te),z(ee,M(ye,{get each(){return t()},children:(e,r)=>(()=>{var i=Cp(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().apiKey),y(()=>c.value=e().model),i})()}),ne),ne.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),z(E,M(N,{each:vm,children:e=>(()=>{var a=wp();return a.firstChild,a.$$click=()=>{let a=t().filter(t=>t.name!==e.key);n([...a,{name:e.key,baseUrl:e.url,apiKey:``,model:e.model}]),r()||i(e.key)},z(a,()=>e.label,null),y(()=>L(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),D.addEventListener(`change`,e=>i(e.currentTarget.value)),z(D,M(N,{get each(){return o()},children:e=>(()=>{var t=Tu();return t.value=e,z(t,e),t})()}),null),z(ee,M(P,{get when(){return s()},get children(){var e=xp(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,s),z(e,()=>s()===a()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,s),e}}),null),z(re,()=>T(`progress interval (min)`,c(),e=>l(e),`how often the harness asks for a progress report`),k),z(re,()=>T(`progress min chars`,u(),e=>d(e),`progress prompts wait for this much real output`),k),ie.$$input=e=>p(e.currentTarget.value===``?null:Number(e.currentTarget.value)),z(re,()=>T(`context window (k tok)`,m(),e=>h(e),`model's real window — 0/blank hides the % gauge`),null),z(re,()=>T(`max spawn depth`,g(),e=>_(e),`sub-agent nesting limit (0 = no spawning)`),null),z(ae,M(P,{get when(){return b().length>0},get children(){return M(ye,{get each(){return b()},children:(e,t)=>(()=>{var n=Tp(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>x(b().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>x(b().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>x(b().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>x(b().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>x(b().filter((e,n)=>n!==t)),u.$$input=e=>x(b().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e().id),y(()=>a.value=e().agent),y(()=>o.value=e().schedule),y(()=>c.checked=!!e().forked),y(()=>u.value=e().prompt),n})()})}}),oe),oe.$$click=()=>x([...b(),{id:``,agent:w()[0]??``,schedule:`every 30m`,prompt:``}]),z(se,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Dp(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=Ep();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(A,()=>e.cfg.version??`unknown`,null),le.$$click=async e=>{try{C(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await $(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=!1;for(let e=0;e<90&&!r;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await $(`/api/version`);e.version&&e.version!==`0.29.3`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){C(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},z(v,M(P,{get when(){return S()},get children(){var e=Wf();return z(e,S),e}}),j),y(()=>D.value=r()),y(()=>ie.value=f()??``),v}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(Gp,{}),document.getElementById(`root`));export{Ml as t};
|
|
30
|
-
//# sourceMappingURL=index-
|
|
29
|
+
Cancel = keep editing your copy`)?(le(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{ue(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=Xf(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:pm(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Yf();return z(t,()=>rm(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(ee)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await O(e,te())})));for(let{p:e,rows:n}of t)n&&re(e,n)}finally{be(!1)}}};return[(()=>{var e=Zf(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(om,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(om,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:C}),null),z(e,M(om,{class:`filetoggle`,get icon(){return te()?`◉.`:`○.`},get title(){return te()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:ne}),null),e})(),(()=>{var e=Qf();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=$f();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(ee)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(cm,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=ip(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=np();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=rp();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return op()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(ym,{get path(){return t().path},get content(){return t().content},get html(){return ae()},get pending(){return se()},get truncated(){return!!t().truncated}})},get children(){var e=sp();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=ap(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>rm(A().length),i),a.$$click=()=>void he(),z(a,()=>j()?`saving…`:`💾 save`),y(()=>a.disabled=j()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=tp(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=lp();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=cp();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=ep();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function ym(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=fp(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=pp();return z(t,()=>e.content),t})()},get children(){var t=up();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return dp()}})]}var bm=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:``,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:``,hint:`zero-markup routing gateway — 'orcarouter/auto' grades each prompt and picks the model`},{key:`openai`,label:`OpenAI`,url:`https://api.openai.com/v1`,model:``,hint:`your account's models — pick from the list once the endpoint answers`},{key:`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)`}],xm={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 Sm(e){let[t,n]=v(bm[0]),[r,i]=v(bm[0].url),[a,o]=v(``),[s,c]=v(bm[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);w(()=>clearTimeout(n))});let C=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${rm(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},ee=()=>C(s()),te=()=>{let e=s().trim().toLowerCase();return e?l().filter(t=>t.id.toLowerCase().includes(e)):l()},T=async t=>{if(t.preventDefault(),x(``),!s().trim())x(l().length?`pick a model — choose one from the list, or type its id`:`pick a model — type its id (the endpoint has not listed any yet)`);else{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=vp(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,w=x.firstChild.nextSibling,ne=x.nextSibling,E=ne.firstChild.nextSibling,D=E.nextSibling,O=ne.nextSibling,re=O.firstChild.nextSibling,k=re.firstChild.nextSibling,ie=re.nextSibling.firstChild.nextSibling,ae=O.nextSibling;return n.addEventListener(`submit`,T),z(u,()=>[...bm,xm].map(e=>(()=>{var n=yp();return n.$$click=()=>S(e),z(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),z(n,M(P,{get when(){return t().hint},get children(){var e=mp();return z(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),z(b,()=>bm.map(e=>(()=>{var t=Tu();return y(()=>t.value=e.url),t})())),w.$$input=e=>o(e.currentTarget.value),E.$$input=e=>c(e.currentTarget.value),z(D,()=>l().map(e=>(()=>{var t=Tu();return y(()=>t.value=e.id),t})())),z(n,M(P,{get when(){return te().length>0},get fallback(){return(()=>{var e=bp();return z(e,()=>l().length?`no model matches that — clear the field to see them all`:`models appear here automatically once the endpoint answers GET /models`),e})()},get children(){return[(()=>{var e=hp();return z(e,()=>te().slice(0,40).map(e=>(()=>{var t=xp(),n=t.firstChild;return t.$$click=()=>c(e.id),z(n,()=>e.id),z(t,M(P,{get when(){return C(e.id)},get children(){var t=nf();return z(t,()=>C(e.id)),t}}),null),y(n=>{var r=`wizmodel`+(s()===e.id?` active`:``),i=C(e.id)||e.id;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})())),e})(),(()=>{var e=_p(),t=e.firstChild;return z(e,()=>te().length,t),z(e,()=>te().length>1?`s`:``,null),z(e,M(P,{get when(){return te().length>40},children:` (showing the first 40 — keep typing to narrow)`}),null),z(e,M(P,{get when(){return ee()},get children(){return[` · selected: `,(()=>{var e=gp();return z(e,ee),e})()]}}),null),e})()]}}),O),k.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),z(n,M(P,{get when(){return _()},get children(){var e=Wf();return z(e,_),e}}),ae),z(ae,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(pick from the list below, or type an id)`,r=h();return n!==e.e&&L(E,`placeholder`,e.e=n),r!==e.t&&(ae.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>w.value=a()),y(()=>E.value=s()),y(()=>k.value=d()),y(()=>ie.value=p()),e})()}function Cm(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),a=()=>e.cfg.defaultProvider??``,o=()=>{let e=[...new Set(t().map(e=>e.name.trim()).filter(Boolean))],n=r();return n&&!e.includes(n)&&e.push(n),e},s=()=>{let e=r();return e?t().some(t=>t.name.trim()===e)?``:e:``},[c,l]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[u,d]=v(e.cfg.progressMinChars??4e3),[f,p]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[m,h]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[g,_]=v(e.cfg.maxSpawnDepth??3),[b,x]=v((e.cfg.tasks??[]).map(e=>({...e}))),[S,C]=v(``),w=()=>(e.cfg.agents??[]).map(e=>e.id),ee=()=>{let e={};for(let n of t()){if(!n.name.trim())return C(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return C(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},te=async t=>{t.preventDefault(),C(``);let n=ee();if(!n)return;let i=b().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of i){if(!e.agent){C(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){C(`task "${e.id}": schedule is required`);return}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,c())*6e4,progressMinChars:Math.max(100,u()),...f()==null?{}:{contextTokenBudget:Math.max(1,f())*1e3},...m()>0?{contextWindowTokens:m()*1e3}:{},maxSpawnDepth:Math.max(0,g()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){C(e.message)}},T=(e,t,n,r)=>(()=>{var i=Sp(),a=i.firstChild;return L(i,`title`,r),z(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return M(cm,{title:`settings`,get onClose(){return e.onClose},get children(){var v=wp(),ee=v.firstChild,ne=ee.firstChild.nextSibling,E=ne.nextSibling;E.firstChild;var D=E.nextSibling.firstChild.firstChild.nextSibling;D.firstChild;var O=ee.nextSibling,re=O.firstChild.nextSibling,k=re.firstChild,ie=k.firstChild.nextSibling,ae=O.nextSibling,oe=ae.firstChild.nextSibling,se=ae.nextSibling;se.firstChild;var ce=se.nextSibling,A=ce.firstChild.nextSibling.firstChild;A.firstChild;var le=A.nextSibling,j=ce.nextSibling;return v.addEventListener(`submit`,te),z(ee,M(ye,{get each(){return t()},children:(e,r)=>(()=>{var i=Tp(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().apiKey),y(()=>c.value=e().model),i})()}),ne),ne.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),z(E,M(N,{each:bm,children:e=>(()=>{var a=Ep();return a.firstChild,a.$$click=()=>{let a=t().filter(t=>t.name!==e.key);n([...a,{name:e.key,baseUrl:e.url,apiKey:``,model:e.model}]),r()||i(e.key)},z(a,()=>e.label,null),y(()=>L(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),D.addEventListener(`change`,e=>i(e.currentTarget.value)),z(D,M(N,{get each(){return o()},children:e=>(()=>{var t=Tu();return t.value=e,z(t,e),t})()}),null),z(ee,M(P,{get when(){return s()},get children(){var e=Cp(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,s),z(e,()=>s()===a()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,s),e}}),null),z(re,()=>T(`progress interval (min)`,c(),e=>l(e),`how often the harness asks for a progress report`),k),z(re,()=>T(`progress min chars`,u(),e=>d(e),`progress prompts wait for this much real output`),k),ie.$$input=e=>p(e.currentTarget.value===``?null:Number(e.currentTarget.value)),z(re,()=>T(`context window (k tok)`,m(),e=>h(e),`model's real window — 0/blank hides the % gauge`),null),z(re,()=>T(`max spawn depth`,g(),e=>_(e),`sub-agent nesting limit (0 = no spawning)`),null),z(ae,M(P,{get when(){return b().length>0},get children(){return M(ye,{get each(){return b()},children:(e,t)=>(()=>{var n=Dp(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>x(b().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>x(b().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>x(b().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>x(b().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>x(b().filter((e,n)=>n!==t)),u.$$input=e=>x(b().map((n,r)=>r===t?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e().id),y(()=>a.value=e().agent),y(()=>o.value=e().schedule),y(()=>c.checked=!!e().forked),y(()=>u.value=e().prompt),n})()})}}),oe),oe.$$click=()=>x([...b(),{id:``,agent:w()[0]??``,schedule:`every 30m`,prompt:``}]),z(se,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=kp(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=Op();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(A,()=>e.cfg.version??`unknown`,null),le.$$click=async e=>{try{C(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await $(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=!1;for(let e=0;e<90&&!r;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await $(`/api/version`);e.version&&e.version!==`0.29.5`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){C(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},z(v,M(P,{get when(){return S()},get children(){var e=Wf();return z(e,S),e}}),j),y(()=>D.value=r()),y(()=>ie.value=f()??``),v}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(qp,{}),document.getElementById(`root`));export{Ml as t};
|
|
30
|
+
//# sourceMappingURL=index-DIjwa8pX.js.map
|