teapot-coding-agent 0.17.2 → 0.17.4

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.
@@ -19,10 +19,10 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
19
19
  `&&(this._liveRegionLineCount++,this._liveRegionLineCount===pc+1&&(this._liveRegion.textContent+=Ge.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=z([B(1,vt),B(2,Dt),B(3,kt)],mc);var hc=class extends H{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 W),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new W),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(V(()=>{Qt(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(G(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(G(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(G(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(G(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,Qt(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=z([B(1,Ot),B(2,kt),B(3,mt),B(4,Nt)],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 nc{constructor(e={}){super(e),this._linkifier=this._register(new nn),this.browser=Aa,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new nn),this._onCursorMove=this._register(new W),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new W),this.onKey=this._onKey.event,this._onRender=this._register(new W),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new W),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new W),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new W),this.onBell=this._onBell.event,this._onFocus=this._register(new W),this._onBlur=this._register(new W),this._onA11yCharEmitter=this._register(new W),this._onA11yTabEmitter=this._register(new W),this._onWillOpen=this._register(new W),this._setup(),this._decorationService=this._instantiationService.createInstance(lc),this._instantiationService.setService(Ct,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(Ta),this._instantiationService.setService(Nt,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(wt)),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(ln.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(ln.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(ln.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(ln.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(V(()=>{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=J.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${K.ESC}]${n};${Bs(r)}${Hi.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=Ji.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=Ji.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(K.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(K.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(G(this.element,`copy`,e=>{this.hasSelection()&&Je(e,this._selectionService)}));let e=e=>Ye(e,this.textarea,this.coreService,this.optionsService);this._register(G(this.textarea,`paste`,e)),this._register(G(this.element,`paste`,e)),Pa?this._register(G(this.element,`mousedown`,e=>{e.button===2&&Qe(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(G(this.element,`contextmenu`,e=>{Qe(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),Ha&&this._register(G(this.element,`auxclick`,e=>{e.button===1&&Ze(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(G(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(G(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(G(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(G(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(G(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(G(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(G(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(G(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`,Ue.get()),Ua||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(Ca,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(Dt,this._coreBrowserService),this._register(G(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(G(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(ya,this._document,this._helperContainer),this._instantiationService.setService(Et,this._charSizeService),this._themeService=this._instantiationService.createInstance(Oo),this._instantiationService.setService(Mt,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(ea),this._instantiationService.setService(jt,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Ya,this.rows,this.screenElement)),this._instantiationService.setService(kt,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(Ui,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(Oa),this._instantiationService.setService(Ot,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(Pi,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(vo,this.element,this.screenElement,r)),this._instantiationService.setService(At,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(ln.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(Fi,this.screenElement)),this._register(G(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(Bi,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Bi,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(va,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(G(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(G(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=K.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){Xe(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=ic(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===K.ETX||n.key===K.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(Io));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(K.ESC+`[I`):this.coreService.triggerDataEvent(K.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(`${K.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(`${K.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 st)}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 st}},Sc=class extends H{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new W),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 H{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 Ue.get()},set promptLabel(e){Ue.set(e)},get tooMuchOutput(){return Ge.get()},set tooMuchOutput(e){Ge.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=P(`<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=P(`<div class=themegrid>`),Lc=P(`<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=P(`<i class=notifdot>`),zc=P(`<br>`),Bc=P(`<span class="badge queued">⏳ <!> of yours queued`),Vc=P(`<span class="badge cron">⏰ `),Hc=P(`<span class=sub>ℹ`),Uc=P(`<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=P(`<div class=divider-msg>── beginning of log ──`),Gc=P(`<div class=divider-msg>loading older events…`),Kc=P(`<details class=reasoning><summary>💭 reasoning</summary><div class=mono>`),qc=P(`<div class=content>`),Jc=P(`<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=P(`<div class=feed>`),Xc=P(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),Zc=P(`<div class=termsplit>`),Qc=P(`<div class="termempty muted">no shell here — click a tab or + to add`),$c=P(`<div class=termpane>`),el=P(`<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=P(`<button class=jump>↓ `),nl=P(`<div class=cmds>`),rl=P(`<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=P(`<div><form><textarea rows=1></textarea><button type=button class="iconbtn maxbtn"></button><button type=submit>send</button></form><div class=hint>`),al=P(`<h3 title="identity + storage locations for this agent">🎛 session`),ol=P(`<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=P(`<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=P(`<div class=meta style=color:var(--fg)>`),ll=P(`<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=P(`<h3>⏯ controls`),dl=P(`<button class=danger title="interrupt: aborts the current LLM call; the running tool finishes first">■ stop`),fl=P(`<button title="stop every sub-agent this agent spawned (descendants included)">⏹ subs`),pl=P(`<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=P(`<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=P(`<span>`),gl=P(`<h3 title="what the agent is working toward — auto-continue keeps looping while the status is 'active'">🎯 goal`),_l=P(`<div class=statrow style=margin-bottom:6px><span class=k>status`),vl=P(`<div class=card><div class=content>`),yl=P(`<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=P(`<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=P(`<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=P(`<span class=badge>/<!> done`),Cl=P(`<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=P(`<div class=bartrack style=margin-bottom:6px><div>`),Tl=P(`<textarea id=todo-input class=mono rows=5 placeholder="- task one
21
21
  - task two"title="shared with the agent — it may check items off via set_todo; your unsaved edits win until you save"style="width:100%;background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font-family:ui-monospace,Menlo,monospace;font-size:12.5px;resize:vertical">`),El=P(`<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=P(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),Ol=P(`<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=P(`<span class="pill ok">⚡ <!>% cached`),Al=P(`<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=P(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),Ml=P(`<h3>⏰ schedule <span class=muted style=text-transform:none;letter-spacing:0>· cron tasks, all agents · edit in settings`),Nl=P(`<div><nav class=sidebar><div class=agent-list></div><div class=sidebar-footer><div class=footer-row style=justify-content:flex-end><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><span></span></div></div><div class=metrics></div></div></nav><section class=channel></section><aside>`),Pl=P(`<div class=notifbackdrop>`),Fl=P(`<button class=editbtn>clear all`),Il=P(`<div class=notiflist>`),Ll=P(`<div class=notifpanel><div class=notifhead>notifications<span style=display:flex;gap:8px;align-items:center><button class=iconbtn title="close notifications">✕`),Rl=P(`<span class=caret>`),zl=P(`<span class=subtag>🧩`),Bl=P(`<span class=mini-cron>⏰`),Vl=P(`<span title="goal done">✓`),Hl=P(`<div><span></span><span>`),Ul=P(`<span class=caret-spacer>`),Wl=P(`<span>🧩 `),Gl=P(`<label class=trow>system light →<select class=w100>`),Kl=P(`<label class=trow>system dark →<select class=w100>`),ql=P(`<option>`),Jl=P(`<button><span class=swdots>`),Yl=P(`<i>`),Xl=P(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),Zl=P(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),Ql=P(`<div class="content muted">thinking…`),$l=P(`<span>⌨ <button class=tabx title="close this shell">✕`),eu=P(`<div><b class=mono></b><span class=muted>`),tu=P(`<div class=cmdrow><b>@</b><span class=muted>`),nu=P(`<button class=runbtn title="run toward the goal (starts the loop)">▶ start`),ru=P(`<span class=badge title="no goal set yet">no goal`),iu=P(`<button>`),au=P(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),ou=P(`<div><div class=vtitle><span class="meta muted"style=margin-left:auto></span></div><div class=content>`),su=P(`<div class="content mdpreview"style="max-height:40vh;padding:8px 10px">`),cu=P(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),lu=P(`<div class=progrow><b>recent</b><span class="content inline-md">`),uu=P(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),du=P(`<div class=progrow><b>next</b><span class="content inline-md">`),fu=P(`<div class=progrow><b>goal</b><span>`),pu=P(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),mu=P(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),hu=P(`<span>% of `),gu=P(`<div class=bartrack><div>`),_u=P(`<div class=bartrack style=margin-top:4px><div>`),vu=P(`<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`),yu=P(`<div><span></span><span> events`),bu=P(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),xu=P(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),Su=P(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class="sched-meta mono"> → next </div><div class="sched-prompt muted">`),Cu=P(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),wu=P(`<div class=nbody>`),Tu=P(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted">`),Eu=P(`<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)`),Du=P(`<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`),Ou=P(`<span class=bashelapsed>running… `),ku=P(`<span class=bashelapsed> elapsed`),Au=P(`<div class=mono>`),ju=P(`<pre class="mono toolbody">`),Mu=P(`<div class=meta>ms`),Nu=P(`<div class=meta>waiting for output…`),Pu=P(`<div class="meta muted"> bytes — open it from 🗂 files for the full view`),Fu=P(`<div class=meta>`),Iu=P(`<div class=meta>writing…`),Lu=P(`<pre class="mono toolbody del">`),Ru=P(`<pre class="mono toolbody add">`),zu=P(`<div class=meta> · <!>ms`),Bu=P(`<div class=meta>applying…`),Vu=P(`<pre class="mono toolbody patch">`),Hu=P(`<div>`),Uu=P(`<div class="pline meta">… <!> more lines`),Wu=P(`<div class=meta>validating…`),Gu=P(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),Ku=P(`<span class=muted>`),qu=P(`<div class=meta>loading…`),Ju=P(`<div class=meta>bundled: `),Yu=P(`<div class=meta>saving…`),Xu=P(`<span class=actor>@`),Zu=P(`<details><summary><b>⚙ </b><span class=meta>`),Qu=P(`<div class=divider-msg>⑂ forked from <!> → `),$u=P(`<div class=divider-msg>🎯 goal <!>: `),ed=P(`<div class=divider-msg>✅ tasks updated (<!>)`),td=P(`<div> → `),nd=P(`<div class=avatar>`),rd=P(`<span class=grouptime>·`),id=P(`<button class=editbtn title="withdraw this message — it has not reached the model yet; the text goes back to the input box">✕ cancel`),ad=P(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),od=P(`<div class=msg-head><span class=author></span><span class=ts></span><span class=ts>`),sd=P(`<div><div class=msg-body>`),cd=P(`<span style=width:38px>`),ld=P(`<div class=qfree><input type=text><button>reply`),ud=P(`<div class=interrupted>⚠ interrupted — partial output kept`),dd=P(`<div class=msgfoot><span>copy summary`),fd=P(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>ms`),pd=P(`<div class="content muted">Rejected: `),md=P(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged</span></summary><div class=content>`),hd=P(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),gd=P(`<div class=qopts>`),_d=P(`<div><div>❓ `),vd=P(`<button class=qopt>`),yd=P(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),bd=P(`<div class="embed fail"><div class=mono>⚠ `),xd=P(`<div class=vtitle style=margin-top:6px>what the agent kept`),Sd=P(`<details class="embed compaction"><summary><b>🗜 context compacted</b><span class=meta> · <!> → <!> tok · `),Cd=P(`<div class="content muted">`),wd=P(`<button class=copybtn>`),Td=P(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),Ed=P(`<span style=color:var(--err);font-size:13px>`),Dd=P(`<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`),Od=P(`<div class=direntry>📁 `),kd=P(`<span class=fsize>`),Ad=P(`<div><span class=ficon></span><span class=fname>`),jd=P(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview"style=display:flex;align-items:center;gap:6px>🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· </span><button class=iconbtn style=margin-left:auto;font-size:11px></button><button class=iconbtn style=font-size:11px>`),Md=P(`<div class=filebox>`),Nd=P(`<div class=muted style=padding:6px>`),Pd=P(`<img>`),Fd=P(`<div class=mediapreview><div class="meta muted"> preview`),Id=P(`<button title="rendered markdown">👁 preview`),Ld=P(`<button title="edit and save back to the workspace">✎ edit`),Rd=P(`<div class=filetoolbar><button title="syntax-highlighted source">&lt;/> code`),zd=P(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Bd=P(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Vd=P(`<div class="content mdpreview">`),Hd=P(`<video controls>`),Ud=P(`<audio controls>`),Wd=P(`<div class=filepreview>`),Gd=P(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),Kd=P(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),qd=P(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),Jd=P(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),Yd=P(`<span style=color:var(--fg)>`),Xd=P(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),Zd=P(`<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=P(`<button type=button>`),$d=P(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),ef=P(`<label><input type=number min=0>`),tf=P(`<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`),nf=P(`<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">✕`),rf=P(`<button type=button>+ `),af=P(`<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">`),of=P(`<span class=muted>🧩 sub of @`),sf=P(`<div class=cfgrow><b></b><span class=muted>`),cf=new Map;function lf(e){let t=cf.get(e);if(t!==void 0)return t;let n=Fe(e);return cf.set(e,n),cf.size>500&&cf.delete(cf.keys().next().value),n}var uf={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`}},df={name:`harness`,icon:`📣`,color:`#3ba55d`},[ff,pf]=v(``),mf,Q=e=>{pf(e),clearTimeout(mf),mf=setTimeout(()=>pf(``),3200)},hf=[{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 gf(){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 _f=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`?uf.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:df}return uf[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},vf=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`]),yf=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 bf=location.hash.match(/[#&]token=([^&]+)/);bf&&(localStorage.setItem(`teapot.token`,decodeURIComponent(bf[1])),history.replaceState(null,``,location.pathname+location.search));var xf=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function Sf(){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,w]=v(!1),[T,E]=v(!1),[te,D]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>1100:localStorage.getItem(`teapot.panel`)===`1`),ne=()=>{let e=!te();D(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},[re,ie]=v(!1),[O,ae]=v(localStorage.getItem(`teapot.theme`)??`dark`),[oe,se]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[ce,le]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[ue,de]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),k=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[fe,pe]=v(k?.matches??!1);ee(()=>{let e=e=>pe(e.matches);k?.addEventListener(`change`,e),C(()=>k?.removeEventListener(`change`,e))}),b(()=>{let e=oe()?fe()?ce():ue():O();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=hf.find(t=>t.key===e)?.mode??`dark`});let[me,he]=v(``),[ge,_e]=v(``),[ve,ye]=v([]),be=()=>Object.keys(g().providers??{});async function xe(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);ye(t.models??[])}catch{ye([])}}let Se=()=>{let e=ge().trim()||R()?.model||``;if(!e)return``;let t=ve().find(t=>t.id===e);if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${jf(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||be()[0]||``;r&&(me()!==i&&(he(i),xe(i)),ge()&&_e(``))});let[P,Ce]=v(!1),[Oe,ke]=v(!0),[Ae,je]=v(0),[Me,Ne]=v(null),[Pe,Ie]=v(``),Le;b(()=>{if(!Me()){clearTimeout(Le),Le=void 0,Ie(``);return}Le||=setTimeout(()=>{Le=void 0,Ie(Me()?.text??``)},(Me()?.text.length??0)>2e4?250:(Me()?.text.length??0)>6e3?120:60)}),C(()=>clearTimeout(Le)),b(()=>{Pe()&&Oe()&&requestAnimationFrame(()=>{Oe()&&Ft(!0)})}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{Pt()&&(ke(!0),je(0),Ft(!0))})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let R=x(()=>e().find(e=>e.id===n())),[Re,ze]=v(null);x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let[Be,Ve]=v([]),[z,B]=v([]),[He,Ue]=v(!1),We=()=>z().filter(e=>!e.read).length,Ge=0,Ke=e=>{B(t=>[{...e,id:`n${++Ge}`,at:Date.now(),read:!1},...t].slice(0,50))},qe=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t;n.type===`message`&&n.data?.final===!0?Ke({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300)}):n.type===`question`?Ke({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300)}):n.type===`error`?Ke({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300)}):n.type===`progress`&&Ke({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)})},Je=x(()=>{let e=new Map,t=new Set,n=new Map;for(let r of i())if(vf.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}}),Ye=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}),Xe=x(()=>{let{consumed:e}=Je(),t=i().filter(t=>{if(!vf.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=Be().filter(e=>!a.some(t=>t.type===`prompt`&&t.data?.source===`user`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)).map(e=>({id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:R()?.session??``,branch:R()?.branch??`br0`,parent:null,type:`prompt`,data:{source:`user`,text:e.text,pending:!e.sent,...e.promptId?{promptId:e.promptId}:{}}}));return[...a,...o]}),Ze=()=>$(`/api/config`).then(_).catch(()=>{}),[Qe,$e]=v(!1);ee(()=>{let e=()=>$e(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[et,tt]=v(``),[nt,rt]=v(!1),[it,at]=v(!1),ot=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==ot?(ot=t,at(!1),tt(r)):t&&!it()&&tt(r)});let st=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:et(),notify:e})}),at(!1),Q(`tasks saved${e&&et().trim()?` & notification queued`:``}`),lt()}catch(e){Q(`save failed: ${e.message}`)}},ct=x(()=>{let e=0,t=0;for(let n of et().split(`
22
- `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),lt=()=>$(`/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(()=>{}),ut=()=>$(`/api/metrics`).then(d).catch(()=>{}),[dt,ft]=v([]),pt=()=>$(`/api/tasks`).then(e=>ft(e.tasks)).catch(()=>{}),mt=e=>dt().filter(t=>t.agent===e),[ht,gt]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),_t=e=>{let t=new Set(ht());t.has(e)?t.delete(e):t.add(e),gt(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},vt=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&&!ht().has(r.id)&&a(e,t+1)}};return a(r,0),i}),[yt,bt]=v(null),xt=new Map;function St(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=xt.get(r.id);if(t[n]=i??r,!i&&(xt.set(r.id,r),xt.size>3e3)){let e=xt.keys().next().value;e!==void 0&&xt.delete(e)}}return t}let[Ct,wt]=v(!1),[Tt,Et]=v(!1),Dt=0,Ot=-1;function kt(e){a(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of St(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function At(){let e=n(),t=i()[0];if(!(!e||!t||Ct()||Tt())){wt(!0);try{let r=Mt(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=yt(),c=(await $(`/api/agents/${e}/events?limit=300&before=${encodeURIComponent(t.id)}${s?`&branch=${encodeURIComponent(s)}`:``}`)).events??[];if(c.length===0){Et(!0);return}if(n()!==e||i()[0]?.id!==t.id)return;kt(c),requestAnimationFrame(()=>{if(n()===e){let e=Mt();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{wt(!1)}}}async function jt(e){let t=Dt;try{let r=yt(),i=t!==Ot||!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&&(Ot=t),t!==Dt||n()!==e)return;a(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of St(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),Dn(d.skills??[])}catch{}}function Mt(){return document.querySelector(`.feed`)}function Nt(){let e=document.querySelector(`.composer textarea`);return 80+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function Pt(){let e=Mt();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<Nt()}function Ft(e=!1){let t=Mt();t&&(e||Oe())&&(t.scrollTop=t.scrollHeight,je(0))}async function It(e,t=!0){let i=n();Dt++,i!==e&&(a([]),xt.clear(),Ne(null),je(0)),r(e),h(f.get(e)??``),bt(null),Et(!1),wt(!1),Ve([]),localStorage.setItem(`teapot.session`,e),Gt(e,t),$(`/api/agents/${e}/load`,{method:`POST`}).then(lt).catch(()=>{}),await jt(e),n()===e&&requestAnimationFrame(()=>{n()===e&&Ft(!0)})}let[Lt,Rt]=v(!1),zt=null,Bt=null;C(()=>zt?.close());let Vt=!1,Ht=null;document.addEventListener(`visibilitychange`,()=>Ht?.()),C(()=>{Ht=null});function Ut(){let e=location.protocol===`https:`?`wss://`:`ws://`;zt=new WebSocket(`${e}${location.host}/api/ws${xf()}`),zt.onopen=()=>Rt(!0),zt.onclose=()=>{Rt(!1),setTimeout(Ut,1500)},zt.onerror=()=>zt?.close();let r=new Set([`state`,`usage`,`session_start`]),a=null;zt.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()&&Ne({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()){Ve(e=>e.map(e=>e.promptId===t.promptId?{...e,sent:!0}:e));return}if(e===`system_note`&&t.event===`prompt-cancelled`&&i.agentId===n()){Ve(e=>e.filter(e=>e.promptId!==t.promptId));return}if(r.has(e)||(qe(i.agentId,i.event),i.event?.agent!==n()))return}if(document.visibilityState===`hidden`){Vt=!0,Bt||=setTimeout(s,2e3);return}Bt||=setTimeout(s,400)}},Vt=!1;let s=async()=>{if(Bt=null,await lt(),await ut(),n()){let e=i().at(-1)?.id,t=o(),r=Date.now();await jt(n()),i().at(-1)?.id!==e&&(a?.id===n()&&a.at>=r||Ne(null),Oe()?Ft(!0):je(Ae()+Math.max(0,o()-t))),Ve(e=>e.filter(e=>!i().some(t=>t.type===`prompt`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)))}};Ht=()=>{document.visibilityState===`visible`&&Vt&&(Vt=!1,Bt||=setTimeout(s,150))}}let Wt=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function Gt(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let t=Wt();t&&e().some(e=>e.id===t)&&t!==n()&&It(t,!1)}),b(()=>{let e=R(),t=e?`${e.status===`running`?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=We()>0?`(${We()}) ${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()){w(!1);return}if(T()){E(!1);return}if(Re()){ze(null);return}if(re()){ie(!1);return}let e=R();if(e?.status===`running`){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(lt);return}te()&&window.innerWidth<=1100&&D(!1);return}if(!(S()||T())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)ne();else if(e.key===`t`)Jt();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=vt().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&&It(t[i].id)}}});let[Kt,qt]=v(localStorage.getItem(`teapot.term`)===`1`),Jt=()=>{let e=!Kt();qt(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[Yt,Xt]=v([]),[Zt,Qt]=v(0),[$t,V]=v(-1),[en,tn]=v(!1),[H,nn]=v(0),[rn,an]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),U=new Map,on=[null,null],sn=()=>Yt()[H()===0?Zt():$t()]??null;function cn(e){if(!Yt()[e])return;let t=H()===0?Zt:$t;(H()===0?$t:Zt)()===e&&(H()===0?V(t()):Qt(t())),t()===e||(H()===0?Qt(e):V(e))}let ln=()=>un();function un(e){let t=e??n();if(!t)return;let r=Yt().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}Yt().length+1;let i=r===0?{key:`${t}`,agentId:t,title:t}:{key:`${t}#${r+1}`,agentId:t,title:`${t}·${r+1}`};Xt(e=>[...e,i]),H()===0?Qt(Yt().length):V(Yt().length)}function dn(e){let t=Yt()[e];if(!t)return;let n=U.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),U.delete(t.key)}let r=Yt().filter((t,n)=>n!==e);Xt(r);let i=t=>t===e?-1:t>e?t-1:t;Qt(e=>Math.min(i(e),r.length-1)),V(e=>e===-1?-1:Math.min(i(e),r.length-1))}function fn(){for(let[,e]of U){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}U.clear()}function pn(e,t){let n=U.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:gf()}),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${xf()}`);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},U.set(e.key,n)}return n}function mn(e){let t=on[e];if(!t)return;let n=Yt()[e===0?Zt():$t()];if(!n){[...U.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=pn(n,t);requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(H()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{if(!Kt())return;let e=n();if(e){if(!Yt().some(t=>t.agentId===e)&&Yt().length===0)un(e);else if(!Yt().some(t=>t.agentId===e)){let t=Yt().findIndex(t=>t.agentId===e);t>=0&&cn(t)}}});let hn=e=>{e.preventDefault();let t=e.clientY,n=rn(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));an(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(rn())),requestAnimationFrame(()=>{mn(0),en()&&mn(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},gn=()=>{let e=!en();if(tn(e),e&&$t()===-1){let e=Yt().findIndex((e,t)=>t!==Zt());V(e>=0?e:-1)}};C(fn);let _n=e=>t=>{on[e]=t};ee(()=>{Ze(),lt().then(()=>{let t=Wt()||localStorage.getItem(`teapot.session`)||``,n=e().find(e=>e.id===t)??e()[0];n&&It(n.id,!1)}),ut(),pt(),W(),Ut();let t=setInterval(()=>{ut(),pt()},3e4);C(()=>clearInterval(t))});let vn=[{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`}],[yn,bn]=v([]),W=()=>$(`/api/personas`).then(e=>bn(e.personas)).catch(()=>{}),[xn,Sn]=v(!1),Cn=()=>{let e=p().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},wn=()=>{let t=Cn();return t===null?[]:[...yn().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))},Tn=new Set([`start`,`stop`,`fork`,`compact`]),[En,Dn]=v([]),[On,kn]=v(-1),An=()=>{let e=p();if(!e.startsWith(`/`)||e.includes(`
22
+ `)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),lt=()=>$(`/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(()=>{}),ut=()=>$(`/api/metrics`).then(d).catch(()=>{}),[dt,ft]=v([]),pt=()=>$(`/api/tasks`).then(e=>ft(e.tasks)).catch(()=>{}),mt=e=>dt().filter(t=>t.agent===e),[ht,gt]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),_t=e=>{let t=new Set(ht());t.has(e)?t.delete(e):t.add(e),gt(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},vt=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&&!ht().has(r.id)&&a(e,t+1)}};return a(r,0),i}),[yt,bt]=v(null),xt=new Map;function St(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=xt.get(r.id);if(t[n]=i??r,!i&&(xt.set(r.id,r),xt.size>3e3)){let e=xt.keys().next().value;e!==void 0&&xt.delete(e)}}return t}let[Ct,wt]=v(!1),[Tt,Et]=v(!1),Dt=0,Ot=-1;function kt(e){a(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of St(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function At(){let e=n(),t=i()[0];if(!(!e||!t||Ct()||Tt())){wt(!0);try{let r=Mt(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=yt(),c=(await $(`/api/agents/${e}/events?limit=300&before=${encodeURIComponent(t.id)}${s?`&branch=${encodeURIComponent(s)}`:``}`)).events??[];if(c.length===0){Et(!0);return}if(n()!==e||i()[0]?.id!==t.id)return;kt(c),requestAnimationFrame(()=>{if(n()===e){let e=Mt();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{wt(!1)}}}async function jt(e){let t=Dt;try{let r=yt(),i=t!==Ot||!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&&(Ot=t),t!==Dt||n()!==e)return;a(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of St(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),Dn(d.skills??[])}catch{}}function Mt(){return document.querySelector(`.feed`)}function Nt(){let e=document.querySelector(`.composer textarea`);return 80+Math.min(Math.max((e?.scrollHeight??0)-(e?.clientHeight??0),0),160)}function Pt(){let e=Mt();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<Nt()}function Ft(e=!1){let t=Mt();t&&(e||Oe())&&(t.scrollTop=t.scrollHeight,je(0))}async function It(e,t=!0){let i=n();Dt++,i!==e&&(a([]),xt.clear(),Ne(null),je(0)),r(e),h(f.get(e)??``),bt(null),Et(!1),wt(!1),Ve([]),localStorage.setItem(`teapot.session`,e),Gt(e,t),$(`/api/agents/${e}/load`,{method:`POST`}).then(lt).catch(()=>{}),await jt(e),n()===e&&requestAnimationFrame(()=>{n()===e&&Ft(!0)})}let[Lt,Rt]=v(!1),zt=null,Bt=null;C(()=>zt?.close());let Vt=!1,Ht=null;document.addEventListener(`visibilitychange`,()=>Ht?.()),C(()=>{Ht=null});function Ut(){let e=location.protocol===`https:`?`wss://`:`ws://`;zt=new WebSocket(`${e}${location.host}/api/ws${xf()}`),zt.onopen=()=>Rt(!0),zt.onclose=()=>{Rt(!1),setTimeout(Ut,1500)},zt.onerror=()=>zt?.close();let r=new Set([`state`,`usage`,`session_start`]),a=null;zt.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()&&Ne({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()){Ve(e=>e.map(e=>e.promptId===t.promptId?{...e,sent:!0}:e));return}if(e===`message`&&t.role===`assistant`&&i.agentId===n()&&Ve(e=>e.filter(e=>!e.sent)),e===`system_note`&&t.event===`prompt-cancelled`&&i.agentId===n()){Ve(e=>e.filter(e=>e.promptId!==t.promptId));return}if(r.has(e)||(qe(i.agentId,i.event),i.event?.agent!==n()))return}if(document.visibilityState===`hidden`){Vt=!0,Bt||=setTimeout(s,2e3);return}Bt||=setTimeout(s,400)}},Vt=!1;let s=async()=>{if(Bt=null,await lt(),await ut(),n()){let e=i().at(-1)?.id,t=o(),r=Date.now();await jt(n()),i().at(-1)?.id!==e&&(a?.id===n()&&a.at>=r||Ne(null),Oe()?Ft(!0):je(Ae()+Math.max(0,o()-t)))}};Ht=()=>{document.visibilityState===`visible`&&Vt&&(Vt=!1,Bt||=setTimeout(s,150))}}let Wt=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function Gt(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let t=Wt();t&&e().some(e=>e.id===t)&&t!==n()&&It(t,!1)}),b(()=>{let e=R(),t=e?`${e.status===`running`?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=We()>0?`(${We()}) ${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()){w(!1);return}if(T()){E(!1);return}if(Re()){ze(null);return}if(re()){ie(!1);return}let e=R();if(e?.status===`running`){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(lt);return}te()&&window.innerWidth<=1100&&D(!1);return}if(!(S()||T())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)ne();else if(e.key===`t`)Jt();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=vt().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&&It(t[i].id)}}});let[Kt,qt]=v(localStorage.getItem(`teapot.term`)===`1`),Jt=()=>{let e=!Kt();qt(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[Yt,Xt]=v([]),[Zt,Qt]=v(0),[$t,V]=v(-1),[en,tn]=v(!1),[H,nn]=v(0),[rn,an]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),U=new Map,on=[null,null],sn=()=>Yt()[H()===0?Zt():$t()]??null;function cn(e){if(!Yt()[e])return;let t=H()===0?Zt:$t;(H()===0?$t:Zt)()===e&&(H()===0?V(t()):Qt(t())),t()===e||(H()===0?Qt(e):V(e))}let ln=()=>un();function un(e){let t=e??n();if(!t)return;let r=Yt().filter(e=>e.agentId===t).length;if(r>=10){Q(`max 10 shells per agent (${t}) — that's already a lot`);return}Yt().length+1;let i=r===0?{key:`${t}`,agentId:t,title:t}:{key:`${t}#${r+1}`,agentId:t,title:`${t}·${r+1}`};Xt(e=>[...e,i]),H()===0?Qt(Yt().length):V(Yt().length)}function dn(e){let t=Yt()[e];if(!t)return;let n=U.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),U.delete(t.key)}let r=Yt().filter((t,n)=>n!==e);Xt(r);let i=t=>t===e?-1:t>e?t-1:t;Qt(e=>Math.min(i(e),r.length-1)),V(e=>e===-1?-1:Math.min(i(e),r.length-1))}function fn(){for(let[,e]of U){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}U.clear()}function pn(e,t){let n=U.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:gf()}),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${xf()}`);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},U.set(e.key,n)}return n}function mn(e){let t=on[e];if(!t)return;let n=Yt()[e===0?Zt():$t()];if(!n){[...U.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=pn(n,t);requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(H()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{if(!Kt())return;let e=n();if(e){if(!Yt().some(t=>t.agentId===e)&&Yt().length===0)un(e);else if(!Yt().some(t=>t.agentId===e)){let t=Yt().findIndex(t=>t.agentId===e);t>=0&&cn(t)}}});let hn=e=>{e.preventDefault();let t=e.clientY,n=rn(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));an(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(rn())),requestAnimationFrame(()=>{mn(0),en()&&mn(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},gn=()=>{let e=!en();if(tn(e),e&&$t()===-1){let e=Yt().findIndex((e,t)=>t!==Zt());V(e>=0?e:-1)}};C(fn);let _n=e=>t=>{on[e]=t};ee(()=>{Ze(),lt().then(()=>{let t=Wt()||localStorage.getItem(`teapot.session`)||``,n=e().find(e=>e.id===t)??e()[0];n&&It(n.id,!1)}),ut(),pt(),W(),Ut();let t=setInterval(()=>{ut(),pt()},3e4);C(()=>clearInterval(t))});let vn=[{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`}],[yn,bn]=v([]),W=()=>$(`/api/personas`).then(e=>bn(e.personas)).catch(()=>{}),[xn,Sn]=v(!1),Cn=()=>{let e=p().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},wn=()=>{let t=Cn();return t===null?[]:[...yn().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))},Tn=new Set([`start`,`stop`,`fork`,`compact`]),[En,Dn]=v([]),[On,kn]=v(-1),An=()=>{let e=p();if(!e.startsWith(`/`)||e.includes(`
23
23
  `))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[3]??``).trim();if(!r&&n!==`skill`){let e=vn.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Tn.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=En().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[]},jn,Mn=()=>{if(!jn)return;Nn=!0;let e=Oe();jn.style.height=`auto`,jn.style.height=P()?``:`${Math.min(jn.scrollHeight,360)}px`,requestAnimationFrame(()=>{let t=Mt();e&&t&&(t.scrollTop=t.scrollHeight),Nn=!1})},Nn=!1;b(()=>{p(),Mn()});let Pn=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})});Ve(n=>[...n,{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now(),promptId:t.promptId}]),requestAnimationFrame(()=>requestAnimationFrame(()=>Ft(!0)))}catch(t){h(e),console.error(`send failed:`,t)}},Fn=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=yn().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:xn()?`fork`:`none`})})).id}${xn()?` (forked context)`:``}`),lt(),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: ${yn().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 In(t,n);return}h(``),await Pn(i)}},In=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(lt);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await It(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 Pn(`[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}`)}},Ln,Rn=0;b(()=>{e(),requestAnimationFrame(()=>{Ln&&(Rn=Math.min(Rn,Ln.scrollHeight),Ln.scrollTop=Rn)})});let zn=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(lt),Bn=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=``),lt())};return[A(M,{get when(){return g()?.needsSetup},fallback:null,get children(){return A(Gf,{onDone:()=>location.reload()})}}),A(M,{get when(){return Qe()},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}}),A(M,{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.firstChild;var _=m.nextSibling,v=_.nextSibling,b=v.nextSibling,x=f.nextSibling,S=x.firstChild.firstChild.nextSibling;S.firstChild;var ee=S.nextSibling,C=x.nextSibling,T=s.nextSibling,D=T.nextSibling;L(l,A(j,{get each(){return vt()},children:({a:t,depth:r})=>(()=>{var i=Hl(),a=i.firstChild,o=a.nextSibling;return i.$$click=()=>It(t.id),L(i,A(M,{get when(){return e().some(e=>e.parent===t.id)},get fallback(){return Ul()},get children(){var e=Rl();return e.$$click=e=>{e.stopPropagation(),_t(t.id)},L(e,()=>ht().has(t.id)?`▸`:`▾`),y(()=>F(e,`title`,ht().has(t.id)?`expand sub-agents`:`collapse sub-agents`)),e}}),a),L(o,()=>t.id),L(i,A(M,{get when(){return ht().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=Wl();return e.firstChild,I(e,`subcount`+(r>0?` live`:``)),L(e,()=>n.length,null),L(e,r>0?` · ▶${r}`:``,null),y(()=>F(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),L(i,A(M,{get when(){return t.parent},get children(){return zl()}}),null),L(i,A(M,{get when(){return mt(t.id).length>0},get children(){var e=Bl();return y(()=>F(e,`title`,mt(t.id).map(e=>`${e.id}: ${e.schedule}`).join(`
24
- `))),e}}),null),L(i,A(M,{get when(){return t.goal.status===`done`},get children(){return Vl()}}),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&&I(i,e.e=o),e.t=Te(i,s,e.t),c!==e.a&&F(i,`title`,e.a=c),l!==e.o&&I(a,e.o=l),e},{e:void 0,t:void 0,a:void 0,o:void 0}),i})()})),L(d,A(M,{get when(){return re()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;se(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),L(e,A(M,{get when(){return!oe()},get fallback(){return[(()=>{var e=Gl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{le(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),L(t,A(j,{get each(){return hf.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=ql();return L(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ce()),e})(),(()=>{var e=Kl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),L(t,A(j,{get each(){return hf.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=ql();return L(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ue()),e})()]},get children(){var e=Ic();return L(e,A(j,{each:hf,children:e=>(()=>{var t=Jl(),n=t.firstChild;return t.$$click=()=>{ae(e.key),localStorage.setItem(`teapot.theme`,e.key)},L(n,()=>e.sw.map(e=>(()=>{var t=Yl();return Ee(t,`background`,e),t})())),L(t,()=>e.label,null),y(n=>{var r=`themebtn`+(O()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=oe()),e}}),f),m.$$click=e=>{e.stopPropagation(),Ue(!He()),He()||B(e=>e.map(e=>({...e,read:!0})))},L(m,A(M,{get when(){return We()>0},get children(){var e=Rc();return L(e,We),e}}),null),_.$$click=()=>{Ze(),w(!0)},v.$$click=()=>ie(!re()),b.$$click=()=>{Ze(),E(!0)},L(S,`0.17.2`,null),L(C,A(M,{get when(){return u()},get children(){return[`master rss `,N(()=>u().rssMb),`MB · heap `,N(()=>u().heapUsedMb),`MB`,zc(),`load1 `,N(()=>u().loadavg1),` · up `,N(()=>Math.floor(u().uptimeSec/60)),`m`]}})),L(T,A(M,{get when(){return R()},get fallback(){return Xl()},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 L(t,()=>R().id),L(n,()=>R().status),L(e,A(M,{get when(){return(R().pendingPrompts??0)>0},get children(){var e=Bc(),t=e.firstChild.nextSibling;return t.nextSibling,L(e,()=>R().pendingPrompts,t),y(()=>F(e,`title`,`${R().pendingPrompts??0} message${(R().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),L(e,A(M,{get when(){return mt(R().id).length>0},get children(){var e=Vc();return e.firstChild,L(e,()=>mt(R().id).length,null),y(()=>F(e,`title`,`scheduled tasks:\n${mt(R().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
25
- `)}`)),e}}),r),L(r,()=>R().model,i),L(r,()=>R().session,a),L(r,()=>R().branch,o),L(r,()=>R().stats.turns,s),L(r,()=>R().stats.toolCalls,null),L(c,A(M,{get when(){return R().statusReason},get children(){var e=Hc();return y(()=>F(e,`title`,R().statusReason)),e}}),l),l.$$click=Jt,u.$$click=ne,y(()=>I(n,`badge ${R().status}`)),e})(),(()=>{var e=Yc();return e.addEventListener(`scroll`,e=>{if(Nn)return;let t=e.currentTarget,r=Pt();r&&Ae()&&je(0),ke(r),t.scrollTop<=4&&n()&&!Ct()&&!Tt()&&i().length>0&&At()}),L(e,A(M,{get when(){return N(()=>!!Tt())()&&Xe().length>0},get children(){return Wc()}}),null),L(e,A(M,{get when(){return Ct()},get children(){return Gc()}}),null),L(e,A(M,{get when(){return Xe().length>0},get fallback(){return Zl()},get children(){return[A(j,{get each(){return Xe()},children:(e,t)=>A(Ef,{e,get prev(){return Xe()[t()-1]},get res(){return Je().resFor.get(e.id)},onOption:e=>void Pn(e),get answeredIds(){return Ye()},get agentActive(){return R()?.status===`running`||R()?.status===`waiting`},onResize:()=>{Oe()&&requestAnimationFrame(()=>Ft(!0))},get onCancel(){return e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);h(p()?`${n}\n\n${p()}`:n),Ve(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`?()=>ze({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),A(M,{get when(){return Me()},get children(){var e=Jc(),t=e.firstChild.nextSibling;return t.firstChild,L(t,A(M,{get when(){return Me().reasoning},get children(){var e=Kc(),t=e.firstChild.nextSibling;return L(t,()=>Me().reasoning),e}}),null),L(t,A(M,{get when(){return Pe()},get fallback(){return Ql()},get children(){var e=qc();return y(()=>e.innerHTML=Fe(Pe()+`▍`)),e}}),null),e}})]}}),null),e})(),A(M,{get when(){return Kt()},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=()=>{an(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(rn()))},n.$$pointerdown=hn,L(i,A(j,{get each(){return Yt()},children:(e,t)=>(()=>{var n=$l(),r=n.firstChild.nextSibling;return n.$$click=()=>cn(t()),L(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),dn(t())},y(r=>{var i=`termtab`+(H()===0&&Zt()===t()?` active`:``)+(en()&&H()===1&&$t()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),a),a.$$click=ln,L(o,(()=>{var t=N(()=>!!sn());return()=>t()?e().find(e=>e.id===sn().agentId)?.workspace.split(`/`).filter(Boolean).pop():R()?.workspace})()),s.$$click=gn,c.$$click=Jt;var d=_n(0);return typeof d==`function`&&De(d,u),u.$$pointerdown=()=>nn(0),L(u,A(M,{get when(){return!sn()||H()===0&&Zt()===-1},get children(){return Xc()}})),L(l,A(M,{get when(){return en()},get children(){return[Zc(),(()=>{var e=$c(),t=_n(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>nn(1),L(e,A(M,{get when(){return $t()===-1||Yt().length<=$t()},get children(){return Qc()}})),y(()=>e.classList.toggle(`focused`,H()===1)),e})()]}}),null),y(e=>{var n={height:`${rn()}px`,"--termh":`${rn()}px`},r=en()?`single pane`:`split panes (50/50)`,i=!!en(),a=H()===0;return e.e=Te(t,n,e.e),r!==e.t&&F(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;L(e,A(M,{get when(){return!Oe()||Ae()>0},get children(){var e=tl();return e.firstChild,e.$$click=()=>Ft(!0),L(e,(()=>{var e=N(()=>Ae()>0);return()=>e()?`${Ae()} new message${Ae()>1?`s`:``}`:`jump to present`})(),null),e}}),t),L(e,A(M,{get when(){return An().length>0},get children(){var e=nl();return L(e,A(j,{get each(){return An()},children:(e,t)=>(()=>{var n=eu(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{h(e.insert),kn(-1)},L(r,()=>e.insert.trim()),L(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===On()?` active`:``),a=e.title;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),L(e,A(M,{get when(){return wn().length>0},get children(){var e=nl();return L(e,A(j,{get each(){return wn()},children:e=>(()=>{var t=tu(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{h(`@${e.key} `),kn(-1)},L(n,()=>e.key,null),L(r,()=>e.label),y(()=>F(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Fn),n.$$keydown=e=>{let t=An();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),kn(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),kn(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&On()>=0){e.preventDefault(),h(t[On()].insert),kn(-1);return}if(e.key===`Escape`&&t.length>0){kn(-1);return}e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),Fn(e))},n.$$input=e=>{h(e.currentTarget.value),kn(0),Mn()};var a=jn;return typeof a==`function`?De(a,n):jn=n,L(t,A(M,{get when(){return N(()=>!!p().startsWith(`@`))()&&p().includes(` `)},get children(){var e=rl(),t=e.firstChild;return t.addEventListener(`change`,e=>Sn(e.currentTarget.checked)),y(()=>t.checked=xn()),e}}),r),r.$$click=()=>{let e=!P();Ce(e),requestAnimationFrame(()=>Mn())},L(r,()=>P()?`⤡`:`⤢`),L(i,()=>ff()||`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`+(P()?` maximized`:``),a=`message #${R().id} — / for commands`,o=P()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&I(e,t.e=i),a!==t.t&&F(n,`placeholder`,t.t=a),o!==t.a&&F(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),y(()=>n.value=p()),e})()]}})),D.addEventListener(`scroll`,e=>{Rn=e.currentTarget.scrollTop});var k=Ln;return typeof k==`function`?De(k,D):Ln=D,L(D,A(M,{get when(){return R()},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 L(n,()=>R().id),L(r,()=>R().status),L(a,()=>R().workspace),L(o,()=>R().session,s),L(o,()=>R().branch,null),y(e=>{var t=`badge ${R().status}`,n=R().workspace;return t!==e.e&&I(r,e.e=t),n!==e.t&&F(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),A(Vf,{get agentId(){return R().id},get workspace(){return R().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=>{he(e.currentTarget.value),xe(e.currentTarget.value)}),L(t,A(j,{get each(){return be()},children:e=>(()=>{var t=ql();return t.value=e,L(t,e,null),L(t,()=>e===g().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>_e(e.currentTarget.value),L(a,A(j,{get each(){return ve()},children:e=>(()=>{var t=ql();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:me(),model:ge().trim()||void 0,contextWindowTokens:ve().find(e=>e.id===(ge().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,lt()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},L(s,()=>R().model,null),L(s,A(M,{get when(){return ve().length},get children(){return[` · `,N(()=>ve().length),` models loaded`]}}),null),L(e,A(M,{get when(){return Se()},get children(){var e=cl();return L(e,Se),e}}),null),y(()=>F(i,`placeholder`,R().model)),y(()=>t.value=me()),y(()=>i.value=ge()),e})(),ul(),(()=>{var i=pl(),o=i.firstChild,s=o.nextSibling;return L(i,A(M,{get when(){return R().status===`running`},get fallback(){return(()=>{var e=nu();return we(e,`click`,zn(`/start`),!0),e})()},get children(){var e=dl();return we(e,`click`,zn(`/stop`),!0),e}}),o),o.$$click=()=>$(`/api/agents/${R().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>It(R().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]?It(o[0].id):(r(null),a([]))},L(i,A(M,{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)`}`),lt())},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(lt)}),y(()=>t.checked=R().autoContinue??!0),e})(),(()=>{var e=gl();return e.firstChild,L(e,A(M,{get when(){return!!R().goal.text.trim()},get fallback(){return ru()},get children(){var e=hl();return L(e,()=>R().goal.status),y(()=>I(e,`badge ${R().goal.status===`active`?`running`:R().goal.status}`)),e}}),null),e})(),(()=>{var e=_l();return e.firstChild,L(e,A(j,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=iu();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(lt)},F(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`),L(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(R().goal.text.trim()&&R().goal.status===e?` on ${e}`:``),i=!!R().goal.text.trim()&&R().goal.status===e;return r!==n.e&&I(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),A(M,{get when(){return R().goal.text},get fallback(){return au()},get children(){return[(()=>{var e=vl(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(R().goal.text))),e})(),A(M,{get when(){return R().goal.verify},get children(){var e=yl(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(R().goal.verify))),e}}),A(M,{get when(){return R().goal.audit},children:e=>(()=>{var t=ou(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return L(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),L(r,()=>Af(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=Fe(e().feedback);return r!==n.e&&I(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`,Bn),e})(),(()=>{var e=Cl(),t=e.firstChild.nextSibling;return L(e,A(M,{get when(){return ct().total>0},get children(){var e=Sl(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,L(e,()=>ct().done,t),L(e,()=>ct().total,n),y(t=>Te(e,ct().done===ct().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),A(M,{get when(){return ct().total>0},get children(){var e=wl(),t=e.firstChild;return y(e=>{var n=`barfill `+(ct().done===ct().total?``:`warn`),r=`${Math.round(ct().done/ct().total*100)}%`;return n!==e.e&&I(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),A(M,{get when(){return nt()},get fallback(){return(()=>{var e=su();return y(()=>e.innerHTML=lf(et())),e})()},get children(){var e=Tl();return e.$$input=e=>{tt(e.currentTarget.value),at(!0)},y(()=>e.value=et()),e}}),(()=>{var e=El(),t=e.firstChild,n=t.nextSibling.nextSibling;return t.$$click=()=>rt(!nt()),L(t,()=>nt()?`👁`:`✎`),n.$$click=st,y(()=>F(t,`title`,nt()?`rendered checklist`:`edit markdown`)),e})(),Dl(),A(M,{get when(){return R().latestProgress},get fallback(){return cu()},children:e=>(()=>{var t=pu(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return L(t,A(M,{get when(){return e().recent},get children(){var t=lu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=lf(e().recent)),t}}),i),L(t,A(M,{get when(){return e().problems},get children(){var t=uu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=lf(e().problems)),t}}),i),L(t,A(M,{get when(){return e().next},get children(){var t=du(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=lf(e().next)),t}}),i),L(t,A(M,{get when(){return e().goalStatus},get children(){var t=fu(),n=t.firstChild.nextSibling;return L(n,()=>e().goalStatus),t}}),i),L(i,()=>Af(e().ts)),y(()=>r.innerHTML=lf(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,L(i,()=>R().stats.turns),L(o,()=>R().stats.toolCalls),L(s,()=>R().stats.compactions??0),L(l,()=>jf(R().stats.inputTokens),u),L(l,()=>jf(R().stats.outputTokens),d),L(c,A(M,{get when(){return(R().stats.cachedInputTokens??0)>0},get children(){var e=kl(),t=e.firstChild.nextSibling;return t.nextSibling,L(e,()=>Math.round(R().stats.cachedInputTokens/Math.max(1,R().stats.inputTokens)*1e3)/10,t),y(()=>F(e,`title`,`${jf(R().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),L(e,A(M,{get when(){return R().ctx},get fallback(){return mu()},children:e=>{let t=ve().find(e=>e.id===R().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=vu(),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,L(d,()=>jf(e().usedTokens),f),L(u,A(M,{when:r,get children(){var e=hu(),t=e.firstChild;return I(e,`pill ${a}`),L(e,()=>o(i),t),L(e,()=>jf(r),null),e}}),null),L(t,A(M,{when:r,get children(){var e=gu(),t=e.firstChild;return I(t,`barfill ${a}`),y(e=>Ee(t,`width`,`${Math.min(100,i)}%`)),e}}),p),L(m,()=>jf(l?s:c),h),L(g,l?` (75% of window)`:` (manual override)`),L(t,A(M,{when:r,get children(){var t=_u(),n=t.firstChild;return I(n,`barfill ${a}`),y(t=>Ee(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(lt)}),L(b,()=>jf(e().compactAt),x),y(()=>v.checked=R().autoCompact!==!1),t})()}}),null),e})(),jl(),A(j,{get each(){return c()},children:e=>(()=>{var t=yu(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=yt()===e.branch?null:e.branch;bt(t),n()&&jt(n())},L(r,()=>e.branch,null),L(r,()=>e.branch===R().branch?` (current)`:``,null),L(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===R().branch||e.branch===yt()?` cur`:``),i=e.branch===yt()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Ml(),A(M,{get when(){return dt().length>0},get fallback(){return bu()},get children(){return A(j,{get each(){return dt()},children:e=>(()=>{var t=Su(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>It(e.agent),L(i,()=>e.id),L(a,()=>e.agent,null),L(r,A(M,{get when(){return e.forked},get children(){return xu()}}),null),L(o,()=>e.schedule,s),L(o,(()=>{var t=N(()=>!!e.next);return()=>t()?Af(e.next):`—`})(),null),L(o,(()=>{var t=N(()=>!!e.last);return()=>t()?` · last ${Af(e.last)}`:` · never ran`})(),null),L(c,()=>Mf(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Mf(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&I(t,r.e=i),a!==r.t&&F(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(te()?``:` right-hidden`),n=`iconbtn notifbtn`+(We()>0?` has-unread`:``),r=We()>0?`${We()} unread notifications`:`notifications`,i=`conn`+(Lt()?` ok`:``),a=Lt()?`live (websocket)`:`reconnecting…`,s=`rightbar`+(te()?` open`:``);return t!==e.e&&I(o,e.e=t),n!==e.t&&I(m,e.t=n),r!==e.a&&F(m,`title`,e.a=r),i!==e.o&&I(ee,e.o=i),a!==e.i&&F(ee,`title`,e.i=a),s!==e.n&&I(D,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),o}}),A(M,{get when(){return He()},get children(){return[(()=>{var e=Pl();return e.$$click=()=>Ue(!1),e})(),(()=>{var t=Ll(),n=t.firstChild.firstChild.nextSibling,r=n.firstChild;return L(n,A(M,{get when(){return z().length>0},get children(){var e=Fl();return e.$$click=()=>B([]),e}}),r),r.$$click=()=>Ue(!1),L(t,A(M,{get when(){return z().length>0},get fallback(){return Cu()},get children(){var t=Il();return L(t,A(j,{get each(){return z()},children:t=>(()=>{var n=Tu(),r=n.firstChild.firstChild,i=r.nextSibling,a=i.nextSibling;return n.$$click=()=>{e().some(e=>e.id===t.agentId)&&It(t.agentId),Ue(!1)},L(r,(()=>{var e=N(()=>t.kind===`finish`);return()=>e()?`✅`:N(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),L(i,()=>t.title),L(a,()=>Af(new Date(t.at).toISOString())),L(n,A(M,{get when(){return t.body},get children(){var e=wu();return L(e,()=>kf(t.body,160)),e}}),null),y(e=>{var r=`notifitem `+t.kind,i=`from ${t.agentId}`;return r!==e.e&&I(n,e.e=r),i!==e.t&&F(n,`title`,e.t=i),e},{e:void 0,t:void 0}),n})()})),t}}),null),t})()]}}),A(M,{get when(){return S()},get children(){return A(Ff,{get providers(){return Object.keys(g().providers??{})},onClose:()=>w(!1),onCreated:e=>{w(!1),lt(),It(e)}})}}),A(M,{get when(){return T()},get children(){return A(Kf,{get cfg(){return g()},onClose:()=>E(!1),onSaved:()=>{Ze(),pt()}})}}),A(M,{get when(){return Re()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return A(Pf,{title:`edit prompt — forks the conversation`,onClose:()=>ze(null),get children(){var t=Du(),i=t.firstChild,s=i.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:a()})}),ze(null),lt();let t=n();t&&await It(t)}catch(e){alert(`edit failed: ${e.message}`)}}),L(t,A(M,{get when(){return r()>0},get children(){var e=Eu(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return L(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>ze(null),y(()=>i.value=e().text),t}})}})]}function Cf(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=Ou();return t.firstChild,L(t,a,null),L(t,(()=>{var t=N(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=ku(),t=e.firstChild;return L(e,a,t),e})()}function wf(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=Au();return L(e,()=>kf(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=(e,t=1500)=>(()=>{var n=ju();return L(n,()=>kf(e,t)),n})(),f=(e=4e3)=>n?[N(()=>d(o(),e)),(()=>{var e=Mu(),t=e.firstChild;return L(e,()=>n.data?.durationMs,t),L(e,()=>n.data?.ok===!1?` · FAILED`:``,null),L(e,A(Nf,{get text(){return o()}}),null),e})()]:Nu();try{switch(a){case`bash`:{let e=u(`command`);s=`$ `+Mf(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=[N(()=>N(()=>e!==s.slice(2))()?d(e,800):null),N(()=>f(6e3))];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${Mf(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=`${jf(e.length)} bytes`,l=[N(()=>d(e,1500)),N(()=>N(()=>e.length>1500)()?(()=>{var t=Pu(),n=t.firstChild;return L(t,()=>jf(e.length),n),t})():null),n?(()=>{var e=Fu();return L(e,()=>Mf(o(),160)),e})():Iu()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=Lu();return L(e,()=>kf(`- `+u(`old_text`),900)),e})(),(()=>{var e=Ru();return L(e,()=>`+ `+kf(u(`new_text`),900)),e})(),n?(()=>{var e=zu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,L(e,()=>Mf(o(),120),t),L(e,()=>n.data?.durationMs,r),e})():Bu()];break;case`apply_patch`:{let e=u(`patch`).split(`
24
+ `))),e}}),null),L(i,A(M,{get when(){return t.goal.status===`done`},get children(){return Vl()}}),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&&I(i,e.e=o),e.t=Te(i,s,e.t),c!==e.a&&F(i,`title`,e.a=c),l!==e.o&&I(a,e.o=l),e},{e:void 0,t:void 0,a:void 0,o:void 0}),i})()})),L(d,A(M,{get when(){return re()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;se(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),L(e,A(M,{get when(){return!oe()},get fallback(){return[(()=>{var e=Gl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{le(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),L(t,A(j,{get each(){return hf.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=ql();return L(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ce()),e})(),(()=>{var e=Kl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),L(t,A(j,{get each(){return hf.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=ql();return L(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ue()),e})()]},get children(){var e=Ic();return L(e,A(j,{each:hf,children:e=>(()=>{var t=Jl(),n=t.firstChild;return t.$$click=()=>{ae(e.key),localStorage.setItem(`teapot.theme`,e.key)},L(n,()=>e.sw.map(e=>(()=>{var t=Yl();return Ee(t,`background`,e),t})())),L(t,()=>e.label,null),y(n=>{var r=`themebtn`+(O()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=oe()),e}}),f),m.$$click=e=>{e.stopPropagation(),Ue(!He()),He()||B(e=>e.map(e=>({...e,read:!0})))},L(m,A(M,{get when(){return We()>0},get children(){var e=Rc();return L(e,We),e}}),null),_.$$click=()=>{Ze(),w(!0)},v.$$click=()=>ie(!re()),b.$$click=()=>{Ze(),E(!0)},L(S,`0.17.4`,null),L(C,A(M,{get when(){return u()},get children(){return[`master rss `,N(()=>u().rssMb),`MB · heap `,N(()=>u().heapUsedMb),`MB`,zc(),`load1 `,N(()=>u().loadavg1),` · up `,N(()=>Math.floor(u().uptimeSec/60)),`m`]}})),L(T,A(M,{get when(){return R()},get fallback(){return Xl()},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 L(t,()=>R().id),L(n,()=>R().status),L(e,A(M,{get when(){return(R().pendingPrompts??0)>0},get children(){var e=Bc(),t=e.firstChild.nextSibling;return t.nextSibling,L(e,()=>R().pendingPrompts,t),y(()=>F(e,`title`,`${R().pendingPrompts??0} message${(R().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),L(e,A(M,{get when(){return mt(R().id).length>0},get children(){var e=Vc();return e.firstChild,L(e,()=>mt(R().id).length,null),y(()=>F(e,`title`,`scheduled tasks:\n${mt(R().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
25
+ `)}`)),e}}),r),L(r,()=>R().model,i),L(r,()=>R().session,a),L(r,()=>R().branch,o),L(r,()=>R().stats.turns,s),L(r,()=>R().stats.toolCalls,null),L(c,A(M,{get when(){return R().statusReason},get children(){var e=Hc();return y(()=>F(e,`title`,R().statusReason)),e}}),l),l.$$click=Jt,u.$$click=ne,y(()=>I(n,`badge ${R().status}`)),e})(),(()=>{var e=Yc();return e.addEventListener(`scroll`,e=>{if(Nn)return;let t=e.currentTarget,r=Pt();r&&Ae()&&je(0),ke(r),t.scrollTop<=4&&n()&&!Ct()&&!Tt()&&i().length>0&&At()}),L(e,A(M,{get when(){return N(()=>!!Tt())()&&Xe().length>0},get children(){return Wc()}}),null),L(e,A(M,{get when(){return Ct()},get children(){return Gc()}}),null),L(e,A(M,{get when(){return Xe().length>0},get fallback(){return Zl()},get children(){return[A(j,{get each(){return Xe()},children:(e,t)=>A(Ef,{e,get prev(){return Xe()[t()-1]},get res(){return Je().resFor.get(e.id)},onOption:e=>void Pn(e),get answeredIds(){return Ye()},get agentActive(){return R()?.status===`running`||R()?.status===`waiting`},onResize:()=>{Oe()&&requestAnimationFrame(()=>Ft(!0))},get onCancel(){return e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);h(p()?`${n}\n\n${p()}`:n),Ve(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`?()=>ze({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),A(M,{get when(){return Me()},get children(){var e=Jc(),t=e.firstChild.nextSibling;return t.firstChild,L(t,A(M,{get when(){return Me().reasoning},get children(){var e=Kc(),t=e.firstChild.nextSibling;return L(t,()=>Me().reasoning),e}}),null),L(t,A(M,{get when(){return Pe()},get fallback(){return Ql()},get children(){var e=qc();return y(()=>e.innerHTML=Fe(Pe()+`▍`)),e}}),null),e}})]}}),null),e})(),A(M,{get when(){return Kt()},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=()=>{an(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(rn()))},n.$$pointerdown=hn,L(i,A(j,{get each(){return Yt()},children:(e,t)=>(()=>{var n=$l(),r=n.firstChild.nextSibling;return n.$$click=()=>cn(t()),L(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),dn(t())},y(r=>{var i=`termtab`+(H()===0&&Zt()===t()?` active`:``)+(en()&&H()===1&&$t()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),a),a.$$click=ln,L(o,(()=>{var t=N(()=>!!sn());return()=>t()?e().find(e=>e.id===sn().agentId)?.workspace.split(`/`).filter(Boolean).pop():R()?.workspace})()),s.$$click=gn,c.$$click=Jt;var d=_n(0);return typeof d==`function`&&De(d,u),u.$$pointerdown=()=>nn(0),L(u,A(M,{get when(){return!sn()||H()===0&&Zt()===-1},get children(){return Xc()}})),L(l,A(M,{get when(){return en()},get children(){return[Zc(),(()=>{var e=$c(),t=_n(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>nn(1),L(e,A(M,{get when(){return $t()===-1||Yt().length<=$t()},get children(){return Qc()}})),y(()=>e.classList.toggle(`focused`,H()===1)),e})()]}}),null),y(e=>{var n={height:`${rn()}px`,"--termh":`${rn()}px`},r=en()?`single pane`:`split panes (50/50)`,i=!!en(),a=H()===0;return e.e=Te(t,n,e.e),r!==e.t&&F(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;L(e,A(M,{get when(){return!Oe()||Ae()>0},get children(){var e=tl();return e.firstChild,e.$$click=()=>Ft(!0),L(e,(()=>{var e=N(()=>Ae()>0);return()=>e()?`${Ae()} new message${Ae()>1?`s`:``}`:`jump to present`})(),null),e}}),t),L(e,A(M,{get when(){return An().length>0},get children(){var e=nl();return L(e,A(j,{get each(){return An()},children:(e,t)=>(()=>{var n=eu(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{h(e.insert),kn(-1)},L(r,()=>e.insert.trim()),L(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===On()?` active`:``),a=e.title;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),L(e,A(M,{get when(){return wn().length>0},get children(){var e=nl();return L(e,A(j,{get each(){return wn()},children:e=>(()=>{var t=tu(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{h(`@${e.key} `),kn(-1)},L(n,()=>e.key,null),L(r,()=>e.label),y(()=>F(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Fn),n.$$keydown=e=>{let t=An();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),kn(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),kn(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&On()>=0){e.preventDefault(),h(t[On()].insert),kn(-1);return}if(e.key===`Escape`&&t.length>0){kn(-1);return}e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),Fn(e))},n.$$input=e=>{h(e.currentTarget.value),kn(0),Mn()};var a=jn;return typeof a==`function`?De(a,n):jn=n,L(t,A(M,{get when(){return N(()=>!!p().startsWith(`@`))()&&p().includes(` `)},get children(){var e=rl(),t=e.firstChild;return t.addEventListener(`change`,e=>Sn(e.currentTarget.checked)),y(()=>t.checked=xn()),e}}),r),r.$$click=()=>{let e=!P();Ce(e),requestAnimationFrame(()=>Mn())},L(r,()=>P()?`⤡`:`⤢`),L(i,()=>ff()||`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`+(P()?` maximized`:``),a=`message #${R().id} — / for commands`,o=P()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&I(e,t.e=i),a!==t.t&&F(n,`placeholder`,t.t=a),o!==t.a&&F(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),y(()=>n.value=p()),e})()]}})),D.addEventListener(`scroll`,e=>{Rn=e.currentTarget.scrollTop});var k=Ln;return typeof k==`function`?De(k,D):Ln=D,L(D,A(M,{get when(){return R()},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 L(n,()=>R().id),L(r,()=>R().status),L(a,()=>R().workspace),L(o,()=>R().session,s),L(o,()=>R().branch,null),y(e=>{var t=`badge ${R().status}`,n=R().workspace;return t!==e.e&&I(r,e.e=t),n!==e.t&&F(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),A(Vf,{get agentId(){return R().id},get workspace(){return R().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=>{he(e.currentTarget.value),xe(e.currentTarget.value)}),L(t,A(j,{get each(){return be()},children:e=>(()=>{var t=ql();return t.value=e,L(t,e,null),L(t,()=>e===g().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>_e(e.currentTarget.value),L(a,A(j,{get each(){return ve()},children:e=>(()=>{var t=ql();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:me(),model:ge().trim()||void 0,contextWindowTokens:ve().find(e=>e.id===(ge().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,lt()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},L(s,()=>R().model,null),L(s,A(M,{get when(){return ve().length},get children(){return[` · `,N(()=>ve().length),` models loaded`]}}),null),L(e,A(M,{get when(){return Se()},get children(){var e=cl();return L(e,Se),e}}),null),y(()=>F(i,`placeholder`,R().model)),y(()=>t.value=me()),y(()=>i.value=ge()),e})(),ul(),(()=>{var i=pl(),o=i.firstChild,s=o.nextSibling;return L(i,A(M,{get when(){return R().status===`running`},get fallback(){return(()=>{var e=nu();return we(e,`click`,zn(`/start`),!0),e})()},get children(){var e=dl();return we(e,`click`,zn(`/stop`),!0),e}}),o),o.$$click=()=>$(`/api/agents/${R().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>It(R().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]?It(o[0].id):(r(null),a([]))},L(i,A(M,{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)`}`),lt())},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(lt)}),y(()=>t.checked=R().autoContinue??!0),e})(),(()=>{var e=gl();return e.firstChild,L(e,A(M,{get when(){return!!R().goal.text.trim()},get fallback(){return ru()},get children(){var e=hl();return L(e,()=>R().goal.status),y(()=>I(e,`badge ${R().goal.status===`active`?`running`:R().goal.status}`)),e}}),null),e})(),(()=>{var e=_l();return e.firstChild,L(e,A(j,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=iu();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(lt)},F(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`),L(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(R().goal.text.trim()&&R().goal.status===e?` on ${e}`:``),i=!!R().goal.text.trim()&&R().goal.status===e;return r!==n.e&&I(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),A(M,{get when(){return R().goal.text},get fallback(){return au()},get children(){return[(()=>{var e=vl(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(R().goal.text))),e})(),A(M,{get when(){return R().goal.verify},get children(){var e=yl(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(R().goal.verify))),e}}),A(M,{get when(){return R().goal.audit},children:e=>(()=>{var t=ou(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return L(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),L(r,()=>Af(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=Fe(e().feedback);return r!==n.e&&I(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`,Bn),e})(),(()=>{var e=Cl(),t=e.firstChild.nextSibling;return L(e,A(M,{get when(){return ct().total>0},get children(){var e=Sl(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,L(e,()=>ct().done,t),L(e,()=>ct().total,n),y(t=>Te(e,ct().done===ct().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),A(M,{get when(){return ct().total>0},get children(){var e=wl(),t=e.firstChild;return y(e=>{var n=`barfill `+(ct().done===ct().total?``:`warn`),r=`${Math.round(ct().done/ct().total*100)}%`;return n!==e.e&&I(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),A(M,{get when(){return nt()},get fallback(){return(()=>{var e=su();return y(()=>e.innerHTML=lf(et())),e})()},get children(){var e=Tl();return e.$$input=e=>{tt(e.currentTarget.value),at(!0)},y(()=>e.value=et()),e}}),(()=>{var e=El(),t=e.firstChild,n=t.nextSibling.nextSibling;return t.$$click=()=>rt(!nt()),L(t,()=>nt()?`👁`:`✎`),n.$$click=st,y(()=>F(t,`title`,nt()?`rendered checklist`:`edit markdown`)),e})(),Dl(),A(M,{get when(){return R().latestProgress},get fallback(){return cu()},children:e=>(()=>{var t=pu(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return L(t,A(M,{get when(){return e().recent},get children(){var t=lu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=lf(e().recent)),t}}),i),L(t,A(M,{get when(){return e().problems},get children(){var t=uu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=lf(e().problems)),t}}),i),L(t,A(M,{get when(){return e().next},get children(){var t=du(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=lf(e().next)),t}}),i),L(t,A(M,{get when(){return e().goalStatus},get children(){var t=fu(),n=t.firstChild.nextSibling;return L(n,()=>e().goalStatus),t}}),i),L(i,()=>Af(e().ts)),y(()=>r.innerHTML=lf(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,L(i,()=>R().stats.turns),L(o,()=>R().stats.toolCalls),L(s,()=>R().stats.compactions??0),L(l,()=>jf(R().stats.inputTokens),u),L(l,()=>jf(R().stats.outputTokens),d),L(c,A(M,{get when(){return(R().stats.cachedInputTokens??0)>0},get children(){var e=kl(),t=e.firstChild.nextSibling;return t.nextSibling,L(e,()=>Math.round(R().stats.cachedInputTokens/Math.max(1,R().stats.inputTokens)*1e3)/10,t),y(()=>F(e,`title`,`${jf(R().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),L(e,A(M,{get when(){return R().ctx},get fallback(){return mu()},children:e=>{let t=ve().find(e=>e.id===R().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;return(()=>{var t=vu(),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,L(d,()=>jf(e().usedTokens),f),L(u,A(M,{when:r,get children(){var e=hu(),t=e.firstChild;return I(e,`pill ${a}`),L(e,()=>o(i),t),L(e,()=>jf(r),null),e}}),null),L(t,A(M,{when:r,get children(){var e=gu(),t=e.firstChild;return I(t,`barfill ${a}`),y(e=>Ee(t,`width`,`${Math.min(100,i)}%`)),e}}),p),L(m,()=>jf(l?s:c),h),L(g,l?` (75% of window)`:` (manual override)`),L(t,A(M,{when:r,get children(){var t=_u(),n=t.firstChild;return I(n,`barfill ${a}`),y(t=>Ee(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(lt)}),L(b,()=>jf(e().compactAt),x),y(()=>v.checked=R().autoCompact!==!1),t})()}}),null),e})(),jl(),A(j,{get each(){return c()},children:e=>(()=>{var t=yu(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=yt()===e.branch?null:e.branch;bt(t),n()&&jt(n())},L(r,()=>e.branch,null),L(r,()=>e.branch===R().branch?` (current)`:``,null),L(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===R().branch||e.branch===yt()?` cur`:``),i=e.branch===yt()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&I(t,n.e=r),i!==n.t&&F(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Ml(),A(M,{get when(){return dt().length>0},get fallback(){return bu()},get children(){return A(j,{get each(){return dt()},children:e=>(()=>{var t=Su(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>It(e.agent),L(i,()=>e.id),L(a,()=>e.agent,null),L(r,A(M,{get when(){return e.forked},get children(){return xu()}}),null),L(o,()=>e.schedule,s),L(o,(()=>{var t=N(()=>!!e.next);return()=>t()?Af(e.next):`—`})(),null),L(o,(()=>{var t=N(()=>!!e.last);return()=>t()?` · last ${Af(e.last)}`:` · never ran`})(),null),L(c,()=>Mf(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Mf(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&I(t,r.e=i),a!==r.t&&F(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(te()?``:` right-hidden`),n=`iconbtn notifbtn`+(We()>0?` has-unread`:``),r=We()>0?`${We()} unread notifications`:`notifications`,i=`conn`+(Lt()?` ok`:``),a=Lt()?`live (websocket)`:`reconnecting…`,s=`rightbar`+(te()?` open`:``);return t!==e.e&&I(o,e.e=t),n!==e.t&&I(m,e.t=n),r!==e.a&&F(m,`title`,e.a=r),i!==e.o&&I(ee,e.o=i),a!==e.i&&F(ee,`title`,e.i=a),s!==e.n&&I(D,e.n=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),o}}),A(M,{get when(){return He()},get children(){return[(()=>{var e=Pl();return e.$$click=()=>Ue(!1),e})(),(()=>{var t=Ll(),n=t.firstChild.firstChild.nextSibling,r=n.firstChild;return L(n,A(M,{get when(){return z().length>0},get children(){var e=Fl();return e.$$click=()=>B([]),e}}),r),r.$$click=()=>Ue(!1),L(t,A(M,{get when(){return z().length>0},get fallback(){return Cu()},get children(){var t=Il();return L(t,A(j,{get each(){return z()},children:t=>(()=>{var n=Tu(),r=n.firstChild.firstChild,i=r.nextSibling,a=i.nextSibling;return n.$$click=()=>{e().some(e=>e.id===t.agentId)&&It(t.agentId),Ue(!1)},L(r,(()=>{var e=N(()=>t.kind===`finish`);return()=>e()?`✅`:N(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),L(i,()=>t.title),L(a,()=>Af(new Date(t.at).toISOString())),L(n,A(M,{get when(){return t.body},get children(){var e=wu();return L(e,()=>kf(t.body,160)),e}}),null),y(e=>{var r=`notifitem `+t.kind,i=`from ${t.agentId}`;return r!==e.e&&I(n,e.e=r),i!==e.t&&F(n,`title`,e.t=i),e},{e:void 0,t:void 0}),n})()})),t}}),null),t})()]}}),A(M,{get when(){return S()},get children(){return A(Ff,{get providers(){return Object.keys(g().providers??{})},onClose:()=>w(!1),onCreated:e=>{w(!1),lt(),It(e)}})}}),A(M,{get when(){return T()},get children(){return A(Kf,{get cfg(){return g()},onClose:()=>E(!1),onSaved:()=>{Ze(),pt()}})}}),A(M,{get when(){return Re()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return A(Pf,{title:`edit prompt — forks the conversation`,onClose:()=>ze(null),get children(){var t=Du(),i=t.firstChild,s=i.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:a()})}),ze(null),lt();let t=n();t&&await It(t)}catch(e){alert(`edit failed: ${e.message}`)}}),L(t,A(M,{get when(){return r()>0},get children(){var e=Eu(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return L(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>ze(null),y(()=>i.value=e().text),t}})}})]}function Cf(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=Ou();return t.firstChild,L(t,a,null),L(t,(()=>{var t=N(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=ku(),t=e.firstChild;return L(e,a,t),e})()}function wf(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=Au();return L(e,()=>kf(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=(e,t=1500)=>(()=>{var n=ju();return L(n,()=>kf(e,t)),n})(),f=(e=4e3)=>n?[N(()=>d(o(),e)),(()=>{var e=Mu(),t=e.firstChild;return L(e,()=>n.data?.durationMs,t),L(e,()=>n.data?.ok===!1?` · FAILED`:``,null),L(e,A(Nf,{get text(){return o()}}),null),e})()]:Nu();try{switch(a){case`bash`:{let e=u(`command`);s=`$ `+Mf(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=[N(()=>N(()=>e!==s.slice(2))()?d(e,800):null),N(()=>f(6e3))];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${Mf(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=`${jf(e.length)} bytes`,l=[N(()=>d(e,1500)),N(()=>N(()=>e.length>1500)()?(()=>{var t=Pu(),n=t.firstChild;return L(t,()=>jf(e.length),n),t})():null),n?(()=>{var e=Fu();return L(e,()=>Mf(o(),160)),e})():Iu()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=Lu();return L(e,()=>kf(`- `+u(`old_text`),900)),e})(),(()=>{var e=Ru();return L(e,()=>`+ `+kf(u(`new_text`),900)),e})(),n?(()=>{var e=zu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,L(e,()=>Mf(o(),120),t),L(e,()=>n.data?.durationMs,r),e})():Bu()];break;case`apply_patch`:{let e=u(`patch`).split(`
26
26
  `).filter(e=>e&&!/^---$/.test(e.trim())),t=e.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);s=t.length?`${t.length} file${t.length>1?`s`:``}: ${Mf(t.join(`, `),80)}`:`patch`;let r=e.slice(0,60);l=[(()=>{var t=Vu();return L(t,()=>r.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Hu();return I(n,`pline`+t),L(n,(()=>{var t=N(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),L(t,(()=>{var t=N(()=>e.length>60);return()=>t()?(()=>{var t=Uu(),n=t.firstChild.nextSibling;return n.nextSibling,L(t,()=>e.length-60,n),t})():null})(),null),t})(),n?(()=>{var e=Fu();return L(e,()=>Mf(o().split(`
27
- `)[0]??``,140),null),L(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Wu()];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=Mf(e,70),c=`web`,l=[(()=>{var e=Fu();return L(e,A(M,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Ku();return L(e,()=>Mf(u(`url`),80)),e})()},get children(){var e=Gu();return y(()=>F(e,`href`,u(`url`))),e}})),e})(),N(()=>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=Fe(e)),t})(),(()=>{var e=Mu(),t=e.firstChild;return L(e,()=>n.data?.durationMs,t),e})()]:qu();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Mf(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[N(()=>N(()=>!!e.length)()?(()=>{var t=Ju();return t.firstChild,L(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=zu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,L(e,()=>Mf(o(),160),t),L(e,()=>n.data?.durationMs,r),e})():Yu()];break}}}catch{}return(()=>{var i=Zu(),o=i.firstChild,u=o.firstChild;u.firstChild;var d=u.nextSibling;return i.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),F(i,`title`,`${a}${c?` — `+c:``}`),L(u,s,null),L(o,A(M,{get when(){return t.data?.actor},get children(){var e=Xu();return e.firstChild,L(e,()=>String(t.data.actor),null),e}}),d),L(d,n?c||``:r?`(result missed)`:a===`bash`?A(Cf,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return Number(t.data?.args?.timeout_ms)||void 0}}):`running…`),L(i,l,null),y(()=>I(i,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),i})()}function Tf(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:``}function Ef(e){let t=e.e,n=_f(t),r=e=>e.type===`tool_call`||e.type===`tool_result`?`tool`:e.type,i=e.prev&&r(e.prev)===r(t)&&_f(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=Qu(),r=n.firstChild.nextSibling;return r.nextSibling,L(n,()=>String(e.fromBranch??`?`),r),L(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:Mf(String(e.text??``),80);return(()=>{var t=$u(),r=t.firstChild.nextSibling;return r.nextSibling,L(t,()=>String(e.event??``),r),L(t,n,null),t})()}return t.type===`todo`?(()=>{var e=ed(),n=e.firstChild.nextSibling;return n.nextSibling,L(e,()=>String(t.data?.by??`human`),n),e})():t.type===`state`?t.data.from===t.data.to?null:(()=>{var e=td(),n=e.firstChild;return L(e,()=>t.data.from,n),L(e,()=>t.data.to,null),L(e,(()=>{var e=N(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>I(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})():(()=>{var r=sd(),a=r.firstChild;return L(r,A(M,{when:!i,get fallback(){return cd()},get children(){var e=nd();return L(e,()=>n.icon),y(t=>{var r=n.color+`33`,i=`1px solid ${n.color}66`;return r!==t.e&&Ee(e,`background`,t.e=r),i!==t.t&&Ee(e,`border`,t.t=i),t},{e:void 0,t:void 0}),e}}),a),L(a,A(M,{when:i,get children(){var e=rd();return y(()=>F(e,`title`,`${yf(t.ts)} · ${t.branch}`)),e}}),null),L(a,A(M,{when:!i,get children(){var r=od(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return L(i,()=>n.name),L(r,A(M,{get when(){return t.data?.actor},get children(){var e=Xu();return e.firstChild,L(e,()=>String(t.data.actor),null),e}}),a),L(a,(()=>{var e=N(()=>!!t.data?.pending);return()=>e()?t.data?.sent===!0?`sent to model ✓`:`pending (queued)…`:yf(t.ts)})()),L(o,()=>t.branch),L(r,A(M,{get when(){return e.onCancel},get children(){var t=id();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),L(r,A(Nf,{get text(){return Tf(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`}),null),L(r,A(M,{get when(){return e.onEdit},get children(){var t=ad();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),L(a,A(Of,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(()=>I(r,`msg`+(i?` grouped`:``)+(t.data?.pending?` pending`:``))),r})()}function Df(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=ld(),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&&F(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 Of(e){let t=e.e;switch(t.type){case`prompt`:return(()=>{var e=qc();return y(()=>e.innerHTML=lf(String(t.data.text??``))),e})();case`message`:return[A(M,{get when(){return N(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Kc(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return L(n,(()=>{var e=N(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${jf(String(t.data.reasoning).length)} — truncated)`:``})(),null),L(r,()=>kf(String(t.data.reasoning),8e3)),e}}),(()=>{var e=qc();return y(()=>e.innerHTML=lf(String(t.data.content??``))),e})(),A(M,{get when(){return t.data.interrupted},get children(){return ud()}}),A(M,{get when(){return t.data.final},get children(){var e=dd(),n=e.firstChild;return L(e,A(Nf,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return A(wf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=fd(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return L(i,()=>Mf(e,120)),L(r,A(Nf,{text:e}),null),L(a,()=>kf(e,4e3)),L(o,()=>t.data.durationMs,s),L(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>I(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=md(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return L(n,A(M,{get when(){return e.length},get children(){var t=pd();return t.firstChild,L(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=lf(String(t.data?.decision??``)),r=lf(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=_d(),a=r.firstChild;return a.firstChild,I(r,`embed question`+(i?` answered`:``)),L(a,()=>String(t.data?.question??``),null),L(r,A(M,{when:i,get children(){return hd()}}),null),L(r,A(M,{get when(){return n.length>0},get children(){var r=gd();return L(r,A(j,{each:n,children:n=>(()=>{var r=vd();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,L(r,n),r})()})),r}}),null),L(r,A(Df,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=yd(),n=e.firstChild.firstChild.nextSibling;return L(e,A(M,{get when(){return t.data.goalStatus},get children(){var e=fu(),n=e.firstChild.nextSibling;return L(n,()=>String(t.data.goalStatus)),e}}),null),L(e,A(M,{get when(){return t.data.recent},get children(){var e=lu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=lf(String(t.data.recent))),e}}),null),L(e,A(M,{get when(){return t.data.problems},get children(){var e=uu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=lf(String(t.data.problems))),e}}),null),L(e,A(M,{get when(){return t.data.next},get children(){var e=du(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=lf(String(t.data.next))),e}}),null),y(()=>n.innerHTML=lf(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=bd(),n=e.firstChild;return n.firstChild,L(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=Sd(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,L(n,()=>String(t.data.mode??``),r),L(n,()=>jf(Number(t.data.tokensBefore??0)),i),L(n,()=>jf(Number(t.data.tokensAfter??0)),a),L(n,(()=>{var e=N(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),L(e,A(M,{get when(){return t.data.summary},get children(){return[xd(),(()=>{var e=qc();return y(()=>e.innerHTML=lf(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Cd();return L(e,()=>kf(JSON.stringify(t.data),200)),e})()}}function kf(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Af(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 jf(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 Mf(e,t){return kf(e.replace(/\s+/g,` `).trim(),t)}function Nf(e){let[t,n]=v(!1);return(()=>{var r=wd();return r.$$click=t=>{t.stopPropagation(),navigator.clipboard.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),900)})},L(r,(()=>{var n=N(()=>!!t());return()=>n()?`✓`:e.label??`⧉`})()),y(()=>F(r,`title`,e.title??`copy to clipboard`)),r})()}function Pf(e){return(()=>{var t=Td(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),L(r,()=>e.title),we(i,`click`,e.onClose,!0),L(n,()=>e.children,null),t})()}function Ff(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 A(Pf,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Dd(),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,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),L(b,A(j,{get each(){return r()},children:e=>(()=>{var n=Od();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),L(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),L(w,A(j,{get each(){return e.providers},children:e=>(()=>{var t=ql();return L(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),L(i,A(M,{get when(){return d()},get children(){var e=Ed();return L(e,d),e}}),E),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>T.value=l()),i}})}var If=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Lf=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Rf=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function zf(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Bf(e);return n===`image`?`🖼`:n===`video`?`🎬`:n===`audio`?`🎵`:[`ts`,`tsx`,`mts`,`cts`].includes(t)?`🟦`:[`js`,`mjs`,`cjs`,`jsx`].includes(t)?`🟨`:t===`json`||t===`jsonc`?`🧾`:t===`md`||t===`mdx`||t===`markdown`?`📝`:t===`css`||t===`scss`||t===`less`?`🎨`:t===`html`||t===`htm`||t===`svg`?`🌐`:[`py`,`pyi`].includes(t)?`🐍`:t===`rs`?`🦀`:t===`go`?`🐹`:t===`java`||t===`kt`||t===`kts`?`☕`:t===`rb`?`💎`:t===`php`?`🐘`:t===`c`||t===`h`||t===`cpp`||t===`hpp`||t===`cc`?`🧩`:t===`sh`||t===`bash`||t===`zsh`||t===`fish`?`🐚`:t===`sql`?`🗄`:t===`yml`||t===`yaml`||t===`toml`||t===`ini`||t===`conf`?`⚙`:t===`lock`?`🔒`:e===`Dockerfile`||t===`dockerfile`?`🐳`:t===`zip`||t===`gz`||t===`tar`||t===`tgz`||t===`bz2`?`📦`:t===`pdf`?`📕`:t===`txt`||t===`log`?`📄`:`·`}function Bf(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return If.has(t)?`image`:Lf.has(t)?`video`:Rf.has(t)?`audio`:null}function Vf(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),[l,u]=v(localStorage.getItem(`teapot.hideIgnored`)===`1`),[d,f]=v(localStorage.getItem(`teapot.showHidden`)===`1`),p=()=>{let e=!d();f(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let e of r())h(e).then(t=>{t&&n(n=>new Map(n).set(e,t))});h(``).then(e=>{e&&n(t=>new Map(t).set(``,e))})},m=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function h(t){try{let n=new URLSearchParams;t&&n.set(`path`,t),d()&&n.set(`hidden`,`1`);let r=await $(`/api/agents/${e.agentId}/tree?${n.toString()}`);return m(t,r.entries??[])}catch(e){return c(e.message),null}}b(()=>{e.agentId,i(new Set),n(new Map),h(``).then(e=>{e&&n(new Map([[``,e]]))})});let g=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 h(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[_,x]=v(``),[S,ee]=v(!1),[w,T]=v(`code`),[E,te]=v(``),[D,ne]=v(!1),re=e=>/\.(md|markdown|mdx)$/i.test(e),ie=0,O=async e=>{let t=++ie;x(``),ee(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-DIih-DWL.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(ie!==t)return;x(e=>e+r)}}catch{ie===t&&x(``)}finally{ie===t&&ee(!1)}};C(()=>{ie++});let[ae,oe]=v(null),se=async(t,n)=>{let r=Bf(t.path);if(r){o({path:t.path,content:``,binary:!0}),oe({path:t.path,kind:r}),T(`media`);return}try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);oe(null),o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),te(r.content??``),T(r.binary?`code`:n),!r.binary&&n!==`md`&&O({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ce=async()=>{let t=a();if(!(!t||D())){ne(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:E(),baseContent:t.content})}),o({...t,content:E()}),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{ne(!1)}}},le=e=>!e.binary&&!e.truncated,ue=(e,n)=>[(()=>{var t=Ad(),i=t.firstChild,a=i.nextSibling;return t.$$click=()=>e.dir?void g(e):void se(e,`code`),L(i,(()=>{var t=N(()=>!!e.dir);return()=>t()?r().has(e.path)?`▾`:`▸`:zf(e.name)})()),L(a,()=>e.name),L(t,A(M,{get when(){return N(()=>!e.dir)()&&e.size!==void 0},get children(){var t=kd();return L(t,()=>jf(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&!l()?` gitignored`:``),a=`padding-left:${n*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&I(t,r.e=i),r.t=Te(t,a,r.t),o!==r.a&&F(t,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),t})(),A(M,{get when(){return N(()=>!!e.dir)()&&r().has(e.path)},get children(){return A(j,{get each(){return t().get(e.path)??[]},children:e=>ue(e,n+1)})}})],de=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace;return[(()=>{var e=jd(),t=e.firstChild.nextSibling;t.firstChild;var n=t.nextSibling,r=n.nextSibling;return L(t,de,null),n.$$click=()=>{let e=!l();u(e),localStorage.setItem(`teapot.hideIgnored`,e?`1`:`0`)},L(n,()=>l()?`🙈 gitignored`:`👁 all`),r.$$click=p,L(r,()=>d()?`◉ .*`:`○ .*`),y(e=>{var t=l()?`gitignored files are hidden — click to show them (dimmed)`:`hiding gitignored files — click to show them (dimmed)`,i=d()?`dotfiles are shown — click to hide them`:`dotfiles are hidden — click to show them`;return t!==e.e&&F(n,`title`,e.e=t),i!==e.t&&F(r,`title`,e.t=i),e},{e:void 0,t:void 0}),e})(),(()=>{var e=Md();return L(e,A(M,{get when(){return(t().get(``)??[]).length>0},get fallback(){return(()=>{var e=Nd();return L(e,()=>s()||`empty workspace`),e})()},get children(){return A(j,{get each(){return(t().get(``)??[]).filter(e=>!l()||!(e.ignored&&!e.dir))},children:e=>ue(e,0)})}})),e})(),A(M,{get when(){return a()},children:t=>A(Pf,{get title(){return`🗂 ${t().path}`},onClose:()=>{ie++,o(null),oe(null)},get children(){return A(M,{get when(){return ae()},get fallback(){return[(()=>{var e=Rd(),n=e.firstChild;return L(e,A(M,{get when(){return N(()=>!!re(t().path))()&&!t().binary},get children(){var e=Id();return e.$$click=()=>T(`md`),y(()=>I(e,w()===`md`?`on`:``)),e}}),n),n.$$click=()=>{T(`code`),_()||O({path:t().path,content:t().content,truncated:t().truncated})},L(e,A(M,{get when(){return le(t())},get children(){var e=Ld();return e.$$click=()=>T(`edit`),y(()=>I(e,w()===`edit`?`on`:``)),e}}),null),y(()=>I(n,w()===`code`?`on`:``)),e})(),A(M,{get when(){return!t().binary},get fallback(){return Bd()},get children(){return A(M,{get when(){return w()===`edit`},get fallback(){return A(M,{get when(){return N(()=>w()===`md`)()&&re(t().path)},get fallback(){return A(Hf,{get path(){return t().path},get content(){return t().content},get html(){return _()},get pending(){return S()},get truncated(){return!!t().truncated}})},get children(){var e=Vd();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=zd(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>te(e.currentTarget.value),F(n,`spellcheck`,!1),L(r,()=>jf(E().length),i),a.$$click=()=>void ce(),L(a,()=>D()?`saving…`:`💾 save`),y(()=>a.disabled=D()||E()===t().content),y(()=>n.value=E()),e}})}})]},get children(){var t=Fd(),n=t.firstChild,r=n.firstChild;return L(t,A(M,{get when(){return ae().kind===`image`},get fallback(){return A(M,{get when(){return ae().kind===`video`},get fallback(){return(()=>{var t=Ud();return y(()=>F(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(ae().path)}`)),t})()},get children(){var t=Hd();return y(()=>F(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(ae().path)}`)),t}})},get children(){var t=Pd();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(ae().path)}`,i=ae().path.split(`/`).pop();return r!==n.e&&F(t,`src`,n.e=r),i!==n.t&&F(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),L(n,()=>ae().kind,r),t}})}})})]}function Hf(e){return[A(M,{get when(){return e.html},get fallback(){return N(()=>!!e.pending)()?(()=>{var t=Kd(),n=t.firstChild.nextSibling;return n.nextSibling,L(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=qd();return L(t,()=>e.content),t})()},get children(){var t=Wd();return y(()=>t.innerHTML=e.html),t}}),A(M,{get when(){return e.truncated},get children(){return Gd()}})]}var Uf=[{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)`}],Wf={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 Gf(e){let[t,n]=v(Uf[0]),[r,i]=v(Uf[0].url),[a,o]=v(``),[s,c]=v(Uf[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 ${jf(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(` · `)},w=()=>ee(s()),T=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=Zd(),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,E=C.firstChild.nextSibling,te=E.nextSibling,D=C.nextSibling,ne=D.firstChild.nextSibling,re=ne.firstChild.nextSibling,ie=ne.nextSibling.firstChild.nextSibling,O=D.nextSibling;return n.addEventListener(`submit`,T),L(u,()=>[...Uf,Wf].map(e=>(()=>{var n=Qd();return n.$$click=()=>S(e),L(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),L(n,A(M,{get when(){return t().hint},get children(){var e=Jd();return L(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),L(b,()=>Uf.map(e=>(()=>{var t=ql();return y(()=>t.value=e.url),t})())),ee.$$input=e=>o(e.currentTarget.value),E.$$input=e=>c(e.currentTarget.value),L(te,()=>l().map(e=>(()=>{var t=ql();return y(()=>t.value=e.id),t})())),L(n,A(M,{get when(){return l().length>0},get fallback(){return $d()},get children(){var e=Xd(),t=e.firstChild;return L(e,()=>l().length,t),L(e,A(M,{get when(){return w()},get children(){return[` · `,(()=>{var e=Yd();return L(e,w),e})()]}}),null),e}}),D),re.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),L(n,A(M,{get when(){return _()},get children(){var e=Ed();return L(e,_),e}}),O),L(O,()=>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&&F(E,`placeholder`,e.e=n),r!==e.t&&(O.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>ee.value=a()),y(()=>E.value=s()),y(()=>re.value=d()),y(()=>ie.value=p()),e})()}function Kf(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=ef(),a=i.firstChild;return F(i,`title`,r),L(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return A(Pf,{title:`settings`,get onClose(){return e.onClose},get children(){var v=tf(),b=v.firstChild,S=b.firstChild.nextSibling,w=S.nextSibling;w.firstChild;var T=w.nextSibling.firstChild.firstChild.nextSibling;T.firstChild;var E=b.nextSibling,te=E.firstChild.nextSibling,D=te.firstChild,ne=D.firstChild.nextSibling,re=E.nextSibling,ie=re.firstChild.nextSibling,O=re.nextSibling;O.firstChild;var ae=O.nextSibling;return v.addEventListener(`submit`,ee),L(b,A(j,{get each(){return t()},children:(e,r)=>(()=>{var i=nf(),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:``}]),L(w,A(j,{each:Uf,children:e=>(()=>{var a=rf();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)},L(a,()=>e.label,null),y(()=>F(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),T.addEventListener(`change`,e=>i(e.currentTarget.value)),L(T,A(j,{get each(){return[...new Set(t().map(e=>e.name.trim()).filter(Boolean))]},children:e=>(()=>{var t=ql();return t.value=e,L(t,e),t})()}),null),L(te,()=>C(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),D),L(te,()=>C(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),D),ne.$$input=e=>u(e.currentTarget.value===``?null:Number(e.currentTarget.value)),L(te,()=>C(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),L(te,()=>C(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),L(re,A(M,{get when(){return h().length>0},get children(){return A(j,{get each(){return h()},children:(e,t)=>(()=>{var n=af(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().map((n,r)=>r===t()?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e.id),y(()=>a.value=e.agent),y(()=>o.value=e.schedule),y(()=>c.checked=!!e.forked),y(()=>u.value=e.prompt),n})()})}}),ie),ie.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),L(O,A(j,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=sf(),n=t.firstChild,r=n.nextSibling;return L(n,()=>e.id),L(r,()=>e.workspace),L(t,A(M,{get when(){return e.parent},get children(){var t=of();return t.firstChild,L(t,()=>e.parent,null),t}}),null),t})()}),null),L(v,A(M,{get when(){return _()},get children(){var e=Ed();return L(e,_),e}}),ae),y(()=>T.value=r()),y(()=>ne.value=l()??``),v}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>A(Sf,{}),document.getElementById(`root`));export{Pc as t};
28
- //# sourceMappingURL=index-DqN59aCT.js.map
27
+ `)[0]??``,140),null),L(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Wu()];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=Mf(e,70),c=`web`,l=[(()=>{var e=Fu();return L(e,A(M,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Ku();return L(e,()=>Mf(u(`url`),80)),e})()},get children(){var e=Gu();return y(()=>F(e,`href`,u(`url`))),e}})),e})(),N(()=>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=Fe(e)),t})(),(()=>{var e=Mu(),t=e.firstChild;return L(e,()=>n.data?.durationMs,t),e})()]:qu();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=Mf(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[N(()=>N(()=>!!e.length)()?(()=>{var t=Ju();return t.firstChild,L(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=zu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,L(e,()=>Mf(o(),160),t),L(e,()=>n.data?.durationMs,r),e})():Yu()];break}}}catch{}return(()=>{var i=Zu(),o=i.firstChild,u=o.firstChild;u.firstChild;var d=u.nextSibling;return i.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),F(i,`title`,`${a}${c?` — `+c:``}`),L(u,s,null),L(o,A(M,{get when(){return t.data?.actor},get children(){var e=Xu();return e.firstChild,L(e,()=>String(t.data.actor),null),e}}),d),L(d,n?c||``:r?`(result missed)`:a===`bash`?A(Cf,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return Number(t.data?.args?.timeout_ms)||void 0}}):`running…`),L(i,l,null),y(()=>I(i,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),i})()}function Tf(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:``}function Ef(e){let t=e.e,n=_f(t),r=e=>e.type===`tool_call`||e.type===`tool_result`?`tool`:e.type,i=e.prev&&r(e.prev)===r(t)&&_f(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=Qu(),r=n.firstChild.nextSibling;return r.nextSibling,L(n,()=>String(e.fromBranch??`?`),r),L(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:Mf(String(e.text??``),80);return(()=>{var t=$u(),r=t.firstChild.nextSibling;return r.nextSibling,L(t,()=>String(e.event??``),r),L(t,n,null),t})()}return t.type===`todo`?(()=>{var e=ed(),n=e.firstChild.nextSibling;return n.nextSibling,L(e,()=>String(t.data?.by??`human`),n),e})():t.type===`state`?t.data.from===t.data.to?null:(()=>{var e=td(),n=e.firstChild;return L(e,()=>t.data.from,n),L(e,()=>t.data.to,null),L(e,(()=>{var e=N(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>I(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})():(()=>{var r=sd(),a=r.firstChild;return L(r,A(M,{when:!i,get fallback(){return cd()},get children(){var e=nd();return L(e,()=>n.icon),y(t=>{var r=n.color+`33`,i=`1px solid ${n.color}66`;return r!==t.e&&Ee(e,`background`,t.e=r),i!==t.t&&Ee(e,`border`,t.t=i),t},{e:void 0,t:void 0}),e}}),a),L(a,A(M,{when:i,get children(){var e=rd();return y(()=>F(e,`title`,`${yf(t.ts)} · ${t.branch}`)),e}}),null),L(a,A(M,{when:!i,get children(){var r=od(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return L(i,()=>n.name),L(r,A(M,{get when(){return t.data?.actor},get children(){var e=Xu();return e.firstChild,L(e,()=>String(t.data.actor),null),e}}),a),L(a,(()=>{var e=N(()=>!!t.data?.pending);return()=>e()?t.data?.sent===!0?`sent to model ✓`:`pending (queued)…`:yf(t.ts)})()),L(o,()=>t.branch),L(r,A(M,{get when(){return e.onCancel},get children(){var t=id();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),L(r,A(Nf,{get text(){return Tf(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`}),null),L(r,A(M,{get when(){return e.onEdit},get children(){var t=ad();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),L(a,A(Of,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(()=>I(r,`msg`+(i?` grouped`:``)+(t.data?.pending?` pending`:``))),r})()}function Df(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=ld(),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&&F(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 Of(e){let t=e.e;switch(t.type){case`prompt`:return(()=>{var e=qc();return y(()=>e.innerHTML=lf(String(t.data.text??``))),e})();case`message`:return[A(M,{get when(){return N(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Kc(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return L(n,(()=>{var e=N(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${jf(String(t.data.reasoning).length)} — truncated)`:``})(),null),L(r,()=>kf(String(t.data.reasoning),8e3)),e}}),(()=>{var e=qc();return y(()=>e.innerHTML=lf(String(t.data.content??``))),e})(),A(M,{get when(){return t.data.interrupted},get children(){return ud()}}),A(M,{get when(){return t.data.final},get children(){var e=dd(),n=e.firstChild;return L(e,A(Nf,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return A(wf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=fd(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return L(i,()=>Mf(e,120)),L(r,A(Nf,{text:e}),null),L(a,()=>kf(e,4e3)),L(o,()=>t.data.durationMs,s),L(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>I(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=md(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return L(n,A(M,{get when(){return e.length},get children(){var t=pd();return t.firstChild,L(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=lf(String(t.data?.decision??``)),r=lf(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=_d(),a=r.firstChild;return a.firstChild,I(r,`embed question`+(i?` answered`:``)),L(a,()=>String(t.data?.question??``),null),L(r,A(M,{when:i,get children(){return hd()}}),null),L(r,A(M,{get when(){return n.length>0},get children(){var r=gd();return L(r,A(j,{each:n,children:n=>(()=>{var r=vd();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,L(r,n),r})()})),r}}),null),L(r,A(Df,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=yd(),n=e.firstChild.firstChild.nextSibling;return L(e,A(M,{get when(){return t.data.goalStatus},get children(){var e=fu(),n=e.firstChild.nextSibling;return L(n,()=>String(t.data.goalStatus)),e}}),null),L(e,A(M,{get when(){return t.data.recent},get children(){var e=lu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=lf(String(t.data.recent))),e}}),null),L(e,A(M,{get when(){return t.data.problems},get children(){var e=uu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=lf(String(t.data.problems))),e}}),null),L(e,A(M,{get when(){return t.data.next},get children(){var e=du(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=lf(String(t.data.next))),e}}),null),y(()=>n.innerHTML=lf(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=bd(),n=e.firstChild;return n.firstChild,L(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=Sd(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,L(n,()=>String(t.data.mode??``),r),L(n,()=>jf(Number(t.data.tokensBefore??0)),i),L(n,()=>jf(Number(t.data.tokensAfter??0)),a),L(n,(()=>{var e=N(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),L(e,A(M,{get when(){return t.data.summary},get children(){return[xd(),(()=>{var e=qc();return y(()=>e.innerHTML=lf(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Cd();return L(e,()=>kf(JSON.stringify(t.data),200)),e})()}}function kf(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Af(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 jf(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 Mf(e,t){return kf(e.replace(/\s+/g,` `).trim(),t)}function Nf(e){let[t,n]=v(!1);return(()=>{var r=wd();return r.$$click=t=>{t.stopPropagation(),navigator.clipboard.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),900)})},L(r,(()=>{var n=N(()=>!!t());return()=>n()?`✓`:e.label??`⧉`})()),y(()=>F(r,`title`,e.title??`copy to clipboard`)),r})()}function Pf(e){return(()=>{var t=Td(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),L(r,()=>e.title),we(i,`click`,e.onClose,!0),L(n,()=>e.children,null),t})()}function Ff(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 A(Pf,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Dd(),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,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),L(b,A(j,{get each(){return r()},children:e=>(()=>{var n=Od();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),L(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),L(w,A(j,{get each(){return e.providers},children:e=>(()=>{var t=ql();return L(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),L(i,A(M,{get when(){return d()},get children(){var e=Ed();return L(e,d),e}}),E),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>T.value=l()),i}})}var If=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Lf=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Rf=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function zf(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Bf(e);return n===`image`?`🖼`:n===`video`?`🎬`:n===`audio`?`🎵`:[`ts`,`tsx`,`mts`,`cts`].includes(t)?`🟦`:[`js`,`mjs`,`cjs`,`jsx`].includes(t)?`🟨`:t===`json`||t===`jsonc`?`🧾`:t===`md`||t===`mdx`||t===`markdown`?`📝`:t===`css`||t===`scss`||t===`less`?`🎨`:t===`html`||t===`htm`||t===`svg`?`🌐`:[`py`,`pyi`].includes(t)?`🐍`:t===`rs`?`🦀`:t===`go`?`🐹`:t===`java`||t===`kt`||t===`kts`?`☕`:t===`rb`?`💎`:t===`php`?`🐘`:t===`c`||t===`h`||t===`cpp`||t===`hpp`||t===`cc`?`🧩`:t===`sh`||t===`bash`||t===`zsh`||t===`fish`?`🐚`:t===`sql`?`🗄`:t===`yml`||t===`yaml`||t===`toml`||t===`ini`||t===`conf`?`⚙`:t===`lock`?`🔒`:e===`Dockerfile`||t===`dockerfile`?`🐳`:t===`zip`||t===`gz`||t===`tar`||t===`tgz`||t===`bz2`?`📦`:t===`pdf`?`📕`:t===`txt`||t===`log`?`📄`:`·`}function Bf(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return If.has(t)?`image`:Lf.has(t)?`video`:Rf.has(t)?`audio`:null}function Vf(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),[l,u]=v(localStorage.getItem(`teapot.hideIgnored`)===`1`),[d,f]=v(localStorage.getItem(`teapot.showHidden`)===`1`),p=()=>{let e=!d();f(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let e of r())h(e).then(t=>{t&&n(n=>new Map(n).set(e,t))});h(``).then(e=>{e&&n(t=>new Map(t).set(``,e))})},m=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function h(t){try{let n=new URLSearchParams;t&&n.set(`path`,t),d()&&n.set(`hidden`,`1`);let r=await $(`/api/agents/${e.agentId}/tree?${n.toString()}`);return m(t,r.entries??[])}catch(e){return c(e.message),null}}b(()=>{e.agentId,i(new Set),n(new Map),h(``).then(e=>{e&&n(new Map([[``,e]]))})});let g=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 h(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[_,x]=v(``),[S,ee]=v(!1),[w,T]=v(`code`),[E,te]=v(``),[D,ne]=v(!1),re=e=>/\.(md|markdown|mdx)$/i.test(e),ie=0,O=async e=>{let t=++ie;x(``),ee(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-DmJ1fGOc.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(ie!==t)return;x(e=>e+r)}}catch{ie===t&&x(``)}finally{ie===t&&ee(!1)}};C(()=>{ie++});let[ae,oe]=v(null),se=async(t,n)=>{let r=Bf(t.path);if(r){o({path:t.path,content:``,binary:!0}),oe({path:t.path,kind:r}),T(`media`);return}try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);oe(null),o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),te(r.content??``),T(r.binary?`code`:n),!r.binary&&n!==`md`&&O({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ce=async()=>{let t=a();if(!(!t||D())){ne(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:E(),baseContent:t.content})}),o({...t,content:E()}),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{ne(!1)}}},le=e=>!e.binary&&!e.truncated,ue=(e,n)=>[(()=>{var t=Ad(),i=t.firstChild,a=i.nextSibling;return t.$$click=()=>e.dir?void g(e):void se(e,`code`),L(i,(()=>{var t=N(()=>!!e.dir);return()=>t()?r().has(e.path)?`▾`:`▸`:zf(e.name)})()),L(a,()=>e.name),L(t,A(M,{get when(){return N(()=>!e.dir)()&&e.size!==void 0},get children(){var t=kd();return L(t,()=>jf(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&!l()?` gitignored`:``),a=`padding-left:${n*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&I(t,r.e=i),r.t=Te(t,a,r.t),o!==r.a&&F(t,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),t})(),A(M,{get when(){return N(()=>!!e.dir)()&&r().has(e.path)},get children(){return A(j,{get each(){return t().get(e.path)??[]},children:e=>ue(e,n+1)})}})],de=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace;return[(()=>{var e=jd(),t=e.firstChild.nextSibling;t.firstChild;var n=t.nextSibling,r=n.nextSibling;return L(t,de,null),n.$$click=()=>{let e=!l();u(e),localStorage.setItem(`teapot.hideIgnored`,e?`1`:`0`)},L(n,()=>l()?`🙈 gitignored`:`👁 all`),r.$$click=p,L(r,()=>d()?`◉ .*`:`○ .*`),y(e=>{var t=l()?`gitignored files are hidden — click to show them (dimmed)`:`hiding gitignored files — click to show them (dimmed)`,i=d()?`dotfiles are shown — click to hide them`:`dotfiles are hidden — click to show them`;return t!==e.e&&F(n,`title`,e.e=t),i!==e.t&&F(r,`title`,e.t=i),e},{e:void 0,t:void 0}),e})(),(()=>{var e=Md();return L(e,A(M,{get when(){return(t().get(``)??[]).length>0},get fallback(){return(()=>{var e=Nd();return L(e,()=>s()||`empty workspace`),e})()},get children(){return A(j,{get each(){return(t().get(``)??[]).filter(e=>!l()||!(e.ignored&&!e.dir))},children:e=>ue(e,0)})}})),e})(),A(M,{get when(){return a()},children:t=>A(Pf,{get title(){return`🗂 ${t().path}`},onClose:()=>{ie++,o(null),oe(null)},get children(){return A(M,{get when(){return ae()},get fallback(){return[(()=>{var e=Rd(),n=e.firstChild;return L(e,A(M,{get when(){return N(()=>!!re(t().path))()&&!t().binary},get children(){var e=Id();return e.$$click=()=>T(`md`),y(()=>I(e,w()===`md`?`on`:``)),e}}),n),n.$$click=()=>{T(`code`),_()||O({path:t().path,content:t().content,truncated:t().truncated})},L(e,A(M,{get when(){return le(t())},get children(){var e=Ld();return e.$$click=()=>T(`edit`),y(()=>I(e,w()===`edit`?`on`:``)),e}}),null),y(()=>I(n,w()===`code`?`on`:``)),e})(),A(M,{get when(){return!t().binary},get fallback(){return Bd()},get children(){return A(M,{get when(){return w()===`edit`},get fallback(){return A(M,{get when(){return N(()=>w()===`md`)()&&re(t().path)},get fallback(){return A(Hf,{get path(){return t().path},get content(){return t().content},get html(){return _()},get pending(){return S()},get truncated(){return!!t().truncated}})},get children(){var e=Vd();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=zd(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>te(e.currentTarget.value),F(n,`spellcheck`,!1),L(r,()=>jf(E().length),i),a.$$click=()=>void ce(),L(a,()=>D()?`saving…`:`💾 save`),y(()=>a.disabled=D()||E()===t().content),y(()=>n.value=E()),e}})}})]},get children(){var t=Fd(),n=t.firstChild,r=n.firstChild;return L(t,A(M,{get when(){return ae().kind===`image`},get fallback(){return A(M,{get when(){return ae().kind===`video`},get fallback(){return(()=>{var t=Ud();return y(()=>F(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(ae().path)}`)),t})()},get children(){var t=Hd();return y(()=>F(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(ae().path)}`)),t}})},get children(){var t=Pd();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(ae().path)}`,i=ae().path.split(`/`).pop();return r!==n.e&&F(t,`src`,n.e=r),i!==n.t&&F(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),L(n,()=>ae().kind,r),t}})}})})]}function Hf(e){return[A(M,{get when(){return e.html},get fallback(){return N(()=>!!e.pending)()?(()=>{var t=Kd(),n=t.firstChild.nextSibling;return n.nextSibling,L(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=qd();return L(t,()=>e.content),t})()},get children(){var t=Wd();return y(()=>t.innerHTML=e.html),t}}),A(M,{get when(){return e.truncated},get children(){return Gd()}})]}var Uf=[{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)`}],Wf={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 Gf(e){let[t,n]=v(Uf[0]),[r,i]=v(Uf[0].url),[a,o]=v(``),[s,c]=v(Uf[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 ${jf(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(` · `)},w=()=>ee(s()),T=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=Zd(),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,E=C.firstChild.nextSibling,te=E.nextSibling,D=C.nextSibling,ne=D.firstChild.nextSibling,re=ne.firstChild.nextSibling,ie=ne.nextSibling.firstChild.nextSibling,O=D.nextSibling;return n.addEventListener(`submit`,T),L(u,()=>[...Uf,Wf].map(e=>(()=>{var n=Qd();return n.$$click=()=>S(e),L(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&I(n,r.e=i),a!==r.t&&F(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),L(n,A(M,{get when(){return t().hint},get children(){var e=Jd();return L(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),L(b,()=>Uf.map(e=>(()=>{var t=ql();return y(()=>t.value=e.url),t})())),ee.$$input=e=>o(e.currentTarget.value),E.$$input=e=>c(e.currentTarget.value),L(te,()=>l().map(e=>(()=>{var t=ql();return y(()=>t.value=e.id),t})())),L(n,A(M,{get when(){return l().length>0},get fallback(){return $d()},get children(){var e=Xd(),t=e.firstChild;return L(e,()=>l().length,t),L(e,A(M,{get when(){return w()},get children(){return[` · `,(()=>{var e=Yd();return L(e,w),e})()]}}),null),e}}),D),re.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),L(n,A(M,{get when(){return _()},get children(){var e=Ed();return L(e,_),e}}),O),L(O,()=>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&&F(E,`placeholder`,e.e=n),r!==e.t&&(O.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>ee.value=a()),y(()=>E.value=s()),y(()=>re.value=d()),y(()=>ie.value=p()),e})()}function Kf(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=ef(),a=i.firstChild;return F(i,`title`,r),L(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return A(Pf,{title:`settings`,get onClose(){return e.onClose},get children(){var v=tf(),b=v.firstChild,S=b.firstChild.nextSibling,w=S.nextSibling;w.firstChild;var T=w.nextSibling.firstChild.firstChild.nextSibling;T.firstChild;var E=b.nextSibling,te=E.firstChild.nextSibling,D=te.firstChild,ne=D.firstChild.nextSibling,re=E.nextSibling,ie=re.firstChild.nextSibling,O=re.nextSibling;O.firstChild;var ae=O.nextSibling;return v.addEventListener(`submit`,ee),L(b,A(j,{get each(){return t()},children:(e,r)=>(()=>{var i=nf(),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:``}]),L(w,A(j,{each:Uf,children:e=>(()=>{var a=rf();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)},L(a,()=>e.label,null),y(()=>F(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),T.addEventListener(`change`,e=>i(e.currentTarget.value)),L(T,A(j,{get each(){return[...new Set(t().map(e=>e.name.trim()).filter(Boolean))]},children:e=>(()=>{var t=ql();return t.value=e,L(t,e),t})()}),null),L(te,()=>C(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),D),L(te,()=>C(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),D),ne.$$input=e=>u(e.currentTarget.value===``?null:Number(e.currentTarget.value)),L(te,()=>C(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),L(te,()=>C(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),L(re,A(M,{get when(){return h().length>0},get children(){return A(j,{get each(){return h()},children:(e,t)=>(()=>{var n=af(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().map((n,r)=>r===t()?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e.id),y(()=>a.value=e.agent),y(()=>o.value=e.schedule),y(()=>c.checked=!!e.forked),y(()=>u.value=e.prompt),n})()})}}),ie),ie.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),L(O,A(j,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=sf(),n=t.firstChild,r=n.nextSibling;return L(n,()=>e.id),L(r,()=>e.workspace),L(t,A(M,{get when(){return e.parent},get children(){var t=of();return t.firstChild,L(t,()=>e.parent,null),t}}),null),t})()}),null),L(v,A(M,{get when(){return _()},get children(){var e=Ed();return L(e,_),e}}),ae),y(()=>T.value=r()),y(()=>ne.value=l()??``),v}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>A(Sf,{}),document.getElementById(`root`));export{Pc as t};
28
+ //# sourceMappingURL=index-Dy4krQZ7.js.map