teapot-coding-agent 0.14.8 → 0.14.9
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/package.json +1 -1
- package/public/assets/{index-CNYEpUp6.js → index-C_ZXWWW5.js} +8 -8
- package/public/assets/index-C_ZXWWW5.js.map +1 -0
- package/public/assets/{shiki-B972ox6D.js → shiki-CE_hx8wa.js} +2 -2
- package/public/assets/{shiki-B972ox6D.js.map → shiki-CE_hx8wa.js.map} +1 -1
- package/public/index.html +1 -1
- package/public/assets/index-CNYEpUp6.js.map +0 -1
package/package.json
CHANGED
|
@@ -18,11 +18,11 @@ WARNING: This link could potentially be dangerous`)){let e=window.open();if(e){t
|
|
|
18
18
|
`))),this._register(this._terminal.onA11yTab(e=>this._handleTab(e))),this._register(this._terminal.onKey(e=>this._handleKey(e.key))),this._register(this._terminal.onBlur(()=>this._clearLiveRegion())),this._register(this._renderService.onDimensionsChange(()=>this._refreshRowsDimensions())),this._register(W(i,`selectionchange`,()=>this._handleSelectionChange())),this._register(this._coreBrowserService.onDprChange(()=>this._refreshRowsDimensions())),this._refreshRowsDimensions(),this._refreshRows(),this._register(B(()=>{this._accessibilityContainer.remove(),this._rowElements.length=0}))}_handleTab(e){for(let t=0;t<e;t++)this._handleChar(` `)}_handleChar(e){this._liveRegionLineCount<pc+1&&(this._charsToConsume.length>0?this._charsToConsume.shift()!==e&&(this._charsToAnnounce+=e):this._charsToAnnounce+=e,e===`
|
|
19
19
|
`&&(this._liveRegionLineCount++,this._liveRegionLineCount===pc+1&&(this._liveRegion.textContent+=Je.get())))}_clearLiveRegion(){this._liveRegion.textContent=``,this._liveRegionLineCount=0}_handleKey(e){this._clearLiveRegion(),/\p{Control}/u.test(e)||this._charsToConsume.push(e)}_refreshRows(e,t){this._liveRegionDebouncer.refresh(e,t,this._terminal.rows)}_renderRows(e,t){let n=this._terminal.buffer,r=n.lines.length.toString();for(let i=e;i<=t;i++){let e=n.lines.get(n.ydisp+i),t=[],a=e?.translateToString(!0,void 0,void 0,t)||``,o=(n.ydisp+i+1).toString(),s=this._rowElements[i];s&&(a.length===0?(s.textContent=`\xA0`,this._rowColumns.set(s,[0,1])):(s.textContent=a,this._rowColumns.set(s,t)),s.setAttribute(`aria-posinset`,o),s.setAttribute(`aria-setsize`,r),this._alignRowWidth(s))}this._announceCharacters()}_announceCharacters(){this._charsToAnnounce.length!==0&&(this._liveRegion.textContent+=this._charsToAnnounce,this._charsToAnnounce=``)}_handleBoundaryFocus(e,t){let n=e.target,r=this._rowElements[t===0?1:this._rowElements.length-2];if(n.getAttribute(`aria-posinset`)===(t===0?`1`:`${this._terminal.buffer.lines.length}`)||e.relatedTarget!==r)return;let i,a;if(t===0?(i=n,a=this._rowElements.pop(),this._rowContainer.removeChild(a)):(i=this._rowElements.shift(),a=n,this._rowContainer.removeChild(i)),i.removeEventListener(`focus`,this._topBoundaryFocusListener),a.removeEventListener(`focus`,this._bottomBoundaryFocusListener),t===0){let e=this._createAccessibilityTreeNode();this._rowElements.unshift(e),this._rowContainer.insertAdjacentElement(`afterbegin`,e)}else{let e=this._createAccessibilityTreeNode();this._rowElements.push(e),this._rowContainer.appendChild(e)}this._rowElements[0].addEventListener(`focus`,this._topBoundaryFocusListener),this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._terminal.scrollLines(t===0?-1:1),this._rowElements[t===0?1:this._rowElements.length-2].focus(),e.preventDefault(),e.stopImmediatePropagation()}_handleSelectionChange(){if(this._rowElements.length===0)return;let e=this._coreBrowserService.mainDocument.getSelection();if(!e)return;if(e.isCollapsed){this._rowContainer.contains(e.anchorNode)&&this._terminal.clearSelection();return}if(!e.anchorNode||!e.focusNode){console.error(`anchorNode and/or focusNode are null`);return}let t={node:e.anchorNode,offset:e.anchorOffset},n={node:e.focusNode,offset:e.focusOffset};if((t.node.compareDocumentPosition(n.node)&Node.DOCUMENT_POSITION_PRECEDING||t.node===n.node&&t.offset>n.offset)&&([t,n]=[n,t]),t.node.compareDocumentPosition(this._rowElements[0])&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_FOLLOWING)&&(t={node:this._rowElements[0].childNodes[0],offset:0}),!this._rowContainer.contains(t.node))return;let r=this._rowElements.slice(-1)[0];if(n.node.compareDocumentPosition(r)&(Node.DOCUMENT_POSITION_CONTAINED_BY|Node.DOCUMENT_POSITION_PRECEDING)&&(n={node:r,offset:r.textContent?.length??0}),!this._rowContainer.contains(n.node))return;let i=({node:e,offset:t})=>{let n=e instanceof Text?e.parentNode:e,r=parseInt(n?.getAttribute(`aria-posinset`),10)-1;if(isNaN(r))return console.warn(`row is invalid. Race condition?`),null;let i=this._rowColumns.get(n);if(!i)return console.warn(`columns is null. Race condition?`),null;let a=t<i.length?i[t]:i.slice(-1)[0]+1;return a>=this._terminal.cols&&(++r,a=0),{row:r,column:a}},a=i(t),o=i(n);if(!(!a||!o)){if(a.row>o.row||a.row===o.row&&a.column>=o.column)throw Error(`invalid range`);this._terminal.select(a.column,a.row,(o.row-a.row)*this._terminal.cols-a.column+o.column)}}_handleResize(e){this._rowElements[this._rowElements.length-1].removeEventListener(`focus`,this._bottomBoundaryFocusListener);for(let e=this._rowContainer.children.length;e<this._terminal.rows;e++)this._rowElements[e]=this._createAccessibilityTreeNode(),this._rowContainer.appendChild(this._rowElements[e]);for(;this._rowElements.length>e;)this._rowContainer.removeChild(this._rowElements.pop());this._rowElements[this._rowElements.length-1].addEventListener(`focus`,this._bottomBoundaryFocusListener),this._refreshRowsDimensions()}_createAccessibilityTreeNode(){let e=this._coreBrowserService.mainDocument.createElement(`div`);return e.setAttribute(`role`,`listitem`),e.tabIndex=-1,this._refreshRowDimensions(e),e}_refreshRowsDimensions(){if(this._renderService.dimensions.css.cell.height){Object.assign(this._accessibilityContainer.style,{width:`${this._renderService.dimensions.css.canvas.width}px`,fontSize:`${this._terminal.options.fontSize}px`}),this._rowElements.length!==this._terminal.rows&&this._handleResize(this._terminal.rows);for(let e=0;e<this._terminal.rows;e++)this._refreshRowDimensions(this._rowElements[e]),this._alignRowWidth(this._rowElements[e])}}_refreshRowDimensions(e){e.style.height=`${this._renderService.dimensions.css.cell.height}px`}_alignRowWidth(e){e.style.transform=``;let t=e.getBoundingClientRect().width,n=this._rowColumns.get(e)?.slice(-1)?.[0];if(!n)return;let r=n*this._renderService.dimensions.css.cell.width;e.style.transform=`scaleX(${r/t})`}};mc=I([L(1,bt),L(2,kt),L(3,jt)],mc);var hc=class extends V{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 U),this.onShowLinkUnderline=this._onShowLinkUnderline.event,this._onHideLinkUnderline=this._register(new U),this.onHideLinkUnderline=this._onHideLinkUnderline.event,this._register(B(()=>{$t(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(W(this._element,`mouseleave`,()=>{this._isMouseOut=!0,this._clearCurrentLink()})),this._register(W(this._element,`mousemove`,this._handleMouseMove.bind(this))),this._register(W(this._element,`mousedown`,this._handleMouseDown.bind(this))),this._register(W(this._element,`mouseup`,this._handleMouseUp.bind(this)))}get currentLink(){return this._currentLink}_handleMouseMove(e){this._lastMouseEvent=e;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);if(!t)return;this._isMouseOut=!1;let n=e.composedPath();for(let e=0;e<n.length;e++){let t=n[e];if(t.classList.contains(`xterm`))break;if(t.classList.contains(`xterm-hover`))return}(!this._lastBufferCell||t.x!==this._lastBufferCell.x||t.y!==this._lastBufferCell.y)&&(this._handleHover(t),this._lastBufferCell=t)}_handleHover(e){if(this._activeLine!==e.y||this._wasResized){this._clearCurrentLink(),this._askForLink(e,!1),this._wasResized=!1;return}this._currentLink&&this._linkAtPosition(this._currentLink.link,e)||(this._clearCurrentLink(),this._askForLink(e,!0))}_askForLink(e,t){(!this._activeProviderReplies||!t)&&(this._activeProviderReplies?.forEach(e=>{e?.forEach(e=>{e.link.dispose&&e.link.dispose()})}),this._activeProviderReplies=new Map,this._activeLine=e.y);let n=!1;for(let[r,i]of this._linkProviderService.linkProviders.entries())t?this._activeProviderReplies?.get(r)&&(n=this._checkLinkProviderResult(r,e,n)):i.provideLinks(e.y,t=>{if(this._isMouseOut)return;let i=t?.map(e=>({link:e}));this._activeProviderReplies?.set(r,i),n=this._checkLinkProviderResult(r,e,n),this._activeProviderReplies?.size===this._linkProviderService.linkProviders.length&&this._removeIntersectingLinks(e.y,this._activeProviderReplies)})}_removeIntersectingLinks(e,t){let n=new Set;for(let r=0;r<t.size;r++){let i=t.get(r);if(i)for(let t=0;t<i.length;t++){let r=i[t],a=r.link.range.start.y<e?0:r.link.range.start.x,o=r.link.range.end.y>e?this._bufferService.cols:r.link.range.end.x;for(let e=a;e<=o;e++){if(n.has(e)){i.splice(t--,1);break}n.add(e)}}}}_checkLinkProviderResult(e,t,n){if(!this._activeProviderReplies)return n;let r=this._activeProviderReplies.get(e),i=!1;for(let t=0;t<e;t++)(!this._activeProviderReplies.has(t)||this._activeProviderReplies.get(t))&&(i=!0);if(!i&&r){let e=r.find(e=>this._linkAtPosition(e.link,t));e&&(n=!0,this._handleNewLink(e))}if(this._activeProviderReplies.size===this._linkProviderService.linkProviders.length&&!n)for(let e=0;e<this._activeProviderReplies.size;e++){let r=this._activeProviderReplies.get(e)?.find(e=>this._linkAtPosition(e.link,t));if(r){n=!0,this._handleNewLink(r);break}}return n}_handleMouseDown(){this._mouseDownLink=this._currentLink}_handleMouseUp(e){if(!this._currentLink)return;let t=this._positionFromMouseEvent(e,this._element,this._mouseService);t&&this._mouseDownLink&&gc(this._mouseDownLink.link,this._currentLink.link)&&this._linkAtPosition(this._currentLink.link,t)&&this._currentLink.link.activate(e,this._currentLink.link.text)}_clearCurrentLink(e,t){!this._currentLink||!this._lastMouseEvent||(!e||!t||this._currentLink.link.range.start.y>=e&&this._currentLink.link.range.end.y<=t)&&(this._linkLeave(this._element,this._currentLink.link,this._lastMouseEvent),this._currentLink=void 0,$t(this._linkCacheDisposables),this._linkCacheDisposables.length=0)}_handleNewLink(e){if(!this._lastMouseEvent)return;let t=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);t&&this._linkAtPosition(e.link,t)&&(this._currentLink=e,this._currentLink.state={decorations:{underline:e.link.decorations===void 0||e.link.decorations.underline,pointerCursor:e.link.decorations===void 0||e.link.decorations.pointerCursor},isHovered:!0},this._linkHover(this._element,e.link,this._lastMouseEvent),e.link.decorations={},Object.defineProperties(e.link.decorations,{pointerCursor:{get:()=>this._currentLink?.state?.decorations.pointerCursor,set:e=>{this._currentLink?.state&&this._currentLink.state.decorations.pointerCursor!==e&&(this._currentLink.state.decorations.pointerCursor=e,this._currentLink.state.isHovered&&this._element.classList.toggle(`xterm-cursor-pointer`,e))}},underline:{get:()=>this._currentLink?.state?.decorations.underline,set:t=>{this._currentLink?.state&&this._currentLink?.state?.decorations.underline!==t&&(this._currentLink.state.decorations.underline=t,this._currentLink.state.isHovered&&this._fireUnderlineEvent(e.link,t))}}}),this._linkCacheDisposables.push(this._renderService.onRenderedViewportChange(e=>{if(!this._currentLink)return;let t=e.start===0?0:e.start+1+this._bufferService.buffer.ydisp,n=this._bufferService.buffer.ydisp+1+e.end;if(this._currentLink.link.range.start.y>=t&&this._currentLink.link.range.end.y<=n&&(this._clearCurrentLink(t,n),this._lastMouseEvent)){let e=this._positionFromMouseEvent(this._lastMouseEvent,this._element,this._mouseService);e&&this._askForLink(e,!1)}})))}_linkHover(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!0,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!0),this._currentLink.state.decorations.pointerCursor&&e.classList.add(`xterm-cursor-pointer`)),t.hover&&t.hover(n,t.text)}_fireUnderlineEvent(e,t){let n=e.range,r=this._bufferService.buffer.ydisp,i=this._createLinkUnderlineEvent(n.start.x-1,n.start.y-r-1,n.end.x,n.end.y-r-1,void 0);(t?this._onShowLinkUnderline:this._onHideLinkUnderline).fire(i)}_linkLeave(e,t,n){this._currentLink?.state&&(this._currentLink.state.isHovered=!1,this._currentLink.state.decorations.underline&&this._fireUnderlineEvent(t,!1),this._currentLink.state.decorations.pointerCursor&&e.classList.remove(`xterm-cursor-pointer`)),t.leave&&t.leave(n,t.text)}_linkAtPosition(e,t){let n=e.range.start.y*this._bufferService.cols+e.range.start.x,r=e.range.end.y*this._bufferService.cols+e.range.end.x,i=t.y*this._bufferService.cols+t.x;return n<=i&&i<=r}_positionFromMouseEvent(e,t,n){let r=n.getCoords(e,t,this._bufferService.cols,this._bufferService.rows);if(r)return{x:r[0],y:r[1]+this._bufferService.buffer.ydisp}}_createLinkUnderlineEvent(e,t,n,r,i){return{x1:e,y1:t,x2:n,y2:r,cols:this._bufferService.cols,fg:i}}};hc=I([L(1,At),L(2,jt),L(3,gt),L(4,Ft)],hc);function gc(e,t){return e.text===t.text&&e.range.start.x===t.range.start.x&&e.range.start.y===t.range.start.y&&e.range.end.x===t.range.end.x&&e.range.end.y===t.range.end.y}var _c=class extends rc{constructor(e={}){super(e),this._linkifier=this._register(new rn),this.browser=ja,this._keyDownHandled=!1,this._keyDownSeen=!1,this._keyPressHandled=!1,this._unprocessedDeadKey=!1,this._accessibilityManager=this._register(new rn),this._onCursorMove=this._register(new U),this.onCursorMove=this._onCursorMove.event,this._onKey=this._register(new U),this.onKey=this._onKey.event,this._onRender=this._register(new U),this.onRender=this._onRender.event,this._onSelectionChange=this._register(new U),this.onSelectionChange=this._onSelectionChange.event,this._onTitleChange=this._register(new U),this.onTitleChange=this._onTitleChange.event,this._onBell=this._register(new U),this.onBell=this._onBell.event,this._onFocus=this._register(new U),this._onBlur=this._register(new U),this._onA11yCharEmitter=this._register(new U),this._onA11yTabEmitter=this._register(new U),this._onWillOpen=this._register(new U),this._setup(),this._decorationService=this._instantiationService.createInstance(lc),this._instantiationService.setService(Tt,this._decorationService),this._linkProviderService=this._instantiationService.createInstance(Ea),this._instantiationService.setService(Ft,this._linkProviderService),this._linkProviderService.registerLinkProvider(this._instantiationService.createInstance(Et)),this._register(this._inputHandler.onRequestBell(()=>this._onBell.fire())),this._register(this._inputHandler.onRequestRefreshRows(e=>this.refresh(e?.start??0,e?.end??this.rows-1))),this._register(this._inputHandler.onRequestSendFocus(()=>this._reportFocus())),this._register(this._inputHandler.onRequestReset(()=>this.reset())),this._register(this._inputHandler.onRequestWindowsOptionsReport(e=>this._reportWindowsOptions(e))),this._register(this._inputHandler.onColor(e=>this._handleColorEvent(e))),this._register(un.forward(this._inputHandler.onCursorMove,this._onCursorMove)),this._register(un.forward(this._inputHandler.onTitleChange,this._onTitleChange)),this._register(un.forward(this._inputHandler.onA11yChar,this._onA11yCharEmitter)),this._register(un.forward(this._inputHandler.onA11yTab,this._onA11yTabEmitter)),this._register(this._bufferService.onResize(e=>this._afterResize(e.cols,e.rows))),this._register(B(()=>{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=q.toColorRGB(e===`ansi`?this._themeService.colors.ansi[t.index]:this._themeService.colors[e]);this.coreService.triggerDataEvent(`${G.ESC}]${n};${Vs(r)}${Ui.ST}`);break;case 1:if(e===`ansi`)this._themeService.modifyColors(e=>e.ansi[t.index]=Yi.toColor(...t.color));else{let n=e;this._themeService.modifyColors(e=>e[n]=Yi.toColor(...t.color))}break;case 2:this._themeService.restoreColor(t.index)}}}_setup(){super._setup(),this._customKeyEventHandler=void 0}get buffer(){return this.buffers.active}focus(){this.textarea&&this.textarea.focus({preventScroll:!0})}_handleScreenReaderModeOptionChange(e){e?!this._accessibilityManager.value&&this._renderService&&(this._accessibilityManager.value=this._instantiationService.createInstance(mc,this)):this._accessibilityManager.clear()}_handleTextAreaFocus(e){this.coreService.decPrivateModes.sendFocus&&this.coreService.triggerDataEvent(G.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(G.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(W(this.element,`copy`,e=>{this.hasSelection()&&Ze(e,this._selectionService)}));let e=e=>Qe(e,this.textarea,this.coreService,this.optionsService);this._register(W(this.textarea,`paste`,e)),this._register(W(this.element,`paste`,e)),Fa?this._register(W(this.element,`mousedown`,e=>{e.button===2&&tt(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})):this._register(W(this.element,`contextmenu`,e=>{tt(e,this.textarea,this.screenElement,this._selectionService,this.options.rightClickSelectsWord)})),Ua&&this._register(W(this.element,`auxclick`,e=>{e.button===1&&et(e,this.textarea,this.screenElement)}))}_bindKeys(){this._register(W(this.textarea,`keyup`,e=>this._keyUp(e),!0)),this._register(W(this.textarea,`keydown`,e=>this._keyDown(e),!0)),this._register(W(this.textarea,`keypress`,e=>this._keyPress(e),!0)),this._register(W(this.textarea,`compositionstart`,()=>this._compositionHelper.compositionstart())),this._register(W(this.textarea,`compositionupdate`,e=>this._compositionHelper.compositionupdate(e))),this._register(W(this.textarea,`compositionend`,()=>this._compositionHelper.compositionend())),this._register(W(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(W(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`,Ke.get()),Wa||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(wa,this.textarea,e.ownerDocument.defaultView??window,this._document??typeof window<`u`?window.document:null)),this._instantiationService.setService(kt,this._coreBrowserService),this._register(W(this.textarea,`focus`,e=>this._handleTextAreaFocus(e))),this._register(W(this.textarea,`blur`,()=>this._handleTextAreaBlur())),this._helperContainer.appendChild(this.textarea),this._charSizeService=this._instantiationService.createInstance(ba,this._document,this._helperContainer),this._instantiationService.setService(Ot,this._charSizeService),this._themeService=this._instantiationService.createInstance(ko),this._instantiationService.setService(Pt,this._themeService),this._characterJoinerService=this._instantiationService.createInstance(ta),this._instantiationService.setService(Nt,this._characterJoinerService),this._renderService=this._register(this._instantiationService.createInstance(Xa,this.rows,this.screenElement)),this._instantiationService.setService(jt,this._renderService),this._register(this._renderService.onRenderedViewportChange(e=>this._onRender.fire(e))),this.onResize(e=>this._renderService.resize(e.cols,e.rows)),this._compositionView=this._document.createElement(`div`),this._compositionView.classList.add(`composition-view`),this._compositionHelper=this._instantiationService.createInstance(Wi,this.textarea,this._compositionView),this._helperContainer.appendChild(this._compositionView),this._mouseService=this._instantiationService.createInstance(ka),this._instantiationService.setService(At,this._mouseService);let r=this._linkifier.value=this._register(this._instantiationService.createInstance(hc,this.screenElement));this.element.appendChild(t);try{this._onWillOpen.fire(this.element)}catch{}this._renderService.hasRenderer()||this._renderService.setRenderer(this._createRenderer()),this._register(this.onCursorMove(()=>{this._renderService.handleCursorMove(),this._syncTextArea()})),this._register(this.onResize(()=>this._renderService.handleResize(this.cols,this.rows))),this._register(this.onBlur(()=>this._renderService.handleBlur())),this._register(this.onFocus(()=>this._renderService.handleFocus())),this._viewport=this._register(this._instantiationService.createInstance(Fi,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(yo,this.element,this.screenElement,r)),this._instantiationService.setService(Mt,this._selectionService),this._register(this._selectionService.onRequestScrollLines(e=>this.scrollLines(e.amount,e.suppressScrollEvent))),this._register(this._selectionService.onSelectionChange(()=>this._onSelectionChange.fire())),this._register(this._selectionService.onRequestRedraw(e=>this._renderService.handleSelectionChanged(e.start,e.end,e.columnSelectMode))),this._register(this._selectionService.onLinuxMouseSelection(e=>{this.textarea.value=e,this.textarea.focus(),this.textarea.select()})),this._register(un.any(this._onScroll.event,this._inputHandler.onScroll)(()=>{this._selectionService.refresh(),this._viewport?.queueSync()})),this._register(this._instantiationService.createInstance(Ii,this.screenElement)),this._register(W(this.element,`mousedown`,e=>this._selectionService.handleMouseDown(e))),this.coreMouseService.areMouseEventsActive?(this._selectionService.disable(),this.element.classList.add(`enable-mouse-events`)):this._selectionService.enable(),this.options.screenReaderMode&&(this._accessibilityManager.value=this._instantiationService.createInstance(mc,this)),this._register(this.optionsService.onSpecificOptionChange(`screenReaderMode`,e=>this._handleScreenReaderModeOptionChange(e))),this.options.overviewRuler.width&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Vi,this._viewportElement,this.screenElement))),this.optionsService.onSpecificOptionChange(`overviewRuler`,e=>{!this._overviewRulerRenderer&&e&&this._viewportElement&&this.screenElement&&(this._overviewRulerRenderer=this._register(this._instantiationService.createInstance(Vi,this._viewportElement,this.screenElement)))}),this._charSizeService.measure(),this.refresh(0,this.rows-1),this._initGlobal(),this.bindMouse()}_createRenderer(){return this._instantiationService.createInstance(ya,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(W(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(W(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=G.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){$e(e,this.textarea,this.coreService,this.optionsService)}attachCustomKeyEventHandler(e){this._customKeyEventHandler=e}attachCustomWheelEventHandler(e){this._customWheelEventHandler=e}registerLinkProvider(e){return this._linkProviderService.registerLinkProvider(e)}registerCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);let t=this._characterJoinerService.register(e);return this.refresh(0,this.rows-1),t}deregisterCharacterJoiner(e){if(!this._characterJoinerService)throw Error(`Terminal must be opened first`);this._characterJoinerService.deregister(e)&&this.refresh(0,this.rows-1)}get markers(){return this.buffer.markers}registerMarker(e){return this.buffer.addMarker(this.buffer.ybase+this.buffer.y+e)}registerDecoration(e){return this._decorationService.registerDecoration(e)}hasSelection(){return this._selectionService?this._selectionService.hasSelection:!1}select(e,t,n){this._selectionService.setSelection(e,t,n)}getSelection(){return this._selectionService?this._selectionService.selectionText:``}getSelectionPosition(){if(!(!this._selectionService||!this._selectionService.hasSelection))return{start:{x:this._selectionService.selectionStart[0],y:this._selectionService.selectionStart[1]},end:{x:this._selectionService.selectionEnd[0],y:this._selectionService.selectionEnd[1]}}}clearSelection(){this._selectionService?.clearSelection()}selectAll(){this._selectionService?.selectAll()}selectLines(e,t){this._selectionService?.selectLines(e,t)}_keyDown(e){if(this._keyDownHandled=!1,this._keyDownSeen=!0,this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;let t=this.browser.isMac&&this.options.macOptionIsMeta&&e.altKey;if(!t&&!this._compositionHelper.keydown(e))return this.options.scrollOnUserInput&&this.buffer.ybase!==this.buffer.ydisp&&this.scrollToBottom(!0),!1;!t&&(e.key===`Dead`||e.key===`AltGraph`)&&(this._unprocessedDeadKey=!0);let n=ac(e,this.coreService.decPrivateModes.applicationCursorKeys,this.browser.isMac,this.options.macOptionIsMeta);if(this.updateCursorStyle(e),n.type===3||n.type===2){let t=this.rows-1;return this.scrollLines(n.type===2?-t:t),this.cancel(e,!0)}if(n.type===1&&this.selectAll(),this._isThirdLevelShift(this.browser,e)||(n.cancel&&this.cancel(e,!0),!n.key)||e.key&&!e.ctrlKey&&!e.altKey&&!e.metaKey&&e.key.length===1&&e.key.charCodeAt(0)>=65&&e.key.charCodeAt(0)<=90)return!0;if(this._unprocessedDeadKey)return this._unprocessedDeadKey=!1,!0;if((n.key===G.ETX||n.key===G.CR)&&(this.textarea.value=``),this._onKey.fire({key:n.key,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(n.key,!0),!this.optionsService.rawOptions.screenReaderMode||e.altKey||e.ctrlKey)return this.cancel(e,!0);this._keyDownHandled=!0}_isThirdLevelShift(e,t){let n=e.isMac&&!this.options.macOptionIsMeta&&t.altKey&&!t.ctrlKey&&!t.metaKey||e.isWindows&&t.altKey&&t.ctrlKey&&!t.metaKey||e.isWindows&&t.getModifierState(`AltGraph`);return t.type===`keypress`?n:n&&(!t.keyCode||t.keyCode>47)}_keyUp(e){this._keyDownSeen=!1,!(this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)&&(vc(e)||this.focus(),this.updateCursorStyle(e),this._keyPressHandled=!1)}_keyPress(e){let t;if(this._keyPressHandled=!1,this._keyDownHandled||this._customKeyEventHandler&&this._customKeyEventHandler(e)===!1)return!1;if(this.cancel(e),e.charCode)t=e.charCode;else if(e.which===null||e.which===void 0)t=e.keyCode;else if(e.which!==0&&e.charCode!==0)t=e.which;else return!1;return!t||(e.altKey||e.ctrlKey||e.metaKey)&&!this._isThirdLevelShift(this.browser,e)?!1:(t=String.fromCharCode(t),this._onKey.fire({key:t,domEvent:e}),this._showCursor(),this.coreService.triggerDataEvent(t,!0),this._keyPressHandled=!0,this._unprocessedDeadKey=!1,!0)}_inputEvent(e){if(e.data&&e.inputType===`insertText`&&(!e.composed||!this._keyDownSeen)&&!this.optionsService.rawOptions.screenReaderMode){if(this._keyPressHandled)return!1;this._unprocessedDeadKey=!1;let t=e.data;return this.coreService.triggerDataEvent(t,!0),this.cancel(e),!0}return!1}resize(e,t){if(e===this.cols&&t===this.rows){this._charSizeService&&!this._charSizeService.hasValidSize&&this._charSizeService.measure();return}super.resize(e,t)}_afterResize(e,t){this._charSizeService?.measure()}clear(){if(this.buffer.ybase!==0||this.buffer.y!==0){this.buffer.clearAllMarkers(),this.buffer.lines.set(0,this.buffer.lines.get(this.buffer.ybase+this.buffer.y)),this.buffer.lines.length=1,this.buffer.ydisp=0,this.buffer.ybase=0,this.buffer.y=0;for(let e=1;e<this.rows;e++)this.buffer.lines.push(this.buffer.getBlankLine(Lo));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(G.ESC+`[I`):this.coreService.triggerDataEvent(G.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(`${G.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(`${G.ESC}[6;${r};${n}t`);break}}cancel(e,t){if(!(!this.options.cancelEvents&&!t))return e.preventDefault(),e.stopPropagation(),!1}};function vc(e){return e.keyCode===16||e.keyCode===17||e.keyCode===18}var yc=class{constructor(){this._addons=[]}dispose(){for(let e=this._addons.length-1;e>=0;e--)this._addons[e].instance.dispose()}loadAddon(e,t){let n={instance:t,dispose:t.dispose,isDisposed:!1};this._addons.push(n),t.dispose=()=>this._wrappedAddonDispose(n),t.activate(e)}_wrappedAddonDispose(e){if(e.isDisposed)return;let t=-1;for(let n=0;n<this._addons.length;n++)if(this._addons[n]===e){t=n;break}if(t===-1)throw Error(`Could not dispose an addon that has not been loaded`);e.isDisposed=!0,e.dispose.apply(e.instance),this._addons.splice(t,1)}},bc=class{constructor(e){this._line=e}get isWrapped(){return this._line.isWrapped}get length(){return this._line.length}getCell(e,t){if(!(e<0||e>=this._line.length))return t?(this._line.loadCell(e,t),t):this._line.loadCell(e,new lt)}translateToString(e,t,n){return this._line.translateToString(e,t,n)}},xc=class{constructor(e,t){this._buffer=e,this.type=t}init(e){return this._buffer=e,this}get cursorY(){return this._buffer.y}get cursorX(){return this._buffer.x}get viewportY(){return this._buffer.ydisp}get baseY(){return this._buffer.ybase}get length(){return this._buffer.lines.length}getLine(e){let t=this._buffer.lines.get(e);if(t)return new bc(t)}getNullCell(){return new lt}},Sc=class extends V{constructor(e){super(),this._core=e,this._onBufferChange=this._register(new U),this.onBufferChange=this._onBufferChange.event,this._normal=new xc(this._core.buffers.normal,`normal`),this._alternate=new xc(this._core.buffers.alt,`alternate`),this._core.buffers.onBufferActivate(()=>this._onBufferChange.fire(this.active))}get active(){if(this._core.buffers.active===this._core.buffers.normal)return this.normal;if(this._core.buffers.active===this._core.buffers.alt)return this.alternate;throw Error(`Active buffer is neither normal nor alternate`)}get normal(){return this._normal.init(this._core.buffers.normal)}get alternate(){return this._alternate.init(this._core.buffers.alt)}},Cc=class{constructor(e){this._core=e}registerCsiHandler(e,t){return this._core.registerCsiHandler(e,e=>t(e.toArray()))}addCsiHandler(e,t){return this.registerCsiHandler(e,t)}registerDcsHandler(e,t){return this._core.registerDcsHandler(e,(e,n)=>t(e,n.toArray()))}addDcsHandler(e,t){return this.registerDcsHandler(e,t)}registerEscHandler(e,t){return this._core.registerEscHandler(e,t)}addEscHandler(e,t){return this.registerEscHandler(e,t)}registerOscHandler(e,t){return this._core.registerOscHandler(e,t)}addOscHandler(e,t){return this.registerOscHandler(e,t)}},wc=class{constructor(e){this._core=e}register(e){this._core.unicodeService.register(e)}get versions(){return this._core.unicodeService.versions}get activeVersion(){return this._core.unicodeService.activeVersion}set activeVersion(e){this._core.unicodeService.activeVersion=e}},Tc=[`cols`,`rows`],Ec=0,Dc=class extends V{constructor(e){super(),this._core=this._register(new _c(e)),this._addonManager=this._register(new yc),this._publicOptions={...this._core.options};let t=e=>this._core.options[e],n=(e,t)=>{this._checkReadonlyOptions(e),this._core.options[e]=t};for(let e in this._core.options){let r={get:t.bind(this,e),set:n.bind(this,e)};Object.defineProperty(this._publicOptions,e,r)}}_checkReadonlyOptions(e){if(Tc.includes(e))throw Error(`Option "${e}" can only be set in the constructor`)}_checkProposedApi(){if(!this._core.optionsService.rawOptions.allowProposedApi)throw Error(`You must set the allowProposedApi option to true to use proposed API`)}get onBell(){return this._core.onBell}get onBinary(){return this._core.onBinary}get onCursorMove(){return this._core.onCursorMove}get onData(){return this._core.onData}get onKey(){return this._core.onKey}get onLineFeed(){return this._core.onLineFeed}get onRender(){return this._core.onRender}get onResize(){return this._core.onResize}get onScroll(){return this._core.onScroll}get onSelectionChange(){return this._core.onSelectionChange}get onTitleChange(){return this._core.onTitleChange}get onWriteParsed(){return this._core.onWriteParsed}get element(){return this._core.element}get parser(){return this._parser||=new Cc(this._core),this._parser}get unicode(){return this._checkProposedApi(),new wc(this._core)}get textarea(){return this._core.textarea}get rows(){return this._core.rows}get cols(){return this._core.cols}get buffer(){return this._buffer||=this._register(new Sc(this._core)),this._buffer}get markers(){return this._checkProposedApi(),this._core.markers}get modes(){let e=this._core.coreService.decPrivateModes,t=`none`;switch(this._core.coreMouseService.activeProtocol){case`X10`:t=`x10`;break;case`VT200`:t=`vt200`;break;case`DRAG`:t=`drag`;break;case`ANY`:t=`any`}return{applicationCursorKeysMode:e.applicationCursorKeys,applicationKeypadMode:e.applicationKeypad,bracketedPasteMode:e.bracketedPasteMode,insertMode:this._core.coreService.modes.insertMode,mouseTrackingMode:t,originMode:e.origin,reverseWraparoundMode:e.reverseWraparound,sendFocusMode:e.sendFocus,synchronizedOutputMode:e.synchronizedOutput,wraparoundMode:e.wraparound}}get options(){return this._publicOptions}set options(e){for(let t in e)this._publicOptions[t]=e[t]}blur(){this._core.blur()}focus(){this._core.focus()}input(e,t=!0){this._core.input(e,t)}resize(e,t){this._verifyIntegers(e,t),this._core.resize(e,t)}open(e){this._core.open(e)}attachCustomKeyEventHandler(e){this._core.attachCustomKeyEventHandler(e)}attachCustomWheelEventHandler(e){this._core.attachCustomWheelEventHandler(e)}registerLinkProvider(e){return this._core.registerLinkProvider(e)}registerCharacterJoiner(e){return this._checkProposedApi(),this._core.registerCharacterJoiner(e)}deregisterCharacterJoiner(e){this._checkProposedApi(),this._core.deregisterCharacterJoiner(e)}registerMarker(e=0){return this._verifyIntegers(e),this._core.registerMarker(e)}registerDecoration(e){return this._checkProposedApi(),this._verifyPositiveIntegers(e.x??0,e.width??0,e.height??0),this._core.registerDecoration(e)}hasSelection(){return this._core.hasSelection()}select(e,t,n){this._verifyIntegers(e,t,n),this._core.select(e,t,n)}getSelection(){return this._core.getSelection()}getSelectionPosition(){return this._core.getSelectionPosition()}clearSelection(){this._core.clearSelection()}selectAll(){this._core.selectAll()}selectLines(e,t){this._verifyIntegers(e,t),this._core.selectLines(e,t)}dispose(){super.dispose()}scrollLines(e){this._verifyIntegers(e),this._core.scrollLines(e)}scrollPages(e){this._verifyIntegers(e),this._core.scrollPages(e)}scrollToTop(){this._core.scrollToTop()}scrollToBottom(){this._core.scrollToBottom()}scrollToLine(e){this._verifyIntegers(e),this._core.scrollToLine(e)}clear(){this._core.clear()}write(e,t){this._core.write(e,t)}writeln(e,t){this._core.write(e),this._core.write(`\r
|
|
20
20
|
`,t)}paste(e){this._core.paste(e)}refresh(e,t){this._verifyIntegers(e,t),this._core.refresh(e,t)}reset(){this._core.reset()}clearTextureAtlas(){this._core.clearTextureAtlas()}loadAddon(e){this._addonManager.loadAddon(this,e)}static get strings(){return{get promptLabel(){return Ke.get()},set promptLabel(e){Ke.set(e)},get tooMuchOutput(){return Je.get()},set tooMuchOutput(e){Je.set(e)}}}_verifyIntegers(...e){for(Ec of e)if(Ec===1/0||isNaN(Ec)||Ec%1!=0)throw Error(`This API only accepts integers`)}_verifyPositiveIntegers(...e){for(Ec of e)if(Ec&&(Ec===1/0||isNaN(Ec)||Ec%1!=0||Ec<0))throw Error(`This API only accepts positive integers`)}},Oc=2,kc=1,Ac=class{activate(e){this._terminal=e}dispose(){}fit(){let e=this.proposeDimensions();if(!e||!this._terminal||isNaN(e.cols)||isNaN(e.rows))return;let t=this._terminal._core;(this._terminal.rows!==e.rows||this._terminal.cols!==e.cols)&&(t._renderService.clear(),this._terminal.resize(e.cols,e.rows))}proposeDimensions(){if(!this._terminal||!this._terminal.element||!this._terminal.element.parentElement)return;let e=this._terminal._core._renderService.dimensions;if(e.css.cell.width===0||e.css.cell.height===0)return;let t=this._terminal.options.scrollback===0?0:this._terminal.options.overviewRuler?.width||14,n=window.getComputedStyle(this._terminal.element.parentElement),r=parseInt(n.getPropertyValue(`height`)),i=Math.max(0,parseInt(n.getPropertyValue(`width`))),a=window.getComputedStyle(this._terminal.element),o={top:parseInt(a.getPropertyValue(`padding-top`)),bottom:parseInt(a.getPropertyValue(`padding-bottom`)),right:parseInt(a.getPropertyValue(`padding-right`)),left:parseInt(a.getPropertyValue(`padding-left`))},s=o.top+o.bottom,c=o.right+o.left,l=r-s,u=i-c-t;return{cols:Math.max(Oc,Math.floor(u/e.css.cell.width)),rows:Math.max(kc,Math.floor(l/e.css.cell.height))}}},jc=`modulepreload`,Mc=function(e){return`/`+e},Nc={},Pc=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=Mc(t,n),t=s(t),t in Nc)return;Nc[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:jc,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},Fc=j(`<div class=overlay><div class=modal style=max-width:360px><div class=modal-head><b>🔒 sign in</b><span></span></div><form style=display:flex;flex-direction:column;gap:10px><input id=pw-input type=password placeholder=password autofocus><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:7px 12px;cursor:pointer">unlock</button><span class=muted style=font-size:11px>the token is stored locally and sent as Bearer to this server only`),Ic=j(`<div class=themegrid>`),Lc=j(`<div class=themepop><label class=trow title="switch automatically when the OS switches appearance — pick which theme to use for each"><input type=checkbox>follow system`),Rc=j(`<br>`),zc=j(`<span class="badge queued">⏳ <!> queued`),Bc=j(`<span class="badge cron">⏰ `),Vc=j(`<span class=sub>ℹ`),Hc=j(`<header class=chan-head><span class=hash>#</span><span class=title></span><span></span><span class=sub> · <!>/<!> · turns <!> · tools </span><span style=margin-left:auto;display:flex;gap:4px><button class=iconbtn title="terminal (t)">⌨</button><button class=iconbtn title="toggle details panel (d)">▤`),Uc=j(`<div class=divider-msg>── beginning of log ──`),Wc=j(`<div class=divider-msg>loading older events…`),Gc=j(`<details class=reasoning><summary>💭 reasoning</summary><div class=mono>`),Kc=j(`<div class=content>`),qc=j(`<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…`),Jc=j(`<div class=feed>`),Yc=j(`<div class="termempty muted">no shell here — + opens one, tabs fill the focused pane`),Xc=j(`<div class=termsplit>`),Zc=j(`<div class="termempty muted">no shell here — click a tab or + to add`),Qc=j(`<div class=termpane>`),$c=j(`<div class=termdrawer><div class=termgrip title="drag to resize · double-click to reset"></div><div class=termbar><div class=termtabs><button class=iconbtn title="new shell in this workspace (max 2 per agent)">+</button></div><div style=display:flex;gap:4px;align-items:center><span class="muted mono"style=flex:1;text-align:center;overflow:hidden;text-overflow:ellipsis;white-space:nowrap></span><button class=iconbtn>◫</button><button class=iconbtn title="close terminal (t)">✕</button></div></div><div class=termbody><div class=termpane>`),el=j(`<button class=jump>↓ `),tl=j(`<div class=cmds>`),nl=j(`<label class=forkchip title="inherit the conversation prefix byte-exactly — the sub-agent's provider prefix cache starts warm"><input type=checkbox>fork ctx`),rl=j(`<div class=composer><form><textarea rows=1></textarea><button type=submit>send</button></form><div class=hint>`),il=j(`<h3 title="identity + storage locations for this agent">🎛 session`),al=j(`<div class="card sesscard"><div class=sessrow><span class=k>agent</span><b></b><span></span></div><div class=sessrow><span class=k>workspace</span><span class="mono ellip"></span></div><div class=sessrow><span class=k>session</span><span class=mono>/`),ol=j(`<h3 title="switch provider/model live — applies from the agent's next turn; the list shows context window & pricing from the provider">🧦 model`),sl=j(`<div class=meta style=color:var(--fg)>`),cl=j(`<div class=modelbox><select title="provider (OpenAI-compatible endpoint)"></select><div style=display:flex;gap:4px><input type=text list=model-list style=flex:1;min-width:0><datalist id=model-list></datalist><button title="apply to this session — takes effect from the agent's next turn">apply</button></div><div class=meta>current: `),ll=j(`<h3>⏯ controls`),ul=j(`<button class=danger title="interrupt: aborts the current LLM call; the running tool finishes first">■ stop`),dl=j(`<button title="stop every sub-agent this agent spawned (descendants included)">⏹ subs`),fl=j(`<div class=btnrow><button title="branch off the conversation here — try things without disturbing the main line">⑂ fork</button><button title="remove agent from teapot (session log stays on disk)">🗑 remove`),pl=j(`<div class=ctrlrow><label title="auto-continue fires after a round ONLY when all hold: ① this toggle is on ② a goal is set and its status is 'active' ③ the round ended cleanly (no error / not stopped). It stops when the goal is marked done, or if you press ■ stop. Sending any prompt also starts an idle agent regardless."><input type=checkbox>auto-continue</label><span class=muted>loops while goal is active · stops on done / stop`),ml=j(`<span>`),hl=j(`<h3 title="what the agent is working toward — auto-continue keeps looping while the status is 'active'">🎯 goal`),gl=j(`<div class=statrow style=margin-bottom:6px><span class=k>status`),_l=j(`<div class=card><div class=content>`),vl=j(`<div class=muted style=font-size:11px;margin-top:4px>stored with the session · the agent reads it via get_goal() · auto-continue loops while status is "working" and stops when marked done`),yl=j(`<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><div style=display:flex;justify-content:flex-end;align-items:center;gap:10px><label class=muted title="queue a harness prompt telling the agent about the new goal at its next turn boundary"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=goal-notify type=checkbox checked> notify agent</label><button type=submit style="background:var(--acc);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save goal`),bl=j(`<span class=badge>/<!> done`),xl=j(`<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)`),Sl=j(`<div class=bartrack style=margin-bottom:6px><div>`),Cl=j(`<textarea id=todo-input class=mono rows=5 placeholder="- task one
|
|
21
|
-
- task two"title="shared with the agent — it may check items off via set_todo; your unsaved edits win until you save"style="width:100%;background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font-family:ui-monospace,Menlo,monospace;font-size:12.5px;resize:vertical">`),wl=j(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><button class=iconbtn></button><label class=muted title="queue a harness prompt telling the agent the task list changed"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=todo-notify type=checkbox checked> notify agent</label><button style="background:var(--ok);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save tasks`),Tl=j(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),El=j(`<h3 title="cumulative billed totals · the cached pill counts tokens served from the provider's prompt cache (far cheaper) · context bar turns orange ≥70% and red ≥85% of the model window">📊 runtime`),Dl=j(`<span class="pill ok">⚡ <!>% cached`),Ol=j(`<div class="card runcard"><div class=statgrid><div class=stat title="LLM turns taken this session"><span>turns</span><b></b></div><div class=stat title="tool calls executed"><span>tools</span><b></b></div><div class=stat title="times old turns were summarized to free context"><span>compacted</span><b></b></div></div><div class=statrow><span class=k>tokens</span><b> in / <!> out`),kl=j(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),Al=j(`<h3>⏰ schedule <span class=muted style=text-transform:none;letter-spacing:0>· cron tasks, all agents · edit in settings`),jl=j(`<div><nav class=sidebar><div class=agent-list></div><div class=sidebar-footer><div class=footer-row><span></span><div class=brand>🫖 teapot <span class=version>v</span></div><span style=margin-left:auto;display:flex;gap:4px;align-items:center><button class=iconbtn title="new agent">+</button><button class=iconbtn title=themes>🎨</button><button class=iconbtn title=settings>⚙</button></span></div><div class=metrics></div></div></nav><section class=channel></section><aside>`),Ml=j(`<span class=caret>`),Nl=j(`<span class=subtag>🧩`),Pl=j(`<span class=mini-cron>⏰`),Fl=j(`<span title="goal done">✓`),Il=j(`<div><span></span><span>`),Ll=j(`<span class=caret-spacer>`),Rl=j(`<label class=trow>system light →<select class=w100>`),zl=j(`<label class=trow>system dark →<select class=w100>`),Bl=j(`<option>`),Vl=j(`<button><span class=swdots>`),Hl=j(`<i>`),Ul=j(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),Wl=j(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),Gl=j(`<div class="content muted">thinking…`),Kl=j(`<span>⌨ <button class=tabx title="close this shell">✕`),ql=j(`<div><b class=mono></b><span class=muted>`),Jl=j(`<div class=cmdrow><b>@</b><span class=muted>`),Yl=j(`<button class=runbtn title="run toward the goal (starts the loop)">▶ start`),Xl=j(`<span class=badge title="no goal set yet">no goal`),Zl=j(`<button>`),Ql=j(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),$l=j(`<div class="content mdpreview"style="max-height:40vh;padding:8px 10px">`),eu=j(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),tu=j(`<div class=progrow><b>recent</b><span class="content inline-md">`),nu=j(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),ru=j(`<div class=progrow><b>next</b><span class="content inline-md">`),iu=j(`<div class=progrow><b>goal</b><span>`),au=j(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),ou=j(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),su=j(`<span>% of `),cu=j(`<div class=bartrack><div>`),lu=j(`<div class=bartrack style=margin-top:4px><div>`),uu=j(`<div class=ctxblock title="estimated live context vs the model's real window. Past the window, old turns are summarized into notes (compaction); the compact line below shows where that starts."><div class=statrow><span class=k>context</span><b>~<!> tok</b></div><div class=statrow style=margin-top:4px><span class=k>compact</span><b> tok</b><span class=muted style=font-size:11px;color:var(--dim)></span></div><div class=ctrlrow style=margin-top:6px><label title="when on, older turns are automatically summarized when context exceeds the budget"><input type=checkbox>auto-compact</label><span class=muted style=font-size:11.5px>summarizes old turns when budget exceeded</span></div><div class=muted style=font-size:11px;margin-top:4px>compaction starts around ~<!> tok — older turns get summarized, recent ones stay intact`),du=j(`<div><span></span><span> events`),fu=j(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),pu=j(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),mu=j(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class="sched-meta mono"> → next </div><div class="sched-prompt muted">`),hu=j(`<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)`),gu=j(`<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`),_u=j(`<span class=bashelapsed> elapsed`),vu=j(`<div class=mono>`),yu=j(`<pre class="mono toolbody">`),bu=j(`<div class=meta>ms`),xu=j(`<div class=meta>waiting for output…`),Su=j(`<div class=meta>`),Cu=j(`<div class=meta>writing…`),wu=j(`<pre class="mono toolbody del">`),Tu=j(`<pre class="mono toolbody add">`),Eu=j(`<div class=meta> · <!>ms`),Du=j(`<div class=meta>applying…`),Ou=j(`<pre class="mono toolbody patch">`),ku=j(`<div>`),Au=j(`<div class=meta>validating…`),ju=j(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),Mu=j(`<span class=muted>`),Nu=j(`<div class=meta>loading…`),Pu=j(`<div class=meta>bundled: `),Fu=j(`<div class=meta>saving…`),Iu=j(`<span class=actor>@`),Lu=j(`<details><summary><b>⚙ </b><span class=meta>`),Ru=j(`<div class=divider-msg>⑂ forked from <!> → `),zu=j(`<div class=divider-msg>🎯 goal <!>: `),Bu=j(`<div class=divider-msg>✅ tasks updated (<!>)`),Vu=j(`<div> → `),Hu=j(`<div class=avatar>`),Uu=j(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),Wu=j(`<div class=msg-head><span class=author></span><span class=ts></span><span class=ts>`),Gu=j(`<div><div class=msg-body>`),Ku=j(`<span style=width:38px>`),qu=j(`<div class=qfree><input type=text><button>reply`),Ju=j(`<div class=interrupted>⚠ interrupted — partial output kept`),Yu=j(`<div class=msgfoot><span>copy summary`),Xu=j(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>ms`),Zu=j(`<div class="content muted">Rejected: `),Qu=j(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged</span></summary><div class=content>`),$u=j(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),ed=j(`<div class=qopts>`),td=j(`<div><div>❓ `),nd=j(`<button class=qopt>`),rd=j(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),id=j(`<div class="embed fail"><div class=mono>⚠ `),ad=j(`<div class="content muted">`),od=j(`<button class=copybtn title="copy to clipboard">`),sd=j(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),cd=j(`<span style=color:var(--err);font-size:13px>`),ld=j(`<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>↑</button></div></label><div class=dirlist></div><div style=display:flex;gap:10px><label style=flex:1>agent name <input type=text placeholder="(directory name)"></label><label>provider<select></select></label><label style=flex:1>model <input type=text placeholder="(provider default)"></label></div><button type=submit style=align-self:flex-end>create`),ud=j(`<div class=direntry>📁 `),dd=j(`<span class=fsize>`),fd=j(`<div><span class=ficon></span><span class=fname>`),pd=j(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview">🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),md=j(`<div class=filebox>`),hd=j(`<div class=muted style=padding:6px>`),gd=j(`<button title="rendered markdown">👁 preview`),_d=j(`<button title="edit and save back to the workspace">✎ edit`),vd=j(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),yd=j(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),bd=j(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),xd=j(`<div class="content mdpreview">`),Sd=j(`<div class=filepreview>`),Cd=j(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),wd=j(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),Td=j(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),Ed=j(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),Dd=j(`<span style=color:var(--fg)>`),Od=j(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),kd=j(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>default model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),Ad=j(`<button type=button>`),jd=j(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),Md=j(`<label><input type=number min=0>`),Nd=j(`<form style=display:flex;flex-direction:column;gap:14px><fieldset><legend>providers</legend><button type=button>+ add custom</button><div style=display:flex;gap:6px;flex-wrap:wrap;margin-top:6px><span class=muted style=font-size:11.5px>quick-add:</span></div><div><label title="agents without an explicit provider use this one"style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<select><option value>(none — first provider wins)</option></select></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid></div></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><button type=submit style="align-self:flex-end;background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">save settings`),Pd=j(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="api key"type=password><input placeholder="default model"><button type=button class=danger title="remove provider">✕`),Fd=j(`<button type=button>+ `),Id=j(`<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">`),Ld=j(`<span class=muted>🧩 sub of @`),Rd=j(`<div class=cfgrow><b></b><span class=muted>`),zd=new Map;function Bd(e){let t=zd.get(e);if(t!==void 0)return t;let n=Re(e);return zd.set(e,n),zd.size>500&&zd.delete(zd.keys().next().value),n}var Vd={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`}},Hd={name:`harness`,icon:`📣`,color:`#3ba55d`},[Ud,Wd]=v(``),Gd,Q=e=>{Wd(e),clearTimeout(Gd),Gd=setTimeout(()=>Wd(``),3200)},Kd=[{key:`dark`,label:`Dark`,mode:`dark`,sw:[`#1a1c22`,`#2b2e39`,`#5865f2`]},{key:`midnight`,label:`Midnight`,mode:`dark`,sw:[`#0d0f18`,`#252a42`,`#8b7cf7`]},{key:`tea`,label:`Milk Tea`,mode:`dark`,sw:[`#241c16`,`#493b2d`,`#d98e32`]},{key:`coffee`,label:`Coffee`,mode:`dark`,sw:[`#191410`,`#403527`,`#c68a4b`]},{key:`matcha`,label:`Matcha`,mode:`dark`,sw:[`#1b2217`,`#3c4a33`,`#8db64e`]},{key:`matrix`,label:`Matrix`,mode:`dark`,sw:[`#060a06`,`#18301d`,`#2fd558`]},{key:`sunset`,label:`Sunset`,mode:`dark`,sw:[`#1c1422`,`#452f52`,`#f2784b`]},{key:`light`,label:`Light`,mode:`light`,sw:[`#eceef4`,`#ffffff`,`#4757d8`]},{key:`strawberry`,label:`Strawberry`,mode:`light`,sw:[`#fbe4ea`,`#fffafb`,`#e05575`]},{key:`ramune`,label:`Ramune`,mode:`light`,sw:[`#ddeff7`,`#fbfeff`,`#1d86ae`]}];function qd(){let e=``,t=``;try{let n=getComputedStyle(document.documentElement);e=n.getPropertyValue(`--term-bg`).trim(),t=n.getPropertyValue(`--term-fg`).trim()}catch{}return{background:e||`#0d0e12`,foreground:t||`#dcdee4`}}var Jd=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`?Vd.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:Hd}return Vd[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},Yd=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`]),Xd=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=``;try{t=(await i.json())?.error??``}catch{}throw Error(t||`${e}: HTTP ${i.status}`)}return i.json()}var Zd=location.hash.match(/[#&]token=([^&]+)/);Zd&&(localStorage.setItem(`teapot.token`,decodeURIComponent(Zd[1])),history.replaceState(null,``,location.pathname+location.search));var Qd=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function $d(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v([]),[o,s]=v(0),[c,l]=v([]),[u,d]=v(null),f=new Map,[p,m]=v(f.get(n()??``)??``),h=e=>{m(e);let t=n();t&&(e?f.set(t,e):f.delete(t))},[g,_]=v({providers:{}}),[S,te]=v(!1),[ne,w]=v(!1),[re,T]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>1100:localStorage.getItem(`teapot.panel`)===`1`),ie=()=>{let e=!re();T(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},[ae,oe]=v(!1),[E,se]=v(localStorage.getItem(`teapot.theme`)??`dark`),[ce,le]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[ue,de]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[fe,pe]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),me=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[he,ge]=v(me?.matches??!1);ee(()=>{let e=e=>ge(e.matches);me?.addEventListener(`change`,e),C(()=>me?.removeEventListener(`change`,e))}),b(()=>{let e=ce()?he()?ue():fe():E();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=Kd.find(t=>t.key===e)?.mode??`dark`});let[_e,ve]=v(``),[ye,be]=v(``),[xe,Se]=v([]),Ce=()=>Object.keys(g().providers??{});async function we(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);Se(t.models??[])}catch{Se([])}}let Te=()=>{let e=ye().trim()||F()?.model||``;if(!e)return``;let t=xe().find(t=>t.id===e);if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${cf(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)};b(()=>{let t=n(),r=e().find(e=>e.id===t),i=r?.provider||g().defaultProvider||Ce()[0]||``;r&&(_e()!==i&&(ve(i),we(i)),ye()&&be(``))});let[j,Ee]=v(!0),[je,Me]=v(0),[Ne,Pe]=v(null),[Fe,Ie]=v(``),Le;b(()=>{if(!Ne()){clearTimeout(Le),Le=void 0,Ie(``);return}Le||=setTimeout(()=>{Le=void 0,Ie(Ne()?.text??``)},(Ne()?.text.length??0)>2e4?250:(Ne()?.text.length??0)>6e3?120:60)}),C(()=>clearTimeout(Le)),b(()=>{Fe()&&j()&&requestAnimationFrame(()=>{wt()&&Tt(!0)})}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{wt()&&(Ee(!0),Me(0),Tt(!0))})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let F=x(()=>e().find(e=>e.id===n())),[ze,Be]=v(null);x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let[Ve,He]=v([]),Ue=x(()=>{let e=new Map,t=new Set,n=new Map;for(let r of i())if(Yd.has(r.type)){if(r.type===`tool_call`){let e=n.get(r.data.callId)??[];e.push(r),n.set(r.data.callId,e)}else if(r.type===`tool_result`){let i=n.get(r.data.callId)?.shift();i&&(e.set(i.id,r),t.add(r.id))}}return{resFor:e,consumed:t}}),We=x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&t.data?.callId&&e.add(String(t.data.callId));return e}),I=x(()=>{let{consumed:e}=Ue(),t=i().filter(t=>!Yd.has(t.type)||t.type===`tool_call`&&t.data?.name===`report_progress`||t.type===`tool_result`&&t.data?.name===`report_progress`?!1:t.type===`tool_result`?!e.has(t.id):t.type===`message`?t.data?.progressEcho?!1:String(t.data?.content??``).trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final:!0),n=[];for(let e of t)if(e.type===`sub`){let t=e.data,r=String(t?.type??`message`);if(r===`state`)continue;n.push({...e,type:r,data:{...t?.data,actor:t?.sub}})}else n.push(e);let r=e=>String(e??``).replace(/\s+/g,` `).trim().toLowerCase(),a=[];for(let e=0;e<n.length;e++){let t=n[e];if(t.type===`message`&&t.data?.role===`assistant`){let i=n[e-1],a=r(t.data.content);if(i?.type===`progress`){let e=i.data;if((a.includes(r(e.doing))||e.recent&&a.includes(r(e.recent)))&&a.length<=Math.max(200,r(e.doing).length*3))continue}if(i?.type===`decision`){let e=i.data,t=r(e.decision);if(t&&a.includes(t)&&a.length<=Math.max(300,t.length*3))continue}}a.push(t)}let o=Ve().filter(e=>!a.some(t=>t.type===`prompt`&&t.data?.source===`user`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)).map(e=>({id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:F()?.session??``,branch:F()?.branch??`br0`,parent:null,type:`prompt`,data:{source:`user`,text:e.text,pending:!0}}));return[...a,...o]}),L=()=>$(`/api/config`).then(_).catch(()=>{}),[Ge,Ke]=v(!1);ee(()=>{let e=()=>Ke(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[qe,Je]=v(``),[Ye,Xe]=v(!1),[Ze,Qe]=v(!1),$e=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==$e?($e=t,Qe(!1),Je(r)):t&&!Ze()&&Je(r)});let et=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:qe(),notify:e})}),Qe(!1),Q(`tasks saved${e&&qe().trim()?` & notification queued`:``}`),R()}catch(e){Q(`save failed: ${e.message}`)}},tt=x(()=>{let e=0,t=0;for(let n of qe().split(`
|
|
22
|
-
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),R=()=>$(`/api/agents`).then(e=>t(t=>{let n=new Map(t.map(e=>[e.id,e]));return(e.agents??[]).map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})})).catch(()=>{}),nt=()=>$(`/api/metrics`).then(d).catch(()=>{}),[rt,it]=v([]),at=()=>$(`/api/tasks`).then(e=>it(e.tasks)).catch(()=>{}),ot=e=>rt().filter(t=>t.agent===e),[st,ct]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),lt=e=>{let t=new Set(st());t.has(e)?t.delete(e):t.add(e),ct(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},ut=x(()=>{let t=e(),n=new Map,r=[];for(let e of t)e.parent&&t.some(t=>t.id===e.parent)?(n.has(e.parent)||n.set(e.parent,[]),n.get(e.parent).push(e)):r.push(e);let i=[],a=(e,t)=>{for(let r of e){i.push({a:r,depth:t});let e=n.get(r.id);e?.length&&!st().has(r.id)&&a(e,t+1)}};return a(r,0),i}),[dt,ft]=v(null),pt=new Map;function mt(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=pt.get(r.id);if(t[n]=i??r,!i&&(pt.set(r.id,r),pt.size>3e3)){let e=pt.keys().next().value;e!==void 0&&pt.delete(e)}}return t}let[ht,gt]=v(!1),[_t,vt]=v(!1),yt=0;function bt(e){a(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of mt(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function xt(){let e=n(),t=i()[0];if(!(!e||!t||ht()||_t())){gt(!0);try{let r=Ct(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=dt(),c=(await $(`/api/agents/${e}/events?limit=300&before=${encodeURIComponent(t.id)}${s?`&branch=${encodeURIComponent(s)}`:``}`)).events??[];if(c.length===0){vt(!0);return}if(n()!==e||i()[0]?.id!==t.id)return;bt(c),requestAnimationFrame(()=>{if(n()===e){let e=Ct();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{gt(!1)}}}async function St(e){let t=++yt;try{let r=dt(),[i,o,c]=await Promise.all([$(`/api/agents/${e}/events?limit=300${r?`&branch=${encodeURIComponent(r)}`:``}`),$(`/api/agents/${e}/branches`),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(t!==yt||n()!==e)return;a(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of mt(i.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),s(i.total??i.events.length),l(o.branches),hn(c.skills??[])}catch{}}function Ct(){return document.querySelector(`.feed`)}function wt(){let e=Ct();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<80}function Tt(e=!1){let t=Ct();t&&(e||j())&&(t.scrollTop=t.scrollHeight,Me(0))}async function Et(e,t=!0){let i=n();yt++,i!==e&&(a([]),pt.clear(),Pe(null),Me(0)),r(e),h(f.get(e)??``),ft(null),vt(!1),gt(!1),He([]),localStorage.setItem(`teapot.session`,e),Nt(e,t),$(`/api/agents/${e}/load`,{method:`POST`}).then(R).catch(()=>{}),await St(e),n()===e&&requestAnimationFrame(()=>{n()===e&&Tt(!0)})}let[Dt,Ot]=v(!1),kt=null,At=null;C(()=>kt?.close());function jt(){let e=location.protocol===`https:`?`wss://`:`ws://`;kt=new WebSocket(`${e}${location.host}/api/ws${
|
|
23
|
-
`))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[3]??``).trim();if(!r&&n!==`skill`){let e=on.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&pn.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=mn().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[]},yn,bn=()=>{yn&&(yn.style.height=`auto`,yn.style.height=`${Math.min(yn.scrollHeight,160)}px`)};b(()=>{p(),bn()});let xn=async(e,t)=>{let r=t??n();if(r)try{await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0})}),He(t=>[...t,{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now()}]),requestAnimationFrame(()=>Tt(!0))}catch(t){h(e),console.error(`send failed:`,t)}},U=async t=>{t.preventDefault();let r=n(),i=p().trim();if(!(!r||!i)){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=H().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:ln()?`fork`:`none`})})).id}${ln()?` (forked context)`:``}`),R(),h(``)}else if(s){if(!a){Q(`usage: @${r} <message>`);return}await $(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),Q(`→ delivered to @${r}`),h(``)}else{Q(`unknown @${r} — personas: ${H().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}return}if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim();if(t===`goal`&&!n){h(`/goal `);return}if(t===`skill`&&!n){h(`/skill `);return}h(``),await Sn(t,n);return}h(``),await xn(i)}},Sn=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(R);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Et(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 xn(`[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}`)}},Cn,wn=0;b(()=>{e(),requestAnimationFrame(()=>{Cn&&(wn=Math.min(wn,Cn.scrollHeight),Cn.scrollTop=wn)})});let Tn=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(R),En=async e=>{e.preventDefault();let t=document.getElementById(`goal-input`),r=document.getElementById(`goal-notify`)?.checked??!0;!n()||!t.value.trim()||(await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t.value,notify:r})}),t.value=``,R())};return[D(k,{get when(){return g()?.needsSetup},fallback:null,get children(){return D(
|
|
24
|
-
`))),e}}),null),P(i,D(k,{get when(){return t.goal.status===`done`},get children(){return Fl()}}),null),y(e=>{var o=`agent-item`+(t.id===n()?` sel`:``)+(r>0?` sub-row`:``),s=r>0?`padding-left:${10+r*14}px`:``,c=t.parent?`sub-agent of @${t.parent}`:void 0,l=`dot ${t.status}`;return o!==e.e&&N(i,e.e=o),e.t=Oe(i,s,e.t),c!==e.a&&M(i,`title`,e.a=c),l!==e.o&&N(a,e.o=l),e},{e:void 0,t:void 0,a:void 0,o:void 0}),i})()})),P(d,D(k,{get when(){return ae()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;le(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),P(e,D(k,{get when(){return!ce()},get fallback(){return[(()=>{var e=Rl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),P(t,D(O,{get each(){return
|
|
25
|
-
`)}`)),e}}),r),P(r,()=>F().model,i),P(r,()=>F().session,a),P(r,()=>F().branch,o),P(r,()=>F().stats.turns,s),P(r,()=>F().stats.toolCalls,null),P(c,D(k,{get when(){return F().statusReason},get children(){var e=Vc();return y(()=>M(e,`title`,F().statusReason)),e}}),l),l.$$click=It,u.$$click=ie,y(()=>N(n,`badge ${F().status}`)),e})(),(()=>{var e=Jc();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r=wt();r&&je()&&Me(0),Ee(r),t.scrollTop<=4&&n()&&!ht()&&!_t()&&i().length>0&&xt()}),P(e,D(k,{get when(){return A(()=>!!_t())()&&I().length>0},get children(){return Uc()}}),null),P(e,D(k,{get when(){return ht()},get children(){return Wc()}}),null),P(e,D(k,{get when(){return I().length>0},get fallback(){return Wl()},get children(){return[D(O,{get each(){return I()},children:(e,t)=>D(nf,{e,get prev(){return I()[t()-1]},get res(){return Ue().resFor.get(e.id)},onOption:e=>void xn(e),get answeredIds(){return We()},get agentActive(){return F()?.status===`running`||F()?.status===`waiting`},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`?()=>Be({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),D(k,{get when(){return Ne()},get children(){var e=qc(),t=e.firstChild.nextSibling;return t.firstChild,P(t,D(k,{get when(){return Ne().reasoning},get children(){var e=Gc(),t=e.firstChild.nextSibling;return P(t,()=>Ne().reasoning),e}}),null),P(t,D(k,{get when(){return Fe()},get fallback(){return Gl()},get children(){var e=Kc();return y(()=>e.innerHTML=Re(Fe()+`▍`)),e}}),null),e}})]}}),null),e})(),D(k,{get when(){return Pt()},get children(){var t=$c(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.firstChild,o=i.nextSibling.firstChild,s=o.nextSibling,c=s.nextSibling,l=r.nextSibling,u=l.firstChild;n.$$dblclick=()=>{qt(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Kt()))},n.$$pointerdown=V,P(i,D(O,{get each(){return z()},children:(e,t)=>(()=>{var n=Kl(),r=n.firstChild.nextSibling;return n.$$click=()=>Zt(t()),P(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),en(t())},y(r=>{var i=`termtab`+(Wt()===0&&Rt()===t()?` active`:``)+(Ht()&&Wt()===1&&Bt()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&N(n,r.e=i),a!==r.t&&M(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),a),a.$$click=Qt,P(o,(()=>{var t=A(()=>!!Xt());return()=>t()?e().find(e=>e.id===Xt().agentId)?.workspace.split(`/`).filter(Boolean).pop():F()?.workspace})()),s.$$click=rn,c.$$click=It;var d=an(0);return typeof d==`function`&&Ae(d,u),u.$$pointerdown=()=>Gt(0),P(u,D(k,{get when(){return!Xt()||Wt()===0&&Rt()===-1},get children(){return Yc()}})),P(l,D(k,{get when(){return Ht()},get children(){return[Xc(),(()=>{var e=Qc(),t=an(1);return typeof t==`function`&&Ae(t,e),e.$$pointerdown=()=>Gt(1),P(e,D(k,{get when(){return Bt()===-1||z().length<=Bt()},get children(){return Zc()}})),y(()=>e.classList.toggle(`focused`,Wt()===1)),e})()]}}),null),y(e=>{var n=`${Kt()}px`,r=Ht()?`single pane`:`split panes (50/50)`,i=!!Ht(),a=Wt()===0;return n!==e.e&&ke(t,`height`,e.e=n),r!==e.t&&M(s,`title`,e.t=r),i!==e.a&&l.classList.toggle(`split`,e.a=i),a!==e.o&&u.classList.toggle(`focused`,e.o=a),e},{e:void 0,t:void 0,a:void 0,o:void 0}),t}}),(()=>{var e=rl(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=t.nextSibling;P(e,D(k,{get when(){return!j()||je()>0},get children(){var e=el();return e.firstChild,e.$$click=()=>Tt(!0),P(e,(()=>{var e=A(()=>je()>0);return()=>e()?`${je()} new message${je()>1?`s`:``}`:`jump to present`})(),null),e}}),t),P(e,D(k,{get when(){return vn().length>0},get children(){var e=tl();return P(e,D(O,{get each(){return vn()},children:(e,t)=>(()=>{var n=ql(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{h(e.insert),_n(-1)},P(r,()=>e.insert.trim()),P(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===gn()?` active`:``),a=e.title;return i!==r.e&&N(n,r.e=i),a!==r.t&&M(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),P(e,D(k,{get when(){return fn().length>0},get children(){var e=tl();return P(e,D(O,{get each(){return fn()},children:e=>(()=>{var t=Jl(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{h(`@${e.key} `),_n(-1)},P(n,()=>e.key,null),P(r,()=>e.label),y(()=>M(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,U),n.$$keydown=e=>{let t=vn();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),_n(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),_n(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&gn()>=0){e.preventDefault(),h(t[gn()].insert),_n(-1);return}if(e.key===`Escape`&&t.length>0){_n(-1);return}e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),U(e))},n.$$input=e=>{h(e.currentTarget.value),_n(0),bn()};var a=yn;return typeof a==`function`?Ae(a,n):yn=n,P(t,D(k,{get when(){return A(()=>!!p().startsWith(`@`))()&&p().includes(` `)},get children(){var e=nl(),t=e.firstChild;return t.addEventListener(`change`,e=>un(e.currentTarget.checked)),y(()=>t.checked=ln()),e}}),r),P(i,()=>Ud()||`enter send · shift+enter newline · ↑↓ sessions · / commands & focus · t terminal · d panel · esc interrupt · messages sent while the agent works queue up and land at the next turn boundary`),y(()=>M(n,`placeholder`,`message #${F().id} — / for commands`)),y(()=>n.value=p()),e})()]}})),ne.addEventListener(`scroll`,e=>{wn=e.currentTarget.scrollTop});var T=Cn;return typeof T==`function`?Ae(T,ne):Cn=ne,P(ne,D(k,{get when(){return F()},get children(){return[il(),(()=>{var e=al(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return P(n,()=>F().id),P(r,()=>F().status),P(a,()=>F().workspace),P(o,()=>F().session,s),P(o,()=>F().branch,null),y(e=>{var t=`badge ${F().status}`,n=F().workspace;return t!==e.e&&N(r,e.e=t),n!==e.t&&M(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),D(pf,{get agentId(){return F().id},get workspace(){return F().workspace}}),ol(),(()=>{var e=cl(),t=e.firstChild,r=t.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=r.nextSibling;return s.firstChild,t.addEventListener(`change`,e=>{ve(e.currentTarget.value),we(e.currentTarget.value)}),P(t,D(O,{get each(){return Ce()},children:e=>(()=>{var t=Bl();return t.value=e,P(t,e,null),P(t,()=>e===g().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>be(e.currentTarget.value),P(a,D(O,{get each(){return xe()},children:e=>(()=>{var t=Bl();return y(()=>t.value=e.id),t})()})),o.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:_e(),model:ye().trim()||void 0,contextWindowTokens:xe().find(e=>e.id===(ye().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,R()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},P(s,()=>F().model,null),P(s,D(k,{get when(){return xe().length},get children(){return[` · `,A(()=>xe().length),` models loaded`]}}),null),P(e,D(k,{get when(){return Te()},get children(){var e=sl();return P(e,Te),e}}),null),y(()=>M(i,`placeholder`,F().model)),y(()=>t.value=_e()),y(()=>i.value=ye()),e})(),ll(),(()=>{var i=fl(),o=i.firstChild,s=o.nextSibling;return P(i,D(k,{get when(){return F().status===`running`},get fallback(){return(()=>{var e=Yl();return De(e,`click`,Tn(`/start`),!0),e})()},get children(){var e=ul();return De(e,`click`,Tn(`/stop`),!0),e}}),o),o.$$click=()=>$(`/api/agents/${F().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>Et(F().id)),s.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await $(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let o=e().filter(e=>e.id!==i);t(o),o[0]?Et(o[0].id):(r(null),a([]))},P(i,D(k,{get when(){return e().some(e=>e.parent===n())},get children(){var e=dl();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),R())},e}}),null),i})(),(()=>{var e=pl(),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(R)}),y(()=>t.checked=F().autoContinue??!0),e})(),(()=>{var e=hl();return e.firstChild,P(e,D(k,{get when(){return!!F().goal.text.trim()},get fallback(){return Xl()},get children(){var e=ml();return P(e,()=>F().goal.status),y(()=>N(e,`badge ${F().goal.status===`active`?`running`:F().goal.status}`)),e}}),null),e})(),(()=>{var e=gl();return e.firstChild,P(e,D(O,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Zl();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(R)},M(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`),P(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(F().goal.text.trim()&&F().goal.status===e?` on ${e}`:``),i=!!F().goal.text.trim()&&F().goal.status===e;return r!==n.e&&N(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),D(k,{get when(){return F().goal.text},get fallback(){return Ql()},get children(){var e=_l(),t=e.firstChild;return y(()=>t.innerHTML=Re(String(F().goal.text))),e}}),vl(),(()=>{var e=yl();return e.addEventListener(`submit`,En),e})(),(()=>{var e=xl(),t=e.firstChild.nextSibling;return P(e,D(k,{get when(){return tt().total>0},get children(){var e=bl(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,P(e,()=>tt().done,t),P(e,()=>tt().total,n),y(t=>Oe(e,tt().done===tt().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),D(k,{get when(){return tt().total>0},get children(){var e=Sl(),t=e.firstChild;return y(e=>{var n=`barfill `+(tt().done===tt().total?``:`warn`),r=`${Math.round(tt().done/tt().total*100)}%`;return n!==e.e&&N(t,e.e=n),r!==e.t&&ke(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),D(k,{get when(){return Ye()},get fallback(){return(()=>{var e=$l();return y(()=>e.innerHTML=Bd(qe())),e})()},get children(){var e=Cl();return e.$$input=e=>{Je(e.currentTarget.value),Qe(!0)},y(()=>e.value=qe()),e}}),(()=>{var e=wl(),t=e.firstChild,n=t.nextSibling.nextSibling;return t.$$click=()=>Xe(!Ye()),P(t,()=>Ye()?`👁`:`✎`),n.$$click=et,y(()=>M(t,`title`,Ye()?`rendered checklist`:`edit markdown`)),e})(),Tl(),D(k,{get when(){return F().latestProgress},get fallback(){return eu()},children:e=>(()=>{var t=au(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return P(t,D(k,{get when(){return e().recent},get children(){var t=tu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=Bd(e().recent)),t}}),i),P(t,D(k,{get when(){return e().problems},get children(){var t=nu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=Bd(e().problems)),t}}),i),P(t,D(k,{get when(){return e().next},get children(){var t=ru(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=Bd(e().next)),t}}),i),P(t,D(k,{get when(){return e().goalStatus},get children(){var t=iu(),n=t.firstChild.nextSibling;return P(n,()=>e().goalStatus),t}}),i),P(i,()=>sf(e().ts)),y(()=>r.innerHTML=Bd(e().doing)),t})()}),El(),(()=>{var e=Ol(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=t.nextSibling,l=c.firstChild.nextSibling,u=l.firstChild,d=u.nextSibling;return d.nextSibling,P(i,()=>F().stats.turns),P(o,()=>F().stats.toolCalls),P(s,()=>F().stats.compactions??0),P(l,()=>cf(F().stats.inputTokens),u),P(l,()=>cf(F().stats.outputTokens),d),P(c,D(k,{get when(){return(F().stats.cachedInputTokens??0)>0},get children(){var e=Dl(),t=e.firstChild.nextSibling;return t.nextSibling,P(e,()=>Math.round(F().stats.cachedInputTokens/Math.max(1,F().stats.inputTokens)*1e3)/10,t),y(()=>M(e,`title`,`${cf(F().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),P(e,D(k,{get when(){return F().ctx},get fallback(){return ou()},children:e=>{let t=xe().find(e=>e.id===F().model),r=e().window||t?.contextLength||0,i=r?Math.min(999,e().usedTokens/r*100):0,a=r?i>=85?`crit`:i>=70?`warn`:`ok`:``,o=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)},s=r?Math.round(r*.75):0,c=e().compactAt,l=e().compactAtIsManual===!0?!1:!c||c>=r;return(()=>{var t=uu(),u=t.firstChild,d=u.firstChild.nextSibling,f=d.firstChild.nextSibling;f.nextSibling;var p=u.nextSibling,m=p.firstChild.nextSibling,h=m.firstChild,g=m.nextSibling,_=p.nextSibling,v=_.firstChild.firstChild,b=_.nextSibling,x=b.firstChild.nextSibling;return x.nextSibling,P(d,()=>cf(e().usedTokens),f),P(u,D(k,{when:r,get children(){var e=su(),t=e.firstChild;return N(e,`pill ${a}`),P(e,()=>o(i),t),P(e,()=>cf(r),null),e}}),null),P(t,D(k,{when:r,get children(){var e=cu(),t=e.firstChild;return N(t,`barfill ${a}`),y(e=>ke(t,`width`,`${Math.min(100,i)}%`)),e}}),p),P(m,()=>cf(l?s:c),h),P(g,l?` (75% of window)`:` (manual override)`),P(t,D(k,{when:r,get children(){var t=lu(),n=t.firstChild;return N(n,`barfill ${a}`),y(t=>ke(n,`width`,`${Math.min(100,Math.round(e().usedTokens/s*100))}%`)),t}}),_),v.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(R)}),P(b,()=>cf(e().compactAt),x),y(()=>v.checked=F().autoCompact!==!1),t})()}}),null),e})(),kl(),D(O,{get each(){return c()},children:e=>(()=>{var t=du(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=dt()===e.branch?null:e.branch;ft(t),n()&&St(n())},P(r,()=>e.branch,null),P(r,()=>e.branch===F().branch?` (current)`:``,null),P(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===F().branch||e.branch===dt()?` cur`:``),i=e.branch===dt()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&N(t,n.e=r),i!==n.t&&M(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Al(),D(k,{get when(){return rt().length>0},get fallback(){return fu()},get children(){return D(O,{get each(){return rt()},children:e=>(()=>{var t=mu(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Et(e.agent),P(i,()=>e.id),P(a,()=>e.agent,null),P(r,D(k,{get when(){return e.forked},get children(){return pu()}}),null),P(o,()=>e.schedule,s),P(o,(()=>{var t=A(()=>!!e.next);return()=>t()?sf(e.next):`—`})(),null),P(o,(()=>{var t=A(()=>!!e.last);return()=>t()?` · last ${sf(e.last)}`:` · never ran`})(),null),P(c,()=>lf(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${lf(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&N(t,r.e=i),a!==r.t&&M(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(re()?``:` right-hidden`),n=`conn`+(Dt()?` ok`:``),r=Dt()?`live (websocket)`:`reconnecting…`,i=`rightbar`+(re()?` open`:``);return t!==e.e&&N(o,e.e=t),n!==e.t&&N(m,e.t=n),r!==e.a&&M(m,`title`,e.a=r),i!==e.o&&N(ne,e.o=i),e},{e:void 0,t:void 0,a:void 0,o:void 0}),o}}),D(k,{get when(){return S()},get children(){return D(ff,{get providers(){return Object.keys(g().providers??{})},onClose:()=>te(!1),onCreated:e=>{te(!1),R(),Et(e)}})}}),D(k,{get when(){return ne()},get children(){return D(vf,{get cfg(){return g()},onClose:()=>w(!1),onSaved:()=>{L(),at()}})}}),D(k,{get when(){return ze()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return D(df,{title:`edit prompt — forks the conversation`,onClose:()=>Be(null),get children(){var t=gu(),i=t.firstChild,s=i.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:a()})}),Be(null),R();let t=n();t&&await Et(t)}catch(e){alert(`edit failed: ${e.message}`)}}),P(t,D(k,{get when(){return r()>0},get children(){var e=hu(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return P(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>Be(null),y(()=>i.value=e().text),t}})}})]}function ef(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>Math.max(0,(n()-t)/1e3);return(()=>{var e=_u(),t=e.firstChild;return P(e,(()=>{var e=A(()=>i()<60);return()=>e()?`${i().toFixed(1)}s`:`${Math.floor(i()/60)}m ${Math.round(i()%60)}s`})(),t),e})()}function tf(e){let t=e.e,n=e.res,r=!e.agentActive&&!n,i=t.data??{},a=String(i.name??`tool`),o=()=>n?String(n.data?.result??``):``,s=a,c=``,l=(()=>{var e=vu();return P(e,()=>of(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=(e,t=1500)=>(()=>{var n=yu();return P(n,()=>of(e,t)),n})(),f=(e=4e3)=>n?[A(()=>d(o(),e)),(()=>{var e=bu(),t=e.firstChild;return P(e,()=>n.data?.durationMs,t),P(e,()=>n.data?.ok===!1?` · FAILED`:``,null),P(e,D(uf,{get text(){return o()}}),null),e})()]:xu();try{switch(a){case`bash`:{let e=u(`command`);s=`$ `+lf(e,96);let r=u(`timeout_ms`)?` · timeout ${Math.round(Number(u(`timeout_ms`))/1e3)}s`:``;c=n?`${n.data?.durationMs??`?`}ms${r}`:`running${r}`,l=[A(()=>A(()=>e!==s.slice(2))()?d(e,800):null),A(()=>f(6e3)),!n&&D(ef,{get startedAt(){return t.ts}})];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${lf(u(`pattern`),40)}/`),Number(i.args?.offset)<0?e.push(`last ${-Number(i.args.offset)} lines`):i.args?.offset&&e.push(`from L${i.args.offset}`),i.args?.limit&&e.push(`≤${i.args.limit} lines`),c=e.join(` · `),l=f(6e3);break}case`write_file`:{let e=String(i.args?.content??``);s=u(`path`)||`(no path)`,c=`${e.length} bytes`,l=[A(()=>d(e)),n?(()=>{var e=Su();return P(e,()=>lf(o(),160)),e})():Cu()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=wu();return P(e,()=>of(`- `+u(`old_text`),900)),e})(),(()=>{var e=Tu();return P(e,()=>`+ `+of(u(`new_text`),900)),e})(),n?(()=>{var e=Eu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,P(e,()=>lf(o(),120),t),P(e,()=>n.data?.durationMs,r),e})():Du()];break;case`apply_patch`:{let e=u(`patch`).split(`
|
|
26
|
-
`).filter(e=>e&&!/^---$/.test(e.trim())),t=e.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);s=t.length?`${t.length} file${t.length>1?`s`:``}: ${
|
|
27
|
-
`)[0]??``,140),null),P(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Au()];break}case`list_dir`:s=u(`path`)||`.`,l=f(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=lf(e,70),c=`web`,l=[(()=>{var e=Su();return P(e,D(k,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Mu();return P(e,()=>lf(u(`url`),80)),e})()},get children(){var e=ju();return y(()=>M(e,`href`,u(`url`))),e}})),e})(),A(()=>f(3e3))];break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=Kc();return y(()=>t.innerHTML=Re(e)),t})(),(()=>{var e=bu(),t=e.firstChild;return P(e,()=>n.data?.durationMs,t),e})()]:Nu();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=lf(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[A(()=>A(()=>!!e.length)()?(()=>{var t=Pu();return t.firstChild,P(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Eu(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,P(e,()=>lf(o(),160),t),P(e,()=>n.data?.durationMs,r),e})():Fu()];break}}}catch{}return(()=>{var e=Lu(),i=e.firstChild,o=i.firstChild;o.firstChild;var u=o.nextSibling;return M(e,`title`,`${a}${c?` — `+c:``}`),P(o,s,null),P(i,D(k,{get when(){return t.data?.actor},get children(){var e=Iu();return e.firstChild,P(e,()=>String(t.data.actor),null),e}}),u),P(u,n?c||``:r?`(result missed)`:`running…`),P(e,l,null),y(()=>N(e,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),e})()}function nf(e){let t=e.e,n=Jd(t),r=e.prev&&e.prev.type===t.type&&Jd(e.prev).name===n.name&&t.session===e.prev.session&&t.branch===e.prev.branch;if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Ru(),r=n.firstChild.nextSibling;return r.nextSibling,P(n,()=>String(e.fromBranch??`?`),r),P(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:lf(String(e.text??``),80);return(()=>{var t=zu(),r=t.firstChild.nextSibling;return r.nextSibling,P(t,()=>String(e.event??``),r),P(t,n,null),t})()}return t.type===`todo`?(()=>{var e=Bu(),n=e.firstChild.nextSibling;return n.nextSibling,P(e,()=>String(t.data?.by??`human`),n),e})():t.type===`state`?t.data.from===t.data.to?null:(()=>{var e=Vu(),n=e.firstChild;return P(e,()=>t.data.from,n),P(e,()=>t.data.to,null),P(e,(()=>{var e=A(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>N(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})():(()=>{var i=Gu(),a=i.firstChild;return P(i,D(k,{when:!r,get fallback(){return Ku()},get children(){var e=Hu();return P(e,()=>n.icon),y(t=>{var r=n.color+`33`,i=`1px solid ${n.color}66`;return r!==t.e&&ke(e,`background`,t.e=r),i!==t.t&&ke(e,`border`,t.t=i),t},{e:void 0,t:void 0}),e}}),a),P(a,D(k,{when:!r,get children(){var r=Wu(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return P(i,()=>n.name),P(r,D(k,{get when(){return t.data?.actor},get children(){var e=Iu();return e.firstChild,P(e,()=>String(t.data.actor),null),e}}),a),P(a,(()=>{var e=A(()=>!!t.data?.pending);return()=>e()?`pending…`:Xd(t.ts)})()),P(o,()=>t.branch),P(r,D(k,{get when(){return e.onEdit},get children(){var t=Uu();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>ke(i,`color`,n.color)),r}}),null),P(a,D(af,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive}}),null),y(()=>N(i,`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``))),i})()}function rf(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=qu(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&M(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 af(e){let t=e.e;switch(t.type){case`prompt`:return(()=>{var e=Kc();return y(()=>e.innerHTML=Bd(String(t.data.text??``))),e})();case`message`:return[D(k,{get when(){return A(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Gc(),n=e.firstChild.nextSibling;return P(n,()=>String(t.data.reasoning)),e}}),(()=>{var e=Kc();return y(()=>e.innerHTML=Bd(String(t.data.content??``))),e})(),D(k,{get when(){return t.data.interrupted},get children(){return Ju()}}),D(k,{get when(){return t.data.final},get children(){var e=Yu(),n=e.firstChild;return P(e,D(uf,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return D(tf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=Xu(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return P(i,()=>lf(e,120)),P(r,D(uf,{text:e}),null),P(a,()=>of(e,4e3)),P(o,()=>t.data.durationMs,s),P(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>N(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=Qu(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return P(n,D(k,{get when(){return e.length},get children(){var t=Zu();return t.firstChild,P(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=Bd(String(t.data?.decision??``)),r=Bd(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=e.answeredIds?.has(r)??!1;return(()=>{var r=td(),a=r.firstChild;return a.firstChild,N(r,`embed question`+(i?` answered`:``)),P(a,()=>String(t.data?.question??``),null),P(r,D(k,{when:i,get children(){return $u()}}),null),P(r,D(k,{get when(){return n.length>0},get children(){var r=ed();return P(r,D(O,{each:n,children:n=>(()=>{var r=nd();return r.$$click=()=>{let r=t.data?.actor;r?$(`/api/agents/${encodeURIComponent(String(r))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},r.disabled=i,P(r,n),r})()})),r}}),null),P(r,D(rf,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=rd(),n=e.firstChild.firstChild.nextSibling;return P(e,D(k,{get when(){return t.data.goalStatus},get children(){var e=iu(),n=e.firstChild.nextSibling;return P(n,()=>String(t.data.goalStatus)),e}}),null),P(e,D(k,{get when(){return t.data.recent},get children(){var e=tu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Bd(String(t.data.recent))),e}}),null),P(e,D(k,{get when(){return t.data.problems},get children(){var e=nu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Bd(String(t.data.problems))),e}}),null),P(e,D(k,{get when(){return t.data.next},get children(){var e=ru(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Bd(String(t.data.next))),e}}),null),y(()=>n.innerHTML=Bd(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=id(),n=e.firstChild;return n.firstChild,P(n,()=>String(t.data.message??``),null),e})();default:return(()=>{var e=ad();return P(e,()=>of(JSON.stringify(t.data),200)),e})()}}function of(e,t){return e.length>t?e.slice(0,t)+` …`:e}function sf(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 cf(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 lf(e,t){return of(e.replace(/\s+/g,` `).trim(),t)}function uf(e){let[t,n]=v(!1);return(()=>{var r=od();return r.$$click=t=>{t.stopPropagation(),navigator.clipboard.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),900)})},P(r,()=>t()?`✓`:`⧉`),r})()}function df(e){return(()=>{var t=sd(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),P(r,()=>e.title),De(i,`click`,e.onClose,!0),P(n,()=>e.children,null),t})()}function ff(e){let[t,n]=v(`~`),[r,i]=v([]),[a,o]=v(``),[s,c]=v(e.providers[0]??``),[l,u]=v(``),[d,f]=v(``);async function p(e){let t=await $(`/api/fs${e?`?path=${encodeURIComponent(e)}`:``}`);n(t.path),i(t.entries)}ee(()=>p(t()));let m=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 D(df,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=ld(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,g=h.nextSibling,_=g.nextSibling,v=f.nextSibling,b=v.nextSibling,x=b.firstChild,S=x.firstChild.nextSibling,ee=x.nextSibling,C=ee.firstChild.nextSibling,te=ee.nextSibling.firstChild.nextSibling,ne=b.nextSibling;return i.addEventListener(`submit`,m),h.$$input=e=>n(e.currentTarget.value),g.$$click=()=>p(t()),_.$$click=()=>p(`..`),P(v,D(O,{get each(){return r()},children:e=>(()=>{var n=ud();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),P(n,e,null),n})()})),S.$$input=e=>o(e.currentTarget.value),C.addEventListener(`change`,e=>c(e.currentTarget.value)),P(C,D(O,{get each(){return e.providers},children:e=>(()=>{var t=Bl();return P(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),P(i,D(k,{get when(){return d()},get children(){var e=cd();return P(e,d),e}}),ne),y(()=>h.value=t()),y(()=>S.value=a()),y(()=>C.value=s()),y(()=>te.value=l()),i}})}function pf(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),l=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{}}));async function u(t){try{let n=await $(`/api/agents/${e.agentId}/tree${t?`?path=${encodeURIComponent(t)}`:``}`);return l(t,n.entries??[])}catch(e){return c(e.message),null}}b(()=>{e.agentId,i(new Set),n(new Map),u(``).then(e=>{e&&n(new Map([[``,e]]))})});let d=async e=>{let a=new Set(r());if(a.has(e.path)){a.delete(e.path),i(a);return}if(a.add(e.path),i(a),!t().has(e.path)){let t=await u(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[f,p]=v(``),[m,h]=v(!1),[g,_]=v(`code`),[x,S]=v(``),[ee,te]=v(!1),ne=e=>/\.(md|markdown|mdx)$/i.test(e),w=0,re=async e=>{let t=++w;p(``),h(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-B972ox6D.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(w!==t)return;p(e=>e+r)}}catch{w===t&&p(``)}finally{w===t&&h(!1)}};C(()=>{w++});let T=async(t,n)=>{try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),S(r.content??``),_(r.binary?`code`:n),!r.binary&&n!==`md`&&re({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ie=async()=>{let t=a();if(!(!t||ee())){te(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:x(),baseContent:t.content})}),o({...t,content:x()}),Q(`saved ${t.path}`)}catch(e){let t=e.message;t.includes(`409`)||t.includes(`changed on disk`)?Q(`file changed on disk — reopen to see the current version`):Q(`save failed: ${t}`)}finally{te(!1)}}},ae=e=>!e.binary&&!e.truncated,oe=(e,n)=>[(()=>{var t=fd(),i=t.firstChild,a=i.nextSibling;return t.$$click=()=>e.dir?void d(e):void T(e,`code`),P(i,(()=>{var t=A(()=>!!e.dir);return()=>t()?r().has(e.path)?`▾`:`▸`:`·`})()),P(a,()=>e.name),P(t,D(k,{get when(){return A(()=>!e.dir)()&&e.size!==void 0},get children(){var t=dd();return P(t,()=>cf(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``),a=`padding-left:${n*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&N(t,r.e=i),r.t=Oe(t,a,r.t),o!==r.a&&M(t,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),t})(),D(k,{get when(){return A(()=>!!e.dir)()&&r().has(e.path)},get children(){return D(O,{get each(){return t().get(e.path)??[]},children:e=>oe(e,n+1)})}})],E=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace;return[(()=>{var e=pd(),t=e.firstChild.nextSibling;return t.firstChild,P(t,E,null),e})(),(()=>{var e=md();return P(e,D(k,{get when(){return(t().get(``)??[]).length>0},get fallback(){return(()=>{var e=hd();return P(e,()=>s()||`empty workspace`),e})()},get children(){return D(O,{get each(){return t().get(``)??[]},children:e=>oe(e,0)})}})),e})(),D(k,{get when(){return a()},children:e=>D(df,{get title(){return`🗂 ${e().path}`},onClose:()=>{w++,o(null)},get children(){return[(()=>{var t=vd(),n=t.firstChild;return P(t,D(k,{get when(){return A(()=>!!ne(e().path))()&&!e().binary},get children(){var e=gd();return e.$$click=()=>_(`md`),y(()=>N(e,g()===`md`?`on`:``)),e}}),n),n.$$click=()=>{_(`code`),f()||re({path:e().path,content:e().content,truncated:e().truncated})},P(t,D(k,{get when(){return ae(e())},get children(){var e=_d();return e.$$click=()=>_(`edit`),y(()=>N(e,g()===`edit`?`on`:``)),e}}),null),y(()=>N(n,g()===`code`?`on`:``)),t})(),D(k,{get when(){return!e().binary},get fallback(){return bd()},get children(){return D(k,{get when(){return g()===`edit`},get fallback(){return D(k,{get when(){return A(()=>g()===`md`)()&&ne(e().path)},get fallback(){return D(mf,{get path(){return e().path},get content(){return e().content},get html(){return f()},get pending(){return m()},get truncated(){return!!e().truncated}})},get children(){var t=xd();return y(()=>t.innerHTML=Re(e().content)),t}})},get children(){var t=yd(),n=t.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>S(e.currentTarget.value),M(n,`spellcheck`,!1),P(r,()=>cf(x().length),i),a.$$click=()=>void ie(),P(a,()=>ee()?`saving…`:`💾 save`),y(()=>a.disabled=ee()||x()===e().content),y(()=>n.value=x()),t}})}})]}})})]}function mf(e){return[D(k,{get when(){return e.html},get fallback(){return A(()=>!!e.pending)()?(()=>{var t=wd(),n=t.firstChild.nextSibling;return n.nextSibling,P(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Td();return P(t,()=>e.content),t})()},get children(){var t=Sd();return y(()=>t.innerHTML=e.html),t}}),D(k,{get when(){return e.truncated},get children(){return Cd()}})]}var hf=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:`anthropic/claude-sonnet-4`,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:`orcarouter/auto`,hint:`zero-markup routing gateway — 'orcarouter/auto' grades each prompt and picks the model`},{key:`openai`,label:`OpenAI`,url:`https://api.openai.com/v1`,model:`gpt-4o-mini`},{key:`llamacpp`,label:`llama.cpp server`,url:`http://localhost:8080/v1`,model:``,hint:`free & local — start it with: llama-server -m ./model.gguf (any model name works)`}],gf={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 _f(e){let[t,n]=v(hf[0]),[r,i]=v(hf[0].url),[a,o]=v(``),[s,c]=v(hf[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 ${cf(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},te=()=>ee(s()),ne=async t=>{t.preventDefault(),x(``),g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}};return(()=>{var e=kd(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,ee=x.firstChild.nextSibling,C=x.nextSibling,w=C.firstChild.nextSibling,re=w.nextSibling,T=C.nextSibling,ie=T.firstChild.nextSibling,ae=ie.firstChild.nextSibling,oe=ie.nextSibling.firstChild.nextSibling,E=T.nextSibling;return n.addEventListener(`submit`,ne),P(u,()=>[...hf,gf].map(e=>(()=>{var n=Ad();return n.$$click=()=>S(e),P(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&N(n,r.e=i),a!==r.t&&M(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),P(n,D(k,{get when(){return t().hint},get children(){var e=Ed();return P(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),P(b,()=>hf.map(e=>(()=>{var t=Bl();return y(()=>t.value=e.url),t})())),ee.$$input=e=>o(e.currentTarget.value),w.$$input=e=>c(e.currentTarget.value),P(re,()=>l().map(e=>(()=>{var t=Bl();return y(()=>t.value=e.id),t})())),P(n,D(k,{get when(){return l().length>0},get fallback(){return jd()},get children(){var e=Od(),t=e.firstChild;return P(e,()=>l().length,t),P(e,D(k,{get when(){return te()},get children(){return[` · `,(()=>{var e=Dd();return P(e,te),e})()]}}),null),e}}),T),ae.$$input=e=>f(e.currentTarget.value),oe.$$input=e=>m(e.currentTarget.value),P(n,D(k,{get when(){return _()},get children(){var e=cd();return P(e,_),e}}),E),P(E,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(type to filter models from the endpoint)`,r=h();return n!==e.e&&M(w,`placeholder`,e.e=n),r!==e.t&&(E.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>ae.value=d()),y(()=>oe.value=p()),e})()}function vf(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),[a,o]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[s,c]=v(e.cfg.progressMinChars??4e3),[l,u]=v(Math.round((e.cfg.contextTokenBudget??96e3)/1e3)),[d,f]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[p,m]=v(e.cfg.maxSpawnDepth??3),[h,g]=v((e.cfg.tasks??[]).map(e=>({...e}))),[_,b]=v(``),x=()=>(e.cfg.agents??[]).map(e=>e.id),S=()=>{let e={};for(let n of t()){if(!n.name.trim())return b(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return b(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},ee=async t=>{t.preventDefault(),b(``);let n=S();if(!n)return;let i=h().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of i){if(!e.agent){b(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){b(`task "${e.id}": schedule is required`);return}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,a())*6e4,progressMinChars:Math.max(100,s()),contextTokenBudget:Math.max(1e3,l())*1e3,...d()>0?{contextWindowTokens:d()*1e3}:{},maxSpawnDepth:Math.max(0,p()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){b(e.message)}},C=(e,t,n,r)=>(()=>{var i=Md(),a=i.firstChild;return M(i,`title`,r),P(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return D(df,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Nd(),b=v.firstChild,S=b.firstChild.nextSibling,te=S.nextSibling;te.firstChild;var ne=te.nextSibling.firstChild.firstChild.nextSibling;ne.firstChild;var w=b.nextSibling,re=w.firstChild.nextSibling,T=w.nextSibling,ie=T.firstChild.nextSibling,ae=T.nextSibling;ae.firstChild;var oe=ae.nextSibling;return v.addEventListener(`submit`,ee),P(b,D(O,{get each(){return t()},children:(e,r)=>(()=>{var i=Pd(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r()?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r()?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r()?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r()?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r())),y(()=>a.value=e.name),y(()=>o.value=e.baseUrl),y(()=>s.value=e.apiKey),y(()=>c.value=e.model),i})()}),S),S.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),P(te,D(O,{each:hf,children:e=>(()=>{var a=Fd();return a.firstChild,a.$$click=()=>{let a=t().filter(t=>t.name!==e.key);n([...a,{name:e.key,baseUrl:e.url,apiKey:``,model:e.model}]),r()||i(e.key)},P(a,()=>e.label,null),y(()=>M(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),ne.addEventListener(`change`,e=>i(e.currentTarget.value)),P(ne,D(O,{get each(){return[...new Set(t().map(e=>e.name.trim()).filter(Boolean))]},children:e=>(()=>{var t=Bl();return t.value=e,P(t,e),t})()}),null),P(re,()=>C(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),null),P(re,()=>C(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),null),P(re,()=>C(`compact budget (k tok)`,l(),e=>u(e),`auto-compact threshold — defaults to 75% of context window when empty; manual override in k tokens`),null),P(re,()=>C(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),P(re,()=>C(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),P(T,D(k,{get when(){return h().length>0},get children(){return D(O,{get each(){return h()},children:(e,t)=>(()=>{var n=Id(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().map((n,r)=>r===t()?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e.id),y(()=>a.value=e.agent),y(()=>o.value=e.schedule),y(()=>c.checked=!!e.forked),y(()=>u.value=e.prompt),n})()})}}),ie),ie.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),P(ae,D(O,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Rd(),n=t.firstChild,r=n.nextSibling;return P(n,()=>e.id),P(r,()=>e.workspace),P(t,D(k,{get when(){return e.parent},get children(){var t=Ld();return t.firstChild,P(t,()=>e.parent,null),t}}),null),t})()}),null),P(v,D(k,{get when(){return _()},get children(){var e=cd();return P(e,_),e}}),oe),y(()=>ne.value=r()),v}})}Ee([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Te(()=>D($d,{}),document.getElementById(`root`));export{Pc as t};
|
|
28
|
-
//# sourceMappingURL=index-
|
|
21
|
+
- task two"title="shared with the agent — it may check items off via set_todo; your unsaved edits win until you save"style="width:100%;background:var(--bg-darkest);border:none;border-radius:6px;padding:6px 8px;color:var(--fg);font-family:ui-monospace,Menlo,monospace;font-size:12.5px;resize:vertical">`),wl=j(`<div style=display:flex;justify-content:flex-end;align-items:center;gap:10px;margin-top:4px><button class=iconbtn></button><label class=muted title="queue a harness prompt telling the agent the task list changed"style=display:flex;align-items:center;gap:4px;font-size:11.5px;white-space:nowrap;cursor:pointer><input id=todo-notify type=checkbox checked> notify agent</label><button style="background:var(--ok);border:none;border-radius:6px;color:#fff;padding:4px 12px;cursor:pointer">✓ save tasks`),Tl=j(`<h3 title="latest report_progress snapshot. The harness asks for one after real activity (time AND output gates); errors show under ⚠ problems">📈 progress`),El=j(`<h3 title="cumulative billed totals · the cached pill counts tokens served from the provider's prompt cache (far cheaper) · context bar turns orange ≥70% and red ≥85% of the model window">📊 runtime`),Dl=j(`<span class="pill ok">⚡ <!>% cached`),Ol=j(`<div class="card runcard"><div class=statgrid><div class=stat title="LLM turns taken this session"><span>turns</span><b></b></div><div class=stat title="tool calls executed"><span>tools</span><b></b></div><div class=stat title="times old turns were summarized to free context"><span>compacted</span><b></b></div></div><div class=statrow><span class=k>tokens</span><b> in / <!> out`),kl=j(`<h3>🌿 branches <span class=muted style=text-transform:none;letter-spacing:0>· click to filter the feed`),Al=j(`<h3>⏰ schedule <span class=muted style=text-transform:none;letter-spacing:0>· cron tasks, all agents · edit in settings`),jl=j(`<div><nav class=sidebar><div class=agent-list></div><div class=sidebar-footer><div class=footer-row><span></span><div class=brand>🫖 teapot <span class=version>v</span></div><span style=margin-left:auto;display:flex;gap:4px;align-items:center><button class=iconbtn title="new agent">+</button><button class=iconbtn title=themes>🎨</button><button class=iconbtn title=settings>⚙</button></span></div><div class=metrics></div></div></nav><section class=channel></section><aside>`),Ml=j(`<span class=caret>`),Nl=j(`<span class=subtag>🧩`),Pl=j(`<span class=mini-cron>⏰`),Fl=j(`<span title="goal done">✓`),Il=j(`<div><span></span><span>`),Ll=j(`<span class=caret-spacer>`),Rl=j(`<label class=trow>system light →<select class=w100>`),zl=j(`<label class=trow>system dark →<select class=w100>`),Bl=j(`<option>`),Vl=j(`<button><span class=swdots>`),Hl=j(`<i>`),Ul=j(`<div class=muted style=display:grid;place-items:center;height:100%>select an agent`),Wl=j(`<div class=muted style=display:grid;place-items:center;height:100%>no events yet — say something or press ▶ start`),Gl=j(`<div class="content muted">thinking…`),Kl=j(`<span>⌨ <button class=tabx title="close this shell">✕`),ql=j(`<div><b class=mono></b><span class=muted>`),Jl=j(`<div class=cmdrow><b>@</b><span class=muted>`),Yl=j(`<button class=runbtn title="run toward the goal (starts the loop)">▶ start`),Xl=j(`<span class=badge title="no goal set yet">no goal`),Zl=j(`<button>`),Ql=j(`<div class="card muted">no goal yet — write one below and press ✓ save. Then ▶ start (or any message) sets it in motion.`),$l=j(`<div class="content mdpreview"style="max-height:40vh;padding:8px 10px">`),eu=j(`<div class=muted>none yet — the harness asks for a report after real activity, and the agent can report_progress anytime`),tu=j(`<div class=progrow><b>recent</b><span class="content inline-md">`),nu=j(`<div class="progrow warn"><b>⚠ problems</b><span class="content inline-md">`),ru=j(`<div class=progrow><b>next</b><span class="content inline-md">`),iu=j(`<div class=progrow><b>goal</b><span>`),au=j(`<div class="card prog"><div class=progrow><b>doing</b><span class="content inline-md"></span></div><div class="meta muted">`),ou=j(`<div class=statrow><span class=k>context</span><span class=muted>no window known for this model yet`),su=j(`<span>% of `),cu=j(`<div class=bartrack><div>`),lu=j(`<div class=bartrack style=margin-top:4px><div>`),uu=j(`<div class=ctxblock title="estimated live context vs the model's real window. Past the window, old turns are summarized into notes (compaction); the compact line below shows where that starts."><div class=statrow><span class=k>context</span><b>~<!> tok</b></div><div class=statrow style=margin-top:4px><span class=k>compact</span><b> tok</b><span class=muted style=font-size:11px;color:var(--dim)></span></div><div class=ctrlrow style=margin-top:6px><label title="when on, older turns are automatically summarized when context exceeds the budget"><input type=checkbox>auto-compact</label><span class=muted style=font-size:11.5px>summarizes old turns when budget exceeded</span></div><div class=muted style=font-size:11px;margin-top:4px>compaction starts around ~<!> tok — older turns get summarized, recent ones stay intact`),du=j(`<div><span></span><span> events`),fu=j(`<div class=muted>no scheduled tasks — add them in ⚙ settings ("scheduled tasks")`),pu=j(`<span title="runs on a forked branch so chatter stays off the main line">⑂`),mu=j(`<div><div class=sched-top><b></b><span class=muted>@</span></div><div class="sched-meta mono"> → next </div><div class="sched-prompt muted">`),hu=j(`<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)`),gu=j(`<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`),_u=j(`<span class=bashelapsed> elapsed`),vu=j(`<div class=mono>`),yu=j(`<pre class="mono toolbody">`),bu=j(`<div class=meta>ms`),xu=j(`<div class=meta>waiting for output…`),Su=j(`<div class="meta muted"> bytes — open it from 🗂 files for the full view`),Cu=j(`<div class=meta>`),wu=j(`<div class=meta>writing…`),Tu=j(`<pre class="mono toolbody del">`),Eu=j(`<pre class="mono toolbody add">`),Du=j(`<div class=meta> · <!>ms`),Ou=j(`<div class=meta>applying…`),ku=j(`<pre class="mono toolbody patch">`),Au=j(`<div>`),ju=j(`<div class="pline meta">… <!> more lines`),Mu=j(`<div class=meta>validating…`),Nu=j(`<a target=_blank rel="noopener noreferrer"referrerpolicy=no-referrer>open ↗`),Pu=j(`<span class=muted>`),Fu=j(`<div class=meta>loading…`),Iu=j(`<div class=meta>bundled: `),Lu=j(`<div class=meta>saving…`),Ru=j(`<span class=actor>@`),zu=j(`<details><summary><b>⚙ </b><span class=meta>`),Bu=j(`<div class=divider-msg>⑂ forked from <!> → `),Vu=j(`<div class=divider-msg>🎯 goal <!>: `),Hu=j(`<div class=divider-msg>✅ tasks updated (<!>)`),Uu=j(`<div> → `),Wu=j(`<div class=avatar>`),Gu=j(`<button class=editbtn title="edit this prompt — forks the conversation here (later events are dropped or summarized)">✎ edit`),Ku=j(`<div class=msg-head><span class=author></span><span class=ts></span><span class=ts>`),qu=j(`<div><div class=msg-body>`),Ju=j(`<span style=width:38px>`),Yu=j(`<div class=qfree><input type=text><button>reply`),Xu=j(`<div class=interrupted>⚠ interrupted — partial output kept`),Zu=j(`<div class=msgfoot><span>copy summary`),Qu=j(`<details><summary><span class=meta></span></summary><div class=mono></div><div class=meta>ms`),$u=j(`<div class="content muted">Rejected: `),ed=j(`<details class="embed decision"><summary><b>📌 <span class="content inline-md"></span></b><span class=meta>decision logged</span></summary><div class=content>`),td=j(`<div class=meta style=color:var(--ok)>✓ answered — continuing below`),nd=j(`<div class=qopts>`),rd=j(`<div><div>❓ `),id=j(`<button class=qopt>`),ad=j(`<div class=embed style=border-color:var(--ok)><div>📈 <div class="content inline-md">`),od=j(`<div class="embed fail"><div class=mono>⚠ `),sd=j(`<div class="content muted">`),cd=j(`<button class=copybtn title="copy to clipboard">`),ld=j(`<div class=overlay><div class=modal><div class=modal-head><b></b><button class=iconbtn>✕`),ud=j(`<span style=color:var(--err);font-size:13px>`),dd=j(`<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>↑</button></div></label><div class=dirlist></div><div style=display:flex;gap:10px><label style=flex:1>agent name <input type=text placeholder="(directory name)"></label><label>provider<select></select></label><label style=flex:1>model <input type=text placeholder="(provider default)"></label></div><button type=submit style=align-self:flex-end>create`),fd=j(`<div class=direntry>📁 `),pd=j(`<span class=fsize>`),md=j(`<div><span class=ficon></span><span class=fname>`),hd=j(`<h3 title="the agent's workspace — lazy-loaded, dotfiles hidden; click a folder to expand, a file to preview">🗂 files <span class=muted style=text-transform:none;letter-spacing:0>· `),gd=j(`<div class=filebox>`),_d=j(`<div class=muted style=padding:6px>`),vd=j(`<button title="rendered markdown">👁 preview`),yd=j(`<button title="edit and save back to the workspace">✎ edit`),bd=j(`<div class=filetoolbar><button title="syntax-highlighted source"></> code`),xd=j(`<div class=fileeditor><textarea class=mono></textarea><div class=filerow-actions><span class=muted> bytes</span><button class=savebtn>`),Sd=j(`<div class=mono style=margin:0;color:var(--dim)>(binary file — inspect it from the terminal)`),Cd=j(`<div class="content mdpreview">`),wd=j(`<div class=filepreview>`),Td=j(`<div class=muted style=padding-top:6px;font-size:11.5px>… truncated (first 100 KB)`),Ed=j(`<div class=muted style=padding:8px;font-size:12px>✨ highlighting <!>…`),Dd=j(`<pre class=mono style=max-height:62vh;overflow:auto;white-space:pre-wrap;margin:0>`),Od=j(`<div class=muted style=font-size:11.5px;margin-top:-6px>`),kd=j(`<span style=color:var(--fg)>`),Ad=j(`<div class=muted style=font-size:11.5px;margin-top:-8px> models found at this endpoint`),jd=j(`<div class=overlay style=background:var(--bg-darkest)><div class=modal style=max-width:560px><div class=modal-head><b>🫖 welcome to teapot</b></div><p class=muted style="margin:0 0 10px;font-size:13px">first run — pick an OpenAI-compatible provider and you're done. everything below can be changed later in ⚙ settings.</p><form style=display:flex;flex-direction:column;gap:12px><div style=display:flex;gap:6px;flex-wrap:wrap></div><label>base url<input type=text class="w100 mono"list=wiz-preset-urls><datalist id=wiz-preset-urls></datalist></label><label>api key <input type=password class=w100 placeholder="(local providers may not need one)"></label><label>default model<input type=text class="w100 mono"list=wiz-model-list><datalist id=wiz-model-list></datalist></label><fieldset><legend>first agent</legend><label>workspace directory<input type=text class="w100 mono"></label><label title="asks for this password when opening the UI or API from another machine — plain-HTTP LAN traffic is NOT encrypted"style=margin-top:4px>protect the API with a password? <input type=password class=w100 placeholder="(optional — LAN traffic is still plain HTTP)"></label></fieldset><button type=submit style="background:var(--acc);border:none;border-radius:8px;color:#fff;padding:9px 14px;font-weight:600;cursor:pointer">`),Md=j(`<button type=button>`),Nd=j(`<div class=muted style=font-size:11.5px;margin-top:-8px>models appear here automatically once the endpoint answers GET /models`),Pd=j(`<label><input type=number min=0>`),Fd=j(`<form style=display:flex;flex-direction:column;gap:14px><fieldset><legend>providers</legend><button type=button>+ add custom</button><div style=display:flex;gap:6px;flex-wrap:wrap;margin-top:6px><span class=muted style=font-size:11.5px>quick-add:</span></div><div><label title="agents without an explicit provider use this one"style=display:flex;align-items:center;gap:6px;margin-top:6px>default provider<select><option value>(none — first provider wins)</option></select></label></div></fieldset><fieldset><legend>agent runtime</legend><div class=cfggrid></div></fieldset><fieldset><legend>scheduled tasks</legend><button type=button>+ add task</button></fieldset><fieldset><legend>agents (read-only — edit config file or use +)</legend></fieldset><button type=submit style="align-self:flex-end;background:var(--acc);border:none;border-radius:6px;color:#fff;padding:6px 14px;cursor:pointer">save settings`),Id=j(`<div class=cfgrow><input class=cfgname placeholder=name><input placeholder=https://…/v1><input placeholder="api key"type=password><input placeholder="default model"><button type=button class=danger title="remove provider">✕`),Ld=j(`<button type=button>+ `),Rd=j(`<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">`),zd=j(`<span class=muted>🧩 sub of @`),Bd=j(`<div class=cfgrow><b></b><span class=muted>`),Vd=new Map;function Hd(e){let t=Vd.get(e);if(t!==void 0)return t;let n=Re(e);return Vd.set(e,n),Vd.size>500&&Vd.delete(Vd.keys().next().value),n}var Ud={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`}},Wd={name:`harness`,icon:`📣`,color:`#3ba55d`},[Gd,Kd]=v(``),qd,Q=e=>{Kd(e),clearTimeout(qd),qd=setTimeout(()=>Kd(``),3200)},Jd=[{key:`dark`,label:`Dark`,mode:`dark`,sw:[`#1a1c22`,`#2b2e39`,`#5865f2`]},{key:`midnight`,label:`Midnight`,mode:`dark`,sw:[`#0d0f18`,`#252a42`,`#8b7cf7`]},{key:`tea`,label:`Milk Tea`,mode:`dark`,sw:[`#241c16`,`#493b2d`,`#d98e32`]},{key:`coffee`,label:`Coffee`,mode:`dark`,sw:[`#191410`,`#403527`,`#c68a4b`]},{key:`matcha`,label:`Matcha`,mode:`dark`,sw:[`#1b2217`,`#3c4a33`,`#8db64e`]},{key:`matrix`,label:`Matrix`,mode:`dark`,sw:[`#060a06`,`#18301d`,`#2fd558`]},{key:`sunset`,label:`Sunset`,mode:`dark`,sw:[`#1c1422`,`#452f52`,`#f2784b`]},{key:`light`,label:`Light`,mode:`light`,sw:[`#eceef4`,`#ffffff`,`#4757d8`]},{key:`strawberry`,label:`Strawberry`,mode:`light`,sw:[`#fbe4ea`,`#fffafb`,`#e05575`]},{key:`ramune`,label:`Ramune`,mode:`light`,sw:[`#ddeff7`,`#fbfeff`,`#1d86ae`]}];function Yd(){let e=``,t=``;try{let n=getComputedStyle(document.documentElement);e=n.getPropertyValue(`--term-bg`).trim(),t=n.getPropertyValue(`--term-fg`).trim()}catch{}return{background:e||`#0d0e12`,foreground:t||`#dcdee4`}}var Xd=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`?Ud.prompt:t.startsWith(`scheduler:`)?{name:t.slice(10),icon:`📣`,color:`#3ba55d`}:Wd}return Ud[e.type]??{name:e.type,icon:`•`,color:`#9298a5`}},Zd=new Set([`user`,`message`,`prompt`,`tool_call`,`tool_result`,`progress`,`state`,`error`,`fork`,`goal`,`todo`,`question`,`decision`]),Qd=e=>{let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}`};async function $(e,t){let n=localStorage.getItem(`teapot.token`),r=new Headers(t?.headers);n&&!r.has(`authorization`)&&r.set(`authorization`,`Bearer ${n}`);let i=await fetch(e,{...t,headers:r});if(!i.ok){i.status===401&&window.dispatchEvent(new CustomEvent(`teapot:unauthorized`));let t=``;try{t=(await i.json())?.error??``}catch{}throw Error(t||`${e}: HTTP ${i.status}`)}return i.json()}var $d=location.hash.match(/[#&]token=([^&]+)/);$d&&(localStorage.setItem(`teapot.token`,decodeURIComponent($d[1])),history.replaceState(null,``,location.pathname+location.search));var ef=()=>{let e=localStorage.getItem(`teapot.token`);return e?`?token=${encodeURIComponent(e)}`:``};function tf(){let[e,t]=v([]),[n,r]=v(null),[i,a]=v([]),[o,s]=v(0),[c,l]=v([]),[u,d]=v(null),f=new Map,[p,m]=v(f.get(n()??``)??``),h=e=>{m(e);let t=n();t&&(e?f.set(t,e):f.delete(t))},[g,_]=v({providers:{}}),[S,te]=v(!1),[ne,w]=v(!1),[re,T]=v(localStorage.getItem(`teapot.panel`)===null?window.innerWidth>1100:localStorage.getItem(`teapot.panel`)===`1`),ie=()=>{let e=!re();T(e),localStorage.setItem(`teapot.panel`,e?`1`:`0`)},[ae,oe]=v(!1),[E,se]=v(localStorage.getItem(`teapot.theme`)??`dark`),[ce,le]=v(localStorage.getItem(`teapot.theme.auto`)===`1`),[ue,de]=v(localStorage.getItem(`teapot.theme.light`)??`light`),[fe,pe]=v(localStorage.getItem(`teapot.theme.dark`)??`dark`),me=typeof window.matchMedia==`function`?window.matchMedia(`(prefers-color-scheme: light)`):null,[he,ge]=v(me?.matches??!1);ee(()=>{let e=e=>ge(e.matches);me?.addEventListener(`change`,e),C(()=>me?.removeEventListener(`change`,e))}),b(()=>{let e=ce()?he()?ue():fe():E();document.documentElement.dataset.theme=e,document.documentElement.dataset.appearance=Jd.find(t=>t.key===e)?.mode??`dark`});let[_e,ve]=v(``),[ye,be]=v(``),[xe,Se]=v([]),Ce=()=>Object.keys(g().providers??{});async function we(e){if(e)try{let t=await $(`/api/models?provider=${encodeURIComponent(e)}`);Se(t.models??[])}catch{Se([])}}let Te=()=>{let e=ye().trim()||F()?.model||``;if(!e)return``;let t=xe().find(t=>t.id===e);if(!t)return``;let n=[];t.contextLength&&n.push(`ctx ${uf(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)};b(()=>{let t=n(),r=e().find(e=>e.id===t),i=r?.provider||g().defaultProvider||Ce()[0]||``;r&&(_e()!==i&&(ve(i),we(i)),ye()&&be(``))});let[j,Ee]=v(!0),[je,Me]=v(0),[Ne,Pe]=v(null),[Fe,Ie]=v(``),Le;b(()=>{if(!Ne()){clearTimeout(Le),Le=void 0,Ie(``);return}Le||=setTimeout(()=>{Le=void 0,Ie(Ne()?.text??``)},(Ne()?.text.length??0)>2e4?250:(Ne()?.text.length??0)>6e3?120:60)}),C(()=>clearTimeout(Le)),b(()=>{Fe()&&j()&&requestAnimationFrame(()=>{wt()&&Tt(!0)})}),b(()=>{if(!n())return;let e=()=>{document.visibilityState===`visible`&&requestAnimationFrame(()=>{wt()&&(Ee(!0),Me(0),Tt(!0))})};document.addEventListener(`visibilitychange`,e),C(()=>document.removeEventListener(`visibilitychange`,e))});let F=x(()=>e().find(e=>e.id===n())),[ze,Be]=v(null);x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&e.add(String(t.data.callId));return e});let[Ve,He]=v([]),Ue=x(()=>{let e=new Map,t=new Set,n=new Map;for(let r of i())if(Zd.has(r.type)){if(r.type===`tool_call`){let e=n.get(r.data.callId)??[];e.push(r),n.set(r.data.callId,e)}else if(r.type===`tool_result`){let i=n.get(r.data.callId)?.shift();i&&(e.set(i.id,r),t.add(r.id))}}return{resFor:e,consumed:t}}),We=x(()=>{let e=new Set;for(let t of i())t.type===`tool_result`&&t.data?.name===`ask_user`&&t.data?.callId&&e.add(String(t.data.callId));return e}),I=x(()=>{let{consumed:e}=Ue(),t=i().filter(t=>!Zd.has(t.type)||t.type===`tool_call`&&t.data?.name===`report_progress`||t.type===`tool_result`&&t.data?.name===`report_progress`?!1:t.type===`tool_result`?!e.has(t.id):t.type===`message`?t.data?.progressEcho?!1:String(t.data?.content??``).trim()!==``||String(t.data?.reasoning??``).trim()!==``||!!t.data?.final:!0),n=[];for(let e of t)if(e.type===`sub`){let t=e.data,r=String(t?.type??`message`);if(r===`state`)continue;n.push({...e,type:r,data:{...t?.data,actor:t?.sub}})}else n.push(e);let r=e=>String(e??``).replace(/\s+/g,` `).trim().toLowerCase(),a=[];for(let e=0;e<n.length;e++){let t=n[e];if(t.type===`message`&&t.data?.role===`assistant`){let i=n[e-1],a=r(t.data.content);if(i?.type===`progress`){let e=i.data;if((a.includes(r(e.doing))||e.recent&&a.includes(r(e.recent)))&&a.length<=Math.max(200,r(e.doing).length*3))continue}if(i?.type===`decision`){let e=i.data,t=r(e.decision);if(t&&a.includes(t)&&a.length<=Math.max(300,t.length*3))continue}}a.push(t)}let o=Ve().filter(e=>!a.some(t=>t.type===`prompt`&&t.data?.source===`user`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)).map(e=>({id:e.id,seq:2**53-1,ts:new Date(e.at).toISOString(),session:F()?.session??``,branch:F()?.branch??`br0`,parent:null,type:`prompt`,data:{source:`user`,text:e.text,pending:!0}}));return[...a,...o]}),L=()=>$(`/api/config`).then(_).catch(()=>{}),[Ge,Ke]=v(!1);ee(()=>{let e=()=>Ke(!0);window.addEventListener(`teapot:unauthorized`,e),C(()=>window.removeEventListener(`teapot:unauthorized`,e))});let[qe,Je]=v(``),[Ye,Xe]=v(!1),[Ze,Qe]=v(!1),$e=``;b(()=>{let t=n(),r=e().find(e=>e.id===t)?.todo??``;t&&t!==$e?($e=t,Qe(!1),Je(r)):t&&!Ze()&&Je(r)});let et=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:qe(),notify:e})}),Qe(!1),Q(`tasks saved${e&&qe().trim()?` & notification queued`:``}`),R()}catch(e){Q(`save failed: ${e.message}`)}},tt=x(()=>{let e=0,t=0;for(let n of qe().split(`
|
|
22
|
+
`)){let r=n.match(/^\s*[-*+] \[([ xX])\]/);r&&(e++,r[1].toLowerCase()===`x`&&t++)}return{total:e,done:t}}),R=()=>$(`/api/agents`).then(e=>t(t=>{let n=new Map(t.map(e=>[e.id,e]));return(e.agents??[]).map(e=>{let t=n.get(e.id);return t&&JSON.stringify(t)===JSON.stringify(e)?t:e})})).catch(()=>{}),nt=()=>$(`/api/metrics`).then(d).catch(()=>{}),[rt,it]=v([]),at=()=>$(`/api/tasks`).then(e=>it(e.tasks)).catch(()=>{}),ot=e=>rt().filter(t=>t.agent===e),[st,ct]=v((()=>{try{return new Set(JSON.parse(localStorage.getItem(`teapot.collapsed`)??`[]`))}catch{return new Set}})()),lt=e=>{let t=new Set(st());t.has(e)?t.delete(e):t.add(e),ct(t),localStorage.setItem(`teapot.collapsed`,JSON.stringify([...t]))},ut=x(()=>{let t=e(),n=new Map,r=[];for(let e of t)e.parent&&t.some(t=>t.id===e.parent)?(n.has(e.parent)||n.set(e.parent,[]),n.get(e.parent).push(e)):r.push(e);let i=[],a=(e,t)=>{for(let r of e){i.push({a:r,depth:t});let e=n.get(r.id);e?.length&&!st().has(r.id)&&a(e,t+1)}};return a(r,0),i}),[dt,ft]=v(null),pt=new Map;function mt(e){let t=Array.from({length:e.length});for(let n=0;n<e.length;n++){let r=e[n],i=pt.get(r.id);if(t[n]=i??r,!i&&(pt.set(r.id,r),pt.size>3e3)){let e=pt.keys().next().value;e!==void 0&&pt.delete(e)}}return t}let[ht,gt]=v(!1),[_t,vt]=v(!1),yt=0;function bt(e){a(t=>{let n=new Map;for(let e of t)n.set(e.id,e);for(let t of mt(e))n.has(t.id)||n.set(t.id,t);return[...n.values()].sort((e,t)=>e.seq-t.seq)})}async function xt(){let e=n(),t=i()[0];if(!(!e||!t||ht()||_t())){gt(!0);try{let r=Ct(),a=r?.scrollHeight??0,o=r?.scrollTop??0,s=dt(),c=(await $(`/api/agents/${e}/events?limit=300&before=${encodeURIComponent(t.id)}${s?`&branch=${encodeURIComponent(s)}`:``}`)).events??[];if(c.length===0){vt(!0);return}if(n()!==e||i()[0]?.id!==t.id)return;bt(c),requestAnimationFrame(()=>{if(n()===e){let e=Ct();e&&(e.scrollTop=o+(e.scrollHeight-a))}})}catch{}finally{gt(!1)}}}async function St(e){let t=++yt;try{let r=dt(),[i,o,c]=await Promise.all([$(`/api/agents/${e}/events?limit=300${r?`&branch=${encodeURIComponent(r)}`:``}`),$(`/api/agents/${e}/branches`),$(`/api/agents/${e}/skills`).catch(()=>({skills:[]}))]);if(t!==yt||n()!==e)return;a(e=>{let t=new Map;for(let n of e)t.set(n.id,n);for(let e of mt(i.events))t.set(e.id,e);return[...t.values()].sort((e,t)=>e.seq-t.seq)}),s(i.total??i.events.length),l(o.branches),hn(c.skills??[])}catch{}}function Ct(){return document.querySelector(`.feed`)}function wt(){let e=Ct();return!e||e.scrollHeight-e.scrollTop-e.clientHeight<80}function Tt(e=!1){let t=Ct();t&&(e||j())&&(t.scrollTop=t.scrollHeight,Me(0))}async function Et(e,t=!0){let i=n();yt++,i!==e&&(a([]),pt.clear(),Pe(null),Me(0)),r(e),h(f.get(e)??``),ft(null),vt(!1),gt(!1),He([]),localStorage.setItem(`teapot.session`,e),Nt(e,t),$(`/api/agents/${e}/load`,{method:`POST`}).then(R).catch(()=>{}),await St(e),n()===e&&requestAnimationFrame(()=>{n()===e&&Tt(!0)})}let[Dt,Ot]=v(!1),kt=null,At=null;C(()=>kt?.close());function jt(){let e=location.protocol===`https:`?`wss://`:`ws://`;kt=new WebSocket(`${e}${location.host}/api/ws${ef()}`),kt.onopen=()=>Ot(!0),kt.onclose=()=>{Ot(!1),setTimeout(jt,1500)},kt.onerror=()=>kt?.close();let t=new Set([`state`,`usage`,`session_start`]),r=null;kt.onmessage=e=>{let i=JSON.parse(e.data);if(i.kind!==`ping`&&i.kind!==`pong`){if(i.kind===`llm-delta`){r={id:i.agentId,at:Date.now()},i.agentId===n()&&Pe({text:i.text??``,reasoning:i.reasoning??``});return}if(!(i.kind===`event`&&t.has(i.event?.type))){if(document.visibilityState===`hidden`){a=!0,At||=setTimeout(s,2e3);return}At||=setTimeout(s,400)}}};let a=!1,s=async()=>{if(At=null,await R(),await nt(),n()){let e=i().at(-1)?.id,t=o(),a=Date.now();await St(n()),i().at(-1)?.id!==e&&(r?.id===n()&&r.at>=a||Pe(null),wt()?Tt(!0):Me(je()+Math.max(0,o()-t))),He(e=>e.filter(e=>!i().some(t=>t.type===`prompt`&&t.data?.text===e.text&&new Date(t.ts).getTime()>=e.at-1e3)))}},c=()=>{document.visibilityState===`visible`&&a&&(a=!1,At||=setTimeout(s,150))};document.addEventListener(`visibilitychange`,c),C(()=>document.removeEventListener(`visibilitychange`,c))}let Mt=()=>decodeURIComponent(location.pathname.split(`/`)[2]??``);function Nt(e,t=!0){let n=`/session/${encodeURIComponent(e)}`;t?history.pushState(null,``,n):history.replaceState(null,``,n)}window.addEventListener(`popstate`,()=>{let t=Mt();t&&e().some(e=>e.id===t)&&t!==n()&&Et(t,!1)}),b(()=>{let e=F();document.title=e?`${e.status===`running`?`▶ `:e.status===`error`?`⚠ `:``}${e.id} · teapot`:`teapot`}),window.addEventListener(`keydown`,e=>{let t=e.target;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)){e.key===`Escape`&&t.blur();return}if(e.key===`Escape`){if(S()){te(!1);return}if(ne()){w(!1);return}if(ze()){Be(null);return}if(ae()){oe(!1);return}let e=F();if(e?.status===`running`){$(`/api/agents/${e.id}/stop`,{method:`POST`}).then(R);return}re()&&window.innerWidth<=1100&&T(!1);return}if(!(S()||ne())){if(e.key===`/`)e.preventDefault(),document.querySelector(`.composer textarea`)?.focus();else if(e.key===`d`)ie();else if(e.key===`t`)It();else if(e.key===`ArrowDown`||e.key===`ArrowUp`){let t=ut().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&&Et(t[i].id)}}});let[Pt,Ft]=v(localStorage.getItem(`teapot.term`)===`1`),It=()=>{let e=!Pt();Ft(e),localStorage.setItem(`teapot.term`,e?`1`:`0`)},[z,Lt]=v([]),[Rt,zt]=v(0),[Bt,Vt]=v(-1),[Ht,Ut]=v(!1),[Wt,Gt]=v(0),[Kt,qt]=v(Number(localStorage.getItem(`teapot.termH`))||Math.max(220,Math.round(window.innerHeight*.35))),Jt=new Map,Yt=[null,null],Xt=()=>z()[Wt()===0?Rt():Bt()]??null;function Zt(e){if(!z()[e])return;let t=Wt()===0?Rt:Bt;(Wt()===0?Bt:Rt)()===e&&(Wt()===0?Vt(t()):zt(t())),t()===e||(Wt()===0?zt(e):Vt(e))}let Qt=()=>$t();function $t(e){let t=e??n();if(!t)return;let r=z().filter(e=>e.agentId===t).length;if(r>=2){Q(`max 2 shells per agent (${t})`);return}z().length+1;let i=r===0?{key:`${t}`,agentId:t,title:t}:{key:`${t}#${r+1}`,agentId:t,title:`${t}·${r+1}`};Lt(e=>[...e,i]),Wt()===0?zt(z().length):Vt(z().length)}function en(e){let t=z()[e];if(!t)return;let n=Jt.get(t.key);if(n){n.ro?.disconnect();try{n.ws.close()}catch{}n.term.dispose(),Jt.delete(t.key)}let r=z().filter((t,n)=>n!==e);Lt(r);let i=t=>t===e?-1:t>e?t-1:t;zt(e=>Math.min(i(e),r.length-1)),Vt(e=>e===-1?-1:Math.min(i(e),r.length-1))}function B(){for(let[,e]of Jt){e.ro?.disconnect();try{e.ws.close()}catch{}e.term.dispose()}Jt.clear()}function tn(e,t){let n=Jt.get(e.key);if(n)n.el.parentElement!==t&&(t.appendChild(n.el),setTimeout(()=>{try{n.fit()}catch{}},30));else{let r=document.createElement(`div`);r.className=`termsession`,t.appendChild(r);let i=new Dc({cursorBlink:!0,fontSize:12.5,fontFamily:`ui-monospace, Menlo, Consolas, monospace`,theme:Yd()}),a=new Ac;i.loadAddon(a),i.open(r);let o=location.protocol===`https:`?`wss://`:`ws://`,s=new WebSocket(`${o}${location.host}/api/agents/${e.agentId}/term${ef()}`);s.onmessage=e=>{let t=JSON.parse(e.data);t.kind===`data`?i.write(t.data):t.kind===`exit`&&i.write(`\r\n\x1b[2m[terminal exited ${t.code??``}]\x1b[0m\r\n`)},i.onData(e=>{s.readyState===WebSocket.OPEN&&s.send(JSON.stringify({kind:`input`,data:e}))});let c={cols:0,rows:0},l=[],u=()=>{try{a.fit()}catch{}(i.cols!==c.cols||i.rows!==c.rows)&&s.readyState===WebSocket.OPEN&&(c={cols:i.cols,rows:i.rows},s.send(JSON.stringify({kind:`resize`,cols:i.cols,rows:i.rows})))},d=new ResizeObserver(()=>{l[0]&&clearTimeout(l[0]),l[0]=setTimeout(u,250)});d.observe(r),setTimeout(u,60),n={el:r,term:i,fit:a,ws:s,ro:d},Jt.set(e.key,n)}return n}function nn(e){let t=Yt[e];if(!t)return;let n=z()[e===0?Rt():Bt()];if(!n){t.replaceChildren();return}let r=tn(n,t);Wt()===(e===0?0:1)&&requestAnimationFrame(()=>{try{r.fit(),r.term.focus()}catch{}})}b(()=>{z(),Ht(),Rt(),Bt(),Kt(),requestAnimationFrame(()=>{nn(0),Ht()&&nn(1)})}),b(()=>{if(!Pt())return;let e=n();if(e){if(!z().some(t=>t.agentId===e)&&z().length===0)$t(e);else if(!z().some(t=>t.agentId===e)){let t=z().findIndex(t=>t.agentId===e);t>=0&&Zt(t)}}});let V=e=>{e.preventDefault();let t=e.clientY,n=Kt(),r=e=>{let r=Math.min(Math.max(n-(e.clientY-t),140),Math.round(window.innerHeight*.85));qt(r)},i=()=>{window.removeEventListener(`pointermove`,r),window.removeEventListener(`pointerup`,i),localStorage.setItem(`teapot.termH`,String(Kt())),requestAnimationFrame(()=>{nn(0),Ht()&&nn(1)})};window.addEventListener(`pointermove`,r),window.addEventListener(`pointerup`,i)},rn=()=>{let e=!Ht();if(Ut(e),e&&Bt()===-1){let e=z().findIndex((e,t)=>t!==Rt());Vt(e>=0?e:-1)}};C(B);let an=e=>t=>{Yt[e]=t};ee(()=>{L(),R().then(()=>{let t=Mt()||localStorage.getItem(`teapot.session`)||``,n=e().find(e=>e.id===t)??e()[0];n&&Et(n.id,!1)}),nt(),at(),cn(),jt();let t=setInterval(()=>{nt(),at()},3e4);C(()=>clearInterval(t))});let on=[{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`}],[H,sn]=v([]),cn=()=>$(`/api/personas`).then(e=>sn(e.personas)).catch(()=>{}),[ln,un]=v(!1),dn=()=>{let e=p().match(/^@([A-Za-z0-9._-]*)$/);return e?e[1].toLowerCase():null},fn=()=>{let t=dn();return t===null?[]:[...H().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))},pn=new Set([`start`,`stop`,`fork`,`compact`]),[mn,hn]=v([]),[gn,_n]=v(-1),vn=()=>{let e=p();if(!e.startsWith(`/`)||e.includes(`
|
|
23
|
+
`))return[];let t=e.match(/^\/([a-z]*)(?:\s+(.*))?$/i);if(!t)return[];let n=t[1].toLowerCase(),r=(t[3]??``).trim();if(!r&&n!==`skill`){let e=on.filter(e=>e.cmd.slice(1).startsWith(n));return e.find(e=>e.cmd.slice(1)===n)&&pn.has(n)?[]:e.map(e=>({insert:e.cmd+` `,title:e.desc}))}if(n===`skill`){let e=mn().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[]},yn,bn=()=>{yn&&(yn.style.height=`auto`,yn.style.height=`${Math.min(yn.scrollHeight,160)}px`)};b(()=>{p(),bn()});let xn=async(e,t)=>{let r=t??n();if(r)try{await $(`/api/agents/${r}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:e,start:!0})}),He(t=>[...t,{id:`@p${Date.now()}${Math.random().toString(36).slice(2,6)}`,text:e,at:Date.now()}]),requestAnimationFrame(()=>Tt(!0))}catch(t){h(e),console.error(`send failed:`,t)}},U=async t=>{t.preventDefault();let r=n(),i=p().trim();if(!(!r||!i)){if(i.startsWith(`@`)){let t=i.indexOf(` `),r=(t===-1?i.slice(1):i.slice(1,t)).toLowerCase(),a=t===-1?``:i.slice(t+1).trim(),o=H().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:ln()?`fork`:`none`})})).id}${ln()?` (forked context)`:``}`),R(),h(``)}else if(s){if(!a){Q(`usage: @${r} <message>`);return}await $(`/api/agents/${encodeURIComponent(r)}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:a,start:!0})}),Q(`→ delivered to @${r}`),h(``)}else{Q(`unknown @${r} — personas: ${H().map(e=>e.key).join(`, `)||`(none)`}`);return}}catch(e){Q(`@${r} failed: ${e.message}`)}return}if(i.startsWith(`/`)){let e=i.indexOf(` `),t=(e===-1?i.slice(1):i.slice(1,e)).toLowerCase(),n=e===-1?``:i.slice(e+1).trim();if(t===`goal`&&!n){h(`/goal `);return}if(t===`skill`&&!n){h(`/skill `);return}h(``),await Sn(t,n);return}h(``),await xn(i)}},Sn=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(R);try{if(e===`start`)await i(`/start`);else if(e===`stop`)await i(`/stop`);else if(e===`fork`)await i(`/fork`,{}),await Et(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 xn(`[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}`)}},Cn,wn=0;b(()=>{e(),requestAnimationFrame(()=>{Cn&&(wn=Math.min(wn,Cn.scrollHeight),Cn.scrollTop=wn)})});let Tn=e=>()=>n()&&$(`/api/agents/${n()}${e}`,{method:`POST`}).then(R),En=async e=>{e.preventDefault();let t=document.getElementById(`goal-input`),r=document.getElementById(`goal-notify`)?.checked??!0;!n()||!t.value.trim()||(await $(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:t.value,notify:r})}),t.value=``,R())};return[D(k,{get when(){return g()?.needsSetup},fallback:null,get children(){return D(yf,{onDone:()=>location.reload()})}}),D(k,{get when(){return Ge()},get children(){var e=Fc();return e.firstChild.firstChild.nextSibling.addEventListener(`submit`,e=>{e.preventDefault();let t=document.getElementById(`pw-input`);localStorage.setItem(`teapot.token`,t.value),location.reload()}),e}}),D(k,{get when(){return!g()?.needsSetup},get children(){var o=jl(),s=o.firstChild,l=s.firstChild,d=l.nextSibling,f=d.firstChild,m=f.firstChild,_=m.nextSibling,v=_.firstChild.nextSibling;v.firstChild;var b=_.nextSibling.firstChild,x=b.nextSibling,S=x.nextSibling,ee=f.nextSibling,C=s.nextSibling,ne=C.nextSibling;P(l,D(O,{get each(){return ut()},children:({a:t,depth:r})=>(()=>{var i=Il(),a=i.firstChild,o=a.nextSibling;return i.$$click=()=>Et(t.id),P(i,D(k,{get when(){return e().some(e=>e.parent===t.id)},get fallback(){return Ll()},get children(){var e=Ml();return e.$$click=e=>{e.stopPropagation(),lt(t.id)},P(e,()=>st().has(t.id)?`▸`:`▾`),y(()=>M(e,`title`,st().has(t.id)?`expand sub-agents`:`collapse sub-agents`)),e}}),a),P(o,()=>t.id),P(i,D(k,{get when(){return t.parent},get children(){return Nl()}}),null),P(i,D(k,{get when(){return ot(t.id).length>0},get children(){var e=Pl();return y(()=>M(e,`title`,ot(t.id).map(e=>`${e.id}: ${e.schedule}`).join(`
|
|
24
|
+
`))),e}}),null),P(i,D(k,{get when(){return t.goal.status===`done`},get children(){return Fl()}}),null),y(e=>{var o=`agent-item`+(t.id===n()?` sel`:``)+(r>0?` sub-row`:``),s=r>0?`padding-left:${10+r*14}px`:``,c=t.parent?`sub-agent of @${t.parent}`:void 0,l=`dot ${t.status}`;return o!==e.e&&N(i,e.e=o),e.t=Oe(i,s,e.t),c!==e.a&&M(i,`title`,e.a=c),l!==e.o&&N(a,e.o=l),e},{e:void 0,t:void 0,a:void 0,o:void 0}),i})()})),P(d,D(k,{get when(){return ae()},get children(){var e=Lc(),t=e.firstChild.firstChild;return t.addEventListener(`change`,e=>{let t=e.currentTarget.checked;le(t),localStorage.setItem(`teapot.theme.auto`,t?`1`:`0`)}),P(e,D(k,{get when(){return!ce()},get fallback(){return[(()=>{var e=Rl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{de(e.currentTarget.value),localStorage.setItem(`teapot.theme.light`,e.currentTarget.value)}),P(t,D(O,{get each(){return Jd.filter(e=>e.mode===`light`)},children:e=>(()=>{var t=Bl();return P(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=ue()),e})(),(()=>{var e=zl(),t=e.firstChild.nextSibling;return t.addEventListener(`change`,e=>{pe(e.currentTarget.value),localStorage.setItem(`teapot.theme.dark`,e.currentTarget.value)}),P(t,D(O,{get each(){return Jd.filter(e=>e.mode===`dark`)},children:e=>(()=>{var t=Bl();return P(t,()=>e.label),y(()=>t.value=e.key),t})()})),y(()=>t.value=fe()),e})()]},get children(){var e=Ic();return P(e,D(O,{each:Jd,children:e=>(()=>{var t=Vl(),n=t.firstChild;return t.$$click=()=>{se(e.key),localStorage.setItem(`teapot.theme`,e.key)},P(n,()=>e.sw.map(e=>(()=>{var t=Hl();return ke(t,`background`,e),t})())),P(t,()=>e.label,null),y(n=>{var r=`themebtn`+(E()===e.key?` on`:``),i=`${e.label} (${e.mode})`;return r!==n.e&&N(t,n.e=r),i!==n.t&&M(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()})),e}}),null),y(()=>t.checked=ce()),e}}),f),P(v,`0.14.9`,null),b.$$click=()=>{L(),te(!0)},x.$$click=()=>oe(!ae()),S.$$click=()=>{L(),w(!0)},P(ee,D(k,{get when(){return u()},get children(){return[`master rss `,A(()=>u().rssMb),`MB · heap `,A(()=>u().heapUsedMb),`MB`,Rc(),`load1 `,A(()=>u().loadavg1),` · up `,A(()=>Math.floor(u().uptimeSec/60)),`m`]}})),P(C,D(k,{get when(){return F()},get fallback(){return Ul()},get children(){return[(()=>{var e=Hc(),t=e.firstChild.nextSibling,n=t.nextSibling,r=n.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling.nextSibling,s=o.nextSibling.nextSibling;s.nextSibling;var c=r.nextSibling,l=c.firstChild,u=l.nextSibling;return P(t,()=>F().id),P(n,()=>F().status),P(e,D(k,{get when(){return(F().pendingPrompts??0)>0},get children(){var e=zc(),t=e.firstChild.nextSibling;return t.nextSibling,P(e,()=>F().pendingPrompts,t),y(()=>M(e,`title`,`${F().pendingPrompts} prompt(s) waiting — the agent picks them up at the next turn boundary`)),e}}),r),P(e,D(k,{get when(){return ot(F().id).length>0},get children(){var e=Bc();return e.firstChild,P(e,()=>ot(F().id).length,null),y(()=>M(e,`title`,`scheduled tasks:\n${ot(F().id).map(e=>`${e.schedule} · ${e.id}${e.forked?` (forked)`:``}`).join(`
|
|
25
|
+
`)}`)),e}}),r),P(r,()=>F().model,i),P(r,()=>F().session,a),P(r,()=>F().branch,o),P(r,()=>F().stats.turns,s),P(r,()=>F().stats.toolCalls,null),P(c,D(k,{get when(){return F().statusReason},get children(){var e=Vc();return y(()=>M(e,`title`,F().statusReason)),e}}),l),l.$$click=It,u.$$click=ie,y(()=>N(n,`badge ${F().status}`)),e})(),(()=>{var e=Jc();return e.addEventListener(`scroll`,e=>{let t=e.currentTarget,r=wt();r&&je()&&Me(0),Ee(r),t.scrollTop<=4&&n()&&!ht()&&!_t()&&i().length>0&&xt()}),P(e,D(k,{get when(){return A(()=>!!_t())()&&I().length>0},get children(){return Uc()}}),null),P(e,D(k,{get when(){return ht()},get children(){return Wc()}}),null),P(e,D(k,{get when(){return I().length>0},get fallback(){return Wl()},get children(){return[D(O,{get each(){return I()},children:(e,t)=>D(af,{e,get prev(){return I()[t()-1]},get res(){return Ue().resFor.get(e.id)},onOption:e=>void xn(e),get answeredIds(){return We()},get agentActive(){return F()?.status===`running`||F()?.status===`waiting`},get onEdit(){return e.type===`prompt`&&e.data?.source===`user`?()=>Be({eventId:e.id,text:String(e.data?.text??``)}):void 0}})}),D(k,{get when(){return Ne()},get children(){var e=qc(),t=e.firstChild.nextSibling;return t.firstChild,P(t,D(k,{get when(){return Ne().reasoning},get children(){var e=Gc(),t=e.firstChild.nextSibling;return P(t,()=>Ne().reasoning),e}}),null),P(t,D(k,{get when(){return Fe()},get fallback(){return Gl()},get children(){var e=Kc();return y(()=>e.innerHTML=Re(Fe()+`▍`)),e}}),null),e}})]}}),null),e})(),D(k,{get when(){return Pt()},get children(){var t=$c(),n=t.firstChild,r=n.nextSibling,i=r.firstChild,a=i.firstChild,o=i.nextSibling.firstChild,s=o.nextSibling,c=s.nextSibling,l=r.nextSibling,u=l.firstChild;n.$$dblclick=()=>{qt(Math.max(220,Math.round(window.innerHeight*.35))),localStorage.setItem(`teapot.termH`,String(Kt()))},n.$$pointerdown=V,P(i,D(O,{get each(){return z()},children:(e,t)=>(()=>{var n=Kl(),r=n.firstChild.nextSibling;return n.$$click=()=>Zt(t()),P(n,()=>e.title,r),r.$$click=e=>{e.stopPropagation(),en(t())},y(r=>{var i=`termtab`+(Wt()===0&&Rt()===t()?` active`:``)+(Ht()&&Wt()===1&&Bt()===t()?` active`:``),a=`${e.title} — click to show in focused pane`;return i!==r.e&&N(n,r.e=i),a!==r.t&&M(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()}),a),a.$$click=Qt,P(o,(()=>{var t=A(()=>!!Xt());return()=>t()?e().find(e=>e.id===Xt().agentId)?.workspace.split(`/`).filter(Boolean).pop():F()?.workspace})()),s.$$click=rn,c.$$click=It;var d=an(0);return typeof d==`function`&&Ae(d,u),u.$$pointerdown=()=>Gt(0),P(u,D(k,{get when(){return!Xt()||Wt()===0&&Rt()===-1},get children(){return Yc()}})),P(l,D(k,{get when(){return Ht()},get children(){return[Xc(),(()=>{var e=Qc(),t=an(1);return typeof t==`function`&&Ae(t,e),e.$$pointerdown=()=>Gt(1),P(e,D(k,{get when(){return Bt()===-1||z().length<=Bt()},get children(){return Zc()}})),y(()=>e.classList.toggle(`focused`,Wt()===1)),e})()]}}),null),y(e=>{var n=`${Kt()}px`,r=Ht()?`single pane`:`split panes (50/50)`,i=!!Ht(),a=Wt()===0;return n!==e.e&&ke(t,`height`,e.e=n),r!==e.t&&M(s,`title`,e.t=r),i!==e.a&&l.classList.toggle(`split`,e.a=i),a!==e.o&&u.classList.toggle(`focused`,e.o=a),e},{e:void 0,t:void 0,a:void 0,o:void 0}),t}}),(()=>{var e=rl(),t=e.firstChild,n=t.firstChild,r=n.nextSibling,i=t.nextSibling;P(e,D(k,{get when(){return!j()||je()>0},get children(){var e=el();return e.firstChild,e.$$click=()=>Tt(!0),P(e,(()=>{var e=A(()=>je()>0);return()=>e()?`${je()} new message${je()>1?`s`:``}`:`jump to present`})(),null),e}}),t),P(e,D(k,{get when(){return vn().length>0},get children(){var e=tl();return P(e,D(O,{get each(){return vn()},children:(e,t)=>(()=>{var n=ql(),r=n.firstChild,i=r.nextSibling;return n.$$click=()=>{h(e.insert),_n(-1)},P(r,()=>e.insert.trim()),P(i,()=>e.title),y(r=>{var i=`cmdrow`+(t()===gn()?` active`:``),a=e.title;return i!==r.e&&N(n,r.e=i),a!==r.t&&M(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})()})),e}}),t),P(e,D(k,{get when(){return fn().length>0},get children(){var e=tl();return P(e,D(O,{get each(){return fn()},children:e=>(()=>{var t=Jl(),n=t.firstChild;n.firstChild;var r=n.nextSibling;return t.$$click=()=>{h(`@${e.key} `),_n(-1)},P(n,()=>e.key,null),P(r,()=>e.label),y(()=>M(t,`title`,e.label)),t})()})),e}}),t),t.addEventListener(`submit`,U),n.$$keydown=e=>{let t=vn();if(t.length>0&&e.key===`ArrowDown`){e.preventDefault(),_n(e=>Math.min(e+1,t.length-1));return}if(t.length>0&&e.key===`ArrowUp`){e.preventDefault(),_n(e=>Math.max(e-1,0));return}if(t.length>0&&(e.key===`Tab`||e.key===`Enter`)&&!e.shiftKey&&gn()>=0){e.preventDefault(),h(t[gn()].insert),_n(-1);return}if(e.key===`Escape`&&t.length>0){_n(-1);return}e.key===`Enter`&&!e.shiftKey&&!e.isComposing&&(e.preventDefault(),U(e))},n.$$input=e=>{h(e.currentTarget.value),_n(0),bn()};var a=yn;return typeof a==`function`?Ae(a,n):yn=n,P(t,D(k,{get when(){return A(()=>!!p().startsWith(`@`))()&&p().includes(` `)},get children(){var e=nl(),t=e.firstChild;return t.addEventListener(`change`,e=>un(e.currentTarget.checked)),y(()=>t.checked=ln()),e}}),r),P(i,()=>Gd()||`enter send · shift+enter newline · ↑↓ sessions · / commands & focus · t terminal · d panel · esc interrupt · messages sent while the agent works queue up and land at the next turn boundary`),y(()=>M(n,`placeholder`,`message #${F().id} — / for commands`)),y(()=>n.value=p()),e})()]}})),ne.addEventListener(`scroll`,e=>{wn=e.currentTarget.scrollTop});var T=Cn;return typeof T==`function`?Ae(T,ne):Cn=ne,P(ne,D(k,{get when(){return F()},get children(){return[il(),(()=>{var e=al(),t=e.firstChild,n=t.firstChild.nextSibling,r=n.nextSibling,i=t.nextSibling,a=i.firstChild.nextSibling,o=i.nextSibling.firstChild.nextSibling,s=o.firstChild;return P(n,()=>F().id),P(r,()=>F().status),P(a,()=>F().workspace),P(o,()=>F().session,s),P(o,()=>F().branch,null),y(e=>{var t=`badge ${F().status}`,n=F().workspace;return t!==e.e&&N(r,e.e=t),n!==e.t&&M(a,`title`,e.t=n),e},{e:void 0,t:void 0}),e})(),D(hf,{get agentId(){return F().id},get workspace(){return F().workspace}}),ol(),(()=>{var e=cl(),t=e.firstChild,r=t.nextSibling,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=r.nextSibling;return s.firstChild,t.addEventListener(`change`,e=>{ve(e.currentTarget.value),we(e.currentTarget.value)}),P(t,D(O,{get each(){return Ce()},children:e=>(()=>{var t=Bl();return t.value=e,P(t,e,null),P(t,()=>e===g().defaultProvider?` ★`:``,null),t})()})),i.$$input=e=>be(e.currentTarget.value),P(a,D(O,{get each(){return xe()},children:e=>(()=>{var t=Bl();return y(()=>t.value=e.id),t})()})),o.$$click=async e=>{if(!n())return;let t=e.currentTarget;t.disabled=!0;try{await $(`/api/agents/${n()}/model`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({provider:_e(),model:ye().trim()||void 0,contextWindowTokens:xe().find(e=>e.id===(ye().trim()||void 0))?.contextLength})}),t.textContent=`✓ applied`,R()}catch(e){alert(`model switch failed: ${e.message}`)}finally{setTimeout(()=>{t.textContent=`apply`,t.disabled=!1},1200)}},P(s,()=>F().model,null),P(s,D(k,{get when(){return xe().length},get children(){return[` · `,A(()=>xe().length),` models loaded`]}}),null),P(e,D(k,{get when(){return Te()},get children(){var e=sl();return P(e,Te),e}}),null),y(()=>M(i,`placeholder`,F().model)),y(()=>t.value=_e()),y(()=>i.value=ye()),e})(),ll(),(()=>{var i=fl(),o=i.firstChild,s=o.nextSibling;return P(i,D(k,{get when(){return F().status===`running`},get fallback(){return(()=>{var e=Yl();return De(e,`click`,Tn(`/start`),!0),e})()},get children(){var e=ul();return De(e,`click`,Tn(`/stop`),!0),e}}),o),o.$$click=()=>$(`/api/agents/${F().id}/fork`,{method:`POST`,headers:{"content-type":`application/json`},body:`{}`}).then(()=>Et(F().id)),s.$$click=async()=>{let i=n();if(!i||!confirm(`remove agent ${i}? (log is kept)`))return;await $(`/api/agents/${i}`,{method:`DELETE`}).catch(()=>{});let o=e().filter(e=>e.id!==i);t(o),o[0]?Et(o[0].id):(r(null),a([]))},P(i,D(k,{get when(){return e().some(e=>e.parent===n())},get children(){var e=dl();return e.$$click=async()=>{n()&&(Q(`stopped: ${((await $(`/api/agents/${n()}/stop-children`,{method:`POST`})).stopped??[]).join(`, `)||`(none)`}`),R())},e}}),null),i})(),(()=>{var e=pl(),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(R)}),y(()=>t.checked=F().autoContinue??!0),e})(),(()=>{var e=hl();return e.firstChild,P(e,D(k,{get when(){return!!F().goal.text.trim()},get fallback(){return Xl()},get children(){var e=ml();return P(e,()=>F().goal.status),y(()=>N(e,`badge ${F().goal.status===`active`?`running`:F().goal.status}`)),e}}),null),e})(),(()=>{var e=gl();return e.firstChild,P(e,D(O,{each:[`active`,`done`,`paused`],children:e=>(()=>{var t=Zl();return t.$$click=()=>{n()&&$(`/api/agents/${n()}/goal`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({status:e})}).then(R)},M(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`),P(t,e===`active`?`▶ working`:e===`done`?`✓ done`:`⏸ paused`),y(n=>{var r=`goalstate`+(F().goal.text.trim()&&F().goal.status===e?` on ${e}`:``),i=!!F().goal.text.trim()&&F().goal.status===e;return r!==n.e&&N(t,n.e=r),i!==n.t&&(t.disabled=n.t=i),n},{e:void 0,t:void 0}),t})()}),null),e})(),D(k,{get when(){return F().goal.text},get fallback(){return Ql()},get children(){var e=_l(),t=e.firstChild;return y(()=>t.innerHTML=Re(String(F().goal.text))),e}}),vl(),(()=>{var e=yl();return e.addEventListener(`submit`,En),e})(),(()=>{var e=xl(),t=e.firstChild.nextSibling;return P(e,D(k,{get when(){return tt().total>0},get children(){var e=bl(),t=e.firstChild,n=t.nextSibling;return n.nextSibling,P(e,()=>tt().done,t),P(e,()=>tt().total,n),y(t=>Oe(e,tt().done===tt().total?`color:var(--ok)`:`color:var(--warn)`,t)),e}}),t),e})(),D(k,{get when(){return tt().total>0},get children(){var e=Sl(),t=e.firstChild;return y(e=>{var n=`barfill `+(tt().done===tt().total?``:`warn`),r=`${Math.round(tt().done/tt().total*100)}%`;return n!==e.e&&N(t,e.e=n),r!==e.t&&ke(t,`width`,e.t=r),e},{e:void 0,t:void 0}),e}}),D(k,{get when(){return Ye()},get fallback(){return(()=>{var e=$l();return y(()=>e.innerHTML=Hd(qe())),e})()},get children(){var e=Cl();return e.$$input=e=>{Je(e.currentTarget.value),Qe(!0)},y(()=>e.value=qe()),e}}),(()=>{var e=wl(),t=e.firstChild,n=t.nextSibling.nextSibling;return t.$$click=()=>Xe(!Ye()),P(t,()=>Ye()?`👁`:`✎`),n.$$click=et,y(()=>M(t,`title`,Ye()?`rendered checklist`:`edit markdown`)),e})(),Tl(),D(k,{get when(){return F().latestProgress},get fallback(){return eu()},children:e=>(()=>{var t=au(),n=t.firstChild,r=n.firstChild.nextSibling,i=n.nextSibling;return P(t,D(k,{get when(){return e().recent},get children(){var t=tu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(e().recent)),t}}),i),P(t,D(k,{get when(){return e().problems},get children(){var t=nu(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(e().problems)),t}}),i),P(t,D(k,{get when(){return e().next},get children(){var t=ru(),n=t.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(e().next)),t}}),i),P(t,D(k,{get when(){return e().goalStatus},get children(){var t=iu(),n=t.firstChild.nextSibling;return P(n,()=>e().goalStatus),t}}),i),P(i,()=>lf(e().ts)),y(()=>r.innerHTML=Hd(e().doing)),t})()}),El(),(()=>{var e=Ol(),t=e.firstChild,r=t.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling,o=a.firstChild.nextSibling,s=a.nextSibling.firstChild.nextSibling,c=t.nextSibling,l=c.firstChild.nextSibling,u=l.firstChild,d=u.nextSibling;return d.nextSibling,P(i,()=>F().stats.turns),P(o,()=>F().stats.toolCalls),P(s,()=>F().stats.compactions??0),P(l,()=>uf(F().stats.inputTokens),u),P(l,()=>uf(F().stats.outputTokens),d),P(c,D(k,{get when(){return(F().stats.cachedInputTokens??0)>0},get children(){var e=Dl(),t=e.firstChild.nextSibling;return t.nextSibling,P(e,()=>Math.round(F().stats.cachedInputTokens/Math.max(1,F().stats.inputTokens)*1e3)/10,t),y(()=>M(e,`title`,`${uf(F().stats.cachedInputTokens)} tokens were served from the provider's prompt cache — billed far cheaper than fresh input`)),e}}),null),P(e,D(k,{get when(){return F().ctx},get fallback(){return ou()},children:e=>{let t=xe().find(e=>e.id===F().model),r=e().window||t?.contextLength||0,i=r?Math.min(999,e().usedTokens/r*100):0,a=r?i>=85?`crit`:i>=70?`warn`:`ok`:``,o=e=>{let t=Math.round(e*10)/10;return Number.isInteger(t)?String(t):t.toFixed(1)},s=r?Math.round(r*.75):0,c=e().compactAt,l=e().compactAtIsManual===!0?!1:!c||c>=r;return(()=>{var t=uu(),u=t.firstChild,d=u.firstChild.nextSibling,f=d.firstChild.nextSibling;f.nextSibling;var p=u.nextSibling,m=p.firstChild.nextSibling,h=m.firstChild,g=m.nextSibling,_=p.nextSibling,v=_.firstChild.firstChild,b=_.nextSibling,x=b.firstChild.nextSibling;return x.nextSibling,P(d,()=>uf(e().usedTokens),f),P(u,D(k,{when:r,get children(){var e=su(),t=e.firstChild;return N(e,`pill ${a}`),P(e,()=>o(i),t),P(e,()=>uf(r),null),e}}),null),P(t,D(k,{when:r,get children(){var e=cu(),t=e.firstChild;return N(t,`barfill ${a}`),y(e=>ke(t,`width`,`${Math.min(100,i)}%`)),e}}),p),P(m,()=>uf(l?s:c),h),P(g,l?` (75% of window)`:` (manual override)`),P(t,D(k,{when:r,get children(){var t=lu(),n=t.firstChild;return N(n,`barfill ${a}`),y(t=>ke(n,`width`,`${Math.min(100,Math.round(e().usedTokens/s*100))}%`)),t}}),_),v.addEventListener(`change`,e=>{n()&&$(`/api/agents/${n()}/auto-compact`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({value:e.currentTarget.checked})}).then(R)}),P(b,()=>uf(e().compactAt),x),y(()=>v.checked=F().autoCompact!==!1),t})()}}),null),e})(),kl(),D(O,{get each(){return c()},children:e=>(()=>{var t=du(),r=t.firstChild,i=r.nextSibling,a=i.firstChild;return t.$$click=()=>{let t=dt()===e.branch?null:e.branch;ft(t),n()&&St(n())},P(r,()=>e.branch,null),P(r,()=>e.branch===F().branch?` (current)`:``,null),P(i,()=>e.events,a),y(n=>{var r=`branch-row`+(e.branch===F().branch||e.branch===dt()?` cur`:``),i=e.branch===dt()?`click to show all branches again`:`show only ${e.branch}`;return r!==n.e&&N(t,n.e=r),i!==n.t&&M(t,`title`,n.t=i),n},{e:void 0,t:void 0}),t})()}),Al(),D(k,{get when(){return rt().length>0},get fallback(){return fu()},get children(){return D(O,{get each(){return rt()},children:e=>(()=>{var t=mu(),r=t.firstChild,i=r.firstChild,a=i.nextSibling;a.firstChild;var o=r.nextSibling,s=o.firstChild,c=o.nextSibling;return t.$$click=()=>Et(e.agent),P(i,()=>e.id),P(a,()=>e.agent,null),P(r,D(k,{get when(){return e.forked},get children(){return pu()}}),null),P(o,()=>e.schedule,s),P(o,(()=>{var t=A(()=>!!e.next);return()=>t()?lf(e.next):`—`})(),null),P(o,(()=>{var t=A(()=>!!e.last);return()=>t()?` · last ${lf(e.last)}`:` · never ran`})(),null),P(c,()=>df(e.prompt,90)),y(r=>{var i=`sched-row`+(e.agent===n()?` cur`:``),a=`${df(e.prompt,200)}\nclick to open #${e.agent}`;return i!==r.e&&N(t,r.e=i),a!==r.t&&M(t,`title`,r.t=a),r},{e:void 0,t:void 0}),t})()})}})]}})),y(e=>{var t=`layout`+(re()?``:` right-hidden`),n=`conn`+(Dt()?` ok`:``),r=Dt()?`live (websocket)`:`reconnecting…`,i=`rightbar`+(re()?` open`:``);return t!==e.e&&N(o,e.e=t),n!==e.t&&N(m,e.t=n),r!==e.a&&M(m,`title`,e.a=r),i!==e.o&&N(ne,e.o=i),e},{e:void 0,t:void 0,a:void 0,o:void 0}),o}}),D(k,{get when(){return S()},get children(){return D(mf,{get providers(){return Object.keys(g().providers??{})},onClose:()=>te(!1),onCreated:e=>{te(!1),R(),Et(e)}})}}),D(k,{get when(){return ne()},get children(){return D(bf,{get cfg(){return g()},onClose:()=>w(!1),onSaved:()=>{L(),at()}})}}),D(k,{get when(){return ze()},fallback:null,children:e=>{let t=()=>i().findIndex(t=>t.id===e().eventId),r=()=>Math.max(0,i().length-t()-1),[a,o]=v(r()>0?`summarize`:`discard`);return D(pf,{title:`edit prompt — forks the conversation`,onClose:()=>Be(null),get children(){var t=gu(),i=t.firstChild,s=i.nextSibling,c=s.firstChild;return t.addEventListener(`submit`,async t=>{t.preventDefault();let r=document.getElementById(`edit-text`);try{await $(`/api/agents/${n()}/edit-prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({eventId:e().eventId,text:r.value,tail:a()})}),Be(null),R();let t=n();t&&await Et(t)}catch(e){alert(`edit failed: ${e.message}`)}}),P(t,D(k,{get when(){return r()>0},get children(){var e=hu(),t=e.firstChild,n=t.firstChild,i=t.nextSibling,s=i.firstChild,c=i.nextSibling.firstChild;return P(t,r,n),s.addEventListener(`change`,()=>o(`summarize`)),c.addEventListener(`change`,()=>o(`discard`)),y(()=>s.checked=a()===`summarize`),y(()=>c.checked=a()===`discard`),e}}),s),c.$$click=()=>Be(null),y(()=>i.value=e().text),t}})}})]}function nf(e){let t=new Date(e.startedAt).getTime(),[n,r]=v(Date.now());ee(()=>{let e=setInterval(()=>r(Date.now()),500);C(()=>clearInterval(e))});let i=()=>Math.max(0,(n()-t)/1e3);return(()=>{var e=_u(),t=e.firstChild;return P(e,(()=>{var e=A(()=>i()<60);return()=>e()?`${i().toFixed(1)}s`:`${Math.floor(i()/60)}m ${Math.round(i()%60)}s`})(),t),e})()}function rf(e){let t=e.e,n=e.res,r=!e.agentActive&&!n,i=t.data??{},a=String(i.name??`tool`),o=()=>n?String(n.data?.result??``):``,s=a,c=``,l=(()=>{var e=vu();return P(e,()=>cf(JSON.stringify(i.args??{},null,1),2e3)),e})(),u=e=>String(i.args?.[e]??``),d=(e,t=1500)=>(()=>{var n=yu();return P(n,()=>cf(e,t)),n})(),f=(e=4e3)=>n?[A(()=>d(o(),e)),(()=>{var e=bu(),t=e.firstChild;return P(e,()=>n.data?.durationMs,t),P(e,()=>n.data?.ok===!1?` · FAILED`:``,null),P(e,D(ff,{get text(){return o()}}),null),e})()]:xu();try{switch(a){case`bash`:{let e=u(`command`);s=`$ `+df(e,96);let r=u(`timeout_ms`)?` · timeout ${Math.round(Number(u(`timeout_ms`))/1e3)}s`:``;c=n?`${n.data?.durationMs??`?`}ms${r}`:`running${r}`,l=[A(()=>A(()=>e!==s.slice(2))()?d(e,800):null),A(()=>f(6e3)),!n&&D(nf,{get startedAt(){return t.ts}})];break}case`read_file`:{s=u(`path`)||`(no path)`;let e=[];u(`pattern`)&&e.push(`grep /${df(u(`pattern`),40)}/`),Number(i.args?.offset)<0?e.push(`last ${-Number(i.args.offset)} lines`):i.args?.offset&&e.push(`from L${i.args.offset}`),i.args?.limit&&e.push(`≤${i.args.limit} lines`),c=e.join(` · `),l=f(6e3);break}case`write_file`:{let e=String(i.args?.content??``);s=u(`path`)||`(no path)`,c=`${uf(e.length)} bytes`,l=[A(()=>d(e,1500)),A(()=>A(()=>e.length>1500)()?(()=>{var t=Su(),n=t.firstChild;return P(t,()=>uf(e.length),n),t})():null),n?(()=>{var e=Cu();return P(e,()=>df(o(),160)),e})():wu()];break}case`edit_file`:s=u(`path`)||`(no path)`,c=i.args?.replace_all===!0?`replace all`:`unique spot`,l=[(()=>{var e=Tu();return P(e,()=>cf(`- `+u(`old_text`),900)),e})(),(()=>{var e=Eu();return P(e,()=>`+ `+cf(u(`new_text`),900)),e})(),n?(()=>{var e=Du(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,P(e,()=>df(o(),120),t),P(e,()=>n.data?.durationMs,r),e})():Ou()];break;case`apply_patch`:{let e=u(`patch`).split(`
|
|
26
|
+
`).filter(e=>e&&!/^---$/.test(e.trim())),t=e.map(e=>e.match(/^\*\*\* (?:Add|Update|Delete) File: (.+)$/)?.[1]).filter(Boolean);s=t.length?`${t.length} file${t.length>1?`s`:``}: ${df(t.join(`, `),80)}`:`patch`;let r=e.slice(0,60);l=[(()=>{var t=ku();return P(t,()=>r.map(e=>{let t=e.startsWith(`+`)?` add`:e.startsWith(`-`)?` del`:/^\*\*\*|^@@/.test(e)?` meta`:``;return(()=>{var n=Au();return N(n,`pline`+t),P(n,(()=>{var t=A(()=>e.length>240);return()=>t()?e.slice(0,240)+`…`:e})()),n})()}),null),P(t,(()=>{var t=A(()=>e.length>60);return()=>t()?(()=>{var t=ju(),n=t.firstChild.nextSibling;return n.nextSibling,P(t,()=>e.length-60,n),t})():null})(),null),t})(),n?(()=>{var e=Cu();return P(e,()=>df(o().split(`
|
|
27
|
+
`)[0]??``,140),null),P(e,()=>n.data?.ok===!1?` · FAILED`:``,null),e})():Mu()];break}case`list_dir`:s=u(`path`)||`.`,l=f(4e3);break;case`read_url`:{let e=u(`url`);try{let t=new URL(e);e=t.host+t.pathname}catch{}s=df(e,70),c=`web`,l=[(()=>{var e=Cu();return P(e,D(k,{get when(){return/^https?:/i.test(u(`url`))},get fallback(){return(()=>{var e=Pu();return P(e,()=>df(u(`url`),80)),e})()},get children(){var e=Nu();return y(()=>M(e,`href`,u(`url`))),e}})),e})(),A(()=>f(3e3))];break}case`load_skill`:{s=`skill: ${u(`name`)}`;let e=o().replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,``);l=n?[(()=>{var t=Kc();return y(()=>t.innerHTML=Re(e)),t})(),(()=>{var e=bu(),t=e.firstChild;return P(e,()=>n.data?.durationMs,t),e})()]:Fu();break}case`save_skill`:{s=`skill: ${u(`name`)}`,c=df(u(`description`),60);let e=Array.isArray(i.args?.files)?i.args.files.map(e=>e?.name).filter(Boolean):[];l=[A(()=>A(()=>!!e.length)()?(()=>{var t=Iu();return t.firstChild,P(t,()=>e.join(`, `),null),t})():null),n?(()=>{var e=Du(),t=e.firstChild,r=t.nextSibling;return r.nextSibling,P(e,()=>df(o(),160),t),P(e,()=>n.data?.durationMs,r),e})():Lu()];break}}}catch{}return(()=>{var e=zu(),i=e.firstChild,o=i.firstChild;o.firstChild;var u=o.nextSibling;return M(e,`title`,`${a}${c?` — `+c:``}`),P(o,s,null),P(i,D(k,{get when(){return t.data?.actor},get children(){var e=Ru();return e.firstChild,P(e,()=>String(t.data.actor),null),e}}),u),P(u,n?c||``:r?`(result missed)`:`running…`),P(e,l,null),y(()=>N(e,`embed`+(n?n.data?.ok===!1?` fail`:` done`:r?` done`:` running`))),e})()}function af(e){let t=e.e,n=Xd(t),r=e.prev&&e.prev.type===t.type&&Xd(e.prev).name===n.name&&t.session===e.prev.session&&t.branch===e.prev.branch;if(t.type===`fork`){let e=t.data??{};return(()=>{var n=Bu(),r=n.firstChild.nextSibling;return r.nextSibling,P(n,()=>String(e.fromBranch??`?`),r),P(n,()=>String(e.newBranch??t.branch),null),n})()}if(t.type===`goal`){let e=t.data??{},n=e.event===`status`?`marked ${String(e.status??``)}`:df(String(e.text??``),80);return(()=>{var t=Vu(),r=t.firstChild.nextSibling;return r.nextSibling,P(t,()=>String(e.event??``),r),P(t,n,null),t})()}return t.type===`todo`?(()=>{var e=Hu(),n=e.firstChild.nextSibling;return n.nextSibling,P(e,()=>String(t.data?.by??`human`),n),e})():t.type===`state`?t.data.from===t.data.to?null:(()=>{var e=Uu(),n=e.firstChild;return P(e,()=>t.data.from,n),P(e,()=>t.data.to,null),P(e,(()=>{var e=A(()=>!!t.data.reason);return()=>e()?` — ${t.data.reason}`:``})(),null),y(()=>N(e,`divider-msg`+(t.data.to===`error`?` err`:``))),e})():(()=>{var i=qu(),a=i.firstChild;return P(i,D(k,{when:!r,get fallback(){return Ju()},get children(){var e=Wu();return P(e,()=>n.icon),y(t=>{var r=n.color+`33`,i=`1px solid ${n.color}66`;return r!==t.e&&ke(e,`background`,t.e=r),i!==t.t&&ke(e,`border`,t.t=i),t},{e:void 0,t:void 0}),e}}),a),P(a,D(k,{when:!r,get children(){var r=Ku(),i=r.firstChild,a=i.nextSibling,o=a.nextSibling;return P(i,()=>n.name),P(r,D(k,{get when(){return t.data?.actor},get children(){var e=Ru();return e.firstChild,P(e,()=>String(t.data.actor),null),e}}),a),P(a,(()=>{var e=A(()=>!!t.data?.pending);return()=>e()?`pending…`:Qd(t.ts)})()),P(o,()=>t.branch),P(r,D(k,{get when(){return e.onEdit},get children(){var t=Gu();return t.$$click=t=>{t.stopPropagation(),e.onEdit()},t}}),null),y(e=>ke(i,`color`,n.color)),r}}),null),P(a,D(sf,{e:t,get res(){return e.res},get onOption(){return e.onOption},get answeredIds(){return e.answeredIds},get agentActive(){return e.agentActive}}),null),y(()=>N(i,`msg`+(r?` grouped`:``)+(t.data?.pending?` pending`:``))),i})()}function of(e){let[t,n]=v(``),r=()=>{let r=t().trim();!r||e.answered||(n(``),e.onOption?.(r))};return(()=>{var i=Yu(),a=i.firstChild,o=a.nextSibling;return a.$$keydown=e=>{e.key===`Enter`&&(e.preventDefault(),r())},a.$$input=e=>n(e.currentTarget.value),o.$$click=r,y(n=>{var r=e.answered?`answered`:`or type your own answer…`,i=e.answered,s=e.answered||!t().trim();return r!==n.e&&M(a,`placeholder`,n.e=r),i!==n.t&&(a.disabled=n.t=i),s!==n.a&&(o.disabled=n.a=s),n},{e:void 0,t:void 0,a:void 0}),y(()=>a.value=t()),i})()}function sf(e){let t=e.e;switch(t.type){case`prompt`:return(()=>{var e=Kc();return y(()=>e.innerHTML=Hd(String(t.data.text??``))),e})();case`message`:return[D(k,{get when(){return A(()=>typeof t.data.reasoning==`string`)()&&t.data.reasoning.trim()},get children(){var e=Gc(),n=e.firstChild;n.firstChild;var r=n.nextSibling;return P(n,(()=>{var e=A(()=>String(t.data.reasoning).length>4e3);return()=>e()?` (${uf(String(t.data.reasoning).length)} — truncated)`:``})(),null),P(r,()=>cf(String(t.data.reasoning),8e3)),e}}),(()=>{var e=Kc();return y(()=>e.innerHTML=Hd(String(t.data.content??``))),e})(),D(k,{get when(){return t.data.interrupted},get children(){return Xu()}}),D(k,{get when(){return t.data.final},get children(){var e=Zu(),n=e.firstChild;return P(e,D(ff,{get text(){return String(t.data.content??``)}}),n),e}})];case`tool_call`:return D(rf,{e:t,get res(){return e.res},get agentActive(){return e.agentActive}});case`tool_result`:{let e=String(t.data.result);return(()=>{var n=Qu(),r=n.firstChild,i=r.firstChild,a=r.nextSibling,o=a.nextSibling,s=o.firstChild;return P(i,()=>df(e,120)),P(r,D(ff,{text:e}),null),P(a,()=>cf(e,4e3)),P(o,()=>t.data.durationMs,s),P(o,()=>t.data.ok?``:` · FAILED`,null),y(()=>N(n,`embed`+(t.data.ok?``:` fail`))),n})()}case`decision`:{let e=Array.isArray(t.data?.alternatives)?t.data.alternatives:[];return(()=>{var n=ed(),r=n.firstChild,i=r.firstChild.firstChild.nextSibling,a=r.nextSibling;return P(n,D(k,{get when(){return e.length},get children(){var t=$u();return t.firstChild,P(t,()=>e.join(` / `),null),t}}),null),y(e=>{var n=Hd(String(t.data?.decision??``)),r=Hd(String(t.data?.rationale??``));return n!==e.e&&(i.innerHTML=e.e=n),r!==e.t&&(a.innerHTML=e.t=r),e},{e:void 0,t:void 0}),n})()}case`question`:{let n=Array.isArray(t.data?.options)?t.data.options:[],r=t.data?.callId?String(t.data.callId):``,i=e.answeredIds?.has(r)??!1;return(()=>{var r=rd(),a=r.firstChild;return a.firstChild,N(r,`embed question`+(i?` answered`:``)),P(a,()=>String(t.data?.question??``),null),P(r,D(k,{when:i,get children(){return td()}}),null),P(r,D(k,{get when(){return n.length>0},get children(){var r=nd();return P(r,D(O,{each:n,children:n=>(()=>{var r=id();return r.$$click=()=>{let r=t.data?.actor;r?$(`/api/agents/${encodeURIComponent(String(r))}/prompt`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({text:n,start:!0})}).then(()=>Q(`→ answered @${String(t.data.actor)}`)).catch(()=>Q(`answer failed`)):e.onOption?.(n)},r.disabled=i,P(r,n),r})()})),r}}),null),P(r,D(of,{answered:i,get onOption(){return e.onOption}}),null),r})()}case`progress`:return(()=>{var e=ad(),n=e.firstChild.firstChild.nextSibling;return P(e,D(k,{get when(){return t.data.goalStatus},get children(){var e=iu(),n=e.firstChild.nextSibling;return P(n,()=>String(t.data.goalStatus)),e}}),null),P(e,D(k,{get when(){return t.data.recent},get children(){var e=tu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(String(t.data.recent))),e}}),null),P(e,D(k,{get when(){return t.data.problems},get children(){var e=nu(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(String(t.data.problems))),e}}),null),P(e,D(k,{get when(){return t.data.next},get children(){var e=ru(),n=e.firstChild.nextSibling;return y(()=>n.innerHTML=Hd(String(t.data.next))),e}}),null),y(()=>n.innerHTML=Hd(String(t.data.doing??``))),e})();case`error`:return(()=>{var e=od(),n=e.firstChild;return n.firstChild,P(n,()=>String(t.data.message??``),null),e})();default:return(()=>{var e=sd();return P(e,()=>cf(JSON.stringify(t.data),200)),e})()}}function cf(e,t){return e.length>t?e.slice(0,t)+` …`:e}function lf(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 uf(e){return e>=1e9?`${+(e/1e9).toFixed(1)}b`:e>=1e6?`${+(e/1e6).toFixed(1)}m`:e>=1e4?`${Math.round(e/1e3)}k`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function df(e,t){return cf(e.replace(/\s+/g,` `).trim(),t)}function ff(e){let[t,n]=v(!1);return(()=>{var r=cd();return r.$$click=t=>{t.stopPropagation(),navigator.clipboard.writeText(e.text).then(()=>{n(!0),setTimeout(()=>n(!1),900)})},P(r,()=>t()?`✓`:`⧉`),r})()}function pf(e){return(()=>{var t=ld(),n=t.firstChild,r=n.firstChild.firstChild,i=r.nextSibling;return t.$$click=t=>t.target===t.currentTarget&&e.onClose(),P(r,()=>e.title),De(i,`click`,e.onClose,!0),P(n,()=>e.children,null),t})()}function mf(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 t=await $(`/api/fs${e?`?path=${encodeURIComponent(e)}`:``}`);n(t.path),i(t.entries)}ee(()=>p(t()));let m=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 D(pf,{title:`new agent`,get onClose(){return e.onClose},get children(){var i=dd(),f=i.firstChild,h=f.firstChild.nextSibling.firstChild,g=h.nextSibling,_=g.nextSibling,v=f.nextSibling,b=v.nextSibling,x=b.firstChild,S=x.firstChild.nextSibling,ee=x.nextSibling,C=ee.firstChild.nextSibling,te=ee.nextSibling.firstChild.nextSibling,ne=b.nextSibling;return i.addEventListener(`submit`,m),h.$$input=e=>n(e.currentTarget.value),g.$$click=()=>p(t()),_.$$click=()=>p(`..`),P(v,D(O,{get each(){return r()},children:e=>(()=>{var n=fd();return n.firstChild,n.$$click=()=>p(`${t()}/${e}`.replace(/\/+/g,`/`)),P(n,e,null),n})()})),S.$$input=e=>o(e.currentTarget.value),C.addEventListener(`change`,e=>c(e.currentTarget.value)),P(C,D(O,{get each(){return e.providers},children:e=>(()=>{var t=Bl();return P(t,e),t})()})),te.$$input=e=>u(e.currentTarget.value),P(i,D(k,{get when(){return d()},get children(){var e=ud();return P(e,d),e}}),ne),y(()=>h.value=t()),y(()=>S.value=a()),y(()=>C.value=s()),y(()=>te.value=l()),i}})}function hf(e){let[t,n]=v(new Map),[r,i]=v(new Set),[a,o]=v(null),[s,c]=v(``),l=(e,t)=>t.map(t=>({name:String(t.name),path:e?`${e}/${t.name}`:String(t.name),dir:!!t.dir,...typeof t.size==`number`?{size:t.size}:{}}));async function u(t){try{let n=await $(`/api/agents/${e.agentId}/tree${t?`?path=${encodeURIComponent(t)}`:``}`);return l(t,n.entries??[])}catch(e){return c(e.message),null}}b(()=>{e.agentId,i(new Set),n(new Map),u(``).then(e=>{e&&n(new Map([[``,e]]))})});let d=async e=>{let a=new Set(r());if(a.has(e.path)){a.delete(e.path),i(a);return}if(a.add(e.path),i(a),!t().has(e.path)){let t=await u(e.path);t&&n(n=>new Map(n).set(e.path,t))}},[f,p]=v(``),[m,h]=v(!1),[g,_]=v(`code`),[x,S]=v(``),[ee,te]=v(!1),ne=e=>/\.(md|markdown|mdx)$/i.test(e),w=0,re=async e=>{let t=++w;p(``),h(!0);try{let{highlightChunks:n}=await Pc(async()=>{let{highlightChunks:e}=await import(`./shiki-CE_hx8wa.js`);return{highlightChunks:e}},[]);for await(let r of n(e.path,e.content)){if(w!==t)return;p(e=>e+r)}}catch{w===t&&p(``)}finally{w===t&&h(!1)}};C(()=>{w++});let T=async(t,n)=>{try{let r=await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`);o({path:t.path,content:r.content??``,binary:r.binary,truncated:r.truncated}),S(r.content??``),_(r.binary?`code`:n),!r.binary&&n!==`md`&&re({path:t.path,content:r.content??``,truncated:r.truncated})}catch(e){Q(`open failed: ${e.message}`)}},ie=async()=>{let t=a();if(!(!t||ee())){te(!0);try{await $(`/api/agents/${e.agentId}/file?path=${encodeURIComponent(t.path)}`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({content:x(),baseContent:t.content})}),o({...t,content:x()}),Q(`saved ${t.path}`)}catch(e){let t=e.message;t.includes(`409`)||t.includes(`changed on disk`)?Q(`file changed on disk — reopen to see the current version`):Q(`save failed: ${t}`)}finally{te(!1)}}},ae=e=>!e.binary&&!e.truncated,oe=(e,n)=>[(()=>{var t=md(),i=t.firstChild,a=i.nextSibling;return t.$$click=()=>e.dir?void d(e):void T(e,`code`),P(i,(()=>{var t=A(()=>!!e.dir);return()=>t()?r().has(e.path)?`▾`:`▸`:`·`})()),P(a,()=>e.name),P(t,D(k,{get when(){return A(()=>!e.dir)()&&e.size!==void 0},get children(){var t=pd();return P(t,()=>uf(e.size)),t}}),null),y(r=>{var i=`filerow`+(e.dir?` isdir`:``),a=`padding-left:${n*13+8}px`,o=e.dir?`browse ${e.path}`:`preview ${e.path}`;return i!==r.e&&N(t,r.e=i),r.t=Oe(t,a,r.t),o!==r.a&&M(t,`title`,r.a=o),r},{e:void 0,t:void 0,a:void 0}),t})(),D(k,{get when(){return A(()=>!!e.dir)()&&r().has(e.path)},get children(){return D(O,{get each(){return t().get(e.path)??[]},children:e=>oe(e,n+1)})}})],E=()=>e.workspace.split(`/`).filter(Boolean).pop()??e.workspace;return[(()=>{var e=hd(),t=e.firstChild.nextSibling;return t.firstChild,P(t,E,null),e})(),(()=>{var e=gd();return P(e,D(k,{get when(){return(t().get(``)??[]).length>0},get fallback(){return(()=>{var e=_d();return P(e,()=>s()||`empty workspace`),e})()},get children(){return D(O,{get each(){return t().get(``)??[]},children:e=>oe(e,0)})}})),e})(),D(k,{get when(){return a()},children:e=>D(pf,{get title(){return`🗂 ${e().path}`},onClose:()=>{w++,o(null)},get children(){return[(()=>{var t=bd(),n=t.firstChild;return P(t,D(k,{get when(){return A(()=>!!ne(e().path))()&&!e().binary},get children(){var e=vd();return e.$$click=()=>_(`md`),y(()=>N(e,g()===`md`?`on`:``)),e}}),n),n.$$click=()=>{_(`code`),f()||re({path:e().path,content:e().content,truncated:e().truncated})},P(t,D(k,{get when(){return ae(e())},get children(){var e=yd();return e.$$click=()=>_(`edit`),y(()=>N(e,g()===`edit`?`on`:``)),e}}),null),y(()=>N(n,g()===`code`?`on`:``)),t})(),D(k,{get when(){return!e().binary},get fallback(){return Sd()},get children(){return D(k,{get when(){return g()===`edit`},get fallback(){return D(k,{get when(){return A(()=>g()===`md`)()&&ne(e().path)},get fallback(){return D(gf,{get path(){return e().path},get content(){return e().content},get html(){return f()},get pending(){return m()},get truncated(){return!!e().truncated}})},get children(){var t=Cd();return y(()=>t.innerHTML=Re(e().content)),t}})},get children(){var t=xd(),n=t.firstChild,r=n.nextSibling.firstChild,i=r.firstChild,a=r.nextSibling;return n.$$input=e=>S(e.currentTarget.value),M(n,`spellcheck`,!1),P(r,()=>uf(x().length),i),a.$$click=()=>void ie(),P(a,()=>ee()?`saving…`:`💾 save`),y(()=>a.disabled=ee()||x()===e().content),y(()=>n.value=x()),t}})}})]}})})]}function gf(e){return[D(k,{get when(){return e.html},get fallback(){return A(()=>!!e.pending)()?(()=>{var t=Ed(),n=t.firstChild.nextSibling;return n.nextSibling,P(t,()=>e.path.split(`/`).pop(),n),t})():(()=>{var t=Dd();return P(t,()=>e.content),t})()},get children(){var t=wd();return y(()=>t.innerHTML=e.html),t}}),D(k,{get when(){return e.truncated},get children(){return Td()}})]}var _f=[{key:`openrouter`,label:`OpenRouter`,url:`https://openrouter.ai/api/v1`,model:`anthropic/claude-sonnet-4`,hint:`400+ models behind one key — teapot sends app-attribution headers automatically`},{key:`orcarouter`,label:`OrcaRouter`,url:`https://api.orcarouter.ai/v1`,model:`orcarouter/auto`,hint:`zero-markup routing gateway — 'orcarouter/auto' grades each prompt and picks the model`},{key:`openai`,label:`OpenAI`,url:`https://api.openai.com/v1`,model:`gpt-4o-mini`},{key:`llamacpp`,label:`llama.cpp server`,url:`http://localhost:8080/v1`,model:``,hint:`free & local — start it with: llama-server -m ./model.gguf (any model name works)`}],vf={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 yf(e){let[t,n]=v(_f[0]),[r,i]=v(_f[0].url),[a,o]=v(``),[s,c]=v(_f[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 ${uf(t.contextLength)} tok`);let r=e=>e===void 0?``:`$${e*1e6>=10?Math.round(e*1e6):+(e*1e6).toFixed(1)}/M`;if(t.pricing){let e=r(t.pricing.prompt),i=r(t.pricing.completion);e&&i?n.push(`${e} in · ${i} out`):(e||i)&&n.push(r(t.pricing.prompt??t.pricing.completion))}return n.join(` · `)},te=()=>ee(s()),ne=async t=>{t.preventDefault(),x(``),g(!0);try{await $(`/api/setup`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({baseUrl:r(),apiKey:a()||void 0,model:s(),workspace:d(),...p()?{password:p()}:{}})}),e.onDone()}catch(e){x(e.message),g(!1)}};return(()=>{var e=jd(),n=e.firstChild.firstChild.nextSibling.nextSibling,u=n.firstChild,g=u.nextSibling,v=g.firstChild.nextSibling,b=v.nextSibling,x=g.nextSibling,ee=x.firstChild.nextSibling,C=x.nextSibling,w=C.firstChild.nextSibling,re=w.nextSibling,T=C.nextSibling,ie=T.firstChild.nextSibling,ae=ie.firstChild.nextSibling,oe=ie.nextSibling.firstChild.nextSibling,E=T.nextSibling;return n.addEventListener(`submit`,ne),P(u,()=>[..._f,vf].map(e=>(()=>{var n=Md();return n.$$click=()=>S(e),P(n,()=>e.label),y(r=>{var i=`presetbtn`+(t().key===e.key?` active`:``),a=e.hint||e.url;return i!==r.e&&N(n,r.e=i),a!==r.t&&M(n,`title`,r.t=a),r},{e:void 0,t:void 0}),n})())),P(n,D(k,{get when(){return t().hint},get children(){var e=Od();return P(e,()=>t().hint),e}}),g),v.$$input=e=>i(e.currentTarget.value),P(b,()=>_f.map(e=>(()=>{var t=Bl();return y(()=>t.value=e.url),t})())),ee.$$input=e=>o(e.currentTarget.value),w.$$input=e=>c(e.currentTarget.value),P(re,()=>l().map(e=>(()=>{var t=Bl();return y(()=>t.value=e.id),t})())),P(n,D(k,{get when(){return l().length>0},get fallback(){return Nd()},get children(){var e=Ad(),t=e.firstChild;return P(e,()=>l().length,t),P(e,D(k,{get when(){return te()},get children(){return[` · `,(()=>{var e=kd();return P(e,te),e})()]}}),null),e}}),T),ae.$$input=e=>f(e.currentTarget.value),oe.$$input=e=>m(e.currentTarget.value),P(n,D(k,{get when(){return _()},get children(){var e=ud();return P(e,_),e}}),E),P(E,()=>h()?`saving…`:`finish setup`),y(e=>{var n=t().key===`llamacpp`?`(any name — serves whichever gguf is loaded)`:`(type to filter models from the endpoint)`,r=h();return n!==e.e&&M(w,`placeholder`,e.e=n),r!==e.t&&(E.disabled=e.t=r),e},{e:void 0,t:void 0}),y(()=>v.value=r()),y(()=>ee.value=a()),y(()=>w.value=s()),y(()=>ae.value=d()),y(()=>oe.value=p()),e})()}function bf(e){let[t,n]=v(Object.entries(e.cfg.providers??{}).map(([e,t])=>({name:e,baseUrl:t.baseUrl??``,apiKey:t.apiKey??``,model:t.model??``}))),[r,i]=v(e.cfg.defaultProvider??``),[a,o]=v(Math.round((e.cfg.progressIntervalMs??6e5)/6e4)),[s,c]=v(e.cfg.progressMinChars??4e3),[l,u]=v(Math.round((e.cfg.contextTokenBudget??96e3)/1e3)),[d,f]=v(e.cfg.contextWindowTokens?Math.round(e.cfg.contextWindowTokens/1e3):0),[p,m]=v(e.cfg.maxSpawnDepth??3),[h,g]=v((e.cfg.tasks??[]).map(e=>({...e}))),[_,b]=v(``),x=()=>(e.cfg.agents??[]).map(e=>e.id),S=()=>{let e={};for(let n of t()){if(!n.name.trim())return b(`provider name is required`),null;if(n.baseUrl&&!/^https?:\/\//.test(n.baseUrl))return b(`provider ${n.name}: baseUrl must start with http(s)://`),null;e[n.name.trim()]={baseUrl:n.baseUrl,...n.apiKey?{apiKey:n.apiKey}:{},...n.model?{model:n.model}:{}}}return e},ee=async t=>{t.preventDefault(),b(``);let n=S();if(!n)return;let i=h().filter(e=>e.id?.trim()||e.prompt?.trim()).map((e,t)=>({id:e.id?.trim()||`task-${t+1}`,agent:e.agent,schedule:e.schedule,prompt:e.prompt,...e.forked?{forked:!0}:{}}));for(let e of i){if(!e.agent){b(`task "${e.id}": agent is required`);return}if(!e.schedule?.trim()){b(`task "${e.id}": schedule is required`);return}}try{await $(`/api/config`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({providers:n,defaultProvider:r()||void 0,progressIntervalMs:Math.max(1,a())*6e4,progressMinChars:Math.max(100,s()),contextTokenBudget:Math.max(1e3,l())*1e3,...d()>0?{contextWindowTokens:d()*1e3}:{},maxSpawnDepth:Math.max(0,p()),tasks:i})}),e.onSaved(),e.onClose()}catch(e){b(e.message)}},C=(e,t,n,r)=>(()=>{var i=Pd(),a=i.firstChild;return M(i,`title`,r),P(i,e,a),a.$$input=e=>n(Number(e.currentTarget.value)),a.value=t,i})();return D(pf,{title:`settings`,get onClose(){return e.onClose},get children(){var v=Fd(),b=v.firstChild,S=b.firstChild.nextSibling,te=S.nextSibling;te.firstChild;var ne=te.nextSibling.firstChild.firstChild.nextSibling;ne.firstChild;var w=b.nextSibling,re=w.firstChild.nextSibling,T=w.nextSibling,ie=T.firstChild.nextSibling,ae=T.nextSibling;ae.firstChild;var oe=ae.nextSibling;return v.addEventListener(`submit`,ee),P(b,D(O,{get each(){return t()},children:(e,r)=>(()=>{var i=Id(),a=i.firstChild,o=a.nextSibling,s=o.nextSibling,c=s.nextSibling,l=c.nextSibling;return a.$$input=e=>n(t().map((t,n)=>n===r()?{...t,name:e.currentTarget.value}:t)),o.$$input=e=>n(t().map((t,n)=>n===r()?{...t,baseUrl:e.currentTarget.value}:t)),s.$$input=e=>n(t().map((t,n)=>n===r()?{...t,apiKey:e.currentTarget.value}:t)),c.$$input=e=>n(t().map((t,n)=>n===r()?{...t,model:e.currentTarget.value}:t)),l.$$click=()=>n(t().filter((e,t)=>t!==r())),y(()=>a.value=e.name),y(()=>o.value=e.baseUrl),y(()=>s.value=e.apiKey),y(()=>c.value=e.model),i})()}),S),S.$$click=()=>n([...t(),{name:``,baseUrl:``,apiKey:``,model:``}]),P(te,D(O,{each:_f,children:e=>(()=>{var a=Ld();return a.firstChild,a.$$click=()=>{let a=t().filter(t=>t.name!==e.key);n([...a,{name:e.key,baseUrl:e.url,apiKey:``,model:e.model}]),r()||i(e.key)},P(a,()=>e.label,null),y(()=>M(a,`title`,`fill a ${e.label} row — ${e.url}${e.model?` (model: ${e.model})`:``}`)),a})()}),null),ne.addEventListener(`change`,e=>i(e.currentTarget.value)),P(ne,D(O,{get each(){return[...new Set(t().map(e=>e.name.trim()).filter(Boolean))]},children:e=>(()=>{var t=Bl();return t.value=e,P(t,e),t})()}),null),P(re,()=>C(`progress interval (min)`,a(),e=>o(e),`how often the harness asks for a progress report`),null),P(re,()=>C(`progress min chars`,s(),e=>c(e),`progress prompts wait for this much real output`),null),P(re,()=>C(`compact budget (k tok)`,l(),e=>u(e),`auto-compact threshold — defaults to 75% of context window when empty; manual override in k tokens`),null),P(re,()=>C(`context window (k tok)`,d(),e=>f(e),`model's real window — 0/blank hides the % gauge`),null),P(re,()=>C(`max spawn depth`,p(),e=>m(e),`sub-agent nesting limit (0 = no spawning)`),null),P(T,D(k,{get when(){return h().length>0},get children(){return D(O,{get each(){return h()},children:(e,t)=>(()=>{var n=Rd(),r=n.firstChild,i=r.firstChild,a=i.nextSibling,o=a.nextSibling,s=o.nextSibling,c=s.firstChild,l=s.nextSibling,u=r.nextSibling;return i.$$input=e=>g(h().map((n,r)=>r===t()?{...n,id:e.currentTarget.value}:n)),a.$$input=e=>g(h().map((n,r)=>r===t()?{...n,agent:e.currentTarget.value}:n)),o.$$input=e=>g(h().map((n,r)=>r===t()?{...n,schedule:e.currentTarget.value}:n)),c.addEventListener(`change`,e=>g(h().map((n,r)=>r===t()?{...n,forked:e.currentTarget.checked}:n))),l.$$click=()=>g(h().filter((e,n)=>n!==t())),u.$$input=e=>g(h().map((n,r)=>r===t()?{...n,prompt:e.currentTarget.value}:n)),y(()=>i.value=e.id),y(()=>a.value=e.agent),y(()=>o.value=e.schedule),y(()=>c.checked=!!e.forked),y(()=>u.value=e.prompt),n})()})}}),ie),ie.$$click=()=>g([...h(),{id:``,agent:x()[0]??``,schedule:`every 30m`,prompt:``}]),P(ae,D(O,{get each(){return e.cfg.agents??[]},children:e=>(()=>{var t=Bd(),n=t.firstChild,r=n.nextSibling;return P(n,()=>e.id),P(r,()=>e.workspace),P(t,D(k,{get when(){return e.parent},get children(){var t=zd();return t.firstChild,P(t,()=>e.parent,null),t}}),null),t})()}),null),P(v,D(k,{get when(){return _()},get children(){var e=ud();return P(e,_),e}}),oe),y(()=>ne.value=r()),v}})}Ee([`click`,`pointerdown`,`dblclick`,`input`,`keydown`]),Te(()=>D(tf,{}),document.getElementById(`root`));export{Pc as t};
|
|
28
|
+
//# sourceMappingURL=index-C_ZXWWW5.js.map
|