teapot-coding-agent 0.15.9 → 0.16.0

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.
@@ -18,11 +18,11 @@ 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(U(i,`selectionchange`,()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(z(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<pc+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
19
19
  `&&(this._liveRegionLineCount++,this._liveRegionLineCount===pc+1&&(this._liveRegion.textContent+=qe.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})`}};mc=L([R(1,bt),R(2,kt),R(3,jt)],mc);var hc=class extends B{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 H),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new H),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(z(()=>{en(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(U(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(U(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(U(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(U(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){if(this._activeLine!==e.y||this._wasResized){this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1;return}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&&gc(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,en(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}}};hc=L([R(1,At),R(2,jt),R(3,gt),R(4,Ft)],hc);function gc(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 _c=class extends rc{constructor(e={}){super(e),this._linkifier=this._register(new an),this.browser=Ma,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new an),this._onCursorMove=this._register(new H),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new H),this.onKey=this._onKey.event,this._onRender=this._register(new H),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new H),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new H),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new H),this.onBell=this._onBell.event,this._onFocus=this._register(new H),this._onBlur=this._register(new H),this._onA11yCharEmitter=this._register(new H),this._onA11yTabEmitter=this._register(new H),this._onWillOpen=this._register(new H),this._setup(),this._decorationService=this._instantiationService.createInstance(lc),this._instantiationService.setService(Tt,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(Da),this._instantiationService.setService(Ft,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Et)),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(dn.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(dn.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(dn.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(dn.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(z(()=>{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=K.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${W.ESC}]${n};${Vs(r)}${Wi.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=Xi.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=Xi.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(mc,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(W.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(W.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(U(this.element,`copy`,e=>{this.hasSelection()&&Xe(e,this._selectionService)}));let e=e=>Ze(e,this.textarea,this.coreService,this.optionsService);this._register(U(this.textarea,`paste`,e)),this._register(U(this.element,`paste`,e)),Ia?this._register(U(this.element,`mousedown`,e=>{e.button===2&&et(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(U(this.element,`contextmenu`,e=>{et(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),Wa&&this._register(U(this.element,`auxclick`,e=>{e.button===1&&$e(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(U(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(U(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(U(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(U(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(U(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(U(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(U(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(U(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`,Ge.get()),Ga||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(Ta,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(kt,this._coreBrowserService),this._register(U(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(U(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(xa,this._document,this._helperContainer),this._instantiationService.setService(Ot,this._charSizeService),this._themeService=this._instantiationService.createInstance(Ao),this._instantiationService.setService(Pt,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(na),this._instantiationService.setService(Nt,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Za,this.rows,this.screenElement)),this._instantiationService.setService(jt,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(Gi,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(Aa),this._instantiationService.setService(At,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(hc,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(Ii,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(bo,this.element,this.screenElement,r)),this._instantiationService.setService(Mt,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(dn.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(Li,this.screenElement)),this._register(U(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(mc,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Hi,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Hi,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(ba,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(U(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(U(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=W.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){Qe(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=ac(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===W.ETX||n.key===W.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)&&(vc(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){if(e===this.cols&&t===this.rows){this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure();return}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(X));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(W.ESC+`[I`):this.coreService.triggerDataEvent(W.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(`${W.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(`${W.ESC}[6;${r};${n}t`);break}}cancel(e,t){if(!(!this.options.cancelEvents&&!t))return e.preventDefault(),e.stopPropagation(),!1}};function vc(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var yc=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)}},bc=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 lt)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},xc=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 bc(t)}getNullCell(){return new lt}},Sc=class extends B{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new H),this.onBufferChange=this._onBufferChange.event,this._normal=new xc(this._core.buffers.normal,`normal`),this._alternate=new xc(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)}},Cc=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)}},wc=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}},Tc=[`cols`,`rows`],Ec=0,Dc=class extends B{constructor(e){super(),this._core=this._register(new _c(e)),this._addonManager=this._register(new yc),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(Tc.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 Cc(this._core),this._parser}get unicode(){return this._checkProposedApi(),new wc(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 Sc(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 Ge.get()},set promptLabel(e){Ge.set(e)},get tooMuchOutput(){return qe.get()},set tooMuchOutput(e){qe.set(e)}}}_verifyIntegers(...e){for(Ec of e)if(Ec===1/0||isNaN(Ec)||Ec%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(Ec of e)if(Ec&&(Ec===1/0||isNaN(Ec)||Ec%1!=0||Ec<0))throw Error(`This API only accepts positive integers`)}},Oc=2,kc=1,Ac=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(Oc,Math.floor(u/e.css.cell.width)),rows:Math.max(kc,Math.floor(l/e.css.cell.height))}}},jc=`modulepreload`,Mc=function(e){return`/`+e},Nc={},Pc=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),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?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Mc(t,n),t=s(t),t in Nc)return;Nc[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:jc,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}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)})},Fc=M(`<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`),Ic=M(`<div class=themegrid>`),Lc=M(`<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`),Rc=M(`<i class=notifdot>`),zc=M(`<br>`),Bc=M(`<span class="badge queued">⏳ <!> of yours queued`),Vc=M(`<span class="badge cron">⏰ `),Hc=M(`<span class=sub>ℹ`),Uc=M(`<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><button class=iconbtn title="terminal (t)">⌨</button><button class=iconbtn title="toggle details panel (d)">▤`),Wc=M(`<div class=divider-msg>── beginning of log ──`),Gc=M(`<div class=divider-msg>loading older events…`),Kc=M(`<details class=reasoning><summary>💭 reasoning</summary><div class=mono>`),qc=M(`<div class=content>`),Jc=M(`<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…`),Yc=M(`<div class=feed>`),Xc=M(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),Zc=M(`<div class=termsplit>`),Qc=M(`<div class="termempty muted">no shell here — click a tab or + to add`),$c=M(`<div class=termpane>`),el=M(`<div class=termdrawer><div class=termgrip title="drag to resize · double-click to reset"></div><div class=termbar><div class=termtabs><button class=iconbtn title="new shell in this workspace">+</button></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><button class=iconbtn>◫</button><button class=iconbtn title="close terminal (t)">✕</button></div></div><div class=termbody><div class=termpane>`),tl=M(`<button class=jump>↓ `),nl=M(`<div class=cmds>`),rl=M(`<label class=forkchip title="inherit the conversation prefix byte-exactly — the sub-agent's provider prefix cache starts warm"><input type=checkbox>fork ctx`),il=M(`<div><form><textarea rows=1></textarea><button type=button class="iconbtn maxbtn"></button><button type=submit>send</button></form><div class=hint>`),al=M(`<h3 title="identity + storage locations for this agent">🎛 session`),ol=M(`<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>/`),sl=M(`<h3 title="switch provider/model live — applies from the agent's next turn; the list shows context window &amp; pricing from the provider">🧦 model`),cl=M(`<div class=meta style=color:var(--fg)>`),ll=M(`<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: `),ul=M(`<h3>⏯ controls`),dl=M(`<button class=danger title="interrupt: aborts the current LLM call; the running tool finishes first">■ stop`),fl=M(`<button title="stop every sub-agent this agent spawned (descendants included)">⏹ subs`),pl=M(`<div class=btnrow><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`),ml=M(`<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`),hl=M(`<span>`),gl=M(`<h3 title="what the agent is working toward — auto-continue keeps looping while the status is 'active'">🎯 goal`),_l=M(`<div class=statrow style=margin-bottom:6px><span class=k>status`),vl=M(`<div class=card><div class=content>`),yl=M(`<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>`),bl=M(`<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`),xl=M(`<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 checked> notify agent</label><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save goal`),Sl=M(`<span class=badge>/<!> done`),Cl=M(`<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)`),wl=M(`<div class=bartrack style=margin-bottom:6px><div>`),Tl=M(`<textarea id=todo-input class=mono rows=5 placeholder="- task one
21
- - task two"title="shared with the agent — it may check items off via set_todo; your unsaved edits win until you save"style="width:100%;background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font-family:ui-monospace,Menlo,monospace;font-size:12.5px;resize:vertical">`),El=M(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><button class=iconbtn></button><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`),Dl=M(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),Ol=M(`<h3 title="cumulative billed totals · the cached pill counts tokens served from the provider's prompt cache (far cheaper) · context bar turns orange ≥70% and red ≥85% of the model window">📊 runtime`),kl=M(`<span class="pill ok">⚡ <!>% cached`),Al=M(`<div class="card runcard"><div class=statgrid><div class=stat title="LLM turns taken this session"><span>turns</span><b></b></div><div class=stat title="tool calls executed"><span>tools</span><b></b></div><div class=stat title="times old turns were summarized to free context"><span>compacted</span><b></b></div></div><div class=statrow><span class=k>tokens</span><b> in / <!> out`),jl=M(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),Ml=M(`<h3>⏰ schedule <span class=muted style=text-transform:none;letter-spacing:0>· cron tasks, all agents · edit in settings`),Nl=M(`<div><nav class=sidebar><div class=agent-list></div><div class=sidebar-footer><div class=footer-row style=justify-content:flex-end><span></span><button>🔔</button><button class=iconbtn title="new agent">+</button><button class=iconbtn title=themes>🎨</button><button class=iconbtn title=settings>⚙</button></div><div class=brand-row><div class=brand>🫖 teapot <span class=version>v</span></div></div><div class=metrics></div></div></nav><section class=channel></section><aside>`),Pl=M(`<button class=editbtn>clear all`),Fl=M(`<div class=notiflist>`),Il=M(`<div class=notifpanel><div class=notifhead>notifications`),Ll=M(`<span class=caret>`),Rl=M(`<span class=subtag>🧩`),zl=M(`<span class=mini-cron>⏰`),Bl=M(`<span title="goal done">✓`),Vl=M(`<div><span></span><span>`),Hl=M(`<span class=caret-spacer>`),Ul=M(`<span>🧩 `),Wl=M(`<label class=trow>system light →<select class=w100>`),Gl=M(`<label class=trow>system dark →<select class=w100>`),Kl=M(`<option>`),ql=M(`<button><span class=swdots>`),Jl=M(`<i>`),Yl=M(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),Xl=M(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),Zl=M(`<div class="content muted">thinking…`),Ql=M(`<span>⌨ <button class=tabx title="close this shell">✕`),$l=M(`<div><b class=mono></b><span class=muted>`),eu=M(`<div class=cmdrow><b>@</b><span class=muted>`),tu=M(`<button class=runbtn title="run toward the goal (starts the loop)">▶ start`),nu=M(`<span class=badge title="no goal set yet">no goal`),ru=M(`<button>`),iu=M(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),au=M(`<div><div class=vtitle><span class="meta muted"style=margin-left:auto></span></div><div class=content>`),ou=M(`<div class="content mdpreview"style="max-height:40vh;padding:8px 10px">`),su=M(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),cu=M(`<div class=progrow><b>recent</b><span class="content inline-md">`),lu=M(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),uu=M(`<div class=progrow><b>next</b><span class="content inline-md">`),du=M(`<div class=progrow><b>goal</b><span>`),fu=M(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),pu=M(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),mu=M(`<span>% of `),hu=M(`<div class=bartrack><div>`),gu=M(`<div class=bartrack style=margin-top:4px><div>`),_u=M(`<div class=ctxblock title="estimated live context vs the model's real window. Past the window, old turns are summarized into notes (compaction); the compact line below shows where that starts."><div class=statrow><span class=k>context</span><b>~<!> tok</b></div><div class=statrow style=margin-top:4px><span class=k>compact</span><b> tok</b><span class=muted style=font-size:11px;color:var(--dim)></span></div><div class=ctrlrow style=margin-top:6px><label title="when on, older turns are automatically summarized when context exceeds the budget"><input type=checkbox>auto-compact</label><span class=muted style=font-size:11.5px>summarizes old turns when budget exceeded</span></div><div class=muted style=font-size:11px;margin-top:4px>compaction starts around ~<!> tok — older turns get summarized, recent ones stay intact`),vu=M(`<div><span></span><span> events`),yu=M(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),bu=M(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),xu=M(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class="sched-meta mono"> → next </div><div class="sched-prompt muted">`),Su=M(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),Cu=M(`<div class=nbody>`),wu=M(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted">`),Tu=M(`<div><div style=font-size:12.5px;margin-bottom:4px> event(s) came after this prompt — what should happen to them on the new branch?</div><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>summarize them into a note the agent can still read</label><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>discard them entirely (clean timeline)`),Eu=M(`<form style=display:flex;flex-direction:column;gap:10px><textarea id=edit-text class="mono w100"rows=6></textarea><div style=display:flex;justify-content:flex-end;gap:8px><button type=button>cancel</button><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 12px;cursor:pointer">⑂ fork & resend`),Du=M(`<span class=bashelapsed> elapsed`),Ou=M(`<div class=mono>`),ku=M(`<pre class="mono toolbody">`),Au=M(`<div class=meta>ms`),ju=M(`<div class=meta>waiting for output…`),Mu=M(`<div class="meta muted"> bytes — open it from 🗂 files for the full view`),Nu=M(`<div class=meta>`),Pu=M(`<div class=meta>writing…`),Fu=M(`<pre class="mono toolbody del">`),Iu=M(`<pre class="mono toolbody add">`),Lu=M(`<div class=meta> · <!>ms`),Ru=M(`<div class=meta>applying…`),zu=M(`<pre class="mono toolbody patch">`),Bu=M(`<div>`),Vu=M(`<div class="pline meta">… <!> more lines`),Hu=M(`<div class=meta>validating…`),Uu=M(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),Wu=M(`<span class=muted>`),Gu=M(`<div class=meta>loading…`),Ku=M(`<div class=meta>bundled: `),qu=M(`<div class=meta>saving…`),Ju=M(`<span class=actor>@`),Yu=M(`<details><summary><b>⚙ </b><span class=meta>`),Xu=M(`<div class=divider-msg>⑂ forked from <!> → `),Zu=M(`<div class=divider-msg>🎯 goal <!>: `),Qu=M(`<div class=divider-msg>✅ tasks updated (<!>)`),$u=M(`<div> → `),ed=M(`<div class=avatar>`),td=M(`<button class=editbtn title="withdraw this message — it has not reached the model yet; the text goes back to the input box">✕ cancel`),nd=M(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),rd=M(`<div class=msg-head><span class=author></span><span class=ts></span><span class=ts>`),id=M(`<div><div class=msg-body>`),ad=M(`<span style=width:38px>`),od=M(`<div class=qfree><input type=text><button>reply`),sd=M(`<div class=interrupted>⚠ interrupted — partial output kept`),cd=M(`<div class=msgfoot><span>copy summary`),ld=M(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>ms`),ud=M(`<div class="content muted">Rejected: `),dd=M(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged</span></summary><div class=content>`),fd=M(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),pd=M(`<div class=qopts>`),md=M(`<div><div>❓ `),hd=M(`<button class=qopt>`),gd=M(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),_d=M(`<div class="embed fail"><div class=mono>⚠ `),vd=M(`<div class="content muted">`),yd=M(`<button class=copybtn title="copy to clipboard">`),bd=M(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),xd=M(`<span style=color:var(--err);font-size:13px>`),Sd=M(`<form style=display:flex;flex-direction:column;gap:10px><label>workspace directory<div style=display:flex;gap:6px><input type=text class="w100 mono"><button type=button>go</button><button type=button 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>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`),Cd=M(`<div class=direntry>📁 `),wd=M(`<span class=fsize>`),Td=M(`<div><span class=ficon></span><span class=fname>`),Ed=M(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview">🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),Dd=M(`<div class=filebox>`),Od=M(`<div class=muted style=padding:6px>`),kd=M(`<img>`),Ad=M(`<div class=mediapreview><div class="meta muted"> preview`),jd=M(`<button title="rendered markdown">👁 preview`),Md=M(`<button title="edit and save back to the workspace">✎ edit`),Nd=M(`<div class=filetoolbar><button title="syntax-highlighted source">&lt;/> code`),Pd=M(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Fd=M(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Id=M(`<div class="content mdpreview">`),Ld=M(`<video controls>`),Rd=M(`<audio controls>`),zd=M(`<div class=filepreview>`),Bd=M(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),Vd=M(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),Hd=M(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),Ud=M(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),Wd=M(`<span style=color:var(--fg)>`),Gd=M(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),Kd=M(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>default model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),qd=M(`<button type=button>`),Jd=M(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),Yd=M(`<label><input type=number min=0>`),Xd=M(`<form style=display:flex;flex-direction:column;gap:14px><fieldset><legend>providers</legend><button type=button>+ add custom</button><div style=display:flex;gap:6px;flex-wrap:wrap;margin-top:6px><span class=muted style=font-size:11.5px>quick-add:</span></div><div><label title="agents without an explicit provider use this one"style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<select><option value>(none — first provider wins)</option></select></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid><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><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`),Zd=M(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="api key"type=password><input placeholder="default model"><button type=button class=danger title="remove provider">✕`),Qd=M(`<button type=button>+ `),$d=M(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),ef=M(`<span class=muted>🧩 sub of @`),tf=M(`<div class=cfgrow><b></b><span class=muted>`),nf=new Map;function rf(e){let t=nf.get(e);if(t!==void 0)return t;let n=Le(e);return nf.set(e,n),nf.size>500&&nf.delete(nf.keys().next().value),n}var af={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`}},of={name:`harness`,icon:`📣`,color:`#3ba55d`},[sf,cf]=v(``),lf,Q=e=>{cf(e),clearTimeout(lf),lf=setTimeout(()=>cf(``),3200)},uf=[{key:`dark`,label:`Dark`,mode:`dark`,sw:[`#1a1c22`,`#2b2e39`,`#5865f2`]},{key:`midnight`,label:`Midnight`,mode:`dark`,sw:[`#0d0f18`,`#252a42`,`#8b7cf7`]},{key:`tea`,label:`Milk Tea`,mode:`dark`,sw:[`#241c16`,`#493b2d`,`#d98e32`]},{key:`coffee`,label:`Coffee`,mode:`dark`,sw:[`#191410`,`#403527`,`#c68a4b`]},{key:`matcha`,label:`Matcha`,mode:`dark`,sw:[`#1b2217`,`#3c4a33`,`#8db64e`]},{key:`matrix`,label:`Matrix`,mode:`dark`,sw:[`#060a06`,`#18301d`,`#2fd558`]},{key:`sunset`,label:`Sunset`,mode:`dark`,sw:[`#1c1422`,`#452f52`,`#f2784b`]},{key:`light`,label:`Light`,mode:`light`,sw:[`#eceef4`,`#ffffff`,`#4757d8`]},{key:`strawberry`,label:`Strawberry`,mode:`light`,sw:[`#fbe4ea`,`#fffafb`,`#e05575`]},{key:`ramune`,label:`Ramune`,mode:`light`,sw:[`#ddeff7`,`#fbfeff`,`#1d86ae`]}];function df(){let e=``,t=``;try{let n=getComputedStyle(document.documentElement);e=n.getPropertyValue(`--term-bg`).trim(),t=n.getPropertyValue(`--term-fg`).trim()}catch{}return{background:e||`#0d0e12`,foreground:t||`#dcdee4`}}var ff=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`?af.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:of}return af[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},pf=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`]),mf=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=``;try{t=(await i.json())?.error??``}catch{}throw Error(t||`${e}: HTTP ${i.status}`)}return i.json()}var hf=location.hash.match(/[#&]token=([^&]+)/);hf&&(localStorage.setItem(`teapot.token`,decodeURIComponent(hf[1])),history.replaceState(null,``,location.pathname+location.search));var gf=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function _f(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v([]),[o,s]=v(0),[c,l]=v([]),[u,d]=v(null),f=new Map,[p,m]=v(f.get(n()??``)??``),h=e=>{m(e);let t=n();t&&(e?f.set(t,e):f.delete(t))},[g,_]=v({providers:{}}),[S,te]=v(!1),[ne,w]=v(!1),[re,T]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>1100:localStorage.getItem(`teapot.panel`)===`1`),ie=()=>{let e=!re();T(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},[ae,oe]=v(!1),[E,se]=v(localStorage.getItem(`teapot.theme`)??`dark`),[ce,le]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[ue,de]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[fe,pe]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),D=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[me,he]=v(D?.matches??!1);ee(()=>{let e=e=>he(e.matches);D?.addEventListener(`change`,e),C(()=>D?.removeEventListener(`change`,e))}),b(()=>{let e=ce()?me()?ue():fe():E();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=uf.find(t=>t.key===e)?.mode??`dark`});let[ge,_e]=v(``),[ve,ye]=v(``),[be,xe]=v([]),Se=()=>Object.keys(g().providers??{});async function Ce(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);xe(t.models??[])}catch{xe([])}}let we=()=>{let e=ve().trim()||I()?.model||``;if(!e)return``;let t=be().find(t=>t.id===e);if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Tf(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)};b(()=>{let t=n(),r=e().find(e=>e.id===t),i=r?.provider||g().defaultProvider||Se()[0]||``;r&&(ge()!==i&&(_e(i),Ce(i)),ve()&&ye(``))});let[M,Te]=v(!1),[Ae,je]=v(!0),[Me,Ne]=v(0),[Pe,Fe]=v(null),[Ie,Re]=v(``),ze;b(()=>{if(!Pe()){clearTimeout(ze),ze=void 0,Re(``);return}ze||=setTimeout(()=>{ze=void 0,Re(Pe()?.text??``)},(Pe()?.text.length??0)>2e4?250:(Pe()?.text.length??0)>6e3?120:60)}),C(()=>clearTimeout(ze)),b(()=>{Ie()&&Ae()&&requestAnimationFrame(()=>{Ae()&&Lt(!0)})}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{It()&&(je(!0),Ne(0),Lt(!0))})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let I=x(()=>e().find(e=>e.id===n())),[Be,Ve]=v(null);x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let[He,Ue]=v([]),[L,R]=v([]),[We,Ge]=v(!1),Ke=()=>L().filter(e=>!e.read).length,qe=0,Je=e=>{R(t=>[{...e,id:`n${++qe}`,at:Date.now(),read:!1},...t].slice(0,50))},Ye=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t;n.type===`message`&&n.data?.final===!0?Je({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300)}):n.type===`question`?Je({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300)}):n.type===`error`?Je({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300)}):n.type===`progress`&&Je({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)})},Xe=x(()=>{let e=new Map,t=new Set,n=new Map;for(let r of i())if(pf.has(r.type)){if(r.type===`tool_call`){let e=n.get(r.data.callId)??[];e.push(r),n.set(r.data.callId,e)}else if(r.type===`tool_result`){let i=n.get(r.data.callId)?.shift();i&&(e.set(i.id,r),t.add(r.id))}}return{resFor:e,consumed:t}}),Ze=x(()=>{let e=new Set,t=-1,n=-1;for(let e of i())e.type===`question`?t=e.seq:e.type===`prompt`&&e.data?.source===`user`?n=e.seq:e.type===`system_note`&&e.data?.event===`prompt-delivered`&&(n=Math.max(n,e.seq));if(t>=0&&n>t)for(let t of i())t.type===`question`&&t.seq<=n&&e.add(String(t.data?.callId??``));return e}),Qe=x(()=>{let{consumed:e}=Xe(),t=i().filter(t=>{if(!pf.has(t.type))return!1;let n=t.type===`tool_call`||t.type===`tool_result`?String(t.data?.name??``):``;return n===`report_progress`||n===`ask_user`?!1:t.type===`tool_result`?!e.has(t.id):t.type===`message`?t.data?.progressEcho?!1:String(t.data?.content??``).trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final:!0}),n=[];for(let e of t)if(e.type===`sub`){let t=e.data,r=String(t?.type??`message`);if(r===`state`)continue;n.push({...e,type:r,data:{...t?.data,actor:t?.sub}})}else n.push(e);let r=e=>String(e??``).replace(/\s+/g,` `).trim().toLowerCase(),a=[];for(let e=0;e<n.length;e++){let t=n[e];if(t.type===`message`&&t.data?.role===`assistant`){let i=n[e-1],a=r(t.data.content);if(i?.type===`progress`){let e=i.data;if((a.includes(r(e.doing))||e.recent&&a.includes(r(e.recent)))&&a.length<=Math.max(200,r(e.doing).length*3))continue}if(i?.type===`decision`){let e=i.data,t=r(e.decision);if(t&&a.includes(t)&&a.length<=Math.max(300,t.length*3))continue}}a.push(t)}let o=He().filter(e=>!a.some(t=>t.type===`prompt`&&t.data?.source===`user`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)).map(e=>({id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:I()?.session??``,branch:I()?.branch??`br0`,parent:null,type:`prompt`,data:{source:`user`,text:e.text,pending:!e.sent,...e.promptId?{promptId:e.promptId}:{}}}));return[...a,...o]}),$e=()=>$(`/api/config`).then(_).catch(()=>{}),[et,tt]=v(!1);ee(()=>{let e=()=>tt(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[nt,rt]=v(``),[it,at]=v(!1),[ot,st]=v(!1),ct=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==ct?(ct=t,st(!1),rt(r)):t&&!ot()&&rt(r)});let lt=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:nt(),notify:e})}),st(!1),Q(`tasks saved${e&&nt().trim()?` & notification queued`:``}`),dt()}catch(e){Q(`save failed: ${e.message}`)}},ut=x(()=>{let e=0,t=0;for(let n of nt().split(`
22
- `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),dt=()=>$(`/api/agents`).then(e=>t(t=>{let n=new Map(t.map(e=>[e.id,e]));return(e.agents??[]).map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})})).catch(()=>{}),ft=()=>$(`/api/metrics`).then(d).catch(()=>{}),[pt,mt]=v([]),ht=()=>$(`/api/tasks`).then(e=>mt(e.tasks)).catch(()=>{}),gt=e=>pt().filter(t=>t.agent===e),[_t,vt]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),yt=e=>{let t=new Set(_t());t.has(e)?t.delete(e):t.add(e),vt(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},bt=x(()=>{let t=e(),n=new Map,r=[];for(let e of t)e.parent&&t.some(t=>t.id===e.parent)?(n.has(e.parent)||n.set(e.parent,[]),n.get(e.parent).unshift(e)):r.push(e);let i=[],a=(e,t)=>{for(let r of e){i.push({a:r,depth:t});let e=n.get(r.id);e?.length&&!_t().has(r.id)&&a(e,t+1)}};return a(r,0),i}),[xt,St]=v(null),Ct=new Map;function wt(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=Ct.get(r.id);if(t[n]=i??r,!i&&(Ct.set(r.id,r),Ct.size>3e3)){let e=Ct.keys().next().value;e!==void 0&&Ct.delete(e)}}return t}let[Tt,Et]=v(!1),[Dt,Ot]=v(!1),kt=0,At=-1;function jt(e){a(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of wt(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function Mt(){let e=n(),t=i()[0];if(!(!e||!t||Tt()||Dt())){Et(!0);try{let r=Pt(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=xt(),c=(await $(`/api/agents/${e}/events?limit=300&before=${encodeURIComponent(t.id)}${s?`&branch=${encodeURIComponent(s)}`:``}`)).events??[];if(c.length===0){Ot(!0);return}if(n()!==e||i()[0]?.id!==t.id)return;jt(c),requestAnimationFrame(()=>{if(n()===e){let e=Pt();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{Et(!1)}}}async function Nt(e){let t=kt;try{let r=xt(),i=t!==At||!c().length,[o,u,d]=await Promise.all([$(`/api/agents/${e}/events?limit=300${r?`&branch=${encodeURIComponent(r)}`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:c()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(At=t),t!==kt||n()!==e)return;a(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of wt(o.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),s(o.total??o.events.length),l(u.branches),kn(d.skills??[])}catch{}}function Pt(){return document.querySelector(`.feed`)}function Ft(){let e=document.querySelector(`.composer textarea`);return 80+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function It(){let e=Pt();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<Ft()}function Lt(e=!1){let t=Pt();t&&(e||Ae())&&(t.scrollTop=t.scrollHeight,Ne(0))}async function Rt(e,t=!0){let i=n();kt++,i!==e&&(a([]),Ct.clear(),Fe(null),Ne(0)),r(e),h(f.get(e)??``),St(null),Ot(!1),Et(!1),Ue([]),localStorage.setItem(`teapot.session`,e),qt(e,t),$(`/api/agents/${e}/load`,{method:`POST`}).then(dt).catch(()=>{}),await Nt(e),n()===e&&requestAnimationFrame(()=>{n()===e&&Lt(!0)})}let[zt,Bt]=v(!1),Vt=null,Ht=null;C(()=>Vt?.close());let Ut=!1,Wt=null;document.addEventListener(`visibilitychange`,()=>Wt?.()),C(()=>{Wt=null});function Gt(){let e=location.protocol===`https:`?`wss://`:`ws://`;Vt=new WebSocket(`${e}${location.host}/api/ws${gf()}`),Vt.onopen=()=>Bt(!0),Vt.onclose=()=>{Bt(!1),setTimeout(Gt,1500)},Vt.onerror=()=>Vt?.close();let r=new Set([`state`,`usage`,`session_start`]),a=null;Vt.onmessage=e=>{let i=JSON.parse(e.data);if(i.kind!==`ping`&&i.kind!==`pong`){if(i.kind===`llm-delta`){a={id:i.agentId,at:Date.now()},i.agentId===n()&&Fe({text:i.text??``,reasoning:i.reasoning??``});return}if(i.kind===`agent-update`&&i.snapshot){t(e=>{let t=e.findIndex(e=>e.id===i.snapshot.id),n=i.snapshot;if(t===-1)return[...e,n];let r=e[t];return JSON.stringify(r)===JSON.stringify(n)?e:e.map((e,r)=>r===t?n:e)});return}if(i.kind===`event`){let e=i.event?.type,t=i.event?.data??{};if(e===`system_note`&&t.event===`prompt-delivered`&&i.agentId===n()){Ue(e=>e.map(e=>e.promptId===t.promptId?{...e,sent:!0}:e));return}if(e===`system_note`&&t.event===`prompt-cancelled`&&i.agentId===n()){Ue(e=>e.filter(e=>e.promptId!==t.promptId));return}if(r.has(e)||(Ye(i.agentId,i.event),i.event?.agent!==n()))return}if(document.visibilityState===`hidden`){Ut=!0,Ht||=setTimeout(s,2e3);return}Ht||=setTimeout(s,400)}},Ut=!1;let s=async()=>{if(Ht=null,await dt(),await ft(),n()){let e=i().at(-1)?.id,t=o(),r=Date.now();await Nt(n()),i().at(-1)?.id!==e&&(a?.id===n()&&a.at>=r||Fe(null),It()?Lt(!0):Ne(Me()+Math.max(0,o()-t))),Ue(e=>e.filter(e=>!i().some(t=>t.type===`prompt`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)))}};Wt=()=>{document.visibilityState===`visible`&&Ut&&(Ut=!1,Ht||=setTimeout(s,150))}}let Kt=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function qt(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let t=Kt();t&&e().some(e=>e.id===t)&&t!==n()&&Rt(t,!1)}),b(()=>{let e=I(),t=e?`${e.status===`running`?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=Ke()>0?`(${Ke()}) ${t}`:t}),window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)){e.key===`Escape`&&t.blur();return}if(e.key===`Escape`){if(S()){te(!1);return}if(ne()){w(!1);return}if(Be()){Ve(null);return}if(ae()){oe(!1);return}let e=I();if(e?.status===`running`){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(dt);return}re()&&window.innerWidth<=1100&&T(!1);return}if(!(S()||ne())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)ie();else if(e.key===`t`)Xt();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=bt().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&&Rt(t[i].id)}}});let[Jt,Yt]=v(localStorage.getItem(`teapot.term`)===`1`),Xt=()=>{let e=!Jt();Yt(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[Zt,Qt]=v([]),[$t,en]=v(0),[tn,z]=v(-1),[nn,rn]=v(!1),[B,an]=v(0),[on,sn]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),V=new Map,cn=[null,null],ln=()=>Zt()[B()===0?$t():tn()]??null;function un(e){if(!Zt()[e])return;let t=B()===0?$t:tn;(B()===0?tn:$t)()===e&&(B()===0?z(t()):en(t())),t()===e||(B()===0?en(e):z(e))}let dn=()=>fn();function fn(e){let t=e??n();if(!t)return;let r=Zt().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}Zt().length+1;let i=r===0?{key:`${t}`,agentId:t,title:t}:{key:`${t}#${r+1}`,agentId:t,title:`${t}·${r+1}`};Qt(e=>[...e,i]),B()===0?en(Zt().length):z(Zt().length)}function pn(e){let t=Zt()[e];if(!t)return;let n=V.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),V.delete(t.key)}let r=Zt().filter((t,n)=>n!==e);Qt(r);let i=t=>t===e?-1:t>e?t-1:t;en(e=>Math.min(i(e),r.length-1)),z(e=>e===-1?-1:Math.min(i(e),r.length-1))}function mn(){for(let[,e]of V){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}V.clear()}function hn(e,t){let n=V.get(e.key);if(n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new Dc({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:df()}),a=new Ac;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${gf()}`);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},V.set(e.key,n)}return n}function gn(e){let t=cn[e];if(!t)return;let n=Zt()[e===0?$t():tn()];if(!n){[...V.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=hn(n,t);requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(B()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{if(!Jt())return;let e=n();if(e){if(!Zt().some(t=>t.agentId===e)&&Zt().length===0)fn(e);else if(!Zt().some(t=>t.agentId===e)){let t=Zt().findIndex(t=>t.agentId===e);t>=0&&un(t)}}});let _n=e=>{e.preventDefault();let t=e.clientY,n=on(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));sn(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(on())),requestAnimationFrame(()=>{gn(0),nn()&&gn(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},vn=()=>{let e=!nn();if(rn(e),e&&tn()===-1){let e=Zt().findIndex((e,t)=>t!==$t());z(e>=0?e:-1)}};C(mn);let yn=e=>t=>{cn[e]=t};ee(()=>{$e(),dt().then(()=>{let t=Kt()||localStorage.getItem(`teapot.session`)||``,n=e().find(e=>e.id===t)??e()[0];n&&Rt(n.id,!1)}),ft(),ht(),H(),Gt();let t=setInterval(()=>{ft(),ht()},3e4);C(()=>clearInterval(t))});let bn=[{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`}],[xn,Sn]=v([]),H=()=>$(`/api/personas`).then(e=>Sn(e.personas)).catch(()=>{}),[Cn,wn]=v(!1),Tn=()=>{let e=p().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},En=()=>{let t=Tn();return t===null?[]:[...xn().map(e=>({key:e.key,label:`${e.label} — spawns a sub-agent`,kind:`persona`})),...e().filter(e=>e.id!==n()).map(e=>({key:e.id,label:`${e.status} — send directly`,kind:`agent`}))].filter(e=>e.key.toLowerCase().startsWith(t))},Dn=new Set([`start`,`stop`,`fork`,`compact`]),[On,kn]=v([]),[An,jn]=v(-1),Mn=()=>{let e=p();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[3]??``).trim();if(!r&&n!==`skill`){let e=bn.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Dn.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=On().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[]},Nn,Pn=()=>{if(!Nn)return;Fn=!0;let e=Ae();Nn.style.height=`auto`,Nn.style.height=M()?``:`${Math.min(Nn.scrollHeight,360)}px`,requestAnimationFrame(()=>{let t=Pt();e&&t&&(t.scrollTop=t.scrollHeight),Fn=!1})},Fn=!1;b(()=>{p(),Pn()});let In=async(e,t)=>{let r=t??n();if(r)try{let t=await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0})});Ue(n=>[...n,{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now(),promptId:t.promptId}]),requestAnimationFrame(()=>requestAnimationFrame(()=>Lt(!0)))}catch(t){h(e),console.error(`send failed:`,t)}},Ln=async t=>{t.preventDefault();let r=n(),i=p().trim();if(!(!r||!i)){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=xn().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:Cn()?`fork`:`none`})})).id}${Cn()?` (forked context)`:``}`),dt(),h(``)}else if(s){if(!a){Q(`usage: @${r} <message>`);return}await $(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),Q(`→ delivered to @${r}`),h(``)}else{Q(`unknown @${r} — personas: ${xn().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}return}if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim();if(t===`goal`&&!n){h(`/goal `);return}if(t===`skill`&&!n){h(`/skill `);return}h(``),await Rn(t,n);return}h(``),await In(i)}},Rn=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(dt);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Rt(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 In(`[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}`)}},zn,Bn=0;b(()=>{e(),requestAnimationFrame(()=>{zn&&(Bn=Math.min(Bn,zn.scrollHeight),zn.scrollTop=Bn)})});let Vn=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(dt),Hn=async e=>{e.preventDefault();let t=document.getElementById(`goal-input`),r=document.getElementById(`goal-verify-input`),i=document.getElementById(`goal-notify`)?.checked??!0;!n()||!t.value.trim()||(await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t.value,notify:i,...r?.value.trim()?{verify:r.value}:{}})}),t.value=``,r&&(r.value=``),dt())};return[O(A,{get when(){return g()?.needsSetup},fallback:null,get children(){return O(zf,{onDone:()=>location.reload()})}}),O(A,{get when(){return et()},get children(){var e=Fc();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),O(A,{get when(){return!g()?.needsSetup},get children(){var o=Nl(),s=o.firstChild,l=s.firstChild,d=l.nextSibling,f=d.firstChild,m=f.firstChild,_=m.nextSibling;_.firstChild;var v=_.nextSibling,b=v.nextSibling,x=b.nextSibling,S=f.nextSibling,ee=S.firstChild.firstChild.nextSibling;ee.firstChild;var C=S.nextSibling,ne=s.nextSibling,T=ne.nextSibling;F(l,O(k,{get each(){return bt()},children:({a:t,depth:r})=>(()=>{var i=Vl(),a=i.firstChild,o=a.nextSibling;return i.$$click=()=>Rt(t.id),F(i,O(A,{get when(){return e().some(e=>e.parent===t.id)},get fallback(){return Hl()},get children(){var e=Ll();return e.$$click=e=>{e.stopPropagation(),yt(t.id)},F(e,()=>_t().has(t.id)?`▸`:`▾`),y(()=>N(e,`title`,_t().has(t.id)?`expand sub-agents`:`collapse sub-agents`)),e}}),a),F(o,()=>t.id),F(i,O(A,{get when(){return _t().has(t.id)},get children(){return(()=>{let n=e().filter(e=>e.parent===t.id),r=n.filter(e=>e.status===`running`||e.status===`waiting`).length;return n.length>0?(()=>{var e=Ul();return e.firstChild,P(e,`subcount`+(r>0?` live`:``)),F(e,()=>n.length,null),F(e,r>0?` · ▶${r}`:``,null),y(()=>N(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),F(i,O(A,{get when(){return t.parent},get children(){return Rl()}}),null),F(i,O(A,{get when(){return gt(t.id).length>0},get children(){var e=zl();return y(()=>N(e,`title`,gt(t.id).map(e=>`${e.id}: ${e.schedule}`).join(`
24
- `))),e}}),null),F(i,O(A,{get when(){return t.goal.status===`done`},get children(){return Bl()}}),null),y(e=>{var o=`agent-item`+(t.id===n()?` sel`:``)+(r>0?` sub-row`:``),s=r>0?`padding-left:${10+r*14}px`:``,c=t.parent?`sub-agent of @${t.parent}`:void 0,l=`dot ${t.status}`;return o!==e.e&&P(i,e.e=o),e.t=De(i,s,e.t),c!==e.a&&N(i,`title`,e.a=c),l!==e.o&&P(a,e.o=l),e},{e:void 0,t:void 0,a:void 0,o:void 0}),i})()})),F(d,O(A,{get when(){return ae()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;le(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),F(e,O(A,{get when(){return!ce()},get fallback(){return[(()=>{var e=Wl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),F(t,O(k,{get each(){return uf.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=Kl();return F(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ue()),e})(),(()=>{var e=Gl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{pe(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),F(t,O(k,{get each(){return uf.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=Kl();return F(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=fe()),e})()]},get children(){var e=Ic();return F(e,O(k,{each:uf,children:e=>(()=>{var t=ql(),n=t.firstChild;return t.$$click=()=>{se(e.key),localStorage.setItem(`teapot.theme`,e.key)},F(n,()=>e.sw.map(e=>(()=>{var t=Jl();return Oe(t,`background`,e),t})())),F(t,()=>e.label,null),y(n=>{var r=`themebtn`+(E()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&P(t,n.e=r),i!==n.t&&N(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ce()),e}}),f),_.$$click=()=>{Ge(!We()),R(e=>e.map(e=>({...e,read:!0})))},F(_,O(A,{get when(){return Ke()>0},get children(){var e=Rc();return F(e,Ke),e}}),null),v.$$click=()=>{$e(),te(!0)},b.$$click=()=>oe(!ae()),x.$$click=()=>{$e(),w(!0)},F(ee,`0.15.9`,null),F(C,O(A,{get when(){return u()},get children(){return[`master rss `,j(()=>u().rssMb),`MB · heap `,j(()=>u().heapUsedMb),`MB`,zc(),`load1 `,j(()=>u().loadavg1),` · up `,j(()=>Math.floor(u().uptimeSec/60)),`m`]}})),F(ne,O(A,{get when(){return I()},get fallback(){return Yl()},get children(){return[(()=>{var e=Uc(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling;s.nextSibling;var c=r.nextSibling,l=c.firstChild,u=l.nextSibling;return F(t,()=>I().id),F(n,()=>I().status),F(e,O(A,{get when(){return(I().pendingPrompts??0)>0},get children(){var e=Bc(),t=e.firstChild.nextSibling;return t.nextSibling,F(e,()=>I().pendingPrompts,t),y(()=>N(e,`title`,`${I().pendingPrompts??0} message${(I().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),F(e,O(A,{get when(){return gt(I().id).length>0},get children(){var e=Vc();return e.firstChild,F(e,()=>gt(I().id).length,null),y(()=>N(e,`title`,`scheduled tasks:\n${gt(I().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
25
- `)}`)),e}}),r),F(r,()=>I().model,i),F(r,()=>I().session,a),F(r,()=>I().branch,o),F(r,()=>I().stats.turns,s),F(r,()=>I().stats.toolCalls,null),F(c,O(A,{get when(){return I().statusReason},get children(){var e=Hc();return y(()=>N(e,`title`,I().statusReason)),e}}),l),l.$$click=Xt,u.$$click=ie,y(()=>P(n,`badge ${I().status}`)),e})(),(()=>{var e=Yc();return e.addEventListener(`scroll`,e=>{if(Fn)return;let t=e.currentTarget,r=It();r&&Me()&&Ne(0),je(r),t.scrollTop<=4&&n()&&!Tt()&&!Dt()&&i().length>0&&Mt()}),F(e,O(A,{get when(){return j(()=>!!Dt())()&&Qe().length>0},get children(){return Wc()}}),null),F(e,O(A,{get when(){return Tt()},get children(){return Gc()}}),null),F(e,O(A,{get when(){return Qe().length>0},get fallback(){return Xl()},get children(){return[O(k,{get each(){return Qe()},children:(e,t)=>O(bf,{e,get prev(){return Qe()[t()-1]},get res(){return Xe().resFor.get(e.id)},onOption:e=>void In(e),get answeredIds(){return Ze()},get agentActive(){return I()?.status===`running`||I()?.status===`waiting`},get onCancel(){return e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);h(p()?`${n}\n\n${p()}`:n),Ue(e=>e.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`?()=>Ve({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),O(A,{get when(){return Pe()},get children(){var e=Jc(),t=e.firstChild.nextSibling;return t.firstChild,F(t,O(A,{get when(){return Pe().reasoning},get children(){var e=Kc(),t=e.firstChild.nextSibling;return F(t,()=>Pe().reasoning),e}}),null),F(t,O(A,{get when(){return Ie()},get fallback(){return Zl()},get children(){var e=qc();return y(()=>e.innerHTML=Le(Ie()+`▍`)),e}}),null),e}})]}}),null),e})(),O(A,{get when(){return Jt()},get children(){var t=el(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.firstChild,o=i.nextSibling.firstChild,s=o.nextSibling,c=s.nextSibling,l=r.nextSibling,u=l.firstChild;n.$$dblclick=()=>{sn(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(on()))},n.$$pointerdown=_n,F(i,O(k,{get each(){return Zt()},children:(e,t)=>(()=>{var n=Ql(),r=n.firstChild.nextSibling;return n.$$click=()=>un(t()),F(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),pn(t())},y(r=>{var i=`termtab`+(B()===0&&$t()===t()?` active`:``)+(nn()&&B()===1&&tn()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),a),a.$$click=dn,F(o,(()=>{var t=j(()=>!!ln());return()=>t()?e().find(e=>e.id===ln().agentId)?.workspace.split(`/`).filter(Boolean).pop():I()?.workspace})()),s.$$click=vn,c.$$click=Xt;var d=yn(0);return typeof d==`function`&&ke(d,u),u.$$pointerdown=()=>an(0),F(u,O(A,{get when(){return!ln()||B()===0&&$t()===-1},get children(){return Xc()}})),F(l,O(A,{get when(){return nn()},get children(){return[Zc(),(()=>{var e=$c(),t=yn(1);return typeof t==`function`&&ke(t,e),e.$$pointerdown=()=>an(1),F(e,O(A,{get when(){return tn()===-1||Zt().length<=tn()},get children(){return Qc()}})),y(()=>e.classList.toggle(`focused`,B()===1)),e})()]}}),null),y(e=>{var n={height:`${on()}px`,"--termh":`${on()}px`},r=nn()?`single pane`:`split panes (50/50)`,i=!!nn(),a=B()===0;return e.e=De(t,n,e.e),r!==e.t&&N(s,`title`,e.t=r),i!==e.a&&l.classList.toggle(`split`,e.a=i),a!==e.o&&u.classList.toggle(`focused`,e.o=a),e},{e:void 0,t:void 0,a:void 0,o:void 0}),t}}),(()=>{var e=il(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=t.nextSibling;F(e,O(A,{get when(){return!Ae()||Me()>0},get children(){var e=tl();return e.firstChild,e.$$click=()=>Lt(!0),F(e,(()=>{var e=j(()=>Me()>0);return()=>e()?`${Me()} new message${Me()>1?`s`:``}`:`jump to present`})(),null),e}}),t),F(e,O(A,{get when(){return Mn().length>0},get children(){var e=nl();return F(e,O(k,{get each(){return Mn()},children:(e,t)=>(()=>{var n=$l(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{h(e.insert),jn(-1)},F(r,()=>e.insert.trim()),F(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===An()?` active`:``),a=e.title;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),F(e,O(A,{get when(){return En().length>0},get children(){var e=nl();return F(e,O(k,{get each(){return En()},children:e=>(()=>{var t=eu(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{h(`@${e.key} `),jn(-1)},F(n,()=>e.key,null),F(r,()=>e.label),y(()=>N(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Ln),n.$$keydown=e=>{let t=Mn();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),jn(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),jn(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&An()>=0){e.preventDefault(),h(t[An()].insert),jn(-1);return}if(e.key===`Escape`&&t.length>0){jn(-1);return}e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),Ln(e))},n.$$input=e=>{h(e.currentTarget.value),jn(0),Pn()};var a=Nn;return typeof a==`function`?ke(a,n):Nn=n,F(t,O(A,{get when(){return j(()=>!!p().startsWith(`@`))()&&p().includes(` `)},get children(){var e=rl(),t=e.firstChild;return t.addEventListener(`change`,e=>wn(e.currentTarget.checked)),y(()=>t.checked=Cn()),e}}),r),r.$$click=()=>{let e=!M();Te(e),requestAnimationFrame(()=>Pn())},F(r,()=>M()?`⤡`:`⤢`),F(i,()=>sf()||`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`+(M()?` maximized`:``),a=`message #${I().id} — / for commands`,o=M()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&P(e,t.e=i),a!==t.t&&N(n,`placeholder`,t.t=a),o!==t.a&&N(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),y(()=>n.value=p()),e})()]}})),T.addEventListener(`scroll`,e=>{Bn=e.currentTarget.scrollTop});var D=zn;return typeof D==`function`?ke(D,T):zn=T,F(T,O(A,{get when(){return I()},get children(){return[al(),(()=>{var e=ol(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return F(n,()=>I().id),F(r,()=>I().status),F(a,()=>I().workspace),F(o,()=>I().session,s),F(o,()=>I().branch,null),y(e=>{var t=`badge ${I().status}`,n=I().workspace;return t!==e.e&&P(r,e.e=t),n!==e.t&&N(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),O(Ff,{get agentId(){return I().id},get workspace(){return I().workspace}}),sl(),(()=>{var e=ll(),t=e.firstChild,r=t.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=r.nextSibling;return s.firstChild,t.addEventListener(`change`,e=>{_e(e.currentTarget.value),Ce(e.currentTarget.value)}),F(t,O(k,{get each(){return Se()},children:e=>(()=>{var t=Kl();return t.value=e,F(t,e,null),F(t,()=>e===g().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>ye(e.currentTarget.value),F(a,O(k,{get each(){return be()},children:e=>(()=>{var t=Kl();return y(()=>t.value=e.id),t})()})),o.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:ge(),model:ve().trim()||void 0,contextWindowTokens:be().find(e=>e.id===(ve().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,dt()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},F(s,()=>I().model,null),F(s,O(A,{get when(){return be().length},get children(){return[` · `,j(()=>be().length),` models loaded`]}}),null),F(e,O(A,{get when(){return we()},get children(){var e=cl();return F(e,we),e}}),null),y(()=>N(i,`placeholder`,I().model)),y(()=>t.value=ge()),y(()=>i.value=ve()),e})(),ul(),(()=>{var i=pl(),o=i.firstChild,s=o.nextSibling;return F(i,O(A,{get when(){return I().status===`running`},get fallback(){return(()=>{var e=tu();return Ee(e,`click`,Vn(`/start`),!0),e})()},get children(){var e=dl();return Ee(e,`click`,Vn(`/stop`),!0),e}}),o),o.$$click=()=>$(`/api/agents/${I().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>Rt(I().id)),s.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await $(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let o=e().filter(e=>e.id!==i);t(o),o[0]?Rt(o[0].id):(r(null),a([]))},F(i,O(A,{get when(){return e().some(e=>e.parent===n())},get children(){var e=fl();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),dt())},e}}),null),i})(),(()=>{var e=ml(),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(dt)}),y(()=>t.checked=I().autoContinue??!0),e})(),(()=>{var e=gl();return e.firstChild,F(e,O(A,{get when(){return!!I().goal.text.trim()},get fallback(){return nu()},get children(){var e=hl();return F(e,()=>I().goal.status),y(()=>P(e,`badge ${I().goal.status===`active`?`running`:I().goal.status}`)),e}}),null),e})(),(()=>{var e=_l();return e.firstChild,F(e,O(k,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=ru();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(dt)},N(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),F(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(I().goal.text.trim()&&I().goal.status===e?` on ${e}`:``),i=!!I().goal.text.trim()&&I().goal.status===e;return r!==n.e&&P(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),O(A,{get when(){return I().goal.text},get fallback(){return iu()},get children(){return[(()=>{var e=vl(),t=e.firstChild;return y(()=>t.innerHTML=Le(String(I().goal.text))),e})(),O(A,{get when(){return I().goal.verify},get children(){var e=yl(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Le(String(I().goal.verify))),e}}),O(A,{get when(){return I().goal.audit},children:e=>(()=>{var t=au(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return F(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),F(r,()=>wf(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=Le(e().feedback);return r!==n.e&&P(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),bl(),(()=>{var e=xl();return e.addEventListener(`submit`,Hn),e})(),(()=>{var e=Cl(),t=e.firstChild.nextSibling;return F(e,O(A,{get when(){return ut().total>0},get children(){var e=Sl(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,F(e,()=>ut().done,t),F(e,()=>ut().total,n),y(t=>De(e,ut().done===ut().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),O(A,{get when(){return ut().total>0},get children(){var e=wl(),t=e.firstChild;return y(e=>{var n=`barfill `+(ut().done===ut().total?``:`warn`),r=`${Math.round(ut().done/ut().total*100)}%`;return n!==e.e&&P(t,e.e=n),r!==e.t&&Oe(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),O(A,{get when(){return it()},get fallback(){return(()=>{var e=ou();return y(()=>e.innerHTML=rf(nt())),e})()},get children(){var e=Tl();return e.$$input=e=>{rt(e.currentTarget.value),st(!0)},y(()=>e.value=nt()),e}}),(()=>{var e=El(),t=e.firstChild,n=t.nextSibling.nextSibling;return t.$$click=()=>at(!it()),F(t,()=>it()?`👁`:`✎`),n.$$click=lt,y(()=>N(t,`title`,it()?`rendered checklist`:`edit markdown`)),e})(),Dl(),O(A,{get when(){return I().latestProgress},get fallback(){return su()},children:e=>(()=>{var t=fu(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return F(t,O(A,{get when(){return e().recent},get children(){var t=cu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=rf(e().recent)),t}}),i),F(t,O(A,{get when(){return e().problems},get children(){var t=lu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=rf(e().problems)),t}}),i),F(t,O(A,{get when(){return e().next},get children(){var t=uu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=rf(e().next)),t}}),i),F(t,O(A,{get when(){return e().goalStatus},get children(){var t=du(),n=t.firstChild.nextSibling;return F(n,()=>e().goalStatus),t}}),i),F(i,()=>wf(e().ts)),y(()=>r.innerHTML=rf(e().doing)),t})()}),Ol(),(()=>{var e=Al(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=t.nextSibling,l=c.firstChild.nextSibling,u=l.firstChild,d=u.nextSibling;return d.nextSibling,F(i,()=>I().stats.turns),F(o,()=>I().stats.toolCalls),F(s,()=>I().stats.compactions??0),F(l,()=>Tf(I().stats.inputTokens),u),F(l,()=>Tf(I().stats.outputTokens),d),F(c,O(A,{get when(){return(I().stats.cachedInputTokens??0)>0},get children(){var e=kl(),t=e.firstChild.nextSibling;return t.nextSibling,F(e,()=>Math.round(I().stats.cachedInputTokens/Math.max(1,I().stats.inputTokens)*1e3)/10,t),y(()=>N(e,`title`,`${Tf(I().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),F(e,O(A,{get when(){return I().ctx},get fallback(){return pu()},children:e=>{let t=be().find(e=>e.id===I().model),r=e().window||t?.contextLength||0,i=r?Math.min(999,e().usedTokens/r*100):0,a=r?i>=85?`crit`:i>=70?`warn`:`ok`:``,o=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)},s=r?Math.round(r*.75):0,c=e().compactAt,l=e().compactAtIsManual===!0?!1:!c||c>=r;return(()=>{var t=_u(),u=t.firstChild,d=u.firstChild.nextSibling,f=d.firstChild.nextSibling;f.nextSibling;var p=u.nextSibling,m=p.firstChild.nextSibling,h=m.firstChild,g=m.nextSibling,_=p.nextSibling,v=_.firstChild.firstChild,b=_.nextSibling,x=b.firstChild.nextSibling;return x.nextSibling,F(d,()=>Tf(e().usedTokens),f),F(u,O(A,{when:r,get children(){var e=mu(),t=e.firstChild;return P(e,`pill ${a}`),F(e,()=>o(i),t),F(e,()=>Tf(r),null),e}}),null),F(t,O(A,{when:r,get children(){var e=hu(),t=e.firstChild;return P(t,`barfill ${a}`),y(e=>Oe(t,`width`,`${Math.min(100,i)}%`)),e}}),p),F(m,()=>Tf(l?s:c),h),F(g,l?` (75% of window)`:` (manual override)`),F(t,O(A,{when:r,get children(){var t=gu(),n=t.firstChild;return P(n,`barfill ${a}`),y(t=>Oe(n,`width`,`${Math.min(100,Math.round(e().usedTokens/s*100))}%`)),t}}),_),v.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(dt)}),F(b,()=>Tf(e().compactAt),x),y(()=>v.checked=I().autoCompact!==!1),t})()}}),null),e})(),jl(),O(k,{get each(){return c()},children:e=>(()=>{var t=vu(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=xt()===e.branch?null:e.branch;St(t),n()&&Nt(n())},F(r,()=>e.branch,null),F(r,()=>e.branch===I().branch?` (current)`:``,null),F(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===I().branch||e.branch===xt()?` cur`:``),i=e.branch===xt()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&P(t,n.e=r),i!==n.t&&N(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Ml(),O(A,{get when(){return pt().length>0},get fallback(){return yu()},get children(){return O(k,{get each(){return pt()},children:e=>(()=>{var t=xu(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Rt(e.agent),F(i,()=>e.id),F(a,()=>e.agent,null),F(r,O(A,{get when(){return e.forked},get children(){return bu()}}),null),F(o,()=>e.schedule,s),F(o,(()=>{var t=j(()=>!!e.next);return()=>t()?wf(e.next):`—`})(),null),F(o,(()=>{var t=j(()=>!!e.last);return()=>t()?` · last ${wf(e.last)}`:` · never ran`})(),null),F(c,()=>Ef(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Ef(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&P(t,r.e=i),a!==r.t&&N(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(re()?``:` right-hidden`),n=`conn`+(zt()?` ok`:``),r=zt()?`live (websocket)`:`reconnecting…`,i=`iconbtn notifbtn`+(Ke()>0?` has-unread`:``),a=Ke()>0?`${Ke()} unread notifications`:`notifications`,s=`rightbar`+(re()?` open`:``);return t!==e.e&&P(o,e.e=t),n!==e.t&&P(m,e.t=n),r!==e.a&&N(m,`title`,e.a=r),i!==e.o&&P(_,e.o=i),a!==e.i&&N(_,`title`,e.i=a),s!==e.n&&P(T,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),o}}),O(A,{get when(){return We()},get children(){var t=Il(),n=t.firstChild;return n.firstChild,F(n,O(A,{get when(){return L().length>0},get children(){var e=Pl();return e.$$click=()=>R([]),e}}),null),F(t,O(A,{get when(){return L().length>0},get fallback(){return Su()},get children(){var t=Fl();return F(t,O(k,{get each(){return L()},children:t=>(()=>{var n=wu(),r=n.firstChild.firstChild,i=r.nextSibling,a=i.nextSibling;return n.$$click=()=>{e().some(e=>e.id===t.agentId)&&Rt(t.agentId),Ge(!1)},F(r,(()=>{var e=j(()=>t.kind===`finish`);return()=>e()?`✅`:j(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),F(i,()=>t.title),F(a,()=>wf(new Date(t.at).toISOString())),F(n,O(A,{get when(){return t.body},get children(){var e=Cu();return F(e,()=>Cf(t.body,160)),e}}),null),y(e=>{var r=`notifitem `+t.kind,i=`from ${t.agentId}`;return r!==e.e&&P(n,e.e=r),i!==e.t&&N(n,`title`,e.t=i),e},{e:void 0,t:void 0}),n})()})),t}}),null),t}}),O(A,{get when(){return S()},get children(){return O(kf,{get providers(){return Object.keys(g().providers??{})},onClose:()=>te(!1),onCreated:e=>{te(!1),dt(),Rt(e)}})}}),O(A,{get when(){return ne()},get children(){return O(Bf,{get cfg(){return g()},onClose:()=>w(!1),onSaved:()=>{$e(),ht()}})}}),O(A,{get when(){return Be()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return O(Of,{title:`edit prompt — forks the conversation`,onClose:()=>Ve(null),get children(){var t=Eu(),i=t.firstChild,s=i.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:a()})}),Ve(null),dt();let t=n();t&&await Rt(t)}catch(e){alert(`edit failed: ${e.message}`)}}),F(t,O(A,{get when(){return r()>0},get children(){var e=Tu(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return F(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>Ve(null),y(()=>i.value=e().text),t}})}})]}function vf(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>Math.max(0,(n()-t)/1e3);return(()=>{var e=Du(),t=e.firstChild;return F(e,(()=>{var e=j(()=>i()<60);return()=>e()?`${i().toFixed(1)}s`:`${Math.floor(i()/60)}m ${Math.round(i()%60)}s`})(),t),e})()}function yf(e){let t=e.e,n=e.res,r=!e.agentActive&&!n,i=t.data??{},a=String(i.name??`tool`),o=()=>n?String(n.data?.result??``):``,s=a,c=``,l=(()=>{var e=Ou();return F(e,()=>Cf(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=(e,t=1500)=>(()=>{var n=ku();return F(n,()=>Cf(e,t)),n})(),f=(e=4e3)=>n?[j(()=>d(o(),e)),(()=>{var e=Au(),t=e.firstChild;return F(e,()=>n.data?.durationMs,t),F(e,()=>n.data?.ok===!1?` · FAILED`:``,null),F(e,O(Df,{get text(){return o()}}),null),e})()]:ju();try{switch(a){case`bash`:{let e=u(`command`);s=`$ `+Ef(e,96);let r=u(`timeout_ms`)?` · timeout ${Math.round(Number(u(`timeout_ms`))/1e3)}s`:``;c=n?`${n.data?.durationMs??`?`}ms${r}`:`running${r}`,l=[j(()=>j(()=>e!==s.slice(2))()?d(e,800):null),j(()=>f(6e3)),!n&&O(vf,{get startedAt(){return t.ts}})];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${Ef(u(`pattern`),40)}/`),Number(i.args?.offset)<0?e.push(`last ${-Number(i.args.offset)} lines`):i.args?.offset&&e.push(`from L${i.args.offset}`),i.args?.limit&&e.push(`≤${i.args.limit} lines`),c=e.join(` · `),l=f(6e3);break}case`write_file`:{let e=String(i.args?.content??``);s=u(`path`)||`(no path)`,c=`${Tf(e.length)} bytes`,l=[j(()=>d(e,1500)),j(()=>j(()=>e.length>1500)()?(()=>{var t=Mu(),n=t.firstChild;return F(t,()=>Tf(e.length),n),t})():null),n?(()=>{var e=Nu();return F(e,()=>Ef(o(),160)),e})():Pu()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=Fu();return F(e,()=>Cf(`- `+u(`old_text`),900)),e})(),(()=>{var e=Iu();return F(e,()=>`+ `+Cf(u(`new_text`),900)),e})(),n?(()=>{var e=Lu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,F(e,()=>Ef(o(),120),t),F(e,()=>n.data?.durationMs,r),e})():Ru()];break;case`apply_patch`:{let e=u(`patch`).split(`
26
- `).filter(e=>e&&!/^---$/.test(e.trim())),t=e.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);s=t.length?`${t.length} file${t.length>1?`s`:``}: ${Ef(t.join(`, `),80)}`:`patch`;let r=e.slice(0,60);l=[(()=>{var t=zu();return F(t,()=>r.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Bu();return P(n,`pline`+t),F(n,(()=>{var t=j(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),F(t,(()=>{var t=j(()=>e.length>60);return()=>t()?(()=>{var t=Vu(),n=t.firstChild.nextSibling;return n.nextSibling,F(t,()=>e.length-60,n),t})():null})(),null),t})(),n?(()=>{var e=Nu();return F(e,()=>Ef(o().split(`
27
- `)[0]??``,140),null),F(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Hu()];break}case`list_dir`:s=u(`path`)||`.`,l=f(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=Ef(e,70),c=`web`,l=[(()=>{var e=Nu();return F(e,O(A,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Wu();return F(e,()=>Ef(u(`url`),80)),e})()},get children(){var e=Uu();return y(()=>N(e,`href`,u(`url`))),e}})),e})(),j(()=>f(3e3))];break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=qc();return y(()=>t.innerHTML=Le(e)),t})(),(()=>{var e=Au(),t=e.firstChild;return F(e,()=>n.data?.durationMs,t),e})()]:Gu();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Ef(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[j(()=>j(()=>!!e.length)()?(()=>{var t=Ku();return t.firstChild,F(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Lu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,F(e,()=>Ef(o(),160),t),F(e,()=>n.data?.durationMs,r),e})():qu()];break}}}catch{}return(()=>{var e=Yu(),i=e.firstChild,o=i.firstChild;o.firstChild;var u=o.nextSibling;return N(e,`title`,`${a}${c?` — `+c:``}`),F(o,s,null),F(i,O(A,{get when(){return t.data?.actor},get children(){var e=Ju();return e.firstChild,F(e,()=>String(t.data.actor),null),e}}),u),F(u,n?c||``:r?`(result missed)`:`running…`),F(e,l,null),y(()=>P(e,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),e})()}function bf(e){let t=e.e,n=ff(t),r=e.prev&&e.prev.type===t.type&&ff(e.prev).name===n.name&&t.session===e.prev.session&&t.branch===e.prev.branch;if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Xu(),r=n.firstChild.nextSibling;return r.nextSibling,F(n,()=>String(e.fromBranch??`?`),r),F(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:Ef(String(e.text??``),80);return(()=>{var t=Zu(),r=t.firstChild.nextSibling;return r.nextSibling,F(t,()=>String(e.event??``),r),F(t,n,null),t})()}return t.type===`todo`?(()=>{var e=Qu(),n=e.firstChild.nextSibling;return n.nextSibling,F(e,()=>String(t.data?.by??`human`),n),e})():t.type===`state`?t.data.from===t.data.to?null:(()=>{var e=$u(),n=e.firstChild;return F(e,()=>t.data.from,n),F(e,()=>t.data.to,null),F(e,(()=>{var e=j(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>P(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})():(()=>{var i=id(),a=i.firstChild;return F(i,O(A,{when:!r,get fallback(){return ad()},get children(){var e=ed();return F(e,()=>n.icon),y(t=>{var r=n.color+`33`,i=`1px solid ${n.color}66`;return r!==t.e&&Oe(e,`background`,t.e=r),i!==t.t&&Oe(e,`border`,t.t=i),t},{e:void 0,t:void 0}),e}}),a),F(a,O(A,{when:!r,get children(){var r=rd(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return F(i,()=>n.name),F(r,O(A,{get when(){return t.data?.actor},get children(){var e=Ju();return e.firstChild,F(e,()=>String(t.data.actor),null),e}}),a),F(a,(()=>{var e=j(()=>!!t.data?.pending);return()=>e()?t.data?.sent===!0?`sent to model ✓`:`pending (queued)…`:mf(t.ts)})()),F(o,()=>t.branch),F(r,O(A,{get when(){return e.onCancel},get children(){var t=td();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),F(r,O(A,{get when(){return e.onEdit},get children(){var t=nd();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Oe(i,`color`,n.color)),r}}),null),F(a,O(Sf,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive}}),null),y(()=>P(i,`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``))),i})()}function xf(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=od(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&N(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function Sf(e){let t=e.e;switch(t.type){case`prompt`:return(()=>{var e=qc();return y(()=>e.innerHTML=rf(String(t.data.text??``))),e})();case`message`:return[O(A,{get when(){return j(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Kc(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return F(n,(()=>{var e=j(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Tf(String(t.data.reasoning).length)} — truncated)`:``})(),null),F(r,()=>Cf(String(t.data.reasoning),8e3)),e}}),(()=>{var e=qc();return y(()=>e.innerHTML=rf(String(t.data.content??``))),e})(),O(A,{get when(){return t.data.interrupted},get children(){return sd()}}),O(A,{get when(){return t.data.final},get children(){var e=cd(),n=e.firstChild;return F(e,O(Df,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return O(yf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=ld(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return F(i,()=>Ef(e,120)),F(r,O(Df,{text:e}),null),F(a,()=>Cf(e,4e3)),F(o,()=>t.data.durationMs,s),F(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>P(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=dd(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return F(n,O(A,{get when(){return e.length},get children(){var t=ud();return t.firstChild,F(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=rf(String(t.data?.decision??``)),r=rf(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 r=md(),a=r.firstChild;return a.firstChild,P(r,`embed question`+(i?` answered`:``)),F(a,()=>String(t.data?.question??``),null),F(r,O(A,{when:i,get children(){return fd()}}),null),F(r,O(A,{get when(){return n.length>0},get children(){var r=pd();return F(r,O(k,{each:n,children:n=>(()=>{var r=hd();return r.$$click=()=>{let r=t.data?.actor;r?$(`/api/agents/${encodeURIComponent(String(r))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},r.disabled=i,F(r,n),r})()})),r}}),null),F(r,O(xf,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=gd(),n=e.firstChild.firstChild.nextSibling;return F(e,O(A,{get when(){return t.data.goalStatus},get children(){var e=du(),n=e.firstChild.nextSibling;return F(n,()=>String(t.data.goalStatus)),e}}),null),F(e,O(A,{get when(){return t.data.recent},get children(){var e=cu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=rf(String(t.data.recent))),e}}),null),F(e,O(A,{get when(){return t.data.problems},get children(){var e=lu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=rf(String(t.data.problems))),e}}),null),F(e,O(A,{get when(){return t.data.next},get children(){var e=uu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=rf(String(t.data.next))),e}}),null),y(()=>n.innerHTML=rf(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=_d(),n=e.firstChild;return n.firstChild,F(n,()=>String(t.data.message??``),null),e})();default:return(()=>{var e=vd();return F(e,()=>Cf(JSON.stringify(t.data),200)),e})()}}function Cf(e,t){return e.length>t?e.slice(0,t)+` …`:e}function wf(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 Tf(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 Ef(e,t){return Cf(e.replace(/\s+/g,` `).trim(),t)}function Df(e){let[t,n]=v(!1);return(()=>{var r=yd();return r.$$click=t=>{t.stopPropagation(),navigator.clipboard.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),900)})},F(r,()=>t()?`✓`:`⧉`),r})()}function Of(e){return(()=>{var t=bd(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),F(r,()=>e.title),Ee(i,`click`,e.onClose,!0),F(n,()=>e.children,null),t})()}function kf(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}ee(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return O(Of,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Sd(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,te=C.firstChild.nextSibling,ne=C.nextSibling.firstChild.nextSibling,w=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),F(b,O(k,{get each(){return r()},children:e=>(()=>{var n=Cd();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),F(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),te.addEventListener(`change`,e=>c(e.currentTarget.value)),F(te,O(k,{get each(){return e.providers},children:e=>(()=>{var t=Kl();return F(t,e),t})()})),ne.$$input=e=>u(e.currentTarget.value),F(i,O(A,{get when(){return d()},get children(){var e=xd();return F(e,d),e}}),w),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>te.value=s()),y(()=>ne.value=l()),i}})}var Af=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),jf=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Mf=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Nf(e){let t=Pf(e);return t===`image`?`🖼`:t===`video`?`🎬`:t===`audio`?`🎵`:`·`}function Pf(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Af.has(t)?`image`:jf.has(t)?`video`:Mf.has(t)?`audio`:null}function Ff(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),l=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{}}));async function u(t){try{let n=await $(`/api/agents/${e.agentId}/tree${t?`?path=${encodeURIComponent(t)}`:``}`);return l(t,n.entries??[])}catch(e){return c(e.message),null}}b(()=>{e.agentId,i(new Set),n(new Map),u(``).then(e=>{e&&n(new Map([[``,e]]))})});let d=async e=>{let a=new Set(r());if(a.has(e.path)){a.delete(e.path),i(a);return}if(a.add(e.path),i(a),!t().has(e.path)){let t=await u(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[f,p]=v(``),[m,h]=v(!1),[g,_]=v(`code`),[x,S]=v(``),[ee,te]=v(!1),ne=e=>/\.(md|markdown|mdx)$/i.test(e),w=0,re=async e=>{let t=++w;p(``),h(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-CQYW-VF6.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(w!==t)return;p(e=>e+r)}}catch{w===t&&p(``)}finally{w===t&&h(!1)}};C(()=>{w++});let[T,ie]=v(null),ae=async(t,n)=>{let r=Pf(t.path);if(r){o({path:t.path,content:``,binary:!0}),ie({path:t.path,kind:r}),_(`media`);return}try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);ie(null),o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),S(r.content??``),_(r.binary?`code`:n),!r.binary&&n!==`md`&&re({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},oe=async()=>{let t=a();if(!(!t||ee())){te(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:x(),baseContent:t.content})}),o({...t,content:x()}),Q(`saved ${t.path}`)}catch(e){let t=e.message;t.includes(`409`)||t.includes(`changed on disk`)?Q(`file changed on disk — reopen to see the current version`):Q(`save failed: ${t}`)}finally{te(!1)}}},E=e=>!e.binary&&!e.truncated,se=(e,n)=>[(()=>{var t=Td(),i=t.firstChild,a=i.nextSibling;return t.$$click=()=>e.dir?void d(e):void ae(e,`code`),F(i,(()=>{var t=j(()=>!!e.dir);return()=>t()?r().has(e.path)?`▾`:`▸`:Nf(e.name)})()),F(a,()=>e.name),F(t,O(A,{get when(){return j(()=>!e.dir)()&&e.size!==void 0},get children(){var t=wd();return F(t,()=>Tf(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``),a=`padding-left:${n*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&P(t,r.e=i),r.t=De(t,a,r.t),o!==r.a&&N(t,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),t})(),O(A,{get when(){return j(()=>!!e.dir)()&&r().has(e.path)},get children(){return O(k,{get each(){return t().get(e.path)??[]},children:e=>se(e,n+1)})}})],ce=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace;return[(()=>{var e=Ed(),t=e.firstChild.nextSibling;return t.firstChild,F(t,ce,null),e})(),(()=>{var e=Dd();return F(e,O(A,{get when(){return(t().get(``)??[]).length>0},get fallback(){return(()=>{var e=Od();return F(e,()=>s()||`empty workspace`),e})()},get children(){return O(k,{get each(){return t().get(``)??[]},children:e=>se(e,0)})}})),e})(),O(A,{get when(){return a()},children:t=>O(Of,{get title(){return`🗂 ${t().path}`},onClose:()=>{w++,o(null),ie(null)},get children(){return O(A,{get when(){return T()},get fallback(){return[(()=>{var e=Nd(),n=e.firstChild;return F(e,O(A,{get when(){return j(()=>!!ne(t().path))()&&!t().binary},get children(){var e=jd();return e.$$click=()=>_(`md`),y(()=>P(e,g()===`md`?`on`:``)),e}}),n),n.$$click=()=>{_(`code`),f()||re({path:t().path,content:t().content,truncated:t().truncated})},F(e,O(A,{get when(){return E(t())},get children(){var e=Md();return e.$$click=()=>_(`edit`),y(()=>P(e,g()===`edit`?`on`:``)),e}}),null),y(()=>P(n,g()===`code`?`on`:``)),e})(),O(A,{get when(){return!t().binary},get fallback(){return Fd()},get children(){return O(A,{get when(){return g()===`edit`},get fallback(){return O(A,{get when(){return j(()=>g()===`md`)()&&ne(t().path)},get fallback(){return O(If,{get path(){return t().path},get content(){return t().content},get html(){return f()},get pending(){return m()},get truncated(){return!!t().truncated}})},get children(){var e=Id();return y(()=>e.innerHTML=Le(t().content)),e}})},get children(){var e=Pd(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>S(e.currentTarget.value),N(n,`spellcheck`,!1),F(r,()=>Tf(x().length),i),a.$$click=()=>void oe(),F(a,()=>ee()?`saving…`:`💾 save`),y(()=>a.disabled=ee()||x()===t().content),y(()=>n.value=x()),e}})}})]},get children(){var t=Ad(),n=t.firstChild,r=n.firstChild;return F(t,O(A,{get when(){return T().kind===`image`},get fallback(){return O(A,{get when(){return T().kind===`video`},get fallback(){return(()=>{var t=Rd();return y(()=>N(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(T().path)}`)),t})()},get children(){var t=Ld();return y(()=>N(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(T().path)}`)),t}})},get children(){var t=kd();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(T().path)}`,i=T().path.split(`/`).pop();return r!==n.e&&N(t,`src`,n.e=r),i!==n.t&&N(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),F(n,()=>T().kind,r),t}})}})})]}function If(e){return[O(A,{get when(){return e.html},get fallback(){return j(()=>!!e.pending)()?(()=>{var t=Vd(),n=t.firstChild.nextSibling;return n.nextSibling,F(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Hd();return F(t,()=>e.content),t})()},get children(){var t=zd();return y(()=>t.innerHTML=e.html),t}}),O(A,{get when(){return e.truncated},get children(){return Bd()}})]}var Lf=[{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)`}],Rf={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 zf(e){let[t,n]=v(Lf[0]),[r,i]=v(Lf[0].url),[a,o]=v(``),[s,c]=v(Lf[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);C(()=>clearTimeout(n))});let ee=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Tf(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},te=()=>ee(s()),ne=async t=>{t.preventDefault(),x(``),g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}};return(()=>{var e=Kd(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,ee=x.firstChild.nextSibling,C=x.nextSibling,w=C.firstChild.nextSibling,re=w.nextSibling,T=C.nextSibling,ie=T.firstChild.nextSibling,ae=ie.firstChild.nextSibling,oe=ie.nextSibling.firstChild.nextSibling,E=T.nextSibling;return n.addEventListener(`submit`,ne),F(u,()=>[...Lf,Rf].map(e=>(()=>{var n=qd();return n.$$click=()=>S(e),F(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),F(n,O(A,{get when(){return t().hint},get children(){var e=Ud();return F(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),F(b,()=>Lf.map(e=>(()=>{var t=Kl();return y(()=>t.value=e.url),t})())),ee.$$input=e=>o(e.currentTarget.value),w.$$input=e=>c(e.currentTarget.value),F(re,()=>l().map(e=>(()=>{var t=Kl();return y(()=>t.value=e.id),t})())),F(n,O(A,{get when(){return l().length>0},get fallback(){return Jd()},get children(){var e=Gd(),t=e.firstChild;return F(e,()=>l().length,t),F(e,O(A,{get when(){return te()},get children(){return[` · `,(()=>{var e=Wd();return F(e,te),e})()]}}),null),e}}),T),ae.$$input=e=>f(e.currentTarget.value),oe.$$input=e=>m(e.currentTarget.value),F(n,O(A,{get when(){return _()},get children(){var e=xd();return F(e,_),e}}),E),F(E,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(type to filter models from the endpoint)`,r=h();return n!==e.e&&N(w,`placeholder`,e.e=n),r!==e.t&&(E.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>ae.value=d()),y(()=>oe.value=p()),e})()}function Bf(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),[a,o]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[s,c]=v(e.cfg.progressMinChars??4e3),[l,u]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[d,f]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[p,m]=v(e.cfg.maxSpawnDepth??3),[h,g]=v((e.cfg.tasks??[]).map(e=>({...e}))),[_,b]=v(``),x=()=>(e.cfg.agents??[]).map(e=>e.id),S=()=>{let e={};for(let n of t()){if(!n.name.trim())return b(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return b(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},ee=async t=>{t.preventDefault(),b(``);let n=S();if(!n)return;let i=h().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of i){if(!e.agent){b(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){b(`task "${e.id}": schedule is required`);return}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,a())*6e4,progressMinChars:Math.max(100,s()),...l()==null?{}:{contextTokenBudget:Math.max(1,l())*1e3},...d()>0?{contextWindowTokens:d()*1e3}:{},maxSpawnDepth:Math.max(0,p()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){b(e.message)}},C=(e,t,n,r)=>(()=>{var i=Yd(),a=i.firstChild;return N(i,`title`,r),F(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return O(Of,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Xd(),b=v.firstChild,S=b.firstChild.nextSibling,te=S.nextSibling;te.firstChild;var ne=te.nextSibling.firstChild.firstChild.nextSibling;ne.firstChild;var w=b.nextSibling,re=w.firstChild.nextSibling,T=re.firstChild,ie=T.firstChild.nextSibling,ae=w.nextSibling,oe=ae.firstChild.nextSibling,E=ae.nextSibling;E.firstChild;var se=E.nextSibling;return v.addEventListener(`submit`,ee),F(b,O(k,{get each(){return t()},children:(e,r)=>(()=>{var i=Zd(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r()?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r()?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r()?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r()?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r())),y(()=>a.value=e.name),y(()=>o.value=e.baseUrl),y(()=>s.value=e.apiKey),y(()=>c.value=e.model),i})()}),S),S.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),F(te,O(k,{each:Lf,children:e=>(()=>{var a=Qd();return a.firstChild,a.$$click=()=>{let a=t().filter(t=>t.name!==e.key);n([...a,{name:e.key,baseUrl:e.url,apiKey:``,model:e.model}]),r()||i(e.key)},F(a,()=>e.label,null),y(()=>N(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),ne.addEventListener(`change`,e=>i(e.currentTarget.value)),F(ne,O(k,{get each(){return[...new Set(t().map(e=>e.name.trim()).filter(Boolean))]},children:e=>(()=>{var t=Kl();return t.value=e,F(t,e),t})()}),null),F(re,()=>C(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),T),F(re,()=>C(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),T),ie.$$input=e=>u(e.currentTarget.value===``?null:Number(e.currentTarget.value)),F(re,()=>C(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),F(re,()=>C(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),F(ae,O(A,{get when(){return h().length>0},get children(){return O(k,{get each(){return h()},children:(e,t)=>(()=>{var n=$d(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().map((n,r)=>r===t()?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e.id),y(()=>a.value=e.agent),y(()=>o.value=e.schedule),y(()=>c.checked=!!e.forked),y(()=>u.value=e.prompt),n})()})}}),oe),oe.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),F(E,O(k,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=tf(),n=t.firstChild,r=n.nextSibling;return F(n,()=>e.id),F(r,()=>e.workspace),F(t,O(A,{get when(){return e.parent},get children(){var t=ef();return t.firstChild,F(t,()=>e.parent,null),t}}),null),t})()}),null),F(v,O(A,{get when(){return _()},get children(){var e=xd();return F(e,_),e}}),se),y(()=>ne.value=r()),y(()=>ie.value=l()??``),v}})}Te([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),we(()=>O(_f,{}),document.getElementById(`root`));export{Pc as t};
28
- //# sourceMappingURL=index-C3s2ks00.js.map
21
+ - task two"title="shared with the agent — it may check items off via set_todo; your unsaved edits win until you save"style="width:100%;background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font-family:ui-monospace,Menlo,monospace;font-size:12.5px;resize:vertical">`),El=M(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><button class=iconbtn></button><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`),Dl=M(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),Ol=M(`<h3 title="cumulative billed totals · the cached pill counts tokens served from the provider's prompt cache (far cheaper) · context bar turns orange ≥70% and red ≥85% of the model window">📊 runtime`),kl=M(`<span class="pill ok">⚡ <!>% cached`),Al=M(`<div class="card runcard"><div class=statgrid><div class=stat title="LLM turns taken this session"><span>turns</span><b></b></div><div class=stat title="tool calls executed"><span>tools</span><b></b></div><div class=stat title="times old turns were summarized to free context"><span>compacted</span><b></b></div></div><div class=statrow><span class=k>tokens</span><b> in / <!> out`),jl=M(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),Ml=M(`<h3>⏰ schedule <span class=muted style=text-transform:none;letter-spacing:0>· cron tasks, all agents · edit in settings`),Nl=M(`<div><nav class=sidebar><div class=agent-list></div><div class=sidebar-footer><div class=footer-row style=justify-content:flex-end><span></span><button>🔔</button><button class=iconbtn title="new agent">+</button><button class=iconbtn title=themes>🎨</button><button class=iconbtn title=settings>⚙</button></div><div class=brand-row><div class=brand>🫖 teapot <span class=version>v</span></div></div><div class=metrics></div></div></nav><section class=channel></section><aside>`),Pl=M(`<button class=editbtn>clear all`),Fl=M(`<div class=notiflist>`),Il=M(`<div class=notifpanel><div class=notifhead>notifications`),Ll=M(`<span class=caret>`),Rl=M(`<span class=subtag>🧩`),zl=M(`<span class=mini-cron>⏰`),Bl=M(`<span title="goal done">✓`),Vl=M(`<div><span></span><span>`),Hl=M(`<span class=caret-spacer>`),Ul=M(`<span>🧩 `),Wl=M(`<label class=trow>system light →<select class=w100>`),Gl=M(`<label class=trow>system dark →<select class=w100>`),Kl=M(`<option>`),ql=M(`<button><span class=swdots>`),Jl=M(`<i>`),Yl=M(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),Xl=M(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),Zl=M(`<div class="content muted">thinking…`),Ql=M(`<span>⌨ <button class=tabx title="close this shell">✕`),$l=M(`<div><b class=mono></b><span class=muted>`),eu=M(`<div class=cmdrow><b>@</b><span class=muted>`),tu=M(`<button class=runbtn title="run toward the goal (starts the loop)">▶ start`),nu=M(`<span class=badge title="no goal set yet">no goal`),ru=M(`<button>`),iu=M(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),au=M(`<div><div class=vtitle><span class="meta muted"style=margin-left:auto></span></div><div class=content>`),ou=M(`<div class="content mdpreview"style="max-height:40vh;padding:8px 10px">`),su=M(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),cu=M(`<div class=progrow><b>recent</b><span class="content inline-md">`),lu=M(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),uu=M(`<div class=progrow><b>next</b><span class="content inline-md">`),du=M(`<div class=progrow><b>goal</b><span>`),fu=M(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),pu=M(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),mu=M(`<span>% of `),hu=M(`<div class=bartrack><div>`),gu=M(`<div class=bartrack style=margin-top:4px><div>`),_u=M(`<div class=ctxblock title="estimated live context vs the model's real window. Past the window, old turns are summarized into notes (compaction); the compact line below shows where that starts."><div class=statrow><span class=k>context</span><b>~<!> tok</b></div><div class=statrow style=margin-top:4px><span class=k>compact</span><b> tok</b><span class=muted style=font-size:11px;color:var(--dim)></span></div><div class=ctrlrow style=margin-top:6px><label title="when on, older turns are automatically summarized when context exceeds the budget"><input type=checkbox>auto-compact</label><span class=muted style=font-size:11.5px>summarizes old turns when budget exceeded</span></div><div class=muted style=font-size:11px;margin-top:4px>compaction starts around ~<!> tok — older turns get summarized, recent ones stay intact`),vu=M(`<div><span></span><span> events`),yu=M(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),bu=M(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),xu=M(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class="sched-meta mono"> → next </div><div class="sched-prompt muted">`),Su=M(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),Cu=M(`<div class=nbody>`),wu=M(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted">`),Tu=M(`<div><div style=font-size:12.5px;margin-bottom:4px> event(s) came after this prompt — what should happen to them on the new branch?</div><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>summarize them into a note the agent can still read</label><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>discard them entirely (clean timeline)`),Eu=M(`<form style=display:flex;flex-direction:column;gap:10px><textarea id=edit-text class="mono w100"rows=6></textarea><div style=display:flex;justify-content:flex-end;gap:8px><button type=button>cancel</button><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 12px;cursor:pointer">⑂ fork & resend`),Du=M(`<span class=bashelapsed>running… `),Ou=M(`<span class=bashelapsed> elapsed`),ku=M(`<div class=mono>`),Au=M(`<pre class="mono toolbody">`),ju=M(`<div class=meta>ms`),Mu=M(`<div class=meta>waiting for output…`),Nu=M(`<div class="meta muted"> bytes — open it from 🗂 files for the full view`),Pu=M(`<div class=meta>`),Fu=M(`<div class=meta>writing…`),Iu=M(`<pre class="mono toolbody del">`),Lu=M(`<pre class="mono toolbody add">`),Ru=M(`<div class=meta> · <!>ms`),zu=M(`<div class=meta>applying…`),Bu=M(`<pre class="mono toolbody patch">`),Vu=M(`<div>`),Hu=M(`<div class="pline meta">… <!> more lines`),Uu=M(`<div class=meta>validating…`),Wu=M(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),Gu=M(`<span class=muted>`),Ku=M(`<div class=meta>loading…`),qu=M(`<div class=meta>bundled: `),Ju=M(`<div class=meta>saving…`),Yu=M(`<span class=actor>@`),Xu=M(`<details><summary><b>⚙ </b><span class=meta>`),Zu=M(`<div class=divider-msg>⑂ forked from <!> → `),Qu=M(`<div class=divider-msg>🎯 goal <!>: `),$u=M(`<div class=divider-msg>✅ tasks updated (<!>)`),ed=M(`<div> → `),td=M(`<div class=avatar>`),nd=M(`<button class=editbtn title="withdraw this message — it has not reached the model yet; the text goes back to the input box">✕ cancel`),rd=M(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),id=M(`<div class=msg-head><span class=author></span><span class=ts></span><span class=ts>`),ad=M(`<div><div class=msg-body>`),od=M(`<span style=width:38px>`),sd=M(`<div class=qfree><input type=text><button>reply`),cd=M(`<div class=interrupted>⚠ interrupted — partial output kept`),ld=M(`<div class=msgfoot><span>copy summary`),ud=M(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>ms`),dd=M(`<div class="content muted">Rejected: `),fd=M(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged</span></summary><div class=content>`),pd=M(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),md=M(`<div class=qopts>`),hd=M(`<div><div>❓ `),gd=M(`<button class=qopt>`),_d=M(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),vd=M(`<div class="embed fail"><div class=mono>⚠ `),yd=M(`<div class="content muted">`),bd=M(`<button class=copybtn title="copy to clipboard">`),xd=M(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),Sd=M(`<span style=color:var(--err);font-size:13px>`),Cd=M(`<form style=display:flex;flex-direction:column;gap:10px><label>workspace directory<div style=display:flex;gap:6px><input type=text class="w100 mono"><button type=button>go</button><button type=button 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>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`),wd=M(`<div class=direntry>📁 `),Td=M(`<span class=fsize>`),Ed=M(`<div><span class=ficon></span><span class=fname>`),Dd=M(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview">🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),Od=M(`<div class=filebox>`),kd=M(`<div class=muted style=padding:6px>`),Ad=M(`<img>`),jd=M(`<div class=mediapreview><div class="meta muted"> preview`),Md=M(`<button title="rendered markdown">👁 preview`),Nd=M(`<button title="edit and save back to the workspace">✎ edit`),Pd=M(`<div class=filetoolbar><button title="syntax-highlighted source">&lt;/> code`),Fd=M(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Id=M(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Ld=M(`<div class="content mdpreview">`),Rd=M(`<video controls>`),zd=M(`<audio controls>`),Bd=M(`<div class=filepreview>`),Vd=M(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),Hd=M(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),Ud=M(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),Wd=M(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),Gd=M(`<span style=color:var(--fg)>`),Kd=M(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),qd=M(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>default model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),Jd=M(`<button type=button>`),Yd=M(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),Xd=M(`<label><input type=number min=0>`),Zd=M(`<form style=display:flex;flex-direction:column;gap:14px><fieldset><legend>providers</legend><button type=button>+ add custom</button><div style=display:flex;gap:6px;flex-wrap:wrap;margin-top:6px><span class=muted style=font-size:11.5px>quick-add:</span></div><div><label title="agents without an explicit provider use this one"style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<select><option value>(none — first provider wins)</option></select></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid><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><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`),Qd=M(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="api key"type=password><input placeholder="default model"><button type=button class=danger title="remove provider">✕`),$d=M(`<button type=button>+ `),ef=M(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),tf=M(`<span class=muted>🧩 sub of @`),nf=M(`<div class=cfgrow><b></b><span class=muted>`),rf=new Map;function af(e){let t=rf.get(e);if(t!==void 0)return t;let n=Le(e);return rf.set(e,n),rf.size>500&&rf.delete(rf.keys().next().value),n}var of={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`}},sf={name:`harness`,icon:`📣`,color:`#3ba55d`},[cf,lf]=v(``),uf,Q=e=>{lf(e),clearTimeout(uf),uf=setTimeout(()=>lf(``),3200)},df=[{key:`dark`,label:`Dark`,mode:`dark`,sw:[`#1a1c22`,`#2b2e39`,`#5865f2`]},{key:`midnight`,label:`Midnight`,mode:`dark`,sw:[`#0d0f18`,`#252a42`,`#8b7cf7`]},{key:`tea`,label:`Milk Tea`,mode:`dark`,sw:[`#241c16`,`#493b2d`,`#d98e32`]},{key:`coffee`,label:`Coffee`,mode:`dark`,sw:[`#191410`,`#403527`,`#c68a4b`]},{key:`matcha`,label:`Matcha`,mode:`dark`,sw:[`#1b2217`,`#3c4a33`,`#8db64e`]},{key:`matrix`,label:`Matrix`,mode:`dark`,sw:[`#060a06`,`#18301d`,`#2fd558`]},{key:`sunset`,label:`Sunset`,mode:`dark`,sw:[`#1c1422`,`#452f52`,`#f2784b`]},{key:`light`,label:`Light`,mode:`light`,sw:[`#eceef4`,`#ffffff`,`#4757d8`]},{key:`strawberry`,label:`Strawberry`,mode:`light`,sw:[`#fbe4ea`,`#fffafb`,`#e05575`]},{key:`ramune`,label:`Ramune`,mode:`light`,sw:[`#ddeff7`,`#fbfeff`,`#1d86ae`]}];function ff(){let e=``,t=``;try{let n=getComputedStyle(document.documentElement);e=n.getPropertyValue(`--term-bg`).trim(),t=n.getPropertyValue(`--term-fg`).trim()}catch{}return{background:e||`#0d0e12`,foreground:t||`#dcdee4`}}var pf=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`?of.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:sf}return of[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},mf=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`]),hf=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=``;try{t=(await i.json())?.error??``}catch{}throw Error(t||`${e}: HTTP ${i.status}`)}return i.json()}var gf=location.hash.match(/[#&]token=([^&]+)/);gf&&(localStorage.setItem(`teapot.token`,decodeURIComponent(gf[1])),history.replaceState(null,``,location.pathname+location.search));var _f=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function vf(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v([]),[o,s]=v(0),[c,l]=v([]),[u,d]=v(null),f=new Map,[p,m]=v(f.get(n()??``)??``),h=e=>{m(e);let t=n();t&&(e?f.set(t,e):f.delete(t))},[g,_]=v({providers:{}}),[S,te]=v(!1),[ne,w]=v(!1),[re,T]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>1100:localStorage.getItem(`teapot.panel`)===`1`),ie=()=>{let e=!re();T(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},[ae,oe]=v(!1),[E,se]=v(localStorage.getItem(`teapot.theme`)??`dark`),[ce,le]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[ue,de]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[fe,pe]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),D=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[me,he]=v(D?.matches??!1);ee(()=>{let e=e=>he(e.matches);D?.addEventListener(`change`,e),C(()=>D?.removeEventListener(`change`,e))}),b(()=>{let e=ce()?me()?ue():fe():E();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=df.find(t=>t.key===e)?.mode??`dark`});let[ge,_e]=v(``),[ve,ye]=v(``),[be,xe]=v([]),Se=()=>Object.keys(g().providers??{});async function Ce(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);xe(t.models??[])}catch{xe([])}}let we=()=>{let e=ve().trim()||I()?.model||``;if(!e)return``;let t=be().find(t=>t.id===e);if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Ef(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)};b(()=>{let t=n(),r=e().find(e=>e.id===t),i=r?.provider||g().defaultProvider||Se()[0]||``;r&&(ge()!==i&&(_e(i),Ce(i)),ve()&&ye(``))});let[M,Te]=v(!1),[Ae,je]=v(!0),[Me,Ne]=v(0),[Pe,Fe]=v(null),[Ie,Re]=v(``),ze;b(()=>{if(!Pe()){clearTimeout(ze),ze=void 0,Re(``);return}ze||=setTimeout(()=>{ze=void 0,Re(Pe()?.text??``)},(Pe()?.text.length??0)>2e4?250:(Pe()?.text.length??0)>6e3?120:60)}),C(()=>clearTimeout(ze)),b(()=>{Ie()&&Ae()&&requestAnimationFrame(()=>{Ae()&&Lt(!0)})}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{It()&&(je(!0),Ne(0),Lt(!0))})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let I=x(()=>e().find(e=>e.id===n())),[Be,Ve]=v(null);x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let[He,Ue]=v([]),[L,R]=v([]),[We,Ge]=v(!1),Ke=()=>L().filter(e=>!e.read).length,qe=0,Je=e=>{R(t=>[{...e,id:`n${++qe}`,at:Date.now(),read:!1},...t].slice(0,50))},Ye=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t;n.type===`message`&&n.data?.final===!0?Je({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300)}):n.type===`question`?Je({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300)}):n.type===`error`?Je({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300)}):n.type===`progress`&&Je({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)})},Xe=x(()=>{let e=new Map,t=new Set,n=new Map;for(let r of i())if(mf.has(r.type)){if(r.type===`tool_call`){let e=n.get(r.data.callId)??[];e.push(r),n.set(r.data.callId,e)}else if(r.type===`tool_result`){let i=n.get(r.data.callId)?.shift();i&&(e.set(i.id,r),t.add(r.id))}}return{resFor:e,consumed:t}}),Ze=x(()=>{let e=new Set,t=-1,n=-1;for(let e of i())e.type===`question`?t=e.seq:e.type===`prompt`&&e.data?.source===`user`?n=e.seq:e.type===`system_note`&&e.data?.event===`prompt-delivered`&&(n=Math.max(n,e.seq));if(t>=0&&n>t)for(let t of i())t.type===`question`&&t.seq<=n&&e.add(String(t.data?.callId??``));return e}),Qe=x(()=>{let{consumed:e}=Xe(),t=i().filter(t=>{if(!mf.has(t.type))return!1;let n=t.type===`tool_call`||t.type===`tool_result`?String(t.data?.name??``):``;return n===`report_progress`||n===`ask_user`?!1:t.type===`tool_result`?!e.has(t.id):t.type===`message`?t.data?.progressEcho?!1:String(t.data?.content??``).trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final:!0}),n=[];for(let e of t)if(e.type===`sub`){let t=e.data,r=String(t?.type??`message`);if(r===`state`)continue;n.push({...e,type:r,data:{...t?.data,actor:t?.sub}})}else n.push(e);let r=e=>String(e??``).replace(/\s+/g,` `).trim().toLowerCase(),a=[];for(let e=0;e<n.length;e++){let t=n[e];if(t.type===`message`&&t.data?.role===`assistant`){let i=n[e-1],a=r(t.data.content);if(i?.type===`progress`){let e=i.data;if((a.includes(r(e.doing))||e.recent&&a.includes(r(e.recent)))&&a.length<=Math.max(200,r(e.doing).length*3))continue}if(i?.type===`decision`){let e=i.data,t=r(e.decision);if(t&&a.includes(t)&&a.length<=Math.max(300,t.length*3))continue}}a.push(t)}let o=He().filter(e=>!a.some(t=>t.type===`prompt`&&t.data?.source===`user`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)).map(e=>({id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:I()?.session??``,branch:I()?.branch??`br0`,parent:null,type:`prompt`,data:{source:`user`,text:e.text,pending:!e.sent,...e.promptId?{promptId:e.promptId}:{}}}));return[...a,...o]}),$e=()=>$(`/api/config`).then(_).catch(()=>{}),[et,tt]=v(!1);ee(()=>{let e=()=>tt(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[nt,rt]=v(``),[it,at]=v(!1),[ot,st]=v(!1),ct=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==ct?(ct=t,st(!1),rt(r)):t&&!ot()&&rt(r)});let lt=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:nt(),notify:e})}),st(!1),Q(`tasks saved${e&&nt().trim()?` & notification queued`:``}`),dt()}catch(e){Q(`save failed: ${e.message}`)}},ut=x(()=>{let e=0,t=0;for(let n of nt().split(`
22
+ `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),dt=()=>$(`/api/agents`).then(e=>t(t=>{let n=new Map(t.map(e=>[e.id,e]));return(e.agents??[]).map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})})).catch(()=>{}),ft=()=>$(`/api/metrics`).then(d).catch(()=>{}),[pt,mt]=v([]),ht=()=>$(`/api/tasks`).then(e=>mt(e.tasks)).catch(()=>{}),gt=e=>pt().filter(t=>t.agent===e),[_t,vt]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),yt=e=>{let t=new Set(_t());t.has(e)?t.delete(e):t.add(e),vt(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},bt=x(()=>{let t=e(),n=new Map,r=[];for(let e of t)e.parent&&t.some(t=>t.id===e.parent)?(n.has(e.parent)||n.set(e.parent,[]),n.get(e.parent).unshift(e)):r.push(e);let i=[],a=(e,t)=>{for(let r of e){i.push({a:r,depth:t});let e=n.get(r.id);e?.length&&!_t().has(r.id)&&a(e,t+1)}};return a(r,0),i}),[xt,St]=v(null),Ct=new Map;function wt(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=Ct.get(r.id);if(t[n]=i??r,!i&&(Ct.set(r.id,r),Ct.size>3e3)){let e=Ct.keys().next().value;e!==void 0&&Ct.delete(e)}}return t}let[Tt,Et]=v(!1),[Dt,Ot]=v(!1),kt=0,At=-1;function jt(e){a(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of wt(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function Mt(){let e=n(),t=i()[0];if(!(!e||!t||Tt()||Dt())){Et(!0);try{let r=Pt(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=xt(),c=(await $(`/api/agents/${e}/events?limit=300&before=${encodeURIComponent(t.id)}${s?`&branch=${encodeURIComponent(s)}`:``}`)).events??[];if(c.length===0){Ot(!0);return}if(n()!==e||i()[0]?.id!==t.id)return;jt(c),requestAnimationFrame(()=>{if(n()===e){let e=Pt();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{Et(!1)}}}async function Nt(e){let t=kt;try{let r=xt(),i=t!==At||!c().length,[o,u,d]=await Promise.all([$(`/api/agents/${e}/events?limit=300${r?`&branch=${encodeURIComponent(r)}`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:c()}),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(i&&(At=t),t!==kt||n()!==e)return;a(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of wt(o.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),s(o.total??o.events.length),l(u.branches),kn(d.skills??[])}catch{}}function Pt(){return document.querySelector(`.feed`)}function Ft(){let e=document.querySelector(`.composer textarea`);return 80+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function It(){let e=Pt();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<Ft()}function Lt(e=!1){let t=Pt();t&&(e||Ae())&&(t.scrollTop=t.scrollHeight,Ne(0))}async function Rt(e,t=!0){let i=n();kt++,i!==e&&(a([]),Ct.clear(),Fe(null),Ne(0)),r(e),h(f.get(e)??``),St(null),Ot(!1),Et(!1),Ue([]),localStorage.setItem(`teapot.session`,e),qt(e,t),$(`/api/agents/${e}/load`,{method:`POST`}).then(dt).catch(()=>{}),await Nt(e),n()===e&&requestAnimationFrame(()=>{n()===e&&Lt(!0)})}let[zt,Bt]=v(!1),Vt=null,Ht=null;C(()=>Vt?.close());let Ut=!1,Wt=null;document.addEventListener(`visibilitychange`,()=>Wt?.()),C(()=>{Wt=null});function Gt(){let e=location.protocol===`https:`?`wss://`:`ws://`;Vt=new WebSocket(`${e}${location.host}/api/ws${_f()}`),Vt.onopen=()=>Bt(!0),Vt.onclose=()=>{Bt(!1),setTimeout(Gt,1500)},Vt.onerror=()=>Vt?.close();let r=new Set([`state`,`usage`,`session_start`]),a=null;Vt.onmessage=e=>{let i=JSON.parse(e.data);if(i.kind!==`ping`&&i.kind!==`pong`){if(i.kind===`llm-delta`){a={id:i.agentId,at:Date.now()},i.agentId===n()&&Fe({text:i.text??``,reasoning:i.reasoning??``});return}if(i.kind===`agent-update`&&i.snapshot){t(e=>{let t=e.findIndex(e=>e.id===i.snapshot.id),n=i.snapshot;if(t===-1)return[...e,n];let r=e[t];return JSON.stringify(r)===JSON.stringify(n)?e:e.map((e,r)=>r===t?n:e)});return}if(i.kind===`event`){let e=i.event?.type,t=i.event?.data??{};if(e===`system_note`&&t.event===`prompt-delivered`&&i.agentId===n()){Ue(e=>e.map(e=>e.promptId===t.promptId?{...e,sent:!0}:e));return}if(e===`system_note`&&t.event===`prompt-cancelled`&&i.agentId===n()){Ue(e=>e.filter(e=>e.promptId!==t.promptId));return}if(r.has(e)||(Ye(i.agentId,i.event),i.event?.agent!==n()))return}if(document.visibilityState===`hidden`){Ut=!0,Ht||=setTimeout(s,2e3);return}Ht||=setTimeout(s,400)}},Ut=!1;let s=async()=>{if(Ht=null,await dt(),await ft(),n()){let e=i().at(-1)?.id,t=o(),r=Date.now();await Nt(n()),i().at(-1)?.id!==e&&(a?.id===n()&&a.at>=r||Fe(null),It()?Lt(!0):Ne(Me()+Math.max(0,o()-t))),Ue(e=>e.filter(e=>!i().some(t=>t.type===`prompt`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)))}};Wt=()=>{document.visibilityState===`visible`&&Ut&&(Ut=!1,Ht||=setTimeout(s,150))}}let Kt=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function qt(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let t=Kt();t&&e().some(e=>e.id===t)&&t!==n()&&Rt(t,!1)}),b(()=>{let e=I(),t=e?`${e.status===`running`?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=Ke()>0?`(${Ke()}) ${t}`:t}),window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)){e.key===`Escape`&&t.blur();return}if(e.key===`Escape`){if(S()){te(!1);return}if(ne()){w(!1);return}if(Be()){Ve(null);return}if(ae()){oe(!1);return}let e=I();if(e?.status===`running`){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(dt);return}re()&&window.innerWidth<=1100&&T(!1);return}if(!(S()||ne())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)ie();else if(e.key===`t`)Xt();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=bt().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&&Rt(t[i].id)}}});let[Jt,Yt]=v(localStorage.getItem(`teapot.term`)===`1`),Xt=()=>{let e=!Jt();Yt(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[Zt,Qt]=v([]),[$t,en]=v(0),[tn,z]=v(-1),[nn,rn]=v(!1),[B,an]=v(0),[on,sn]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),V=new Map,cn=[null,null],ln=()=>Zt()[B()===0?$t():tn()]??null;function un(e){if(!Zt()[e])return;let t=B()===0?$t:tn;(B()===0?tn:$t)()===e&&(B()===0?z(t()):en(t())),t()===e||(B()===0?en(e):z(e))}let dn=()=>fn();function fn(e){let t=e??n();if(!t)return;let r=Zt().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}Zt().length+1;let i=r===0?{key:`${t}`,agentId:t,title:t}:{key:`${t}#${r+1}`,agentId:t,title:`${t}·${r+1}`};Qt(e=>[...e,i]),B()===0?en(Zt().length):z(Zt().length)}function pn(e){let t=Zt()[e];if(!t)return;let n=V.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),V.delete(t.key)}let r=Zt().filter((t,n)=>n!==e);Qt(r);let i=t=>t===e?-1:t>e?t-1:t;en(e=>Math.min(i(e),r.length-1)),z(e=>e===-1?-1:Math.min(i(e),r.length-1))}function mn(){for(let[,e]of V){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}V.clear()}function hn(e,t){let n=V.get(e.key);if(n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new Dc({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:ff()}),a=new Ac;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${_f()}`);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},V.set(e.key,n)}return n}function gn(e){let t=cn[e];if(!t)return;let n=Zt()[e===0?$t():tn()];if(!n){[...V.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=hn(n,t);requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(B()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{if(!Jt())return;let e=n();if(e){if(!Zt().some(t=>t.agentId===e)&&Zt().length===0)fn(e);else if(!Zt().some(t=>t.agentId===e)){let t=Zt().findIndex(t=>t.agentId===e);t>=0&&un(t)}}});let _n=e=>{e.preventDefault();let t=e.clientY,n=on(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));sn(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(on())),requestAnimationFrame(()=>{gn(0),nn()&&gn(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},vn=()=>{let e=!nn();if(rn(e),e&&tn()===-1){let e=Zt().findIndex((e,t)=>t!==$t());z(e>=0?e:-1)}};C(mn);let yn=e=>t=>{cn[e]=t};ee(()=>{$e(),dt().then(()=>{let t=Kt()||localStorage.getItem(`teapot.session`)||``,n=e().find(e=>e.id===t)??e()[0];n&&Rt(n.id,!1)}),ft(),ht(),H(),Gt();let t=setInterval(()=>{ft(),ht()},3e4);C(()=>clearInterval(t))});let bn=[{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`}],[xn,Sn]=v([]),H=()=>$(`/api/personas`).then(e=>Sn(e.personas)).catch(()=>{}),[Cn,wn]=v(!1),Tn=()=>{let e=p().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},En=()=>{let t=Tn();return t===null?[]:[...xn().map(e=>({key:e.key,label:`${e.label} — spawns a sub-agent`,kind:`persona`})),...e().filter(e=>e.id!==n()).map(e=>({key:e.id,label:`${e.status} — send directly`,kind:`agent`}))].filter(e=>e.key.toLowerCase().startsWith(t))},Dn=new Set([`start`,`stop`,`fork`,`compact`]),[On,kn]=v([]),[An,jn]=v(-1),Mn=()=>{let e=p();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[3]??``).trim();if(!r&&n!==`skill`){let e=bn.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Dn.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=On().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[]},Nn,Pn=()=>{if(!Nn)return;Fn=!0;let e=Ae();Nn.style.height=`auto`,Nn.style.height=M()?``:`${Math.min(Nn.scrollHeight,360)}px`,requestAnimationFrame(()=>{let t=Pt();e&&t&&(t.scrollTop=t.scrollHeight),Fn=!1})},Fn=!1;b(()=>{p(),Pn()});let In=async(e,t)=>{let r=t??n();if(r)try{let t=await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0})});Ue(n=>[...n,{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now(),promptId:t.promptId}]),requestAnimationFrame(()=>requestAnimationFrame(()=>Lt(!0)))}catch(t){h(e),console.error(`send failed:`,t)}},Ln=async t=>{t.preventDefault();let r=n(),i=p().trim();if(!(!r||!i)){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=xn().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:Cn()?`fork`:`none`})})).id}${Cn()?` (forked context)`:``}`),dt(),h(``)}else if(s){if(!a){Q(`usage: @${r} <message>`);return}await $(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),Q(`→ delivered to @${r}`),h(``)}else{Q(`unknown @${r} — personas: ${xn().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}return}if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim();if(t===`goal`&&!n){h(`/goal `);return}if(t===`skill`&&!n){h(`/skill `);return}h(``),await Rn(t,n);return}h(``),await In(i)}},Rn=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(dt);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Rt(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 In(`[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}`)}},zn,Bn=0;b(()=>{e(),requestAnimationFrame(()=>{zn&&(Bn=Math.min(Bn,zn.scrollHeight),zn.scrollTop=Bn)})});let Vn=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(dt),Hn=async e=>{e.preventDefault();let t=document.getElementById(`goal-input`),r=document.getElementById(`goal-verify-input`),i=document.getElementById(`goal-notify`)?.checked??!0;!n()||!t.value.trim()||(await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t.value,notify:i,...r?.value.trim()?{verify:r.value}:{}})}),t.value=``,r&&(r.value=``),dt())};return[O(A,{get when(){return g()?.needsSetup},fallback:null,get children(){return O(Bf,{onDone:()=>location.reload()})}}),O(A,{get when(){return et()},get children(){var e=Fc();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),O(A,{get when(){return!g()?.needsSetup},get children(){var o=Nl(),s=o.firstChild,l=s.firstChild,d=l.nextSibling,f=d.firstChild,m=f.firstChild,_=m.nextSibling;_.firstChild;var v=_.nextSibling,b=v.nextSibling,x=b.nextSibling,S=f.nextSibling,ee=S.firstChild.firstChild.nextSibling;ee.firstChild;var C=S.nextSibling,ne=s.nextSibling,T=ne.nextSibling;F(l,O(k,{get each(){return bt()},children:({a:t,depth:r})=>(()=>{var i=Vl(),a=i.firstChild,o=a.nextSibling;return i.$$click=()=>Rt(t.id),F(i,O(A,{get when(){return e().some(e=>e.parent===t.id)},get fallback(){return Hl()},get children(){var e=Ll();return e.$$click=e=>{e.stopPropagation(),yt(t.id)},F(e,()=>_t().has(t.id)?`▸`:`▾`),y(()=>N(e,`title`,_t().has(t.id)?`expand sub-agents`:`collapse sub-agents`)),e}}),a),F(o,()=>t.id),F(i,O(A,{get when(){return _t().has(t.id)},get children(){return(()=>{let n=e().filter(e=>e.parent===t.id),r=n.filter(e=>e.status===`running`||e.status===`waiting`).length;return n.length>0?(()=>{var e=Ul();return e.firstChild,P(e,`subcount`+(r>0?` live`:``)),F(e,()=>n.length,null),F(e,r>0?` · ▶${r}`:``,null),y(()=>N(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),F(i,O(A,{get when(){return t.parent},get children(){return Rl()}}),null),F(i,O(A,{get when(){return gt(t.id).length>0},get children(){var e=zl();return y(()=>N(e,`title`,gt(t.id).map(e=>`${e.id}: ${e.schedule}`).join(`
24
+ `))),e}}),null),F(i,O(A,{get when(){return t.goal.status===`done`},get children(){return Bl()}}),null),y(e=>{var o=`agent-item`+(t.id===n()?` sel`:``)+(r>0?` sub-row`:``),s=r>0?`padding-left:${10+r*14}px`:``,c=t.parent?`sub-agent of @${t.parent}`:void 0,l=`dot ${t.status}`;return o!==e.e&&P(i,e.e=o),e.t=De(i,s,e.t),c!==e.a&&N(i,`title`,e.a=c),l!==e.o&&P(a,e.o=l),e},{e:void 0,t:void 0,a:void 0,o:void 0}),i})()})),F(d,O(A,{get when(){return ae()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;le(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),F(e,O(A,{get when(){return!ce()},get fallback(){return[(()=>{var e=Wl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),F(t,O(k,{get each(){return df.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=Kl();return F(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ue()),e})(),(()=>{var e=Gl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{pe(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),F(t,O(k,{get each(){return df.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=Kl();return F(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=fe()),e})()]},get children(){var e=Ic();return F(e,O(k,{each:df,children:e=>(()=>{var t=ql(),n=t.firstChild;return t.$$click=()=>{se(e.key),localStorage.setItem(`teapot.theme`,e.key)},F(n,()=>e.sw.map(e=>(()=>{var t=Jl();return Oe(t,`background`,e),t})())),F(t,()=>e.label,null),y(n=>{var r=`themebtn`+(E()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&P(t,n.e=r),i!==n.t&&N(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ce()),e}}),f),_.$$click=()=>{Ge(!We()),R(e=>e.map(e=>({...e,read:!0})))},F(_,O(A,{get when(){return Ke()>0},get children(){var e=Rc();return F(e,Ke),e}}),null),v.$$click=()=>{$e(),te(!0)},b.$$click=()=>oe(!ae()),x.$$click=()=>{$e(),w(!0)},F(ee,`0.16.0`,null),F(C,O(A,{get when(){return u()},get children(){return[`master rss `,j(()=>u().rssMb),`MB · heap `,j(()=>u().heapUsedMb),`MB`,zc(),`load1 `,j(()=>u().loadavg1),` · up `,j(()=>Math.floor(u().uptimeSec/60)),`m`]}})),F(ne,O(A,{get when(){return I()},get fallback(){return Yl()},get children(){return[(()=>{var e=Uc(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling;s.nextSibling;var c=r.nextSibling,l=c.firstChild,u=l.nextSibling;return F(t,()=>I().id),F(n,()=>I().status),F(e,O(A,{get when(){return(I().pendingPrompts??0)>0},get children(){var e=Bc(),t=e.firstChild.nextSibling;return t.nextSibling,F(e,()=>I().pendingPrompts,t),y(()=>N(e,`title`,`${I().pendingPrompts??0} message${(I().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),F(e,O(A,{get when(){return gt(I().id).length>0},get children(){var e=Vc();return e.firstChild,F(e,()=>gt(I().id).length,null),y(()=>N(e,`title`,`scheduled tasks:\n${gt(I().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
25
+ `)}`)),e}}),r),F(r,()=>I().model,i),F(r,()=>I().session,a),F(r,()=>I().branch,o),F(r,()=>I().stats.turns,s),F(r,()=>I().stats.toolCalls,null),F(c,O(A,{get when(){return I().statusReason},get children(){var e=Hc();return y(()=>N(e,`title`,I().statusReason)),e}}),l),l.$$click=Xt,u.$$click=ie,y(()=>P(n,`badge ${I().status}`)),e})(),(()=>{var e=Yc();return e.addEventListener(`scroll`,e=>{if(Fn)return;let t=e.currentTarget,r=It();r&&Me()&&Ne(0),je(r),t.scrollTop<=4&&n()&&!Tt()&&!Dt()&&i().length>0&&Mt()}),F(e,O(A,{get when(){return j(()=>!!Dt())()&&Qe().length>0},get children(){return Wc()}}),null),F(e,O(A,{get when(){return Tt()},get children(){return Gc()}}),null),F(e,O(A,{get when(){return Qe().length>0},get fallback(){return Xl()},get children(){return[O(k,{get each(){return Qe()},children:(e,t)=>O(xf,{e,get prev(){return Qe()[t()-1]},get res(){return Xe().resFor.get(e.id)},onOption:e=>void In(e),get answeredIds(){return Ze()},get agentActive(){return I()?.status===`running`||I()?.status===`waiting`},get onCancel(){return e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);h(p()?`${n}\n\n${p()}`:n),Ue(e=>e.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`?()=>Ve({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),O(A,{get when(){return Pe()},get children(){var e=Jc(),t=e.firstChild.nextSibling;return t.firstChild,F(t,O(A,{get when(){return Pe().reasoning},get children(){var e=Kc(),t=e.firstChild.nextSibling;return F(t,()=>Pe().reasoning),e}}),null),F(t,O(A,{get when(){return Ie()},get fallback(){return Zl()},get children(){var e=qc();return y(()=>e.innerHTML=Le(Ie()+`▍`)),e}}),null),e}})]}}),null),e})(),O(A,{get when(){return Jt()},get children(){var t=el(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.firstChild,o=i.nextSibling.firstChild,s=o.nextSibling,c=s.nextSibling,l=r.nextSibling,u=l.firstChild;n.$$dblclick=()=>{sn(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(on()))},n.$$pointerdown=_n,F(i,O(k,{get each(){return Zt()},children:(e,t)=>(()=>{var n=Ql(),r=n.firstChild.nextSibling;return n.$$click=()=>un(t()),F(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),pn(t())},y(r=>{var i=`termtab`+(B()===0&&$t()===t()?` active`:``)+(nn()&&B()===1&&tn()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),a),a.$$click=dn,F(o,(()=>{var t=j(()=>!!ln());return()=>t()?e().find(e=>e.id===ln().agentId)?.workspace.split(`/`).filter(Boolean).pop():I()?.workspace})()),s.$$click=vn,c.$$click=Xt;var d=yn(0);return typeof d==`function`&&ke(d,u),u.$$pointerdown=()=>an(0),F(u,O(A,{get when(){return!ln()||B()===0&&$t()===-1},get children(){return Xc()}})),F(l,O(A,{get when(){return nn()},get children(){return[Zc(),(()=>{var e=$c(),t=yn(1);return typeof t==`function`&&ke(t,e),e.$$pointerdown=()=>an(1),F(e,O(A,{get when(){return tn()===-1||Zt().length<=tn()},get children(){return Qc()}})),y(()=>e.classList.toggle(`focused`,B()===1)),e})()]}}),null),y(e=>{var n={height:`${on()}px`,"--termh":`${on()}px`},r=nn()?`single pane`:`split panes (50/50)`,i=!!nn(),a=B()===0;return e.e=De(t,n,e.e),r!==e.t&&N(s,`title`,e.t=r),i!==e.a&&l.classList.toggle(`split`,e.a=i),a!==e.o&&u.classList.toggle(`focused`,e.o=a),e},{e:void 0,t:void 0,a:void 0,o:void 0}),t}}),(()=>{var e=il(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=t.nextSibling;F(e,O(A,{get when(){return!Ae()||Me()>0},get children(){var e=tl();return e.firstChild,e.$$click=()=>Lt(!0),F(e,(()=>{var e=j(()=>Me()>0);return()=>e()?`${Me()} new message${Me()>1?`s`:``}`:`jump to present`})(),null),e}}),t),F(e,O(A,{get when(){return Mn().length>0},get children(){var e=nl();return F(e,O(k,{get each(){return Mn()},children:(e,t)=>(()=>{var n=$l(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{h(e.insert),jn(-1)},F(r,()=>e.insert.trim()),F(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===An()?` active`:``),a=e.title;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),F(e,O(A,{get when(){return En().length>0},get children(){var e=nl();return F(e,O(k,{get each(){return En()},children:e=>(()=>{var t=eu(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{h(`@${e.key} `),jn(-1)},F(n,()=>e.key,null),F(r,()=>e.label),y(()=>N(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Ln),n.$$keydown=e=>{let t=Mn();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),jn(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),jn(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&An()>=0){e.preventDefault(),h(t[An()].insert),jn(-1);return}if(e.key===`Escape`&&t.length>0){jn(-1);return}e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),Ln(e))},n.$$input=e=>{h(e.currentTarget.value),jn(0),Pn()};var a=Nn;return typeof a==`function`?ke(a,n):Nn=n,F(t,O(A,{get when(){return j(()=>!!p().startsWith(`@`))()&&p().includes(` `)},get children(){var e=rl(),t=e.firstChild;return t.addEventListener(`change`,e=>wn(e.currentTarget.checked)),y(()=>t.checked=Cn()),e}}),r),r.$$click=()=>{let e=!M();Te(e),requestAnimationFrame(()=>Pn())},F(r,()=>M()?`⤡`:`⤢`),F(i,()=>cf()||`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`+(M()?` maximized`:``),a=`message #${I().id} — / for commands`,o=M()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&P(e,t.e=i),a!==t.t&&N(n,`placeholder`,t.t=a),o!==t.a&&N(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),y(()=>n.value=p()),e})()]}})),T.addEventListener(`scroll`,e=>{Bn=e.currentTarget.scrollTop});var D=zn;return typeof D==`function`?ke(D,T):zn=T,F(T,O(A,{get when(){return I()},get children(){return[al(),(()=>{var e=ol(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return F(n,()=>I().id),F(r,()=>I().status),F(a,()=>I().workspace),F(o,()=>I().session,s),F(o,()=>I().branch,null),y(e=>{var t=`badge ${I().status}`,n=I().workspace;return t!==e.e&&P(r,e.e=t),n!==e.t&&N(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),O(If,{get agentId(){return I().id},get workspace(){return I().workspace}}),sl(),(()=>{var e=ll(),t=e.firstChild,r=t.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=r.nextSibling;return s.firstChild,t.addEventListener(`change`,e=>{_e(e.currentTarget.value),Ce(e.currentTarget.value)}),F(t,O(k,{get each(){return Se()},children:e=>(()=>{var t=Kl();return t.value=e,F(t,e,null),F(t,()=>e===g().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>ye(e.currentTarget.value),F(a,O(k,{get each(){return be()},children:e=>(()=>{var t=Kl();return y(()=>t.value=e.id),t})()})),o.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:ge(),model:ve().trim()||void 0,contextWindowTokens:be().find(e=>e.id===(ve().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,dt()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},F(s,()=>I().model,null),F(s,O(A,{get when(){return be().length},get children(){return[` · `,j(()=>be().length),` models loaded`]}}),null),F(e,O(A,{get when(){return we()},get children(){var e=cl();return F(e,we),e}}),null),y(()=>N(i,`placeholder`,I().model)),y(()=>t.value=ge()),y(()=>i.value=ve()),e})(),ul(),(()=>{var i=pl(),o=i.firstChild,s=o.nextSibling;return F(i,O(A,{get when(){return I().status===`running`},get fallback(){return(()=>{var e=tu();return Ee(e,`click`,Vn(`/start`),!0),e})()},get children(){var e=dl();return Ee(e,`click`,Vn(`/stop`),!0),e}}),o),o.$$click=()=>$(`/api/agents/${I().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>Rt(I().id)),s.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await $(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let o=e().filter(e=>e.id!==i);t(o),o[0]?Rt(o[0].id):(r(null),a([]))},F(i,O(A,{get when(){return e().some(e=>e.parent===n())},get children(){var e=fl();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),dt())},e}}),null),i})(),(()=>{var e=ml(),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(dt)}),y(()=>t.checked=I().autoContinue??!0),e})(),(()=>{var e=gl();return e.firstChild,F(e,O(A,{get when(){return!!I().goal.text.trim()},get fallback(){return nu()},get children(){var e=hl();return F(e,()=>I().goal.status),y(()=>P(e,`badge ${I().goal.status===`active`?`running`:I().goal.status}`)),e}}),null),e})(),(()=>{var e=_l();return e.firstChild,F(e,O(k,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=ru();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(dt)},N(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),F(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(I().goal.text.trim()&&I().goal.status===e?` on ${e}`:``),i=!!I().goal.text.trim()&&I().goal.status===e;return r!==n.e&&P(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),O(A,{get when(){return I().goal.text},get fallback(){return iu()},get children(){return[(()=>{var e=vl(),t=e.firstChild;return y(()=>t.innerHTML=Le(String(I().goal.text))),e})(),O(A,{get when(){return I().goal.verify},get children(){var e=yl(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Le(String(I().goal.verify))),e}}),O(A,{get when(){return I().goal.audit},children:e=>(()=>{var t=au(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return F(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),F(r,()=>Tf(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=Le(e().feedback);return r!==n.e&&P(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),bl(),(()=>{var e=xl();return e.addEventListener(`submit`,Hn),e})(),(()=>{var e=Cl(),t=e.firstChild.nextSibling;return F(e,O(A,{get when(){return ut().total>0},get children(){var e=Sl(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,F(e,()=>ut().done,t),F(e,()=>ut().total,n),y(t=>De(e,ut().done===ut().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),O(A,{get when(){return ut().total>0},get children(){var e=wl(),t=e.firstChild;return y(e=>{var n=`barfill `+(ut().done===ut().total?``:`warn`),r=`${Math.round(ut().done/ut().total*100)}%`;return n!==e.e&&P(t,e.e=n),r!==e.t&&Oe(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),O(A,{get when(){return it()},get fallback(){return(()=>{var e=ou();return y(()=>e.innerHTML=af(nt())),e})()},get children(){var e=Tl();return e.$$input=e=>{rt(e.currentTarget.value),st(!0)},y(()=>e.value=nt()),e}}),(()=>{var e=El(),t=e.firstChild,n=t.nextSibling.nextSibling;return t.$$click=()=>at(!it()),F(t,()=>it()?`👁`:`✎`),n.$$click=lt,y(()=>N(t,`title`,it()?`rendered checklist`:`edit markdown`)),e})(),Dl(),O(A,{get when(){return I().latestProgress},get fallback(){return su()},children:e=>(()=>{var t=fu(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return F(t,O(A,{get when(){return e().recent},get children(){var t=cu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=af(e().recent)),t}}),i),F(t,O(A,{get when(){return e().problems},get children(){var t=lu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=af(e().problems)),t}}),i),F(t,O(A,{get when(){return e().next},get children(){var t=uu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=af(e().next)),t}}),i),F(t,O(A,{get when(){return e().goalStatus},get children(){var t=du(),n=t.firstChild.nextSibling;return F(n,()=>e().goalStatus),t}}),i),F(i,()=>Tf(e().ts)),y(()=>r.innerHTML=af(e().doing)),t})()}),Ol(),(()=>{var e=Al(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=t.nextSibling,l=c.firstChild.nextSibling,u=l.firstChild,d=u.nextSibling;return d.nextSibling,F(i,()=>I().stats.turns),F(o,()=>I().stats.toolCalls),F(s,()=>I().stats.compactions??0),F(l,()=>Ef(I().stats.inputTokens),u),F(l,()=>Ef(I().stats.outputTokens),d),F(c,O(A,{get when(){return(I().stats.cachedInputTokens??0)>0},get children(){var e=kl(),t=e.firstChild.nextSibling;return t.nextSibling,F(e,()=>Math.round(I().stats.cachedInputTokens/Math.max(1,I().stats.inputTokens)*1e3)/10,t),y(()=>N(e,`title`,`${Ef(I().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),F(e,O(A,{get when(){return I().ctx},get fallback(){return pu()},children:e=>{let t=be().find(e=>e.id===I().model),r=e().window||t?.contextLength||0,i=r?Math.min(999,e().usedTokens/r*100):0,a=r?i>=85?`crit`:i>=70?`warn`:`ok`:``,o=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)},s=r?Math.round(r*.75):0,c=e().compactAt,l=e().compactAtIsManual===!0?!1:!c||c>=r;return(()=>{var t=_u(),u=t.firstChild,d=u.firstChild.nextSibling,f=d.firstChild.nextSibling;f.nextSibling;var p=u.nextSibling,m=p.firstChild.nextSibling,h=m.firstChild,g=m.nextSibling,_=p.nextSibling,v=_.firstChild.firstChild,b=_.nextSibling,x=b.firstChild.nextSibling;return x.nextSibling,F(d,()=>Ef(e().usedTokens),f),F(u,O(A,{when:r,get children(){var e=mu(),t=e.firstChild;return P(e,`pill ${a}`),F(e,()=>o(i),t),F(e,()=>Ef(r),null),e}}),null),F(t,O(A,{when:r,get children(){var e=hu(),t=e.firstChild;return P(t,`barfill ${a}`),y(e=>Oe(t,`width`,`${Math.min(100,i)}%`)),e}}),p),F(m,()=>Ef(l?s:c),h),F(g,l?` (75% of window)`:` (manual override)`),F(t,O(A,{when:r,get children(){var t=gu(),n=t.firstChild;return P(n,`barfill ${a}`),y(t=>Oe(n,`width`,`${Math.min(100,Math.round(e().usedTokens/s*100))}%`)),t}}),_),v.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(dt)}),F(b,()=>Ef(e().compactAt),x),y(()=>v.checked=I().autoCompact!==!1),t})()}}),null),e})(),jl(),O(k,{get each(){return c()},children:e=>(()=>{var t=vu(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=xt()===e.branch?null:e.branch;St(t),n()&&Nt(n())},F(r,()=>e.branch,null),F(r,()=>e.branch===I().branch?` (current)`:``,null),F(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===I().branch||e.branch===xt()?` cur`:``),i=e.branch===xt()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&P(t,n.e=r),i!==n.t&&N(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Ml(),O(A,{get when(){return pt().length>0},get fallback(){return yu()},get children(){return O(k,{get each(){return pt()},children:e=>(()=>{var t=xu(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Rt(e.agent),F(i,()=>e.id),F(a,()=>e.agent,null),F(r,O(A,{get when(){return e.forked},get children(){return bu()}}),null),F(o,()=>e.schedule,s),F(o,(()=>{var t=j(()=>!!e.next);return()=>t()?Tf(e.next):`—`})(),null),F(o,(()=>{var t=j(()=>!!e.last);return()=>t()?` · last ${Tf(e.last)}`:` · never ran`})(),null),F(c,()=>Df(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Df(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&P(t,r.e=i),a!==r.t&&N(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(re()?``:` right-hidden`),n=`conn`+(zt()?` ok`:``),r=zt()?`live (websocket)`:`reconnecting…`,i=`iconbtn notifbtn`+(Ke()>0?` has-unread`:``),a=Ke()>0?`${Ke()} unread notifications`:`notifications`,s=`rightbar`+(re()?` open`:``);return t!==e.e&&P(o,e.e=t),n!==e.t&&P(m,e.t=n),r!==e.a&&N(m,`title`,e.a=r),i!==e.o&&P(_,e.o=i),a!==e.i&&N(_,`title`,e.i=a),s!==e.n&&P(T,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),o}}),O(A,{get when(){return We()},get children(){var t=Il(),n=t.firstChild;return n.firstChild,F(n,O(A,{get when(){return L().length>0},get children(){var e=Pl();return e.$$click=()=>R([]),e}}),null),F(t,O(A,{get when(){return L().length>0},get fallback(){return Su()},get children(){var t=Fl();return F(t,O(k,{get each(){return L()},children:t=>(()=>{var n=wu(),r=n.firstChild.firstChild,i=r.nextSibling,a=i.nextSibling;return n.$$click=()=>{e().some(e=>e.id===t.agentId)&&Rt(t.agentId),Ge(!1)},F(r,(()=>{var e=j(()=>t.kind===`finish`);return()=>e()?`✅`:j(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),F(i,()=>t.title),F(a,()=>Tf(new Date(t.at).toISOString())),F(n,O(A,{get when(){return t.body},get children(){var e=Cu();return F(e,()=>wf(t.body,160)),e}}),null),y(e=>{var r=`notifitem `+t.kind,i=`from ${t.agentId}`;return r!==e.e&&P(n,e.e=r),i!==e.t&&N(n,`title`,e.t=i),e},{e:void 0,t:void 0}),n})()})),t}}),null),t}}),O(A,{get when(){return S()},get children(){return O(Af,{get providers(){return Object.keys(g().providers??{})},onClose:()=>te(!1),onCreated:e=>{te(!1),dt(),Rt(e)}})}}),O(A,{get when(){return ne()},get children(){return O(Vf,{get cfg(){return g()},onClose:()=>w(!1),onSaved:()=>{$e(),ht()}})}}),O(A,{get when(){return Be()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return O(kf,{title:`edit prompt — forks the conversation`,onClose:()=>Ve(null),get children(){var t=Eu(),i=t.firstChild,s=i.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:a()})}),Ve(null),dt();let t=n();t&&await Rt(t)}catch(e){alert(`edit failed: ${e.message}`)}}),F(t,O(A,{get when(){return r()>0},get children(){var e=Tu(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return F(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>Ve(null),y(()=>i.value=e().text),t}})}})]}function yf(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>Math.max(0,(n()-t)/1e3),a=()=>i()<60?`${i().toFixed(1)}s`:`${Math.floor(i()/60)}m ${Math.round(i()%60)}s`;return e.inline?(()=>{var t=Du();return t.firstChild,F(t,a,null),F(t,(()=>{var t=j(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=Ou(),t=e.firstChild;return F(e,a,t),e})()}function bf(e){let t=e.e,n=e.res,r=!e.agentActive&&!n,i=t.data??{},a=String(i.name??`tool`),o=()=>n?String(n.data?.result??``):``,s=a,c=``,l=(()=>{var e=ku();return F(e,()=>wf(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=(e,t=1500)=>(()=>{var n=Au();return F(n,()=>wf(e,t)),n})(),f=(e=4e3)=>n?[j(()=>d(o(),e)),(()=>{var e=ju(),t=e.firstChild;return F(e,()=>n.data?.durationMs,t),F(e,()=>n.data?.ok===!1?` · FAILED`:``,null),F(e,O(Of,{get text(){return o()}}),null),e})()]:Mu();try{switch(a){case`bash`:{let e=u(`command`);s=`$ `+Df(e,96);let t=u(`timeout_ms`)?` · timeout ${Math.round(Number(u(`timeout_ms`))/1e3)}s`:``;c=n?`${n.data?.durationMs??`?`}ms${t}`:null,l=[j(()=>j(()=>e!==s.slice(2))()?d(e,800):null),j(()=>f(6e3))];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${Df(u(`pattern`),40)}/`),Number(i.args?.offset)<0?e.push(`last ${-Number(i.args.offset)} lines`):i.args?.offset&&e.push(`from L${i.args.offset}`),i.args?.limit&&e.push(`≤${i.args.limit} lines`),c=e.join(` · `),l=f(6e3);break}case`write_file`:{let e=String(i.args?.content??``);s=u(`path`)||`(no path)`,c=`${Ef(e.length)} bytes`,l=[j(()=>d(e,1500)),j(()=>j(()=>e.length>1500)()?(()=>{var t=Nu(),n=t.firstChild;return F(t,()=>Ef(e.length),n),t})():null),n?(()=>{var e=Pu();return F(e,()=>Df(o(),160)),e})():Fu()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=Iu();return F(e,()=>wf(`- `+u(`old_text`),900)),e})(),(()=>{var e=Lu();return F(e,()=>`+ `+wf(u(`new_text`),900)),e})(),n?(()=>{var e=Ru(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,F(e,()=>Df(o(),120),t),F(e,()=>n.data?.durationMs,r),e})():zu()];break;case`apply_patch`:{let e=u(`patch`).split(`
26
+ `).filter(e=>e&&!/^---$/.test(e.trim())),t=e.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);s=t.length?`${t.length} file${t.length>1?`s`:``}: ${Df(t.join(`, `),80)}`:`patch`;let r=e.slice(0,60);l=[(()=>{var t=Bu();return F(t,()=>r.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Vu();return P(n,`pline`+t),F(n,(()=>{var t=j(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),F(t,(()=>{var t=j(()=>e.length>60);return()=>t()?(()=>{var t=Hu(),n=t.firstChild.nextSibling;return n.nextSibling,F(t,()=>e.length-60,n),t})():null})(),null),t})(),n?(()=>{var e=Pu();return F(e,()=>Df(o().split(`
27
+ `)[0]??``,140),null),F(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Uu()];break}case`list_dir`:s=u(`path`)||`.`,l=f(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=Df(e,70),c=`web`,l=[(()=>{var e=Pu();return F(e,O(A,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Gu();return F(e,()=>Df(u(`url`),80)),e})()},get children(){var e=Wu();return y(()=>N(e,`href`,u(`url`))),e}})),e})(),j(()=>f(3e3))];break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=qc();return y(()=>t.innerHTML=Le(e)),t})(),(()=>{var e=ju(),t=e.firstChild;return F(e,()=>n.data?.durationMs,t),e})()]:Ku();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Df(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[j(()=>j(()=>!!e.length)()?(()=>{var t=qu();return t.firstChild,F(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Ru(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,F(e,()=>Df(o(),160),t),F(e,()=>n.data?.durationMs,r),e})():Ju()];break}}}catch{}return(()=>{var e=Xu(),i=e.firstChild,o=i.firstChild;o.firstChild;var u=o.nextSibling;return N(e,`title`,`${a}${c?` — `+c:``}`),F(o,s,null),F(i,O(A,{get when(){return t.data?.actor},get children(){var e=Yu();return e.firstChild,F(e,()=>String(t.data.actor),null),e}}),u),F(u,n?c||``:r?`(result missed)`:a===`bash`?O(yf,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return Number(t.data?.args?.timeout_ms)||void 0}}):`running…`),F(e,l,null),y(()=>P(e,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),e})()}function xf(e){let t=e.e,n=pf(t),r=e.prev&&e.prev.type===t.type&&pf(e.prev).name===n.name&&t.session===e.prev.session&&t.branch===e.prev.branch;if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Zu(),r=n.firstChild.nextSibling;return r.nextSibling,F(n,()=>String(e.fromBranch??`?`),r),F(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:Df(String(e.text??``),80);return(()=>{var t=Qu(),r=t.firstChild.nextSibling;return r.nextSibling,F(t,()=>String(e.event??``),r),F(t,n,null),t})()}return t.type===`todo`?(()=>{var e=$u(),n=e.firstChild.nextSibling;return n.nextSibling,F(e,()=>String(t.data?.by??`human`),n),e})():t.type===`state`?t.data.from===t.data.to?null:(()=>{var e=ed(),n=e.firstChild;return F(e,()=>t.data.from,n),F(e,()=>t.data.to,null),F(e,(()=>{var e=j(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>P(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})():(()=>{var i=ad(),a=i.firstChild;return F(i,O(A,{when:!r,get fallback(){return od()},get children(){var e=td();return F(e,()=>n.icon),y(t=>{var r=n.color+`33`,i=`1px solid ${n.color}66`;return r!==t.e&&Oe(e,`background`,t.e=r),i!==t.t&&Oe(e,`border`,t.t=i),t},{e:void 0,t:void 0}),e}}),a),F(a,O(A,{when:!r,get children(){var r=id(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return F(i,()=>n.name),F(r,O(A,{get when(){return t.data?.actor},get children(){var e=Yu();return e.firstChild,F(e,()=>String(t.data.actor),null),e}}),a),F(a,(()=>{var e=j(()=>!!t.data?.pending);return()=>e()?t.data?.sent===!0?`sent to model ✓`:`pending (queued)…`:hf(t.ts)})()),F(o,()=>t.branch),F(r,O(A,{get when(){return e.onCancel},get children(){var t=nd();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),F(r,O(A,{get when(){return e.onEdit},get children(){var t=rd();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Oe(i,`color`,n.color)),r}}),null),F(a,O(Cf,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive}}),null),y(()=>P(i,`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``))),i})()}function Sf(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=sd(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&N(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function Cf(e){let t=e.e;switch(t.type){case`prompt`:return(()=>{var e=qc();return y(()=>e.innerHTML=af(String(t.data.text??``))),e})();case`message`:return[O(A,{get when(){return j(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Kc(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return F(n,(()=>{var e=j(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Ef(String(t.data.reasoning).length)} — truncated)`:``})(),null),F(r,()=>wf(String(t.data.reasoning),8e3)),e}}),(()=>{var e=qc();return y(()=>e.innerHTML=af(String(t.data.content??``))),e})(),O(A,{get when(){return t.data.interrupted},get children(){return cd()}}),O(A,{get when(){return t.data.final},get children(){var e=ld(),n=e.firstChild;return F(e,O(Of,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return O(bf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=ud(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return F(i,()=>Df(e,120)),F(r,O(Of,{text:e}),null),F(a,()=>wf(e,4e3)),F(o,()=>t.data.durationMs,s),F(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>P(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=fd(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return F(n,O(A,{get when(){return e.length},get children(){var t=dd();return t.firstChild,F(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=af(String(t.data?.decision??``)),r=af(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 r=hd(),a=r.firstChild;return a.firstChild,P(r,`embed question`+(i?` answered`:``)),F(a,()=>String(t.data?.question??``),null),F(r,O(A,{when:i,get children(){return pd()}}),null),F(r,O(A,{get when(){return n.length>0},get children(){var r=md();return F(r,O(k,{each:n,children:n=>(()=>{var r=gd();return r.$$click=()=>{let r=t.data?.actor;r?$(`/api/agents/${encodeURIComponent(String(r))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},r.disabled=i,F(r,n),r})()})),r}}),null),F(r,O(Sf,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=_d(),n=e.firstChild.firstChild.nextSibling;return F(e,O(A,{get when(){return t.data.goalStatus},get children(){var e=du(),n=e.firstChild.nextSibling;return F(n,()=>String(t.data.goalStatus)),e}}),null),F(e,O(A,{get when(){return t.data.recent},get children(){var e=cu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=af(String(t.data.recent))),e}}),null),F(e,O(A,{get when(){return t.data.problems},get children(){var e=lu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=af(String(t.data.problems))),e}}),null),F(e,O(A,{get when(){return t.data.next},get children(){var e=uu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=af(String(t.data.next))),e}}),null),y(()=>n.innerHTML=af(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=vd(),n=e.firstChild;return n.firstChild,F(n,()=>String(t.data.message??``),null),e})();default:return(()=>{var e=yd();return F(e,()=>wf(JSON.stringify(t.data),200)),e})()}}function wf(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Tf(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 Ef(e){return e>=1e9?`${+(e/1e9).toFixed(1)}b`:e>=1e6?`${+(e/1e6).toFixed(1)}m`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Df(e,t){return wf(e.replace(/\s+/g,` `).trim(),t)}function Of(e){let[t,n]=v(!1);return(()=>{var r=bd();return r.$$click=t=>{t.stopPropagation(),navigator.clipboard.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),900)})},F(r,()=>t()?`✓`:`⧉`),r})()}function kf(e){return(()=>{var t=xd(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),F(r,()=>e.title),Ee(i,`click`,e.onClose,!0),F(n,()=>e.children,null),t})()}function Af(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let r=await $(`/api/fs?path=${encodeURIComponent(e??t())}`);n(r.path),h(r.parent??``),i(r.entries??[])}ee(()=>p(t()));let[m,h]=v(``),g=async n=>{n.preventDefault(),f(``);try{let n=await $(`/api/agents`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({workspace:t(),id:a(),provider:s()||void 0,model:l()||void 0,start:!1})});e.onCreated(n.agent.id)}catch(e){f(String(e.message))}};return O(kf,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Cd(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,te=C.firstChild.nextSibling,ne=C.nextSibling.firstChild.nextSibling,w=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),F(b,O(k,{get each(){return r()},children:e=>(()=>{var n=wd();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),F(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),te.addEventListener(`change`,e=>c(e.currentTarget.value)),F(te,O(k,{get each(){return e.providers},children:e=>(()=>{var t=Kl();return F(t,e),t})()})),ne.$$input=e=>u(e.currentTarget.value),F(i,O(A,{get when(){return d()},get children(){var e=Sd();return F(e,d),e}}),w),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>te.value=s()),y(()=>ne.value=l()),i}})}var jf=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Mf=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Nf=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Pf(e){let t=Ff(e);return t===`image`?`🖼`:t===`video`?`🎬`:t===`audio`?`🎵`:`·`}function Ff(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return jf.has(t)?`image`:Mf.has(t)?`video`:Nf.has(t)?`audio`:null}function If(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),l=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{}}));async function u(t){try{let n=await $(`/api/agents/${e.agentId}/tree${t?`?path=${encodeURIComponent(t)}`:``}`);return l(t,n.entries??[])}catch(e){return c(e.message),null}}b(()=>{e.agentId,i(new Set),n(new Map),u(``).then(e=>{e&&n(new Map([[``,e]]))})});let d=async e=>{let a=new Set(r());if(a.has(e.path)){a.delete(e.path),i(a);return}if(a.add(e.path),i(a),!t().has(e.path)){let t=await u(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[f,p]=v(``),[m,h]=v(!1),[g,_]=v(`code`),[x,S]=v(``),[ee,te]=v(!1),ne=e=>/\.(md|markdown|mdx)$/i.test(e),w=0,re=async e=>{let t=++w;p(``),h(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-DPNcXMDA.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(w!==t)return;p(e=>e+r)}}catch{w===t&&p(``)}finally{w===t&&h(!1)}};C(()=>{w++});let[T,ie]=v(null),ae=async(t,n)=>{let r=Ff(t.path);if(r){o({path:t.path,content:``,binary:!0}),ie({path:t.path,kind:r}),_(`media`);return}try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);ie(null),o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),S(r.content??``),_(r.binary?`code`:n),!r.binary&&n!==`md`&&re({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},oe=async()=>{let t=a();if(!(!t||ee())){te(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:x(),baseContent:t.content})}),o({...t,content:x()}),Q(`saved ${t.path}`)}catch(e){let t=e.message;t.includes(`409`)||t.includes(`changed on disk`)?Q(`file changed on disk — reopen to see the current version`):Q(`save failed: ${t}`)}finally{te(!1)}}},E=e=>!e.binary&&!e.truncated,se=(e,n)=>[(()=>{var t=Ed(),i=t.firstChild,a=i.nextSibling;return t.$$click=()=>e.dir?void d(e):void ae(e,`code`),F(i,(()=>{var t=j(()=>!!e.dir);return()=>t()?r().has(e.path)?`▾`:`▸`:Pf(e.name)})()),F(a,()=>e.name),F(t,O(A,{get when(){return j(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Td();return F(t,()=>Ef(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``),a=`padding-left:${n*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&P(t,r.e=i),r.t=De(t,a,r.t),o!==r.a&&N(t,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),t})(),O(A,{get when(){return j(()=>!!e.dir)()&&r().has(e.path)},get children(){return O(k,{get each(){return t().get(e.path)??[]},children:e=>se(e,n+1)})}})],ce=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace;return[(()=>{var e=Dd(),t=e.firstChild.nextSibling;return t.firstChild,F(t,ce,null),e})(),(()=>{var e=Od();return F(e,O(A,{get when(){return(t().get(``)??[]).length>0},get fallback(){return(()=>{var e=kd();return F(e,()=>s()||`empty workspace`),e})()},get children(){return O(k,{get each(){return t().get(``)??[]},children:e=>se(e,0)})}})),e})(),O(A,{get when(){return a()},children:t=>O(kf,{get title(){return`🗂 ${t().path}`},onClose:()=>{w++,o(null),ie(null)},get children(){return O(A,{get when(){return T()},get fallback(){return[(()=>{var e=Pd(),n=e.firstChild;return F(e,O(A,{get when(){return j(()=>!!ne(t().path))()&&!t().binary},get children(){var e=Md();return e.$$click=()=>_(`md`),y(()=>P(e,g()===`md`?`on`:``)),e}}),n),n.$$click=()=>{_(`code`),f()||re({path:t().path,content:t().content,truncated:t().truncated})},F(e,O(A,{get when(){return E(t())},get children(){var e=Nd();return e.$$click=()=>_(`edit`),y(()=>P(e,g()===`edit`?`on`:``)),e}}),null),y(()=>P(n,g()===`code`?`on`:``)),e})(),O(A,{get when(){return!t().binary},get fallback(){return Id()},get children(){return O(A,{get when(){return g()===`edit`},get fallback(){return O(A,{get when(){return j(()=>g()===`md`)()&&ne(t().path)},get fallback(){return O(Lf,{get path(){return t().path},get content(){return t().content},get html(){return f()},get pending(){return m()},get truncated(){return!!t().truncated}})},get children(){var e=Ld();return y(()=>e.innerHTML=Le(t().content)),e}})},get children(){var e=Fd(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>S(e.currentTarget.value),N(n,`spellcheck`,!1),F(r,()=>Ef(x().length),i),a.$$click=()=>void oe(),F(a,()=>ee()?`saving…`:`💾 save`),y(()=>a.disabled=ee()||x()===t().content),y(()=>n.value=x()),e}})}})]},get children(){var t=jd(),n=t.firstChild,r=n.firstChild;return F(t,O(A,{get when(){return T().kind===`image`},get fallback(){return O(A,{get when(){return T().kind===`video`},get fallback(){return(()=>{var t=zd();return y(()=>N(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(T().path)}`)),t})()},get children(){var t=Rd();return y(()=>N(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(T().path)}`)),t}})},get children(){var t=Ad();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(T().path)}`,i=T().path.split(`/`).pop();return r!==n.e&&N(t,`src`,n.e=r),i!==n.t&&N(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),F(n,()=>T().kind,r),t}})}})})]}function Lf(e){return[O(A,{get when(){return e.html},get fallback(){return j(()=>!!e.pending)()?(()=>{var t=Hd(),n=t.firstChild.nextSibling;return n.nextSibling,F(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Ud();return F(t,()=>e.content),t})()},get children(){var t=Bd();return y(()=>t.innerHTML=e.html),t}}),O(A,{get when(){return e.truncated},get children(){return Vd()}})]}var Rf=[{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)`}],zf={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 Bf(e){let[t,n]=v(Rf[0]),[r,i]=v(Rf[0].url),[a,o]=v(``),[s,c]=v(Rf[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);C(()=>clearTimeout(n))});let ee=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Ef(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},te=()=>ee(s()),ne=async t=>{t.preventDefault(),x(``),g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}};return(()=>{var e=qd(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,ee=x.firstChild.nextSibling,C=x.nextSibling,w=C.firstChild.nextSibling,re=w.nextSibling,T=C.nextSibling,ie=T.firstChild.nextSibling,ae=ie.firstChild.nextSibling,oe=ie.nextSibling.firstChild.nextSibling,E=T.nextSibling;return n.addEventListener(`submit`,ne),F(u,()=>[...Rf,zf].map(e=>(()=>{var n=Jd();return n.$$click=()=>S(e),F(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&P(n,r.e=i),a!==r.t&&N(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),F(n,O(A,{get when(){return t().hint},get children(){var e=Wd();return F(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),F(b,()=>Rf.map(e=>(()=>{var t=Kl();return y(()=>t.value=e.url),t})())),ee.$$input=e=>o(e.currentTarget.value),w.$$input=e=>c(e.currentTarget.value),F(re,()=>l().map(e=>(()=>{var t=Kl();return y(()=>t.value=e.id),t})())),F(n,O(A,{get when(){return l().length>0},get fallback(){return Yd()},get children(){var e=Kd(),t=e.firstChild;return F(e,()=>l().length,t),F(e,O(A,{get when(){return te()},get children(){return[` · `,(()=>{var e=Gd();return F(e,te),e})()]}}),null),e}}),T),ae.$$input=e=>f(e.currentTarget.value),oe.$$input=e=>m(e.currentTarget.value),F(n,O(A,{get when(){return _()},get children(){var e=Sd();return F(e,_),e}}),E),F(E,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(type to filter models from the endpoint)`,r=h();return n!==e.e&&N(w,`placeholder`,e.e=n),r!==e.t&&(E.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>ae.value=d()),y(()=>oe.value=p()),e})()}function Vf(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),[a,o]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[s,c]=v(e.cfg.progressMinChars??4e3),[l,u]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[d,f]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[p,m]=v(e.cfg.maxSpawnDepth??3),[h,g]=v((e.cfg.tasks??[]).map(e=>({...e}))),[_,b]=v(``),x=()=>(e.cfg.agents??[]).map(e=>e.id),S=()=>{let e={};for(let n of t()){if(!n.name.trim())return b(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return b(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},ee=async t=>{t.preventDefault(),b(``);let n=S();if(!n)return;let i=h().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of i){if(!e.agent){b(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){b(`task "${e.id}": schedule is required`);return}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,a())*6e4,progressMinChars:Math.max(100,s()),...l()==null?{}:{contextTokenBudget:Math.max(1,l())*1e3},...d()>0?{contextWindowTokens:d()*1e3}:{},maxSpawnDepth:Math.max(0,p()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){b(e.message)}},C=(e,t,n,r)=>(()=>{var i=Xd(),a=i.firstChild;return N(i,`title`,r),F(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return O(kf,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Zd(),b=v.firstChild,S=b.firstChild.nextSibling,te=S.nextSibling;te.firstChild;var ne=te.nextSibling.firstChild.firstChild.nextSibling;ne.firstChild;var w=b.nextSibling,re=w.firstChild.nextSibling,T=re.firstChild,ie=T.firstChild.nextSibling,ae=w.nextSibling,oe=ae.firstChild.nextSibling,E=ae.nextSibling;E.firstChild;var se=E.nextSibling;return v.addEventListener(`submit`,ee),F(b,O(k,{get each(){return t()},children:(e,r)=>(()=>{var i=Qd(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r()?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r()?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r()?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r()?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r())),y(()=>a.value=e.name),y(()=>o.value=e.baseUrl),y(()=>s.value=e.apiKey),y(()=>c.value=e.model),i})()}),S),S.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),F(te,O(k,{each:Rf,children:e=>(()=>{var a=$d();return a.firstChild,a.$$click=()=>{let a=t().filter(t=>t.name!==e.key);n([...a,{name:e.key,baseUrl:e.url,apiKey:``,model:e.model}]),r()||i(e.key)},F(a,()=>e.label,null),y(()=>N(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),ne.addEventListener(`change`,e=>i(e.currentTarget.value)),F(ne,O(k,{get each(){return[...new Set(t().map(e=>e.name.trim()).filter(Boolean))]},children:e=>(()=>{var t=Kl();return t.value=e,F(t,e),t})()}),null),F(re,()=>C(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),T),F(re,()=>C(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),T),ie.$$input=e=>u(e.currentTarget.value===``?null:Number(e.currentTarget.value)),F(re,()=>C(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),F(re,()=>C(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),F(ae,O(A,{get when(){return h().length>0},get children(){return O(k,{get each(){return h()},children:(e,t)=>(()=>{var n=ef(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().map((n,r)=>r===t()?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e.id),y(()=>a.value=e.agent),y(()=>o.value=e.schedule),y(()=>c.checked=!!e.forked),y(()=>u.value=e.prompt),n})()})}}),oe),oe.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),F(E,O(k,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=nf(),n=t.firstChild,r=n.nextSibling;return F(n,()=>e.id),F(r,()=>e.workspace),F(t,O(A,{get when(){return e.parent},get children(){var t=tf();return t.firstChild,F(t,()=>e.parent,null),t}}),null),t})()}),null),F(v,O(A,{get when(){return _()},get children(){var e=Sd();return F(e,_),e}}),se),y(()=>ne.value=r()),y(()=>ie.value=l()??``),v}})}Te([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),we(()=>O(vf,{}),document.getElementById(`root`));export{Pc as t};
28
+ //# sourceMappingURL=index-Ce97EUXt.js.map