@wrongstack/webui 0.155.0 → 0.236.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/codicon-ngg6Pgfi.ttf +0 -0
- package/dist/assets/css.worker-CvXBzhp8.js +89 -0
- package/dist/assets/html.worker-BO6WuOEO.js +502 -0
- package/dist/assets/index-Cm_R0cfw.css +2 -0
- package/dist/assets/index-DIwGHhP2.js +163 -0
- package/dist/assets/json.worker-BkJRGcCJ.js +58 -0
- package/dist/assets/ts.worker-B0J26iPs.js +67734 -0
- package/dist/assets/vendor-BtOIO1oa.js +1303 -0
- package/dist/assets/vendor-CEQg2uSG.css +1 -0
- package/dist/index.css +103 -0
- package/dist/index.css.map +1 -0
- package/dist/index.html +4 -4
- package/dist/index.js +11132 -4801
- package/dist/index.js.map +1 -1
- package/dist/server/entry.js +1740 -201
- package/dist/server/entry.js.map +1 -1
- package/dist/server/index.d.ts +170 -2
- package/dist/server/index.js +1738 -200
- package/dist/server/index.js.map +1 -1
- package/package.json +35 -30
- package/dist/assets/index-BFp_MWOB.css +0 -2
- package/dist/assets/index-CrAP_pW-.js +0 -93
- package/dist/assets/vendor-C1_detLm.js +0 -81
- package/dist/assets/vendor-XkZLp0g1.css +0 -1
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{$ as t,$n as n,$t as r,A as i,An as a,At as o,B as s,Bn as c,Bt as l,C as u,Cn as d,Ct as f,D as p,Dn as m,Dt as h,E as g,En as _,Et as v,F as y,Fn as b,Ft as x,G as S,Gn as C,Gt as w,H as T,Hn as E,Ht as D,I as O,In as k,It as A,J as j,Jn as M,Jt as N,K as ee,Kn as te,Kt as P,L as ne,Ln as re,Lt as ie,M as ae,Mn as oe,Mt as se,N as ce,Nn as F,Nt as le,O as ue,On as de,Ot as fe,P as pe,Pn as me,Pt as he,Q as ge,Qn as _e,Qt as ve,R as ye,Rn as be,Rt as xe,S as Se,Sn as Ce,St as we,T as Te,Tn as Ee,Tt as De,U as Oe,Un as ke,Ut as Ae,V as je,Vn as Me,Vt as Ne,W as Pe,Wn as Fe,Wt as Ie,X as Le,Xn as Re,Xt as ze,Y as Be,Yn as Ve,Yt as He,Z as Ue,Zn as We,Zt as Ge,_ as Ke,_n as qe,_t as Je,a as Ye,an as Xe,at as Ze,b as Qe,bn as $e,bt as et,c as tt,cn as nt,ct as rt,d as it,dn as at,dt as ot,en as st,er as ct,et as lt,f as ut,fn as dt,ft,g as pt,gn as mt,gt as ht,h as gt,hn as _t,ht as vt,i as yt,in as bt,it as xt,j as St,jn as Ct,jt as wt,k as Tt,kn as Et,kt as Dt,l as Ot,ln as kt,lt as At,m as jt,mn as I,mt as Mt,n as Nt,nn as Pt,nt as Ft,o as It,on as Lt,ot as Rt,p as zt,pn as Bt,pt as Vt,q as Ht,qn as Ut,qt as Wt,r as Gt,rn as Kt,rt as qt,s as Jt,sn as Yt,st as Xt,t as Zt,tn as Qt,tr as $t,tt as en,u as tn,un as nn,ut as rn,v as an,vn as on,vt as sn,w as cn,wn as ln,wt as un,x as dn,xn as fn,xt as pn,y as mn,yn as hn,yt as gn,z as L,zn as _n,zt as vn}from"./vendor-BtOIO1oa.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();function R(e,t){if(e==null){let e=Error(t?`Expected ${t} to be defined`:`Expected value to be defined`);throw e.name=`ExpectDefinedError`,e}return e}function yn(e,t){let n=e=>e.trim().replace(/\s+/g,` `).toLowerCase();return n(e)===n(t)}var z=e($t(),1),bn=e(ct(),1),xn=`#4f46e5`;function Sn(e){return`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
|
2
|
+
<rect x="2" y="2" width="60" height="60" rx="14" fill="${xn}" />
|
|
3
|
+
<text x="32" y="44" text-anchor="middle" font-family="-apple-system,Segoe UI,Roboto,sans-serif" font-size="38" font-weight="700" fill="#fff">W</text>
|
|
4
|
+
${e===`ready`?`<circle cx="50" cy="14" r="14" fill="#22c55e" stroke="#fff" stroke-width="3" />`:e===`error`?`<circle cx="50" cy="14" r="14" fill="#ef4444" stroke="#fff" stroke-width="3" />`:e===`running`?`<circle cx="50" cy="14" r="14" fill="#f59e0b" stroke="#fff" stroke-width="3" />`:e===`attention`?`<circle cx="50" cy="14" r="14" fill="#eab308" stroke="#fff" stroke-width="3"><animate attributeName="opacity" values="1;0.3;1" dur="1s" repeatCount="indefinite"/></circle>`:``}
|
|
5
|
+
</svg>`}function Cn(e){return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`}function wn(){if(typeof document>`u`)return null;let e=document.querySelector(`link[rel="icon"]`);return e||(e=document.createElement(`link`),e.rel=`icon`,e.type=`image/svg+xml`,document.head.appendChild(e)),e}var Tn=`idle`;function En(e){Tn=e;let t=wn();t&&(t.href=Cn(Sn(e)))}var Dn=!1;function On(){Dn||typeof document>`u`||(Dn=!0,document.addEventListener(`visibilitychange`,()=>{!document.hidden&&(Tn===`ready`||Tn===`error`||Tn===`attention`)&&En(`idle`)}))}var kn=`ws_token`;function An(){try{return sessionStorage.getItem(kn)}catch{return null}}function jn(e){try{sessionStorage.setItem(kn,e)}catch{}}function Mn(){try{sessionStorage.removeItem(kn)}catch{}}var Nn=class{ws=null;url;handlers=new Map;reconnectAttempts=0;maxReconnectAttempts=10;reconnectDelay=1e3;shouldReconnect=!0;reconnectTimer=null;messageQueue=[];pendingConfirms=new Map;sessionId=null;lastErrorText;statusListeners=new Set;currentStatus={state:`connecting`};onStatus(e){return this.statusListeners.add(e),e(this.currentStatus),()=>this.statusListeners.delete(e)}get status(){return this.currentStatus}setStatus(e){this.currentStatus=e;for(let t of this.statusListeners)try{t(e)}catch{}}constructor(e){this.url=e??Ln()}async connect(){return new Promise((e,t)=>{if(this.ws?.readyState===WebSocket.OPEN){e();return}this.setStatus({state:`connecting`});try{let n=An(),r=n?`${this.url}${this.url.includes(`?`)?`&`:`?`}token=${n}`:this.url;this.ws=new WebSocket(r),this.ws.binaryType=`arraybuffer`;let i=setTimeout(()=>{t(Error(`Connection timeout`))},1e4),a=!1;this.ws.onopen=()=>{clearTimeout(i),a=!0,this.reconnectAttempts=0,this.lastErrorText=void 0,this.setStatus({state:`open`}),this.flushMessageQueue(),e()},this.ws.onmessage=e=>{try{let t=JSON.parse(e.data);this.handleMessage(t)}catch(e){console.error(JSON.stringify({level:`error`,event:`ws_client.message_parse_failed`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))}},this.ws.onerror=e=>{console.error(JSON.stringify({level:`error`,event:`ws_client.error`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()})),this.lastErrorText=`Connection error (see browser devtools)`,a||(clearTimeout(i),t(Error(this.lastErrorText)))},this.ws.onclose=e=>{if(!a){clearTimeout(i);let n=e.reason||`Closed with code ${e.code}`;this.lastErrorText=n,t(Error(n));return}e.reason&&!this.lastErrorText?this.lastErrorText=`${e.reason} (code ${e.code})`:!this.lastErrorText&&e.code!==1e3&&(this.lastErrorText=`Closed with code ${e.code}`),this.attemptReconnect()}}catch(e){this.lastErrorText=e instanceof Error?e.message:String(e),this.setStatus({state:`closed`,error:this.lastErrorText}),t(e)}})}attemptReconnect(){if(!this.shouldReconnect||this.reconnectAttempts>=this.maxReconnectAttempts){this.reconnectTimer=null,this.setStatus({state:`closed`,error:this.lastErrorText??`Disconnected`});return}this.reconnectAttempts++;let e=Math.min(this.reconnectDelay*2**(this.reconnectAttempts-1),3e4),t=Date.now()+e;this.setStatus({state:`reconnecting`,attempt:this.reconnectAttempts,nextRetryAt:t,lastError:this.lastErrorText}),this.reconnectTimer=setTimeout(async()=>{if(this.shouldReconnect)try{await this.connect()}catch(e){console.error(JSON.stringify({level:`error`,event:`ws_client.reconnect_failed`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))}},e)}retryNow(){this.currentStatus.state!==`open`&&(this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null),this.reconnectAttempts=0,this.connect().catch(e=>console.warn(JSON.stringify({level:`warn`,event:`ws_client.reconnect_failed`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))))}flushMessageQueue(){for(;this.messageQueue.length>0;){let e=this.messageQueue.shift();e&&this.send(e)}}handleMessage(e){if(e.type===`tool.confirm_needed`){let t=e.payload;this.pendingConfirms.set(t.id,{resolve:t.resolve});let n={...e,payload:{...t,resolve:()=>{}}};this.emit(n);return}if(e.type===`session.start`){let t=e.payload;this.sessionId=t.sessionId,t.wsToken&&jn(t.wsToken)}this.emit(e)}emit(e){let t=this.handlers.get(e.type);if(t)for(let n of t)try{n(e)}catch(t){console.error(JSON.stringify({level:`error`,event:`ws_client.handler_error`,messageType:e.type,message:t instanceof Error?t.message:String(t),timestamp:new Date().toISOString()}))}}send(e){this.ws?.readyState===WebSocket.OPEN?this.ws.send(JSON.stringify(e)):this.messageQueue.push(e)}on(e,t){let n=this.handlers.get(e);return n||(n=new Set,this.handlers.set(e,n)),n.add(t),()=>n?.delete(t)}off(e,t){this.handlers.get(e)?.delete(t)}sendMessage(e){let t=`msg_${Date.now()}_${crypto.randomUUID().slice(0,8)}`;return this.send({type:`user_message`,payload:{id:t,content:e,timestamp:Date.now()}}),t}sendAbort(){this.send({type:`abort`,payload:{}})}sendConfirm(e,t){let n=this.pendingConfirms.get(e);n&&(n.resolve(t),this.pendingConfirms.delete(e)),this.send({type:`tool.confirm_result`,payload:{id:e,decision:t}})}switchModel(e,t){this.send({type:`model.switch`,payload:{provider:e,model:t}})}newSession(){this.send({type:`session.new`})}listProviders(){this.send({type:`providers.list`})}listProviderModels(e){this.send({type:`provider.models`,payload:{providerId:e}})}listSavedProviders(){this.send({type:`providers.saved`})}addKey(e,t,n){this.send({type:`key.add`,payload:{providerId:e,label:t,apiKey:n}})}updateKey(e,t,n){this.send({type:`key.update`,payload:{providerId:e,label:t,apiKey:n}})}deleteKey(e,t){this.send({type:`key.delete`,payload:{providerId:e,label:t}})}setActiveKey(e,t){this.send({type:`key.set_active`,payload:{providerId:e,label:t}})}addProvider(e,t,n,r){this.send({type:`provider.add`,payload:{id:e,family:t,baseUrl:n,apiKey:r}})}removeProvider(e){this.send({type:`provider.remove`,payload:{providerId:e}})}clearContext(){this.send({type:`context.clear`})}compactContext(e=!1){this.send({type:`context.compact`,payload:{aggressive:e}})}repairContext(){this.send({type:`context.repair`})}debugContext(){this.send({type:`context.debug`})}listContextModes(){this.send({type:`context.modes.list`})}switchContextMode(e){this.send({type:`context.mode.switch`,payload:{id:e}})}createContextMode(e){this.send({type:`context.mode.create`,payload:e})}updateContextMode(e,t){this.send({type:`context.mode.update`,payload:{id:e,...t}})}deleteContextMode(e){this.send({type:`context.mode.delete`,payload:{id:e}})}switchAutonomy(e){this.send({type:`autonomy.switch`,payload:{mode:e}})}updatePrefs(e){this.send({type:`prefs.update`,payload:e})}getPrefs(){this.send({type:`prefs.get`})}listTools(){this.send({type:`tools.list`})}listMemory(){this.send({type:`memory.list`})}remember(e,t){this.send({type:`memory.remember`,payload:{text:e,scope:t}})}forget(e,t){this.send({type:`memory.forget`,payload:{text:e,scope:t}})}listSkills(){this.send({type:`skills.list`})}getDiag(){this.send({type:`diag.get`})}getStats(){this.send({type:`stats.get`})}saveSession(){this.send({type:`session.save`})}resumeSessionById(e){this.send({type:`session.resume`,payload:{id:e}})}listModes(){this.send({type:`modes.list`})}switchMode(e){this.send({type:`mode.switch`,payload:{id:e}})}listFiles(e,t,n){this.send({type:`files.list`,payload:{query:e,limit:t,path:n}})}getTodos(){this.send({type:`todos.get`})}clearTodos(){this.send({type:`todos.clear`})}removeTodo(e){let t=typeof e==`number`?{index:e}:{id:e};this.send({type:`todos.remove`,payload:t})}updateTodoStatus(e,t){this.send({type:`todo.update`,payload:{id:e,status:t}})}getTasks(){this.send({type:`tasks.get`})}updateTaskStatus(e,t){this.send({type:`task.update`,payload:{id:e,status:t}})}getPlan(){this.send({type:`plan.get`})}updatePlanItem(e,t){this.send({type:`plan.item.update`,payload:{target:e,status:t}})}listSessions(e=50){this.send({type:`sessions.list`,payload:{limit:e}})}deleteSession(e){this.send({type:`session.delete`,payload:{id:e}})}listProjects(){this.send({type:`projects.list`})}addProject(e,t){this.send({type:`projects.add`,payload:{root:e,name:t}})}selectProject(e,t){this.send({type:`projects.select`,payload:{root:e,name:t}})}setWorkingDir(e){this.send({type:`working_dir.set`,payload:{path:e}})}resumeSession(e){this.send({type:`session.resume`,payload:{id:e}})}ping(){this.send({type:`ping`})}refineModel(e){this.send({type:`model.refine`,payload:{text:e}})}disconnect(){this.shouldReconnect=!1,this.reconnectTimer&&=(clearTimeout(this.reconnectTimer),null),this.ws?.close(),this.ws=null,Mn()}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}get currentSessionId(){return this.sessionId}},Pn=null,Fn=3457;function In(){if(typeof document>`u`)return Fn;let e=document.querySelector(`meta[name="wrongstack-ws-port"]`)?.getAttribute(`content`),t=e?Number.parseInt(e,10):NaN;return Number.isFinite(t)&&t>0&&t<65536?t:Fn}function Ln(){let e=In();if(typeof window>`u`||!window.location?.hostname)return`ws://127.0.0.1:${e}`;let t=window.location.hostname.toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t===`::1`?`ws://127.0.0.1:${e}`:`ws://${window.location.hostname}:${e}`}function B(e){return Pn||=new Nn(e),Pn}function Rn(e){if(!e)return e;let t=e.split(/\n{2,}/),n=[];for(let e of t)n.length>0&&n[n.length-1]?.trim()===e.trim()||n.push(e);return n.map(e=>{let t=e.split(`
|
|
6
|
+
`),n=[];for(let e of t)n.length>0&&e.trim().length>0&&n[n.length-1]?.trim()===e.trim()||n.push(e);return n.join(`
|
|
7
|
+
`)}).join(`
|
|
8
|
+
|
|
9
|
+
`)}var V=n()(_e((e,t)=>({messages:[],currentAssistantMessageId:null,currentToolId:null,isLoading:!1,abortController:null,executions:new Map,queue:[],runStart:null,thinkingBuffer:``,thinkingStartedAt:null,addMessage:t=>{let n=`msg_${Date.now()}_${crypto.randomUUID().slice(0,8)}`,r={...t,id:n,timestamp:t.timestamp??Date.now()};return e(e=>({messages:[...e.messages,r],currentAssistantMessageId:t.role===`assistant`?n:e.currentAssistantMessageId})),n},updateMessage:(t,n)=>{e(e=>({messages:e.messages.map(e=>e.id===t?{...e,...n}:e)}))},appendToMessage:(t,n)=>{e(e=>({messages:e.messages.map(e=>e.id===t?{...e,content:e.content+n}:e)}))},finalizeMessage:t=>{e(e=>({messages:e.messages.map(e=>e.id===t?{...e,content:Rn(e.content),streaming:!1}:e)}))},setToolResult:(t,n,r)=>{e(e=>({messages:e.messages.map(e=>e.id===t?{...e,toolResult:n,isError:!r,progressLines:void 0}:e)}))},appendToolProgress:(t,n)=>{e(e=>({messages:e.messages.map(e=>{if(e.id!==t)return e;let r=[...e.progressLines??[],n],i=r.length>30?r.slice(r.length-30):r;return{...e,progressLines:i}})}))},setLoading:t=>e({isLoading:t}),setAbortController:t=>e({abortController:t}),clearMessages:()=>e({messages:[],currentAssistantMessageId:null,currentToolId:null,executions:new Map}),setCurrentAssistantMessage:t=>e({currentAssistantMessageId:t}),setCurrentToolId:t=>e({currentToolId:t}),truncateAfter:t=>e(e=>{let n=e.messages.findIndex(e=>e.id===t);return n===-1?e:{messages:e.messages.slice(0,n),currentAssistantMessageId:null,currentToolId:null}}),addExecution:t=>{e(e=>{let n=new Map(e.executions);return n.set(t.id,t),{executions:n}})},updateExecution:(t,n)=>{e(e=>{let r=new Map(e.executions),i=r.get(t);return i&&r.set(t,{...i,...n}),{executions:r}})},enqueue:t=>e(e=>({queue:[...e.queue,t]})),dequeue:()=>{let{queue:n}=t();if(n.length===0)return null;let[r,...i]=n;return e({queue:i}),R(r)},removeQueued:t=>e(e=>({queue:e.queue.filter((e,n)=>n!==t)})),clearQueue:()=>e({queue:[]}),setRunStart:t=>e({runStart:t}),appendThinking:t=>e(e=>({thinkingBuffer:e.thinkingBuffer+t,thinkingStartedAt:e.thinkingStartedAt??Date.now()})),clearThinking:()=>e({thinkingBuffer:``,thinkingStartedAt:null})}),{name:`wrongstack-chat`,partialize:()=>({})})),H=n()(_e(e=>({provider:`anthropic`,model:`claude-sonnet-4-20250514`,wsUrl:(()=>{if(typeof window>`u`||!window.location?.hostname)return`ws://127.0.0.1:3457`;let e=window.location.hostname.toLowerCase();return e===`localhost`||e===`127.0.0.1`||e===`[::1]`||e===`::1`?`ws://127.0.0.1:3457`:`ws://${window.location.hostname}:3457`})(),wsConnected:!1,wsStatus:{state:`connecting`},theme:`system`,autoConnect:!0,soundOnComplete:!1,setProvider:t=>e({provider:t}),setModel:t=>e({model:t}),setConfig:t=>e(t),setTheme:t=>e({theme:t}),setWsConnected:t=>e({wsConnected:t}),setWsStatus:t=>e({wsStatus:t,wsConnected:t.state===`open`}),setSoundOnComplete:t=>e({soundOnComplete:t})}),{name:`wrongstack-config`})),U=n()(_e(e=>({session:null,totalTokens:{input:0,output:0,cacheRead:0,cacheWrite:0},lastInputTokens:0,cost:0,startTime:null,maxContext:0,inputCost:0,outputCost:0,cacheReadCost:0,projectName:``,projectRoot:``,cwd:``,mode:`default`,modes:[],contextMode:`balanced`,contextModes:[],iteration:null,todos:[],setSession:t=>e({session:t}),updateUsage:t=>e(e=>{let n=t.input+(t.cacheRead??0)+(t.cacheWrite??0),r=t.cacheRead??0,i=t.cacheWrite??0;return{totalTokens:{input:e.totalTokens.input+t.input,output:e.totalTokens.output+t.output,cacheRead:(e.totalTokens.cacheRead??0)+r,cacheWrite:(e.totalTokens.cacheWrite??0)+i},lastInputTokens:n||e.lastInputTokens}}),addCost:t=>e(e=>({cost:e.cost+t})),startSession:t=>e({session:t,startTime:Date.now(),iteration:null,lastInputTokens:0,totalTokens:{input:0,output:0,cacheRead:0,cacheWrite:0},cost:0}),endSession:()=>e({session:null,startTime:null,iteration:null}),setEnv:t=>e(e=>({maxContext:t.maxContext??e.maxContext,projectRoot:t.projectRoot??e.projectRoot,projectName:t.projectName??e.projectName,cwd:t.cwd??e.cwd,mode:t.mode??e.mode,contextMode:t.contextMode??e.contextMode,inputCost:t.inputCost??e.inputCost,outputCost:t.outputCost??e.outputCost,cacheReadCost:t.cacheReadCost??e.cacheReadCost})),setIteration:t=>e({iteration:t}),setModes:t=>e({modes:t}),setContextModes:t=>e({contextModes:t}),setTodos:t=>e({todos:t})}),{name:`wrongstack-session`,partialize:()=>({})})),zn=[`chat`,`agents`,`history`,`files`,`projects`,`mailbox`];function Bn(e){return zn.includes(e)?e:e===`context`?`chat`:e===`sessions`?`history`:`chat`}var W=n()(_e(e=>({sidebarOpen:!0,activeActivity:`chat`,settingsOpen:!1,currentView:`chat`,showConfirmDialog:!1,confirmInfo:null,paletteOpen:!1,shortcutsOpen:!1,searchOpen:!1,searchQuery:``,promptHistory:[],sidebarWidth:304,pinnedIds:[],compactMode:!1,modelSwitcherOpen:!1,favoriteSessionIds:[],sessionNicknames:{},fileExplorerWidth:220,refineEnabled:!0,refinePanel:null,dockSection:null,selectActivity:t=>e({activeActivity:t}),toggleSidebar:()=>e(e=>({sidebarOpen:!e.sidebarOpen})),setSidebarOpen:t=>e({sidebarOpen:t}),setSettingsOpen:t=>e({settingsOpen:t}),setCurrentView:t=>e({currentView:t}),showConfirm:t=>e({showConfirmDialog:!0,confirmInfo:t}),hideConfirm:()=>e({showConfirmDialog:!1,confirmInfo:null}),setPaletteOpen:t=>e({paletteOpen:t}),setShortcutsOpen:t=>e({shortcutsOpen:t}),setSearchOpen:t=>e({searchOpen:t,searchQuery:``}),setSearchQuery:t=>e({searchQuery:t}),pushPrompt:t=>e(e=>{let n=t.trim();return n?{promptHistory:[n,...e.promptHistory.filter(e=>e!==n)].slice(0,50)}:e}),setSidebarWidth:t=>e({sidebarWidth:Math.max(240,Math.min(560,Math.round(t)))}),togglePin:t=>e(e=>({pinnedIds:e.pinnedIds.includes(t)?e.pinnedIds.filter(e=>e!==t):[...e.pinnedIds,t]})),unpinAll:()=>e({pinnedIds:[]}),toggleCompactMode:()=>e(e=>({compactMode:!e.compactMode})),setModelSwitcherOpen:t=>e({modelSwitcherOpen:t}),toggleFavoriteSession:t=>e(e=>({favoriteSessionIds:e.favoriteSessionIds.includes(t)?e.favoriteSessionIds.filter(e=>e!==t):[...e.favoriteSessionIds,t]})),setSessionNickname:(t,n)=>e(e=>{let r=n.trim(),i={...e.sessionNicknames};return r?i[t]=r:delete i[t],{sessionNicknames:i}}),setFileExplorerWidth:t=>e({fileExplorerWidth:Math.max(160,Math.min(400,Math.round(t)))}),toggleRefineEnabled:()=>e(e=>({refineEnabled:!e.refineEnabled})),setRefinePanel:t=>e({refinePanel:t}),setDockSection:t=>e({dockSection:t}),toggleDockSection:t=>e(e=>({dockSection:e.dockSection===t?null:t}))}),{name:`wrongstack-ui`,version:1,migrate:e=>{let t=e??{};return t.activeActivity=Bn(t.activeActivity),typeof t.sidebarWidth==`number`&&(t.sidebarWidth=Math.max(240,Math.min(560,t.sidebarWidth))),t},partialize:e=>({sidebarOpen:e.sidebarOpen,activeActivity:e.activeActivity,sidebarWidth:e.sidebarWidth,promptHistory:e.promptHistory,pinnedIds:e.pinnedIds,compactMode:e.compactMode,favoriteSessionIds:e.favoriteSessionIds,sessionNicknames:e.sessionNicknames,fileExplorerWidth:e.fileExplorerWidth,refineEnabled:e.refineEnabled})})),Vn=n()(e=>({messages:[],agents:[],setMessages:t=>e({messages:t}),setAgents:t=>e({agents:t})}));function Hn(e){return e.messages.filter(e=>e.readByCount===0&&!e.completed).length}var Un=n()(e=>({entries:[],loading:!1,error:null,setEntries:(t,n=null)=>e({entries:t,error:n,loading:!1}),setLoading:t=>e({loading:t}),removeEntry:t=>e(e=>({entries:e.entries.filter(e=>e.id!==t)})),clearHistory:()=>e({entries:[]})})),Wn=n()(e=>({worktrees:[],baseBranch:``,activity:[],setSnapshot:(t,n)=>e({worktrees:t,baseBranch:n}),pushEvent:t=>e(e=>({activity:[...e.activity,t].slice(-40)}))}));function Gn(e,t,n){return{id:e,name:t?.trim()||e,sessionId:n,status:`running`,iteration:0,toolCalls:0,costUsd:0,ctxPct:0,ctxTokens:0,maxContext:0,extensions:0,startedAt:Date.now(),toolLog:[]}}var Kn=n()((e,t)=>({agents:new Map,clear:()=>e({agents:new Map}),getAgentsBySession:e=>{let n=[];for(let r of t().agents.values())r.sessionId===e&&n.push(r);return n},applyEvent:t=>e(e=>{let n=new Map(e.agents);if(t.kind===`session_stopped`&&t.sessionId){for(let[e,r]of n)r.sessionId===t.sessionId&&n.delete(e);return{agents:n}}if(!t.subagentId)return e;let r={...n.get(t.subagentId)??Gn(t.subagentId,t.name,t.sessionId)};switch(t.kind){case`spawned`:r.name=t.name?.trim()||r.name,r.provider=t.provider??r.provider,r.model=t.model??r.model,r.description=t.description??r.description,r.taskId=t.taskId??r.taskId,r.sessionId=t.sessionId??r.sessionId,r.status=`running`;break;case`task_started`:r.description=t.description??r.description,r.taskId=t.taskId??r.taskId,r.status=`running`;break;case`tool_executed`:r.lastTool=t.toolName??r.lastTool,r.toolCalls+=1,r.toolLog=[{name:t.toolName??`unknown`,ok:typeof t.ok==`boolean`?t.ok:!0,durationMs:typeof t.durationMs==`number`?t.durationMs:0,at:Date.now()},...r.toolLog].slice(0,50);break;case`iteration_summary`:r.iteration=t.iteration??r.iteration,typeof t.toolCalls==`number`&&(r.toolCalls=t.toolCalls),typeof t.costUsd==`number`&&(r.costUsd=t.costUsd),r.currentTool=t.currentTool??r.currentTool,typeof t.partialText==`string`&&t.partialText&&(r.partialText=t.partialText);break;case`budget_extended`:r.extensions=t.totalExtensions??r.extensions+1;break;case`ctx_pct`:r.ctxPct=Math.round(Math.min(1,Math.max(0,t.load??0))*100),r.ctxTokens=t.tokens??r.ctxTokens,r.maxContext=t.maxContext??r.maxContext,typeof t.costUsd==`number`&&(r.costUsd=t.costUsd);break;case`task_completed`:r.status=t.status===`success`?`completed`:t.status??`completed`,typeof t.iterations==`number`&&(r.iteration=t.iterations),typeof t.toolCalls==`number`&&(r.toolCalls=t.toolCalls),r.error=t.error,r.currentTool=void 0,r.completedAt=Date.now(),typeof t.finalText==`string`&&t.finalText&&(r.finalText=t.finalText);break}return n.set(t.subagentId,r),{agents:n}})}));function qn(e){return!e||typeof e.goal!=`string`||!e.goal.trim()?null:{goal:e.goal,refinedGoal:typeof e.refinedGoal==`string`?e.refinedGoal:void 0,goalState:[`active`,`paused`,`completed`,`failed`,`abandoned`].includes(e.goalState)?e.goalState:`active`,iterations:typeof e.iterations==`number`?e.iterations:0,progress:typeof e.progress==`number`?e.progress:0,progressNote:typeof e.progressNote==`string`?e.progressNote:void 0,progressTrend:e.progressTrend===`accelerating`?`up`:e.progressTrend===`stalling`?`down`:e.progressTrend===`steady`?`stable`:void 0,deliverables:Array.isArray(e.deliverables)?e.deliverables.map((e,t)=>typeof e==`string`?{id:`d${t}`,text:e,status:/^\[[x✓]\]|✅|\(done\)/i.test(e)?`done`:`pending`}:e):void 0,journal:Array.isArray(e.journal)?e.journal:void 0,lastTask:typeof e.lastTask==`string`?e.lastTask:void 0,lastStatus:typeof e.lastStatus==`string`?e.lastStatus:void 0}}var Jn=n()(e=>({goal:null,setGoal:t=>e({goal:qn(t)}),clear:()=>e({goal:null}),refresh:()=>{try{B()?.send?.({type:`goal.get`})}catch{}}})),Yn=n()(e=>({phases:[],activePhaseId:null,overallPercent:0,autonomous:!1,title:null,setState:t=>e(e=>({phases:t.phases??e.phases,activePhaseId:t.activePhaseId===void 0?e.activePhaseId:t.activePhaseId,overallPercent:t.overallPercent??e.overallPercent,autonomous:t.autonomous??e.autonomous,title:t.title===void 0?e.title:t.title})),clear:()=>e({phases:[],activePhaseId:null,overallPercent:0,autonomous:!1,title:null})})),Xn={autonomy:`off`,autonomyDelayMs:45e3,autoProceedMaxIterations:50,yolo:!1,maxIterations:500,chime:!1,confirmExit:!0,streamFleet:!0,nextPrediction:!1,featureMcp:!0,featurePlugins:!0,featureMemory:!0,featureSkills:!0,featureModelsRegistry:!0,indexOnStart:!0,contextAutoCompact:!0,contextStrategy:`hybrid`,logLevel:`info`,auditLevel:`standard`,enhanceEnabled:!0,enhanceDelayMs:6e4,enhanceLanguage:`original`},Zn=n()(_e(e=>({...Xn,set:t=>e(t),reset:()=>e(Xn)}),{name:`wrongstack-local-prefs`,version:2,migrate:e=>{let t=e??{};return[`hybrid`,`intelligent`,`selective`].includes(t.contextStrategy)||(t.contextStrategy=`hybrid`),t.auditLevel===`verbose`&&(t.auditLevel=`full`),[`minimal`,`standard`,`full`].includes(t.auditLevel)||(t.auditLevel=`standard`),typeof t.autoProceedMaxIterations!=`number`&&(t.autoProceedMaxIterations=50),t}})),G=n()((e,t)=>({projectRoot:``,tree:[],openFiles:[],activeFilePath:null,treeLoading:!1,error:null,setTree:(t,n)=>e({projectRoot:t,tree:n,treeLoading:!1,error:null}),openFile:(n,r)=>{let i=t();if(i.openFiles.find(e=>e.path===n)){e({activeFilePath:n});return}e({openFiles:[...i.openFiles,{path:n,content:r,dirty:!1,savedContent:r}],activeFilePath:n})},closeFile:n=>{let r=t(),i=r.openFiles.findIndex(e=>e.path===n);if(i===-1)return;let a=[...r.openFiles];a.splice(i,1);let o=r.activeFilePath;r.activeFilePath===n&&(o=a.length===0?null:i<a.length?a[i].path:a[a.length-1].path),e({openFiles:a,activeFilePath:o})},setActiveFile:t=>e({activeFilePath:t}),updateContent:(t,n)=>{e(e=>({openFiles:e.openFiles.map(e=>e.path===t?{...e,content:n,dirty:n!==e.savedContent}:e)}))},markSaved:t=>{e(e=>({openFiles:e.openFiles.map(e=>e.path===t?{...e,dirty:!1,savedContent:e.content}:e)}))},setTreeLoading:t=>e({treeLoading:t}),setError:t=>e({error:t})})),Qn=0;function K(){return`viz_${Date.now()}_${++Qn}`}var q={provider:`hsl(180, 80%, 55%)`,agent:`hsl(280, 80%, 65%)`,tool:`hsl(40, 90%, 55%)`,mailbox:`hsl(140, 70%, 55%)`,session:`hsl(220, 80%, 60%)`,system:`hsl(0, 0%, 60%)`,error:`hsl(0, 80%, 55%)`},$n={"provider:call":`hsl(180, 80%, 55%)`,"provider:delta":`hsl(180, 60%, 70%)`,"agent:tool":`hsl(40, 90%, 55%)`,"mailbox:send":`hsl(140, 70%, 55%)`,default:`hsl(0, 0%, 40%)`},er=n()((e,t)=>({events:[],nodes:new Map,edges:new Map,isActive:!1,maxEvents:500,counters:{totalTokens:0,totalCost:0,totalToolCalls:0,activeAgents:0,completedTasks:0,errors:0,mailboxMessages:0},pushEvent:t=>e(e=>{let n=[{...t,id:K(),timestamp:t.timestamp||Date.now()},...e.events];return n.length>e.maxEvents&&(n.length=e.maxEvents),{events:n}}),upsertNode:t=>e(e=>{let n=new Map(e.nodes),r=n.get(t.id);return n.set(t.id,{...r,...t,lastSeenAt:Date.now()}),{nodes:n}}),removeNode:t=>e(e=>{let n=new Map(e.nodes);n.delete(t);let r=new Map(e.edges);for(let[e,n]of r)(n.source===t||n.target===t)&&r.delete(e);return{nodes:n,edges:r}}),upsertEdge:t=>e(e=>{let n=new Map(e.edges),r=n.get(t.id);return n.set(t.id,{...r,...t,lastActiveAt:Date.now(),intensity:t.intensity??r?.intensity??.5,color:t.color??$n[t.kind]??$n.default,totalMagnitude:(r?.totalMagnitude??0)+(t.totalMagnitude??0)}),{edges:n}}),removeEdge:t=>e(e=>{let n=new Map(e.edges);return n.delete(t),{edges:n}}),clear:()=>e({events:[],nodes:new Map,edges:new Map,counters:{totalTokens:0,totalCost:0,totalToolCalls:0,activeAgents:0,completedTasks:0,errors:0,mailboxMessages:0}}),setActive:t=>e({isActive:t}),decayActivity:()=>e(e=>{let t=new Map(e.nodes);for(let[e,n]of t)n.activity>.01&&t.set(e,{...n,activity:n.activity*.92});return{nodes:t}}),prunesStale:t=>e(e=>{let n=Date.now()-t,r=new Map(e.nodes);for(let[e,t]of r)t.lastSeenAt<n&&t.status!==`active`&&r.delete(e);let i=new Map(e.edges);for(let[e,t]of i)t.lastActiveAt<n&&i.delete(e);return{nodes:r,edges:i,events:e.events.filter(e=>e.timestamp>n)}})}));function tr(e,t){switch(e){case`provider.text_delta`:{let e=t.text??``;return{id:K(),kind:`provider:delta`,timestamp:Date.now(),source:`provider`,target:`leader`,label:e.slice(0,60),magnitude:e.length,data:{text:e},color:q.provider,flowGroup:`provider`}}case`provider.response`:{let e=t.usage,n=(e?.input??0)+(e?.output??0);return{id:K(),kind:`provider:response`,timestamp:Date.now(),source:`provider`,target:`leader`,label:`${(e?.input??0).toLocaleString()} in / ${(e?.output??0).toLocaleString()} out`,magnitude:n,data:t,color:q.provider,flowGroup:`provider`}}case`tool.started`:{let e=t.name??`tool`;return{id:K(),kind:`tool:started`,timestamp:Date.now(),source:e,target:`filesystem`,label:e,magnitude:1,data:t,color:q.tool,flowGroup:`tool:${e}`}}case`tool.executed`:{let e=t.name??`tool`,n=t.ok??!0;return{id:K(),kind:`tool:executed`,timestamp:Date.now(),source:e,target:`leader`,label:`${e} ${n?`✓`:`✗`} (${t.durationMs??0}ms)`,magnitude:t.durationMs??0,data:t,color:n?q.tool:q.error,flowGroup:`tool:${e}`}}case`subagent.event`:{let e=t.kind,n=t.subagentId??`unknown`,r=t.name??n;switch(e){case`spawned`:return{id:K(),kind:`agent:spawned`,timestamp:Date.now(),source:n,target:`session`,label:`${r} spawned`,magnitude:1,data:t,color:q.agent,flowGroup:`agent:${n}`};case`tool_executed`:{let e=t.toolName??`tool`,r=t.ok??!0;return{id:K(),kind:`agent:tool`,timestamp:Date.now(),source:n,target:e,label:e,magnitude:t.durationMs??0,data:t,color:r?q.tool:q.error,flowGroup:`agent:${n}`}}case`task_completed`:{let e=t.status??`completed`;return{id:K(),kind:`agent:status`,timestamp:Date.now(),source:n,target:`session`,label:`${r} ${e}`,magnitude:1,data:t,color:e===`success`?`hsl(140, 70%, 55%)`:q.error,flowGroup:`agent:${n}`}}case`ctx_pct`:return{id:K(),kind:`agent:ctx`,timestamp:Date.now(),source:n,target:`session`,label:`ctx ${Math.round((t.load??0)*100)}%`,magnitude:t.tokens??0,data:t,color:q.agent,flowGroup:`agent:${n}`};case`iteration_summary`:return{id:K(),kind:`agent:text`,timestamp:Date.now(),source:n,target:`session`,label:(t.partialText??``).slice(0,80)||`iter ${t.iteration??0}`,magnitude:t.costUsd??0,data:t,color:q.agent,flowGroup:`agent:${n}`};case`budget_extended`:return{id:K(),kind:`budget:extended`,timestamp:Date.now(),source:n,target:`session`,label:`${r} extended budget`,magnitude:t.totalExtensions??1,data:t,color:`hsl(40, 90%, 55%)`,flowGroup:`agent:${n}`}}return null}case`mailbox.event`:{let e=t.event,n=t.from??`?`,r=t.to??`?`,i=t.subject??``,a=e===`mailbox.sent`;return{id:K(),kind:a?`mailbox:send`:`mailbox:deliver`,timestamp:Date.now(),source:n,target:r,label:i||(a?`→ ${r}`:`← ${n}`),magnitude:1,data:t,color:q.mailbox,flowGroup:`mailbox`}}case`iteration.started`:{let e=t.index??0;return{id:K(),kind:`iteration:start`,timestamp:Date.now(),source:`leader`,target:`session`,label:`Iteration ${e}`,magnitude:e,data:t,color:q.agent,flowGroup:`iteration`}}case`error`:{let e=t.message??`Error`;return{id:K(),kind:`error`,timestamp:Date.now(),source:t.phase??`system`,target:`session`,label:e,magnitude:1,data:t,color:q.error,flowGroup:`error`}}case`context.compacted`:return{id:K(),kind:`context:compacted`,timestamp:Date.now(),source:`system`,target:`session`,label:`Compacted: ${(t.saved??0).toLocaleString()} tokens`,magnitude:t.saved??0,data:t,color:`hsl(220, 60%, 50%)`,flowGroup:`context`};case`context.repaired`:return{id:K(),kind:`context:repaired`,timestamp:Date.now(),source:`system`,target:`session`,label:`Repaired: ${t.removedMessages??0} msgs`,magnitude:t.removedMessages??0,data:t,color:`hsl(220, 60%, 50%)`,flowGroup:`context`};case`session.start`:{let e=t.sessionId??`?`,n=t.projectName??``;return{id:K(),kind:`session:start`,timestamp:Date.now(),source:`session`,target:`leader`,label:n||e.slice(0,12),magnitude:1,data:t,color:q.session,flowGroup:`session`}}case`sessions.status_update`:{let e=t.sessions??[];return{id:K(),kind:`fleet:snapshot`,timestamp:Date.now(),source:`system`,target:`session`,label:`${e.length} session(s)`,magnitude:e.length,data:t,color:q.system,flowGroup:`fleet`}}default:return null}}function J(...e){return Re(We(e))}var Y=ne(),nr=n(e=>({toasts:[],push:t=>{let n=`toast_${Date.now()}_${Math.random().toString(36).slice(2,7)}`;return e(e=>({toasts:[...e.toasts,{...t,id:n}]})),n},dismiss:t=>e(e=>({toasts:e.toasts.filter(e=>e.id!==t)}))})),X={success:(e,t=3500)=>nr.getState().push({message:e,variant:`success`,ttl:t}),error:(e,t=6e3)=>nr.getState().push({message:e,variant:`error`,ttl:t}),warn:(e,t=4500)=>nr.getState().push({message:e,variant:`warn`,ttl:t}),info:(e,t=3500)=>nr.getState().push({message:e,variant:`info`,ttl:t}),dismiss:e=>nr.getState().dismiss(e)};function rr({variant:e}){return e===`success`?(0,Y.jsx)(F,{className:`h-4 w-4 text-green-500`}):e===`error`?(0,Y.jsx)(a,{className:`h-4 w-4 text-destructive`}):e===`warn`?(0,Y.jsx)(j,{className:`h-4 w-4 text-amber-500`}):(0,Y.jsx)(ze,{className:`h-4 w-4 text-blue-500`})}function ir({entry:e}){let t=nr(e=>e.dismiss);return(0,z.useEffect)(()=>{let n=setTimeout(()=>t(e.id),e.ttl);return()=>clearTimeout(n)},[e.id,e.ttl,t]),(0,Y.jsxs)(`div`,{className:J(`flex items-start gap-2 rounded-lg border bg-popover shadow-lg px-3 py-2 text-sm max-w-sm`,`animate-message`,e.variant===`error`&&`border-destructive/40`,e.variant===`warn`&&`border-amber-500/40`,e.variant===`success`&&`border-green-500/40`),children:[(0,Y.jsx)(rr,{variant:e.variant}),(0,Y.jsx)(`div`,{className:`flex-1 min-w-0 whitespace-pre-wrap break-words leading-snug`,children:e.message}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`text-muted-foreground hover:text-foreground`,title:`Dismiss`,children:(0,Y.jsx)(L,{className:`h-3.5 w-3.5`})})]})}function ar(){let e=nr(e=>e.toasts);return e.length===0?null:(0,Y.jsx)(`div`,{className:`fixed bottom-4 right-4 z-[60] flex flex-col gap-2 pointer-events-auto`,children:e.map(e=>(0,Y.jsx)(ir,{entry:e},e.id))})}var or=null;function sr(){if(typeof window>`u`)return null;if(or)return or;let e=window.AudioContext||window.webkitAudioContext;if(!e)return null;try{or=new e}catch{return null}return or}function cr(e,t,n){let r=sr();if(!r)return;let i=r.currentTime+t,a=r.createOscillator(),o=r.createGain();a.type=`sine`,a.frequency.value=e,o.gain.setValueAtTime(0,i),o.gain.linearRampToValueAtTime(.18,i+.01),o.gain.exponentialRampToValueAtTime(1e-4,i+n),a.connect(o).connect(r.destination),a.start(i),a.stop(i+n+.02)}function lr(){cr(659.25,0,.18),cr(880,.12,.24)}function ur(){cr(523.25,0,.15),cr(659.25,.1,.15),cr(783.99,.2,.25)}var dr=`default`;dr=typeof window<`u`&&`Notification`in window?Notification.permission:`unsupported`;async function fr(){if(dr===`unsupported`||dr===`granted`||dr===`denied`)return dr;try{let e=await Notification.requestPermission();return dr=e,e}catch{return`denied`}}function pr(e,t,n){if(!(typeof document>`u`||!document.hidden)&&dr===`granted`)try{let r=new Notification(e,{body:t,icon:`/favicon.ico`,tag:n??`wrongstack-run`,requireInteraction:n===`wrongstack-confirm`});r.onclick=()=>{window.focus(),r.close()}}catch{}}function mr(e){let t=tr(`session.start`,e.payload);t&&(er.getState().pushEvent(t),er.getState().setActive(!0));let n=e.payload,r=U.getState().session?.id,i=!r||r!==n.sessionId||n.reset;if(n.needsSetup&&W.getState().setCurrentView(`setup`),i?U.getState().startSession({id:n.sessionId,startedAt:Date.now(),model:n.model,provider:n.provider}):U.getState().setSession({id:n.sessionId,startedAt:U.getState().session?.startedAt??Date.now(),model:n.model,provider:n.provider}),U.getState().setEnv({maxContext:n.maxContext,projectRoot:n.projectRoot??``,projectName:n.projectName,cwd:n.cwd,mode:n.mode,contextMode:n.contextMode,inputCost:n.inputCost,outputCost:n.outputCost,cacheReadCost:n.cacheReadCost}),H.getState().setConfig({provider:n.provider,model:n.model}),i){V.getState().clearMessages(),V.getState().setLoading(!1),U.setState({todos:[]}),En(`ready`);let e=Kn.getState();if(n.clearedSessionId){let t=new Map;for(let[r,i]of e.agents)i.sessionId!==n.clearedSessionId&&t.set(r,i);Kn.setState({agents:t})}else e.clear();G.getState().setTreeLoading(!0),B().send({type:`files.tree`,payload:{path:U.getState().cwd}})}let a=n.replayMessages;if(a&&a.length>0){let e=V.getState();for(let t of a){let n=typeof t.ts==`string`?Date.parse(t.ts):NaN,r=Number.isFinite(n)?n:void 0;if(t.role===`user`||t.role===`assistant`||t.role===`system`){let n=``;if(typeof t.content==`string`)n=t.content;else if(Array.isArray(t.content)){for(let i of t.content)if(i.type===`text`&&typeof i.text==`string`)n+=(n?`
|
|
10
|
+
`:``)+i.text;else if(i.type===`tool_use`)n&&=(e.addMessage({role:t.role,content:n,timestamp:r}),``),e.addMessage({role:`tool`,content:``,toolName:String(i.name??`tool`),toolInput:i.input,toolUseId:String(i.id??``),timestamp:r});else if(i.type===`tool_result`){let t=V.getState().messages,n;for(let e=t.length-1;e>=0;e--)if(t[e]?.toolUseId===String(i.tool_use_id??``)){n=R(t[e]);break}n&&e.setToolResult(n.id,typeof i.content==`string`?i.content:JSON.stringify(i.content),!i.is_error)}}n&&e.addMessage({role:t.role,content:n,timestamp:r})}}}if(a){let e=n.replayUsage;if(e){let t=U.getState(),n=e.input??0,r=e.output??0,i=e.cacheRead??0,a=e.cacheWrite??0;U.setState({totalTokens:{input:n,output:r,cacheRead:i,cacheWrite:a},cost:(n*t.inputCost+r*t.outputCost+i*t.cacheReadCost)/1e6})}W.getState().currentView!==`chat`&&W.getState().setCurrentView(`chat`),typeof window<`u`&&window.matchMedia?.(`(max-width: 768px)`).matches&&W.getState().setSidebarOpen(!1)}}function hr(e){let t=e.payload,n=e=>e.toLocaleString(),r=[...t.tools.breakdown].sort((e,t)=>t.tokens-e.tokens).slice(0,8),i=[...t.messages.breakdown].sort((e,t)=>t.tokens-e.tokens).slice(0,8);V.getState().addMessage({role:`assistant`,content:[`📊 **Context breakdown** (heuristic — 4 chars/token)`,``,`**Total estimate:** ${n(t.total)} tokens`,`• System prompt: ${n(t.systemPrompt)}`,`• Tool schemas: ${n(t.tools.total)} (${t.tools.count} tools)`,`• Messages: ${n(t.messages.total)} (${t.messages.count} messages)`,``,`**Top tool schemas:**`,...r.map(e=>` · ${e.name}: ${n(e.tokens)}`),``,`**Top messages:**`,...i.map(e=>` · #${e.index} ${e.role}: ${n(e.tokens)} — ${e.preview||`(empty)`}`)].join(`
|
|
11
|
+
`)})}function gr(e){let t=e.payload;t.success?X.success(t.message):X.error(t.message),B(H.getState().wsUrl).listSavedProviders()}function _r(e){Ur(e);let t=e.payload,n=t.reductions.length?t.reductions.map(e=>`${e.phase}: ${e.saved}`).join(`, `):`no-op`;t.repaired&&(n+=`; repaired ${t.repaired.removedToolUses?.length??0} tool_use, ${t.repaired.removedToolResults?.length??0} tool_result, ${t.repaired.removedMessages} empty messages`),V.getState().addMessage({role:`assistant`,content:`🗜️ Context compacted: ${t.before} → ${t.after} tokens (saved ~${t.saved}). ${n}`}),U.setState({lastInputTokens:t.after})}function vr(e){let t=e.payload,n=t.usage,r=(n.input??0)+(n.cacheWrite??0)-(n.cacheRead??0);r>0&&U.setState({lastInputTokens:r}),U.getState().updateUsage(t.usage);let{inputCost:i,outputCost:a,cacheReadCost:o}=U.getState(),s=(t.usage.input*i+t.usage.output*a+(t.usage.cacheRead??0)*o)/1e6;s>0&&U.getState().addCost(s),t.stopReason!==`tool_use`&&t.stopReason!==`tool_call`&&V.getState().setLoading(!1);let c=V.getState().currentAssistantMessageId;c&&(V.getState().finalizeMessage(c),t.usage.output>0&&V.getState().updateMessage(c,{usage:t.usage})),V.getState().setCurrentAssistantMessage(null),V.getState().clearThinking()}function yr(e){let t=e.payload,n=t.removedToolUses.length+t.removedToolResults.length+t.removedMessages,r=t.beforeMessages!==void 0&&t.afterMessages!==void 0?` Messages: ${t.beforeMessages} -> ${t.afterMessages}.`:``;V.getState().addMessage({role:`assistant`,content:`Context repaired: removed ${n} orphan protocol item(s).${r} tool_use ${t.removedToolUses.length}, tool_result ${t.removedToolResults.length}.`})}function br(){H.getState().setWsConnected(!1)}function xr(e){Ur(e);let t=e.payload;U.getState().setIteration({index:t.index,max:t.maxIterations??0}),V.getState().setLoading(!0),typeof document<`u`&&document.hidden&&En(`running`),V.getState().runStart===null&&V.getState().setRunStart({at:Date.now(),cost:U.getState().cost}),V.getState().setCurrentAssistantMessage(null)}function Sr(e){let t=e.payload;V.getState().clearThinking();let n=V.getState().currentAssistantMessageId;n||(n=V.getState().addMessage({role:`assistant`,content:``,streaming:!0}),V.getState().setCurrentAssistantMessage(n)),V.getState().appendToMessage(n,t.text)}function Cr(e){let t=e.payload;t.text&&V.getState().appendThinking(t.text)}function wr(e){let t=e.payload,n=V.getState().messages.find(e=>e.toolUseId===t.id);if(n){V.getState().setCurrentToolId(n.id);return}V.getState().clearThinking(),V.getState().setCurrentAssistantMessage(null);let r=V.getState().addMessage({role:`tool`,content:``,toolName:t.name,toolInput:t.input,toolUseId:t.id});V.getState().setCurrentToolId(r),V.getState().addExecution({id:t.id,name:t.name,input:t.input,ok:!0,startedAt:Date.now()})}function Tr(e){let t=e.payload,n=(t.event?.text??``).trim();if(!n)return;let r=V.getState().messages.find(e=>e.toolUseId===t.id);if(!r)return;let i=t.event?.type===`warning`?`⚠ `:``;V.getState().appendToolProgress(r.id,i+n)}function Er(e){let t=e.payload,{messages:n,currentToolId:r}=V.getState(),i=t.id?n.find(e=>e.toolUseId===t.id):r?n.find(e=>e.id===r):void 0;i?.toolResult===void 0&&(i&&(V.getState().setToolResult(i.id,t.output??``,t.ok),V.getState().updateMessage(i.id,{toolDurationMs:t.durationMs})),t.id&&V.getState().updateExecution(t.id,{completedAt:Date.now(),durationMs:t.durationMs,output:t.output,ok:t.ok}),r&&i&&i.id===r&&V.getState().setCurrentToolId(null))}function Dr(e){let t=e.payload;W.getState().showConfirm({id:t.id,toolName:t.toolName,input:t.input,suggestedPattern:t.suggestedPattern});try{ur()}catch{}fr(),pr(`${U.getState().projectName||`Agent`} needs approval`,`Tool "${t.toolName}" is waiting for your decision.`,`agent-confirm`),typeof document<`u`&&document.hidden&&En(`attention`)}function Or(e){let t=e.payload;U.getState().setIteration(null),V.getState().setLoading(!1),V.getState().setCurrentAssistantMessage(null),V.getState().clearThinking();let n=V.getState().runStart;if(n&&t.status===`done`){let e=V.getState().messages,r=-1,i=0;for(let t=e.length-1;t>=0;t--){let a=R(e[t]);if(a.role===`assistant`&&r===-1&&a.content&&(r=t),a.role===`tool`&&a.timestamp>=n.at&&(i+=1),a.role===`user`&&a.timestamp<=n.at)break}if(r!==-1){let a=U.getState().cost;V.getState().updateMessage(e[r]?.id,{runSummary:{iterations:t.iterations,tools:i,durationMs:Date.now()-n.at,costDelta:Math.max(0,a-n.cost)}})}}if(V.getState().setRunStart(null),t.status!==`done`&&t.error)V.getState().addMessage({role:`assistant`,content:`Error: ${t.error.message}`,isError:!0}),X.error(`Run ended: ${t.error.message}`),pr(`${U.getState().projectName||`Agent`} run failed`,t.error.message),typeof document<`u`&&document.hidden&&En(`error`);else if(t.status===`done`&&(typeof document<`u`&&document.hidden&&(X.success(`Run completed in ${t.iterations} iteration${t.iterations===1?``:`s`}`),pr(`${U.getState().projectName||`Agent`} run finished`,`Completed in ${t.iterations} iteration${t.iterations===1?``:`s`}.`),En(`ready`)),fr(),H.getState().soundOnComplete))try{lr()}catch{}let r=V.getState().dequeue();if(r){let e=B(H.getState().wsUrl);V.getState().addMessage({role:`user`,content:r}),V.getState().setLoading(!0),e.sendMessage(r)}}function kr(e){let t=e.payload;V.getState().addMessage({role:`assistant`,content:[`🛠️ **Registered tools** (${t.tools.length})`,``,...t.tools.map(e=>`• \`${e.name}\`${e.params.length?` (${e.params.join(`, `)})`:``} — ${e.description||`_no description_`}`)].join(`
|
|
12
|
+
`)})}function Ar(e){let t=e.payload,n=t.text?.trim();V.getState().addMessage({role:`assistant`,content:t.error?`Memory read failed: ${t.error}`:n?`🧠 **Memory** \n\n${n}`:`🧠 **Memory**
|
|
13
|
+
|
|
14
|
+
_empty — nothing remembered yet_`})}function jr(e){let t=e.payload;if(!t.enabled){V.getState().addMessage({role:`assistant`,content:`🎯 **Skills**
|
|
15
|
+
|
|
16
|
+
_disabled (config.features.skills = false)_`});return}let n=[`🎯 **Skills** (${t.skills.length})`,``,...t.skills.length===0?[`_none registered_`]:t.skills.map(e=>`• \`${e.name}\`${e.version?` v${e.version}`:``} _(${e.source})_ — ${e.description||e.trigger||`_no description_`}`)];t.error&&n.push(``,`⚠ ${t.error}`),V.getState().addMessage({role:`assistant`,content:n.join(`
|
|
17
|
+
`)})}function Mr(e){let t=e.payload;V.getState().addMessage({role:`assistant`,content:[`🩺 **Runtime diagnostics**`,``,`**Provider:** \`${t.provider}\` / \`${t.model}\``,`**Mode:** \`${t.mode}\``,`**Session:** \`${t.sessionId}\``,`**CWD:** \`${t.cwd}\``,``,`**Tools:** ${t.tools.count}`,`**Messages:** ${t.messages} · **Todos:** ${t.todos}`,`**Usage:** ${t.usage.input.toLocaleString()} in · ${t.usage.output.toLocaleString()} out${t.usage.cacheRead?` · ${t.usage.cacheRead.toLocaleString()} cache`:``}`,``,`**Features:** memory=${t.features.memory?`✓`:`✗`} · skills=${t.features.skills?`✓`:`✗`} · modelsRegistry=${t.features.modelsRegistry?`✓`:`✗`}`].join(`
|
|
18
|
+
`)})}function Nr(e){let t=e.payload,n=Math.floor(t.elapsedMs/1e3),r=n<60?`${n}s`:n<3600?`${Math.floor(n/60)}m ${n%60}s`:`${Math.floor(n/3600)}h ${Math.floor(n%3600/60)}m`;V.getState().addMessage({role:`assistant`,content:[`📈 **Session stats**`,``,`**Session:** \`${t.sessionId}\``,`**Provider/Model:** \`${t.provider}\` / \`${t.model}\``,`**Elapsed:** ${r}`,``,`**Usage:** ${t.usage.input.toLocaleString()} in · ${t.usage.output.toLocaleString()} out`,...t.cache&&t.cache.readTokens>0?[`**Cache:** ${t.cache.readTokens.toLocaleString()} read · ${t.cache.writeTokens.toLocaleString()} write · hit ratio ${(t.cache.hitRatio*100).toFixed(1)}%`]:[],`**Cost:** $${t.cost.toFixed(4)}`,``,`**Messages:** ${t.messages} · **Files read:** ${t.readFiles} · **Tools available:** ${t.tools}`].join(`
|
|
19
|
+
`)})}function Pr(e){let t=e.payload;U.getState().setTodos(t.todos??[])}function Fr(e){let t=e.payload;U.getState().setModes(t.modes.map(e=>({id:e.id,name:e.name,description:e.description}))),U.getState().setEnv({mode:t.activeId})}function Ir(e){let t=e.payload;U.getState().setContextModes(t.modes.map(e=>({id:e.id,name:e.name,description:e.description,thresholds:e.thresholds,preserveK:e.preserveK,eliseThreshold:e.eliseThreshold,custom:e.custom}))),U.getState().setEnv({contextMode:t.activeId})}function Lr(e){let t=e.payload;U.getState().setEnv({contextMode:t.id})}function Rr(e){let t=e.payload;Un.getState().setEntries(t.sessions??[],t.error??null)}function zr(e){let t=e.payload;V.getState().addMessage({role:`assistant`,content:`[${t.phase}] ${t.message}`,isError:!0}),V.getState().setLoading(!1)}function Br(e){let t=e.payload;Wn.getState().setSnapshot(t.worktrees??[],t.baseBranch??``)}function Vr(e){let t=e.payload;Wn.getState().pushEvent(t)}function Hr(e){Kn.getState().applyEvent(e.payload);let t=tr(`subagent.event`,e.payload);t&&(er.getState().pushEvent(t),er.getState().setActive(!0))}function Ur(e){let t=tr(e.type,e.payload);return t&&(er.getState().pushEvent(t),er.getState().setActive(!0)),e}function Wr(e){let t=e.payload;Yn.getState().setState({phases:Array.isArray(t.phases)?t.phases:void 0,activePhaseId:typeof t.activePhaseId==`string`?t.activePhaseId:void 0,overallPercent:typeof t.overallPercent==`number`?t.overallPercent:void 0,autonomous:typeof t.autonomous==`boolean`?t.autonomous:void 0,title:typeof t.title==`string`?t.title:void 0})}function Gr(e){let t=e.payload;Jn.getState().setGoal(t)}function Kr(e){let t=e.payload;Zn.getState().set(t)}function qr(e){let t=e.payload;if(t.error){G.getState().setError(t.error);return}G.getState().setTree(t.root,t.tree)}function Jr(e){let t=e.payload;if(t.error){G.getState().setError(t.error);return}G.getState().openFile(t.filePath,t.content)}function Yr(e){let t=e.payload;t.success?G.getState().markSaved(t.filePath):t.error&&G.getState().setError(`Save failed: ${t.error}`)}function Xr(){let e=B(H.getState().wsUrl);e?.send?.({type:`mailbox.messages`,payload:{limit:30}}),e?.send?.({type:`mailbox.agents`,payload:{}})}var Zr={"session.start":e=>{mr(e),Xr()},"context.debug":hr,"key.operation_result":gr,"context.compacted":_r,"provider.response":vr,"context.repaired":yr,"session.end":br,"iteration.started":xr,"provider.text_delta":Sr,"provider.thinking_delta":Cr,"tool.started":wr,"tool.progress":Tr,"tool.executed":Er,"tool.confirm_needed":Dr,"run.result":Or,"tools.list":kr,"memory.list":Ar,"skills.list":jr,"diag.get":Mr,"stats.get":Nr,"todos.updated":Pr,"tasks.updated":e=>{},"plan.updated":e=>{},"modes.list":Fr,"context.modes.list":Ir,"context.mode.changed":Lr,"sessions.list":Rr,error:zr,"worktree.state":Br,"worktree.event":Vr,"subagent.event":Hr,"goal.updated":Gr,"prefs.updated":Kr,"sessions.status_update":e=>{let t=tr(`sessions.status_update`,e.payload);t&&(er.getState().pushEvent(t),er.getState().setActive(!0))},"files.tree":qr,"files.read":Jr,"files.written":Yr,"autophase.state":Wr,"session.checkpoints":e=>{},"process.list":e=>{},"projects.list":e=>{},"projects.added":e=>{},"projects.selected":e=>{},"mailbox.event":e=>{let t=tr(`mailbox.event`,e.payload);t&&(er.getState().pushEvent(t),er.getState().setActive(!0)),Xr()},"mailbox.messages":e=>{let t=e.payload;t?.messages&&Vn.getState().setMessages(t.messages)},"mailbox.agents":e=>{let t=e.payload;t?.agents&&Vn.getState().setAgents(t.agents)},"mailbox.cleared":e=>{Vn.getState().setMessages([]),Xr()},"brain.status":e=>{let t=e.payload,n=[`🧠 **Brain** — policy → LLM decision chain`,``,`Autonomy ceiling: \`${t.maxAutoRisk}\` _(change with \`/brain risk <off|low|medium|high|all>\`)_`];if(t.log.length===0)n.push(``,`_No decisions recorded yet this session._`);else{n.push(``,`Recent decisions (${t.log.length}):`);for(let e of t.log.slice(-10)){let t=Math.max(0,Math.round((Date.now()-e.at)/1e3)),r=t<60?`${t}s`:t<3600?`${Math.round(t/60)}m`:`${Math.round(t/3600)}h`,i=e.question.length>70?`${e.question.slice(0,67)}…`:e.question;n.push(`- \`${r} ago\` **${e.kind}** — ${i}${e.outcome?` → _${e.outcome}_`:``}`)}}V.getState().addMessage({role:`assistant`,content:n.join(`
|
|
20
|
+
`)})},"brain.answer":e=>{let t=e.payload,n;if(t.decision.type===`answer`){let e=t.decision.rationale&&t.decision.rationale!==t.decision.text?`\n\n_${t.decision.rationale}_`:``;n=`🧠 ${t.decision.text??``}${e}`}else n=t.decision.type===`deny`?`🧠 Denied: ${t.decision.reason??``}`:`🧠 The Brain escalated this question back to you — it needs human judgement.`;V.getState().addMessage({role:`assistant`,content:n})},"brain.event":e=>{let t=e.payload;if(t.event===`brain.intervention`){let e=t.decision?.rationale??t.decision?.text??``,n=t.intervened?`🧠 **Brain intervention** — corrective guidance was sent to the agent.`:`🧠 **Brain check** — a distress signal was reviewed; no action needed.`;V.getState().addMessage({role:`assistant`,content:[n,t.request?.question??``,e?`_${e}_`:``].filter(Boolean).join(`
|
|
21
|
+
|
|
22
|
+
`)}),t.intervened&&X.info(`Brain intervened: agent steered`)}else t.event===`brain.decision_denied`&&X.warn(`Brain denied: ${t.decision?.reason??t.request?.question??`request`}`)},"working_dir.changed":e=>{let t=e.payload;U.getState().setEnv({cwd:t.cwd,projectRoot:t.projectRoot,projectName:t.projectRoot.split(/[/\\]/).pop()||t.projectRoot}),G.getState().setTreeLoading(!0),B().send({type:`files.tree`,payload:{path:t.cwd}})},"model.refine_result":e=>{let t=e.payload,n=W.getState().refinePanel;if(!n)return;if(t.error){X.error(`Refinement failed: ${t.error}`);let{original:e}=n;W.getState().setRefinePanel(null),V.getState().addMessage({role:`user`,content:e}),V.getState().setLoading(!0),B().send({type:`user_message`,payload:{id:`msg_${Date.now()}`,content:e,timestamp:Date.now()}});return}let r=n.original;if(yn(t.refined,r)){W.getState().setRefinePanel(null),V.getState().addMessage({role:`user`,content:r}),V.getState().setLoading(!0),B().send({type:`user_message`,payload:{id:`msg_${Date.now()}`,content:r,timestamp:Date.now()}});return}W.getState().setRefinePanel({...n,refined:t.refined,english:t.english})}};function Qr(e){let t=[];for(let[n,r]of Object.entries(Zr))t.push(e.on(n,r));return()=>{for(let e of t)e()}}function $r(){let{autoConnect:e,wsUrl:t}=H(),n=H(e=>e.setWsStatus),r=(0,z.useRef)(!1);(0,z.useEffect)(()=>{if(!e)return;On();let i=B(t),a=!1,o=i.onStatus(e=>{a||n(e)});if(i.connect().then(()=>{a||i.getPrefs()}).catch(e=>{a||console.warn(JSON.stringify({level:`warn`,event:`webui.ws_connection_failed`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))}),r.current)return()=>{a=!0,o()};r.current=!0;let s=Qr(i);return()=>{a=!0,s(),o()}},[e,t,n])}function Z(){let{wsUrl:e}=H(),t=B(e),n=(0,z.useCallback)(e=>t.isConnected?t.sendMessage(e):null,[t]),r=(0,z.useCallback)(()=>t.sendAbort(),[t]),{hideConfirm:i}=W(),a=(0,z.useCallback)((e,n)=>{t.sendConfirm(e,n),i()},[t,i]),o=(0,z.useCallback)((e,n)=>t.switchModel(e,n),[t]),s=(0,z.useCallback)(()=>t.listProviders(),[t]),c=(0,z.useCallback)(e=>t.listProviderModels(e),[t]),l=(0,z.useCallback)(()=>t.listSavedProviders(),[t]),u=(0,z.useCallback)((e,n,r)=>t.addKey(e,n,r),[t]),d=(0,z.useCallback)((e,n,r)=>t.updateKey(e,n,r),[t]),f=(0,z.useCallback)((e,n)=>t.deleteKey(e,n),[t]),p=(0,z.useCallback)((e,n)=>t.setActiveKey(e,n),[t]),m=(0,z.useCallback)((e,n,r,i)=>t.addProvider(e,n,r,i),[t]),h=(0,z.useCallback)(e=>t.removeProvider(e),[t]),g=(0,z.useCallback)(e=>{Un.getState().setLoading(!0),t.listSessions(e)},[t]),_=(0,z.useCallback)(e=>{Un.getState().removeEntry(e),t.deleteSession(e)},[t]),v=(0,z.useCallback)(e=>t.resumeSessionById(e),[t]),y=(0,z.useCallback)(()=>t.saveSession(),[t]),b=(0,z.useCallback)(()=>t.listTools(),[t]),x=(0,z.useCallback)(()=>t.listMemory(),[t]),S=(0,z.useCallback)(()=>t.listSkills(),[t]),C=(0,z.useCallback)(()=>t.getDiag(),[t]),w=(0,z.useCallback)(()=>t.getStats(),[t]),T=(0,z.useCallback)(()=>t.getPlan(),[t]),E=(0,z.useCallback)(()=>t.listModes(),[t]),D=(0,z.useCallback)(e=>t.switchMode(e),[t]),O=(0,z.useCallback)(()=>t.listContextModes(),[t]),k=(0,z.useCallback)(e=>t.switchContextMode(e),[t]),A=(0,z.useCallback)(e=>t.createContextMode(e),[t]),j=(0,z.useCallback)((e,n)=>t.updateContextMode(e,n),[t]),M=(0,z.useCallback)(e=>t.deleteContextMode(e),[t]),N=(0,z.useCallback)(()=>t.repairContext(),[t]),ee=(0,z.useCallback)(e=>t.refineModel(e),[t]),te=(0,z.useCallback)(e=>t.switchAutonomy(e),[t]),P=(0,z.useCallback)(e=>t.updatePrefs(e),[t]);return{client:t,sendMessage:n,sendAbort:r,sendConfirm:a,switchModel:o,listProviders:s,listProviderModels:c,listSavedProviders:l,addKey:u,updateKey:d,deleteKey:f,setActiveKey:p,addProvider:m,removeProvider:h,listSessions:g,deleteSession:_,resumeSession:v,saveSession:y,listTools:b,listMemory:x,listSkills:S,getDiag:C,getStats:w,getPlan:T,listModes:E,switchMode:D,listContextModes:O,switchContextMode:k,createContextMode:A,updateContextMode:j,deleteContextMode:M,repairContext:N,toggleAutoPhaseAutonomous:(0,z.useCallback)(e=>{t.send({type:`autophase.toggleAutonomous`,payload:{autonomous:e}})},[t]),startAutoPhase:(0,z.useCallback)((e,n,r=!0)=>{t.send({type:`autophase.start`,payload:{title:e,phases:n,autonomous:r}})},[t]),pauseAutoPhase:(0,z.useCallback)(()=>{t.send({type:`autophase.pause`,payload:{}})},[t]),resumeAutoPhase:(0,z.useCallback)(()=>{t.send({type:`autophase.resume`,payload:{}})},[t]),stopAutoPhase:(0,z.useCallback)(()=>{t.send({type:`autophase.stop`,payload:{}})},[t]),selectAutoPhase:(0,z.useCallback)(e=>{t.send({type:`autophase.selectPhase`,payload:{phaseId:e}})},[t]),switchAutonomy:te,updatePrefs:P,refineModel:ee}}var ei=(0,z.createContext)(void 0);function ti({children:e,defaultTheme:t=`system`,storageKey:n=`wrongstack-theme`}){let{setTheme:r}=H(),[i,a]=(0,z.useState)(()=>typeof window<`u`&&localStorage.getItem(n)||t);(0,z.useEffect)(()=>{let e=window.document.documentElement;if(e.classList.remove(`light`,`dark`),i===`system`){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`;e.classList.add(t)}else e.classList.add(i)},[i]);let o={theme:i,setTheme:e=>{localStorage.setItem(n,e),a(e),r(e)}};return(0,Y.jsx)(ei.Provider,{value:o,children:e})}function ni(){let e=(0,z.useContext)(ei);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e}var ri=[{id:`chat`,icon:(0,Y.jsx)(x,{size:16}),label:`Session`,shortcut:`Ctrl+1`,pairedView:`chat`},{id:`agents`,icon:(0,Y.jsx)(E,{size:16}),label:`Agents`,shortcut:`Ctrl+2`},{id:`history`,icon:(0,Y.jsx)(de,{size:16}),label:`History`,shortcut:`Ctrl+3`},{id:`files`,icon:(0,Y.jsx)(Xe,{size:16}),label:`Files`,shortcut:`Ctrl+4`,pairedView:`files`},{id:`projects`,icon:(0,Y.jsx)(Pt,{size:16}),label:`Projects`,shortcut:`Ctrl+5`},{id:`mailbox`,icon:(0,Y.jsx)(xe,{size:16}),label:`Mailbox`,shortcut:`Ctrl+6`}],ii=[{id:`autophase`,icon:(0,Y.jsx)(vt,{size:16}),label:`Phases`},{id:`agentflow`,icon:(0,Y.jsx)(st,{size:16}),label:`Flow`},{id:`settings`,icon:(0,Y.jsx)(rn,{size:16}),label:`Settings`}];function ai(e){let t=W.getState();if(!t.sidebarOpen)t.setSidebarOpen(!0),t.selectActivity(e);else if(t.activeActivity===e){t.setSidebarOpen(!1);return}else t.selectActivity(e);let n=ri.find(t=>t.id===e)?.pairedView;n&&t.currentView!==n&&t.setCurrentView(n)}var oi=ri.map(e=>e.id);function si(){let e=W(e=>e.activeActivity),t=W(e=>e.sidebarOpen),n=W(e=>e.currentView),r=W(e=>e.setCurrentView),i=U(e=>e.projectName),a=U(e=>e.cwd),o=H(e=>e.wsConnected),s=Kn(e=>Array.from(e.agents.values()).filter(e=>e.status===`running`).length),c=Vn(Hn),l=e=>{if(e===`agents`)return s||void 0;if(e===`mailbox`)return c||void 0};return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full w-12 shrink-0 border-r bg-card/60`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col items-center pt-2.5 pb-2 border-b border-border/50`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{W.getState().setSidebarOpen(!0),W.getState().selectActivity(`chat`),r(`chat`)},title:i?`${i} — return to chat`:`WrongStack — return to chat`,className:`relative w-8 h-8 rounded-md bg-primary flex items-center justify-center shadow-[0_0_0_1px_hsl(var(--primary)/0.4),0_2px_8px_-2px_hsl(var(--primary)/0.5)] hover:shadow-[0_0_0_1px_hsl(var(--primary)/0.6),0_3px_12px_-2px_hsl(var(--primary)/0.6)] transition-shadow`,children:(0,Y.jsx)(ye,{className:`h-4 w-4 text-primary-foreground`,strokeWidth:2.4})}),(0,Y.jsx)(`span`,{className:`mt-1.5 text-[8px] font-semibold tracking-tight text-muted-foreground text-center leading-tight w-10 truncate`,title:a||i||`WrongStack`,children:i||`WS`}),(0,Y.jsx)(`span`,{className:J(`mt-1 inline-block w-1.5 h-1.5 rounded-full`,o?`bg-[hsl(var(--success))] shadow-[0_0_4px_hsl(var(--success)/0.6)]`:`bg-[hsl(var(--warning))]`),title:o?`Connected`:`Disconnected`})]}),(0,Y.jsx)(`div`,{className:`flex flex-col items-center gap-0.5 pt-2`,children:ri.map(n=>(0,Y.jsx)(li,{icon:n.icon,label:`${n.label} (${n.shortcut})`,active:t&&e===n.id,badge:l(n.id),onClick:()=>ai(n.id)},n.id))}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5 pb-2 border-b border-border/50 mb-2`,children:[(0,Y.jsx)(li,{icon:(0,Y.jsx)(m,{size:16}),label:`Command palette (Ctrl+K)`,active:!1,onClick:()=>W.getState().setPaletteOpen(!0)}),(0,Y.jsx)(ci,{}),(0,Y.jsx)(li,{icon:(0,Y.jsx)(Wt,{size:16}),label:`Keyboard shortcuts (?)`,active:!1,onClick:()=>W.getState().setShortcutsOpen(!0)})]}),(0,Y.jsx)(`div`,{className:`flex flex-col items-center gap-0.5 pb-2`,children:ii.map(e=>(0,Y.jsx)(li,{icon:e.icon,label:e.label,active:n===e.id,onClick:()=>r(n===e.id?`chat`:e.id)},e.id))})]})}function ci(){let{theme:e,setTheme:t}=ni(),n=e===`light`?`dark`:e===`dark`?`system`:`light`;return(0,Y.jsx)(li,{icon:e===`light`?(0,Y.jsx)(lt,{size:16}):e===`dark`?(0,Y.jsx)(wt,{size:16}):(0,Y.jsx)(se,{size:16}),label:`Theme: ${e} — click for ${n}`,active:!1,onClick:()=>t(n)})}function li({icon:e,label:t,active:n,badge:r,onClick:i}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:i,title:t,className:J(`relative flex items-center justify-center w-10 h-10 rounded-lg transition-colors`,`text-muted-foreground hover:text-foreground hover:bg-muted/70`,n&&`text-primary bg-primary/10`),children:[n&&(0,Y.jsx)(`span`,{className:`absolute left-0 top-1/2 -translate-y-1/2 w-0.5 h-6 rounded-r-full bg-primary`}),(0,Y.jsx)(`span`,{className:`h-5 w-5`,children:e}),r!==void 0&&r>0&&(0,Y.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 min-w-[15px] h-[15px] flex items-center justify-center rounded-full bg-primary text-[8px] font-bold text-primary-foreground leading-none px-1 tabular`,children:r>99?`99+`:r})]})}function Q(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}function ui(e){return e>=75?`bg-destructive`:e>=60?`bg-[hsl(var(--warning))]`:`bg-[hsl(var(--success))]`}function di(e){return e>=75?`text-destructive`:e>=60?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`}function fi({pct:e,tokens:t,maxTokens:n,showTokens:r=!0,className:i,onClick:a}){let o=Math.max(0,Math.min(100,e)),s=`${Math.round(e)}%`,c=r&&t!==void 0&&n!==void 0&&n>0?` ${Q(t)}/${Q(n)}`:``;return(0,Y.jsxs)(`span`,{className:J(`inline-flex items-center gap-1.5`,a&&`cursor-pointer hover:opacity-80 transition-opacity`,i),title:(t!==void 0&&n!==void 0?`Context window: ${t.toLocaleString()} / ${n.toLocaleString()} tokens (${s})`:`Context window: ${s}`)+(a?` — click for breakdown`:``),onClick:a?e=>{e.stopPropagation(),a()}:void 0,onKeyDown:a?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),a())}:void 0,role:a?`button`:void 0,tabIndex:a?0:void 0,children:[(0,Y.jsx)(`span`,{className:`h-1.5 w-16 overflow-hidden rounded-full bg-muted shrink-0`,children:(0,Y.jsx)(`span`,{className:J(`h-full rounded-full transition-all duration-300`,ui(e)),style:{width:`${Math.max(2,o)}%`}})}),(0,Y.jsx)(`span`,{className:J(`text-[11px] font-mono tabular-nums font-medium`,di(e)),children:s}),c&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:c})]})}function pi({open:e,onClose:t}){let n=H(e=>e.wsUrl),{lastInputTokens:r,maxContext:i}=U(),[a,o]=(0,z.useState)(null),[c,l]=(0,z.useState)(!1),[u,d]=(0,z.useState)(null);if((0,z.useEffect)(()=>{if(!e){o(null),d(null);return}l(!0),d(null),o(null);let t=B(n);if(!t?.send){d(`WebSocket not connected`),l(!1);return}t.send({type:`context.debug`});let r=t.on(`context.debug`,e=>{e.type===`context.debug`&&(o(e.payload),l(!1))}),i=setTimeout(()=>{c&&(l(!1),d(`No debug data received. The server may not support context debugging.`))},5e3);return()=>{clearTimeout(i),r()}},[e,n]),(0,z.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),!e)return null;let f=i>0&&r>0?Math.min(100,Math.round(r/i*100)):0;return(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,children:(0,Y.jsxs)(`div`,{className:`w-full max-w-2xl max-h-[80vh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b sticky top-0 bg-card z-10`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(j,{className:`h-4 w-4 text-[hsl(var(--warning))]`}),`Context Breakdown`]}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Window Usage`}),(0,Y.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[Q(r),` / `,Q(i),` (`,f,`%)`]})]}),(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Context Mode`}),(0,Y.jsx)(`span`,{className:`block text-sm font-mono font-medium`,children:a?.mode??`—`})]})]}),c?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground py-4`,children:[(0,Y.jsx)(Je,{className:`h-4 w-4 animate-spin`}),`Fetching context breakdown…`]}):u?(0,Y.jsx)(`div`,{className:`rounded-md bg-destructive/10 border border-destructive/20 p-3 text-sm text-destructive`,children:u}):a?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,Y.jsx)(nn,{className:`h-3 w-3`}),`System Prompt`]}),(0,Y.jsx)(`span`,{className:`block text-sm font-mono font-medium`,children:Q(a.systemPrompt)})]}),(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,Y.jsx)(s,{className:`h-3 w-3`}),`Tools`]}),(0,Y.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[Q(a.tools.total),` (`,a.tools.count,`)`]})]}),(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,Y.jsx)(x,{className:`h-3 w-3`}),`Messages`]}),(0,Y.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[Q(a.messages.total),` (`,a.messages.count,`)`]})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:`Token Allocation`}),(0,Y.jsx)(`div`,{className:`mt-1.5 h-3 w-full overflow-hidden rounded-full bg-muted flex`,children:a.total>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`h-full bg-blue-500/70 transition-all`,style:{width:`${a.systemPrompt/a.total*100}%`},title:`System: ${Q(a.systemPrompt)}`}),(0,Y.jsx)(`span`,{className:`h-full bg-amber-500/70 transition-all`,style:{width:`${a.tools.total/a.total*100}%`},title:`Tools: ${Q(a.tools.total)}`}),(0,Y.jsx)(`span`,{className:`h-full bg-emerald-500/70 transition-all`,style:{width:`${a.messages.total/a.total*100}%`},title:`Messages: ${Q(a.messages.total)}`})]})}),(0,Y.jsxs)(`div`,{className:`flex gap-3 mt-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500/70`}),` System`]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-amber-500/70`}),` Tools`]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-500/70`}),` Messages`]})]})]}),a.tools.breakdown.length>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:`Tool Breakdown`}),(0,Y.jsx)(`div`,{className:`mt-1 space-y-0.5`,children:a.tools.breakdown.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-xs py-0.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.name}),(0,Y.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[e.tokens.toLocaleString(),` tok`]})]},e.name))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[`Messages (`,a.messages.count,`) — `,Q(a.messages.total),` tok`]}),(0,Y.jsx)(`div`,{className:`mt-1 space-y-0.5 max-h-40 overflow-y-auto`,children:a.messages.breakdown.slice(0,20).map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs py-0.5`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground font-mono w-6 text-right`,children:e.index}),(0,Y.jsx)(`span`,{className:`text-muted-foreground font-mono w-14`,children:e.role}),(0,Y.jsxs)(`span`,{className:`tabular-nums text-muted-foreground w-14`,children:[e.tokens.toLocaleString(),` tok`]}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/70 truncate flex-1`,children:e.preview.slice(0,80)})]},e.index))})]})]}):null]})]})})}function mi(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function hi(e){let t=Math.floor(e/1e3),n=Math.floor(t/3600),r=Math.floor(t%3600/60),i=t%60;return n>0?`${n}:${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`:`${String(r).padStart(2,`0`)}:${String(i).padStart(2,`0`)}`}var gi=[`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`];function _i(e,t,n=12,r=2e3){let i=Array(n).fill(0),a=t-n*r;for(let o of e){if(o<a||o>t)continue;let e=Math.floor((o-a)/r);e<0&&(e=0),e>=n&&(e=n-1),i[e]=(i[e]??0)+1}return i}function vi(e){if(e.length===0)return``;let t=Math.max(1,...e);return e.map(e=>e<=0?gi[0]:gi[Math.min(gi.length-1,Math.ceil(e/t*(gi.length-1)))]??gi[0]).join(``)}var yi={running:{icon:(0,Y.jsx)(`span`,{className:`led text-[hsl(var(--success))] led-pulse`}),color:`text-[hsl(var(--success))]`,label:`running`},idle:{icon:(0,Y.jsx)(`span`,{className:`led text-muted-foreground`}),color:`text-muted-foreground`,label:`idle`},completed:{icon:(0,Y.jsx)(F,{className:`h-3.5 w-3.5`}),color:`text-[hsl(var(--success))]`,label:`done`},failed:{icon:(0,Y.jsx)(a,{className:`h-3.5 w-3.5`}),color:`text-destructive`,label:`failed`},timeout:{icon:(0,Y.jsx)(de,{className:`h-3.5 w-3.5`}),color:`text-[hsl(var(--warning))]`,label:`timeout`},stopped:{icon:(0,Y.jsx)(`span`,{className:`led text-muted-foreground`}),color:`text-muted-foreground`,label:`stopped`}};function bi({agent:e,now:t}){let[n,r]=(0,z.useState)(!1),i=(0,z.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3)}catch{}},[]),a=e.status===`running`,o=e.currentTool,c=e.toolLog[0],l=vi(_i(e.toolLog.map(e=>e.at),t)),u=e.partialText||e.finalText||void 0,d=!e.finalText&&!!e.partialText;return(0,Y.jsxs)(`div`,{className:`rounded-lg border border-primary/30 bg-card p-4 space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-primary`,children:e.name}),(0,Y.jsx)(`span`,{className:J(`text-[10px] uppercase tracking-wider`,yi[e.status]?.color??`text-muted-foreground`),children:yi[e.status]?.label??e.status})]}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:a?hi(Math.max(0,t-e.startedAt)):`—`})]}),(l||c)&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[l&&(0,Y.jsx)(`span`,{className:`text-sm text-[hsl(var(--success))] font-mono tracking-[-0.1em]`,children:l}),c&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`last: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:c.name}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[` `,c.durationMs,`ms`]}),!c.ok&&(0,Y.jsx)(`span`,{className:`text-destructive ml-1`,children:`✗`})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-2 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground`,children:`Provider / Model`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,Y.jsx)(ln,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsxs)(`span`,{className:`text-[11px] font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]})]}),(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-2 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground`,children:`Iterations`}),(0,Y.jsxs)(`span`,{className:`block text-[11px] font-mono font-medium mt-0.5`,children:[`L`,Ci(e)]})]}),(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-2 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground`,children:`Tool Calls`}),(0,Y.jsxs)(`span`,{className:`block text-[11px] font-mono font-medium mt-0.5`,children:[e.toolCalls,`t`]})]}),(0,Y.jsxs)(`div`,{className:`rounded bg-muted/30 px-2 py-1.5 col-span-3`,children:[(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground`,children:`Cost Breakdown`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] font-mono font-medium text-[hsl(var(--success))]`,children:[mi(e.costUsd),` total`]}),e.ctxPct>0&&(0,Y.jsxs)(`span`,{className:`text-[11px] font-mono text-[hsl(var(--warning))]`,children:[`ctx `,e.ctxPct,`%`]})]})]})]}),e.maxContext>0&&(0,Y.jsx)(fi,{pct:e.ctxPct,tokens:e.ctxTokens,maxTokens:e.maxContext}),o&&a&&(0,Y.jsxs)(`div`,{className:`rounded-lg border border-primary/30 bg-primary/[0.04] px-3 py-2 flex items-center gap-2`,children:[(0,Y.jsx)(s,{className:`h-3.5 w-3.5 text-primary animate-pulse`}),(0,Y.jsx)(`span`,{className:`text-xs font-mono`,children:o}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:`running…`})]}),u?(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:d?`Live Output`:`Output`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(u),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:[n?(0,Y.jsx)(F,{className:`h-3 w-3 text-emerald-500`}):(0,Y.jsx)(_,{className:`h-3 w-3`}),n?`Copied`:`Copy`]})]}),(0,Y.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-48 overflow-y-auto`,children:u})]}):a?(0,Y.jsx)(`div`,{className:`rounded-lg border border-dashed border-border p-3 text-center`,children:(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`})}):null,e.extensions>0&&(0,Y.jsxs)(`div`,{className:`rounded-lg bg-[hsl(var(--warning))]/10 px-3 py-1.5 flex items-center gap-2`,children:[(0,Y.jsx)(ye,{className:`h-3.5 w-3.5 text-[hsl(var(--warning))]`}),(0,Y.jsxs)(`span`,{className:`text-xs`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.extensions}),` budget extension`,e.extensions===1?``:`s`]})]}),e.error&&(0,Y.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`}),(0,Y.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1`,children:e.error.message})]}),e.toolLog.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,Y.jsx)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5`,children:e.toolLog.slice(0,20).map((e,t)=>(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-2 rounded px-2 py-1 text-[10px]`,e.ok?`bg-muted/30`:`bg-destructive/5 border border-destructive/20`),children:[(0,Y.jsx)(`span`,{className:J(`led shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`)}),(0,Y.jsx)(`span`,{className:`font-mono truncate flex-1`,children:e.name}),(0,Y.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,Y.jsx)(`span`,{className:`text-destructive font-medium`,children:`fail`})]},`${e.name}-${e.at}-${t}`))})]})]})}function xi({agent:e,now:t,selected:n,onClick:r,onContextClick:i}){let a=yi[e.status]??yi.idle,o=e.status===`running`,s=e.provider&&e.model?`${e.provider}/${e.model}`:e.model??`—`,c=U(e=>e.projectName);return(0,Y.jsxs)(`button`,{type:`button`,onClick:r,className:J(`w-full text-left rounded-lg border px-3 py-2 transition-colors flex items-center gap-3`,n?`border-primary/50 bg-primary/[0.06]`:`border-border/60 hover:border-primary/30 hover:bg-primary/[0.03]`,e.status===`failed`||e.status===`timeout`?`opacity-80`:``),children:[(0,Y.jsx)(`span`,{className:J(`shrink-0`,n?`text-primary`:`text-muted-foreground/30`),children:n?(0,Y.jsx)(k,{className:`h-4 w-4`}):(0,Y.jsx)(`span`,{className:`w-4 inline-block`})}),(0,Y.jsx)(`span`,{className:a.color,children:a.icon}),(0,Y.jsx)(`span`,{className:J(`text-xs font-semibold min-w-0 truncate max-w-[8rem]`,n&&`text-primary`),children:e.name}),`sessionId`in e&&e.sessionId&&(0,Y.jsx)(`span`,{className:`shrink-0 text-[9px] font-mono text-muted-foreground/50 bg-muted/40 px-1 py-0.5 rounded select-none`,title:`Session: ${e.sessionId}${c?` · Project: ${c}`:``}`,children:e.sessionId.slice(0,8)}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono truncate max-w-[10rem] shrink`,children:s}),(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0`,children:[`L`,Ci(e),` `,e.toolCalls,`t`]}),e.ctxPct>0&&e.maxContext>0&&(0,Y.jsx)(`div`,{className:`shrink-0`,children:(0,Y.jsx)(fi,{pct:e.ctxPct,tokens:e.ctxTokens,maxTokens:e.maxContext,onClick:i})}),o&&e.currentTool&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-primary font-mono truncate max-w-[8rem] shrink`,children:[`→ `,e.currentTool]}),e.extensions>0&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-[hsl(var(--warning))] shrink-0`,children:[`⚡×`,e.extensions]}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums shrink-0 ml-auto`,children:o?hi(Math.max(0,t-e.startedAt)):yi[e.status]?.label??``}),e.costUsd>0&&(0,Y.jsx)(`span`,{className:`text-[10px] text-[hsl(var(--success))] tabular-nums font-medium shrink-0`,children:mi(e.costUsd)})]})}function Si(e){return e.id===`leader`?e.lastEventAt:e.completedAt??e.startedAt}function Ci(e){return e.id===`leader`?e.iterations:e.iteration}function wi({className:e}){let t=Kn(e=>e.agents),n=U(),{provider:r,model:i}=H(),a=V(e=>e.isLoading),o=V(e=>e.messages),[s,c]=(0,z.useState)(null),[l,u]=(0,z.useState)(Date.now()),[d,f]=(0,z.useState)(!1);(0,z.useEffect)(()=>{let e=setInterval(()=>u(Date.now()),1e3);return()=>clearInterval(e)},[]);let p=(0,z.useMemo)(()=>{let e=o.filter(e=>e.role===`tool`),t=a;return{id:`leader`,name:`LEADER`,sessionId:n.session?.id,provider:r,model:i,status:t?`running`:`idle`,iterations:0,toolCalls:e.length,costUsd:n.cost,ctxPct:n.maxContext>0?Math.min(100,Math.round(n.lastInputTokens/n.maxContext*100)):0,ctxTokens:n.lastInputTokens,maxContext:n.maxContext,startedAt:n.startTime??Date.now(),lastEventAt:Date.now(),extensions:0,toolLog:[]}},[r,i,n.cost,n.lastInputTokens,n.maxContext,n.startTime,n.session?.id,o,a]),m=(0,z.useMemo)(()=>{let e=t.get(`leader`),n=[e?{...p,status:e.status===`running`?`running`:p.status,iterations:e.iteration||p.iterations,toolCalls:e.toolCalls||p.toolCalls,costUsd:e.costUsd||p.costUsd,ctxPct:e.ctxPct,ctxTokens:e.ctxTokens,maxContext:e.maxContext||p.maxContext,extensions:e.extensions,currentTool:e.currentTool??e.lastTool,toolLog:e.toolLog,partialText:e.partialText,finalText:e.finalText,error:e.error,lastEventAt:e.completedAt??e.startedAt??p.lastEventAt}:p],r=Array.from(t.values()).filter(e=>e.id!==`leader`);return n.push(...r),n},[p,t]),h=(0,z.useMemo)(()=>[...m].sort((e,t)=>{let n=e.status===`running`?0:e.status===`idle`?1:2,r=t.status===`running`?0:t.status===`idle`?1:2;return n===r?n===2?Si(t)-Si(e):e.startedAt-t.startedAt:n-r}),[m]),g=(0,z.useMemo)(()=>{let e=0,t=0,n=0,r=0;for(let i of m)i.status===`running`?e++:i.status===`idle`?t++:i.status===`completed`?n++:r++;return{running:e,idle:t,completed:n,failed:r}},[m]),_=(0,z.useMemo)(()=>m.reduce((e,t)=>e+(t.costUsd??0),0),[m]),v=s?m.find(e=>e.id===s)??null:null,y=(0,z.useRef)(null);(0,z.useEffect)(()=>{let e=e=>{let t=e.target?.tagName?.toLowerCase();if(!(t===`input`||t===`textarea`))if(e.key===`ArrowDown`||e.key===`j`){e.preventDefault();let t=s?h.findIndex(e=>e.id===s):-1,n=h[Math.min(h.length-1,t+1)];n&&c(n.id)}else if(e.key===`ArrowUp`||e.key===`k`){e.preventDefault();let t=s?h.findIndex(e=>e.id===s):0,n=h[Math.max(0,t-1)];n&&c(n.id)}else e.key===`Escape`&&c(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s,h]);let b=(0,z.useMemo)(()=>{let e=new Map;for(let t of h)t.model&&!e.has(t.name)&&e.set(t.name,`${t.provider??`?`}/${t.model}`);return[...e.entries()].slice(0,4)},[h]);return(0,Y.jsxs)(`div`,{className:J(`flex flex-col h-full`,e),ref:y,children:[(0,Y.jsx)(`div`,{className:`border-b bg-card/95 backdrop-blur-sm shrink-0`,children:(0,Y.jsxs)(`div`,{className:`px-4 py-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-sm font-semibold flex items-center gap-1.5`,children:[(0,Y.jsx)(E,{className:`h-4 w-4 text-primary`}),`AGENTS · LIVE`]}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/40`,children:`│`}),g.running>0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-[hsl(var(--success))] font-medium`,children:[(0,Y.jsx)(`span`,{className:`led led-pulse text-[hsl(var(--success))]`}),g.running,` running`]}),(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[g.completed,` done`]}),g.failed>0&&(0,Y.jsxs)(`span`,{className:`text-[11px] text-destructive`,children:[g.failed,` failed`]}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:`j/k or ↑↓ to navigate · Esc to deselect`})]}),b.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`models`}),b.map(([e,t])=>(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[e,`:`,t]},e))]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`shown`}),(0,Y.jsx)(`span`,{className:`text-[10px] font-medium`,children:h.length}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`total`}),(0,Y.jsx)(`span`,{className:`text-[10px] text-[hsl(var(--success))] font-medium tabular-nums`,children:mi(_)}),(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`(leader `,mi(p.costUsd),` · fleet `,mi(_-p.costUsd),`)`]})]})]})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:h.length===0?(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,Y.jsx)(E,{className:`h-8 w-8 text-muted-foreground/40 mx-auto`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No agents running.`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:`Agents appear here when the fleet is active.`})]})}):(0,Y.jsx)(`div`,{className:`p-3 space-y-1.5`,children:(()=>{let e=new Map;for(let t of h){let n=(`sessionId`in t?t.sessionId:void 0)??`__unknown__`,r=e.get(n)??[];r.push(t),e.set(n,r)}let t=[...e.entries()],n=t.length>1,r=[];for(let[e,i]of t){if(n){let t=e===`__unknown__`?`Unknown session`:e.slice(0,8),n=i.length;r.push((0,Y.jsxs)(`button`,{type:`button`,className:`text-[9px] text-muted-foreground/50 font-mono px-1 pt-2 pb-0.5 uppercase tracking-wider hover:text-muted-foreground hover:bg-muted/30 rounded transition-colors cursor-pointer w-full text-left`,title:`Session: ${e} — click to copy ID`,onClick:async()=>{try{await navigator.clipboard.writeText(e)}catch{}},children:[t,e!==`__unknown__`&&(0,Y.jsx)(`span`,{className:`ml-1.5 text-[8px] opacity-60`,children:`session`}),(0,Y.jsxs)(`span`,{className:`ml-1 text-[8px] opacity-40`,children:[`· `,n,` agent`,n===1?``:`s`]})]},`grp-${e}`))}for(let e of i)r.push((0,Y.jsx)(xi,{agent:e,now:l,selected:e.id===v?.id,onClick:()=>c(s===e.id?null:e.id),onContextClick:()=>f(!0)},e.id))}return r})()})}),v&&(0,Y.jsxs)(`div`,{className:`border-t bg-card/50 shrink-0 max-h-[50vh] overflow-y-auto p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`───`}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-primary`,children:v.name}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`details ───`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>c(null),className:`ml-auto text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:`✕ close`})]}),(0,Y.jsx)(bi,{agent:v,now:l})]}),(0,Y.jsx)(pi,{open:d,onClose:()=>f(!1)})]})}var Ti={pending:{icon:(0,Y.jsx)(Et,{className:`w-4 h-4`}),color:`text-slate-400`,bg:`bg-slate-100 dark:bg-slate-800`,label:`Pending`},ready:{icon:(0,Y.jsx)(et,{className:`w-4 h-4`}),color:`text-blue-500`,bg:`bg-blue-50 dark:bg-blue-950`,label:`Ready`},running:{icon:(0,Y.jsx)(de,{className:`w-4 h-4 animate-spin`}),color:`text-amber-500`,bg:`bg-amber-50 dark:bg-amber-950`,label:`Running`},paused:{icon:(0,Y.jsx)(De,{className:`w-4 h-4`}),color:`text-orange-500`,bg:`bg-orange-50 dark:bg-orange-950`,label:`Paused`},completed:{icon:(0,Y.jsx)(F,{className:`w-4 h-4`}),color:`text-emerald-500`,bg:`bg-emerald-50 dark:bg-emerald-950`,label:`Completed`},failed:{icon:(0,Y.jsx)(a,{className:`w-4 h-4`}),color:`text-red-500`,bg:`bg-red-50 dark:bg-red-950`,label:`Failed`},skipped:{icon:(0,Y.jsx)(Rt,{className:`w-4 h-4`}),color:`text-slate-400`,bg:`bg-slate-100 dark:bg-slate-800`,label:`Skipped`}},Ei={critical:`bg-red-500`,high:`bg-orange-500`,medium:`bg-blue-500`,low:`bg-slate-400`};function Di(e){if(!e)return``;let t=Math.floor(e/6e4);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;return r>0?`${n}h ${r}m`:`${n}h`}function Oi({phases:e,activePhaseId:t,onPhaseClick:n,overallPercent:r,autonomous:i,onToggleAutonomous:a,className:o}){return(0,Y.jsxs)(`div`,{className:J(`flex flex-col h-full w-72 border-r border-border bg-card`,o),children:[(0,Y.jsxs)(`div`,{className:`p-4 border-b border-border`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Phases`}),(0,Y.jsx)(`button`,{type:`button`,onClick:a,className:J(`px-2 py-1 text-xs rounded-full transition-colors`,i?`bg-emerald-100 text-emerald-700 dark:bg-emerald-900 dark:text-emerald-300`:`bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400`),title:i?`Autonomous mode active — pause`:`Autonomous mode inactive — start`,children:i?`● Auto`:`○ Manual`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-xs text-muted-foreground`,children:[(0,Y.jsx)(`span`,{children:`Overall Progress`}),(0,Y.jsxs)(`span`,{children:[r,`%`]})]}),(0,Y.jsx)(`div`,{className:`h-2 bg-muted rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-emerald-500 transition-all duration-500 rounded-full`,style:{width:`${r}%`}})})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3 space-y-2`,children:e.map(e=>{let r=Ti[e.status];return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n?.(e.id),className:J(`w-full text-left rounded-lg border p-3 transition-all hover:shadow-sm`,e.id===t?`border-amber-300 bg-amber-50/50 dark:bg-amber-950/30 ring-1 ring-amber-200`:`border-border bg-card hover:bg-accent/50`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`span`,{className:J(`mt-0.5`,r.color),children:r.icon}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`div`,{className:J(`w-1.5 h-1.5 rounded-full`,Ei[e.priority])}),(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.name})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground truncate mt-0.5`,children:e.description})]})]}),(0,Y.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between text-xs`,children:[(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completedTasks,`/`,e.taskCount,` tasks`]}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.progressPercent,`%`]})]}),(0,Y.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:J(`h-full transition-all duration-500 rounded-full`,e.status===`completed`?`bg-emerald-500`:e.status===`failed`?`bg-red-500`:`bg-amber-500`),style:{width:`${e.progressPercent}%`}})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 text-xs text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{children:[`~`,e.estimateHours,`h`]}),e.actualDurationMs&&(0,Y.jsxs)(`span`,{children:[`· `,Di(e.actualDurationMs)]}),e.assignedAgents.length>0&&(0,Y.jsxs)(`span`,{children:[`· `,e.assignedAgents.length,` agent`,e.assignedAgents.length===1?``:`s`]})]})]},e.id)})})]})}var ki={pending:{icon:(0,Y.jsx)(Et,{className:`w-4 h-4`}),color:`text-muted-foreground`,label:`Pending`},in_progress:{icon:(0,Y.jsx)(de,{className:`w-4 h-4 animate-spin`}),color:`text-primary`,label:`In Progress`},blocked:{icon:(0,Y.jsx)(De,{className:`w-4 h-4`}),color:`text-[hsl(var(--warning))]`,label:`Blocked`},failed:{icon:(0,Y.jsx)(a,{className:`w-4 h-4`}),color:`text-destructive`,label:`Failed`},review:{icon:(0,Y.jsx)(Mt,{className:`w-4 h-4`}),color:`text-[hsl(var(--info))]`,label:`Review`},completed:{icon:(0,Y.jsx)(F,{className:`w-4 h-4`}),color:`text-[hsl(var(--success))]`,label:`Done`}},Ai={critical:`bg-destructive/15 text-destructive`,high:`bg-orange-500/15 text-orange-600 dark:text-orange-400`,medium:`bg-[hsl(var(--info)/0.15)] text-[hsl(var(--info))]`,low:`bg-muted text-muted-foreground`},ji={feature:`bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))]`,bugfix:`bg-destructive/15 text-destructive`,refactor:`bg-violet-500/15 text-violet-600 dark:text-violet-400`,docs:`bg-sky-500/15 text-sky-600 dark:text-sky-400`,test:`bg-primary/15 text-primary`,chore:`bg-muted text-muted-foreground`};function Mi(e){if(!e)return``;let t=Math.floor(e/6e4);if(t<60)return`${t}m`;let n=Math.floor(t/60),r=t%60;return r>0?`${n}h ${r}m`:`${n}h`}function Ni({phaseName:e,phaseStatus:t,tasks:n,onTaskClick:r,onTaskStatusChange:i,className:a}){let o={in_progress:n.filter(e=>e.status===`in_progress`),pending:n.filter(e=>e.status===`pending`||e.status===`blocked`),completed:n.filter(e=>e.status===`completed`),failed:n.filter(e=>e.status===`failed`),review:n.filter(e=>e.status===`review`)};return(0,Y.jsxs)(`div`,{className:J(`flex flex-col h-full bg-background`,a),children:[(0,Y.jsx)(`div`,{className:`p-4 border-b border-border`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:e}),(0,Y.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:[n.length,` tasks · `,n.filter(e=>e.status===`completed`).length,` completed`]})]}),(0,Y.jsx)(`div`,{className:J(`px-3 py-1 rounded-full text-xs font-medium`,t===`running`?`bg-primary/15 text-primary`:t===`completed`?`bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))]`:t===`failed`?`bg-destructive/15 text-destructive`:`bg-muted text-muted-foreground`),children:t===`running`?`Running`:t===`completed`?`Completed`:t===`failed`?`Failed`:t===`paused`?`Paused`:t===`ready`?`Ready`:`Pending`})]})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-6`,children:[`in_progress`,`pending`,`review`,`failed`,`completed`].map(e=>{let t=o[e];if(t.length===0)return null;let n={in_progress:`In Progress`,pending:`Pending`,review:`Review`,failed:`Failed`,completed:`Completed`}[e];return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-2`,children:[n,` (`,t.length,`)`]}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>{let t=ki[e.status];return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r?.(e.id),className:J(`w-full text-left rounded-lg border p-3 transition-all hover:shadow-sm hover:border-primary/40 cursor-pointer`,e.status===`in_progress`?`border-primary/40 bg-primary/5`:e.status===`completed`?`border-[hsl(var(--success)/0.35)] bg-[hsl(var(--success)/0.06)]`:e.status===`failed`?`border-destructive/40 bg-destructive/5`:`border-border bg-card`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`span`,{className:J(`mt-0.5`,t.color),children:t.icon}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:e.title}),(0,Y.jsx)(`span`,{className:J(`px-1.5 py-0.5 rounded text-[10px] font-medium`,Ai[e.priority]),children:e.priority}),(0,Y.jsx)(`span`,{className:J(`px-1.5 py-0.5 rounded text-[10px] font-medium`,ji[e.type]),children:e.type})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 line-clamp-2`,children:e.description})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 mt-2 text-xs text-muted-foreground`,children:[e.estimateHours&&(0,Y.jsxs)(`span`,{children:[`~`,e.estimateHours,`h`]}),e.actualHours&&(0,Y.jsxs)(`span`,{children:[`• `,e.actualHours,`h`]}),e.assignee&&(0,Y.jsxs)(`span`,{children:[`• `,e.assignee]}),e.startedAt&&(0,Y.jsxs)(`span`,{children:[`• `,Mi(Date.now()-e.startedAt)]})]}),e.tags.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:e.tags.map(e=>(0,Y.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,children:e},e))}),i&&e.status!==`completed`&&(0,Y.jsxs)(`div`,{className:`flex gap-1 mt-2`,children:[e.status!==`in_progress`&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.id,`in_progress`)},className:`px-2 py-0.5 text-[10px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,children:`Start`}),e.status===`in_progress`&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.id,`completed`)},className:`px-2 py-0.5 text-[10px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,children:`Complete`}),e.status!==`failed`&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),i(e.id,`failed`)},className:`px-2 py-0.5 text-[10px] rounded bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,children:`Fail`})]})]},e.id)})})]},e)})})]})}var Pi=[`#3b82f6`,`#06b6d4`,`#22c55e`,`#eab308`,`#f97316`,`#a855f7`,`#ec4899`],Fi=e=>e.replace(/^wstack\/ap\//,``);function Ii(e){return[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt).map((e,t)=>({handle:e,color:Pi[t%Pi.length],y:60+t*48}))}var Li={allocating:{dash:`4 4`,opacity:.4},active:{dash:`4 4`,opacity:.6},committing:{dash:`4 4`,opacity:.8},merging:{dash:`0`,opacity:.9},merged:{dash:`0`,opacity:1},"needs-review":{dash:`2 3`,opacity:.9},failed:{dash:`2 3`,opacity:.6}};function Ri({worktrees:e,baseBranch:t}){let n=Ii(e),r=Math.max(120,60+n.length*48+20);return(0,Y.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-[--color-border-dark] bg-[--color-card-dark]/40 p-3`,children:(0,Y.jsxs)(`svg`,{width:`100%`,height:r,viewBox:`0 0 600 ${r}`,className:`min-w-[420px]`,role:`img`,"aria-label":`Worktree branch graph off ${t||`HEAD`}`,children:[(0,Y.jsx)(`title`,{children:`Worktree branch graph off ${t||`HEAD`}`}),(0,Y.jsx)(`line`,{x1:40,y1:20,x2:40,y2:r-10,stroke:`#F93951`,strokeWidth:3}),(0,Y.jsx)(`text`,{x:36,y:14,fontSize:11,fill:`#9ca3af`,children:t||`HEAD`}),(0,Y.jsx)(`circle`,{cx:40,cy:20,r:5,fill:`#F93951`}),n.map(e=>{let n=Li[e.handle.status]??R(Li.active),r=e.handle.status===`merged`,i=e.handle.status===`needs-review`||e.handle.status===`failed`;return(0,Y.jsxs)(`g`,{className:`transition-all duration-500`,children:[(0,Y.jsx)(`path`,{d:`M 40 ${e.y-24} C 100 ${e.y-24}, 160 ${e.y}, 220 ${e.y}`,fill:`none`,stroke:e.color,strokeWidth:2,strokeDasharray:n.dash,opacity:n.opacity}),r?(0,Y.jsx)(`path`,{d:`M 220 ${e.y} C 160 ${e.y+20}, 100 ${e.y+24}, 40 ${e.y+24}`,fill:`none`,stroke:`#34d399`,strokeWidth:2,opacity:.9}):null,(0,Y.jsx)(`circle`,{cx:220,cy:e.y,r:5,fill:i?`#e879f9`:e.color}),(0,Y.jsx)(`text`,{x:232,y:e.y-6,fontSize:12,fill:`#e5e7eb`,fontFamily:`monospace`,children:Fi(e.handle.branch)}),(0,Y.jsx)(`text`,{x:232,y:e.y+10,fontSize:10,fill:`#9ca3af`,children:i?`⚠ ${e.handle.status}`:r?`✓ merged → ${t}`:`+${e.handle.insertions}/-${e.handle.deletions} · ${e.handle.ownerLabel}`})]},e.handle.handleId)})]})})}var zi={allocating:{icon:`○`,label:`allocating`,tint:`border-zinc-400/40`,dot:`bg-zinc-400`},active:{icon:`●`,label:`active`,tint:`border-amber-400/40`,dot:`bg-amber-400 animate-pulse`},committing:{icon:`◐`,label:`committing`,tint:`border-cyan-400/40`,dot:`bg-cyan-400 animate-pulse`},merging:{icon:`⇡`,label:`merging`,tint:`border-blue-400/40`,dot:`bg-blue-400 animate-pulse`},merged:{icon:`✓`,label:`merged`,tint:`border-emerald-400/40`,dot:`bg-emerald-400`},"needs-review":{icon:`⚠`,label:`conflict`,tint:`border-fuchsia-400/50`,dot:`bg-fuchsia-400`},failed:{icon:`✗`,label:`failed`,tint:`border-rose-400/50`,dot:`bg-rose-400`}};function Bi(e){return zi[e]??{icon:`?`,label:e,tint:`border-border`,dot:`bg-muted-foreground`}}var Vi=e=>e.replace(/^wstack\/ap\//,``);function Hi({worktrees:e,baseBranch:t}){if(e.length===0)return null;let n=[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt);return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-card/50 backdrop-blur-sm px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`font-semibold tracking-wide uppercase text-[10px]`,children:`Worktrees`}),(0,Y.jsx)(`span`,{className:`opacity-60`,children:`· base`}),(0,Y.jsx)(`code`,{className:`font-mono text-primary`,children:t||`HEAD`}),(0,Y.jsxs)(`span`,{className:`opacity-60`,children:[`· `,n.length,` isolated`]})]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:n.map(e=>{let t=Bi(e.status),n=e.status===`needs-review`,r=Math.min(100,e.insertions+e.deletions);return(0,Y.jsxs)(`div`,{className:J(`group relative flex items-center gap-3 rounded-lg border px-3 py-2 transition-all duration-500`,`bg-background/60 hover:bg-accent/20`,t.tint),children:[(0,Y.jsx)(`span`,{className:J(`h-2.5 w-2.5 shrink-0 rounded-full`,t.dot),"aria-hidden":!0}),(0,Y.jsx)(`code`,{className:`w-44 shrink-0 truncate font-mono text-sm`,children:Vi(e.branch)}),(0,Y.jsxs)(`span`,{className:`shrink-0 rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:[`⟵ `,e.ownerLabel]}),n?(0,Y.jsx)(`span`,{className:`font-mono text-xs font-bold text-fuchsia-400`,children:`CONFLICT`}):(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-xs transition-all duration-500`,children:[(0,Y.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,Y.jsxs)(`span`,{className:`text-rose-500`,children:[`-`,e.deletions]}),(0,Y.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[e.files,`f`]})]}),(0,Y.jsx)(`div`,{className:`ml-auto hidden h-1 w-24 overflow-hidden rounded-full bg-muted sm:block`,children:(0,Y.jsx)(`div`,{className:`h-full bg-gradient-to-r from-emerald-500 to-rose-500 transition-all duration-700`,style:{width:`${r}%`}})}),(0,Y.jsx)(`span`,{className:`w-20 shrink-0 text-right text-xs text-muted-foreground`,children:t.label}),e.recentActivity.length>0?(0,Y.jsxs)(`span`,{className:`absolute -bottom-2 left-9 max-w-[60%] truncate rounded bg-muted px-1.5 text-[10px] text-muted-foreground opacity-0 transition-opacity duration-300 group-hover:opacity-100`,children:[e.recentActivity[e.recentActivity.length-1]?.kind,`: `,e.recentActivity[e.recentActivity.length-1]?.text]}):null]},e.handleId)})})]})}var Ui=y(`inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,outline:`border border-input bg-background hover:bg-accent hover:text-accent-foreground`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-10 px-4 py-2`,sm:`h-9 rounded-md px-3`,lg:`h-11 rounded-md px-8`,icon:`h-10 w-10`}},defaultVariants:{variant:`default`,size:`default`}}),$=z.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},a)=>(0,Y.jsx)(r?O:`button`,{className:J(Ui({variant:t,size:n,className:e})),ref:a,...i}));$.displayName=`Button`;function Wi({onClose:e}){let{client:t}=Z(),n=Yn(e=>e.phases),r=Yn(e=>e.activePhaseId),i=Yn(e=>e.overallPercent),a=Yn(e=>e.autonomous),o=Yn(e=>e.title),s=Wn(e=>e.worktrees),c=Wn(e=>e.baseBranch),[l,u]=(0,z.useState)(``),[d,f]=(0,z.useState)(!1),[p,m]=(0,z.useState)(!1),h=n.length>0,g=(0,z.useCallback)(async()=>{let e=l.trim();!e||d||(f(!0),await new Promise(e=>setTimeout(e,100)),t?.send?.({type:`autophase.start`,payload:{title:e,autonomous:!0}}),f(!1))},[l,d,t]),_=(0,z.useCallback)(e=>{t?.send?.({type:`autophase.selectPhase`,payload:{phaseId:e}})},[t]),v=(0,z.useCallback)(()=>{t?.send?.({type:`autophase.toggleAutonomous`,payload:{}})},[t]),y=(0,z.useCallback)((e,n)=>{t?.send?.({type:`autophase.taskStatus`,payload:{taskId:e,status:n}})},[t]),b=n.find(e=>e.id===r),x=b?b.tasks??[]:[];return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full bg-background`,children:[(0,Y.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-2 border-b bg-card shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(P,{className:`h-5 w-5 text-muted-foreground`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:h&&o||`AutoPhase`}),h&&(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[n.length,` phase`,n.length===1?``:`s`,` · `,i,`% complete`]})]})]}),(0,Y.jsx)($,{variant:`ghost`,size:`icon`,onClick:e,children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]}),h?(0,Y.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Y.jsx)(Oi,{phases:n,activePhaseId:r??void 0,onPhaseClick:_,overallPercent:i,autonomous:a,onToggleAutonomous:v,className:`w-72 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:b?(0,Y.jsx)(Ni,{phaseName:b.name,phaseStatus:b.status,tasks:x.map(e=>({id:e.id,title:e.title,description:e.description,status:e.status,priority:e.priority||`medium`,type:e.type||`feature`,estimateHours:e.estimateHours,assignee:e.assignee,tags:e.tags??[]})),onTaskStatusChange:y}):(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center text-muted-foreground`,children:(0,Y.jsx)(`p`,{className:`text-sm`,children:`Select a phase from the left panel to view its tasks.`})})})]}):(0,Y.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-8`,children:(0,Y.jsxs)(`div`,{className:`max-w-lg w-full space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,Y.jsx)(vt,{className:`h-10 w-10 mx-auto text-primary/60`}),(0,Y.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Start a Phase Plan`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Describe what you want to build. WrongStack will plan phases and tasks, then execute them autonomously.`})]}),(0,Y.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),placeholder:`e.g. Build a REST API for user management with Express and SQLite...`,rows:5,className:`w-full rounded-lg border border-border bg-card px-4 py-3 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-primary/30 placeholder:text-muted-foreground/50`,onKeyDown:e=>{e.key===`Enter`&&(e.ctrlKey||e.metaKey)&&(e.preventDefault(),g())}}),(0,Y.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,Y.jsxs)($,{onClick:g,disabled:!l.trim()||d,className:`flex-1 gap-2`,children:[(0,Y.jsx)(et,{className:`h-4 w-4`}),d?`Starting…`:`Start AutoPhase`]})}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:`Ctrl+Enter to start · Phases execute sequentially with full agent tool access`})]})}),s.length>0&&(0,Y.jsxs)(`div`,{className:`border-t bg-card/50 shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 pt-2 text-xs`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>m(!1),className:J(`rounded px-2 py-0.5 border transition-colors`,p?`border-border text-muted-foreground hover:text-foreground`:`bg-primary/10 border-primary/30 text-primary`),children:`Lanes`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>m(!0),className:J(`rounded px-2 py-0.5 border transition-colors`,p?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:`Graph`})]}),(0,Y.jsx)(`div`,{className:`px-4 pb-3`,children:p?(0,Y.jsx)(Ri,{worktrees:s,baseBranch:c}):(0,Y.jsx)(Hi,{worktrees:s,baseBranch:c})})]})]})}var Gi=[{mode:`off`,label:`Off`,description:`Full manual control — agent waits for your input.`,icon:(0,Y.jsx)(De,{className:`h-3.5 w-3.5`})},{mode:`suggest`,label:`Suggest`,description:`Agent suggests next steps but waits for approval.`,icon:(0,Y.jsx)(te,{className:`h-3.5 w-3.5`})},{mode:`auto`,label:`Auto`,description:`Agent auto-proceeds after brief confirmation delay.`,icon:(0,Y.jsx)(et,{className:`h-3.5 w-3.5`})},{mode:`eternal`,label:`Eternal`,description:`Agent runs autonomously until goal is complete.`,icon:(0,Y.jsx)(Ve,{className:`h-3.5 w-3.5`})},{mode:`eternal-parallel`,label:`Eternal Parallel`,description:`Multi-agent autonomous execution — fleet mode.`,icon:(0,Y.jsx)(Ve,{className:`h-3.5 w-3.5`})}];function Ki({value:e,onChange:t,className:n,compact:r=!1}){let[i,a]=(0,z.useState)(!1),o=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!i)return;let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]),(0,z.useEffect)(()=>{if(!i)return;let e=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i]);let s=Gi.find(t=>t.mode===e);return(0,Y.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:J(`flex items-center gap-1 px-2 py-0.5 rounded-md border text-[11px] font-medium transition-colors hover:opacity-80`,e===`eternal`||e===`eternal-parallel`?`bg-rose-500/15 text-rose-600 dark:text-rose-400 border-rose-500/30`:e===`auto`?`bg-amber-500/15 text-amber-600 dark:text-amber-400 border-amber-500/30`:e===`suggest`?`bg-blue-500/15 text-blue-600 dark:text-blue-400 border-blue-500/30`:`bg-muted text-muted-foreground border-transparent`,n),title:`Autonomy: ${s?.label??e}`,children:[s?.icon,!r&&(0,Y.jsx)(`span`,{className:`truncate max-w-[7rem]`,children:s?.label??e}),(0,Y.jsx)(re,{className:`h-3 w-3 opacity-60`})]}),i&&(0,Y.jsxs)(`div`,{className:`absolute top-full mt-1 right-0 z-50 w-56 rounded-lg border bg-popover shadow-lg p-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1`,children:`Autonomy Mode`}),Gi.map(n=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{t(n.mode),a(!1)},className:J(`w-full flex items-start gap-2 px-3 py-2 rounded text-left transition-colors`,e===n.mode?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,Y.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:n.icon}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:n.label}),(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground leading-snug`,children:n.description})]}),e===n.mode&&(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary mt-2 shrink-0`})]},n.mode))]})]})}function qi(){let e=V.getState().messages,t=[],n=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`),r=U.getState().projectName||`chat`,i=U.getState().session?.title||r;t.push(`# ${i} — chat export`),t.push(`*Exported: ${new Date().toISOString()}*`),t.push(``);for(let n of e)if(n.role===`user`)t.push(`## 👤 User`),t.push(``),t.push(n.content),t.push(``);else if(n.role===`assistant`)t.push(`## 🤖 Assistant`),t.push(``),t.push(n.content),t.push(``);else if(n.role===`tool`){let e=n.isError?`❌`:n.toolResult===void 0?`⏳`:`✅`;t.push(`### 🔧 Tool: \`${n.toolName??`unknown`}\` ${e}`),n.toolInput!==void 0&&(t.push("```json"),t.push(JSON.stringify(n.toolInput,null,2)),t.push("```")),n.toolResult&&(t.push(`<details><summary>Output</summary>`),t.push(``),t.push("```"),t.push(n.toolResult),t.push("```"),t.push(`</details>`)),t.push(``)}let a=new Blob([t.join(`
|
|
23
|
+
`)],{type:`text/markdown`}),o=URL.createObjectURL(a),s=document.createElement(`a`);s.href=o,s.download=`${r.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}-chat-${n}.md`,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o)}function Ji(){let e=V.getState().messages,t=U.getState(),n=t.projectName||`chat`,r=escape(t.session?.title||n),i=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`),a=e=>e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`),o=e.map(e=>{if(e.role===`tool`){let t=e.isError?`❌`:e.toolResult===void 0?`⏳`:`✅`;return`
|
|
24
|
+
<section class="bubble tool ${e.isError?`error`:``}">
|
|
25
|
+
<header><span class="icon">🔧</span><code>${a(e.toolName??`tool`)}</code> ${t}</header>
|
|
26
|
+
${e.toolInput===void 0?``:`<details><summary>Input</summary><pre>${a(JSON.stringify(e.toolInput,null,2))}</pre></details>`}
|
|
27
|
+
${e.toolResult?`<details><summary>Output</summary><pre>${a(e.toolResult)}</pre></details>`:``}
|
|
28
|
+
</section>`}return`
|
|
29
|
+
<section class="bubble ${e.role===`user`?`user`:`assistant`}">
|
|
30
|
+
<header><span class="icon">${e.role===`user`?`👤`:`🤖`}</span><strong>${e.role===`user`?`User`:`Assistant`}</strong></header>
|
|
31
|
+
<pre class="content">${a(e.content)}</pre>
|
|
32
|
+
</section>`}),s=`<!doctype html>
|
|
33
|
+
<html lang="en"><head>
|
|
34
|
+
<meta charset="utf-8">
|
|
35
|
+
<title>${r} — chat export</title>
|
|
36
|
+
<style>
|
|
37
|
+
:root { color-scheme: light dark; }
|
|
38
|
+
body { font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; max-width: 920px; margin: 24px auto; padding: 0 16px; }
|
|
39
|
+
h1 { font-size: 20px; margin-bottom: 4px; }
|
|
40
|
+
.meta { color: #666; font-size: 12px; margin-bottom: 24px; }
|
|
41
|
+
.bubble { margin: 12px 0; padding: 10px 14px; border-radius: 10px; border: 1px solid #ddd; }
|
|
42
|
+
.bubble header { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #666; margin-bottom: 6px; }
|
|
43
|
+
.bubble header .icon { margin-right: 4px; }
|
|
44
|
+
.bubble.user { background: #eef4ff; border-color: #c8d8f5; }
|
|
45
|
+
.bubble.assistant { background: #fff; }
|
|
46
|
+
.bubble.tool { background: #fafafa; }
|
|
47
|
+
.bubble.tool.error { background: #fff5f5; border-color: #f5c8c8; }
|
|
48
|
+
pre.content, .bubble pre { white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; margin: 0; }
|
|
49
|
+
details summary { cursor: pointer; color: #555; font-size: 12px; }
|
|
50
|
+
details pre { margin-top: 6px; background: #f4f4f4; padding: 8px; border-radius: 6px; max-height: 360px; overflow: auto; }
|
|
51
|
+
@media (prefers-color-scheme: dark) {
|
|
52
|
+
body { background: #0d0d0f; color: #e6e6e6; }
|
|
53
|
+
.bubble { border-color: #2a2a2e; }
|
|
54
|
+
.bubble.user { background: #16213a; border-color: #2a3d6b; }
|
|
55
|
+
.bubble.assistant { background: #161618; }
|
|
56
|
+
.bubble.tool { background: #131315; }
|
|
57
|
+
.bubble.tool.error { background: #2a1717; border-color: #5c2a2a; }
|
|
58
|
+
details pre { background: #1a1a1c; }
|
|
59
|
+
.meta, .bubble header, details summary { color: #999; }
|
|
60
|
+
}
|
|
61
|
+
</style>
|
|
62
|
+
</head><body>
|
|
63
|
+
<h1>${r} — chat export</h1>
|
|
64
|
+
<div class="meta">
|
|
65
|
+
Exported ${new Date().toISOString()}${t.session?.provider?` · ${escape(t.session.provider)}/${escape(t.session.model)}`:``} · ${e.length} message${e.length===1?``:`s`}
|
|
66
|
+
</div>
|
|
67
|
+
${o.join(``)}
|
|
68
|
+
</body></html>`,c=new Blob([s],{type:`text/html;charset=utf-8`}),l=URL.createObjectURL(c),u=document.createElement(`a`);u.href=l,u.download=`${n.toLowerCase().replace(/[^a-z0-9]+/g,`-`)}-chat-${i}.html`,document.body.appendChild(u),u.click(),document.body.removeChild(u),URL.revokeObjectURL(l)}function Yi(){let e=W(e=>e.paletteOpen),t=W(e=>e.setPaletteOpen),n=W(e=>e.setCurrentView),r=H(e=>e.setTheme),{entries:i}=Un(),{addMessage:a,clearMessages:o}=V(),c=Z(),[l,u]=(0,z.useState)(``),[f,p]=(0,z.useState)(0),m=(0,z.useRef)(null);(0,z.useEffect)(()=>{e&&(u(``),p(0),requestAnimationFrame(()=>m.current?.focus()))},[e]),(0,z.useEffect)(()=>{let e=e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`){e.preventDefault(),t(!W.getState().paletteOpen);return}e.key===`Escape`&&W.getState().paletteOpen&&(e.preventDefault(),t(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let h=(0,z.useMemo)(()=>{let e=[{id:`help`,category:`Command`,label:`Show slash commands`,icon:ve,keywords:[`help`,`commands`,`?`],run:()=>{a({role:`assistant`,content:"Type `/` in the message box to see every slash command."})}},{id:`tools`,category:`Command`,label:`List tools`,icon:s,keywords:[`tools`,`list`],run:()=>c.listTools()},{id:`memory`,category:`Command`,label:`Show memory`,icon:Me,keywords:[`memory`,`remember`,`notes`],run:()=>c.listMemory()},{id:`skills`,category:`Command`,label:`List skills`,icon:xt,keywords:[`skills`],run:()=>c.listSkills()},{id:`diag`,category:`Command`,label:`Runtime diagnostics`,icon:en,keywords:[`diag`,`diagnostics`,`debug`],run:()=>c.getDiag()},{id:`stats`,category:`Command`,label:`Session stats (tokens, cache, cost)`,icon:_n,keywords:[`stats`,`tokens`,`cost`,`cache`],run:()=>c.getStats()},{id:`clear`,category:`Session`,label:`Clear context`,hint:`Wipe in-memory context, keep session id`,icon:Ue,keywords:[`clear`,`reset`,`wipe`],run:()=>{o(),c.client?.clearContext?.()}},{id:`new`,category:`Session`,label:`New session`,hint:`Brand-new on disk + memory`,icon:Mt,keywords:[`new`,`fresh`,`session`],run:()=>{c.client?.newSession?.(),n(`chat`)}},{id:`compact`,category:`Session`,label:`Compact context`,icon:d,keywords:[`compact`,`shrink`,`context`],run:()=>c.client?.compactContext?.()},{id:`repair-context`,category:`Session`,label:`Repair context`,hint:`Remove orphan tool protocol blocks`,icon:s,keywords:[`repair`,`context`,`tool_use`,`tool_result`],run:()=>c.client?.repairContext?.()},{id:`export`,category:`Session`,label:`Export chat as markdown`,icon:Ce,keywords:[`export`,`save`,`markdown`,`download`],run:()=>qi()},{id:`export-html`,category:`Session`,label:`Export chat as HTML`,hint:`Self-contained, opens in any browser`,icon:Ce,keywords:[`export`,`html`,`download`,`archive`],run:()=>Ji()},{id:`history`,category:`Command`,label:`Open history panel`,icon:Ge,keywords:[`history`,`sessions`],run:()=>{W.getState().setSidebarOpen(!0),W.getState().selectActivity(`history`)}},{id:`settings`,category:`Command`,label:`Open settings`,icon:rn,keywords:[`settings`,`config`],run:()=>n(`settings`)},{id:`model`,category:`Command`,label:`Change provider/model`,icon:ln,keywords:[`model`,`provider`,`change`],run:()=>W.getState().setModelSwitcherOpen(!0)},{id:`theme-light`,category:`Theme`,label:`Theme: Light`,icon:lt,keywords:[`theme`,`light`,`mode`],run:()=>r(`light`)},{id:`theme-dark`,category:`Theme`,label:`Theme: Dark`,icon:wt,keywords:[`theme`,`dark`,`mode`],run:()=>r(`dark`)},{id:`theme-system`,category:`Theme`,label:`Theme: Follow system`,icon:se,keywords:[`theme`,`system`,`auto`],run:()=>r(`system`)},{id:`compact-toggle`,category:`Command`,label:`Toggle compact density`,icon:ie,hint:`Ctrl+Shift+D`,keywords:[`compact`,`dense`,`density`,`size`],run:()=>W.getState().toggleCompactMode()},{id:`sound-toggle`,category:`Command`,label:H.getState().soundOnComplete?`Sound on completion: ON — turn off`:`Sound on completion: OFF — turn on`,icon:H.getState().soundOnComplete?Pe:Oe,hint:`Chime when a run finishes`,keywords:[`sound`,`audio`,`chime`,`notify`,`beep`],run:()=>{let e=!H.getState().soundOnComplete;H.getState().setSoundOnComplete(e),e&&lr()}}];for(let t of i.slice(0,10))t.isCurrent||e.push({id:`resume-${t.id}`,category:`Session`,label:`Resume: ${t.title||`(empty)`}`,hint:`${t.provider}/${t.model}`,icon:M,keywords:[`resume`,t.title,t.id,t.provider,t.model],run:()=>c.resumeSession(t.id)});return e},[i,c,n,r,a,o]),g=(0,z.useMemo)(()=>{let e=l.toLowerCase().trim();return e?h.filter(t=>[t.label,t.hint??``,t.category,...t.keywords??[]].join(` `).toLowerCase().includes(e)):h},[h,l]);if((0,z.useEffect)(()=>{f>=g.length&&p(0)},[g.length,f]),!e)return null;let _=e=>{e&&(t(!1),e.run())};return(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/60 backdrop-blur-sm flex items-start justify-center pt-[14vh] px-4`,onClick:()=>t(!1),onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,Y.jsxs)(`div`,{onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),className:`w-full max-w-2xl rounded-xl border bg-popover shadow-2xl overflow-hidden flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b`,children:[(0,Y.jsx)(ft,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`input`,{ref:m,value:l,onChange:e=>u(e.target.value),placeholder:`Search commands, sessions, settings…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`,onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),p(e=>(e+1)%Math.max(1,g.length))):e.key===`ArrowUp`?(e.preventDefault(),p(e=>(e-1+Math.max(1,g.length))%Math.max(1,g.length))):e.key===`Enter`&&(e.preventDefault(),_(g[f]))}}),(0,Y.jsx)(`kbd`,{className:`text-[10px] text-muted-foreground border rounded px-1.5 py-0.5`,children:`Esc`})]}),(0,Y.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto`,children:g.length===0?(0,Y.jsxs)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:[`No matches for "`,l,`"`]}):Xi(g,f,_,p)}),(0,Y.jsxs)(`div`,{className:`border-t px-4 py-2 text-[10px] uppercase tracking-wider text-muted-foreground flex items-center gap-3`,children:[(0,Y.jsx)(`span`,{children:`↑↓ navigate`}),(0,Y.jsx)(`span`,{children:`↵ select`}),(0,Y.jsx)(`span`,{children:`Esc dismiss`})]})]})})}function Xi(e,t,n,r){let i={};return e.forEach((e,t)=>{i[e.category]||(i[e.category]=[]),i[e.category]?.push({item:e,globalIdx:t})}),(0,Y.jsx)(`div`,{className:`p-1`,children:Object.entries(i).map(([e,i])=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:e}),i.map(({item:e,globalIdx:i})=>{let a=e.icon,o=i===t;return(0,Y.jsxs)(`button`,{type:`button`,onMouseEnter:()=>r(i),onClick:()=>n(e),className:J(`w-full flex items-center gap-3 px-3 py-2 rounded text-left text-sm transition-colors`,o?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,Y.jsx)(a,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`truncate`,children:e.label}),e.hint&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.hint})]}),o&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`↵`})]},e.id)})]},e))})}function Zi({query:e,onPick:t,onClose:n}){let r=Z(),i=H(e=>e.wsUrl),[a,o]=(0,z.useState)([]),[s,c]=(0,z.useState)(0),l=(0,z.useRef)(null),u=(0,z.useRef)(null);return(0,z.useEffect)(()=>{let e=B(i).on(`files.list`,e=>{let t=e.payload;o(t.files??[]),c(0),u.current?.resolve(t.files??[]),u.current=null});return()=>e()},[i]),(0,z.useEffect)(()=>(l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{r.client.listFiles(e,50)},80),()=>{l.current&&clearTimeout(l.current)}),[e,r.client]),(0,z.useEffect)(()=>{let e=e=>{if(e.key===`ArrowDown`)e.preventDefault(),c(e=>(e+1)%Math.max(1,a.length));else if(e.key===`ArrowUp`)e.preventDefault(),c(e=>(e-1+Math.max(1,a.length))%Math.max(1,a.length));else if(e.key===`Enter`||e.key===`Tab`){if(a.length===0)return;e.preventDefault(),t(R(a[s]))}else e.key===`Escape`&&(e.preventDefault(),n())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[a,s,t,n]),(0,Y.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 mb-2 rounded-lg border bg-popover shadow-md p-1 text-sm max-h-72 overflow-auto`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1 flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{children:[`@ Files `,e&&`· "${e}"`]}),(0,Y.jsx)(`span`,{children:`↑/↓ select · ↵ insert · Esc dismiss`})]}),a.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-2 text-xs text-muted-foreground italic`,children:e?`No files match "${e}"`:`Searching project…`}):a.map((e,n)=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>t(e),onMouseEnter:()=>c(n),className:J(`w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-2 font-mono text-xs`,n===s?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[e.includes(`/`)?(0,Y.jsx)(Kt,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Y.jsx)(nn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e})]},e))]})}var Qi=[{name:`/new`,category:`Session`,description:`Start a brand-new session (fresh on disk and in memory)`},{name:`/clear`,category:`Session`,description:`Wipe current context (keeps session id, disk record stays)`},{name:`/compact`,category:`Session`,description:`Shrink context — elide ancient tool output`},{name:`/compact!`,category:`Session`,description:`Aggressively shrink context now`},{name:`/repair`,category:`Session`,description:`Repair orphan tool-use / tool-result protocol blocks`},{name:`/save`,category:`Session`,description:`Force-flush the session (auto-saved already)`},{name:`/load`,category:`Session`,aliases:[`/resume`],description:`Resume a previous session from disk`},{name:`/export`,category:`Session`,description:`Download the current chat as markdown`},{name:`/debug`,category:`Inspect`,aliases:[`/context`],description:`Context size breakdown per section`},{name:`/tools`,category:`Inspect`,description:`List every registered tool the model can call`},{name:`/memory`,category:`Inspect`,description:`Manage memory: show, remember, forget, clear, stats`},{name:`/todos`,category:`Inspect`,description:`List current todos`},{name:`/stats`,category:`Inspect`,description:`Session stats: tokens, cost, elapsed`},{name:`/skill`,category:`Inspect`,aliases:[`/skills`],description:`List active skills`},{name:`/diag`,category:`Inspect`,description:`Runtime diagnostics (provider, tools, mode, usage)`},{name:`/agents`,category:`Inspect`,description:`Show status of spawned subagents`},{name:`/brain`,category:`Inspect`,description:`Brain status, risk ceiling (risk <level>), or decision support (ask <question>)`},{name:`/plan`,category:`Inspect`,description:`Strategic plan board: show, add, start, done, promote, clear`},{name:`/suggest`,category:`Inspect`,aliases:[`/next-steps`],description:`Ask the agent for concrete next steps`},{name:`/next`,category:`Inspect`,description:`Show or run numbered next-step suggestions`},{name:`/settings`,category:`Config`,aliases:[`/model`],description:`Open settings (provider/model/keys)`},{name:`/enhance`,category:`Config`,description:`Toggle prompt refinement before sending`},{name:`/abort`,category:`Config`,aliases:[`/stop`],description:`Abort the current run`},{name:`/help`,category:`App`,description:`Show every slash command and what it does`},{name:`/exit`,category:`App`,description:`Exit the session and close WebUI`}],$i=[`Session`,`Inspect`,`Config`,`App`];function ea(e){let t=e.toLowerCase();return t===`/`||t===``?Qi:Qi.filter(e=>e.name.startsWith(t)||(e.aliases?.some(e=>e.startsWith(t))??!1))}function ta(e,t){let n=t-1;for(;n>=0;){let r=R(e[n]);if(r===`@`){let r=n>0?e[n-1]:``;return n===0||/\s/.test(r??``)?{start:n,query:e.slice(n+1,t)}:null}if(/\s/.test(r))return null;n--}return null}var na=[{lang:`typescript`,patterns:[{regex:/:\s*(string|number|boolean|void|never|any|unknown|Promise|Array|Record|Map|Set)\b/,weight:4},{regex:/\b(interface|type|enum|namespace|implements|extends|as|satisfies|infer)\b/,weight:3},{regex:/\b(import|export)\s+/,weight:3},{regex:/\b(const|let|var)\s+\w+\s*[:=]/,weight:2},{regex:/=>/,weight:1},{regex:/\.tsx?['"]/,weight:2}]},{lang:`javascript`,patterns:[{regex:/\b(import|export|require)\s*[({]/,weight:3},{regex:/\b(const|let|var)\s+\w+\s*=\s*require/,weight:2},{regex:/\bmodule\.exports/,weight:3},{regex:/\.jsx?['"]/,weight:2}]},{lang:`python`,patterns:[{regex:/^\s*def\s+\w+\s*\(/,weight:4},{regex:/^\s*class\s+\w+.*:/,weight:3},{regex:/\bimport\s+\w+/,weight:2},{regex:/\bfrom\s+\w+\s+import/,weight:3},{regex:/\bprint\(/,weight:1},{regex:/\bself\./,weight:2},{regex:/if\s+__name__\s*==\s*['"]__main__['"]/,weight:4}]},{lang:`rust`,patterns:[{regex:/\bfn\s+\w+\s*[<(]/,weight:4},{regex:/\blet\s+mut\s/,weight:3},{regex:/\b(struct|enum|impl|trait|mod)\s+\w+/,weight:3},{regex:/\bpub\s+(fn|struct|enum)/,weight:3},{regex:/->\s*\w+/,weight:1},{regex:/::\w+/,weight:1}]},{lang:`go`,patterns:[{regex:/\bfunc\s+\w+\s*\(/,weight:4},{regex:/\bpackage\s+\w+/,weight:4},{regex:/\bimport\s*\(/,weight:3},{regex:/\b(err|nil)\b/,weight:2},{regex:/:=/,weight:2},{regex:/\bdefer\s/,weight:2}]},{lang:`json`,patterns:[{regex:/^\s*[{[]/,weight:3},{regex:/"[^"]+"\s*:\s*/,weight:3},{regex:/^\s*[}\]]\s*$/,weight:1}]},{lang:`yaml`,patterns:[{regex:/^---\s*$/,weight:4},{regex:/^\s*\w[\w.-]*:\s/,weight:2},{regex:/^\s*-\s+\w/,weight:1}]},{lang:`html`,patterns:[{regex:/<(!DOCTYPE|html|head|body|div|span|a|p|ul|li|table)/i,weight:4},{regex:/<\/?\w+[\s>]/,weight:2},{regex:/\b(class|id|href|src)="/,weight:2}]},{lang:`css`,patterns:[{regex:/[{]\s*$/,weight:1},{regex:/^\s*[.#@]\S+\s*[{]/,weight:3},{regex:/\b(\d+px|\d+em|\d+rem|\d+vh|\d+vw)\b/,weight:3},{regex:/:\s*\w+\s*!important/,weight:3},{regex:/@(media|keyframes|import|apply)/,weight:3}]},{lang:`sql`,patterns:[{regex:/\b(SELECT|INSERT|UPDATE|DELETE|CREATE TABLE|ALTER TABLE|DROP TABLE)\b/i,weight:4},{regex:/\bFROM\s+\w+/i,weight:2},{regex:/\bWHERE\s+/i,weight:2},{regex:/\b(JOIN|INNER JOIN|LEFT JOIN)\b/i,weight:2}]},{lang:`bash`,patterns:[{regex:/^#!\/.*(bash|sh|zsh)/,weight:5},{regex:/\becho\s/,weight:2},{regex:/\bexport\s+\w+=/,weight:2},{regex:/\bif\s+\[\[?\s/,weight:2},{regex:/\$\{?\w+/,weight:1},{regex:/&&|\|\|/,weight:1}]},{lang:`toml`,patterns:[{regex:/^\s*\[.*\]\s*$/,weight:3},{regex:/^\s*\w+\s*=\s*['"]/,weight:2},{regex:/^\s*\[\[.*\]\]\s*$/,weight:3}]}],ra=6,ia=3,aa=180;function oa(e){let t=e.split(`
|
|
69
|
+
`);if(t.length<ia)return!1;let n=0,r=0;for(let e of t){let t=e.trim();t.length!==0&&(t.length>aa&&r++,/^ {2,}/.test(e)&&n++,/[.!?]$/.test(t)&&r++,/[{}();=<>[\]]/.test(t)&&n++,/[#$]/.test(t)&&!/^# /.test(t)&&n++)}return n>=r&&n>=2}function sa(e){if(!oa(e))return null;let t={};for(let n of na){let r=0;for(let{regex:t,weight:i}of n.patterns){let n=e.match(new RegExp(t.source,t.flags.includes(`g`)?t.flags:`${t.flags}g`));n&&(r+=n.length*i)}r>0&&(t[n.lang]=r)}t.javascript&&t.typescript&&(t.typescript>=t.javascript?delete t.javascript:t.javascript>t.typescript&&delete t.typescript);let n=null,r=0;for(let[e,i]of Object.entries(t))i>r&&(r=i,n=e);return r>=ra?n:null}function ca(e){let t=e.trim();return/^```[\s\S]*```\s*$/.test(t)}function la(e){if(ca(e))return null;let t=sa(e);return t?{fenced:`\`\`\`${t}\n${e}\n\`\`\``,lang:t}:null}function ua({original:e,refined:t,english:n,onDecision:i,autoSendDelayMs:a=0}){let o=W(e=>e.setRefinePanel),[s,c]=(0,z.useState)(a>0?Math.ceil(a/1e3):null),[l,u]=(0,z.useState)(t),[d,f]=(0,z.useState)(!1),p=(0,z.useRef)(null),m=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!(a<=0||d))return p.current=setInterval(()=>{c(e=>e===null||e<=1?(clearInterval(p.current),i(`refined`),null):e-1)},1e3),()=>{p.current&&clearInterval(p.current)}},[a,d,i]),(0,z.useEffect)(()=>{let e=e=>{if(!(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement))switch(e.key){case`Enter`:d||(e.preventDefault(),i(`refined`));break;case`e`:case`E`:d||(e.preventDefault(),i(`english`));break;case`o`:case`O`:d||(e.preventDefault(),i(`original`));break;case`t`:case`T`:d||(e.preventDefault(),f(!0));break;case`Escape`:e.preventDefault(),d?(f(!1),u(t)):(o(null),i(`original`));break}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[d,i,t,o]),(0,z.useEffect)(()=>{d&&m.current&&m.current.querySelector(`textarea`)?.focus()},[d]);let h=e=>{p.current&&clearInterval(p.current),o(null),i(e)};return(0,Y.jsxs)(`div`,{ref:m,className:`rounded-lg border bg-card text-card-foreground shadow-sm overflow-hidden animate-message`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:`✨ Refine Prompt`}),s!==null&&!d&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`auto-send in `,s,`s`]})]}),(0,Y.jsx)(`button`,{onClick:()=>h(`original`),className:`text-muted-foreground hover:text-foreground transition-colors`,title:`Cancel (Esc)`,children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`div`,{className:`p-4 space-y-3`,children:d?(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`label`,{className:`text-xs text-muted-foreground font-medium`,children:`Edit refined prompt:`}),(0,Y.jsx)(`textarea`,{value:l,onChange:e=>u(e.target.value),className:`w-full min-h-[80px] rounded-md border border-input bg-background px-3 py-2 text-sm resize-none focus:outline-none focus:ring-2 focus:ring-ring`,placeholder:`Edit the refined prompt...`}),(0,Y.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,Y.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>{f(!1),u(t)},children:`Cancel`}),(0,Y.jsxs)($,{size:`sm`,onClick:()=>{l.trim()&&h(`edit`)},disabled:!l.trim(),children:[(0,Y.jsx)(be,{className:`h-3 w-3 mr-1`}),`Use Edit`]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground font-medium uppercase tracking-wider`,children:`Original`}),(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground bg-muted/30 rounded-md px-3 py-2`,children:e.length>200?e.slice(0,200)+`...`:e})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-yellow-600 dark:text-yellow-400 font-medium uppercase tracking-wider`,children:[`Refined `,(0,Y.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(your language)`})]}),(0,Y.jsx)(`div`,{className:J(`text-sm bg-yellow-500/10 border border-yellow-500/20 rounded-md px-3 py-2 cursor-pointer`,`hover:bg-yellow-500/20 transition-colors`),onClick:()=>h(`refined`),title:`Click or press Enter to use this version`,children:t.length>300?t.slice(0,300)+`...`:t})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 font-medium uppercase tracking-wider`,children:[(0,Y.jsx)(r,{className:`h-3 w-3`}),`English`]}),(0,Y.jsx)(`div`,{className:J(`text-sm bg-blue-500/10 border border-blue-500/20 rounded-md px-3 py-2 cursor-pointer`,`hover:bg-blue-500/20 transition-colors`),onClick:()=>h(`english`),title:`Press e to use English version`,children:n.length>300?n.slice(0,300)+`...`:n})]})]})}),!d&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-4 py-3 border-t bg-muted/20`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-1 text-xs text-muted-foreground`,children:[(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono`,children:`Enter`}),(0,Y.jsx)(`span`,{children:`refined`}),(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`e`}),(0,Y.jsx)(`span`,{children:`English`}),(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`o`}),(0,Y.jsx)(`span`,{children:`original`}),(0,Y.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`t`}),(0,Y.jsx)(`span`,{children:`edit`})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>h(`original`),className:`text-xs`,children:[(0,Y.jsx)(L,{className:`h-3 w-3 mr-1`}),`Original`]}),(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>f(!0),className:`text-xs`,children:[(0,Y.jsx)(un,{className:`h-3 w-3 mr-1`}),`Edit`]}),(0,Y.jsxs)($,{size:`sm`,onClick:()=>h(`refined`),className:`text-xs bg-yellow-600 hover:bg-yellow-700 text-white`,children:[(0,Y.jsx)(be,{className:`h-3 w-3 mr-1`}),`Use Refined`]})]})]})]})}function da({onOpenBreakdown:e}={}){let{isLoading:t,setLoading:n,addMessage:r,clearMessages:i}=V(),a=V(e=>e.queue),o=V(e=>e.enqueue),s=V(e=>e.removeQueued),c=V(e=>e.clearQueue),{setCurrentView:l}=W(),u=W(e=>e.pushPrompt),d=W(e=>e.promptHistory),p=Z(),{sendMessage:m,sendAbort:h,client:g,refineModel:_}=p,v=W(e=>e.refineEnabled),y=W(e=>e.refinePanel),b=W(e=>e.toggleRefineEnabled),x=W(e=>e.setRefinePanel),S=U(e=>e.lastInputTokens),C=U(e=>e.maxContext),[w,T]=(0,z.useState)(``),[E,D]=(0,z.useState)(0),[O,k]=(0,z.useState)(-1),[A,j]=(0,z.useState)(null),[M,N]=(0,z.useState)(null),[ee,te]=(0,z.useState)(!1),P=(0,z.useRef)(null),ne=(0,z.useCallback)(t=>{let a=t.trim(),o=a.indexOf(` `),s=(o===-1?a:a.slice(0,o)).toLowerCase(),c=o===-1?``:a.slice(o+1).trim(),u=s;switch(u){case`/help`:return r({role:`assistant`,content:[`📖 **Slash commands**`,``,...Qi.map(e=>`• \`${e.name}\`${e.aliases?.length?` (${e.aliases.map(e=>`\`${e}\``).join(`, `)})`:``} — ${e.description}`)].join(`
|
|
70
|
+
`)}),!0;case`/clear`:return i(),g?.clearContext?.(),!0;case`/new`:return g?.newSession?.(),!0;case`/exit`:return g?.send?.({type:`webui.shutdown`,payload:{}}),r({role:`assistant`,content:`👋 Shutting down WebUI server…`}),!0;case`/compact`:case`/compact!`:return g?.compactContext?.(u===`/compact!`),!0;case`/repair`:return g?.repairContext?.(),!0;case`/debug`:case`/context`:return e?.(),!0;case`/tools`:return p.listTools(),!0;case`/memory`:return p.listMemory(),!0;case`/skill`:case`/skills`:return p.listSkills(),!0;case`/diag`:return p.getDiag(),!0;case`/stats`:return p.getStats(),!0;case`/save`:return p.saveSession(),!0;case`/load`:case`/resume`:return p.listSessions(50),l(`sessions`),!0;case`/agents`:return l(`agents`),!0;case`/brain`:{let[e,...t]=c.split(/\s+/).filter(Boolean),n=(e??``).toLowerCase();if(n===`risk`)g?.send?.({type:`brain.risk`,payload:{level:(t[0]??``).toLowerCase()}});else if(n===`ask`){let e=t.join(` `).trim();e?g?.send?.({type:`brain.ask`,payload:{question:e}}):r({role:`assistant`,content:"Usage: `/brain ask <question>`"})}else g?.send?.({type:`brain.status`});return!0}case`/plan`:return p.getPlan(),l(`chat`),W.getState().setDockSection(`work`),!0;case`/todos`:{if(c.toLowerCase()===`clear`)return g?.clearTodos?.(),!0;let e=U.getState().todos;if(e.length===0)return r({role:`assistant`,content:`✅ **Todos** — _empty. Ask the agent to plan something and they'll show up here._`}),!0;let t=[`✅ **Todos** (${e.filter(e=>e.status===`completed`).length}/${e.length} done)`,``];for(let n of e){let e=n.status===`completed`?`[x]`:n.status===`in_progress`?`[~]`:`[ ]`,r=n.status===`in_progress`&&n.activeForm?n.activeForm:n.content;t.push(`- ${e} ${r}`)}return t.push(``,"_Use `/todos clear` to wipe the list._"),r({role:`assistant`,content:t.join(`
|
|
71
|
+
`)}),!0}case`/export`:return qi(),r({role:`assistant`,content:`📥 Chat exported to your downloads folder.`}),!0;case`/abort`:case`/stop`:return h(),n(!1),!0;case`/settings`:case`/model`:return l(`settings`),!0;case`/enhance`:{let e=!W.getState().refineEnabled;return b(),r({role:`assistant`,content:`Prompt refinement ${e?`enabled`:`disabled`}.`}),!0}case`/suggest`:case`/next-steps`:return oe(`What are the next steps I should take? Be specific and actionable.`),!0;case`/next`:{let e=c.trim().toLowerCase();return!e||e===`list`||e===`ls`||e===`show`?se():e===`clear`||e===`reset`?(r({role:`assistant`,content:`💡 _Suggestion list cleared._`}),!0):ce(c.trim())}default:return!1}},[r,i,g,h,n,l,b,p,e]),re=/💡\s*Next steps?\s*\n+((?:\d+\.\s+.+\n?)+)/i;function ie(e){let t=re.exec(e);if(!t?.[1])return[];let n=[];for(let e of t[1].split(`
|
|
72
|
+
`).filter(Boolean)){let t=/^(\d+)\.\s+(.+)$/.exec(e.trim());t&&n.push({index:Number.parseInt(t[1],10),text:t[2].trim()})}return n.slice(0,6)}function ae(){let e=V.getState().messages;for(let t=e.length-1;t>=0;t--){let n=e[t];if(n?.role===`assistant`&&n.content)return ie(n.content)}return[]}function oe(e){if(t){o(e);return}r({role:`user`,content:e}),m(e)&&n(!0)}function se(){let e=V.getState().messages,t=``;for(let n=e.length-1;n>=0;n--){let r=e[n];if(r?.role===`assistant`&&r.content){t=r.content;break}}let n=ie(t);if(n.length===0)return r({role:`assistant`,content:"💡 _No next-step suggestions found. Use `/suggest` to generate some._"}),!0;let i=[`💡 **Next steps**`,``];for(let e of n)i.push(`${e.index}. ${e.text}`);return i.push(``,"_Use `/next 1`, `/next 1 2 3` to execute._"),r({role:`assistant`,content:i.join(`
|
|
73
|
+
`)}),!0}function ce(e){let t=ae();if(t.length===0)return r({role:`assistant`,content:"💡 _No suggestions available. Use `/suggest` first._"}),!0;let n=e.split(/[\s,]+/).filter(Boolean).map(e=>Number.parseInt(e,10)).filter(e=>!Number.isNaN(e)&&e>0);if(n.length===0)return r({role:`assistant`,content:`💡 _No valid suggestion numbers._`}),!0;let i=n.filter(e=>e>t.length);if(i.length>0)return r({role:`assistant`,content:`💡 _Invalid suggestion(s): ${i.join(`, `)}. Valid range: 1–${t.length}._`}),!0;for(let e of n){let n=t[e-1];n&&oe(n.text)}return!0}let F=w.startsWith(`/`)&&!w.includes(` `)?ea(w):[];(0,z.useEffect)(()=>{E>=F.length&&D(0)},[F.length,E]);let le=(0,z.useCallback)(()=>{let e=P.current;e&&(e.value=``,e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,t||e.focus())},[t]),ue=(0,z.useCallback)(async e=>{if(e.preventDefault(),!w.trim())return;let i=w.trim();if(i.startsWith(`/`)&&ne(i)){u(i),T(``),k(-1),le();return}if(T(``),k(-1),le(),u(i),le(),t){o(i);return}try{g?.isConnected?v&&_?(x({original:i,refined:i,english:i,resolve:e=>{}}),_(i)):(r({role:`user`,content:i}),n(!0),m(i)):console.warn(JSON.stringify({level:`warn`,event:`ws_send_failed`,reason:`not_connected`,timestamp:new Date().toISOString()}))}catch(e){console.warn(JSON.stringify({level:`warn`,event:`ws_send_error`,error:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()})),n(!1)}},[w,t,o,g,m,_,v,x,r,n,ne,u,le]),de=(0,z.useCallback)(()=>{h(),n(!1)},[h,n]),fe=(0,z.useCallback)(()=>{h(),n(!1);let e=V.getState().messages;for(let t=e.length-1;t>=0;t--){let n=R(e[t]);if(n.role===`user`&&n.content){T(n.content),requestAnimationFrame(()=>{let e=P.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,e.focus(),e.setSelectionRange(n.content.length,n.content.length))});return}}},[h,n]),pe=(0,z.useCallback)(e=>{if(F.length===0&&!A&&d.length>0){if(e.key===`ArrowUp`){let t=e.currentTarget,n=t.value.slice(0,t.selectionStart);if(O>=0||n.indexOf(`
|
|
74
|
+
`)===-1){e.preventDefault();let t=Math.min(d.length-1,O+1);k(t);let n=d[t]??``;T(n),requestAnimationFrame(()=>{let e=P.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,e.setSelectionRange(n.length,n.length))});return}}if(e.key===`ArrowDown`&&O>=0){e.preventDefault();let t=O-1;if(t<0)k(-1),T(``);else{k(t);let e=d[t]??``;T(e),requestAnimationFrame(()=>{let t=P.current;t&&(t.style.height=`auto`,t.style.height=`${Math.min(t.scrollHeight,200)}px`,t.setSelectionRange(e.length,e.length))})}return}}if(F.length>0){if(e.key===`ArrowDown`){e.preventDefault(),D(e=>(e+1)%F.length);return}if(e.key===`ArrowUp`){e.preventDefault(),D(e=>(e-1+F.length)%F.length);return}if(e.key===`Tab`){e.preventDefault();let t=F[E];t&&(T(t.name+` `),D(0));return}if(e.key===`Enter`&&!e.shiftKey){let t=F[E];if(t&&t.name!==w.toLowerCase().trim()){e.preventDefault(),T(``),ne(t.name);return}}if(e.key===`Escape`){e.preventDefault(),T(``);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),ue(e))},[F,E,A,d,O,w,ne,ue]),me=()=>{let e=P.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)};return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[M&&(0,Y.jsxs)(`div`,{className:J(`rounded-md border px-2.5 py-1.5 text-xs flex items-center justify-between gap-2 animate-message`,M.lang?`border-emerald-500/30 bg-emerald-500/5 text-emerald-700 dark:text-emerald-300`:`border-amber-500/30 bg-amber-500/5 text-amber-700 dark:text-amber-300`),children:[(0,Y.jsx)(`span`,{children:M.lang?(0,Y.jsxs)(Y.Fragment,{children:[`Auto-fenced as`,` `,(0,Y.jsx)(`span`,{className:`font-mono font-semibold`,children:M.lang}),` — `,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:M.chars.toLocaleString()}),` chars`,` (`,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:M.lines}),` lines)`]}):(0,Y.jsxs)(Y.Fragment,{children:[`Pasted`,` `,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:M.chars.toLocaleString()}),` chars`,` (`,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:M.lines}),` lines) — fenced code blocks render best with `,(0,Y.jsx)(`span`,{className:`font-mono`,children:"```"}),`.`]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[M.undoFence&&(0,Y.jsx)(`button`,{type:`button`,onClick:M.undoFence,className:`underline underline-offset-2 hover:opacity-80`,title:`Remove fences and restore raw text`,children:`Undo`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>N(null),className:`opacity-60 hover:opacity-100 shrink-0`,title:`Dismiss`,children:`×`})]})]}),a.length>0&&(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium`,children:[`Queued (`,a.length,`)`]}),(0,Y.jsx)(`button`,{type:`button`,onClick:c,className:`text-muted-foreground hover:text-destructive text-xs`,children:`Clear all`})]}),(0,Y.jsx)(`ul`,{className:`space-y-1`,children:a.map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-start justify-between gap-2 rounded bg-background/60 border px-2 py-1`,children:[(0,Y.jsx)(`span`,{className:`truncate flex-1 min-w-0`,children:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:`text-muted-foreground hover:text-destructive shrink-0`,title:`Remove from queue`,children:`×`})]},t))})]}),y&&(0,Y.jsx)(ua,{original:y.original,refined:y.refined,english:y.english,onDecision:e=>{let{original:t,refined:i,english:a}=y,o=t;if(e===`refined`?o=i:e===`english`?o=a:e===`edit`&&(o=i),e===`edit`){T(i);return}x(null),g?.isConnected&&(r({role:`user`,content:o}),n(!0),m(o))}}),(0,Y.jsxs)(`form`,{onSubmit:ue,onDragEnter:e=>{!e.dataTransfer||!Array.from(e.dataTransfer.types).includes(`Files`)||(e.preventDefault(),te(!0))},onDragOver:e=>{!e.dataTransfer||!Array.from(e.dataTransfer.types).includes(`Files`)||(e.preventDefault(),e.dataTransfer.dropEffect=`copy`)},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||te(!1)},onDrop:e=>{if(!e.dataTransfer)return;let t=Array.from(e.dataTransfer.files??[]);if(t.length===0){te(!1);return}e.preventDefault(),te(!1);let n=P.current,r=n?.selectionStart??w.length,i=w.slice(0,r),a=w.slice(r),o=i.length>0&&!/\s$/.test(i)?` `:``,s=t.map(e=>`@${e.name}`),c=s.join(` `),l=a.length===0||!/^\s/.test(a)?` `:``,u=`${o}${c}${l}`;T(i+u+a);let d=i.length+o.length+s.slice(0,-1).join(` `).length+ +(s.length>1),f=t[t.length-1]?.name;requestAnimationFrame(()=>{if(n){let e=i.length+u.length-l.length;n.focus(),n.setSelectionRange(e,e),n.style.height=`auto`,n.style.height=`${Math.min(n.scrollHeight,200)}px`}j({start:d,query:f})})},className:J(`flex items-end gap-2 relative rounded-lg transition-colors`,ee&&`ring-2 ring-primary ring-offset-2 ring-offset-background bg-primary/5`),children:[ee&&(0,Y.jsxs)(`div`,{className:`absolute inset-0 z-20 flex items-center justify-center pointer-events-none rounded-lg bg-primary/10 text-primary text-sm font-medium`,children:[`Drop file`,`(s)`,` to attach as @-mention`]}),(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[A&&(0,Y.jsx)(Zi,{query:A.query,onClose:()=>j(null),onPick:e=>{let t=w.slice(0,A.start),n=w.slice(A.start+1+A.query.length),r=`@${e} `;T(t+r+n),j(null),requestAnimationFrame(()=>{let e=P.current;if(e){let n=t.length+r.length;e.focus(),e.setSelectionRange(n,n),e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`}})}}),!A&&F.length>0&&(()=>{let e={};F.forEach((t,n)=>{e[t.category]||(e[t.category]=[]),e[t.category]?.push({cmd:t,idx:n})});let t=$i.filter(t=>e[t]?.length);return(0,Y.jsxs)(`div`,{className:`absolute bottom-full left-0 right-0 mb-2 rounded-lg border bg-popover shadow-md p-1 text-sm max-h-72 overflow-auto`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-1 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1`,children:`↑/↓ select · Tab complete · Enter dispatch · Esc dismiss`}),t.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 pt-1 pb-0.5 text-[10px] uppercase tracking-wider text-muted-foreground/70 font-semibold`,children:t}),e[t]?.map(({cmd:e,idx:t})=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{T(``),ne(e.name)},onMouseEnter:()=>D(t),className:J(`w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-3`,t===E?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,Y.jsx)(`span`,{className:`font-mono shrink-0`,children:e.name}),e.aliases?.length?(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground/70 font-mono shrink-0`,children:[`(`,e.aliases.join(`, `),`)`]}):null,(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground truncate`,children:[`— `,e.description]})]},e.name))]},t))]})})(),(0,Y.jsx)(`textarea`,{ref:P,value:w,onChange:e=>{let t=e.target.value;T(t),me(),O>=0&&k(-1),j(ta(t,e.target.selectionStart??t.length))},onSelect:e=>{let t=e.currentTarget;j(ta(t.value,t.selectionStart))},onKeyDown:pe,onPaste:e=>{let t=e.clipboardData?.getData(`text`)??``;if(!t)return;let n=la(t);if(n){e.preventDefault();let r=P.current;if(!r)return;let i=r.selectionStart,a=r.selectionEnd,o=w.slice(0,i),s=w.slice(a),c=n.fenced;T(o+c+s);let l=t.split(`
|
|
75
|
+
`).length;N({chars:t.length,lines:l,lang:n.lang,undoFence:()=>{T(o+t+s),N(null),requestAnimationFrame(()=>{r&&(r.focus(),r.style.height=`auto`,r.style.height=`${Math.min(r.scrollHeight,200)}px`)})}}),setTimeout(()=>N(null),6e3),requestAnimationFrame(()=>{r.style.height=`auto`,r.style.height=`${Math.min(r.scrollHeight,200)}px`;let e=o.length+c.length;r.setSelectionRange(e,e)});return}if(t.length>800){let e=t.split(`
|
|
76
|
+
`).length;N({chars:t.length,lines:e}),setTimeout(()=>N(null),4e3)}},placeholder:g?.isConnected?t?`Agent is running — type to queue a follow-up…`:`Message the agent… (type / for commands, @ for files)`:`Connect to server first…`,className:J(`flex min-h-[44px] w-full resize-none rounded-lg border border-input bg-background px-4 py-3 pr-12`,`text-sm ring-offset-background placeholder:text-muted-foreground`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,`disabled:cursor-not-allowed disabled:opacity-50`,`scrollbar-thin`),rows:1,disabled:!g?.isConnected}),w.length>0&&(()=>{let e=w.length>=400,t=Math.ceil(w.length/4),n=`text-muted-foreground`,r;if(C>0&&e){let e=(S+t+64)/C*100;e>=100?(n=`text-red-600 dark:text-red-400 font-medium`,r=`Projected ${Math.round(e)}% of ${C.toLocaleString()} ctx — will likely error or compact.`):e>=85?(n=`text-amber-600 dark:text-amber-400 font-medium`,r=`Projected ${Math.round(e)}% of ${C.toLocaleString()} ctx — getting tight.`):r=`≈ ${t.toLocaleString()} tokens · projected ${Math.round(e)}% of ${C.toLocaleString()} ctx.`}else e&&(r=`≈ ${t.toLocaleString()} tokens (4-char heuristic)`);return(0,Y.jsxs)(`span`,{className:J(`absolute bottom-1.5 right-12 text-xs tabular-nums`,n),title:r,children:[w.length,e&&(0,Y.jsxs)(`span`,{className:`ml-1 opacity-70`,children:[`· ≈`,t>=1e3?`${(t/1e3).toFixed(1)}k`:t,`t`]})]})})()]}),(0,Y.jsx)(`div`,{className:`flex gap-1`,children:t?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)($,{type:`button`,size:`icon`,variant:`outline`,onClick:fe,className:`h-[44px] w-[44px] rounded-lg`,title:`Stop run and edit the last prompt (reuse + rewrite)`,children:(0,Y.jsx)(f,{className:`h-4 w-4`})}),(0,Y.jsx)($,{type:`button`,size:`icon`,variant:`destructive`,onClick:de,className:`h-[44px] w-[44px] rounded-lg`,title:`Abort the current run`,children:(0,Y.jsx)(qt,{className:`h-4 w-4 fill-current`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)($,{type:`button`,size:`icon`,variant:v?`default`:`outline`,disabled:!g?.isConnected,onClick:b,className:J(`h-[44px] w-[44px] rounded-lg transition-colors`,v&&`bg-yellow-500/20 hover:bg-yellow-500/30 text-yellow-600 dark:text-yellow-400 border-yellow-500/50`),title:v?`Refining enabled — click to disable`:`Refining disabled — click to enable`,children:(0,Y.jsx)(xt,{className:`h-4 w-4`})}),(0,Y.jsx)($,{type:`submit`,size:`icon`,disabled:!w.trim()||!g?.isConnected,className:`h-[44px] w-[44px] rounded-lg`,children:(0,Y.jsx)(ot,{className:`h-4 w-4`})})]})})]})]})}function fa({open:e,onClose:t,className:n}){let[r,i]=(0,z.useState)([]),[a,o]=(0,z.useState)(!1),s=Z(),c=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!(!e||!s.client?.isConnected))return s.client.send?.({type:`session.checkpoints`}),c.current=s.client.on?.(`session.checkpoints`,e=>{let t=e?.payload;t?.checkpoints&&i(t.checkpoints)})??null,()=>{c.current?.()}},[e,s.client]);let l=(0,z.useCallback)(async e=>{o(!0),s.client.send?.({type:`session.rewind`,payload:{checkpointIndex:e}}),setTimeout(()=>{t(),o(!1)},800)},[s.client,t]);return e?(0,Y.jsx)(`div`,{className:J(`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,n),onClick:e=>{e.target===e.currentTarget&&t()},children:(0,Y.jsxs)(`div`,{className:`w-full max-w-md rounded-xl border bg-card shadow-2xl max-h-[75vh] flex flex-col animate-in fade-in zoom-in-95`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Y.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-lg bg-violet-500/10 text-violet-600 dark:text-violet-400`,children:(0,Y.jsx)(Ge,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Session Checkpoints`}),(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[r.length,` checkpoint`,r.length===1?``:`s`]})]})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`div`,{className:`px-4 py-2.5 border-b bg-muted/20 text-[10px] text-muted-foreground leading-relaxed`,children:`Rewind the session to any checkpoint. Messages and file changes revert to that point — the LLM continues from there as if nothing happened after.`}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,Y.jsx)(de,{className:`h-10 w-10 opacity-15`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:`No checkpoints yet`}),(0,Y.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:`Checkpoints are automatically created each time you send a message. Send a few messages and come back.`})]}):(0,Y.jsx)(`div`,{className:`py-1`,children:[...r].reverse().map((e,t)=>{let n=t===0;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>l(e.index),disabled:a,className:J(`w-full flex items-start gap-3 px-4 py-3 text-left transition-colors group`,n?`bg-primary/5 hover:bg-primary/10`:`hover:bg-accent/40`,a&&`opacity-50 pointer-events-none`),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col items-center mt-1.5`,children:[(0,Y.jsx)(`div`,{className:J(`w-2.5 h-2.5 rounded-full border-2 shrink-0 transition-colors`,n?`border-primary bg-primary/20 shadow-[0_0_0_3px_hsl(var(--primary)/0.1)]`:`border-muted-foreground/30 bg-background group-hover:border-primary/40`)}),t<r.length-1&&(0,Y.jsx)(`div`,{className:`w-px flex-1 min-h-[20px] bg-border/50`})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground tabular-nums shrink-0`,children:[`#`,e.index]}),(0,Y.jsx)(`span`,{className:`text-xs font-medium truncate`,children:e.label}),n&&(0,Y.jsx)(`span`,{className:`text-[9px] px-1.5 py-0.5 rounded-full bg-primary/10 text-primary font-medium shrink-0`,children:`latest`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[e.messageCount,` msg`,e.messageCount===1?``:`s`]}),(0,Y.jsx)(`span`,{children:`·`}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[`~`,e.tokens.toLocaleString(),` tok`]}),(0,Y.jsx)(`span`,{children:`·`}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[`iter `,e.iteration]})]})]}),(0,Y.jsx)(`span`,{className:`shrink-0 mt-1.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Y.jsx)(ht,{className:`h-4 w-4 text-violet-500`})})]},e.index)})})}),(0,Y.jsxs)(`div`,{className:`border-t px-4 py-2 text-[10px] text-muted-foreground text-center shrink-0`,children:[`Click any checkpoint to rewind ·`,` `,(0,Y.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted font-mono text-[9px]`,children:`Esc`}),` to close`]})]})}):null}var pa=[{id:`balanced`,name:`Balanced`,description:`Default rolling compaction`,thresholds:{warn:.6,soft:.75,hard:.9},preserveK:10,eliseThreshold:2e3}];function ma(){let e=U(e=>e.contextMode),t=U(e=>e.contextModes),{listContextModes:n,switchContextMode:r}=Z(),[i,a]=(0,z.useState)(!1),o=(0,z.useRef)(null);(0,z.useEffect)(()=>{i&&n()},[i,n]),(0,z.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=t.length>0?t:pa,c=s.find(t=>t.id===e)??R(s[0]);return(0,Y.jsxs)(`div`,{ref:o,className:`relative shrink-0`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:J(`flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-emerald-500/10 text-emerald-700 dark:text-emerald-300 hover:bg-emerald-500/15 transition-colors border border-transparent hover:border-emerald-500/30`),title:`Context-window mode`,children:[(0,Y.jsx)(Qt,{className:`h-3 w-3`}),`ctx: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e||c.id}),(0,Y.jsx)(re,{className:`h-3 w-3 opacity-60`})]}),i&&(0,Y.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 w-80 rounded-md border bg-popover shadow-lg z-30 py-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Context Window`}),s.map(t=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{r(t.id),a(!1)},className:J(`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2`,t.id===e&&`bg-accent/30`),children:[(0,Y.jsx)(be,{className:J(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-mono`,children:t.id}),t.thresholds?.warn!==void 0&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[Math.round(t.thresholds.warn*100),`/`,Math.round(t.thresholds.soft*100),`/`,Math.round(t.thresholds.hard*100),`%`]})]}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description}),(t.preserveK||t.eliseThreshold)&&(0,Y.jsxs)(`div`,{className:`mt-1 text-[10px] text-muted-foreground/80`,children:[`keep `,t.preserveK??`-`,` recent · elide `,t.eliseThreshold??`-`,`+ tokens`]})]})]},t.id))]})]})}function ha(){let e=U(e=>e.cost),t=U(e=>e.inputCost),n=U(e=>e.outputCost),r=U(e=>e.cacheReadCost),i=V(e=>e.messages),[a,o]=(0,z.useState)(!1),s=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!a)return;let e=e=>{s.current?.contains(e.target)||o(!1)},t=e=>{e.key===`Escape`&&o(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]);let c=(()=>{let e=[];for(let t of i)t.role===`assistant`&&t.runSummary&&t.runSummary.costDelta>0&&e.push({id:t.id,preview:t.content.slice(0,80).replace(/\s+/g,` `).trim()||`(empty)`,cost:t.runSummary.costDelta,tools:t.runSummary.tools,ms:t.runSummary.durationMs,ts:t.timestamp});return e.sort((e,t)=>t.cost-e.cost),e.slice(0,5)})(),l=e=>e>=.01?`$${e.toFixed(4)}`:e>0?`$${e.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:`$0`,u=t>0||n>0;return(0,Y.jsxs)(`div`,{ref:s,className:`relative inline-block`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:J(`font-medium text-green-600 dark:text-green-400 hover:underline tabular-nums`),title:`Click for per-turn cost breakdown`,children:[`$`,e.toFixed(4)]}),a&&(0,Y.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-30 w-80 rounded-md border bg-popover shadow-lg p-3 text-foreground`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Cost breakdown`}),(0,Y.jsx)(`span`,{className:`font-mono tabular-nums text-sm font-semibold text-green-600 dark:text-green-400`,children:l(e)})]}),u?(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground font-mono mb-3 border-b pb-2`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{children:`input /1M`}),(0,Y.jsxs)(`span`,{children:[`$`,t.toFixed(2)]})]}),(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{children:`output /1M`}),(0,Y.jsxs)(`span`,{children:[`$`,n.toFixed(2)]})]}),r>0&&(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{children:`cache /1M`}),(0,Y.jsxs)(`span`,{children:[`$`,r.toFixed(2)]})]})]}):(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic mb-3 border-b pb-2`,children:`No pricing for the current model — cost figures are zero.`}),c.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No completed turns yet. Run a prompt to see per-turn cost here.`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground/80 mb-1`,children:[`Top `,c.length,` expensive turn`,c.length===1?``:`s`]}),(0,Y.jsx)(`ul`,{className:`space-y-1`,children:c.map(e=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=document.querySelector(`[data-message-id="${e.id}"]`);t&&t.scrollIntoView({behavior:`smooth`,block:`center`}),o(!1)},className:`w-full text-left rounded px-2 py-1.5 hover:bg-accent/40 transition-colors`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs truncate`,children:e.preview}),(0,Y.jsx)(`span`,{className:`text-xs font-mono tabular-nums text-green-600 dark:text-green-400 shrink-0`,children:l(e.cost)})]}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-0.5`,children:[e.tools,` tool`,e.tools===1?``:`s`,` · `,(e.ms/1e3).toFixed(1),`s`]})]})},e.id))})]})]})]})}var ga=[`path`,`file_path`,`pattern`,`command`,`cmd`,`url`,`query`,`description`,`content`];function _a(e,t){if(t==null)return``;if(typeof t!=`object`)return va(String(t),120);let n=t,r=(e??``).toLowerCase();if(/^todo(_?write)?$|^todos$/i.test(r)||Array.isArray(n.todos)){let e=n.todos??[];if(Array.isArray(e)){let t=e.filter(e=>e.status===`completed`).length,n=e.filter(e=>e.status===`in_progress`).length,r=[`${e.length} todo${e.length===1?``:`s`}`];return t>0&&r.push(`${t} done`),n>0&&r.push(`${n} in-progress`),r.join(` · `)}}if(/batch|parallel/.test(r)||Array.isArray(n.tool_uses)||Array.isArray(n.calls)){let e=n.tool_uses??n.calls??n.batch;if(Array.isArray(e)){let t=new Set;for(let n of e)n&&typeof n==`object`&&`name`in n&&t.add(String(n.name));let n=[...t].slice(0,3).join(`, `),r=t.size>3?` +${t.size-3}`:``;return`${e.length} sub-tool${e.length===1?``:`s`}${n?` · ${n}${r}`:``}`}}if(/^(edit|str_replace|edit_file|patch)$/.test(r)){let e=ya(n),t=typeof n.old_string==`string`?n.old_string:``,r=typeof n.new_string==`string`?n.new_string:``,i=t?t.split(`
|
|
77
|
+
`).length:0,a=r?r.split(`
|
|
78
|
+
`).length:0;return`edit ${e||`(file)`}${i||a?` (${i} → ${a} lines)`:``}`}if(/^(write|write_file|create_file|new_file)$/.test(r)){let e=ya(n),t=typeof n.content==`string`?n.content:``,r=t?t.split(`
|
|
79
|
+
`).length:0;return`write ${e||`(file)`}${r?` · ${r} lines`:``}`}if(/^(bash|shell|exec|run|run_command|run_shell)$/.test(r)){let e=n.command??n.cmd??n.script;if(typeof e==`string`)return`$ ${va(e,110)}`}if(/^(fetch|http|web|webfetch|curl|request)$/.test(r)){let e=n.url;if(typeof e==`string`)return`${(n.method??`GET`).toUpperCase()} ${va(e,100)}`}if(/^(grep|search|ripgrep)$/.test(r)){let e=n.pattern,t=n.path??n.glob??n.type;if(typeof e==`string`)return t?`grep ${va(e,60)} in ${t}`:`grep ${va(e,100)}`}if(/^(glob|find)$/.test(r)){let e=n.pattern??n.glob;if(typeof e==`string`)return`glob ${va(e,100)}`}if(/^(read|read_file|cat)$/.test(r)){let e=ya(n),t=n.offset,r=n.limit;if(e&&(typeof t==`number`||typeof r==`number`)){let n=t??0;return`read ${e} (${n}…${typeof r==`number`?n+r:``})`}if(e)return`read ${e}`}for(let e of ga){let t=n[e];if(typeof t==`string`&&t.length>0)return`${e}: ${va(t,100)}`}return va(ba(t),120)}function va(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}function ya(e){let t=e.file_path??e.path??e.filepath;return typeof t==`string`?t:``}function ba(e){try{return JSON.stringify(e)}catch{return String(e)}}var xa=(0,z.memo)(function({oldText:e,newText:t,caption:n}){let r=(0,z.useMemo)(()=>Ca(e,t),[e,t]);if(r===null)return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic px-3 py-2`,children:`Diff omitted (file too large to render inline).`});let i=r.filter(e=>e.kind===`add`).length,a=r.filter(e=>e.kind===`del`).length;return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b bg-muted/40`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-muted-foreground truncate`,children:n??`diff`}),(0,Y.jsxs)(`span`,{className:`font-mono shrink-0`,children:[(0,Y.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,i]}),(0,Y.jsx)(`span`,{className:`text-muted-foreground mx-1`,children:`·`}),(0,Y.jsxs)(`span`,{className:`text-rose-600 dark:text-rose-400`,children:[`-`,a]})]})]}),(0,Y.jsx)(`div`,{className:`font-mono leading-relaxed max-h-96 overflow-auto`,children:r.map((e,t)=>(0,Y.jsxs)(`div`,{className:J(`flex`,e.kind===`add`&&`bg-emerald-500/10`,e.kind===`del`&&`bg-rose-500/10`),children:[(0,Y.jsx)(`span`,{className:J(`w-6 shrink-0 text-center select-none`,e.kind===`add`&&`text-emerald-600 dark:text-emerald-400`,e.kind===`del`&&`text-rose-600 dark:text-rose-400`,e.kind===`ctx`&&`text-muted-foreground/40`),children:e.kind===`add`?`+`:e.kind===`del`?`-`:` `}),(0,Y.jsx)(`pre`,{className:J(`whitespace-pre-wrap break-all flex-1 px-2`,e.kind===`ctx`&&`text-muted-foreground/70`),children:e.text||`\xA0`})]},t))})]})}),Sa=5e3;function Ca(e,t){let n=e.split(`
|
|
80
|
+
`),r=t.split(`
|
|
81
|
+
`);if(n.length>Sa||r.length>Sa)return null;let i=n.length,a=r.length,o=Array.from({length:i+1},()=>Array(a+1).fill(0));for(let e=i-1;e>=0;e--)for(let t=a-1;t>=0;t--)n[e]===r[t]?R(o[e])[t]=R(o[e+1]?.[t+1])+1:R(o[e])[t]=Math.max(R(o[e+1]?.[t]),R(o[e]?.[t+1]));let s=[],c=0,l=0;for(;c<i&&l<a;)n[c]===r[l]?(s.push({kind:`ctx`,text:R(n[c])}),c++,l++):R(o[c+1]?.[l])>=R(o[c]?.[l+1])?(s.push({kind:`del`,text:R(n[c])}),c++):(s.push({kind:`add`,text:R(r[l])}),l++);for(;c<i;)s.push({kind:`del`,text:R(n[c++])});for(;l<a;)s.push({kind:`add`,text:R(r[l++])});return s}function wa(e,t){if(!e||typeof t!=`object`||!t)return null;let n=t,r=String(n.file_path??n.path??``);switch(e){case`edit`:case`str_replace`:case`edit_file`:{let e=typeof n.old_string==`string`?n.old_string:``,t=typeof n.new_string==`string`?n.new_string:``;return!e&&!t?null:{oldText:e,newText:t,caption:`edit ${r}`}}case`write`:case`write_file`:case`create_file`:return{oldText:``,newText:typeof n.content==`string`?n.content:``,caption:`write ${r} (new)`};default:return null}}var Ta=25,Ea=12;function Da({text:e,isError:t,className:n,wrapClass:r,showLineNumbers:i}){let a=(0,z.useMemo)(()=>e.split(`
|
|
82
|
+
`),[e]),o=a.length>Ta,[s,c]=(0,z.useState)(!o),l=s?e:a.slice(0,Ea).join(`
|
|
83
|
+
`),u=!!i&&o&&s;return(0,Y.jsxs)(`div`,{className:J(`rounded-md border bg-background/40 overflow-hidden`,n),children:[u?(0,Y.jsxs)(`div`,{className:`flex max-h-96 overflow-auto`,children:[(0,Y.jsx)(`pre`,{"aria-hidden":!0,className:`text-xs font-mono leading-[1.4] py-2 pl-2 pr-2 text-muted-foreground/50 select-none border-r border-border/40 bg-muted/20 tabular-nums text-right whitespace-pre shrink-0`,children:a.map((e,t)=>`${t+1}`).join(`
|
|
84
|
+
`)}),(0,Y.jsx)(`pre`,{className:J(`text-xs font-mono leading-[1.4] py-2 px-2 flex-1 whitespace-pre`,t?`text-destructive`:`text-foreground`),children:l})]}):(0,Y.jsx)(`pre`,{className:J(`text-xs font-mono p-2 max-h-96 overflow-auto`,r,t?`text-destructive`:`text-foreground`),children:l}),o&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),className:`w-full flex items-center justify-center gap-1 px-2 py-1 border-t bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground transition-colors`,children:s?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(me,{className:`h-3 w-3`}),`Collapse to first `,Ea,` lines`]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(b,{className:`h-3 w-3`}),`Show all `,a.length,` lines (`,a.length-Ea,` more)`]})})]})}var Oa=(0,z.memo)(function({toolName:e,result:t,isError:n,className:r}){let i=(0,z.useMemo)(()=>ka(e,t),[e,t]);return i.kind===`json`?(0,Y.jsx)(Aa,{value:i.value,isError:n,className:r}):i.kind===`numbered`?(0,Y.jsx)(Da,{text:t,isError:n,className:r,wrapClass:`whitespace-pre`}):i.kind===`bash`?(0,Y.jsxs)(`div`,{className:J(`rounded-md border bg-background/40 overflow-hidden`,r),children:[i.stdout&&(0,Y.jsx)(Da,{text:i.stdout,isError:n,className:`border-0 rounded-none bg-transparent`,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0}),(i.exitCode!==void 0||i.duration)&&(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-3 text-[11px] px-2 py-1 border-t bg-muted/30 tabular-nums`,i.exitCode&&i.exitCode!==0?`text-destructive`:`text-muted-foreground`),children:[i.exitCode!==void 0&&(0,Y.jsxs)(`span`,{children:[`exit code: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:i.exitCode})]}),i.duration&&(0,Y.jsx)(`span`,{children:i.duration})]})]}):(0,Y.jsx)(Da,{text:t,isError:n,className:r,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0})});function ka(e,t){let n=t.trim();if(/^\s*\d+→/m.test(t.slice(0,200)))return{kind:`numbered`};if(n.startsWith(`{`)&&n.endsWith(`}`)||n.startsWith(`[`)&&n.endsWith(`]`))try{let e=JSON.parse(n);if(typeof e==`object`&&e)return{kind:`json`,value:e}}catch{}let r=!!e&&/^(bash|shell|exec|run)/i.test(e),i=t.match(/(?:^|\n)\s*(?:\[?exit(?:\s*code)?\]?\s*[:=]?\s*)(\d+)\s*$/i),a=t.match(/(?:^|\s)(\d+\s*ms|\d+\.\d+s)\s*$/i);if(r||i){let e=t;return i&&(e=t.slice(0,i.index).trimEnd()),{kind:`bash`,stdout:e,exitCode:i?Number(i[1]):void 0,duration:a?.[1]}}return{kind:`plain`}}function Aa({value:e,isError:t,className:n}){let r=(0,z.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]),i=r.split(`
|
|
85
|
+
`).length,[a,o]=(0,z.useState)(i<30);return(0,Y.jsxs)(`div`,{className:J(`rounded-md border bg-background/40 overflow-hidden`,t&&`border-destructive/40`,n),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:`w-full flex items-center justify-between px-2 py-1 border-b bg-muted/30 text-[11px] text-muted-foreground hover:text-foreground`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[a?(0,Y.jsx)(re,{className:`h-3 w-3`}):(0,Y.jsx)(k,{className:`h-3 w-3`}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[`JSON · `,i,` lines`]})]}),(0,Y.jsx)(`span`,{children:a?`collapse`:`expand`})]}),a&&(0,Y.jsx)(`pre`,{className:J(`text-xs font-mono whitespace-pre p-2 max-h-96 overflow-auto`,t?`text-destructive`:`text-foreground`),children:r})]})}var ja=/💡\s*Next steps?\s*\n+((?:\d+\.\s+.+\n?)+)/i;function Ma(e){let t=ja.exec(e);if(!t?.[1])return[];let n=t[1].split(`
|
|
86
|
+
`).filter(Boolean),r=[];for(let e of n){let t=/^(\d+)\.\s+(.+)$/.exec(e.trim());t&&r.push({index:Number.parseInt(t[1],10),text:t[2].trim()})}return r.slice(0,6)}function Na(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function Pa({steps:e}){return e.length===0?null:(0,Y.jsxs)(`div`,{className:`mt-4 rounded-xl border border-primary/20 bg-primary/[0.03] overflow-hidden animate-message`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3.5 py-2 border-b border-primary/10 bg-primary/[0.04]`,children:[(0,Y.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md bg-primary/15 text-primary`,children:(0,Y.jsx)(Ie,{className:`h-3 w-3`})}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-foreground/90`,children:`Next steps`}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:`click to fill input`})]}),(0,Y.jsx)(`div`,{className:`flex flex-col p-2 gap-1`,children:e.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>Na(e.text),className:`group flex items-center gap-2.5 w-full text-left px-3 py-2 rounded-lg transition-all
|
|
87
|
+
hover:bg-primary/[0.08] hover:shadow-sm
|
|
88
|
+
border border-transparent hover:border-primary/20`,title:`Click to fill: ${e.text}`,children:[(0,Y.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md bg-muted/80 group-hover:bg-primary/20
|
|
89
|
+
text-[11px] font-mono font-semibold tabular-nums shrink-0
|
|
90
|
+
text-muted-foreground group-hover:text-primary transition-colors`,children:e.index}),(0,Y.jsx)(C,{className:`h-3.5 w-3.5 text-muted-foreground/60 group-hover:text-primary group-hover:translate-x-0.5 transition-all shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm leading-snug text-foreground/80 group-hover:text-foreground transition-colors flex-1 min-w-0`,children:e.text}),(0,Y.jsx)(o,{className:`h-3.5 w-3.5 opacity-0 group-hover:opacity-100 text-primary/60 transition-all shrink-0`})]},e.index))})]})}async function Fa(e){try{if(typeof navigator<`u`&&navigator.clipboard?.writeText)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}function Ia(e,t){if(typeof document>`u`)return;let n=new Blob([t],{type:`text/plain;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i),setTimeout(()=>URL.revokeObjectURL(r),1e3)}function La(e){let t=(e??``).toLowerCase();return/bash|shell|exec|run/.test(t)?`log`:(/grep|search|find/.test(t),`txt`)}function Ra(e){return e<1e3?`${e} ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m ${Math.floor(e%6e4/1e3)}s`}var za=[ae];function Ba({text:e}){let[t,n]=(0,z.useState)(!1);return(0,Y.jsxs)(`button`,{type:`button`,onClick:(0,z.useCallback)(async()=>{await Fa(e)&&(n(!0),setTimeout(()=>n(!1),1500))},[e]),className:J(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[10px] transition-colors`,`hover:bg-muted-foreground/10`,t?`text-emerald-500`:`text-muted-foreground hover:text-foreground`),title:t?`Copied!`:`Copy code`,children:[t?(0,Y.jsx)(be,{className:`h-3 w-3`}):(0,Y.jsx)(_,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:t?`Copied`:`Copy`})]})}var Va={code({inline:e,className:t,children:n,...r}){let i=/language-(\w+)/.exec(t??``),a=String(n??``).replace(/\n$/,``);if(e||!i)return(0,Y.jsx)(`code`,{className:J(`rounded bg-muted/60 px-1.5 py-0.5 text-[0.85em] font-mono`,t),...r,children:n});let o=(0,z.useMemo)(()=>a.split(`
|
|
91
|
+
`),[a]),s=o.length>1;return(0,Y.jsxs)(`div`,{className:`not-prose relative my-3 rounded-lg border bg-muted/30 overflow-hidden group/codeblock`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1 border-b bg-muted/40 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(mt,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-muted-foreground font-medium`,children:i[1]}),o.length>0&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums`,children:[o.length,` line`,o.length===1?``:`s`]})]}),(0,Y.jsx)(Ba,{text:a})]}),s?(0,Y.jsxs)(`div`,{className:`flex max-h-[40rem] overflow-auto`,children:[(0,Y.jsx)(`pre`,{"aria-hidden":!0,className:`text-xs font-mono leading-[1.55] py-3 pl-3 pr-2 text-muted-foreground/40 select-none border-r border-border/30 bg-muted/10 tabular-nums text-right shrink-0`,children:o.map((e,t)=>(0,Y.jsx)(`div`,{children:t+1},t))}),(0,Y.jsx)(`pre`,{className:`overflow-x-auto py-3 px-3 text-xs leading-[1.55] font-mono flex-1`,children:(0,Y.jsx)(`code`,{className:J(`hljs`,t),...r,children:n})})]}):(0,Y.jsx)(`pre`,{className:`overflow-x-auto p-3 text-xs leading-relaxed font-mono max-h-[40rem]`,children:(0,Y.jsx)(`code`,{className:J(`hljs`,t),...r,children:n})}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute bottom-8 left-0 right-0 h-8 bg-gradient-to-t from-muted/30 to-transparent opacity-0 group-hover/codeblock:opacity-100 transition-opacity`})]})}};function Ha({text:e,className:t,label:n=`Copy`}){let[r,i]=(0,z.useState)(!1);return(0,Y.jsx)(`button`,{type:`button`,onClick:async t=>{t.stopPropagation(),await Fa(e)&&(i(!0),setTimeout(()=>i(!1),1400))},className:J(`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,t),title:n,children:r?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(be,{className:`h-3 w-3 text-green-500`}),(0,Y.jsx)(`span`,{children:`Copied`})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(_,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:n})]})})}function Ua(e){let t=e.split(`
|
|
92
|
+
`);for(let e=0;e<t.length;e++){let n=R(t[e]);if(/^\s*at\s+\S+.*\(.*:\d+:\d+\)\s*$/.test(n)||/^\s*at\s+\S+\.\S+\(\S+\.java:\d+\)\s*$/.test(n)||/^\s+File "[^"]+", line \d+/.test(n))return e}return-1}function Wa({text:e}){let t=Ua(e),[n,r]=(0,z.useState)(!1);if(t===-1)return(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:e});let i=e.split(`
|
|
93
|
+
`),a=i.slice(0,t).join(`
|
|
94
|
+
`).trim(),o=i.slice(t).join(`
|
|
95
|
+
`),s=o.split(`
|
|
96
|
+
`).filter(e=>e.trim().length>0).length;return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:a}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`inline-flex items-center gap-1 text-xs text-destructive hover:text-destructive/80 font-medium`,children:[n?`▾`:`▸`,` `,n?`Hide`:`Show`,` stack trace (`,s,` frame`,s===1?``:`s`,`)`]}),n&&(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[11px] leading-snug bg-destructive/5 border border-destructive/20 rounded p-2 max-h-80 overflow-auto`,children:o})]})}function Ga({input:e}){let[t,n]=(0,z.useState)({});if(typeof e!=`object`||!e||Array.isArray(e))return(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-all text-xs font-mono`,children:JSON.stringify(e,null,2)});let r=Object.entries(e);return r.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(no params)`}):(0,Y.jsx)(`div`,{className:`text-xs font-mono`,children:r.map(([e,r])=>{if(r==null||typeof r==`string`||typeof r==`number`||typeof r==`boolean`){let t=r===null?`null`:r===void 0?`undefined`:typeof r==`string`?r:String(r),n=typeof r==`string`&&(t.length>80||t.includes(`
|
|
97
|
+
`));return(0,Y.jsxs)(`div`,{className:J(`py-0.5`,n?`flex flex-col gap-0.5`:`flex items-baseline gap-2`),children:[(0,Y.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`span`,{className:J(`text-foreground`,n?`whitespace-pre-wrap break-all bg-muted/40 rounded px-1.5 py-1`:`truncate`,typeof r==`string`?``:`text-amber-600 dark:text-amber-400`),title:typeof r==`string`&&!n?t:void 0,children:t})]},e)}let i=!!t[e],a=Array.isArray(r)?`[${r.length} item${r.length===1?``:`s`}]`:`{${Object.keys(r).length} key${Object.keys(r).length===1?``:`s`}}`;return(0,Y.jsxs)(`div`,{className:`py-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n(t=>({...t,[e]:!t[e]})),className:`flex items-baseline gap-2 hover:bg-muted/30 rounded px-1 -mx-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground/60 text-[10px]`,children:i?`▾`:`▸`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,Y.jsx)(`span`,{className:`text-violet-600 dark:text-violet-400`,children:a})]}),i&&(0,Y.jsx)(`pre`,{className:`ml-3 mt-1 whitespace-pre-wrap break-all text-[11px] bg-muted/40 rounded px-2 py-1.5`,children:JSON.stringify(r,null,2)})]},e)})})}var Ka=(0,z.memo)(function({message:e,isFirst:t=!1,isContinuation:n=!1}){let[r,i]=(0,z.useState)({}),[o,s]=(0,z.useState)(!1),[c,l]=(0,z.useState)(``),[u,d]=(0,z.useState)(!1),p=e.role===`user`,m=e.role===`tool`;e.role;let h=V(e=>e.truncateAfter),g=V(e=>e.addMessage),_=V(e=>e.setLoading),v=V(e=>e.isLoading),y=H(e=>e.wsUrl),b=W(e=>e.pinnedIds),x=W(e=>e.togglePin),S=W(e=>e.compactMode),C=b.includes(e.id),w=U(e=>e.inputCost),T=U(e=>e.outputCost),D=U(e=>e.cacheReadCost),O=(()=>{if(e.role!==`assistant`||v)return!1;let t=V.getState().messages;for(let n=t.length-1;n>=0;n--){let r=R(t[n]);if(r.role===`assistant`)return r.id===e.id}return!1})(),A=()=>{let t=V.getState().messages,n=t.findIndex(t=>t.id===e.id);if(n===-1)return;let r=-1;for(let e=n-1;e>=0;e--)if(t[e]?.role===`user`){r=e;break}if(r===-1)return;let i=R(t[r]);h(i.id),g({role:`user`,content:i.content}),_(!0),B(y).sendMessage(i.content)},j=e=>{i(t=>({...t,[e]:!t[e]}))},M=()=>{l(e.content),s(!0)},N=()=>{s(!1),l(``)},te=()=>{let t=c.trim();if(!t){N();return}h(e.id),g({role:`user`,content:t}),_(!0),B(y).sendMessage(t),s(!1),l(``)};return(0,Y.jsxs)(`div`,{"data-message-id":e.id,"data-pinned":C?`1`:void 0,className:J(`group flex msg-bubble animate-message rounded-lg transition-shadow`,S?`gap-2`:`gap-3`,p?`flex-row-reverse`:`flex-row`,C&&`ring-1 ring-amber-500/30 bg-amber-500/[0.02] px-1 -mx-1`),children:[n?(0,Y.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,Y.jsx)(`div`,{className:J(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,`ring-2 ring-offset-2 ring-offset-background`,p?`bg-primary text-primary-foreground ring-primary/20`:m?`bg-secondary text-secondary-foreground ring-secondary/20`:`bg-accent text-accent-foreground ring-accent/20`),children:p?(0,Y.jsx)(ee,{className:`h-4 w-4`}):m?(0,Y.jsx)(ge,{className:`h-4 w-4`}):(0,Y.jsx)(E,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{className:J(`flex flex-col gap-1.5 max-w-[85%]`,p&&`items-end`),children:[t&&!n&&(0,Y.jsx)(`span`,{className:J(`text-xs font-medium px-1`,p?`text-primary`:m?`text-secondary`:`text-muted-foreground`),children:p?`You`:m?`Tool`:`Assistant`}),m&&e.toolName&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>j(e.id),className:J(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1 -mx-2 transition-colors`,e.isError?`text-destructive`:`text-foreground`),children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:r[e.id]?(0,Y.jsx)(re,{className:`h-3 w-3`}):(0,Y.jsx)(k,{className:`h-3 w-3`})}),(0,Y.jsx)(ge,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:e.toolName}),e.toolResult===void 0?(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500 animate-pulse`,"aria-hidden":!0}):e.isError?(0,Y.jsx)(a,{className:`h-3 w-3 text-destructive`}):(0,Y.jsx)(F,{className:`h-3 w-3 text-green-500`}),typeof e.toolDurationMs==`number`&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:Ra(e.toolDurationMs)})]}),(0,Y.jsx)(`div`,{className:J(`rounded-2xl`,S?`px-3 py-1.5`:`px-4 py-3`,p?`bg-primary text-primary-foreground rounded-br-md`:m?e.isError?`bg-destructive/5 border border-destructive/20 text-destructive`:`bg-muted/80 text-foreground`:`bg-card border text-foreground`,e.isError&&!m&&`border-destructive/20`),children:m?(()=>{let t=!!r[e.id],n=e.toolInput===void 0?``:_a(e.toolName,e.toolInput),i=e.toolResult?e.toolResult.split(`
|
|
98
|
+
`).length:0;return(0,Y.jsxs)(`div`,{className:`space-y-1 tool-details`,children:[n&&!t&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono truncate`,children:n}),e.toolResult===void 0&&e.progressLines&&e.progressLines.length>0&&(0,Y.jsx)(`div`,{className:`mt-1 rounded-md border border-amber-500/20 bg-amber-500/5 p-1.5 text-[11px] font-mono leading-snug max-h-32 overflow-auto`,children:(()=>{let t=new Map;return e.progressLines.slice(-6).map(e=>{let n=t.get(e)??0;return t.set(e,n+1),(0,Y.jsx)(`div`,{className:`truncate text-muted-foreground`,children:e},`${e}-${n}`)})})()}),t&&e.toolInput!==void 0&&(()=>{let t=wa(e.toolName,e.toolInput);return t?(0,Y.jsx)(xa,{oldText:t.oldText,newText:t.newText,caption:t.caption}):(0,Y.jsxs)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-muted-foreground mb-2 text-xs`,children:[(0,Y.jsx)(de,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:`Input`})]}),(0,Y.jsx)(Ga,{input:e.toolInput})]})})(),t&&e.toolResult!==void 0&&e.toolResult.length>0&&(0,Y.jsxs)(`div`,{className:`relative group/tool`,children:[(0,Y.jsx)(Oa,{toolName:e.toolName,result:e.toolResult,isError:e.isError}),(0,Y.jsxs)(`div`,{className:`absolute top-1.5 right-1.5 flex items-center gap-1 opacity-0 group-hover/tool:opacity-100 transition-opacity`,children:[(0,Y.jsx)(Ha,{text:e.toolResult,label:``,className:`bg-background/80 border rounded px-1.5 py-0.5`}),e.toolResult.split(`
|
|
99
|
+
`).length>5&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation();let n=La(e.toolName);Ia(`${(e.toolName??`output`).replace(/[^a-z0-9_-]+/gi,`-`).toLowerCase()}-${new Date().toISOString().replace(/[:.]/g,`-`)}.${n}`,e.toolResult??``)},className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground bg-background/80 border rounded px-1.5 py-0.5`,title:`Download as file`,children:(0,Y.jsx)(Ce,{className:`h-3 w-3`})})]})]}),t&&e.toolResult!==void 0&&e.toolResult.length===0&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(empty)`}),!t&&e.isError&&e.toolResult&&(0,Y.jsx)(`div`,{className:`text-xs font-mono text-destructive truncate`,children:e.toolResult.split(`
|
|
100
|
+
`)[0]}),(e.toolResult!==void 0&&e.toolResult.length>0||e.toolInput!==void 0&&Object.keys(e.toolInput??{}).length>0)&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>j(e.id),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:t?`Hide details`:`Show details${i>0?` (${i} line${i===1?``:`s`})`:``}`})]})})():o&&p?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-[280px]`,children:[(0,Y.jsx)(`textarea`,{value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),N()):e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),te())},rows:Math.min(8,Math.max(2,c.split(`
|
|
101
|
+
`).length)),className:`w-full resize-none rounded-md border bg-background text-foreground px-2 py-1.5 text-sm font-mono focus:outline-none focus:ring-2 focus:ring-ring`}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-primary-foreground/60`,children:`⌘/Ctrl+Enter to save · Esc to cancel`}),(0,Y.jsxs)(`div`,{className:`flex gap-1`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:N,className:`text-xs px-2 py-0.5 rounded border border-primary-foreground/30 hover:bg-primary-foreground/10`,children:`Cancel`}),(0,Y.jsx)(`button`,{type:`button`,onClick:te,disabled:!c.trim(),className:`text-xs px-2 py-0.5 rounded bg-primary-foreground text-primary disabled:opacity-50`,children:`Save & resend`})]})]})]}):(0,Y.jsx)(`div`,{className:J(`text-sm leading-relaxed markdown-content`,e.streaming&&`streaming-cursor`),children:e.content?u&&e.role===`assistant`?(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-foreground/90 max-h-[40rem] overflow-auto`,children:e.content}):e.role===`assistant`&&e.isError?(0,Y.jsx)(Wa,{text:e.content}):(0,Y.jsx)(pe,{remarkPlugins:[ce],rehypePlugins:za,components:Va,children:e.content}):e.streaming?(0,Y.jsx)(`span`,{className:`inline-block animate-pulse text-muted-foreground`,children:`Typing...`}):(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`No content`})})}),O&&e.content&&(()=>{let t=Ma(e.content);return t.length===0?null:(0,Y.jsx)(Pa,{steps:t})})(),(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-2 px-1`,p?`flex-row-reverse`:`flex-row`),children:[(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground/50`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),(0,Y.jsx)(`span`,{className:`w-px h-3 bg-border/60 shrink-0`,"aria-hidden":!0}),e.runSummary&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[`Iterations: ${e.runSummary.iterations}`,`Tool calls: ${e.runSummary.tools}`,`Elapsed: ${(e.runSummary.durationMs/1e3).toFixed(2)}s`,e.runSummary.costDelta>0?`Cost: ${e.runSummary.costDelta.toFixed(4)}`:``].filter(Boolean).join(` · `),children:[e.runSummary.iterations,` iter`,e.runSummary.tools>0?` · ${e.runSummary.tools} tool${e.runSummary.tools===1?``:`s`}`:``,` · `,e.runSummary.durationMs<6e4?`${(e.runSummary.durationMs/1e3).toFixed(1)}s`:`${Math.floor(e.runSummary.durationMs/6e4)}m ${Math.floor(e.runSummary.durationMs%6e4/1e3)}s`,e.runSummary.costDelta>0?` · ${e.runSummary.costDelta>=.01?e.runSummary.costDelta.toFixed(4):e.runSummary.costDelta.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``]}),e.usage&&(e.usage.input>0||e.usage.output>0)&&(()=>{let t=e.usage,n=(t.input*w+t.output*T+(t.cacheRead??0)*D)/1e6,r=w>0||T>0,i=n>=.01?`${n.toFixed(4)}`:n>0?`${n.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``;return(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 font-mono tabular-nums`,title:[`Input: ${t.input.toLocaleString()}`,`Output: ${t.output.toLocaleString()}`,t.cacheRead?`Cache read: ${t.cacheRead.toLocaleString()}`:``,r?`Cost: ${i}`:``].filter(Boolean).join(` · `),children:[t.input.toLocaleString(),`→`,t.output.toLocaleString(),t.cacheRead?` · ${t.cacheRead.toLocaleString()} ↺`:``,r&&i?` · ${i}`:``]})})(),!m&&e.content&&!e.streaming&&(0,Y.jsx)(Ha,{text:e.content,label:`Copy`,className:`opacity-50 hover:opacity-100 transition-opacity`}),e.role===`assistant`&&e.content&&!e.streaming&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),title:u?`Show rendered markdown`:`Show raw markdown source`,className:J(`text-xs inline-flex items-center gap-1 transition-opacity`,u?`text-primary hover:text-primary/80 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[(0,Y.jsx)(mt,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:u?`Rendered`:`Raw`})]}),p&&!o&&!v&&e.content&&(0,Y.jsxs)(`button`,{type:`button`,onClick:M,title:`Edit & resend this prompt`,className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,Y.jsx)(f,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:`Edit`})]}),e.role===`assistant`&&e.content&&!e.streaming&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>x(e.id),title:C?`Unpin`:`Pin this answer`,className:J(`text-xs inline-flex items-center gap-1 transition-opacity`,C?`text-amber-500 hover:text-amber-600 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[C?(0,Y.jsx)(pn,{className:`h-3 w-3`}):(0,Y.jsx)(we,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:C?`Pinned`:`Pin`})]}),O&&e.content&&!e.streaming&&(0,Y.jsxs)(`button`,{type:`button`,onClick:A,title:`Regenerate this response`,className:`opacity-50 hover:opacity-100 transition-opacity text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,Y.jsx)(Mt,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:`Retry`})]})]})]})]})});function qa(){let e=U(e=>e.mode),t=U(e=>e.modes),{listModes:n,switchMode:r}=Z(),[i,a]=(0,z.useState)(!1),o=(0,z.useRef)(null);(0,z.useEffect)(()=>{i&&n()},[i,n]),(0,z.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[i]);let s=t.length>0?t:[{id:`default`,name:`Default`,description:`Standard agent behaviour`}];return(0,Y.jsxs)(`div`,{ref:o,className:`relative shrink-0`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:J(`flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-accent/40 text-foreground hover:bg-accent transition-colors border border-transparent hover:border-primary/30`),title:`Active mode`,children:[`mode: `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e||`default`}),(0,Y.jsx)(re,{className:`h-3 w-3 opacity-60`})]}),i&&(0,Y.jsxs)(`div`,{className:`absolute top-full left-0 mt-1 w-64 rounded-md border bg-popover shadow-lg z-30 py-1`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Mode`}),s.map(t=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{r(t.id),a(!1)},className:J(`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-start gap-2`,t.id===e&&`bg-accent/30`),children:[(0,Y.jsx)(be,{className:J(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-mono`,children:t.id}),t.description&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description})]})]},t.id))]})]})}function Ja({open:e,onClose:t,className:n}){let[r,i]=(0,z.useState)([]),a=Z(),o=(0,z.useRef)(null),s=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!(!e||!a.client?.isConnected))return a.client.send?.({type:`process.list`}),o.current=a.client.on?.(`process.list`,e=>{let t=e?.payload;t?.processes&&i(t.processes)})??null,s.current=setInterval(()=>{a.client.send?.({type:`process.list`})},3e3),()=>{o.current?.(),s.current&&clearInterval(s.current)}},[e,a.client]);let c=(0,z.useCallback)(e=>{a.client.send?.({type:`process.kill`,payload:{pid:e}})},[a.client]),l=(0,z.useCallback)(()=>{a.client.send?.({type:`process.killAll`})},[a.client]),u=r.filter(e=>e.status===`running`);return e?(0,Y.jsx)(`div`,{className:J(`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,n),onClick:e=>{e.target===e.currentTarget&&t()},children:(0,Y.jsxs)(`div`,{className:`w-full max-w-lg rounded-xl border bg-card shadow-2xl max-h-[75vh] flex flex-col animate-in fade-in zoom-in-95`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Y.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-lg bg-amber-500/10 text-amber-600 dark:text-amber-400`,children:(0,Y.jsx)(ge,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Running Processes`}),(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[u.length,` active · `,r.length,` total`]})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[u.length>0&&(0,Y.jsxs)(`button`,{type:`button`,onClick:l,className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md text-xs text-destructive hover:bg-destructive/10 transition-colors font-medium`,children:[(0,Y.jsx)(qt,{className:`h-3 w-3 fill-current`}),`Kill All`]}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,Y.jsx)(ge,{className:`h-10 w-10 opacity-15`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:`No processes tracked`}),(0,Y.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:`Processes appear here when the agent runs bash or exec tools. Active processes show a pulsing LED.`})]}):(0,Y.jsx)(`div`,{className:`divide-y`,children:r.map(e=>{let t=e.status===`running`?Math.floor((Date.now()-e.startedAt)/1e3):null,n=t?t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`:null,r=e.protected===!0;return(0,Y.jsxs)(`div`,{className:J(`flex items-center justify-between px-4 py-3 text-xs transition-colors`,e.status===`running`?`bg-background hover:bg-muted/30`:`bg-muted/20 text-muted-foreground`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:J(`led shrink-0`,e.status===`running`?r?`text-blue-400`:`text-[hsl(var(--success))] led-pulse`:`text-muted-foreground`)}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground shrink-0`,children:[`PID `,e.pid]}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:e.tool}),r&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1 py-0.5 rounded text-[9px] bg-blue-500/10 text-blue-600 dark:text-blue-400 font-medium shrink-0`,title:`Protected — survives kill/killAll`,children:[(0,Y.jsx)(rt,{className:`h-2.5 w-2.5`}),`protected`]})]}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 truncate block mt-0.5 font-mono`,children:e.command})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0 ml-3`,children:[n&&(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:n}),e.status===`running`&&!r&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>c(e.pid),className:`p-1.5 rounded-md hover:bg-destructive/10 hover:text-destructive transition-colors`,title:`Kill PID ${e.pid}`,children:(0,Y.jsx)(qt,{className:`h-3.5 w-3.5 fill-current`})})]})]},e.pid)})})})]})}):null}function Ya(){let e=W(e=>e.searchOpen),t=W(e=>e.setSearchOpen),n=W(e=>e.searchQuery),r=W(e=>e.setSearchQuery),i=V(e=>e.messages),a=(0,z.useRef)(null),[o,s]=(0,z.useState)(0);(0,z.useEffect)(()=>{e&&requestAnimationFrame(()=>a.current?.focus())},[e]);let c=(0,z.useMemo)(()=>{let e=n.trim().toLowerCase();return e?i.filter(t=>t.role===`tool`?(t.toolName??``).toLowerCase().includes(e)||(t.toolResult??``).toLowerCase().includes(e)||JSON.stringify(t.toolInput??``).toLowerCase().includes(e):t.content.toLowerCase().includes(e)).map(e=>e.id):[]},[i,n]);if((0,z.useEffect)(()=>{o>=c.length&&s(0)},[c,o]),(0,z.useEffect)(()=>{let t=window,r=t.CSS?.highlights,i=t.Highlight;if(!r||!i)return;let a=()=>{r.delete(`chat-search`),r.delete(`chat-search-active`)},s=n.trim();if(!s||!e){a();return}let l=s.toLowerCase(),u=[],d=[],f=c[o];for(let e of document.querySelectorAll(`[data-message-id]`)){let t=e.dataset.messageId===f,n=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),r=n.nextNode();for(;r;){let e=r.nodeValue??``;if(e.length>0){let n=e.toLowerCase(),i=0;for(;i<=n.length-l.length;){let e=n.indexOf(l,i);if(e===-1)break;let a=document.createRange();a.setStart(r,e),a.setEnd(r,e+l.length),u.push(a),t&&d.push(a),i=e+l.length}}r=n.nextNode()}}return u.length>0?r.set(`chat-search`,new i(...u)):r.delete(`chat-search`),d.length>0?r.set(`chat-search-active`,new i(...d)):r.delete(`chat-search-active`),a},[n,c,o,e]),(0,z.useEffect)(()=>{let e=c[o];if(!e)return;let t=document.querySelector(`[data-message-id="${e}"]`);t&&t.scrollIntoView({behavior:`smooth`,block:`center`})},[c,o]),!e)return null;let l=e=>{c.length!==0&&s(t=>(t+e+c.length)%c.length)};return(0,Y.jsx)(`div`,{className:`absolute top-2 right-4 z-30 w-[28rem] max-w-[calc(100%-2rem)] rounded-lg border bg-popover shadow-xl`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,Y.jsx)(ft,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,Y.jsx)(`input`,{ref:a,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),t(!1)):e.key===`Enter`?(e.preventDefault(),l(e.shiftKey?-1:1)):e.key===`ArrowDown`?(e.preventDefault(),l(1)):e.key===`ArrowUp`&&(e.preventDefault(),l(-1))},placeholder:`Search in chat…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums shrink-0`,children:c.length===0?n?`0`:``:`${o+1} / ${c.length}`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>l(-1),disabled:c.length===0,className:J(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Previous hit`,children:(0,Y.jsx)(Fe,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>l(1),disabled:c.length===0,className:J(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Next hit`,children:(0,Y.jsx)(Ut,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`p-1 rounded hover:bg-muted text-muted-foreground`,title:`Close (Esc)`,children:(0,Y.jsx)(L,{className:`h-3.5 w-3.5`})})]})})}function Xa(e){return e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(e<1e4?2:1)}s`:`${Math.floor(e/6e4)}m${Math.floor(e%6e4/1e3)}s`}var Za=(0,z.memo)(function({tools:e,defaultOpen:t=!1,isContinuation:n=!1}){let[r,i]=(0,z.useState)(t);if(e.length===1)return(0,Y.jsx)(Ka,{message:R(e[0]),isFirst:!0,isContinuation:n});let o=e.filter(e=>e.toolResult===void 0).length,s=e.filter(e=>e.isError).length,c=e.reduce((e,t)=>e+(t.toolDurationMs??0),0),l=Array.from(new Set(e.map(e=>e.toolName).filter(Boolean))),u=l.slice(0,3).join(`, `),d=l.length>3?` +${l.length-3}`:``;return(0,Y.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[n?(0,Y.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,Y.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-secondary text-secondary-foreground ring-2 ring-offset-2 ring-offset-background ring-secondary/20`,children:(0,Y.jsx)(ge,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] flex-1 min-w-0`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:J(`flex items-center gap-2 text-sm font-medium cursor-pointer select-none`,`hover:bg-muted/50 rounded-lg px-2 py-1.5 -mx-2 transition-colors`,`border border-border/40 bg-muted/30`),children:[r?(0,Y.jsx)(re,{className:`h-3.5 w-3.5 text-muted-foreground`}):(0,Y.jsx)(k,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(ge,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsxs)(`span`,{className:`font-mono text-xs`,children:[e.length,` tool call`,e.length===1?``:`s`]}),o>0?(0,Y.jsx)(D,{className:`h-3 w-3 animate-spin text-amber-500`}):s>0?(0,Y.jsx)(a,{className:`h-3 w-3 text-destructive`}):(0,Y.jsx)(F,{className:`h-3 w-3 text-green-500`}),c>0&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:Xa(c)}),u&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 font-mono truncate`,children:[`· `,u,d]})]}),r&&(0,Y.jsx)(`div`,{className:`space-y-2 pl-3 border-l-2 border-border/40 ml-2 tool-details`,children:e.map(e=>(0,Y.jsx)(Ka,{message:e,isFirst:!1},e.id))})]})]})}),Qa=[{icon:ft,title:`Explore`,hint:`Understand the code before changing it`,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/20`,prompts:[`Walk me through this codebase: what are the top-level packages or modules, what does each do, and how do they depend on one another? What cross-cutting patterns or abstractions should I understand first?`,`Find the public API surface of this project — all exported functions, classes, and types that external consumers rely on. Flag any that lack documentation or have unclear contracts.`,`Map the data flow for a single user action from entry point to persistence. Where does validation happen? Where are side effects triggered? Show me the call chain and any middleware involved.`]},{icon:s,title:`Build`,hint:`Add a feature end-to-end`,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20`,prompts:[`Add a new end-to-end feature. Walk through the layers: data model, API/serialization, business logic, UI (if applicable), and tests. Use existing patterns in this codebase rather than inventing new ones.`,`Write comprehensive tests for an existing module that has low coverage. Cover happy paths, edge cases, and error states. Use whatever test runner and patterns this project already uses.`,`Add structured logging or observability to a critical code path. Use the project’s existing logging conventions. Make sure errors carry enough context to debug without re-running.`]},{icon:c,title:`Debug`,hint:`Track a problem to its root cause`,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/20`,prompts:[`Something isn't behaving as expected — data looks wrong, a feature silently fails, or state drifts over time. Help me trace it: start from the symptom, follow the code path, and identify where the logic diverges from intent.`,`The app works fine locally but breaks in production or CI. Check for environment differences, missing config, race conditions, or infrastructure-level assumptions that might explain the gap.`,`Performance degrades under load or over time. Profile the hot path, identify bottlenecks (N+1 queries, blocking I/O, large allocations, expensive renders), and propose targeted fixes with measurable impact.`]},{icon:xt,title:`Refactor`,hint:`Clean up without breaking behavior`,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20`,prompts:[`Find duplicated or near-duplicated logic across the codebase. Extract the shared pieces into a single module or utility, update call sites, and ensure the existing tests still pass.`,`Identify modules that have grown too large or have too many responsibilities. Propose a split that respects the project’s existing structure, keeps the public API stable, and can be done incrementally.`,`Audit error handling across the codebase: are errors propagated consistently? Are they wrapped with enough context? Are there swallowed errors or bare panics? Propose a uniform approach and apply it to the worst offenders.`]}],$a=[{name:`/help`,hint:`list every slash command`},{name:`/diag`,hint:`runtime diagnostics`},{name:`/stats`,hint:`tokens · cache · cost · elapsed`},{name:`/tools`,hint:`show registered tools`},{name:`/memory`,hint:`show remembered notes`},{name:`/compact`,hint:`shrink context`},{name:`/clear`,hint:`wipe current context`},{name:`/new`,hint:`fresh session`}];function eo(e){let t=document.querySelector(`textarea`);t&&((Object.getOwnPropertyDescriptor(window.HTMLTextAreaElement.prototype,`value`)?.set)?.call(t,e),t.dispatchEvent(new Event(`input`,{bubbles:!0})),t.focus())}function to(){let{projectName:e,cwd:t}=U(),{provider:n,model:r}=H(),i=H(e=>e.wsConnected),a=H(e=>e.wsUrl),o=W(e=>e.setCurrentView),[s,c]=(0,z.useState)(void 0);(0,z.useEffect)(()=>{if(!i)return;let e=B(a),t=e.on(`providers.saved`,e=>{let t=e.payload;c(t.providers?.length??0)});return e.listSavedProviders(),()=>{t()}},[i,a]);let l=W(e=>e.promptHistory).slice(0,6),{listSessions:u,resumeSession:d}=Z(),f=Un(e=>e.entries);(0,z.useEffect)(()=>{i&&f.length===0&&u(10)},[i]);let p=W(e=>e.sessionNicknames),m=f.filter(e=>!e.isCurrent).slice(0,4);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-8 py-8 px-2 max-w-5xl mx-auto w-full`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-3`,children:[(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(`div`,{className:`w-14 h-14 rounded-2xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center shadow-lg shadow-primary/20`,children:(0,Y.jsx)(ye,{className:`h-7 w-7 text-primary-foreground`})}),(0,Y.jsx)(`div`,{className:`absolute -inset-3 bg-gradient-to-r from-transparent via-primary/10 to-transparent animate-pulse rounded-full -z-10`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:[`Where do you want to start`,e?(0,Y.jsxs)(Y.Fragment,{children:[` in `,(0,Y.jsx)(`span`,{className:`text-primary`,children:e})]}):``,`?`]}),(0,Y.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-2xl mx-auto leading-relaxed`,children:[`The agent is connected to your project and ready to read, edit, run commands, search the codebase, track todos, and remember context across sessions. Pick a starting prompt below, write your own, or type`,` `,(0,Y.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`/`}),` for the full command palette.`]}),n&&r&&(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground/70 mt-2 font-mono`,children:[n,` / `,r]}),t&&(0,Y.jsxs)(`p`,{className:`text-[11px] text-muted-foreground/50 mt-1 font-mono`,title:t,children:[`Working directory: `,t]})]})]}),i&&s===0&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>o(`settings`),className:J(`group rounded-xl border bg-gradient-to-br from-amber-500/10 via-amber-500/5 to-transparent`,`border-amber-500/30 hover:border-amber-500/50 transition-colors`,`p-4 flex items-center gap-4 text-left`),children:[(0,Y.jsx)(`span`,{className:`flex items-center justify-center w-12 h-12 rounded-lg bg-amber-500/15 text-amber-600 dark:text-amber-400 shrink-0`,children:(0,Y.jsx)(He,{className:`h-6 w-6`})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:`No API key configured yet`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground leading-relaxed`,children:`Register a provider in Settings before sending a message — otherwise the agent has nothing to talk to. Anthropic, OpenAI, Google, and any OpenAI-compatible endpoint all work.`})]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-amber-600 dark:text-amber-400 font-medium shrink-0 group-hover:translate-x-0.5 transition-transform`,children:[`Open Settings `,(0,Y.jsx)(C,{className:`h-3.5 w-3.5`})]})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:Qa.map((e,t)=>{let n=e.icon;return(0,Y.jsxs)(`div`,{className:`rounded-xl border bg-card/40 backdrop-blur-sm p-4 flex flex-col gap-3 animate-message hover:border-primary/20 hover:shadow-sm transition-all`,style:{animationDelay:`${t*80}ms`},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:J(`flex items-center justify-center w-8 h-8 rounded-lg border`,e.tone),children:(0,Y.jsx)(n,{className:`h-4 w-4`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.title}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:e.prompts.map((e,t)=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>eo(e),className:`text-left text-xs leading-relaxed text-foreground/80 hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-muted/40 transition-colors line-clamp-3`,title:e,children:e},t))})]},e.title)})}),m.length>0&&(0,Y.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(M,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Pick back up`})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:m.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>d(e.id),className:`text-left rounded-lg border border-border/40 bg-background/60 hover:border-primary/40 hover:bg-accent/30 px-3 py-2 transition-colors group/sess`,title:e.title,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium truncate text-foreground group-hover/sess:text-primary`,children:p[e.id]||e.title||`(empty)`}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model,e.tokenTotal>0&&(0,Y.jsxs)(`span`,{className:`ml-2`,children:[`· `,e.tokenTotal.toLocaleString(),` tok`]})]})]},e.id))})]}),l.length>0&&(0,Y.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(de,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Recent prompts`})]}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:l.filter(e=>!e.startsWith(`/`)).slice(0,5).map((e,t)=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>eo(e),className:`text-left text-xs leading-relaxed text-muted-foreground hover:text-foreground border border-transparent hover:border-border/60 rounded-lg px-3 py-2 hover:bg-background/60 transition-colors line-clamp-2`,title:e,children:e},t))})]}),(0,Y.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,Y.jsx)(Wt,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Quick commands`})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2`,children:$a.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>eo(e.name),className:`text-left flex flex-col gap-0.5 rounded-md border border-border/40 bg-background/60 px-3 py-2 hover:border-primary/40 hover:bg-accent/40 transition-colors`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-xs text-foreground`,children:e.name}),(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground truncate`,children:e.hint})]},e.name))})]})]})}var no=z.forwardRef(({className:e,children:t,...n},r)=>(0,Y.jsxs)(ue,{ref:r,className:J(`relative overflow-hidden`,e),...n,children:[(0,Y.jsx)(St,{className:`h-full w-full rounded-[inherit]`,children:t}),(0,Y.jsx)(ro,{}),(0,Y.jsx)(p,{})]}));no.displayName=ue.displayName;var ro=z.forwardRef(({className:e,orientation:t=`vertical`,...n},r)=>(0,Y.jsx)(Tt,{ref:r,orientation:t,className:J(`flex touch-none select-none transition-colors`,t===`vertical`&&`h-full w-2.5 border-l border-l-transparent p-[1px]`,t===`horizontal`&&`h-2.5 flex-col border-t border-t-transparent p-[1px]`,e),...n,children:(0,Y.jsx)(i,{className:`relative flex-1 rounded-full bg-border`})}));ro.displayName=Tt.displayName;function io(){let e=V(e=>e.thinkingBuffer);if(!e)return null;let t=e.split(`
|
|
102
|
+
`).slice(-6).join(`
|
|
103
|
+
`).trim();return(0,Y.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,Y.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-2 ring-offset-2 ring-offset-background ring-violet-500/20`,children:(0,Y.jsx)(Me,{className:`h-4 w-4 animate-pulse`})}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1 max-w-[85%] min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-violet-600 dark:text-violet-400 px-1`,children:`Thinking…`}),(0,Y.jsx)(`div`,{className:`rounded-2xl rounded-bl-md px-3 py-2 bg-violet-500/[0.04] border border-violet-500/20 text-foreground/80`,children:(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden`,children:t||`…`})})]})]})}function ao(){let{messages:e,isLoading:t}=V(),n=W(e=>e.sidebarOpen),r=W(e=>e.toggleSidebar),i=W(e=>e.compactMode),{totalTokens:a,startTime:o,lastInputTokens:s,maxContext:c,iteration:l}=U(),u=U(e=>e.session),d=u?.id,p=W(e=>d?e.sessionNicknames[d]:void 0),m=W(e=>e.setSessionNickname),h=u?.title,[g,_]=(0,z.useState)(!1),[y,b]=(0,z.useState)(``),x=Un(e=>e.entries),[S,C]=(0,z.useState)(!1),w=(0,z.useRef)(null);(0,z.useEffect)(()=>{if(!S)return;let e=e=>{w.current?.contains(e.target)||C(!1)},t=e=>{e.key===`Escape`&&C(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[S]);let{provider:T,model:D}=H(),O=(0,z.useRef)(null),k=Zn(e=>e.autonomy),A=(0,z.useCallback)(e=>{Zn.getState().set({autonomy:e}),B()?.send?.({type:`autonomy.switch`,payload:{mode:e}})},[]),[j,M]=(0,z.useState)(!1),[N,ee]=(0,z.useState)(!1),[te,P]=(0,z.useState)(!1),ne=c>0&&s>0?Math.min(100,Math.round(s/c*100)):0,[ie,ae]=(0,z.useState)(!0),[oe,se]=(0,z.useState)(0),[ce,F]=(0,z.useState)(!1),le=(0,z.useRef)(e.length),ue=(0,z.useCallback)(()=>O.current?.querySelector(`[data-radix-scroll-area-viewport]`)??null,[]);(0,z.useEffect)(()=>{let t=ue();if(!t)return;let n=()=>{let n=t.scrollHeight-t.scrollTop-t.clientHeight<120;ae(n),n&&(se(0),le.current=e.length),F(t.scrollTop>t.clientHeight&&t.scrollHeight>t.clientHeight*2.5)};return t.addEventListener(`scroll`,n,{passive:!0}),()=>t.removeEventListener(`scroll`,n)},[ue,e.length]),(0,z.useEffect)(()=>{let t=ue();if(t)if(ie)t.scrollTop=t.scrollHeight,le.current=e.length;else{let t=e.length-le.current;t>0&&se(t)}},[e,ie,ue]),(0,z.useEffect)(()=>{let e=ue();e&&(e.scrollTop=e.scrollHeight,ae(!0),se(0),le.current=V.getState().messages.length)},[d,ue]);let de=(0,z.useCallback)(()=>{let t=ue();t&&(t.scrollTo({top:t.scrollHeight,behavior:`smooth`}),ae(!0),se(0),le.current=e.length)},[ue,e.length]),fe=(0,z.useCallback)(()=>{let e=ue();e&&e.scrollTo({top:0,behavior:`smooth`})},[ue]),[pe,me]=(0,z.useState)(null),[he,_e]=(0,z.useState)(()=>Date.now()),ve=(0,z.useRef)(null);(0,z.useEffect)(()=>{t&&pe===null&&me(Date.now()),!t&&pe!==null&&me(null)},[t,pe]),(0,z.useEffect)(()=>{if(!t)return;let e=setInterval(()=>_e(Date.now()),500);return()=>clearInterval(e)},[t]);let be=e=>{if(!e)return`--`;let t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`},xe=(()=>{if(!t)return`idle`;let n=e[e.length-1];return n?.role===`assistant`&&n.content&&n.streaming?`streaming`:`thinking`})(),Se=xe===`idle`?`bg-muted text-muted-foreground`:xe===`streaming`?`bg-blue-500/10 text-blue-600 dark:text-blue-400`:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,Ce=c>0&&s>0||a.input>0||!!o;return(0,Y.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col border-b bg-card/95 backdrop-blur-sm supports-[backdrop-filter]:bg-card/80 shrink-0 sticky top-0 z-20`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1 overflow-hidden`,children:[!n&&(0,Y.jsx)($,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:r,title:`Open sidebar (Ctrl+\\\\)`,children:(0,Y.jsx)(v,{className:`h-4 w-4`})}),!n&&(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 mr-1`,children:(0,Y.jsx)(`div`,{className:`w-5 h-5 rounded bg-primary flex items-center justify-center`,children:(0,Y.jsx)(ye,{className:`h-3 w-3 text-primary-foreground`})})}),(0,Y.jsxs)(`span`,{className:J(`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium shrink-0 tabular-nums`,Se),title:`Agent state: ${xe}`,children:[xe!==`idle`&&(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-current animate-pulse`}),(0,Y.jsx)(`span`,{children:xe})]}),d&&(g?(0,Y.jsx)(`input`,{value:y,onChange:e=>b(e.target.value),onBlur:()=>{y.trim()&&m(d,y),_(!1)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),y.trim()&&m(d,y),_(!1)):e.key===`Escape`&&(e.preventDefault(),_(!1))},placeholder:`Session name…`,className:`h-5 px-1.5 text-[11px] bg-background border border-primary/40 rounded focus:outline-none focus:ring-1 focus:ring-ring shrink-0 w-32`,autoFocus:!0}):(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{b(p||h||``),_(!0)},className:`flex items-center gap-1 text-[11px] font-medium text-foreground/80 hover:text-foreground truncate max-w-[12rem] shrink-0 px-1 -mx-1 rounded hover:bg-muted/50 transition-colors`,title:`Click to rename session`,children:[(0,Y.jsx)(f,{className:`h-2.5 w-2.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:p||h||`Untitled`})]}))]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[x.length>1&&(0,Y.jsxs)(`div`,{ref:w,className:`relative shrink-0`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>C(e=>!e),className:`flex items-center gap-0.5 px-1 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors`,title:`Switch session`,children:[(0,Y.jsx)(Ge,{className:`h-3 w-3`}),(0,Y.jsx)(re,{className:`h-2.5 w-2.5`})]}),S&&(0,Y.jsx)(`div`,{className:`absolute left-0 top-full mt-1 z-40 w-64 rounded-md border bg-popover shadow-lg p-1 max-h-60 overflow-y-auto`,children:x.slice(0,15).map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{B()?.resumeSession?.(e.id),C(!1)},className:J(`w-full text-left px-2 py-1.5 rounded text-xs hover:bg-accent transition-colors`,e.isCurrent&&`bg-primary/10`),children:[(0,Y.jsx)(`div`,{className:`font-medium truncate`,children:e.title||`(empty)`}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[e.provider,`/`,e.model,` · `,e.tokenTotal.toLocaleString(),` tok`]})]},e.id))})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>W.getState().setModelSwitcherOpen(!0),className:`group hidden sm:flex items-center gap-1 px-2 py-0.5 rounded-md border bg-background/50 hover:bg-accent hover:border-primary/40 transition-colors text-[11px] min-w-0 shrink-0`,title:`Change provider / model (Ctrl+M)`,children:[(0,Y.jsx)(ln,{className:`h-3 w-3 text-muted-foreground group-hover:text-foreground shrink-0`}),(0,Y.jsxs)(`span`,{className:`font-mono truncate max-w-[9rem] xl:max-w-[16rem]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:T||`no-provider`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/40 mx-0.5`,children:`/`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:D||`no-model`})]})]}),(0,Y.jsxs)(`div`,{className:`hidden md:flex items-center gap-1.5 shrink-0`,children:[(0,Y.jsx)(qa,{}),(0,Y.jsx)(ma,{})]}),l&&(0,Y.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-medium bg-primary/10 text-primary shrink-0 hover:bg-primary/20 transition-colors cursor-pointer`,title:`Agent iteration — click to jump to live activity`,onClick:()=>document.getElementById(`chat-activity`)?.scrollIntoView({behavior:`smooth`,block:`center`}),children:[(0,Y.jsx)(Ve,{className:`h-3 w-3 animate-pulse`}),`iter `,l.index,l.max>0?`/${l.max}`:``]}),(0,Y.jsx)(Ki,{value:k,onChange:A,compact:!0})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,Y.jsxs)($,{variant:j?`secondary`:`ghost`,size:`icon`,className:J(`h-7 w-7 relative`,j&&`bg-amber-500/10 text-amber-600 dark:text-amber-400`),onClick:()=>M(e=>!e),title:`Running processes`,children:[(0,Y.jsx)(ge,{className:`h-4 w-4`}),j&&(0,Y.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-amber-500`})]}),(0,Y.jsxs)($,{variant:N?`secondary`:`ghost`,size:`icon`,className:J(`h-7 w-7 relative`,N&&`bg-violet-500/10 text-violet-600 dark:text-violet-400`),onClick:()=>ee(e=>!e),title:`Session checkpoints — rewind`,children:[(0,Y.jsx)(Ge,{className:`h-4 w-4`}),N&&(0,Y.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-violet-500`})]})]})]}),Ce&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-3 py-1 border-t bg-muted/20 text-[11px] text-muted-foreground`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 tabular-nums`,children:[c>0&&s>0&&(0,Y.jsx)(fi,{pct:ne,tokens:s,maxTokens:c,onClick:()=>P(!0)}),a.input>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:Q(a.input)}),(0,Y.jsx)(`span`,{children:`in`})]}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:Q(a.output)}),(0,Y.jsx)(`span`,{children:`out`})]}),a.cacheRead&&a.cacheRead>0&&(()=>{let e=(a.cacheRead??0)+a.input,t=e>0?Math.round((a.cacheRead??0)/e*100):0;return(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Cache hit ratio: ${t}%`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:Q(a.cacheRead)}),(0,Y.jsxs)(`span`,{children:[`cache (`,t,`%)`]})]})})(),(0,Y.jsx)(ha,{})]})]}),o&&(0,Y.jsx)(`span`,{className:`text-muted-foreground/70 tabular-nums shrink-0`,children:be(o)})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 relative overflow-hidden`,children:[(0,Y.jsx)(Ya,{}),!ie&&(0,Y.jsxs)(`button`,{type:`button`,onClick:de,className:J(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10 jump-bottom`,`flex items-center gap-2 px-4 py-2 rounded-full shadow-lg`,`bg-primary text-primary-foreground text-xs font-medium`,`hover:bg-primary/90 transition-colors animate-message`),children:[(0,Y.jsx)(Ut,{className:`h-3.5 w-3.5`}),oe>0?`${oe} new message${oe===1?``:`s`}`:`Jump to latest`]}),ce&&(0,Y.jsxs)(`button`,{type:`button`,onClick:fe,title:`Scroll to top (oldest)`,className:J(`absolute top-3 right-3 z-10`,`flex items-center gap-1 px-2.5 py-1 rounded-full shadow-md border`,`bg-background/90 backdrop-blur-sm text-[11px] text-muted-foreground`,`hover:text-foreground hover:bg-background transition-colors animate-message`),children:[(0,Y.jsx)(Fe,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:`Top`})]}),(0,Y.jsx)(no,{className:`h-full`,ref:O,children:(0,Y.jsxs)(`div`,{className:J(`mx-auto pb-8`,i?`max-w-5xl p-3 space-y-3`:`max-w-5xl p-4 space-y-6`),children:[e.length===0&&!t&&(0,Y.jsx)(to,{}),(()=>{let n=[];for(let t=0;t<e.length;t++){let r=R(e[t]);if(r.role===`tool`){let e=n[n.length-1];e&&e.kind===`tools`?e.tools.push(r):n.push({kind:`tools`,tools:[r],key:r.id})}else{let i=e[t-1];n.push({kind:`msg`,message:r,isFirst:!i||i.role!==r.role})}}let r=[];for(let e of n){if(e.kind===`msg`&&e.message.role===`user`){r.push({kind:`user`,message:e.message,key:e.message.id});continue}let t=r[r.length-1];if(t&&t.kind===`agent`)t.items.push(e);else{let t=e.kind===`msg`?e.message.id:e.key;r.push({kind:`agent`,items:[e],key:t})}}let a=null,o=e=>{let t=new Date(e);return`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`},s=e=>{let t=new Date(e),n=new Date,r=new Date(Date.now()-864e5);return o(e)===o(n.getTime())?`Today`:o(e)===o(r.getTime())?`Yesterday`:t.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,year:t.getFullYear()===n.getFullYear()?void 0:`numeric`})},c=e=>{if(e.kind===`user`)return e.message.timestamp;let t=R(e.items[0]);return t.kind===`msg`?t.message.timestamp:t.tools[0]?.timestamp},l=[];for(let e=0;e<r.length;e++){let n=R(r[e]),u=c(n),d=o(u);if(d!==a&&(l.push((0,Y.jsxs)(`div`,{className:`flex items-center gap-3 py-1 text-[11px] text-muted-foreground/70 uppercase tracking-wider font-medium`,children:[(0,Y.jsx)(`div`,{className:`flex-1 h-px bg-border/50`}),(0,Y.jsx)(`span`,{children:s(u)}),(0,Y.jsx)(`div`,{className:`flex-1 h-px bg-border/50`})]},`day-${d}-${e}`)),a=d),n.kind===`user`){l.push((0,Y.jsx)(Ka,{message:n.message,isFirst:!0},n.key));continue}let f=e===r.length-1;l.push((0,Y.jsx)(`div`,{className:J(`chat-turn`,i?`space-y-1`:`space-y-1.5`),children:n.items.map((e,r)=>{let i=r>0;if(e.kind===`msg`)return(0,Y.jsx)(Ka,{message:e.message,isFirst:!i&&e.isFirst,isContinuation:i},e.message.id);let a=f&&r===n.items.length-1&&t&&e.tools.some(e=>e.toolResult===void 0);return(0,Y.jsx)(Za,{tools:e.tools,defaultOpen:a,isContinuation:i},e.key)})},n.key))}return l})(),(0,Y.jsxs)(`div`,{id:`chat-activity`,children:[(0,Y.jsx)(io,{}),t&&(()=>{let t=e[e.length-1],n=e.filter(e=>e.role===`tool`&&e.toolResult===void 0),r=`Thinking…`;if(n.length>0){let e=Array.from(new Set(n.map(e=>e.toolName).filter(Boolean))),t=e.slice(0,2).join(`, `),i=e.length>2?` +${e.length-2}`:``;r=n.length===1?`Running ${t||`tool`}…`:`Running ${n.length} tools (${t}${i})…`}else t?.role===`assistant`&&t.content?r=`Writing reply…`:t?.role===`tool`&&t.toolResult!==void 0&&(r=`Thinking about the next step…`);let i=pe?Math.max(0,Math.floor((he-pe)/1e3)):0,a=i<60?`${i}s`:`${Math.floor(i/60)}m ${i%60}s`,o=``,s=t?.role===`assistant`&&t.streaming&&t.content?t:null;if(s){let e=ve.current;if(!e||e.id!==s.id)ve.current={id:s.id,at:Date.now(),len:s.content.length};else{let t=Math.max(1,he-e.at),n=Math.max(0,s.content.length-e.len);if(t>500&&n>0){let e=n*1e3/t;o=e>=1e3?`${(e/1e3).toFixed(1)}k ch/s`:`${Math.round(e)} ch/s`}}}else ve.current&&=null;return(0,Y.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,Y.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center bg-accent text-accent-foreground ring-2 ring-offset-2 ring-offset-background ring-accent/20`,children:(0,Y.jsx)(E,{className:`h-4 w-4`})}),(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,Y.jsx)(`div`,{className:`rounded-2xl px-4 py-3 bg-card border text-foreground`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,Y.jsxs)(`span`,{className:`flex gap-1`,children:[(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]`}),(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]`}),(0,Y.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce`})]}),(0,Y.jsx)(`span`,{className:`text-foreground/90`,children:r}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:a}),l&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[`· iter `,l.index,l.max>0?`/${l.max}`:``]}),o&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 tabular-nums`,children:[`· `,o]})]})})})]})})()]})]})})]}),(0,Y.jsxs)(`div`,{className:`border-t bg-card/50 backdrop-blur supports-[backdrop-filter]:bg-card/50 shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`max-w-5xl mx-auto px-4 pt-1.5 flex items-center gap-3 text-[10px] text-muted-foreground/50 select-none overflow-x-auto`,children:[(0,Y.jsxs)(`span`,{title:`Enter`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Enter`}),` send`]}),(0,Y.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Shift+Enter`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Shift`}),`+`,(0,Y.jsx)(`kbd`,{children:`↵`}),` newline`]}),(0,Y.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+\\\\`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+\\`}),` sidebar`]}),(0,Y.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+F`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+F`}),` search`]}),(0,Y.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+K`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+K`}),` palette`]}),(0,Y.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+L / Ctrl+N`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+L`}),` clear`]}),(0,Y.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Y.jsxs)(`span`,{title:`j/k to navigate`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`j`}),(0,Y.jsx)(`kbd`,{children:`k`}),` navigate`]}),(0,Y.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+M`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+M`}),` model`]}),(0,Y.jsx)(`span`,{className:`opacity-30`,children:`·`}),(0,Y.jsxs)(`span`,{title:`Ctrl+Shift+D`,className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(`kbd`,{children:`Ctrl+⇧D`}),` density`]})]}),(0,Y.jsx)(`div`,{className:`p-4`,children:(0,Y.jsx)(`div`,{className:`max-w-5xl mx-auto`,children:(0,Y.jsx)(da,{onOpenBreakdown:()=>P(!0)})})})]}),(0,Y.jsx)(Ja,{open:j,onClose:()=>M(!1)}),(0,Y.jsx)(fa,{open:N,onClose:()=>ee(!1)}),(0,Y.jsx)(pi,{open:te,onClose:()=>P(!1)})]})}cn.defineTheme(`wrongstack-dark`,{base:`vs-dark`,inherit:!0,rules:[{token:`comment`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.line`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.block`,foreground:`6e717a`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`6e717a`,fontStyle:`italic`},{token:`string`,foreground:`64d488`},{token:`string.escape`,foreground:`49d3c5`},{token:`string.template`,foreground:`64d488`},{token:`number`,foreground:`f2a23a`},{token:`number.hex`,foreground:`f2a23a`},{token:`number.float`,foreground:`f2a23a`},{token:`keyword`,foreground:`f28dbc`},{token:`keyword.control`,foreground:`f28dbc`},{token:`keyword.operator`,foreground:`9ea0a8`},{token:`type`,foreground:`6cb6ff`},{token:`type.identifier`,foreground:`6cb6ff`},{token:`type.parameter`,foreground:`eeede7`},{token:`function`,foreground:`6cb6ff`},{token:`predefined`,foreground:`6cb6ff`},{token:`variable`,foreground:`eeede7`},{token:`variable.parameter`,foreground:`f2a23a`},{token:`variable.readonly`,foreground:`f2a23a`},{token:`variable.language`,foreground:`f28dbc`},{token:`tag`,foreground:`f47a95`},{token:`metatag`,foreground:`f47a95`},{token:`tag.html`,foreground:`f47a95`},{token:`tag.jsx`,foreground:`f47a95`},{token:`tag.tsx`,foreground:`f47a95`},{token:`attribute.name`,foreground:`ffb055`},{token:`attribute.value`,foreground:`64d488`},{token:`attribute.name.html`,foreground:`ffb055`},{token:`attribute.name.jsx`,foreground:`ffb055`},{token:`regexp`,foreground:`49d3c5`},{token:`delimiter`,foreground:`9ea0a8`},{token:`delimiter.bracket`,foreground:`9ea0a8`},{token:`delimiter.parenthesis`,foreground:`9ea0a8`},{token:`delimiter.curly`,foreground:`9ea0a8`},{token:`delimiter.square`,foreground:`9ea0a8`},{token:`delimiter.array`,foreground:`9ea0a8`},{token:`operator`,foreground:`9ea0a8`},{token:`constant`,foreground:`f2a23a`},{token:`constant.language`,foreground:`f28dbc`},{token:`support`,foreground:`6cb6ff`},{token:`support.function`,foreground:`6cb6ff`},{token:`support.type`,foreground:`6cb6ff`},{token:`support.constant`,foreground:`f2a23a`},{token:`support.variable`,foreground:`eeede7`},{token:`storage`,foreground:`f28dbc`},{token:`storage.modifier`,foreground:`f28dbc`},{token:`storage.type`,foreground:`6cb6ff`},{token:`entity.name.type`,foreground:`6cb6ff`},{token:`entity.name.function`,foreground:`6cb6ff`},{token:`entity.other.inherited-class`,foreground:`6cb6ff`},{token:`entity.name.tag`,foreground:`f47a95`},{token:`entity.other.attribute-name`,foreground:`ffb055`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`6cb6ff`,fontStyle:`bold`},{token:`link`,foreground:`49d3c5`,fontStyle:`underline`},{token:`class`,foreground:`6cb6ff`},{token:`interface`,foreground:`49d3c5`},{token:`enum`,foreground:`f2a23a`},{token:`enumMember`,foreground:`f2a23a`},{token:`typeParameter`,foreground:`f2a23a`},{token:`namespace`,foreground:`6cb6ff`},{token:`method`,foreground:`6cb6ff`},{token:`property`,foreground:`eeede7`},{token:`property.readonly`,foreground:`f2a23a`},{token:`property.static`,foreground:`eeede7`},{token:`parameter`,foreground:`f2a23a`},{token:`variable.defaultLibrary`,foreground:`6cb6ff`},{token:`function.defaultLibrary`,foreground:`6cb6ff`},{token:`macro`,foreground:`c4a0ff`},{token:`decorator`,foreground:`c4a0ff`},{token:`label`,foreground:`f2a23a`},{token:`comment.deprecated`,foreground:`6e717a`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`6e717a`,fontStyle:`strikethrough`}],colors:{"editor.background":`#121318`,"editor.foreground":`#eeede7`,"editorCursor.foreground":`#f2a23a`,"editor.selectionBackground":`#f2a23a25`,"editor.selectionHighlightBackground":`#f2a23a15`,"editor.inactiveSelectionBackground":`#f2a23a10`,"editor.lineHighlightBackground":`#1a1c23`,"editorLineNumber.foreground":`#4a4d55`,"editorLineNumber.activeForeground":`#9ea0a8`,"editorRuler.foreground":`#1e2028`,"editorBracketMatch.background":`#f2a23a15`,"editorBracketMatch.border":`#f2a23a30`,"editor.findMatchBackground":`#f2a23a30`,"editor.findMatchHighlightBackground":`#f2a23a15`,"editorWidget.background":`#1a1c23`,"editorWidget.border":`#262830`,"editorSuggestWidget.background":`#1a1c23`,"editorSuggestWidget.border":`#262830`,"editorSuggestWidget.selectedBackground":`#262830`,"editorHoverWidget.background":`#1a1c23`,"editorHoverWidget.border":`#262830`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#4a4d5530`,"scrollbarSlider.hoverBackground":`#f2a23a50`,"scrollbarSlider.activeBackground":`#f2a23a70`,"minimap.background":`#121318`,"diffEditor.insertedTextBackground":`#64d48815`,"diffEditor.removedTextBackground":`#d63c3c15`,"sideBar.background":`#121318`,"sideBar.border":`#1e2028`,"input.background":`#1a1c23`,"input.border":`#262830`,"input.foreground":`#eeede7`,"input.placeholderForeground":`#6e717a`,focusBorder:`#f2a23a40`,"list.activeSelectionBackground":`#262830`,"list.hoverBackground":`#1e2028`,"dropdown.background":`#1a1c23`,"dropdown.border":`#262830`,"badge.background":`#f2a23a`,"badge.foreground":`#1a1208`,"editorBracketHighlighting.foreground1":`#f2a23a`,"editorBracketHighlighting.foreground2":`#6cb6ff`,"editorBracketHighlighting.foreground3":`#f28dbc`,"editorBracketHighlighting.foreground4":`#64d488`,"editorBracketHighlighting.foreground5":`#49d3c5`,"editorBracketHighlighting.foreground6":`#c4a0ff`,"editorBracketPairGuide.background1":`#f2a23a18`,"editorBracketPairGuide.background2":`#6cb6ff18`,"editorBracketPairGuide.background3":`#f28dbc18`,"editorBracketPairGuide.background4":`#64d48818`,"editorBracketPairGuide.background5":`#49d3c518`,"editorBracketPairGuide.background6":`#c4a0ff18`,"editorBracketPairGuide.activeBackground1":`#f2a23a30`,"editorBracketPairGuide.activeBackground2":`#6cb6ff30`,"editorBracketPairGuide.activeBackground3":`#f28dbc30`,"editorBracketPairGuide.activeBackground4":`#64d48830`,"editorBracketPairGuide.activeBackground5":`#49d3c530`,"editorBracketPairGuide.activeBackground6":`#c4a0ff30`}}),cn.defineTheme(`wrongstack-light`,{base:`vs`,inherit:!0,rules:[{token:`comment`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.line`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.block`,foreground:`9a9d99`,fontStyle:`italic`},{token:`comment.documentation`,foreground:`9a9d99`,fontStyle:`italic`},{token:`string`,foreground:`3b8c5a`},{token:`string.escape`,foreground:`17998e`},{token:`string.template`,foreground:`3b8c5a`},{token:`number`,foreground:`d97a12`},{token:`number.hex`,foreground:`d97a12`},{token:`number.float`,foreground:`d97a12`},{token:`keyword`,foreground:`d65a9a`},{token:`keyword.control`,foreground:`d65a9a`},{token:`keyword.operator`,foreground:`6b6d72`},{token:`type`,foreground:`3178c6`},{token:`type.identifier`,foreground:`3178c6`},{token:`type.parameter`,foreground:`1a1c23`},{token:`function`,foreground:`3178c6`},{token:`predefined`,foreground:`3178c6`},{token:`variable`,foreground:`1a1c23`},{token:`variable.parameter`,foreground:`d97a12`},{token:`variable.readonly`,foreground:`d97a12`},{token:`variable.language`,foreground:`d65a9a`},{token:`tag`,foreground:`c93a5e`},{token:`metatag`,foreground:`c93a5e`},{token:`tag.html`,foreground:`c93a5e`},{token:`tag.jsx`,foreground:`c93a5e`},{token:`tag.tsx`,foreground:`c93a5e`},{token:`attribute.name`,foreground:`d4893a`},{token:`attribute.value`,foreground:`3b8c5a`},{token:`attribute.name.html`,foreground:`d4893a`},{token:`attribute.name.jsx`,foreground:`d4893a`},{token:`regexp`,foreground:`17998e`},{token:`delimiter`,foreground:`6b6d72`},{token:`delimiter.bracket`,foreground:`6b6d72`},{token:`delimiter.parenthesis`,foreground:`6b6d72`},{token:`delimiter.curly`,foreground:`6b6d72`},{token:`delimiter.square`,foreground:`6b6d72`},{token:`delimiter.array`,foreground:`6b6d72`},{token:`operator`,foreground:`6b6d72`},{token:`constant`,foreground:`d97a12`},{token:`constant.language`,foreground:`d65a9a`},{token:`support`,foreground:`3178c6`},{token:`support.function`,foreground:`3178c6`},{token:`support.type`,foreground:`3178c6`},{token:`support.constant`,foreground:`d97a12`},{token:`support.variable`,foreground:`1a1c23`},{token:`storage`,foreground:`d65a9a`},{token:`storage.modifier`,foreground:`d65a9a`},{token:`storage.type`,foreground:`3178c6`},{token:`entity.name.type`,foreground:`3178c6`},{token:`entity.name.function`,foreground:`3178c6`},{token:`entity.other.inherited-class`,foreground:`3178c6`},{token:`entity.name.tag`,foreground:`c93a5e`},{token:`entity.other.attribute-name`,foreground:`d4893a`},{token:`invalid`,foreground:`d63c3c`},{token:`invalid.deprecated`,foreground:`d63c3c`},{token:`emphasis`,fontStyle:`italic`},{token:`strong`,fontStyle:`bold`},{token:`header`,foreground:`3178c6`,fontStyle:`bold`},{token:`link`,foreground:`17998e`,fontStyle:`underline`},{token:`class`,foreground:`3178c6`},{token:`interface`,foreground:`17998e`},{token:`enum`,foreground:`d97a12`},{token:`enumMember`,foreground:`d97a12`},{token:`typeParameter`,foreground:`d97a12`},{token:`namespace`,foreground:`3178c6`},{token:`method`,foreground:`3178c6`},{token:`property`,foreground:`1a1c23`},{token:`property.readonly`,foreground:`d97a12`},{token:`property.static`,foreground:`1a1c23`},{token:`parameter`,foreground:`d97a12`},{token:`variable.defaultLibrary`,foreground:`3178c6`},{token:`function.defaultLibrary`,foreground:`3178c6`},{token:`macro`,foreground:`8b5cf6`},{token:`decorator`,foreground:`8b5cf6`},{token:`label`,foreground:`d97a12`},{token:`comment.deprecated`,foreground:`9a9d99`,fontStyle:`italic strikethrough`},{token:`variable.deprecated`,foreground:`9a9d99`,fontStyle:`strikethrough`}],colors:{"editor.background":`#f7f7f5`,"editor.foreground":`#1a1c23`,"editorCursor.foreground":`#e07b0e`,"editor.selectionBackground":`#e07b0e18`,"editor.selectionHighlightBackground":`#e07b0e10`,"editor.inactiveSelectionBackground":`#e07b0e08`,"editor.lineHighlightBackground":`#f0efe9`,"editorLineNumber.foreground":`#bab8b0`,"editorLineNumber.activeForeground":`#6b6d72`,"editorRuler.foreground":`#e8e6de`,"editorBracketMatch.background":`#e07b0e12`,"editorBracketMatch.border":`#e07b0e25`,"editor.findMatchBackground":`#e07b0e25`,"editor.findMatchHighlightBackground":`#e07b0e12`,"editorWidget.background":`#f7f7f5`,"editorWidget.border":`#ddd9d0`,"editorSuggestWidget.background":`#f7f7f5`,"editorSuggestWidget.border":`#ddd9d0`,"editorSuggestWidget.selectedBackground":`#eeece2`,"editorHoverWidget.background":`#f7f7f5`,"editorHoverWidget.border":`#ddd9d0`,"scrollbar.shadow":`#00000000`,"scrollbarSlider.background":`#bab8b040`,"scrollbarSlider.hoverBackground":`#e07b0e50`,"scrollbarSlider.activeBackground":`#e07b0e70`,"minimap.background":`#f7f7f5`,"diffEditor.insertedTextBackground":`#3b8c5a12`,"diffEditor.removedTextBackground":`#d63c3c12`,"sideBar.background":`#f7f7f5`,"sideBar.border":`#e8e6de`,"input.background":`#ffffff`,"input.border":`#ddd9d0`,"input.foreground":`#1a1c23`,"input.placeholderForeground":`#9a9d99`,focusBorder:`#e07b0e35`,"list.activeSelectionBackground":`#eeece2`,"list.hoverBackground":`#f0efe9`,"dropdown.background":`#ffffff`,"dropdown.border":`#ddd9d0`,"badge.background":`#e07b0e`,"badge.foreground":`#ffffff`,"editorBracketHighlighting.foreground1":`#d97a12`,"editorBracketHighlighting.foreground2":`#3178c6`,"editorBracketHighlighting.foreground3":`#d65a9a`,"editorBracketHighlighting.foreground4":`#3b8c5a`,"editorBracketHighlighting.foreground5":`#17998e`,"editorBracketHighlighting.foreground6":`#8b5cf6`,"editorBracketPairGuide.background1":`#d97a1215`,"editorBracketPairGuide.background2":`#3178c615`,"editorBracketPairGuide.background3":`#d65a9a15`,"editorBracketPairGuide.background4":`#3b8c5a15`,"editorBracketPairGuide.background5":`#17998e15`,"editorBracketPairGuide.background6":`#8b5cf615`,"editorBracketPairGuide.activeBackground1":`#d97a1228`,"editorBracketPairGuide.activeBackground2":`#3178c628`,"editorBracketPairGuide.activeBackground3":`#d65a9a28`,"editorBracketPairGuide.activeBackground4":`#3b8c5a28`,"editorBracketPairGuide.activeBackground5":`#17998e28`,"editorBracketPairGuide.activeBackground6":`#8b5cf628`}});function oo(){return typeof document>`u`||document.documentElement.classList.contains(`dark`)?`wrongstack-dark`:`wrongstack-light`}g.config({monaco:u});var so={ts:`typescript`,tsx:`typescript`,js:`javascript`,jsx:`javascript`,json:`json`,css:`css`,html:`html`,svg:`xml`,md:`markdown`,yml:`yaml`,yaml:`yaml`,toml:`toml`,sh:`shell`,bash:`shell`,ps1:`powershell`,py:`python`,rs:`rust`,go:`go`,rb:`ruby`,java:`java`,c:`c`,cpp:`cpp`,h:`c`,hpp:`cpp`,sql:`sql`,xml:`xml`};function co(e){return so[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function lo(){let e=G(e=>e.openFiles),t=G(e=>e.activeFilePath),n=G(e=>e.setActiveFile),r=G(e=>e.closeFile);return e.length===0?null:(0,Y.jsx)(`div`,{className:`flex items-center border-b bg-muted/40 overflow-x-auto shrink-0`,children:e.map(e=>{let i=e.path===t,a=e.path.split(`/`).pop()??e.path;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),onMouseDown:t=>{t.button===1&&(t.preventDefault(),r(e.path))},className:J(`group flex items-center gap-1.5 px-3 py-1.5 text-[11px] border-r whitespace-nowrap min-w-0 max-w-[180px] transition-colors`,i?`bg-background border-t-2 border-t-primary text-foreground -mb-px`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),title:e.path,children:[e.dirty&&(0,Y.jsx)(Et,{className:`h-2 w-2 fill-current text-primary shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:a}),(0,Y.jsx)(L,{className:J(`h-3 w-3 shrink-0 rounded-sm hover:bg-muted-foreground/20 opacity-0 group-hover:opacity-100 transition-opacity`,i&&`opacity-100`),onClick:t=>{t.stopPropagation(),r(e.path)}})]},e.path)})})}function uo(){let e=G(e=>e.openFiles),t=G(e=>e.activeFilePath),n=G(e=>e.updateContent),{theme:r}=ni(),i=(0,z.useRef)(null),a=(0,z.useMemo)(()=>e.find(e=>e.path===t)??null,[e,t]),o=t?co(t):`plaintext`,s=oo();(0,z.useEffect)(()=>{let e=oo();cn.setTheme(e)},[r]);let c=(0,z.useCallback)(e=>{i.current=e,cn.setTheme(oo())},[]),l=(0,z.useCallback)(e=>{t&&e!==void 0&&n(t,e)},[t,n]);return(0,z.useEffect)(()=>{let e=e=>{let n=e.ctrlKey||e.metaKey,r=e.target?.tagName?.toLowerCase()===`textarea`||e.target?.closest(`.monaco-editor`)!==null;!n||!r||(e.key.toLowerCase()===`s`&&(e.preventDefault(),window.dispatchEvent(new CustomEvent(`wrongstack:save-file`,{detail:{filePath:t}}))),e.key.toLowerCase()===`w`&&(e.preventDefault(),t&&G.getState().closeFile(t)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e.length===0?(0,Y.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,Y.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No files open`}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/60`,children:`Select a file from the explorer to start editing`})]})}):(0,Y.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,Y.jsx)(lo,{}),(0,Y.jsx)(`div`,{className:`flex-1 relative`,children:a?(0,Y.jsx)(Te,{language:o,value:a.content,onChange:l,theme:s,onMount:c,loading:(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground animate-pulse`,children:`Loading editor…`})}),options:{minimap:{enabled:!1},fontSize:13,fontFamily:`'IBM Plex Mono', 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace`,lineNumbers:`on`,renderWhitespace:`selection`,scrollBeyondLastLine:!1,wordWrap:`off`,tabSize:2,smoothScrolling:!0,cursorBlinking:`smooth`,cursorSmoothCaretAnimation:`on`,bracketPairColorization:{enabled:!0},"semanticHighlighting.enabled":!0,automaticLayout:!0,padding:{top:8}}},a.path):(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Select a tab to view its content`})})})]})}var fo=Qe,po=Se,mo=mn,ho=z.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(an,{ref:n,className:J(`fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));ho.displayName=an.displayName;var go=z.forwardRef(({className:e,children:t,...n},r)=>(0,Y.jsxs)(mo,{children:[(0,Y.jsx)(ho,{}),(0,Y.jsxs)(pt,{ref:r,className:J(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...n,children:[t,(0,Y.jsxs)(gt,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`,children:[(0,Y.jsx)(L,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));go.displayName=pt.displayName;var _o=({className:e,...t})=>(0,Y.jsx)(`div`,{className:J(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});_o.displayName=`DialogHeader`;var vo=({className:e,...t})=>(0,Y.jsx)(`div`,{className:J(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});vo.displayName=`DialogFooter`;var yo=z.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(dn,{ref:n,className:J(`text-lg font-semibold leading-none tracking-tight`,e),...t}));yo.displayName=dn.displayName;var bo=z.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(Ke,{ref:n,className:J(`text-sm text-muted-foreground`,e),...t}));bo.displayName=Ke.displayName;function xo(e){return/edit|write|create|patch/i.test(e)?at:/bash|shell|exec|run|command/i.test(e)?ge:/fetch|http|web|curl|request/i.test(e)?r:s}function So({toolName:e,input:t}){let n=wa(e,t);if(n)return(0,Y.jsx)(`div`,{className:`rounded-lg overflow-hidden border`,children:(0,Y.jsx)(xa,{oldText:n.oldText,newText:n.newText,caption:n.caption})});if(typeof t==`object`&&t){let e=t,n=e.command??e.cmd??e.script;if(typeof n==`string`&&n.trim().length>0)return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b bg-muted/40 flex items-center gap-1.5`,children:[(0,Y.jsx)(ge,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:`Command`})]}),(0,Y.jsxs)(`pre`,{className:`px-3 py-2 text-xs font-mono whitespace-pre-wrap break-all max-h-40 overflow-auto`,children:[`$`,n]})]});let r=e.url;if(typeof r==`string`)return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-background/40 px-3 py-2 text-xs font-mono`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:(e.method??`GET`).toUpperCase()}),` `,(0,Y.jsx)(`span`,{className:`break-all`,children:r})]})}return(0,Y.jsxs)(`div`,{className:`p-3 rounded-lg bg-muted/50 border text-xs font-mono`,children:[(0,Y.jsx)(`div`,{className:`text-muted-foreground mb-2`,children:`Input:`}),(0,Y.jsx)(`pre`,{className:`whitespace-pre-wrap break-all max-h-60 overflow-auto`,children:JSON.stringify(t,null,2)})]})}function Co(){let{showConfirmDialog:e,confirmInfo:t,hideConfirm:n}=W(),{sendConfirm:r}=Z(),i=(0,z.useRef)(null),a=e=>{t&&r(t.id,e),n()};if((0,z.useEffect)(()=>{if(!e)return;let t=e=>{let t=e.target?.tagName?.toLowerCase();t===`input`||t===`textarea`||(e.key===`y`||e.key===`Y`?(e.preventDefault(),a(`yes`)):e.key===`n`||e.key===`N`||e.key===`Escape`?(e.preventDefault(),a(`no`)):e.key===`a`||e.key===`A`?(e.preventDefault(),a(`always`)):(e.key===`d`||e.key===`D`)&&(e.preventDefault(),a(`deny`)))};return window.addEventListener(`keydown`,t),i.current?.focus(),()=>window.removeEventListener(`keydown`,t)},[e,t?.id]),!t)return(0,Y.jsx)(fo,{open:e,onOpenChange:()=>n(),children:(0,Y.jsx)(go,{})});let o=xo(t.toolName),s=/edit|write/i.test(t.toolName);return(0,Y.jsx)(fo,{open:e,onOpenChange:()=>n(),children:(0,Y.jsxs)(go,{className:`sm:max-w-2xl border-yellow-500/50`,ref:i,tabIndex:-1,children:[(0,Y.jsxs)(_o,{children:[(0,Y.jsxs)(yo,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(At,{className:`h-5 w-5 text-yellow-500 animate-pulse`}),`Approval required: `,t.toolName]}),(0,Y.jsxs)(bo,{children:[`The agent wants to `,s?`modify a file`:`run this tool`,`. Review the request below and decide whether to proceed.`]})]}),(0,Y.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-muted`,children:[(0,Y.jsx)(o,{className:`h-5 w-5 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`font-medium font-mono truncate`,children:t.toolName}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[s?`File modification`:`Tool execution`,` — preview below`]})]})]}),t.input!==void 0&&(0,Y.jsx)(So,{toolName:t.toolName,input:t.input}),t.suggestedPattern&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20`,children:[(0,Y.jsx)(j,{className:`h-4 w-4 text-yellow-600 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{className:`text-sm min-w-0`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-yellow-800 dark:text-yellow-200`,children:`Trust pattern suggestion`}),(0,Y.jsx)(`div`,{className:`font-mono text-xs mt-1 break-all`,children:t.suggestedPattern}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Picking `,(0,Y.jsx)(`span`,{className:`font-medium`,children:`Always`}),` will whitelist matching calls for this project.`]})]})]})]}),(0,Y.jsxs)(vo,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`deny`),title:`Reject this and all future calls matching the pattern (d)`,children:[`Deny always `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`d`})]}),(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`no`),title:`Reject this single call (Esc / n)`,children:[`No `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`n`})]}),(0,Y.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`always`),title:`Approve and remember the pattern for the project (a)`,children:[`Always `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`a`})]}),(0,Y.jsxs)($,{size:`sm`,onClick:()=>a(`yes`),title:`Approve this single call (y)`,children:[`Yes `,(0,Y.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`y`})]})]})]})})}var wo=n()((e,t)=>({request:null,open:n=>{t().request?.resolve(!1),e({request:n})},settle:n=>{t().request?.resolve(n),e({request:null})}}));function To(e){return new Promise(t=>{wo.getState().open({...e,resolve:t})})}function Eo(){let e=wo(e=>e.request),t=wo(e=>e.settle);return(0,z.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Enter`&&(e.preventDefault(),wo.getState().settle(!0))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,Y.jsx)(fo,{open:e!==null,onOpenChange:e=>{e||t(!1)},children:(0,Y.jsxs)(go,{className:`max-w-md`,children:[(0,Y.jsxs)(_o,{children:[(0,Y.jsx)(yo,{children:e?.title}),e?.message&&(0,Y.jsx)(bo,{children:e.message})]}),(0,Y.jsxs)(vo,{className:`gap-2`,children:[(0,Y.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>t(!1),children:e?.cancelLabel??`Cancel`}),(0,Y.jsx)($,{variant:e?.danger?`destructive`:`default`,size:`sm`,autoFocus:!0,onClick:()=>t(!0),children:e?.confirmLabel??`Confirm`})]})]})})}function Do(){let e=H(e=>e.wsStatus),t=H(e=>e.wsUrl),[n,r]=(0,z.useState)(!1),[i,a]=(0,z.useState)(Date.now());if((0,z.useEffect)(()=>{if(e.state!==`reconnecting`)return;let t=setInterval(()=>a(Date.now()),500);return()=>clearInterval(t)},[e.state]),(0,z.useEffect)(()=>{e.state===`open`&&r(!1)},[e.state]),e.state===`open`||e.state===`connecting`||n)return null;let o=()=>B(t).retryNow(),s=e.state===`reconnecting`,c=e.state===`closed`?e.error:e.state===`reconnecting`?e.lastError:void 0,l=s?Math.max(0,Math.ceil((e.nextRetryAt-i)/1e3)):0;return(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-3 px-4 py-2 border-b text-sm`,s?`bg-orange-500/10 text-orange-700 dark:text-orange-300 border-orange-500/30`:`bg-red-500/10 text-red-700 dark:text-red-300 border-red-500/30`),children:[s?(0,Y.jsx)(D,{className:`h-4 w-4 animate-spin shrink-0`}):(0,Y.jsx)(T,{className:`h-4 w-4 shrink-0`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:s?`Reconnecting to backend (attempt ${e.attempt}) — retrying in ${l}s`:`Disconnected from backend`}),c&&(0,Y.jsx)(`div`,{className:`text-xs opacity-80 truncate`,children:c})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:o,className:J(`inline-flex items-center gap-1 px-2.5 py-1 rounded-md border text-xs font-medium`,`hover:bg-background/30 transition-colors shrink-0`,s?`border-orange-500/40`:`border-red-500/40`),title:`Retry connection now`,children:[(0,Y.jsx)(Mt,{className:`h-3 w-3`}),`Retry now`]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>r(!0),className:`text-current/60 hover:text-current shrink-0`,title:`Dismiss (chip in topbar still shows status)`,children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]})}var Oo=class extends z.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary]`,e,t.componentStack),this.props.onError?.(e,t)}handleReset=()=>{this.setState({error:null})};render(){return this.state.error?(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-screen bg-background`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md text-center`,children:[(0,Y.jsx)(j,{className:`h-12 w-12 text-destructive`}),(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Something went wrong`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`A rendering error occurred. Your session is still active on the server — reloading will pick up where you left off.`}),(0,Y.jsx)(`pre`,{className:`text-xs font-mono text-muted-foreground bg-muted/50 rounded p-3 max-h-32 overflow-auto w-full text-left`,children:this.state.error.message}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>window.location.reload(),children:[(0,Y.jsx)(Je,{className:`h-4 w-4 mr-1`}),`Reload page`]}),(0,Y.jsx)($,{size:`sm`,onClick:this.handleReset,children:`Try again`})]})]})}):this.props.children}};function ko(e,t,n,r,i){let a=[];for(let n of e){let e=t[n.id]??[];for(let t of e)a.push({provider:n.id,model:t.id,modelName:t.name||t.id,contextWindow:t.contextWindow,isCurrent:n.id===r&&t.id===i})}let o=n.toLowerCase().trim();return(o?a.filter(e=>e.provider.toLowerCase().includes(o)||e.model.toLowerCase().includes(o)||e.modelName.toLowerCase().includes(o)):a).sort((e,t)=>e.isCurrent===t.isCurrent?e.provider.localeCompare(t.provider)||e.model.localeCompare(t.model):e.isCurrent?-1:1)}function Ao(){let e=W(e=>e.modelSwitcherOpen),t=W(e=>e.setModelSwitcherOpen),[n,r]=(0,z.useState)(``),[i,a]=(0,z.useState)(0),[o,s]=(0,z.useState)([]),[c,l]=(0,z.useState)({}),u=(0,z.useRef)(null),d=H(e=>e.wsUrl),f=H(e=>e.provider),p=H(e=>e.model),m=W(e=>e.paletteOpen),{listSavedProviders:h,listProviderModels:g,switchModel:_}=Z();(0,z.useEffect)(()=>{let n=n=>{if((n.ctrlKey||n.metaKey)&&n.key.toLowerCase()===`m`&&!n.shiftKey&&!n.altKey){if(m)return;n.preventDefault(),t(!e);return}n.key===`Escape`&&e&&(n.preventDefault(),t(!1))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[e,m]),(0,z.useEffect)(()=>{let e=B(d),t=e.on(`providers.saved`,e=>{let t=e.payload;s(t.providers??[])}),n=e.on(`provider.models`,e=>{let t=e.payload;l(e=>({...e,[t.provider]:t.models}))});return()=>{t(),n()}},[d]),(0,z.useEffect)(()=>{e&&(r(``),a(0),h(),requestAnimationFrame(()=>u.current?.focus()))},[e,h]),(0,z.useEffect)(()=>{if(e)for(let e of o)c[e.id]||g(e.id)},[e,o,c,g]);let v=(0,z.useMemo)(()=>ko(o,c,n,f,p),[o,c,n,f,p]);(0,z.useEffect)(()=>{i>=v.length&&a(0)},[v.length,i]);let y=e=>{let n=v[e];n&&(_(n.provider,n.model),t(!1))};return e?(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center bg-background/60 backdrop-blur-sm pt-[15vh]`,onClick:e=>{e.target===e.currentTarget&&t(!1)},onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,Y.jsxs)(`div`,{className:`w-full max-w-xl rounded-xl border bg-popover shadow-2xl overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Y.jsx)(ft,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`input`,{ref:u,value:n,onChange:e=>{r(e.target.value),a(0)},onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),a(e=>Math.min(v.length-1,e+1))):e.key===`ArrowUp`?(e.preventDefault(),a(e=>Math.max(0,e-1))):e.key===`Enter`?(e.preventDefault(),y(i)):e.key===`Escape`&&(e.preventDefault(),t(!1))},placeholder:`Filter providers and models…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:`↑↓ · Enter · Esc`})]}),(0,Y.jsx)(`div`,{className:`max-h-[50vh] overflow-y-auto py-1`,children:v.length===0?(0,Y.jsx)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:o.length===0?`No saved providers — register a key in Settings first.`:`Loading models…`}):v.map((e,t)=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>y(t),onMouseEnter:()=>a(t),className:J(`w-full flex items-center gap-3 px-3 py-2 text-left text-sm transition-colors`,t===i?`bg-accent text-accent-foreground`:`hover:bg-accent/40`,e.isCurrent&&`font-medium`),children:[(0,Y.jsx)(ln,{className:J(`h-4 w-4 shrink-0`,e.isCurrent?`text-primary`:`text-muted-foreground`)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e.provider}),(0,Y.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`·`}),(0,Y.jsx)(`span`,{children:e.modelName})]}),e.contextWindow&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono`,children:[e.model,` · ctx `,e.contextWindow.toLocaleString()]})]}),e.isCurrent?(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-primary font-semibold`,children:`active`}):(0,Y.jsx)(C,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100`})]},`${e.provider}:${e.model}`))})]})}):null}var jo=z.forwardRef(({className:e,type:t,...n},r)=>(0,Y.jsx)(`input`,{type:t,className:J(`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,e),ref:r,...n}));jo.displayName=`Input`;var Mo=zt,No=z.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(ut,{ref:n,className:J(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,e),...t}));No.displayName=ut.displayName;var Po=z.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(jt,{ref:n,className:J(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm`,e),...t}));Po.displayName=jt.displayName;var Fo=z.forwardRef(({className:e,...t},n)=>(0,Y.jsx)(it,{ref:n,className:J(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));Fo.displayName=it.displayName;function Io({label:e,hint:t,selector:n,onChange:r,configKey:i,value:a}){let o=typeof a==`boolean`,s=W(e=>n?n(e):!1),c=H(e=>i?e[i]:!1),l=o?a:n?s:c;return(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,Y.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":l,onClick:()=>{if(o)r?.();else if(n)r?.();else if(i===`soundOnComplete`){let e=!H.getState().soundOnComplete;H.getState().setSoundOnComplete(e),e&&lr()}},className:J(`shrink-0 relative inline-flex h-5 w-9 rounded-full border transition-colors`,l?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,Y.jsx)(`span`,{className:J(`absolute top-0.5 left-0.5 h-3.5 w-3.5 rounded-full bg-background shadow transition-transform`,l&&`translate-x-4`)})})]})}function Lo({label:e,hint:t,value:n,min:r,max:i,step:a=1,onChange:o,unit:s}){return(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Y.jsx)(`input`,{type:`range`,min:r,max:i,step:a,value:n,onChange:e=>o(Number(e.target.value)),className:`w-24 h-1.5 accent-primary`}),(0,Y.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-right text-muted-foreground`,children:[n,s??``]})]})]})}function Ro({label:e,hint:t,value:n,options:r,onChange:i}){return(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,Y.jsx)(`select`,{value:n,onChange:e=>i(e.target.value),className:`shrink-0 h-8 rounded-md border bg-background px-2 text-xs`,children:r.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}var zo=[`anthropic`,`openai`,`google`,`openai-compatible`];function Bo({activeProvider:e,catalogProviders:t,isLoadingCatalog:n,savedProviders:i,isLoadingSaved:a,providerTab:o,setProviderTab:s,onSelectProvider:c,onAddKey:l,onDeleteKey:u,onSetActiveKey:d,onAddProvider:f,onRemoveProvider:p,catalogQuery:m,setCatalogQuery:h}){let[g,_]=(0,z.useState)(null),[v,y]=(0,z.useState)(``),[b,x]=(0,z.useState)(``),[S,C]=(0,z.useState)(!1),[w,T]=(0,z.useState)(!1),[E,O]=(0,z.useState)(``),[k,A]=(0,z.useState)(`openai-compatible`),[j,M]=(0,z.useState)(``),[ee,te]=(0,z.useState)(``),P=(0,z.useCallback)(e=>{!v.trim()||!b.trim()||(l(e,v.trim(),b.trim()),y(``),x(``),_(null))},[l,v,b]),ne=(0,z.useCallback)(()=>{E.trim()&&(f(E.trim(),k,j||void 0,ee||void 0),O(``),A(`openai-compatible`),M(``),te(``),T(!1))},[f,E,k,j,ee]),re=m.trim()?t.filter(e=>{let t=m.trim().toLowerCase();return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||e.family.toLowerCase().includes(t)}):t,ie=re.reduce((e,t)=>(e[t.family]||(e[t.family]=[]),e[t.family]?.push(t),e),{});return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,Y.jsxs)($,{variant:o===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>s(`catalog`),children:[(0,Y.jsx)(r,{className:`h-4 w-4 mr-1`}),`Catalog`]}),(0,Y.jsxs)($,{variant:o===`saved`?`default`:`outline`,size:`sm`,onClick:()=>s(`saved`),children:[(0,Y.jsx)(N,{className:`h-4 w-4 mr-1`}),`Saved (`,i.length,`)`]})]}),o===`catalog`&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsx)(jo,{placeholder:`Search ${t.length} providers (name / id / family)…`,value:m,onChange:e=>h(e.target.value),className:`text-sm`}),n&&t.length===0?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,Y.jsx)(D,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading catalog...`})]}):re.length===0&&m?(0,Y.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground text-sm`,children:[`No providers match "`,(0,Y.jsx)(`span`,{className:`font-mono`,children:m}),`".`]}):(0,Y.jsx)(Y.Fragment,{children:zo.map(t=>{let n=ie[t];return n?.length?(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:t}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:n.map(t=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>c(t.id),className:J(`flex flex-col items-start p-3 rounded-lg border text-left transition-all`,e===t.id?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border hover:bg-muted`),children:[(0,Y.jsxs)(`div`,{className:`flex w-full justify-between items-start`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,Y.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,t.id,`)`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.hasApiKey&&(0,Y.jsxs)(`span`,{className:`text-xs bg-green-500/10 text-green-600 px-2 py-0.5 rounded`,children:[(0,Y.jsx)(N,{className:`h-3 w-3 inline mr-1`}),`Configured`]}),t.envVars[0]&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`ENV: `,t.envVars[0]]}),e===t.id&&(0,Y.jsx)(F,{className:`h-4 w-4 text-primary`})]})]}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.modelCount,` models`,t.apiBase&&` · ${t.apiBase}`]})]},t.id))})]},t):null})})]}),o===`saved`&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Manage your API keys and provider configurations`}),(0,Y.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>T(!w),children:[(0,Y.jsx)(gn,{className:`h-4 w-4 mr-1`}),`Add Provider`]})]}),w&&(0,Y.jsxs)(`div`,{className:`p-4 border rounded-lg space-y-3 bg-muted/50`,children:[(0,Y.jsx)(`h4`,{className:`font-medium`,children:`Add Custom Provider`}),(0,Y.jsx)(jo,{placeholder:`Provider ID (e.g. my-llm-server)`,value:E,onChange:e=>O(e.target.value)}),(0,Y.jsxs)(`select`,{className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:k,onChange:e=>A(e.target.value),children:[(0,Y.jsx)(`option`,{value:`anthropic`,children:`Anthropic`}),(0,Y.jsx)(`option`,{value:`openai`,children:`OpenAI`}),(0,Y.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI Compatible`}),(0,Y.jsx)(`option`,{value:`google`,children:`Google`})]}),(0,Y.jsx)(jo,{placeholder:`Base URL (optional, e.g. http://localhost:11434/v1)`,value:j,onChange:e=>M(e.target.value)}),(0,Y.jsx)(jo,{type:`password`,placeholder:`API Key (optional)`,value:ee,onChange:e=>te(e.target.value)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)($,{size:`sm`,onClick:ne,disabled:!E.trim(),children:`Add`}),(0,Y.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>T(!1),children:`Cancel`})]})]}),a?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,Y.jsx)(D,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):i.length===0?(0,Y.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Y.jsx)(N,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,Y.jsx)(`p`,{children:`No saved providers yet`}),(0,Y.jsx)(`p`,{className:`text-sm`,children:`Add a provider to get started`})]}):i.map(e=>(0,Y.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between items-start`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h4`,{className:`font-medium`,children:e.id}),e.family&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.family})]}),(0,Y.jsx)(`div`,{className:`flex gap-2`,children:(0,Y.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>p(e.id),children:(0,Y.jsx)(Ue,{className:`h-4 w-4 text-destructive`})})})]}),e.baseUrl&&(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,Y.jsx)(r,{className:`h-3 w-3 inline mr-1`}),e.baseUrl]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:`API Keys`}),(0,Y.jsxs)($,{size:`sm`,variant:`ghost`,onClick:()=>_(g===e.id?null:e.id),children:[(0,Y.jsx)(gn,{className:`h-3 w-3 mr-1`}),`Add Key`]})]}),e.apiKeys.length===0&&!g&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No keys configured`}),e.apiKeys.map(t=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-muted/50 rounded`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:t.label}),t.isActive&&(0,Y.jsx)(`span`,{className:`ml-2 text-xs bg-green-500/10 text-green-600 px-1.5 py-0.5 rounded`,children:`Active`}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.maskedKey})]}),(0,Y.jsxs)(`div`,{className:`flex gap-1`,children:[!t.isActive&&(0,Y.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>d(e.id,t.label),children:`Set Active`}),(0,Y.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>u(e.id,t.label),children:(0,Y.jsx)(Ue,{className:`h-3 w-3 text-destructive`})})]})]},t.label)),g===e.id&&(0,Y.jsxs)(`div`,{className:`p-3 border rounded space-y-2 bg-background`,children:[(0,Y.jsx)(jo,{placeholder:`Key label (e.g. default, production)`,value:v,onChange:e=>y(e.target.value)}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(jo,{type:S?`text`:`password`,placeholder:`API key`,value:b,onChange:e=>x(e.target.value)}),(0,Y.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>C(!S),children:S?(0,Y.jsx)(hn,{className:`h-4 w-4`}):(0,Y.jsx)(on,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)($,{size:`sm`,onClick:()=>P(e.id),disabled:!v.trim()||!b.trim(),children:`Save Key`}),(0,Y.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>{_(null),y(``),x(``)},children:`Cancel`})]})]})]})]},e.id))]})]})}function Vo({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,setIsLoadingModels:i,onModelSelect:a,refreshModels:o}){let s=H(e=>e.model);return(0,Y.jsx)(`div`,{className:`space-y-4`,children:e?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:n?.name||e}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]}),(0,Y.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{i(!0),o(e)},children:(0,Y.jsx)(Je,{className:J(`h-4 w-4`,r&&`animate-spin`)})})]}),r&&!t[e]?(0,Y.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,Y.jsx)(D,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading models...`})]}):(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(t[e]||[]).map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:J(`w-full flex items-center justify-between p-3 rounded-lg border text-left transition-all`,s===e.id?`border-primary bg-primary/5 ring-2 ring-primary/20`:`border-border hover:bg-muted`),children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.name||e.id}),(0,Y.jsx)(`div`,{className:`flex gap-2 mt-1`,children:e.capabilities.map(e=>(0,Y.jsx)(`span`,{className:`text-xs bg-muted px-1.5 py-0.5 rounded`,children:e},e))})]}),(0,Y.jsxs)(`div`,{className:`text-right text-xs text-muted-foreground`,children:[e.contextWindow&&(0,Y.jsxs)(`div`,{children:[e.contextWindow/1e3,`k context`]}),e.inputCost&&e.outputCost&&(0,Y.jsxs)(`div`,{children:[`$`,e.inputCost,`/$`,e.outputCost]}),s===e.id&&(0,Y.jsx)(F,{className:`h-4 w-4 text-primary mt-1`})]})]},e.id)),t[e]?.length===0&&(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground text-center py-4`,children:`No models found for this provider. The catalog might be empty or still loading.`})]})]}):(0,Y.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,Y.jsx)(ln,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,Y.jsx)(`p`,{children:`Select a provider first`})]})})}function Ho(){let{setCurrentView:e}=W(),{provider:t,model:n,setProvider:i,setModel:a,wsConnected:o}=H(),{theme:s,setTheme:c}=ni(),l=Z(),u=l.client,{updatePrefs:d,switchAutonomy:f}=l,p=Zn(),m=(0,z.useCallback)((e,t)=>{p.set({[e]:t}),d({[e]:t})},[p,d]),[h,g]=(0,z.useState)([]),[_,v]=(0,z.useState)({}),[y,b]=(0,z.useState)([]),[x,S]=(0,z.useState)(!1),[C,w]=(0,z.useState)(!1),[T,D]=(0,z.useState)(!1),[O,k]=(0,z.useState)(`catalog`),[A,j]=(0,z.useState)(``),M=h.find(e=>e.id===t);(0,z.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;g(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),S(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;v(e=>({...e,[t.provider]:t.models})),w(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));b(t),D(!1),t.length>0&&k(`saved`)}};if(!o||!u)return;let r=u.on(`provider.catalog`,e),i=u.on(`provider.models`,t),a=u.on(`providers.saved`,n);return S(!0),D(!0),u.listProviders(),u.listSavedProviders(),()=>{r?.(),i?.(),a?.()}},[o,u]);let N=(0,z.useCallback)(e=>{i(e),_[e]||(w(!0),l.listProviderModels?.(e))},[_,i,l]),ee=(0,z.useCallback)(e=>{a(e);let t=H.getState().provider;l.switchModel?.(t,e),X.success(`Switching to ${t} / ${e}…`)},[a,l]),te=(0,z.useCallback)((e,t,n)=>{l.addKey?.(e,t,n)},[l]),ne=(0,z.useCallback)((e,t)=>{l.deleteKey?.(e,t)},[l]),re=(0,z.useCallback)((e,t)=>{l.setActiveKey?.(e,t)},[l]),ie=(0,z.useCallback)((e,t,n,r)=>{l.addProvider?.(e,t,n,r)},[l]),ae=(0,z.useCallback)(e=>{l.removeProvider?.(e)},[l]);return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,Y.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card shrink-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,Y.jsx)($,{variant:`ghost`,size:`icon`,onClick:()=>e(`chat`),children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]}),(0,Y.jsx)(no,{className:`flex-1`,children:(0,Y.jsx)(`div`,{className:`p-6 max-w-2xl mx-auto`,children:(0,Y.jsxs)(Mo,{defaultValue:`provider`,children:[(0,Y.jsxs)(No,{className:`w-full justify-start mb-6 grid grid-cols-5`,children:[(0,Y.jsxs)(Po,{value:`provider`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(Dt,{className:`h-3.5 w-3.5`}),`Provider`]}),(0,Y.jsxs)(Po,{value:`connection`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(r,{className:`h-3.5 w-3.5`}),`Connect`]}),(0,Y.jsxs)(Po,{value:`appearance`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(fe,{className:`h-3.5 w-3.5`}),`Look`]}),(0,Y.jsxs)(Po,{value:`agent`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(E,{className:`h-3.5 w-3.5`}),`Agent`]}),(0,Y.jsxs)(Po,{value:`features`,className:`gap-1 text-xs`,children:[(0,Y.jsx)(sn,{className:`h-3.5 w-3.5`}),`Feat.`]})]}),(0,Y.jsxs)(Fo,{value:`provider`,className:`space-y-4`,children:[(0,Y.jsx)(Bo,{activeProvider:t,catalogProviders:h,isLoadingCatalog:x,savedProviders:y,isLoadingSaved:T,providerTab:O,setProviderTab:k,onSelectProvider:N,onAddKey:te,onDeleteKey:ne,onSetActiveKey:re,onAddProvider:ie,onRemoveProvider:ae,catalogQuery:A,setCatalogQuery:j}),(0,Y.jsxs)(`div`,{className:`pt-4 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,Y.jsx)(ln,{className:`h-4 w-4 text-muted-foreground`}),`Model`]}),(0,Y.jsx)(Vo,{provider:t,catalogModels:_,currentCatalogProvider:M,isLoadingModels:C,setIsLoadingModels:w,onModelSelect:ee,refreshModels:e=>l.listProviderModels?.(e)})]})]}),(0,Y.jsxs)(Fo,{value:`connection`,className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`label`,{htmlFor:`websocket-url`,className:`text-sm font-medium flex items-center gap-2`,children:[(0,Y.jsx)(r,{className:`h-4 w-4 text-muted-foreground`}),`WebSocket Server URL`]}),(0,Y.jsx)(jo,{id:`websocket-url`,value:H.getState().wsUrl,onChange:e=>H.getState().setConfig({wsUrl:e.target.value}),placeholder:`ws://localhost:3457`,className:`font-mono text-sm`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`URL of the agent WebSocket server. The server runs alongside the CLI.`})]}),(0,Y.jsxs)(`div`,{className:`p-4 rounded-lg border bg-muted/50`,children:[(0,Y.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:`Starting the WebSocket Server`}),(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:[`Standalone: run `,(0,Y.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`./dev.ps1`}),` `,`from the repo root, or set WS_HOST/WS_PORT before launching`,` `,(0,Y.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`node packages/webui/dist/server/entry.js`}),`. Or alongside the CLI:`,` `,(0,Y.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`wstack --webui`}),`.`]})]})]}),(0,Y.jsxs)(Fo,{value:`appearance`,className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:`Theme`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-md`,children:[(0,Y.jsxs)($,{variant:s===`light`?`default`:`outline`,size:`sm`,onClick:()=>c(`light`),children:[(0,Y.jsx)(lt,{className:`h-4 w-4 mr-1`}),`Light`]}),(0,Y.jsxs)($,{variant:s===`dark`?`default`:`outline`,size:`sm`,onClick:()=>c(`dark`),children:[(0,Y.jsx)(wt,{className:`h-4 w-4 mr-1`}),`Dark`]}),(0,Y.jsxs)($,{variant:s===`system`?`default`:`outline`,size:`sm`,onClick:()=>c(`system`),children:[(0,Y.jsx)(se,{className:`h-4 w-4 mr-1`}),`System`]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:`System follows your OS-level light/dark preference.`})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsx)(`h3`,{className:`text-sm font-semibold mb-3 mt-3`,children:`Preferences`}),(0,Y.jsx)(Io,{label:`Compact density`,hint:`Tighter spacing throughout the chat.`,selector:e=>e.compactMode,onChange:()=>W.getState().toggleCompactMode()}),(0,Y.jsx)(Io,{label:`Sound on completion`,hint:`Play a soft chime when a run finishes.`,selector:null,configKey:`soundOnComplete`})]})]}),(0,Y.jsxs)(Fo,{value:`agent`,className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,Y.jsx)(Ve,{className:`h-4 w-4 text-muted-foreground`}),`Autonomy & Behavior`]}),(0,Y.jsx)(Ro,{label:`Autonomy mode`,hint:`How independently the agent proceeds between turns.`,value:p.autonomy,options:[{value:`off`,label:`Off — full manual control`},{value:`suggest`,label:`Suggest — suggests next steps`},{value:`auto`,label:`Auto — brief confirmation delay`},{value:`eternal`,label:`Eternal — autonomous until goal done`},{value:`eternal-parallel`,label:`Eternal Parallel — multi-agent fleet`}],onChange:e=>{p.set({autonomy:e}),f(e)}}),(0,Y.jsx)(Lo,{label:`Auto-proceed delay`,hint:`Milliseconds before the agent auto-proceeds in Auto mode. 0 = immediate.`,value:p.autonomyDelayMs,min:0,max:1e4,step:500,unit:`ms`,onChange:e=>m(`autonomyDelayMs`,e)}),(0,Y.jsx)(Io,{label:`YOLO mode`,hint:`Bypass tool confirmation prompts — the agent runs without asking.`,value:p.yolo,onChange:()=>m(`yolo`,!p.yolo)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(ye,{className:`h-4 w-4 text-muted-foreground`}),`Prompt Refinement`]}),(0,Y.jsx)(Io,{label:`Enable refine`,hint:`Rewrite prompts before sending — clearer instructions, better results.`,value:p.enhanceEnabled,onChange:()=>m(`enhanceEnabled`,!p.enhanceEnabled)}),(0,Y.jsx)(Lo,{label:`Refine delay`,hint:`Countdown before the refined prompt auto-sends.`,value:p.enhanceDelayMs,min:3e4,max:12e4,step:15e3,unit:`ms`,onChange:e=>m(`enhanceDelayMs`,e)}),(0,Y.jsx)(Ro,{label:`Refine language`,hint:`Keep your language or translate to English for the model.`,value:p.enhanceLanguage,options:[{value:`original`,label:`Original — keep your language`},{value:`english`,label:`English — translate to English`}],onChange:e=>m(`enhanceLanguage`,e)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(ye,{className:`h-4 w-4 text-muted-foreground`}),`Execution`]}),(0,Y.jsx)(Lo,{label:`Max iterations per run`,hint:`Hard cap on LLM turns per agent.run().`,value:p.maxIterations,min:10,max:2e3,step:10,onChange:e=>m(`maxIterations`,e)}),(0,Y.jsx)(Lo,{label:`Auto-proceed max iterations`,hint:`Stop auto-proceed after N iterations. 0 = unlimited.`,value:p.autoProceedMaxIterations,min:0,max:250,step:5,onChange:e=>m(`autoProceedMaxIterations`,e)}),(0,Y.jsx)(Io,{label:`Confirm before exit`,hint:`First Ctrl+C aborts work, second confirms exit.`,value:p.confirmExit,onChange:()=>m(`confirmExit`,!p.confirmExit)}),(0,Y.jsx)(Io,{label:`Chime on completion`,hint:`Terminal bell when an agent run finishes.`,value:p.chime,onChange:()=>m(`chime`,!p.chime)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(P,{className:`h-4 w-4 text-muted-foreground`}),`Fleet & Streaming`]}),(0,Y.jsx)(Io,{label:`Stream fleet events`,hint:`Show live subagent activity in the fleet panel.`,value:p.streamFleet,onChange:()=>m(`streamFleet`,!p.streamFleet)}),(0,Y.jsx)(Io,{label:`Next-step prediction`,hint:`After a turn completes, predict likely next steps.`,value:p.nextPrediction,onChange:()=>m(`nextPrediction`,!p.nextPrediction)})]})]}),(0,Y.jsxs)(Fo,{value:`features`,className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,Y.jsx)(sn,{className:`h-4 w-4 text-muted-foreground`}),`Feature Flags`]}),(0,Y.jsx)(Io,{label:`MCP servers`,hint:`Enable Model Context Protocol integrations.`,value:p.featureMcp,onChange:()=>m(`featureMcp`,!p.featureMcp)}),(0,Y.jsx)(Io,{label:`Plugins`,hint:`Load and run user-installed plugins.`,value:p.featurePlugins,onChange:()=>m(`featurePlugins`,!p.featurePlugins)}),(0,Y.jsx)(Io,{label:`Memory`,hint:`Persist and recall facts across sessions.`,value:p.featureMemory,onChange:()=>m(`featureMemory`,!p.featureMemory)}),(0,Y.jsx)(Io,{label:`Skills`,hint:`Load domain-specific skill prompts.`,value:p.featureSkills,onChange:()=>m(`featureSkills`,!p.featureSkills)}),(0,Y.jsx)(Io,{label:`Models registry`,hint:`Use the models.dev catalog for provider discovery.`,value:p.featureModelsRegistry,onChange:()=>m(`featureModelsRegistry`,!p.featureModelsRegistry)}),(0,Y.jsx)(Io,{label:`Index on start`,hint:`Build the codebase symbol index at session start.`,value:p.indexOnStart,onChange:()=>m(`indexOnStart`,!p.indexOnStart)})]}),(0,Y.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,Y.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,Y.jsx)(rt,{className:`h-4 w-4 text-muted-foreground`}),`Context & Debug`]}),(0,Y.jsx)(Io,{label:`Auto-compact context`,hint:`Automatically trim the context window when near limits.`,value:p.contextAutoCompact,onChange:()=>m(`contextAutoCompact`,!p.contextAutoCompact)}),(0,Y.jsx)(Ro,{label:`Compactor strategy`,hint:`How the context is compacted when it grows too large.`,value:p.contextStrategy,options:[{value:`hybrid`,label:`Hybrid — fast rules (default)`},{value:`intelligent`,label:`Intelligent — LLM summarization`},{value:`selective`,label:`Selective — LLM-driven selection`}],onChange:e=>m(`contextStrategy`,e)}),(0,Y.jsx)(Ro,{label:`Log level`,hint:`Minimum severity for server-side logging.`,value:p.logLevel,options:[{value:`debug`,label:`Debug — everything`},{value:`info`,label:`Info — normal flow`},{value:`warn`,label:`Warn — problems only`},{value:`error`,label:`Error — failures only`}],onChange:e=>m(`logLevel`,e)}),(0,Y.jsx)(Ro,{label:`Audit level`,hint:`Detail level for session audit logs.`,value:p.auditLevel,options:[{value:`minimal`,label:`Minimal — errors only`},{value:`standard`,label:`Standard — tool calls + errors`},{value:`full`,label:`Full — every event (large logs)`}],onChange:e=>m(`auditLevel`,e)})]})]})]})})})]})}function Uo({provider:e,isSelected:t,onSelect:n}){return(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:J(`w-full text-left rounded-xl border p-4 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-semibold text-sm`,children:e.name}),e.hasApiKey&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border border-emerald-500/20`,children:[(0,Y.jsx)(be,{className:`h-2.5 w-2.5`}),`Key set`]})]}),(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e.family,` · `,e.modelCount,` models`]})]}),t&&(0,Y.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,Y.jsx)(be,{className:`h-3 h-3 text-primary-foreground`})})]})})}function Wo({model:e,isSelected:t,onSelect:n}){let r=e.inputCost==null?null:`$${e.inputCost}/1M tok`,i=e.outputCost==null?null:`$${e.outputCost}/1M tok`,a=e.contextWindow?`${(e.contextWindow/1e6).toFixed(0)}M ctx`:null;return(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:J(`w-full text-left rounded-xl border p-3 transition-all`,`hover:border-primary/40 hover:bg-primary/5`,t?`border-primary bg-primary/10 ring-1 ring-primary/30`:`border-border bg-card`),children:(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a&&(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:a}),r&&i&&(0,Y.jsxs)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:[r,` · `,i]}),e.capabilities.slice(0,3).map(e=>(0,Y.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-primary/10 text-primary border border-primary/20`,children:e},e))]})]}),t&&(0,Y.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,Y.jsx)(be,{className:`h-3 w-3 text-primary-foreground`})})]})})}function Go({providerId:e,onSave:t}){let[n,r]=(0,z.useState)(``),[i,a]=(0,z.useState)(`default`),[o,s]=(0,z.useState)(!1);return(0,Y.jsxs)(`div`,{className:`space-y-3 p-4 rounded-xl border border-amber-500/30 bg-amber-500/5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(He,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium`,children:`API Key required`})]}),(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Enter your API key for `,e,`. The key is stored locally and never sent to any server other than the provider's API endpoint.`]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(jo,{type:`password`,placeholder:`sk-...`,value:n,onChange:e=>r(e.target.value),className:`font-mono text-sm`}),(0,Y.jsx)(jo,{placeholder:`Label (optional)`,value:i,onChange:e=>a(e.target.value),className:`w-28 text-sm`})]}),(0,Y.jsx)($,{onClick:async()=>{if(n.trim()){s(!0);try{B(H.getState().wsUrl).addKey(e,i.trim()||`default`,n.trim()),t(n.trim()),r(``),X.success(`API key saved`)}catch{X.error(`Failed to save API key`)}finally{s(!1)}}},disabled:!n.trim()||o,size:`sm`,children:o?(0,Y.jsx)(D,{className:`h-4 w-4 animate-spin`}):`Save Key`})]})}function Ko(){let{setCurrentView:e}=W(),{provider:t,model:n,setProvider:r,setModel:i,wsConnected:a,wsUrl:o}=H();Z();let[s,c]=(0,z.useState)(`provider`),[l,u]=(0,z.useState)([]),[d,f]=(0,z.useState)({}),[p,m]=(0,z.useState)([]),[h,g]=(0,z.useState)(!1),[_,v]=(0,z.useState)(!1),[y,b]=(0,z.useState)(null),[x,S]=(0,z.useState)(null);(0,z.useEffect)(()=>{if(!a)return;let e=B(o),r=e.on(`provider.catalog`,e=>{if(e.type===`provider.catalog`){let n=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));u(n),g(!1),t&&n.some(e=>e.id===t)?b(t):n.length===1&&b(n[0].id)}}),i=e.on(`provider.models`,e=>{if(e.type===`provider.models`){let t=e.payload;f(e=>({...e,[t.provider]:t.models})),v(!1),t.models.length===1?S(t.models[0].id):n&&t.models.some(e=>e.id===n)&&S(n)}}),s=e.on(`providers.saved`,e=>{if(e.type===`providers.saved`){let t=e.payload;m(t.providers.sort((e,t)=>e.id.localeCompare(t.id)))}});return g(!0),e.listProviders(),()=>{r?.(),i?.(),s?.()}},[a,o,t,n]),(0,z.useEffect)(()=>{if(!y||!a)return;let e=B(o);d[y]||(v(!0),e.listProviderModels(y))},[y,a,o,d]);let w=l.find(e=>e.id===y),T=p.find(e=>e.id===y)?.apiKeys.some(e=>e.isActive)||w?.hasApiKey,O=(0,z.useCallback)(e=>{b(e),S(null),c(`model`)},[]),A=(0,z.useCallback)(e=>{S(e),c(T?`done`:`apikey`)},[T]),j=(0,z.useCallback)(()=>{c(`done`)},[]),M=(0,z.useCallback)(()=>{if(!y||!x)return;r(y),i(x);let t=B(o);t.switchModel(y,x);let n=null,a=()=>{n&&clearTimeout(n)},s=t.on(`key.operation_result`,n=>{let r=n.payload;a(),s(),r.success?(t.newSession(),e(`chat`)):X.error(r.message)});n=setTimeout(()=>{a(),s(),X.error(`Model switch timed out. Please try again.`)},5e3)},[y,x,r,i,o,e]),N=y?d[y]??[]:[];return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,Y.jsx)(`header`,{className:`flex items-center justify-between px-6 py-4 border-b bg-card shrink-0`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`w-10 h-10 rounded-xl bg-gradient-to-br from-primary via-primary to-primary/60 flex items-center justify-center`,children:(0,Y.jsx)(ye,{className:`h-5 w-5 text-primary-foreground`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Welcome to WrongStack`}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Configure your AI provider to get started`})]})]})}),(0,Y.jsx)(no,{className:`flex-1`,children:(0,Y.jsxs)(`div`,{className:`p-6 max-w-2xl mx-auto space-y-8`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-1.5`,s===`provider`&&`text-primary font-medium`),children:[(0,Y.jsx)(Dt,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:`Provider`})]}),(0,Y.jsx)(k,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-1.5`,s===`model`&&`text-primary font-medium`),children:[(0,Y.jsx)(ln,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:`Model`})]}),(0,Y.jsx)(k,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-1.5`,(s===`apikey`||s===`done`)&&`text-primary font-medium`),children:[(0,Y.jsx)(He,{className:`h-4 w-4`}),(0,Y.jsx)(`span`,{children:`API Key`})]})]}),s===`provider`&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(Dt,{className:`h-4 w-4 text-primary`}),`Choose a Provider`]}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Select the AI provider you want to use. You can add API keys in the next step.`})]}),h?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Y.jsx)(D,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:l.map(e=>(0,Y.jsx)(Uo,{provider:e,isSelected:y===e.id,onSelect:()=>O(e.id)},e.id))})]}),s===`model`&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(ln,{className:`h-4 w-4 text-primary`}),`Choose a Model`]}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:w?`Models available for ${w.name}`:`Loading models...`})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>c(`provider`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change provider`}),_?(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,Y.jsx)(D,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):N.length>0?(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:N.map(e=>(0,Y.jsx)(Wo,{model:e,isSelected:x===e.id,onSelect:()=>A(e.id)},e.id))}):(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground py-8 text-center`,children:`No models available. Please check your API key.`})]}),s===`apikey`&&(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(He,{className:`h-4 w-4 text-primary`}),`Add Your API Key`]}),(0,Y.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[w?`Enter your API key for ${w.name}. `:`Enter your API key. `,`The key is stored locally and encrypted.`]})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>c(`model`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change model`}),y&&(0,Y.jsx)(Go,{providerId:y,onSave:j})]}),s===`done`&&(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8`,children:[(0,Y.jsx)(`div`,{className:`w-16 h-16 rounded-2xl bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 border border-emerald-500/30 flex items-center justify-center mb-4`,children:(0,Y.jsx)(be,{className:`h-8 w-8 text-emerald-500`})}),(0,Y.jsx)(`h2`,{className:`text-xl font-semibold`,children:`You're all set!`}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-sm`,children:`Configuration complete. Your agent is ready to start working.`})]}),(0,Y.jsxs)(`div`,{className:`rounded-xl border bg-card p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:y})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Model`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:x})]})]}),(0,Y.jsxs)($,{onClick:M,className:`w-full`,size:`lg`,children:[(0,Y.jsx)(E,{className:`h-4 w-4 mr-2`}),`Start Session`,(0,Y.jsx)(C,{className:`h-4 w-4 ml-2`})]})]})]})})]})}function qo(e){switch(e){case`running`:return`▶`;case`streaming`:return`↻`;case`waiting_user`:return`⏳`;case`error`:return`✗`;case`idle`:return`■`;default:return`?`}}function Jo(e){switch(e){case`running`:return`text-emerald-400`;case`streaming`:return`text-cyan-400`;case`waiting_user`:return`text-amber-400`;case`error`:return`text-red-400`;default:return`text-slate-500`}}function Yo(e){switch(e){case`active`:return`text-emerald-400`;case`idle`:return`text-cyan-400`;case`closing`:return`text-amber-400`;default:return`text-slate-500`}}function Xo(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`<1m`;if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d`}function Zo(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/1e3);if(n<10)return`just now`;if(n<60)return`${n}s ago`;let r=Math.floor(n/60);return r<60?`${r}m ago`:`${Math.floor(r/60)}h ago`}function Qo(){let[e,t]=(0,z.useState)([]),[n,r]=(0,z.useState)(!0),[i,a]=(0,z.useState)(null),o=(0,z.useCallback)(async()=>{try{let e=await fetch(`/api/sessions`);if(!e.ok){if(e.status===404){a(null),t([]);return}throw Error(`HTTP ${e.status}`)}t(await e.json()),a(null)}catch(e){a(e instanceof Error?e.message:String(e))}finally{r(!1)}},[]);return(0,z.useEffect)(()=>{o();let e=setInterval(o,5e3);return()=>clearInterval(e)},[o]),n?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-slate-400`,children:[(0,Y.jsx)(D,{className:`h-4 w-4 animate-spin`}),`Loading sessions...`]}):i?(0,Y.jsxs)(`div`,{className:`p-4 text-slate-500 text-sm`,children:[`Session API unavailable — run `,(0,Y.jsx)(`code`,{className:`text-cyan-400`,children:`wstack --webui`}),` with session tracking enabled.`]}):e.length===0?(0,Y.jsx)(`div`,{className:`p-4 text-slate-500 text-sm`,children:`No live sessions. Open another wstack instance to see it here.`}):(0,Y.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,Y.jsxs)(`h2`,{className:`text-sm font-semibold text-slate-200 uppercase tracking-wider`,children:[`Live Sessions (`,e.length,`)`]}),(0,Y.jsx)(`span`,{className:`text-xs text-slate-500`,children:`auto-refresh every 5s`})]}),e.map(e=>(0,Y.jsxs)(`div`,{className:`rounded-lg border border-slate-700 bg-slate-800/50 p-3 space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:Yo(e.status),children:e.status===`active`?(0,Y.jsx)(je,{className:`h-3.5 w-3.5 inline`}):e.status===`idle`?(0,Y.jsx)(T,{className:`h-3.5 w-3.5 inline`}):null}),(0,Y.jsx)(`span`,{className:`font-medium text-slate-200 text-sm`,children:e.projectName}),(0,Y.jsxs)(`span`,{className:`text-slate-500 text-xs`,children:[`[`,e.projectSlug,`]`]}),e.gitBranch?(0,Y.jsxs)(`span`,{className:`text-purple-400 text-xs flex items-center gap-1`,children:[(0,Y.jsx)(Yt,{className:`h-3 w-3`}),e.gitBranch]}):null,(0,Y.jsxs)(`span`,{className:`text-slate-500 text-xs ml-auto flex items-center gap-1`,children:[(0,Y.jsx)(de,{className:`h-3 w-3`}),Xo(e.startedAt)]}),(0,Y.jsxs)(`span`,{className:`text-slate-600 text-xs`,children:[`PID `,e.pid]})]}),(0,Y.jsxs)(`div`,{className:`text-slate-500 text-xs flex items-center gap-1`,children:[(0,Y.jsx)(ln,{className:`h-3 w-3`}),e.workingDir]}),(0,Y.jsxs)(`div`,{className:`space-y-1 mt-2`,children:[e.agents.slice(0,5).map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs pl-2 border-l-2 border-slate-700`,children:[(0,Y.jsx)(`span`,{className:Jo(e.status),children:qo(e.status)}),(0,Y.jsx)(`span`,{className:`text-slate-300 font-medium`,children:e.name}),e.currentTool?(0,Y.jsxs)(`span`,{className:`text-slate-500`,children:[`[`,e.currentTool,`]`]}):null,(0,Y.jsxs)(`span`,{className:`text-slate-600 ml-auto`,children:[e.iterations,` iter · `,e.toolCalls,` tools · `,Zo(e.lastActivityAt)]})]},e.id)),e.agents.length>5?(0,Y.jsxs)(`div`,{className:`text-slate-600 text-xs pl-4`,children:[`... and `,e.agents.length-5,` more`]}):null,e.agents.length===0?(0,Y.jsx)(`div`,{className:`text-slate-600 text-xs pl-4`,children:`No agents`}):null]})]},e.sessionId))]})}var $o=[{section:`Global`,items:[{keys:[`Ctrl`,`K`],description:`Open command palette`},{keys:[`?`],description:`Show this shortcuts overlay`},{keys:[`Ctrl`,`\\`],description:`Toggle sidebar`},{keys:[`Ctrl`,`1-6`],description:`Open side panel (Session, Agents, History, Files, Projects, Mailbox)`},{keys:[`Ctrl`,`/`],description:`Focus the message input`}]},{section:`Chat input`,items:[{keys:[`Enter`],description:`Send message`},{keys:[`Shift`,`Enter`],description:`Insert a newline`},{keys:[`↑`],description:`Recall previous prompt (in empty input)`},{keys:[`↓`],description:`Recall next prompt`},{keys:[`/`],description:`Open slash command popup`},{keys:[`Tab`],description:`Autocomplete highlighted command`},{keys:[`Esc`],description:`Dismiss popup / clear input`}]},{section:`Chat`,items:[{keys:[`Ctrl`,`F`],description:`Search within current chat`},{keys:[`Ctrl`,`L`],description:`Clear context (same as /clear)`},{keys:[`Ctrl`,`N`],description:`Start a new session (same as /new)`},{keys:[`Ctrl`,`E`],description:`Export chat as markdown`},{keys:[`Ctrl`,`M`],description:`Quick model switcher overlay`},{keys:[`Ctrl`,`Shift`,`D`],description:`Toggle compact UI density`},{keys:[`Esc`],description:`Abort the current run (when running)`}]},{section:`Chat navigation (when not typing)`,items:[{keys:[`j`],description:`Focus next message (alias: ↓)`},{keys:[`k`],description:`Focus previous message (alias: ↑)`},{keys:[`g`],description:`Jump to first message`},{keys:[`Shift`,`G`],description:`Jump to last message`},{keys:[`c`],description:`Copy focused message text`},{keys:[`Esc`],description:`Clear focused message`}]}];function es(){let e=W(e=>e.shortcutsOpen),t=W(e=>e.setShortcutsOpen);return(0,z.useEffect)(()=>{let e=e=>{let n=e.target,r=n?.tagName?.toLowerCase();if(!(r===`input`||r===`textarea`||n?.isContentEditable)&&e.key===`?`&&!e.ctrlKey&&!e.metaKey&&!e.altKey){e.preventDefault(),t(!W.getState().shortcutsOpen);return}e.key===`Escape`&&W.getState().shortcutsOpen&&(e.preventDefault(),t(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e?(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/60 backdrop-blur-sm flex items-center justify-center px-4`,onClick:()=>t(!1),onKeyDown:e=>{e.key===`Escape`&&t(!1)},children:(0,Y.jsxs)(`div`,{onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),className:`w-full max-w-2xl rounded-xl border bg-popover shadow-2xl overflow-hidden flex flex-col max-h-[80vh]`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Wt,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Keyboard shortcuts`})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`text-muted-foreground hover:text-foreground p-1 rounded hover:bg-muted`,children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]}),(0,Y.jsx)(`div`,{className:`overflow-y-auto px-5 py-4 space-y-6`,children:$o.map(e=>(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-2`,children:e.section}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-1.5`,children:e.items.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-sm px-2 py-1.5 rounded hover:bg-muted/40`,children:[(0,Y.jsx)(`span`,{className:`text-foreground/80`,children:e.description}),(0,Y.jsx)(`span`,{className:`flex items-center gap-1 shrink-0`,children:e.keys.map((e,t)=>(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[t>0&&(0,Y.jsx)(`span`,{className:`text-muted-foreground/40 text-xs`,children:`+`}),(0,Y.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1.5 py-0.5 bg-background`,children:e})]},e))})]},e.description))})]},e.section))}),(0,Y.jsxs)(`div`,{className:`border-t px-5 py-3 text-xs text-muted-foreground`,children:[`Press`,` `,(0,Y.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1 py-0.5 bg-background`,children:`?`}),` `,`any time to reopen this list.`]})]})}):null}function ts(){return(0,Y.jsx)(`style`,{children:`
|
|
104
|
+
.react-flow__node {
|
|
105
|
+
cursor: pointer;
|
|
106
|
+
transition: transform 0.15s ease;
|
|
107
|
+
}
|
|
108
|
+
.react-flow__node:hover {
|
|
109
|
+
transform: scale(1.02);
|
|
110
|
+
}
|
|
111
|
+
.react-flow__edge-path {
|
|
112
|
+
transition: stroke-width 0.2s ease, stroke-opacity 0.2s ease;
|
|
113
|
+
}
|
|
114
|
+
/* Animated edges with flowing dashes */
|
|
115
|
+
.animated-edge {
|
|
116
|
+
animation: flowDash 1s linear infinite;
|
|
117
|
+
}
|
|
118
|
+
@keyframes flowDash {
|
|
119
|
+
0% { stroke-dashoffset: 10; }
|
|
120
|
+
100% { stroke-dashoffset: 0; }
|
|
121
|
+
}
|
|
122
|
+
/* Custom controls styling */
|
|
123
|
+
.react-flow__controls {
|
|
124
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
|
125
|
+
border-radius: 8px;
|
|
126
|
+
overflow: hidden;
|
|
127
|
+
border: 1px solid hsl(var(--border));
|
|
128
|
+
}
|
|
129
|
+
.react-flow__controls-button {
|
|
130
|
+
background: transparent;
|
|
131
|
+
border: none;
|
|
132
|
+
color: hsl(var(--foreground));
|
|
133
|
+
transition: background 0.2s ease;
|
|
134
|
+
}
|
|
135
|
+
.react-flow__controls-button:hover {
|
|
136
|
+
background: hsl(var(--muted));
|
|
137
|
+
}
|
|
138
|
+
.react-flow__controls-button svg {
|
|
139
|
+
fill: currentColor;
|
|
140
|
+
}
|
|
141
|
+
/* MiniMap styling */
|
|
142
|
+
.react-flow__minimap {
|
|
143
|
+
border-radius: 8px;
|
|
144
|
+
overflow: hidden;
|
|
145
|
+
border: 1px solid hsl(var(--border));
|
|
146
|
+
}
|
|
147
|
+
/* Selection styling */
|
|
148
|
+
.react-flow__node.selected {
|
|
149
|
+
z-index: 100;
|
|
150
|
+
}
|
|
151
|
+
/* Edge hover */
|
|
152
|
+
.react-flow__edge:hover .react-flow__edge-path {
|
|
153
|
+
stroke-width: 3;
|
|
154
|
+
}
|
|
155
|
+
/* React Flow attribution hidden */
|
|
156
|
+
.react-flow__attribution {
|
|
157
|
+
display: none;
|
|
158
|
+
}
|
|
159
|
+
/* Background dots styling */
|
|
160
|
+
.react-flow__background {
|
|
161
|
+
background-color: hsl(var(--background));
|
|
162
|
+
}
|
|
163
|
+
`})}var ns={read:(0,Y.jsx)(nn,{className:`h-3 w-3`}),write:(0,Y.jsx)(nn,{className:`h-3 w-3`}),bash:(0,Y.jsx)(ge,{className:`h-3 w-3`}),exec:(0,Y.jsx)(ge,{className:`h-3 w-3`}),glob:(0,Y.jsx)(Xe,{className:`h-3 w-3`}),grep:(0,Y.jsx)(t,{className:`h-3 w-3`}),edit:(0,Y.jsx)(s,{className:`h-3 w-3`}),fetch:(0,Y.jsx)(r,{className:`h-3 w-3`}),search:(0,Y.jsx)(t,{className:`h-3 w-3`})};function rs({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#22c55e`;return(0,Y.jsxs)(`div`,{className:J(`rounded-lg border-2 p-3 min-w-[160px] transition-all`,t?`border-emerald-500/50 bg-emerald-500/10`:`border-gray-500/40 bg-gray-500/10`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:J(`flex items-center justify-center w-8 h-8 rounded-lg`,t?`bg-emerald-500/20`:`bg-gray-500/20`),children:(0,Y.jsx)(Xe,{className:`h-4 w-4`,style:{color:n}})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-bold truncate`,style:{color:n},children:e.label}),e.sublabel&&(0,Y.jsx)(`div`,{className:`text-[9px] text-gray-500 truncate`,children:e.sublabel})]}),t&&(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-400 animate-pulse`,style:{boxShadow:`0 0 8px hsl(140,70%,50%)`}})]}),e.stats&&(0,Y.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-white/10 grid grid-cols-3 gap-1 text-[9px]`,children:[e.stats.iterations!==void 0&&(0,Y.jsxs)(`div`,{className:`text-center`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-emerald-400`,children:e.stats.iterations}),(0,Y.jsx)(`div`,{className:`text-gray-500`,children:`iter`})]}),e.stats.toolCalls!==void 0&&(0,Y.jsxs)(`div`,{className:`text-center`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-blue-400`,children:e.stats.toolCalls}),(0,Y.jsx)(`div`,{className:`text-gray-500`,children:`tools`})]}),e.stats.costUsd!==void 0&&e.stats.costUsd>0&&(0,Y.jsxs)(`div`,{className:`text-center`,children:[(0,Y.jsxs)(`div`,{className:`font-mono text-amber-400`,children:[`$`,e.stats.costUsd.toFixed(3)]}),(0,Y.jsx)(`div`,{className:`text-gray-500`,children:`cost`})]})]})]})}function is({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.status===`error`,r=e.color||`#a855f7`;return(0,Y.jsxs)(`div`,{className:J(`rounded-lg border-2 p-2.5 min-w-[140px] transition-all`,t?`border-purple-500/50 bg-purple-500/10`:n?`border-red-500/50 bg-red-500/10`:`border-gray-500/40 bg-gray-500/10`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:J(`flex items-center justify-center w-7 h-7 rounded-lg`,t?`bg-purple-500/20`:`bg-purple-500/10`),children:(0,Y.jsx)(E,{className:`h-4 w-4`,style:{color:r}})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-bold truncate`,style:{color:r},children:e.label}),e.currentTool&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 text-[9px] text-amber-400/70`,children:[(0,Y.jsx)(s,{className:`h-2.5 w-2.5`}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool})]})]}),t&&(0,Y.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-purple-400 animate-pulse`,style:{boxShadow:`0 0 6px hsl(280,80%,60%)`}})]}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between text-[9px]`,children:[(0,Y.jsxs)(`span`,{className:`text-gray-500`,children:[`iter `,e.stats?.iterations??0]}),(0,Y.jsxs)(`span`,{className:`text-gray-500`,children:[`tools `,e.stats?.toolCalls??0]}),e.stats?.costUsd!==void 0&&e.stats.costUsd>0&&(0,Y.jsxs)(`span`,{className:`text-emerald-400/70`,children:[`$`,e.stats.costUsd.toFixed(3)]})]}),e.stats?.ctxPct!==void 0&&(0,Y.jsxs)(`div`,{className:`mt-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[9px] mb-0.5`,children:[(0,Y.jsx)(`span`,{className:`text-gray-500`,children:`ctx`}),(0,Y.jsxs)(`span`,{className:e.stats.ctxPct>80?`text-red-400`:e.stats.ctxPct>60?`text-amber-400`:`text-gray-400`,children:[e.stats.ctxPct,`%`]})]}),(0,Y.jsx)(`div`,{className:`h-1 rounded-full bg-black/30 overflow-hidden`,children:(0,Y.jsx)(`div`,{className:J(`h-full rounded-full transition-all`,e.stats.ctxPct>80?`bg-red-500`:e.stats.ctxPct>60?`bg-amber-500`:`bg-blue-500`),style:{width:`${Math.min(100,e.stats.ctxPct)}%`}})})]})]})}function as({data:e}){let t=e.color||`#f59e0b`,n=ns[e.label?.toLowerCase()??``]||(0,Y.jsx)(s,{className:`h-3 w-3`});return(0,Y.jsxs)(`div`,{className:`rounded-lg border border-amber-500/30 bg-amber-500/10 p-2 min-w-[100px] transition-all`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{style:{color:t},children:n}),(0,Y.jsx)(`span`,{className:`text-[10px] font-mono font-medium truncate`,style:{color:t},children:e.label})]}),e.stats?.durationMs!==void 0&&(0,Y.jsxs)(`div`,{className:`mt-1 text-[9px] text-gray-500 text-center`,children:[e.stats.durationMs,`ms`]})]})}function os({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#06b6d4`;return(0,Y.jsx)(`div`,{className:J(`rounded-lg border-2 p-3 min-w-[120px] transition-all`,t?`border-cyan-500/50 bg-cyan-500/10`:`border-cyan-500/30 bg-cyan-500/5`),children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:J(`flex items-center justify-center w-8 h-8 rounded-lg`,t?`bg-cyan-500/20`:`bg-cyan-500/10`),children:(0,Y.jsx)(ln,{className:`h-4 w-4`,style:{color:n}})}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-bold`,style:{color:n},children:`LLM`}),(0,Y.jsx)(`div`,{className:`text-[9px] text-gray-500 truncate`,children:e.sublabel||`Provider`})]}),t&&(0,Y.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-cyan-400 animate-pulse`,style:{boxShadow:`0 0 8px hsl(180,80%,60%)`}})]})})}function ss({data:e}){let t=e.color||`#3b82f6`;return(0,Y.jsxs)(`div`,{className:`rounded-lg border border-blue-500/30 bg-blue-500/10 p-2 min-w-[90px] transition-all`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(d,{className:`h-3 w-3`,style:{color:t}}),(0,Y.jsx)(`span`,{className:`text-[10px] font-medium`,style:{color:t},children:`Context`})]}),e.stats?.ctxPct!==void 0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`mt-1 text-[9px] text-center text-gray-400`,children:[e.stats.ctxPct,`%`]}),(0,Y.jsx)(`div`,{className:`h-1 mt-0.5 rounded-full bg-black/30 overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full rounded-full bg-blue-500`,style:{width:`${Math.min(100,e.stats.ctxPct)}%`}})})]})]})}var cs={session:rs,agent:is,tool:as,provider:os,context:ss};function ls({id:e,sourceX:t,sourceY:n,targetX:r,targetY:i,data:a,selected:o}){let[s,c,l]=us(t,n,r,i),u=a?.color||`#6366f1`,d=a?.animated;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`path`,{id:e,d:s,fill:`none`,stroke:u,strokeWidth:o?3:2,strokeOpacity:.5,className:`react-flow__edge-path`}),d&&(0,Y.jsx)(`path`,{d:s,fill:`none`,stroke:u,strokeWidth:2,strokeDasharray:`5 5`,className:`animated-edge`}),a?.label&&(0,Y.jsx)(`foreignObject`,{width:80,height:20,x:c-40,y:l-10,className:`overflow-visible`,children:(0,Y.jsx)(`div`,{className:`text-[8px] text-center bg-background/80 px-1 py-0.5 rounded border border-border`,children:a.label})})]})}function us(e,t,n,r){let i=Math.abs(n-e),a=Math.max(40,i*.4),o=(e+n)/2,s=Math.min(t,r)-a;return[`M ${e} ${t} C ${e} ${s}, ${n} ${s}, ${n} ${r}`,o,s]}var ds={flow:ls};function fs({containerRef:e}){let{fitView:t}=tn(),n=U(e=>e.session),r=U(e=>e.projectName),i=U(e=>e.iteration),a=U(e=>e.cost),o=U(e=>e.lastInputTokens),s=U(e=>e.maxContext),c=Kn(e=>e.agents);er(e=>e.nodes),er(e=>e.edges);let l=er(e=>e.events),u=er(e=>e.counters),[d,f,p]=Ot([]),[m,h,g]=tt([]),[_,v]=(0,z.useState)(null);(0,z.useEffect)(()=>{let e=[],l=[];e.push({id:`provider`,type:`provider`,position:{x:400,y:20},data:{label:`LLM`,sublabel:n?.model||`claude-3-5-sonnet`,type:`provider`,status:n?`active`:`idle`,color:`#06b6d4`}}),e.push({id:`session`,type:`session`,position:{x:400,y:120},data:{label:n?.title||r||`Session`,sublabel:n?.id.slice(0,8),type:`session`,status:n?`active`:`idle`,color:`#22c55e`,stats:{iterations:i?.index,toolCalls:Array.from(c.values()).reduce((e,t)=>e+t.toolCalls,0),costUsd:a}}});let u=s?Math.round(o/s*100):0;e.push({id:`context`,type:`context`,position:{x:700,y:200},data:{label:`Context`,type:`context`,status:u>80?`active`:`idle`,color:`#3b82f6`,stats:{ctxPct:u}}});let d=Array.from(c.values()),p=Math.min(200,800/(d.length+1)),m=Math.max(100,(800-(d.length-1)*p)/2);d.forEach((t,n)=>{let r=t.status===`running`,i=t.status===`failed`,a=`agent-${t.id}`,o=i?`#ef4444`:r?`#a855f7`:`#8b5cf6`;e.push({id:a,type:`agent`,position:{x:m+n*p,y:300},data:{label:t.name,type:`agent`,status:r?`active`:i?`error`:t.status===`completed`?`completed`:`idle`,color:o,stats:{iterations:t.iteration,toolCalls:t.toolCalls,costUsd:t.costUsd,ctxPct:t.ctxPct},currentTool:t.currentTool||t.lastTool}}),l.push({id:`session->${a}`,source:`session`,target:a,type:`flow`,animated:r,data:{color:o,animated:r}}),l.push({id:`${a}->provider`,source:a,target:`provider`,type:`flow`,animated:r,data:{color:`#06b6d4`,animated:r}});let s=t.currentTool||t.lastTool;if(s){let i=`tool-${t.id}-${d.indexOf(t)}`;e.push({id:i,type:`tool`,position:{x:m+n*p,y:450},data:{label:s,type:`tool`,status:r?`active`:`idle`,color:`#f59e0b`,stats:{durationMs:t.toolLog?.[0]?.durationMs}}}),l.push({id:`${a}->${i}`,source:a,target:i,type:`flow`,animated:r,data:{color:`#f59e0b`,animated:r,label:s}})}}),l.push({id:`provider->session`,source:`provider`,target:`session`,type:`flow`,animated:!!n,data:{color:`#06b6d4`,animated:!!n,label:`llm`}}),l.push({id:`context->session`,source:`context`,target:`session`,type:`flow`,data:{color:`#3b82f6`}}),f(e),h(l),setTimeout(()=>t({padding:.2,duration:300}),50)},[n,r,i,c,a,o,s,f,h,t]),(0,z.useEffect)(()=>{if(l.length===0)return;let e=l[0];if(e){if(e.kind===`agent:tool`&&e.source){let t=`agent-${e.source}`;f(n=>n.map(n=>n.id===t?{...n,data:{...n.data,status:`streaming`,currentTool:e.label}}:n))}if(e.kind===`agent:status`){let t=`agent-${e.source}`,n=e.label.includes(`completed`)?`completed`:e.label.includes(`failed`)?`error`:e.label.includes(`running`)?`active`:`idle`;f(e=>e.map(e=>e.id===t?{...e,data:{...e.data,status:n}}:e))}}},[l,f]);let y=(0,z.useCallback)(e=>h(t=>It({...e,type:`flow`},t)),[h]),b=(0,z.useCallback)((e,t)=>{v(t)},[]),x=(0,z.useCallback)(()=>{v(null)},[]);return(0,Y.jsxs)(`div`,{className:`w-full h-full bg-background relative`,children:[(0,Y.jsx)(ts,{}),(0,Y.jsxs)(Jt,{nodes:d,edges:m,onNodesChange:p,onEdgesChange:g,onConnect:y,onNodeClick:b,onPaneClick:x,nodeTypes:cs,edgeTypes:ds,fitView:!0,attributionPosition:`bottom-left`,proOptions:{hideAttribution:!0},children:[(0,Y.jsx)(Zt,{variant:Nt.Dots,gap:20,size:1,color:`hsl(var(--border))`}),(0,Y.jsx)(Gt,{className:`!bg-background/80 !border-border backdrop-blur`}),(0,Y.jsx)(yt,{className:`!bg-background/80 !border-border`,nodeColor:e=>{switch(e.type){case`session`:return`#22c55e`;case`agent`:return`#a855f7`;case`tool`:return`#f59e0b`;case`provider`:return`#06b6d4`;case`context`:return`#3b82f6`;default:return`#6366f1`}}})]}),_&&(0,Y.jsxs)(`div`,{className:`absolute top-4 right-4 w-64 bg-background/95 border border-border rounded-lg shadow-xl backdrop-blur z-50`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-b border-border`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-bold capitalize`,children:_.type}),(0,Y.jsx)(`span`,{className:J(`px-1.5 py-0.5 rounded text-[9px] font-medium`,_.data.status===`active`&&`bg-emerald-500/20 text-emerald-400`,_.data.status===`streaming`&&`bg-blue-500/20 text-blue-400`,_.data.status===`error`&&`bg-red-500/20 text-red-400`,_.data.status===`completed`&&`bg-blue-500/20 text-blue-400`,_.data.status===`idle`&&`bg-gray-500/20 text-gray-400`),children:_.data.status})]}),(0,Y.jsx)(`button`,{onClick:()=>v(null),className:`text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`p-3 space-y-2 text-[11px]`,children:[(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Label`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:String(_.data.label??``)})]}),_.data.sublabel&&(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Sublabel`}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px]`,children:String(_.data.sublabel)})]}),_.data.currentTool&&(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool`}),(0,Y.jsx)(`span`,{className:`font-mono text-amber-400`,children:String(_.data.currentTool)})]}),_.data.stats&&(0,Y.jsxs)(Y.Fragment,{children:[_.data.stats.iterations!==void 0&&(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:_.data.stats.iterations})]}),_.data.stats.toolCalls!==void 0&&(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:_.data.stats.toolCalls})]}),_.data.stats.costUsd!==void 0&&(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Cost`}),(0,Y.jsxs)(`span`,{className:`font-mono text-emerald-400`,children:[`$`,_.data.stats.costUsd.toFixed(4)]})]}),_.data.stats.ctxPct!==void 0&&(0,Y.jsxs)(`div`,{className:`flex justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Context`}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[_.data.stats.ctxPct,`%`]})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`absolute bottom-4 left-4 bg-background/95 border border-border rounded-lg p-2 backdrop-blur`,children:[(0,Y.jsx)(`div`,{className:`text-[9px] text-muted-foreground mb-1 font-semibold uppercase tracking-wider`,children:`Live`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-x-3 gap-y-1 text-[10px]`,children:[(0,Y.jsx)(ps,{label:`Tokens`,value:u.totalTokens.toLocaleString()}),(0,Y.jsx)(ps,{label:`Cost`,value:`$${u.totalCost.toFixed(3)}`}),(0,Y.jsx)(ps,{label:`Tools`,value:u.totalToolCalls}),(0,Y.jsx)(ps,{label:`Agents`,value:u.activeAgents}),(0,Y.jsx)(ps,{label:`Done`,value:u.completedTasks}),(0,Y.jsx)(ps,{label:`Errors`,value:u.errors})]})]}),(0,Y.jsxs)(`div`,{className:`absolute bottom-4 right-4 bg-background/95 border border-border rounded-lg p-2 backdrop-blur`,children:[(0,Y.jsx)(`div`,{className:`text-[9px] text-muted-foreground mb-1 font-semibold uppercase tracking-wider`,children:`Legend`}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(ms,{color:`#22c55e`,label:`Session`}),(0,Y.jsx)(ms,{color:`#a855f7`,label:`Agent`}),(0,Y.jsx)(ms,{color:`#f59e0b`,label:`Tool`}),(0,Y.jsx)(ms,{color:`#06b6d4`,label:`Provider`}),(0,Y.jsx)(ms,{color:`#3b82f6`,label:`Context`})]})]})]})}function ps({label:e,value:t}){return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e}),(0,Y.jsx)(`span`,{className:`font-mono font-bold text-foreground`,children:t})]})}function ms({color:e,label:t}){return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px]`,children:[(0,Y.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-sm`,style:{backgroundColor:e}}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:t})]})}function hs(e){return(0,Y.jsx)(Ye,{children:(0,Y.jsx)(fs,{...e})})}var gs={ts:I,tsx:I,js:I,jsx:I,mjs:I,cjs:I,json:qe,lock:dt,css:nn,scss:nn,less:nn,html:kt,htm:kt,svg:Bt,xml:kt,md:nn,mdx:nn,txt:nn,yml:nn,yaml:nn,toml:_t,env:_t,gitignore:_t,editorconfig:_t,sh:I,bash:I,zsh:I,fish:I,ps1:I,bat:I,py:I,pyi:I,pyx:I,rs:I,go:I,rb:I,java:I,c:I,cpp:I,h:I,hpp:I,sql:I,graphql:I,png:Bt,jpg:Bt,jpeg:Bt,gif:Bt,webp:Bt,ico:Bt};function _s(e,t){if(t){let t=e.toLowerCase();return t===`.git`?`text-orange-500/80 dark:text-orange-400/80`:t===`node_modules`?`text-red-400/60 dark:text-red-500/60`:t===`src`||t===`lib`||t===`packages`?`text-amber-500/70 dark:text-amber-400/70`:t===`tests`||t===`test`||t===`__tests__`?`text-emerald-500/70 dark:text-emerald-400/70`:t===`dist`||t===`build`||t===`.next`?`text-muted-foreground/50`:`text-amber-500/70 dark:text-amber-400/70`}let n=e.split(`.`).pop()?.toLowerCase()??``;return/^(ts|tsx|js|jsx|mjs|cjs)$/.test(n)?`text-blue-500 dark:text-blue-400`:/^(json|lock)$/.test(n)?`text-amber-500 dark:text-amber-400`:/^(css|scss|less|sass)$/.test(n)?`text-teal-500 dark:text-teal-400`:/^(html|htm|xml|svg)$/.test(n)?`text-rose-500 dark:text-rose-400`:/^(md|mdx)$/.test(n)?`text-violet-500 dark:text-violet-400`:/^(yml|yaml|toml|env)$/.test(n)?`text-emerald-500 dark:text-emerald-400`:/^(sh|bash|zsh|fish|ps1|bat)$/.test(n)?`text-orange-400 dark:text-orange-300`:/^(py|pyi|pyx)$/.test(n)?`text-cyan-500 dark:text-cyan-400`:n===`rs`?`text-orange-500 dark:text-orange-400`:n===`go`?`text-sky-500 dark:text-sky-400`:n===`rb`?`text-red-400 dark:text-red-400`:/^(c|h|cpp|hpp|cc|hh)$/.test(n)?`text-slate-500 dark:text-slate-400`:/^(png|jpe?g|gif|webp|ico|svg)$/.test(n)?`text-purple-500 dark:text-purple-400`:/^(gitignore|editorconfig|prettierrc|eslintrc)$/.test(n)?`text-muted-foreground/60`:`text-muted-foreground`}function vs(e){return gs[e.split(`.`).pop()?.toLowerCase()??``]??nt}function ys({node:e,depth:t,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a}){let[o,s]=(0,z.useState)(t<1),c=G(e=>e.activeFilePath),l=e.type===`file`&&e.path===c;if((0,z.useEffect)(()=>{r!==null&&s(r)},[r]),e.type===`directory`){let c=(e.children?.length??0)>0,l=o?Xe:Kt,u=e.name===`.git`,d=_s(e.name,!0);return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:J(`flex items-center gap-1 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`),style:{paddingLeft:`${t*14+4}px`},children:[(0,Y.jsx)(k,{className:J(`h-3 w-3 shrink-0 text-muted-foreground transition-transform`,o&&`rotate-90`)}),u?(0,Y.jsx)(Lt,{className:J(`h-3.5 w-3.5 shrink-0`,d)}):(0,Y.jsx)(l,{className:J(`h-3.5 w-3.5 shrink-0`,d)}),(0,Y.jsx)(`span`,{className:`truncate font-medium flex-1 min-w-0`,children:e.name})]}),o&&c&&(0,Y.jsx)(`div`,{children:(e.children??[]).map(e=>(0,Y.jsx)(ys,{node:e,depth:t+1,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a},e.path))}),o&&!c&&(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic py-0.5`,style:{paddingLeft:`${(t+1)*14+4}px`},children:`empty`})]})}let u=vs(e.name),d=_s(e.name,!1),f=e.path===n;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e.path),onDoubleClick:t=>{t.preventDefault(),a(e.path)},className:J(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors`,l&&`bg-primary/10 text-primary`,f&&!l&&`bg-muted/70 ring-1 ring-inset ring-border`),style:{paddingLeft:`${t*14+4}px`},children:[(0,Y.jsx)(`span`,{className:`w-3 shrink-0`}),` `,(0,Y.jsx)(u,{className:J(`h-3.5 w-3.5 shrink-0`,d)}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.name})]})}function bs(){let e=G(e=>e.tree),t=G(e=>e.treeLoading),n=G(e=>e.error),r=G(e=>e.openFiles),i=G(e=>e.activeFilePath),a=U(e=>e.cwd),o=U(e=>e.projectName),s=a?.includes(`\\`)?`\\`:`/`,c=(e,t=8,n=4)=>e.length<=t+n+2?e:`${e.slice(0,t)}…${e.slice(-n)}`,l=(()=>{if(!a||!o)return!0;let e=a.replace(/\\/g,`/`).split(`/`).filter(Boolean);return(e[e.length-1]??``)===o})(),u=(0,z.useMemo)(()=>{if(!a||!o)return[];let e=a.replace(/\\/g,`/`).split(`/`).filter(Boolean),t=-1;for(let n=e.length-1;n>=0;n--)if(e[n]===o){t=n;break}if(t===-1)return e.map((t,n)=>({label:t,path:`/`+e.slice(0,n+1).join(`/`),isLast:n===e.length-1}));let n=e.slice(t);return n.map((r,i)=>({label:r,path:`/`+e.slice(0,t+i+1).join(`/`),isLast:i===n.length-1}))},[a,o]),d=(0,z.useRef)(null);(0,z.useEffect)(()=>{let e=d.current;e&&u.length>1&&(e.scrollLeft=e.scrollWidth)},[u]);let f=(0,z.useCallback)(e=>{B().send({type:`working_dir.set`,payload:{path:e}})},[]),[p,m]=(0,z.useState)(null);(0,z.useEffect)(()=>{if(!p)return;let e=()=>m(null),t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`click`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`click`,e),window.removeEventListener(`keydown`,t)}},[p]);let h=(0,z.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),m({x:e.clientX,y:e.clientY,crumb:t})},[]),g=(0,z.useCallback)(e=>{navigator.clipboard.writeText(e),m(null)},[]),_=(0,z.useCallback)(()=>{if(!i)return;let e=i.replace(/\\/g,`/`).split(`/`).slice(0,-1).join(`/`)||`.`;B().send({type:`working_dir.set`,payload:{path:e}})},[i]),v=(0,z.useCallback)((e,t)=>{B().send({type:`shell.open`,payload:{path:e,target:t}}),m(null)},[]),y=(0,z.useCallback)(()=>{if(!a)return;let e=a.replace(/\\/g,`/`),t=e.split(`/`).slice(0,-1).join(`/`)||e;B().send({type:`working_dir.set`,payload:{path:t}})},[a]),[b,x]=(0,z.useState)(!1),S=(0,z.useRef)(null);(0,z.useEffect)(()=>(t?S.current=setTimeout(()=>x(!0),150):(S.current&&clearTimeout(S.current),x(!1)),()=>{S.current&&clearTimeout(S.current)}),[t]);let[C,w]=(0,z.useState)(null),[T,E]=(0,z.useState)(null),O=(0,z.useMemo)(()=>{let t=0,n=e=>{for(let r of e)r.type===`directory`&&t++,r.children&&n(r.children)};return n(e),t},[e]),k=(0,z.useMemo)(()=>{let t=0,n=0;for(let r of e)r.type===`directory`?n++:t++;return{files:t,dirs:n}},[e]),A={value:!1},j=(0,z.useCallback)(()=>{A.value=!0,E(!1),setTimeout(()=>{A.value=!1},400)},[]),M=(0,z.useCallback)(()=>{A.value=!0,E(!0),setTimeout(()=>{A.value=!1},400)},[]),N=(0,z.useCallback)(e=>{if(r.find(t=>t.path===e)){G.getState().setActiveFile(e);return}w(t=>t===e?null:e)},[r]),ee=(0,z.useCallback)(e=>{window.dispatchEvent(new CustomEvent(`wrongstack:open-file`,{detail:{filePath:e}})),w(null)},[]);return(0,z.useEffect)(()=>{i&&w(null)},[i]),b?(0,Y.jsx)(`div`,{className:`flex items-center justify-center h-full py-8`,children:(0,Y.jsx)(D,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):n?(0,Y.jsxs)(`div`,{className:`p-3 text-[11px] text-destructive`,children:[`Failed to load files: `,n]}):(0,Y.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[e.length>0&&O>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-0.5 border-b shrink-0`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:M,className:J(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Expand all directories`,children:[(0,Y.jsx)(Pt,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:`Expand all`})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:j,className:J(`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] transition-colors`,`hover:bg-muted/60 text-muted-foreground hover:text-foreground`),title:`Collapse all directories`,children:[(0,Y.jsx)(he,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:`Collapse`})]}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[9px] text-muted-foreground/50 tabular-nums`,children:[O,` folder`,O===1?``:`s`]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-1`,children:[u.length>0&&(0,Y.jsxs)(`div`,{ref:d,className:`relative flex items-center gap-0.5 px-1 pb-1 border-b border-border/30 overflow-x-auto`,children:[(0,Y.jsx)(`span`,{className:`sticky left-0 shrink-0 w-3 h-full bg-gradient-to-r from-background to-transparent pointer-events-none`}),u.map((e,t)=>{let n=e.isLast?e.label:c(e.label),r=e.path.replace(/\//g,s),i=a?a.replace(/\\/g,`/`).split(`/`).filter(Boolean):[],l=(()=>{for(let e=i.length-1;e>=0;e--)if(i[e]===o)return e;return-1})(),u=l>=0?i.slice(0,l+t+1):i.slice(0,t+1),d=s===`\\`?u.join(`\\`):`/`+u.join(`/`),p=(l>=0?i.slice(l+1,l+t+1):[]).join(s)||`.`;return(0,Y.jsxs)(`span`,{className:`flex items-center gap-0.5 shrink-0`,children:[t>0&&(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground/40 select-none`,children:s}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(e.path),onContextMenu:e=>h(e,{absPath:d,relPath:p}),className:J(`px-1 py-0.5 rounded text-[11px] transition-colors whitespace-nowrap`,e.isLast?`text-foreground font-medium`:`text-muted-foreground hover:text-foreground hover:bg-muted/60`),title:e.isLast?`Current directory: ${r}`:`Navigate to ${r}`,children:n})]},e.path)}),e.length>0&&(0,Y.jsxs)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground/50 tabular-nums pl-2`,children:[k.files>0&&`${k.files} file${k.files===1?``:`s`}`,k.files>0&&k.dirs>0&&`, `,k.dirs>0&&`${k.dirs} folder${k.dirs===1?``:`s`}`]})]}),i&&(0,Y.jsxs)(`button`,{type:`button`,onClick:_,className:`flex items-center gap-1 w-full text-left px-2 py-0.5 border-b border-border/30 text-[10px] text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors`,title:`Navigate to parent directory of ${i.replace(/\//g,s)}`,children:[(0,Y.jsx)(I,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:(()=>{let e=i.replace(/\\/g,`/`).split(`/`);return e[e.length-1]??i})()}),(0,Y.jsx)(`span`,{className:`ml-auto text-[8px] text-muted-foreground/40 shrink-0`,children:`go to dir`})]}),u.length===0&&!l&&(0,Y.jsxs)(`button`,{type:`button`,onClick:y,className:J(`flex items-center gap-1.5 w-full text-left px-1 py-0.5 text-[11px] rounded`,`hover:bg-muted/60 transition-colors text-muted-foreground hover:text-foreground`,`font-medium`),children:[(0,Y.jsx)(Ee,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{children:`..`}),(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground/50 ml-auto`,children:`parent directory`})]}),e.map(e=>(0,Y.jsx)(ys,{node:e,depth:0,selectedPath:C,forceExpand:T,onSelect:N,onOpen:ee},e.path)),e.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic p-2`,children:`No files found`})]}),p&&(0,Y.jsxs)(`div`,{className:`fixed z-50 min-w-[140px] bg-popover border rounded-md shadow-md py-1 text-[11px]`,style:{left:p.x,top:p.y},children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>g(p.crumb.absPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy absolute path`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>g(p.crumb.relPath),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Copy relative path`}),(0,Y.jsx)(`div`,{className:`border-t border-border/50 my-0.5`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>v(p.crumb.absPath,`terminal`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in terminal`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>v(p.crumb.absPath,`file-manager`),className:`flex items-center gap-2 w-full text-left px-3 py-1.5 hover:bg-accent transition-colors`,children:`Open in file manager`}),(0,Y.jsx)(`div`,{className:`border-t border-border/50 mt-0.5 pt-0.5`,children:(0,Y.jsx)(`div`,{className:`px-3 py-1 text-[9px] text-muted-foreground/50 truncate max-w-[200px]`,children:p.crumb.absPath})})]})]})}var xs={note:nn,ask:Ct,assign:ot,steer:Vt,btw:ke,broadcast:ot,status:Et,result:F};function Ss(e){let t=new Date(e),n=Date.now()-t.getTime();return n<6e4?`now`:n<36e5?`${Math.round(n/6e4)}m`:n<864e5?`${Math.round(n/36e5)}h`:t.toLocaleDateString()}function Cs({className:e}){let t=Vn(e=>e.messages),n=Vn(e=>e.agents),[r,i]=(0,z.useState)(!1),[a,o]=(0,z.useState)(!1),{client:s}=Z(),[c,l]=(0,z.useState)(s.status.state===`open`);(0,z.useEffect)(()=>s.onStatus(e=>l(e.state===`open`)),[s]),(0,z.useEffect)(()=>{c&&(s.send({type:`mailbox.messages`,payload:{limit:30}}),s.send({type:`mailbox.agents`,payload:{}}))},[c,s]);let u=t.filter(e=>!e.completed).length,d=n.filter(e=>e.online).length;async function f(){t.length!==0&&await To({title:`Delete all ${t.length} message${t.length===1?``:`s`}?`,message:`The mailbox file is truncated for every agent. This cannot be undone.`,confirmLabel:`Delete all`,danger:!0})&&(o(!0),s.send({type:`mailbox.clear`}))}return(0,z.useEffect)(()=>{a&&t.length===0&&o(!1)},[a,t.length]),(0,Y.jsxs)(`div`,{className:J(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,e),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,Y.jsx)(xe,{className:`h-4 w-4 text-cyan-500`}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Mailbox`}),u>0&&(0,Y.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-bold bg-yellow-100 dark:bg-yellow-900/40 text-yellow-700 dark:text-yellow-400`,children:u}),(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[d,` online`]})]}),!r&&(0,Y.jsxs)(`div`,{className:`px-3 pb-3 space-y-2`,children:[t.length>0?(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide`,children:`Messages`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:f,disabled:a,className:`flex items-center gap-1 text-[10px] text-muted-foreground hover:text-red-500 disabled:opacity-40 transition-colors`,title:`Delete all messages`,children:[(0,Y.jsx)(Ue,{className:`h-3 w-3`}),a?`Deleting…`:`Delete all`]})]}),t.slice(0,8).map(e=>{let t=xs[e.type]??x,n=e.readByCount>0;return(0,Y.jsxs)(`div`,{className:J(`flex items-start gap-2 px-2 py-1.5 rounded text-xs`,!n&&`bg-yellow-50 dark:bg-yellow-950/20`),children:[(0,Y.jsx)(t,{className:J(`h-3.5 w-3.5 mt-0.5 shrink-0`,n?`text-muted-foreground`:`text-yellow-600`)}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:J(`font-medium truncate`,!n&&`text-yellow-800 dark:text-yellow-300`),children:e.from}),e.completed&&(0,Y.jsx)(F,{className:`h-3 w-3 text-green-500 shrink-0`}),!n&&(0,Y.jsx)(`span`,{className:`text-[9px] text-yellow-600 font-bold`,children:`NEW`})]}),(0,Y.jsx)(`div`,{className:`text-muted-foreground truncate`,children:e.subject}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:[e.body.slice(0,60),e.body.length>60?`…`:``]})]}),(0,Y.jsxs)(`div`,{className:`shrink-0 text-[10px] text-muted-foreground flex flex-col items-end gap-0.5`,children:[(0,Y.jsx)(`span`,{children:Ss(e.timestamp)}),n&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Y.jsx)(Ht,{className:`h-3 w-3`}),e.readByCount]})]})]},e.id)})]}):(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground py-2 text-center`,children:[(0,Y.jsx)(vn,{className:`h-4 w-4 mx-auto mb-1 opacity-40`}),`No messages yet.`]}),n.length>0&&(0,Y.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,Y.jsxs)(`div`,{className:`text-[10px] font-semibold text-muted-foreground mb-1 flex items-center gap-1`,children:[(0,Y.jsx)(S,{className:`h-3 w-3`}),` Agents`]}),n.filter(e=>e.online).slice(0,5).map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground py-0.5`,children:[(0,Y.jsx)(`span`,{className:J(`h-1.5 w-1.5 rounded-full`,e.online?`bg-green-500`:`bg-muted-foreground/30`)}),(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e.name}),e.role&&(0,Y.jsxs)(`span`,{className:`opacity-60`,children:[`(`,e.role,`)`]}),(0,Y.jsx)(`span`,{className:`opacity-50`,children:e.status}),e.currentTool&&(0,Y.jsx)(`span`,{className:`text-cyan-500`,children:e.currentTool}),(0,Y.jsx)(`span`,{className:`ml-auto opacity-50`,children:Ss(e.lastSeenAt)})]},e.agentId)),n.filter(e=>!e.online).length>0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/50 mt-0.5`,children:[`+`,n.filter(e=>!e.online).length,` offline`]})]})]})]})}function ws({fullView:e}){let[t,n]=(0,z.useState)([]),[r,i]=(0,z.useState)(!0),[a,o]=(0,z.useState)(!1),[s,c]=(0,z.useState)(``),[l,u]=(0,z.useState)(``),[d,f]=(0,z.useState)(!1),p=(0,z.useRef)(null),[m,h]=(0,z.useState)({open:!1,project:null,agentCount:0}),g=(0,z.useCallback)(()=>{B().send({type:`projects.list`})},[]);(0,z.useEffect)(()=>{i(!0);let e=B(),t=e.on(`projects.list`,e=>{let t=e.payload;n(t.projects??[]),i(!1)}),r=e.on(`projects.added`,e=>{let t=e.payload;t.slug?(X.success(t.message),g()):X.error(t.message)});return g(),()=>{t(),r()}},[g]);let _=e=>{if(!e)return`never`;let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);if(r<24)return`${r}h ago`;let i=Math.floor(r/24);return i===1?`yesterday`:i<30?`${i}d ago`:i<365?`${Math.floor(i/30)}mo ago`:`${Math.floor(i/365)}y ago`},v=(0,z.useCallback)(e=>{let t=U.getState().session?.id;if(t){let n=Kn.getState().getAgentsBySession(t).filter(e=>e.status===`running`);if(n.length>0){h({open:!0,project:e,agentCount:n.length});return}}y(e)},[]),y=(0,z.useCallback)(e=>{let t=B();t.send({type:`projects.select`,payload:{root:e.root,name:e.name}});let n=t.on(`projects.selected`,e=>{let t=e.payload;n();let r=t.message.match(/(https?:\/\/[^\s]+)/);r&&r[1]?(window.open(r[1],`_blank`),X.success(`Opening ${t.name} in a new tab...`)):X.info(t.message)})},[]),b=(0,z.useCallback)(()=>{let e=s.trim();if(!e){X.error(`Please enter a folder path.`);return}o(!0);let t=B();t.send({type:`projects.add`,payload:{root:e,name:l.trim()||void 0}});let n=t.on(`projects.added`,()=>{n(),o(!1),f(!1),c(``),u(``)})},[s,l]),x=m.open&&m.project&&(0,Y.jsx)(fo,{open:!0,onOpenChange:()=>h({open:!1,project:null,agentCount:0}),children:(0,Y.jsxs)(go,{className:`sm:max-w-sm`,children:[(0,Y.jsxs)(_o,{children:[(0,Y.jsx)(yo,{children:`Running Agents`}),(0,Y.jsxs)(bo,{children:[m.agentCount,` agent`,m.agentCount===1?` is`:`s are`,` running in the current session. Switching projects will stop them.`]})]}),(0,Y.jsxs)(vo,{children:[(0,Y.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>h({open:!1,project:null,agentCount:0}),children:`Cancel`}),(0,Y.jsx)($,{size:`sm`,variant:`destructive`,onClick:()=>{let e=m.project;h({open:!1,project:null,agentCount:0}),y(e)},children:`Switch anyway`})]})]})}),S=[...t].sort((e,t)=>e.lastSeen&&t.lastSeen?t.lastSeen.localeCompare(e.lastSeen):e.lastSeen?-1:t.lastSeen?1:e.name.localeCompare(t.name)),C=(0,Y.jsxs)(fo,{open:d,onOpenChange:f,children:[(0,Y.jsx)(po,{asChild:!0,children:(0,Y.jsxs)($,{variant:`outline`,size:`sm`,className:`gap-1 h-7 text-xs`,children:[(0,Y.jsx)(bt,{className:`h-3 w-3`}),`Register Project`]})}),(0,Y.jsxs)(go,{className:`sm:max-w-md`,children:[(0,Y.jsxs)(_o,{children:[(0,Y.jsx)(yo,{children:`Register New Project`}),(0,Y.jsxs)(bo,{children:[`Enter the absolute path to a project folder. The project will be added to`,` `,(0,Y.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded text-xs`,children:`~/.wrongstack/projects.json`}),`.`]})]}),(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`proj-folder`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Folder path`}),(0,Y.jsx)(jo,{id:`proj-folder`,placeholder:`/home/user/my-project or C:\\Users\\me\\my-project`,value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&p.current?.focus()}})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{htmlFor:`proj-name`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Project name (optional — defaults to folder name)`}),(0,Y.jsx)(jo,{id:`proj-name`,ref:p,placeholder:`My Project`,value:l,onChange:e=>u(e.target.value),onKeyDown:e=>{e.key===`Enter`&&b()}})]})]}),(0,Y.jsxs)(vo,{children:[(0,Y.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>f(!1),children:`Cancel`}),(0,Y.jsxs)($,{size:`sm`,onClick:b,disabled:a||!s.trim(),children:[a?(0,Y.jsx)(D,{className:`h-3 w-3 animate-spin mr-1`}):null,`Register`]})]})]})]});if(r){let t=(0,Y.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,Y.jsx)(D,{className:`h-4 w-4 animate-spin text-muted-foreground`})});return e?(0,Y.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:(0,Y.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`})}),(0,Y.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:t})]}):t}let w=(0,Y.jsx)(`div`,{className:J(`space-y-1`,e&&`p-2`),children:S.map(e=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>v(e),className:`flex items-start gap-2 w-full text-left px-2 py-1.5 rounded border bg-card/40 text-xs hover:bg-accent hover:border-primary/40 transition-colors`,children:[(0,Y.jsx)(Kt,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`font-medium truncate`,children:e.name}),(0,Y.jsx)(`div`,{className:`font-mono text-[10px] text-muted-foreground truncate`,children:e.root}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-[10px] text-muted-foreground/60`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.slug}),e.lastSeen&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(Ge,{className:`h-2.5 w-2.5`}),_(e.lastSeen)]})]})]}),(0,Y.jsx)($e,{className:`h-3 w-3 shrink-0 mt-1 text-muted-foreground/40`})]},e.slug))});return e?(0,Y.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[x,(0,Y.jsxs)(`div`,{className:`px-3 py-2 border-b shrink-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`}),C]}),(0,Y.jsxs)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:[`Known projects from`,` `,(0,Y.jsx)(`code`,{className:`font-mono bg-muted/40 px-0.5 rounded`,children:`~/.wrongstack/projects.json`})]})]}),t.length===0?(0,Y.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,Y.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]})}):(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:w}),(0,Y.jsx)(`div`,{className:`px-3 py-2 border-t shrink-0`,children:(0,Y.jsx)(`p`,{className:`text-[9px] text-muted-foreground/40 text-center`,children:`Click a project to open it in a new WebUI tab`})})]}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[x,(0,Y.jsx)(`div`,{className:`flex items-center justify-between`,children:C}),t.length===0?(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,Y.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]}):w]})}var Ts={running:{led:`text-[hsl(var(--success))]`,label:`running`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,label:`done`,pulse:!1},failed:{led:`text-destructive`,label:`failed`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,label:`timeout`,pulse:!1},stopped:{led:`text-muted-foreground`,label:`stopped`,pulse:!1}};function Es(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function Ds(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Os(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function ks({agent:e,onClose:t}){let n=Ts[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool,a=Date.now()-e.startedAt,[o,c]=(0,z.useState)(!1),l=(0,z.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),c(!0),setTimeout(()=>c(!1),2e3)}catch{}},[]),u=e.ctxPct>=85?`bg-red-500/15 text-red-600 dark:text-red-400`:e.ctxPct>=70?`bg-amber-500/15 text-amber-600 dark:text-amber-400`:`bg-muted text-muted-foreground`;return(0,Y.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,children:(0,Y.jsxs)(`div`,{className:`w-full max-w-xl max-h-[80vh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,Y.jsxs)(`div`,{className:J(`flex items-center justify-between px-4 py-3 border-b`,r?`border-primary/20`:`border-border`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:J(`led`,n.led,n.pulse&&`led-pulse`)}),(0,Y.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:n.label})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,Y.jsx)(L,{className:`h-4 w-4`})})]}),(0,Y.jsxs)(`div`,{className:`p-4 space-y-4`,children:[e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed`,children:e.description}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Provider / Model`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,Y.jsx)(ln,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsxs)(`span`,{className:`text-xs font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,Y.jsx)(de,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-mono tabular`,children:Os(a)}),r&&(0,Y.jsx)(`span`,{className:`text-[10px] text-[hsl(var(--success))]`,children:`· running`})]})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Iterations`}),(0,Y.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.iteration})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Tool Calls`}),(0,Y.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.toolCalls})]}),(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,Y.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:Es(e.costUsd)})]}),e.extensions>0&&(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Budget Extensions`}),(0,Y.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.extensions})]})]}),e.maxContext>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Context window`}),(0,Y.jsxs)(`span`,{className:J(`tabular font-medium`,u.replace(/bg-\S+\s*/g,``)),children:[e.ctxPct,`%`]})]}),(0,Y.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,Y.jsx)(`div`,{className:J(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.max(2,e.ctxPct)}%`}})}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground tabular text-right`,children:[Ds(e.ctxTokens),` / `,Ds(e.maxContext),` tokens`]})]}),i&&(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-2 rounded-lg border px-3 py-2`,r?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,Y.jsx)(s,{className:J(`h-3.5 w-3.5`,r?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,Y.jsx)(`span`,{className:`text-xs font-mono`,children:i}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?`running…`:`last tool`})]}),e.error&&(0,Y.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`}),(0,Y.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1 leading-relaxed`,children:e.error.message})]}),e.finalText?(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Final Output`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>l(e.finalText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[o?(0,Y.jsx)(be,{className:`h-3 w-3 text-emerald-500`}):(0,Y.jsx)(_,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,Y.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:e.finalText})]}):e.partialText?(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Live Output`}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>l(e.partialText),className:`flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,title:`Copy output`,children:[o?(0,Y.jsx)(be,{className:`h-3 w-3 text-emerald-500`}):(0,Y.jsx)(_,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,Y.jsx)(`pre`,{className:`text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-48 overflow-y-auto`,children:e.partialText})]}):r?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-3 text-center`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`}),(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:`Output appears here as the agent streams text.`})]}):null,e.toolLog.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,Y.jsxs)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5`,children:[e.toolLog.slice(0,15).map((e,t)=>(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-2 rounded px-2 py-1 text-[10px]`,e.ok?`bg-muted/30`:`bg-destructive/5 border border-destructive/20`),children:[(0,Y.jsx)(`span`,{className:J(`led shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`)}),(0,Y.jsx)(`span`,{className:`font-mono truncate flex-1`,children:e.name}),(0,Y.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,Y.jsx)(`span`,{className:`text-destructive font-medium`,children:`fail`})]},`${e.name}-${e.at}-${t}`)),e.toolLog.length>15&&(0,Y.jsxs)(`p`,{className:`text-[9px] text-muted-foreground text-center px-2 py-0.5`,children:[`+`,e.toolLog.length-15,` more tools`]})]})]})]})]})})}function As({a:e,onClick:t}){let n=Ts[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool;return(0,Y.jsxs)(`button`,{type:`button`,onClick:t,className:J(`flex min-w-[12rem] max-w-[15rem] flex-col gap-1 rounded-lg border p-2 transition-colors text-left cursor-pointer`,`hover:border-primary/40 hover:bg-primary/[0.06]`,r?`border-primary/30 bg-primary/[0.04]`:`border-border bg-card opacity-85`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Y.jsx)(`span`,{className:J(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,Y.jsx)(`span`,{className:`truncate text-[11px] font-semibold text-foreground`,title:e.name,children:e.name}),(0,Y.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it · `,e.toolCalls,`t`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[e.model&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-0.5 text-[10px] text-muted-foreground truncate`,title:`${e.provider??``}/${e.model}`,children:[(0,Y.jsx)(ln,{className:`h-2.5 w-2.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:e.model})]}),(0,Y.jsx)(`span`,{className:`tabular text-[10px] text-foreground/75 ml-auto`,children:Es(e.costUsd)})]}),i&&(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-1 text-[10px] truncate`,r?`text-primary`:`text-muted-foreground`),title:e.currentTool?`running ${i}`:`last: ${i}`,children:[(0,Y.jsx)(s,{className:J(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse`)}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:i})]}),r&&e.maxContext>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,title:`Context ${e.ctxPct}%`,children:[(0,Y.jsx)(`div`,{className:`h-1 flex-1 overflow-hidden rounded-full bg-muted`,children:(0,Y.jsx)(`div`,{className:J(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.max(2,e.ctxPct)}%`}})}),(0,Y.jsxs)(`span`,{className:`tabular text-[9px] text-muted-foreground`,children:[e.ctxPct,`%`]})]}),e.error&&(0,Y.jsx)(`div`,{className:`truncate rounded bg-destructive/10 px-1 py-0.5 text-[9px] text-destructive`,title:e.error.message,children:e.error.message})]})}function js({className:e}){let t=Kn(e=>e.agents),[n,r]=(0,z.useState)(!0),[i,a]=(0,z.useState)(null),o=(0,z.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),e},[t]),s=i?o.find(e=>e.id===i):null;if(o.length===0)return null;let c=o.filter(e=>e.status===`running`),l=o.filter(e=>e.status===`completed`),u=o.filter(e=>e.status===`failed`||e.status===`timeout`),d=o.reduce((e,t)=>e+(t.costUsd??0),0),f=n&&o.length>=3;return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:J(`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,e),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-muted/30 transition-colors`,children:[(0,Y.jsx)(E,{className:`h-3.5 w-3.5 text-primary`}),(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground`,children:`Fleet`}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 ml-auto text-[10px]`,children:[c.length>0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-[hsl(var(--success))]`,children:[(0,Y.jsx)(`span`,{className:`led led-pulse text-[hsl(var(--success))]`}),c.length]}),l.length>0&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[l.length,` done`]}),u.length>0&&(0,Y.jsxs)(`span`,{className:`text-destructive`,children:[u.length,` err`]}),d>0&&(0,Y.jsx)(`span`,{className:`tabular text-foreground/70`,children:Es(d)})]}),f?(0,Y.jsx)(k,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Y.jsx)(re,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!f&&(0,Y.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-2 pb-2`,children:o.map(e=>(0,Y.jsx)(As,{a:e,onClick:()=>a(e.id)},e.id))})]}),s&&(0,Y.jsx)(ks,{agent:s,onClose:()=>a(null)})]})}var Ms={running:{led:`text-[hsl(var(--success))]`,label:`running`,pulse:!0},completed:{led:`text-[hsl(var(--success))]`,label:`done`,pulse:!1},failed:{led:`text-destructive`,label:`failed`,pulse:!1},timeout:{led:`text-[hsl(var(--warning))]`,label:`timeout`,pulse:!1},stopped:{led:`text-muted-foreground`,label:`stopped`,pulse:!1}};function Ns(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function Ps({agent:e,onClick:t}){let n=Ms[e.status],r=e.status===`running`;return(0,Y.jsxs)(`button`,{type:`button`,onClick:t,className:J(`w-full text-left rounded-lg border px-2.5 py-2 transition-colors`,`hover:border-primary/40 hover:bg-primary/[0.04]`,r?`border-primary/30 bg-primary/[0.03]`:`border-border/60 bg-card/40`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,Y.jsx)(`span`,{className:J(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,Y.jsx)(`span`,{className:`truncate text-[11px] font-semibold`,title:e.name,children:e.name}),(0,Y.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it`]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5 min-w-0`,children:[e.model?(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate font-mono`,children:e.model}):(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`pending…`}),(0,Y.jsx)(`span`,{className:`tabular ml-auto text-[10px] text-foreground/70`,children:Ns(e.costUsd)})]}),(e.currentTool||e.lastTool)&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 mt-1 text-[10px] text-muted-foreground truncate`,children:[(0,Y.jsx)(s,{className:J(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse text-primary`)}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool??e.lastTool})]})]})}function Fs(){let e=Kn(e=>e.agents),t=W(e=>e.setCurrentView),[n,r]=(0,z.useState)(null),i=(0,z.useMemo)(()=>{let t=Array.from(e.values());return t.sort((e,t)=>{let n=e.status===`running`?0:1,r=t.status===`running`?0:1;return n===r?e.startedAt-t.startedAt:n-r}),t},[e]),a=i.filter(e=>e.status===`running`).length,o=n?i.find(e=>e.id===n)??null:null;return i.length===0?(0,Y.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-4`,children:(0,Y.jsxs)(`div`,{className:`text-center text-muted-foreground`,children:[(0,Y.jsx)(E,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents yet`}),(0,Y.jsx)(`p`,{className:`text-xs mt-1`,children:`Subagents appear here when the fleet is active.`})]})}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`px-3 py-2 border-b text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-semibold uppercase tracking-wider`,children:`Fleet`}),(0,Y.jsxs)(`span`,{className:`ml-auto tabular-nums`,children:[a>0?`${a} running · `:``,i.length,` total`]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 space-y-1.5`,children:i.map(e=>(0,Y.jsx)(Ps,{agent:e,onClick:()=>r(e.id)},e.id))}),(0,Y.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>t(`agents`),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,Y.jsx)(w,{className:`h-3 w-3`}),`Open full agents view`]})}),o&&(0,Y.jsx)(ks,{agent:o,onClose:()=>r(null)})]})}var Is=e=>{let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Date.now()-t;if(n<6e4)return`just now`;if(n<36e5)return`${Math.floor(n/6e4)}m ago`;if(n<864e5)return`${Math.floor(n/36e5)}h ago`;let r=Math.floor(n/864e5);return r<7?`${r}d ago`:new Date(t).toLocaleDateString()};function Ls(e){return e.filter(e=>e.tokenTotal===0&&!e.isCurrent).map(e=>e.id)}function Rs({historyQuery:e,setHistoryQuery:t,historyEntries:n,historyLoading:r,historyError:i,wsConnected:a,listSessions:o,resumeSession:s,deleteSession:c}){let l=W(e=>e.favoriteSessionIds),u=W(e=>e.toggleFavoriteSession),d=W(e=>e.sessionNicknames),f=W(e=>e.setSessionNickname),[p,m]=(0,z.useState)(null),[h,g]=(0,z.useState)(``),[_,v]=(0,z.useState)(null);(0,z.useEffect)(()=>{_&&n.some(e=>e.id===_&&e.isCurrent)&&v(null)},[_,n]);let y=(0,z.useCallback)(e=>{v(e),s(e),setTimeout(()=>v(t=>t===e?null:t),1e4)},[s]),b=(0,z.useMemo)(()=>Ls(n),[n]),x=(0,z.useCallback)(async()=>{if(b.length!==0&&await To({title:b.length===1?`Delete 1 empty session?`:`Delete ${b.length} empty sessions?`,message:`Sessions without any token usage are removed from disk.`,confirmLabel:`Delete`,danger:!0}))for(let e of b)c(e)},[b,c]),S=(()=>{let t=e.trim().toLowerCase(),r=t?n.filter(e=>e.title.toLowerCase().includes(t)||e.model.toLowerCase().includes(t)||e.provider.toLowerCase().includes(t)||e.id.toLowerCase().includes(t)):n,i=new Date;i.setHours(0,0,0,0);let a=i.getTime(),o=a-864e5,s=a-6*864e5,c={today:[],yesterday:[],week:[],older:[]};for(let e of r){let t=Date.parse(e.startedAt);if(Number.isNaN(t)){c.older.push(e);continue}t>=a?c.today.push(e):t>=o?c.yesterday.push(e):t>=s?c.week.push(e):c.older.push(e)}let u=new Set(l),d=r.filter(e=>u.has(e.id)),f=[];d.length&&f.push({label:`Favorites`,rows:d,star:!0});let p=e=>e.filter(e=>!u.has(e.id)),m=p(c.today),h=p(c.yesterday),g=p(c.week),_=p(c.older);return m.length&&f.push({label:`Today`,rows:m}),h.length&&f.push({label:`Yesterday`,rows:h}),g.length&&f.push({label:`This week`,rows:g}),_.length&&f.push({label:`Earlier`,rows:_}),f})();return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b`,children:[(0,Y.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground`,children:`Recent sessions`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[b.length>0&&(0,Y.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted text-muted-foreground hover:text-destructive`,onClick:x,disabled:!a,title:`Delete ${b.length} empty session${b.length===1?``:`s`}`,children:(0,Y.jsx)(Ue,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,className:`h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted`,onClick:()=>o(50),disabled:!a,title:`Refresh`,children:r?(0,Y.jsx)(D,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Je,{className:`h-3.5 w-3.5`})})]})]}),n.length>3&&(0,Y.jsx)(`div`,{className:`px-3 py-2 border-b`,children:(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(ft,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground/60`}),(0,Y.jsx)(`input`,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Filter title, model, provider…`,className:`w-full pl-7 pr-7 py-1 text-xs rounded-md bg-muted/40 border border-transparent focus:bg-background focus:border-input focus:outline-none focus:ring-1 focus:ring-ring placeholder:text-muted-foreground/50`}),e&&(0,Y.jsx)(`button`,{type:`button`,onClick:()=>t(``),className:`absolute right-1 top-1/2 -translate-y-1/2 text-muted-foreground/60 hover:text-foreground p-0.5`,title:`Clear filter`,children:(0,Y.jsx)(L,{className:`h-3 w-3`})})]})}),i&&(0,Y.jsx)(`div`,{className:`px-4 py-2 text-xs text-destructive bg-destructive/5 border-b`,children:i}),(0,Y.jsx)(no,{className:`flex-1`,children:n.length===0&&!r?(0,Y.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,Y.jsx)(Ge,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:`No history yet`}),(0,Y.jsx)(`p`,{className:`text-xs mt-1`,children:`Your conversations will appear here`})]}):S.length===0?(0,Y.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,Y.jsx)(ft,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,Y.jsx)(`p`,{className:`text-sm font-medium`,children:`No matches`}),(0,Y.jsx)(`p`,{className:`text-xs mt-1`,children:`Try a different filter`})]}):(0,Y.jsx)(`div`,{className:`p-2 space-y-3`,children:S.map(e=>(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:J(`sticky top-0 z-[1] px-1 pb-1 text-[10px] uppercase tracking-wider font-semibold bg-card/90 backdrop-blur-sm flex items-center gap-1`,e.star?`text-amber-500`:`text-muted-foreground/80`),children:[e.star&&(0,Y.jsx)(Ft,{className:`h-3 w-3 fill-current`}),e.label,` `,(0,Y.jsxs)(`span`,{className:`text-muted-foreground/50 font-normal normal-case ml-1`,children:[`(`,e.rows.length,`)`]})]}),e.rows.map(e=>(0,Y.jsxs)(`div`,{className:J(`group relative rounded-md border text-sm transition-colors`,e.isCurrent?`bg-primary/5 border-primary/40`:`bg-card border-border/60 hover:bg-muted/40 hover:border-primary/40`),children:[(0,Y.jsx)(`button`,{type:`button`,disabled:e.isCurrent||p===e.id||_!==null,onClick:()=>y(e.id),onDoubleClick:t=>{t.stopPropagation(),m(e.id),g(d[e.id]??e.title??``)},className:`block w-full rounded-md px-3 py-2 pr-16 text-left disabled:cursor-default focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[p===e.id?(0,Y.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{f(e.id,h),m(null)},onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),f(e.id,h),m(null)):t.key===`Escape`&&(t.preventDefault(),m(null))},placeholder:e.title||`Nickname`,className:`w-full text-sm bg-background border border-input rounded px-1.5 py-0.5 focus:outline-none focus:ring-1 focus:ring-ring`}):(0,Y.jsx)(`div`,{className:`font-medium truncate text-foreground`,title:d[e.id]?`${d[e.id]} — original: ${e.title}`:`${e.title}\n\nDouble-click to rename`,children:d[e.id]||e.title||`(empty)`}),(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground/80 mt-0.5`,children:[_===e.id?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-primary font-medium`,children:[(0,Y.jsx)(D,{className:`h-3 w-3 animate-spin`}),`resuming…`]}):(0,Y.jsx)(`span`,{children:Is(e.startedAt)}),e.tokenTotal>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{children:`·`}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[e.tokenTotal.toLocaleString(),` tok`]})]}),e.isCurrent&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{children:`·`}),(0,Y.jsx)(`span`,{className:`text-primary font-medium`,children:`active`})]})]})]})}),(0,Y.jsxs)(`div`,{className:`absolute right-2 top-2 flex items-center gap-1`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>u(e.id),className:J(`transition-opacity hover:text-amber-500`,l.includes(e.id)?`opacity-100 text-amber-500`:`opacity-0 group-hover:opacity-100 text-muted-foreground`),title:l.includes(e.id)?`Unfavorite`:`Mark as favorite`,children:(0,Y.jsx)(Ft,{className:J(`h-3.5 w-3.5`,l.includes(e.id)&&`fill-current`)})}),!e.isCurrent&&(0,Y.jsx)(`button`,{type:`button`,onClick:async()=>{await To({title:`Delete session?`,message:`"${d[e.id]||e.title||`(empty)`}" will be removed from disk. This cannot be undone.`,confirmLabel:`Delete`,danger:!0})&&c(e.id)},className:`opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-destructive`,title:`Delete session`,children:(0,Y.jsx)(Ue,{className:`h-3.5 w-3.5`})})]})]},e.id))]},e.label))})})]})}function zs(){let e=H(e=>e.wsConnected),{entries:t,loading:n,error:r}=Un(),{listSessions:i,resumeSession:a,deleteSession:o}=Z(),s=W(e=>e.setCurrentView),c=U(e=>e.session?.id),[l,u]=(0,z.useState)(``);return(0,z.useEffect)(()=>{e&&i(50)},[e,c,i]),(0,Y.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,Y.jsx)(Rs,{historyQuery:l,setHistoryQuery:u,historyEntries:t,historyLoading:n,historyError:r,wsConnected:e,listSessions:i,resumeSession:a,deleteSession:o}),(0,Y.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(`sessions`),className:`w-full flex items-center justify-center gap-1.5 h-7 rounded-md border border-border text-[11px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,children:[(0,Y.jsx)(w,{className:`h-3 w-3`}),`Open sessions dashboard`]})})]})}function Bs(e){return e<=0?`$0.000`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function Vs(e){if(e<=0)return`--`;let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function Hs({icon:e,label:t,onClick:n,disabled:r,tone:i,title:a}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:n,disabled:r,title:a??t,className:J(`flex items-center justify-center gap-1.5 h-8 rounded-md border text-[11px] font-medium transition-colors`,`disabled:opacity-40 disabled:cursor-not-allowed`,i===`primary`?`border-primary/40 bg-primary/10 text-primary hover:bg-primary/20`:i===`danger`?`border-destructive/40 bg-destructive/10 text-destructive hover:bg-destructive/20`:`border-border bg-card hover:bg-accent text-foreground/80`),children:[e,t]})}function Us({label:e,value:t,sub:n}){return(0,Y.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/40 border border-border/40 min-w-0`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold tabular-nums truncate`,children:t}),n&&(0,Y.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 truncate`,children:n})]})}function Ws({icon:e,label:t,right:n}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[e,t]}),n]})}function Gs({label:e,value:t,onChange:n,title:r}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,title:r,children:[(0,Y.jsx)(`span`,{className:`text-xs text-foreground/80`,children:e}),(0,Y.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,onClick:n,className:J(`shrink-0 relative inline-flex h-4 w-7 rounded-full border transition-colors`,t?`bg-primary border-primary`:`bg-muted border-input hover:bg-muted/80`),children:(0,Y.jsx)(`span`,{className:J(`absolute top-0.5 left-0.5 h-2.5 w-2.5 rounded-full bg-background shadow transition-transform`,t&&`translate-x-3`)})})]})}function Ks(){let{client:e,updatePrefs:t,switchAutonomy:n}=Z(),r=H(e=>e.wsConnected),i=H(e=>e.wsUrl),a=H(e=>e.provider),o=H(e=>e.model),s=H(e=>e.soundOnComplete),c=U(e=>e.session),l=U(e=>e.totalTokens),u=U(e=>e.cost),d=U(e=>e.iteration),f=U(e=>e.todos),p=U(e=>e.lastInputTokens),m=U(e=>e.maxContext),h=V(e=>e.messages),g=V(e=>e.isLoading),_=Kn(e=>e.agents),v=W(e=>e.pinnedIds),y=W(e=>e.unpinAll),b=W(e=>e.setModelSwitcherOpen),x=Zn(),S=(0,z.useCallback)((e,n)=>{x.set({[e]:n}),t({[e]:n})},[x,t]),[C,w]=(0,z.useState)(!1),E=c?.startedAt??null,[D,O]=(0,z.useState)(()=>Date.now());(0,z.useEffect)(()=>{if(!E)return;let e=setInterval(()=>O(Date.now()),1e3);return()=>clearInterval(e)},[E]);let k=(0,z.useMemo)(()=>Array.from(_.values()).filter(e=>e.status===`running`).length,[_]),A=m>0&&p>0?Math.min(100,Math.round(p/m*100)):0,j=v.map(e=>h.find(t=>t.id===e)).filter(e=>!!e&&e.content.length>0),M=e=>B(i)?.send?.(e);return(0,Y.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b grid grid-cols-2 gap-1.5`,children:[g?(0,Y.jsx)(Hs,{icon:(0,Y.jsx)(qt,{className:`h-3 w-3`}),label:`Abort`,tone:`danger`,onClick:()=>M({type:`abort`,payload:{}}),disabled:!r}):(0,Y.jsx)(Hs,{icon:(0,Y.jsx)(gn,{className:`h-3 w-3`}),label:`New session`,tone:`primary`,onClick:()=>{e?.newSession?.(),W.getState().setCurrentView(`chat`)},disabled:!r,title:`Start a new session (Ctrl+N)`}),(0,Y.jsx)(Hs,{icon:(0,Y.jsx)(Ce,{className:`h-3 w-3`}),label:`Export`,onClick:()=>qi(),title:`Export chat as markdown (Ctrl+E)`}),(0,Y.jsx)(Hs,{icon:(0,Y.jsx)(Xt,{className:`h-3 w-3`}),label:`Compact`,onClick:()=>M({type:`context.compact`,payload:{aggressive:!1}}),disabled:!r,title:`Compact the context window`}),(0,Y.jsx)(Hs,{icon:(0,Y.jsx)(fn,{className:`h-3 w-3`}),label:`Clear`,onClick:()=>M({type:`context.clear`}),disabled:!r,title:`Clear context (Ctrl+L)`})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>b(!0),className:`w-full px-4 py-2.5 border-b text-left hover:bg-muted/40 transition-colors`,title:`Change model (Ctrl+M)`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-0.5`,children:`Model`}),(0,Y.jsxs)(`div`,{className:`font-mono text-xs truncate`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:a||`—`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground/40 mx-1`,children:`/`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:o||`—`})]})]}),m>0&&(0,Y.jsxs)(`div`,{className:`px-4 py-2.5 border-b space-y-1.5`,children:[(0,Y.jsx)(Ws,{icon:null,label:`Context`,right:(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[Q(p),`/`,Q(m),` · `,A,`%`]})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>w(!0),className:`w-full block`,title:`Click for a context breakdown`,children:(0,Y.jsx)(fi,{pct:A,tokens:p,maxTokens:m,showTokens:!1})})]}),(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,Y.jsx)(Ws,{icon:(0,Y.jsx)(ln,{className:`h-3 w-3`}),label:`Session`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,Y.jsx)(Us,{label:`Messages`,value:h.length}),(0,Y.jsx)(Us,{label:`Elapsed`,value:E?Vs(D-E):`--`}),(0,Y.jsx)(Us,{label:`Tokens`,value:Q(l.input+l.output),sub:`${Q(l.input)} in / ${Q(l.output)} out`}),(0,Y.jsx)(Us,{label:`Cost`,value:Bs(u)}),d&&(0,Y.jsx)(Us,{label:`Iteration`,value:d.index,sub:d.max?`of ${d.max}`:void 0}),_.size>0&&(0,Y.jsx)(Us,{label:`Agents`,value:_.size,sub:k>0?`${k} running`:void 0})]})]}),f.length>0&&(()=>{let e=f.filter(e=>e.status===`completed`).length,t=f.filter(e=>e.status===`in_progress`).length,n=Math.round(e/f.length*100),r=e===f.length;return(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,Y.jsx)(Ws,{icon:(0,Y.jsx)(Ae,{className:`h-3 w-3`}),label:`Plan`,right:(0,Y.jsxs)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:[e,`/`,f.length]})}),(0,Y.jsx)(`div`,{className:J(`relative h-1.5 w-full overflow-hidden rounded-full bg-muted`,t>0&&`bar-sweep`),title:`${n}% complete`,children:(0,Y.jsx)(`div`,{className:J(`h-full rounded-full transition-all duration-500`,r?`bg-[hsl(var(--success))]`:`bg-primary`),style:{width:`${Math.max(n,t>0?4:0)}%`}})}),(0,Y.jsx)(`ul`,{className:`space-y-0.5 max-h-56 overflow-y-auto pr-1 -mx-1`,children:f.map(e=>{let t=e.status===`completed`?F:e.status===`in_progress`?oe:Et,n=e.status===`in_progress`,r=e.status===`completed`?`text-[hsl(var(--success))] line-through opacity-60`:n?`text-foreground`:`text-muted-foreground`;return(0,Y.jsxs)(`li`,{className:J(`flex items-start gap-2 text-xs leading-snug rounded-md px-1.5 py-1 transition-colors`,n&&`bg-primary/10 ring-1 ring-inset ring-primary/20`,r),children:[(0,Y.jsx)(t,{className:J(`h-3.5 w-3.5 mt-0.5 shrink-0`,n&&`text-primary animate-pulse`)}),(0,Y.jsx)(`span`,{className:`break-words`,children:n&&e.activeForm?e.activeForm:e.content})]},e.id)})})]})})(),j.length>0&&(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,Y.jsx)(Ws,{icon:(0,Y.jsx)(we,{className:`h-3 w-3 text-amber-500`}),label:`Pinned`,right:(0,Y.jsx)(`button`,{type:`button`,onClick:y,className:`text-[10px] text-muted-foreground hover:text-destructive`,children:`Clear`})}),(0,Y.jsx)(`ul`,{className:`space-y-1 max-h-48 overflow-y-auto pr-1`,children:j.map(e=>{let t=e.content.replace(/\s+/g,` `).slice(0,80);return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{let t=document.querySelector(`[data-message-id="${e.id}"]`);t&&(t.scrollIntoView({behavior:`smooth`,block:`center`}),t.classList.add(`ring-2`,`ring-amber-500/60`),setTimeout(()=>{t.classList.remove(`ring-2`,`ring-amber-500/60`)},1600))},className:`w-full text-left text-xs px-2 py-1.5 rounded bg-muted/40 hover:bg-muted/70 border border-amber-500/20 leading-snug`,title:e.content.slice(0,400),children:[t,e.content.length>80?`…`:``]})},e.id)})})]}),(0,Y.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1`,children:[(0,Y.jsx)(Ws,{icon:(0,Y.jsx)(Ze,{className:`h-3 w-3`}),label:`Quick settings`}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs text-foreground/80`,children:`Autonomy`}),(0,Y.jsxs)(`select`,{value:x.autonomy,onChange:e=>{let t=e.target.value;x.set({autonomy:t}),n(t)},className:`shrink-0 h-6 max-w-[150px] rounded-md border bg-background px-1.5 text-[11px]`,children:[(0,Y.jsx)(`option`,{value:`off`,children:`Off`}),(0,Y.jsx)(`option`,{value:`suggest`,children:`Suggest`}),(0,Y.jsx)(`option`,{value:`auto`,children:`Auto`}),(0,Y.jsx)(`option`,{value:`eternal`,children:`Eternal`}),(0,Y.jsx)(`option`,{value:`eternal-parallel`,children:`Eternal Parallel`})]})]}),(0,Y.jsx)(Gs,{label:`YOLO mode`,title:`Bypass tool confirmation prompts`,value:x.yolo,onChange:()=>S(`yolo`,!x.yolo)}),(0,Y.jsx)(Gs,{label:`Refine prompts`,title:`Rewrite prompts before sending`,value:x.enhanceEnabled,onChange:()=>S(`enhanceEnabled`,!x.enhanceEnabled)}),(0,Y.jsx)(Gs,{label:`Sound on completion`,title:`Play a soft chime when a run finishes`,value:s,onChange:()=>{let e=!H.getState().soundOnComplete;H.getState().setSoundOnComplete(e),e&&lr()}})]}),(0,Y.jsxs)(`div`,{className:`px-4 py-2.5`,children:[(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-2 text-[11px]`,r?`text-[hsl(var(--success))]`:`text-[hsl(var(--warning))]`),children:[r?(0,Y.jsx)(je,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(T,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:r?`Connected`:`Disconnected`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground font-mono truncate ml-auto`,title:i,children:i})]}),c&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-1 truncate`,title:c.id,children:[`session `,c.id.slice(0,8)]})]}),(0,Y.jsx)(pi,{open:C,onClose:()=>w(!1)})]})}var qs={chat:`Session`,agents:`Agents`,history:`History`,files:`Files`,projects:`Projects`,mailbox:`Mailbox`};function Js(){let e=W(e=>e.activeActivity),t=W(e=>e.setSidebarOpen),n=W(e=>e.sidebarWidth),r=W(e=>e.setSidebarWidth),i=H(e=>e.wsConnected),{client:a}=Z();return(0,z.useEffect)(()=>{if(e!==`files`||!i)return;G.getState().setTreeLoading(!0);let t=U.getState().cwd;a?.send({type:`files.tree`,payload:t?{path:t}:{}})},[e,i,a]),(0,Y.jsxs)(`aside`,{style:{width:`${n}px`},className:`relative border-r bg-card flex flex-col shrink-0 overflow-hidden animate-slide-in`,children:[(0,Y.jsx)(`div`,{onMouseDown:e=>{e.preventDefault();let t=e.clientX,i=n,a=e=>r(i+(e.clientX-t)),o=()=>{window.removeEventListener(`mousemove`,a),window.removeEventListener(`mouseup`,o),document.body.style.cursor=``,document.body.style.userSelect=``};window.addEventListener(`mousemove`,a),window.addEventListener(`mouseup`,o),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},onDoubleClick:()=>r(304),className:`group/handle absolute top-0 right-0 h-full w-2 cursor-col-resize z-10 flex items-center justify-end`,title:`Drag to resize · double-click to reset`,children:(0,Y.jsx)(`div`,{className:`h-full w-px bg-border group-hover/handle:bg-primary/60 group-hover/handle:w-0.5 transition-all`})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2.5 border-b shrink-0`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-semibold tracking-tight text-muted-foreground uppercase`,children:qs[e]}),(0,Y.jsx)($,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>t(!1),title:`Collapse panel (Ctrl+\\)`,children:(0,Y.jsx)(h,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[e===`chat`&&(0,Y.jsx)(Ks,{}),e===`agents`&&(0,Y.jsx)(Fs,{}),e===`history`&&(0,Y.jsx)(zs,{}),e===`files`&&(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,Y.jsx)(bs,{})}),e===`projects`&&(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,Y.jsx)(ws,{})}),e===`mailbox`&&(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,Y.jsx)(Cs,{})})]})]})}function Ys({sessionId:e,className:t}){let[n,r]=(0,z.useState)([]),[i,a]=(0,z.useState)(!1),[o,s]=(0,z.useState)(null),[c,u]=(0,z.useState)(null),[d,f]=(0,z.useState)(0),[p,m]=(0,z.useState)(!1),h=B(H(e=>e.wsUrl));(0,z.useEffect)(()=>{let t=[];return t.push(h.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&r(n.participants??[])})),t.push(h.on(`collab.participant.joined`,t=>{let n=t.payload;n.sessionId===e&&r(e=>e.some(e=>e.participantId===n.participantId)?e:[...e,{participantId:n.participantId,role:n.role,joinedAt:n.joinedAt}])})),t.push(h.on(`collab.participant.left`,t=>{let n=t.payload;if(n.sessionId!==e)return;let i=n.participantId;r(e=>e.filter(e=>e.participantId!==i))})),t.push(h.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(u(t.message),a(!1))})),t.push(h.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||f(e=>e+1))})),t.push(h.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&f(e=>Math.max(0,e-1))})),t.push(h.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&m(!0)})),t.push(h.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&m(!1)})),()=>{for(let e of t)e()}},[h,e]);let g=(t=`observer`)=>{u(null),h.send({type:`collab.join`,payload:{sessionId:e,role:t}}),a(!0),s(t)};return n.length===0&&!c?(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-2 px-3 py-2 rounded-md border border-dashed border-border bg-card/40`,t),children:[(0,Y.jsx)(S,{className:`w-4 h-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No live observers`}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g(`observer`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,title:`Join as a read-only observer (Phase 1)`,children:[(0,Y.jsx)(Ne,{className:`w-3 h-3`}),`observer`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g(`annotator`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:`Join as an annotator — leave inline notes on tool calls (Phase 2)`,children:[(0,Y.jsx)(A,{className:`w-3 h-3`}),`annotator`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>g(`controller`),className:`inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:`Join as a controller — can pause the agent loop (Phase 3)`,children:[(0,Y.jsx)(De,{className:`w-3 h-3`}),`controller`]})]})]}):c?(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-2 px-3 py-2 rounded-md border border-destructive/50 bg-destructive/10`,t),role:`alert`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-destructive`,children:[`Collab: `,c]}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{u(null),a(!1)},className:`ml-auto text-xs underline text-destructive`,children:`dismiss`})]}):(0,Y.jsxs)(`div`,{className:J(`flex items-center gap-2 px-3 py-2 rounded-md border border-emerald-500/40 bg-emerald-500/5`,t),children:[(0,Y.jsxs)(`span`,{className:`relative flex h-2 w-2`,"aria-label":`Live`,children:[(0,Y.jsx)(`span`,{className:`absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75 animate-ping`}),(0,Y.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-emerald-500`})]}),(0,Y.jsx)(S,{className:`w-4 h-4 text-emerald-700 dark:text-emerald-400`}),(0,Y.jsxs)(`span`,{className:`text-xs font-medium text-emerald-700 dark:text-emerald-300`,children:[n.length,` `,n.length===1?`observer`:`observers`]}),d>0&&(0,Y.jsxs)(`span`,{title:`${d} open annotation(s) — annotators reviewing this session`,className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-amber-500/15 text-amber-700 dark:text-amber-300 border border-amber-500/30`,children:[(0,Y.jsx)(A,{className:`w-3 h-3`}),d,` note`,d===1?``:`s`]}),p&&(0,Y.jsxs)(`span`,{title:`Agent loop is paused — a controller is reviewing`,className:`ml-2 inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-rose-500/15 text-rose-700 dark:text-rose-300 border border-rose-500/40`,children:[(0,Y.jsx)(De,{className:`w-3 h-3`}),`paused`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 ml-2`,children:[n.slice(0,3).map(e=>(0,Y.jsxs)(`span`,{title:`Joined ${new Date(e.joinedAt).toLocaleTimeString()}`,className:`inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-700 dark:text-emerald-300`,children:[(0,Y.jsx)(on,{className:`w-3 h-3`}),e.role]},e.participantId)),n.length>3&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,n.length-3]})]}),i&&o===`controller`&&(p?(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{h.send({type:`collab.resume`,payload:{sessionId:e}})},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-rose-500/40 bg-rose-500/10 text-rose-700 dark:text-rose-300 hover:bg-rose-500/20 transition-colors`,title:`Resume the agent loop`,children:[(0,Y.jsx)(et,{className:`w-3 h-3`}),`Resume`]}):(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{h.send({type:`collab.request_pause`,payload:{sessionId:e}})},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-300 hover:bg-amber-500/20 transition-colors`,title:`Pause the agent before the next tool call`,children:[(0,Y.jsx)(De,{className:`w-3 h-3`}),`Pause agent`]})),i&&o!==`controller`&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{h.send({type:`collab.leave`,payload:{sessionId:e}}),a(!1),r([])},className:`ml-auto inline-flex items-center gap-1 text-xs px-2 py-1 rounded border border-border hover:bg-muted transition-colors`,title:`Leave the observer session`,children:[(0,Y.jsx)(l,{className:`w-3 h-3`}),`Leave`]})]})}var Xs={up:(0,Y.jsx)(Be,{className:`h-3.5 w-3.5 text-emerald-500`}),down:(0,Y.jsx)(Le,{className:`h-3.5 w-3.5 text-red-500`}),stable:(0,Y.jsx)(le,{className:`h-3.5 w-3.5 text-amber-500`})},Zs={active:{color:`text-emerald-600 dark:text-emerald-400`,bg:`bg-emerald-100 dark:bg-emerald-900/40`,label:`Active`},paused:{color:`text-amber-600 dark:text-amber-400`,bg:`bg-amber-100 dark:bg-amber-900/40`,label:`Paused`},completed:{color:`text-blue-600 dark:text-blue-400`,bg:`bg-blue-100 dark:bg-blue-900/40`,label:`Done`},failed:{color:`text-red-600 dark:text-red-400`,bg:`bg-red-100 dark:bg-red-900/40`,label:`Failed`},abandoned:{color:`text-stone-600 dark:text-stone-400`,bg:`bg-stone-100 dark:bg-stone-900/40`,label:`Abandoned`}};function Qs({goal:e,className:n}){let[r,i]=(0,z.useState)(!1);if((0,z.useEffect)(()=>{let e=B();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,z.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&i(!0)},[e]),!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let a=Zs[e.goalState],o=e.deliverables?.filter(e=>e.status===`done`).length??0,s=e.deliverables?.length??0,c=e.journal?.slice(-5).reverse()??[],l=e.progressTrend?Xs[e.progressTrend]:null;return(0,Y.jsxs)(`div`,{className:J(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,n),children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2.5 text-left hover:bg-accent/40 rounded-t-lg transition-colors`,children:[(0,Y.jsx)(t,{className:`h-4 w-4 text-rose-500`}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Goal`}),(0,Y.jsx)(`span`,{className:J(`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium shrink-0`,a.bg,a.color),children:a.label}),r?(0,Y.jsx)(k,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Y.jsx)(re,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!r&&(0,Y.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t pt-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`p`,{className:`text-xs text-foreground leading-relaxed whitespace-pre-wrap break-words`,children:e.goal}),e.refinedGoal&&e.refinedGoal!==e.goal&&(0,Y.jsxs)(`div`,{className:`mt-1.5 p-2 rounded bg-accent/40 border border-border/50`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground mb-0.5 uppercase tracking-wider font-medium`,children:`Refined`}),(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap break-words`,children:e.refinedGoal})]})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground uppercase tracking-wider font-medium`,children:`Progress`}),(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums`,children:[l,(0,Y.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.progress,`%`]})]})]}),(0,Y.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,Y.jsx)(`div`,{className:J(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-emerald-500`:e.progress>=50?`bg-amber-500`:`bg-primary`),style:{width:`${Math.max(2,e.progress)}%`}})}),e.progressNote&&(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:e.progressNote})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(de,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`tabular-nums font-medium`,children:e.iterations}),(0,Y.jsx)(`span`,{children:`iterations`}),e.lastStatus&&(0,Y.jsx)(`span`,{className:`text-border`,children:`·`}),e.lastStatus&&(0,Y.jsx)(`span`,{className:`truncate`,children:e.lastStatus})]}),s>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:[(0,Y.jsx)(`span`,{children:`Deliverables`}),(0,Y.jsxs)(`span`,{className:`tabular-nums`,children:[o,`/`,s]})]}),(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:e.deliverables?.map(e=>(0,Y.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px]`,children:[e.status===`done`?(0,Y.jsx)(F,{className:`h-3 w-3 text-emerald-500 mt-0.5 shrink-0`}):(0,Y.jsx)(Et,{className:`h-3 w-3 text-muted-foreground/50 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{className:J(`leading-snug`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground`),children:e.text})]},e.id))})]}),c.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:`Recent Activity`}),(0,Y.jsx)(`div`,{className:`space-y-1`,children:c.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{className:`font-mono tabular-nums shrink-0 text-foreground/60`,children:[`#`,e.iteration]}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.task||e.status||e.progressNote||`…`})]},`${e.iteration}-${t}`))})]})]})]})}var $s={in_progress:0,pending:1,completed:2};function ec(){let[e,t]=(0,z.useState)([]),[n,r]=(0,z.useState)(new Set),i=B(),a=(0,z.useRef)(null);(0,z.useEffect)(()=>(i.send({type:`todos.get`}),a.current=i.on(`todos.updated`,e=>{let n=e?.payload;n?.todos&&t(n.todos)}),()=>{a.current?.()}),[i]);let o=(0,z.useCallback)(e=>{i.removeTodo(e)},[i]),s=(0,z.useCallback)(e=>{if(e.status===`in_progress`)return;let t=e.status===`completed`?`pending`:`completed`;i.updateTodoStatus(e.id,t)},[i]),c=[...e].sort((e,t)=>($s[e.status]??9)-($s[t.status]??9)),l=c.filter(e=>e.status===`in_progress`),u=c.filter(e=>e.status===`pending`),d=c.filter(e=>e.status===`completed`),f=d.length>0,p=n.has(`completed`),m=e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},h=e=>{let t=e.status===`in_progress`&&e.activeForm?e.activeForm:e.content,n=e.status===`in_progress`,r=e.status===`completed`,i=!n;return(0,Y.jsxs)(`div`,{onClick:()=>i&&s(e),className:J(`px-3 py-1.5 flex items-start gap-2 text-[13px] group transition-colors`,i&&`cursor-pointer hover:bg-accent/40`,n?`bg-yellow-50/40 dark:bg-yellow-950/25`:r?`bg-emerald-50/20 dark:bg-emerald-950/10`:`bg-background`),role:i?`button`:void 0,"aria-label":i?`Toggle ${e.content}`:void 0,tabIndex:i?0:void 0,onKeyDown:t=>{i&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s(e))},children:[(0,Y.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:r?(0,Y.jsx)(F,{className:`w-3.5 h-3.5 text-emerald-500`}):n?(0,Y.jsx)(de,{className:`w-3.5 h-3.5 text-yellow-500 animate-spin`}):(0,Y.jsx)(Et,{className:J(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/40 group-hover:text-emerald-400`)})}),(0,Y.jsx)(`span`,{className:J(`leading-snug flex-1 min-w-0`,n?`text-yellow-800 dark:text-yellow-200 font-medium`:r?`text-muted-foreground line-through`:`text-foreground/80`),children:t}),(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),o(e.id)},className:`shrink-0 p-0.5 rounded opacity-0 group-hover:opacity-50 hover:opacity-100 hover:bg-destructive/10 transition-all`,title:`Remove todo`,"aria-label":`Remove "${e.content}"`,children:(0,Y.jsx)(Ue,{className:`w-3 h-3 text-muted-foreground`})})]},e.id)};return e.length===0?null:(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Y.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Todos`}),(0,Y.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[d.length,`/`,e.length]})]}),l.length>0&&(0,Y.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:l.map(h)}),u.length>0&&(0,Y.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:u.map(h)}),f&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>m(`completed`),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,Y.jsxs)(`span`,{className:`tabular`,children:[p?`▶`:`▼`,` `,d.length,` completed`]})}),!p&&d.map(h)]})]})}var tc={pending:{icon:(0,Y.jsx)(Et,{className:`w-3.5 h-3.5`}),label:`Pending`,color:`text-muted-foreground/50`},in_progress:{icon:(0,Y.jsx)(de,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},blocked:{icon:(0,Y.jsx)(De,{className:`w-3.5 h-3.5`}),label:`Blocked`,color:`text-orange-500`},failed:{icon:(0,Y.jsx)(a,{className:`w-3.5 h-3.5`}),label:`Failed`,color:`text-red-500`},review:{icon:(0,Y.jsx)(Mt,{className:`w-3.5 h-3.5`}),label:`Review`,color:`text-blue-500`},completed:{icon:(0,Y.jsx)(F,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}},nc={critical:`text-red-600 dark:text-red-400`,high:`text-orange-600 dark:text-orange-400`,medium:`text-yellow-600 dark:text-yellow-400`,low:`text-muted-foreground`},rc={feature:`⚡`,bugfix:`🐛`,refactor:`♻️`,docs:`📝`,test:`🧪`,chore:`🔧`};function ic(){let[e,t]=(0,z.useState)([]),[n,r]=(0,z.useState)(new Set),i=B(),a=(0,z.useRef)(null);(0,z.useEffect)(()=>(i.getTasks(),a.current=i.on(`tasks.updated`,e=>{let n=e?.payload;n?.tasks&&t(n.tasks)}),()=>{a.current?.()}),[i]);let o=(0,z.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,z.useCallback)((e,t)=>{i.updateTaskStatus(e,t)},[i]),c=[`in_progress`,`blocked`,`review`,`pending`,`failed`,`completed`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`completed`)?.length??0;return e.length===0?null:(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Y.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Tasks`}),(0,Y.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=tc[e],i=n.has(e);return(0,Y.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,Y.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,Y.jsxs)(`div`,{className:J(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,Y.jsx)(`span`,{className:J(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,Y.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,Y.jsxs)(`span`,{className:J(e.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[rc[e.type],` `,e.title]}),e.priority!==`medium`&&(0,Y.jsx)(`span`,{className:J(`ml-1 text-[10px]`,nc[e.priority]),children:e.priority}),e.assignee&&(0,Y.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,e.assignee]}),e.estimateHours&&(0,Y.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[e.estimateHours,`h`]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status!==`in_progress`&&e.status!==`completed`&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status===`in_progress`&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`completed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Complete`,children:`Done`}),e.status!==`completed`&&e.status!==`failed`&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e.id,`failed`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-destructive/15 text-destructive hover:bg-destructive/25 transition-colors`,title:`Mark failed`,children:`Fail`})]})]},e.id))]},e)})]})}var ac={open:{icon:(0,Y.jsx)(Et,{className:`w-3.5 h-3.5`}),label:`Open`,color:`text-muted-foreground/50`},in_progress:{icon:(0,Y.jsx)(de,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},done:{icon:(0,Y.jsx)(F,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}};function oc(){let[e,t]=(0,z.useState)([]),[n,r]=(0,z.useState)(new Set),i=B(),a=(0,z.useRef)(null);(0,z.useEffect)(()=>(i.getPlan(),a.current=i.on(`plan.updated`,e=>{let n=e?.payload;n?.plan?.items&&t(n.plan.items)}),()=>{a.current?.()}),[i]);let o=(0,z.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,z.useCallback)((e,t)=>{i.updatePlanItem(e.id,t)},[i]),c=[`in_progress`,`open`,`done`],l=new Map;for(let t of e){let e=l.get(t.status)??[];e.push(t),l.set(t.status,e)}let u=l.get(`done`)?.length??0;return e.length===0?null:(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,Y.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`📋 Plan`}),(0,Y.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[u,`/`,e.length]})]}),c.map(e=>{let t=l.get(e);if(!t||t.length===0)return null;let r=ac[e],i=n.has(e);return(0,Y.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(e),className:`w-full px-3 py-1 flex items-center gap-1.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:(0,Y.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,Y.jsxs)(`div`,{className:J(`px-3 py-1.5 flex items-start gap-2 text-[13px] group`,e.status===`in_progress`?`bg-yellow-50/40 dark:bg-yellow-950/25`:``),children:[(0,Y.jsx)(`span`,{className:J(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,Y.jsx)(`span`,{className:J(`leading-snug flex-1 min-w-0`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground/80`),children:e.title}),(0,Y.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status===`open`&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`in_progress`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-primary/15 text-primary hover:bg-primary/25 transition-colors`,title:`Start`,children:`Start`}),e.status!==`done`&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`done`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-[hsl(var(--success)/0.15)] text-[hsl(var(--success))] hover:bg-[hsl(var(--success)/0.25)] transition-colors`,title:`Mark done`,children:`Done`}),e.status===`done`&&(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),s(e,`open`)},className:`px-1.5 py-0.5 text-[9px] rounded bg-muted text-muted-foreground hover:bg-accent hover:text-foreground transition-colors`,title:`Reopen`,children:`Reopen`})]})]},e.id))]},e)})]})}var sc=[{id:`todos`,label:`Todos`,icon:`✅`},{id:`tasks`,label:`Tasks`,icon:`📋`},{id:`plan`,label:`Plan`,icon:`🗺️`}];function cc(){let[e,t]=(0,z.useState)(`todos`);return(0,Y.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,Y.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:sc.map(n=>(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:J(`flex items-center gap-1 px-3 py-1.5 text-[11px] font-medium transition-colors`,`border-b-2 -mb-px`,e===n.id?`border-primary text-foreground bg-background`:`border-transparent text-muted-foreground hover:text-foreground hover:bg-accent/30`),children:[(0,Y.jsx)(`span`,{className:`text-xs`,children:n.icon}),n.label]},n.id))}),(0,Y.jsx)(`div`,{className:J(e===`todos`?`block`:`hidden`),children:(0,Y.jsx)(ec,{})}),(0,Y.jsx)(`div`,{className:J(e===`tasks`?`block`:`hidden`),children:(0,Y.jsx)(ic,{})}),(0,Y.jsx)(`div`,{className:J(e===`plan`?`block`:`hidden`),children:(0,Y.jsx)(oc,{})})]})}var lc={autophase:{active:`bg-primary/15 border-primary/40 text-primary`,idle:`text-primary/80 hover:bg-primary/10`},goal:{active:`bg-rose-500/15 border-rose-500/40 text-rose-600 dark:text-rose-400`,idle:`text-rose-600/80 dark:text-rose-400/80 hover:bg-rose-500/10`},fleet:{active:`bg-emerald-500/15 border-emerald-500/40 text-emerald-600 dark:text-emerald-400`,idle:`text-emerald-600/80 dark:text-emerald-400/80 hover:bg-emerald-500/10`},work:{active:`bg-amber-500/15 border-amber-500/40 text-amber-600 dark:text-amber-400`,idle:`text-amber-600/80 dark:text-amber-400/80 hover:bg-amber-500/10`},worktrees:{active:`bg-violet-500/15 border-violet-500/40 text-violet-600 dark:text-violet-400`,idle:`text-violet-600/80 dark:text-violet-400/80 hover:bg-violet-500/10`},collab:{active:`bg-cyan-500/15 border-cyan-500/40 text-cyan-600 dark:text-cyan-400`,idle:`text-muted-foreground hover:bg-muted/60`}};function uc({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=lc[e];return(0,Y.jsxs)(`button`,{type:`button`,onClick:o,title:i?`Collapse ${n}`:`Expand ${n}`,className:J(`flex items-center gap-1.5 h-6 px-2 rounded-full border text-[11px] font-medium shrink-0 transition-colors`,i?s.active:J(`border-transparent`,s.idle)),children:[(0,Y.jsx)(`span`,{className:J(a&&`animate-pulse`),children:t}),n,r&&(0,Y.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function dc({sessionId:e}){let n=W(e=>e.dockSection),r=W(e=>e.toggleDockSection),i=W(e=>e.setCurrentView),a=Jn(e=>e.goal),o=Yn(e=>e),s=Wn(e=>e.worktrees),c=Wn(e=>e.baseBranch),l=U(e=>e.todos),u=Kn(e=>e.agents),[d,f]=(0,z.useState)(`graph`),p=u.size,m=(0,z.useMemo)(()=>Array.from(u.values()).filter(e=>e.status===`running`).length,[u]),h=l.filter(e=>e.status===`completed`).length,g=l.some(e=>e.status===`in_progress`),_=o.phases.length>0,v=(0,z.useRef)(o.phases.length);(0,z.useEffect)(()=>{let e=W.getState();v.current===0&&o.phases.length>0&&e.dockSection===null&&e.setDockSection(`autophase`),o.phases.length===0&&e.dockSection===`autophase`&&e.setDockSection(null),v.current=o.phases.length},[o.phases.length]);let y={autophase:_,goal:a!==null,fleet:p>0,work:!0,worktrees:s.length>0,collab:!0},b=n&&y[n]?n:null;return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[y.autophase&&(0,Y.jsx)(uc,{section:`autophase`,icon:(0,Y.jsx)(vt,{className:`h-3 w-3`}),label:`AutoPhase`,value:`${o.overallPercent}%`,active:b===`autophase`,pulse:o.activePhaseId!=null,onClick:()=>r(`autophase`)}),y.goal&&a&&(0,Y.jsx)(uc,{section:`goal`,icon:(0,Y.jsx)(t,{className:`h-3 w-3`}),label:`Goal`,value:`${a.progress}%`,active:b===`goal`,pulse:a.goalState===`active`,onClick:()=>r(`goal`)}),y.fleet&&(0,Y.jsx)(uc,{section:`fleet`,icon:(0,Y.jsx)(E,{className:`h-3 w-3`}),label:`Fleet`,value:`${m}/${p}`,active:b===`fleet`,pulse:m>0,onClick:()=>r(`fleet`)}),(0,Y.jsx)(uc,{section:`work`,icon:(0,Y.jsx)(Ae,{className:`h-3 w-3`}),label:`Work`,value:l.length>0?`${h}/${l.length}`:void 0,active:b===`work`,pulse:g,onClick:()=>r(`work`)}),y.worktrees&&(0,Y.jsx)(uc,{section:`worktrees`,icon:(0,Y.jsx)(st,{className:`h-3 w-3`}),label:`Worktrees`,value:String(s.length),active:b===`worktrees`,onClick:()=>r(`worktrees`)}),(0,Y.jsx)(uc,{section:`collab`,icon:(0,Y.jsx)(S,{className:`h-3 w-3`}),label:`Collab`,active:b===`collab`,onClick:()=>r(`collab`)})]}),b===`autophase`&&_&&(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsxs)($,{variant:`outline`,size:`sm`,className:`h-6 gap-1 text-[10px]`,onClick:()=>i(`autophase`),children:[(0,Y.jsx)(ie,{className:`h-3 w-3`}),`Full view`]})}),(0,Y.jsx)(Oi,{phases:o.phases,activePhaseId:o.activePhaseId??void 0,overallPercent:o.overallPercent,autonomous:o.autonomous})]}),b===`goal`&&(0,Y.jsx)(Qs,{goal:a}),b===`fleet`&&(0,Y.jsx)(js,{}),b===`worktrees`&&(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>f(e),className:J(`text-[10px] px-2 py-0.5 rounded-full border transition-colors capitalize`,d===e?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),d===`graph`?(0,Y.jsx)(Ri,{worktrees:s,baseBranch:c||`HEAD`}):(0,Y.jsx)(Hi,{worktrees:s,baseBranch:c||`HEAD`})]}),(0,Y.jsx)(`div`,{className:J(b===`work`?`block`:`hidden`),id:`panel-work`,children:(0,Y.jsx)(cc,{})}),(0,Y.jsx)(`div`,{className:J(b===`collab`?`block`:`hidden`),children:(0,Y.jsx)(Ys,{sessionId:e})})]})}function fc(){let{theme:e}=ni(),{currentView:t,sidebarOpen:n,toggleSidebar:r,setSearchOpen:i,setSidebarOpen:a,setCurrentView:o}=W(),s=V(e=>e.isLoading),c=U(e=>e.iteration),l=U(e=>e.projectName),u=U(e=>e.session?.title),d=U(e=>e.session?.id),f=W(e=>d?e.sessionNicknames[d]:void 0);return(0,z.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=B(H.getState().wsUrl);n&&n.send({type:`files.read`,payload:{filePath:t}})};return window.addEventListener(`wrongstack:open-file`,e),()=>window.removeEventListener(`wrongstack:open-file`,e)},[]),(0,z.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=G.getState().openFiles.find(e=>e.path===t);if(!n)return;let r=B(H.getState().wsUrl);r&&r.send({type:`files.write`,payload:{filePath:t,content:n.content}})};return window.addEventListener(`wrongstack:save-file`,e),()=>window.removeEventListener(`wrongstack:save-file`,e)},[]),(0,z.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: 768px)`),t=()=>{e.matches&&W.getState().sidebarOpen&&a(!1)};return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[a]),$r(),(0,z.useEffect)(()=>{let e=[];if(s){let t=c?` iter ${c.index}${c.max?`/${c.max}`:``}`:``;e.push(`●${t}`)}let t=f?.trim()||u?.trim(),n=l?.trim();t&&e.push(t),n&&e.push(n),e.length===0&&e.push(n||`AI Agent`);let r=e.filter(Boolean).join(` · `);return document.title=r,()=>{document.title=l||`AI Agent`}},[s,c,l,u,f]),(0,z.useEffect)(()=>{let e=e=>{let t=e.target,n=t?.tagName?.toLowerCase(),a=n===`input`||n===`textarea`||t?.isContentEditable,o=e.ctrlKey||e.metaKey;if(o&&e.key===`\\`){e.preventDefault(),r();return}if(o&&!e.shiftKey&&!e.altKey&&e.key>=`1`&&e.key<=String(oi.length)){let t=oi[Number(e.key)-1];if(t){e.preventDefault(),ai(t);return}}if(o&&e.key.toLowerCase()===`f`){e.preventDefault(),i(!0);return}if(o&&e.key.toLowerCase()===`/`){e.preventDefault(),document.querySelector(`textarea`)?.focus();return}if(o&&!a&&(e.key.toLowerCase()===`l`?(e.preventDefault(),V.getState().clearMessages(),B(H.getState().wsUrl)?.clearContext?.()):e.key.toLowerCase()===`n`?(e.preventDefault(),B(H.getState().wsUrl)?.newSession?.(),W.getState().setCurrentView(`chat`)):e.key.toLowerCase()===`e`&&(e.preventDefault(),qi())),o&&e.shiftKey&&e.key.toLowerCase()===`d`&&(e.preventDefault(),W.getState().toggleCompactMode()),!a&&!o&&!e.altKey){let t=Array.from(document.querySelectorAll(`[data-message-id]`));if(t.length===0)return;let n=document.querySelector(`[data-message-id][data-focused="true"]`),r=n?t.indexOf(n):-1,i=e=>{for(let e of t)e.removeAttribute(`data-focused`);e.setAttribute(`data-focused`,`true`),e.scrollIntoView({behavior:`smooth`,block:`center`})};if(e.key===`j`||e.key===`ArrowDown`){let n=t[Math.min(t.length-1,Math.max(0,r+1))];n&&(e.preventDefault(),i(n));return}if(e.key===`k`||e.key===`ArrowUp`){let n=t[Math.max(0,r<=0?0:r-1)];n&&(e.preventDefault(),i(n));return}if(e.key===`g`&&!e.shiftKey){e.preventDefault(),i(R(t[0]));return}if(e.key===`G`||e.key===`g`&&e.shiftKey){e.preventDefault(),i(R(t[t.length-1]));return}if(e.key===`Escape`&&n){e.preventDefault(),n.removeAttribute(`data-focused`);return}if(e.key===`c`&&n){let t=n.querySelector(`.markdown-content`)?.innerText??n.innerText;t&&(navigator.clipboard?.writeText(t).catch(()=>{}),e.preventDefault());return}}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,i]),(0,Y.jsxs)(`div`,{className:J(`flex h-screen`,e),children:[t!==`setup`&&(0,Y.jsx)(si,{}),n&&t!==`setup`&&(0,Y.jsx)(Js,{}),(0,Y.jsxs)(`main`,{className:`flex-1 flex flex-col overflow-hidden`,children:[t!==`setup`&&(0,Y.jsx)(Do,{}),t===`chat`&&(0,Y.jsxs)(Y.Fragment,{children:[d&&(0,Y.jsx)(`div`,{className:`px-4 pt-2`,children:(0,Y.jsx)(dc,{sessionId:d})}),(0,Y.jsx)(ao,{})]}),t===`settings`&&(0,Y.jsx)(Ho,{}),t===`setup`&&(0,Y.jsx)(Ko,{}),t===`autophase`&&(0,Y.jsx)(Wi,{onClose:()=>o(`chat`)}),t===`agents`&&(0,Y.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,Y.jsx)(wi,{})}),t===`agentflow`&&(0,Y.jsx)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:(0,Y.jsx)(hs,{})}),t===`sessions`&&(0,Y.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,Y.jsx)(Qo,{})}),t===`files`&&(0,Y.jsx)(uo,{})]}),(0,Y.jsx)(Co,{}),(0,Y.jsx)(Eo,{}),(0,Y.jsx)(Yi,{}),(0,Y.jsx)(es,{}),(0,Y.jsx)(Ao,{}),(0,Y.jsx)(ar,{})]})}function pc(){return(0,Y.jsx)(Oo,{children:(0,Y.jsx)(ti,{defaultTheme:`system`,children:(0,Y.jsx)(fc,{})})})}bn.createRoot(R(document.getElementById(`root`))).render((0,Y.jsx)(z.StrictMode,{children:(0,Y.jsx)(pc,{})}));
|