teapot-coding-agent 0.35.15 → 0.35.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/agent.js +104 -10
- package/dist/agent/compact-rules.js +123 -0
- package/package.json +1 -1
- package/public/assets/{index-U0afHQC8.js → index-CnvxbU1K.js} +6 -6
- package/public/assets/index-CnvxbU1K.js.map +1 -0
- package/public/assets/index-Dmi9LMj-.css +1 -0
- package/public/assets/{shiki-BzdfW5Bh.js → shiki-CT0bGajG.js} +2 -2
- package/public/assets/{shiki-BzdfW5Bh.js.map → shiki-CT0bGajG.js.map} +1 -1
- package/public/index.html +2 -2
- package/public/assets/index-DgvUnJm-.css +0 -1
- package/public/assets/index-U0afHQC8.js.map +0 -1
|
@@ -18,13 +18,13 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
|
|
|
18
18
|
`))),this._register(this._terminal.onA11yTab(e=>this._handleTab(e))),this._register(this._terminal.onKey(e=>this._handleKey(e.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(q(i,`selectionchange`,()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(U(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<Wl+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
|
|
19
19
|
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===Wl+1&&(this._liveRegion.textContent+=xn.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})`}};Gl=V([H(1,Jn),H(2,rr),H(3,ar)],Gl);var Kl=class extends W{constructor(e,t,n,r,i){super(),this._element=e,this._mouseService=t,this._renderService=n,this._bufferService=r,this._linkProviderService=i,this._linkCacheDisposables=[],this._isMouseOut=!0,this._wasResized=!1,this._activeLine=-1,this._onShowLinkUnderline=this._register(new K),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new K),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(U(()=>{Or(this._linkCacheDisposables),this._linkCacheDisposables.length=0,this._lastMouseEvent=void 0,this._activeProviderReplies?.clear()})),this._register(this._bufferService.onResize(()=>{this._clearCurrentLink(),this._wasResized=!0})),this._register(q(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(q(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(q(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(q(this._element,`mouseup`,this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){this._activeLine!==e.y||this._wasResized?(this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1):this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){(!this._activeProviderReplies||!t)&&(this._activeProviderReplies?.forEach(e=>{e?.forEach(e=>{e.link.dispose&&e.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,t=>{if(this._isMouseOut)return;let i=t?.map(e=>({link:e}));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)(!this._activeProviderReplies.has(t)||this._activeProviderReplies.get(t))&&(i=!0);if(!i&&r){let e=r.find(e=>this._linkAtPosition(e.link,t));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find(e=>this._linkAtPosition(e.link,t));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&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,Or(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}}};Kl=V([H(1,ir),H(2,ar),H(3,Wn),H(4,lr)],Kl);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 Jl=class extends Nl{constructor(e={}){super(e),this._linkifier=this._register(new Mr),this.browser=cs,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new Mr),this._onCursorMove=this._register(new K),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new K),this.onKey=this._onKey.event,this._onRender=this._register(new K),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new K),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new K),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new K),this.onBell=this._onBell.event,this._onFocus=this._register(new K),this._onBlur=this._register(new K),this._onA11yCharEmitter=this._register(new K),this._onA11yTabEmitter=this._register(new K),this._onWillOpen=this._register(new K),this._setup(),this._decorationService=this._instantiationService.createInstance(Bl),this._instantiationService.setService($n,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(rs),this._instantiationService.setService(lr,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(er)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(e=>this.refresh(e?.start??0,e?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(e=>this._reportWindowsOptions(e))),this._register(this._inputHandler.onColor(e=>this._handleColorEvent(e))),this._register(Rr.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(Rr.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(Rr.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(Rr.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(U(()=>{this._customKeyEventHandler=void 0,this.element?.parentNode?.removeChild(this.element)}))}get linkifier(){return this._linkifier.value}get onFocus(){return this._onFocus.event}get onBlur(){return this._onBlur.event}get onA11yChar(){return this._onA11yCharEmitter.event}get onA11yTab(){return this._onA11yTabEmitter.event}get onWillOpen(){return this._onWillOpen.event}_handleColorEvent(e){if(this._themeService)for(let t of e){let e,n=``;switch(t.index){case 256:e=`foreground`,n=`10`;break;case 257:e=`background`,n=`11`;break;case 258:e=`cursor`,n=`12`;break;default:e=`ansi`,n=`4;`+t.index}switch(t.type){case 0:let r=Y.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${J.ESC}]${n};${_l(r)}${vo.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=To.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=To.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(Gl,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(J.ESC+`[I`),this.element.classList.add(`focus`),this._showCursor(),this._onFocus.fire()}blur(){return this.textarea?.blur()}_handleTextAreaBlur(){this.textarea.value=``,this.refresh(this.buffer.y,this.buffer.y),this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(J.ESC+`[O`),this.element.classList.remove(`focus`),this._onBlur.fire()}_syncTextArea(){if(!this.textarea||!this.buffer.isCursorInViewport||this._compositionHelper.isComposing||!this._renderService)return;let e=this.buffer.ybase+this.buffer.y,t=this.buffer.lines.get(e);if(!t)return;let n=Math.min(this.buffer.x,this.cols-1),r=this._renderService.dimensions.css.cell.height,i=t.getWidth(n),a=this._renderService.dimensions.css.cell.width*i,o=this.buffer.y*this._renderService.dimensions.css.cell.height,s=n*this._renderService.dimensions.css.cell.width;this.textarea.style.left=s+`px`,this.textarea.style.top=o+`px`,this.textarea.style.width=a+`px`,this.textarea.style.height=r+`px`,this.textarea.style.lineHeight=r+`px`,this.textarea.style.zIndex=`-5`}_initGlobal(){this._bindKeys(),this._register(q(this.element,`copy`,e=>{this.hasSelection()&&wn(e,this._selectionService)}));let e=e=>Tn(e,this.textarea,this.coreService,this.optionsService);this._register(q(this.textarea,`paste`,e)),this._register(q(this.element,`paste`,e)),fs?this._register(q(this.element,`mousedown`,e=>{e.button===2&&On(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(q(this.element,`contextmenu`,e=>{On(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),bs&&this._register(q(this.element,`auxclick`,e=>{e.button===1&&Dn(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(q(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(q(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(q(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(q(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(q(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(q(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(q(this.textarea,`input`,e=>this._inputEvent(e),!0)),this._register(this.onRender(()=>this._compositionHelper.updateCompositionElements()))}open(e){if(!e)throw Error(`Terminal requires a parent element.`);if(e.isConnected||this._logService.debug(`Terminal.open was called on an element that was not attached to the DOM`),this.element?.ownerDocument.defaultView&&this._coreBrowserService){this.element.ownerDocument.defaultView!==this._coreBrowserService.window&&(this._coreBrowserService.window=this.element.ownerDocument.defaultView);return}this._document=e.ownerDocument,this.options.documentOverride&&this.options.documentOverride instanceof Document&&(this._document=this.optionsService.rawOptions.documentOverride),this.element=this._document.createElement(`div`),this.element.dir=`ltr`,this.element.classList.add(`terminal`),this.element.classList.add(`xterm`),e.appendChild(this.element);let t=this._document.createDocumentFragment();this._viewportElement=this._document.createElement(`div`),this._viewportElement.classList.add(`xterm-viewport`),t.appendChild(this._viewportElement),this.screenElement=this._document.createElement(`div`),this.screenElement.classList.add(`xterm-screen`),this._register(q(this.screenElement,`mousemove`,e=>this.updateCursorStyle(e))),this._helperContainer=this._document.createElement(`div`),this._helperContainer.classList.add(`xterm-helpers`),this.screenElement.appendChild(this._helperContainer),t.appendChild(this.screenElement);let n=this.textarea=this._document.createElement(`textarea`);this.textarea.classList.add(`xterm-helper-textarea`),this.textarea.setAttribute(`aria-label`,yn.get()),xs||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(ts,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(rr,this._coreBrowserService),this._register(q(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(q(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(Zo,this._document,this._helperContainer),this._instantiationService.setService(nr,this._charSizeService),this._themeService=this._instantiationService.createInstance(ac),this._instantiationService.setService(cr,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(Mo),this._instantiationService.setService(sr,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Ds,this.rows,this.screenElement)),this._instantiationService.setService(ar,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(yo,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(os),this._instantiationService.setService(ir,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(Kl,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(lo,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(Ys,this.element,this.screenElement,r)),this._instantiationService.setService(or,this._selectionService),this._register(this._selectionService.onRequestScrollLines(e=>this.scrollLines(e.amount,e.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()})),this._register(Rr.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(uo,this.screenElement)),this._register(q(this.element,`mousedown`,e=>this._selectionService.handleMouseDown(e))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add(`enable-mouse-events`)):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(Gl,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(go,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(go,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(Xo,this,this._document,this.element,this.screenElement,this._viewportElement,this._helperContainer,this.linkifier)}bindMouse(){let e=this,t=this.element;function n(t){let n=e._mouseService.getMouseReportCoords(t,e.screenElement);if(!n)return!1;let r,i;switch(t.overrideType||t.type){case`mousemove`:i=32,t.buttons===void 0?(r=3,t.button!==void 0&&(r=t.button<3?t.button:3)):r=t.buttons&1?0:t.buttons&4?1:t.buttons&2?2:3;break;case`mouseup`:i=0,r=t.button<3?t.button:3;break;case`mousedown`:i=1,r=t.button<3?t.button:3;break;case`wheel`:if(e._customWheelEventHandler&&e._customWheelEventHandler(t)===!1)return!1;let n=t.deltaY;if(n===0||e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return!1;i=n<0?0:1,r=4;break;default:return!1}return i===void 0||r===void 0||r>4?!1:e.coreMouseService.triggerMouseEvent({col:n.col,row:n.row,x:n.x,y:n.y,button:r,action:i,ctrl:t.ctrlKey,alt:t.altKey,shift:t.shiftKey})}let r={mouseup:null,wheel:null,mousedrag:null,mousemove:null},i={mouseup:e=>(n(e),e.buttons||(this._document.removeEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.removeEventListener(`mousemove`,r.mousedrag)),this.cancel(e)),wheel:e=>(n(e),this.cancel(e,!0)),mousedrag:e=>{e.buttons&&n(e)},mousemove:e=>{e.buttons||n(e)}};this._register(this.coreMouseService.onProtocolChange(e=>{e?(this.optionsService.rawOptions.logLevel===`debug`&&this._logService.debug(`Binding to mouse events:`,this.coreMouseService.explainEvents(e)),this.element.classList.add(`enable-mouse-events`),this._selectionService.disable()):(this._logService.debug(`Unbinding from mouse events.`),this.element.classList.remove(`enable-mouse-events`),this._selectionService.enable()),e&8?r.mousemove||=(t.addEventListener(`mousemove`,i.mousemove),i.mousemove):(t.removeEventListener(`mousemove`,r.mousemove),r.mousemove=null),e&16?r.wheel||=(t.addEventListener(`wheel`,i.wheel,{passive:!1}),i.wheel):(t.removeEventListener(`wheel`,r.wheel),r.wheel=null),e&2?r.mouseup||=i.mouseup:(this._document.removeEventListener(`mouseup`,r.mouseup),r.mouseup=null),e&4?r.mousedrag||=i.mousedrag:(this._document.removeEventListener(`mousemove`,r.mousedrag),r.mousedrag=null)})),this.coreMouseService.activeProtocol=this.coreMouseService.activeProtocol,this._register(q(t,`mousedown`,e=>{if(e.preventDefault(),this.focus(),this.coreMouseService.areMouseEventsActive&&!this._selectionService.shouldForceSelection(e))return n(e),r.mouseup&&this._document.addEventListener(`mouseup`,r.mouseup),r.mousedrag&&this._document.addEventListener(`mousemove`,r.mousedrag),this.cancel(e)})),this._register(q(t,`wheel`,t=>{if(!r.wheel){if(this._customWheelEventHandler&&this._customWheelEventHandler(t)===!1)return!1;if(!this.buffer.hasScrollback){if(t.deltaY===0)return!1;if(e.coreMouseService.consumeWheelEvent(t,e._renderService?.dimensions?.device?.cell?.height,e._coreBrowserService?.dpr)===0)return this.cancel(t,!0);let n=J.ESC+(this.coreService.decPrivateModes.applicationCursorKeys?`O`:`[`)+(t.deltaY<0?`A`:`B`);return this.coreService.triggerDataEvent(n,!0),this.cancel(t,!0)}}},{passive:!1}))}refresh(e,t){this._renderService?.refreshRows(e,t)}updateCursorStyle(e){this._selectionService?.shouldColumnSelect(e)?this.element.classList.add(`column-select`):this.element.classList.remove(`column-select`)}_showCursor(){this.coreService.isCursorInitialized||(this.coreService.isCursorInitialized=!0,this.refresh(this.buffer.y,this.buffer.y))}scrollLines(e,t){this._viewport?this._viewport.scrollLines(e):super.scrollLines(e,t),this.refresh(0,this.rows-1)}scrollPages(e){this.scrollLines(e*(this.rows-1))}scrollToTop(){this.scrollLines(-this._bufferService.buffer.ydisp)}scrollToBottom(e){e&&this._viewport?this._viewport.scrollToLine(this.buffer.ybase,!0):this.scrollLines(this._bufferService.buffer.ybase-this._bufferService.buffer.ydisp)}scrollToLine(e){let t=e-this._bufferService.buffer.ydisp;t!==0&&this.scrollLines(t)}paste(e){En(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=Fl(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),n.type===3||n.type===2){let t=this.rows-1;return this.scrollLines(n.type===2?-t:t),this.cancel(e,!0)}if(n.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(n.cancel&&this.cancel(e,!0),!n.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((n.key===J.ETX||n.key===J.CR)&&(this.textarea.value=``),this._onKey.fire({key:n.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(n.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let n=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState(`AltGraph`);return t.type===`keypress`?n:n&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(Yl(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(pc));this._onScroll.fire({position:this.buffer.ydisp}),this.refresh(0,this.rows-1)}}reset(){this.options.rows=this.rows,this.options.cols=this.cols;let e=this._customKeyEventHandler;this._setup(),super.reset(),this._selectionService?.reset(),this._decorationService.reset(),this._customKeyEventHandler=e,this.refresh(0,this.rows-1)}clearTextureAtlas(){this._renderService?.clearTextureAtlas()}_reportFocus(){this.element?.classList.contains(`focus`)?this.coreService.triggerDataEvent(J.ESC+`[I`):this.coreService.triggerDataEvent(J.ESC+`[O`)}_reportWindowsOptions(e){if(this._renderService)switch(e){case 0:let e=this._renderService.dimensions.css.canvas.width.toFixed(0),t=this._renderService.dimensions.css.canvas.height.toFixed(0);this.coreService.triggerDataEvent(`${J.ESC}[4;${t};${e}t`);break;case 1:let n=this._renderService.dimensions.css.cell.width.toFixed(0),r=this._renderService.dimensions.css.cell.height.toFixed(0);this.coreService.triggerDataEvent(`${J.ESC}[6;${r};${n}t`)}}cancel(e,t){if(this.options.cancelEvents||t)return e.preventDefault(),e.stopPropagation(),!1}};function Yl(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var Xl=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)}},Zl=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 Ln)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},Ql=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 Zl(t)}getNullCell(){return new Ln}},$l=class extends W{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new K),this.onBufferChange=this._onBufferChange.event,this._normal=new Ql(this._core.buffers.normal,`normal`),this._alternate=new Ql(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)}},eu=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)}},tu=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}},nu=[`cols`,`rows`],ru=0,iu=class extends W{constructor(e){super(),this._core=this._register(new Jl(e)),this._addonManager=this._register(new Xl),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(nu.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 eu(this._core),this._parser}get unicode(){return this._checkProposedApi(),new tu(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 $l(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 yn.get()},set promptLabel(e){yn.set(e)},get tooMuchOutput(){return xn.get()},set tooMuchOutput(e){xn.set(e)}}}_verifyIntegers(...e){for(ru of e)if(ru===1/0||isNaN(ru)||ru%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(ru of e)if(ru&&(ru===1/0||isNaN(ru)||ru%1!=0||ru<0))throw Error(`This API only accepts positive integers`)}},au=2,ou=1,su=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(au,Math.floor(u/e.css.cell.width)),rows:Math.max(ou,Math.floor(l/e.css.cell.height))}}};function cu(e){return e.length}function lu(e,t){return t<=0||e<0?-1:Math.min(e,t-1)}function uu(e,t,n){return lu(e===t?t:e>t?e-1:e,n)}function du(e,t){return Array.from({length:t},(e,t)=>t).find(t=>t!==e)??-1}function fu(e,t){let n=e.filter(e=>!t.has(e.id));return n.find(e=>!e.workspaceMissing)??n[0]??null}var pu=`modulepreload`,mu=function(e){return`/`+e},hu={},gu=function(e){return e.pathname.endsWith(`.css`)},_u=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},vu=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=mu(t,n);let r=s(t),i=gu(r);return _u(hu,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`:pu,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)})},yu=I(`<div class=overlay><div class=modal style=max-width:360px><div class=modal-head><b>🔒 sign in</b><span></span></div><form style=display:flex;flex-direction:column;gap:10px><input id=pw-input type=password placeholder=password autofocus><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:7px 12px;cursor:pointer">unlock</button><span class=muted style=font-size:11px>the token is stored locally and sent as Bearer to this server only`),bu=I(`<i class=notifdot>`),xu=I(`<br>`),Su=I(`<span class="badge queued">⏳ <!> of yours queued`),Cu=I(`<span class="badge cron">⏰ `),wu=I(`<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>`),Tu=I(`<div class=divider-msg>── beginning of log ──`),Eu=I(`<div class=divider-msg>loading older events…`),Du=I(`<details class=reasoning open><summary>💭 thinking </summary><div class="mono thinkscroll">`),Ou=I(`<div class=muted style=font-size:11.5px;margin-bottom:4px>🗜 summarizing older context…`),ku=I(`<div class=content>`),Au=I(`<div class="msg live"><div class=avatar style="background:#5865f233;border:1px solid #5865f266">🫖</div><div class=msg-body><div class=msg-head><span class=author style=color:var(--acc)>agent</span><span class=ts>streaming…`),ju=I(`<div class=feed>`),Mu=I(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),Nu=I(`<div class=termsplit>`),Pu=I(`<div class="termempty muted">no shell here — click a tab or + to add`),Fu=I(`<div class=termpane>`),Iu=I(`<div class=termdrawer><div class=termgrip title="drag to resize · double-click to reset"></div><div class=termbar><div class=termtabs></div><div style=display:flex;gap:4px;align-items:center><span class="muted mono"style=flex:1;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span></div></div><div class=termbody><div class=termpane>`),Lu=I(`<button class=jump>↓ `),Ru=I(`<div class=cmds>`),zu=I(`<div class=imgstage><span class=muted style=font-size:11px;align-self:center> image<!> attached`),Bu=I(`<label class=forkchip title="inherit the conversation prefix byte-exactly — the sub-agent's provider prefix cache starts warm"><input type=checkbox>fork ctx`),Vu=I(`<span class=muted style=font-size:11.5px;white-space:nowrap>🖼 `),Hu=I(`<div class="hint flashhint">`),Uu=I(`<div><form><textarea rows=1></textarea><button type=button class="iconbtn maxbtn"></button><button type=submit>send</button><input id=composer-file type=file accept=image/* multiple style=display:none>`),Wu=I(`<div class=rightbarbackdrop>`),Gu=I(`<div><nav class=sidebar><div class=agent-list></div><div class=sidebar-footer><div class=footer-row style=justify-content:flex-end><button>🔔</button></div><div class=brand-row><div class=brand>🫖 teapot <span class=version>v</span><span></span></div></div><div class=metrics></div></div></nav><section class=channel></section><aside><div class=rightbarhead><span class=muted>details`),Ku=I(`<div class=notifbackdrop>`),qu=I(`<button class=editbtn>clear all`),Ju=I(`<div class=notiflist>`),Yu=I(`<div class=notifpanel><div class=notifhead>notifications<span style=display:flex;gap:8px;align-items:center><button class=iconbtn title="close notifications">✕`),Xu=I(`<img class=bgphoto sizes=100vw alt aria-hidden=true decoding=async>`),Zu=I(`<span class=wscount>`),Qu=I(`<div class=wsheader><span class=wscaret>`),$u=I(`<span class=notifbadge>🔔`),ed=I(`<span class=subtag>🧩`),td=I(`<span class=mini-cron>⏰`),nd=I(`<span class=goaldone title="goal done">✓`),rd=I(`<div><span></span><span>`),id=I(`<span class=caret-spacer>`),ad=I(`<span class=caret>`),od=I(`<span class=ghosttag title="workspace missing">👻`),sd=I(`<span>🧩 `),cd=I(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),ld=I(`<div class="divider-msg compacting"title="the harness is compressing old turns into notes so work can continue within the context window">🗜 `),ud=I(`<div class=muted style=display:grid;place-items:center;height:100%><span><span class=spinner aria-hidden=true></span> loading timeline…`),dd=I(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),fd=I(`<div class="content muted">thinking…`),pd=I(`<span>⌨ <button class=tabx title="close this shell">✕`),md=I(`<div><b class=mono></b><span class=muted>`),hd=I(`<div class=cmdrow><b>@</b><span class=muted>`),gd=I(`<span class=imgchip><img><button type=button class=imgx title=remove>✕`),_d=I(`<h3 title="switch provider/model live — applies from the agent's next turn; the list shows context window & pricing from the provider">🧦 model`),vd=I(`<div style=display:flex;gap:6px;align-items:center;margin-top:6px><label class=muted style=font-size:11.5px;white-space:nowrap>effort</label><select style=flex:1;min-width:0><option value>provider default`),yd=I(`<div class=meta style=color:var(--fg)>`),bd=I(`<div class=modelbox><select title="provider (OpenAI-compatible endpoint)"></select><div style=display:flex;gap:4px><input type=text list=model-list style=flex:1;min-width:0><datalist id=model-list></datalist></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: `),xd=I(`<div class=ctrlrow><label title="auto-continue fires after a round ONLY when all hold: ① this toggle is on ② a goal is set and its status is 'active' ③ the round ended cleanly (no error / not stopped). It stops when the goal is marked done, or if you press ■ stop. Sending any prompt also starts an idle agent regardless."><input type=checkbox>auto-continue`),Sd=I(`<span>`),Cd=I(`<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`),wd=I(`<div class=statrow style=margin-bottom:6px><span class=k>status`),Td=I(`<div class="card goalcard"><div class=content>`),Ed=I(`<div class="card verifycard"title="verification contract — finish(goalComplete=true) is audited against these requirements by an independent reviewer before the goal counts as done"><div class=vtitle>🔍 verification contract</div><div class=content>`),Dd=I(`<form style=display:flex;flex-direction:column;gap:6px;margin-top:8px;margin-bottom:6px><textarea id=goal-input rows=3 placeholder="set new goal…"style="background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;width:100%;resize:vertical"></textarea><textarea id=goal-verify-input rows=2 placeholder="verification contract (optional) — e.g. 'npm test passes; endpoint documented'. finish(goalComplete=true) is then audited against this."title="pi-goal-x-style verification contract — an independent reviewer checks the agent's finish against these requirements"style="background:var(--bg-darkest);border:1px solid var(--bg-light);border-radius:6px;padding:6px 8px;color:var(--fg);font:inherit;font-size:12.5px;width:100%;resize:vertical"></textarea><div style=display:flex;justify-content:flex-end;align-items:center;gap:10px><label class=muted title="queue a harness prompt telling the agent about the new goal at its next turn boundary"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=goal-notify type=checkbox> notify agent</label><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save goal`),Od=I(`<span class=badge>/<!> done`),kd=I(`<h3 title="todo.md — a shared checklist in the session dir. Write tasks like '- [ ] fix login'; the agent ticks them off via set_todo, you edit here. With notify on, it's told at its next turn boundary.">✅ tasks<span class=muted style=text-transform:none;letter-spacing:0>· shared checklist (you + agent)`),Ad=I(`<div class=bartrack style=margin-bottom:6px><div>`),jd=I(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><label class=muted title="queue a harness prompt telling the agent the task list changed"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=todo-notify type=checkbox checked> notify agent</label><button style="background:var(--ok);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save tasks`),Md=I(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),Nd=I(`<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`),Pd=I(`<div class=rtcell><span>cost</span><b>$`),Fd=I(`<div class=rtcell><span>cached</span><b>%`),Id=I(`<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>`),Ld=I(`<div class=muted style=font-size:11px;text-transform:none;letter-spacing:0>showing <b></b> and the history it inherited before forking`),Rd=I(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),zd=I(`<span class=muted style=text-transform:none;letter-spacing:0>· <!> · all agents`),Bd=I(`<h3 title="cron tasks, all agents — click a row to open that agent. Edit them in ⚙ settings → scheduled tasks.">⏰ schedule`),Vd=I(`<option>`),Hd=I(`<span class=badge title="no goal set yet">no goal`),Ud=I(`<button>`),Wd=I(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),Gd=I(`<div><div class=vtitle><span class="meta muted"style=margin-left:auto></span></div><div class=content>`),Kd=I(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),qd=I(`<div class=progrow><b>recent</b><span class="content inline-md">`),Jd=I(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),Yd=I(`<div class=progrow><b>next</b><span class="content inline-md">`),Xd=I(`<div class=progrow><b>goal</b><span>`),Zd=I(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),Qd=I(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),$d=I(`<span>% of `),ef=I(`<div class=bartrack><div>`),tf=I(`<div class=statrow title="a compaction pass is running right now — the summarizer's output streams in the timeline"><span class=k>🗜</span><b>compacting…</b><span class=muted style=font-size:11px;color:var(--acc)>`),nf=I(`<div class=ctxblock title="estimated live context vs the model's real window. Past the window, old turns are summarized into notes (compaction); the compact line below shows where that starts."><div class=statrow><span class=k>context</span><b>~<!> tok</b></div><div class=statrow style=margin-top:4px><span class=k>compact 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`),rf=I(`<div><span></span><span> events`),af=I(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),of=I(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),sf=I(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class=sched-meta> → next </div><div class="sched-prompt muted">`),cf=I(`<div class=muted style=padding:10px>nothing yet — progress, finishes, questions and errors will land here`),lf=I(`<div class=nbody>`),uf=I(`<div><div class=nhead><span class=nicon></span><span class=ntitle></span><span class="meta muted"></span><button class="iconbtn nreadbtn">`),df=I(`<div><div style=font-size:12.5px;margin-bottom:4px> event(s) came after this prompt — what should happen to them on the new branch?</div><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>summarize them into a note the agent can still read</label><label style=display:flex;gap:6px;align-items:center;font-size:13px;color:var(--fg)><input type=radio name=tail>discard them entirely (clean timeline)`),ff=I(`<form style=display:flex;flex-direction:column;gap:10px><textarea id=edit-text class="mono w100"rows=6></textarea><div style=display:flex;justify-content:flex-end;gap:8px><button type=button>cancel</button><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 12px;cursor:pointer">⑂ fork & resend`),pf=I(`<span class=bashelapsed>running… `),mf=I(`<span class=bashelapsed> elapsed`),hf=I(`<span class=thinktimer>`),gf=I(`<pre class="mono toolbody">`),_f=I(`<div class=meta>`),vf=I(`<div class=meta>waiting for output…`),yf=I(`<div class=mono>`),bf=I(`<div class="meta bgjob-note">runs in background — poll with <b>bash_output(job_id="<!>")`),xf=I(`<b>action="kill"`),Sf=I(`<div class="meta muted"> bytes — open it from 🗂 files for the full view`),Cf=I(`<div class=meta>writing…`),wf=I(`<pre class="mono toolbody del">`),Tf=I(`<pre class="mono toolbody add">`),Ef=I(`<div class=meta> · `),Df=I(`<div class=meta>applying…`),Of=I(`<pre class="mono toolbody patch">`),kf=I(`<div>`),Af=I(`<div class="pline meta">… <!> more lines`),jf=I(`<div class=meta>validating…`),Mf=I(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),Nf=I(`<span class=muted>`),Pf=I(`<div class=meta>loading…`),Ff=I(`<div class=meta>bundled: `),If=I(`<div class=meta>saving…`),Lf=I(`<span class=actor>@`),Rf=I(`<details><summary><b></b><span class=meta></span><span class=toolcopy>`),zf=I(`<div class=divider-msg>⑂ forked from <!> → `),Bf=I(`<div><div class=goalline-label>`),Vf=I(`<div class=divider-msg>✅ tasks updated (<!>)`),Hf=I(`<div> → `),Uf=I(`<div class="embed fail"><div class=mono>🛑 runaway: <!> tool failures in a row (limit <!>)</div><div class=meta>last: <!> — `),Wf=I(`<div class="embed warn-embed"title="a round-fatal API error occurred; auto-retry is waiting, then a fresh round starts (onError: retry)"><div class=mono>↻ API error — retrying (attempt <!>) in <!>s…`),Gf=I(`<div class=divider-msg>🗜 compacted: <!> → <!> tok (<!>)`),Kf=I(`<div class=divider-msg title="compaction is rewriting older history — the agent is not stuck">🗜 compacting: summarizing <!> earlier messages from <!> tok (<!>)…`),qf=I(`<span class=ts>`),Jf=I(`<button class=editbtn title="withdraw this message — it has not reached the model yet; the text goes back to the input box">✕ cancel`),Yf=I(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),Xf=I(`<div class=msg-head><span class=author></span><span class=ts>`),Zf=I(`<div><div></div><div class=msg-body>`),Qf=I(`<span class=grouptime>`),$f=I(`<div class=qfree><input type=text><button>reply`),ep=I(`<div class=promptimgs>`),tp=I(`<img class=promptimg alt=attachment>`),np=I(`<details class=reasoning><summary>💭 reasoning</summary><div class=mono>`),rp=I(`<div class=interrupted>⚠ interrupted — partial output kept`),ip=I(`<div class=msgfoot><span>copy summary`),ap=I(`<div class=meta>its call is no longer in the loaded events — the run itself finished`),op=I(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>`),sp=I(`<div class="content muted">Rejected: `),cp=I(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged</span></summary><div class=content>`),lp=I(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),up=I(`<div class=qopts>`),dp=I(`<div><div>❓ <div class="content inline-md">`),fp=I(`<button class=qopt>`),pp=I(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),mp=I(`<div class="embed fail"><div class=mono>⚠ `),hp=I(`<div class=vtitle style=margin-top:6px>what the agent kept`),gp=I(`<details class="embed compaction"><summary><b>🗜 context compacted</b><span class=meta> · <!> → <!> tok · `),_p=I(`<div class="content muted">`),vp=I(`<button type=button><span class=iconbtn-glyph>`),yp=I(`<button class=copybtn>`),bp=I(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),xp=I(`<span style=color:var(--err);font-size:13px>`),Sp=I(`<form style=display:flex;flex-direction:column;gap:10px><label>workspace directory<div style=display:flex;gap:6px><input type=text class="w100 mono"><button type=button>go</button><button type=button title="parent directory">↑</button></div></label><div class=dirlist></div><div style=display:flex;gap:10px><label style=flex:1>agent name <input type=text placeholder="(directory name)"></label><label style="flex:0 1 auto;min-width:0">provider<select></select></label><label style=flex:1>model <input type=text placeholder="(provider default)"></label></div><button type=submit style=align-self:flex-end>create`),Cp=I(`<div class=direntry>📁 `),wp=I(`<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%>`),Tp=I(`<select title="which custom theme to edit — selecting one also applies it">`),Ep=I(`<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`),Dp=I(`<div class=muted style="margin:6px 0">`),Op=I(`<b>+ duplicate current`),kp=I(`<div class=cfggrid style=margin-top:8px><label class=trow>name<input class=w100></label><label class=trow>appearance<select><option value=dark>dark</option><option value=light>light`),Ap=I(`<div class=paletterows>`),jp=I(`<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`),Mp=I(`<h4 class=cfgsub>background image`),Np=I(`<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`),Pp=I(`<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>`),Fp=I(`<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.`),Ip=I(`<label class=paletterow><input type=color><span class=paletterow-label></span><input class="mono paletterow-hex">`),Lp=I(`<div class="content mdpreview todopane">`),Rp=I(`<textarea id=todo-input class="mono todopane-edit"rows=5 placeholder="- task one
|
|
21
|
-
- task two"title="shared with the agent \\u2014 it may check items off via set_todo; your unsaved edits win until you save">`),zp=I(`<span class=fsize>`),Bp=I(`<div><span class=ficon></span><span class=fname>`),Vp=I(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview"style=display:flex;align-items:center;gap:6px>🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),Hp=I(`<div class=filebox>`),Up=I(`<div class=muted style=padding:6px>`),Wp=I(`<img>`),Gp=I(`<div class=mediapreview><div class="meta muted"> preview`),Kp=I(`<button title="rendered markdown">👁 preview`),qp=I(`<button title="edit and save back to the workspace">✎ edit`),Jp=I(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),Yp=I(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Xp=I(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Zp=I(`<div class="content mdpreview">`),Qp=I(`<video controls>`),$p=I(`<audio controls>`),em=I(`<div class=filepreview>`),tm=I(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),nm=I(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),rm=I(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),im=I(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),am=I(`<div class=wizmodels>`),om=I(`<span style=color:var(--fg)>`),sm=I(`<div class=muted style=font-size:11.5px;margin-top:-6px> model`),cm=I(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),lm=I(`<button type=button>`),um=I(`<div class=muted style=font-size:11.5px;margin-top:-8px>`),dm=I(`<button type=button><span class=mono>`),fm=I(`<label><input type=number min=0>`),pm=I(`<div class=muted style=font-size:11.5px;margin-top:4px>⚠ configured default provider <code></code> has no provider row here<!> Add a provider named <code></code> or pick a default below; otherwise agents fall back to the first provider.`),mm=I(`<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>`),hm=I(`<div class=skilllist>`),gm=I(`<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 style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">update & restart</button><span class=muted style=margin-left:8px;font-size:12px>gracefully stops all agents, spawns new process, then reloads this page</span></div></fieldset><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>save settings`),_m=I(`<button type=button><span class=cfgmenu-label>`),vm=I(`<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`),ym=I(`<button type=button title="remove this key">−`),bm=I(`<div class=cfgkeyrow><input type=password>`),xm=I(`<button type=button>+ `),Sm=I(`<div class=cfgsub style=margin-bottom:var(--space-1)>`),Cm=I(`<div class=themepick>`),wm=I(`<button type=button><span class=themecard-preview></span><span class=themecard-label> ★`),Tm=I(`<button type=button><span class=themecard-preview></span><span class=themecard-label>`),Em=I(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),Dm=I(`<input placeholder="command (e.g. npx)">`),Om=I(`<input placeholder="args, space separated">`),km=I(`<input type=password placeholder="paste the token"title="sent as Authorization: Bearer <token>"style=flex:1>`),Am=I(`<input placeholder="header name"style="flex:0 1 150px">`),jm=I(`<input type=password placeholder=value style=flex:1>`),Mm=I(`<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>`),Nm=I(`<button type=button class=archrestore title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),Pm=I(`<span class="mcpstate connected"title="an OAuth access token is usable">🔑 authorized`),Fm=I(`<button type=button title="forget the stored grant (the refresh token is deleted)">disconnect`),Im=I(`<div class=muted style=font-size:11px;color:var(--warn)>`),Lm=I(`<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`),Rm=I(`<span class=muted> · needs a grant (🔑 authorize)`),zm=I(`<ul class=mcptools>`),Bm=I(`<div><div class=mcpresult-head><b>`),Vm=I(`<span class=mcptool-desc>`),Hm=I(`<li><code class=mono>`),Um=I(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),Wm=I(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),Gm=I(`<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`),Km=I(`<span class=muted>🧩 sub of @`),qm=I(`<div class=cfgrow><b></b><span class=muted>`),Jm=I(`<div class=muted>`),Ym=I(`<pre class="skillbody mono">`),Xm=I(`<div class=skillrow><button type=button class=skillhead title="show the playbook"><span class=skillcaret></span><b class=mono></b><span class=muted>`),Zm=I(`<div class="muted skillbody">`),Qm=new Map;function $m(e){let t=Qm.get(e);if(t!==void 0)return t;let n=Fe(e);return Qm.set(e,n),Qm.size>500&&Qm.delete(Qm.keys().next().value),n}var eh=[`minimal`,`low`,`medium`,`high`],th=1100,nh={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`}},rh={name:`harness`,icon:`📣`,color:`#3ba55d`},[ih,ah]=v(``),oh,Q=e=>{ah(e),clearTimeout(oh),oh=setTimeout(()=>ah(``),3200)},sh=!1,ch=[{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`]}],lh=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`?nh.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:rh}return nh[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},uh=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),dh=new Set([`system_note`]),fh=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`]),ph=new Set([`runaway-detected`,`error-retry`,`background-exit`,`context-compacted`,`context-compaction-started`]),mh=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 hh=location.hash.match(/[#&]token=([^&]+)/);hh&&(localStorage.setItem(`teapot.token`,decodeURIComponent(hh[1])),history.replaceState(null,``,location.pathname+location.search));var gh=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function _h(){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,T]=v([]),[E,te]=v(null),D=new Map,[ne,re]=v(D.get(n()??``)??``),O=e=>{re(e);let t=n();t&&(e?D.set(t,e):D.delete(t))},[k,ie]=v({providers:{}}),[ae,oe]=v(!1),se=[640,1280,1920,2560,3840],ce=()=>{let e=je()?We()?Ne():Re():ke();return Ie().find(t=>t.id===e)?.backgroundImage??``},[A,le]=v(!1);b(()=>{A()&&!Zi()&&$(`/api/features`).then(e=>Qi(e)).catch(()=>Qi(null))});let j=new Set,ue=()=>window.innerWidth<=th,[de,fe]=v(ue());ee(()=>{let e=()=>fe(ue());window.addEventListener(`resize`,e),C(()=>window.removeEventListener(`resize`,e)),e()});let pe,me,he=0,ge=``,_e=()=>{he=0;let e=Gr();if(!e)return;if(oa=e.scrollHeight,ua=e.clientHeight,ht()){Jr();return}let t=xe(e);if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;r&&(e.scrollTop+=r,aa={top:e.scrollTop,height:e.scrollHeight}),Ot(Kr())};function ve(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||(e.scrollTop+=r,aa={top:e.scrollTop,height:e.scrollHeight})}let ye=()=>{he||=requestAnimationFrame(_e)},be=e=>{e&&e!==me&&(pe??=new ResizeObserver(e=>{let t=e[0]?.contentRect,n=t?`${Math.round(t.width)}x${Math.round(t.height)}`:``;n!==ge&&(ge=n,ye())}),me&&pe.unobserve(me),me=e,ge=``,pe.observe(e))};ee(()=>{window.addEventListener(`resize`,ye),C(()=>{window.removeEventListener(`resize`,ye),pe?.disconnect(),pe=void 0,me=void 0,he&&cancelAnimationFrame(he)})});function xe(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[Se,I]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>th:localStorage.getItem(`teapot.panel`)===`1`),Ce=e=>{I(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},we=()=>Ce(!Se()),Oe=()=>{Se()&&Ce(!1)},[ke,Ae]=v(localStorage.getItem(`teapot.theme`)??`dark`),[je,Me]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[Ne,Pe]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[Ie,Le]=v(ln()),[Re,ze]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),Be=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[We,Ke]=v(Be?.matches??!1);ee(()=>{let e=e=>Ke(e.matches);Be?.addEventListener(`change`,e),C(()=>Be?.removeEventListener(`change`,e))}),b(()=>{let e=hn({want:je()?We()?Ne():Re():ke(),customIds:Ie().map(e=>e.id),presetIds:ch.map(e=>e.key),fallback:`dark`}),t=e.active,n=Ie().find(e=>e.id===t)??null;e.repaired&&(je()?localStorage.setItem(We()?`teapot.theme.light`:`teapot.theme.dark`,t):localStorage.setItem(`teapot.theme`,t)),document.documentElement.dataset.theme=t,fn(document.documentElement,n),document.documentElement.dataset.appearance=n?.mode??ch.find(e=>e.key===t)?.mode??`dark`});let[Ze,Qe]=v(``),[$e,et]=v(``),[tt,nt]=v(``);b(()=>{let t=n();nt(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[rt,it]=v([]),at=()=>Object.keys(k().providers??{});async function ot(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);it(t.models??[])}catch{it([])}}let st=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)}`:``},ct=()=>{let e=$e().trim()||B()?.model||``;if(!e)return``;let t=rt().find(t=>t.id===e);if(!t)return``;let n=[],r=st(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${Dh(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(` · `)},lt=null,ut=!1;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||k().defaultProvider||at()[0]||``;if(r){if(t!==lt)lt=t,ut=!1,S(()=>Ze())!==i&&(Qe(i),ot(i)),S(()=>$e())&&et(``);else{let e=S(()=>Ze());!S(()=>$e())&&e!==i&&Gt(ut)&&(Qe(i),ot(i))}}});let[dt,pt]=v(!1),[ht,gt]=v(!0),[vt,Tt]=v(0),[Et,Dt]=v(-1),Ot=e=>Dt(e?en(e):-1),[Mt,Rt]=v(null),zt=()=>an().startsWith(`[compact] `),Bt=()=>zt()?an().slice(10):an();b(()=>{Mt()||rn(e=>e?.text.startsWith(`[compact] `)?null:e)}),b(()=>{Mt(),requestAnimationFrame(()=>requestAnimationFrame(()=>{ht()&&Jr()}))});let[Ht,Jt]=v(new Map),nn=()=>{let e=n();return e?Ht().get(e)??null:null},rn=e=>{let t=n();t&&Jt(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})},[an,on]=v(``),[sn,cn]=v(0),un=()=>sn(),[dn,pn]=v(``),mn;b(()=>{nn()?mn||=setTimeout(()=>{mn=void 0,on(nn()?.text??``),pn(nn()?.reasoning??``)},(nn()?.text.length??0)>2e4?250:(nn()?.text.length??0)>6e3?120:60):(clearTimeout(mn),mn=void 0,on(``),pn(``))}),C(()=>clearTimeout(mn)),b(()=>{let t=e();Jt(e=>Je(e,e=>t.find(t=>t.id===e)?.status)),cn(e=>Xe(e,t,n(),nn()))}),b(()=>{let e=an(),t=nn()?.reasoning??``;(e||t)&&requestAnimationFrame(()=>{ht()&&Jr()})}),b(()=>{let e=B()?.pendingPrompts??0,t=B()?.pendingPromptIds,n=xn(),r=Sn(n),i=At(r,e,t);i!==r&&Cn(n,i)}),b(()=>{let e=B()?.pendingPromptQueue;if(!e?.length)return;let t=xn(),n=new Set(Sn(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&Cn(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}:{}})),...Sn(t)])}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{qr()&&(gt(!0),Tt(0),Yr(!0),Mn())})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let B=x(()=>e().find(e=>e.id===n())),gn=()=>{let e=B();return e?e.live??(e.status===`running`||e.status===`waiting`||e.status===`needs_operator`):!1},_n=()=>Ft(B(),i(),gn()),[V,H]=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 vn=new Map,[yn,bn]=v([]),xn=()=>i()||n()||`?`,Sn=e=>vn.get(e)??[],Cn=(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?vn.delete(e):vn.set(e,r),xn()===e&&bn(r)},[wn,Tn]=v([]),[En,Dn]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[On,kn]=v(!1),An=()=>wn().filter(e=>!e.read).length,jn=e=>{Tn(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},Mn=()=>{let e=n();e&&wn().some(t=>!t.read&&t.agentId===e)&&jn(e)},Nn=t=>{let n=wn().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Nn(r.id));return n},Pn=0,Fn=e=>{Tn(t=>[{...e,id:`n${++Pn}`,at:Date.now(),read:!1},...t].slice(0,50))},In=(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?Fn({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?Fn({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?Fn({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&Fn({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})},Ln=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))},Rn=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of m())if(uh.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}}),[zn,Bn]=v(new Set),Vn=e=>{e&&Bn(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},Hn=()=>Bn(new Set),Un=x(()=>kt(m(),zn())),Wn=x(()=>ft({events:m(),consumed:Rn().consumed,pending:yn(),echo:Jn,feedTypes:uh,renderedTypes:fh,renderedNoteEvents:ph})),Gn=x(()=>{let e=new WeakMap;return Wn().forEach((t,n)=>e.set(t,n)),e}),Kn=(e,t)=>{let n=Gn().get(e);if(n!==void 0)return Wn()[n+t]},qn=new Map;function Jn(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=qn.get(t);if(n)return n;qn.size>64&&qn.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:B()?.session??``,branch:B()?.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 qn.set(t,r),r}let Yn=()=>$(`/api/config`).then(ie).catch(()=>{}),[Xn,Zn]=v(!1);ee(()=>{let e=()=>Zn(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[Qn,$n]=v(``),[er,tr]=v(!0),[nr,rr]=v(!1),ir=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==ir?(ir=t,rr(!1),$n(r)):t&&!nr()&&$n(r)});let ar=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:Qn(),notify:e})}),rr(!1),tr(!0),Q(`tasks saved${e&&Qn().trim()?` & notification queued`:``}`),cr()}catch(e){Q(`save failed: ${e.message}`)}},or=x(()=>{let e=0,t=0;for(let n of Qn().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">`),zp=I(`<span class=fsize>`),Bp=I(`<div><span class=ficon></span><span class=fname>`),Vp=I(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview"style=display:flex;align-items:center;gap:6px>🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),Hp=I(`<div class=filebox>`),Up=I(`<div class=muted style=padding:6px>`),Wp=I(`<img>`),Gp=I(`<div class=mediapreview><div class="meta muted"> preview`),Kp=I(`<button title="rendered markdown">👁 preview`),qp=I(`<button title="edit and save back to the workspace">✎ edit`),Jp=I(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),Yp=I(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Xp=I(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Zp=I(`<div class="content mdpreview">`),Qp=I(`<video controls>`),$p=I(`<audio controls>`),em=I(`<div class=filepreview>`),tm=I(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),nm=I(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),rm=I(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),im=I(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),am=I(`<div class=wizmodels>`),om=I(`<span style=color:var(--fg)>`),sm=I(`<div class=muted style=font-size:11.5px;margin-top:-6px> model`),cm=I(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),lm=I(`<button type=button>`),um=I(`<div class=muted style=font-size:11.5px;margin-top:-8px>`),dm=I(`<button type=button><span class=mono>`),fm=I(`<label><input type=number min=0>`),pm=I(`<div class=muted style=font-size:11.5px;margin-top:4px>⚠ configured default provider <code></code> has no provider row here<!> Add a provider named <code></code> or pick a default below; otherwise agents fall back to the first provider.`),mm=I(`<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>`),hm=I(`<div class=skilllist>`),gm=I(`<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 style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">update & restart</button><span class=muted style=margin-left:8px;font-size:12px>gracefully stops all agents, spawns new process, then reloads this page</span></div></fieldset><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>`),_m=I(`<button type=button><span class=cfgmenu-label>`),vm=I(`<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`),ym=I(`<button type=button title="remove this key">−`),bm=I(`<div class=cfgkeyrow><input type=password>`),xm=I(`<button type=button>+ `),Sm=I(`<div class=cfgsub style=margin-bottom:var(--space-1)>`),Cm=I(`<div class=themepick>`),wm=I(`<button type=button><span class=themecard-preview></span><span class=themecard-label> ★`),Tm=I(`<button type=button><span class=themecard-preview></span><span class=themecard-label>`),Em=I(`<div class=muted style=font-size:12.5px>no MCP servers. add one below — a remote url, or a local command for stdio.`),Dm=I(`<input placeholder="command (e.g. npx)">`),Om=I(`<input placeholder="args, space separated">`),km=I(`<input type=password placeholder="paste the token"title="sent as Authorization: Bearer <token>"style=flex:1>`),Am=I(`<input placeholder="header name"style="flex:0 1 150px">`),jm=I(`<input type=password placeholder=value style=flex:1>`),Mm=I(`<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>`),Nm=I(`<button type=button class=archrestore title="start the OAuth flow: a browser tab opens, and the tools appear when you finish">🔑 authorize`),Pm=I(`<span class="mcpstate connected"title="an OAuth access token is usable">🔑 authorized`),Fm=I(`<button type=button title="forget the stored grant (the refresh token is deleted)">disconnect`),Im=I(`<div class=muted style=font-size:11px;color:var(--warn)>`),Lm=I(`<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`),Rm=I(`<span class=muted> · needs a grant (🔑 authorize)`),zm=I(`<ul class=mcptools>`),Bm=I(`<div><div class=mcpresult-head><b>`),Vm=I(`<span class=mcptool-desc>`),Hm=I(`<li><code class=mono>`),Um=I(`<div class=cfgcol><div class=cfgrow><input placeholder=id><input placeholder="agent id"><input placeholder="every 30m / cron"><label style=display:flex;gap:3px;align-items:center;white-space:nowrap;color:var(--dim);font-size:11px><input type=checkbox>fork</label><button type=button class=danger>✕</button></div><textarea rows=2 placeholder="prompt to send">`),Wm=I(`<div class=muted style=font-size:12.5px>nothing archived. 🗄 archive in the controls panel puts an agent away without losing its history.`),Gm=I(`<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`),Km=I(`<span class=muted>🧩 sub of @`),qm=I(`<div class=cfgrow><b></b><span class=muted>`),Jm=I(`<div class=muted>`),Ym=I(`<pre class="skillbody mono">`),Xm=I(`<div class=skillrow><button type=button class=skillhead title="show the playbook"><span class=skillcaret></span><b class=mono></b><span class=muted>`),Zm=I(`<div class="muted skillbody">`),Qm=new Map;function $m(e){let t=Qm.get(e);if(t!==void 0)return t;let n=Fe(e);return Qm.set(e,n),Qm.size>500&&Qm.delete(Qm.keys().next().value),n}var eh=[`minimal`,`low`,`medium`,`high`],th=1100,nh={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`}},rh={name:`harness`,icon:`📣`,color:`#3ba55d`},[ih,ah]=v(``),oh,Q=e=>{ah(e),clearTimeout(oh),oh=setTimeout(()=>ah(``),3200)},sh=!1,ch=[{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`]}],lh=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`?nh.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:rh}return nh[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},uh=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`,`system_note`]),dh=new Set([`system_note`]),fh=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`error`,`fork`,`goal`,`todo`,`question`,`decision`,`compaction`]),ph=new Set([`runaway-detected`,`error-retry`,`background-exit`,`context-compacted`,`context-compaction-started`]),mh=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 hh=location.hash.match(/[#&]token=([^&]+)/);hh&&(localStorage.setItem(`teapot.token`,decodeURIComponent(hh[1])),history.replaceState(null,``,location.pathname+location.search));var gh=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function _h(){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,T]=v([]),[E,te]=v(null),D=new Map,[ne,re]=v(D.get(n()??``)??``),O=e=>{re(e);let t=n();t&&(e?D.set(t,e):D.delete(t))},[k,ie]=v({providers:{}}),[ae,oe]=v(!1),se=[640,1280,1920,2560,3840],ce=()=>{let e=je()?We()?Ne():Re():ke();return Ie().find(t=>t.id===e)?.backgroundImage??``},[A,le]=v(!1);b(()=>{A()&&!Zi()&&$(`/api/features`).then(e=>Qi(e)).catch(()=>Qi(null))});let j=new Set,ue=()=>window.innerWidth<=th,[de,fe]=v(ue());ee(()=>{let e=()=>fe(ue());window.addEventListener(`resize`,e),C(()=>window.removeEventListener(`resize`,e)),e()});let pe,me,he=0,ge=``,_e=()=>{he=0;let e=Gr();if(!e)return;if(oa=e.scrollHeight,ua=e.clientHeight,ht()){Jr();return}let t=xe(e);if(!t)return;let n=e.querySelector(t.sel);if(!n)return;let r=n.getBoundingClientRect().top-t.top;r&&(e.scrollTop+=r,aa={top:e.scrollTop,height:e.scrollHeight}),Ot(Kr())};function ve(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||(e.scrollTop+=r,aa={top:e.scrollTop,height:e.scrollHeight})}let ye=()=>{he||=requestAnimationFrame(_e)},be=e=>{e&&e!==me&&(pe??=new ResizeObserver(e=>{let t=e[0]?.contentRect,n=t?`${Math.round(t.width)}x${Math.round(t.height)}`:``;n!==ge&&(ge=n,ye())}),me&&pe.unobserve(me),me=e,ge=``,pe.observe(e))};ee(()=>{window.addEventListener(`resize`,ye),C(()=>{window.removeEventListener(`resize`,ye),pe?.disconnect(),pe=void 0,me=void 0,he&&cancelAnimationFrame(he)})});function xe(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[Se,I]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>th:localStorage.getItem(`teapot.panel`)===`1`),Ce=e=>{I(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},we=()=>Ce(!Se()),Oe=()=>{Se()&&Ce(!1)},[ke,Ae]=v(localStorage.getItem(`teapot.theme`)??`dark`),[je,Me]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[Ne,Pe]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[Ie,Le]=v(ln()),[Re,ze]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),Be=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[We,Ke]=v(Be?.matches??!1);ee(()=>{let e=e=>Ke(e.matches);Be?.addEventListener(`change`,e),C(()=>Be?.removeEventListener(`change`,e))}),b(()=>{let e=hn({want:je()?We()?Ne():Re():ke(),customIds:Ie().map(e=>e.id),presetIds:ch.map(e=>e.key),fallback:`dark`}),t=e.active,n=Ie().find(e=>e.id===t)??null;e.repaired&&(je()?localStorage.setItem(We()?`teapot.theme.light`:`teapot.theme.dark`,t):localStorage.setItem(`teapot.theme`,t)),document.documentElement.dataset.theme=t,fn(document.documentElement,n),document.documentElement.dataset.appearance=n?.mode??ch.find(e=>e.key===t)?.mode??`dark`});let[Ze,Qe]=v(``),[$e,et]=v(``),[tt,nt]=v(``);b(()=>{let t=n();nt(S(()=>e().find(e=>e.id===t)?.reasoningEffort??``))});let[rt,it]=v([]),at=()=>Object.keys(k().providers??{});async function ot(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);it(t.models??[])}catch{it([])}}let st=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)}`:``},ct=()=>{let e=$e().trim()||B()?.model||``;if(!e)return``;let t=rt().find(t=>t.id===e);if(!t)return``;let n=[],r=st(t);r&&r!==`📄 → 📄`&&n.push(r),t.contextLength&&n.push(`ctx ${Dh(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(` · `)},lt=null,ut=!1;b(()=>{let t=n();if(!t)return;let r=e().find(e=>e.id===t),i=r?.provider||k().defaultProvider||at()[0]||``;if(r){if(t!==lt)lt=t,ut=!1,S(()=>Ze())!==i&&(Qe(i),ot(i)),S(()=>$e())&&et(``);else{let e=S(()=>Ze());!S(()=>$e())&&e!==i&&Gt(ut)&&(Qe(i),ot(i))}}});let[dt,pt]=v(!1),[ht,gt]=v(!0),[vt,Tt]=v(0),[Et,Dt]=v(-1),Ot=e=>Dt(e?en(e):-1),[Mt,Rt]=v(null),zt=()=>an().startsWith(`[compact] `),Bt=()=>zt()?an().slice(10):an();b(()=>{Mt()||rn(e=>e?.text.startsWith(`[compact] `)?null:e)}),b(()=>{Mt(),requestAnimationFrame(()=>requestAnimationFrame(()=>{ht()&&Jr()}))});let[Ht,Jt]=v(new Map),nn=()=>{let e=n();return e?Ht().get(e)??null:null},rn=e=>{let t=n();t&&Jt(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})},[an,on]=v(``),[sn,cn]=v(0),un=()=>sn(),[dn,pn]=v(``),mn;b(()=>{nn()?mn||=setTimeout(()=>{mn=void 0,on(nn()?.text??``),pn(nn()?.reasoning??``)},(nn()?.text.length??0)>2e4?250:(nn()?.text.length??0)>6e3?120:60):(clearTimeout(mn),mn=void 0,on(``),pn(``))}),C(()=>clearTimeout(mn)),b(()=>{let t=e();Jt(e=>Je(e,e=>t.find(t=>t.id===e)?.status)),cn(e=>Xe(e,t,n(),nn()))}),b(()=>{let e=an(),t=nn()?.reasoning??``;(e||t)&&requestAnimationFrame(()=>{ht()&&Jr()})}),b(()=>{let e=B()?.pendingPrompts??0,t=B()?.pendingPromptIds,n=xn(),r=Sn(n),i=At(r,e,t);i!==r&&Cn(n,i)}),b(()=>{let e=B()?.pendingPromptQueue;if(!e?.length)return;let t=xn(),n=new Set(Sn(t).map(e=>e.promptId).filter(Boolean)),r=e.filter(e=>e.id&&!n.has(e.id));r.length&&Cn(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}:{}})),...Sn(t)])}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{qr()&&(gt(!0),Tt(0),Yr(!0),Mn())})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let B=x(()=>e().find(e=>e.id===n())),gn=()=>{let e=B();return e?e.live??(e.status===`running`||e.status===`waiting`||e.status===`needs_operator`):!1},_n=()=>Ft(B(),i(),gn()),[V,H]=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 vn=new Map,[yn,bn]=v([]),xn=()=>i()||n()||`?`,Sn=e=>vn.get(e)??[],Cn=(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?vn.delete(e):vn.set(e,r),xn()===e&&bn(r)},[wn,Tn]=v([]),[En,Dn]=v(localStorage.getItem(`teapot.hideGhosts`)===`1`),[On,kn]=v(!1),An=()=>wn().filter(e=>!e.read).length,jn=e=>{Tn(t=>{let n=!1,r=t.map(t=>t.read||t.agentId!==e?t:(n=!0,{...t,read:!0}));return n?r:t})},Mn=()=>{let e=n();e&&wn().some(t=>!t.read&&t.agentId===e)&&jn(e)},Nn=t=>{let n=wn().filter(e=>!e.read&&e.agentId===t).length;for(let r of e())r.parent===t&&(n+=Nn(r.id));return n},Pn=0,Fn=e=>{Tn(t=>[{...e,id:`n${++Pn}`,at:Date.now(),read:!1},...t].slice(0,50))},In=(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?Fn({agentId:t,kind:`finish`,title:`${r} finished`,body:String(n.data.content??``).slice(0,300),eventId:i}):n.type===`question`?Fn({agentId:t,kind:`question`,title:`${r} asks a question`,body:String(n.data.question??``).slice(0,300),eventId:i}):n.type===`error`?Fn({agentId:t,kind:`error`,title:`${r} hit an error`,body:String(n.data.message??``).slice(0,300),eventId:i}):n.type===`progress`&&Fn({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})},Ln=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))},Rn=x(()=>{let e=new Map,t=new Set,n=new Map,r=new Map;for(let i of m())if(uh.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}}),[zn,Bn]=v(new Set),Vn=e=>{e&&Bn(t=>{if(t.has(e))return t;let n=new Set(t);return n.add(e),n})},Hn=()=>Bn(new Set),Un=x(()=>kt(m(),zn())),Wn=x(()=>ft({events:m(),consumed:Rn().consumed,pending:yn(),echo:Jn,feedTypes:uh,renderedTypes:fh,renderedNoteEvents:ph})),Gn=x(()=>{let e=new WeakMap;return Wn().forEach((t,n)=>e.set(t,n)),e}),Kn=(e,t)=>{let n=Gn().get(e);if(n!==void 0)return Wn()[n+t]},qn=new Map;function Jn(e){let t=`${e.id}:${e.sent?`s`:`p`}`,n=qn.get(t);if(n)return n;qn.size>64&&qn.clear();let r={id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:B()?.session??``,branch:B()?.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 qn.set(t,r),r}let Yn=()=>$(`/api/config`).then(ie).catch(()=>{}),[Xn,Zn]=v(!1);ee(()=>{let e=()=>Zn(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[Qn,$n]=v(``),[er,tr]=v(!0),[nr,rr]=v(!1),ir=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==ir?(ir=t,rr(!1),$n(r)):t&&!nr()&&$n(r)});let ar=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:Qn(),notify:e})}),rr(!1),tr(!0),Q(`tasks saved${e&&Qn().trim()?` & notification queued`:``}`),cr()}catch(e){Q(`save failed: ${e.message}`)}},or=x(()=>{let e=0,t=0;for(let n of Qn().split(`
|
|
22
22
|
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}});function sr(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 cr=()=>$(`/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),sr(t,e.agents??[]))),n&&p()}).catch(()=>{}),lr=()=>$(`/api/metrics`).then(te).catch(()=>{}),[ur,dr]=v([]),fr=()=>$(`/api/tasks`).then(e=>dr(e.tasks)).catch(()=>{}),pr=e=>ur().filter(t=>t.agent===e),[mr,hr]=v((()=>{try{let e=JSON.parse(localStorage.getItem(`teapot.expandedSubs`)??`[]`);return new Set(e.filter(e=>typeof e==`string`))}catch{return new Set}})()),[gr,_r]=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}})()),vr=e=>gr().has(e)||!mr().has(e),yr=e=>{let t=new Set(mr());if(t.has(e)?t.delete(e):t.add(e),hr(t),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...t])),t.has(e)&&gr().has(e)){let t=new Set(gr());t.delete(e),_r(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))}},br=t=>St(e(),t),[xr,Sr]=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}})()),Cr=x(()=>{let e=new Set;for(let t of xr())t.startsWith(`chat:`)&&e.add(t);return e}),wr=x(()=>_t(e(),new Set(e().filter(e=>vr(e.id)).map(e=>e.id)),En(),Cr())),Tr=(t,r,i,a)=>{let o=new Set(xr());if(i)o.delete(t),a&&o.delete(a);else{o.add(t),a&&o.delete(a);let i=n();i&&(t===`chat:${i}`||br(e().find(e=>e.id===i))===t)&&Q(`hid ${r} — click the header to show it`)}Sr(o);try{localStorage.setItem(`teapot.wsCollapsed`,JSON.stringify([...o]))}catch{}},Er=e=>e.replace(/\/+$/,``).split(/[/\\]/).pop()||e,Dr=e=>{let t=Or().get(e)??0;return`${t} chat${t===1?``:`s`}`},Or=x(()=>Ct(e())),kr=x(()=>wt(e(),wr(),xr())),U=2e3,[Ar,jr]=v(null),W=new Map;function Mr(e){return`${i()||(n()??`?`)}:${e.id}`}function Nr(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=Mr(r),a=W.get(i);if(t[n]=a??r,!a&&(W.set(i,r),W.size>6e3)){let e=W.keys().next().value;e!==void 0&&W.delete(e)}}return t}let[Pr,G]=v(!1),[Fr,Ir]=v(!1),[Lr,Rr]=v(!1),zr=0,Br=-1;function Vr(e){let t=Nr(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 Hr(){let e=n();if(!e||Lr()||Pr()||ht())return;if(m().length>=g()){Rr(!0);return}let t=()=>{let e=Gr();return e&&e.clientHeight>0?e:null},r=0;for(;r++<20&&!Lr()&&n()===e;){let r=t();if(r&&r.scrollHeight>r.clientHeight+40)return;if(m().length>=g()){Rr(!0);return}let i=m().length;if(await Ur(),m().length===i)return;Xt(Kr())&&n()===e&&Yr(!0)}}async function Ur(){let e=n(),t=m()[0];if(e&&t&&!Pr()&&!Lr()){G(!0);try{let r=Gr(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=Ar(),c=i(),l=c&&c!==e?`&session=${encodeURIComponent(c)}`:``,u=(await $(`/api/agents/${e}/events?limit=${U}&before=${encodeURIComponent(t.id)}${l}${s?`&branch=${encodeURIComponent(s)}&lineage=true`:``}`)).events??[];if(u.length===0){Rr(!0);return}if(n()!==e||m()[0]?.id!==t.id)return;Vr(u),requestAnimationFrame(()=>{if(n()===e){let e=Gr();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{G(!1)}}}async function Wr(e,t){let r=zr,a=t??i()??``;try{let t=Ar(),i=r!==Br||!w().length;m().length||Ir(!0);let o=a&&a!==e?`&session=${encodeURIComponent(a)}`:``;$(`/api/agents/${e}/skills`).then(t=>{r===zr&&n()===e&&Xi(t.skills??[])}).catch(()=>{});let[s,c]=await Promise.all([$(`/api/agents/${e}/events?limit=${U}${o}${t?`&branch=${encodeURIComponent(t)}&lineage=true`:``}`),i?$(`/api/agents/${e}/branches`):Promise.resolve({branches:w()})]);if(i&&(Br=r),r!==zr||n()!==e)return;h(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of Nr(s.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),_(s.total??s.events.length),T(c.branches)}catch{}finally{Ir(!1)}}function Gr(){return document.querySelector(`.feed`)}function Kr(){let e=Gr();return e?{top:e.scrollTop,height:e.scrollHeight,viewport:e.clientHeight}:null}function qr(){return Xt(Kr())}function Jr(){let e=Gr();e&&(e.scrollTop=e.scrollHeight,aa={top:e.scrollTop,height:e.scrollHeight},Tt(0))}function Yr(e=!1){(e||ht())&&Jr()}let K=new Map,Xr=(t,n)=>jt(c().get(t),e().find(e=>e.id===t)?.session,n);async function Zr(e,t=!0,o){let s=n(),l=i(),u=m(),d=g();zr++,c().size||p();let f=Xr(e,o)??e;if(s!==e||f!==l){if(l&&u.length&&(K.set(l,{events:u,total:d,at:Date.now()}),K.size>6)){let e=[...K.entries()].sort((e,t)=>e[1].at-t[1].at)[0];e&&K.delete(e[0])}h([]),W.clear(),Hn(),Rt(null),Tt(0),gt(!0),ia=void 0}r(e),a(f),O(D.get(e)??``),jr(null),Rr(!1),G(!1),Cn(l||s||`?`,yn()),bn(Sn(f||e)),localStorage.setItem(`teapot.session`,e),li(f,t);let v=K.get(f);v?.events.length&&(Nr(v.events),h(Nr(v.events)),_(v.total),requestAnimationFrame(()=>{n()===e&&Yr(!0)})),$(`/api/agents/${e}/load`,{method:`POST`}).then(cr).catch(()=>{}),await Wr(e,f),n()===e&&(Jt(t=>{let n=t.get(e)??null,r=Ye(n,m(),B()?.status);if(r===n)return t;let i=new Map(t);return r?i.set(e,r):i.delete(e),i}),Rt(B()?.ctx?.compacting?{phase:String(B().ctx.compacting)}:null),requestAnimationFrame(()=>{n()===e&&Yr(!0)}),Hr())}let[Qr,$r]=v(!1),ei=null,ti=null;C(()=>ei?.close());let ni=!1,ri=null;document.addEventListener(`visibilitychange`,()=>ri?.()),C(()=>{ri=null});let ii=!0,ai=null;async function oi(){let e=n(),t=m().at(-1)?.id,r=i(),a=document.visibilityState===`hidden`;if(!e||!t)ni=!0,a||ai?.();else try{let n=r&&r!==e?`&session=${encodeURIComponent(r)}`:``,i=Ar(),o=await $(`/api/agents/${e}/events?after=${encodeURIComponent(t)}${n}${i?`&branch=${encodeURIComponent(i)}&lineage=true`:``}`),s=o.events??[];o.gap?(h(Nr(s)),_(s.length)):s.length&&(Vr(s),_(e=>e+s.length)),await cr(),s.length&&!a&&lr()}catch{ni=!0}}function si(){ii=!0;let r=location.protocol===`https:`?`wss://`:`ws://`,a=new WebSocket(`${r}${location.host}/api/ws${gh()}`);ei=a,a.onopen=()=>{$r(!0),ii?ii=!1:oi()},a.onclose=()=>{$r(!1),setTimeout(si,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=>sr(e,c.agents));let n=e();Jt(e=>Je(e,e=>n.find(t=>t.id===e)?.status))}else if(c.kind===`event`&&Ue(c.event))Jt(e=>He(e,c.agentId));else if(c.kind===`llm-delta`){if(!Pt(c,n(),i()))return;if(Jt(e=>Ve(e,c.agentId,c)),c.agentId===n()){let e=String(c.reasoning??``),t=String(c.text??``);e&&!t?sn()||cn(Date.now()):t&&cn(0)}}else if(c.kind===`compaction-progress`){if(c.agentId!==n())return;c.phase===`done`?Rt(null):Rt({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]:sr(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())&&Cn(xn(),yn().filter(e=>e.promptId!==t.promptId)),o.has(e)&&!dh.has(e)||(In(c.agentId,c.event),c.event?.agent!==n())||!Nt(c.event,n(),i()))return;if(Vr([c.event]),c.event?.type===`message`&&c.event.data?.role===`assistant`){let e=nn();e&&Ge(e,m(),B()?.status)&&rn(null)}if(ni=!0,document.visibilityState!==`visible`||ti)return;ti=setTimeout(s,60)}document.visibilityState===`hidden`?ni=!0:ti||=setTimeout(s,120)}}},ni=!1;let s=async()=>{if(ti=null,await cr(),await lr(),n()){let e=m().at(-1)?.id,t=m().length;await Wr(n());let r=nn();r&&!Ye(r,m(),B()?.status)&&rn(null),m().at(-1)?.id!==e&&(ht()?(Jr(),jn(n())):(Tt(e=>e+Math.max(0,m().length-t)),Ot(Kr())))}};ai=s,ri=()=>{document.visibilityState===`visible`&&n()&&(ni?(ni=!1,s()):m().at(-1)?.id?oi():(ni=!0,s()))}}let ci=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function li(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let e=ci(),t=o().get(e);t&&(t!==n()||e!==i())&&Zr(t,!1,e||null)}),b(()=>{let e=B(),t=e?`${gn()?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`;document.title=An()>0?`(${An()}) ${t}`:t});let ui=()=>ae()||A()||V()!==null||ue()&&Se();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(ae()){oe(!1);return}if(A()){le(!1);return}if(V()){H(null);return}if(ue()&&Se()){Oe();return}let e=B();if(e&&gn()){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(cr);return}}else if(!ui()){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)we();else if(e.key===`t`)pi();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=wr().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&&Zr(t[i].id)}}});let[di,fi]=v(localStorage.getItem(`teapot.term`)===`1`),pi=()=>{let e=!di();fi(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[mi,hi]=v([]),[gi,_i]=v(0),[vi,yi]=v(-1),[bi,xi]=v(!1),[Si,Ci]=v(0),[wi,Ti]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),Ei=new Map,Di=[null,null],Oi=()=>mi()[Si()===0?gi():vi()]??null;function ki(e){if(!mi()[e])return;let t=Si(),n=t===0?gi():vi(),r=t===0?vi():gi(),i=e=>t===0?_i(e):yi(e);r===e?((e=>t===0?yi(e):_i(e))(n),i(e)):n!==e&&i(e)}let Ai=()=>ji();async function ji(e){let t=e??n();if(t){if(mi().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=cu(mi());hi(t=>[...t,{key:e.id,agentId:e.agentId,title:e.title}]),Si()===0?_i(n):yi(n)}catch(e){Q(`could not open a shell: ${e.message}`)}}}function Mi(e){let t=mi()[e];if(!t)return;$(`/api/terminals/${encodeURIComponent(t.key)}`,{method:`DELETE`}).catch(()=>{});let n=Ei.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),Ei.delete(t.key)}let r=mi().filter((t,n)=>n!==e);hi(r),_i(t=>uu(t,e,r.length)),yi(t=>t===-1?-1:uu(t,e,r.length))}b(()=>{je(),ke(),We(),Ne(),Re();for(let[,e]of Ei)Lt(e.term)});function Ni(){for(let[,e]of Ei){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}Ei.clear()}function Pi(e,t){let n=Ei.get(e.key);if(n&&Lt(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 iu({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:It()}),a=new su;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)}${gh()}`);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`),hi(t=>t.filter(t=>t.key!==e.key)),Ei.get(e.key)?.term.dispose(),Ei.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(()=>{Ei.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},Ei.set(e.key,n)}return n}function Fi(e){let t=Di[e];if(!t)return;let n=mi()[e===0?gi():vi()];if(!n){[...Ei.values()].some(e=>e.el.parentElement===t)&&t.replaceChildren();return}let r=Pi(n,t);for(let[e,r]of Ei)e!==n.key&&r.el.parentElement===t&&r.el.remove();requestAnimationFrame(()=>{r.el.parentElement!==t&&t.appendChild(r.el);try{r.fit()}catch{}if(Si()===(e===0?0:1))try{r.term.focus()}catch{}})}b(()=>{mi(),bi(),gi(),vi(),wi(),requestAnimationFrame(()=>{Fi(0),bi()&&Fi(1)})});let Ii=null;b(()=>{if(!di())return;let e=n();if(!e||e===Ii)return;Ii=e;let t=mi().map((e,t)=>({t:e,i:t})).filter(t=>t.t.agentId===e);t.length&&ki(t[t.length-1].i)}),b(()=>{let e=mi().length,t=lu(gi(),e);if(t!==gi()&&_i(t),bi()){let t=lu(vi(),e);t!==vi()&&yi(t)}});let Li=e=>{e.preventDefault();let t=e.clientY,n=wi(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));Ti(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(wi())),requestAnimationFrame(()=>{Fi(0),bi()&&Fi(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},Ri=()=>{let e=!bi();xi(e),e&&(vi()<0||vi()===gi()||vi()>=mi().length)&&yi(du(gi(),mi().length)),requestAnimationFrame(()=>{Fi(0),bi()&&Fi(1)})};C(Ni);let zi=e=>t=>{Di[e]=t,t&&requestAnimationFrame(()=>{Fi(e),bi()&&Fi(1),setTimeout(()=>Fi(e),200)})};ee(()=>{Yn(),cr().then(async()=>{await p();let t=ci(),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&&Zr(r.id,!1,t||null)}),lr(),fr(),Ui(),si(),$(`/api/terminals`).then(e=>{let t=e.terminals??[];t.length&&(hi(t.map(e=>({key:e.id,agentId:e.agentId,title:e.title}))),di()&&(_i(0),yi(-1)))}).catch(()=>{});let t=setInterval(()=>{lr(),fr()},3e4);C(()=>clearInterval(t))});let Bi=[{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`}],[Vi,Hi]=v([]),Ui=()=>$(`/api/personas`).then(e=>Hi(e.personas)).catch(()=>{}),[Wi,Gi]=v(!1),Ki=()=>{let e=ne().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},qi=()=>{let t=Ki();return t===null?[]:[...Vi().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))},Ji=new Set([`start`,`stop`,`fork`,`compact`]),[Yi,Xi]=v([]),[Zi,Qi]=v(null),[$i,ea]=v(-1),ta=()=>{let e=ne();if(!e.startsWith(`/`)||e.includes(`
|
|
23
|
-
`))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[2]??``).trim();if(!r&&n!==`skill`){let e=Bi.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Ji.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=Yi().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[]},na,ra=()=>{if(!na)return;let e=dt();if(!na.value&&!e){na.style.height=``;return}na.style.height=`auto`;let t=e?-1:tn(na.scrollHeight,360);na.style.height=t===-1?``:`${t}px`,na.scrollHeight},ia,aa=null,oa,sa=null,ca=0,la=4,ua;b(()=>{let e=ne();na&&Kt(sh)&&(qt(na.value,e)&&(na.value=e),ra())});let[da,fa]=v([]),pa=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=()=>{fa(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},ma=async(e,t)=>{let r=t??n();if(!r)return;let i=da();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}:{}})});Cn(xn(),[...yn(),{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)}:{}}]),fa([]),dt()&&pt(!1),ra(),ht()&&requestAnimationFrame(()=>{ht()&&Jr()})}catch(t){O(e),console.error(`send failed:`,t)}},ha=async t=>{t.preventDefault();let r=n(),i=ne().trim();if(r&&i){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=Vi().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:Wi()?`fork`:`none`})})).id}${Wi()?` (forked context)`:``}`),cr(),O(``)}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}`),O(``)}else{Q(`unknown @${r} — personas: ${Vi().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){O(`/goal `);return}if(t===`skill`&&!n){O(`/skill `);return}O(``);try{await ga(t,n)}catch(e){throw O(ne()?`${i}\n${ne()}`:i),e}}else O(``),await ma(i)}},ga=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(cr);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Zr(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 ma(`[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}`)}},_a,va=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!_a)return;let e=Math.min(va,_a.scrollHeight);Math.abs(_a.scrollTop-e)>1&&(_a.scrollTop=e)})})});let ya=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(cr),q=async()=>{let i=n();if(!i)return;let a=new Set([i,...xt(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=fu(e(),a);s?Zr(s.id):(r(null),h([]))},ba=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),cr())},xa=()=>$(`/api/agents/${B().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await p(!0),await Zr(B().id)}),[Sa,Ca]=v(``),[wa,Ta]=v(``),[Ea,Da]=v(!1),[Oa,ka]=v(!0),Aa=``;b(()=>{let e=n();e&&(B()?.goal,e!==Aa&&(Aa=e,Da(!1),Ca(``),Ta(``)))});let ja=async e=>{if(e.preventDefault(),n()&&Sa().trim())try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:Sa(),notify:Oa(),...wa().trim()?{verify:wa()}:{}})}),Ca(``),Ta(``),Da(!1),cr()}catch(e){Q(`goal save failed: ${e.message}`)}};return[M(P,{get when(){return k()?.needsSetup},fallback:null,get children(){return M(Jh,{onDone:()=>location.reload()})}}),M(P,{get when(){return Xn()},get children(){var e=yu();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}}),
|
|
24
|
-
`))),e}}),null),z(r,M(P,{get when(){return t.a.goal.status===`done`},get children(){return nd()}}),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=bt(t.a.id,Vi().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&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),d!==e.i&&L(i,`title`,e.i=d),f!==e.n&&R(a,e.n=f),p!==e.s&&L(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(),kn(!On()),On()||Tn(e=>e.map(e=>({...e,read:!0})))},z(o,M(P,{get when(){return An()>0},get children(){var e=bu();return z(e,An),e}}),null),z(a,M(Ah,{icon:`👻`,get active(){return En()},get title(){return En()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!En();if(Dn(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&B()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Zr(t.id)}}}),null),z(a,M(Ah,{icon:`+`,title:`new agent`,onClick:()=>{Yn(),oe(!0)}}),null),z(a,M(Ah,{icon:`⚙`,title:`settings`,onClick:()=>{Yn(),le(!0)}}),null),z(c,`0.35.
|
|
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=Bi.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&Ji.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=Yi().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[]},na,ra=()=>{if(!na)return;let e=dt();if(!na.value&&!e){na.style.height=``;return}na.style.height=`auto`;let t=e?-1:tn(na.scrollHeight,360);na.style.height=t===-1?``:`${t}px`,na.scrollHeight},ia,aa=null,oa,sa=null,ca=0,la=4,ua;b(()=>{let e=ne();na&&Kt(sh)&&(qt(na.value,e)&&(na.value=e),ra())});let[da,fa]=v([]),pa=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=()=>{fa(n=>[...n,{url:String(t.result),name:e.name}].slice(0,4))},t.readAsDataURL(e)}},ma=async(e,t)=>{let r=t??n();if(!r)return;let i=da();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}:{}})});Cn(xn(),[...yn(),{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)}:{}}]),fa([]),dt()&&pt(!1),ra(),ht()&&requestAnimationFrame(()=>{ht()&&Jr()})}catch(t){O(e),console.error(`send failed:`,t)}},ha=async t=>{t.preventDefault();let r=n(),i=ne().trim();if(r&&i){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=Vi().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:Wi()?`fork`:`none`})})).id}${Wi()?` (forked context)`:``}`),cr(),O(``)}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}`),O(``)}else{Q(`unknown @${r} — personas: ${Vi().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){O(`/goal `);return}if(t===`skill`&&!n){O(`/skill `);return}O(``);try{await ga(t,n)}catch(e){throw O(ne()?`${i}\n${ne()}`:i),e}}else O(``),await ma(i)}},ga=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(cr);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Zr(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 ma(`[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}`)}},_a,va=0;b(()=>{e(),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(!_a)return;let e=Math.min(va,_a.scrollHeight);Math.abs(_a.scrollTop-e)>1&&(_a.scrollTop=e)})})});let ya=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(cr),q=async()=>{let i=n();if(!i)return;let a=new Set([i,...xt(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=fu(e(),a);s?Zr(s.id):(r(null),h([]))},ba=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),cr())},xa=()=>$(`/api/agents/${B().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(async()=>{await p(!0),await Zr(B().id)}),[Sa,Ca]=v(``),[wa,Ta]=v(``),[Ea,Da]=v(!1),[Oa,ka]=v(!0),Aa=``;b(()=>{let e=n();e&&(B()?.goal,e!==Aa&&(Aa=e,Da(!1),Ca(``),Ta(``)))});let ja=async e=>{if(e.preventDefault(),n()&&Sa().trim())try{await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:Sa(),notify:Oa(),...wa().trim()?{verify:wa()}:{}})}),Ca(``),Ta(``),Da(!1),cr()}catch(e){Q(`goal save failed: ${e.message}`)}};return[M(P,{get when(){return k()?.needsSetup},fallback:null,get children(){return M(Jh,{onDone:()=>location.reload()})}}),M(P,{get when(){return Xn()},get children(){var e=yu();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}}),'/** * The wallpaper layer lives OUTSIDE `.layout`, as its own sibling. * * This is the whole fix for "背景色があるときにUIのほぼすべてが透明になってほぼ何も見えない": * the image was INSIDE `.layout`, which is `position: relative; z-index: 1` and therefore a * stacking context. Within that context `.bgphoto` had `z-index: 0`, while the sidebar, the * feed and the panels are ordinary STATIC elements — so the positioned image painted ON TOP of * all of them. What looked like transparency was the photo covering the UI with the text * faintly showing through. * * A backdrop cannot be a child of the thing it sits behind. As a sibling with `z-index: -1` it * is behind `.layout`\'s own stacking context, and no z-index inside the app can accidentally * interact with it. */',M(P,{get when(){return ce()},children:e=>(()=>{var t=Xu();return y(n=>{var r=e(),i=se.map(t=>`${e()}?w=${t} ${t}w`).join(`, `);return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`srcset`,n.t=i),n},{e:void 0,t:void 0}),t})()}),M(P,{get when(){return!k()?.needsSetup},get children(){var t=Gu(),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,z(i,M(N,{get each(){return kr()},children:t=>[M(P,{get when(){return F(()=>t.wsHeader!==void 0)()&&t.wsHeader!==``},get children(){var e=Qu(),n=e.firstChild;return e.$$click=()=>Tr(`ws:${t.wsHeader}`,Er(t.wsHeader),t.wsCollapsedGroup===!0,t.collapsedVia),z(n,()=>t.wsCollapsedGroup?`▸`:`▾`),z(e,()=>Er(t.wsHeader),null),z(e,M(P,{get when(){return(Or().get(t.wsHeader)??0)>1||t.wsCollapsedGroup},get children(){var e=Zu();return z(e,()=>Or().get(t.wsHeader)??0),e}}),null),y(()=>L(e,`title`,t.wsCollapsedGroup?`${t.wsHeader} — collapsed (${Dr(t.wsHeader)} hidden). Click to show.`:(Or().get(t.wsHeader)??0)>1?`${t.wsHeader} — ${Dr(t.wsHeader)} in this directory`:t.wsHeader||``)),e}}),M(P,{get when(){return F(()=>!t.headerOnly)()&&!t.wsCollapsedGroup},get children(){var r=rd(),i=r.firstChild,a=i.nextSibling;return r.$$click=()=>Zr(t.a.id),z(r,M(P,{get when(){return yt({isSub:!!t.a.parent,collapsed:t.chatCollapsedGroup===!0,hasChildren:e().some(e=>e.parent===t.a.id)})},get fallback(){return id()},get children(){return(()=>{let e=!t.a.parent,n=e&&Cr().has(`chat:${t.a.id}`)||vr(t.a.id);return(()=>{var r=ad();return r.$$click=r=>{if(r.stopPropagation(),e){if(n){if(!mr().has(t.a.id)){let e=new Set(mr());e.add(t.a.id),hr(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}if(gr().has(t.a.id)){let e=new Set(gr());e.delete(t.a.id),_r(e),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...e]))}}else if(mr().has(t.a.id)){let e=new Set(mr());e.delete(t.a.id),hr(e),localStorage.setItem(`teapot.expandedSubs`,JSON.stringify([...e]))}Tr(`chat:${t.a.id}`,t.a.id,n)}else yr(t.a.id)},z(r,n?`▸`:`▾`),y(()=>L(r,`title`,e?n?`show ${t.a.id}`:`hide ${t.a.id} and its sub-agents`:n?`expand sub-agents`:`collapse sub-agents`)),r})()})()}}),i),z(a,()=>t.a.sessionTitle??u().get(t.a.session??``)??t.a.id),z(r,(()=>{var e=F(()=>!!t.a.workspaceMissing);return()=>e()?od():null})(),null),z(r,M(P,{get when(){return Nn(t.a.id)>0},get children(){var e=$u();return e.firstChild,z(e,()=>Nn(t.a.id),null),y(()=>L(e,`title`,`${Nn(t.a.id)} unread notification${Nn(t.a.id)>1?`s`:``} (including sub-agents)`)),e}}),null),z(r,M(P,{get when(){return vr(t.a.id)||t.chatCollapsedGroup===!0&&Cr().has(`chat:${t.a.id}`)},get children(){return(()=>{let n=xt(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=sd();return e.firstChild,R(e,`subcount`+(r>0?` live`:``)),z(e,()=>n.length,null),z(e,r>0?` · ▶${r}`:``,null),y(()=>L(e,`title`,`${n.length} sub-agent${n.length>1?`s`:``} (${r} active)`)),e})():null})()}}),null),z(r,M(P,{get when(){return t.a.parent},get children(){return ed()}}),null),z(r,M(P,{get when(){return pr(t.a.id).length>0},get children(){var e=td();return y(()=>L(e,`title`,pr(t.a.id).map(e=>`${e.id}: ${e.schedule}`).join(`
|
|
24
|
+
`))),e}}),null),z(r,M(P,{get when(){return t.a.goal.status===`done`},get children(){return nd()}}),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=bt(t.a.id,Vi().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&&R(r,e.e=o),e.t=Te(r,s,e.t),c!==e.a&&L(r,`title`,e.a=c),l!==e.o&&R(i,e.o=l),d!==e.i&&L(i,`title`,e.i=d),f!==e.n&&R(a,e.n=f),p!==e.s&&L(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(),kn(!On()),On()||Tn(e=>e.map(e=>({...e,read:!0})))},z(o,M(P,{get when(){return An()>0},get children(){var e=bu();return z(e,An),e}}),null),z(a,M(Ah,{icon:`👻`,get active(){return En()},get title(){return En()?`show ghost sessions again (👻 workspace missing on disk)`:`hide ghost sessions (👻 — their workspace directory no longer exists)`},onClick:t=>{t.stopPropagation();let r=!En();if(Dn(r),localStorage.setItem(`teapot.hideGhosts`,r?`1`:`0`),r&&n()&&B()?.workspaceMissing){let t=e().find(e=>!e.workspaceMissing);t&&Zr(t.id)}}}),null),z(a,M(Ah,{icon:`+`,title:`new agent`,onClick:()=>{Yn(),oe(!0)}}),null),z(a,M(Ah,{icon:`⚙`,title:`settings`,onClick:()=>{Yn(),le(!0)}}),null),z(c,`0.35.17`,null),z(d,M(P,{get when(){return E()},get children(){return[`master rss `,F(()=>E().rssMb),`MB · heap `,F(()=>E().heapUsedMb),`MB`,xu(),`load1 `,F(()=>E().loadavg1),` · up `,F(()=>Math.floor(E().uptimeSec/60)),`m`]}})),z(f,M(P,{get when(){return B()?.id},keyed:!0,get fallback(){return cd()},get children(){return[(()=>{var t=wu(),r=t.firstChild.nextSibling,i=r.nextSibling,a=i.nextSibling,o=a.firstChild,s=o.nextSibling,c=s.nextSibling.nextSibling,l=c.nextSibling.nextSibling,u=l.nextSibling.nextSibling;u.nextSibling;var d=a.nextSibling,f=d.firstChild,p=f.nextSibling;return z(r,()=>B().id),z(i,()=>B().status),z(t,M(P,{get when(){return(B().pendingPromptIds?.length??B().pendingPrompts??0)>0},get children(){var e=Su(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>B().pendingPromptIds?.length??B().pendingPrompts,t),z(e,()=>B().status===`stopped`?` (stopped)`:``,null),y(()=>L(e,`title`,B().status===`stopped`?`${B().pendingPromptIds?.length??B().pendingPrompts??0} message${(B().pendingPromptIds?.length??B().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.`:`${B().pendingPromptIds?.length??B().pendingPrompts??0} message${(B().pendingPromptIds?.length??B().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}}),a),z(t,M(P,{get when(){return pr(B().id).length>0},get children(){var e=Cu();return e.firstChild,z(e,()=>pr(B().id).length,null),y(()=>L(e,`title`,`scheduled tasks:\n${pr(B().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
|
|
25
25
|
`)}`)),e}}),a),z(a,()=>B().model,o),z(a,()=>B().session,s),z(a,()=>B().branch,c),z(a,()=>B().stats.turns,l),z(a,()=>B().stats.toolCalls,u),f.$$click=()=>(gn()?ya(`/stop`):ya(`/start`))(),z(f,()=>gn()?`■ stop`:`▶ start`),z(d,M(P,{get when(){return e().some(e=>e.parent===n())},get children(){return M(Ah,{icon:`⏹`,title:`stop every sub-agent this agent spawned (descendants included)`,onClick:ba})}}),p),z(d,M(Ah,{icon:`⑂`,title:`fork: branch off the conversation here — try things without disturbing the main line`,onClick:xa}),null),z(d,M(Ah,{icon:`⌨`,title:`terminal (t)`,onClick:pi}),null),z(d,M(Ah,{icon:`▤`,title:`toggle details panel (d)`,get active(){return Se()},onClick:we}),null),z(d,M(Ah,{icon:`🗄`,title:`archive this agent — reversible: it leaves the list but keeps its config and history (restore in ⚙ settings → archive)`,onClick:q}),null),y(e=>{var t=`badge ${B().status}`,n=B().statusReason&&!/^(round complete|prompt|api start|goal set|created via web|start)$/.test(B().statusReason)?`${B().status} — ${B().statusReason}`:void 0,r=`${B().model} · ${B().session}/${B().branch} · turns ${B().stats.turns} · tools ${B().stats.toolCalls}`,o=`runbtn`+(gn()?` danger`:``),s=gn()?`interrupt: aborts the current LLM call; the running tool finishes first`:`run toward the goal (starts the loop)`;return t!==e.e&&R(i,e.e=t),n!==e.t&&L(i,`title`,e.t=n),r!==e.a&&L(a,`title`,e.a=r),o!==e.o&&R(f,e.o=o),s!==e.i&&L(f,`title`,e.i=s),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),t})(),(()=>{var e=ju();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r={top:t.scrollTop,height:t.scrollHeight,viewport:t.clientHeight},i=Zt(r,aa,oa,ua);i===`layout`&&la>0&&Math.abs(r.height-(oa??r.height))>1&&(la--,ve(t,sa)),aa=null,oa=r.height,ua=r.viewport,Ot(r);let a=ht(),o=performance.now();o-ca>100&&(ca=o,sa=xe(t));let s=$t(a,i,r);s!==a&>(s),i===`reader`&&(la=4),s&&i!==`reader`?(vt()&&Tt(0),Mn(),Qt(s,r)&&Yt(r)>0&&Jr()):s&&Xt(r)&&(vt()&&Tt(0),Mn()),r.top<=4&&n()&&!Pr()&&!Lr()&&m().length>0&&Ur()}),De(e=>be(e),e),z(e,M(P,{get when(){return Mt()},children:e=>(()=>{var t=ld();return t.firstChild,z(t,(()=>{var t=F(()=>e().phase===`harvesting`);return()=>t()?`saving durable lessons…`:`summarizing ${e().summarized?Dh(e().summarized)+` `:``}older messages…`})(),null),t})()}),null),z(e,M(P,{get when(){return F(()=>!!Lr())()&&Wn().length>0},get children(){return Tu()}}),null),z(e,M(P,{get when(){return Pr()},get children(){return Eu()}}),null),z(e,M(P,{get when(){return Wn().length>0},get fallback(){return F(()=>!!Fr())()?ud():dd()},get children(){return[M(N,{get each(){return Wn()},children:e=>M(Sh,{e,prev:()=>Kn(e,-1),next:()=>Kn(e,1),get showBranch(){return w().length>1},res:()=>Rn().resFor.get(e.id),get orphan(){return Rn().orphanCalls.has(e.id)},onOption:e=>void ma(e),answeredIds:Un,onAnswered:Vn,get agentActive(){return F(()=>!!_n())()&&qe(e)},onResize:()=>{ht()&&Jr()},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??``);O(ne()?`${n}\n\n${ne()}`:n),Cn(xn(),yn().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&&!gn()?()=>H({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),M(P,{get when(){return F(()=>!!_n())()&&nn()},get children(){var e=Au(),t=e.firstChild.nextSibling;return t.firstChild,z(t,M(P,{get when(){return dn().trim()!==``},get children(){var e=Du(),t=e.firstChild;t.firstChild;var n=t.nextSibling;return z(t,M(yh,{get startedAt(){return un()}}),null),De(e=>{let t=!0;e.addEventListener(`scroll`,()=>{t=e.scrollHeight-e.scrollTop-e.clientHeight<24}),b(()=>{dn(),t&&(e.scrollTop=e.scrollHeight)})},n),z(n,dn),e}}),null),z(t,M(P,{get when(){return an()},get fallback(){return fd()},get children(){return M(P,{get when(){return zt()},get fallback(){return(()=>{var e=ku();return y(()=>e.innerHTML=Fe(an()+`▍`)),e})()},get children(){return[Ou(),(()=>{var e=ku();return y(()=>e.innerHTML=Fe(Bt()+`▍`)),e})()]}})}}),null),e}})]}}),null),e})(),M(P,{get when(){return di()},get children(){var t=Iu(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=r.nextSibling,c=s.firstChild;n.$$dblclick=()=>{Ti(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(wi()))},n.$$pointerdown=Li,z(i,M(N,{get each(){return mi()},children:(e,t)=>(()=>{var n=pd(),r=n.firstChild.nextSibling;return n.$$click=()=>ki(t()),z(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),Mi(t())},y(r=>{var i=`termtab`+(Si()===0&&gi()===t()?` active`:``)+(bi()&&Si()===1&&vi()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),null),z(i,M(Ah,{icon:`+`,title:`new shell in this workspace`,onClick:Ai}),null),z(o,(()=>{var t=F(()=>!!Oi());return()=>t()?e().find(e=>e.id===Oi().agentId)?.workspace.split(`/`).filter(Boolean).pop():B()?.workspace})()),z(a,M(Ah,{icon:`◫`,get title(){return bi()?`single pane`:`split panes (50/50)`},onClick:Ri}),null),z(a,M(Ah,{icon:`▾`,title:`hide the terminal (shells keep running; reopen with t) — close individual shells with their ✕ tab buttons`,onClick:pi}),null);var l=zi(0);return typeof l==`function`&&De(l,c),c.$$pointerdown=()=>Ci(0),z(c,M(P,{get when(){return gi()<0||gi()>=mi().length},get children(){return Mu()}})),z(s,M(P,{get when(){return bi()},get children(){return[Nu(),(()=>{var e=Fu(),t=zi(1);return typeof t==`function`&&De(t,e),e.$$pointerdown=()=>Ci(1),z(e,M(P,{get when(){return vi()<0||vi()>=mi().length},get children(){return Pu()}})),y(()=>e.classList.toggle(`focused`,Si()===1)),e})()]}}),null),y(e=>{var n={height:`${wi()}px`},r=!!bi(),i=Si()===0;return e.e=Te(t,n,e.e),r!==e.t&&s.classList.toggle(`split`,e.t=r),i!==e.a&&c.classList.toggle(`focused`,e.a=i),e},{e:void 0,t:void 0,a:void 0}),t}}),(()=>{var e=Uu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=r.nextSibling,a=i.nextSibling;return z(e,M(P,{get when(){return F(()=>Et()>32)()&&!ht()},get children(){var e=Lu();return e.firstChild,e.$$click=()=>{Yr(!0),Mn()},z(e,(()=>{var e=F(()=>vt()>0);return()=>e()?`${vt()} new message${vt()>1?`s`:``}`:`jump to present`})(),null),e}}),t),z(e,M(P,{get when(){return ta().length>0},get children(){var e=Ru();return z(e,M(N,{get each(){return ta()},children:(e,t)=>(()=>{var n=md(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{O(e.insert),ea(-1)},z(r,()=>e.insert.trim()),z(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===$i()?` active`:``),a=e.title;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),z(e,M(P,{get when(){return qi().length>0},get children(){var e=Ru();return z(e,M(N,{get each(){return qi()},children:e=>(()=>{var t=hd(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{O(`@${e.key} `),ea(-1)},z(n,()=>e.key,null),z(r,()=>e.label),y(()=>L(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,ha),z(t,M(P,{get when(){return da().length>0},get children(){var e=zu(),t=e.firstChild,n=t.firstChild,r=n.nextSibling;return r.nextSibling,z(e,M(N,{get each(){return da()},children:(e,t)=>(()=>{var n=gd(),r=n.firstChild,i=r.nextSibling;return i.$$click=()=>fa(e=>e.filter((e,n)=>n!==t())),y(t=>{var i=e.name,a=e.url,o=e.name;return i!==t.e&&L(n,`title`,t.e=i),a!==t.t&&L(r,`src`,t.t=a),o!==t.a&&L(r,`alt`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),n})()}),t),z(t,()=>da().length,n),z(t,()=>da().length>1?`s`:``,r),e}}),n),n.$$keydown=e=>{let t=ta();t.length>0&&e.key===`ArrowDown`?(e.preventDefault(),ea(e=>Math.min(e+1,t.length-1))):t.length>0&&e.key===`ArrowUp`?(e.preventDefault(),ea(e=>Math.max(e-1,0))):t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&$i()>=0&&!sh?(e.preventDefault(),O(t[$i()].insert),ea(-1)):e.key===`Escape`&&t.length>0?ea(-1):e.key===`Enter`&&!e.shiftKey&&!sh&&!dt()&&(e.preventDefault(),ha(e))},n.$$input=e=>{O(e.currentTarget.value),ea(0),ra()},n.addEventListener(`paste`,e=>{let t=Array.from(e.clipboardData?.files??[]).filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),pa(t))}),n.addEventListener(`compositionend`,()=>{requestAnimationFrame(()=>{sh=!1}),O(na?.value??``)}),n.addEventListener(`compositionstart`,()=>{sh=!0}),De(e=>{na=e,e.value=ne()},n),z(t,M(P,{get when(){return F(()=>!!ne().startsWith(`@`))()&&ne().includes(` `)},get children(){var e=Bu(),t=e.firstChild;return t.addEventListener(`change`,e=>Gi(e.currentTarget.checked)),y(()=>t.checked=Wi()),e}}),r),r.$$click=()=>{let e=!dt();pt(e),requestAnimationFrame(()=>ra())},z(r,()=>dt()?`⤡`:`⤢`),z(t,M(Ah,{icon:`📎`,title:`attach images (or paste them straight into the box)`,onClick:()=>document.getElementById(`composer-file`)?.click()}),i),z(t,M(P,{get when(){return da().length},get children(){var e=Vu();return e.firstChild,z(e,()=>da().length,null),e}}),i),a.addEventListener(`change`,e=>{e.currentTarget.files?.length&&pa(e.currentTarget.files),e.currentTarget.value=``}),z(e,M(P,{get when(){return ih()},get children(){var e=Hu();return z(e,ih),e}}),null),y(t=>{var i=`composer`+(dt()?` maximized`:``),a=`message #${B().id} — / for commands · paste or 📎 to attach images`,o=dt()?`restore composer (hide timeline)`:`maximize composer — hide the timeline and fill the main column`;return i!==t.e&&R(e,t.e=i),a!==t.t&&L(n,`placeholder`,t.t=a),o!==t.a&&L(r,`title`,t.a=o),t},{e:void 0,t:void 0,a:void 0}),e})()]}})),z(t,M(P,{get when(){return F(()=>!!de())()&&Se()},get children(){var e=Wu();return e.$$click=()=>Ce(!1),e}}),p),p.addEventListener(`scroll`,e=>{va=e.currentTarget.scrollTop});var v=_a;return typeof v==`function`?De(v,p):_a=p,z(g,M(Ah,{icon:`✕`,title:`close details panel (esc)`,onClick:Oe}),null),z(p,M(P,{get when(){return B()?.id},keyed:!0,fallback:null,children:t=>[M(P,{get when(){return B().id},keyed:!0,fallback:null,children:e=>M(Wh,{agentId:e,get workspace(){return B().workspace}})}),_d(),(()=>{var t=bd(),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;ut=!0,Qe(r),et(Ut(k().providers,r,e().find(e=>e.id===n()))),ot(r)}),z(r,M(N,{get each(){return at()},children:e=>(()=>{var t=Vd();return t.value=e,z(t,e,null),z(t,()=>e===k().defaultProvider?` ★`:``,null),t})()})),a.$$input=e=>et(e.currentTarget.value),z(o,M(N,{get each(){return rt()},children:e=>(()=>{var t=Vd();return y(()=>t.value=e.id),t})()})),z(t,M(P,{get when(){return B().effortSupported},get children(){var e=vd(),t=e.firstChild.nextSibling;return t.firstChild,t.addEventListener(`change`,e=>nt(e.currentTarget.value)),z(t,M(N,{get each(){return F(()=>!!B().effortOptions?.length)()?B().effortOptions:eh},children:e=>(()=>{var t=Vd();return t.value=e,z(t,e),t})()}),null),y(()=>t.value=tt()),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:Ze(),model:$e().trim()||void 0,contextWindowTokens:rt().find(e=>e.id===($e().trim()||void 0))?.contextLength,...B().effortSupported?{reasoningEffort:tt()}:{}})}),t.textContent=`✓ applied`,cr()}catch(e){alert(`apply failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},z(l,()=>B().model,null),z(l,M(P,{get when(){return rt().length},get children(){return[` · `,F(()=>rt().length),` models loaded`]}}),null),z(t,M(P,{get when(){return ct()},get children(){var e=yd();return z(e,ct),e}}),null),y(()=>L(a,`placeholder`,Wt(k().providers,Ze(),B(),Vt(B(),k().providers,k().defaultProvider)))),y(()=>r.value=Ze()),y(()=>a.value=$e()),t})(),(()=>{var e=xd(),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(cr)}),y(()=>t.checked=B().autoContinue??!0),e})(),(()=>{var e=Cd();return e.firstChild,z(e,M(P,{get when(){return!!B().goal.text.trim()},get fallback(){return Hd()},get children(){var e=Sd();return z(e,()=>B().goal.status),y(()=>R(e,`badge ${B().goal.status===`active`?`running`:B().goal.status}`)),e}}),null),e})(),(()=>{var e=wd();return e.firstChild,z(e,M(N,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Ud();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(cr)},L(t,`title`,e===`active`?`agent keeps working toward the goal (with auto-continue)`:e===`done`?`mark achieved — auto-continue stops`:`parked on purpose — resume by setting active again`),z(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(B().goal.text.trim()&&B().goal.status===e?` on ${e}`:``),i=!!B().goal.text.trim()&&B().goal.status===e;return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),M(P,{get when(){return B().goal.text},get fallback(){return Wd()},get children(){return[(()=>{var e=Td(),t=e.firstChild;return y(()=>t.innerHTML=Fe(String(B().goal.text))),e})(),M(P,{get when(){return B().goal.verify},get children(){var e=Ed(),t=e.firstChild.nextSibling;return y(()=>t.innerHTML=Fe(String(B().goal.verify))),e}}),M(P,{get when(){return B().goal.audit},children:e=>(()=>{var t=Gd(),n=t.firstChild,r=n.firstChild,i=n.nextSibling;return z(n,()=>e().verdict===`approved`?`✅ audit: approved`:`⚠ audit: changes required`,r),z(r,()=>Eh(e().at)),y(n=>{var r=`card auditcard `+(e().verdict===`approved`?`ok`:`warn`),a=mt(e().feedback)?Fe(`_the auditor returned a verdict with no detail_`):Fe(e().feedback);return r!==n.e&&R(t,n.e=r),a!==n.t&&(i.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t})()})]}}),(()=>{var e=Dd(),t=e.firstChild,n=t.nextSibling,r=n.nextSibling.firstChild.firstChild;return e.addEventListener(`submit`,ja),t.$$input=e=>{Ca(e.currentTarget.value),Da(!0)},n.$$input=e=>{Ta(e.currentTarget.value),Da(!0)},r.addEventListener(`change`,e=>ka(e.currentTarget.checked)),y(()=>t.value=Sa()),y(()=>n.value=wa()),y(()=>r.checked=Oa()),e})(),(()=>{var e=kd(),t=e.firstChild.nextSibling;return z(e,M(P,{get when(){return or().total>0},get children(){var e=Od(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,z(e,()=>or().done,t),z(e,()=>or().total,n),y(t=>Te(e,or().done===or().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),M(P,{get when(){return or().total>0},get children(){var e=Ad(),t=e.firstChild;return y(e=>{var n=`barfill `+(or().done===or().total?``:`warn`),r=`${Math.round(or().done/or().total*100)}%`;return n!==e.e&&R(t,e.e=n),r!==e.t&&Ee(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),M(Uh,{get draft(){return Qn()},get preview(){return er()},onDraft:e=>{$n(e),rr(!0)}}),(()=>{var e=jd(),t=e.firstChild,n=t.nextSibling;return z(e,M(Ah,{get icon(){return er()?`✎`:`👁`},get title(){return er()?`edit markdown`:`rendered checklist`},onClick:()=>tr(!er())}),t),n.$$click=ar,e})(),Md(),M(P,{get when(){return B().latestProgress},get fallback(){return Kd()},children:e=>(()=>{var t=Zd(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return z(t,M(P,{get when(){return e().recent},get children(){var t=qd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=$m(e().recent)),t}}),i),z(t,M(P,{get when(){return e().problems},get children(){var t=Jd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=$m(e().problems)),t}}),i),z(t,M(P,{get when(){return e().next},get children(){var t=Yd(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=$m(e().next)),t}}),i),z(t,M(P,{get when(){return e().goalStatus},get children(){var t=Xd(),n=t.firstChild.nextSibling;return z(n,()=>e().goalStatus),t}}),i),z(i,()=>Eh(e().ts)),y(()=>r.innerHTML=$m(e().doing)),t})()}),Nd(),(()=>{var e=Id(),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 z(e,M(P,{get when(){return B().ctx},keyed:!0,get fallback(){return Qd()},children:e=>{let t=x(()=>{let t=e,n=rt().find(e=>e.id===B().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=nf(),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 z(a,()=>Dh(r().usedTokens),o),z(t,M(P,{get when(){return r().effectiveWindow},get children(){var e=$d(),t=e.firstChild;return z(e,()=>i(r().pct),t),z(e,()=>Dh(r().effectiveWindow),null),y(()=>R(e,`pill ${r().cls}`)),e}}),null),z(e,M(P,{get when(){return r().effectiveWindow},get children(){var e=ef(),t=e.firstChild;return y(e=>{var n=`barfill ${r().cls}`,i=`${Math.min(100,r().pct)}%`;return n!==e.e&&R(t,e.e=n),i!==e.t&&Ee(t,`width`,e.t=i),e},{e:void 0,t:void 0}),e}}),s),z(c,()=>Dh(r().usingDerived?r().derivedBudget:r().compactAt),l),z(u,()=>r().usingDerived?`75% of window`:`manual`),z(e,M(P,{get when(){return Mt()||r().compacting},get children(){var e=tf(),t=e.firstChild.nextSibling.nextSibling;return z(t,()=>Mt()?.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(cr)}),y(()=>f.checked=B().autoCompact!==!1),e})()}}),t),z(i,()=>Dh(B().stats.inputTokens)),z(o,()=>Dh(B().stats.outputTokens)),z(c,()=>B().stats.turns),z(u,()=>B().stats.toolCalls),z(f,()=>B().stats.compactions??0),z(t,M(P,{get when(){return(B().stats.costUsd??0)>0},get children(){var e=Pd(),t=e.firstChild.nextSibling;return t.firstChild,z(t,()=>Oh(B().stats.costUsd??0),null),y(()=>L(e,`title`,`≈ ${(B().stats.costUsd??0).toFixed(4)} this session, from the model's USD/token pricing and per-turn usage. Cached input is estimated at ~10% of the prompt rate; treat as an approximation, not an invoice.`)),e}}),null),z(t,M(P,{get when(){return(B().stats.cachedInputTokens??0)>0},get children(){var e=Fd(),t=e.firstChild.nextSibling,n=t.firstChild;return z(t,()=>Math.round(B().stats.cachedInputTokens/Math.max(1,B().stats.inputTokens)*100),n),y(()=>L(e,`title`,`${Dh(B().stats.cachedInputTokens)} input tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),y(()=>L(d,`title`,`how many times old turns were summarized into notes to make room. ${B().stats.compactions?`Each one keeps the recent stretch verbatim.`:`Not yet — the context has fit so far.`}`)),e})(),(()=>{var e=Rd();return e.firstChild.nextSibling,z(e,M(P,{get when(){return Ar()},get children(){var e=Ld(),t=e.firstChild.nextSibling;return z(t,Ar),e}}),null),e})(),M(N,{get each(){return w()},children:e=>(()=>{var t=rf(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=Ar()===e.branch?null:e.branch,r=t!==Ar();jr(t),n()&&(r&&(zr++,h([]),_(0),Rr(!1)),Wr(n()))},z(r,()=>e.branch,null),z(r,()=>e.branch===B().branch?` (current)`:``,null),z(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===B().branch||e.branch===Ar()?` cur`:``),i=e.branch===Ar()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),(()=>{var e=Bd();return e.firstChild,z(e,M(P,{get when(){return ur().length>0},get children(){var e=zd(),t=e.firstChild.nextSibling;return t.nextSibling,z(e,()=>ur().length,t),e}}),null),e})(),M(P,{get when(){return ur().length>0},get fallback(){return af()},get children(){return M(N,{get each(){return ur()},children:e=>(()=>{var t=sf(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Zr(e.agent),z(i,()=>e.id),z(a,()=>e.agent,null),z(r,M(P,{get when(){return e.forked},get children(){return of()}}),null),z(o,()=>e.schedule,s),z(o,(()=>{var t=F(()=>!!e.next);return()=>t()?Eh(e.next):`—`})(),null),z(o,(()=>{var t=F(()=>!!e.last);return()=>t()?` · last ${Eh(e.last)}`:` · never ran`})(),null),z(c,()=>kh(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${kh(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&R(t,r.e=i),a!==r.t&&L(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}),null),y(e=>{var n=`layout`+(Se()?``:` right-hidden`),r=`iconbtn notifbtn`+(An()>0?` has-unread`:``),i=An()>0?`${An()} unread notifications`:`notifications`,a=`conn`+(Qr()?` ok`:``),s=Qr()?`live (websocket)`:`reconnecting…`,c={"--termh":`${wi()}px`},u=`rightbar`+(Se()?` open`:``);return n!==e.e&&R(t,e.e=n),r!==e.t&&R(o,e.t=r),i!==e.a&&L(o,`title`,e.a=i),a!==e.o&&R(l,e.o=a),s!==e.i&&L(l,`title`,e.i=s),e.n=Te(f,c,e.n),u!==e.s&&R(p,e.s=u),e},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),t}}),M(P,{get when(){return On()},get children(){return[(()=>{var e=Ku();return e.$$click=()=>kn(!1),e})(),(()=>{var t=Yu(),r=t.firstChild.firstChild.nextSibling,i=r.firstChild;return z(r,M(P,{get when(){return wn().length>0},get children(){var e=qu();return e.$$click=()=>Tn([]),e}}),i),i.$$click=()=>kn(!1),z(t,M(P,{get when(){return wn().length>0},get fallback(){return cf()},get children(){var t=Ju();return z(t,M(N,{get each(){return wn()},children:t=>(()=>{var r=uf(),i=r.firstChild.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling;return r.$$click=()=>{Tn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e)),n()!==t.agentId&&e().some(e=>e.id===t.agentId)&&Zr(t.agentId),kn(!1),t.eventId&&setTimeout(()=>Ln(t.eventId),n()===t.agentId?60:350)},z(i,(()=>{var e=F(()=>t.kind===`finish`);return()=>e()?`✅`:F(()=>t.kind===`question`)()?`❓`:t.kind===`error`?`⚠️`:`📈`})()),z(a,()=>t.title),z(o,()=>Eh(new Date(t.at).toISOString())),s.$$click=e=>{e.stopPropagation(),Tn(e=>e.map(e=>e.id===t.id?{...e,read:!0}:e))},z(s,()=>t.read?`✓`:`○`),z(r,M(P,{get when(){return t.body},get children(){var e=lf();return z(e,()=>Th(t.body,160)),e}}),null),y(e=>{var n=`notifitem `+t.kind+(t.read?` read`:``),i=`from ${t.agentId}`,a=t.read?`already read`:`mark as read`;return n!==e.e&&R(r,e.e=n),i!==e.t&&L(r,`title`,e.t=i),a!==e.a&&L(s,`title`,e.a=a),e},{e:void 0,t:void 0,a:void 0}),r})()})),t}}),null),t})()]}}),M(P,{get when(){return ae()},get children(){return M(Nh,{get providers(){return Object.keys(k().providers??{})},onClose:()=>oe(!1),onCreated:e=>{oe(!1),cr(),Zr(e)}})}}),M(P,{get when(){return A()},get children(){return M(Yh,{get cfg(){return k()},onClose:()=>le(!1),announcedOAuth:j,get skills(){return Yi()},get hasSelection(){return!!n()},get agentId(){return n()},get features(){return Zi()},onSaved:()=>{Yn(),fr()},theme:{themes:Ie,activeId:ke,auto:je,setAuto:Me,dark:Re,setDark:ze,light:Ne,setLight:Pe,setThemes:Le,setActive:Ae}})}}),M(P,{get when(){return V()},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 M(Mh,{title:`edit prompt — forks the conversation`,onClose:()=>H(null),get children(){var t=ff(),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()})}),H(null),cr();let t=n();t&&await Zr(t)}catch(e){alert(`edit failed: ${e.message}`)}}),z(t,M(P,{get when(){return r()>0},get children(){var e=df(),t=e.firstChild,n=t.firstChild,o=t.nextSibling,s=o.firstChild,c=o.nextSibling.firstChild;return z(t,r,n),s.addEventListener(`change`,()=>a(`summarize`)),c.addEventListener(`change`,()=>a(`discard`)),y(()=>s.checked=i()===`summarize`),y(()=>c.checked=i()===`discard`),e}}),s),c.$$click=()=>H(null),y(()=>o.value=e().text),t}})}})]}function vh(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=()=>Be(Math.max(0,n()-t));return e.inline?(()=>{var t=pf();return t.firstChild,z(t,i,null),z(t,(()=>{var t=F(()=>!!e.timeoutMs);return()=>t()?` · timeout ${Math.round(e.timeoutMs/1e3)}s`:``})(),null),t})():(()=>{var e=mf(),t=e.firstChild;return z(e,i,t),e})()}function yh(e){let[t,n]=v(Date.now());return ee(()=>{let e=setInterval(()=>n(Date.now()),500);C(()=>clearInterval(e))}),e.startedAt?(()=>{var n=hf();return z(n,()=>Be(Math.max(0,t()-e.startedAt))),n})():null}function bh(e){let t=e.e,n=Ot(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)=>(()=>{var n=gf();return z(n,()=>Th(e,t)),n})(),f=(e=4e3)=>(()=>{let t=r();return t?[F(()=>d(s(),e)),(()=>{var e=_f();return z(e,()=>Be(t.data?.durationMs),null),z(e,()=>o===`bash`?zt(Rt(t.data?.ok,String(t.data?.result??``))):t.data?.ok===!1?` · FAILED`:``,null),z(e,M(jh,{get text(){return s()}}),null),e})()]:vf()})(),p=x(()=>{r();let e=o,t=``,n=(()=>{var e=yf();return z(e,()=>Th(JSON.stringify(a.args??{},null,1),2e3)),e})();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?`⏳ `:`$ `)+kh(i,96);let u=c(`timeout_ms`)?Number(c(`timeout_ms`)):void 0,p=r(),m=Rt(p?.data?.ok,p?String(p.data?.result??``):``);t=p?o?`background job${l?` ${l}`:``}${u?` · timeout ${Math.round(u/1e3)}s`:``}`:Bt({outcome:m,durationMs:p.data?.durationMs,timeoutMs:u,fmtDur:Be}):null,n=[o?(()=>{var e=bf(),t=e.firstChild.nextSibling,n=t.firstChild.nextSibling;return n.nextSibling,z(t,l||`?`,n),z(e,l?[` · kill with `,xf()]:null,null),e})():null,F(()=>F(()=>i!==e.slice(2))()?d(i,800):null),F(()=>f(6e3))];break}case`read_file`:{e=c(`path`)||`(no path)`;let r=[];c(`pattern`)&&r.push(`grep /${kh(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=f(6e3);break}case`write_file`:{let i=String(a.args?.content??``);e=c(`path`)||`(no path)`,t=`${Dh(i.length)} bytes`,n=[F(()=>d(i,1500)),F(()=>F(()=>i.length>1500)()?(()=>{var e=Sf(),t=e.firstChild;return z(e,()=>Dh(i.length),t),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=_f();return z(e,()=>kh(s(),160)),e})():Cf())];break}case`edit_file`:e=c(`path`)||`(no path)`,t=a.args?.replace_all===!0?`replace all`:`unique spot`,n=[(()=>{var e=wf();return z(e,()=>Th(`- `+c(`old_text`),900)),e})(),(()=>{var e=Tf();return z(e,()=>`+ `+Th(c(`new_text`),900)),e})(),F(()=>F(()=>!!r())()?(()=>{var e=Ef(),t=e.firstChild;return z(e,()=>kh(s(),120),t),z(e,()=>Be(r().data?.durationMs),null),e})():Df())];break;case`apply_patch`:{let t=c(`patch`).split(`
|
|
26
26
|
`).filter(e=>e&&!/^---$/.test(e.trim())),i=t.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);e=i.length?`${i.length} file${i.length>1?`s`:``}: ${kh(i.join(`, `),80)}`:`patch`;let a=t.slice(0,60);n=[(()=>{var e=Of();return z(e,()=>a.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=kf();return R(n,`pline`+t),z(n,(()=>{var t=F(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),z(e,(()=>{var e=F(()=>t.length>60);return()=>e()?(()=>{var e=Af(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>t.length-60,n),e})():null})(),null),e})(),F(()=>F(()=>!!r())()?(()=>{var e=_f();return z(e,()=>kh(s().split(`
|
|
27
|
-
`)[0]??``,140),null),z(e,()=>r().data?.ok===!1?` · FAILED`:``,null),e})():jf())];break}case`list_dir`:e=c(`path`)||`.`,n=f(4e3);break;case`read_url`:{let r=c(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=kh(r,70),t=`web`,n=[(()=>{var e=_f();return z(e,M(P,{get when(){return/^https?:/i.test(c(`url`))},get fallback(){return(()=>{var e=Nf();return z(e,()=>kh(c(`url`),80)),e})()},get children(){var e=Mf();return y(()=>L(e,`href`,c(`url`))),e}})),e})(),F(()=>f(3e3))];break}case`bash_output`:{let r=c(`action`)||`read`;e=`bash_output ${c(`job_id`)||`(?)`}`,t=r,n=f(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=ku();return y(()=>e.innerHTML=Fe(t)),e})(),(()=>{var e=_f();return z(e,()=>Be(r().data?.durationMs)),e})()]:Pf();break}case`save_skill`:{e=`skill: ${c(`name`)}`,t=kh(c(`description`),60);let i=Array.isArray(a.args?.files)?a.args.files.map(e=>e?.name).filter(Boolean):[];n=[F(()=>F(()=>!!i.length)()?(()=>{var e=Ff();return e.firstChild,z(e,()=>i.join(`, `),null),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=Ef(),t=e.firstChild;return z(e,()=>kh(s(),160),t),z(e,()=>Be(r().data?.durationMs),null),e})():If())];break}default:e=o,t=r()?Be(r().data?.durationMs):null,n=[(()=>{var e=yf();return z(e,()=>Th(JSON.stringify(a.args??{},null,1),2e3)),e})(),F(()=>f(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=Rf(),c=a.firstChild,d=c.firstChild,f=d.nextSibling,m=f.nextSibling;return a.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),z(d,()=>p().label),z(c,M(P,{get when(){return t.data?.actor},get children(){var e=Lf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),f),z(f,(()=>{var e=F(()=>!!r());return()=>e()?p().hint||``:F(()=>!!i())()?`(result missed)`:F(()=>!!(o===`bash`||u()))()?M(vh,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return u()}}):`running…`})()),z(m,M(jh,{get text(){return l()},label:`⧉ cmd`,title:`copy the ${o} arguments`}),null),z(m,M(P,{get when(){return r()},get children(){return M(jh,{get text(){return s()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(a,()=>p().body,null),y(e=>{var t=`embed`+(n?` grouped`:``)+(r()?r().data?.ok===!1?` fail`:` done`:i()?` done`:` running`),s=`${o}${p().hint?` — `+p().hint:``}`;return t!==e.e&&R(a,e.e=t),s!==e.t&&L(a,`title`,e.t=s),e},{e:void 0,t:void 0}),a})()}function xh(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 Sh(e){let t=e.e,n=lh(t),r=()=>Ot(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Ot(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=zf(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=gt(t.data??{});return(()=>{var t=Bf(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=kf();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Vf(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Hf(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Uf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Wf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=kf();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=Gf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Kf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=Zf(),o=a.firstChild,s=o.nextSibling;return z(o,(()=>{var e=F(()=>!!r());return()=>e()?``:n.icon})()),z(s,(()=>{var e=F(()=>!!r());return()=>e()&&(()=>{var e=Qf();return y(()=>L(e,`title`,`${mh(t.ts)} · ${t.branch}`)),e})()})(),null),z(s,M(P,{get when(){return!r()},get children(){var r=Xf(),i=r.firstChild,a=i.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=Lf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:mh(t.ts)})()),z(r,M(P,{get when(){return e.showBranch},get children(){var e=qf();return z(e,()=>t.branch),e}}),null),z(r,M(P,{get when(){return e.onCancel},get children(){var t=Jf();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(jh,{get text(){return xh(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=Yf();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(s,M(wh,{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()?`${mh(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&R(a,e.e=s),c!==e.t&&L(a,`data-eid`,e.t=c),l!==e.a&&R(o,e.a=l),u!==e.o&&Ee(o,`background`,e.o=u),d!==e.i&&Ee(o,`border`,e.i=d),f!==e.n&&L(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 Ch(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=$f(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&L(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function wh(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=ku();return y(()=>e.innerHTML=$m(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=ep();return z(t,M(N,{each:e,children:e=>(()=>{var t=tp();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=np(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Dh(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>Th(String(t.data.reasoning),8e3)),e}}),(()=>{var e=ku();return y(()=>e.innerHTML=$m(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return rp()}}),M(P,{get when(){return t.data.final},get children(){var e=ip(),n=e.firstChild;return z(e,M(jh,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(bh,{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=op(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(jh,{text:n}),null),z(c,()=>Th(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?zt(Rt(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return ap()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=cp(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=sp();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=$m(String(t.data?.decision??``)),r=$m(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=dp(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return lp()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=up();return z(a,M(N,{each:n,children:n=>(()=>{var a=fp();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M(Ch,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=$m(String(t.data?.question??``));return n!==e.e&&R(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=pp(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=Xd(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=qd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=Jd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=Yd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.next))),e}}),null),y(()=>n.innerHTML=$m(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=mp(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=gp(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>Dh(Number(t.data.tokensBefore??0)),i),z(n,()=>Dh(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[hp(),(()=>{var e=ku();return y(()=>e.innerHTML=$m(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=_p();return z(e,()=>Th(JSON.stringify(t.data),200)),e})()}}function Th(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Eh(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 Dh(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 Oh(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 kh(e,t){return Th(e.replace(/\s+/g,` `).trim(),t)}function Ah(e){return(()=>{var t=vp(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function jh(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),Tt(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=yp();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function Mh(e){return(()=>{var t=bp(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function Nh(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 M(Mh,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Sp(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=Cp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),z(w,M(N,{get each(){return e.providers},children:e=>(()=>{var t=Vd();return z(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=xp();return z(e,d),e}}),E),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>T.value=l()),i}})}var Ph=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Fh=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Ih=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Lh(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Rh(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 Rh(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Ph.has(t)?`image`:Fh.has(t)?`video`:Ih.has(t)?`audio`:null}var zh=new Map,Bh=e=>{let t=zh.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},zh.set(e,t)),t};function Vh(e){let t=()=>e.palette;return(()=>{var e=wp(),n=e.firstChild,r=n.nextSibling,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;return y(p=>{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!==p.e&&Ee(e,`background`,p.e=m),h!==p.t&&Ee(n,`background`,p.t=h),g!==p.a&&Ee(r,`background`,p.a=g),_!==p.o&&Ee(i,`background`,p.o=_),v!==p.i&&Ee(a,`background`,p.i=v),y!==p.n&&Ee(o,`background`,p.n=y),b!==p.s&&Ee(s,`background`,p.s=b),x!==p.h&&Ee(c,`background`,p.h=x),S!==p.r&&Ee(l,`background`,p.r=S),ee!==p.d&&Ee(u,`background`,p.d=ee),C!==p.l&&Ee(d,`background`,p.l=C),w!==p.u&&Ee(f,`background`,p.u=w),p},{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}),e})()}function Hh(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[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=mn(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.activeId),r=ch.find(t=>t.key===e.activeId),i=t??r??ch[0],a=getComputedStyle(document.documentElement),o={...an};for(let{key:e,cssVar:t}of nn){let n=mn(a.getPropertyValue(t));n&&(o[e]=n)}let s=dn(e.themes().map(e=>e.id).concat(ch.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=Ep(),f=d.firstChild.nextSibling,p=f.firstChild;return p.$$click=l,z(f,M(P,{get when(){return e.themes().length>0},get children(){var r=Tp();return r.addEventListener(`change`,t=>{n(t.currentTarget.value),e.onPick(t.currentTarget.value)}),z(r,M(N,{get each(){return e.themes()},children:e=>(()=>{var t=Vd();return z(t,()=>e.label),y(()=>t.value=e.id),t})()})),y(()=>r.value=t()),r}}),null),z(d,M(P,{get when(){return F(()=>!!(r()&&e.themes().some(t=>t.id===e.activeId)))()?r():null},get fallback(){return(()=>{var t=Dp();return z(t,(()=>{var t=F(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,Op(),` 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 `,Op(),`).`]})()),t})()},children:t=>[(()=>{var e=kp(),t=e.firstChild,n=t.firstChild.nextSibling,i=t.nextSibling.firstChild.nextSibling;return n.$$input=e=>s(t=>({...t,label:e.currentTarget.value.slice(0,40)})),i.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),y(()=>n.value=r().label),y(()=>i.value=r().mode),e})(),(()=>{var e=Ap();return z(e,M(N,{each:nn,children:e=>(()=>{var t=Ip(),n=t.firstChild,o=n.nextSibling,s=o.nextSibling;return n.$$input=t=>c(e.key,t.currentTarget.value),z(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)},L(s,`spellcheck`,!1),y(()=>L(t,`title`,e.cssVar)),y(()=>n.value=mn(r().palette[e.key])??`#000000`),y(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=jp(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...an}})),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})(),Mp(),(()=>{var e=Pp(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),z(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`?De(i,n):o=n,z(e,M(P,{get when(){return r().backgroundImage},get children(){var e=Np(),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 z(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)})),z(o,()=>Math.round((r().backgroundDim??.55)*100),c),u.$$input=e=>s(t=>({...t,surfaceAlpha:Number(e.currentTarget.value)})),z(d,()=>Math.round((r().surfaceAlpha??.82)*100),f),p.$$click=()=>s(e=>({...e,backgroundImage:void 0})),y(()=>L(t,`src`,r().backgroundImage)),y(()=>a.value=r().backgroundDim??.55),y(()=>u.value=r().surfaceAlpha??.82),e}}),null),e})(),Fp()]}),null),d})()}function Uh(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 M(P,{get when(){return e.preview},get fallback(){return(()=>{var t=Rp();return t.$$input=t=>e.onDraft(t.currentTarget.value),De(a,t),y(e=>Te(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=Lp();return De(a,t),y(n=>{var r=i(),a=$m(e.draft);return n.e=Te(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function Wh(e){let t=Bh(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,[T,E]=v(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!T(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await re(t,e)}))).then(t=>{E(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&O(e,n)})},D=(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 ne(e){return re(e,T())}async function re(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 D(t,i.entries??[])}catch(e){return _(e.message),null}}let O=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),k=``;b(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),ne(``).then(e=>{e&&k===t&&r(new Map([[``,e]]))}))});let ie=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await ne(e.path);t&&O(e.path,t)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[j,ue]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await vu(async()=>{let{highlightChunks:e}=await import(`./shiki-BzdfW5Bh.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};C(()=>{fe++});let me=async(t,n)=>{let r=Rh(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(t&&!j()){ue(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
27
|
+
`)[0]??``,140),null),z(e,()=>r().data?.ok===!1?` · FAILED`:``,null),e})():jf())];break}case`list_dir`:e=c(`path`)||`.`,n=f(4e3);break;case`read_url`:{let r=c(`url`);try{let e=new URL(r);r=e.host+e.pathname}catch{}e=kh(r,70),t=`web`,n=[(()=>{var e=_f();return z(e,M(P,{get when(){return/^https?:/i.test(c(`url`))},get fallback(){return(()=>{var e=Nf();return z(e,()=>kh(c(`url`),80)),e})()},get children(){var e=Mf();return y(()=>L(e,`href`,c(`url`))),e}})),e})(),F(()=>f(3e3))];break}case`bash_output`:{let r=c(`action`)||`read`;e=`bash_output ${c(`job_id`)||`(?)`}`,t=r,n=f(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=ku();return y(()=>e.innerHTML=Fe(t)),e})(),(()=>{var e=_f();return z(e,()=>Be(r().data?.durationMs)),e})()]:Pf();break}case`save_skill`:{e=`skill: ${c(`name`)}`,t=kh(c(`description`),60);let i=Array.isArray(a.args?.files)?a.args.files.map(e=>e?.name).filter(Boolean):[];n=[F(()=>F(()=>!!i.length)()?(()=>{var e=Ff();return e.firstChild,z(e,()=>i.join(`, `),null),e})():null),F(()=>F(()=>!!r())()?(()=>{var e=Ef(),t=e.firstChild;return z(e,()=>kh(s(),160),t),z(e,()=>Be(r().data?.durationMs),null),e})():If())];break}default:e=o,t=r()?Be(r().data?.durationMs):null,n=[(()=>{var e=yf();return z(e,()=>Th(JSON.stringify(a.args??{},null,1),2e3)),e})(),F(()=>f(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=Rf(),c=a.firstChild,d=c.firstChild,f=d.nextSibling,m=f.nextSibling;return a.addEventListener(`toggle`,t=>{t.target.open&&e.onResize?.()}),z(d,()=>p().label),z(c,M(P,{get when(){return t.data?.actor},get children(){var e=Lf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),f),z(f,(()=>{var e=F(()=>!!r());return()=>e()?p().hint||``:F(()=>!!i())()?`(result missed)`:F(()=>!!(o===`bash`||u()))()?M(vh,{get startedAt(){return t.ts},inline:!0,get timeoutMs(){return u()}}):`running…`})()),z(m,M(jh,{get text(){return l()},label:`⧉ cmd`,title:`copy the ${o} arguments`}),null),z(m,M(P,{get when(){return r()},get children(){return M(jh,{get text(){return s()},label:`⧉ out`,title:`copy this tool's full output`})}}),null),z(a,()=>p().body,null),y(e=>{var t=`embed`+(n?` grouped`:``)+(r()?r().data?.ok===!1?` fail`:` done`:i()?` done`:` running`),s=`${o}${p().hint?` — `+p().hint:``}`;return t!==e.e&&R(a,e.e=t),s!==e.t&&L(a,`title`,e.t=s),e},{e:void 0,t:void 0}),a})()}function xh(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 Sh(e){let t=e.e,n=lh(t),r=()=>Ot(e.prev?.(),t),i=()=>{let n=e.next?.();return!!n&&Ot(t,n)};if(t.type===`fork`){let e=t.data??{};return(()=>{var n=zf(),r=n.firstChild.nextSibling;return r.nextSibling,z(n,()=>String(e.fromBranch??`?`),r),z(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=gt(t.data??{});return(()=>{var t=Bf(),n=t.firstChild;return z(n,()=>e.label),z(t,M(P,{get when(){return e.hasCard},get children(){var t=kf();return y(n=>{var r=`card `+(e.tone===`ok`?`auditcard ok`:e.tone===`warn`?`auditcard`:`verifycard`),i=e.markdown?Fe(e.detail):Fe(`\`\`\`\n${e.detail}\n\`\`\``);return r!==n.e&&R(t,n.e=r),i!==n.t&&(t.innerHTML=n.t=i),n},{e:void 0,t:void 0}),t}}),null),y(()=>R(t,`goalline `+(e.tone===`err`?`err`:e.tone===`warn`?`warn`:``))),t})()}if(t.type===`todo`)return(()=>{var e=Vf(),n=e.firstChild.nextSibling;return n.nextSibling,z(e,()=>String(t.data?.by??`human`),n),e})();if(t.type===`state`)return t.data.from===t.data.to?null:(()=>{var e=Hf(),n=e.firstChild;return z(e,()=>t.data.from,n),z(e,()=>t.data.to,null),z(e,(()=>{var e=F(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>R(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})();if(t.type===`system_note`){let e=String(t.data?.event??``);if(e===`runaway-detected`)return(()=>{var e=Uf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;i.nextSibling;var a=n.nextSibling,o=a.firstChild.nextSibling;return o.nextSibling,z(n,()=>String(t.data?.failures),r),z(n,()=>String(t.data?.limit),i),z(a,()=>String(t.data?.lastTool),o),z(a,()=>String(t.data?.lastError??``).slice(0,200),null),y(()=>L(e,`title`,`${t.data?.failures} consecutive tool failures hit the configured limit (${t.data?.limit})`)),e})();if(e===`error-retry`)return(()=>{var e=Wf(),n=e.firstChild,r=n.firstChild.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(n,()=>String(t.data?.attempt),r),z(n,()=>Math.round(Number(t.data?.waitMs)/1e3),i),e})();if(e===`background-exit`){let e=t.data?.failed===!0,n=Math.round(Number(t.data?.durationMs??0)/1e3);return(()=>{var r=kf();return R(r,`divider-msg`+(e?` err`:``)),z(r,()=>(e?`⚠ background job `:`✓ background job `)+String(t.data?.jobId??`?`)+` `+(e?`FAILED (exit ${String(t.data?.code??`?`)})`:`finished (${n}s)`)),y(()=>L(r,`title`,String(t.data?.cmd??``))),r})()}return e===`context-compacted`?(()=>{var e=Gf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.tokensBefore??`?`),n),z(e,()=>String(t.data?.tokensAfter??`?`),r),z(e,()=>String(t.data?.mode??``),i),e})():e===`context-compaction-started`?(()=>{var e=Kf(),n=e.firstChild.nextSibling,r=n.nextSibling.nextSibling,i=r.nextSibling.nextSibling;return i.nextSibling,z(e,()=>String(t.data?.messages??`?`),n),z(e,()=>String(t.data?.tokensBefore??`?`),r),z(e,()=>String(t.data?.reason??`auto`),i),e})():null}return(()=>{var a=Zf(),o=a.firstChild,s=o.nextSibling;return z(o,(()=>{var e=F(()=>!!r());return()=>e()?``:n.icon})()),z(s,(()=>{var e=F(()=>!!r());return()=>e()&&(()=>{var e=Qf();return y(()=>L(e,`title`,`${mh(t.ts)} · ${t.branch}`)),e})()})(),null),z(s,M(P,{get when(){return!r()},get children(){var r=Xf(),i=r.firstChild,a=i.nextSibling;return z(i,()=>n.name),z(r,M(P,{get when(){return t.data?.actor},get children(){var e=Lf();return e.firstChild,z(e,()=>String(t.data.actor),null),e}}),a),z(a,(()=>{var e=F(()=>!!t.data?.pending);return()=>e()?`queued…`:F(()=>!!t.data?.cancelled)()?`withdrawn`:mh(t.ts)})()),z(r,M(P,{get when(){return e.showBranch},get children(){var e=qf();return z(e,()=>t.branch),e}}),null),z(r,M(P,{get when(){return e.onCancel},get children(){var t=Jf();return t.$$click=t=>{t.stopPropagation(),e.onCancel()},t}}),null),z(r,M(P,{get when(){return t.type!==`tool_call`},get children(){return M(jh,{get text(){return xh(t)},label:`⧉ copy`,title:`copy the RAW text of this message (no markdown rendering)`})}}),null),z(r,M(P,{get when(){return e.onEdit},get children(){var t=Yf();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>Ee(i,`color`,n.color)),r}}),null),z(s,M(wh,{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()?`${mh(t.ts)} · ${t.branch}`:void 0;return s!==e.e&&R(a,e.e=s),c!==e.t&&L(a,`data-eid`,e.t=c),l!==e.a&&R(o,e.a=l),u!==e.o&&Ee(o,`background`,e.o=u),d!==e.i&&Ee(o,`border`,e.i=d),f!==e.n&&L(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 Ch(e){let[t,n]=v(``),r=()=>{let r=t().trim();r&&!e.answered&&(n(``),e.onOption?.(r))};return(()=>{var i=$f(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&!e.isComposing&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&L(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function wh(e){let t=e.e;switch(t.type){case`prompt`:{let e=t.data?.images??[];return[(()=>{var e=ku();return y(()=>e.innerHTML=$m(String(t.data.text??``))),e})(),M(P,{get when(){return e.length},get children(){var t=ep();return z(t,M(N,{each:e,children:e=>(()=>{var t=tp();return L(t,`src`,e),t})()})),t}})]}case`message`:return[M(P,{get when(){return F(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=np(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return z(n,(()=>{var e=F(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${Dh(String(t.data.reasoning).length)} — truncated)`:``})(),null),z(r,()=>Th(String(t.data.reasoning),8e3)),e}}),(()=>{var e=ku();return y(()=>e.innerHTML=$m(String(t.data.content??``))),e})(),M(P,{get when(){return t.data.interrupted},get children(){return rp()}}),M(P,{get when(){return t.data.final},get children(){var e=ip(),n=e.firstChild;return z(e,M(jh,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return M(bh,{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=op(),o=a.firstChild,s=o.firstChild,c=o.nextSibling,l=c.nextSibling;return R(a,`embed `+(i?``:`fail`)),z(s,r===`bash`?`$ (bash, call evicted)`:r),z(o,M(jh,{text:n}),null),z(c,()=>Th(n,4e3)),z(l,()=>Be(t.data.durationMs),null),z(l,()=>r===`bash`?zt(Rt(t.data.ok,n)):i?``:` · FAILED`,null),z(a,M(P,{get when(){return e.orphan},get children(){return ap()}}),null),y(()=>a.open=e.orphan),a})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=cp(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return z(n,M(P,{get when(){return e.length},get children(){var t=sp();return t.firstChild,z(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=$m(String(t.data?.decision??``)),r=$m(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=dp(),o=a.firstChild.firstChild.nextSibling;return z(a,M(P,{get when(){return i()},get children(){return lp()}}),null),z(a,M(P,{get when(){return n.length>0},get children(){var a=up();return z(a,M(N,{each:n,children:n=>(()=>{var a=fp();return a.$$click=()=>{e.onAnswered?.(r);let i=t.data?.actor;i?$(`/api/agents/${encodeURIComponent(String(i))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},z(a,n),y(()=>a.disabled=i()),a})()})),a}}),null),z(a,M(Ch,{get answered(){return i()},get onOption(){return e.onOption}}),null),y(e=>{var n=`embed question`+(i()?` answered`:``),r=$m(String(t.data?.question??``));return n!==e.e&&R(a,e.e=n),r!==e.t&&(o.innerHTML=e.t=r),e},{e:void 0,t:void 0}),a})()}case`progress`:return(()=>{var e=pp(),n=e.firstChild.firstChild.nextSibling;return z(e,M(P,{get when(){return t.data.goalStatus},get children(){var e=Xd(),n=e.firstChild.nextSibling;return z(n,()=>String(t.data.goalStatus)),e}}),null),z(e,M(P,{get when(){return t.data.recent},get children(){var e=qd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.recent))),e}}),null),z(e,M(P,{get when(){return t.data.problems},get children(){var e=Jd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.problems))),e}}),null),z(e,M(P,{get when(){return t.data.next},get children(){var e=Yd(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=$m(String(t.data.next))),e}}),null),y(()=>n.innerHTML=$m(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=mp(),n=e.firstChild;return n.firstChild,z(n,()=>String(t.data.message??``),null),e})();case`compaction`:return(()=>{var e=gp(),n=e.firstChild.firstChild.nextSibling,r=n.firstChild,i=r.nextSibling,a=i.nextSibling.nextSibling;return a.nextSibling,z(n,()=>String(t.data.mode??``),r),z(n,()=>Dh(Number(t.data.tokensBefore??0)),i),z(n,()=>Dh(Number(t.data.tokensAfter??0)),a),z(n,(()=>{var e=F(()=>!!t.data.summarized);return()=>e()?`${t.data.summarized} summarized`:`${t.data.dropped} dropped`})(),null),z(e,M(P,{get when(){return t.data.summary},get children(){return[hp(),(()=>{var e=ku();return y(()=>e.innerHTML=$m(String(t.data.summary))),e})()]}}),null),e})();default:return(()=>{var e=_p();return z(e,()=>Th(JSON.stringify(t.data),200)),e})()}}function Th(e,t){return e.length>t?e.slice(0,t)+` …`:e}function Eh(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 Dh(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 Oh(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 kh(e,t){return Th(e.replace(/\s+/g,` `).trim(),t)}function Ah(e){return(()=>{var t=vp(),n=t.firstChild;return we(t,`click`,e.onClick,!0),z(n,()=>e.icon),y(n=>{var r=`iconbtn`+(e.active?` active`:``)+(e.class?` `+e.class:``),i=e.title,a=e.style;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n.a=Te(t,a,n.a),n},{e:void 0,t:void 0,a:void 0}),t})()}function jh(e){let[t,n]=v(!1),[r,i]=v(!1),a=t=>{t.preventDefault(),t.stopPropagation(),Tt(e.text??``).then(e=>{e===`unsupported`||e===`failed`?(i(!0),setTimeout(()=>i(!1),1200)):(n(!0),setTimeout(()=>n(!1),900))})};return(()=>{var n=yp();return n.$$click=a,z(n,(()=>{var n=F(()=>!!t());return()=>n()?`✓`:F(()=>!!r())()?`✗`:e.label??`⧉`})()),y(()=>L(n,`title`,e.title??`copy to clipboard`)),n})()}function Mh(e){return(()=>{var t=bp(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),z(r,()=>e.title),we(i,`click`,e.onClose,!0),z(n,()=>e.children,null),t})()}function Nh(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 M(Mh,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=Sp(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,_=h.nextSibling,v=_.nextSibling,b=f.nextSibling,x=b.nextSibling,S=x.firstChild,ee=S.firstChild.nextSibling,C=S.nextSibling,w=C.firstChild.nextSibling,T=C.nextSibling.firstChild.nextSibling,E=x.nextSibling;return i.addEventListener(`submit`,g),h.$$input=e=>n(e.currentTarget.value),_.$$click=()=>p(t()),v.$$click=()=>m()?p(m()):p(`..`),z(b,M(N,{get each(){return r()},children:e=>(()=>{var n=Cp();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),z(n,e,null),n})()})),ee.$$input=e=>o(e.currentTarget.value),w.addEventListener(`change`,e=>c(e.currentTarget.value)),z(w,M(N,{get each(){return e.providers},children:e=>(()=>{var t=Vd();return z(t,e),t})()})),T.$$input=e=>u(e.currentTarget.value),z(i,M(P,{get when(){return d()},get children(){var e=xp();return z(e,d),e}}),E),y(()=>h.value=t()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>T.value=l()),i}})}var Ph=new Set([`png`,`jpg`,`jpeg`,`gif`,`webp`,`svg`,`bmp`,`ico`,`avif`]),Fh=new Set([`mp4`,`webm`,`mov`,`mkv`,`avi`,`m4v`]),Ih=new Set([`mp3`,`wav`,`ogg`,`m4a`,`flac`,`aac`,`opus`]);function Lh(e){let t=e.split(`.`).pop()?.toLowerCase()??``,n=Rh(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 Rh(e){let t=e.split(`.`).pop()?.toLowerCase()??``;return Ph.has(t)?`image`:Fh.has(t)?`video`:Ih.has(t)?`audio`:null}var zh=new Map,Bh=e=>{let t=zh.get(e);return t||(t={expanded:new Set,preview:null,media:null,viewMode:`code`},zh.set(e,t)),t};function Vh(e){let t=()=>e.palette;return(()=>{var e=wp(),n=e.firstChild,r=n.nextSibling,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;return y(p=>{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!==p.e&&Ee(e,`background`,p.e=m),h!==p.t&&Ee(n,`background`,p.t=h),g!==p.a&&Ee(r,`background`,p.a=g),_!==p.o&&Ee(i,`background`,p.o=_),v!==p.i&&Ee(a,`background`,p.i=v),y!==p.n&&Ee(o,`background`,p.n=y),b!==p.s&&Ee(s,`background`,p.s=b),x!==p.h&&Ee(c,`background`,p.h=x),S!==p.r&&Ee(l,`background`,p.r=S),ee!==p.d&&Ee(u,`background`,p.d=ee),C!==p.l&&Ee(d,`background`,p.l=C),w!==p.u&&Ee(f,`background`,p.u=w),p},{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}),e})()}function Hh(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[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=mn(t);n&&s(t=>({...t,palette:{...t.palette,[e]:n}}))},l=()=>{let t=e.themes().find(t=>t.id===e.activeId),r=ch.find(t=>t.key===e.activeId),i=t??r??ch[0],a=getComputedStyle(document.documentElement),o={...an};for(let{key:e,cssVar:t}of nn){let n=mn(a.getPropertyValue(t));n&&(o[e]=n)}let s=dn(e.themes().map(e=>e.id).concat(ch.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=Ep(),f=d.firstChild.nextSibling,p=f.firstChild;return p.$$click=l,z(f,M(P,{get when(){return e.themes().length>0},get children(){var r=Tp();return r.addEventListener(`change`,t=>{n(t.currentTarget.value),e.onPick(t.currentTarget.value)}),z(r,M(N,{get each(){return e.themes()},children:e=>(()=>{var t=Vd();return z(t,()=>e.label),y(()=>t.value=e.id),t})()})),y(()=>r.value=t()),r}}),null),z(d,M(P,{get when(){return F(()=>!!(r()&&e.themes().some(t=>t.id===e.activeId)))()?r():null},get fallback(){return(()=>{var t=Dp();return z(t,(()=>{var t=F(()=>e.themes().length===0);return()=>t()?[`no custom themes yet — press `,Op(),` 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 `,Op(),`).`]})()),t})()},children:t=>[(()=>{var e=kp(),t=e.firstChild,n=t.firstChild.nextSibling,i=t.nextSibling.firstChild.nextSibling;return n.$$input=e=>s(t=>({...t,label:e.currentTarget.value.slice(0,40)})),i.addEventListener(`change`,e=>s(t=>({...t,mode:e.currentTarget.value}))),y(()=>n.value=r().label),y(()=>i.value=r().mode),e})(),(()=>{var e=Ap();return z(e,M(N,{each:nn,children:e=>(()=>{var t=Ip(),n=t.firstChild,o=n.nextSibling,s=o.nextSibling;return n.$$input=t=>c(e.key,t.currentTarget.value),z(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)},L(s,`spellcheck`,!1),y(()=>L(t,`title`,e.cssVar)),y(()=>n.value=mn(r().palette[e.key])??`#000000`),y(()=>s.value=i()[e.key]??r().palette[e.key]),t})()})),e})(),(()=>{var t=jp(),i=t.firstChild,a=i.nextSibling;return i.$$click=()=>s(e=>({...e,palette:{...an}})),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})(),Mp(),(()=>{var e=Pp(),t=e.firstChild,n=t.nextSibling;t.$$click=()=>o?.click(),z(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`?De(i,n):o=n,z(e,M(P,{get when(){return r().backgroundImage},get children(){var e=Np(),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 z(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)})),z(o,()=>Math.round((r().backgroundDim??.55)*100),c),u.$$input=e=>s(t=>({...t,surfaceAlpha:Number(e.currentTarget.value)})),z(d,()=>Math.round((r().surfaceAlpha??.82)*100),f),p.$$click=()=>s(e=>({...e,backgroundImage:void 0})),y(()=>L(t,`src`,r().backgroundImage)),y(()=>a.value=r().backgroundDim??.55),y(()=>u.value=r().surfaceAlpha??.82),e}}),null),e})(),Fp()]}),null),d})()}function Uh(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 M(P,{get when(){return e.preview},get fallback(){return(()=>{var t=Rp();return t.$$input=t=>e.onDraft(t.currentTarget.value),De(a,t),y(e=>Te(t,i(),e)),y(()=>t.value=e.draft),t})()},get children(){var t=Lp();return De(a,t),y(n=>{var r=i(),a=$m(e.draft);return n.e=Te(t,r,n.e),a!==n.t&&(t.innerHTML=n.t=a),n},{e:void 0,t:void 0}),t}})}function Wh(e){let t=Bh(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,[T,E]=v(localStorage.getItem(`teapot.showHidden`)===`1`),te=()=>{let e=!T(),t=[``,...i()];Promise.all(t.map(async t=>({p:t,rows:await re(t,e)}))).then(t=>{E(e),localStorage.setItem(`teapot.showHidden`,e?`1`:`0`);for(let{p:e,rows:n}of t)n&&O(e,n)})},D=(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 ne(e){return re(e,T())}async function re(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 D(t,i.entries??[])}catch(e){return _(e.message),null}}let O=(e,n)=>r(r=>{let i=r.get(e);if(!i)return new Map(r).set(e,n);let a=i.map(e=>{let t=n.find(t=>t.path===e.path);return t&&t.dir===e.dir&&t.size===e.size&&t.ignored===e.ignored&&t.name===e.name?e:t??e});for(let e of n)i.some(t=>t.path===e.path)||a.push(e);let o=a.filter(e=>n.some(t=>t.path===e.path)||t.preview?.path===e.path),s=new Map(r);return s.set(e,o),s}),k=``;b(()=>{let t=e.agentId;t!==k&&(k=t,l(new Set),c(null),f(null),r(new Map),ne(``).then(e=>{e&&k===t&&r(new Map([[``,e]]))}))});let ie=async e=>{let t=new Set(i());if(t.has(e.path))t.delete(e.path),l(t);else if(t.add(e.path),l(t),!n().has(e.path)){let t=await ne(e.path);t&&O(e.path,t)}},[ae,oe]=v(``),[se,ce]=v(!1),[A,le]=v(``),[j,ue]=v(!1),de=e=>/\.(md|markdown|mdx)$/i.test(e),fe=0,pe=async e=>{let t=++fe;oe(``),ce(!0);try{let{highlightChunks:n}=await vu(async()=>{let{highlightChunks:e}=await import(`./shiki-CT0bGajG.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(fe!==t)return;oe(e=>e+r)}}catch{fe===t&&oe(``)}finally{fe===t&&ce(!1)}};C(()=>{fe++});let me=async(t,n)=>{let r=Rh(t.path);if(r)c({path:t.path,content:``,binary:!0}),f({path:t.path,kind:r}),h(`media`);else try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);f(null),c({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),le(r.content??``),h(r.binary?`code`:n),!r.binary&&n!==`md`&&pe({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},he=async()=>{let t=o();if(t&&!j()){ue(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:A(),baseContent:t.content})}),c({...t,content:A()}),Q(`saved ${t.path}`)}catch(e){let n=e.payload,r=n&&typeof n==`object`&&n.error===`file changed on disk`?n:null;r?.current===void 0?Q(`save failed: ${e.message}`):confirm(`This file changed on disk since you opened it.
|
|
28
28
|
OK = load the disk version into the editor (your edits are discarded)
|
|
29
|
-
Cancel = keep editing your copy`)?(le(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{ue(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=Bp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Lh(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=zp();return z(t,()=>Dh(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(w)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await re(e,T())})));for(let{p:e,rows:n}of t)n&&O(e,n)}finally{be(!1)}}};return[(()=>{var e=Vp(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(Ah,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(Ah,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),z(e,M(Ah,{class:`filetoggle`,get icon(){return T()?`◉.`:`○.`},get title(){return T()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:te}),null),e})(),(()=>{var e=Hp();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=Up();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(w)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(Mh,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=Jp(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=Kp();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=qp();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return Xp()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(Gh,{get path(){return t().path},get content(){return t().content},get html(){return ae()},get pending(){return se()},get truncated(){return!!t().truncated}})},get children(){var e=Zp();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=Yp(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>Dh(A().length),i),a.$$click=()=>void he(),z(a,()=>j()?`saving…`:`💾 save`),y(()=>a.disabled=j()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=Gp(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=$p();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Qp();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Wp();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function Gh(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=nm(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=rm();return z(t,()=>e.content),t})()},get children(){var t=em();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return tm()}})]}var Kh=[{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)`}],qh={key:`custom`,label:`Custom`,url:``,model:``,hint:`any OpenAI-compatible /v1 endpoint — vLLM, LM Studio, llama.cpp, a company gateway… fill the fields below`};function Jh(e){let[t,n]=v(Kh[0]),[r,i]=v(Kh[0].url),[a,o]=v(``),[s,c]=v(Kh[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);C(()=>clearTimeout(n))});let ee=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Dh(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},w=()=>ee(s()),T=()=>{let e=s().trim().toLowerCase();return e?l().filter(t=>t.id.toLowerCase().includes(e)):l()},E=async t=>{if(t.preventDefault(),x(``),!s().trim())x(l().length?`pick a model — choose one from the list, or type its id`:`pick a model — type its id (the endpoint has not listed any yet)`);else{g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}}};return(()=>{var e=cm(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,C=x.firstChild.nextSibling,te=x.nextSibling,D=te.firstChild.nextSibling,ne=D.nextSibling,re=te.nextSibling,O=re.firstChild.nextSibling,k=O.firstChild.nextSibling,ie=O.nextSibling.firstChild.nextSibling,ae=re.nextSibling;return n.addEventListener(`submit`,E),z(u,()=>[...Kh,qh].map(e=>(()=>{var n=lm();return n.$$click=()=>S(e),z(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),z(n,M(P,{get when(){return t().hint},get children(){var e=im();return z(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),z(b,()=>Kh.map(e=>(()=>{var t=Vd();return y(()=>t.value=e.url),t})())),C.$$input=e=>o(e.currentTarget.value),D.$$input=e=>c(e.currentTarget.value),z(ne,()=>l().map(e=>(()=>{var t=Vd();return y(()=>t.value=e.id),t})())),z(n,M(P,{get when(){return T().length>0},get fallback(){return(()=>{var e=um();return z(e,()=>l().length?`no model matches that — clear the field to see them all`:`models appear here automatically once the endpoint answers GET /models`),e})()},get children(){return[(()=>{var e=am();return z(e,()=>T().slice(0,40).map(e=>(()=>{var t=dm(),n=t.firstChild;return t.$$click=()=>c(e.id),z(n,()=>e.id),z(t,M(P,{get when(){return ee(e.id)},get children(){var t=Nf();return z(t,()=>ee(e.id)),t}}),null),y(n=>{var r=`wizmodel`+(s()===e.id?` active`:``),i=ee(e.id)||e.id;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})())),e})(),(()=>{var e=sm(),t=e.firstChild;return z(e,()=>T().length,t),z(e,()=>T().length>1?`s`:``,null),z(e,M(P,{get when(){return T().length>40},children:` (showing the first 40 — keep typing to narrow)`}),null),z(e,M(P,{get when(){return w()},get children(){return[` · selected: `,(()=>{var e=om();return z(e,w),e})()]}}),null),e})()]}}),re),k.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),z(n,M(P,{get when(){return _()},get children(){var e=xp();return z(e,_),e}}),ae),z(ae,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(pick from the list below, or type an id)`,r=h();return n!==e.e&&L(D,`placeholder`,e.e=n),r!==e.t&&(ae.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>C.value=a()),y(()=>D.value=s()),y(()=>k.value=d()),y(()=>ie.value=p()),e})()}function Yh(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}))),[T,E]=v((e.cfg.mcpServers??[]).map(e=>({...e}))),[te,D]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ne,re]=v({}),[O,k]=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`]}))),[ie,ae]=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]??``]}))),[oe,se]=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:``]}))),[ce,A]=v({}),[le,j]=v({}),[ue,de]=v({}),fe=async()=>{let e=await $(`/api/mcp`).catch(()=>null);j(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},pe=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&&de(e=>({...e,[t]:n}))},me=async(t,n)=>{if(!n.name){A(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}A(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){A(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await pe(n.name),await fe();return}if(!r?.ok||!r.url){A(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await pe(n.name);return}window.open(r.url,`_blank`,`noopener`),A(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(de(e=>({...e,[t]:r})),r.authorized){A(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await fe(),e.onSaved();return}if(r.flow?.phase===`error`){A(e=>({...e,[t]:{kind:`err`,text:r.flow.message??r.lastError??`authorization failed`}}));return}}}A(e=>({...e,[t]:{kind:`err`,text:`authorization timed out`}}))};b(()=>{_e()===`mcp`&&(fe(),T().forEach((e,t)=>{e.name&&pe(e.name)}))});let[he,ge]=v(``),[_e,ve]=v(`providers`),[be,xe]=v([]),Se=async()=>{let e=await $(`/api/archived`).catch(()=>null);xe(e?.agents??[])},I=()=>be().filter(e=>!e.parent);b(()=>{_e()===`archive`&&Se()});let Ce=[{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`}],we=()=>(e.cfg.agents??[]).map(e=>e.id),Te=()=>e.theme.themes(),Ee=()=>e.theme.activeId(),De=t=>e.theme.setActive(t),Oe=()=>e.theme.auto(),ke=t=>e.theme.setAuto(t),Ae=()=>e.theme.dark(),je=t=>e.theme.setDark(t),Me=()=>e.theme.light(),Ne=t=>e.theme.setLight(t),Pe=t=>e.theme.setThemes(t),Fe=e=>on[e]??an,Ie=()=>{let e={};for(let t of n()){if(!t.name.trim())return ge(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return ge(`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},Le=async t=>{t.preventDefault(),ge(``);let n=Ie();if(!n)return;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){ge(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){ge(`task "${e.id}": schedule is required`);return}}let a=[],o=new Set;for(let e of T()){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){ge(`MCP: a server needs a name`);return}if(o.has(t)){ge(`MCP: two servers are named "${t}"`);return}if(o.add(t),r===`stdio`?!i:!n){ge(`MCP "${t}": ${r===`stdio`?`a command is`:`a url is`} required`);return}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 fe(),await Promise.all(a.map((e,t)=>e.name?pe(e.name):Promise.resolve())),setTimeout(()=>{fe(),a.forEach((e,t)=>{e.name&&pe(e.name)})},1200),e.onSaved();let t=new Set(a.map(e=>e.name).filter(Boolean)),o=T().filter(e=>{let n=String(e.name??``).trim();return t.has(n)&&ue()[n]?.required&&!ue()[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`)}else e.onClose()}catch(e){ge(e.message)}},Re=(e,t,n,r)=>(()=>{var i=fm(),a=i.firstChild;return L(i,`title`,r),z(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return M(Mh,{title:`settings`,get onClose(){return e.onClose},get children(){var t=gm(),b=t.firstChild,j=b.firstChild,de=j.nextSibling.firstChild,fe=de.firstChild.nextSibling,be=fe.nextSibling;be.firstChild;var xe=be.nextSibling.firstChild.firstChild.nextSibling;xe.firstChild;var Ie=de.nextSibling,ze=Ie.firstChild.nextSibling,Be=ze.firstChild.firstChild.nextSibling,Ve=ze.nextSibling,He=Ie.nextSibling,Ue=He.firstChild.nextSibling,We=Ue.firstChild,Ge=We.firstChild.nextSibling,Ke=Ue.nextSibling.firstChild,qe=He.nextSibling,Je=qe.firstChild.nextSibling.nextSibling,Ye=qe.nextSibling,Xe=Ye.firstChild.nextSibling,Ze=Ye.nextSibling;Ze.firstChild;var Qe=Ze.nextSibling;Qe.firstChild;var $e=Qe.nextSibling,et=$e.firstChild.nextSibling.firstChild;et.firstChild;var tt=et.nextSibling,nt=$e.nextSibling,rt=nt.firstChild.nextSibling.firstChild,it=rt.firstChild.nextSibling,at=rt.nextSibling.firstChild.nextSibling,ot=nt.nextSibling,st=b.nextSibling,ct=st.firstChild;return t.addEventListener(`submit`,Le),z(j,M(N,{each:Ce,children:e=>(()=>{var t=_m(),n=t.firstChild;return t.$$click=()=>ve(e.key),z(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(_e()===e.key?` on`:``),i=e.hint,a=_e()===e.key?`page`:void 0;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),z(de,M(ye,{get each(){return n()},children:(e,t)=>(()=>{var i=vm(),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)),z(l,M(N,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=bm(),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,z(o,M(P,{get when(){return e().apiKeys.length>1},get children(){var e=ym();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>L(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})()}),fe),fe.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),z(be,M(N,{each:Kh,children:e=>(()=>{var t=xm();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)},z(t,()=>e.label,null),y(()=>L(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),xe.addEventListener(`change`,e=>a(e.currentTarget.value)),z(xe,M(N,{get each(){return s()},children:e=>(()=>{var t=Vd();return t.value=e,z(t,e),t})()}),null),z(de,M(P,{get when(){return c()},get children(){var e=pm(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,c),z(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,c),e}}),null),Be.addEventListener(`change`,e=>{ke(e.currentTarget.checked),localStorage.setItem(`teapot.theme.auto`,e.currentTarget.checked?`1`:`0`)}),z(Ie,M(P,{get when(){return Oe()},get children(){var e=mm(),t=e.firstChild,n=t.firstChild.nextSibling,r=t.nextSibling.firstChild.nextSibling;return n.addEventListener(`change`,e=>{je(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),z(n,M(N,{get each(){return Te().filter(e=>e.mode===`dark`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(ch.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=Vd();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),r.addEventListener(`change`,e=>{Ne(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(r,M(N,{get each(){return Te().filter(e=>e.mode===`light`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(ch.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=Vd();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>n.value=Ae()),y(()=>r.value=Me()),e}}),Ve),z(Ie,M(N,{each:[{mode:`dark`,title:`dark themes`},{mode:`light`,title:`light themes`}],children:e=>M(P,{get when(){return[...Te(),...ch].some(t=>t.mode===e.mode)},get children(){return[(()=>{var t=Sm();return z(t,()=>e.title),t})(),(()=>{var t=Cm();return z(t,M(N,{get each(){return Te().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=wm(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>{De(e.id),localStorage.setItem(`teapot.theme`,e.id)},z(n,M(Vh,{get palette(){return e.palette}})),z(r,()=>e.label,i),y(n=>{var r=`themecard`+(Ee()===e.id?` on`:``),i=`${e.label} (custom)${e.backgroundImage?` · with a background image`:``}`,a=Ee()===e.id;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),z(t,M(N,{get each(){return ch.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=Tm(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>{De(e.key),localStorage.setItem(`teapot.theme`,e.key)},z(n,M(Vh,{get palette(){return Fe(e.key)}})),z(r,()=>e.label),y(n=>{var r=`themecard`+(Ee()===e.key?` on`:``),i=`${e.label} (${e.mode})`,a=Ee()===e.key;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),t})()]}})}),null),z(Ie,M(Hh,{themes:Te,get activeId(){return Ee()},onChange:e=>{let t=un(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=un(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}}Pe(n);let r=e=>n.some(t=>t.id===e)||ch.some(t=>t.key===e);r(Ee())||(De(`dark`),localStorage.setItem(`teapot.theme`,`dark`)),r(Ae())||(je(`dark`),localStorage.setItem(`teapot.theme.dark`,`dark`)),r(Me())||(Ne(`light`),localStorage.setItem(`teapot.theme.light`,`light`))},onPick:e=>{De(e),localStorage.setItem(`teapot.theme`,e)}}),null),z(Ue,()=>Re(`progress interval (min)`,l(),e=>u(e),`how often the harness asks for a progress report`),We),z(Ue,()=>Re(`progress min chars`,d(),e=>f(e),`progress prompts wait for this much real output`),We),Ge.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),z(Ue,()=>Re(`context window (k tok)`,h(),e=>g(e),`model's real window — 0/blank hides the % gauge`),null),z(Ue,()=>Re(`max spawn depth`,_(),e=>x(e),`sub-agent nesting limit (0 = no spawning)`),null),Ke.addEventListener(`change`,e=>ee(e.currentTarget.checked)),z(qe,M(P,{get when(){return T().length>0},get fallback(){return Em()},get children(){return M(ye,{get each(){return T()},children:(e,t)=>{let n=()=>le()[e().name],r=e=>E(T().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=Lm(),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=p.nextSibling,g=h.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=()=>E(T().filter((e,n)=>n!==t)),f.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),z(d,M(P,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=Dm();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=Om();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(k(e=>({...e,[t]:n})),n===`none`)r({headers:void 0});else if(n===`bearer`){let e=ie()[t]??``;r({headers:e?{Authorization:`Bearer ${e}`}:void 0})}else if(n===`header`){let e=oe()[t]??``,n=ie()[t]??``;r({headers:e&&n?{[e]:n}:void 0})}}),z(p,M(P,{get when(){return O()[t]===`bearer`},get children(){var e=km();return e.$$input=e=>{let n=e.currentTarget.value;ae(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},y(()=>e.value=ie()[t]??``),e}}),null),z(p,M(P,{get when(){return O()[t]===`header`},get children(){return[(()=>{var e=Am();return e.$$input=e=>{let n=e.currentTarget.value;se(e=>({...e,[t]:n}));let i=ie()[t]??``;r({headers:n&&i?{[n]:i}:void 0})},y(()=>e.value=oe()[t]??``),e})(),(()=>{var e=jm();return e.$$input=e=>{let n=e.currentTarget.value;ae(e=>({...e,[t]:n}));let i=oe()[t]??``;r({headers:i&&n?{[i]:n}:void 0})},y(()=>e.value=ie()[t]??``),e})()]}}),null),z(i,M(P,{get when(){return O()[t]===`json`},get children(){var e=Mm(),n=e.firstChild;return n.$$input=e=>{let n=e.currentTarget.value;if(D(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}),re(e=>({...e,[t]:``}))}catch{re(e=>({...e,[t]:`must be a JSON object — not applied`}))}},y(()=>n.value=te()[t]??``),e}}),h),g.$$click=async()=>{let e=T()[t];if(!e.name){A(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}A(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);A(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 pe(e.name)},z(h,M(P,{get when(){return F(()=>!!ue()[String(e().name??``).trim()]?.required)()&&!ue()[String(e().name??``).trim()]?.authorized},get children(){var n=Nm();return n.$$click=()=>void me(t,e()),n}}),null),z(h,M(P,{get when(){return ue()[String(e().name??``).trim()]?.authorized},get children(){return[Pm(),(()=>{var n=Fm();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await pe(e().name),A(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),z(h,M(P,{get when(){return n()},get children(){var e=Sd();return z(e,(()=>{var e=F(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:F(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&R(e,t.e=r),i!==t.t&&L(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),z(i,M(P,{get when(){return ne()[t]},get children(){var e=Im();return z(e,()=>ne()[t]),e}}),null),z(i,M(P,{get when(){return ce()[t]},children:e=>(()=>{var t=Bm(),n=t.firstChild,r=n.firstChild;return z(r,()=>e().text),z(n,M(P,{get when(){return e().needsOAuth},get children(){return Rm()}}),null),z(t,M(P,{get when(){return(e().tools?.length??0)>0},get children(){var t=zm();return z(t,M(N,{get each(){return e().tools??[]},children:e=>(()=>{var t=Hm(),n=t.firstChild;return z(n,()=>e.name),z(t,M(P,{get when(){return e.description},get children(){var t=Vm();return z(t,()=>e.description),t}}),null),y(()=>L(t,`title`,e.description??``)),t})()})),t}}),null),y(()=>R(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=O()[t]??`none`),i})()}})}}),Je),Je.$$click=()=>E([...T(),{name:``,url:``,transport:`http`,enabled:!0}]),z(Ye,M(P,{get when(){return C().length>0},get children(){return M(ye,{get each(){return C()},children:(e,t)=>(()=>{var n=Um(),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})()})}}),Xe),Xe.$$click=()=>w([...C(),{id:``,agent:we()[0]??``,schedule:`every 30m`,prompt:``}]),z(Ze,M(P,{get when(){return I().length>0},get fallback(){return Wm()},get children(){return M(N,{get each(){return I()},children:t=>(()=>{var n=Gm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return z(i,()=>t.id),z(a,()=>t.sessions,o),z(a,()=>t.sessions===1?``:`s`,null),z(a,(()=>{var e=F(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),z(a,(()=>{var e=F(()=>!!t.archivedAt);return()=>e()?` · archived ${Eh(new Date(t.archivedAt).toISOString())}`:``})(),null),z(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await Se(),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 Se(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>L(s,`title`,t.workspace)),n})()})}}),null),z(Qe,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=qm(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=Km();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(et,()=>e.cfg.version??`unknown`,null),tt.$$click=async e=>{try{ge(``);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.35.15`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){ge(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},z(it,(()=>{var t=F(()=>!!e.features);return()=>t()?F(()=>!!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…`})()),z(at,(()=>{var t=F(()=>!!e.features);return()=>t()?F(()=>!!e.features.pty.available)()?`on — ${e.features.pty.provider}`:`off — no pty provider; terminals run on plain pipes (no resize)`:`checking…`})()),z(nt,M(P,{get when(){return e.skills.length>0},get fallback(){return(()=>{var t=Jm();return z(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=hm();return z(t,M(N,{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=Xm(),r=e.firstChild,a=r.firstChild,s=a.nextSibling,l=s.nextSibling;return r.$$click=c,z(a,()=>n()?`▾`:`▸`),z(s,()=>t.name),z(l,()=>t.description),z(e,M(P,{get when(){return n()},get children(){return M(P,{get when(){return i()!==null},get fallback(){return(()=>{var e=Zm();return z(e,()=>o()||`loading…`),e})()},get children(){var e=Ym();return z(e,i),e}})}}),null),y(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),z(st,M(P,{get when(){return he()},get children(){var e=xp();return z(e,he),e}}),ct),y(e=>{var t=_e()!==`providers`,n=_e()!==`appearance`,r=_e()!==`runtime`,i=_e()!==`mcp`,a=_e()!==`tasks`,o=_e()!==`archive`,s=_e()!==`agents`,c=_e()!==`update`,l=_e()!==`skills`,u=_e()!==`help`;return t!==e.e&&de.classList.toggle(`hide`,e.e=t),n!==e.t&&Ie.classList.toggle(`hide`,e.t=n),r!==e.a&&He.classList.toggle(`hide`,e.a=r),i!==e.o&&qe.classList.toggle(`hide`,e.o=i),a!==e.i&&Ye.classList.toggle(`hide`,e.i=a),o!==e.n&&Ze.classList.toggle(`hide`,e.n=o),s!==e.s&&Qe.classList.toggle(`hide`,e.s=s),c!==e.h&&$e.classList.toggle(`hide`,e.h=c),l!==e.r&&nt.classList.toggle(`hide`,e.r=l),u!==e.d&&ot.classList.toggle(`hide`,e.d=u),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}),y(()=>xe.value=i()),y(()=>Be.checked=Oe()),y(()=>Ge.value=p()??``),y(()=>Ke.checked=S()),t}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(_h,{}),document.getElementById(`root`));export{vu as t};
|
|
30
|
-
//# sourceMappingURL=index-
|
|
29
|
+
Cancel = keep editing your copy`)?(le(r.current),c({...t,content:r.current}),Q(`loaded the current file from disk`)):Q(`kept your edits — use Save As via bash to force-write`)}finally{ue(!1)}}},ge=e=>!e.binary&&!e.truncated,_e=(e,t)=>[(()=>{var n=Bp(),r=n.firstChild,a=r.nextSibling;return n.$$click=()=>e.dir?void ie(e):void me(e,`code`),z(r,(()=>{var t=F(()=>!!e.dir);return()=>t()?i().has(e.path)?`▾`:`▸`:Lh(e.name)})()),z(a,()=>e.name),z(n,M(P,{get when(){return F(()=>!e.dir)()&&e.size!==void 0},get children(){var t=zp();return z(t,()=>Dh(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``)+(e.ignored&&x()===`dim`?` gitignored`:``),a=`padding-left:${t*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&R(n,r.e=i),r.t=Te(n,a,r.t),o!==r.a&&L(n,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),n})(),M(P,{get when(){return F(()=>!!e.dir)()&&i().has(e.path)},get children(){return M(N,{get each(){return(n().get(e.path)??[]).filter(w)},children:e=>_e(e,t+1)})}})],ve=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace,[ye,be]=v(!1),xe=async()=>{if(!ye()){be(!0);try{let e=[``,...i()],t=await Promise.all(e.map(async e=>({p:e,rows:await re(e,T())})));for(let{p:e,rows:n}of t)n&&O(e,n)}finally{be(!1)}}};return[(()=>{var e=Vp(),t=e.firstChild.nextSibling;return t.firstChild,z(t,ve,null),z(e,M(Ah,{class:`filetoggle`,get icon(){return ye()?`…`:`⟳`},title:`refresh the tree (root + expanded folders) — open popups are kept`,onClick:()=>void xe()}),null),z(e,M(Ah,{class:`filetoggle`,style:`margin-left:auto`,get icon(){return F(()=>x()===`hide`)()?`🙈`:x()===`dim`?`👁`:`✨`},get title(){return`gitignored files: ${x()} — click to cycle (dim → hidden → shown)`},onClick:ee}),null),z(e,M(Ah,{class:`filetoggle`,get icon(){return T()?`◉.`:`○.`},get title(){return T()?`dotfiles shown — click to hide`:`dotfiles hidden — click to show`},onClick:te}),null),e})(),(()=>{var e=Hp();return z(e,M(P,{get when(){return(n().get(``)??[]).length>0},get fallback(){return(()=>{var e=Up();return z(e,()=>g()||`empty workspace`),e})()},get children(){return M(N,{get each(){return(n().get(``)??[]).filter(w)},children:e=>_e(e,0)})}})),e})(),M(P,{get when(){return o()},children:t=>M(Mh,{get title(){return`🗂 ${t().path}`},onClose:()=>{fe++,c(null),f(null)},get children(){return M(P,{get when(){return u()},get fallback(){return[(()=>{var e=Jp(),n=e.firstChild;return z(e,M(P,{get when(){return F(()=>!!de(t().path))()&&!t().binary},get children(){var e=Kp();return e.$$click=()=>h(`md`),y(()=>R(e,p()===`md`?`on`:``)),e}}),n),n.$$click=()=>{h(`code`),ae()||pe({path:t().path,content:t().content,truncated:t().truncated})},z(e,M(P,{get when(){return ge(t())},get children(){var e=qp();return e.$$click=()=>h(`edit`),y(()=>R(e,p()===`edit`?`on`:``)),e}}),null),y(()=>R(n,p()===`code`?`on`:``)),e})(),M(P,{get when(){return!t().binary},get fallback(){return Xp()},get children(){return M(P,{get when(){return p()===`edit`},get fallback(){return M(P,{get when(){return F(()=>p()===`md`)()&&de(t().path)},get fallback(){return M(Gh,{get path(){return t().path},get content(){return t().content},get html(){return ae()},get pending(){return se()},get truncated(){return!!t().truncated}})},get children(){var e=Zp();return y(()=>e.innerHTML=Fe(t().content)),e}})},get children(){var e=Yp(),n=e.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>le(e.currentTarget.value),L(n,`spellcheck`,!1),z(r,()=>Dh(A().length),i),a.$$click=()=>void he(),z(a,()=>j()?`saving…`:`💾 save`),y(()=>a.disabled=j()||A()===t().content),y(()=>n.value=A()),e}})}})]},get children(){var t=Gp(),n=t.firstChild,r=n.firstChild;return z(t,M(P,{get when(){return u().kind===`image`},get fallback(){return M(P,{get when(){return u().kind===`video`},get fallback(){return(()=>{var t=$p();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t})()},get children(){var t=Qp();return y(()=>L(t,`src`,`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`)),t}})},get children(){var t=Wp();return y(n=>{var r=`/api/agents/${e.agentId}/raw?path=${encodeURIComponent(u().path)}`,i=u().path.split(`/`).pop();return r!==n.e&&L(t,`src`,n.e=r),i!==n.t&&L(t,`alt`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),z(n,()=>u().kind,r),t}})}})})]}function Gh(e){return[M(P,{get when(){return e.html},get fallback(){return F(()=>!!e.pending)()?(()=>{var t=nm(),n=t.firstChild.nextSibling;return n.nextSibling,z(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=rm();return z(t,()=>e.content),t})()},get children(){var t=em();return y(()=>t.innerHTML=e.html),t}}),M(P,{get when(){return e.truncated},get children(){return tm()}})]}var Kh=[{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)`}],qh={key:`custom`,label:`Custom`,url:``,model:``,hint:`any OpenAI-compatible /v1 endpoint — vLLM, LM Studio, llama.cpp, a company gateway… fill the fields below`};function Jh(e){let[t,n]=v(Kh[0]),[r,i]=v(Kh[0].url),[a,o]=v(``),[s,c]=v(Kh[0].model),[l,u]=v([]),[d,f]=v(`~/teapot-workspace`),[p,m]=v(``),[h,g]=v(!1),[_,x]=v(``),S=e=>{n(e),e.key!==`custom`&&e.url&&(i(e.url),e.model&&c(e.model))};b(()=>{let e=r().trim(),t=a();if(!/^https?:\/\//.test(e)){u([]);return}let n=setTimeout(async()=>{try{let n=await $(`/api/setup/models?baseUrl=${encodeURIComponent(e)}${t?`&apiKey=${encodeURIComponent(t)}`:``}`);u(n.models??[])}catch{u([])}},600);C(()=>clearTimeout(n))});let ee=e=>{let t=l().find(t=>t.id===e.trim());if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${Dh(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},w=()=>ee(s()),T=()=>{let e=s().trim().toLowerCase();return e?l().filter(t=>t.id.toLowerCase().includes(e)):l()},E=async t=>{if(t.preventDefault(),x(``),!s().trim())x(l().length?`pick a model — choose one from the list, or type its id`:`pick a model — type its id (the endpoint has not listed any yet)`);else{g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}}};return(()=>{var e=cm(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,C=x.firstChild.nextSibling,te=x.nextSibling,D=te.firstChild.nextSibling,ne=D.nextSibling,re=te.nextSibling,O=re.firstChild.nextSibling,k=O.firstChild.nextSibling,ie=O.nextSibling.firstChild.nextSibling,ae=re.nextSibling;return n.addEventListener(`submit`,E),z(u,()=>[...Kh,qh].map(e=>(()=>{var n=lm();return n.$$click=()=>S(e),z(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&R(n,r.e=i),a!==r.t&&L(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),z(n,M(P,{get when(){return t().hint},get children(){var e=im();return z(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),z(b,()=>Kh.map(e=>(()=>{var t=Vd();return y(()=>t.value=e.url),t})())),C.$$input=e=>o(e.currentTarget.value),D.$$input=e=>c(e.currentTarget.value),z(ne,()=>l().map(e=>(()=>{var t=Vd();return y(()=>t.value=e.id),t})())),z(n,M(P,{get when(){return T().length>0},get fallback(){return(()=>{var e=um();return z(e,()=>l().length?`no model matches that — clear the field to see them all`:`models appear here automatically once the endpoint answers GET /models`),e})()},get children(){return[(()=>{var e=am();return z(e,()=>T().slice(0,40).map(e=>(()=>{var t=dm(),n=t.firstChild;return t.$$click=()=>c(e.id),z(n,()=>e.id),z(t,M(P,{get when(){return ee(e.id)},get children(){var t=Nf();return z(t,()=>ee(e.id)),t}}),null),y(n=>{var r=`wizmodel`+(s()===e.id?` active`:``),i=ee(e.id)||e.id;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})())),e})(),(()=>{var e=sm(),t=e.firstChild;return z(e,()=>T().length,t),z(e,()=>T().length>1?`s`:``,null),z(e,M(P,{get when(){return T().length>40},children:` (showing the first 40 — keep typing to narrow)`}),null),z(e,M(P,{get when(){return w()},get children(){return[` · selected: `,(()=>{var e=om();return z(e,w),e})()]}}),null),e})()]}}),re),k.$$input=e=>f(e.currentTarget.value),ie.$$input=e=>m(e.currentTarget.value),z(n,M(P,{get when(){return _()},get children(){var e=xp();return z(e,_),e}}),ae),z(ae,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(pick from the list below, or type an id)`,r=h();return n!==e.e&&L(D,`placeholder`,e.e=n),r!==e.t&&(ae.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>C.value=a()),y(()=>D.value=s()),y(()=>k.value=d()),y(()=>ie.value=p()),e})()}function Yh(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}))),[T,E]=v((e.cfg.mcpServers??[]).map(e=>({...e}))),[te,D]=v(Object.fromEntries((e.cfg.mcpServers??[]).map((e,t)=>[t,e.headers?JSON.stringify(e.headers):``]))),[ne,re]=v({}),[O,k]=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`]}))),[ie,ae]=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]??``]}))),[oe,se]=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:``]}))),[ce,A]=v({}),[le,j]=v({}),[ue,de]=v({}),fe=async()=>{let e=await $(`/api/mcp`).catch(()=>null);j(Object.fromEntries((e?.states??[]).map(e=>[e.name,e])))},pe=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&&de(e=>({...e,[t]:n}))},me=async(t,n)=>{if(!n.name){A(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}A(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){A(e=>({...e,[t]:{kind:`ok`,text:`already authorized`}})),await pe(n.name),await fe();return}if(!r?.ok||!r.url){A(e=>({...e,[t]:{kind:`err`,text:r?.error??`no response`}})),await pe(n.name);return}window.open(r.url,`_blank`,`noopener`),A(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(de(e=>({...e,[t]:r})),r.authorized){A(e=>({...e,[t]:{kind:`ok`,text:`authorized — the tools are available now`}})),await fe(),e.onSaved();return}if(r.flow?.phase===`error`){A(e=>({...e,[t]:{kind:`err`,text:r.flow.message??r.lastError??`authorization failed`}}));return}}}A(e=>({...e,[t]:{kind:`err`,text:`authorization timed out`}}))};b(()=>{_e()===`mcp`&&(fe(),T().forEach((e,t)=>{e.name&&pe(e.name)}))});let[he,ge]=v(``),[_e,ve]=v(`providers`),[be,xe]=v([]),Se=async()=>{let e=await $(`/api/archived`).catch(()=>null);xe(e?.agents??[])},I=()=>be().filter(e=>!e.parent);b(()=>{_e()===`archive`&&Se()});let Ce=[{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`}],we=()=>(e.cfg.agents??[]).map(e=>e.id),Te=()=>e.theme.themes(),Ee=()=>e.theme.activeId(),De=t=>e.theme.setActive(t),Oe=()=>e.theme.auto(),ke=t=>e.theme.setAuto(t),Ae=()=>e.theme.dark(),je=t=>e.theme.setDark(t),Me=()=>e.theme.light(),Ne=t=>e.theme.setLight(t),Pe=t=>e.theme.setThemes(t),Fe=e=>on[e]??an,Ie=()=>{let e={};for(let t of n()){if(!t.name.trim())return ge(`provider name is required`),null;if(t.baseUrl&&!/^https?:\/\//.test(t.baseUrl))return ge(`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},[Le,Re]=v(`idle`),ze=e=>{ge(e),Re(e=>e===`saving`?`idle`:e)},Be=async t=>{t.preventDefault(),ge(``),Re(`saving`);let n=Ie();if(!n)return Re(`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 ze(`task "${e.id}": agent is required`);if(!e.schedule?.trim())return ze(`task "${e.id}": schedule is required`)}let a=[],o=new Set;for(let e of T()){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 ze(`MCP: a server needs a name`);if(o.has(t))return ze(`MCP: two servers are named "${t}"`);if(o.add(t),r===`stdio`?!i:!n)return ze(`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 fe(),await Promise.all(a.map((e,t)=>e.name?pe(e.name):Promise.resolve())),setTimeout(()=>{fe(),a.forEach((e,t)=>{e.name&&pe(e.name)})},1200),e.onSaved();let t=new Set(a.map(e=>e.name).filter(Boolean)),o=T().filter(e=>{let n=String(e.name??``).trim();return t.has(n)&&ue()[n]?.required&&!ue()[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`),Re(`saved`),setTimeout(()=>Re(`idle`),1200)}else Re(`saved`),setTimeout(()=>{Re(`idle`),e.onClose()},400)}catch(e){ge(e.message),Re(`error`),setTimeout(()=>Re(`idle`),1600)}},Ve=(e,t,n,r)=>(()=>{var i=fm(),a=i.firstChild;return L(i,`title`,r),z(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return M(Mh,{title:`settings`,get onClose(){return e.onClose},get children(){var t=gm(),b=t.firstChild,j=b.firstChild,de=j.nextSibling.firstChild,fe=de.firstChild.nextSibling,be=fe.nextSibling;be.firstChild;var xe=be.nextSibling.firstChild.firstChild.nextSibling;xe.firstChild;var Ie=de.nextSibling,Re=Ie.firstChild.nextSibling,ze=Re.firstChild.firstChild.nextSibling,He=Re.nextSibling,Ue=Ie.nextSibling,We=Ue.firstChild.nextSibling,Ge=We.firstChild,Ke=Ge.firstChild.nextSibling,qe=We.nextSibling.firstChild,Je=Ue.nextSibling,Ye=Je.firstChild.nextSibling.nextSibling,Xe=Je.nextSibling,Ze=Xe.firstChild.nextSibling,Qe=Xe.nextSibling;Qe.firstChild;var $e=Qe.nextSibling;$e.firstChild;var et=$e.nextSibling,tt=et.firstChild.nextSibling.firstChild;tt.firstChild;var nt=tt.nextSibling,rt=et.nextSibling,it=rt.firstChild.nextSibling.firstChild,at=it.firstChild.nextSibling,ot=it.nextSibling.firstChild.nextSibling,st=rt.nextSibling,ct=b.nextSibling,lt=ct.firstChild;return t.addEventListener(`submit`,Be),z(j,M(N,{each:Ce,children:e=>(()=>{var t=_m(),n=t.firstChild;return t.$$click=()=>ve(e.key),z(n,()=>e.label),y(n=>{var r=`cfgmenu-item`+(_e()===e.key?` on`:``),i=e.hint,a=_e()===e.key?`page`:void 0;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-current`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()})),z(de,M(ye,{get each(){return n()},children:(e,t)=>(()=>{var i=vm(),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)),z(l,M(N,{get each(){return e().apiKeys},children:(i,a)=>(()=>{var o=bm(),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,z(o,M(P,{get when(){return e().apiKeys.length>1},get children(){var e=ym();return e.$$click=()=>r(n().map((e,n)=>n===t?{...e,apiKeys:e.apiKeys.filter((e,t)=>t!==a())}:e)),e}}),null),y(()=>L(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})()}),fe),fe.$$click=()=>r([...n(),{name:``,baseUrl:``,apiKeys:[``],model:``}]),z(be,M(N,{each:Kh,children:e=>(()=>{var t=xm();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)},z(t,()=>e.label,null),y(()=>L(t,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),t})()}),null),xe.addEventListener(`change`,e=>a(e.currentTarget.value)),z(xe,M(N,{get each(){return s()},children:e=>(()=>{var t=Vd();return t.value=e,z(t,e),t})()}),null),z(de,M(P,{get when(){return c()},get children(){var e=pm(),t=e.firstChild.nextSibling,n=t.nextSibling.nextSibling,r=n.nextSibling.nextSibling;return z(t,c),z(e,()=>c()===o()?` — the dropdown above cannot show it.`:` — it was replaced by your selection.`,n),z(r,c),e}}),null),ze.addEventListener(`change`,e=>{ke(e.currentTarget.checked),localStorage.setItem(`teapot.theme.auto`,e.currentTarget.checked?`1`:`0`)}),z(Ie,M(P,{get when(){return Oe()},get children(){var e=mm(),t=e.firstChild,n=t.firstChild.nextSibling,r=t.nextSibling.firstChild.nextSibling;return n.addEventListener(`change`,e=>{je(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),z(n,M(N,{get each(){return Te().filter(e=>e.mode===`dark`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(ch.filter(e=>e.mode===`dark`))},children:e=>(()=>{var t=Vd();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),r.addEventListener(`change`,e=>{Ne(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),z(r,M(N,{get each(){return Te().filter(e=>e.mode===`light`).map(e=>({key:e.id,label:`${e.label} (custom)`})).concat(ch.filter(e=>e.mode===`light`))},children:e=>(()=>{var t=Vd();return z(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>n.value=Ae()),y(()=>r.value=Me()),e}}),He),z(Ie,M(N,{each:[{mode:`dark`,title:`dark themes`},{mode:`light`,title:`light themes`}],children:e=>M(P,{get when(){return[...Te(),...ch].some(t=>t.mode===e.mode)},get children(){return[(()=>{var t=Sm();return z(t,()=>e.title),t})(),(()=>{var t=Cm();return z(t,M(N,{get each(){return Te().filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=wm(),n=t.firstChild,r=n.nextSibling,i=r.firstChild;return t.$$click=()=>{De(e.id),localStorage.setItem(`teapot.theme`,e.id)},z(n,M(Vh,{get palette(){return e.palette}})),z(r,()=>e.label,i),y(n=>{var r=`themecard`+(Ee()===e.id?` on`:``),i=`${e.label} (custom)${e.backgroundImage?` · with a background image`:``}`,a=Ee()===e.id;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),z(t,M(N,{get each(){return ch.filter(t=>t.mode===e.mode)},children:e=>(()=>{var t=Tm(),n=t.firstChild,r=n.nextSibling;return t.$$click=()=>{De(e.key),localStorage.setItem(`teapot.theme`,e.key)},z(n,M(Vh,{get palette(){return Fe(e.key)}})),z(r,()=>e.label),y(n=>{var r=`themecard`+(Ee()===e.key?` on`:``),i=`${e.label} (${e.mode})`,a=Ee()===e.key;return r!==n.e&&R(t,n.e=r),i!==n.t&&L(t,`title`,n.t=i),a!==n.a&&L(t,`aria-pressed`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),null),t})()]}})}),null),z(Ie,M(Hh,{themes:Te,get activeId(){return Ee()},onChange:e=>{let t=un(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=un(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}}Pe(n);let r=e=>n.some(t=>t.id===e)||ch.some(t=>t.key===e);r(Ee())||(De(`dark`),localStorage.setItem(`teapot.theme`,`dark`)),r(Ae())||(je(`dark`),localStorage.setItem(`teapot.theme.dark`,`dark`)),r(Me())||(Ne(`light`),localStorage.setItem(`teapot.theme.light`,`light`))},onPick:e=>{De(e),localStorage.setItem(`teapot.theme`,e)}}),null),z(We,()=>Ve(`progress interval (min)`,l(),e=>u(e),`how often the harness asks for a progress report`),Ge),z(We,()=>Ve(`progress min chars`,d(),e=>f(e),`progress prompts wait for this much real output`),Ge),Ke.$$input=e=>m(e.currentTarget.value===``?null:Number(e.currentTarget.value)),z(We,()=>Ve(`context window (k tok)`,h(),e=>g(e),`model's real window — 0/blank hides the % gauge`),null),z(We,()=>Ve(`max spawn depth`,_(),e=>x(e),`sub-agent nesting limit (0 = no spawning)`),null),qe.addEventListener(`change`,e=>ee(e.currentTarget.checked)),z(Je,M(P,{get when(){return T().length>0},get fallback(){return Em()},get children(){return M(ye,{get each(){return T()},children:(e,t)=>{let n=()=>le()[e().name],r=e=>E(T().map((n,r)=>r===t?{...n,...e}:n));return(()=>{var i=Lm(),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=p.nextSibling,g=h.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=()=>E(T().filter((e,n)=>n!==t)),f.addEventListener(`change`,e=>r({transport:e.currentTarget.value})),z(d,M(P,{get when(){return e().transport===`stdio`},get children(){return[(()=>{var t=Dm();return t.$$input=e=>r({command:e.currentTarget.value}),y(()=>t.value=e().command??``),t})(),(()=>{var t=Om();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(k(e=>({...e,[t]:n})),n===`none`)r({headers:void 0});else if(n===`bearer`){let e=ie()[t]??``;r({headers:e?{Authorization:`Bearer ${e}`}:void 0})}else if(n===`header`){let e=oe()[t]??``,n=ie()[t]??``;r({headers:e&&n?{[e]:n}:void 0})}}),z(p,M(P,{get when(){return O()[t]===`bearer`},get children(){var e=km();return e.$$input=e=>{let n=e.currentTarget.value;ae(e=>({...e,[t]:n})),r({headers:n?{Authorization:`Bearer ${n}`}:void 0})},y(()=>e.value=ie()[t]??``),e}}),null),z(p,M(P,{get when(){return O()[t]===`header`},get children(){return[(()=>{var e=Am();return e.$$input=e=>{let n=e.currentTarget.value;se(e=>({...e,[t]:n}));let i=ie()[t]??``;r({headers:n&&i?{[n]:i}:void 0})},y(()=>e.value=oe()[t]??``),e})(),(()=>{var e=jm();return e.$$input=e=>{let n=e.currentTarget.value;ae(e=>({...e,[t]:n}));let i=oe()[t]??``;r({headers:i&&n?{[i]:n}:void 0})},y(()=>e.value=ie()[t]??``),e})()]}}),null),z(i,M(P,{get when(){return O()[t]===`json`},get children(){var e=Mm(),n=e.firstChild;return n.$$input=e=>{let n=e.currentTarget.value;if(D(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}),re(e=>({...e,[t]:``}))}catch{re(e=>({...e,[t]:`must be a JSON object — not applied`}))}},y(()=>n.value=te()[t]??``),e}}),h),g.$$click=async()=>{let e=T()[t];if(!e.name){A(e=>({...e,[t]:{kind:`err`,text:`give it a name first`}}));return}A(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);A(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 pe(e.name)},z(h,M(P,{get when(){return F(()=>!!ue()[String(e().name??``).trim()]?.required)()&&!ue()[String(e().name??``).trim()]?.authorized},get children(){var n=Nm();return n.$$click=()=>void me(t,e()),n}}),null),z(h,M(P,{get when(){return ue()[String(e().name??``).trim()]?.authorized},get children(){return[Pm(),(()=>{var n=Fm();return n.$$click=async()=>{await $(`/api/mcp/oauth/disconnect`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({name:e().name})}).catch(()=>{}),await pe(e().name),A(e=>({...e,[t]:{kind:`ok`,text:`disconnected`}}))},n})()]}}),null),z(h,M(P,{get when(){return n()},get children(){var e=Sd();return z(e,(()=>{var e=F(()=>n()?.status===`connected`);return()=>e()?`● ${n()?.tools} tools`:F(()=>n()?.status===`error`)()?`● error`:n()?.status===`disabled`?`● off`:`● idle`})()),y(t=>{var r=`mcpstate `+(n()?.status??``),i=n()?.lastError??``;return r!==t.e&&R(e,t.e=r),i!==t.t&&L(e,`title`,t.t=i),t},{e:void 0,t:void 0}),e}}),null),z(i,M(P,{get when(){return ne()[t]},get children(){var e=Im();return z(e,()=>ne()[t]),e}}),null),z(i,M(P,{get when(){return ce()[t]},children:e=>(()=>{var t=Bm(),n=t.firstChild,r=n.firstChild;return z(r,()=>e().text),z(n,M(P,{get when(){return e().needsOAuth},get children(){return Rm()}}),null),z(t,M(P,{get when(){return(e().tools?.length??0)>0},get children(){var t=zm();return z(t,M(N,{get each(){return e().tools??[]},children:e=>(()=>{var t=Hm(),n=t.firstChild;return z(n,()=>e.name),z(t,M(P,{get when(){return e.description},get children(){var t=Vm();return z(t,()=>e.description),t}}),null),y(()=>L(t,`title`,e.description??``)),t})()})),t}}),null),y(()=>R(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=O()[t]??`none`),i})()}})}}),Ye),Ye.$$click=()=>E([...T(),{name:``,url:``,transport:`http`,enabled:!0}]),z(Xe,M(P,{get when(){return C().length>0},get children(){return M(ye,{get each(){return C()},children:(e,t)=>(()=>{var n=Um(),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})()})}}),Ze),Ze.$$click=()=>w([...C(),{id:``,agent:we()[0]??``,schedule:`every 30m`,prompt:``}]),z(Qe,M(P,{get when(){return I().length>0},get fallback(){return Wm()},get children(){return M(N,{get each(){return I()},children:t=>(()=>{var n=Gm(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.firstChild,s=a.nextSibling,c=r.nextSibling,l=c.nextSibling;return z(i,()=>t.id),z(a,()=>t.sessions,o),z(a,()=>t.sessions===1?``:`s`,null),z(a,(()=>{var e=F(()=>(t.subs??0)>0);return()=>e()?` · +${t.subs} sub-agent${t.subs===1?``:`s`} (restored together)`:``})(),null),z(a,(()=>{var e=F(()=>!!t.archivedAt);return()=>e()?` · archived ${Eh(new Date(t.archivedAt).toISOString())}`:``})(),null),z(s,()=>t.workspace),c.$$click=async()=>{let n=await $(`/api/agents/${t.id}/restore`,{method:`POST`}).catch(()=>null);await Se(),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 Se(),e.onSaved(),Q(`deleted ${t.id} for good`))},y(()=>L(s,`title`,t.workspace)),n})()})}}),null),z($e,M(N,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=qm(),n=t.firstChild,r=n.nextSibling;return z(n,()=>e.id),z(r,()=>e.workspace),z(t,M(P,{get when(){return e.parent},get children(){var t=Km();return t.firstChild,z(t,()=>e.parent,null),t}}),null),t})()}),null),z(tt,()=>e.cfg.version??`unknown`,null),nt.$$click=async e=>{try{ge(``);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.35.17`&&(r=!0,window.location.reload())}catch{}}if(!r)throw Error(`restart timeout — new server did not come up`)}catch(e){ge(e.message)}finally{e.currentTarget.disabled=!1,e.currentTarget.textContent=`update & restart`}},z(at,(()=>{var t=F(()=>!!e.features);return()=>t()?F(()=>!!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…`})()),z(ot,(()=>{var t=F(()=>!!e.features);return()=>t()?F(()=>!!e.features.pty.available)()?`on — ${e.features.pty.provider}`:`off — no pty provider; terminals run on plain pipes (no resize)`:`checking…`})()),z(rt,M(P,{get when(){return e.skills.length>0},get fallback(){return(()=>{var t=Jm();return z(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=hm();return z(t,M(N,{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=Xm(),r=e.firstChild,a=r.firstChild,s=a.nextSibling,l=s.nextSibling;return r.$$click=c,z(a,()=>n()?`▾`:`▸`),z(s,()=>t.name),z(l,()=>t.description),z(e,M(P,{get when(){return n()},get children(){return M(P,{get when(){return i()!==null},get fallback(){return(()=>{var e=Zm();return z(e,()=>o()||`loading…`),e})()},get children(){var e=Ym();return z(e,i),e}})}}),null),y(()=>e.classList.toggle(`open`,!!n())),e})()}})),t}}),null),z(ct,M(P,{get when(){return he()},get children(){var e=xp();return z(e,he),e}}),lt),z(lt,(()=>{var e=F(()=>Le()===`saving`);return()=>e()?`saving…`:F(()=>Le()===`saved`)()?`✓ saved`:Le()===`error`?`✕ failed`:`save settings`})()),y(e=>{var t=_e()!==`providers`,n=_e()!==`appearance`,r=_e()!==`runtime`,i=_e()!==`mcp`,a=_e()!==`tasks`,o=_e()!==`archive`,s=_e()!==`agents`,c=_e()!==`update`,l=_e()!==`skills`,u=_e()!==`help`,d=Le()===`saved`,f=Le()===`error`,p=Le()===`saving`;return t!==e.e&&de.classList.toggle(`hide`,e.e=t),n!==e.t&&Ie.classList.toggle(`hide`,e.t=n),r!==e.a&&Ue.classList.toggle(`hide`,e.a=r),i!==e.o&&Je.classList.toggle(`hide`,e.o=i),a!==e.i&&Xe.classList.toggle(`hide`,e.i=a),o!==e.n&&Qe.classList.toggle(`hide`,e.n=o),s!==e.s&&$e.classList.toggle(`hide`,e.s=s),c!==e.h&&et.classList.toggle(`hide`,e.h=c),l!==e.r&&rt.classList.toggle(`hide`,e.r=l),u!==e.d&&st.classList.toggle(`hide`,e.d=u),d!==e.l&<.classList.toggle(`saved`,e.l=d),f!==e.u&<.classList.toggle(`error`,e.u=f),p!==e.c&&(lt.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(()=>xe.value=i()),y(()=>ze.checked=Oe()),y(()=>Ke.value=p()??``),y(()=>qe.checked=S()),t}})}Ce([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Se(()=>M(_h,{}),document.getElementById(`root`));export{vu as t};
|
|
30
|
+
//# sourceMappingURL=index-CnvxbU1K.js.map
|