teapot-coding-agent 0.36.5 → 0.36.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server/api.js +58 -4
- package/package.json +1 -1
- package/public/assets/{index-O1SluPcT.js → index-MXkEkm6p.js} +7 -7
- package/public/assets/index-MXkEkm6p.js.map +1 -0
- package/public/assets/index-cEph2_ps.css +1 -0
- package/public/assets/{shiki-DQxXtlWj.js → shiki-DlE9AYQg.js} +2 -2
- package/public/assets/{shiki-DQxXtlWj.js.map → shiki-DlE9AYQg.js.map} +1 -1
- package/public/index.html +2 -2
- package/public/assets/index-CkDRpo_M.css +0 -1
- package/public/assets/index-O1SluPcT.js.map +0 -1
|
@@ -18,14 +18,14 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
|
|
|
18
18
|
`))),this._register(this._terminal.onA11yTab(e=>this._handleTab(e))),this._register(this._terminal.onKey(e=>this._handleKey(e.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(K(i,`selectionchange`,()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(V(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<Yl+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
|
|
19
19
|
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===Yl+1&&(this._liveRegion.textContent+=On.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})`}};Xl=z([B(1,tr),B(2,ur),B(3,fr)],Xl);var Zl=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(()=>{Fr(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(K(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(K(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(K(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(K(this._element,`mouseup`,this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){this._activeLine!==e.y||this._wasResized?(this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1):this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){(!this._activeProviderReplies||!t)&&(this._activeProviderReplies?.forEach(e=>{e?.forEach(e=>{e.link.dispose&&e.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,t=>{if(this._isMouseOut)return;let i=t?.map(e=>({link:e}));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)(!this._activeProviderReplies.has(t)||this._activeProviderReplies.get(t))&&(i=!0);if(!i&&r){let e=r.find(e=>this._linkAtPosition(e.link,t));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find(e=>this._linkAtPosition(e.link,t));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&Ql(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,Fr(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}}};Zl=z([B(1,dr),B(2,fr),B(3,Zn),B(4,gr)],Zl);function Ql(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 $l=class extends Rl{constructor(e={}){super(e),this._linkifier=this._register(new zr),this.browser=ps,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new zr),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(Gl),this._instantiationService.setService(or,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(cs),this._instantiationService.setService(gr,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(sr)),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(Gr.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(Gr.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(Gr.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(Gr.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(`${q.ESC}]${n};${Sl(r)}${wo.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=jo.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=jo.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(Xl,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(q.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(q.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(K(this.element,`copy`,e=>{this.hasSelection()&&jn(e,this._selectionService)}));let e=e=>Mn(e,this.textarea,this.coreService,this.optionsService);this._register(K(this.textarea,`paste`,e)),this._register(K(this.element,`paste`,e)),_s?this._register(K(this.element,`mousedown`,e=>{e.button===2&&Fn(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(K(this.element,`contextmenu`,e=>{Fn(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),Ts&&this._register(K(this.element,`auxclick`,e=>{e.button===1&&Pn(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(K(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(K(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(K(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(K(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(K(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(K(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(K(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(K(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`,En.get()),Es||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(os,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(ur,this._coreBrowserService),this._register(K(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(K(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(ns,this._document,this._helperContainer),this._instantiationService.setService(lr,this._charSizeService),this._themeService=this._instantiationService.createInstance(uc),this._instantiationService.setService(hr,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(Lo),this._instantiationService.setService(mr,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Ms,this.rows,this.screenElement)),this._instantiationService.setService(fr,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(To,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(ds),this._instantiationService.setService(dr,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(Zl,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(go,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(ec,this.element,this.screenElement,r)),this._instantiationService.setService(pr,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(Gr.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(_o,this.screenElement)),this._register(K(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(Xl,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(So,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(So,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(ts,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(K(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(K(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=q.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){Nn(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=Bl(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===q.ETX||n.key===q.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)&&(eu(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType===`insertText`&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){e===this.cols&&t===this.rows?this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure():super.resize(e,t)}_afterResize(e,t){this._charSizeService?.measure()}clear(){if(this.buffer.ybase!==0||this.buffer.y!==0){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(vc));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(q.ESC+`[I`):this.coreService.triggerDataEvent(q.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(`${q.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(`${q.ESC}[6;${r};${n}t`)}}cancel(e,t){if(this.options.cancelEvents||t)return e.preventDefault(),e.stopPropagation(),!1}};function eu(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var tu=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)}},nu=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 Wn)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},ru=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 nu(t)}getNullCell(){return new Wn}},iu=class extends H{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new W),this.onBufferChange=this._onBufferChange.event,this._normal=new ru(this._core.buffers.normal,`normal`),this._alternate=new ru(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)}},au=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)}},ou=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}},su=[`cols`,`rows`],cu=0,lu=class extends H{constructor(e){super(),this._core=this._register(new $l(e)),this._addonManager=this._register(new tu),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(su.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 au(this._core),this._parser}get unicode(){return this._checkProposedApi(),new ou(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 iu(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 En.get()},set promptLabel(e){En.set(e)},get tooMuchOutput(){return On.get()},set tooMuchOutput(e){On.set(e)}}}_verifyIntegers(...e){for(cu of e)if(cu===1/0||isNaN(cu)||cu%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(cu of e)if(cu&&(cu===1/0||isNaN(cu)||cu%1!=0||cu<0))throw Error(`This API only accepts positive integers`)}},uu=2,du=1,fu=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(uu,Math.floor(u/e.css.cell.width)),rows:Math.max(du,Math.floor(l/e.css.cell.height))}}};function pu(e){return e.length}function mu(e,t){return t<=0||e<0?-1:Math.min(e,t-1)}function hu(e,t,n){return mu(e===t?t:e>t?e-1:e,n)}function gu(e,t){return Array.from({length:t},(e,t)=>t).find(t=>t!==e)??-1}function _u(e,t){let n=e.filter(e=>!t.has(e.id));return n.find(e=>!e.workspaceMissing)??n[0]??null}var vu=`modulepreload`,yu=function(e){return`/`+e},bu={},xu=function(e){return e.pathname.endsWith(`.css`)},Su=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},Cu=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=yu(t,n);let r=s(t),i=xu(r);return Su(bu,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:vu,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{t.addEventListener(`load`,e),t.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${r}`)))})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},wu=F(`<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 class=primarybtn>unlock</button><span class=muted style=font-size:11px>the token is stored locally and sent as Bearer to this server only`),Tu=F(`<div class=leftbarbackdrop>`),Eu=F(`<div class=sidehead><b>agents</b><button class=iconbtn title="close the agent list">✕`),Du=F(`<i class=notifdot>`),Ou=F(`<br>`),ku=F(`<button class="iconbtn ham"title="agent list">☰`),Au=F(`<span class="badge queued">⏳ <!> of yours queued`),ju=F(`<span class="badge cron">⏰ `),Mu=F(`<header class=chan-head><span class=hash>#</span><span class=title></span><span></span><span class=sub> · <!>/<!> · <!>↻ <!>⚙</span><span class=head-actions><button></button><span class=head-sep aria-hidden=true>`),Nu=F(`<div class=divider-msg>── beginning of log ──`),Pu=F(`<div class=divider-msg>loading older events…`),Fu=F(`<details class=reasoning open><summary>💭 thinking </summary><div class="mono thinkscroll">`),Iu=F(`<div class=muted style=font-size:11.5px;margin-bottom:4px>🗜 summarizing older context…`),Lu=F(`<div class=content>`),Ru=F(`<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…`),zu=F(`<div class=feed>`),Bu=F(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),Vu=F(`<div class=termsplit>`),Hu=F(`<div class="termempty muted">no shell here — click a tab or + to add`),Uu=F(`<div class=termpane>`),Wu=F(`<div class=termdrawer><div class=termgrip title="drag to resize · double-click to reset"></div><div class=termbar><div class=termtabs></div><div style=display:flex;gap:4px;align-items:center><span class="muted mono"style=flex:1;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span></div></div><div class=termbody><div class=termpane>`),Gu=F(`<button class=jump>↓ `),Ku=F(`<div class=cmds>`),qu=F(`<div class=imgstage><span class=muted style=font-size:11px;align-self:center> image<!> attached`),Ju=F(`<label class=forkchip title="inherit the conversation prefix byte-exactly — the sub-agent's provider prefix cache starts warm"><input type=checkbox>fork ctx`),Yu=F(`<span class=muted style=font-size:11.5px;white-space:nowrap>🖼 `),Xu=F(`<div class="hint flashhint">`),Zu=F(`<div><form><textarea rows=1></textarea><button type=button class="iconbtn maxbtn"></button><button type=submit>send</button><input id=composer-file type=file accept=image/* multiple style=display:none>`),Qu=F(`<div class=rightbarbackdrop>`),$u=F(`<div><nav><div class=agent-list></div><div class=sidebar-footer><div class=footer-row style=justify-content:flex-end><button>🔔</button></div><div class=brand-row><div class=brand>🫖 teapot <span class=version>v</span><span></span></div></div><div class=metrics></div></div></nav><section class=channel></section><aside><div class=rightbarhead><span class=muted>details`),ed=F(`<div class=notifbackdrop>`),td=F(`<button class=editbtn>clear all`),nd=F(`<div class=notiflist>`),rd=F(`<div class=notifpanel><div class=notifhead>notifications<span style=display:flex;gap:8px;align-items:center><button class=iconbtn title="close notifications">✕`),id=F(`<div class=bgphoto aria-hidden=true><img sizes=100vw alt decoding=async><span class=bgphoto-veil>`),ad=F(`<span class=wscount>`),od=F(`<div class=wsheader><span class=wscaret>`),sd=F(`<span class=notifbadge>🔔`),cd=F(`<span class=subtag>🧩`),ld=F(`<span class=mini-cron>⏰`),ud=F(`<span class=goaldone title="goal done">✓`),dd=F(`<div><span></span><span>`),fd=F(`<span class=caret-spacer>`),pd=F(`<span class=caret>`),md=F(`<span class=ghosttag title="workspace missing">👻`),hd=F(`<span>🧩 `),gd=F(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),_d=F(`<div class="divider-msg compacting"title="the harness is compressing old turns into notes so work can continue within the context window">🗜 `),vd=F(`<div class=muted style=display:grid;place-items:center;height:100%><span><span class=spinner aria-hidden=true></span> loading timeline…`),yd=F(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),bd=F(`<div class="content muted">thinking…`),xd=F(`<span>⌨ <button class=tabx title="close this shell">✕`),Sd=F(`<div><b class=mono></b><span class=muted>`),Cd=F(`<div class=cmdrow><b>@</b><span class=muted>`),wd=F(`<span class=imgchip><img><button type=button class=imgx title=remove>✕`),Td=F(`<h3 title="switch provider/model live — applies from the agent's next turn; the list shows context window & pricing from the provider">🧦 model`),Ed=F(`<div style=display:flex;gap:6px;align-items:center;margin-top:6px><label class=muted style=font-size:11.5px;white-space:nowrap>effort</label><select style=flex:1;min-width:0><option value>provider default`),Dd=F(`<div class=meta style=color:var(--fg)>`),Od=F(`<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></div><div style=display:flex;gap:6px;align-items:center;margin-top:6px><button title="apply the provider, model and effort above to this session — takes effect from the agent's next turn"style=flex:1>apply</button></div><div class=meta>current: `),kd=F(`<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`),Ad=F(`<span>`),jd=F(`<h3 title="what the agent is working toward. Stored with the session; the agent reads it via get_goal(). Auto-continue keeps looping while the status is 'active' and stops when marked done.">🎯 goal`),Md=F(`<div class=statrow style=margin-bottom:6px><span class=k>status`),Nd=F(`<div class="card goalcard"><div class=content>`),Pd=F(`<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>`),Fd=F(`<form style=display:flex;flex-direction:column;gap:6px;margin-top:8px;margin-bottom:6px><textarea id=goal-input rows=3 placeholder="set new goal…"style="background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;width:100%;resize:vertical"></textarea><textarea id=goal-verify-input rows=2 placeholder="verification contract (optional) — e.g. 'npm test passes; endpoint documented'. finish(goalComplete=true) is then audited against this."title="pi-goal-x-style verification contract — an independent reviewer checks the agent's finish against these requirements"style="background:var(--bg-darkest);border:1px solid var(--bg-light);border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;font-size:12.5px;width:100%;resize:vertical"></textarea><div style=display:flex;justify-content:flex-end;align-items:center;gap:10px><label class=muted title="queue a harness prompt telling the agent about the new goal at its next turn boundary"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=goal-notify type=checkbox> notify agent</label><button type=submit class=primarybtn>✓ save goal`),Id=F(`<span class=badge>/<!> done`),Ld=F(`<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)`),Rd=F(`<div class=bartrack style=margin-bottom:6px><div>`),zd=F(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><label class=muted title="queue a harness prompt telling the agent the task list changed"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=todo-notify type=checkbox checked> notify agent</label><button class=okbtn>✓ save tasks`),Bd=F(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),Vd=F(`<h3 title="context is how much of the model's window the live conversation occupies. Past the threshold, the oldest turns are summarized into notes so work can continue.">📊 runtime`),Hd=F(`<div class=rtcell><span>cost</span><b>$`),Ud=F(`<div class=rtcell><span>cached</span><b>%`),Wd=F(`<div class="card runcard"><div class=rtgrid><div class=rtcell title="prompt tokens billed this session"><span>tokens in</span><b></b></div><div class=rtcell title="completion tokens billed this session"><span>tokens out</span><b></b></div><div class=rtcell title="assistant turns this session"><span>turns</span><b></b></div><div class=rtcell title="tool calls this session"><span>tools</span><b></b></div><div class=rtcell><span>compacted</span><b>`),Gd=F(`<div class=muted style=font-size:11px;text-transform:none;letter-spacing:0>showing <b></b> and the history it inherited before forking`),Kd=F(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),qd=F(`<span class=muted style=text-transform:none;letter-spacing:0>· <!> · all agents`),Jd=F(`<h3 title="cron tasks, all agents — click a row to open that agent. Edit them in ⚙ settings → scheduled tasks.">⏰ schedule`),Yd=F(`<option>`),Xd=F(`<span class=badge title="no goal set yet">no goal`),Zd=F(`<button>`),Qd=F(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),$d=F(`<div><div class=vtitle><span class="meta muted"style=margin-left:auto></span></div><div class=content>`),ef=F(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),tf=F(`<div class=progrow><b>recent</b><span class="content inline-md">`),nf=F(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),rf=F(`<div class=progrow><b>next</b><span class="content inline-md">`),af=F(`<div class=progrow><b>goal</b><span>`),of=F(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),sf=F(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),cf=F(`<span>% of `),lf=F(`<div class=bartrack><div>`),uf=F(`<div class=statrow title="a compaction pass is running right now — the summarizer's output streams in the timeline"><span class=k>🗜</span><b>compacting…</b><span class=muted style=font-size:11px;color:var(--acc)>`),df=F(`<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 at</span><b> tok</b><span class=muted style=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`),ff=F(`<div><span></span><span> events`),pf=F(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),mf=F(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),hf=F(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class=sched-meta> → next </div><div class="sched-prompt muted">`),gf=F(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),_f=F(`<div class=nbody>`),vf=F(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted"></span><button class="iconbtn nreadbtn">`),yf=F(`<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)`),bf=F(`<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 class=primarybtn>⑂ fork & resend`),xf=F(`<span class=bashelapsed>running… `),Sf=F(`<span class=bashelapsed> elapsed`),Cf=F(`<span class=thinktimer>`),wf=F(`<div class="toolbody shiki">`),Tf=F(`<pre class="mono toolbody">`),Ef=F(`<div class=meta>`),Df=F(`<div class=meta>waiting for output…`),Of=F(`<div class="meta bgjob-note">runs in background — poll with <b>bash_output(job_id="<!>")`),kf=F(`<b>action="kill"`),Af=F(`<div class="meta muted"> bytes — open it from 🗂 files for the full view`),jf=F(`<div class=meta>writing…`),Mf=F(`<pre class="mono toolbody del">`),Nf=F(`<pre class="mono toolbody add">`),Pf=F(`<div class=meta> · `),Ff=F(`<div class=meta>applying…`),If=F(`<pre class="mono toolbody patch">`),Lf=F(`<div>`),Rf=F(`<div class="pline meta">… <!> more lines`),zf=F(`<div class=meta>validating…`),Bf=F(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),Vf=F(`<span class=muted>`),Hf=F(`<div class=meta>loading…`),Uf=F(`<div class=meta>bundled: `),Wf=F(`<div class=meta>saving…`),Gf=F(`<span class=actor>@`),Kf=F(`<details><summary><b></b><span class=meta></span><span class=toolcopy>`),qf=F(`<div class=divider-msg>⑂ forked from <!> → `),Jf=F(`<div><div class=goalline-label>`),Yf=F(`<div class=divider-msg>✅ tasks updated (<!>)`),Xf=F(`<div> → `),Zf=F(`<div class="embed fail"><div class=mono>🛑 runaway: <!> tool failures in a row (limit <!>)</div><div class=meta>last: <!> — `),Qf=F(`<div class="embed warn-embed"title="a round-fatal API error occurred; auto-retry is waiting, then a fresh round starts (onError: retry)"><div class=mono>↻ API error — retrying (attempt <!>) in <!>s…`),$f=F(`<div class=divider-msg>🗜 compacted: <!> → <!> tok (<!>)`),ep=F(`<div class=divider-msg title="compaction is rewriting older history — the agent is not stuck">🗜 compacting: summarizing <!> earlier messages from <!> tok (<!>)…`),tp=F(`<span class=ts>`),np=F(`<button class=editbtn title="withdraw this message — it has not reached the model yet; the text goes back to the input box">✕ cancel`),rp=F(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),ip=F(`<div class=msg-head><span class=author></span><span class=ts>`),ap=F(`<div><div></div><div class=msg-body>`),op=F(`<span class=grouptime>`),sp=F(`<div class=qfree><input type=text><button>reply`),cp=F(`<div class=promptimgs>`),lp=F(`<img class=promptimg alt=attachment>`),up=F(`<details class=reasoning><summary>💭 reasoning</summary><div class=mono>`),dp=F(`<div class=interrupted>⚠ interrupted — partial output kept`),fp=F(`<div class=msgfoot><span>copy summary`),pp=F(`<div class=meta>its call is no longer in the loaded events — the run itself finished`),mp=F(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>`),hp=F(`<div class="content muted">Rejected: `),gp=F(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged</span></summary><div class=content>`),_p=F(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),vp=F(`<div class=qopts>`),yp=F(`<div><div>❓ <div class="content inline-md">`),bp=F(`<button class=qopt>`),xp=F(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),Sp=F(`<div class="embed fail"><div class=mono>⚠ `),Cp=F(`<div class=vtitle style=margin-top:6px>what the agent kept`),wp=F(`<details class="embed compaction"><summary><b>🗜 context compacted</b><span class=meta> · <!> → <!> tok · `),Tp=F(`<div class="content muted">`),Ep=F(`<button type=button><span class=iconbtn-glyph>`),Dp=F(`<button class=copybtn>`),Op=F(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),kp=F(`<span style=color:var(--err);font-size:13px>`),Ap=F(`<form style=display:flex;flex-direction:column;gap:10px><label>workspace directory<div style=display:flex;gap:6px><input type=text class="w100 mono"><button type=button>go</button><button type=button title="parent directory">↑</button></div></label><div class=dirlist></div><div style=display:flex;gap:10px><label style=flex:1>agent name <input type=text placeholder="(directory name)"></label><label style="flex:0 1 auto;min-width:0">provider<select></select></label><label style=flex:1>model <input type=text placeholder="(provider default)"></label></div><button type=submit style=align-self:flex-end>create`),jp=F(`<div class=direntry>📁 `),Mp=F(`<span class=tprev-bg>`),Np=F(`<span class=tprev><span class=tprev-nav></span><span class=tprev-head></span><span class=tprev-panel></span><span class=tprev-line style=left:32%;top:38%;width:34%;opacity:0.85></span><span class=tprev-line style=left:32%;top:50%;width:22%></span><span class=tprev-line style=left:32%;top:62%;width:40%></span><span class=tprev-dot style=left:6%;top:20%></span><span class=tprev-dot style=left:6%;top:40%></span><span class=tprev-dot style=left:6%;top:60%></span><span class=tprev-dot style=left:70%;top:12%></span><span class=tprev-dot style=left:84%;top:12%>`),Pp=F(`<select title="which custom theme to edit — selecting one also applies it">`),Fp=F(`<div class=themeeditor><h4 class=cfgsub>your themes</h4><div class=btnrow><button type=button title="copy the theme you are using into a new editable one — presets themselves are never modified">+ duplicate current`),Ip=F(`<div class=muted style="margin:6px 0">`),Lp=F(`<b>+ duplicate current`),Rp=F(`<div class=cfggrid style=margin-top:8px><label class=trow>appearance<select><option value=dark>dark</option><option value=light>light`),zp=F(`<div class=paletterows>`),Bp=F(`<div class=btnrow><button type=button title="put every colour back to the palette this theme was created from">↺ reset palette</button><button type=button title="delete this custom theme">🗑 delete`),Vp=F(`<h4 class=cfgsub>background image`),Hp=F(`<div class=bgpreview><img alt="theme background preview"><span class=muted title="this image is served from the server; the theme stores only its URL">✓ image set</span><div class=btnrow><label class=trow title="how much the image is dimmed so text stays readable">dim<input type=range min=0 max=0.9 step=0.05><span class="muted mono">%</span></label><label title="how much of the background shows through code blocks and tool cards — lower is more transparent">surfaces<input type=range min=0.35 max=1 step=0.01><span class="muted mono">%</span></label><button type=button>✕ remove`),Up=F(`<div class=cfggrid><button type=button class=trow title="PNG/JPG/WebP. Stored in this browser, applied behind the panels."></button><input type=file accept=image/* style=display:none>`),Wp=F(`<div class=muted style=margin-top:6px;font-size:var(--text-xs)>the image is uploaded to the server and sits behind the panels, dimmed so text stays readable. No size limit — it is a file now, not browser storage.`),Gp=F(`<label class=paletterow><input type=color><span class=paletterow-label></span><input class="mono paletterow-hex">`),Kp=F(`<div class="content mdpreview todopane">`),qp=F(`<textarea id=todo-input class="mono todopane-edit"rows=5 placeholder="- task one
|
|
21
|
-
- task two"title="shared with the agent \\u2014 it may check items off via set_todo; your unsaved edits win until you save">`),Jp=F(`<span class=fsize>`),Yp=F(`<div><span class=ficon></span><span class=fname>`),Xp=F(`<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>· `),Zp=F(`<div class=filebox>`),Qp=F(`<div class=muted style=padding:6px>`),$p=F(`<img>`),em=F(`<div class=mediapreview><div class="meta muted"> preview`),tm=F(`<button title="rendered markdown">👁 preview`),nm=F(`<button title="edit and save back to the workspace">✎ edit`),rm=F(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),im=F(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),am=F(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),om=F(`<div class="content mdpreview">`),sm=F(`<video controls>`),cm=F(`<audio controls>`),lm=F(`<div class=filepreview>`),um=F(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),dm=F(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),fm=F(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),pm=F(`<label><input type=number min=0>`),mm=F(`<div class=muted style=font-size:11.5px;margin-top:4px>⚠ configured default provider <code></code> has no provider row here<!> Add a provider named <code></code> or pick a default below; otherwise agents fall back to the first provider.`),hm=F(`<div class=cfggrid style=margin-top:8px><label class=trow>dark theme →<select class=w100></select></label><label class=trow>light theme →<select class=w100>`),gm=F(`<div class=skilllist>`),_m=F(`<form style=display:flex;flex-direction:column;gap:12px;min-height:0><div class=cfgbody><nav class=cfgmenu aria-label="settings sections"></nav><div class=cfgpanel><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>appearance</legend><div class=cfggrid><label class=trow>follow the system<input type=checkbox></label></div><h4 class=cfgsub>themes</h4></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><label class=cfgtoggle title="prune old tool output early (at 60% of the budget) instead of waiting for the window to fill. Meant for small-window models — on a large window it throws away context you had room for."><input type=checkbox>short-context mode (#161)</label></fieldset><fieldset><legend>MCP servers — external tools, shared by every agent</legend><div class=muted style=font-size:11.5px;margin-bottom:8px>each tool becomes <code class=mono>mcp__server__tool</code> for every agent. saving connects them; the status shown here is live.</div><button type=button>+ add MCP server</button></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>archived agents — restore, or delete for good</legend></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><fieldset><legend>live update</legend><div class=cfgrow><span class=muted>current version: </span><button type=button class=primarybtn>update & restart</button><span class=muted style=margin-left:8px;font-size:12px>gracefully stops all agents, spawns new process, then reloads this page</span></div></fieldset><fieldset><legend>skills</legend><div class=featgrid><div class=featrow><b>image downscaling</b><span class=muted></span></div><div class=featrow><b>terminal pty</b><span class=muted></span></div></div></fieldset><fieldset><legend>help</legend><div class=helpsec><h4 class=cfgsub>keyboard</h4><div class=helprow><kbd>enter</kbd><span>send (shift+enter for a newline)</span></div><div class=helprow><span class=kbdgroup><kbd>↑</kbd><kbd>↓</kbd></span><span>move between sessions</span></div><div class=helprow><kbd>/</kbd><span>command palette — commands and focus</span></div><div class=helprow><kbd>t</kbd><span>open the terminal panel</span></div><div class=helprow><kbd>d</kbd><span>toggle the details panel</span></div><div class=helprow><kbd>esc</kbd><span>interrupt the running turn</span></div></div><div class=helpsec><h4 class=cfgsub>what the toggles do</h4><div class=helprow><b>auto-continue</b><span>fires after a round only when all hold: the toggle is on, a goal is set and its status is <code>active</code>, and the round ended cleanly (not an error, not stopped). It stops when the goal is marked done, or when you press ■ stop. Sending any prompt starts an idle agent regardless.</span></div><div class=helprow><b>auto-compact</b><span>when the live context passes the budget shown under 📊 runtime, older turns are summarized into notes and the recent stretch is kept verbatim, so work continues without losing the thread. Off means you compact by hand (<code>/compact</code>).</span></div><div class=helprow><b>messages while it works</b><span>anything you send queues up and is handed to the model at its next turn boundary — the timeline shows it as "pending (queued)…" until then. Withdraw it with ✕ cancel while it is still queued.</span></div><div class=helprow><b>👻 ghost sessions</b><span>a session whose workspace directory no longer exists on disk. The session log is intact — recreate the directory and it stops being a ghost.</span></div></div></fieldset></div></div><div class=cfgfoot><button type=submit class=cfgsave>`),vm=F(`<button type=button><span class=cfgmenu-label>`),ym=F(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="default model"><button type=button class=danger title="remove provider">✕</button><div class=cfgkeys><button type=button title="add another key for this provider — they are rotated round-robin, and a rate-limited key is skipped for a minute">+ key`),bm=F(`<button type=button title="remove this key">−`),xm=F(`<div class=cfgkeyrow><input type=password>`),Sm=F(`<button type=button>+ `),Cm=F(`<div class=cfgsub style=margin-bottom:var(--space-1)>`),wm=F(`<div class=themepick>`),Tm=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label> ★`),Em=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label>`),Dm=F(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),Om=F(`<input placeholder="command (e.g. npx)">`),km=F(`<input placeholder="args, space separated">`),Am=F(`<input type=password placeholder="paste the token"title="sent as Authorization: Bearer <token>"style=flex:1>`),jm=F(`<input placeholder="header name"style="flex:0 1 150px">`),Mm=F(`<input type=password placeholder=value style=flex:1>`),Nm=F(`<div class=cfgrow><textarea class=mono rows=2 placeholder="{"Authorization": "Bearer …", "X-Team": "infra"}"title="static headers for every request. Use the bearer option unless the server needs something unusual."style=flex:1>`),Pm=F(`<button type=button class=archrestore title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),Fm=F(`<span class="mcpstate connected"title="an OAuth access token is usable">🔑 authorized`),Im=F(`<button type=button title="forget the stored grant (the refresh token is deleted)">disconnect`),Lm=F(`<div class=muted style=font-size:11px;color:var(--warn)>`),Rm=F(`<div class="cfgcol mcpcard"><div class=cfgrow><input class=cfgname placeholder=name title="the name that appears inside mcp__<name>__ in tool names"><input placeholder="https://example.com/mcp (or leave empty for a stdio command)"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>on</label><button type=button class=danger>✕</button></div><div class=cfgrow><select title="streamable HTTP is the current spec; legacy SSE is the 2024-11-05 handshake; stdio spawns a local process"><option value=http>streamable http</option><option value=sse>legacy http+sse</option><option value=stdio>stdio (local command)</option></select></div><div class=cfgrow><select title="how this server authenticates"><option value=none>no auth</option><option value=bearer>bearer token</option><option value=header>custom header</option><option value=json>headers as JSON (advanced)</option></select></div><div class=cfgrow><button type=button title="connect now and list the tools — nothing is saved">test`),zm=F(`<option value=oauth selected>`),Bm=F(`<span class=muted> · needs a grant (🔑 authorize)`),Vm=F(`<ul class=mcptools>`),Hm=F(`<div><div class=mcpresult-head><b>`),Um=F(`<span class=mcptool-desc>`),Wm=F(`<li><code class=mono>`),Gm=F(`<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">`),Km=F(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),qm=F(`<div class="cfgrow archrow"><div class=archmain><b></b><span class=muted> session</span><span class="muted mono ellip"></span></div><button type=button class=archrestore title="bring it back and start it again — its history was never touched">↩ restore</button><button type=button class=danger title="erase the config entry AND every session directory — irreversible">🗑 delete`),Jm=F(`<span class=muted>🧩 sub of @`),Ym=F(`<div class=cfgrow><b></b><span class=muted>`),Xm=F(`<div class=muted>`),Zm=F(`<div class=skillbody>`),Qm=F(`<div class=skillrow><button type=button class=skillhead title="show the playbook"><span class=skillcaret></span><b class=mono></b><span class=muted>`),$m=F(`<div class="muted skillbody">`),eh=new Map;function th(e){let t=eh.get(e);if(t!==void 0)return t;let n=Ie(e);return eh.set(e,n),eh.size>500&&eh.delete(eh.keys().next().value),n}var nh=[`minimal`,`low`,`medium`,`high`],rh=1100,ih={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`}},ah={name:`harness`,icon:`📣`,color:`#3ba55d`},[oh,sh]=v(``),ch,Q=e=>{sh(e),clearTimeout(ch),ch=setTimeout(()=>sh(``),3200)},lh=!1,uh=[{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`]}],dh=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`?ih.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:ah}return ih[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},fh=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),ph=new Set([`system_note`]),mh=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`]),hh=new Set([`runaway-detected`,`error-retry`,`background-exit`,`context-compacted`,`context-compaction-started`]),gh=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=null;try{t=await i.json()}catch{}let n=(t&&typeof t==`object`&&`error`in t?String(t.error):``)||`${e}: HTTP ${i.status}`;throw Object.assign(Error(n),{payload:t})}return i.json()}var _h=location.hash.match(/[#&]token=([^&]+)/);_h&&(localStorage.setItem(`teapot.token`,decodeURIComponent(_h[1])),history.replaceState(null,``,location.pathname+location.search));var vh=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function yh(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v(``),[o,s]=v(new Map),[c,l]=v(new Map),[u,d]=v(new Map),f=!1;async function p(e=!1){if(!f||e){f=!0;try{let e=await $(`/api/sessions`),t=new Map,n=new Map,r=new Map;for(let i of e.sessions??[]){t.set(i.id,i.agentId),typeof i.title==`string`&&i.title&&r.set(i.id,i.title);let e=n.get(i.agentId)??[];e.push(i.id),n.set(i.agentId,e)}s(t),l(n),d(r)}catch{}}}let[m,h]=v([]),[g,_]=v(0),[w,te]=v([]),[T,ne]=v(null),E=new Map,[re,ie]=v(E.get(n()??``)??``),D=e=>{ie(e);let t=n();t&&(e?E.set(t,e):E.delete(t))},[O,ae]=v({providers:{}}),[oe,se]=v(!1),ce=[640,1280,1920,2560,3840],le=()=>{let e=Re()?tt()?Be():Qe():Fe();return Ge().find(t=>t.id===e)?.backgroundImage??``},k=()=>{let e=Re()?tt()?Be():Qe():Fe();return Ge().some(t=>t.id===e)||uh.some(t=>t.key===e)?e:`dark`},[ue,A]=v(!1),de=!1;b(()=>{!de&&O()?.needsSetup&&(de=!0,requestAnimationFrame(()=>{ar(),A(!0)}))}),b(()=>{ue()&&!oa()&&$(`/api/features`).then(e=>sa(e)).catch(()=>sa(null))});let fe=new Set,pe=()=>window.innerWidth<=rh,[me,he]=v(pe());ee(()=>{let e=()=>he(pe());window.addEventListener(`resize`,e),C(()=>window.removeEventListener(`resize`,e)),e()});let ge,_e,ve=0,ye=``,be=()=>{ve=0;let e=ti();if(!e)return;if(ya=e.scrollHeight,wa=e.clientHeight,Ct()){ri();return}let t=F(e);if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;r&&(e.scrollTop+=r,va={top:e.scrollTop,height:e.scrollHeight}),Ut(ni())};function xe(e,t){if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;Math.abs(r)<1||Math.abs(r)>Sa||(e.scrollTop+=r,va={top:e.scrollTop,height:e.scrollHeight})}let Se=()=>{ve||=requestAnimationFrame(be)},Ce=e=>{e&&e!==_e&&(ge??=new ResizeObserver(e=>{let t=e[0]?.contentRect,n=t?`${Math.round(t.width)}x${Math.round(t.height)}`:``;n!==ye&&(ye=n,Se())}),_e&&ge.unobserve(_e),_e=e,ye=``,ge.observe(e))};ee(()=>{window.addEventListener(`resize`,Se),C(()=>{window.removeEventListener(`resize`,Se),ge?.disconnect(),ge=void 0,_e=void 0,ve&&cancelAnimationFrame(ve)})});function F(e){let t=e.querySelectorAll(`[data-eid]`);if(!t.length)return null;let n=e.getBoundingClientRect().top,r=e=>t[e].getBoundingClientRect(),i=0,a=t.length-1,o=-1;for(;i<=a;){let e=i+a>>1;r(e).bottom>n?(o=e,a=e-1):i=e+1}if(o<0)return null;let s=t[o].dataset.eid??``;return s?{sel:`[data-eid="${CSS.escape(s)}"]`,top:r(o).top}:null}let[we,Te]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>rh:localStorage.getItem(`teapot.panel`)===`1`),ke=e=>{Te(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},Ae=()=>ke(!we()),je=()=>{we()&&ke(!1)},[Me,Ne]=v(!1),Pe=()=>Ne(!1),[Fe,Le]=v(localStorage.getItem(`teapot.theme`)??`dark`),[Re,ze]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[Be,Ve]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[Ge,qe]=v(mn());ee(()=>{gn().then(e=>{if(e===null)return;let t=xt(Ge(),e);qe(t),hn(t)})});let[Qe,$e]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),et=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[tt,nt]=v(et?.matches??!1);ee(()=>{let e=e=>nt(e.matches);et?.addEventListener(`change`,e),C(()=>et?.removeEventListener(`change`,e))}),b(()=>{let e=xn({want:Re()?tt()?Be():Qe():Fe(),customIds:Ge().map(e=>e.id),presetIds:uh.map(e=>e.key),fallback:`dark`}),t=e.active,n=Ge().find(e=>e.id===t)??null;e.repaired&&(Re()?localStorage.setItem(tt()?`teapot.theme.light`:`teapot.theme.dark`,t):localStorage.setItem(`teapot.theme`,t)),document.documentElement.dataset.theme=t,vn(document.documentElement,n),document.documentElement.dataset.appearance=n?.mode??uh.find(e=>e.key===t)?.mode??`dark`});let[rt,it]=v(``),[at,ot]=v(``),[st,ct]=v(``);b(()=>{let t=n();ct(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[lt,ut]=v([]),dt=()=>Object.keys(O().providers??{});async function ft(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);ut(t.models??[])}catch{ut([])}}let mt=e=>{let t={text:`📄`,image:`🖼️`,audio:`🔊`,video:`🎬`,file:`📎`},n=e=>(e??[`text`]).map(e=>t[e]??e).join(``);return e?.modalities?`${n(e.modalities.input)} → ${n(e.modalities.output)}`:``},gt=()=>{let e=at().trim()||z()?.model||``;if(!e)return``;let t=lt().find(t=>t.id===e);if(!t)return``;let n=[],r=mt(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${Ah(t.contextLength)} tok`);let i=e=>e===void 0?``:`${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=i(t.pricing.prompt),r=i(t.pricing.completion);e&&r?n.push(`${e} in · ${r} out`):(e||r)&&n.push(i(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},_t=null,vt=!1;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||O().defaultProvider||dt()[0]||``;if(r){if(t!==_t)_t=t,vt=!1,S(()=>rt())!==i&&(it(i),ft(i)),S(()=>at())&&ot(``);else{let e=S(()=>rt());!S(()=>at())&&e!==i&&Xt(vt)&&(it(i),ft(i))}}});let[yt,bt]=v(!1),[Ct,At]=v(!0),[jt,Mt]=v(0),[Nt,Lt]=v(-1),Ut=e=>Lt(e?on(e):-1),[Wt,Gt]=v(null),qt=()=>fn().startsWith(`[compact] `),$t=()=>{let e=qt()?fn().slice(10):fn();return e.length>1200?`…`+e.slice(-1200):e};b(()=>{Wt()||dn(e=>e?.text.startsWith(`[compact] `)?null:e)}),b(()=>{Wt(),requestAnimationFrame(()=>requestAnimationFrame(()=>{Ct()&&ri()}))});let[cn,ln]=v(new Map),un=()=>{let e=n();return e?cn().get(e)??null:null},dn=e=>{let t=n();t&&ln(n=>{let r=new Map(n),i=typeof e==`function`?e(n.get(t)??null):e;return i?r.set(t,{...i,at:Date.now()}):r.delete(t),r})},[fn,pn]=v(``),[_n,yn]=v(0),bn=()=>_n(),[Sn,Cn]=v(``),wn;b(()=>{un()?wn||=setTimeout(()=>{wn=void 0,pn(un()?.text??``),Cn(un()?.reasoning??``)},(un()?.text.length??0)>2e4?250:(un()?.text.length??0)>6e3?120:60):(clearTimeout(wn),wn=void 0,pn(``),Cn(``))}),C(()=>clearTimeout(wn)),b(()=>{let t=e();ln(e=>Ye(e,e=>t.find(t=>t.id===e)?.status)),yn(e=>Ze(e,t,n(),un()))}),b(()=>{let e=fn(),t=un()?.reasoning??``;(e||t)&&requestAnimationFrame(()=>{Ct()&&ri()})}),b(()=>{let e=z()?.pendingPrompts??0,t=z()?.pendingPromptIds,n=jn(),r=Mn(n),i=Ft(r,e,t);i!==r&&Nn(n,i)}),b(()=>{let e=z()?.pendingPromptQueue;if(!e?.length)return;let t=jn(),n=new Set(Mn(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&Nn(t,[...r.map(e=>({id:`p${e.id}`,text:e.text,at:Number(e.at)||Date.now(),promptId:e.id,images:e.images?.map(e=>e.url),...e.source?{source:e.source}:{}})),...Mn(t)])}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{W()&&(At(!0),Mt(0),ii(!0),Hn())})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let z=x(()=>e().find(e=>e.id===n())),B=()=>{let e=z();return e?e.live??(e.status===`running`||e.status===`waiting`||e.status===`needs_operator`):!1},Tn=()=>Bt(z(),i(),B()),[En,Dn]=v(null);x(()=>{let e=new Set;for(let t of m())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let On=new Map,[kn,An]=v([]),jn=()=>i()||n()||`?`,Mn=e=>On.get(e)??[],Nn=(e,t)=>{let n=new Set,r=[];for(let e=t.length-1;e>=0;e--){let i=t[e],a=i.promptId;a?n.has(a)||(n.add(a),r.push(i)):r.push(i)}r.reverse(),r.length===0?On.delete(e):On.set(e,r),jn()===e&&An(r)},[Pn,Fn]=v([]),[In,Ln]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[Rn,zn]=v(!1),Bn=()=>Pn().filter(e=>!e.read).length,Vn=e=>{Fn(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},Hn=()=>{let e=n();e&&Pn().some(t=>!t.read&&t.agentId===e)&&Vn(e)},Un=t=>{let n=Pn().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Un(r.id));return n},Wn=0,Gn=e=>{Fn(t=>[{...e,id:`n${++Wn}`,at:Date.now(),read:!1},...t].slice(0,50))},Kn=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t,i=typeof n.id==`string`?n.id:void 0;n.type===`message`&&n.data?.final===!0?Gn({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?Gn({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?Gn({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&Gn({agentId:t,kind:`progress`,title:`${r}: ${String(n.data.doing??`progress`)}`.slice(0,120),body:[n.data.recent&&`recent: ${n.data.recent}`,n.data.next&&`next: ${n.data.next}`].filter(Boolean).join(` · `).slice(0,300),eventId:i})},qn=e=>{let t=document.querySelector(`[data-eid="${e}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`flash-target`),setTimeout(()=>t.classList.remove(`flash-target`),1600))},Jn=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of m())if(fh.has(i.type)){if(i.type===`tool_call`){let e=n.get(i.data.callId)??[];e.push(i),n.set(i.data.callId,e)}else if(i.type===`tool_result`){let a=n.get(i.data.callId)?.shift();a?(e.set(a.id,i),t.add(i.id)):r.set(i.id,i)}}return{resFor:e,consumed:t,orphanCalls:r}}),[Yn,Xn]=v(new Set),Zn=e=>{e&&Xn(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},Qn=()=>Xn(new Set),$n=x(()=>Pt(m(),Yn())),er=x(()=>pt({events:m(),consumed:Jn().consumed,pending:kn(),echo:ir,feedTypes:fh,renderedTypes:mh,renderedNoteEvents:hh})),tr=x(()=>{let e=new WeakMap;return er().forEach((t,n)=>e.set(t,n)),e}),nr=(e,t)=>{let n=tr().get(e);if(n!==void 0)return er()[n+t]},rr=new Map;function ir(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=rr.get(t);if(n)return n;rr.size>64&&rr.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:z()?.session??``,branch:z()?.branch??`br0`,parent:null,type:`prompt`,data:{source:e.source??`user`,text:e.text,pending:!e.sent,...e.images?.length?{images:e.images}:{},...e.promptId?{promptId:e.promptId}:{}}};return rr.set(t,r),r}let ar=()=>$(`/api/config`).then(ae).catch(()=>{}),[or,sr]=v(!1);ee(()=>{let e=()=>sr(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[cr,lr]=v(``),[ur,dr]=v(!0),[fr,pr]=v(!1),mr=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==mr?(mr=t,pr(!1),lr(r)):t&&!fr()&&lr(r)});let hr=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:cr(),notify:e})}),pr(!1),dr(!0),Q(`tasks saved${e&&cr().trim()?` & notification queued`:``}`),vr()}catch(e){Q(`save failed: ${e.message}`)}},gr=x(()=>{let e=0,t=0;for(let n of cr().split(`
|
|
21
|
+
- task two"title="shared with the agent \\u2014 it may check items off via set_todo; your unsaved edits win until you save">`),Jp=F(`<span class=fsize>`),Yp=F(`<div><span class=ficon></span><span class=fname>`),Xp=F(`<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>· `),Zp=F(`<div class=filebox>`),Qp=F(`<div class=muted style=padding:6px>`),$p=F(`<img>`),em=F(`<div class=mediapreview><div class="meta muted"> preview`),tm=F(`<button title="rendered markdown">👁 preview`),nm=F(`<button title="edit and save back to the workspace">✎ edit`),rm=F(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),im=F(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),am=F(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),om=F(`<div class="content mdpreview">`),sm=F(`<video controls>`),cm=F(`<audio controls>`),lm=F(`<div class=filepreview>`),um=F(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),dm=F(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),fm=F(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),pm=F(`<label><input type=number min=0>`),mm=F(`<div class=muted style=font-size:11.5px;margin-top:4px>⚠ configured default provider <code></code> has no provider row here<!> Add a provider named <code></code> or pick a default below; otherwise agents fall back to the first provider.`),hm=F(`<div class=cfggrid style=margin-top:8px><label class=trow>dark theme →<select class=w100></select></label><label class=trow>light theme →<select class=w100>`),gm=F(`<div class=skilllist>`),_m=F(`<form style=display:flex;flex-direction:column;gap:12px;min-height:0><div class=cfgbody><nav class=cfgmenu aria-label="settings sections"></nav><div class=cfgpanel><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>appearance</legend><div class=cfggrid><label class=trow>follow the system<input type=checkbox></label></div><h4 class=cfgsub>themes</h4></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><label class=cfgtoggle title="prune old tool output early (at 60% of the budget) instead of waiting for the window to fill. Meant for small-window models — on a large window it throws away context you had room for."><input type=checkbox>short-context mode (#161)</label></fieldset><fieldset><legend>MCP servers — external tools, shared by every agent</legend><div class=muted style=font-size:11.5px;margin-bottom:8px>each tool becomes <code class=mono>mcp__server__tool</code> for every agent. saving connects them; the status shown here is live.</div><button type=button>+ add MCP server</button></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>archived agents — restore, or delete for good</legend></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><fieldset><legend>live update</legend><div class=cfgrow><span class=muted>current version: </span><button type=button class=primarybtn>update & restart</button><span class=muted style=margin-left:8px;font-size:12px>gracefully stops all agents, spawns new process, then reloads this page</span></div></fieldset><fieldset><legend>skills</legend><div class=featgrid><div class=featrow><b>image downscaling</b><span class=muted></span></div><div class=featrow><b>terminal pty</b><span class=muted></span></div></div></fieldset><fieldset><legend>help</legend><div class=helpsec><h4 class=cfgsub>keyboard</h4><div class=helprow><kbd>enter</kbd><span>send (shift+enter for a newline)</span></div><div class=helprow><span class=kbdgroup><kbd>↑</kbd><kbd>↓</kbd></span><span>move between sessions</span></div><div class=helprow><kbd>/</kbd><span>command palette — commands and focus</span></div><div class=helprow><kbd>t</kbd><span>open the terminal panel</span></div><div class=helprow><kbd>d</kbd><span>toggle the details panel</span></div><div class=helprow><kbd>esc</kbd><span>interrupt the running turn</span></div></div><div class=helpsec><h4 class=cfgsub>what the toggles do</h4><div class=helprow><b>auto-continue</b><span>fires after a round only when all hold: the toggle is on, a goal is set and its status is <code>active</code>, and the round ended cleanly (not an error, not stopped). It stops when the goal is marked done, or when you press ■ stop. Sending any prompt starts an idle agent regardless.</span></div><div class=helprow><b>auto-compact</b><span>when the live context passes the budget shown under 📊 runtime, older turns are summarized into notes and the recent stretch is kept verbatim, so work continues without losing the thread. Off means you compact by hand (<code>/compact</code>).</span></div><div class=helprow><b>messages while it works</b><span>anything you send queues up and is handed to the model at its next turn boundary — the timeline shows it as "pending (queued)…" until then. Withdraw it with ✕ cancel while it is still queued.</span></div><div class=helprow><b>👻 ghost sessions</b><span>a session whose workspace directory no longer exists on disk. The session log is intact — recreate the directory and it stops being a ghost.</span></div></div></fieldset></div></div><div class=cfgfoot><button type=submit class=cfgsave>`),vm=F(`<button type=button><span class=cfgmenu-label>`),ym=F(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="default model"><button type=button class=danger title="remove provider">✕</button><div class=cfgkeys><button type=button title="add another key for this provider — they are rotated round-robin, and a rate-limited key is skipped for a minute">+ key`),bm=F(`<button type=button title="remove this key">−`),xm=F(`<div class=cfgkeyrow><input type=password>`),Sm=F(`<button type=button>+ `),Cm=F(`<div class=cfgsub style=margin-bottom:var(--space-1)>`),wm=F(`<div class=themepick>`),Tm=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label> ★`),Em=F(`<button type=button><span class=themecard-preview></span><span class=themecard-label>`),Dm=F(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),Om=F(`<input placeholder="command (e.g. npx)">`),km=F(`<input placeholder="args, space separated">`),Am=F(`<input type=password placeholder="paste the token"title="sent as Authorization: Bearer <token>"style=flex:1>`),jm=F(`<input placeholder="header name"style="flex:0 1 150px">`),Mm=F(`<input type=password placeholder=value style=flex:1>`),Nm=F(`<div class=cfgrow><textarea class=mono rows=2 placeholder="{"Authorization": "Bearer …", "X-Team": "infra"}"title="static headers for every request. Use the bearer option unless the server needs something unusual."style=flex:1>`),Pm=F(`<button type=button class=archrestore title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),Fm=F(`<span class="mcpstate connected"title="an OAuth access token is usable">🔑 authorized`),Im=F(`<button type=button title="forget the stored grant (the refresh token is deleted)">disconnect`),Lm=F(`<div class=muted style=font-size:11px;color:var(--warn)>`),Rm=F(`<div class="cfgcol mcpcard"><div class=cfgrow><input class=cfgname placeholder=name title="the name that appears inside mcp__<name>__ in tool names"><input placeholder="https://example.com/mcp (or leave empty for a stdio command)"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>on</label><button type=button class=danger>✕</button></div><div class=cfgrow><select title="streamable HTTP is the current spec; legacy SSE is the 2024-11-05 handshake; stdio spawns a local process"><option value=http>streamable http</option><option value=sse>legacy http+sse</option><option value=stdio>stdio (local command)</option></select></div><div class=cfgrow><select title="how this server authenticates"><option value=none>no auth</option><option value=bearer>bearer token</option><option value=header>custom header</option><option value=json>headers as JSON (advanced)</option></select></div><div class=cfgrow><button type=button title="connect now and list the tools — nothing is saved">test`),zm=F(`<option value=oauth selected>`),Bm=F(`<span class=muted> · needs a grant (🔑 authorize)`),Vm=F(`<ul class=mcptools>`),Hm=F(`<div><div class=mcpresult-head><b>`),Um=F(`<span class=mcptool-desc>`),Wm=F(`<li><code class=mono>`),Gm=F(`<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">`),Km=F(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),qm=F(`<div class="cfgrow archrow"><div class=archmain><b></b><span class=muted> session</span><span class="muted mono ellip"></span></div><button type=button class=archrestore title="bring it back and start it again — its history was never touched">↩ restore</button><button type=button class=danger title="erase the config entry AND every session directory — irreversible">🗑 delete`),Jm=F(`<span class=muted>🧩 sub of @`),Ym=F(`<div class=cfgrow><b></b><span class=muted>`),Xm=F(`<div class=muted>`),Zm=F(`<div class=skillbody>`),Qm=F(`<div class=skillrow><button type=button class=skillhead title="show the playbook"><span class=skillcaret></span><b class=mono></b><span class=muted>`),$m=F(`<div class="muted skillbody">`),eh=new Map;function th(e){let t=eh.get(e);if(t!==void 0)return t;let n=Ie(e);return eh.set(e,n),eh.size>500&&eh.delete(eh.keys().next().value),n}var nh=[`minimal`,`low`,`medium`,`high`],rh=1100,ih={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`}},ah={name:`harness`,icon:`📣`,color:`#3ba55d`},[oh,sh]=v(``),ch,Q=e=>{sh(e),clearTimeout(ch),ch=setTimeout(()=>sh(``),3200)},lh=!1,uh=[{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`]}],dh=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`?ih.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:ah}return ih[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},fh=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),ph=new Set([`system_note`]),mh=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`]),hh=new Set([`runaway-detected`,`error-retry`,`background-exit`,`context-compacted`,`context-compaction-started`]),gh=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=null;try{t=await i.json()}catch{}let n=(t&&typeof t==`object`&&`error`in t?String(t.error):``)||`${e}: HTTP ${i.status}`;throw Object.assign(Error(n),{payload:t})}return i.json()}var _h=location.hash.match(/[#&]token=([^&]+)/);_h&&(localStorage.setItem(`teapot.token`,decodeURIComponent(_h[1])),history.replaceState(null,``,location.pathname+location.search));var vh=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function yh(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v(``),[o,s]=v(new Map),[c,l]=v(new Map),[u,d]=v(new Map),f=!1;async function p(e=!1){if(!f||e){f=!0;try{let e=await $(`/api/sessions`),t=new Map,n=new Map,r=new Map;for(let i of e.sessions??[]){t.set(i.id,i.agentId),typeof i.title==`string`&&i.title&&r.set(i.id,i.title);let e=n.get(i.agentId)??[];e.push(i.id),n.set(i.agentId,e)}s(t),l(n),d(r)}catch{}}}let[m,h]=v([]),[g,_]=v(0),[w,te]=v([]),[T,ne]=v(null),E=new Map,[re,ie]=v(E.get(n()??``)??``),D=e=>{ie(e);let t=n();t&&(e?E.set(t,e):E.delete(t))},[O,ae]=v({providers:{}}),[oe,se]=v(!1),ce=[640,1280,1920,2560,3840],le=()=>{let e=Re()?tt()?Be():Qe():Fe();return Ge().find(t=>t.id===e)?.backgroundImage??``},k=()=>{let e=Re()?tt()?Be():Qe():Fe();return Ge().some(t=>t.id===e)||uh.some(t=>t.key===e)?e:`dark`},[ue,A]=v(!1),de=!1;b(()=>{!de&&O()?.needsSetup&&(de=!0,requestAnimationFrame(()=>{ar(),A(!0)}))}),b(()=>{ue()&&!oa()&&$(`/api/features`).then(e=>sa(e)).catch(()=>sa(null))});let fe=new Set,pe=()=>window.innerWidth<=rh,[me,he]=v(pe());ee(()=>{let e=()=>he(pe());window.addEventListener(`resize`,e),C(()=>window.removeEventListener(`resize`,e)),e()});let ge,_e,ve=0,ye=``,be=()=>{ve=0;let e=ti();if(!e)return;if(ya=e.scrollHeight,wa=e.clientHeight,Ct()){ri();return}let t=F(e);if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;r&&(e.scrollTop+=r,va={top:e.scrollTop,height:e.scrollHeight}),Ut(ni())};function xe(e,t){if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;Math.abs(r)<1||Math.abs(r)>Sa||(e.scrollTop+=r,va={top:e.scrollTop,height:e.scrollHeight})}let Se=()=>{ve||=requestAnimationFrame(be)},Ce=e=>{e&&e!==_e&&(ge??=new ResizeObserver(e=>{let t=e[0]?.contentRect,n=t?`${Math.round(t.width)}x${Math.round(t.height)}`:``;n!==ye&&(ye=n,Se())}),_e&&ge.unobserve(_e),_e=e,ye=``,ge.observe(e))};ee(()=>{window.addEventListener(`resize`,Se),C(()=>{window.removeEventListener(`resize`,Se),ge?.disconnect(),ge=void 0,_e=void 0,ve&&cancelAnimationFrame(ve)})});function F(e){let t=e.querySelectorAll(`[data-eid]`);if(!t.length)return null;let n=e.getBoundingClientRect().top,r=e=>t[e].getBoundingClientRect(),i=0,a=t.length-1,o=-1;for(;i<=a;){let e=i+a>>1;r(e).bottom>n?(o=e,a=e-1):i=e+1}if(o<0)return null;let s=t[o].dataset.eid??``;return s?{sel:`[data-eid="${CSS.escape(s)}"]`,top:r(o).top}:null}let[we,Te]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>rh:localStorage.getItem(`teapot.panel`)===`1`),ke=e=>{Te(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},Ae=()=>ke(!we()),je=()=>{we()&&ke(!1)},[Me,Ne]=v(!1),Pe=()=>Ne(!1),[Fe,Le]=v(localStorage.getItem(`teapot.theme`)??`dark`),[Re,ze]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[Be,Ve]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[Ge,qe]=v(mn());ee(()=>{gn().then(e=>{if(e===null)return;let t=xt(Ge(),e);qe(t),hn(t)})});let[Qe,$e]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),et=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[tt,nt]=v(et?.matches??!1);ee(()=>{let e=e=>nt(e.matches);et?.addEventListener(`change`,e),C(()=>et?.removeEventListener(`change`,e))}),b(()=>{let e=xn({want:Re()?tt()?Be():Qe():Fe(),customIds:Ge().map(e=>e.id),presetIds:uh.map(e=>e.key),fallback:`dark`}),t=e.active,n=Ge().find(e=>e.id===t)??null;e.repaired&&(Re()?localStorage.setItem(tt()?`teapot.theme.light`:`teapot.theme.dark`,t):localStorage.setItem(`teapot.theme`,t)),document.documentElement.dataset.theme=t,vn(document.documentElement,n),document.documentElement.dataset.appearance=n?.mode??uh.find(e=>e.key===t)?.mode??`dark`});let[rt,it]=v(``),[at,ot]=v(``),[st,ct]=v(``);b(()=>{let t=n();ct(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[lt,ut]=v([]),dt=()=>Object.keys(O().providers??{});async function ft(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);ut(t.models??[])}catch{ut([])}}let mt=e=>{let t={text:`📄`,image:`🖼️`,audio:`🔊`,video:`🎬`,file:`📎`},n=e=>(e??[`text`]).map(e=>t[e]??e).join(``);return e?.modalities?`${n(e.modalities.input)} → ${n(e.modalities.output)}`:``},gt=()=>{let e=at().trim()||z()?.model||``;if(!e)return``;let t=lt().find(t=>t.id===e);if(!t)return``;let n=[],r=mt(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${Nh(t.contextLength)} tok`);let i=e=>e===void 0?``:`${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=i(t.pricing.prompt),r=i(t.pricing.completion);e&&r?n.push(`${e} in · ${r} out`):(e||r)&&n.push(i(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},_t=null,vt=!1;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||O().defaultProvider||dt()[0]||``;if(r){if(t!==_t)_t=t,vt=!1,S(()=>rt())!==i&&(it(i),ft(i)),S(()=>at())&&ot(``);else{let e=S(()=>rt());!S(()=>at())&&e!==i&&Xt(vt)&&(it(i),ft(i))}}});let[yt,bt]=v(!1),[Ct,At]=v(!0),[jt,Mt]=v(0),[Nt,Lt]=v(-1),Ut=e=>Lt(e?on(e):-1),[Wt,Gt]=v(null),qt=()=>fn().startsWith(`[compact] `),$t=()=>{let e=qt()?fn().slice(10):fn();return e.length>1200?`…`+e.slice(-1200):e};b(()=>{Wt()||dn(e=>e?.text.startsWith(`[compact] `)?null:e)}),b(()=>{Wt(),requestAnimationFrame(()=>requestAnimationFrame(()=>{Ct()&&ri()}))});let[cn,ln]=v(new Map),un=()=>{let e=n();return e?cn().get(e)??null:null},dn=e=>{let t=n();t&&ln(n=>{let r=new Map(n),i=typeof e==`function`?e(n.get(t)??null):e;return i?r.set(t,{...i,at:Date.now()}):r.delete(t),r})},[fn,pn]=v(``),[_n,yn]=v(0),bn=()=>_n(),[Sn,Cn]=v(``),wn;b(()=>{un()?wn||=setTimeout(()=>{wn=void 0,pn(un()?.text??``),Cn(un()?.reasoning??``)},(un()?.text.length??0)>2e4?250:(un()?.text.length??0)>6e3?120:60):(clearTimeout(wn),wn=void 0,pn(``),Cn(``))}),C(()=>clearTimeout(wn)),b(()=>{let t=e();ln(e=>Ye(e,e=>t.find(t=>t.id===e)?.status)),yn(e=>Ze(e,t,n(),un()))}),b(()=>{let e=fn(),t=un()?.reasoning??``;(e||t)&&requestAnimationFrame(()=>{Ct()&&ri()})}),b(()=>{let e=z()?.pendingPrompts??0,t=z()?.pendingPromptIds,n=jn(),r=Mn(n),i=Ft(r,e,t);i!==r&&Nn(n,i)}),b(()=>{let e=z()?.pendingPromptQueue;if(!e?.length)return;let t=jn(),n=new Set(Mn(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&Nn(t,[...r.map(e=>({id:`p${e.id}`,text:e.text,at:Number(e.at)||Date.now(),promptId:e.id,images:e.images?.map(e=>e.url),...e.source?{source:e.source}:{}})),...Mn(t)])}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{W()&&(At(!0),Mt(0),ii(!0),Hn())})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let z=x(()=>e().find(e=>e.id===n())),B=()=>{let e=z();return e?e.live??(e.status===`running`||e.status===`waiting`||e.status===`needs_operator`):!1},Tn=()=>Bt(z(),i(),B()),[En,Dn]=v(null);x(()=>{let e=new Set;for(let t of m())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let On=new Map,[kn,An]=v([]),jn=()=>i()||n()||`?`,Mn=e=>On.get(e)??[],Nn=(e,t)=>{let n=new Set,r=[];for(let e=t.length-1;e>=0;e--){let i=t[e],a=i.promptId;a?n.has(a)||(n.add(a),r.push(i)):r.push(i)}r.reverse(),r.length===0?On.delete(e):On.set(e,r),jn()===e&&An(r)},[Pn,Fn]=v([]),[In,Ln]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[Rn,zn]=v(!1),Bn=()=>Pn().filter(e=>!e.read).length,Vn=e=>{Fn(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},Hn=()=>{let e=n();e&&Pn().some(t=>!t.read&&t.agentId===e)&&Vn(e)},Un=t=>{let n=Pn().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Un(r.id));return n},Wn=0,Gn=e=>{Fn(t=>[{...e,id:`n${++Wn}`,at:Date.now(),read:!1},...t].slice(0,50))},Kn=(t,n)=>{let r=e().find(e=>e.id===t)?.id??t,i=typeof n.id==`string`?n.id:void 0;n.type===`message`&&n.data?.final===!0?Gn({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?Gn({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?Gn({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&Gn({agentId:t,kind:`progress`,title:`${r}: ${String(n.data.doing??`progress`)}`.slice(0,120),body:[n.data.recent&&`recent: ${n.data.recent}`,n.data.next&&`next: ${n.data.next}`].filter(Boolean).join(` · `).slice(0,300),eventId:i})},qn=e=>{let t=document.querySelector(`[data-eid="${e}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`flash-target`),setTimeout(()=>t.classList.remove(`flash-target`),1600))},Jn=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of m())if(fh.has(i.type)){if(i.type===`tool_call`){let e=n.get(i.data.callId)??[];e.push(i),n.set(i.data.callId,e)}else if(i.type===`tool_result`){let a=n.get(i.data.callId)?.shift();a?(e.set(a.id,i),t.add(i.id)):r.set(i.id,i)}}return{resFor:e,consumed:t,orphanCalls:r}}),[Yn,Xn]=v(new Set),Zn=e=>{e&&Xn(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},Qn=()=>Xn(new Set),$n=x(()=>Pt(m(),Yn())),er=x(()=>pt({events:m(),consumed:Jn().consumed,pending:kn(),echo:ir,feedTypes:fh,renderedTypes:mh,renderedNoteEvents:hh})),tr=x(()=>{let e=new WeakMap;return er().forEach((t,n)=>e.set(t,n)),e}),nr=(e,t)=>{let n=tr().get(e);if(n!==void 0)return er()[n+t]},rr=new Map;function ir(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=rr.get(t);if(n)return n;rr.size>64&&rr.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:z()?.session??``,branch:z()?.branch??`br0`,parent:null,type:`prompt`,data:{source:e.source??`user`,text:e.text,pending:!e.sent,...e.images?.length?{images:e.images}:{},...e.promptId?{promptId:e.promptId}:{}}};return rr.set(t,r),r}let ar=()=>$(`/api/config`).then(ae).catch(()=>{}),[or,sr]=v(!1);ee(()=>{let e=()=>sr(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[cr,lr]=v(``),[ur,dr]=v(!0),[fr,pr]=v(!1),mr=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==mr?(mr=t,pr(!1),lr(r)):t&&!fr()&&lr(r)});let hr=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:cr(),notify:e})}),pr(!1),dr(!0),Q(`tasks saved${e&&cr().trim()?` & notification queued`:``}`),vr()}catch(e){Q(`save failed: ${e.message}`)}},gr=x(()=>{let e=0,t=0;for(let n of cr().split(`
|
|
22
22
|
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}});function _r(e,t){let n=new Map(e.map(e=>[e.id,e]));return t.map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})}let vr=()=>$(`/api/agents`).then(e=>{let n=!1;t(t=>(t.length!==(e.agents??[]).length&&(n=!0),(e.agents??[]).some(e=>!t.some(t=>t.id===e.id))&&(n=!0),_r(t,e.agents??[]))),n&&p()}).catch(()=>{}),yr=()=>$(`/api/metrics`).then(ne).catch(()=>{}),[br,xr]=v([]),Sr=()=>$(`/api/tasks`).then(e=>xr(e.tasks)).catch(()=>{}),Cr=e=>br().filter(t=>t.agent===e),[wr,Tr]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.expandedSubs`)??`[]`);return new Set(e.filter(e=>typeof e==`string`))}catch{return new Set}})()),[Er,Dr]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`);return new Set(e.filter(e=>typeof e==`string`&&!e.startsWith(`chat:`)))}catch{return new Set}})()),Or=e=>Er().has(e)||!wr().has(e),kr=e=>{let t=new Set(wr());if(t.has(e)?t.delete(e):t.add(e),Tr(t),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...t])),t.has(e)&&Er().has(e)){let t=new Set(Er());t.delete(e),Dr(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))}},Ar=t=>Dt(e(),t),[jr,Mr]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.wsCollapsed`)??`[]`),t=Array.isArray(e)?e.filter(e=>typeof e==`string`):[];if(Number(localStorage.getItem(`teapot.wsCollapsed.v`)??`0`)<2){let e=t.filter(e=>!e.startsWith(`chat:`));return t.length-e.length>0&&localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify(e)),localStorage.setItem(`teapot.wsCollapsed.v`,`2`),new Set(e)}return new Set(t)}catch{return new Set}})()),Nr=x(()=>{let e=new Set;for(let t of jr())t.startsWith(`chat:`)&&e.add(t);return e}),Pr=x(()=>St(e(),new Set(e().filter(e=>Or(e.id)).map(e=>e.id)),In(),Nr())),Fr=(t,r,i,a)=>{let o=new Set(jr());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||Ar(e().find(e=>e.id===i))===t)&&Q(`hid ${r} — click the header to show it`)}Mr(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},Ir=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,V=e=>{let t=Lr().get(e)??0;return`${t} chat${t===1?``:`s`}`},Lr=x(()=>Ot(e())),Rr=x(()=>kt(e(),Pr(),jr())),H=2e3,[zr,Br]=v(null),Vr=new Map;function U(e){return`${i()||(n()??`?`)}:${e.id}`}function Hr(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=U(r),a=Vr.get(i);if(t[n]=a??r,!a&&(Vr.set(i,r),Vr.size>6e3)){let e=Vr.keys().next().value;e!==void 0&&Vr.delete(e)}}return t}let[Ur,Wr]=v(!1),[Gr,Kr]=v(!1),[qr,Jr]=v(!1),Yr=0,Xr=-1;function Zr(e){let t=Hr(e);h(e=>{if(t.length>0&&e.length>0){let n=e[e.length-1],r=t.every(e=>e.seq>n.seq),i=new Set(e.map(e=>e.id));if(r&&t.every(e=>!i.has(e.id)))return[...e,...t]}let n=new Map;for(let t of e)n.set(t.id,t);let r=!1;for(let e of t)n.has(e.id)||(n.set(e.id,e),r=!0);return r?[...n.values()].sort((e,t)=>e.seq-t.seq):e})}async function Qr(){let e=n();if(!e||qr()||Ur()||Ct())return;if(m().length>=g()){Jr(!0);return}let t=()=>{let e=ti();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!qr()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(m().length>=g()){Jr(!0);return}let i=m().length;if(await $r(),m().length===i)return;tn(ni())&&n()===e&&ii(!0)}}async function $r(){let e=n(),t=m()[0];if(e&&t&&!Ur()&&!qr()){Wr(!0);try{let r=ti(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=zr(),c=i(),l=c&&c!==e?`&session=${encodeURIComponent(c)}`:``,u=(await $(`/api/agents/${e}/events?limit=${H}&before=${encodeURIComponent(t.id)}${l}${s?`&branch=${encodeURIComponent(s)}&lineage=true`:``}`)).events??[];if(u.length===0){Jr(!0);return}if(n()!==e||m()[0]?.id!==t.id)return;Zr(u),requestAnimationFrame(()=>{if(n()===e){let e=ti();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{Wr(!1)}}}async function ei(e,t){let r=Yr,a=t??i()??``;try{let t=zr(),i=r!==Xr||!w().length;m().length||Kr(!0);let o=a&&a!==e?`&session=${encodeURIComponent(a)}`:``;$(`/api/agents/${e}/skills`).then(t=>{r===Yr&&n()===e&&aa(t.skills??[])}).catch(()=>{});let[s,c]=await Promise.all([$(`/api/agents/${e}/events?limit=${H}${o}${t?`&branch=${encodeURIComponent(t)}&lineage=true`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:w()})]);if(i&&(Xr=r),r!==Yr||n()!==e)return;h(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of Hr(s.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),_(s.total??s.events.length),te(c.branches)}catch{}finally{Kr(!1)}}function ti(){return document.querySelector(`.feed`)}function ni(){let e=ti();return e?{top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight}:null}function W(){return tn(ni())}function ri(){let e=ti();e&&(e.scrollTop=e.scrollHeight,va={top:e.scrollTop,height:e.scrollHeight},Mt(0))}function ii(e=!1){(e||Ct())&&ri()}let ai=new Map,oi=(t,n)=>It(c().get(t),e().find(e=>e.id===t)?.session,n);async function si(e,t=!0,o){let s=n(),l=i(),u=m(),d=g();Yr++,c().size||p();let f=oi(e,o)??e;if(s!==e||f!==l){if(l&&u.length&&(ai.set(l,{events:u,total:d,at:Date.now()}),ai.size>6)){let e=[...ai.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&ai.delete(e[0])}h([]),Vr.clear(),Qn(),Gt(null),Mt(0),At(!0),_a=void 0}r(e),a(f),D(E.get(e)??``),Br(null),Jr(!1),Wr(!1),Nn(l||s||`?`,kn()),An(Mn(f||e)),localStorage.setItem(`teapot.session`,e),yi(f,t);let v=ai.get(f);v?.events.length&&(Hr(v.events),h(Hr(v.events)),_(v.total),requestAnimationFrame(()=>{n()===e&&ii(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(vr).catch(()=>{}),await ei(e,f),n()===e&&(ln(t=>{let n=t.get(e)??null,r=Xe(n,m(),z()?.status);if(r===n)return t;let i=new Map(t);return r?i.set(e,r):i.delete(e),i}),Gt(z()?.ctx?.compacting?{phase:String(z().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&ii(!0)}),Qr())}let[ci,li]=v(!1),ui=null,di=null;C(()=>ui?.close());let fi=!1,pi=null;document.addEventListener(`visibilitychange`,()=>pi?.()),C(()=>{pi=null});let mi=!0,hi=null;async function gi(){let e=n(),t=m().at(-1)?.id,r=i(),a=document.visibilityState===`hidden`;if(!e||!t)fi=!0,a||hi?.();else try{let n=r&&r!==e?`&session=${encodeURIComponent(r)}`:``,i=zr(),o=await $(`/api/agents/${e}/events?after=${encodeURIComponent(t)}${n}${i?`&branch=${encodeURIComponent(i)}&lineage=true`:``}`),s=o.events??[];o.gap?(h(Hr(s)),_(s.length)):s.length&&(Zr(s),_(e=>e+s.length)),await vr(),s.length&&!a&&yr()}catch{fi=!0}}function _i(){mi=!0;let r=location.protocol===`https:`?`wss://`:`ws://`,a=new WebSocket(`${r}${location.host}/api/ws${vh()}`);ui=a,a.onopen=()=>{li(!0),mi?mi=!1:gi()},a.onclose=()=>{li(!1),setTimeout(_i,1500)},a.onerror=()=>a.close();let o=new Set([`state`,`usage`,`session_start`]);a.onmessage=r=>{let c=JSON.parse(r.data);if(c.kind===`ping`)try{a.send(JSON.stringify({kind:`pong`}))}catch{}else if(c.kind!==`pong`){if(c.kind===`hello`&&Array.isArray(c.agents)){t(e=>_r(e,c.agents));let n=e();ln(e=>Ye(e,e=>n.find(t=>t.id===e)?.status))}else if(c.kind===`event`&&We(c.event))ln(e=>Ue(e,c.agentId));else if(c.kind===`llm-delta`){if(!zt(c,n(),i()))return;if(ln(e=>He(e,c.agentId,c)),c.agentId===n()){let e=String(c.reasoning??``),t=String(c.text??``);e&&!t?_n()||yn(Date.now()):t&&yn(0)}}else if(c.kind===`compaction-progress`){if(c.agentId!==n())return;c.phase===`done`?Gt(null):Gt({phase:c.phase,summarized:c.summarized})}else if(c.kind===`agent-update`&&c.snapshot)t(e=>{let t=e.findIndex(e=>e.id===c.snapshot.id),n=c.snapshot;return t===-1?[...e,n]:_r(e,e.map((e,n)=>n===t?c.snapshot:e))});else{if(c.kind===`event`){let e=c.event?.type,t=c.event?.data??{};if((e===`system_note`&&t.event===`prompt-delivered`&&c.agentId===n()||e===`system_note`&&t.event===`prompt-cancelled`&&c.agentId===n())&&Nn(jn(),kn().filter(e=>e.promptId!==t.promptId)),o.has(e)&&!ph.has(e)||(Kn(c.agentId,c.event),c.event?.agent!==n())||!Rt(c.event,n(),i()))return;if(Zr([c.event]),c.event?.type===`message`&&c.event.data?.role===`assistant`){let e=un();e&&Ke(e,m(),z()?.status)&&dn(null)}if(fi=!0,document.visibilityState!==`visible`||di)return;di=setTimeout(s,60)}document.visibilityState===`hidden`?fi=!0:di||=setTimeout(s,120)}}},fi=!1;let s=async()=>{if(di=null,await vr(),await yr(),n()){let e=m().at(-1)?.id,t=m().length;await ei(n());let r=un();r&&!Xe(r,m(),z()?.status)&&dn(null),m().at(-1)?.id!==e&&(Ct()?(ri(),Vn(n())):(Mt(e=>e+Math.max(0,m().length-t)),Ut(ni())))}};hi=s,pi=()=>{document.visibilityState===`visible`&&n()&&(fi?(fi=!1,s()):m().at(-1)?.id?gi():(fi=!0,s()))}}let vi=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function yi(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=vi(),t=o().get(e);t&&(t!==n()||e!==i())&&si(t,!1,e||null)}),b(()=>{let e=z(),t=e?`${B()?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=Bn()>0?`(${Bn()}) ${t}`:t});let bi=()=>oe()||ue()||En()!==null||pe()&&we();window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable))e.key===`Escape`&&t.blur();else if(e.key===`Escape`){if(oe()){se(!1);return}if(ue()){A(!1);return}if(En()){Dn(null);return}if(pe()&&we()){je();return}let e=z();if(e&&B()){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(vr);return}}else if(!bi()){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)Ae();else if(e.key===`t`)Ci();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=Pr().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&&si(t[i].id)}}});let[xi,Si]=v(localStorage.getItem(`teapot.term`)===`1`),Ci=()=>{let e=!xi();Si(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[G,wi]=v([]),[Ti,Ei]=v(0),[Di,Oi]=v(-1),[ki,Ai]=v(!1),[ji,Mi]=v(0),[Ni,Pi]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),Fi=new Map,Ii=[null,null],Li=()=>G()[ji()===0?Ti():Di()]??null;function Ri(e){if(!G()[e])return;let t=ji(),n=t===0?Ti():Di(),r=t===0?Di():Ti(),i=e=>t===0?Ei(e):Oi(e);r===e?((e=>t===0?Oi(e):Ei(e))(n),i(e)):n!==e&&i(e)}let zi=()=>Bi();async function Bi(e){let t=e??n();if(t){if(G().filter(e=>e.agentId===t).length>=10)Q(`max 10 shells per agent (${t}) — that's already a lot`);else try{let e=(await $(`/api/terminals`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({agentId:t})})).terminal;if(!e){Q(`could not open a shell`);return}let n=pu(G());wi(t=>[...t,{key:e.id,agentId:e.agentId,title:e.title}]),ji()===0?Ei(n):Oi(n)}catch(e){Q(`could not open a shell: ${e.message}`)}}}function Vi(e){let t=G()[e];if(!t)return;$(`/api/terminals/${encodeURIComponent(t.key)}`,{method:`DELETE`}).catch(()=>{});let n=Fi.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),Fi.delete(t.key)}let r=G().filter((t,n)=>n!==e);wi(r),Ei(t=>hu(t,e,r.length)),Oi(t=>t===-1?-1:hu(t,e,r.length))}b(()=>{Re(),Fe(),tt(),Be(),Qe();for(let[,e]of Fi)Ht(e.term)});function Hi(){for(let[,e]of Fi){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}Fi.clear()}function Ui(e,t){let n=Fi.get(e.key);if(n&&Ht(n.term),n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new lu({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:Vt()}),a=new fu;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${encodeURIComponent(e.agentId)}/term?terminal=${encodeURIComponent(e.key)}${vh()}`);s.onmessage=t=>{let n=JSON.parse(t.data);n.kind===`data`?i.write(n.data):n.kind===`exit`?(i.write(`\r\n\x1b[2m[terminal exited ${n.code??``}]\x1b[0m\r\n`),wi(t=>t.filter(t=>t.key!==e.key)),Fi.get(e.key)?.term.dispose(),Fi.delete(e.key)):n.kind===`attach`&&n.error&&i.write(`\r\n\x1b[2m[${n.error}]\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=[],d=()=>{try{a.fit()}catch{}s.readyState===WebSocket.OPEN?(i.cols!==c.cols||i.rows!==c.rows)&&(c={cols:i.cols,rows:i.rows},s.send(JSON.stringify({kind:`resize`,cols:i.cols,rows:i.rows}))):f()};function f(){l||=setInterval(()=>{Fi.has(e.key)?s.readyState===WebSocket.OPEN&&(clearInterval(l),l=void 0,d()):(clearInterval(l),l=void 0)},400)}s.addEventListener(`open`,()=>d());let p=r.parentElement??r,m=new ResizeObserver(()=>{u[0]&&clearTimeout(u[0]),u[0]=setTimeout(d,250)});m.observe(p),p!==r&&m.observe(r),setTimeout(d,60),n={el:r,term:i,fit:a,ws:s,ro:m},Fi.set(e.key,n)}return n}function Wi(e){let t=Ii[e];if(!t)return;let n=G()[e===0?Ti():Di()];if(!n){[...Fi.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Ui(n,t);for(let[e,r]of Fi)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(ji()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{G(),ki(),Ti(),Di(),Ni(),requestAnimationFrame(()=>{Wi(0),ki()&&Wi(1)})});let Gi=null;b(()=>{if(!xi())return;let e=n();if(!e||e===Gi)return;Gi=e;let t=G().map((e,t)=>({t:e,i:t})).filter(t=>t.t.agentId===e);t.length&&Ri(t[t.length-1].i)}),b(()=>{let e=G().length,t=mu(Ti(),e);if(t!==Ti()&&Ei(t),ki()){let t=mu(Di(),e);t!==Di()&&Oi(t)}});let Ki=e=>{e.preventDefault();let t=e.clientY,n=Ni(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Pi(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(Ni())),requestAnimationFrame(()=>{Wi(0),ki()&&Wi(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},qi=()=>{let e=!ki();Ai(e),e&&(Di()<0||Di()===Ti()||Di()>=G().length)&&Oi(gu(Ti(),G().length)),requestAnimationFrame(()=>{Wi(0),ki()&&Wi(1)})};C(Hi);let Ji=e=>t=>{Ii[e]=t,t&&requestAnimationFrame(()=>{Wi(e),ki()&&Wi(1),setTimeout(()=>Wi(e),200)})};ee(()=>{ar(),vr().then(async()=>{await p();let t=vi(),n=t?o().get(t):void 0,r=(n?e().find(e=>e.id===n):void 0)??e().find(e=>e.id===t&&!o().has(t))??e().find(e=>e.id===localStorage.getItem(`teapot.session`))??e()[0];r&&si(r.id,!1,t||null)}),yr(),Sr(),Qi(),_i(),$(`/api/terminals`).then(e=>{let t=e.terminals??[];t.length&&(wi(t.map(e=>({key:e.id,agentId:e.agentId,title:e.title}))),xi()&&(Ei(0),Oi(-1)))}).catch(()=>{});let t=setInterval(()=>{yr(),Sr()},3e4);C(()=>clearInterval(t))});let Yi=[{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`}],[Xi,Zi]=v([]),Qi=()=>$(`/api/personas`).then(e=>Zi(e.personas)).catch(()=>{}),[$i,ea]=v(!1),ta=()=>{let e=re().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},na=()=>{let t=ta();return t===null?[]:[...Xi().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))},ra=new Set([`start`,`stop`,`fork`,`compact`]),[ia,aa]=v([]),[oa,sa]=v(null),[ca,la]=v(-1),ua=()=>{let e=re();if(!e.startsWith(`/`)||e.includes(`
|
|
23
23
|
`))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[2]??``).trim();if(!r&&n!==`skill`){let e=Yi.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&ra.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=ia().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[]},da,fa,pa,ma=!1;function ha(e){if(!fa){fa=document.createElement(`div`),fa.setAttribute(`aria-hidden`,`true`);let e=fa.style;e.position=`absolute`,e.visibility=`hidden`,e.pointerEvents=`none`,e.top=`0`,e.left=`-9999px`,e.whiteSpace=`pre-wrap`,e.overflowWrap=`anywhere`,e.wordBreak=`break-word`,fa.dataset.mirror=``}let t=getComputedStyle(e);for(let e of[`font-family`,`font-size`,`font-weight`,`line-height`,`letter-spacing`,`padding-top`,`padding-bottom`,`padding-left`,`padding-right`,`border-top-width`,`border-bottom-width`,`box-sizing`])fa.style.setProperty(e,t.getPropertyValue(e));if(fa.style.width=`${e.clientWidth}px`,fa.setAttribute(`data-mirror-text`,e.value.endsWith(`
|
|
24
24
|
`)?`${e.value} `:e.value),pa||(pa=document.createElement(`div`),pa.setAttribute(`aria-hidden`,`true`),pa.style.cssText=`position:absolute;left:-9999px;top:0;pointer-events:none`,document.body.appendChild(pa)),fa.parentElement!==pa&&pa.appendChild(fa),!ma){let e=document.createElement(`style`);e.textContent=`[data-mirror]::after{content:attr(data-mirror-text);white-space:pre-wrap;display:block}`,document.head.appendChild(e),ma=!0}return fa.scrollHeight}let ga=()=>{if(!da)return;let e=yt();if(!da.value&&!e){da.style.height=``;return}let t=ha(da),n=e?-1:sn(t,360);da.style.height=n===-1?``:`${n}px`},_a,va=null,ya,ba=null,xa=0,Sa=240,Ca=4,wa;b(()=>{let e=re();da&&Zt(lh)&&(Qt(da.value,e)&&(da.value=e),ga())}),ee(()=>{let e=0,t=()=>{e||=requestAnimationFrame(()=>{e=0,ga()})};window.addEventListener(`resize`,t),C(()=>{window.removeEventListener(`resize`,t),e&&cancelAnimationFrame(e)})});let[Ta,K]=v([]),Ea=e=>{let t=Array.from(e).filter(e=>e.type.startsWith(`image/`));for(let e of t){if(e.size>8e6){Q(`"${e.name}" is over 8 MB — skipped`);continue}let t=new FileReader;t.onload=()=>{K(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},Da=async(e,t)=>{let r=t??n();if(!r)return;let i=Ta();try{let t=await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0,...i.length?{images:i}:{}})});Nn(jn(),[...kn(),{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now(),promptId:t.promptId,...i.length?{images:i.map(e=>e.url)}:{}}]),K([]),yt()&&bt(!1),ga(),Ct()&&requestAnimationFrame(()=>{Ct()&&ri()})}catch(t){D(e),console.error(`send failed:`,t)}},Oa=async t=>{t.preventDefault();let r=n(),i=re().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=Xi().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:$i()?`fork`:`none`})})).id}${$i()?` (forked context)`:``}`),vr(),D(``)}else if(s){if(!a){Q(`usage: @${r} <message>`);return}await $(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),Q(`→ delivered to @${r}`),D(``)}else{Q(`unknown @${r} — personas: ${Xi().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}}else if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim();if(t===`goal`&&!n){D(`/goal `);return}if(t===`skill`&&!n){D(`/skill `);return}D(``);try{await ka(t,n)}catch(e){throw D(re()?`${i}\n${re()}`:i),e}}else D(``),await Da(i)}},ka=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(vr);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await si(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 Da(`[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}`)}},Aa,ja=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!Aa)return;let e=Math.min(ja,Aa.scrollHeight);Math.abs(Aa.scrollTop-e)>1&&(Aa.scrollTop=e)})})});let Ma=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(vr),Na=async()=>{let i=n();if(!i)return;let a=new Set([i,...Et(e(),i).map(e=>e.id)]),o=a.size-1;if(!confirm(`archive agent ${i}?\n\n`+(o>0?`Its ${o} sub-agent${o===1?``:`s`} will be archived too.\n\n`:``)+`They stop running and leave the list, but the config and full session history are KEPT — restore any of them from ⚙ settings → archive.`))return;await $(`/api/agents/${i}/archive`,{method:`POST`}).catch(()=>{}),t(e().filter(e=>!a.has(e.id))),p(!0);let s=_u(e(),a);s?si(s.id):(r(null),h([]))},Pa=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),vr())},Fa=()=>$(`/api/agents/${z().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await p(!0),await si(z().id)}),[Ia,La]=v(``),[Ra,za]=v(``),[Ba,Va]=v(!1),[Ha,Ua]=v(!0),Wa=``;b(()=>{let e=n();e&&(z()?.goal,e!==Wa&&(Wa=e,Va(!1),La(``),za(``)))});let Ga=async e=>{if(e.preventDefault(),n()&&Ia().trim())try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:Ia(),notify:Ha(),...Ra().trim()?{verify:Ra()}:{}})}),La(``),za(``),Va(!1),vr()}catch(e){Q(`goal save failed: ${e.message}`)}};return[j(N,{get when(){return or()},get children(){var e=wu();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}}),j(N,{get when(){return le()},children:e=>(()=>{var t=id(),n=t.firstChild;return y(t=>{var r=e(),i=ce.map(t=>`${e()}?w=${t} ${t}w`).join(`, `);return r!==t.e&&I(n,`src`,t.e=r),i!==t.t&&I(n,`srcset`,t.t=i),t},{e:void 0,t:void 0}),t})()}),(()=>{var t=$u(),r=t.firstChild,i=r.firstChild,a=i.nextSibling.firstChild,o=a.firstChild;o.firstChild;var s=a.nextSibling,c=s.firstChild.firstChild.nextSibling;c.firstChild;var l=c.nextSibling,d=s.nextSibling,f=r.nextSibling,p=f.nextSibling,g=p.firstChild;g.firstChild,R(t,j(N,{get when(){return P(()=>!!me())()&&Me()},get children(){var e=Tu();return e.$$click=Pe,e}}),r),R(r,j(N,{get when(){return me()},get children(){var e=Eu(),t=e.firstChild.nextSibling;return t.$$click=Pe,e}}),i),R(i,j(M,{get each(){return Rr()},children:t=>[j(N,{get when(){return P(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=od(),n=e.firstChild;return e.$$click=()=>Fr(`ws:${t.wsHeader}`,Ir(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),R(n,()=>t.wsCollapsedGroup?`▸`:`▾`),R(e,()=>Ir(t.wsHeader),null),R(e,j(N,{get when(){return(Lr().get(t.wsHeader)??0)>1||t.wsCollapsedGroup},get children(){var e=ad();return R(e,()=>Lr().get(t.wsHeader)??0),e}}),null),y(()=>I(e,`title`,t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${V(t.wsHeader)} hidden). Click to show.`:(Lr().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${V(t.wsHeader)} in this directory`:t.wsHeader||``)),e}}),j(N,{get when(){return P(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=dd(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>si(t.a.id),R(r,j(N,{get when(){return wt({isSub:!!t.a.parent,collapsed:t.chatCollapsedGroup===!0,hasChildren:e().some(e=>e.parent===t.a.id)})},get fallback(){return fd()},get children(){return(()=>{let e=!t.a.parent,n=e&&Nr().has(`chat:${t.a.id}`)||Or(t.a.id);return(()=>{var r=pd();return r.$$click=r=>{if(r.stopPropagation(),e){if(n){if(!wr().has(t.a.id)){let e=new Set(wr());e.add(t.a.id),Tr(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}if(Er().has(t.a.id)){let e=new Set(Er());e.delete(t.a.id),Dr(e),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...e]))}}else if(wr().has(t.a.id)){let e=new Set(wr());e.delete(t.a.id),Tr(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}Fr(`chat:${t.a.id}`,t.a.id,n)}else kr(t.a.id)},R(r,n?`▸`:`▾`),y(()=>I(r,`title`,e?n?`show ${t.a.id}`:`hide ${t.a.id} and its sub-agents`:n?`expand sub-agents`:`collapse sub-agents`)),r})()})()}}),i),R(a,()=>t.a.sessionTitle??u().get(t.a.session??``)??t.a.id),R(r,(()=>{var e=P(()=>!!t.a.workspaceMissing);return()=>e()?md():null})(),null),R(r,j(N,{get when(){return Un(t.a.id)>0},get children(){var e=sd();return e.firstChild,R(e,()=>Un(t.a.id),null),y(()=>I(e,`title`,`${Un(t.a.id)} unread notification${Un(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),R(r,j(N,{get when(){return Or(t.a.id)||t.chatCollapsedGroup===!0&&Nr().has(`chat:${t.a.id}`)},get children(){return(()=>{let n=Et(e(),t.a.id),r=n.filter(e=>e.live??(e.status===`running`||e.status===`waiting`||e.status===`needs_operator`)).length;return n.length>0?(()=>{var e=hd();return e.firstChild,L(e,`subcount`+(r>0?` live`:``)),R(e,()=>n.length,null),R(e,r>0?` · ▶${r}`:``,null),y(()=>I(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),R(r,j(N,{get when(){return t.a.parent},get children(){return cd()}}),null),R(r,j(N,{get when(){return Cr(t.a.id).length>0},get children(){var e=ld();return y(()=>I(e,`title`,Cr(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
|
|
25
|
-
`))),e}}),null),R(r,j(N,{get when(){return t.a.goal.status===`done`},get children(){return ud()}}),null),y(e=>{var o=`agent-item`+(t.a.id===n()?` sel`:``)+(t.depth>0?` sub-row`:``)+(t.chatCollapsedGroup?` collapsed`:``),s=t.depth>0?`padding-left:${10+t.depth*14}px`:``,c=t.a.parent?(()=>{let e=Tt(t.a.id,Xi().map(e=>e.key));return e?`sub-agent of @${t.a.parent} — "${e}"`:`sub-agent of @${t.a.parent}`})():void 0,l=`dot ${t.a.status}`,d=t.a.status===`needs_operator`?`waiting for your answer`:t.a.status===`waiting`?`waiting on its own work — resumes by itself`:t.a.status,f=t.a.workspaceMissing?` ghost`:``,p=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:t.a.sessionTitle??u().get(t.a.session??``)?`${t.a.sessionTitle??u().get(t.a.session??``)} — ${t.a.id}`:t.a.id;return o!==e.e&&L(r,e.e=o),e.t=Ee(r,s,e.t),c!==e.a&&I(r,`title`,e.a=c),l!==e.o&&L(i,e.o=l),d!==e.i&&I(i,`title`,e.i=d),f!==e.n&&L(a,e.n=f),p!==e.s&&I(a,`title`,e.s=p),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),r}})]})),o.$$click=e=>{e.stopPropagation(),zn(!Rn()),Rn()||Fn(e=>e.map(e=>({...e,read:!0})))},R(o,j(N,{get when(){return Bn()>0},get children(){var e=Du();return R(e,Bn),e}}),null),R(a,j(
|
|
26
|
-
`)}`)),e}}),o),R(o,()=>z().model,s),R(o,()=>z().session,c),R(o,()=>z().branch,l),R(o,()=>z().stats.turns,u),R(o,()=>z().stats.toolCalls,d),p.$$click=()=>(B()?Ma(`/stop`):Ma(`/start`))(),R(p,()=>B()?`■ stop`:`▶ start`),R(f,j(N,{get when(){return e().some(e=>e.parent===n())},get children(){return j(Nh,{icon:`⏹`,title:`stop every sub-agent this agent spawned (descendants included)`,onClick:Pa})}}),m),R(f,j(Nh,{icon:`🗄`,title:`archive this agent — reversible: it leaves the list but keeps its config and history (restore in ⚙ settings → archive)`,onClick:Na}),null),R(f,j(Nh,{icon:`⑂`,title:`fork: branch off the conversation here — try things without disturbing the main line`,onClick:Fa}),null),R(f,j(Nh,{icon:`⌨`,title:`terminal (t)`,onClick:Ci}),null),R(f,j(Nh,{icon:`▤`,title:`toggle details panel (d)`,get active(){return we()},onClick:Ae}),null),y(e=>{var t=`badge ${z().status}`,n=z().statusReason&&!/^(round complete|prompt|api start|goal set|created via web|start)$/.test(z().statusReason)?`${z().status} — ${z().statusReason}`:void 0,r=`${z().model} · ${z().session}/${z().branch} · turns ${z().stats.turns} · tools ${z().stats.toolCalls}`,i=`runbtn`+(B()?` danger`:``),s=B()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&L(a,e.e=t),n!==e.t&&I(a,`title`,e.t=n),r!==e.a&&I(o,`title`,e.a=r),i!==e.o&&L(p,e.o=i),s!==e.i&&I(p,`title`,e.i=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),t})(),(()=>{var e=zu();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r={top:t.scrollTop,height:t.scrollHeight,viewport:t.clientHeight},i=nn(r,va,ya,wa);i===`layout`&&!Ct()&&Ca>0&&Math.abs(r.height-(ya??r.height))>1&&(Ca--,xe(t,ba)),va=null,ya=r.height,wa=r.viewport,Ut(r);let a=Ct(),o=performance.now();o-xa>100&&(xa=o,ba=F(t));let s=an(a,i,r);s!==a&&At(s),i===`reader`&&(Ca=4),s&&i!==`reader`?(jt()&&Mt(0),Hn(),rn(s,r)&&en(r)>0&&ri()):s&&tn(r)&&(jt()&&Mt(0),Hn()),r.top<=4&&n()&&!Ur()&&!qr()&&m().length>0&&$r()}),Oe(e=>Ce(e),e),R(e,j(N,{get when(){return Wt()},children:e=>(()=>{var t=_d();return t.firstChild,R(t,(()=>{var t=P(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Ah(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),R(e,j(N,{get when(){return P(()=>!!qr())()&&er().length>0},get children(){return Nu()}}),null),R(e,j(N,{get when(){return Ur()},get children(){return Pu()}}),null),R(e,j(N,{get when(){return er().length>0},get fallback(){return P(()=>!!Gr())()?vd():yd()},get children(){return[j(M,{get each(){return er()},children:e=>j(Th,{e,prev:()=>nr(e,-1),next:()=>nr(e,1),get showBranch(){return w().length>1},res:()=>Jn().resFor.get(e.id),get orphan(){return Jn().orphanCalls.has(e.id)},onOption:e=>void Da(e),answeredIds:$n,onAnswered:Zn,get agentActive(){return P(()=>!!Tn())()&&Je(e)},onResize:()=>{Ct()&&ri()},get onCancel(){return e.data?.source===`user`&&e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);D(re()?`${n}\n\n${re()}`:n),Nn(jn(),kn().filter(e=>e.promptId!==t)),Q(`message withdrawn — draft restored`)}).catch(()=>Q(`withdraw failed — it may have already been sent`))}:void 0},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`&&!(e.data?.pending&&e.data?.sent!==!0)&&!e.data?.cancelled&&!B()?()=>Dn({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),j(N,{get when(){return P(()=>!!Tn())()&&un()},get children(){var e=Ru(),t=e.firstChild.nextSibling;return t.firstChild,R(t,j(N,{get when(){return Sn().trim()!==``},get children(){var e=Fu(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return R(t,j(xh,{get startedAt(){return bn()}}),null),Oe(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{Sn(),t&&(e.scrollTop=e.scrollHeight)})},n),R(n,Sn),e}}),null),R(t,j(N,{get when(){return fn()},get fallback(){return bd()},get children(){return j(N,{get when(){return qt()},get fallback(){return(()=>{var e=Lu();return y(()=>e.innerHTML=Ie(fn()+`▍`)),e})()},get children(){return[Iu(),(()=>{var e=Lu();return y(()=>e.innerHTML=Ie($t()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),j(N,{get when(){return xi()},get children(){var t=Wu(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Pi(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Ni()))},n.$$pointerdown=Ki,R(i,j(M,{get each(){return G()},children:(e,t)=>(()=>{var n=xd(),r=n.firstChild.nextSibling;return n.$$click=()=>Ri(t()),R(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Vi(t())},y(r=>{var i=`termtab`+(ji()===0&&Ti()===t()?` active`:``)+(ki()&&ji()===1&&Di()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&L(n,r.e=i),a!==r.t&&I(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),R(i,j(Nh,{icon:`+`,title:`new shell in this workspace`,onClick:zi}),null),R(o,(()=>{var t=P(()=>!!Li());return()=>t()?e().find(e=>e.id===Li().agentId)?.workspace.split(`/`).filter(Boolean).pop():z()?.workspace})()),R(a,j(Nh,{icon:`◫`,get title(){return ki()?`single pane`:`split panes (50/50)`},onClick:qi}),null),R(a,j(Nh,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:Ci}),null);var l=Ji(0);return typeof l==`function`&&Oe(l,c),c.$$pointerdown=()=>Mi(0),R(c,j(N,{get when(){return Ti()<0||Ti()>=G().length},get children(){return Bu()}})),R(s,j(N,{get when(){return ki()},get children(){return[Vu(),(()=>{var e=Uu(),t=Ji(1);return typeof t==`function`&&Oe(t,e),e.$$pointerdown=()=>Mi(1),R(e,j(N,{get when(){return Di()<0||Di()>=G().length},get children(){return Hu()}})),y(()=>e.classList.toggle(`focused`,ji()===1)),e})()]}}),null),y(e=>{var n={height:`${Ni()}px`},r=!!ki(),i=ji()===0;return e.e=Ee(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=Zu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling;return R(e,j(N,{get when(){return P(()=>Nt()>32)()&&!Ct()},get children(){var e=Gu();return e.firstChild,e.$$click=()=>{ii(!0),Hn()},R(e,(()=>{var e=P(()=>jt()>0);return()=>e()?`${jt()} new message${jt()>1?`s`:``}`:`jump to present`})(),null),e}}),t),R(e,j(N,{get when(){return ua().length>0},get children(){var e=Ku();return R(e,j(M,{get each(){return ua()},children:(e,t)=>(()=>{var n=Sd(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{D(e.insert),la(-1)},R(r,()=>e.insert.trim()),R(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===ca()?` active`:``),a=e.title;return i!==r.e&&L(n,r.e=i),a!==r.t&&I(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),R(e,j(N,{get when(){return na().length>0},get children(){var e=Ku();return R(e,j(M,{get each(){return na()},children:e=>(()=>{var t=Cd(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{D(`@${e.key} `),la(-1)},R(n,()=>e.key,null),R(r,()=>e.label),y(()=>I(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Oa),R(t,j(N,{get when(){return Ta().length>0},get children(){var e=qu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,R(e,j(M,{get each(){return Ta()},children:(e,t)=>(()=>{var n=wd(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>K(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&I(n,`title`,t.e=i),a!==t.t&&I(r,`src`,t.t=a),o!==t.a&&I(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),R(t,()=>Ta().length,n),R(t,()=>Ta().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=ua();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),la(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),la(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&ca()>=0&&!lh?(e.preventDefault(),D(t[ca()].insert),la(-1)):e.key===`Escape`&&t.length>0?la(-1):e.key===`Enter`&&!e.shiftKey&&!lh&&!yt()&&(e.preventDefault(),Oa(e))},n.$$input=e=>{D(e.currentTarget.value),la(0),ga()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),Ea(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{lh=!1}),D(da?.value??``)}),n.addEventListener(`compositionstart`,()=>{lh=!0}),Oe(e=>{da=e,e.value=re()},n),R(t,j(N,{get when(){return P(()=>!!re().startsWith(`@`))()&&re().includes(` `)},get children(){var e=Ju(),t=e.firstChild;return t.addEventListener(`change`,e=>ea(e.currentTarget.checked)),y(()=>t.checked=$i()),e}}),r),r.$$click=()=>{let e=!yt();bt(e),requestAnimationFrame(()=>ga())},R(r,()=>yt()?`⤡`:`⤢`),R(t,j(Nh,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),R(t,j(N,{get when(){return Ta().length},get children(){var e=Yu();return e.firstChild,R(e,()=>Ta().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&Ea(e.currentTarget.files),e.currentTarget.value=``}),R(e,j(N,{get when(){return oh()},get children(){var e=Xu();return R(e,oh),e}}),null),y(t=>{var i=`composer`+(yt()?` maximized`:``),a=`message #${z().id} — / for commands · paste or 📎 to attach images`,o=yt()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&L(e,t.e=i),a!==t.t&&I(n,`placeholder`,t.t=a),o!==t.a&&I(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()]}})),R(t,j(N,{get when(){return P(()=>!!me())()&&we()},get children(){var e=Qu();return e.$$click=()=>ke(!1),e}}),p),p.addEventListener(`scroll`,e=>{ja=e.currentTarget.scrollTop});var v=Aa;return typeof v==`function`?Oe(v,p):Aa=p,R(g,j(Nh,{icon:`✕`,title:`close details panel (esc)`,onClick:je}),null),R(p,j(N,{get when(){return z()?.id},keyed:!0,fallback:null,children:t=>[j(N,{get when(){return z().id},keyed:!0,fallback:null,children:e=>j(qh,{agentId:e,get workspace(){return z().workspace}})}),Td(),(()=>{var t=Od(),r=t.firstChild,i=r.nextSibling,a=i.firstChild,o=a.nextSibling,s=i.nextSibling,c=s.firstChild,l=s.nextSibling;return l.firstChild,r.addEventListener(`change`,t=>{let r=t.currentTarget.value;vt=!0,it(r),ot(Jt(O().providers,r,e().find(e=>e.id===n()))),ft(r)}),R(r,j(M,{get each(){return dt()},children:e=>(()=>{var t=Yd();return t.value=e,R(t,e,null),R(t,()=>e===O().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>ot(e.currentTarget.value),R(o,j(M,{get each(){return lt()},children:e=>(()=>{var t=Yd();return y(()=>t.value=e.id),t})()})),R(t,j(N,{get when(){return z().effortSupported},get children(){var e=Ed(),t=e.firstChild.nextSibling;return t.firstChild,t.addEventListener(`change`,e=>ct(e.currentTarget.value)),R(t,j(M,{get each(){return P(()=>!!z().effortOptions?.length)()?z().effortOptions:nh},children:e=>(()=>{var t=Yd();return t.value=e,R(t,e),t})()}),null),y(()=>t.value=st()),e}}),s),c.$$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:rt(),model:at().trim()||void 0,contextWindowTokens:lt().find(e=>e.id===(at().trim()||void 0))?.contextLength,...z().effortSupported?{reasoningEffort:st()}:{}})}),t.textContent=`✓ applied`,vr()}catch(e){alert(`apply failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},R(l,()=>z().model,null),R(l,j(N,{get when(){return lt().length},get children(){return[` · `,P(()=>lt().length),` models loaded`]}}),null),R(t,j(N,{get when(){return gt()},get children(){var e=Dd();return R(e,gt),e}}),null),y(()=>I(a,`placeholder`,Yt(O().providers,rt(),z(),Kt(z(),O().providers,O().defaultProvider)))),y(()=>r.value=rt()),y(()=>a.value=at()),t})(),(()=>{var e=kd(),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(vr)}),y(()=>t.checked=z().autoContinue??!0),e})(),(()=>{var e=jd();return e.firstChild,R(e,j(N,{get when(){return!!z().goal.text.trim()},get fallback(){return Xd()},get children(){var e=Ad();return R(e,()=>z().goal.status),y(()=>L(e,`badge ${z().goal.status===`active`?`running`:z().goal.status}`)),e}}),null),e})(),(()=>{var e=Md();return e.firstChild,R(e,j(M,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Zd();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(vr)},I(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`),R(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(z().goal.text.trim()&&z().goal.status===e?` on ${e}`:``),i=!!z().goal.text.trim()&&z().goal.status===e;return r!==n.e&&L(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),j(N,{get when(){return z().goal.text},get fallback(){return Qd()},get children(){return[(()=>{var e=Nd(),t=e.firstChild;return y(()=>t.innerHTML=Ie(String(z().goal.text))),e})(),j(N,{get when(){return z().goal.verify},get children(){var e=Pd(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Ie(String(z().goal.verify))),e}}),j(N,{get when(){return z().goal.audit},children:e=>(()=>{var t=$d(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return R(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),R(r,()=>kh(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=ht(e().feedback)?Ie(`_the auditor returned a verdict with no detail_`):Ie(e().feedback);return r!==n.e&&L(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),(()=>{var e=Fd(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,Ga),t.$$input=e=>{La(e.currentTarget.value),Va(!0)},n.$$input=e=>{za(e.currentTarget.value),Va(!0)},r.addEventListener(`change`,e=>Ua(e.currentTarget.checked)),y(()=>t.value=Ia()),y(()=>n.value=Ra()),y(()=>r.checked=Ha()),e})(),(()=>{var e=Ld(),t=e.firstChild.nextSibling;return R(e,j(N,{get when(){return gr().total>0},get children(){var e=Id(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,R(e,()=>gr().done,t),R(e,()=>gr().total,n),y(t=>Ee(e,gr().done===gr().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),j(N,{get when(){return gr().total>0},get children(){var e=Rd(),t=e.firstChild;return y(e=>{var n=`barfill `+(gr().done===gr().total?``:`warn`),r=`${Math.round(gr().done/gr().total*100)}%`;return n!==e.e&&L(t,e.e=n),r!==e.t&&De(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),j(Kh,{get draft(){return cr()},get preview(){return ur()},onDraft:e=>{lr(e),pr(!0)}}),(()=>{var e=zd(),t=e.firstChild,n=t.nextSibling;return R(e,j(Nh,{get icon(){return ur()?`✎`:`👁`},get title(){return ur()?`edit markdown`:`rendered checklist`},onClick:()=>dr(!ur())}),t),n.$$click=hr,e})(),Bd(),j(N,{get when(){return z().latestProgress},get fallback(){return ef()},children:e=>(()=>{var t=of(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return R(t,j(N,{get when(){return e().recent},get children(){var t=tf(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=th(e().recent)),t}}),i),R(t,j(N,{get when(){return e().problems},get children(){var t=nf(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=th(e().problems)),t}}),i),R(t,j(N,{get when(){return e().next},get children(){var t=rf(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=th(e().next)),t}}),i),R(t,j(N,{get when(){return e().goalStatus},get children(){var t=af(),n=t.firstChild.nextSibling;return R(n,()=>e().goalStatus),t}}),i),R(i,()=>kh(e().ts)),y(()=>r.innerHTML=th(e().doing)),t})()}),Vd(),(()=>{var e=Wd(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling,c=s.firstChild.nextSibling,l=s.nextSibling,u=l.firstChild.nextSibling,d=l.nextSibling,f=d.firstChild.nextSibling;return R(e,j(N,{get when(){return z().ctx},keyed:!0,get fallback(){return sf()},children:e=>{let t=x(()=>{let t=e,n=lt().find(e=>e.id===z().model),r=t.window||n?.contextLength||0,i=r?Math.min(999,t.usedTokens/r*100):0;return{usedTokens:t.usedTokens,compactAt:t.compactAt,compacting:t.compacting,window:t.window,effectiveWindow:r,pct:i,cls:r?i>=85?`crit`:i>=70?`warn`:`ok`:``,derivedBudget:r?Math.round(r*.75):0,usingDerived:t.compactAtIsManual!==!0}}),r=()=>t(),i=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)};return(()=>{var e=df(),t=e.firstChild,a=t.firstChild.nextSibling,o=a.firstChild.nextSibling;o.nextSibling;var s=t.nextSibling,c=s.firstChild.nextSibling,l=c.firstChild,u=c.nextSibling,d=s.nextSibling,f=d.firstChild.firstChild;return R(a,()=>Ah(r().usedTokens),o),R(t,j(N,{get when(){return r().effectiveWindow},get children(){var e=cf(),t=e.firstChild;return R(e,()=>i(r().pct),t),R(e,()=>Ah(r().effectiveWindow),null),y(()=>L(e,`pill ${r().cls}`)),e}}),null),R(e,j(N,{get when(){return r().effectiveWindow},get children(){var e=lf(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&L(t,e.e=n),i!==e.t&&De(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),R(c,()=>Ah(r().usingDerived?r().derivedBudget:r().compactAt),l),R(u,()=>r().usingDerived?`75% of window`:`manual`),R(e,j(N,{get when(){return Wt()||r().compacting},get children(){var e=uf(),t=e.firstChild.nextSibling.nextSibling;return R(t,()=>Wt()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(vr)}),y(()=>f.checked=z().autoCompact!==!1),e})()}}),t),R(i,()=>Ah(z().stats.inputTokens)),R(o,()=>Ah(z().stats.outputTokens)),R(c,()=>z().stats.turns),R(u,()=>z().stats.toolCalls),R(f,()=>z().stats.compactions??0),R(t,j(N,{get when(){return(z().stats.costUsd??0)>0},get children(){var e=Hd(),t=e.firstChild.nextSibling;return t.firstChild,R(t,()=>jh(z().stats.costUsd??0),null),y(()=>I(e,`title`,`≈ ${(z().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),R(t,j(N,{get when(){return(z().stats.cachedInputTokens??0)>0},get children(){var e=Ud(),t=e.firstChild.nextSibling,n=t.firstChild;return R(t,()=>Math.round(z().stats.cachedInputTokens/Math.max(1,z().stats.inputTokens)*100),n),y(()=>I(e,`title`,`${Ah(z().stats.cachedInputTokens)} input tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),y(()=>I(d,`title`,`how many times old turns were summarized into notes to make room. ${z().stats.compactions?`Each one keeps the recent stretch verbatim.`:`Not yet — the context has fit so far.`}`)),e})(),(()=>{var e=Kd();return e.firstChild.nextSibling,R(e,j(N,{get when(){return zr()},get children(){var e=Gd(),t=e.firstChild.nextSibling;return R(t,zr),e}}),null),e})(),j(M,{get each(){return w()},children:e=>(()=>{var t=ff(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=zr()===e.branch?null:e.branch,r=t!==zr();Br(t),n()&&(r&&(Yr++,h([]),_(0),Jr(!1)),ei(n()))},R(r,()=>e.branch,null),R(r,()=>e.branch===z().branch?` (current)`:``,null),R(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===z().branch||e.branch===zr()?` cur`:``),i=e.branch===zr()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),(()=>{var e=Jd();return e.firstChild,R(e,j(N,{get when(){return br().length>0},get children(){var e=qd(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>br().length,t),e}}),null),e})(),j(N,{get when(){return br().length>0},get fallback(){return pf()},get children(){return j(M,{get each(){return br()},children:e=>(()=>{var t=hf(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>si(e.agent),R(i,()=>e.id),R(a,()=>e.agent,null),R(r,j(N,{get when(){return e.forked},get children(){return mf()}}),null),R(o,()=>e.schedule,s),R(o,(()=>{var t=P(()=>!!e.next);return()=>t()?kh(e.next):`—`})(),null),R(o,(()=>{var t=P(()=>!!e.last);return()=>t()?` · last ${kh(e.last)}`:` · never ran`})(),null),R(c,()=>Mh(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Mh(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&L(t,r.e=i),a!==r.t&&I(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var n=`layout`+(we()?``:` right-hidden`)+(Me()?` left-open`:``),i=`sidebar`+(Me()?` open`:``),a=`iconbtn notifbtn`+(Bn()>0?` has-unread`:``),s=Bn()>0?`${Bn()} unread notifications`:`notifications`,c=`conn`+(ci()?` ok`:``),u=ci()?`live (websocket)`:`reconnecting…`,d={"--termh":`${Ni()}px`},m=`rightbar`+(we()?` open`:``);return n!==e.e&&L(t,e.e=n),i!==e.t&&L(r,e.t=i),a!==e.a&&L(o,e.a=a),s!==e.o&&I(o,`title`,e.o=s),c!==e.i&&L(l,e.i=c),u!==e.n&&I(l,`title`,e.n=u),e.s=Ee(f,d,e.s),m!==e.h&&L(p,e.h=m),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),t})(),j(N,{get when(){return Rn()},get children(){return[(()=>{var e=ed();return e.$$click=()=>zn(!1),e})(),(()=>{var t=rd(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return R(r,j(N,{get when(){return Pn().length>0},get children(){var e=td();return e.$$click=()=>Fn([]),e}}),i),i.$$click=()=>zn(!1),R(t,j(N,{get when(){return Pn().length>0},get fallback(){return gf()},get children(){var t=nd();return R(t,j(M,{get each(){return Pn()},children:t=>(()=>{var r=vf(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{Fn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&si(t.agentId),zn(!1),t.eventId&&setTimeout(()=>qn(t.eventId),n()===t.agentId?60:350)},R(i,(()=>{var e=P(()=>t.kind===`finish`);return()=>e()?`✅`:P(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),R(a,()=>t.title),R(o,()=>kh(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),Fn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},R(s,()=>t.read?`✓`:`○`),R(r,j(N,{get when(){return t.body},get children(){var e=_f();return R(e,()=>Oh(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&L(r,e.e=n),i!==e.t&&I(r,`title`,e.t=i),a!==e.a&&I(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),j(N,{get when(){return oe()},get children(){return j(Ih,{get providers(){return Object.keys(O().providers??{})},onClose:()=>se(!1),onCreated:e=>{se(!1),vr(),si(e)}})}}),j(N,{get when(){return ue()},get children(){return j(Zh,{get cfg(){return O()},onClose:()=>A(!1),announcedOAuth:fe,get skills(){return ia()},get hasSelection(){return!!n()},get agentId(){return n()},get features(){return oa()},onSaved:()=>{ar(),Sr()},theme:{themes:Ge,activeId:Fe,paintedId:k,auto:Re,setAuto:ze,dark:Qe,setDark:$e,light:Be,setLight:Ve,setThemes:qe,setActive:Le}})}}),j(N,{get when(){return En()},fallback:null,children:e=>{let t=()=>m().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,m().length-t()-1),[i,a]=v(r()>0?`summarize`:`discard`);return j(Fh,{title:`edit prompt — forks the conversation`,onClose:()=>Dn(null),get children(){var t=bf(),o=t.firstChild,s=o.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:i()})}),Dn(null),vr();let t=n();t&&await si(t)}catch(e){alert(`edit failed: ${e.message}`)}}),R(t,j(N,{get when(){return r()>0},get children(){var e=yf(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return R(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>Dn(null),y(()=>o.value=e().text),t}})}})]}function bh(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=()=>Ve(Math.max(0,n()-t));return e.inline?(()=>{var t=xf();return t.firstChild,R(t,i,null),R(t,(()=>{var t=P(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=Sf(),t=e.firstChild;return R(e,i,t),e})()}function xh(e){let[t,n]=v(Date.now());return ee(()=>{let e=setInterval(()=>n(Date.now()),500);C(()=>clearInterval(e))}),e.startedAt?(()=>{var n=Cf();return R(n,()=>Ve(Math.max(0,t()-e.startedAt))),n})():null}function Sh(e){let[t,n]=v(``),r=0;return b(()=>{let t=e.text,i=e.lang,a=++r;n(``),i&&t.trim()&&(async()=>{try{let{highlightLangChunks:e}=await Cu(async()=>{let{highlightLangChunks:e}=await import(`./shiki-DQxXtlWj.js`);return{highlightLangChunks:e}},[]),o=``;for await(let s of e(i,t)){if(r!==a)return;o+=s,n(o)}}catch{r===a&&n(``)}})()}),C(()=>{r++}),j(N,{get when(){return!!t()},get fallback(){return(()=>{var t=Tf();return R(t,()=>e.text),t})()},get children(){var e=wf();return y(()=>e.innerHTML=t()),e}})}function Ch(e){let t=e.e,n=Nt(e.prev,t),r=()=>e.res?.(),i=()=>!e.agentActive&&!r(),a=t.data??{},o=String(a.name??`tool`),s=()=>String(r()?.data?.result??``),c=e=>String(a.args?.[e]??``),l=()=>o===`bash`?c(`command`):c(`path`)||JSON.stringify(a.args??{},null,1),u=()=>o===`bash`?Number(c(`timeout_ms`))||void 0:o===`wait_children`?Number(c(`timeout_ms`))||3e5:Number(c(`timeout_ms`))||void 0,d=(e,t=1500,n)=>j(Sh,{get text(){return Oh(e,t)},lang:n}),f=(e=2e3)=>j(Sh,{get text(){return Oh(JSON.stringify(a.args??{},null,1),e)},lang:`json`}),p=(e=4e3)=>(()=>{let t=r();return t?[P(()=>d(s(),e,bt(s()))),(()=>{var e=Ef();return R(e,()=>Ve(t.data?.durationMs),null),R(e,()=>o===`bash`?Wt(Ut(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),R(e,j(Ph,{get text(){return s()}}),null),e})()]:Df()})(),m=x(()=>{r();let e=o,t=``,n=f(2e3);try{switch(o){case`bash`:{let i=c(`command`),o=a.args?.background===!0,l=o?String(s()).match(/job (bg\d+)/)?.[1]??``:``;e=(o?`⏳ `:`$ `)+Mh(i,96);let u=c(`timeout_ms`)?Number(c(`timeout_ms`)):void 0,f=r(),m=Ut(f?.data?.ok,f?String(f.data?.result??``):``);t=f?o?`background job${l?` ${l}`:``}${u?` · timeout ${Math.round(u/1e3)}s`:``}`:Gt({outcome:m,durationMs:f.data?.durationMs,timeoutMs:u,fmtDur:Ve}):null,n=[o?(()=>{var e=Of(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,R(t,l||`?`,n),R(e,l?[` · kill with `,kf()]:null,null),e})():null,P(()=>P(()=>i!==e.slice(2))()?d(i,800,`shellscript`):null),P(()=>p(6e3))];break}case`read_file`:{e=c(`path`)||`(no path)`;let r=[];c(`pattern`)&&r.push(`grep /${Mh(c(`pattern`),40)}/`),Number(a.args?.offset)<0?r.push(`last ${-Number(a.args.offset)} lines`):a.args?.offset&&r.push(`from L${a.args.offset}`),a.args?.limit&&r.push(`≤${a.args.limit} lines`),t=r.join(` · `),n=p(6e3);break}case`write_file`:{let i=String(a.args?.content??``);e=c(`path`)||`(no path)`,t=`${Ah(i.length)} bytes`,n=[P(()=>d(i,1500)),P(()=>P(()=>i.length>1500)()?(()=>{var e=Af(),t=e.firstChild;return R(e,()=>Ah(i.length),t),e})():null),P(()=>P(()=>!!r())()?(()=>{var e=Ef();return R(e,()=>Mh(s(),160)),e})():jf())];break}case`edit_file`:e=c(`path`)||`(no path)`,t=a.args?.replace_all===!0?`replace all`:`unique spot`,n=[(()=>{var e=Mf();return R(e,()=>Oh(`- `+c(`old_text`),900)),e})(),(()=>{var e=Nf();return R(e,()=>`+ `+Oh(c(`new_text`),900)),e})(),P(()=>P(()=>!!r())()?(()=>{var e=Pf(),t=e.firstChild;return R(e,()=>Mh(s(),120),t),R(e,()=>Ve(r().data?.durationMs),null),e})():Ff())];break;case`apply_patch`:{let t=c(`patch`).split(`
|
|
27
|
-
`).filter(e=>e&&!/^---$/.test(e.trim())),
|
|
28
|
-
`)[0]??``,140),null),R(e,()=>r().data?.ok===!1?` · FAILED`:``,null),e})():zf())];break}case`list_dir`:e=c(`path`)||`.`,n=p(4e3);break;case`read_url`:{let r=c(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=Mh(r,70),t=`web`,n=[(()=>{var e=Ef();return R(e,j(N,{get when(){return/^https?:/i.test(c(`url`))},get fallback(){return(()=>{var e=Vf();return R(e,()=>Mh(c(`url`),80)),e})()},get children(){var e=Bf();return y(()=>I(e,`href`,c(`url`))),e}})),e})(),P(()=>p(3e3))];break}case`bash_output`:{let r=c(`action`)||`read`;e=`bash_output ${c(`job_id`)||`(?)`}`,t=r,n=p(4e3);break}case`load_skill`:{e=`skill: ${c(`name`)}`;let t=s().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);n=r()?[(()=>{var e=Lu();return y(()=>e.innerHTML=Ie(t)),e})(),(()=>{var e=Ef();return R(e,()=>Ve(r().data?.durationMs)),e})()]:Hf();break}case`save_skill`:{e=`skill: ${c(`name`)}`,t=Mh(c(`description`),60);let i=Array.isArray(a.args?.files)?a.args.files.map(e=>e?.name).filter(Boolean):[];n=[P(()=>P(()=>!!i.length)()?(()=>{var e=Uf();return e.firstChild,R(e,()=>i.join(`, `),null),e})():null),P(()=>P(()=>!!r())()?(()=>{var e=Pf(),t=e.firstChild;return R(e,()=>Mh(s(),160),t),R(e,()=>Ve(r().data?.durationMs),null),e})():Wf())];break}default:e=o,t=r()?Ve(r().data?.durationMs):null,n=[P(()=>f(2e3)),P(()=>p(4e3))]}}catch{}return{label:e,hint:t,body:n,key:`${r()?.id??`none`}|${e}|${t??``}`}},void 0,{equals:(e,t)=>e.key===t.key});return(()=>{var a=Kf(),c=a.firstChild,d=c.firstChild,f=d.nextSibling,p=f.nextSibling;return a.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),R(d,()=>m().label),R(c,j(N,{get when(){return t.data?.actor},get children(){var e=Gf();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),f),R(f,(()=>{var e=P(()=>!!r());return()=>e()?m().hint||``:P(()=>!!i())()?`(result missed)`:P(()=>!!(o===`bash`||u()))()?j(bh,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return u()}}):`running…`})()),R(p,j(Ph,{get text(){return l()},label:`⧉ cmd`,title:`copy the ${o} arguments`}),null),R(p,j(N,{get when(){return r()},get children(){return j(Ph,{get text(){return s()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),R(a,()=>m().body,null),y(e=>{var t=`embed`+(n?` grouped`:``)+(r()?r().data?.ok===!1?` fail`:` done`:i()?` done`:` running`),s=`${o}${m().hint?` — `+m().hint:``}`;return t!==e.e&&L(a,e.e=t),s!==e.t&&I(a,`title`,e.t=s),e},{e:void 0,t:void 0}),a})()}function wh(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function Th(e){let t=e.e,n=dh(t),r=()=>Nt(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Nt(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=qf(),r=n.firstChild.nextSibling;return r.nextSibling,R(n,()=>String(e.fromBranch??`?`),r),R(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=_t(t.data??{});return(()=>{var t=Jf(),n=t.firstChild;return R(n,()=>e.label),R(t,j(N,{get when(){return e.hasCard},get children(){var t=Lf();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Ie(e.detail):Ie(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&L(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>L(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Yf(),n=e.firstChild.nextSibling;return n.nextSibling,R(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Xf(),n=e.firstChild;return R(e,()=>t.data.from,n),R(e,()=>t.data.to,null),R(e,(()=>{var e=P(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>L(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Zf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,R(n,()=>String(t.data?.failures),r),R(n,()=>String(t.data?.limit),i),R(a,()=>String(t.data?.lastTool),o),R(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>I(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Qf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(n,()=>String(t.data?.attempt),r),R(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Lf();return L(r,`divider-msg`+(e?` err`:``)),R(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>I(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=$f(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(e,()=>String(t.data?.tokensBefore??`?`),n),R(e,()=>String(t.data?.tokensAfter??`?`),r),R(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=ep(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(e,()=>String(t.data?.messages??`?`),n),R(e,()=>String(t.data?.tokensBefore??`?`),r),R(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=ap(),o=a.firstChild,s=o.nextSibling;return R(o,(()=>{var e=P(()=>!!r());return()=>e()?``:n.icon})()),R(s,(()=>{var e=P(()=>!!r());return()=>e()&&(()=>{var e=op();return y(()=>I(e,`title`,`${gh(t.ts)} · ${t.branch}`)),e})()})(),null),R(s,j(N,{get when(){return!r()},get children(){var r=ip(),i=r.firstChild,a=i.nextSibling;return R(i,()=>n.name),R(r,j(N,{get when(){return t.data?.actor},get children(){var e=Gf();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),a),R(a,(()=>{var e=P(()=>!!t.data?.pending);return()=>e()?`queued…`:P(()=>!!t.data?.cancelled)()?`withdrawn`:gh(t.ts)})()),R(r,j(N,{get when(){return e.showBranch},get children(){var e=tp();return R(e,()=>t.branch),e}}),null),R(r,j(N,{get when(){return e.onCancel},get children(){var t=np();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),R(r,j(N,{get when(){return t.type!==`tool_call`},get children(){return j(Ph,{get text(){return wh(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),R(r,j(N,{get when(){return e.onEdit},get children(){var t=rp();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>De(i,`color`,n.color)),r}}),null),R(s,j(Dh,{e:t,get prev(){return e.prev?.()},get res(){return e.res},get orphan(){return e.orphan},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get onAnswered(){return e.onAnswered},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var s=`msg`+(r()?` grouped`:``)+(i()?` next-grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),c=t.id,l=`avatar avghost`+(r()?` ghosted`:``),u=r()?`transparent`:n.color+`33`,d=r()?`1px solid transparent`:`1px solid ${n.color}66`,f=r()?`${gh(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&L(a,e.e=s),c!==e.t&&I(a,`data-eid`,e.t=c),l!==e.a&&L(o,e.a=l),u!==e.o&&De(o,`background`,e.o=u),d!==e.i&&De(o,`border`,e.i=d),f!==e.n&&I(o,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),a})()}function Eh(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=sp(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&I(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 Dh(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Lu();return y(()=>e.innerHTML=th(String(t.data.text??``))),e})(),j(N,{get when(){return e.length},get children(){var t=cp();return R(t,j(M,{each:e,children:e=>(()=>{var t=lp();return I(t,`src`,e),t})()})),t}})]}case`message`:return[j(N,{get when(){return P(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=up(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return R(n,(()=>{var e=P(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Ah(String(t.data.reasoning).length)} — truncated)`:``})(),null),R(r,()=>Oh(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Lu();return y(()=>e.innerHTML=th(String(t.data.content??``))),e})(),j(N,{get when(){return t.data.interrupted},get children(){return dp()}}),j(N,{get when(){return t.data.final},get children(){var e=fp(),n=e.firstChild;return R(e,j(Ph,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return j(Ch,{e:t,get prev(){return e.prev},get res(){return e.res},get orphan(){return e.orphan},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=mp(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return L(a,`embed `+(i?``:`fail`)),R(s,r===`bash`?`$ (bash, call evicted)`:r),R(o,j(Ph,{text:n}),null),R(c,()=>Oh(n,4e3)),R(l,()=>Ve(t.data.durationMs),null),R(l,()=>r===`bash`?Wt(Ut(t.data.ok,n)):i?``:` · FAILED`,null),R(a,j(N,{get when(){return e.orphan},get children(){return pp()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=gp(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return R(n,j(N,{get when(){return e.length},get children(){var t=hp();return t.firstChild,R(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=th(String(t.data?.decision??``)),r=th(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=()=>e.answeredIds?.().has(r)??!1;return(()=>{var a=yp(),o=a.firstChild.firstChild.nextSibling;return R(a,j(N,{get when(){return i()},get children(){return _p()}}),null),R(a,j(N,{get when(){return n.length>0},get children(){var a=vp();return R(a,j(M,{each:n,children:n=>(()=>{var a=bp();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},R(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),R(a,j(Eh,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=th(String(t.data?.question??``));return n!==e.e&&L(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=xp(),n=e.firstChild.firstChild.nextSibling;return R(e,j(N,{get when(){return t.data.goalStatus},get children(){var e=af(),n=e.firstChild.nextSibling;return R(n,()=>String(t.data.goalStatus)),e}}),null),R(e,j(N,{get when(){return t.data.recent},get children(){var e=tf(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=th(String(t.data.recent))),e}}),null),R(e,j(N,{get when(){return t.data.problems},get children(){var e=nf(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=th(String(t.data.problems))),e}}),null),R(e,j(N,{get when(){return t.data.next},get children(){var e=rf(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=th(String(t.data.next))),e}}),null),y(()=>n.innerHTML=th(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=Sp(),n=e.firstChild;return n.firstChild,R(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=wp(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,R(n,()=>String(t.data.mode??``),r),R(n,()=>Ah(Number(t.data.tokensBefore??0)),i),R(n,()=>Ah(Number(t.data.tokensAfter??0)),a),R(n,(()=>{var e=P(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),R(e,j(N,{get when(){return t.data.summary},get children(){return[Cp(),(()=>{var e=Lu();return y(()=>e.innerHTML=th(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Tp();return R(e,()=>Oh(JSON.stringify(t.data),200)),e})()}}function Oh(e,t){return e.length>t?e.slice(0,t)+` …`:e}function kh(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 Ah(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 jh(e){return e>=100?Math.round(e).toLocaleString():e>=10?e.toFixed(1):e>=1?e.toFixed(2):e>=.01?e.toFixed(3):e.toFixed(4)}function Mh(e,t){return Oh(e.replace(/\s+/g,` `).trim(),t)}function Nh(e){return(()=>{var t=Ep(),n=t.firstChild;return Te(t,`click`,e.onClick,!0),R(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),n.a=Ee(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Ph(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),At(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=Dp();return n.$$click=a,R(n,(()=>{var n=P(()=>!!t());return()=>n()?`✓`:P(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>I(n,`title`,e.title??`copy to clipboard`)),n})()}function Fh(e){return(()=>{var t=Op(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),R(r,()=>e.title),Te(i,`click`,e.onClose,!0),R(n,()=>e.children,null),t})()}function Ih(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 j(Fh,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Ap(),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,te=C.nextSibling.firstChild.nextSibling,T=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),R(b,j(M,{get each(){return r()},children:e=>(()=>{var n=jp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),R(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),R(w,j(M,{get each(){return e.providers},children:e=>(()=>{var t=Yd();return R(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),R(i,j(N,{get when(){return d()},get children(){var e=kp();return R(e,d),e}}),T),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>te.value=l()),i}})}var Lh=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Rh=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),zh=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Bh(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Vh(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 Vh(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Lh.has(t)?`image`:Rh.has(t)?`video`:zh.has(t)?`audio`:null}var Hh=new Map,Uh=e=>{let t=Hh.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Hh.set(e,t)),t};function Wh(e){let t=()=>e.palette;return(()=>{var n=Np(),r=n.firstChild,i=r.nextSibling,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.nextSibling,d=u.nextSibling,f=d.nextSibling,p=f.nextSibling;return R(n,j(N,{get when(){return e.backgroundImage},get children(){var t=Mp();return y(n=>De(t,`background-image`,e.backgroundImage)),t}}),r),y(e=>{var m=t().bgDark,h=t().bgDarkest,g=t().bgDarkest,_=t().bgMid,v=t().fg,y=t().acc,b=t().dim,x=t().acc,S=t().dim,ee=t().ok,C=t().warn,w=t().err;return m!==e.e&&De(n,`background`,e.e=m),h!==e.t&&De(r,`background`,e.t=h),g!==e.a&&De(i,`background`,e.a=g),_!==e.o&&De(a,`background`,e.o=_),v!==e.i&&De(o,`background`,e.i=v),y!==e.n&&De(s,`background`,e.n=y),b!==e.s&&De(c,`background`,e.s=b),x!==e.h&&De(l,`background`,e.h=x),S!==e.r&&De(u,`background`,e.r=S),ee!==e.d&&De(d,`background`,e.d=ee),C!==e.l&&De(f,`background`,e.l=C),w!==e.u&&De(p,`background`,e.u=w),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0}),n})()}function Gh(e){let[t,n]=v(e.themes().some(t=>t.id===e.activeId)?e.activeId:e.themes()[0]?.id??``),r=()=>{let n=e.themes();return n.find(e=>e.id===t())??n.find(t=>t.id===e.activeId)??n[0]},[i,a]=v({}),o,s=t=>{let n=r()?.id;if(!n)return;let i=e.themes().map(e=>e.id===n?t(e):e);e.onChange(i)},c=(e,t)=>{let n=bn(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.paintedId),r=uh.find(t=>t.key===e.paintedId),i=t??r??uh[0],a=getComputedStyle(document.documentElement),o={...un};for(let{key:e,cssVar:t}of cn){let n=bn(a.getPropertyValue(t));n&&(o[e]=n)}let s=_n(e.themes().map(e=>e.id).concat(uh.map(e=>e.key))),c={id:s,label:`${i.label}${t?``:` copy`}`.slice(0,40),mode:i.mode,palette:o,...t?.backgroundImage?{backgroundImage:t.backgroundImage,backgroundDim:t.backgroundDim,surfaceAlpha:t.surfaceAlpha}:{}};e.onChange([...e.themes(),c]),n(s),e.onPick(s)},u=async t=>{if(t){if(!/^image\//.test(t.type))Q(`that file is ${JSON.stringify(t.type||`unknown`)} — pick an image`);else{Q(`uploading ${t.name} (${Math.round(t.size/1024)}KB)…`);try{let n=await fetch(`/api/assets`,{method:`POST`,headers:{"content-type":t.type},body:t}).then(async e=>({ok:e.ok,body:await e.json().catch(()=>null)}));if(!n.ok||!n.body?.url){Q(n.body?.error??`upload failed`);return}s(e=>({...e,backgroundImage:n.body.url,backgroundImageBytes:n.body.bytes}));let i=r()?.id;i&&e.onPick(i),Q(`background image set`)}catch(e){Q(`upload failed: ${e.message}`)}}}};return(()=>{var d=Fp(),f=d.firstChild.nextSibling,p=f.firstChild;return p.$$click=l,R(f,j(N,{get when(){return e.themes().length>0},get children(){var r=Pp();return r.addEventListener(`change`,t=>{n(t.currentTarget.value),e.onPick(t.currentTarget.value)}),R(r,j(M,{get each(){return e.themes()},children:e=>(()=>{var t=Yd();return R(t,()=>e.label),y(()=>t.value=e.id),t})()})),y(()=>r.value=t()),r}}),null),R(d,j(N,{get when(){return P(()=>!!(r()&&e.themes().some(t=>t.id===e.activeId)))()?r():null},get fallback(){return(()=>{var t=Ip();return R(t,(()=>{var t=P(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,Lp(),` to start from the palette you are using.`]:[`the editor shows when one of your themes is ACTIVE — pick one under "your themes" above (or press `,Lp(),`).`]})()),t})()},children:t=>[(()=>{var e=Rp(),t=e.firstChild.firstChild.nextSibling;return t.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),y(()=>t.value=r().mode),e})(),(()=>{var e=zp();return R(e,j(M,{each:cn,children:e=>(()=>{var t=Gp(),n=t.firstChild,o=n.nextSibling,s=o.nextSibling;return n.$$input=t=>c(e.key,t.currentTarget.value),R(o,()=>e.label),s.addEventListener(`blur`,()=>a(t=>{let n={...t};return delete n[e.key],n})),s.$$input=t=>{let n=t.currentTarget.value;a(t=>({...t,[e.key]:n})),c(e.key,n)},I(s,`spellcheck`,!1),y(()=>I(t,`title`,e.cssVar)),y(()=>n.value=bn(r().palette[e.key])??`#000000`),y(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=Bp(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...un}})),a.$$click=()=>{let t=r()?.id;t&&(e.onChange(e.themes().filter(e=>e.id!==t)),n(e.themes().find(e=>e.id!==t)?.id??``))},t})(),Vp(),(()=>{var e=Up(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),R(t,()=>r().backgroundImage?`🖼 replace image…`:`🖼 choose image…`),n.addEventListener(`change`,e=>{e.stopPropagation(),u(e.currentTarget.files?.[0]),e.currentTarget.value=``}),n.$$input=e=>e.stopPropagation();var i=o;return typeof i==`function`?Oe(i,n):o=n,R(e,j(N,{get when(){return r().backgroundImage},get children(){var e=Hp(),t=e.firstChild,n=t.nextSibling;n.firstChild;var i=n.nextSibling.firstChild,a=i.firstChild.nextSibling,o=a.nextSibling,c=o.firstChild,l=i.nextSibling,u=l.firstChild.nextSibling,d=u.nextSibling,f=d.firstChild,p=l.nextSibling;return R(n,()=>{let e=r()?.backgroundImageBytes;return e?` — ${Math.max(1,Math.round(e/1024))} KB`:``},null),a.$$input=e=>s(t=>({...t,backgroundDim:Number(e.currentTarget.value)})),R(o,()=>Math.round((r().backgroundDim??.55)*100),c),u.$$input=e=>s(t=>({...t,surfaceAlpha:Number(e.currentTarget.value)})),R(d,()=>Math.round((r().surfaceAlpha??.82)*100),f),p.$$click=()=>s(e=>({...e,backgroundImage:void 0})),y(()=>I(t,`src`,r().backgroundImage)),y(()=>a.value=r().backgroundDim??.55),y(()=>u.value=r().surfaceAlpha??.82),e}}),null),e})(),Wp()]}),null),d})()}function Kh(e){let t=Number(localStorage.getItem(`teapot.todoH`)??``),[n,r]=v(Number.isFinite(t)&&t>0?t:0),i=()=>n()>0?{height:`${n()}px`}:void 0,a=e=>{let t=new ResizeObserver(()=>{let t=e.offsetHeight;t<=0||r(e=>Math.abs(e-t)<1?e:(localStorage.setItem(`teapot.todoH`,String(t)),t))});t.observe(e),C(()=>t.disconnect())};return j(N,{get when(){return e.preview},get fallback(){return(()=>{var t=qp();return t.$$input=t=>e.onDraft(t.currentTarget.value),Oe(a,t),y(e=>Ee(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=Kp();return Oe(a,t),y(n=>{var r=i(),a=th(e.draft);return n.e=Ee(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function qh(e){let t=Uh(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),ee=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},w=e=>x()!==`hide`||!e.ignored,[te,T]=v(localStorage.getItem(`teapot.showHidden`)===`1`),ne=()=>{let e=!te(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await ie(t,e)}))).then(t=>{T(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&D(e,n)})},E=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function re(e){return ie(e,te())}async function ie(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return E(t,i.entries??[])}catch(e){return _(e.message),null}}let D=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),O=``;b(()=>{let t=e.agentId;t!==O&&(O=t,l(new Set),c(null),f(null),r(new Map),re(``).then(e=>{e&&O===t&&r(new Map([[``,e]]))}))});let ae=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await re(e.path);t&&D(e.path,t)}},[oe,se]=v(``),[ce,le]=v(!1),[k,ue]=v(``),[A,de]=v(!1),fe=e=>/\.(md|markdown|mdx)$/i.test(e),pe=0,me=async e=>{let t=++pe;se(``),le(!0);try{let{highlightChunks:n}=await Cu(async()=>{let{highlightChunks:e}=await import(`./shiki-DQxXtlWj.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(pe!==t)return;se(e=>e+r)}}catch{pe===t&&se(``)}finally{pe===t&&le(!1)}};C(()=>{pe++});let he=async(t,n)=>{let r=Vh(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),ue(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&me({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ge=async()=>{let t=o();if(t&&!A()){de(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:k(),baseContent:t.content})}),c({...t,content:k()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
25
|
+
`))),e}}),null),R(r,j(N,{get when(){return t.a.goal.status===`done`},get children(){return ud()}}),null),y(e=>{var o=`agent-item`+(t.a.id===n()?` sel`:``)+(t.depth>0?` sub-row`:``)+(t.chatCollapsedGroup?` collapsed`:``),s=t.depth>0?`padding-left:${10+t.depth*14}px`:``,c=t.a.parent?(()=>{let e=Tt(t.a.id,Xi().map(e=>e.key));return e?`sub-agent of @${t.a.parent} — "${e}"`:`sub-agent of @${t.a.parent}`})():void 0,l=`dot ${t.a.status}`,d=t.a.status===`needs_operator`?`waiting for your answer`:t.a.status===`waiting`?`waiting on its own work — resumes by itself`:t.a.status,f=t.a.workspaceMissing?` ghost`:``,p=t.a.workspaceMissing?`workspace not found on disk (${t.a.workspace}) — it will be created when this session runs`:t.a.sessionTitle??u().get(t.a.session??``)?`${t.a.sessionTitle??u().get(t.a.session??``)} — ${t.a.id}`:t.a.id;return o!==e.e&&L(r,e.e=o),e.t=Ee(r,s,e.t),c!==e.a&&I(r,`title`,e.a=c),l!==e.o&&L(i,e.o=l),d!==e.i&&I(i,`title`,e.i=d),f!==e.n&&L(a,e.n=f),p!==e.s&&I(a,`title`,e.s=p),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),r}})]})),o.$$click=e=>{e.stopPropagation(),zn(!Rn()),Rn()||Fn(e=>e.map(e=>({...e,read:!0})))},R(o,j(N,{get when(){return Bn()>0},get children(){var e=Du();return R(e,Bn),e}}),null),R(a,j(Ih,{icon:`👻`,get active(){return In()},get title(){return In()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!In();if(Ln(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&z()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&si(t.id)}}}),null),R(a,j(Ih,{icon:`+`,title:`new agent`,onClick:()=>{ar(),se(!0)}}),null),R(a,j(Ih,{icon:`⚙`,title:`settings`,onClick:()=>{ar(),A(!0)}}),null),R(c,`0.36.6`,null),R(d,j(N,{get when(){return T()},get children(){return[`master rss `,P(()=>T().rssMb),`MB · heap `,P(()=>T().heapUsedMb),`MB`,Ou(),`load1 `,P(()=>T().loadavg1),` · up `,P(()=>Math.floor(T().uptimeSec/60)),`m`]}})),R(f,j(N,{get when(){return z()?.id},keyed:!0,get fallback(){return gd()},get children(){return[(()=>{var t=Mu(),r=t.firstChild,i=r.nextSibling,a=i.nextSibling,o=a.nextSibling,s=o.firstChild,c=s.nextSibling,l=c.nextSibling.nextSibling,u=l.nextSibling.nextSibling,d=u.nextSibling.nextSibling;d.nextSibling;var f=o.nextSibling,p=f.firstChild,m=p.nextSibling;return R(t,j(N,{get when(){return me()},get children(){var e=ku();return e.$$click=()=>Ne(!Me()),y(()=>I(e,`aria-expanded`,Me())),e}}),r),R(i,()=>z().id),R(a,()=>z().status),R(t,j(N,{get when(){return(z().pendingPromptIds?.length??z().pendingPrompts??0)>0},get children(){var e=Au(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>z().pendingPromptIds?.length??z().pendingPrompts,t),R(e,()=>z().status===`stopped`?` (stopped)`:``,null),y(()=>I(e,`title`,z().status===`stopped`?`${z().pendingPromptIds?.length??z().pendingPrompts??0} message${(z().pendingPromptIds?.length??z().pendingPrompts??0)>1?`s`:``} from you are still queued, but this agent is STOPPED — nothing will run until you press start (or it is resumed). Each can be withdrawn with ✕ cancel while it is still queued.`:`${z().pendingPromptIds?.length??z().pendingPrompts??0} message${(z().pendingPromptIds?.length??z().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}}),o),R(t,j(N,{get when(){return Cr(z().id).length>0},get children(){var e=ju();return e.firstChild,R(e,()=>Cr(z().id).length,null),y(()=>I(e,`title`,`scheduled tasks:\n${Cr(z().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
|
|
26
|
+
`)}`)),e}}),o),R(o,()=>z().model,s),R(o,()=>z().session,c),R(o,()=>z().branch,l),R(o,()=>z().stats.turns,u),R(o,()=>z().stats.toolCalls,d),p.$$click=()=>(B()?Ma(`/stop`):Ma(`/start`))(),R(p,()=>B()?`■ stop`:`▶ start`),R(f,j(N,{get when(){return e().some(e=>e.parent===n())},get children(){return j(Ih,{icon:`⏹`,title:`stop every sub-agent this agent spawned (descendants included)`,onClick:Pa})}}),m),R(f,j(Ih,{icon:`🗄`,title:`archive this agent — reversible: it leaves the list but keeps its config and history (restore in ⚙ settings → archive)`,onClick:Na}),null),R(f,j(Ih,{icon:`⑂`,title:`fork: branch off the conversation here — try things without disturbing the main line`,onClick:Fa}),null),R(f,j(Ih,{icon:`⌨`,title:`terminal (t)`,onClick:Ci}),null),R(f,j(Ih,{icon:`▤`,title:`toggle details panel (d)`,get active(){return we()},onClick:Ae}),null),y(e=>{var t=`badge ${z().status}`,n=z().statusReason&&!/^(round complete|prompt|api start|goal set|created via web|start)$/.test(z().statusReason)?`${z().status} — ${z().statusReason}`:void 0,r=`${z().model} · ${z().session}/${z().branch} · turns ${z().stats.turns} · tools ${z().stats.toolCalls}`,i=`runbtn`+(B()?` danger`:``),s=B()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&L(a,e.e=t),n!==e.t&&I(a,`title`,e.t=n),r!==e.a&&I(o,`title`,e.a=r),i!==e.o&&L(p,e.o=i),s!==e.i&&I(p,`title`,e.i=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),t})(),(()=>{var e=zu();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r={top:t.scrollTop,height:t.scrollHeight,viewport:t.clientHeight},i=nn(r,va,ya,wa);i===`layout`&&!Ct()&&Ca>0&&Math.abs(r.height-(ya??r.height))>1&&(Ca--,xe(t,ba)),va=null,ya=r.height,wa=r.viewport,Ut(r);let a=Ct(),o=performance.now();o-xa>100&&(xa=o,ba=F(t));let s=an(a,i,r);s!==a&&At(s),i===`reader`&&(Ca=4),s&&i!==`reader`?(jt()&&Mt(0),Hn(),rn(s,r)&&en(r)>0&&ri()):s&&tn(r)&&(jt()&&Mt(0),Hn()),r.top<=4&&n()&&!Ur()&&!qr()&&m().length>0&&$r()}),Oe(e=>Ce(e),e),R(e,j(N,{get when(){return Wt()},children:e=>(()=>{var t=_d();return t.firstChild,R(t,(()=>{var t=P(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Nh(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),R(e,j(N,{get when(){return P(()=>!!qr())()&&er().length>0},get children(){return Nu()}}),null),R(e,j(N,{get when(){return Ur()},get children(){return Pu()}}),null),R(e,j(N,{get when(){return er().length>0},get fallback(){return P(()=>!!Gr())()?vd():yd()},get children(){return[j(M,{get each(){return er()},children:e=>j(Oh,{e,prev:()=>nr(e,-1),next:()=>nr(e,1),get showBranch(){return w().length>1},res:()=>Jn().resFor.get(e.id),get orphan(){return Jn().orphanCalls.has(e.id)},onOption:e=>void Da(e),answeredIds:$n,onAnswered:Zn,get agentActive(){return P(()=>!!Tn())()&&Je(e)},onResize:()=>{Ct()&&ri()},get onCancel(){return e.data?.source===`user`&&e.data?.pending&&e.data?.promptId&&e.data?.sent!==!0?()=>{let t=String(e.data.promptId);$(`/api/agents/${n()}/prompt/cancel`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({promptId:t})}).then(e=>{let n=String(e.text??``);D(re()?`${n}\n\n${re()}`:n),Nn(jn(),kn().filter(e=>e.promptId!==t)),Q(`message withdrawn — draft restored`)}).catch(()=>Q(`withdraw failed — it may have already been sent`))}:void 0},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`&&!(e.data?.pending&&e.data?.sent!==!0)&&!e.data?.cancelled&&!B()?()=>Dn({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),j(N,{get when(){return P(()=>!!Tn())()&&un()},get children(){var e=Ru(),t=e.firstChild.nextSibling;return t.firstChild,R(t,j(N,{get when(){return Sn().trim()!==``},get children(){var e=Fu(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return R(t,j(xh,{get startedAt(){return bn()}}),null),Oe(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{Sn(),t&&(e.scrollTop=e.scrollHeight)})},n),R(n,Sn),e}}),null),R(t,j(N,{get when(){return fn()},get fallback(){return bd()},get children(){return j(N,{get when(){return qt()},get fallback(){return(()=>{var e=Lu();return y(()=>e.innerHTML=Ie(fn()+`▍`)),e})()},get children(){return[Iu(),(()=>{var e=Lu();return y(()=>e.innerHTML=Ie($t()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),j(N,{get when(){return xi()},get children(){var t=Wu(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Pi(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Ni()))},n.$$pointerdown=Ki,R(i,j(M,{get each(){return G()},children:(e,t)=>(()=>{var n=xd(),r=n.firstChild.nextSibling;return n.$$click=()=>Ri(t()),R(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Vi(t())},y(r=>{var i=`termtab`+(ji()===0&&Ti()===t()?` active`:``)+(ki()&&ji()===1&&Di()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&L(n,r.e=i),a!==r.t&&I(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),R(i,j(Ih,{icon:`+`,title:`new shell in this workspace`,onClick:zi}),null),R(o,(()=>{var t=P(()=>!!Li());return()=>t()?e().find(e=>e.id===Li().agentId)?.workspace.split(`/`).filter(Boolean).pop():z()?.workspace})()),R(a,j(Ih,{icon:`◫`,get title(){return ki()?`single pane`:`split panes (50/50)`},onClick:qi}),null),R(a,j(Ih,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:Ci}),null);var l=Ji(0);return typeof l==`function`&&Oe(l,c),c.$$pointerdown=()=>Mi(0),R(c,j(N,{get when(){return Ti()<0||Ti()>=G().length},get children(){return Bu()}})),R(s,j(N,{get when(){return ki()},get children(){return[Vu(),(()=>{var e=Uu(),t=Ji(1);return typeof t==`function`&&Oe(t,e),e.$$pointerdown=()=>Mi(1),R(e,j(N,{get when(){return Di()<0||Di()>=G().length},get children(){return Hu()}})),y(()=>e.classList.toggle(`focused`,ji()===1)),e})()]}}),null),y(e=>{var n={height:`${Ni()}px`},r=!!ki(),i=ji()===0;return e.e=Ee(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=Zu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling;return R(e,j(N,{get when(){return P(()=>Nt()>32)()&&!Ct()},get children(){var e=Gu();return e.firstChild,e.$$click=()=>{ii(!0),Hn()},R(e,(()=>{var e=P(()=>jt()>0);return()=>e()?`${jt()} new message${jt()>1?`s`:``}`:`jump to present`})(),null),e}}),t),R(e,j(N,{get when(){return ua().length>0},get children(){var e=Ku();return R(e,j(M,{get each(){return ua()},children:(e,t)=>(()=>{var n=Sd(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{D(e.insert),la(-1)},R(r,()=>e.insert.trim()),R(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===ca()?` active`:``),a=e.title;return i!==r.e&&L(n,r.e=i),a!==r.t&&I(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),R(e,j(N,{get when(){return na().length>0},get children(){var e=Ku();return R(e,j(M,{get each(){return na()},children:e=>(()=>{var t=Cd(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{D(`@${e.key} `),la(-1)},R(n,()=>e.key,null),R(r,()=>e.label),y(()=>I(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,Oa),R(t,j(N,{get when(){return Ta().length>0},get children(){var e=qu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,R(e,j(M,{get each(){return Ta()},children:(e,t)=>(()=>{var n=wd(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>K(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&I(n,`title`,t.e=i),a!==t.t&&I(r,`src`,t.t=a),o!==t.a&&I(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),R(t,()=>Ta().length,n),R(t,()=>Ta().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=ua();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),la(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),la(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&ca()>=0&&!lh?(e.preventDefault(),D(t[ca()].insert),la(-1)):e.key===`Escape`&&t.length>0?la(-1):e.key===`Enter`&&!e.shiftKey&&!lh&&!yt()&&(e.preventDefault(),Oa(e))},n.$$input=e=>{D(e.currentTarget.value),la(0),ga()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),Ea(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{lh=!1}),D(da?.value??``)}),n.addEventListener(`compositionstart`,()=>{lh=!0}),Oe(e=>{da=e,e.value=re()},n),R(t,j(N,{get when(){return P(()=>!!re().startsWith(`@`))()&&re().includes(` `)},get children(){var e=Ju(),t=e.firstChild;return t.addEventListener(`change`,e=>ea(e.currentTarget.checked)),y(()=>t.checked=$i()),e}}),r),r.$$click=()=>{let e=!yt();bt(e),requestAnimationFrame(()=>ga())},R(r,()=>yt()?`⤡`:`⤢`),R(t,j(Ih,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),R(t,j(N,{get when(){return Ta().length},get children(){var e=Yu();return e.firstChild,R(e,()=>Ta().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&Ea(e.currentTarget.files),e.currentTarget.value=``}),R(e,j(N,{get when(){return oh()},get children(){var e=Xu();return R(e,oh),e}}),null),y(t=>{var i=`composer`+(yt()?` maximized`:``),a=`message #${z().id} — / for commands · paste or 📎 to attach images`,o=yt()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&L(e,t.e=i),a!==t.t&&I(n,`placeholder`,t.t=a),o!==t.a&&I(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()]}})),R(t,j(N,{get when(){return P(()=>!!me())()&&we()},get children(){var e=Qu();return e.$$click=()=>ke(!1),e}}),p),p.addEventListener(`scroll`,e=>{ja=e.currentTarget.scrollTop});var v=Aa;return typeof v==`function`?Oe(v,p):Aa=p,R(g,j(Ih,{icon:`✕`,title:`close details panel (esc)`,onClick:je}),null),R(p,j(N,{get when(){return z()?.id},keyed:!0,fallback:null,children:t=>[j(N,{get when(){return z().id},keyed:!0,fallback:null,children:e=>j(Xh,{agentId:e,get workspace(){return z().workspace}})}),Td(),(()=>{var t=Od(),r=t.firstChild,i=r.nextSibling,a=i.firstChild,o=a.nextSibling,s=i.nextSibling,c=s.firstChild,l=s.nextSibling;return l.firstChild,r.addEventListener(`change`,t=>{let r=t.currentTarget.value;vt=!0,it(r),ot(Jt(O().providers,r,e().find(e=>e.id===n()))),ft(r)}),R(r,j(M,{get each(){return dt()},children:e=>(()=>{var t=Yd();return t.value=e,R(t,e,null),R(t,()=>e===O().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>ot(e.currentTarget.value),R(o,j(M,{get each(){return lt()},children:e=>(()=>{var t=Yd();return y(()=>t.value=e.id),t})()})),R(t,j(N,{get when(){return z().effortSupported},get children(){var e=Ed(),t=e.firstChild.nextSibling;return t.firstChild,t.addEventListener(`change`,e=>ct(e.currentTarget.value)),R(t,j(M,{get each(){return P(()=>!!z().effortOptions?.length)()?z().effortOptions:nh},children:e=>(()=>{var t=Yd();return t.value=e,R(t,e),t})()}),null),y(()=>t.value=st()),e}}),s),c.$$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:rt(),model:at().trim()||void 0,contextWindowTokens:lt().find(e=>e.id===(at().trim()||void 0))?.contextLength,...z().effortSupported?{reasoningEffort:st()}:{}})}),t.textContent=`✓ applied`,vr()}catch(e){alert(`apply failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},R(l,()=>z().model,null),R(l,j(N,{get when(){return lt().length},get children(){return[` · `,P(()=>lt().length),` models loaded`]}}),null),R(t,j(N,{get when(){return gt()},get children(){var e=Dd();return R(e,gt),e}}),null),y(()=>I(a,`placeholder`,Yt(O().providers,rt(),z(),Kt(z(),O().providers,O().defaultProvider)))),y(()=>r.value=rt()),y(()=>a.value=at()),t})(),(()=>{var e=kd(),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(vr)}),y(()=>t.checked=z().autoContinue??!0),e})(),(()=>{var e=jd();return e.firstChild,R(e,j(N,{get when(){return!!z().goal.text.trim()},get fallback(){return Xd()},get children(){var e=Ad();return R(e,()=>z().goal.status),y(()=>L(e,`badge ${z().goal.status===`active`?`running`:z().goal.status}`)),e}}),null),e})(),(()=>{var e=Md();return e.firstChild,R(e,j(M,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Zd();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(vr)},I(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`),R(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(z().goal.text.trim()&&z().goal.status===e?` on ${e}`:``),i=!!z().goal.text.trim()&&z().goal.status===e;return r!==n.e&&L(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),j(N,{get when(){return z().goal.text},get fallback(){return Qd()},get children(){return[(()=>{var e=Nd(),t=e.firstChild;return y(()=>t.innerHTML=Ie(String(z().goal.text))),e})(),j(N,{get when(){return z().goal.verify},get children(){var e=Pd(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Ie(String(z().goal.verify))),e}}),j(N,{get when(){return z().goal.audit},children:e=>(()=>{var t=$d(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return R(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),R(r,()=>Mh(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=ht(e().feedback)?Ie(`_the auditor returned a verdict with no detail_`):Ie(e().feedback);return r!==n.e&&L(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),(()=>{var e=Fd(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,Ga),t.$$input=e=>{La(e.currentTarget.value),Va(!0)},n.$$input=e=>{za(e.currentTarget.value),Va(!0)},r.addEventListener(`change`,e=>Ua(e.currentTarget.checked)),y(()=>t.value=Ia()),y(()=>n.value=Ra()),y(()=>r.checked=Ha()),e})(),(()=>{var e=Ld(),t=e.firstChild.nextSibling;return R(e,j(N,{get when(){return gr().total>0},get children(){var e=Id(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,R(e,()=>gr().done,t),R(e,()=>gr().total,n),y(t=>Ee(e,gr().done===gr().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),j(N,{get when(){return gr().total>0},get children(){var e=Rd(),t=e.firstChild;return y(e=>{var n=`barfill `+(gr().done===gr().total?``:`warn`),r=`${Math.round(gr().done/gr().total*100)}%`;return n!==e.e&&L(t,e.e=n),r!==e.t&&De(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),j(Yh,{get draft(){return cr()},get preview(){return ur()},onDraft:e=>{lr(e),pr(!0)}}),(()=>{var e=zd(),t=e.firstChild,n=t.nextSibling;return R(e,j(Ih,{get icon(){return ur()?`✎`:`👁`},get title(){return ur()?`edit markdown`:`rendered checklist`},onClick:()=>dr(!ur())}),t),n.$$click=hr,e})(),Bd(),j(N,{get when(){return z().latestProgress},get fallback(){return ef()},children:e=>(()=>{var t=of(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return R(t,j(N,{get when(){return e().recent},get children(){var t=tf(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=th(e().recent)),t}}),i),R(t,j(N,{get when(){return e().problems},get children(){var t=nf(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=th(e().problems)),t}}),i),R(t,j(N,{get when(){return e().next},get children(){var t=rf(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=th(e().next)),t}}),i),R(t,j(N,{get when(){return e().goalStatus},get children(){var t=af(),n=t.firstChild.nextSibling;return R(n,()=>e().goalStatus),t}}),i),R(i,()=>Mh(e().ts)),y(()=>r.innerHTML=th(e().doing)),t})()}),Vd(),(()=>{var e=Wd(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling,c=s.firstChild.nextSibling,l=s.nextSibling,u=l.firstChild.nextSibling,d=l.nextSibling,f=d.firstChild.nextSibling;return R(e,j(N,{get when(){return z().ctx},keyed:!0,get fallback(){return sf()},children:e=>{let t=x(()=>{let t=e,n=lt().find(e=>e.id===z().model),r=t.window||n?.contextLength||0,i=r?Math.min(999,t.usedTokens/r*100):0;return{usedTokens:t.usedTokens,compactAt:t.compactAt,compacting:t.compacting,window:t.window,effectiveWindow:r,pct:i,cls:r?i>=85?`crit`:i>=70?`warn`:`ok`:``,derivedBudget:r?Math.round(r*.75):0,usingDerived:t.compactAtIsManual!==!0}}),r=()=>t(),i=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)};return(()=>{var e=df(),t=e.firstChild,a=t.firstChild.nextSibling,o=a.firstChild.nextSibling;o.nextSibling;var s=t.nextSibling,c=s.firstChild.nextSibling,l=c.firstChild,u=c.nextSibling,d=s.nextSibling,f=d.firstChild.firstChild;return R(a,()=>Nh(r().usedTokens),o),R(t,j(N,{get when(){return r().effectiveWindow},get children(){var e=cf(),t=e.firstChild;return R(e,()=>i(r().pct),t),R(e,()=>Nh(r().effectiveWindow),null),y(()=>L(e,`pill ${r().cls}`)),e}}),null),R(e,j(N,{get when(){return r().effectiveWindow},get children(){var e=lf(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&L(t,e.e=n),i!==e.t&&De(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),R(c,()=>Nh(r().usingDerived?r().derivedBudget:r().compactAt),l),R(u,()=>r().usingDerived?`75% of window`:`manual`),R(e,j(N,{get when(){return Wt()||r().compacting},get children(){var e=uf(),t=e.firstChild.nextSibling.nextSibling;return R(t,()=>Wt()?.phase??String(r().compacting)),e}}),d),f.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(vr)}),y(()=>f.checked=z().autoCompact!==!1),e})()}}),t),R(i,()=>Nh(z().stats.inputTokens)),R(o,()=>Nh(z().stats.outputTokens)),R(c,()=>z().stats.turns),R(u,()=>z().stats.toolCalls),R(f,()=>z().stats.compactions??0),R(t,j(N,{get when(){return(z().stats.costUsd??0)>0},get children(){var e=Hd(),t=e.firstChild.nextSibling;return t.firstChild,R(t,()=>Ph(z().stats.costUsd??0),null),y(()=>I(e,`title`,`≈ ${(z().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),R(t,j(N,{get when(){return(z().stats.cachedInputTokens??0)>0},get children(){var e=Ud(),t=e.firstChild.nextSibling,n=t.firstChild;return R(t,()=>Math.round(z().stats.cachedInputTokens/Math.max(1,z().stats.inputTokens)*100),n),y(()=>I(e,`title`,`${Nh(z().stats.cachedInputTokens)} input tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),y(()=>I(d,`title`,`how many times old turns were summarized into notes to make room. ${z().stats.compactions?`Each one keeps the recent stretch verbatim.`:`Not yet — the context has fit so far.`}`)),e})(),(()=>{var e=Kd();return e.firstChild.nextSibling,R(e,j(N,{get when(){return zr()},get children(){var e=Gd(),t=e.firstChild.nextSibling;return R(t,zr),e}}),null),e})(),j(M,{get each(){return w()},children:e=>(()=>{var t=ff(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=zr()===e.branch?null:e.branch,r=t!==zr();Br(t),n()&&(r&&(Yr++,h([]),_(0),Jr(!1)),ei(n()))},R(r,()=>e.branch,null),R(r,()=>e.branch===z().branch?` (current)`:``,null),R(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===z().branch||e.branch===zr()?` cur`:``),i=e.branch===zr()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),(()=>{var e=Jd();return e.firstChild,R(e,j(N,{get when(){return br().length>0},get children(){var e=qd(),t=e.firstChild.nextSibling;return t.nextSibling,R(e,()=>br().length,t),e}}),null),e})(),j(N,{get when(){return br().length>0},get fallback(){return pf()},get children(){return j(M,{get each(){return br()},children:e=>(()=>{var t=hf(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>si(e.agent),R(i,()=>e.id),R(a,()=>e.agent,null),R(r,j(N,{get when(){return e.forked},get children(){return mf()}}),null),R(o,()=>e.schedule,s),R(o,(()=>{var t=P(()=>!!e.next);return()=>t()?Mh(e.next):`—`})(),null),R(o,(()=>{var t=P(()=>!!e.last);return()=>t()?` · last ${Mh(e.last)}`:` · never ran`})(),null),R(c,()=>Fh(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${Fh(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&L(t,r.e=i),a!==r.t&&I(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var n=`layout`+(we()?``:` right-hidden`)+(Me()?` left-open`:``),i=`sidebar`+(Me()?` open`:``),a=`iconbtn notifbtn`+(Bn()>0?` has-unread`:``),s=Bn()>0?`${Bn()} unread notifications`:`notifications`,c=`conn`+(ci()?` ok`:``),u=ci()?`live (websocket)`:`reconnecting…`,d={"--termh":`${Ni()}px`},m=`rightbar`+(we()?` open`:``);return n!==e.e&&L(t,e.e=n),i!==e.t&&L(r,e.t=i),a!==e.a&&L(o,e.a=a),s!==e.o&&I(o,`title`,e.o=s),c!==e.i&&L(l,e.i=c),u!==e.n&&I(l,`title`,e.n=u),e.s=Ee(f,d,e.s),m!==e.h&&L(p,e.h=m),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0}),t})(),j(N,{get when(){return Rn()},get children(){return[(()=>{var e=ed();return e.$$click=()=>zn(!1),e})(),(()=>{var t=rd(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return R(r,j(N,{get when(){return Pn().length>0},get children(){var e=td();return e.$$click=()=>Fn([]),e}}),i),i.$$click=()=>zn(!1),R(t,j(N,{get when(){return Pn().length>0},get fallback(){return gf()},get children(){var t=nd();return R(t,j(M,{get each(){return Pn()},children:t=>(()=>{var r=vf(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{Fn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&si(t.agentId),zn(!1),t.eventId&&setTimeout(()=>qn(t.eventId),n()===t.agentId?60:350)},R(i,(()=>{var e=P(()=>t.kind===`finish`);return()=>e()?`✅`:P(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),R(a,()=>t.title),R(o,()=>Mh(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),Fn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},R(s,()=>t.read?`✓`:`○`),R(r,j(N,{get when(){return t.body},get children(){var e=_f();return R(e,()=>jh(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&L(r,e.e=n),i!==e.t&&I(r,`title`,e.t=i),a!==e.a&&I(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),j(N,{get when(){return oe()},get children(){return j(zh,{get providers(){return Object.keys(O().providers??{})},onClose:()=>se(!1),onCreated:e=>{se(!1),vr(),si(e)}})}}),j(N,{get when(){return ue()},get children(){return j(eg,{get cfg(){return O()},onClose:()=>A(!1),announcedOAuth:fe,get skills(){return ia()},get hasSelection(){return!!n()},get agentId(){return n()},get features(){return oa()},onSaved:()=>{ar(),Sr()},theme:{themes:Ge,activeId:Fe,paintedId:k,auto:Re,setAuto:ze,dark:Qe,setDark:$e,light:Be,setLight:Ve,setThemes:qe,setActive:Le}})}}),j(N,{get when(){return En()},fallback:null,children:e=>{let t=()=>m().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,m().length-t()-1),[i,a]=v(r()>0?`summarize`:`discard`);return j(Rh,{title:`edit prompt — forks the conversation`,onClose:()=>Dn(null),get children(){var t=bf(),o=t.firstChild,s=o.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:i()})}),Dn(null),vr();let t=n();t&&await si(t)}catch(e){alert(`edit failed: ${e.message}`)}}),R(t,j(N,{get when(){return r()>0},get children(){var e=yf(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return R(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>Dn(null),y(()=>o.value=e().text),t}})}})]}function bh(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=()=>Ve(Math.max(0,n()-t));return e.inline?(()=>{var t=xf();return t.firstChild,R(t,i,null),R(t,(()=>{var t=P(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=Sf(),t=e.firstChild;return R(e,i,t),e})()}function xh(e){let[t,n]=v(Date.now());return ee(()=>{let e=setInterval(()=>n(Date.now()),500);C(()=>clearInterval(e))}),e.startedAt?(()=>{var n=Cf();return R(n,()=>Ve(Math.max(0,t()-e.startedAt))),n})():null}var Sh=new Map,Ch=400;function wh(e,t){if(Sh.size>=Ch){let e=Sh.keys().next();e.done||Sh.delete(e.value)}Sh.set(e,t)}function Th(e){let t=()=>e.lang?`${e.lang}::${e.text.length}::${e.text}`:``,[n,r]=v((e.lang?Sh.get(t()):void 0)??``);return b(()=>{let n=t(),i=e.text,a=e.lang;if(!a||!i.trim()){r(``);return}let o=Sh.get(n);o===void 0?(async()=>{try{let{highlightLangChunks:e}=await Cu(async()=>{let{highlightLangChunks:e}=await import(`./shiki-DlE9AYQg.js`);return{highlightLangChunks:e}},[]),o=``;for await(let t of e(a,i))o+=t;if(!o)return;wh(n,o),t()===n&&r(o)}catch{}})():r(o)}),j(N,{get when(){return!!n()},get fallback(){return(()=>{var t=Tf();return R(t,()=>e.text),t})()},get children(){var e=wf();return y(()=>e.innerHTML=n()),e}})}function Eh(e){let t=e.e,n=Nt(e.prev,t),r=x(()=>e.res?.(),void 0,{equals:(e,t)=>e?.id===t?.id}),i=()=>r(),a=()=>!e.agentActive&&!i(),o=t.data??{},s=String(o.name??`tool`),c=()=>String(i()?.data?.result??``),l=e=>String(o.args?.[e]??``),u=()=>s===`bash`?l(`command`):l(`path`)||JSON.stringify(o.args??{},null,1),d=()=>s===`bash`?Number(l(`timeout_ms`))||void 0:s===`wait_children`?Number(l(`timeout_ms`))||3e5:Number(l(`timeout_ms`))||void 0,f=(e,t=1500,n)=>j(Th,{get text(){return jh(e,t)},lang:n}),p=(e=2e3)=>j(Th,{get text(){return jh(JSON.stringify(o.args??{},null,1),e)},lang:`json`}),m=(e=4e3)=>(()=>{let t=i();return t?[P(()=>f(c(),e,bt(c()))),(()=>{var e=Ef();return R(e,()=>Ve(t.data?.durationMs),null),R(e,()=>s===`bash`?Wt(Ut(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),R(e,j(Lh,{get text(){return c()}}),null),e})()]:Df()})(),h=x(()=>{i();let e=s,t=``,n=p(2e3);try{switch(s){case`bash`:{let r=l(`command`),a=o.args?.background===!0,s=a?String(c()).match(/job (bg\d+)/)?.[1]??``:``;e=(a?`⏳ `:`$ `)+Fh(r,96);let u=l(`timeout_ms`)?Number(l(`timeout_ms`)):void 0,d=i(),p=Ut(d?.data?.ok,d?String(d.data?.result??``):``);t=d?a?`background job${s?` ${s}`:``}${u?` · timeout ${Math.round(u/1e3)}s`:``}`:Gt({outcome:p,durationMs:d.data?.durationMs,timeoutMs:u,fmtDur:Ve}):null,n=[a?(()=>{var e=Of(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,R(t,s||`?`,n),R(e,s?[` · kill with `,kf()]:null,null),e})():null,P(()=>P(()=>r!==e.slice(2))()?f(r,800,`shellscript`):null),P(()=>m(6e3))];break}case`read_file`:{e=l(`path`)||`(no path)`;let r=[];l(`pattern`)&&r.push(`grep /${Fh(l(`pattern`),40)}/`),Number(o.args?.offset)<0?r.push(`last ${-Number(o.args.offset)} lines`):o.args?.offset&&r.push(`from L${o.args.offset}`),o.args?.limit&&r.push(`≤${o.args.limit} lines`),t=r.join(` · `),n=m(6e3);break}case`write_file`:{let r=String(o.args?.content??``);e=l(`path`)||`(no path)`,t=`${Nh(r.length)} bytes`,n=[P(()=>f(r,1500)),P(()=>P(()=>r.length>1500)()?(()=>{var e=Af(),t=e.firstChild;return R(e,()=>Nh(r.length),t),e})():null),P(()=>P(()=>!!i())()?(()=>{var e=Ef();return R(e,()=>Fh(c(),160)),e})():jf())];break}case`edit_file`:e=l(`path`)||`(no path)`,t=o.args?.replace_all===!0?`replace all`:`unique spot`,n=[(()=>{var e=Mf();return R(e,()=>jh(`- `+l(`old_text`),900)),e})(),(()=>{var e=Nf();return R(e,()=>`+ `+jh(l(`new_text`),900)),e})(),P(()=>P(()=>!!i())()?(()=>{var e=Pf(),t=e.firstChild;return R(e,()=>Fh(c(),120),t),R(e,()=>Ve(i().data?.durationMs),null),e})():Ff())];break;case`apply_patch`:{let t=l(`patch`).split(`
|
|
27
|
+
`).filter(e=>e&&!/^---$/.test(e.trim())),r=t.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);e=r.length?`${r.length} file${r.length>1?`s`:``}: ${Fh(r.join(`, `),80)}`:`patch`;let a=t.slice(0,60);n=[(()=>{var e=If();return R(e,()=>a.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Lf();return L(n,`pline`+t),R(n,(()=>{var t=P(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),R(e,(()=>{var e=P(()=>t.length>60);return()=>e()?(()=>{var e=Rf(),n=e.firstChild.nextSibling;return n.nextSibling,R(e,()=>t.length-60,n),e})():null})(),null),e})(),P(()=>P(()=>!!i())()?(()=>{var e=Ef();return R(e,()=>Fh(c().split(`
|
|
28
|
+
`)[0]??``,140),null),R(e,()=>i().data?.ok===!1?` · FAILED`:``,null),e})():zf())];break}case`list_dir`:e=l(`path`)||`.`,n=m(4e3);break;case`read_url`:{let r=l(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=Fh(r,70),t=`web`,n=[(()=>{var e=Ef();return R(e,j(N,{get when(){return/^https?:/i.test(l(`url`))},get fallback(){return(()=>{var e=Vf();return R(e,()=>Fh(l(`url`),80)),e})()},get children(){var e=Bf();return y(()=>I(e,`href`,l(`url`))),e}})),e})(),P(()=>m(3e3))];break}case`bash_output`:{let r=l(`action`)||`read`;e=`bash_output ${l(`job_id`)||`(?)`}`,t=r,n=m(4e3);break}case`load_skill`:{e=`skill: ${l(`name`)}`;let t=c().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);n=i()?[(()=>{var e=Lu();return y(()=>e.innerHTML=Ie(t)),e})(),(()=>{var e=Ef();return R(e,()=>Ve(i().data?.durationMs)),e})()]:Hf();break}case`save_skill`:{e=`skill: ${l(`name`)}`,t=Fh(l(`description`),60);let r=Array.isArray(o.args?.files)?o.args.files.map(e=>e?.name).filter(Boolean):[];n=[P(()=>P(()=>!!r.length)()?(()=>{var e=Uf();return e.firstChild,R(e,()=>r.join(`, `),null),e})():null),P(()=>P(()=>!!i())()?(()=>{var e=Pf(),t=e.firstChild;return R(e,()=>Fh(c(),160),t),R(e,()=>Ve(i().data?.durationMs),null),e})():Wf())];break}default:e=s,t=i()?Ve(i().data?.durationMs):null,n=[P(()=>p(2e3)),P(()=>m(4e3))]}}catch{}return{label:e,hint:t,body:n,key:`${i()?.id??`none`}|${e}|${t??``}`}},void 0,{equals:(e,t)=>e.key===t.key});return(()=>{var r=Kf(),o=r.firstChild,l=o.firstChild,f=l.nextSibling,p=f.nextSibling;return r.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),R(l,()=>h().label),R(o,j(N,{get when(){return t.data?.actor},get children(){var e=Gf();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),f),R(f,(()=>{var e=P(()=>!!i());return()=>e()?h().hint||``:P(()=>!!a())()?`(result missed)`:P(()=>!!(s===`bash`||d()))()?j(bh,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return d()}}):`running…`})()),R(p,j(Lh,{get text(){return u()},label:`⧉ cmd`,title:`copy the ${s} arguments`}),null),R(p,j(N,{get when(){return i()},get children(){return j(Lh,{get text(){return c()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),R(r,()=>h().body,null),y(e=>{var t=`embed`+(n?` grouped`:``)+(i()?i().data?.ok===!1?` fail`:` done`:a()?` done`:` running`),o=`${s}${h().hint?` — `+h().hint:``}`;return t!==e.e&&L(r,e.e=t),o!==e.t&&I(r,`title`,e.t=o),e},{e:void 0,t:void 0}),r})()}function Dh(e){let t=e.data??{};return e.type===`prompt`?String(t.text??``):e.type===`message`?`${typeof t.reasoning==`string`&&t.reasoning.trim()?`<reasoning>\n${t.reasoning}\n</reasoning>\n\n`:``}${String(t.content??``)}`:(e.type,``)}function Oh(e){let t=e.e,n=dh(t),r=()=>Nt(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Nt(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=qf(),r=n.firstChild.nextSibling;return r.nextSibling,R(n,()=>String(e.fromBranch??`?`),r),R(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=_t(t.data??{});return(()=>{var t=Jf(),n=t.firstChild;return R(n,()=>e.label),R(t,j(N,{get when(){return e.hasCard},get children(){var t=Lf();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Ie(e.detail):Ie(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&L(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>L(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Yf(),n=e.firstChild.nextSibling;return n.nextSibling,R(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Xf(),n=e.firstChild;return R(e,()=>t.data.from,n),R(e,()=>t.data.to,null),R(e,(()=>{var e=P(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>L(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Zf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,R(n,()=>String(t.data?.failures),r),R(n,()=>String(t.data?.limit),i),R(a,()=>String(t.data?.lastTool),o),R(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>I(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Qf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(n,()=>String(t.data?.attempt),r),R(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=Lf();return L(r,`divider-msg`+(e?` err`:``)),R(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>I(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=$f(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(e,()=>String(t.data?.tokensBefore??`?`),n),R(e,()=>String(t.data?.tokensAfter??`?`),r),R(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=ep(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,R(e,()=>String(t.data?.messages??`?`),n),R(e,()=>String(t.data?.tokensBefore??`?`),r),R(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=ap(),o=a.firstChild,s=o.nextSibling;return R(o,(()=>{var e=P(()=>!!r());return()=>e()?``:n.icon})()),R(s,(()=>{var e=P(()=>!!r());return()=>e()&&(()=>{var e=op();return y(()=>I(e,`title`,`${gh(t.ts)} · ${t.branch}`)),e})()})(),null),R(s,j(N,{get when(){return!r()},get children(){var r=ip(),i=r.firstChild,a=i.nextSibling;return R(i,()=>n.name),R(r,j(N,{get when(){return t.data?.actor},get children(){var e=Gf();return e.firstChild,R(e,()=>String(t.data.actor),null),e}}),a),R(a,(()=>{var e=P(()=>!!t.data?.pending);return()=>e()?`queued…`:P(()=>!!t.data?.cancelled)()?`withdrawn`:gh(t.ts)})()),R(r,j(N,{get when(){return e.showBranch},get children(){var e=tp();return R(e,()=>t.branch),e}}),null),R(r,j(N,{get when(){return e.onCancel},get children(){var t=np();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),R(r,j(N,{get when(){return t.type!==`tool_call`},get children(){return j(Lh,{get text(){return Dh(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),R(r,j(N,{get when(){return e.onEdit},get children(){var t=rp();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>De(i,`color`,n.color)),r}}),null),R(s,j(Ah,{e:t,get prev(){return e.prev?.()},get res(){return e.res},get orphan(){return e.orphan},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get onAnswered(){return e.onAnswered},get agentActive(){return e.agentActive},get onResize(){return e.onResize}}),null),y(e=>{var s=`msg`+(r()?` grouped`:``)+(i()?` next-grouped`:``)+(t.data?.pending?` pending`:``)+(t.data?.cancelled?` withdrawn`:``),c=t.id,l=`avatar avghost`+(r()?` ghosted`:``),u=r()?`transparent`:n.color+`33`,d=r()?`1px solid transparent`:`1px solid ${n.color}66`,f=r()?`${gh(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&L(a,e.e=s),c!==e.t&&I(a,`data-eid`,e.t=c),l!==e.a&&L(o,e.a=l),u!==e.o&&De(o,`background`,e.o=u),d!==e.i&&De(o,`border`,e.i=d),f!==e.n&&I(o,`title`,e.n=f),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),a})()}function kh(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=sp(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&I(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 Ah(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=Lu();return y(()=>e.innerHTML=th(String(t.data.text??``))),e})(),j(N,{get when(){return e.length},get children(){var t=cp();return R(t,j(M,{each:e,children:e=>(()=>{var t=lp();return I(t,`src`,e),t})()})),t}})]}case`message`:return[j(N,{get when(){return P(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=up(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return R(n,(()=>{var e=P(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Nh(String(t.data.reasoning).length)} — truncated)`:``})(),null),R(r,()=>jh(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Lu();return y(()=>e.innerHTML=th(String(t.data.content??``))),e})(),j(N,{get when(){return t.data.interrupted},get children(){return dp()}}),j(N,{get when(){return t.data.final},get children(){var e=fp(),n=e.firstChild;return R(e,j(Lh,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return j(Eh,{e:t,get prev(){return e.prev},get res(){return e.res},get orphan(){return e.orphan},get agentActive(){return e.agentActive},get onResize(){return e.onResize}});case`tool_result`:{let n=String(t.data.result??``),r=String(t.data.name??`tool`),i=t.data.ok!==!1;return(()=>{var a=mp(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return L(a,`embed `+(i?``:`fail`)),R(s,r===`bash`?`$ (bash, call evicted)`:r),R(o,j(Lh,{text:n}),null),R(c,()=>jh(n,4e3)),R(l,()=>Ve(t.data.durationMs),null),R(l,()=>r===`bash`?Wt(Ut(t.data.ok,n)):i?``:` · FAILED`,null),R(a,j(N,{get when(){return e.orphan},get children(){return pp()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=gp(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return R(n,j(N,{get when(){return e.length},get children(){var t=hp();return t.firstChild,R(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=th(String(t.data?.decision??``)),r=th(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=()=>e.answeredIds?.().has(r)??!1;return(()=>{var a=yp(),o=a.firstChild.firstChild.nextSibling;return R(a,j(N,{get when(){return i()},get children(){return _p()}}),null),R(a,j(N,{get when(){return n.length>0},get children(){var a=vp();return R(a,j(M,{each:n,children:n=>(()=>{var a=bp();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},R(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),R(a,j(kh,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=th(String(t.data?.question??``));return n!==e.e&&L(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=xp(),n=e.firstChild.firstChild.nextSibling;return R(e,j(N,{get when(){return t.data.goalStatus},get children(){var e=af(),n=e.firstChild.nextSibling;return R(n,()=>String(t.data.goalStatus)),e}}),null),R(e,j(N,{get when(){return t.data.recent},get children(){var e=tf(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=th(String(t.data.recent))),e}}),null),R(e,j(N,{get when(){return t.data.problems},get children(){var e=nf(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=th(String(t.data.problems))),e}}),null),R(e,j(N,{get when(){return t.data.next},get children(){var e=rf(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=th(String(t.data.next))),e}}),null),y(()=>n.innerHTML=th(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=Sp(),n=e.firstChild;return n.firstChild,R(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=wp(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,R(n,()=>String(t.data.mode??``),r),R(n,()=>Nh(Number(t.data.tokensBefore??0)),i),R(n,()=>Nh(Number(t.data.tokensAfter??0)),a),R(n,(()=>{var e=P(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),R(e,j(N,{get when(){return t.data.summary},get children(){return[Cp(),(()=>{var e=Lu();return y(()=>e.innerHTML=th(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=Tp();return R(e,()=>jh(JSON.stringify(t.data),200)),e})()}}function jh(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Mh(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 Nh(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 Ph(e){return e>=100?Math.round(e).toLocaleString():e>=10?e.toFixed(1):e>=1?e.toFixed(2):e>=.01?e.toFixed(3):e.toFixed(4)}function Fh(e,t){return jh(e.replace(/\s+/g,` `).trim(),t)}function Ih(e){return(()=>{var t=Ep(),n=t.firstChild;return Te(t,`click`,e.onClick,!0),R(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),n.a=Ee(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function Lh(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),At(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=Dp();return n.$$click=a,R(n,(()=>{var n=P(()=>!!t());return()=>n()?`✓`:P(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>I(n,`title`,e.title??`copy to clipboard`)),n})()}function Rh(e){return(()=>{var t=Op(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),R(r,()=>e.title),Te(i,`click`,e.onClose,!0),R(n,()=>e.children,null),t})()}function zh(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 j(Rh,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Ap(),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,te=C.nextSibling.firstChild.nextSibling,T=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),R(b,j(M,{get each(){return r()},children:e=>(()=>{var n=jp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),R(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),R(w,j(M,{get each(){return e.providers},children:e=>(()=>{var t=Yd();return R(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),R(i,j(N,{get when(){return d()},get children(){var e=kp();return R(e,d),e}}),T),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>te.value=l()),i}})}var Bh=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Vh=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Hh=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Uh(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Wh(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 Wh(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Bh.has(t)?`image`:Vh.has(t)?`video`:Hh.has(t)?`audio`:null}var Gh=new Map,Kh=e=>{let t=Gh.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},Gh.set(e,t)),t};function qh(e){let t=()=>e.palette;return(()=>{var n=Np(),r=n.firstChild,i=r.nextSibling,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.nextSibling,d=u.nextSibling,f=d.nextSibling,p=f.nextSibling;return R(n,j(N,{get when(){return e.backgroundImage},get children(){var t=Mp();return y(n=>De(t,`background-image`,e.backgroundImage)),t}}),r),y(e=>{var m=t().bgDark,h=t().bgDarkest,g=t().bgDarkest,_=t().bgMid,v=t().fg,y=t().acc,b=t().dim,x=t().acc,S=t().dim,ee=t().ok,C=t().warn,w=t().err;return m!==e.e&&De(n,`background`,e.e=m),h!==e.t&&De(r,`background`,e.t=h),g!==e.a&&De(i,`background`,e.a=g),_!==e.o&&De(a,`background`,e.o=_),v!==e.i&&De(o,`background`,e.i=v),y!==e.n&&De(s,`background`,e.n=y),b!==e.s&&De(c,`background`,e.s=b),x!==e.h&&De(l,`background`,e.h=x),S!==e.r&&De(u,`background`,e.r=S),ee!==e.d&&De(d,`background`,e.d=ee),C!==e.l&&De(f,`background`,e.l=C),w!==e.u&&De(p,`background`,e.u=w),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0}),n})()}function Jh(e){let[t,n]=v(e.themes().some(t=>t.id===e.activeId)?e.activeId:e.themes()[0]?.id??``),r=()=>{let n=e.themes();return n.find(e=>e.id===t())??n.find(t=>t.id===e.activeId)??n[0]},[i,a]=v({}),o,s=t=>{let n=r()?.id;if(!n)return;let i=e.themes().map(e=>e.id===n?t(e):e);e.onChange(i)},c=(e,t)=>{let n=bn(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.paintedId),r=uh.find(t=>t.key===e.paintedId),i=t??r??uh[0],a=getComputedStyle(document.documentElement),o={...un};for(let{key:e,cssVar:t}of cn){let n=bn(a.getPropertyValue(t));n&&(o[e]=n)}let s=_n(e.themes().map(e=>e.id).concat(uh.map(e=>e.key))),c={id:s,label:`${i.label}${t?``:` copy`}`.slice(0,40),mode:i.mode,palette:o,...t?.backgroundImage?{backgroundImage:t.backgroundImage,backgroundDim:t.backgroundDim,surfaceAlpha:t.surfaceAlpha}:{}};e.onChange([...e.themes(),c]),n(s),e.onPick(s)},u=async t=>{if(t){if(!/^image\//.test(t.type))Q(`that file is ${JSON.stringify(t.type||`unknown`)} — pick an image`);else{Q(`uploading ${t.name} (${Math.round(t.size/1024)}KB)…`);try{let n=await fetch(`/api/assets`,{method:`POST`,headers:{"content-type":t.type},body:t}).then(async e=>({ok:e.ok,body:await e.json().catch(()=>null)}));if(!n.ok||!n.body?.url){Q(n.body?.error??`upload failed`);return}s(e=>({...e,backgroundImage:n.body.url,backgroundImageBytes:n.body.bytes}));let i=r()?.id;i&&e.onPick(i),Q(`background image set`)}catch(e){Q(`upload failed: ${e.message}`)}}}};return(()=>{var d=Fp(),f=d.firstChild.nextSibling,p=f.firstChild;return p.$$click=l,R(f,j(N,{get when(){return e.themes().length>0},get children(){var r=Pp();return r.addEventListener(`change`,t=>{n(t.currentTarget.value),e.onPick(t.currentTarget.value)}),R(r,j(M,{get each(){return e.themes()},children:e=>(()=>{var t=Yd();return R(t,()=>e.label),y(()=>t.value=e.id),t})()})),y(()=>r.value=t()),r}}),null),R(d,j(N,{get when(){return P(()=>!!(r()&&e.themes().some(t=>t.id===e.activeId)))()?r():null},get fallback(){return(()=>{var t=Ip();return R(t,(()=>{var t=P(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,Lp(),` to start from the palette you are using.`]:[`the editor shows when one of your themes is ACTIVE — pick one under "your themes" above (or press `,Lp(),`).`]})()),t})()},children:t=>[(()=>{var e=Rp(),t=e.firstChild.firstChild.nextSibling;return t.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),y(()=>t.value=r().mode),e})(),(()=>{var e=zp();return R(e,j(M,{each:cn,children:e=>(()=>{var t=Gp(),n=t.firstChild,o=n.nextSibling,s=o.nextSibling;return n.$$input=t=>c(e.key,t.currentTarget.value),R(o,()=>e.label),s.addEventListener(`blur`,()=>a(t=>{let n={...t};return delete n[e.key],n})),s.$$input=t=>{let n=t.currentTarget.value;a(t=>({...t,[e.key]:n})),c(e.key,n)},I(s,`spellcheck`,!1),y(()=>I(t,`title`,e.cssVar)),y(()=>n.value=bn(r().palette[e.key])??`#000000`),y(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=Bp(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...un}})),a.$$click=()=>{let t=r()?.id;t&&(e.onChange(e.themes().filter(e=>e.id!==t)),n(e.themes().find(e=>e.id!==t)?.id??``))},t})(),Vp(),(()=>{var e=Up(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),R(t,()=>r().backgroundImage?`🖼 replace image…`:`🖼 choose image…`),n.addEventListener(`change`,e=>{e.stopPropagation(),u(e.currentTarget.files?.[0]),e.currentTarget.value=``}),n.$$input=e=>e.stopPropagation();var i=o;return typeof i==`function`?Oe(i,n):o=n,R(e,j(N,{get when(){return r().backgroundImage},get children(){var e=Hp(),t=e.firstChild,n=t.nextSibling;n.firstChild;var i=n.nextSibling.firstChild,a=i.firstChild.nextSibling,o=a.nextSibling,c=o.firstChild,l=i.nextSibling,u=l.firstChild.nextSibling,d=u.nextSibling,f=d.firstChild,p=l.nextSibling;return R(n,()=>{let e=r()?.backgroundImageBytes;return e?` — ${Math.max(1,Math.round(e/1024))} KB`:``},null),a.$$input=e=>s(t=>({...t,backgroundDim:Number(e.currentTarget.value)})),R(o,()=>Math.round((r().backgroundDim??.55)*100),c),u.$$input=e=>s(t=>({...t,surfaceAlpha:Number(e.currentTarget.value)})),R(d,()=>Math.round((r().surfaceAlpha??.82)*100),f),p.$$click=()=>s(e=>({...e,backgroundImage:void 0})),y(()=>I(t,`src`,r().backgroundImage)),y(()=>a.value=r().backgroundDim??.55),y(()=>u.value=r().surfaceAlpha??.82),e}}),null),e})(),Wp()]}),null),d})()}function Yh(e){let t=Number(localStorage.getItem(`teapot.todoH`)??``),[n,r]=v(Number.isFinite(t)&&t>0?t:0),i=()=>n()>0?{height:`${n()}px`}:void 0,a=e=>{let t=new ResizeObserver(()=>{let t=e.offsetHeight;t<=0||r(e=>Math.abs(e-t)<1?e:(localStorage.setItem(`teapot.todoH`,String(t)),t))});t.observe(e),C(()=>t.disconnect())};return j(N,{get when(){return e.preview},get fallback(){return(()=>{var t=qp();return t.$$input=t=>e.onDraft(t.currentTarget.value),Oe(a,t),y(e=>Ee(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=Kp();return Oe(a,t),y(n=>{var r=i(),a=th(e.draft);return n.e=Ee(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function Xh(e){let t=Kh(e.agentId),[n,r]=v(new Map),[i,a]=v(t.expanded),[o,s]=v(t.preview),c=e=>{t.preview=e,s(e)},l=e=>{t.expanded=e,a(e)},[u,d]=v(t.media),f=e=>{t.media=e,d(e)},[p,m]=v(t.viewMode),h=e=>{t.viewMode=e,m(e)},[g,_]=v(``),[x,S]=v(localStorage.getItem(`teapot.ignoreMode`)??`dim`),ee=()=>{let e=[`dim`,`hide`,`show`],t=e[(e.indexOf(x())+1)%3];S(t),localStorage.setItem(`teapot.ignoreMode`,t)},w=e=>x()!==`hide`||!e.ignored,[te,T]=v(localStorage.getItem(`teapot.showHidden`)===`1`),ne=()=>{let e=!te(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await ie(t,e)}))).then(t=>{T(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&D(e,n)})},E=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{},...t.ignored?{ignored:!0}:{}}));async function re(e){return ie(e,te())}async function ie(t,n){try{let r=new URLSearchParams;t&&r.set(`path`,t),n&&r.set(`hidden`,`1`);let i=await $(`/api/agents/${e.agentId}/tree?${r.toString()}`);return E(t,i.entries??[])}catch(e){return _(e.message),null}}let D=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),O=``;b(()=>{let t=e.agentId;t!==O&&(O=t,l(new Set),c(null),f(null),r(new Map),re(``).then(e=>{e&&O===t&&r(new Map([[``,e]]))}))});let ae=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await re(e.path);t&&D(e.path,t)}},[oe,se]=v(``),[ce,le]=v(!1),[k,ue]=v(``),[A,de]=v(!1),fe=e=>/\.(md|markdown|mdx)$/i.test(e),pe=0,me=async e=>{let t=++pe;se(``),le(!0);try{let{highlightChunks:n}=await Cu(async()=>{let{highlightChunks:e}=await import(`./shiki-DlE9AYQg.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(pe!==t)return;se(e=>e+r)}}catch{pe===t&&se(``)}finally{pe===t&&le(!1)}};C(()=>{pe++});let he=async(t,n)=>{let r=Wh(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),ue(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&me({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ge=async()=>{let t=o();if(t&&!A()){de(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:k(),baseContent:t.content})}),c({...t,content:k()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
29
29
|
OK = load the disk version into the editor (your edits are discarded)
|
|
30
|
-
Cancel = keep editing your copy`)?(ue(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{de(!1)}}},_e=e=>!e.binary&&!e.truncated,ve=(e,t)=>[(()=>{var n=Yp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ae(e):void he(e,`code`),R(r,(()=>{var t=P(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Bh(e.name)})()),R(a,()=>e.name),R(n,j(N,{get when(){return P(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Jp();return R(t,()=>Ah(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&L(n,r.e=i),r.t=Ee(n,a,r.t),o!==r.a&&I(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),j(N,{get when(){return P(()=>!!e.dir)()&&i().has(e.path)},get children(){return j(M,{get each(){return(n().get(e.path)??[]).filter(w)},children:e=>ve(e,t+1)})}})],ye=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[be,xe]=v(!1),Se=async()=>{if(!be()){xe(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await ie(e,te())})));for(let{p:e,rows:n}of t)n&&D(e,n)}finally{xe(!1)}}};return[(()=>{var e=Xp(),t=e.firstChild.nextSibling;return t.firstChild,R(t,ye,null),R(e,j(Nh,{class:`filetoggle`,get icon(){return be()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void Se()}),null),R(e,j(Nh,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return P(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),R(e,j(Nh,{class:`filetoggle`,get icon(){return te()?`◉.`:`○.`},get title(){return te()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:ne}),null),e})(),(()=>{var e=Zp();return R(e,j(N,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=Qp();return R(e,()=>g()||`empty workspace`),e})()},get children(){return j(M,{get each(){return(n().get(``)??[]).filter(w)},children:e=>ve(e,0)})}})),e})(),j(N,{get when(){return o()},children:t=>j(Fh,{get title(){return`🗂 ${t().path}`},onClose:()=>{pe++,c(null),f(null)},get children(){return j(N,{get when(){return u()},get fallback(){return[(()=>{var e=rm(),n=e.firstChild;return R(e,j(N,{get when(){return P(()=>!!fe(t().path))()&&!t().binary},get children(){var e=tm();return e.$$click=()=>h(`md`),y(()=>L(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),oe()||me({path:t().path,content:t().content,truncated:t().truncated})},R(e,j(N,{get when(){return _e(t())},get children(){var e=nm();return e.$$click=()=>h(`edit`),y(()=>L(e,p()===`edit`?`on`:``)),e}}),null),y(()=>L(n,p()===`code`?`on`:``)),e})(),j(N,{get when(){return!t().binary},get fallback(){return am()},get children(){return j(N,{get when(){return p()===`edit`},get fallback(){return j(N,{get when(){return P(()=>p()===`md`)()&&fe(t().path)},get fallback(){return j(Jh,{get path(){return t().path},get content(){return t().content},get html(){return oe()},get pending(){return ce()},get truncated(){return!!t().truncated}})},get children(){var e=om();return y(()=>e.innerHTML=Ie(t().content)),e}})},get children(){var e=im(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>ue(e.currentTarget.value),I(n,`spellcheck`,!1),R(r,()=>Ah(k().length),i),a.$$click=()=>void ge(),R(a,()=>A()?`saving…`:`💾 save`),y(()=>a.disabled=A()||k()===t().content),y(()=>n.value=k()),e}})}})]},get children(){var t=em(),n=t.firstChild,r=n.firstChild;return R(t,j(N,{get when(){return u().kind===`image`},get fallback(){return j(N,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=cm();return y(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=sm();return y(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=$p();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&I(t,`src`,n.e=r),i!==n.t&&I(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),R(n,()=>u().kind,r),t}})}})})]}function Jh(e){return[j(N,{get when(){return e.html},get fallback(){return P(()=>!!e.pending)()?(()=>{var t=dm(),n=t.firstChild.nextSibling;return n.nextSibling,R(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=fm();return R(t,()=>e.content),t})()},get children(){var t=lm();return y(()=>t.innerHTML=e.html),t}}),j(N,{get when(){return e.truncated},get children(){return um()}})]}var Yh=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:``,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:``,hint:`zero-markup routing gateway — 'orcarouter/auto' grades each prompt and picks the model`},{key:`openai`,label:`OpenAI`,url:`https://api.openai.com/v1`,model:``,hint:`your account's models — pick from the list once the endpoint answers`},{key:`opencode-go`,label:`OpenCode Go`,url:`https://opencode.ai/zen/go/v1`,model:``,hint:`OpenCode's open-model subscription — teapot sends the required x-opencode-session header; choose a chat/completions model`},{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)`}];function Xh(e){return(()=>{var t=pm(),n=t.firstChild;return R(t,()=>e.label,n),n.$$input=t=>e.onValue(Number(t.currentTarget.value)),y(()=>I(t,`title`,e.hint)),y(()=>n.value=e.value),t})()}function Zh(e){let t=(e,t)=>{let n=Array.isArray(t?.apiKeys)&&t.apiKeys.length?t.apiKeys.filter(e=>typeof e==`string`&&e.trim()):t?.apiKey?[String(t.apiKey)]:[``];return{name:e,baseUrl:t?.baseUrl??``,apiKeys:n.length?n:[``],model:t?.model??``}},[n,r]=v(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=v(e.cfg.defaultProvider??``),o=()=>e.cfg.defaultProvider??``,s=()=>{let e=[...new Set(n().map(e=>e.name.trim()).filter(Boolean))],t=i();return t&&!e.includes(t)&&e.push(t),e},c=()=>{let e=i();return e?n().some(t=>t.name.trim()===e)?``:e:``},[l,u]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=v(e.cfg.progressMinChars??4e3),[p,m]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,x]=v(e.cfg.maxSpawnDepth??3),[S,ee]=v(!!e.cfg.shortContext),[C,w]=v((e.cfg.tasks??[]).map(e=>({...e}))),[te,T]=v((e.cfg.mcpServers??[]).map(e=>({...e}))),[ne,E]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[re,ie]=v({}),[D,O]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=e.headers??{},r=Object.keys(n);if(!r.length)return[t,`none`];let i=r.length===1?r[0]:``;return i===`Authorization`&&/^Bearer /i.test(n[i]??``)?[t,`bearer`]:[t,r.length===1?`header`:`json`]}))),[ae,oe]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=e.headers??{},r=Object.keys(n);if(r.length!==1)return[t,``];let i=r[0];return[t,i===`Authorization`?(n[i]??``).replace(/^Bearer /i,``):n[i]??``]}))),[se,ce]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=Object.keys(e.headers??{}),r=n.length===1?n[0]:``;return[t,r&&r!==`Authorization`?r:``]}))),[le,k]=v({}),[ue,A]=v({}),[de,fe]=v({}),pe=e=>{let t=String(e??``).trim();if(!t)return null;let n=de()[t];return n&&(n.required||n.authorized)?n:null},me=async()=>{let e=await $(`/api/mcp`).catch(()=>null);A(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},he=async e=>{let t=String(e??``).trim();if(!t)return;let n=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&fe(e=>({...e,[t]:n}))},ge=async(t,n)=>{if(!n.name){k(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}k(e=>({...e,[t]:{kind:`testing`,text:`discovering the authorization server…`}}));let r=await $(`/api/mcp/oauth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name})}).catch(()=>null);if(r?.alreadyAuthorized){k(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await he(n.name),await me();return}if(!r?.ok||!r.url){k(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await he(n.name);return}window.open(r.url,`_blank`,`noopener`),k(e=>({...e,[t]:{kind:`testing`,text:`waiting for you to finish in the browser…`}}));let i=Date.now()+3e5;for(;Date.now()<i;){await new Promise(e=>setTimeout(e,1e3));let r=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(n.name)}`).catch(()=>null);if(r&&!r.error){if(fe(e=>({...e,[t]:r})),r.authorized){k(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await me(),e.onSaved();return}if(r.flow?.phase===`error`){k(e=>({...e,[t]:{kind:`err`,text:r.flow.message??r.lastError??`authorization failed`}}));return}}}k(e=>({...e,[t]:{kind:`err`,text:`authorization timed out`}}))};b(()=>{ye()===`mcp`&&(me(),te().forEach((e,t)=>{e.name&&he(e.name)}))});let[_e,ve]=v(``),[ye,xe]=v(`providers`),Se=(t,n)=>{let{slot:r}=vt(e.theme.auto(),n);r===`dark`?e.theme.setDark(t):r===`light`?e.theme.setLight(t):e.theme.setActive(t)},Ce=t=>yt({auto:e.theme.auto(),fixed:e.theme.activeId(),dark:e.theme.dark(),light:e.theme.light(),prefersLight:typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-color-scheme: light)`).matches})===t,[F,we]=v([]),Te=async()=>{let e=await $(`/api/archived`).catch(()=>null);we(e?.agents??[])},Ee=()=>F().filter(e=>!e.parent);b(()=>{ye()===`archive`&&Te()});let De=[{key:`providers`,label:`🧦 providers`,hint:`endpoints, API keys, default models`},{key:`appearance`,label:`🎨 appearance`,hint:`theme, custom palettes, background image`},{key:`runtime`,label:`⚙️ runtime`,hint:`context budget, retries, spawn depth`},{key:`tasks`,label:`⏰ scheduled tasks`,hint:`cron prompts run against an agent`},{key:`mcp`,label:`🔌 MCP servers`,hint:`external tool servers exposed to every agent`},{key:`archive`,label:`🗄 archive`,hint:`agents you put away — restore or delete for good`},{key:`agents`,label:`👥 agents`,hint:`what exists (read-only)`},{key:`update`,label:`⬆️ live update`,hint:`restart onto a newer build`},{key:`skills`,label:`🧠 skills`,hint:`reusable playbooks available to the selected session`},{key:`help`,label:`❔ help`,hint:`keyboard shortcuts and what each toggle does`}],Oe=()=>(e.cfg.agents??[]).map(e=>e.id),ke=()=>e.theme.themes(),Ae=()=>e.theme.activeId(),je=()=>{let t=e.theme.paintedId();return e.theme.themes().find(e=>e.id===t)?.mode??uh.find(e=>e.key===t)?.mode??`dark`},Me=t=>e.theme.setActive(t),Ne=()=>e.theme.auto(),Pe=t=>e.theme.setAuto(t),Fe=()=>e.theme.dark(),Ie=t=>e.theme.setDark(t),Le=()=>e.theme.light(),Re=t=>e.theme.setLight(t),ze=t=>e.theme.setThemes(t),Be=e=>dn[e]??un,Ve=()=>{let e={};for(let t of n()){if(!t.name.trim())return ve(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return ve(`provider ${t.name}: baseUrl must start with http(s)://`),null;let n=t.apiKeys.map(e=>e.trim()).filter(Boolean);e[t.name.trim()]={baseUrl:t.baseUrl,...n.length?{apiKeys:n,apiKey:n[0]}:{},...t.model?{model:t.model}:{}}}return e},[He,Ue]=v(`idle`),We=e=>{ve(e),Ue(e=>e===`saving`?`idle`:e)},Ge=async t=>{t.preventDefault(),ve(``),Ue(`saving`);let n=Ve();if(!n)return Ue(`idle`);let r=C().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 r){if(!e.agent)return We(`task "${e.id}": agent is required`);if(!e.schedule?.trim())return We(`task "${e.id}": schedule is required`)}let a=[],o=new Set;for(let e of te()){let t=String(e.name??``).trim(),n=String(e.url??``).trim(),r=e.transport??`http`,i=String(e.command??``).trim();if(t||n||i){if(!t)return We(`MCP: a server needs a name`);if(o.has(t))return We(`MCP: two servers are named "${t}"`);if(o.add(t),r===`stdio`?!i:!n)return We(`MCP "${t}": ${r===`stdio`?`a command is`:`a url is`} required`);a.push({name:t,transport:r,enabled:e.enabled!==!1,...n?{url:n}:{},...r===`stdio`?{command:i,...e.args?.length?{args:e.args}:{}}:{},...e.headers&&Object.keys(e.headers).length?{headers:e.headers}:{}})}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:i()||void 0,progressIntervalMs:Math.max(1,l())*6e4,progressMinChars:Math.max(100,d()),...p()==null?{}:{contextTokenBudget:Math.max(1,p())*1e3},...h()>0?{contextWindowTokens:h()*1e3}:{},maxSpawnDepth:Math.max(0,_()),shortContext:S(),tasks:r,mcpServers:a})}),await me(),await Promise.all(a.map((e,t)=>e.name?he(e.name):Promise.resolve())),setTimeout(()=>{me(),a.forEach((e,t)=>{e.name&&he(e.name)})},1200),e.onSaved();let t=new Set(a.map(e=>e.name).filter(Boolean)),o=te().filter(e=>{let n=String(e.name??``).trim();return t.has(n)&&de()[n]?.required&&!de()[n]?.authorized}).filter(t=>!e.announcedOAuth.has(String(t.name??``)));if(o.length>0){for(let t of o)e.announcedOAuth.add(String(t.name??``));Q(`${o.map(e=>String(e.name??``).trim()).filter(Boolean).join(`, `)||`a saved MCP server`} needs authorization — 🔑 authorize in MCP servers`)}Ue(`saved`),setTimeout(()=>{Ue(`idle`),e.onClose()},400)}catch(e){ve(e.message),Ue(`error`),setTimeout(()=>Ue(`idle`),1600)}};return j(Fh,{title:`settings`,get onClose(){return e.onClose},get children(){var t=_m(),b=t.firstChild,A=b.firstChild,fe=A.nextSibling.firstChild,me=fe.firstChild.nextSibling,F=me.nextSibling;F.firstChild;var we=F.nextSibling.firstChild.firstChild.nextSibling;we.firstChild;var Ve=fe.nextSibling,Ue=Ve.firstChild.nextSibling,We=Ue.firstChild.firstChild.nextSibling,Ke=Ue.nextSibling,qe=Ve.nextSibling,Je=qe.firstChild.nextSibling,Ye=Je.firstChild,Xe=Ye.firstChild.nextSibling,Ze=Je.nextSibling.firstChild,Qe=qe.nextSibling,$e=Qe.firstChild.nextSibling.nextSibling,et=Qe.nextSibling,tt=et.firstChild.nextSibling,nt=et.nextSibling;nt.firstChild;var rt=nt.nextSibling;rt.firstChild;var it=rt.nextSibling,at=it.firstChild.nextSibling.firstChild;at.firstChild;var ot=at.nextSibling,st=it.nextSibling,ct=st.firstChild.nextSibling.firstChild,lt=ct.firstChild.nextSibling,ut=ct.nextSibling.firstChild.nextSibling,dt=st.nextSibling,ft=b.nextSibling,pt=ft.firstChild;return t.addEventListener(`submit`,Ge),R(A,j(M,{each:De,children:e=>(()=>{var t=vm(),n=t.firstChild;return t.$$click=()=>xe(e.key),R(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(ye()===e.key?` on`:``),i=e.hint,a=ye()===e.key?`page`:void 0;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),a!==n.a&&I(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),R(fe,j(be,{get each(){return n()},children:(e,t)=>(()=>{var i=ym(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.firstChild;return a.$$input=e=>r(n().map((n,r)=>r===t?{...n,name:e.currentTarget.value}:n)),o.$$input=e=>r(n().map((n,r)=>r===t?{...n,baseUrl:e.currentTarget.value}:n)),s.$$input=e=>r(n().map((n,r)=>r===t?{...n,model:e.currentTarget.value}:n)),c.$$click=()=>r(n().filter((e,n)=>n!==t)),R(l,j(M,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=xm(),s=o.firstChild;return s.$$input=e=>r(n().map((n,r)=>r===t?{...n,apiKeys:n.apiKeys.map((t,n)=>n===a()?e.currentTarget.value:t)}:n)),s.value=i,R(o,j(N,{get when(){return e().apiKeys.length>1},get children(){var e=bm();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>I(s,`placeholder`,a()===0?`api key`:`api key (backup)`)),o})()}),u),u.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:[...e.apiKeys,``]}:e)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().model),i})()}),me),me.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),R(F,j(M,{each:Yh,children:e=>(()=>{var t=Sm();return t.firstChild,t.$$click=()=>{let t=n().filter(t=>t.name!==e.key);r([...t,{name:e.key,baseUrl:e.url,apiKeys:[``],model:e.model}]),i()||a(e.key)},R(t,()=>e.label,null),y(()=>I(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),we.addEventListener(`change`,e=>a(e.currentTarget.value)),R(we,j(M,{get each(){return s()},children:e=>(()=>{var t=Yd();return t.value=e,R(t,e),t})()}),null),R(fe,j(N,{get when(){return c()},get children(){var e=mm(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return R(t,c),R(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),R(r,c),e}}),null),We.addEventListener(`change`,e=>{Pe(e.currentTarget.checked),localStorage.setItem(`teapot.theme.auto`,e.currentTarget.checked?`1`:`0`)}),R(Ve,j(N,{get when(){return Ne()},get children(){var e=hm(),t=e.firstChild,n=t.firstChild.nextSibling,r=t.nextSibling.firstChild.nextSibling;return n.addEventListener(`change`,e=>{Ie(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),R(n,j(M,{get each(){return ke().filter(e=>e.mode===`dark`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(uh.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=Yd();return R(t,()=>e.label),y(()=>t.value=e.key),t})()})),r.addEventListener(`change`,e=>{Re(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),R(r,j(M,{get each(){return ke().filter(e=>e.mode===`light`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(uh.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=Yd();return R(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>n.value=Fe()),y(()=>r.value=Le()),e}}),Ke),R(Ve,j(M,{each:[{mode:`dark`,title:`dark themes`},{mode:`light`,title:`light themes`}],children:e=>j(N,{get when(){return P(()=>!![...ke(),...uh].some(t=>t.mode===e.mode))()&&(Ne()||je()===e.mode)},get children(){return[(()=>{var t=Cm();return R(t,()=>e.title),t})(),(()=>{var t=wm();return R(t,j(M,{get each(){return ke().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=Tm(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>Se(e.id,e.mode),R(n,j(Wh,{get palette(){return e.palette},get backgroundImage(){return e.backgroundImage}})),R(r,()=>e.label,i),y(n=>{var r=`themecard`+(Ce(e.id)?` on`:``),i=`${e.label} (custom)${e.backgroundImage?` · with a background image`:``}`,a=Ce(e.id);return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),a!==n.a&&I(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),R(t,j(M,{get each(){return uh.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=Em(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>Se(e.key,e.mode),R(n,j(Wh,{get palette(){return Be(e.key)}})),R(r,()=>e.label),y(n=>{var r=`themecard`+(Ce(e.key)?` on`:``),i=`${e.label} (${e.mode})`,a=Ce(e.key);return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),a!==n.a&&I(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),t})()]}})}),null),R(Ve,j(Gh,{themes:ke,get activeId(){return Ae()},get paintedId(){return e.theme.paintedId()},onChange:e=>{let t=hn(e),n=e;if(!t.ok){let t=e.map(e=>e.backgroundImage?{...e,backgroundImage:void 0,backgroundDim:void 0,surfaceAlpha:void 0,backgroundImageBytes:void 0}:e),r=hn(t);if(r.ok)n=t,Q(`storage was full — saved without the background image(s)`);else{Q(r.error??`could not save theme`);return}}ze(n);let r=e=>n.some(t=>t.id===e)||uh.some(t=>t.key===e);r(Ae())||(Me(`dark`),localStorage.setItem(`teapot.theme`,`dark`)),r(Fe())||(Ie(`dark`),localStorage.setItem(`teapot.theme.dark`,`dark`)),r(Le())||(Re(`light`),localStorage.setItem(`teapot.theme.light`,`light`))},onPick:e=>{let t=ke().find(t=>t.id===e)?.mode??uh.find(t=>t.key===e)?.mode??`dark`,n=vt(Ne(),t);n.slot===`dark`?Ie(e):n.slot===`light`?Re(e):Me(e),localStorage.setItem(n.key,e)}}),null),R(Je,j(Xh,{label:`progress interval (min)`,get value(){return l()},onValue:e=>u(e),hint:`how often the harness asks for a progress report`}),Ye),R(Je,j(Xh,{label:`progress min chars`,get value(){return d()},onValue:e=>f(e),hint:`progress prompts wait for this much real output`}),Ye),Xe.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),R(Je,j(Xh,{label:`context window (k tok)`,get value(){return h()},onValue:e=>g(e),hint:`model's real window — 0/blank hides the % gauge`}),null),R(Je,j(Xh,{label:`max spawn depth`,get value(){return _()},onValue:e=>x(e),hint:`sub-agent nesting limit (0 = no spawning)`}),null),Ze.addEventListener(`change`,e=>ee(e.currentTarget.checked)),R(Qe,j(N,{get when(){return te().length>0},get fallback(){return Dm()},get children(){return j(be,{get each(){return te()},children:(e,t)=>{let n=()=>ue()[e().name],r=e=>T(te().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=Rm(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.nextSibling,l=c.firstChild,u=c.nextSibling,d=a.nextSibling,f=d.firstChild,p=d.nextSibling,m=p.firstChild,h=m.firstChild,g=p.nextSibling,_=g.firstChild;return o.$$input=e=>r({name:e.currentTarget.value}),s.$$input=e=>r({url:e.currentTarget.value}),l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>T(te().filter((e,n)=>n!==t)),f.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),R(d,j(N,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=Om();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=km();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),y(()=>t.value=(e().args??[]).join(` `)),t})()]}}),null),m.addEventListener(`change`,e=>{let n=e.currentTarget.value;if(O(e=>({...e,[t]:n})),n===`none`)r({headers:void 0});else if(n===`bearer`){let e=ae()[t]??``;r({headers:e?{Authorization:`Bearer ${e}`}:void 0})}else if(n===`header`){let e=se()[t]??``,n=ae()[t]??``;r({headers:e&&n?{[e]:n}:void 0})}}),R(m,j(N,{get when(){return pe(String(e().name??``))},children:e=>(()=>{var t=zm();return R(t,()=>e().authorized?`OAuth — authorized`:`OAuth — authorization needed`),t})()}),h),R(p,j(N,{get when(){return D()[t]===`bearer`},get children(){var e=Am();return e.$$input=e=>{let n=e.currentTarget.value;oe(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},y(()=>e.value=ae()[t]??``),e}}),null),R(p,j(N,{get when(){return D()[t]===`header`},get children(){return[(()=>{var e=jm();return e.$$input=e=>{let n=e.currentTarget.value;ce(e=>({...e,[t]:n}));let i=ae()[t]??``;r({headers:n&&i?{[n]:i}:void 0})},y(()=>e.value=se()[t]??``),e})(),(()=>{var e=Mm();return e.$$input=e=>{let n=e.currentTarget.value;oe(e=>({...e,[t]:n}));let i=se()[t]??``;r({headers:i&&n?{[i]:n}:void 0})},y(()=>e.value=ae()[t]??``),e})()]}}),null),R(i,j(N,{get when(){return D()[t]===`json`},get children(){var e=Nm(),n=e.firstChild;return n.$$input=e=>{let n=e.currentTarget.value;if(E(e=>({...e,[t]:n})),!n.trim())r({headers:void 0});else try{let e=JSON.parse(n);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`not an object`);r({headers:e}),ie(e=>({...e,[t]:``}))}catch{ie(e=>({...e,[t]:`must be a JSON object — not applied`}))}},y(()=>n.value=ne()[t]??``),e}}),g),_.$$click=async()=>{let e=te()[t];if(!e.name){k(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}k(e=>({...e,[t]:{kind:`testing`,text:`connecting…`}}));let n=await $(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}).catch(()=>null);k(e=>({...e,[t]:n?.ok?{kind:`ok`,text:`${n.tools?.length??0} tool${n.tools?.length===1?``:`s`}`,tools:n.tools??[]}:{kind:`err`,text:n?.error??`no response`,...n?.needsOAuth?{needsOAuth:!0}:{}}})),n?.ok||await he(e.name)},R(g,j(N,{get when(){return P(()=>!!de()[String(e().name??``).trim()]?.required)()&&!de()[String(e().name??``).trim()]?.authorized},get children(){var n=Pm();return n.$$click=()=>void ge(t,e()),n}}),null),R(g,j(N,{get when(){return de()[String(e().name??``).trim()]?.authorized},get children(){return[Fm(),(()=>{var n=Im();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await he(e().name),k(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),R(g,j(N,{get when(){return n()},get children(){var e=Ad();return R(e,(()=>{var e=P(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:P(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&L(e,t.e=r),i!==t.t&&I(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),R(i,j(N,{get when(){return re()[t]},get children(){var e=Lm();return R(e,()=>re()[t]),e}}),null),R(i,j(N,{get when(){return le()[t]},children:e=>(()=>{var t=Hm(),n=t.firstChild,r=n.firstChild;return R(r,()=>e().text),R(n,j(N,{get when(){return e().needsOAuth},get children(){return Bm()}}),null),R(t,j(N,{get when(){return(e().tools?.length??0)>0},get children(){var t=Vm();return R(t,j(M,{get each(){return e().tools??[]},children:e=>(()=>{var t=Wm(),n=t.firstChild;return R(n,()=>e.name),R(t,j(N,{get when(){return e.description},get children(){var t=Um();return R(t,()=>e.description),t}}),null),y(()=>I(t,`title`,e.description??``)),t})()})),t}}),null),y(()=>L(t,`mcpresult `+(e().kind===`err`?`err`:`ok`))),t})()}),null),y(()=>o.value=e().name),y(()=>s.value=e().url??``),y(()=>l.checked=e().enabled!==!1),y(()=>f.value=e().transport??`http`),y(()=>m.value=pe(String(e().name??``))?`oauth`:D()[t]??`none`),i})()}})}}),$e),$e.$$click=()=>T([...te(),{name:``,url:``,transport:`http`,enabled:!0}]),R(et,j(N,{get when(){return C().length>0},get children(){return j(be,{get each(){return C()},children:(e,t)=>(()=>{var n=Gm(),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=>w(C().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>w(C().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>w(C().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>w(C().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>w(C().filter((e,n)=>n!==t)),u.$$input=e=>w(C().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})()})}}),tt),tt.$$click=()=>w([...C(),{id:``,agent:Oe()[0]??``,schedule:`every 30m`,prompt:``}]),R(nt,j(N,{get when(){return Ee().length>0},get fallback(){return Km()},get children(){return j(M,{get each(){return Ee()},children:t=>(()=>{var n=qm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return R(i,()=>t.id),R(a,()=>t.sessions,o),R(a,()=>t.sessions===1?``:`s`,null),R(a,(()=>{var e=P(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),R(a,(()=>{var e=P(()=>!!t.archivedAt);return()=>e()?` · archived ${kh(new Date(t.archivedAt).toISOString())}`:``})(),null),R(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await Te(),e.onSaved();let r=(n?.ids?.length??1)-1;Q((n?.live===!1?`restored ${t.id} — it could not be started (check its provider)`:`restored ${t.id}`)+(r>0?` + ${r} sub-agent${r===1?``:`s`}`:``))},l.$$click=async()=>{confirm(`PERMANENTLY DELETE ${t.id}?\n\n${t.sessions} session${t.sessions===1?``:`s`} of history will be erased from disk along with the config entry. This cannot be undone — archiving was the reversible option.`)&&(await $(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await Te(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>I(s,`title`,t.workspace)),n})()})}}),null),R(rt,j(M,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Ym(),n=t.firstChild,r=n.nextSibling;return R(n,()=>e.id),R(r,()=>e.workspace),R(t,j(N,{get when(){return e.parent},get children(){var t=Jm();return t.firstChild,R(t,()=>e.parent,null),t}}),null),t})()}),null),R(at,()=>e.cfg.version??`unknown`,null),ot.$$click=async e=>{try{ve(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await $(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=!1;for(let e=0;e<90&&!r;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await $(`/api/version`);e.version&&e.version!==`0.36.5`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){ve(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},R(lt,(()=>{var t=P(()=>!!e.features);return()=>t()?P(()=>!!e.features.imageResize.available)()?`on — ${e.features.imageResize.tool}, long edge ≤ ${e.features.imageResize.maxEdge}px`:`off — no ffmpeg / ImageMagick found; uploads are served as-is`:`checking…`})()),R(ut,(()=>{var t=P(()=>!!e.features);return()=>t()?P(()=>!!e.features.pty.available)()?`on — ${e.features.pty.provider}`:`off — no pty provider; terminals run on plain pipes (no resize)`:`checking…`})()),R(st,j(N,{get when(){return e.skills.length>0},get fallback(){return(()=>{var t=Xm();return R(t,()=>e.hasSelection?`this session has no skills yet — the agent saves them with save_skill once a procedure proves itself`:`select a session to see the skills available to it`),t})()},get children(){var t=gm();return R(t,j(M,{get each(){return e.skills},children:t=>{let[n,r]=v(!1),[i,a]=v(null),[o,s]=v(``),c=async()=>{if(n())return r(!1);if(r(!0),i()===null&&e.agentId)try{let n=await $(`/api/agents/${e.agentId}/skills/${encodeURIComponent(t.name)}`);a(String(n.text??``))}catch(e){s(e.message)}};return(()=>{var e=Qm(),r=e.firstChild,a=r.firstChild,s=a.nextSibling,l=s.nextSibling;return r.$$click=c,R(a,()=>n()?`▾`:`▸`),R(s,()=>t.name),R(l,()=>t.description),R(e,j(N,{get when(){return n()},get children(){return j(N,{get when(){return i()!==null},get fallback(){return(()=>{var e=$m();return R(e,()=>o()||`loading…`),e})()},get children(){var e=Zm();return y(()=>e.innerHTML=th(String(i()??``))),e}})}}),null),y(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),R(ft,j(N,{get when(){return _e()},get children(){var e=kp();return R(e,_e),e}}),pt),R(pt,(()=>{var e=P(()=>He()===`saving`);return()=>e()?`saving…`:P(()=>He()===`saved`)()?`✓ saved`:He()===`error`?`✕ failed`:`save settings`})()),y(e=>{var t=ye()!==`providers`,n=ye()!==`appearance`,r=ye()!==`runtime`,i=ye()!==`mcp`,a=ye()!==`tasks`,o=ye()!==`archive`,s=ye()!==`agents`,c=ye()!==`update`,l=ye()!==`skills`,u=ye()!==`help`,d=He()===`saved`,f=He()===`error`,p=He()===`saving`;return t!==e.e&&fe.classList.toggle(`hide`,e.e=t),n!==e.t&&Ve.classList.toggle(`hide`,e.t=n),r!==e.a&&qe.classList.toggle(`hide`,e.a=r),i!==e.o&&Qe.classList.toggle(`hide`,e.o=i),a!==e.i&&et.classList.toggle(`hide`,e.i=a),o!==e.n&&nt.classList.toggle(`hide`,e.n=o),s!==e.s&&rt.classList.toggle(`hide`,e.s=s),c!==e.h&&it.classList.toggle(`hide`,e.h=c),l!==e.r&&st.classList.toggle(`hide`,e.r=l),u!==e.d&&dt.classList.toggle(`hide`,e.d=u),d!==e.l&&pt.classList.toggle(`saved`,e.l=d),f!==e.u&&pt.classList.toggle(`error`,e.u=f),p!==e.c&&(pt.disabled=e.c=p),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0,c:void 0}),y(()=>we.value=i()),y(()=>We.checked=Ne()),y(()=>Xe.value=p()??``),y(()=>Ze.checked=S()),t}})}we([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Ce(()=>j(yh,{}),document.getElementById(`root`));export{Cu as t};
|
|
31
|
-
//# sourceMappingURL=index-
|
|
30
|
+
Cancel = keep editing your copy`)?(ue(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{de(!1)}}},_e=e=>!e.binary&&!e.truncated,ve=(e,t)=>[(()=>{var n=Yp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ae(e):void he(e,`code`),R(r,(()=>{var t=P(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Uh(e.name)})()),R(a,()=>e.name),R(n,j(N,{get when(){return P(()=>!e.dir)()&&e.size!==void 0},get children(){var t=Jp();return R(t,()=>Nh(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&L(n,r.e=i),r.t=Ee(n,a,r.t),o!==r.a&&I(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),j(N,{get when(){return P(()=>!!e.dir)()&&i().has(e.path)},get children(){return j(M,{get each(){return(n().get(e.path)??[]).filter(w)},children:e=>ve(e,t+1)})}})],ye=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[be,xe]=v(!1),Se=async()=>{if(!be()){xe(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await ie(e,te())})));for(let{p:e,rows:n}of t)n&&D(e,n)}finally{xe(!1)}}};return[(()=>{var e=Xp(),t=e.firstChild.nextSibling;return t.firstChild,R(t,ye,null),R(e,j(Ih,{class:`filetoggle`,get icon(){return be()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void Se()}),null),R(e,j(Ih,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return P(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),R(e,j(Ih,{class:`filetoggle`,get icon(){return te()?`◉.`:`○.`},get title(){return te()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:ne}),null),e})(),(()=>{var e=Zp();return R(e,j(N,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=Qp();return R(e,()=>g()||`empty workspace`),e})()},get children(){return j(M,{get each(){return(n().get(``)??[]).filter(w)},children:e=>ve(e,0)})}})),e})(),j(N,{get when(){return o()},children:t=>j(Rh,{get title(){return`🗂 ${t().path}`},onClose:()=>{pe++,c(null),f(null)},get children(){return j(N,{get when(){return u()},get fallback(){return[(()=>{var e=rm(),n=e.firstChild;return R(e,j(N,{get when(){return P(()=>!!fe(t().path))()&&!t().binary},get children(){var e=tm();return e.$$click=()=>h(`md`),y(()=>L(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),oe()||me({path:t().path,content:t().content,truncated:t().truncated})},R(e,j(N,{get when(){return _e(t())},get children(){var e=nm();return e.$$click=()=>h(`edit`),y(()=>L(e,p()===`edit`?`on`:``)),e}}),null),y(()=>L(n,p()===`code`?`on`:``)),e})(),j(N,{get when(){return!t().binary},get fallback(){return am()},get children(){return j(N,{get when(){return p()===`edit`},get fallback(){return j(N,{get when(){return P(()=>p()===`md`)()&&fe(t().path)},get fallback(){return j(Zh,{get path(){return t().path},get content(){return t().content},get html(){return oe()},get pending(){return ce()},get truncated(){return!!t().truncated}})},get children(){var e=om();return y(()=>e.innerHTML=Ie(t().content)),e}})},get children(){var e=im(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>ue(e.currentTarget.value),I(n,`spellcheck`,!1),R(r,()=>Nh(k().length),i),a.$$click=()=>void ge(),R(a,()=>A()?`saving…`:`💾 save`),y(()=>a.disabled=A()||k()===t().content),y(()=>n.value=k()),e}})}})]},get children(){var t=em(),n=t.firstChild,r=n.firstChild;return R(t,j(N,{get when(){return u().kind===`image`},get fallback(){return j(N,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=cm();return y(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=sm();return y(()=>I(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=$p();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&I(t,`src`,n.e=r),i!==n.t&&I(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),R(n,()=>u().kind,r),t}})}})})]}function Zh(e){return[j(N,{get when(){return e.html},get fallback(){return P(()=>!!e.pending)()?(()=>{var t=dm(),n=t.firstChild.nextSibling;return n.nextSibling,R(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=fm();return R(t,()=>e.content),t})()},get children(){var t=lm();return y(()=>t.innerHTML=e.html),t}}),j(N,{get when(){return e.truncated},get children(){return um()}})]}var Qh=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:``,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:``,hint:`zero-markup routing gateway — 'orcarouter/auto' grades each prompt and picks the model`},{key:`openai`,label:`OpenAI`,url:`https://api.openai.com/v1`,model:``,hint:`your account's models — pick from the list once the endpoint answers`},{key:`opencode-go`,label:`OpenCode Go`,url:`https://opencode.ai/zen/go/v1`,model:``,hint:`OpenCode's open-model subscription — teapot sends the required x-opencode-session header; choose a chat/completions model`},{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)`}];function $h(e){return(()=>{var t=pm(),n=t.firstChild;return R(t,()=>e.label,n),n.$$input=t=>e.onValue(Number(t.currentTarget.value)),y(()=>I(t,`title`,e.hint)),y(()=>n.value=e.value),t})()}function eg(e){let t=(e,t)=>{let n=Array.isArray(t?.apiKeys)&&t.apiKeys.length?t.apiKeys.filter(e=>typeof e==`string`&&e.trim()):t?.apiKey?[String(t.apiKey)]:[``];return{name:e,baseUrl:t?.baseUrl??``,apiKeys:n.length?n:[``],model:t?.model??``}},[n,r]=v(Object.entries(e.cfg.providers??{}).map(([e,n])=>t(e,n))),[i,a]=v(e.cfg.defaultProvider??``),o=()=>e.cfg.defaultProvider??``,s=()=>{let e=[...new Set(n().map(e=>e.name.trim()).filter(Boolean))],t=i();return t&&!e.includes(t)&&e.push(t),e},c=()=>{let e=i();return e?n().some(t=>t.name.trim()===e)?``:e:``},[l,u]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[d,f]=v(e.cfg.progressMinChars??4e3),[p,m]=v(e.cfg.contextTokenBudget==null?null:Math.round(e.cfg.contextTokenBudget/1e3)),[h,g]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[_,x]=v(e.cfg.maxSpawnDepth??3),[S,ee]=v(!!e.cfg.shortContext),[C,w]=v((e.cfg.tasks??[]).map(e=>({...e}))),[te,T]=v((e.cfg.mcpServers??[]).map(e=>({...e}))),[ne,E]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[re,ie]=v({}),[D,O]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=e.headers??{},r=Object.keys(n);if(!r.length)return[t,`none`];let i=r.length===1?r[0]:``;return i===`Authorization`&&/^Bearer /i.test(n[i]??``)?[t,`bearer`]:[t,r.length===1?`header`:`json`]}))),[ae,oe]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=e.headers??{},r=Object.keys(n);if(r.length!==1)return[t,``];let i=r[0];return[t,i===`Authorization`?(n[i]??``).replace(/^Bearer /i,``):n[i]??``]}))),[se,ce]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>{let n=Object.keys(e.headers??{}),r=n.length===1?n[0]:``;return[t,r&&r!==`Authorization`?r:``]}))),[le,k]=v({}),[ue,A]=v({}),[de,fe]=v({}),pe=e=>{let t=String(e??``).trim();if(!t)return null;let n=de()[t];return n&&(n.required||n.authorized)?n:null},me=async()=>{let e=await $(`/api/mcp`).catch(()=>null);A(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},he=async e=>{let t=String(e??``).trim();if(!t)return;let n=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(t)}`).catch(()=>null);n&&!n.error&&fe(e=>({...e,[t]:n}))},ge=async(t,n)=>{if(!n.name){k(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}k(e=>({...e,[t]:{kind:`testing`,text:`discovering the authorization server…`}}));let r=await $(`/api/mcp/oauth/start`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:n.name})}).catch(()=>null);if(r?.alreadyAuthorized){k(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await he(n.name),await me();return}if(!r?.ok||!r.url){k(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await he(n.name);return}window.open(r.url,`_blank`,`noopener`),k(e=>({...e,[t]:{kind:`testing`,text:`waiting for you to finish in the browser…`}}));let i=Date.now()+3e5;for(;Date.now()<i;){await new Promise(e=>setTimeout(e,1e3));let r=await $(`/api/mcp/oauth/status?name=${encodeURIComponent(n.name)}`).catch(()=>null);if(r&&!r.error){if(fe(e=>({...e,[t]:r})),r.authorized){k(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await me(),e.onSaved();return}if(r.flow?.phase===`error`){k(e=>({...e,[t]:{kind:`err`,text:r.flow.message??r.lastError??`authorization failed`}}));return}}}k(e=>({...e,[t]:{kind:`err`,text:`authorization timed out`}}))};b(()=>{ye()===`mcp`&&(me(),te().forEach((e,t)=>{e.name&&he(e.name)}))});let[_e,ve]=v(``),[ye,xe]=v(`providers`),Se=(t,n)=>{let{slot:r}=vt(e.theme.auto(),n);r===`dark`?e.theme.setDark(t):r===`light`?e.theme.setLight(t):e.theme.setActive(t)},Ce=t=>yt({auto:e.theme.auto(),fixed:e.theme.activeId(),dark:e.theme.dark(),light:e.theme.light(),prefersLight:typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-color-scheme: light)`).matches})===t,[F,we]=v([]),Te=async()=>{let e=await $(`/api/archived`).catch(()=>null);we(e?.agents??[])},Ee=()=>F().filter(e=>!e.parent);b(()=>{ye()===`archive`&&Te()});let De=[{key:`providers`,label:`🧦 providers`,hint:`endpoints, API keys, default models`},{key:`appearance`,label:`🎨 appearance`,hint:`theme, custom palettes, background image`},{key:`runtime`,label:`⚙️ runtime`,hint:`context budget, retries, spawn depth`},{key:`tasks`,label:`⏰ scheduled tasks`,hint:`cron prompts run against an agent`},{key:`mcp`,label:`🔌 MCP servers`,hint:`external tool servers exposed to every agent`},{key:`archive`,label:`🗄 archive`,hint:`agents you put away — restore or delete for good`},{key:`agents`,label:`👥 agents`,hint:`what exists (read-only)`},{key:`update`,label:`⬆️ live update`,hint:`restart onto a newer build`},{key:`skills`,label:`🧠 skills`,hint:`reusable playbooks available to the selected session`},{key:`help`,label:`❔ help`,hint:`keyboard shortcuts and what each toggle does`}],Oe=()=>(e.cfg.agents??[]).map(e=>e.id),ke=()=>e.theme.themes(),Ae=()=>e.theme.activeId(),je=()=>{let t=e.theme.paintedId();return e.theme.themes().find(e=>e.id===t)?.mode??uh.find(e=>e.key===t)?.mode??`dark`},Me=t=>e.theme.setActive(t),Ne=()=>e.theme.auto(),Pe=t=>e.theme.setAuto(t),Fe=()=>e.theme.dark(),Ie=t=>e.theme.setDark(t),Le=()=>e.theme.light(),Re=t=>e.theme.setLight(t),ze=t=>e.theme.setThemes(t),Be=e=>dn[e]??un,Ve=()=>{let e={};for(let t of n()){if(!t.name.trim())return ve(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return ve(`provider ${t.name}: baseUrl must start with http(s)://`),null;let n=t.apiKeys.map(e=>e.trim()).filter(Boolean);e[t.name.trim()]={baseUrl:t.baseUrl,...n.length?{apiKeys:n,apiKey:n[0]}:{},...t.model?{model:t.model}:{}}}return e},[He,Ue]=v(`idle`),We=e=>{ve(e),Ue(e=>e===`saving`?`idle`:e)},Ge=async t=>{t.preventDefault(),ve(``),Ue(`saving`);let n=Ve();if(!n)return Ue(`idle`);let r=C().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 r){if(!e.agent)return We(`task "${e.id}": agent is required`);if(!e.schedule?.trim())return We(`task "${e.id}": schedule is required`)}let a=[],o=new Set;for(let e of te()){let t=String(e.name??``).trim(),n=String(e.url??``).trim(),r=e.transport??`http`,i=String(e.command??``).trim();if(t||n||i){if(!t)return We(`MCP: a server needs a name`);if(o.has(t))return We(`MCP: two servers are named "${t}"`);if(o.add(t),r===`stdio`?!i:!n)return We(`MCP "${t}": ${r===`stdio`?`a command is`:`a url is`} required`);a.push({name:t,transport:r,enabled:e.enabled!==!1,...n?{url:n}:{},...r===`stdio`?{command:i,...e.args?.length?{args:e.args}:{}}:{},...e.headers&&Object.keys(e.headers).length?{headers:e.headers}:{}})}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:i()||void 0,progressIntervalMs:Math.max(1,l())*6e4,progressMinChars:Math.max(100,d()),...p()==null?{}:{contextTokenBudget:Math.max(1,p())*1e3},...h()>0?{contextWindowTokens:h()*1e3}:{},maxSpawnDepth:Math.max(0,_()),shortContext:S(),tasks:r,mcpServers:a})}),await me(),await Promise.all(a.map((e,t)=>e.name?he(e.name):Promise.resolve())),setTimeout(()=>{me(),a.forEach((e,t)=>{e.name&&he(e.name)})},1200),e.onSaved();let t=new Set(a.map(e=>e.name).filter(Boolean)),o=te().filter(e=>{let n=String(e.name??``).trim();return t.has(n)&&de()[n]?.required&&!de()[n]?.authorized}).filter(t=>!e.announcedOAuth.has(String(t.name??``)));if(o.length>0){for(let t of o)e.announcedOAuth.add(String(t.name??``));Q(`${o.map(e=>String(e.name??``).trim()).filter(Boolean).join(`, `)||`a saved MCP server`} needs authorization — 🔑 authorize in MCP servers`)}Ue(`saved`),setTimeout(()=>{Ue(`idle`),e.onClose()},400)}catch(e){ve(e.message),Ue(`error`),setTimeout(()=>Ue(`idle`),1600)}};return j(Rh,{title:`settings`,get onClose(){return e.onClose},get children(){var t=_m(),b=t.firstChild,A=b.firstChild,fe=A.nextSibling.firstChild,me=fe.firstChild.nextSibling,F=me.nextSibling;F.firstChild;var we=F.nextSibling.firstChild.firstChild.nextSibling;we.firstChild;var Ve=fe.nextSibling,Ue=Ve.firstChild.nextSibling,We=Ue.firstChild.firstChild.nextSibling,Ke=Ue.nextSibling,qe=Ve.nextSibling,Je=qe.firstChild.nextSibling,Ye=Je.firstChild,Xe=Ye.firstChild.nextSibling,Ze=Je.nextSibling.firstChild,Qe=qe.nextSibling,$e=Qe.firstChild.nextSibling.nextSibling,et=Qe.nextSibling,tt=et.firstChild.nextSibling,nt=et.nextSibling;nt.firstChild;var rt=nt.nextSibling;rt.firstChild;var it=rt.nextSibling,at=it.firstChild.nextSibling.firstChild;at.firstChild;var ot=at.nextSibling,st=it.nextSibling,ct=st.firstChild.nextSibling.firstChild,lt=ct.firstChild.nextSibling,ut=ct.nextSibling.firstChild.nextSibling,dt=st.nextSibling,ft=b.nextSibling,pt=ft.firstChild;return t.addEventListener(`submit`,Ge),R(A,j(M,{each:De,children:e=>(()=>{var t=vm(),n=t.firstChild;return t.$$click=()=>xe(e.key),R(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(ye()===e.key?` on`:``),i=e.hint,a=ye()===e.key?`page`:void 0;return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),a!==n.a&&I(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),R(fe,j(be,{get each(){return n()},children:(e,t)=>(()=>{var i=ym(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling,u=l.firstChild;return a.$$input=e=>r(n().map((n,r)=>r===t?{...n,name:e.currentTarget.value}:n)),o.$$input=e=>r(n().map((n,r)=>r===t?{...n,baseUrl:e.currentTarget.value}:n)),s.$$input=e=>r(n().map((n,r)=>r===t?{...n,model:e.currentTarget.value}:n)),c.$$click=()=>r(n().filter((e,n)=>n!==t)),R(l,j(M,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=xm(),s=o.firstChild;return s.$$input=e=>r(n().map((n,r)=>r===t?{...n,apiKeys:n.apiKeys.map((t,n)=>n===a()?e.currentTarget.value:t)}:n)),s.value=i,R(o,j(N,{get when(){return e().apiKeys.length>1},get children(){var e=bm();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>I(s,`placeholder`,a()===0?`api key`:`api key (backup)`)),o})()}),u),u.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:[...e.apiKeys,``]}:e)),y(()=>a.value=e().name),y(()=>o.value=e().baseUrl),y(()=>s.value=e().model),i})()}),me),me.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),R(F,j(M,{each:Qh,children:e=>(()=>{var t=Sm();return t.firstChild,t.$$click=()=>{let t=n().filter(t=>t.name!==e.key);r([...t,{name:e.key,baseUrl:e.url,apiKeys:[``],model:e.model}]),i()||a(e.key)},R(t,()=>e.label,null),y(()=>I(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),we.addEventListener(`change`,e=>a(e.currentTarget.value)),R(we,j(M,{get each(){return s()},children:e=>(()=>{var t=Yd();return t.value=e,R(t,e),t})()}),null),R(fe,j(N,{get when(){return c()},get children(){var e=mm(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return R(t,c),R(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),R(r,c),e}}),null),We.addEventListener(`change`,e=>{Pe(e.currentTarget.checked),localStorage.setItem(`teapot.theme.auto`,e.currentTarget.checked?`1`:`0`)}),R(Ve,j(N,{get when(){return Ne()},get children(){var e=hm(),t=e.firstChild,n=t.firstChild.nextSibling,r=t.nextSibling.firstChild.nextSibling;return n.addEventListener(`change`,e=>{Ie(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),R(n,j(M,{get each(){return ke().filter(e=>e.mode===`dark`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(uh.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=Yd();return R(t,()=>e.label),y(()=>t.value=e.key),t})()})),r.addEventListener(`change`,e=>{Re(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),R(r,j(M,{get each(){return ke().filter(e=>e.mode===`light`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(uh.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=Yd();return R(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>n.value=Fe()),y(()=>r.value=Le()),e}}),Ke),R(Ve,j(M,{each:[{mode:`dark`,title:`dark themes`},{mode:`light`,title:`light themes`}],children:e=>j(N,{get when(){return P(()=>!![...ke(),...uh].some(t=>t.mode===e.mode))()&&(Ne()||je()===e.mode)},get children(){return[(()=>{var t=Cm();return R(t,()=>e.title),t})(),(()=>{var t=wm();return R(t,j(M,{get each(){return ke().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=Tm(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>Se(e.id,e.mode),R(n,j(qh,{get palette(){return e.palette},get backgroundImage(){return e.backgroundImage}})),R(r,()=>e.label,i),y(n=>{var r=`themecard`+(Ce(e.id)?` on`:``),i=`${e.label} (custom)${e.backgroundImage?` · with a background image`:``}`,a=Ce(e.id);return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),a!==n.a&&I(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),R(t,j(M,{get each(){return uh.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=Em(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>Se(e.key,e.mode),R(n,j(qh,{get palette(){return Be(e.key)}})),R(r,()=>e.label),y(n=>{var r=`themecard`+(Ce(e.key)?` on`:``),i=`${e.label} (${e.mode})`,a=Ce(e.key);return r!==n.e&&L(t,n.e=r),i!==n.t&&I(t,`title`,n.t=i),a!==n.a&&I(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),t})()]}})}),null),R(Ve,j(Jh,{themes:ke,get activeId(){return Ae()},get paintedId(){return e.theme.paintedId()},onChange:e=>{let t=hn(e),n=e;if(!t.ok){let t=e.map(e=>e.backgroundImage?{...e,backgroundImage:void 0,backgroundDim:void 0,surfaceAlpha:void 0,backgroundImageBytes:void 0}:e),r=hn(t);if(r.ok)n=t,Q(`storage was full — saved without the background image(s)`);else{Q(r.error??`could not save theme`);return}}ze(n);let r=e=>n.some(t=>t.id===e)||uh.some(t=>t.key===e);r(Ae())||(Me(`dark`),localStorage.setItem(`teapot.theme`,`dark`)),r(Fe())||(Ie(`dark`),localStorage.setItem(`teapot.theme.dark`,`dark`)),r(Le())||(Re(`light`),localStorage.setItem(`teapot.theme.light`,`light`))},onPick:e=>{let t=ke().find(t=>t.id===e)?.mode??uh.find(t=>t.key===e)?.mode??`dark`,n=vt(Ne(),t);n.slot===`dark`?Ie(e):n.slot===`light`?Re(e):Me(e),localStorage.setItem(n.key,e)}}),null),R(Je,j($h,{label:`progress interval (min)`,get value(){return l()},onValue:e=>u(e),hint:`how often the harness asks for a progress report`}),Ye),R(Je,j($h,{label:`progress min chars`,get value(){return d()},onValue:e=>f(e),hint:`progress prompts wait for this much real output`}),Ye),Xe.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),R(Je,j($h,{label:`context window (k tok)`,get value(){return h()},onValue:e=>g(e),hint:`model's real window — 0/blank hides the % gauge`}),null),R(Je,j($h,{label:`max spawn depth`,get value(){return _()},onValue:e=>x(e),hint:`sub-agent nesting limit (0 = no spawning)`}),null),Ze.addEventListener(`change`,e=>ee(e.currentTarget.checked)),R(Qe,j(N,{get when(){return te().length>0},get fallback(){return Dm()},get children(){return j(be,{get each(){return te()},children:(e,t)=>{let n=()=>ue()[e().name],r=e=>T(te().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=Rm(),a=i.firstChild,o=a.firstChild,s=o.nextSibling,c=s.nextSibling,l=c.firstChild,u=c.nextSibling,d=a.nextSibling,f=d.firstChild,p=d.nextSibling,m=p.firstChild,h=m.firstChild,g=p.nextSibling,_=g.firstChild;return o.$$input=e=>r({name:e.currentTarget.value}),s.$$input=e=>r({url:e.currentTarget.value}),l.addEventListener(`change`,e=>r({enabled:e.currentTarget.checked})),u.$$click=()=>T(te().filter((e,n)=>n!==t)),f.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),R(d,j(N,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=Om();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=km();return t.$$input=e=>r({args:e.currentTarget.value.split(` `).filter(Boolean)}),y(()=>t.value=(e().args??[]).join(` `)),t})()]}}),null),m.addEventListener(`change`,e=>{let n=e.currentTarget.value;if(O(e=>({...e,[t]:n})),n===`none`)r({headers:void 0});else if(n===`bearer`){let e=ae()[t]??``;r({headers:e?{Authorization:`Bearer ${e}`}:void 0})}else if(n===`header`){let e=se()[t]??``,n=ae()[t]??``;r({headers:e&&n?{[e]:n}:void 0})}}),R(m,j(N,{get when(){return pe(String(e().name??``))},children:e=>(()=>{var t=zm();return R(t,()=>e().authorized?`OAuth — authorized`:`OAuth — authorization needed`),t})()}),h),R(p,j(N,{get when(){return D()[t]===`bearer`},get children(){var e=Am();return e.$$input=e=>{let n=e.currentTarget.value;oe(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},y(()=>e.value=ae()[t]??``),e}}),null),R(p,j(N,{get when(){return D()[t]===`header`},get children(){return[(()=>{var e=jm();return e.$$input=e=>{let n=e.currentTarget.value;ce(e=>({...e,[t]:n}));let i=ae()[t]??``;r({headers:n&&i?{[n]:i}:void 0})},y(()=>e.value=se()[t]??``),e})(),(()=>{var e=Mm();return e.$$input=e=>{let n=e.currentTarget.value;oe(e=>({...e,[t]:n}));let i=se()[t]??``;r({headers:i&&n?{[i]:n}:void 0})},y(()=>e.value=ae()[t]??``),e})()]}}),null),R(i,j(N,{get when(){return D()[t]===`json`},get children(){var e=Nm(),n=e.firstChild;return n.$$input=e=>{let n=e.currentTarget.value;if(E(e=>({...e,[t]:n})),!n.trim())r({headers:void 0});else try{let e=JSON.parse(n);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`not an object`);r({headers:e}),ie(e=>({...e,[t]:``}))}catch{ie(e=>({...e,[t]:`must be a JSON object — not applied`}))}},y(()=>n.value=ne()[t]??``),e}}),g),_.$$click=async()=>{let e=te()[t];if(!e.name){k(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}k(e=>({...e,[t]:{kind:`testing`,text:`connecting…`}}));let n=await $(`/api/mcp/test`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e)}).catch(()=>null);k(e=>({...e,[t]:n?.ok?{kind:`ok`,text:`${n.tools?.length??0} tool${n.tools?.length===1?``:`s`}`,tools:n.tools??[]}:{kind:`err`,text:n?.error??`no response`,...n?.needsOAuth?{needsOAuth:!0}:{}}})),n?.ok||await he(e.name)},R(g,j(N,{get when(){return P(()=>!!de()[String(e().name??``).trim()]?.required)()&&!de()[String(e().name??``).trim()]?.authorized},get children(){var n=Pm();return n.$$click=()=>void ge(t,e()),n}}),null),R(g,j(N,{get when(){return de()[String(e().name??``).trim()]?.authorized},get children(){return[Fm(),(()=>{var n=Im();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await he(e().name),k(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),R(g,j(N,{get when(){return n()},get children(){var e=Ad();return R(e,(()=>{var e=P(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:P(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&L(e,t.e=r),i!==t.t&&I(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),R(i,j(N,{get when(){return re()[t]},get children(){var e=Lm();return R(e,()=>re()[t]),e}}),null),R(i,j(N,{get when(){return le()[t]},children:e=>(()=>{var t=Hm(),n=t.firstChild,r=n.firstChild;return R(r,()=>e().text),R(n,j(N,{get when(){return e().needsOAuth},get children(){return Bm()}}),null),R(t,j(N,{get when(){return(e().tools?.length??0)>0},get children(){var t=Vm();return R(t,j(M,{get each(){return e().tools??[]},children:e=>(()=>{var t=Wm(),n=t.firstChild;return R(n,()=>e.name),R(t,j(N,{get when(){return e.description},get children(){var t=Um();return R(t,()=>e.description),t}}),null),y(()=>I(t,`title`,e.description??``)),t})()})),t}}),null),y(()=>L(t,`mcpresult `+(e().kind===`err`?`err`:`ok`))),t})()}),null),y(()=>o.value=e().name),y(()=>s.value=e().url??``),y(()=>l.checked=e().enabled!==!1),y(()=>f.value=e().transport??`http`),y(()=>m.value=pe(String(e().name??``))?`oauth`:D()[t]??`none`),i})()}})}}),$e),$e.$$click=()=>T([...te(),{name:``,url:``,transport:`http`,enabled:!0}]),R(et,j(N,{get when(){return C().length>0},get children(){return j(be,{get each(){return C()},children:(e,t)=>(()=>{var n=Gm(),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=>w(C().map((n,r)=>r===t?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>w(C().map((n,r)=>r===t?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>w(C().map((n,r)=>r===t?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>w(C().map((n,r)=>r===t?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>w(C().filter((e,n)=>n!==t)),u.$$input=e=>w(C().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})()})}}),tt),tt.$$click=()=>w([...C(),{id:``,agent:Oe()[0]??``,schedule:`every 30m`,prompt:``}]),R(nt,j(N,{get when(){return Ee().length>0},get fallback(){return Km()},get children(){return j(M,{get each(){return Ee()},children:t=>(()=>{var n=qm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return R(i,()=>t.id),R(a,()=>t.sessions,o),R(a,()=>t.sessions===1?``:`s`,null),R(a,(()=>{var e=P(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),R(a,(()=>{var e=P(()=>!!t.archivedAt);return()=>e()?` · archived ${Mh(new Date(t.archivedAt).toISOString())}`:``})(),null),R(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await Te(),e.onSaved();let r=(n?.ids?.length??1)-1;Q((n?.live===!1?`restored ${t.id} — it could not be started (check its provider)`:`restored ${t.id}`)+(r>0?` + ${r} sub-agent${r===1?``:`s`}`:``))},l.$$click=async()=>{confirm(`PERMANENTLY DELETE ${t.id}?\n\n${t.sessions} session${t.sessions===1?``:`s`} of history will be erased from disk along with the config entry. This cannot be undone — archiving was the reversible option.`)&&(await $(`/api/agents/${t.id}/purge`,{method:`DELETE`}).catch(()=>{}),await Te(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>I(s,`title`,t.workspace)),n})()})}}),null),R(rt,j(M,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Ym(),n=t.firstChild,r=n.nextSibling;return R(n,()=>e.id),R(r,()=>e.workspace),R(t,j(N,{get when(){return e.parent},get children(){var t=Jm();return t.firstChild,R(t,()=>e.parent,null),t}}),null),t})()}),null),R(at,()=>e.cfg.version??`unknown`,null),ot.$$click=async e=>{try{ve(``);let t=e.currentTarget;t.disabled=!0,t.textContent=`updating…`;let n=await $(`/api/update/restart`,{method:`POST`});if(!n.ok)throw Error((await n.json()).error??`restart failed`);t.textContent=`restarting…`;let r=!1;for(let e=0;e<90&&!r;e++){await new Promise(e=>setTimeout(e,1e3));try{let e=await $(`/api/version`);e.version&&e.version!==`0.36.6`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){ve(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},R(lt,(()=>{var t=P(()=>!!e.features);return()=>t()?P(()=>!!e.features.imageResize.available)()?`on — ${e.features.imageResize.tool}, long edge ≤ ${e.features.imageResize.maxEdge}px`:`off — no ffmpeg / ImageMagick found; uploads are served as-is`:`checking…`})()),R(ut,(()=>{var t=P(()=>!!e.features);return()=>t()?P(()=>!!e.features.pty.available)()?`on — ${e.features.pty.provider}`:`off — no pty provider; terminals run on plain pipes (no resize)`:`checking…`})()),R(st,j(N,{get when(){return e.skills.length>0},get fallback(){return(()=>{var t=Xm();return R(t,()=>e.hasSelection?`this session has no skills yet — the agent saves them with save_skill once a procedure proves itself`:`select a session to see the skills available to it`),t})()},get children(){var t=gm();return R(t,j(M,{get each(){return e.skills},children:t=>{let[n,r]=v(!1),[i,a]=v(null),[o,s]=v(``),c=async()=>{if(n())return r(!1);if(r(!0),i()===null&&e.agentId)try{let n=await $(`/api/agents/${e.agentId}/skills/${encodeURIComponent(t.name)}`);a(String(n.text??``))}catch(e){s(e.message)}};return(()=>{var e=Qm(),r=e.firstChild,a=r.firstChild,s=a.nextSibling,l=s.nextSibling;return r.$$click=c,R(a,()=>n()?`▾`:`▸`),R(s,()=>t.name),R(l,()=>t.description),R(e,j(N,{get when(){return n()},get children(){return j(N,{get when(){return i()!==null},get fallback(){return(()=>{var e=$m();return R(e,()=>o()||`loading…`),e})()},get children(){var e=Zm();return y(()=>e.innerHTML=th(String(i()??``))),e}})}}),null),y(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),R(ft,j(N,{get when(){return _e()},get children(){var e=kp();return R(e,_e),e}}),pt),R(pt,(()=>{var e=P(()=>He()===`saving`);return()=>e()?`saving…`:P(()=>He()===`saved`)()?`✓ saved`:He()===`error`?`✕ failed`:`save settings`})()),y(e=>{var t=ye()!==`providers`,n=ye()!==`appearance`,r=ye()!==`runtime`,i=ye()!==`mcp`,a=ye()!==`tasks`,o=ye()!==`archive`,s=ye()!==`agents`,c=ye()!==`update`,l=ye()!==`skills`,u=ye()!==`help`,d=He()===`saved`,f=He()===`error`,p=He()===`saving`;return t!==e.e&&fe.classList.toggle(`hide`,e.e=t),n!==e.t&&Ve.classList.toggle(`hide`,e.t=n),r!==e.a&&qe.classList.toggle(`hide`,e.a=r),i!==e.o&&Qe.classList.toggle(`hide`,e.o=i),a!==e.i&&et.classList.toggle(`hide`,e.i=a),o!==e.n&&nt.classList.toggle(`hide`,e.n=o),s!==e.s&&rt.classList.toggle(`hide`,e.s=s),c!==e.h&&it.classList.toggle(`hide`,e.h=c),l!==e.r&&st.classList.toggle(`hide`,e.r=l),u!==e.d&&dt.classList.toggle(`hide`,e.d=u),d!==e.l&&pt.classList.toggle(`saved`,e.l=d),f!==e.u&&pt.classList.toggle(`error`,e.u=f),p!==e.c&&(pt.disabled=e.c=p),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0,l:void 0,u:void 0,c:void 0}),y(()=>we.value=i()),y(()=>We.checked=Ne()),y(()=>Xe.value=p()??``),y(()=>Ze.checked=S()),t}})}we([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Ce(()=>j(yh,{}),document.getElementById(`root`));export{Cu as t};
|
|
31
|
+
//# sourceMappingURL=index-MXkEkm6p.js.map
|