@wrongstack/webui 0.265.1 → 0.267.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/index-UZtAQH-v.css +2 -0
- package/dist/assets/index-q6W9UOEF.js +121 -0
- package/dist/assets/{vendor-BX-wfDR9.js → vendor-HxGAEBey.js} +230 -230
- package/dist/index.html +3 -3
- package/dist/index.js +3331 -2562
- package/dist/index.js.map +1 -1
- package/dist/server/entry.js +493 -365
- package/dist/server/entry.js.map +1 -1
- package/dist/server/index.d.ts +50 -24
- package/dist/server/index.js +512 -382
- package/dist/server/index.js.map +1 -1
- package/dist/types.d.ts +29 -0
- package/package.json +6 -5
- package/dist/assets/index-CC3KdGXG.js +0 -118
- package/dist/assets/index-CFHDQU3T.css +0 -2
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import{r as e,t}from"./rolldown-runtime-QTnfLwEv.js";import{$ as n,$n as r,$t as i,A as a,An as o,Ar as s,At as c,B as l,Bn as u,Br as d,Bt as f,C as p,Cn as m,Cr as h,Ct as g,D as _,Dn as v,Dr as y,Dt as b,E as x,En as S,Er as C,Et as w,F as T,Fn as E,Fr as D,Ft as O,G as k,Gn as A,Gt as ee,H as j,Hn as M,Hr as N,Ht as P,I as F,In as I,Ir as te,It as L,J as ne,Jn as R,Jt as re,K as ie,Kn as ae,Kt as oe,L as se,Ln as ce,Lr as le,Lt as ue,M as de,Mn as fe,Mr as pe,Mt as me,N as he,Nn as ge,Nr as _e,Nt as ve,O as ye,On as be,Or as xe,Ot as Se,P as Ce,Pn as we,Pr as Te,Pt as Ee,Q as De,Qn as Oe,Qt as ke,R as Ae,Rn as je,Rr as Me,Rt as Ne,S as Pe,Sn as Fe,Sr as Ie,St as Le,T as Re,Tn as ze,Tr as Be,Tt as Ve,U as He,Un as Ue,Ur as We,Ut as Ge,V as Ke,Vn as qe,Vr as Je,Vt as Ye,W as Xe,Wn as Ze,Wt as Qe,X as $e,Xn as et,Xt as tt,Y as nt,Yn as rt,Yt as it,Z as at,Zn as ot,Zt as st,_ as ct,_n as lt,_r as ut,_t as dt,a as ft,an as pt,ar as mt,at as ht,b as gt,bn as _t,br as vt,bt as yt,c as bt,cn as xt,cr as St,ct as Ct,d as wt,dn as Tt,dr as Et,dt as Dt,en as Ot,er as kt,et as At,f as jt,fn as z,fr as Mt,ft as Nt,g as Pt,gn as Ft,gr as It,gt as Lt,h as Rt,hn as zt,hr as Bt,ht as Vt,i as Ht,in as Ut,ir as Wt,it as Gt,j as Kt,jn as qt,jr as Jt,jt as Yt,k as Xt,kn as Zt,kr as Qt,kt as $t,l as en,ln as tn,lr as nn,lt as rn,m as an,mn as on,mr as sn,mt as cn,n as ln,nn as un,nr as dn,nt as fn,o as pn,on as mn,or as hn,ot as gn,p as _n,pn as vn,pr as yn,pt as bn,q as xn,qn as Sn,qt as Cn,r as wn,rn as Tn,rr as En,rt as Dn,s as On,sn as kn,sr as An,st as jn,t as Mn,tn as Nn,tr as Pn,tt as Fn,u as In,un as Ln,ur as Rn,ut as zn,v as Bn,vn as Vn,vr as Hn,vt as Un,w as Wn,wn as Gn,wr as Kn,wt as qn,x as Jn,xn as Yn,xr as Xn,xt as Zn,y as Qn,yn as $n,yr as er,yt as tr,z as nr,zn as rr,zr as ir,zt as ar}from"./vendor-BX-wfDR9.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 B(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 or(e){return e instanceof Error?e.message:String(e)}function sr(e,t){let n=e=>e.trim().replace(/\s+/g,` `).toLowerCase();return n(e)===n(t)}var V=e(We(),1),cr=e(N(),1),lr=`#4f46e5`;function ur(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="${lr}" />
|
|
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 dr(e){return`data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`}function fr(){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 pr=`idle`;function mr(e){pr=e;let t=fr();t&&(t.href=dr(ur(e)))}var hr=!1;function gr(){hr||typeof document>`u`||(hr=!0,document.addEventListener(`visibilitychange`,()=>{!document.hidden&&(pr===`ready`||pr===`error`||pr===`attention`)&&mr(`idle`)}))}function _r(e){return{type:`provider.clear_models`,payload:{providerId:e}}}function vr(e,t){return{type:`provider.undo_clear`,payload:{providerId:e,previousModels:[...t]}}}function yr(e){return{type:`provider.update`,payload:e}}function br(e){try{return new URL(e).searchParams.get(`token`)}catch{return null}}var xr=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??Tr()}async ensureAuthCookie(){if(typeof window>`u`||document.cookie.split(`;`).some(e=>e.trim().startsWith(`ws_token=`)))return;let e=br(this.url);if(!e)return;let t=Er()+`/ws-auth?token=${encodeURIComponent(e)}`;try{let e=await fetch(t,{method:`GET`,credentials:`same-origin`,cache:`no-store`});e.ok||console.warn(JSON.stringify({level:`warn`,event:`ws_client.ws_auth_failed`,status:e.status,timestamp:new Date().toISOString()}))}catch(e){console.warn(JSON.stringify({level:`warn`,event:`ws_client.ws_auth_error`,message:e instanceof Error?e.message:String(e),timestamp:new Date().toISOString()}))}}async connect(){return await this.ensureAuthCookie(),new Promise((e,t)=>{if(this.ws?.readyState===WebSocket.OPEN){e();return}this.setStatus({state:`connecting`});try{let n=br(this.url),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}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,t){let n=`msg_${Date.now()}_${crypto.randomUUID().slice(0,8)}`;return this.send({type:`user_message`,payload:{id:n,content:e,timestamp:Date.now(),...t?{imageBase64:t}:{}}}),n}sendAbort(){this.send({type:`abort`,payload:{}})}getGitInfo(){this.send({type:`git.info`})}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}})}probeProvider(e,t){this.send({type:`provider.probe`,payload:t===void 0?{providerId:e}:{providerId:e,timeoutMs:t}})}clearProviderModels(e){this.send(_r(e))}undoProviderClear(e,t){this.send(vr(e,t))}updateProvider(e){this.send(yr(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}})}listMcpServers(){this.send({type:`mcp.list`})}addMcpServer(e){this.send({type:`mcp.add`,payload:e})}removeMcpServer(e){this.send({type:`mcp.remove`,payload:{name:e}})}updateMcpServer(e){this.send({type:`mcp.update`,payload:e})}wakeMcpServer(e){this.send({type:`mcp.wake`,payload:{name:e}})}sleepMcpServer(e){this.send({type:`mcp.sleep`,payload:{name:e}})}discoverMcpServer(e){this.send({type:`mcp.discover`,payload:{name:e}})}enableMcpServer(e){this.send({type:`mcp.enable`,payload:{name:e}})}disableMcpServer(e){this.send({type:`mcp.disable`,payload:{name:e}})}restartMcpServer(e){this.send({type:`mcp.restart`,payload:{name:e}})}listSkills(){this.send({type:`skills.list`})}getSkillContent(e,t){this.send({type:`skills.content`,payload:{name:e,source:t}})}installSkill(e,t){this.send({type:`skills.install`,payload:{ref:e,global:t}})}uninstallSkill(e,t){this.send({type:`skills.uninstall`,payload:{name:e,global:t}})}checkForUpdates(e,t){this.send({type:`skills.update`,payload:{name:e,global:t}})}createSkill(e,t,n){this.send({type:`skills.create`,payload:{name:e,description:t,scope:n}})}editSkill(e,t){this.send({type:`skills.edit`,payload:{name:e,body:t}})}exportAllSkills(){this.send({type:`skills.export`})}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}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}get currentSessionId(){return this.sessionId}},Sr=null,Cr=3457;function wr(){if(typeof document>`u`)return Cr;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:Cr}function Tr(){let e=wr();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 Er(){if(typeof window>`u`||!window.location?.hostname)return`http://127.0.0.1:3456`;let e=window.location.hostname.toLowerCase(),t=window.location.port?Number.parseInt(window.location.port,10):NaN,n=Number.isFinite(t)&&t>0?t:3456;return e===`localhost`||e===`127.0.0.1`||e===`[::1]`||e===`::1`?`http://127.0.0.1:${n}`:`http://${window.location.hostname}:${n}`}function H(e){return Sr||=new xr(e),Sr}function Dr(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 U=Je()(d((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:Dr(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:(e,n)=>{t().appendToolProgressLines(e,[n])},appendToolProgressLines:(t,n)=>{n.length!==0&&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+1),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}),B(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:()=>({})})),W=Je()(d(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`})),G=Je()(d(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:()=>({})})),Or=[`chat`,`agents`,`history`,`files`,`projects`,`mailbox`,`skills`,`officemap`];function kr(e){return Or.includes(e)?e:e===`context`?`chat`:e===`sessions`?`history`:e===`officemap`?`officemap`:`chat`}var K=Je()(d(e=>({sidebarOpen:!0,activeActivity:`chat`,settingsOpen:!1,currentView:`chat`,showConfirmDialog:!1,confirmInfo:null,paletteOpen:!1,shortcutsOpen:!1,searchOpen:!1,searchQuery:``,scrollTarget:null,promptHistory:[],sidebarWidth:304,pinnedIds:[],compactMode:!1,modelSwitcherOpen:!1,favoriteSessionIds:[],sessionNicknames:{},fileExplorerWidth:220,refineEnabled:!0,refinePanel:null,dockSection:null,fleetMonitorOpen:!1,agentsMonitorOpen:!1,inspectorOpen:!1,inspectorTab:`fleet`,processMonitorOpen:!1,queuePanelOpen:!1,skillsState:{selectedSkill:null,navHistory:[],historyIndex:-1,detailOpen:!1,knownRefs:{},updateAvailableCount:0},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}),requestScrollToMessage:t=>e(e=>({scrollTarget:{id:t,nonce:(e.scrollTarget?.nonce??0)+1}})),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})),setFleetMonitorOpen:t=>e({fleetMonitorOpen:t}),setAgentsMonitorOpen:t=>e({agentsMonitorOpen:t}),setInspectorOpen:t=>e({inspectorOpen:t}),setInspectorTab:t=>e({inspectorTab:t}),toggleInspector:()=>e(e=>({inspectorOpen:!e.inspectorOpen})),setProcessMonitorOpen:t=>e({processMonitorOpen:t}),setQueuePanelOpen:t=>e({queuePanelOpen:t}),setSkillsState:t=>e({skillsState:t})}),{name:`wrongstack-ui`,version:4,migrate:(e,t)=>{let n=e??{};return n.activeActivity=kr(n.activeActivity),typeof n.sidebarWidth==`number`&&(n.sidebarWidth=Math.max(240,Math.min(560,n.sidebarWidth))),t<2&&(delete n.fleetDrawerOpen,delete n.agentsDrawerOpen),n},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,inspectorOpen:e.inspectorOpen,inspectorTab:e.inspectorTab,skillsState:e.skillsState})})),Ar=Je()(e=>({messages:[],agents:[],setMessages:t=>e({messages:t}),setAgents:t=>e({agents:t})}));function jr(e){return e.messages.filter(e=>!e.completed&&(e.readByCount??0)===0).length}var Mr=Je()(e=>({info:null,setInfo:t=>e({info:t}),clear:()=>e({info:null})})),Nr=Je()(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:[]})})),Pr=Je()(e=>({worktrees:[],baseBranch:``,activity:[],setSnapshot:(t,n)=>e({worktrees:t,baseBranch:n}),pushEvent:t=>e(e=>({activity:[...e.activity,t].slice(-40)}))})),q=fn(),Fr=/(?:💡\s*Next steps?|<next_steps>)\s*\n+/i,Ir=/^(?:(\d+)[.)]\s*|[-*•]\s*)(.+?)(\s+auto="true")?$/,Lr=6;function Rr(e,t=!0){let n=t?Fr.exec(e):Br().exec(e);if(!n)return{steps:[],stripped:e};let r=n.index+n[0].length,i=e.slice(r),a=i.split(`
|
|
10
|
-
`),o=[],s=new Set,c=0,l=0;for(let e of a){let t=e.trim();if(t===`</next_steps>`){c+=e.length+1;break}if(!t){c+=e.length+1;continue}let n=Ir.exec(t);if(!n)break;let r=n[1],i=n[2].trim(),a=!!n[3],u=r===void 0?o.length+1:Number.parseInt(r,10);if(s.has(u)){c+=e.length+1;continue}if(s.add(u),o.push(a?{index:u,text:i,auto:!0}:{index:u,text:i}),c+=e.length+1,l++,l>=Lr)break}if(o.length===0||t&&/<next_steps>/i.test(n[0])&&!i.includes(`</next_steps>`))return{steps:[],stripped:e};let u=n.index,d=r+c;return{steps:o,stripped:(e.slice(0,u)+e.slice(d)).replace(/\n{3,}/g,`
|
|
11
|
-
|
|
12
|
-
`).trim()}}var zr=[{re:/💡\s*Next steps?\s*\n+/i,label:`emoji`},{re:/##?\s*Next steps?\s*\n+/i,label:`markdown`},{re:/\n{1,2}Next steps?\s*\n+/i,label:`plain`},{re:/<next_steps>\s*\n+/i,label:`xml-tag`}];function Br(){let e=zr.map(({re:e})=>`(?:${e.source})`).join(`|`);return new RegExp(e,`i`)}function Vr(e){return e.replace(/<next_steps\b[^>]*>[\s\S]*?<\/next_steps>/gi,``).replace(/<next_steps\b[^>]*\/?>/gi,``).replace(/\n{3,}/g,`
|
|
13
|
-
|
|
14
|
-
`).trim()}function Hr(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 Ur({delayMs:e,onComplete:t}){let[n,r]=(0,V.useState)(Math.ceil(e/1e3));return(0,V.useEffect)(()=>{if(n<=0){t();return}let e=setTimeout(()=>r(e=>e-1),1e3);return()=>clearTimeout(e)},[n,t]),(0,q.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-primary font-medium`,children:[(0,q.jsx)(dt,{className:`h-3 w-3`}),n,`s`]})}function Wr({steps:e,yoloMode:t=!1,autoMode:n=!1,autoDelayMs:r=3e4,onAutoSubmit:i,canAutoSubmit:a=!0}){if(e.length===0)return null;let o=t&&n&&a,s=o?e.find(e=>e.auto):void 0;return(0,q.jsxs)(`div`,{className:`mt-4 rounded-xl border border-primary/20 bg-primary/[0.03] overflow-hidden animate-message`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3.5 py-2 border-b border-primary/10 bg-primary/[0.04]`,children:[(0,q.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md bg-primary/15 text-primary`,children:(0,q.jsx)(Ft,{className:`h-3 w-3`})}),(0,q.jsx)(`span`,{className:`text-xs font-semibold text-foreground/90`,children:`Next steps`}),o&&s?(0,q.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-xs text-primary`,children:[(0,q.jsx)(dt,{className:`h-3 w-3`}),`auto-submitting in `,(0,q.jsx)(Ur,{delayMs:r,onComplete:()=>i?.(s.text)})]}):(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:`click to fill input`})]}),(0,q.jsx)(`div`,{className:`flex flex-col p-2 gap-1`,children:e.map(e=>{let t=o&&e.auto;return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>Hr(e.text),className:`group flex items-center gap-2.5 w-full text-left px-3 py-2 rounded-lg transition-all border ${t?`bg-primary/10 border-primary/30 ring-1 ring-primary/20`:`border-transparent hover:bg-primary/[0.08] hover:shadow-sm hover:border-primary/20`}`,title:`Click to fill: ${e.text}`,children:[(0,q.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-md text-[11px] font-mono font-semibold tabular-nums shrink-0 transition-colors ${t?`bg-primary/30 text-primary`:`bg-muted/80 group-hover:bg-primary/20 text-muted-foreground group-hover:text-primary`}`,children:e.index}),(0,q.jsx)(Te,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`text-primary`:`text-muted-foreground/60 group-hover:text-primary group-hover:translate-x-0.5`}`}),(0,q.jsx)(`span`,{className:`text-sm leading-snug flex-1 min-w-0 transition-colors ${t?`text-foreground font-medium`:`text-foreground/80 group-hover:text-foreground`}`,children:e.text}),e.auto&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1 text-[10px] text-primary/70`,children:[n&&e.index===1&&!o?(0,q.jsx)(`span`,{title:`Will auto-submit after countdown`,children:`⏩`}):(0,q.jsx)(dt,{className:`h-3 w-3`}),`auto`]}),(0,q.jsx)(Ot,{className:`h-3.5 w-3.5 shrink-0 transition-all ${t?`opacity-100 text-primary/60`:`opacity-0 group-hover:opacity-100 text-primary/60`}`})]},e.index)})})]})}var Gr=12,Kr=20;function qr(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:[],sparklineBins:Array(Gr).fill(0)}}var Jr=0;function Yr(){return`tl_${Date.now()}_${++Jr}`}function Xr(e,t){return[t,...e].slice(0,Kr)}function Zr(e){return[e[0]+1,...e.slice(0,Gr-1)]}var J=Je()((e,t)=>({agents:new Map,leaderId:void 0,fleetTokensIn:0,fleetTokensOut:0,fleetConcurrency:0,fleetConcurrencyMax:4,eventTimeline:[],clear:()=>e({agents:new Map,leaderId:void 0,fleetTokensIn:0,fleetTokensOut:0,fleetConcurrency:0,eventTimeline:[]}),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),r=e.eventTimeline,i=e.leaderId,a=e.fleetTokensIn,o=e.fleetTokensOut;if(t.kind===`session_stopped`&&t.sessionId){for(let[e,r]of n)r.sessionId===t.sessionId&&n.delete(e);return{agents:n,leaderId:void 0,fleetTokensIn:0,fleetTokensOut:0}}if(t.kind===`leader_updated`&&t.subagentId){let a=e.leaderId;if(a&&a!==t.subagentId){let e=n.get(a);e&&n.set(a,{...e,isLeader:!1})}i=t.subagentId;let o=n.get(t.subagentId)??qr(t.subagentId,t.name,t.sessionId);return n.set(t.subagentId,{...o,isLeader:!0,name:t.name?.trim()||o.name}),r=Xr(r,{id:Yr(),kind:`leader_updated`,agentId:t.subagentId,agentName:t.name??i,timestamp:Date.now(),message:`${t.name??t.subagentId} became leader`}),{agents:n,leaderId:i,eventTimeline:r}}if(!t.subagentId)return e;let s=n.get(t.subagentId)??qr(t.subagentId,t.name,t.sessionId),c={...s},l=Date.now();switch(t.kind){case`spawned`:c.name=t.name?.trim()||c.name,c.provider=t.provider??c.provider,c.model=t.model??c.model,c.description=t.description??c.description,c.taskId=t.taskId??c.taskId,c.sessionId=t.sessionId??c.sessionId,c.status=`running`,c.sparklineBins=Array(Gr).fill(0),r=Xr(r,{id:Yr(),kind:`spawned`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} spawned`});break;case`task_started`:c.description=t.description??c.description,c.taskId=t.taskId??c.taskId,c.status=`running`,r=Xr(r,{id:Yr(),kind:`task_started`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} started: ${t.description??`new task`}`});break;case`tool_executed`:{let e=typeof t.ok==`boolean`?t.ok:!0,n=typeof t.durationMs==`number`?t.durationMs:0;c.lastTool=t.toolName??c.lastTool,c.toolCalls+=1,c.toolLog=[{name:t.toolName??`unknown`,ok:e,durationMs:n,at:l},...c.toolLog].slice(0,50),c.sparklineBins=Zr(c.sparklineBins),r=Xr(r,{id:Yr(),kind:`tool_executed`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} ${e?`✓`:`✗`} ${t.toolName??`tool`}`,value:n});break}case`iteration_summary`:c.iteration=t.iteration??c.iteration,typeof t.toolCalls==`number`&&(c.toolCalls=t.toolCalls),typeof t.costUsd==`number`&&(c.costUsd=t.costUsd),c.currentTool=t.currentTool??c.currentTool,typeof t.partialText==`string`&&t.partialText&&(c.partialText=t.partialText),c.sparklineBins=Zr(c.sparklineBins),r=Xr(r,{id:Yr(),kind:`iteration_summary`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} iter ${t.iteration??c.iteration} · ${t.currentTool?`${t.currentTool}`:``}`,value:t.costUsd});break;case`budget_extended`:c.extensions=t.totalExtensions??c.extensions+1,c.budgetWarning=void 0,r=Xr(r,{id:Yr(),kind:`budget_extended`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} extended budget ⚡×${c.extensions}`});break;case`ctx_pct`:c.ctxPct=Math.round(Math.max(0,t.load??0)*100),c.ctxTokens=t.tokens??c.ctxTokens,c.maxContext=t.maxContext??c.maxContext,c.ctxPct>=80&&!c.budgetWarning&&(c.budgetWarning=c.ctxPct>=100?{kind:`hard`,used:c.ctxPct,limit:100}:{kind:`soft`,used:c.ctxPct,limit:100}),typeof t.costUsd==`number`&&(c.costUsd=t.costUsd),typeof t.tokensIn==`number`&&(c.tokensIn=t.tokensIn,a=a-(s.tokensIn??0)+t.tokensIn),typeof t.tokensOut==`number`&&(c.tokensOut=t.tokensOut,o=o-(s.tokensOut??0)+t.tokensOut),r=Xr(r,{id:Yr(),kind:`ctx_pct`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} ctx ${c.ctxPct}%`,value:c.ctxPct});break;case`task_completed`:{c.status=t.status===`success`?`completed`:t.status??`completed`,typeof t.iterations==`number`&&(c.iteration=t.iterations),typeof t.toolCalls==`number`&&(c.toolCalls=t.toolCalls),c.error=t.error,c.currentTool=void 0,c.completedAt=l,c.failureReason=t.failureReason??c.failureReason,typeof t.finalText==`string`&&t.finalText&&(c.finalText=Vr(t.finalText));let e=t.status===`success`?`✓ completed`:t.status===`failed`?`✗ failed${t.failureReason?` (${t.failureReason})`:``}`:t.status===`timeout`?`⏱ timeout${t.failureReason?` (${t.failureReason})`:``}`:`stopped`;r=Xr(r,{id:Yr(),kind:`task_completed`,agentId:t.subagentId,agentName:c.name,timestamp:l,message:`${c.name} ${e}`,value:c.costUsd});break}}return n.set(t.subagentId,c),{agents:n,leaderId:i,fleetTokensIn:a,fleetTokensOut:o,eventTimeline:r}})}));function Qr(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 $r=Je()(e=>({goal:null,setGoal:t=>e({goal:Qr(t)}),clear:()=>e({goal:null}),refresh:()=>{try{H()?.send?.({type:`goal.get`})}catch{}}})),ei=Je()(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})})),ti={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`,tgConfigured:!1,tgSessionEnd:!1,tgDelegate:!0,tgLongToolMs:3e4},ni=Je()(d(e=>({...ti,set:t=>e(t),reset:()=>e(ti)}),{name:`wrongstack-local-prefs`,version:3,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}})),Y=Je()((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})}));function ri(e,t=!1){if(t&&e.target){if(e.kind===`agent:tool`||e.kind===`tool:executed`||e.kind===`tool:started`)return`tool`;if(e.source===`leader`||e.source===`coordinator`)return`coordinator`;if(e.kind.startsWith(`provider:`))return`provider`;if(e.kind.startsWith(`mailbox:`))return`mailbox`}switch(e.kind){case`provider:call`:case`provider:delta`:case`provider:response`:return`provider`;case`agent:spawned`:case`agent:tool`:case`agent:status`:case`agent:text`:case`agent:ctx`:case`budget:extended`:return`agent`;case`tool:started`:case`tool:executed`:case`tool:progress`:return`tool`;case`mailbox:send`:case`mailbox:deliver`:return`mailbox`;case`session:start`:case`session:end`:case`iteration:start`:case`iteration:end`:case`fleet:snapshot`:return`session`;case`context:compacted`:case`context:repaired`:case`cost:update`:return`system`;case`error`:return`error`;default:return`system`}}function ii(e){switch(e){case`provider:call`:case`provider:delta`:case`agent:tool`:case`tool:started`:case`tool:progress`:case`iteration:start`:case`agent:text`:return`streaming`;case`agent:status`:case`iteration:end`:return`completed`;case`error`:return`error`;case`tool:executed`:return`completed`;case`session:end`:return`idle`;default:return`active`}}var ai=0;function oi(){return`viz_${Date.now()}_${++ai}`}var si={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%)`},ci={"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%)`},li=Je()((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:t.id??oi(),timestamp:t.timestamp||Date.now()},...e.events];n.length>e.maxEvents&&(n.length=e.maxEvents);let r=new Map(e.nodes),i=new Map(e.edges),a=Date.now(),o={id:t.source,kind:ri(t),label:t.label,status:ii(t.kind),activity:1,color:t.color??si[ri(t)],lastSeenAt:a},s=r.get(t.source);if(r.set(t.source,{...s,...o}),t.target){let e={id:t.target,kind:ri(t,!0),label:t.target,status:ii(t.kind),activity:.8,color:t.color??si[ri(t,!0)],lastSeenAt:a},n=r.get(t.target);r.set(t.target,{...n,...e});let o=`${t.source}->${t.target}`,s=i.get(o);i.set(o,{id:o,source:t.source,target:t.target,kind:t.kind,label:t.label,intensity:s?Math.min(1,s.intensity+.3):.7,color:t.color??si[ri(t)]??`#6366f1`,lastActiveAt:a,totalMagnitude:(s?.totalMagnitude??0)+(t.magnitude??0)})}return{events:n,nodes:r,edges:i}}),upsertNode:t=>e(e=>{let n=new Map(e.nodes),r=n.get(t.id);return n.set(t.id,{...r,...t,lastSeenAt:t.lastSeenAt===void 0?Date.now():t.lastSeenAt}),{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:t.lastActiveAt===void 0?Date.now():t.lastActiveAt,intensity:t.intensity??r?.intensity??.5,color:t.color??ci[t.kind]??ci.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)if(n.activity>=.01){let r=n.activity*.92;t.set(e,{...n,activity:r<.01?0:r})}let n=new Map(e.edges);for(let[e,t]of n)if(t.intensity>=.01){let r=t.intensity*.9;n.set(e,{...t,intensity:r<.01?0:r})}return{nodes:t,edges:n}}),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!==void 0&&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 ui(e,t){switch(e){case`provider.text_delta`:{let e=t.text??``;return{id:oi(),kind:`provider:delta`,timestamp:Date.now(),source:`provider`,target:`leader`,label:e.slice(0,60),magnitude:e.length,data:{text:e},color:si.provider,flowGroup:`provider`}}case`provider.response`:{let e=t.usage,n=(e?.input??0)+(e?.output??0);return{id:oi(),kind:`provider:response`,timestamp:Date.now(),source:`provider`,target:`leader`,label:`${(e?.input??0).toLocaleString(`en-US`)} in / ${(e?.output??0).toLocaleString(`en-US`)} out`,magnitude:n,data:t,color:si.provider,flowGroup:`provider`}}case`tool.started`:{let e=t.name??`tool`;return{id:oi(),kind:`tool:started`,timestamp:Date.now(),source:e,target:`filesystem`,label:e,magnitude:1,data:t,color:si.tool,flowGroup:`tool:${e}`}}case`tool.executed`:{let e=t.name??`tool`,n=t.ok??!0;return{id:oi(),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?si.tool:si.error,flowGroup:`tool:${e}`}}case`tool.progress`:{let e=t.name??`tool`,n=t.event?.text??``;return{id:oi(),kind:`tool:progress`,timestamp:Date.now(),source:e,target:`leader`,label:n.slice(0,60)||e,magnitude:n.length,data:t,color:si.tool,flowGroup:`tool:${e}`}}case`subagent.event`:{let e=t.kind,n=t.subagentId??`unknown`,r=t.name??n;switch(e){case`spawned`:return{id:oi(),kind:`agent:spawned`,timestamp:Date.now(),source:n,target:`session`,label:`${r} spawned`,magnitude:1,data:t,color:si.agent,flowGroup:`agent:${n}`};case`tool_executed`:{let e=t.toolName??`tool`,r=t.ok??!0;return{id:oi(),kind:`agent:tool`,timestamp:Date.now(),source:n,target:e,label:e,magnitude:t.durationMs??0,data:t,color:r?si.tool:si.error,flowGroup:`agent:${n}`}}case`task_completed`:{let e=t.status??`completed`;return{id:oi(),kind:`agent:status`,timestamp:Date.now(),source:n,target:`session`,label:`${r} ${e}`,magnitude:1,data:t,color:e===`success`?`hsl(140, 70%, 55%)`:si.error,flowGroup:`agent:${n}`}}case`ctx_pct`:return{id:oi(),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:si.agent,flowGroup:`agent:${n}`};case`iteration_summary`:return{id:oi(),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:si.agent,flowGroup:`agent:${n}`};case`budget_extended`:return{id:oi(),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:oi(),kind:a?`mailbox:send`:`mailbox:deliver`,timestamp:Date.now(),source:n,target:r,label:i||(a?`→ ${r}`:`← ${n}`),magnitude:1,data:t,color:si.mailbox,flowGroup:`mailbox`}}case`iteration.started`:{let e=t.index??0;return{id:oi(),kind:`iteration:start`,timestamp:Date.now(),source:`leader`,target:`session`,label:`Iteration ${e}`,magnitude:e,data:t,color:si.agent,flowGroup:`iteration`}}case`error`:{let e=t.message??`Error`;return{id:oi(),kind:`error`,timestamp:Date.now(),source:t.phase??`system`,target:`session`,label:e,magnitude:1,data:t,color:si.error,flowGroup:`error`}}case`context.compacted`:return{id:oi(),kind:`context:compacted`,timestamp:Date.now(),source:`system`,target:`session`,label:`Compacted: ${(t.saved??0).toLocaleString(`en-US`)} tokens`,magnitude:t.saved??0,data:t,color:`hsl(220, 60%, 50%)`,flowGroup:`context`};case`context.repaired`:return{id:oi(),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:oi(),kind:`session:start`,timestamp:Date.now(),source:`session`,target:`leader`,label:n||e.slice(0,12),magnitude:1,data:t,color:si.session,flowGroup:`session`}}case`sessions.status_update`:{let e=t.sessions??[];return{id:oi(),kind:`fleet:snapshot`,timestamp:Date.now(),source:`system`,target:`session`,label:`${e.length} session(s)`,magnitude:e.length,data:t,color:si.system,flowGroup:`fleet`}}default:return null}}function di(e){switch(e){case`tui`:return`tui`;case`cli`:case`repl`:return`repl`;case`webui`:return`webui`;default:return`webui`}}function fi(e){let t={tui:0,webui:0,repl:0},n=0,r=0,i={toolCalls:0,costUsd:0,tokensIn:0,tokensOut:0};for(let a of e){t[di(a.clientType)]+=1;for(let e of a.agents)n+=1,(e.status===`running`||e.status===`streaming`)&&(r+=1),i.toolCalls+=e.toolCalls??0,i.costUsd+=e.costUsd??0,i.tokensIn+=e.tokensIn??0,i.tokensOut+=e.tokensOut??0}return{clientCounts:t,totalAgents:n,activeAgents:r,aggregate:i}}var pi=0,mi=Je()(e=>({clientCounts:{tui:0,webui:0,repl:0},mailActivity:[],totalMessages:0,openMessages:0,unreadMessages:0,totalAgents:0,activeAgents:0,currentSession:{},liveSessions:[],aggregate:{toolCalls:0,costUsd:0,tokensIn:0,tokensOut:0},lastUpdated:Date.now(),setClientCounts:t=>e({clientCounts:t,lastUpdated:Date.now()}),setLiveSessions:t=>e({liveSessions:t,...fi(t),lastUpdated:Date.now()}),addMailActivity:t=>e(e=>({mailActivity:[{...t,seq:t.seq??++pi},...e.mailActivity].slice(0,50),lastUpdated:Date.now()})),setMailStats:(t,n,r)=>e({totalMessages:t,openMessages:n,unreadMessages:r,lastUpdated:Date.now()}),setAgentStats:(t,n)=>e({totalAgents:t,activeAgents:n,lastUpdated:Date.now()}),setCurrentSession:t=>e({currentSession:{...mi.getState().currentSession,...t},lastUpdated:Date.now()}),clear:()=>e({clientCounts:{tui:0,webui:0,repl:0},mailActivity:[],totalMessages:0,openMessages:0,unreadMessages:0,totalAgents:0,activeAgents:0,currentSession:{},liveSessions:[],aggregate:{toolCalls:0,costUsd:0,tokensIn:0,tokensOut:0},lastUpdated:Date.now()})}));function hi(e,t){return t>=100?`danger`:`warning`}function gi(e,t){switch(e){case`budget.threshold_reached`:{let e=t,n=e.limit>0?Math.round(e.used/e.limit*100):0;return`${e.subagentId} [${e.kind}] ${n}% (${e.used}/${e.limit})`}case`budget.decision`:{let e=t;return`${e.subagentId} [${e.kind}] → ${e.decision}`}case`consensus.vote_initiated`:{let e=t;return`Vote: "${e.title}" — ${e.eligible.length} voters`}case`consensus.vote_cast`:{let e=t;return`${e.voterId} voted ${e.value}`}case`consensus.vote_resolved`:{let e=t;return`${e.result} — ✅${e.approveCount} ❌${e.rejectCount}`}case`task.pending`:return`Task queued: "${t.description.slice(0,60)}"`;case`task.started`:{let e=t;return`${e.subagentId} started ${e.taskId}`}case`task.completed`:{let e=t;return`Task ${e.taskId} ${e.status} (${e.durationMs}ms)`}case`task.failed`:{let e=t;return`Task ${e.taskId} failed: ${e.error.slice(0,60)}`}case`subagent.budget_extended`:{let e=t;return`${e.subagentId} [${e.kind}] extended → ${e.extendedTo}ms`}default:return e}}var _i=200,vi=50,yi=300,bi=200,xi=100;function Si(e,t,n){if(!(e.size<=t)){if(n)for(let[r,i]of e){if(e.size<=t)break;n(i)&&e.delete(r)}for(let n of e.keys()){if(e.size<=t)break;e.delete(n)}}}var X=Je()(e=>({coordinatorStatus:`idle`,subagents:new Map,events:[],consensusVotes:new Map,tasks:new Map,taskCounts:{pending:0,running:0,completed:0,failed:0},budgetAlerts:[],lastUpdated:Date.now(),setCoordinatorStatus:(t,n)=>e(e=>({coordinatorStatus:t,coordinatorMode:n,lastUpdated:Date.now()})),updateCoordinatorStats:t=>e(e=>{let n=new Map(e.subagents);for(let e of t.subagentStatuses??[]){let t=n.get(e.id);n.set(e.id,{id:e.id,name:e.name,role:t?.role??`agent`,status:e.status,currentTask:e.currentTask,budgetLimits:t?.budgetLimits,budgetUsage:t?.budgetUsage,lastSeen:t?.lastSeen??Date.now()})}return Si(n,bi,e=>e.status===`stopped`),{subagents:n,taskCounts:{pending:t.pending,running:t.inFlight,completed:t.completed,failed:0},lastUpdated:Date.now()}}),updateSubagentBudget:(t,n)=>e(e=>{let r=new Map(e.subagents),i=r.get(t);return r.set(t,{id:t,name:i?.name??t,role:i?.role??`agent`,status:i?.status??`idle`,...i,...n,lastSeen:Date.now()}),Si(r,bi,e=>e.status===`stopped`),{subagents:r,lastUpdated:Date.now()}}),pushEvent:(t,n,r,i,a)=>e(e=>{let o=n.kind??t,s=(t.includes(`budget`)||t.includes(`threshold`))&&typeof n.limit==`number`&&n.limit>0?Math.round(n.used/n.limit*100):void 0,c=s===void 0?t.includes(`consensus.vote_resolved`)?`info`:t.includes(`consensus.vote_initiated`)?`warning`:`info`:s>=100?`danger`:s>=85?`warning`:`info`;return{events:[{id:`${r}-${t}`,ts:r,type:t,subagentId:i,taskId:a,payload:n,kind:o,level:c,message:gi(t,n)},...e.events].slice(0,_i),lastUpdated:Date.now()}}),pushConsensusVote:(t,n,r)=>e(e=>{let i=new Map(e.consensusVotes);return i.set(t,{changeId:t,title:n,status:`pending`,eligible:r,votes:[],approveCount:0,rejectCount:0,abstainCount:0,expiresAt:Date.now()+300*1e3}),Si(i,xi,e=>e.status!==`pending`),{consensusVotes:i,lastUpdated:Date.now()}}),recordConsensusVote:(t,n,r,i)=>e(e=>{let a=new Map(e.consensusVotes),o=a.get(t);if(!o)return{};let s={...o,votes:[...o.votes.filter(e=>e.agentId!==n),{agentId:n,agentName:r,value:i,votedAt:Date.now()}],approveCount:i===`approve`?o.approveCount+1:o.approveCount,rejectCount:i===`reject`?o.rejectCount+1:o.rejectCount,abstainCount:i===`abstain`?o.abstainCount+1:o.abstainCount};return a.set(t,s),{consensusVotes:a,lastUpdated:Date.now()}}),resolveConsensusVote:(t,n,r,i)=>e(e=>{let a=new Map(e.consensusVotes),o=a.get(t);return o?(a.set(t,{...o,status:n,approveCount:r,rejectCount:i,resolvedAt:Date.now()}),{consensusVotes:a,lastUpdated:Date.now()}):{}}),pushTaskPending:(t,n,r)=>e(e=>{let i=new Map(e.tasks);return i.set(t,{id:t,description:n,status:`pending`,priority:r,queuedAt:Date.now()}),Si(i,yi,e=>e.status===`completed`||e.status===`failed`),{tasks:i,taskCounts:{...e.taskCounts,pending:e.taskCounts.pending+1},lastUpdated:Date.now()}}),startTask:(t,n)=>e(e=>{let r=new Map(e.tasks),i=r.get(t);return i?r.set(t,{...i,status:`running`,subagentId:n,startedAt:Date.now()}):r.set(t,{id:t,description:``,status:`running`,subagentId:n,startedAt:Date.now()}),{tasks:r,taskCounts:{...e.taskCounts,pending:Math.max(0,e.taskCounts.pending-1),running:e.taskCounts.running+1},lastUpdated:Date.now()}}),completeTask:(t,n,r)=>e(e=>{let i=new Map(e.tasks),a=i.get(t);return a&&i.set(t,{...a,status:n,completedAt:Date.now(),durationMs:r}),Si(i,yi,e=>e.status===`completed`||e.status===`failed`),{tasks:i,taskCounts:{...e.taskCounts,running:Math.max(0,e.taskCounts.running-1),completed:n===`completed`?e.taskCounts.completed+1:e.taskCounts.completed,failed:n===`failed`?e.taskCounts.failed+1:e.taskCounts.failed},lastUpdated:Date.now()}}),failTask:(t,n)=>e(e=>{let r=new Map(e.tasks),i=r.get(t);return i&&r.set(t,{...i,status:`failed`,error:n,completedAt:Date.now()}),Si(r,yi,e=>e.status===`completed`||e.status===`failed`),{tasks:r,taskCounts:{...e.taskCounts,running:Math.max(0,e.taskCounts.running-1),failed:e.taskCounts.failed+1},lastUpdated:Date.now()}}),recordBudgetDecision:(t,n,r,i)=>e(e=>{let a=new Map(e.budgetAlerts.reduce((e,r)=>(r.subagentId===t&&r.kind===n||e.set(`${r.subagentId}:${r.kind}`,r),e),new Map)),o=`${t}:${n}`,s=a.get(o);return s&&a.set(o,{...s,decision:r,newLimit:i,level:r===`extend`?`warning`:`danger`}),{budgetAlerts:Array.from(a.values()),lastUpdated:Date.now()}}),recordBudgetAlert:(t,n,r,i)=>e(e=>{let a=`${Date.now()}-${t}-${n}`,o=i>0?Math.round(r/i*100):0;return{budgetAlerts:[{id:a,ts:Date.now(),subagentId:t,kind:n,level:hi(n,o),used:r,limit:i,pct:o},...e.budgetAlerts].slice(0,vi),lastUpdated:Date.now()}}),recordBudgetExtended:(t,n,r)=>e(e=>{let i=new Map(e.subagents),a=i.get(t);if(a&&a.budgetLimits){let e={...a.budgetLimits};n===`timeout`&&r&&(e.timeoutMs=r),n===`iterations`&&(e.maxIterations=r),n===`tool_calls`&&(e.maxToolCalls=r),i.set(t,{...a,budgetLimits:e,lastSeen:Date.now()})}return{subagents:i,lastUpdated:Date.now()}}),clear:()=>e({coordinatorStatus:`idle`,coordinatorMode:void 0,subagents:new Map,events:[],consensusVotes:new Map,tasks:new Map,taskCounts:{pending:0,running:0,completed:0,failed:0},budgetAlerts:[],lastUpdated:Date.now()})})),Ci=Je()(d(e=>({showHud:!0,showLegend:!0,showMinimap:!0,showControls:!0,animateEdges:!0,showFeed:!0,background:`dots`,setShowHud:t=>e({showHud:t}),setShowLegend:t=>e({showLegend:t}),setShowMinimap:t=>e({showMinimap:t}),setShowControls:t=>e({showControls:t}),setAnimateEdges:t=>e({animateEdges:t}),setShowFeed:t=>e({showFeed:t}),setBackground:t=>e({background:t})}),{name:`wrongstack-officemap`}));function Z(...e){return At(Fn(e))}var wi=t(((e,t)=>{t.exports={}}))(),Ti=8e3,Ei=Je(e=>({toasts:[],push:t=>{let n=`toast_${(0,wi.randomUUID)()}`;return e(e=>({toasts:[...e.toasts,{...t,id:n}]})),n},dismiss:t=>e(e=>({toasts:e.toasts.filter(e=>e.id!==t)}))})),Q={success:(e,t=3500)=>Ei.getState().push({message:e,variant:`success`,ttl:t}),error:(e,t=6e3)=>Ei.getState().push({message:e,variant:`error`,ttl:t}),warn:(e,t=4500)=>Ei.getState().push({message:e,variant:`warn`,ttl:t}),info:(e,t=3500)=>Ei.getState().push({message:e,variant:`info`,ttl:t}),undoable:(e,t,n=`Undo`,r=Ti)=>Ei.getState().push({message:e,variant:`info`,ttl:r,action:{label:n,onClick:t}}),dismiss:e=>Ei.getState().dismiss(e)};function Di({variant:e}){return e===`success`?(0,q.jsx)(ut,{className:`h-4 w-4 text-green-500`}):e===`error`?(0,q.jsx)(sn,{className:`h-4 w-4 text-destructive`}):e===`warn`?(0,q.jsx)(bn,{className:`h-4 w-4 text-amber-500`}):(0,q.jsx)(Fe,{className:`h-4 w-4 text-blue-500`})}function Oi({entry:e}){let t=Ei(e=>e.dismiss);return(0,V.useEffect)(()=>{let n=setTimeout(()=>t(e.id),e.ttl);return()=>clearTimeout(n)},[e.id,e.ttl,t]),(0,q.jsxs)(`div`,{className:Z(`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,q.jsx)(Di,{variant:e.variant}),(0,q.jsx)(`div`,{className:`flex-1 min-w-0 whitespace-pre-wrap break-words leading-snug`,children:e.message}),e.action&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>{e.action?.onClick(),t(e.id)},className:`shrink-0 font-medium text-primary hover:underline`,children:e.action.label}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>t(e.id),className:`text-muted-foreground hover:text-foreground`,title:`Dismiss`,children:(0,q.jsx)(Gt,{className:`h-3.5 w-3.5`})})]})}function ki(){let e=Ei(e=>e.toasts);return e.length===0?null:(0,q.jsx)(`div`,{className:`fixed bottom-4 right-4 z-[60] flex flex-col gap-2 pointer-events-auto`,children:e.map(e=>(0,q.jsx)(Oi,{entry:e},e.id))})}var Ai=null;function ji(){if(typeof window>`u`)return null;if(Ai)return Ai;let e=window.AudioContext||window.webkitAudioContext;if(!e)return null;try{Ai=new e}catch{return null}return Ai}function Mi(e,t,n){let r=ji();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 Ni(){Mi(659.25,0,.18),Mi(880,.12,.24)}function Pi(){Mi(523.25,0,.15),Mi(659.25,.1,.15),Mi(783.99,.2,.25)}var Fi=`default`;Fi=typeof window<`u`&&`Notification`in window?Notification.permission:`unsupported`;async function Ii(){if(Fi===`unsupported`||Fi===`granted`||Fi===`denied`)return Fi;try{let e=await Notification.requestPermission();return Fi=e,e}catch{return`denied`}}function Li(e,t,n){if(!(typeof document>`u`||!document.hidden)&&Fi===`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 Ri(e){typeof requestAnimationFrame==`function`?requestAnimationFrame(e):queueMicrotask(e)}var zi=new class{pending=new Map;scheduled=!1;push(e,t,n){if(!t)return;let r=this.pending.get(e);r?(r.buffer+=t,r.flush=n):this.pending.set(e,{buffer:t,flush:n}),this.schedule()}schedule(){this.scheduled||(this.scheduled=!0,Ri(()=>{this.scheduled=!1,this.drain()}))}drain(){if(this.pending.size===0)return;let e=Array.from(this.pending.entries());this.pending.clear();for(let[t,n]of e)n.buffer&&n.flush(t,n.buffer)}drop(e){this.pending.delete(e)}flush(e){let t=this.pending.get(e);t&&(this.pending.delete(e),t.buffer&&t.flush(e,t.buffer))}flushAll(){this.drain()}};function Bi(e){let t=ui(`session.start`,e.payload);t&&(li.getState().pushEvent(t),li.getState().setActive(!0));let n=e.payload,r=G.getState().session?.id,i=!r||r!==n.sessionId||n.reset;if(n.needsSetup&&K.getState().setCurrentView(`setup`),i?G.getState().startSession({id:n.sessionId,startedAt:Date.now(),model:n.model,provider:n.provider}):G.getState().setSession({id:n.sessionId,startedAt:G.getState().session?.startedAt??Date.now(),model:n.model,provider:n.provider}),G.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}),W.getState().setConfig({provider:n.provider,model:n.model}),i){U.getState().clearMessages(),U.getState().setLoading(!1),G.setState({todos:[]}),mr(`ready`);let e=J.getState();if(n.clearedSessionId){let t=new Map;for(let[r,i]of e.agents)i.sessionId!==n.clearedSessionId&&t.set(r,i);J.setState({agents:t})}else e.clear();Y.getState().setTreeLoading(!0),H().send({type:`files.tree`,payload:{path:G.getState().cwd}})}let a=n.replayMessages;if(a&&a.length>0){let e=U.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?`
|
|
15
|
-
`:``)+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=U.getState().messages,n;for(let e=t.length-1;e>=0;e--)if(t[e]?.toolUseId===String(i.tool_use_id??``)){n=B(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=G.getState(),n=e.input??0,r=e.output??0,i=e.cacheRead??0,a=e.cacheWrite??0;G.setState({totalTokens:{input:n,output:r,cacheRead:i,cacheWrite:a},cost:(n*t.inputCost+r*t.outputCost+i*t.cacheReadCost)/1e6})}K.getState().currentView!==`chat`&&K.getState().setCurrentView(`chat`),typeof window<`u`&&window.matchMedia?.(`(max-width: 768px)`).matches&&K.getState().setSidebarOpen(!1)}}function Vi(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);U.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(`
|
|
16
|
-
`)})}function Hi(e){let t=e.payload;t.success?Q.success(t.message):Q.error(t.message),H(W.getState().wsUrl).listSavedProviders()}function Ui(e){ga(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`),U.getState().addMessage({role:`assistant`,content:`🗜️ Context compacted: ${t.before} → ${t.after} tokens (saved ~${t.saved}). ${n}`}),G.setState({lastInputTokens:t.after})}function Wi(e){ga(e);let t=e.payload,n=t.usage,r=(n.input??0)+(n.cacheWrite??0)-(n.cacheRead??0);r>0&&G.setState({lastInputTokens:r}),G.getState().updateUsage(t.usage);let{inputCost:i,outputCost:a,cacheReadCost:o}=G.getState(),s=(t.usage.input*i+t.usage.output*a+(t.usage.cacheRead??0)*o)/1e6;s>0&&G.getState().addCost(s),t.stopReason!==`tool_use`&&t.stopReason!==`tool_call`&&U.getState().setLoading(!1);let c=U.getState().currentAssistantMessageId;c&&(zi.flush(c),U.getState().finalizeMessage(c),t.usage.output>0&&U.getState().updateMessage(c,{usage:t.usage})),U.getState().setCurrentAssistantMessage(null),U.getState().clearThinking()}function Gi(e){ga(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}.`:``;U.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 Ki(){W.getState().setWsConnected(!1)}function qi(e){ga(e);let t=e.payload;G.getState().setIteration({index:t.index,max:t.maxIterations??0}),U.getState().setLoading(!0),typeof document<`u`&&document.hidden&&mr(`running`),U.getState().runStart===null&&U.getState().setRunStart({at:Date.now(),cost:G.getState().cost}),U.getState().setCurrentAssistantMessage(null)}function Ji(e){ga(e);let t=e.payload;U.getState().clearThinking(),zi.drop(`__thinking__`);let n=U.getState().currentAssistantMessageId;n||(n=U.getState().addMessage({role:`assistant`,content:``,streaming:!0}),U.getState().setCurrentAssistantMessage(n)),zi.push(n,t.text,(e,t)=>U.getState().appendToMessage(e,t))}function Yi(e){ga(e);let t=e.payload;t.text&&zi.push(`__thinking__`,t.text,(e,t)=>U.getState().appendThinking(t))}function Xi(e){ga(e);let t=e.payload,n=U.getState().messages.find(e=>e.toolUseId===t.id);if(n){U.getState().setCurrentToolId(n.id);return}U.getState().clearThinking(),zi.drop(`__thinking__`),U.getState().setCurrentAssistantMessage(null);let r=U.getState().addMessage({role:`tool`,content:``,toolName:t.name,toolInput:t.input,toolUseId:t.id});U.getState().setCurrentToolId(r),U.getState().addExecution({id:t.id,name:t.name,input:t.input,ok:!0,startedAt:Date.now()})}function Zi(e){let t=e.payload,n=(t.event?.text??``).trim();if(!n)return;let r=U.getState().messages.find(e=>e.toolUseId===t.id);if(!r)return;let i=t.event?.type===`warning`?`⚠ `:``;zi.push(r.id,`${i}${n}\n`,(e,t)=>U.getState().appendToolProgressLines(e,t.split(`
|
|
17
|
-
`).filter(e=>e.length>0)))}function Qi(e){ga(e);let t=e.payload,{messages:n,currentToolId:r}=U.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&&(zi.drop(i.id),U.getState().setToolResult(i.id,t.output??``,t.ok),U.getState().updateMessage(i.id,{toolDurationMs:t.durationMs})),t.id&&U.getState().updateExecution(t.id,{completedAt:Date.now(),durationMs:t.durationMs,output:t.output,ok:t.ok}),r&&i&&i.id===r&&U.getState().setCurrentToolId(null))}function $i(e){let t=e.payload;K.getState().showConfirm({id:t.id,toolName:t.toolName,input:t.input,suggestedPattern:t.suggestedPattern});try{Pi()}catch{}Ii(),Li(`${G.getState().projectName||`Agent`} needs approval`,`Tool "${t.toolName}" is waiting for your decision.`,`agent-confirm`),typeof document<`u`&&document.hidden&&mr(`attention`)}function ea(e){let t=e.payload;zi.flushAll(),G.getState().setIteration(null),U.getState().setLoading(!1),U.getState().setCurrentAssistantMessage(null),U.getState().clearThinking();let n=U.getState().runStart;if(n&&t.status===`done`){let e=U.getState().messages,r=-1,i=0;for(let t=e.length-1;t>=0;t--){let a=B(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=G.getState().cost;U.getState().updateMessage(e[r]?.id,{runSummary:{iterations:t.iterations,tools:i,durationMs:Date.now()-n.at,costDelta:Math.max(0,a-n.cost)}})}}if(U.getState().setRunStart(null),t.status!==`done`&&t.error)U.getState().addMessage({role:`assistant`,content:`Error: ${t.error.message}`,isError:!0}),Q.error(`Run ended: ${t.error.message}`),Li(`${G.getState().projectName||`Agent`} run failed`,t.error.message),typeof document<`u`&&document.hidden&&mr(`error`);else if(t.status===`done`&&(typeof document<`u`&&document.hidden&&(Q.success(`Run completed in ${t.iterations} iteration${t.iterations===1?``:`s`}`),Li(`${G.getState().projectName||`Agent`} run finished`,`Completed in ${t.iterations} iteration${t.iterations===1?``:`s`}.`),mr(`ready`)),Ii(),W.getState().soundOnComplete))try{Ni()}catch{}let r=U.getState().dequeue();if(r){let e=H(W.getState().wsUrl);U.getState().addMessage({role:`user`,content:r}),U.getState().setLoading(!0),e.sendMessage(r)}}function ta(e){let t=e.payload;U.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(`
|
|
18
|
-
`)})}function na(e){let t=e.payload,n=t.text?.trim();U.getState().addMessage({role:`assistant`,content:t.error?`Memory read failed: ${t.error}`:n?`🧠 **Memory** \n\n${n}`:`🧠 **Memory**
|
|
19
|
-
|
|
20
|
-
_empty — nothing remembered yet_`})}function ra(e){let t=e.payload;if(!t.enabled){U.getState().addMessage({role:`assistant`,content:`🎯 **Skills**
|
|
21
|
-
|
|
22
|
-
_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}`),U.getState().addMessage({role:`assistant`,content:n.join(`
|
|
23
|
-
`)})}function ia(e){let t=e.payload;U.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(`
|
|
24
|
-
`)})}function aa(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`;U.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(`
|
|
25
|
-
`)})}function oa(e){let t=e.payload;G.getState().setTodos(t.todos??[])}function sa(e){let t=e.payload;G.getState().setModes(t.modes.map(e=>({id:e.id,name:e.name,description:e.description}))),G.getState().setEnv({mode:t.activeId})}function ca(e){let t=e.payload;G.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}))),G.getState().setEnv({contextMode:t.activeId})}function la(e){let t=e.payload;G.getState().setEnv({contextMode:t.id})}function ua(e){let t=e.payload;Nr.getState().setEntries(t.sessions??[],t.error??null)}function da(e){let t=e.payload;U.getState().addMessage({role:`assistant`,content:`[${t.phase}] ${t.message}`,isError:!0}),U.getState().setLoading(!1)}function fa(e){let t=e.payload;Pr.getState().setSnapshot(t.worktrees??[],t.baseBranch??``)}function pa(e){let t=e.payload;Pr.getState().pushEvent(t)}function ma(e){J.getState().applyEvent(e.payload);let t=ui(`subagent.event`,e.payload);t&&(li.getState().pushEvent(t),li.getState().setActive(!0))}function ha(e){let t=e.payload;J.setState({fleetConcurrency:t.fleetConcurrency,fleetConcurrencyMax:t.fleetConcurrencyMax})}function ga(e){let t=ui(e.type,e.payload);return t&&(li.getState().pushEvent(t),li.getState().setActive(!0)),e}function _a(e){let t=e.payload;ei.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 va(e){let t=e.payload;$r.getState().setGoal(t)}function ya(e){let t=e.payload;ni.getState().set(t)}function ba(e){let t=e.payload;if(t.error){Y.getState().setError(t.error);return}Y.getState().setTree(t.root,t.tree)}function xa(e){let t=e.payload;if(t.error){Y.getState().setError(t.error);return}Y.getState().openFile(t.filePath,t.content)}function Sa(e){let t=e.payload;t.success?Y.getState().markSaved(t.filePath):t.error&&Y.getState().setError(`Save failed: ${t.error}`)}function Ca(){let e=H();e?.send?.({type:`mailbox.messages`,payload:{limit:30,incompleteOnly:!0}}),e?.send?.({type:`mailbox.agents`,payload:{}})}var wa={"session.start":e=>{Bi(e),Ca()},"context.debug":Vi,"key.operation_result":Hi,"context.compacted":Ui,"provider.response":Wi,"context.repaired":Gi,"session.end":Ki,"iteration.started":qi,"provider.text_delta":Ji,"provider.thinking_delta":Yi,"tool.started":Xi,"tool.progress":Zi,"tool.executed":Qi,"tool.confirm_needed":$i,"run.result":ea,"tools.list":ta,"memory.list":na,"skills.list":ra,"diag.get":ia,"stats.get":aa,"todos.updated":oa,"tasks.updated":e=>{},"plan.updated":e=>{},"modes.list":sa,"context.modes.list":ca,"context.mode.changed":la,"sessions.list":ua,error:da,"worktree.state":fa,"worktree.event":pa,"subagent.event":ma,"fleet.concurrency_update":ha,"goal.updated":va,"prefs.updated":ya,"client.status_update":e=>{let t=e.payload;mi.getState().setCurrentSession({clientType:t.clientType,clientId:t.clientId,agentCount:t.agentCount,model:t.model,mode:t.mode,toolCalls:t.toolCalls,inputTokens:t.inputTokens,outputTokens:t.outputTokens,cacheTokens:t.cacheTokens,costUsd:t.costUsd,timestamp:t.timestamp})},"sessions.status_update":e=>{let t=e.payload;mi.getState().setLiveSessions(t?.sessions??[]);let n=ui(`sessions.status_update`,e.payload);n&&(li.getState().pushEvent(n),li.getState().setActive(!0))},"files.tree":ba,"files.read":xa,"files.written":Sa,"autophase.state":_a,"session.checkpoints":e=>{},"process.list":e=>{},"projects.list":e=>{},"projects.added":e=>{},"projects.selected":e=>{},"mailbox.event":e=>{let t=ui(`mailbox.event`,e.payload);t&&(li.getState().pushEvent(t),li.getState().setActive(!0)),Ca()},"mailbox.messages":e=>{let t=e.payload;t?.messages&&Ar.getState().setMessages(t.messages)},"mailbox.agents":e=>{let t=e.payload;t?.agents&&Ar.getState().setAgents(t.agents)},"mailbox.cleared":e=>{Ar.getState().setMessages([]),Ca()},"mailbox.purged":e=>{Ca()},"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}_`:``}`)}}U.getState().addMessage({role:`assistant`,content:n.join(`
|
|
26
|
-
`)})},"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.`;U.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.`;U.getState().addMessage({role:`assistant`,content:[n,t.request?.question??``,e?`_${e}_`:``].filter(Boolean).join(`
|
|
27
|
-
|
|
28
|
-
`)}),t.intervened&&Q.info(`Brain intervened: agent steered`)}else t.event===`brain.decision_denied`&&Q.warn(`Brain denied: ${t.decision?.reason??t.request?.question??`request`}`)},"working_dir.changed":e=>{let t=e.payload;G.getState().setEnv({cwd:t.cwd,projectRoot:t.projectRoot,projectName:t.projectRoot.split(/[/\\]/).pop()||t.projectRoot}),Y.getState().setTreeLoading(!0),H().send({type:`files.tree`,payload:{path:t.cwd}})},"model.refine_result":e=>{let t=e.payload,n=K.getState().refinePanel;if(!n)return;if(t.error){Q.error(`Refinement failed: ${t.error}`);let{original:e}=n;K.getState().setRefinePanel(null),U.getState().addMessage({role:`user`,content:e}),U.getState().setLoading(!0),H().send({type:`user_message`,payload:{id:`msg_${Date.now()}`,content:e,timestamp:Date.now()}});return}let r=n.original;if(sr(t.refined,r)){K.getState().setRefinePanel(null),U.getState().addMessage({role:`user`,content:r}),U.getState().setLoading(!0),H().send({type:`user_message`,payload:{id:`msg_${Date.now()}`,content:r,timestamp:Date.now()}});return}K.getState().setRefinePanel({...n,refined:t.refined,english:t.english})},"git.info":e=>{let t=e.payload;Mr.getState().setInfo({...t,fetchedAt:Date.now()})},"coordinator.status":e=>{let t=e.payload;X.getState().setCoordinatorStatus(t.status,t.mode),t.taskQueue&&X.getState().updateCoordinatorStats({total:t.subagentCount??0,running:0,idle:0,stopped:0,inFlight:t.taskQueue.running,pending:t.taskQueue.pending,completed:t.taskQueue.completed})},"coordinator.stats":e=>{let t=e.payload;X.getState().updateCoordinatorStats(t)},"budget.threshold_reached":e=>{let t=e.payload;X.getState().pushEvent(`budget.threshold_reached`,t,t.ts??Date.now(),t.subagentId,t.taskId),t.limit>0&&t.used/t.limit*100>=85&&X.getState().recordBudgetAlert(t.subagentId,t.kind,t.used,t.limit),X.getState().updateSubagentBudget(t.subagentId,{budgetUsage:{iterations:0,toolCalls:0,tokens:0,costUsd:0,elapsedMs:t.used??0}})},"budget.decision":e=>{let t=e.payload,n=t.extended?.timeoutMs??t.extended?.maxIterations??t.extended?.maxToolCalls;X.getState().recordBudgetDecision(t.subagentId,t.kind,t.decision,n),X.getState().pushEvent(`budget.decision`,{subagentId:t.subagentId,kind:t.kind,decision:t.decision,newLimit:n},Date.now(),t.subagentId)},"subagent.budget_extended":e=>{let t=e.payload;X.getState().recordBudgetExtended(t.subagentId,t.kind,t.extendedTo),X.getState().pushEvent(`subagent.budget_extended`,t,Date.now(),t.subagentId)},"consensus.vote_initiated":e=>{let t=e.payload;X.getState().pushConsensusVote(t.changeId,t.title,t.eligible),X.getState().pushEvent(`consensus.vote_initiated`,t,Date.now()),Q.info(`Vote started: `+t.title)},"consensus.vote_cast":e=>{let t=e.payload,n=X.getState().consensusVotes.get(t.changeId)?.eligible.find(e=>e.agentId===t.voterId);X.getState().recordConsensusVote(t.changeId,t.voterId,n?.agentName??t.voterId,t.value),X.getState().pushEvent(`consensus.vote_cast`,t,Date.now(),t.voterId)},"consensus.vote_resolved":e=>{let t=e.payload;X.getState().resolveConsensusVote(t.changeId,t.result,t.approveCount,t.rejectCount),X.getState().pushEvent(`consensus.vote_resolved`,t,Date.now()),Q.info(`Vote resolved: `+t.result+` (y`+t.approveCount+` n`+t.rejectCount+`)`)},"task.pending":e=>{let t=e.payload;X.getState().pushTaskPending(t.taskId,t.description,t.priority),X.getState().pushEvent(`task.pending`,t,Date.now())},"task.started":e=>{let t=e.payload;X.getState().startTask(t.taskId,t.subagentId),X.getState().pushEvent(`task.started`,t,Date.now(),t.subagentId)},"task.completed":e=>{let t=e.payload;X.getState().completeTask(t.taskId,t.status,t.durationMs),X.getState().pushEvent(`task.completed`,t,Date.now(),t.subagentId)},"task.failed":e=>{let t=e.payload;X.getState().failTask(t.taskId,t.error),X.getState().pushEvent(`task.failed`,{taskId:t.taskId,subagentId:t.subagentId,error:String(t.error).slice(0,120)},Date.now(),t.subagentId),Q.error(`Task failed: `+String(t.error).slice(0,80))}};function Ta(e){let t=[];for(let[n,r]of Object.entries(wa))t.push(e.on(n,r));return()=>{for(let e of t)e()}}function Ea(){let{autoConnect:e,wsUrl:t}=W(),n=W(e=>e.setWsStatus),r=(0,V.useRef)(!1);(0,V.useEffect)(()=>{if(!e)return;gr();let i=H(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=Ta(i);return()=>{a=!0,s(),o()}},[e,t,n])}function Da(){let{wsUrl:e}=W(),t=H(e),n=(0,V.useCallback)((e,n)=>t.isConnected?t.sendMessage(e,n):null,[t]),r=(0,V.useCallback)(()=>t.sendAbort(),[t]),{hideConfirm:i}=K(),a=(0,V.useCallback)((e,n)=>{t.sendConfirm(e,n),i()},[t,i]),o=(0,V.useCallback)((e,n)=>t.switchModel(e,n),[t]),s=(0,V.useCallback)(()=>t.listProviders(),[t]),c=(0,V.useCallback)(e=>t.listProviderModels(e),[t]),l=(0,V.useCallback)(()=>t.listSavedProviders(),[t]),u=(0,V.useCallback)((e,n,r)=>t.addKey(e,n,r),[t]),d=(0,V.useCallback)((e,n,r)=>t.updateKey(e,n,r),[t]),f=(0,V.useCallback)((e,n)=>t.deleteKey(e,n),[t]),p=(0,V.useCallback)((e,n)=>t.setActiveKey(e,n),[t]),m=(0,V.useCallback)((e,n,r,i)=>t.addProvider(e,n,r,i),[t]),h=(0,V.useCallback)(e=>t.removeProvider(e),[t]),g=(0,V.useCallback)(e=>{Nr.getState().setLoading(!0),t.listSessions(e)},[t]),_=(0,V.useCallback)(e=>{Nr.getState().removeEntry(e),t.deleteSession(e)},[t]),v=(0,V.useCallback)(e=>t.resumeSessionById(e),[t]),y=(0,V.useCallback)(()=>t.saveSession(),[t]),b=(0,V.useCallback)(()=>t.listTools(),[t]),x=(0,V.useCallback)(()=>t.listMemory(),[t]),S=(0,V.useCallback)(()=>t.listSkills(),[t]),C=(0,V.useCallback)(()=>t.getDiag(),[t]),w=(0,V.useCallback)(()=>t.getStats(),[t]),T=(0,V.useCallback)(()=>t.getPlan(),[t]),E=(0,V.useCallback)(()=>t.listModes(),[t]),D=(0,V.useCallback)(e=>t.switchMode(e),[t]),O=(0,V.useCallback)(()=>t.listContextModes(),[t]),k=(0,V.useCallback)(e=>t.switchContextMode(e),[t]),A=(0,V.useCallback)(e=>t.createContextMode(e),[t]),ee=(0,V.useCallback)((e,n)=>t.updateContextMode(e,n),[t]),j=(0,V.useCallback)(e=>t.deleteContextMode(e),[t]),M=(0,V.useCallback)(()=>t.repairContext(),[t]),N=(0,V.useCallback)(e=>t.refineModel(e),[t]),P=(0,V.useCallback)(e=>t.switchAutonomy(e),[t]),F=(0,V.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:ee,deleteContextMode:j,repairContext:M,toggleAutoPhaseAutonomous:(0,V.useCallback)(e=>{t.send({type:`autophase.toggleAutonomous`,payload:{autonomous:e}})},[t]),startAutoPhase:(0,V.useCallback)((e,n,r=!0)=>{t.send({type:`autophase.start`,payload:{title:e,phases:n,autonomous:r}})},[t]),pauseAutoPhase:(0,V.useCallback)(()=>{t.send({type:`autophase.pause`,payload:{}})},[t]),resumeAutoPhase:(0,V.useCallback)(()=>{t.send({type:`autophase.resume`,payload:{}})},[t]),stopAutoPhase:(0,V.useCallback)(()=>{t.send({type:`autophase.stop`,payload:{}})},[t]),selectAutoPhase:(0,V.useCallback)(e=>{t.send({type:`autophase.selectPhase`,payload:{phaseId:e}})},[t]),switchAutonomy:P,updatePrefs:F,refineModel:N}}var Oa=(0,V.createContext)(void 0);function ka({children:e,defaultTheme:t=`system`,storageKey:n=`wrongstack-theme`}){let{setTheme:r}=W(),[i,a]=(0,V.useState)(()=>typeof window<`u`&&localStorage.getItem(n)||t);(0,V.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,q.jsx)(Oa.Provider,{value:o,children:e})}function Aa(){let e=(0,V.useContext)(Oa);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e}var ja=[`chat`,`files`,`skill`,`officemap`],Ma=[{id:`chat`,icon:(0,q.jsx)(pt,{size:16}),label:`Session`,shortcut:`Ctrl+1`,pairedView:`chat`},{id:`agents`,icon:(0,q.jsx)(Qt,{size:16}),label:`Agents`,shortcut:`Ctrl+2`},{id:`history`,icon:(0,q.jsx)(Et,{size:16}),label:`History`,shortcut:`Ctrl+3`},{id:`files`,icon:(0,q.jsx)(E,{size:16}),label:`Files`,shortcut:`Ctrl+4`,pairedView:`files`},{id:`projects`,icon:(0,q.jsx)(qt,{size:16}),label:`Projects`,shortcut:`Ctrl+5`},{id:`mailbox`,icon:(0,q.jsx)(xt,{size:16}),label:`Mailbox`,shortcut:`Ctrl+6`},{id:`skills`,icon:(0,q.jsx)(qn,{size:16}),label:`Skills`,shortcut:`Ctrl+7`,pairedView:`skill`},{id:`officemap`,icon:(0,q.jsx)(y,{size:16}),label:`Office Map`,shortcut:`Ctrl+8`,pairedView:`officemap`}],Na=[{id:`autophase`,icon:(0,q.jsx)(ue,{size:16}),label:`Phases`},{id:`settings`,icon:(0,q.jsx)(c,{size:16}),label:`Settings`}];function Pa(e){let t=K.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=Ma.find(t=>t.id===e)?.pairedView;n?t.currentView!==n&&t.setCurrentView(n):ja.includes(t.currentView)&&t.currentView!==`chat`&&t.setCurrentView(`chat`)}var Fa=Ma.map(e=>e.id);function Ia(){let e=K(e=>e.activeActivity),t=K(e=>e.sidebarOpen),n=K(e=>e.currentView),r=K(e=>e.setCurrentView),i=G(e=>e.projectName),a=G(e=>e.cwd),o=W(e=>e.wsConnected),s=J(e=>Array.from(e.agents.values()).filter(e=>e.status===`running`).length),c=Ar(jr),l=K(e=>e.inspectorOpen),u=K(e=>e.inspectorTab),d=e=>{if(e===`agents`)return s||void 0;if(e===`mailbox`)return c||void 0};return(0,q.jsxs)(`div`,{className:`flex flex-col h-full w-12 shrink-0 border-r bg-card/60`,children:[(0,q.jsxs)(`div`,{className:`flex flex-col items-center pt-2.5 pb-2 border-b border-border/50`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>{K.getState().setSidebarOpen(!0),K.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,q.jsx)(Dn,{className:`h-4 w-4 text-primary-foreground`,strokeWidth:2.4})}),(0,q.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,q.jsx)(`span`,{className:Z(`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,q.jsx)(`div`,{className:`flex flex-col items-center gap-0.5 pt-2`,children:Ma.map(n=>(0,q.jsx)(Ra,{icon:n.icon,label:`${n.label} (${n.shortcut})`,active:t&&e===n.id,badge:d(n.id),onClick:()=>Pa(n.id)},n.id))}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-0.5 pb-2 border-b border-border/50 mb-2`,children:[(0,q.jsx)(Ra,{icon:(0,q.jsx)(nn,{size:16}),label:`Command palette (Ctrl+K)`,active:!1,onClick:()=>K.getState().setPaletteOpen(!0)}),(0,q.jsx)(La,{}),(0,q.jsx)(Ra,{icon:(0,q.jsx)($n,{size:16}),label:`Keyboard shortcuts (?)`,active:!1,onClick:()=>K.getState().setShortcutsOpen(!0)}),(0,q.jsx)(Ra,{icon:(0,q.jsx)(lt,{size:16}),label:`Fleet Monitor (Ctrl+Shift+M)`,active:l&&u===`fleet`,onClick:()=>{let e=K.getState();e.inspectorOpen&&e.inspectorTab===`fleet`?e.setInspectorOpen(!1):(e.setInspectorTab(`fleet`),e.setInspectorOpen(!0))}}),(0,q.jsx)(Ra,{icon:(0,q.jsx)(ir,{size:16}),label:`Agents Monitor (Ctrl+Shift+A)`,active:l&&u===`agents`,onClick:()=>{let e=K.getState();e.inspectorOpen&&e.inspectorTab===`agents`?e.setInspectorOpen(!1):(e.setInspectorTab(`agents`),e.setInspectorOpen(!0))}})]}),(0,q.jsx)(`div`,{className:`flex flex-col items-center gap-0.5 pb-2`,children:Na.map(e=>(0,q.jsx)(Ra,{icon:e.icon,label:e.label,active:n===e.id,onClick:()=>r(n===e.id?`chat`:e.id)},e.id))})]})}function La(){let{theme:e,setTheme:t}=Aa(),n=e===`light`?`dark`:e===`dark`?`system`:`light`;return(0,q.jsx)(Ra,{icon:e===`light`?(0,q.jsx)(yt,{size:16}):e===`dark`?(0,q.jsx)(Nn,{size:16}):(0,q.jsx)(un,{size:16}),label:`Theme: ${e} — click for ${n}`,active:!1,onClick:()=>t(n)})}function Ra({icon:e,label:t,active:n,badge:r,onClick:i}){return(0,q.jsxs)(`button`,{type:`button`,onClick:i,title:t,className:Z(`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,q.jsx)(`span`,{className:`absolute left-0 top-1/2 -translate-y-1/2 w-0.5 h-6 rounded-r-full bg-primary`}),(0,q.jsx)(`span`,{className:`h-5 w-5`,children:e}),r!==void 0&&r>0&&(0,q.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})]})}var za={pending:{icon:(0,q.jsx)(yn,{className:`w-4 h-4`}),color:`text-slate-400`,bg:`bg-slate-100 dark:bg-slate-800`,label:`Pending`},ready:{icon:(0,q.jsx)(P,{className:`w-4 h-4`}),color:`text-blue-500`,bg:`bg-blue-50 dark:bg-blue-950`,label:`Ready`},running:{icon:(0,q.jsx)(Et,{className:`w-4 h-4 animate-spin`,"aria-label":`Running`}),color:`text-amber-500`,bg:`bg-amber-50 dark:bg-amber-950`,label:`Running`},paused:{icon:(0,q.jsx)(Cn,{className:`w-4 h-4`}),color:`text-orange-500`,bg:`bg-orange-50 dark:bg-orange-950`,label:`Paused`},completed:{icon:(0,q.jsx)(ut,{className:`w-4 h-4`}),color:`text-emerald-500`,bg:`bg-emerald-50 dark:bg-emerald-950`,label:`Completed`},failed:{icon:(0,q.jsx)(sn,{className:`w-4 h-4`}),color:`text-red-500`,bg:`bg-red-50 dark:bg-red-950`,label:`Failed`},skipped:{icon:(0,q.jsx)(w,{className:`w-4 h-4`}),color:`text-slate-400`,bg:`bg-slate-100 dark:bg-slate-800`,label:`Skipped`}},Ba={critical:`bg-red-500`,high:`bg-orange-500`,medium:`bg-blue-500`,low:`bg-slate-400`};function Va(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 Ha({phases:e,activePhaseId:t,onPhaseClick:n,overallPercent:r,autonomous:i,onToggleAutonomous:a,className:o}){return(0,q.jsxs)(`div`,{className:Z(`flex flex-col h-full border-r border-border bg-card`,o),children:[(0,q.jsxs)(`div`,{className:`p-4 border-b border-border`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,q.jsx)(`h2`,{className:`text-sm font-semibold text-foreground`,children:`Phases`}),(0,q.jsx)(`button`,{type:`button`,onClick:a,className:Z(`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 — click to pause`:`Manual mode — click to enable autonomous`,children:i?`● Autonomous`:`○ Manual`})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between text-xs text-muted-foreground`,children:[(0,q.jsx)(`span`,{children:`Overall Progress`}),(0,q.jsxs)(`span`,{children:[r,`%`]})]}),(0,q.jsx)(`div`,{className:`h-2 bg-muted rounded-full overflow-hidden`,children:(0,q.jsx)(`div`,{className:`h-full bg-emerald-500 transition-all duration-500 rounded-full`,style:{width:`${r}%`}})})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3 space-y-2`,children:e.map(e=>{let r=za[e.status];return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n?.(e.id),className:Z(`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,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(`span`,{className:Z(`mt-0.5`,r.color),children:r.icon}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`div`,{className:Z(`w-1.5 h-1.5 rounded-full`,Ba[e.priority])}),(0,q.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e.name})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground truncate mt-0.5`,children:e.description})]})]}),(0,q.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between text-xs`,children:[(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.completedTasks,`/`,e.taskCount,` tasks`]}),(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.progressPercent,`%`]})]}),(0,q.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,q.jsx)(`div`,{className:Z(`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,q.jsxs)(`div`,{className:`flex items-center gap-2 mt-2 text-xs text-muted-foreground`,children:[(0,q.jsxs)(`span`,{children:[`~`,e.estimateHours,`h`]}),e.actualDurationMs&&(0,q.jsxs)(`span`,{children:[`· `,Va(e.actualDurationMs)]}),e.assignedAgents.length>0&&(0,q.jsxs)(`span`,{children:[`· `,e.assignedAgents.length,` agent`,e.assignedAgents.length===1?``:`s`]})]})]},e.id)})})]})}var Ua={pending:{icon:(0,q.jsx)(yn,{className:`w-4 h-4`}),color:`text-muted-foreground`,label:`Pending`},in_progress:{icon:(0,q.jsx)(Et,{className:`w-4 h-4 animate-spin`,"aria-label":`In Progress`}),color:`text-primary`,label:`In Progress`},blocked:{icon:(0,q.jsx)(Cn,{className:`w-4 h-4`}),color:`text-[hsl(var(--warning))]`,label:`Blocked`},failed:{icon:(0,q.jsx)(sn,{className:`w-4 h-4`}),color:`text-destructive`,label:`Failed`},review:{icon:(0,q.jsx)(L,{className:`w-4 h-4`}),color:`text-[hsl(var(--info))]`,label:`Review`},completed:{icon:(0,q.jsx)(ut,{className:`w-4 h-4`}),color:`text-[hsl(var(--success))]`,label:`Done`}},Wa={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`},Ga={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 Ka(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 qa({phaseName:e,phaseStatus:t,tasks:n,onTaskStatusChange:r,className:i}){let a={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,q.jsxs)(`div`,{className:Z(`flex flex-col h-full bg-background`,i),children:[(0,q.jsx)(`div`,{className:`p-4 border-b border-border`,children:(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h2`,{className:`text-lg font-semibold text-foreground`,children:e}),(0,q.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:[n.length,` tasks · `,n.filter(e=>e.status===`completed`).length,` completed`]})]}),(0,q.jsx)(`div`,{className:Z(`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,q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-6`,children:[`in_progress`,`pending`,`review`,`failed`,`completed`].map(e=>{let t=a[e];if(t.length===0)return null;let n={in_progress:`In Progress`,pending:`Pending`,review:`Review`,failed:`Failed`,completed:`Completed`}[e];return(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-2`,children:[n,` (`,t.length,`)`]}),(0,q.jsx)(`div`,{className:`space-y-2`,children:t.map(e=>{let t=Ua[e.status];return(0,q.jsxs)(`button`,{type:`button`,className:Z(`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,q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,q.jsx)(`span`,{className:Z(`mt-0.5`,t.color),children:t.icon}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium`,children:e.title}),(0,q.jsx)(`span`,{className:Z(`px-1.5 py-0.5 rounded text-[10px] font-medium`,Wa[e.priority]),children:e.priority}),(0,q.jsx)(`span`,{className:Z(`px-1.5 py-0.5 rounded text-[10px] font-medium`,Ga[e.type]),children:e.type})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 line-clamp-2`,children:e.description})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mt-2 text-xs text-muted-foreground`,children:[e.estimateHours&&(0,q.jsxs)(`span`,{children:[`~`,e.estimateHours,`h`]}),e.actualHours&&(0,q.jsxs)(`span`,{children:[`• `,e.actualHours,`h`]}),e.assignee&&(0,q.jsxs)(`span`,{children:[`• `,e.assignee]}),e.startedAt&&(0,q.jsxs)(`span`,{children:[`• `,Ka(Date.now()-e.startedAt)]})]}),e.tags.length>0&&(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:e.tags.map(e=>(0,q.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] bg-muted text-muted-foreground`,children:e},e))}),r&&e.status!==`completed`&&(0,q.jsxs)(`div`,{className:`flex gap-1 mt-2`,children:[e.status!==`in_progress`&&(0,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(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,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(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,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(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 Ja=[`#3b82f6`,`#06b6d4`,`#22c55e`,`#eab308`,`#f97316`,`#a855f7`,`#ec4899`],Ya=e=>e.replace(/^wstack\/ap\//,``);function Xa(e){return[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt).map((e,t)=>({handle:e,color:Ja[t%Ja.length],y:60+t*48}))}var Za={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 Qa({worktrees:e,baseBranch:t}){let n=Xa(e),r=Math.max(120,60+n.length*48+20);return(0,q.jsx)(`div`,{className:`overflow-x-auto rounded-lg border border-[--color-border-dark] bg-[--color-card-dark]/40 p-3`,children:(0,q.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,q.jsx)(`title`,{children:`Worktree branch graph off ${t||`HEAD`}`}),(0,q.jsx)(`line`,{x1:40,y1:20,x2:40,y2:r-10,stroke:`#F93951`,strokeWidth:3}),(0,q.jsx)(`text`,{x:36,y:14,fontSize:11,fill:`#9ca3af`,children:t||`HEAD`}),(0,q.jsx)(`circle`,{cx:40,cy:20,r:5,fill:`#F93951`}),n.map(e=>{let n=Za[e.handle.status]??B(Za.active),r=e.handle.status===`merged`,i=e.handle.status===`needs-review`||e.handle.status===`failed`;return(0,q.jsxs)(`g`,{className:`transition-all duration-500`,children:[(0,q.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,q.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,q.jsx)(`circle`,{cx:220,cy:e.y,r:5,fill:i?`#e879f9`:e.color}),(0,q.jsx)(`text`,{x:232,y:e.y-6,fontSize:12,fill:`#e5e7eb`,fontFamily:`monospace`,children:Ya(e.handle.branch)}),(0,q.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 $a={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 eo(e){return $a[e]??{icon:`?`,label:e,tint:`border-border`,dot:`bg-muted-foreground`}}var to=e=>e.replace(/^wstack\/ap\//,``);function no({worktrees:e,baseBranch:t}){if(e.length===0)return null;let n=[...e].sort((e,t)=>e.allocatedAt-t.allocatedAt);return(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card/50 backdrop-blur-sm px-3 py-3`,children:[(0,q.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,q.jsx)(`span`,{className:`font-semibold tracking-wide uppercase text-[10px]`,children:`Worktrees`}),(0,q.jsx)(`span`,{className:`opacity-60`,children:`· base`}),(0,q.jsx)(`code`,{className:`font-mono text-primary`,children:t||`HEAD`}),(0,q.jsxs)(`span`,{className:`opacity-60`,children:[`· `,n.length,` isolated`]})]}),(0,q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:n.map(e=>{let t=eo(e.status),n=e.status===`needs-review`,r=Math.min(100,e.insertions+e.deletions);return(0,q.jsxs)(`div`,{className:Z(`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,q.jsx)(`span`,{className:Z(`h-2.5 w-2.5 shrink-0 rounded-full`,t.dot),"aria-hidden":!0}),(0,q.jsx)(`code`,{className:`w-44 shrink-0 truncate font-mono text-sm`,children:to(e.branch)}),(0,q.jsxs)(`span`,{className:`shrink-0 rounded bg-muted px-2 py-0.5 text-xs text-muted-foreground`,children:[`⟵ `,e.ownerLabel]}),n?(0,q.jsx)(`span`,{className:`font-mono text-xs font-bold text-fuchsia-400`,children:`CONFLICT`}):(0,q.jsxs)(`span`,{className:`flex items-center gap-1 font-mono text-xs transition-all duration-500`,children:[(0,q.jsxs)(`span`,{className:`text-emerald-500`,children:[`+`,e.insertions]}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,q.jsxs)(`span`,{className:`text-rose-500`,children:[`-`,e.deletions]}),(0,q.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[e.files,`f`]})]}),(0,q.jsx)(`div`,{className:`ml-auto hidden h-1 w-24 overflow-hidden rounded-full bg-muted sm:block`,children:(0,q.jsx)(`div`,{className:`h-full bg-gradient-to-r from-emerald-500 to-rose-500 transition-all duration-700`,style:{width:`${r}%`}})}),(0,q.jsx)(`span`,{className:`w-20 shrink-0 text-right text-xs text-muted-foreground`,children:t.label}),e.recentActivity.length>0?(0,q.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 ro=De(`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`}}),$=V.forwardRef(({className:e,variant:t,size:r,asChild:i=!1,...a},o)=>(0,q.jsx)(i?n:`button`,{className:Z(ro({variant:t,size:r,className:e})),ref:o,...a}));$.displayName=`Button`;function io({onClose:e}){let{client:t}=Da(),n=ei(e=>e.phases),r=ei(e=>e.activePhaseId),i=ei(e=>e.overallPercent),a=ei(e=>e.autonomous),o=ei(e=>e.title),s=Pr(e=>e.worktrees),c=Pr(e=>e.baseBranch),[l,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(!1),[p,m]=(0,V.useState)(!1),h=n.length>0,g=(0,V.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,V.useCallback)(e=>{t?.send?.({type:`autophase.selectPhase`,payload:{phaseId:e}})},[t]),v=(0,V.useCallback)(()=>{t?.send?.({type:`autophase.toggleAutonomous`,payload:{}})},[t]),y=(0,V.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,q.jsxs)(`div`,{className:`flex flex-col h-full bg-background`,children:[(0,q.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-2 border-b bg-card shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Vn,{className:`h-5 w-5 text-muted-foreground`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h1`,{className:`text-lg font-semibold`,children:h&&o||`AutoPhase`}),h&&(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[n.length,` phase`,n.length===1?``:`s`,` · `,i,`% complete`]})]})]}),(0,q.jsx)($,{variant:`ghost`,size:`icon`,onClick:e,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]}),h?(0,q.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,q.jsx)(Ha,{phases:n,activePhaseId:r??void 0,onPhaseClick:_,overallPercent:i,autonomous:a,onToggleAutonomous:v,className:`w-72 shrink-0`}),(0,q.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:b?(0,q.jsx)(qa,{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,q.jsx)(`div`,{className:`flex h-full items-center justify-center text-muted-foreground`,children:(0,q.jsx)(`p`,{className:`text-sm`,children:`Select a phase from the left panel to view its tasks.`})})})]}):(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-8`,children:(0,q.jsxs)(`div`,{className:`max-w-lg w-full space-y-6`,children:[(0,q.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,q.jsx)(ue,{className:`h-10 w-10 mx-auto text-primary/60`}),(0,q.jsx)(`h2`,{className:`text-xl font-semibold`,children:`Start a Phase Plan`}),(0,q.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,q.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,q.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,q.jsxs)($,{onClick:g,disabled:!l.trim()||d,className:`flex-1 gap-2`,children:[(0,q.jsx)(P,{className:`h-4 w-4`}),d?`Starting…`:`Start AutoPhase`]})}),(0,q.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,q.jsxs)(`div`,{className:`border-t bg-card/50 shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-end gap-2 px-4 pt-2 text-xs`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>m(!1),className:Z(`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,q.jsx)(`button`,{type:`button`,onClick:()=>m(!0),className:Z(`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,q.jsx)(`div`,{className:`px-4 pb-3`,children:p?(0,q.jsx)(Qa,{worktrees:s,baseBranch:c}):(0,q.jsx)(no,{worktrees:s,baseBranch:c})})]})]})}var ao=[{mode:`off`,label:`Off`,description:`Full manual control — agent waits for your input.`,icon:(0,q.jsx)(Cn,{className:`h-3.5 w-3.5`})},{mode:`suggest`,label:`Suggest`,description:`Agent suggests next steps but waits for approval.`,icon:(0,q.jsx)(D,{className:`h-3.5 w-3.5`})},{mode:`auto`,label:`Auto`,description:`Agent auto-proceeds after brief confirmation delay.`,icon:(0,q.jsx)(P,{className:`h-3.5 w-3.5`})},{mode:`eternal`,label:`Eternal`,description:`Agent runs autonomously until goal is complete.`,icon:(0,q.jsx)(ir,{className:`h-3.5 w-3.5`})},{mode:`eternal-parallel`,label:`Eternal Parallel`,description:`Multi-agent autonomous execution — fleet mode.`,icon:(0,q.jsx)(ir,{className:`h-3.5 w-3.5`})}];function oo({value:e,onChange:t,className:n,compact:r=!1}){let[i,a]=(0,V.useState)(!1),o=(0,V.useRef)(null);(0,V.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,V.useEffect)(()=>{if(!i)return;let e=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[i]);let s=ao.find(t=>t.mode===e);return(0,q.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:Z(`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,q.jsx)(`span`,{className:`truncate max-w-[7rem]`,children:s?.label??e}),(0,q.jsx)(Kn,{className:`h-3 w-3 opacity-60`})]}),i&&(0,q.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,q.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b mb-1`,children:`Autonomy Mode`}),ao.map(n=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{t(n.mode),a(!1)},className:Z(`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,q.jsx)(`span`,{className:`mt-0.5 text-muted-foreground`,children:n.icon}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium`,children:n.label}),(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground leading-snug`,children:n.description})]}),e===n.mode&&(0,q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary mt-2 shrink-0`})]},n.mode))]})]})}var so=0,co=!1;function lo(){let e=ni(e=>e.autoProceedMaxIterations),t=ni(e=>e.autonomy),n=(0,V.useRef)(so),r=(0,V.useRef)(co),i=(0,V.useRef)(t);(0,V.useEffect)(()=>{n.current=so,r.current=co}),(0,V.useEffect)(()=>{i.current!==`auto`&&t===`auto`&&(co=!1,r.current=!1),i.current=t},[t]);let a=(0,V.useCallback)(()=>e<=0?!0:n.current<e,[e]),o=(0,V.useCallback)(()=>{let t=e;return t>0&&n.current>=t?!1:(so=++n.current,t>0&&so>=t&&(co=!0,r.current=!0),!0)},[e]),s=(0,V.useCallback)(()=>{so=0,n.current=0,co=!1,r.current=!1},[]),c=(0,V.useCallback)(()=>{co=!1,r.current=!1},[]);return{streak:n.current,capWarned:r.current,canAutoSubmit:a,recordAutoSubmit:o,reset:s,resetCapWarned:c}}function uo(){let e=U.getState().messages,t=[],n=new Date().toISOString().slice(0,19).replace(/[:T]/g,`-`),r=G.getState().projectName||`chat`,i=G.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(`
|
|
29
|
-
`)],{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 fo(){let e=U.getState().messages,t=G.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`
|
|
30
|
-
<section class="bubble tool ${e.isError?`error`:``}">
|
|
31
|
-
<header><span class="icon">🔧</span><code>${a(e.toolName??`tool`)}</code> ${t}</header>
|
|
32
|
-
${e.toolInput===void 0?``:`<details><summary>Input</summary><pre>${a(JSON.stringify(e.toolInput,null,2))}</pre></details>`}
|
|
33
|
-
${e.toolResult?`<details><summary>Output</summary><pre>${a(e.toolResult)}</pre></details>`:``}
|
|
34
|
-
</section>`}return`
|
|
35
|
-
<section class="bubble ${e.role===`user`?`user`:`assistant`}">
|
|
36
|
-
<header><span class="icon">${e.role===`user`?`👤`:`🤖`}</span><strong>${e.role===`user`?`User`:`Assistant`}</strong></header>
|
|
37
|
-
<pre class="content">${a(e.content)}</pre>
|
|
38
|
-
</section>`}),s=`<!doctype html>
|
|
39
|
-
<html lang="en"><head>
|
|
40
|
-
<meta charset="utf-8">
|
|
41
|
-
<title>${r} — chat export</title>
|
|
42
|
-
<style>
|
|
43
|
-
:root { color-scheme: light dark; }
|
|
44
|
-
body { font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; max-width: 920px; margin: 24px auto; padding: 0 16px; }
|
|
45
|
-
h1 { font-size: 20px; margin-bottom: 4px; }
|
|
46
|
-
.meta { color: #666; font-size: 12px; margin-bottom: 24px; }
|
|
47
|
-
.bubble { margin: 12px 0; padding: 10px 14px; border-radius: 10px; border: 1px solid #ddd; }
|
|
48
|
-
.bubble header { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #666; margin-bottom: 6px; }
|
|
49
|
-
.bubble header .icon { margin-right: 4px; }
|
|
50
|
-
.bubble.user { background: #eef4ff; border-color: #c8d8f5; }
|
|
51
|
-
.bubble.assistant { background: #fff; }
|
|
52
|
-
.bubble.tool { background: #fafafa; }
|
|
53
|
-
.bubble.tool.error { background: #fff5f5; border-color: #f5c8c8; }
|
|
54
|
-
pre.content, .bubble pre { white-space: pre-wrap; word-break: break-word; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; margin: 0; }
|
|
55
|
-
details summary { cursor: pointer; color: #555; font-size: 12px; }
|
|
56
|
-
details pre { margin-top: 6px; background: #f4f4f4; padding: 8px; border-radius: 6px; max-height: 360px; overflow: auto; }
|
|
57
|
-
@media (prefers-color-scheme: dark) {
|
|
58
|
-
body { background: #0d0d0f; color: #e6e6e6; }
|
|
59
|
-
.bubble { border-color: #2a2a2e; }
|
|
60
|
-
.bubble.user { background: #16213a; border-color: #2a3d6b; }
|
|
61
|
-
.bubble.assistant { background: #161618; }
|
|
62
|
-
.bubble.tool { background: #131315; }
|
|
63
|
-
.bubble.tool.error { background: #2a1717; border-color: #5c2a2a; }
|
|
64
|
-
details pre { background: #1a1a1c; }
|
|
65
|
-
.meta, .bubble header, details summary { color: #999; }
|
|
66
|
-
}
|
|
67
|
-
</style>
|
|
68
|
-
</head><body>
|
|
69
|
-
<h1>${r} — chat export</h1>
|
|
70
|
-
<div class="meta">
|
|
71
|
-
Exported ${new Date().toISOString()}${t.session?.provider?` · ${escape(t.session.provider)}/${escape(t.session.model)}`:``} · ${e.length} message${e.length===1?``:`s`}
|
|
72
|
-
</div>
|
|
73
|
-
${o.join(``)}
|
|
74
|
-
</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 po(){let e=K(e=>e.paletteOpen),t=K(e=>e.setPaletteOpen),n=K(e=>e.setCurrentView),r=W(e=>e.setTheme),{entries:i}=Nr(),{addMessage:a,clearMessages:o}=U(),s=Da(),[l,u]=(0,V.useState)(``),[d,f]=(0,V.useState)(0),p=(0,V.useRef)(null);(0,V.useEffect)(()=>{e&&(u(``),f(0),requestAnimationFrame(()=>p.current?.focus()))},[e]),(0,V.useEffect)(()=>{let e=e=>{if((e.ctrlKey||e.metaKey)&&e.key.toLowerCase()===`k`){e.preventDefault(),t(!K.getState().paletteOpen);return}e.key===`Escape`&&K.getState().paletteOpen&&(e.preventDefault(),t(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]);let m=(0,V.useMemo)(()=>{let e=[{id:`help`,category:`Command`,label:`Show slash commands`,icon:ze,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:ht,keywords:[`tools`,`list`],run:()=>s.listTools()},{id:`memory`,category:`Command`,label:`Show memory`,icon:xe,keywords:[`memory`,`remember`,`notes`],run:()=>s.listMemory()},{id:`skills`,category:`Command`,label:`List skills`,icon:qn,keywords:[`skills`],run:()=>s.listSkills()},{id:`diag`,category:`Command`,label:`Runtime diagnostics`,icon:Zn,keywords:[`diag`,`diagnostics`,`debug`],run:()=>s.getDiag()},{id:`stats`,category:`Command`,label:`Session stats (tokens, cache, cost)`,icon:C,keywords:[`stats`,`tokens`,`cost`,`cache`],run:()=>s.getStats()},{id:`clear`,category:`Session`,label:`Clear context`,hint:`Wipe in-memory context, keep session id`,icon:Lt,keywords:[`clear`,`reset`,`wipe`],run:()=>{o(),s.client?.clearContext?.()}},{id:`new`,category:`Session`,label:`New session`,hint:`Brand-new on disk + memory`,icon:L,keywords:[`new`,`fresh`,`session`],run:()=>{s.client?.newSession?.(),n(`chat`)}},{id:`compact`,category:`Session`,label:`Compact context`,icon:En,keywords:[`compact`,`shrink`,`context`],run:()=>s.client?.compactContext?.()},{id:`repair-context`,category:`Session`,label:`Repair context`,hint:`Remove orphan tool protocol blocks`,icon:ht,keywords:[`repair`,`context`,`tool_use`,`tool_result`],run:()=>s.client?.repairContext?.()},{id:`export`,category:`Session`,label:`Export chat as markdown`,icon:Pn,keywords:[`export`,`save`,`markdown`,`download`],run:()=>uo()},{id:`export-html`,category:`Session`,label:`Export chat as HTML`,hint:`Self-contained, opens in any browser`,icon:Pn,keywords:[`export`,`html`,`download`,`archive`],run:()=>fo()},{id:`history`,category:`Command`,label:`Open history panel`,icon:Gn,keywords:[`history`,`sessions`],run:()=>{K.getState().setSidebarOpen(!0),K.getState().selectActivity(`history`)}},{id:`settings`,category:`Command`,label:`Open settings`,icon:c,keywords:[`settings`,`config`],run:()=>n(`settings`)},{id:`model`,category:`Command`,label:`Change provider/model`,icon:hn,keywords:[`model`,`provider`,`change`],run:()=>K.getState().setModelSwitcherOpen(!0)},{id:`theme-light`,category:`Theme`,label:`Theme: Light`,icon:yt,keywords:[`theme`,`light`,`mode`],run:()=>r(`light`)},{id:`theme-dark`,category:`Theme`,label:`Theme: Dark`,icon:Nn,keywords:[`theme`,`dark`,`mode`],run:()=>r(`dark`)},{id:`theme-system`,category:`Theme`,label:`Theme: Follow system`,icon:un,keywords:[`theme`,`system`,`auto`],run:()=>r(`system`)},{id:`compact-toggle`,category:`Command`,label:`Toggle compact density`,icon:kn,hint:`Ctrl+Shift+D`,keywords:[`compact`,`dense`,`density`,`size`],run:()=>K.getState().toggleCompactMode()},{id:`sound-toggle`,category:`Command`,label:W.getState().soundOnComplete?`Sound on completion: ON — turn off`:`Sound on completion: OFF — turn on`,icon:W.getState().soundOnComplete?rn:Ct,hint:`Chime when a run finishes`,keywords:[`sound`,`audio`,`chime`,`notify`,`beep`],run:()=>{let e=!W.getState().soundOnComplete;W.getState().setSoundOnComplete(e),e&&Ni()}},{id:`autophase-open`,category:`Command`,label:`Open AutoPhase view`,icon:ue,keywords:[`autophase`,`autonomous`,`phases`,`rocket`],run:()=>n(`autophase`)},{id:`autophase-toggle`,category:`Command`,label:ei.getState().autonomous?`Autonomous mode: ON — disable`:`Autonomous mode: OFF — enable`,icon:ei.getState().autonomous?Cn:P,hint:`Toggle autonomous phase execution`,keywords:[`autonomous`,`autophase`,`auto`,`pause`,`resume`],run:()=>{let e=!ei.getState().autonomous;s.toggleAutoPhaseAutonomous(e)}},{id:`autophase-stop`,category:`Command`,label:`Stop AutoPhase`,icon:g,keywords:[`autophase`,`stop`,`autonomous`,`end`],run:()=>s.stopAutoPhase()}];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:Me,keywords:[`resume`,t.title,t.id,t.provider,t.model],run:()=>s.resumeSession(t.id)});return e},[i,s,n,r,a,o]),h=(0,V.useMemo)(()=>{let e=l.toLowerCase().trim();return e?m.filter(t=>[t.label,t.hint??``,t.category,...t.keywords??[]].join(` `).toLowerCase().includes(e)):m},[m,l]);if((0,V.useEffect)(()=>{d>=h.length&&f(0)},[h.length,d]),!e)return null;let _=e=>{e&&(t(!1),e.run())};return(0,q.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,q.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,q.jsxs)(`div`,{className:`flex items-center gap-2 px-4 py-3 border-b`,children:[(0,q.jsx)(ve,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(`input`,{ref:p,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(),f(e=>(e+1)%Math.max(1,h.length))):e.key===`ArrowUp`?(e.preventDefault(),f(e=>(e-1+Math.max(1,h.length))%Math.max(1,h.length))):e.key===`Enter`&&(e.preventDefault(),_(h[d]))}}),(0,q.jsx)(`kbd`,{className:`text-[10px] text-muted-foreground border rounded px-1.5 py-0.5`,children:`Esc`})]}),(0,q.jsx)(`div`,{className:`max-h-[60vh] overflow-y-auto`,children:h.length===0?(0,q.jsxs)(`div`,{className:`px-4 py-8 text-center text-sm text-muted-foreground`,children:[`No matches for "`,l,`"`]}):mo(h,d,_,f)}),(0,q.jsxs)(`div`,{className:`border-t px-4 py-2 text-[10px] uppercase tracking-wider text-muted-foreground flex items-center gap-3`,children:[(0,q.jsx)(`span`,{children:`↑↓ navigate`}),(0,q.jsx)(`span`,{children:`↵ select`}),(0,q.jsx)(`span`,{children:`Esc dismiss`})]})]})})}function mo(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,q.jsx)(`div`,{className:`p-1`,children:Object.entries(i).map(([e,i])=>(0,q.jsxs)(`div`,{children:[(0,q.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,q.jsxs)(`button`,{type:`button`,onMouseEnter:()=>r(i),onClick:()=>n(e),className:Z(`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,q.jsx)(a,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`truncate`,children:e.label}),e.hint&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.hint})]}),o&&(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`↵`})]},e.id)})]},e))})}function ho({query:e,onPick:t,onClose:n}){let r=Da(),i=W(e=>e.wsUrl),[a,o]=(0,V.useState)([]),[s,c]=(0,V.useState)(0),l=(0,V.useRef)(null),u=(0,V.useRef)(null);return(0,V.useEffect)(()=>{let e=H(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,V.useEffect)(()=>(l.current&&clearTimeout(l.current),l.current=setTimeout(()=>{r.client.listFiles(e,50)},80),()=>{l.current&&clearTimeout(l.current)}),[e,r.client]),(0,V.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(B(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,q.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,q.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,q.jsxs)(`span`,{children:[`@ Files `,e&&`· "${e}"`]}),(0,q.jsx)(`span`,{children:`↑/↓ select · ↵ insert · Esc dismiss`})]}),a.length===0?(0,q.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,q.jsxs)(`button`,{type:`button`,onClick:()=>t(e),onMouseEnter:()=>c(n),className:Z(`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,q.jsx)(fe,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,q.jsx)(qe,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:e})]},e))]})}var go=[{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:`/interrupt`,category:`Run`,aliases:[`/abort`,`/stop`,`/int`],description:`Stop the current run (abort the in-flight request)`},{name:`/help`,category:`App`,description:`Show every slash command and what it does`},{name:`/exit`,category:`App`,description:`Exit the session and close WebUI`}],_o=[`Run`,`Session`,`Inspect`,`Config`,`App`];function vo(e){let t=e.toLowerCase();return t===`/`||t===``?go:go.filter(e=>e.name.startsWith(t)||(e.aliases?.some(e=>e.startsWith(t))??!1))}function yo(e,t){let n=t-1;for(;n>=0;){let r=B(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 bo=[{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}]}],xo=6,So=3,Co=180;function wo(e){let t=e.split(`
|
|
75
|
-
`);if(t.length<So)return!1;let n=0,r=0;for(let e of t){let t=e.trim();t.length!==0&&(t.length>Co&&r++,/^ {2,}/.test(e)&&n++,/[.!?]$/.test(t)&&r++,/[{}();=<>[\]]/.test(t)&&n++,/[#$]/.test(t)&&!/^# /.test(t)&&n++)}return n>=r&&n>=2}function To(e){if(!wo(e))return null;let t={};for(let n of bo){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>=xo?n:null}function Eo(e){let t=e.trim();return/^```[\s\S]*```\s*$/.test(t)}function Do(e){if(Eo(e))return null;let t=To(e);return t?{fenced:`\`\`\`${t}\n${e}\n\`\`\``,lang:t}:null}function Oo({original:e,refined:t,english:n,onDecision:r,autoSendDelayMs:i=0}){let a=K(e=>e.setRefinePanel),[o,s]=(0,V.useState)(i>0?Math.ceil(i/1e3):null),[c,l]=(0,V.useState)(t),[u,d]=(0,V.useState)(!1),f=(0,V.useRef)(null),p=(0,V.useRef)(null);(0,V.useEffect)(()=>{if(!(i<=0||u))return f.current=setInterval(()=>{s(e=>e===null||e<=1?(clearInterval(f.current),r(`refined`),null):e-1)},1e3),()=>{f.current&&clearInterval(f.current)}},[i,u,r]),(0,V.useEffect)(()=>{let e=e=>{if(!(e.target instanceof HTMLInputElement||e.target instanceof HTMLTextAreaElement))switch(e.key){case`Enter`:u||(e.preventDefault(),r(`refined`));break;case`e`:case`E`:u||(e.preventDefault(),r(`english`));break;case`o`:case`O`:u||(e.preventDefault(),r(`original`));break;case`t`:case`T`:u||(e.preventDefault(),d(!0));break;case`Escape`:e.preventDefault(),u?(d(!1),l(t)):(a(null),r(`original`));break}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u,r,t,a]),(0,V.useEffect)(()=>{u&&p.current&&p.current.querySelector(`textarea`)?.focus()},[u]);let m=e=>{f.current&&clearInterval(f.current),a(null),r(e)};return(0,q.jsxs)(`div`,{ref:p,className:`rounded-lg border bg-card text-card-foreground shadow-sm overflow-hidden animate-message`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium`,children:`✨ Refine Prompt`}),o!==null&&!u&&(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`auto-send in `,o,`s`]})]}),(0,q.jsx)(`button`,{onClick:()=>m(`original`),className:`text-muted-foreground hover:text-foreground transition-colors`,title:`Cancel (Esc)`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]}),(0,q.jsx)(`div`,{className:`p-4 space-y-3`,children:u?(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`label`,{className:`text-xs text-muted-foreground font-medium`,children:`Edit refined prompt:`}),(0,q.jsx)(`textarea`,{value:c,onChange:e=>l(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,q.jsxs)(`div`,{className:`flex gap-2 justify-end`,children:[(0,q.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>{d(!1),l(t)},children:`Cancel`}),(0,q.jsxs)($,{size:`sm`,onClick:()=>{c.trim()&&m(`edit`)},disabled:!c.trim(),children:[(0,q.jsx)(Be,{className:`h-3 w-3 mr-1`}),`Use Edit`]})]})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground font-medium uppercase tracking-wider`,children:`Original`}),(0,q.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,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.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,q.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(your language)`})]}),(0,q.jsx)(`div`,{className:Z(`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:()=>m(`refined`),title:`Click or press Enter to use this version`,children:t.length>300?t.slice(0,300)+`...`:t})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-blue-600 dark:text-blue-400 font-medium uppercase tracking-wider`,children:[(0,q.jsx)(v,{className:`h-3 w-3`}),`English`]}),(0,q.jsx)(`div`,{className:Z(`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:()=>m(`english`),title:`Press e to use English version`,children:n.length>300?n.slice(0,300)+`...`:n})]})]})}),!u&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-4 py-3 border-t bg-muted/20`,children:[(0,q.jsxs)(`div`,{className:`flex gap-1 text-xs text-muted-foreground`,children:[(0,q.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono`,children:`Enter`}),(0,q.jsx)(`span`,{children:`refined`}),(0,q.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`e`}),(0,q.jsx)(`span`,{children:`English`}),(0,q.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`o`}),(0,q.jsx)(`span`,{children:`original`}),(0,q.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border font-mono ml-2`,children:`t`}),(0,q.jsx)(`span`,{children:`edit`})]}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsxs)($,{variant:`ghost`,size:`sm`,onClick:()=>m(`original`),className:`text-xs`,children:[(0,q.jsx)(Gt,{className:`h-3 w-3 mr-1`}),`Original`]}),(0,q.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>d(!0),className:`text-xs`,children:[(0,q.jsx)(oe,{className:`h-3 w-3 mr-1`}),`Edit`]}),(0,q.jsxs)($,{size:`sm`,onClick:()=>m(`refined`),className:`text-xs bg-yellow-600 hover:bg-yellow-700 text-white`,children:[(0,q.jsx)(Be,{className:`h-3 w-3 mr-1`}),`Use Refined`]})]})]})]})}function ko({onOpenBreakdown:e}={}){let{isLoading:t,setLoading:n,addMessage:r,clearMessages:i}=U(),a=U(e=>e.queue),o=U(e=>e.enqueue),s=U(e=>e.removeQueued),c=U(e=>e.clearQueue),{setCurrentView:l}=K(),u=K(e=>e.pushPrompt),d=K(e=>e.promptHistory),f=Da(),{sendMessage:p,sendAbort:m,client:h,refineModel:_}=f,v=K(e=>e.refineEnabled),y=K(e=>e.refinePanel),b=K(e=>e.toggleRefineEnabled),x=K(e=>e.setRefinePanel),S=K(e=>e.setProcessMonitorOpen),C=K(e=>e.setQueuePanelOpen),{reset:w}=lo(),T=G(e=>e.lastInputTokens),E=G(e=>e.maxContext),[D,O]=(0,V.useState)(``),[k,A]=(0,V.useState)(0),[j,M]=(0,V.useState)(-1),[N,P]=(0,V.useState)(null),[F,I]=(0,V.useState)(null),[te,L]=(0,V.useState)(!1),ne=(0,V.useRef)(null),R=(0,V.useCallback)(t=>{let o=t.trim(),s=o.indexOf(` `),c=(s===-1?o:o.slice(0,s)).toLowerCase(),u=s===-1?``:o.slice(s+1).trim(),d=c;switch(d){case`/help`:return r({role:`assistant`,content:[`📖 **Slash commands**`,``,...go.map(e=>`• \`${e.name}\`${e.aliases?.length?` (${e.aliases.map(e=>`\`${e}\``).join(`, `)})`:``} — ${e.description}`)].join(`
|
|
76
|
-
`)}),!0;case`/clear`:return i(),h?.clearContext?.(),!0;case`/new`:return h?.newSession?.(),!0;case`/exit`:return h?.send?.({type:`webui.shutdown`}),r({role:`assistant`,content:`👋 Shutting down WebUI server…`}),!0;case`/compact`:case`/compact!`:return h?.compactContext?.(d===`/compact!`),!0;case`/repair`:return h?.repairContext?.(),!0;case`/debug`:case`/context`:return e?.(),!0;case`/tools`:return f.listTools(),!0;case`/memory`:return f.listMemory(),!0;case`/skill`:case`/skills`:return f.listSkills(),!0;case`/diag`:return f.getDiag(),!0;case`/stats`:return f.getStats(),!0;case`/save`:return f.saveSession(),!0;case`/load`:case`/resume`:return f.listSessions(50),l(`sessions`),!0;case`/agents`:return K.getState().setAgentsMonitorOpen(!0),!0;case`/brain`:{let[e,...t]=u.split(/\s+/).filter(Boolean),n=(e??``).toLowerCase();if(n===`risk`)h?.send?.({type:`brain.risk`,payload:{level:(t[0]??``).toLowerCase()}});else if(n===`ask`){let e=t.join(` `).trim();e?h?.send?.({type:`brain.ask`,payload:{question:e}}):r({role:`assistant`,content:"Usage: `/brain ask <question>`"})}else h?.send?.({type:`brain.status`});return!0}case`/plan`:return f.getPlan(),l(`chat`),K.getState().setDockSection(`work`),!0;case`/todos`:{if(u.toLowerCase()===`clear`)return h?.clearTodos?.(),!0;let e=G.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(`
|
|
77
|
-
`)}),!0}case`/export`:return uo(),r({role:`assistant`,content:`📥 Chat exported to your downloads folder.`}),!0;case`/interrupt`:case`/abort`:case`/stop`:case`/int`:return m(),n(!1),!0;case`/settings`:case`/model`:return l(`settings`),!0;case`/enhance`:{let e=!K.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`/kill`:case`/ps`:return S(!0),!0;case`/queue`:{let e=a;if(e.length===0)r({role:`assistant`,content:`📋 **Message Queue** — empty.
|
|
78
|
-
|
|
79
|
-
Type while the agent is running to queue messages; they are sent automatically when the agent finishes.`});else{let t=[`📋 **Message Queue** (${e.length} queued)`,``];e.forEach((e,n)=>{let r=e.length>80?`${e.slice(0,77)}…`:e;t.push(`${n+1}. ${r}`)}),t.push(``,"_Use `/queue open` to manage, or `/queue clear` to wipe._"),r({role:`assistant`,content:t.join(`
|
|
80
|
-
`)})}return u.toLowerCase()===`open`&&C(!0),!0}case`/next`:{let e=u.trim().toLowerCase();return!e||e===`list`||e===`ls`||e===`show`?se():e===`clear`||e===`reset`?(r({role:`assistant`,content:`💡 _Suggestion list cleared._`}),!0):ce(u.trim())}default:return!1}},[r,i,h,a,m,n,l,b,S,C,f,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(`
|
|
81
|
-
`).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=U.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}),p(e)&&n(!0)}function se(){let e=U.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(`
|
|
82
|
-
`)}),!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 le=D.startsWith(`/`)&&!D.includes(` `)?vo(D):[];(0,V.useEffect)(()=>{k>=le.length&&A(0)},[le.length,k]);let ue=(0,V.useCallback)(()=>{let e=ne.current;e&&(e.value=``,e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`,t||e.focus())},[t]),de=(0,V.useCallback)(async e=>{if(e.preventDefault(),w(),!D.trim()&&!ge.current)return;let i=ge.current;ge.current=null;let a=D.trim();if(a.startsWith(`/`)&&R(a)){u(a),O(``),M(-1),ue();return}if(O(``),M(-1),ue(),u(a),ue(),t){o(i?`\n\n${a}`:a);return}try{h?.isConnected?v&&_?(x({original:a,refined:a,english:a,resolve:e=>{}}),_(a)):(r({role:`user`,content:i?`\n\n${a}`:a}),n(!0),p(a,i??void 0)):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:or(e),timestamp:new Date().toISOString()})),n(!1)}},[D,t,o,h,p,_,v,x,r,n,R,u,ue,w]),fe=(0,V.useCallback)(()=>{m(),n(!1)},[m,n]),pe=(0,V.useCallback)(()=>{m(),n(!1);let e=U.getState().messages;for(let t=e.length-1;t>=0;t--){let n=B(e[t]);if(n.role===`user`&&n.content){O(n.content),requestAnimationFrame(()=>{let e=ne.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}}},[m,n]),he=(0,V.useCallback)(e=>{if(le.length===0&&!N&&d.length>0){if(e.key===`ArrowUp`){let t=e.currentTarget,n=t.value.slice(0,t.selectionStart);if(j>=0||n.indexOf(`
|
|
83
|
-
`)===-1){e.preventDefault();let t=Math.min(d.length-1,j+1);M(t);let n=d[t]??``;O(n),requestAnimationFrame(()=>{let e=ne.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`&&j>=0){e.preventDefault();let t=j-1;if(t<0)M(-1),O(``);else{M(t);let e=d[t]??``;O(e),requestAnimationFrame(()=>{let t=ne.current;t&&(t.style.height=`auto`,t.style.height=`${Math.min(t.scrollHeight,200)}px`,t.setSelectionRange(e.length,e.length))})}return}}if(le.length>0){if(e.key===`ArrowDown`){e.preventDefault(),A(e=>(e+1)%le.length);return}if(e.key===`ArrowUp`){e.preventDefault(),A(e=>(e-1+le.length)%le.length);return}if(e.key===`Tab`){e.preventDefault();let t=le[k];t&&(O(t.name+` `),A(0));return}if(e.key===`Enter`&&!e.shiftKey){let t=le[k];if(t&&t.name!==D.toLowerCase().trim()){e.preventDefault(),O(``),R(t.name);return}}if(e.key===`Escape`){e.preventDefault(),O(``);return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),de(e))},[le,k,N,d,j,D,R,de]),ge=(0,V.useRef)(null);(0,V.useEffect)(()=>{let e=ne.current;if(!e)return;let t=async e=>{let t=e.clipboardData?.items;if(t){for(let n of t)if(n.type.startsWith(`image/`)){e.preventDefault();try{let e=n.getAsFile();if(!e)continue;let t=new FileReader;t.onload=()=>{ge.current=t.result},t.readAsDataURL(e)}catch{}return}}};return e.addEventListener(`paste`,t),()=>e.removeEventListener(`paste`,t)},[]);let _e=()=>{let e=ne.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)};return(0,q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[F&&(0,q.jsxs)(`div`,{className:Z(`rounded-md border px-2.5 py-1.5 text-xs flex items-center justify-between gap-2 animate-message`,F.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,q.jsx)(`span`,{children:F.lang?(0,q.jsxs)(q.Fragment,{children:[`Auto-fenced as`,` `,(0,q.jsx)(`span`,{className:`font-mono font-semibold`,children:F.lang}),` — `,(0,q.jsx)(`span`,{className:`font-mono tabular-nums`,children:F.chars.toLocaleString()}),` chars`,` (`,(0,q.jsx)(`span`,{className:`font-mono tabular-nums`,children:F.lines}),` lines)`]}):(0,q.jsxs)(q.Fragment,{children:[`Pasted`,` `,(0,q.jsx)(`span`,{className:`font-mono tabular-nums`,children:F.chars.toLocaleString()}),` chars`,` (`,(0,q.jsx)(`span`,{className:`font-mono tabular-nums`,children:F.lines}),` lines) — fenced code blocks render best with `,(0,q.jsx)(`span`,{className:`font-mono`,children:"```"}),`.`]})}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[F.undoFence&&(0,q.jsx)(`button`,{type:`button`,onClick:F.undoFence,className:`underline underline-offset-2 hover:opacity-80`,title:`Remove fences and restore raw text`,children:`Undo`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>I(null),className:`opacity-60 hover:opacity-100 shrink-0`,title:`Dismiss`,children:`×`})]})]}),a.length>0&&(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2 text-xs`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,q.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium`,children:[`Queued (`,a.length,`)`]}),(0,q.jsx)(`button`,{type:`button`,onClick:c,className:`text-muted-foreground hover:text-destructive text-xs`,children:`Clear all`})]}),(0,q.jsx)(`ul`,{className:`space-y-1`,children:a.map((e,t)=>(0,q.jsxs)(`li`,{className:`flex items-start justify-between gap-2 rounded bg-background/60 border px-2 py-1`,children:[(0,q.jsx)(`span`,{className:`truncate flex-1 min-w-0`,children:e}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:`text-muted-foreground hover:text-destructive shrink-0`,title:`Remove from queue`,children:`×`})]},t))})]}),y&&(0,q.jsx)(Oo,{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`){O(i);return}x(null),h?.isConnected&&(r({role:`user`,content:o}),n(!0),p(o))}}),(0,q.jsxs)(`form`,{onSubmit:de,onDragEnter:e=>{!e.dataTransfer||!Array.from(e.dataTransfer.types).includes(`Files`)||(e.preventDefault(),L(!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)||L(!1)},onDrop:e=>{if(!e.dataTransfer)return;let t=Array.from(e.dataTransfer.files??[]);if(t.length===0){L(!1);return}e.preventDefault(),L(!1);let n=ne.current,r=n?.selectionStart??D.length,i=D.slice(0,r),a=D.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}`;O(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`}P({start:d,query:f})})},className:Z(`flex items-end gap-2 relative rounded-lg transition-colors`,te&&`ring-2 ring-primary ring-offset-2 ring-offset-background bg-primary/5`),children:[te&&(0,q.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,q.jsxs)(`div`,{className:`relative flex-1`,children:[N&&(0,q.jsx)(ho,{query:N.query,onClose:()=>P(null),onPick:e=>{let t=D.slice(0,N.start),n=D.slice(N.start+1+N.query.length),r=`@${e} `;O(t+r+n),P(null),requestAnimationFrame(()=>{let e=ne.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`}})}}),!N&&le.length>0&&(()=>{let e={};le.forEach((t,n)=>{e[t.category]||(e[t.category]=[]),e[t.category]?.push({cmd:t,idx:n})});let t=_o.filter(t=>e[t]?.length);return(0,q.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,q.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,q.jsxs)(`div`,{className:`mb-1`,children:[(0,q.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,q.jsxs)(`button`,{type:`button`,onClick:()=>{O(``),R(e.name)},onMouseEnter:()=>A(t),className:Z(`w-full text-left px-3 py-1.5 rounded transition-colors flex items-center gap-3`,t===k?`bg-accent text-accent-foreground`:`hover:bg-accent/40`),children:[(0,q.jsx)(`span`,{className:`font-mono shrink-0`,children:e.name}),e.aliases?.length?(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground/70 font-mono shrink-0`,children:[`(`,e.aliases.join(`, `),`)`]}):null,(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground truncate`,children:[`— `,e.description]})]},e.name))]},t))]})})(),(0,q.jsx)(`textarea`,{ref:ne,value:D,onChange:e=>{let t=e.target.value;O(t),_e(),j>=0&&M(-1),P(yo(t,e.target.selectionStart??t.length))},onSelect:e=>{let t=e.currentTarget;P(yo(t.value,t.selectionStart))},onKeyDown:he,onPaste:e=>{let t=e.clipboardData?.getData(`text`)??``;if(!t)return;let n=Do(t);if(n){e.preventDefault();let r=ne.current;if(!r)return;let i=r.selectionStart,a=r.selectionEnd,o=D.slice(0,i),s=D.slice(a),c=n.fenced;O(o+c+s);let l=t.split(`
|
|
84
|
-
`).length;I({chars:t.length,lines:l,lang:n.lang,undoFence:()=>{O(o+t+s),I(null),requestAnimationFrame(()=>{r&&(r.focus(),r.style.height=`auto`,r.style.height=`${Math.min(r.scrollHeight,200)}px`)})}}),setTimeout(()=>I(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(`
|
|
85
|
-
`).length;I({chars:t.length,lines:e}),setTimeout(()=>I(null),4e3)}},placeholder:h?.isConnected?t?`Agent is running — type to queue a follow-up…`:`Message the agent… (type / for commands, @ for files)`:`Connect to server first…`,className:Z(`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:!h?.isConnected}),D.length>0&&(()=>{let e=D.length>=400,t=Math.ceil(D.length/4),n=`text-muted-foreground`,r;if(E>0&&e){let e=(T+t+64)/E*100;e>=100?(n=`text-red-600 dark:text-red-400 font-medium`,r=`Projected ${Math.round(e)}% of ${E.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 ${E.toLocaleString()} ctx — getting tight.`):r=`≈ ${t.toLocaleString()} tokens · projected ${Math.round(e)}% of ${E.toLocaleString()} ctx.`}else e&&(r=`≈ ${t.toLocaleString()} tokens (4-char heuristic)`);return(0,q.jsxs)(`span`,{className:Z(`absolute bottom-1.5 right-12 text-xs tabular-nums`,n),title:r,children:[D.length,e&&(0,q.jsxs)(`span`,{className:`ml-1 opacity-70`,children:[`· ≈`,t>=1e3?`${(t/1e3).toFixed(1)}k`:t,`t`]})]})})()]}),(0,q.jsx)(`div`,{className:`flex gap-1`,children:t?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)($,{type:`button`,size:`icon`,variant:`outline`,onClick:pe,className:`h-[44px] w-[44px] rounded-lg`,title:`Stop run and edit the last prompt (reuse + rewrite)`,children:(0,q.jsx)(ee,{className:`h-4 w-4`})}),(0,q.jsx)($,{type:`button`,size:`icon`,variant:`destructive`,onClick:fe,className:`h-[44px] w-[44px] rounded-lg`,title:`Abort the current run`,children:(0,q.jsx)(g,{className:`h-4 w-4 fill-current`})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)($,{type:`button`,size:`icon`,variant:v?`default`:`outline`,disabled:!h?.isConnected,onClick:b,className:Z(`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,q.jsx)(qn,{className:`h-4 w-4`})}),(0,q.jsx)($,{type:`submit`,size:`icon`,disabled:!D.trim()||!h?.isConnected,className:`h-[44px] w-[44px] rounded-lg`,children:(0,q.jsx)(me,{className:`h-4 w-4`})})]})})]})]})}function Ao({open:e,onClose:t,className:n}){let[r,i]=(0,V.useState)([]),[a,o]=(0,V.useState)(!1),s=Da(),c=(0,V.useRef)(null);(0,V.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,V.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,q.jsx)(`div`,{className:Z(`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,q.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,q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,q.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,q.jsx)(Gn,{className:`h-4 w-4`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Session Checkpoints`}),(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[r.length,` checkpoint`,r.length===1?``:`s`]})]})]}),(0,q.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]}),(0,q.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,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,q.jsx)(Et,{className:`h-10 w-10 opacity-15`}),(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:`No checkpoints yet`}),(0,q.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,q.jsx)(`div`,{className:`py-1`,children:[...r].reverse().map((e,t)=>{let n=t===0;return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>l(e.index),disabled:a,className:Z(`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,q.jsxs)(`div`,{className:`flex flex-col items-center mt-1.5`,children:[(0,q.jsx)(`div`,{className:Z(`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.25)]`:`border-muted-foreground/30 bg-background group-hover:border-primary/40`)}),t<r.length-1&&(0,q.jsx)(`div`,{className:`w-px flex-1 min-h-[20px] bg-border/50`})]}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`span`,{className:`text-xs font-mono text-muted-foreground tabular-nums shrink-0`,children:[`#`,e.index]}),(0,q.jsx)(`span`,{className:`text-xs font-medium truncate`,children:e.label}),n&&(0,q.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,q.jsxs)(`div`,{className:`flex items-center gap-2 mt-1 text-[10px] text-muted-foreground`,children:[(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[e.messageCount,` msg`,e.messageCount===1?``:`s`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[`~`,e.tokens.toLocaleString(),` tok`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[`iter `,e.iteration]})]})]}),(0,q.jsx)(`span`,{className:`shrink-0 mt-1.5 opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,q.jsx)(Ne,{className:`h-4 w-4 text-violet-500`})})]},e.index)})})}),(0,q.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,q.jsx)(`kbd`,{className:`px-1 py-0.5 rounded bg-muted font-mono text-[9px]`,children:`Esc`}),` to close`]})]})}):null}var jo=[{id:`balanced`,name:`Balanced`,description:`Default rolling compaction`,thresholds:{warn:.6,soft:.75,hard:.9},preserveK:10,eliseThreshold:2e3}];function Mo(){let e=G(e=>e.contextMode),t=G(e=>e.contextModes),{listContextModes:n,switchContextMode:r,client:i}=Da(),[a,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(!1),u=(0,V.useRef)(null),d=(0,V.useRef)(null);(0,V.useEffect)(()=>{a&&n()},[a,n]),(0,V.useEffect)(()=>{if(!a)return;let e=e=>{u.current?.contains(e.target)||s(!1)},t=e=>{e.key===`Escape`&&s(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[a]),(0,V.useEffect)(()=>{if(!c)return;let e=e=>{d.current?.contains(e.target)||l(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[c]);let f=(0,V.useCallback)(e=>{i?.compactContext?.(e),l(!1),s(!1)},[i]),p=(0,V.useCallback)(()=>{i?.repairContext?.(),l(!1),s(!1)},[i]),m=t.length>0?t:jo,h=m.find(t=>t.id===e)??B(m[0]);return(0,q.jsxs)(`div`,{ref:u,className:`relative shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:Z(`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,q.jsx)(o,{className:`h-3 w-3`}),`ctx: `,(0,q.jsx)(`span`,{className:`font-mono`,children:e||h.id}),(0,q.jsx)(Kn,{className:`h-3 w-3 opacity-60`})]}),(0,q.jsxs)(`div`,{ref:d,className:`relative`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),className:Z(`flex items-center justify-center h-5 w-5 rounded-full`,`text-muted-foreground hover:text-foreground hover:bg-accent/50 transition-colors`,c&&`bg-accent/50 text-foreground`),title:`Context operations`,children:(0,q.jsx)(ht,{className:`h-3 w-3`})}),c&&(0,q.jsxs)(`div`,{className:`absolute top-full right-0 mt-1 w-52 rounded-md border bg-popover shadow-lg z-40 py-1`,children:[(0,q.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Context Operations`}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>f(!1),className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,q.jsx)(Dn,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-xs`,children:`Compact Now`}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Elide old tool output`})]})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>f(!0),className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,q.jsx)(Dn,{className:`h-3.5 w-3.5 shrink-0 text-red-400`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-xs`,children:`Compact Aggressive`}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Maximum elision now`})]})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:p,className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,q.jsx)(ht,{className:`h-3.5 w-3.5 shrink-0 text-blue-400`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-xs`,children:`Repair Context`}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Fix orphan tool-use blocks`})]})]}),(0,q.jsx)(`div`,{className:`border-t mt-1 pt-1 px-3 py-1.5`,children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{document.dispatchEvent(new CustomEvent(`open:context-breakdown`)),l(!1),s(!1)},className:`w-full text-left px-3 py-2 hover:bg-accent/40 flex items-center gap-2`,children:[(0,q.jsx)(M,{className:`h-3.5 w-3.5 shrink-0 text-green-400`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-xs`,children:`Debug Context`}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Size breakdown per section`})]})]})})]})]})]}),a&&(0,q.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,q.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Context Window`}),m.map(t=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{r(t.id),s(!1)},className:Z(`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,q.jsx)(Be,{className:Z(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsx)(`span`,{className:`text-xs font-mono`,children:t.id}),t.thresholds?.warn!==void 0&&(0,q.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,q.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description}),(t.preserveK||t.eliseThreshold)&&(0,q.jsxs)(`div`,{className:`mt-1 text-[10px] text-muted-foreground/80`,children:[`keep `,t.preserveK??`-`,` recent · elide `,t.eliseThreshold??`-`,`+ tokens`]})]})]},t.id))]})]})}function No(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}k`:String(e)}var Po=e=>{let t=new Date(e);return`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`};function Fo(e,t){let n=new Date(e),r=new Date(t),i=new Date(t-864e5);return Po(e)===Po(r.getTime())?`Today`:Po(e)===Po(i.getTime())?`Yesterday`:n.toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,year:n.getFullYear()===r.getFullYear()?void 0:`numeric`})}function Io(e,t=Date.now()){let n=[];for(let t=0;t<e.length;t++){let r=B(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 i=e=>{if(e.kind===`user`)return e.message.timestamp;let t=B(e.items[0]);return t.kind===`msg`?t.message.timestamp:t.tools[0]?.timestamp??0},a=[],o=null;for(let e=0;e<r.length;e++){let n=B(r[e]),s=i(n),c=Po(s);if(c!==o&&(a.push({kind:`day`,key:`day-${c}-${e}`,label:Fo(s,t)}),o=c),n.kind===`user`){a.push({kind:`user`,key:n.key,message:n.message});continue}let l=e===r.length-1,u=n.items.map((e,t)=>{let r=t>0;return e.kind===`msg`?{kind:`msg`,key:e.message.id,message:e.message,isFirst:!r&&e.isFirst,isContinuation:r}:{kind:`tools`,key:e.key,tools:e.tools,isContinuation:r,isLastGroup:t===n.items.length-1,hasRunningTool:e.tools.some(e=>e.toolResult===void 0)}});a.push({kind:`agent`,key:n.key,items:u,isLastTurn:l})}return a}var Lo={0:``,1:`▏`,2:`▎`,3:`▍`,4:`▌`,5:`▋`,6:`▊`,7:`▉`,8:`█`};function Ro(e){return e>=75?`bg-destructive`:e>=60?`bg-[hsl(var(--warning))]`:`bg-[hsl(var(--success))]`}function zo(e){return e>=75?`text-destructive`:e>=60?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`}function Bo({pct:e,tokens:t,maxTokens:n,segments:r=10,showTokens:i=!0,className:a,onClick:o}){let s=Math.round(Math.max(0,Math.min(200,e))/100*r*8),c=[],l=s;for(let e=0;e<r;e++){let e=Math.min(8,l);c.push({fill:e}),l-=e}let u=e>=100?`${Math.round(e)}%+`:`${Math.round(e)}%`,d=i&&t!==void 0&&n!==void 0&&n>0?` ${No(t)}/${No(n)}`:``;return(0,q.jsxs)(`span`,{className:Z(`inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full text-[11px] font-mono font-medium shrink-0`,o&&`cursor-pointer hover:ring-1 hover:ring-ring transition-shadow`,zo(e),e>=75?`bg-red-500/10`:e>=60?`bg-amber-500/10`:`bg-emerald-500/10`,a),title:(t!==void 0&&n!==void 0?`Context window: ${t.toLocaleString()} / ${n.toLocaleString()} tokens (${u})`:`Context window: ${u}`)+(o?` — click for breakdown`:``),onClick:o?e=>{e.stopPropagation(),o()}:void 0,onKeyDown:o?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),o())}:void 0,role:o?`button`:void 0,tabIndex:o?0:void 0,children:[(0,q.jsx)(`span`,{className:`inline-flex font-mono text-[10px] leading-none tracking-tight`,children:c.map((t,n)=>(0,q.jsx)(`span`,{className:Z(`tabular-nums w-[0.55em] text-center`,t.fill>0?zo(e):`text-muted-foreground/30`),children:Lo[t.fill]??` `},n))}),(0,q.jsx)(`span`,{children:u}),d&&(0,q.jsx)(`span`,{className:`tabular-nums`,children:d})]})}function Vo({pct:e,tokens:t,maxTokens:n,showTokens:r=!0,className:i,onClick:a}){let o=Math.max(0,Math.min(200,e)),s=e>100?`${Math.round(e)}%+`:`${Math.round(e)}%`,c=r&&t!==void 0&&n!==void 0&&n>0?` ${No(t)}/${No(n)}`:``;return(0,q.jsxs)(`span`,{className:Z(`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,q.jsx)(`span`,{className:`h-1.5 w-16 overflow-hidden rounded-full bg-muted shrink-0`,children:(0,q.jsx)(`span`,{className:Z(`h-full rounded-full transition-all duration-300`,Ro(e)),style:{width:`${Math.max(2,o)}%`}})}),(0,q.jsx)(`span`,{className:Z(`text-[11px] font-mono tabular-nums font-medium`,zo(e)),children:s}),c&&(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:c})]})}function Ho({open:e,onClose:t}){let n=W(e=>e.wsUrl),{lastInputTokens:r,maxContext:i}=G(),[a,o]=(0,V.useState)(null),[s,c]=(0,V.useState)(!1),[l,u]=(0,V.useState)(null);if((0,V.useEffect)(()=>{if(!e){o(null),u(null);return}c(!0),u(null),o(null);let t=H(n);if(!t?.send){u(`WebSocket not connected`),c(!1);return}t.send({type:`context.debug`});let r=t.on(`context.debug`,e=>{e.type===`context.debug`&&(o(e.payload),c(!1))}),i=setTimeout(()=>{s&&(c(!1),u(`No debug data received. The server may not support context debugging.`))},5e3);return()=>{clearTimeout(i),r()}},[e,n]),(0,V.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 d=i>0&&r>0?Math.min(100,Math.round(r/i*100)):0;return(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,children:(0,q.jsxs)(`div`,{className:`w-full max-w-2xl max-h-[80vh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b sticky top-0 bg-card z-10`,children:[(0,q.jsxs)(`h3`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,q.jsx)(bn,{className:`h-4 w-4 text-[hsl(var(--warning))]`}),`Context Breakdown`]}),(0,q.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]}),(0,q.jsxs)(`div`,{className:`p-4 space-y-4`,children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,q.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Window Usage`}),(0,q.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[No(r),` / `,No(i),` (`,d,`%)`]})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Context Mode`}),(0,q.jsx)(`span`,{className:`block text-sm font-mono font-medium`,children:a?.mode??`—`})]})]}),s?(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground py-4`,children:[(0,q.jsx)(ar,{className:`h-4 w-4 animate-spin`}),`Fetching context breakdown…`]}):l?(0,q.jsx)(`div`,{className:`rounded-md bg-destructive/10 border border-destructive/20 p-3 text-sm text-destructive`,children:l}):a?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[(0,q.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,q.jsx)(qe,{className:`h-3 w-3`}),`System Prompt`]}),(0,q.jsx)(`span`,{className:`block text-sm font-mono font-medium`,children:No(a.systemPrompt)})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,q.jsx)(ht,{className:`h-3 w-3`}),`Tools`]}),(0,q.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[No(a.tools.total),` (`,a.tools.count,`)`]})]}),(0,q.jsxs)(`div`,{className:`rounded bg-muted/30 px-3 py-2`,children:[(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground flex items-center gap-1`,children:[(0,q.jsx)(pt,{className:`h-3 w-3`}),`Messages`]}),(0,q.jsxs)(`span`,{className:`block text-sm font-mono font-medium`,children:[No(a.messages.total),` (`,a.messages.count,`)`]})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:`Token Allocation`}),(0,q.jsx)(`div`,{className:`mt-1.5 h-3 w-full overflow-hidden rounded-full bg-muted flex`,children:a.total>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`h-full bg-blue-500/70 transition-all`,style:{width:`${a.systemPrompt/a.total*100}%`},title:`System: ${No(a.systemPrompt)}`}),(0,q.jsx)(`span`,{className:`h-full bg-amber-500/70 transition-all`,style:{width:`${a.tools.total/a.total*100}%`},title:`Tools: ${No(a.tools.total)}`}),(0,q.jsx)(`span`,{className:`h-full bg-emerald-500/70 transition-all`,style:{width:`${a.messages.total/a.total*100}%`},title:`Messages: ${No(a.messages.total)}`})]})}),(0,q.jsxs)(`div`,{className:`flex gap-3 mt-1 text-[10px] text-muted-foreground`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500/70`}),` System`]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-amber-500/70`}),` Tools`]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-500/70`}),` Messages`]})]})]}),a.tools.breakdown.length>0&&(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:`Tool Breakdown`}),(0,q.jsx)(`div`,{className:`mt-1 space-y-0.5`,children:a.tools.breakdown.map(e=>(0,q.jsxs)(`div`,{className:`flex items-center justify-between text-xs py-0.5`,children:[(0,q.jsx)(`span`,{className:`font-mono`,children:e.name}),(0,q.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[e.tokens.toLocaleString(),` tok`]})]},e.name))})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[`Messages (`,a.messages.count,`) — `,No(a.messages.total),` tok`]}),(0,q.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,q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs py-0.5`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground font-mono w-6 text-right`,children:e.index}),(0,q.jsx)(`span`,{className:`text-muted-foreground font-mono w-14`,children:e.role}),(0,q.jsxs)(`span`,{className:`tabular-nums text-muted-foreground w-14`,children:[e.tokens.toLocaleString(),` tok`]}),(0,q.jsx)(`span`,{className:`text-muted-foreground/70 truncate flex-1`,children:e.preview.slice(0,80)})]},e.index))})]})]}):null]})]})})}function Uo(){let e=G(e=>e.cost),t=G(e=>e.inputCost),n=G(e=>e.outputCost),r=G(e=>e.cacheReadCost),i=U(e=>e.messages),[a,o]=(0,V.useState)(!1),s=(0,V.useRef)(null);(0,V.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,q.jsxs)(`div`,{ref:s,className:`relative inline-block`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),className:Z(`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,q.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,q.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,q.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Cost breakdown`}),(0,q.jsx)(`span`,{className:`font-mono tabular-nums text-sm font-semibold text-green-600 dark:text-green-400`,children:l(e)})]}),u?(0,q.jsxs)(`div`,{className:`text-[11px] text-muted-foreground font-mono mb-3 border-b pb-2`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{children:`input /1M`}),(0,q.jsxs)(`span`,{children:[`$`,t.toFixed(2)]})]}),(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{children:`output /1M`}),(0,q.jsxs)(`span`,{children:[`$`,n.toFixed(2)]})]}),r>0&&(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{children:`cache /1M`}),(0,q.jsxs)(`span`,{children:[`$`,r.toFixed(2)]})]})]}):(0,q.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,q.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No completed turns yet. Run a prompt to see per-turn cost here.`}):(0,q.jsxs)(q.Fragment,{children:[(0,q.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,q.jsx)(`ul`,{className:`space-y-1`,children:c.map(e=>(0,q.jsx)(`li`,{children:(0,q.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,q.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2`,children:[(0,q.jsx)(`span`,{className:`text-xs truncate`,children:e.preview}),(0,q.jsx)(`span`,{className:`text-xs font-mono tabular-nums text-green-600 dark:text-green-400 shrink-0`,children:l(e.cost)})]}),(0,q.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 Wo=[`path`,`file_path`,`pattern`,`command`,`cmd`,`url`,`query`,`description`,`content`];function Go(e,t){if(t==null)return``;if(typeof t!=`object`)return Ko(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=qo(n),t=typeof n.old_string==`string`?n.old_string:``,r=typeof n.new_string==`string`?n.new_string:``,i=t?t.split(`
|
|
86
|
-
`).length:0,a=r?r.split(`
|
|
87
|
-
`).length:0;return`edit ${e||`(file)`}${i||a?` (${i} → ${a} lines)`:``}`}if(/^(write|write_file|create_file|new_file)$/.test(r)){let e=qo(n),t=typeof n.content==`string`?n.content:``,r=t?t.split(`
|
|
88
|
-
`).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`$ ${Ko(e,110)}`}if(/^(fetch|http|web|webfetch|curl|request)$/.test(r)){let e=n.url;if(typeof e==`string`)return`${(n.method??`GET`).toUpperCase()} ${Ko(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 ${Ko(e,60)} in ${t}`:`grep ${Ko(e,100)}`}if(/^(glob|find)$/.test(r)){let e=n.pattern??n.glob;if(typeof e==`string`)return`glob ${Ko(e,100)}`}if(/^(read|read_file|cat)$/.test(r)){let e=qo(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 Wo){let t=n[e];if(typeof t==`string`&&t.length>0)return`${e}: ${Ko(t,100)}`}return Ko(Jo(t),120)}function Ko(e,t){return e.length>t?`${e.slice(0,t-1)}…`:e}function qo(e){let t=e.file_path??e.path??e.filepath;return typeof t==`string`?t:``}function Jo(e){try{return JSON.stringify(e)}catch{return String(e)}}var Yo={file:{color:`#60a5fa`},edit:{color:`#fbbf24`},search:{color:`#a78bfa`},folder:{color:`#38bdf8`},terminal:{color:`#ef4444`},web:{color:`#34d399`},git:{color:`#fb923c`},tree:{color:`#22d3ee`},code:{color:`#818cf8`},test:{color:`#4ade80`},package:{color:`#f472b6`},document:{color:`#94a3b8`},scaffold:{color:`#c084fc`},todo:{color:`#facc15`},plan:{color:`#2dd4bf`},task:{color:`#5eead4`},meta:{color:`#cbd5e1`},index:{color:`#06b6d4`},json:{color:`#eab308`},diff:{color:`#f97316`},logs:{color:`#a3a3a3`},settings:{color:`#9ca3af`},brain:{color:`#e879f9`},fallback:{color:`#9ca3af`}},Xo={read:`file`,cat:`file`,view:`file`,write:`file`,create:`file`,edit:`edit`,replace:`edit`,str_replace:`edit`,multi_edit:`edit`,patch:`diff`,grep:`search`,search:`search`,rg:`search`,ripgrep:`search`,glob:`search`,find:`search`,folder:`folder`,ls:`folder`,list:`folder`,set_working_dir:`folder`,tree:`tree`,bash:`terminal`,shell:`terminal`,sh:`terminal`,exec:`terminal`,run:`terminal`,command:`terminal`,fetch:`web`,web_fetch:`web`,web_search:`web`,git:`git`,diff:`diff`,lint:`code`,format:`settings`,typecheck:`code`,test:`test`,install:`package`,outdated:`package`,audit:`package`,document:`document`,scaffold:`scaffold`,todo:`todo`,plan:`plan`,task:`task`,json:`json`,index:`index`,logs:`logs`,mode:`meta`,tool_search:`meta`,tool_use:`meta`,batch_tool_use:`meta`,tool_help:`meta`,remember:`brain`,forget:`brain`,search_memory:`brain`,find_related_memories:`brain`};function Zo(e){return e?Xo[e.toLowerCase()]??`fallback`:`fallback`}var Qo={file:qe,edit:Ue,search:ve,folder:E,terminal:Un,web:v,git:Zt,tree:ge,code:Rn,test:je,package:ke,document:Ee,scaffold:S,todo:vn,plan:Mt,task:zt,meta:ht,index:En,json:et,diff:be,logs:ze,settings:c,brain:xe,fallback:ht};function $o(e){let t=Zo(e);return{Icon:Qo[t],color:Yo[t].color}}var es={file:`file read/write`,edit:`file editing`,search:`search & grep`,folder:`folder navigation`,terminal:`shell commands`,web:`web fetch`,git:`git operations`,tree:`directory tree`,code:`code quality`,test:`testing`,package:`package management`,document:`documentation`,scaffold:`project scaffolding`,todo:`todo tracking`,plan:`planning`,task:`task management`,meta:`tool orchestration`,index:`code indexing`,json:`JSON data`,diff:`diff & patch`,logs:`log viewing`,settings:`configuration`,brain:`memory`,fallback:`external tool`};function ts(e){let t=Zo(e),n=ns(Yo[t].color);return`${es[t]} — ${n}`}function ns(e){return{"#60a5fa":`blue`,"#fbbf24":`amber`,"#a78bfa":`violet`,"#38bdf8":`sky`,"#ef4444":`red`,"#34d399":`emerald`,"#fb923c":`orange`,"#22d3ee":`cyan`,"#818cf8":`indigo`,"#4ade80":`green`,"#f472b6":`pink`,"#94a3b8":`slate`,"#c084fc":`purple`,"#facc15":`yellow`,"#2dd4bf":`teal`,"#5eead4":`teal-light`,"#cbd5e1":`slate-light`,"#06b6d4":`cyan-dark`,"#eab308":`yellow-dark`,"#f97316":`orange-dark`,"#a3a3a3":`neutral`,"#9ca3af":`gray`,"#e879f9":`fuchsia`}[e]??`colored`}var rs=(0,V.memo)(function({oldText:e,newText:t,caption:n}){let r=(0,V.useMemo)(()=>as(e,t),[e,t]);if(r===null)return(0,q.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,q.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden text-xs`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1.5 border-b bg-muted/40`,children:[(0,q.jsx)(`span`,{className:`font-mono text-muted-foreground truncate`,children:n??`diff`}),(0,q.jsxs)(`span`,{className:`font-mono shrink-0`,children:[(0,q.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:[`+`,i]}),(0,q.jsx)(`span`,{className:`text-muted-foreground mx-1 opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{className:`text-rose-600 dark:text-rose-400`,children:[`-`,a]})]})]}),(0,q.jsx)(`div`,{className:`font-mono leading-relaxed max-h-96 overflow-auto`,children:r.map((e,t)=>(0,q.jsxs)(`div`,{className:Z(`flex`,e.kind===`add`&&`bg-emerald-500/10`,e.kind===`del`&&`bg-rose-500/10`),children:[(0,q.jsx)(`span`,{className:Z(`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,q.jsx)(`pre`,{className:Z(`whitespace-pre-wrap break-all flex-1 px-2`,e.kind===`ctx`&&`text-muted-foreground/70`),children:e.text||`\xA0`})]},t))})]})}),is=5e3;function as(e,t){let n=e.split(`
|
|
89
|
-
`),r=t.split(`
|
|
90
|
-
`);if(n.length>is||r.length>is)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]?B(o[e])[t]=B(o[e+1]?.[t+1])+1:B(o[e])[t]=Math.max(B(o[e+1]?.[t]),B(o[e]?.[t+1]));let s=[],c=0,l=0;for(;c<i&&l<a;)n[c]===r[l]?(s.push({kind:`ctx`,text:B(n[c])}),c++,l++):B(o[c+1]?.[l])>=B(o[c]?.[l+1])?(s.push({kind:`del`,text:B(n[c])}),c++):(s.push({kind:`add`,text:B(r[l])}),l++);for(;c<i;)s.push({kind:`del`,text:B(n[c++])});for(;l<a;)s.push({kind:`add`,text:B(r[l++])});return s}function os(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 ss=25,cs=12;function ls({text:e,isError:t,className:n,wrapClass:r,showLineNumbers:i}){let a=(0,V.useMemo)(()=>e.split(`
|
|
91
|
-
`),[e]),o=a.length>ss,[s,c]=(0,V.useState)(!o),l=s?e:a.slice(0,cs).join(`
|
|
92
|
-
`),u=!!i&&o&&s;return(0,q.jsxs)(`div`,{className:Z(`rounded-md border bg-background/40 overflow-hidden`,n),children:[u?(0,q.jsxs)(`div`,{className:`flex max-h-96 overflow-auto`,children:[(0,q.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(`
|
|
93
|
-
`)}),(0,q.jsx)(`pre`,{className:Z(`text-xs font-mono leading-[1.4] py-2 px-2 flex-1 whitespace-pre`,t?`text-destructive`:`text-foreground`),children:l})]}):(0,q.jsx)(`pre`,{className:Z(`text-xs font-mono p-2 max-h-96 overflow-auto`,r,t?`text-destructive`:`text-foreground`),children:l}),o&&(0,q.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,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(er,{className:`h-3 w-3`}),`Collapse to first `,cs,` lines`]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(vt,{className:`h-3 w-3`}),`Show all `,a.length,` lines (`,a.length-cs,` more)`]})})]})}var us=(0,V.memo)(function({toolName:e,result:t,isError:n,className:r}){let i=(0,V.useMemo)(()=>ds(e,t),[e,t]);return i.kind===`json`?(0,q.jsx)(fs,{value:i.value,isError:n,className:r}):i.kind===`numbered`?(0,q.jsx)(ls,{text:t,isError:n,className:r,wrapClass:`whitespace-pre`}):i.kind===`bash`?(0,q.jsxs)(`div`,{className:Z(`rounded-md border bg-background/40 overflow-hidden`,r),children:[i.stdout&&(0,q.jsx)(ls,{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,q.jsxs)(`div`,{className:Z(`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,q.jsxs)(`span`,{children:[`exit code: `,(0,q.jsx)(`span`,{className:`font-mono`,children:i.exitCode})]}),i.duration&&(0,q.jsx)(`span`,{children:i.duration})]})]}):(0,q.jsx)(ls,{text:t,isError:n,className:r,wrapClass:`whitespace-pre-wrap break-all`,showLineNumbers:!0})});function ds(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 fs({value:e,isError:t,className:n}){let r=(0,V.useMemo)(()=>{try{return JSON.stringify(e,null,2)}catch{return String(e)}},[e]),i=r.split(`
|
|
94
|
-
`).length,[a,o]=(0,V.useState)(i<30);return(0,q.jsxs)(`div`,{className:Z(`rounded-md border bg-background/40 overflow-hidden`,t&&`border-destructive/40`,n),children:[(0,q.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,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[a?(0,q.jsx)(Kn,{className:`h-3 w-3`}):(0,q.jsx)(Ie,{className:`h-3 w-3`}),(0,q.jsxs)(`span`,{className:`font-mono`,children:[`JSON · `,i,` lines`]})]}),(0,q.jsx)(`span`,{children:a?`collapse`:`expand`})]}),a&&(0,q.jsx)(`pre`,{className:Z(`text-xs font-mono whitespace-pre p-2 max-h-96 overflow-auto`,t?`text-destructive`:`text-foreground`),children:r})]})}async function ps(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 ms(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 hs(e){let t=(e??``).toLowerCase();return/bash|shell|exec|run/.test(t)?`log`:(/grep|search|find/.test(t),`txt`)}function gs(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 _s=[ne];function vs({text:e}){let[t,n]=(0,V.useState)(!1);return(0,q.jsxs)(`button`,{type:`button`,onClick:(0,V.useCallback)(async()=>{await ps(e)&&(n(!0),setTimeout(()=>n(!1),1500))},[e]),className:Z(`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,q.jsx)(Be,{className:`h-3 w-3`}):(0,q.jsx)(St,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:t?`Copied`:`Copy`})]})}var ys={code({inline:e,className:t,children:n,...r}){let i=/language-(\w+)/.exec(t??``),a=String(n??``).replace(/\n$/,``);if(e||!i)return(0,q.jsx)(`code`,{className:Z(`rounded border border-border/60 px-1.5 py-0.5 text-[0.85em] font-mono`,t),...r,children:n});let o=(0,V.useMemo)(()=>a.split(`
|
|
95
|
-
`),[a]),s=o.length>1;return(0,q.jsxs)(`div`,{className:`not-prose relative my-3 rounded-lg border border-border overflow-hidden group/codeblock`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-1 border-b border-border text-xs`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(rt,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`font-mono text-muted-foreground font-medium`,children:i[1]}),o.length>0&&(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums`,children:[o.length,` line`,o.length===1?``:`s`]})]}),(0,q.jsx)(vs,{text:a})]}),s?(0,q.jsxs)(`div`,{className:`flex max-h-[40rem] overflow-auto`,children:[(0,q.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 tabular-nums text-right shrink-0`,children:o.map((e,t)=>(0,q.jsx)(`div`,{children:t+1},t))}),(0,q.jsx)(`pre`,{className:`overflow-x-auto py-3 px-3 text-xs leading-[1.55] font-mono flex-1`,children:(0,q.jsx)(`code`,{className:Z(`hljs`,t),...r,children:n})})]}):(0,q.jsx)(`pre`,{className:`overflow-x-auto p-3 text-xs leading-relaxed font-mono max-h-[40rem]`,children:(0,q.jsx)(`code`,{className:Z(`hljs`,t),...r,children:n})}),(0,q.jsx)(`div`,{className:`pointer-events-none absolute bottom-8 left-0 right-0 h-8 bg-gradient-to-t from-black/10 to-transparent opacity-0 group-hover/codeblock:opacity-100 transition-opacity`})]})}};function bs({text:e,className:t,label:n=`Copy`}){let[r,i]=(0,V.useState)(!1);return(0,q.jsx)(`button`,{type:`button`,onClick:async t=>{t.stopPropagation(),await ps(e)&&(i(!0),setTimeout(()=>i(!1),1400))},className:Z(`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,t),title:n,children:r?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Be,{className:`h-3 w-3 text-green-500`}),(0,q.jsx)(`span`,{children:`Copied`})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(St,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:n})]})})}function xs(e){let t=e.split(`
|
|
96
|
-
`);for(let e=0;e<t.length;e++){let n=B(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 Ss({text:e}){let t=xs(e),[n,r]=(0,V.useState)(!1);if(t===-1)return(0,q.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:e});let i=e.split(`
|
|
97
|
-
`),a=i.slice(0,t).join(`
|
|
98
|
-
`).trim(),o=i.slice(t).join(`
|
|
99
|
-
`),s=o.split(`
|
|
100
|
-
`).filter(e=>e.trim().length>0).length;return(0,q.jsxs)(`div`,{className:`space-y-2`,children:[a&&(0,q.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-xs leading-relaxed`,children:a}),(0,q.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,q.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 Cs({input:e}){let[t,n]=(0,V.useState)({});if(typeof e!=`object`||!e||Array.isArray(e))return(0,q.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,q.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(no params)`}):(0,q.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(`
|
|
101
|
-
`));return(0,q.jsxs)(`div`,{className:Z(`py-0.5`,n?`flex flex-col gap-0.5`:`flex items-baseline gap-2`),children:[(0,q.jsxs)(`span`,{className:`text-muted-foreground shrink-0`,children:[e,`:`]}),(0,q.jsx)(`span`,{className:Z(`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,q.jsxs)(`div`,{className:`py-0.5`,children:[(0,q.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,q.jsx)(`span`,{className:`text-muted-foreground/60 text-[10px]`,children:i?`▾`:`▸`}),(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,q.jsx)(`span`,{className:`text-violet-600 dark:text-violet-400`,children:a})]}),i&&(0,q.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 ws=(0,V.memo)(function({message:e,isFirst:t=!1,isContinuation:n=!1}){let[r,i]=(0,V.useState)({}),[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(``),[l,u]=(0,V.useState)(!1),d=e.role===`user`,f=e.role===`tool`;e.role;let p=U(e=>e.truncateAfter),m=U(e=>e.addMessage),h=U(e=>e.setLoading),g=U(e=>e.isLoading),_=W(e=>e.wsUrl),v=K(e=>e.pinnedIds),y=K(e=>e.togglePin),b=K(e=>e.compactMode),x=v.includes(e.id),S=G(e=>e.inputCost),C=G(e=>e.outputCost),w=G(e=>e.cacheReadCost),T=ni(),{autonomy:E,yolo:D}=T,{canAutoSubmit:O,recordAutoSubmit:k,capWarned:A}=lo(),j=T.autoProceedMaxIterations<=0||O(),M=e=>{if(!O()){A||m({role:`assistant`,content:`⚠️ _Auto-proceed paused — maximum consecutive automatic turns reached. Type anything to continue (autonomy stays on)._`});return}k(),m({role:`user`,content:e}),h(!0),H(_).sendMessage(e),Hr(``)},N=(()=>{if(e.role!==`assistant`||g)return!1;let t=U.getState().messages;for(let n=t.length-1;n>=0;n--){let r=B(t[n]);if(r.role===`assistant`)return r.id===e.id}return!1})(),P=(0,V.useMemo)(()=>N&&e.content?Rr(e.content):null,[N,e.content]),F=()=>{let t=U.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=B(t[r]);p(i.id),m({role:`user`,content:i.content}),h(!0),H(_).sendMessage(i.content)},I=e=>{i(t=>({...t,[e]:!t[e]}))},te=()=>{c(e.content),o(!0)},ne=()=>{o(!1),c(``)},R=()=>{let t=s.trim();if(!t){ne();return}p(e.id),m({role:`user`,content:t}),h(!0),H(_).sendMessage(t),o(!1),c(``)};return(0,q.jsxs)(`div`,{"data-message-id":e.id,"data-pinned":x?`1`:void 0,className:Z(`group flex msg-bubble animate-message rounded-lg transition-shadow`,b?`gap-2`:`gap-3`,d?`flex-row-reverse`:`flex-row`,x&&`ring-1 ring-amber-500/30 bg-amber-500/[0.02] px-1 -mx-1`),children:[n?(0,q.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,q.jsx)(`div`,{className:Z(`flex-shrink-0 w-8 h-8 rounded-full flex items-center justify-center`,`ring-2 ring-offset-2 ring-offset-background`,d?`bg-primary text-primary-foreground ring-primary/20`:f?`bg-secondary text-secondary-foreground ring-secondary/20`:`bg-accent text-accent-foreground ring-accent/20`),children:d?(0,q.jsx)(Dt,{className:`h-4 w-4`}):f?(0,q.jsx)(Un,{className:`h-4 w-4`}):(0,q.jsx)(Qt,{className:`h-4 w-4`})}),(0,q.jsxs)(`div`,{className:Z(`flex flex-col gap-1.5 max-w-[85%]`,d&&`items-end`),children:[t&&!n&&(0,q.jsx)(`span`,{className:Z(`text-xs font-medium px-1`,d?`text-primary`:f?`text-secondary`:`text-muted-foreground`),children:d?`You`:f?`Tool`:`Assistant`}),f&&e.toolName&&(()=>{let{Icon:t,color:n}=$o(e.toolName),i=ts(e.toolName);return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>I(e.id),className:Z(`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`),title:i,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground/50`,children:r[e.id]?(0,q.jsx)(Kn,{className:`h-3 w-3`}):(0,q.jsx)(Ie,{className:`h-3 w-3`})}),(0,q.jsx)(t,{className:`h-3 w-3`,style:{color:n}}),(0,q.jsx)(`span`,{className:`font-mono`,style:{color:n},children:e.toolName}),e.toolResult===void 0?(0,q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-amber-500 animate-pulse`,"aria-hidden":!0}):e.isError?(0,q.jsx)(sn,{className:`h-3 w-3 text-destructive`}):(0,q.jsx)(ut,{className:`h-3 w-3 text-green-500`}),typeof e.toolDurationMs==`number`&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:gs(e.toolDurationMs)})]})})(),(0,q.jsx)(`div`,{className:Z(`rounded-2xl`,b?`px-3 py-1.5`:`px-4 py-3`,d?`bg-primary text-primary-foreground rounded-br-md`:f?e.isError?`bg-destructive/5 border border-destructive/20 text-destructive`:`bg-muted/80 text-foreground`:`bg-card border text-foreground`,e.isError&&!f&&`border-destructive/20`),children:f?(()=>{let t=!!r[e.id],n=e.toolInput===void 0?``:Go(e.toolName,e.toolInput),i=e.toolResult?e.toolResult.split(`
|
|
102
|
-
`).length:0;return(0,q.jsxs)(`div`,{className:`space-y-1 tool-details`,children:[n&&!t&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono truncate`,children:n}),e.toolResult===void 0&&e.progressLines&&e.progressLines.length>0&&(0,q.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,q.jsx)(`div`,{className:`truncate text-muted-foreground`,children:e},`${e}-${n}`)})})()}),t&&e.toolInput!==void 0&&(()=>{let t=os(e.toolName,e.toolInput);return t?(0,q.jsx)(rs,{oldText:t.oldText,newText:t.newText,caption:t.caption}):(0,q.jsxs)(`div`,{className:`p-3 bg-muted/50 rounded-lg overflow-x-auto`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1 text-muted-foreground mb-2 text-xs`,children:[(0,q.jsx)(Et,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:`Input`})]}),(0,q.jsx)(Cs,{input:e.toolInput})]})})(),t&&e.toolResult!==void 0&&e.toolResult.length>0&&(0,q.jsxs)(`div`,{className:`relative group/tool`,children:[(0,q.jsx)(us,{toolName:e.toolName,result:e.toolResult,isError:e.isError}),(0,q.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,q.jsx)(bs,{text:e.toolResult,label:``,className:`bg-background/80 border rounded px-1.5 py-0.5`}),e.toolResult.split(`
|
|
103
|
-
`).length>5&&(0,q.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation();let n=hs(e.toolName);ms(`${(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,q.jsx)(Pn,{className:`h-3 w-3`})})]})]}),t&&e.toolResult!==void 0&&e.toolResult.length===0&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`(empty)`}),!t&&e.isError&&e.toolResult&&(0,q.jsx)(`div`,{className:`text-xs font-mono text-destructive truncate`,children:e.toolResult.split(`
|
|
104
|
-
`)[0]}),(e.toolResult!==void 0&&e.toolResult.length>0||e.toolInput!==void 0&&Object.keys(e.toolInput??{}).length>0)&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>I(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`})`:``}`})]})})():a&&d?(0,q.jsxs)(`div`,{className:`flex flex-col gap-2 min-w-[280px]`,children:[(0,q.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),ne()):e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),R())},rows:Math.min(8,Math.max(2,s.split(`
|
|
105
|
-
`).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,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-primary-foreground/60`,children:`⌘/Ctrl+Enter to save · Esc to cancel`}),(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:ne,className:`text-xs px-2 py-0.5 rounded border border-primary-foreground/30 hover:bg-primary-foreground/10`,children:`Cancel`}),(0,q.jsx)(`button`,{type:`button`,onClick:R,disabled:!s.trim(),className:`text-xs px-2 py-0.5 rounded bg-primary-foreground text-primary disabled:opacity-50`,children:`Save & resend`})]})]})]}):(()=>{let t=P?P.stripped:e.content;return(0,q.jsx)(`div`,{className:Z(`text-sm leading-relaxed markdown-content`,e.streaming&&`streaming-cursor`),children:t?l&&e.role===`assistant`?(0,q.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,q.jsx)(Ss,{text:e.content}):(0,q.jsx)($e,{remarkPlugins:[nt],rehypePlugins:_s,components:ys,children:t}):e.streaming?(0,q.jsx)(`span`,{className:`inline-block animate-pulse text-muted-foreground`,children:`Typing...`}):(0,q.jsx)(`span`,{className:`text-muted-foreground italic`,children:`No content`})})})()}),P&&P.steps.length>0&&(0,q.jsx)(Wr,{steps:P.steps,yoloMode:D,autoMode:E===`auto`,autoDelayMs:T.autonomyDelayMs,onAutoSubmit:M,canAutoSubmit:j}),(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-2 px-1`,d?`flex-row-reverse`:`flex-row`),children:[(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground/50`,children:new Date(e.timestamp).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}),(0,q.jsx)(`span`,{className:`w-px h-3 bg-border/60 shrink-0`,"aria-hidden":!0}),e.runSummary&&(0,q.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*S+t.output*C+(t.cacheRead??0)*w)/1e6,r=S>0||C>0,i=n>=.01?`${n.toFixed(4)}`:n>0?`${n.toFixed(6).replace(/0+$/,``).replace(/\.$/,``)}`:``;return(0,q.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}`:``]})})(),!f&&e.content&&!e.streaming&&(0,q.jsx)(bs,{text:e.content,label:`Copy`,className:`opacity-50 hover:opacity-100 transition-opacity`}),e.role===`assistant`&&e.content&&!e.streaming&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>u(e=>!e),title:l?`Show rendered markdown`:`Show raw markdown source`,className:Z(`text-xs inline-flex items-center gap-1 transition-opacity`,l?`text-primary hover:text-primary/80 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[(0,q.jsx)(rt,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:l?`Rendered`:`Raw`})]}),d&&!a&&!g&&e.content&&(0,q.jsxs)(`button`,{type:`button`,onClick:te,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,q.jsx)(ee,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:`Edit`})]}),e.role===`assistant`&&e.content&&!e.streaming&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>y(e.id),title:x?`Unpin`:`Pin this answer`,className:Z(`text-xs inline-flex items-center gap-1 transition-opacity`,x?`text-amber-500 hover:text-amber-600 opacity-100`:`opacity-50 hover:opacity-100 text-muted-foreground hover:text-foreground`),children:[x?(0,q.jsx)(Qe,{className:`h-3 w-3`}):(0,q.jsx)(Ge,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:x?`Pinned`:`Pin`})]}),N&&e.content&&!e.streaming&&(0,q.jsxs)(`button`,{type:`button`,onClick:F,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,q.jsx)(L,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:`Retry`})]})]})]})]})});function Ts(){let e=G(e=>e.mode),t=G(e=>e.modes),{listModes:n,switchMode:r}=Da(),[i,a]=(0,V.useState)(!1),o=(0,V.useRef)(null);(0,V.useEffect)(()=>{i&&n()},[i,n]),(0,V.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,q.jsxs)(`div`,{ref:o,className:`relative shrink-0`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),className:Z(`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,q.jsx)(`span`,{className:`font-mono`,children:e||`default`}),(0,q.jsx)(Kn,{className:`h-3 w-3 opacity-60`})]}),i&&(0,q.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,q.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] uppercase tracking-wider text-muted-foreground border-b`,children:`Mode`}),s.map(t=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{r(t.id),a(!1)},className:Z(`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,q.jsx)(Be,{className:Z(`h-3.5 w-3.5 mt-0.5 shrink-0`,t.id===e?`opacity-100 text-primary`:`opacity-0`)}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`text-xs font-mono`,children:t.id}),t.description&&(0,q.jsx)(`div`,{className:`text-[11px] text-muted-foreground leading-snug`,children:t.description})]})]},t.id))]})]})}function Es({open:e,onClose:t,className:n}){let[r,i]=(0,V.useState)([]),a=Da(),o=(0,V.useRef)(null),s=(0,V.useRef)(null);(0,V.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,V.useCallback)(e=>{a.client.send?.({type:`process.kill`,payload:{pid:e}})},[a.client]),l=(0,V.useCallback)(()=>{a.client.send?.({type:`process.killAll`})},[a.client]),u=r.filter(e=>e.status===`running`);return e?(0,q.jsx)(`div`,{className:Z(`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,q.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,q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,q.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,q.jsx)(Un,{className:`h-4 w-4`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Running Processes`}),(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[u.length,` active · `,r.length,` total`]})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[u.length>0&&(0,q.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,q.jsx)(g,{className:`h-3 w-3 fill-current`}),`Kill All`]}),(0,q.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,q.jsx)(Un,{className:`h-10 w-10 opacity-15`}),(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:`No processes tracked`}),(0,q.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,q.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,q.jsxs)(`div`,{className:Z(`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,q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,q.jsx)(`span`,{className:Z(`led shrink-0`,e.status===`running`?r?`text-blue-400`:`text-[hsl(var(--success))] led-pulse`:`text-muted-foreground`)}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)(`span`,{className:`font-mono text-[10px] text-muted-foreground shrink-0`,children:[`PID `,e.pid]}),(0,q.jsx)(`span`,{className:`font-medium truncate`,children:e.tool}),r&&(0,q.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,q.jsx)(Se,{className:`h-2.5 w-2.5`}),`protected`]})]}),(0,q.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 truncate block mt-0.5 font-mono`,children:e.command})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0 ml-3`,children:[n&&(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:n}),e.status===`running`&&!r&&(0,q.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,q.jsx)(g,{className:`h-3.5 w-3.5 fill-current`})})]})]},e.pid)})})})]})}):null}var Ds=`
|
|
106
|
-
::highlight(chat-search) { background-color: hsl(var(--primary) / 0.3); color: inherit; }
|
|
107
|
-
::highlight(chat-search-active) { background-color: hsl(var(--primary) / 0.85); color: hsl(var(--primary-foreground)); }
|
|
108
|
-
`;function Os(){let e=K(e=>e.searchOpen),t=K(e=>e.setSearchOpen),n=K(e=>e.searchQuery),r=K(e=>e.setSearchQuery),i=U(e=>e.messages),a=K(e=>e.requestScrollToMessage),o=(0,V.useRef)(null),[s,c]=(0,V.useState)(0),[l,u]=(0,V.useState)(0);(0,V.useEffect)(()=>{e&&requestAnimationFrame(()=>o.current?.focus())},[e]),(0,V.useEffect)(()=>{let e=document.createElement(`style`);return e.textContent=Ds,document.head.appendChild(e),()=>{document.head.removeChild(e)}},[]);let d=(0,V.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,V.useEffect)(()=>{s>=d.length&&c(0)},[d,s]),(0,V.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`)},o=n.trim();if(!o||!e){a();return}let c=o.toLowerCase(),l=[],u=[],f=d[s];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-c.length;){let e=n.indexOf(c,i);if(e===-1)break;let a=document.createRange();a.setStart(r,e),a.setEnd(r,e+c.length),l.push(a),t&&u.push(a),i=e+c.length}}r=n.nextNode()}}return l.length>0?r.set(`chat-search`,new i(...l)):r.delete(`chat-search`),u.length>0?r.set(`chat-search-active`,new i(...u)):r.delete(`chat-search-active`),a},[n,d,s,e,l]),(0,V.useEffect)(()=>{let e=d[s];if(!e)return;a(e);let t=0,n=requestAnimationFrame(function e(){u(e=>e+1),++t<3&&(n=requestAnimationFrame(e))});return()=>cancelAnimationFrame(n)},[d,s,a]),!e)return null;let f=e=>{d.length!==0&&c(t=>(t+e+d.length)%d.length)};return(0,q.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,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,q.jsx)(ve,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,q.jsx)(`input`,{ref:o,value:n,onChange:e=>r(e.target.value),onKeyDown:e=>{e.key===`Escape`?(e.preventDefault(),t(!1)):e.key===`Enter`?(e.preventDefault(),f(e.shiftKey?-1:1)):e.key===`ArrowDown`?(e.preventDefault(),f(1)):e.key===`ArrowUp`&&(e.preventDefault(),f(-1))},placeholder:`Search in chat…`,className:`flex-1 bg-transparent outline-none text-sm placeholder:text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums shrink-0`,children:d.length===0?n?`0`:``:`${s+1} / ${d.length}`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>f(-1),disabled:d.length===0,className:Z(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Previous hit`,children:(0,q.jsx)(pe,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>f(1),disabled:d.length===0,className:Z(`p-1 rounded hover:bg-muted disabled:opacity-30 disabled:cursor-not-allowed`),title:`Next hit`,children:(0,q.jsx)(te,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`p-1 rounded hover:bg-muted text-muted-foreground`,title:`Close (Esc)`,children:(0,q.jsx)(Gt,{className:`h-3.5 w-3.5`})})]})})}function ks(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 As=(0,V.memo)(function({tools:e,defaultOpen:t=!1,isContinuation:n=!1}){let[r,i]=(0,V.useState)(t);if(e.length===1)return(0,q.jsx)(ws,{message:B(e[0]),isFirst:!0,isContinuation:n});let a=e.filter(e=>e.toolResult===void 0).length,o=e.filter(e=>e.isError).length,s=e.reduce((e,t)=>e+(t.toolDurationMs??0),0),c=Array.from(new Set(e.map(e=>e.toolName).filter(Boolean))),l=c.slice(0,3).join(`, `),u=c.length>3?` +${c.length-3}`:``;return(0,q.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[n?(0,q.jsx)(`div`,{className:`flex-shrink-0 w-8 h-8`,"aria-hidden":!0}):(0,q.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,q.jsx)(Un,{className:`h-4 w-4`})}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1.5 max-w-[85%] flex-1 min-w-0`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>i(e=>!e),className:Z(`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,q.jsx)(Kn,{className:`h-3.5 w-3.5 text-muted-foreground`}):(0,q.jsx)(Ie,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsx)(Un,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`font-mono text-xs`,children:[e.length,` tool call`,e.length===1?``:`s`]}),a>0?(0,q.jsx)(z,{className:`h-3 w-3 animate-spin text-amber-500`}):o>0?(0,q.jsx)(sn,{className:`h-3 w-3 text-destructive`}):(0,q.jsx)(ut,{className:`h-3 w-3 text-green-500`}),s>0&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-normal`,children:ks(s)}),l&&(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 font-mono truncate`,children:[`· `,l,u]})]}),r&&(0,q.jsx)(`div`,{className:`space-y-2 pl-3 border-l-2 border-border/40 ml-2 tool-details`,children:e.map(e=>(0,q.jsx)(ws,{message:e,isFirst:!1},e.id))})]})]})}),js=[{icon:ve,title:`Understand`,hint:`Explore and analyze the codebase`,tone:`text-blue-600 dark:text-blue-400 bg-blue-500/10 border-blue-500/20`,prompts:[`Map out the structure of this codebase: what are the main modules or components, how do they depend on each other, and what are the key patterns used throughout?`,`Find and document the public API surface — all exported interfaces, functions, and types that other parts of the system depend on.`,`Trace the flow of data through the system for a typical operation. Where does input validation happen? Where are side effects triggered?`]},{icon:Ft,title:`Create`,hint:`Build new features and functionality`,tone:`text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 border-emerald-500/20`,prompts:[`Add a new feature that covers the full stack: data model, business logic, and any UI or API layers. Follow existing patterns in this codebase.`,`Write comprehensive tests for a module with low coverage. Include happy paths, edge cases, and error scenarios.`,`Add observability to a critical path — structured logging, error tracking, or metrics that help diagnose issues in production.`]},{icon:mt,title:`Investigate`,hint:`Debug issues and find root causes`,tone:`text-amber-600 dark:text-amber-400 bg-amber-500/10 border-amber-500/20`,prompts:[`Something isn't working as expected — help me trace from the symptom to the root cause. Follow the code path and identify where behavior diverges from intent.`,`There's a difference between how this works locally versus in production or CI. Check for environment differences, configuration issues, or hidden assumptions.`,`Performance is degrading. Identify the bottlenecks — whether N+1 queries, blocking I/O, unnecessary allocations, or something else — and propose targeted fixes.`]},{icon:qn,title:`Improve`,hint:`Refactor and optimize existing code`,tone:`text-violet-600 dark:text-violet-400 bg-violet-500/10 border-violet-500/20`,prompts:[`Find duplicated or similar logic that could be consolidated into shared utilities. Extract the common parts and update the call sites.`,`Identify modules that have grown too large or handle too many responsibilities. Propose a cleaner separation that can be done incrementally.`,`Review error handling across the codebase: are errors consistent, well-contextualized, and properly propagated? Suggest improvements to the worst cases.`]}],Ms=[{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 Ns(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 Ps(){let{projectName:e,cwd:t}=G(),{provider:n,model:r}=W(),i=W(e=>e.wsConnected),a=W(e=>e.wsUrl),o=K(e=>e.setCurrentView),[s,c]=(0,V.useState)(void 0);(0,V.useEffect)(()=>{if(!i)return;let e=H(a),t=e.on(`providers.saved`,e=>{let t=e.payload;c(t.providers?.length??0)});return e.listSavedProviders(),()=>{t()}},[i,a]);let l=K(e=>e.promptHistory).slice(0,6),{listSessions:u,resumeSession:d}=Da(),f=Nr(e=>e.entries);(0,V.useEffect)(()=>{i&&f.length===0&&u(10)},[i]);let p=K(e=>e.sessionNicknames),m=f.filter(e=>!e.isCurrent).slice(0,4);return(0,q.jsxs)(`div`,{className:`flex flex-col gap-8 py-8 px-2 max-w-5xl mx-auto w-full`,children:[(0,q.jsxs)(`div`,{className:`flex flex-col items-center text-center gap-3`,children:[(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.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,q.jsx)(Dn,{className:`h-7 w-7 text-primary-foreground`})}),(0,q.jsx)(`div`,{className:`absolute -inset-3 bg-gradient-to-r from-transparent via-primary/10 to-transparent animate-pulse rounded-full -z-10`})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:[`Where do you want to start`,e?(0,q.jsxs)(q.Fragment,{children:[` in `,(0,q.jsx)(`span`,{className:`text-primary`,children:e})]}):``,`?`]}),(0,q.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,q.jsx)(`span`,{className:`font-mono text-foreground/80`,children:`/`}),` for the full command palette.`]}),n&&r&&(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground/70 mt-2 font-mono`,children:[n,` / `,r]}),t&&(0,q.jsxs)(`p`,{className:`text-[11px] text-muted-foreground/50 mt-1 font-mono`,title:t,children:[`Working directory: `,t]})]})]}),i&&s===0&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>o(`settings`),className:Z(`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,q.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,q.jsx)(Yn,{className:`h-6 w-6`})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`h3`,{className:`text-base font-semibold mb-1`,children:`No API key configured yet`}),(0,q.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,q.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,q.jsx)(Te,{className:`h-3.5 w-3.5`})]})]}),(0,q.jsx)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:js.map((e,t)=>{let n=e.icon;return(0,q.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,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:Z(`flex items-center justify-center w-8 h-8 rounded-lg border`,e.tone),children:(0,q.jsx)(n,{className:`h-4 w-4`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.title}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.hint})]})]}),(0,q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:e.prompts.map((e,t)=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>Ns(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,q.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,q.jsx)(Me,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Pick back up`})]}),(0,q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:m.map(e=>(0,q.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,q.jsx)(`div`,{className:`text-sm font-medium truncate text-foreground group-hover/sess:text-primary`,children:p[e.id]||e.title||`(empty)`}),(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model,e.tokenTotal>0&&(0,q.jsxs)(`span`,{className:`ml-2`,children:[`· `,e.tokenTotal.toLocaleString(),` tok`]})]})]},e.id))})]}),l.length>0&&(0,q.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,q.jsx)(Et,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Recent prompts`})]}),(0,q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:l.filter(e=>!e.startsWith(`/`)).slice(0,5).map((e,t)=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>Ns(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,q.jsxs)(`div`,{className:`rounded-xl border bg-muted/20 p-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-3`,children:[(0,q.jsx)($n,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground font-medium`,children:`Quick commands`})]}),(0,q.jsx)(`div`,{className:`grid grid-cols-2 md:grid-cols-4 gap-2`,children:Ms.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>Ns(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,q.jsx)(`span`,{className:`font-mono text-xs text-foreground`,children:e.name}),(0,q.jsx)(`span`,{className:`text-[11px] text-muted-foreground truncate`,children:e.hint})]},e.name))})]})]})}function Fs(){let e=U(e=>e.thinkingBuffer);if(!e)return null;let t=e.split(`
|
|
109
|
-
`).slice(-6).join(`
|
|
110
|
-
`).trim();return(0,q.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,q.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,q.jsx)(xe,{className:`h-4 w-4 animate-pulse`})}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-1 max-w-[85%] min-w-0`,children:[(0,q.jsx)(`span`,{className:`text-xs font-medium text-violet-600 dark:text-violet-400 px-1`,children:`Thinking…`}),(0,q.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,q.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-sans text-xs leading-relaxed italic max-h-32 overflow-hidden`,children:t||`…`})})]})]})}var Is=(0,V.memo)(function({row:e,isLoading:t,compactMode:n,isFirstRow:r}){let i=Z(`mx-auto max-w-5xl w-full px-4`,r&&`pt-4`,n?`pb-3`:`pb-6`);return e.kind===`day`?(0,q.jsx)(`div`,{className:i,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-3 py-1 text-[11px] text-muted-foreground/70 uppercase tracking-wider font-medium`,children:[(0,q.jsx)(`div`,{className:`flex-1 h-px bg-border/50`}),(0,q.jsx)(`span`,{children:e.label}),(0,q.jsx)(`div`,{className:`flex-1 h-px bg-border/50`})]})}):e.kind===`user`?(0,q.jsx)(`div`,{className:i,children:(0,q.jsx)(ws,{message:e.message,isFirst:!0})}):(0,q.jsx)(`div`,{className:i,children:(0,q.jsx)(`div`,{className:Z(`chat-turn`,n?`space-y-1`:`space-y-1.5`),children:e.items.map(n=>{if(n.kind===`msg`)return(0,q.jsx)(ws,{message:n.message,isFirst:n.isFirst,isContinuation:n.isContinuation},n.key);let r=e.isLastTurn&&n.isLastGroup&&t&&n.hasRunningTool;return(0,q.jsx)(As,{tools:n.tools,defaultOpen:r,isContinuation:n.isContinuation},n.key)})})})});function Ls(){let e=U(e=>e.messages),t=U(e=>e.isLoading),n=K(e=>e.sidebarOpen),r=K(e=>e.toggleSidebar),i=K(e=>e.compactMode),{totalTokens:a,startTime:o,lastInputTokens:s,maxContext:c,iteration:l}=G(),u=G(e=>e.session),d=u?.id,f=K(e=>d?e.sessionNicknames[d]:void 0),p=K(e=>e.setSessionNickname),m=u?.title,[h,g]=(0,V.useState)(!1),[_,v]=(0,V.useState)(``),y=Nr(e=>e.entries),[b,x]=(0,V.useState)(!1),S=(0,V.useRef)(null);(0,V.useEffect)(()=>{if(!b)return;let e=e=>{S.current?.contains(e.target)||x(!1)},t=e=>{e.key===`Escape`&&x(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[b]);let{provider:C,model:w}=W(),T=(0,V.useRef)(null),E=(0,V.useMemo)(()=>Io(e),[e]),D=(0,V.useRef)(0);D.current=E.length+1;let O=(0,V.useMemo)(()=>{let e=new Map;return E.forEach((t,n)=>{if(t.kind===`user`)e.set(t.message.id,n);else if(t.kind===`agent`)for(let r of t.items)if(r.kind===`msg`)e.set(r.message.id,n);else for(let t of r.tools)e.set(t.id,n)}),e},[E]),k=K(e=>e.scrollTarget),A=ni(e=>e.autonomy),j=(0,V.useCallback)(e=>{ni.getState().set({autonomy:e}),H()?.send?.({type:`autonomy.switch`,payload:{mode:e}})},[]),[M,N]=(0,V.useState)(!1),[P,F]=(0,V.useState)(!1),[I,L]=(0,V.useState)(!1);(0,V.useEffect)(()=>{let e=()=>L(!0);return document.addEventListener(`open:context-breakdown`,e),()=>document.removeEventListener(`open:context-breakdown`,e)},[]);let ne=c>0&&s>0?Math.round(s/c*100):0,[R,re]=(0,V.useState)(!0),[ie,ae]=(0,V.useState)(0),[oe,se]=(0,V.useState)(!1),ce=(0,V.useRef)(e.length),le=(0,V.useCallback)(()=>{let e=T.current;if(!e)return;let t=e.scrollSize-e.scrollOffset-e.viewportSize<120;re(t),t&&(ae(0),ce.current=U.getState().messages.length),se(e.scrollOffset>e.viewportSize&&e.scrollSize>e.viewportSize*2.5)},[]),ue=(0,V.useCallback)(e=>{H()?.resumeSession?.(e),x(!1)},[]);(0,V.useEffect)(()=>{let t=T.current;if(t)if(R)t.scrollToIndex(D.current-1,{align:`end`}),ce.current=e.length;else{let t=e.length-ce.current;t>0&&ae(t)}},[e,R]),(0,V.useEffect)(()=>{re(!0),ae(0),ce.current=U.getState().messages.length,requestAnimationFrame(()=>{T.current?.scrollToIndex(D.current-1,{align:`end`})})},[d]),(0,V.useEffect)(()=>{if(!k)return;let e=O.get(k.id);e!==void 0&&T.current?.scrollToIndex(e,{align:`center`,smooth:!0})},[k,O]);let de=(0,V.useCallback)(()=>{T.current?.scrollToIndex(D.current-1,{align:`end`,smooth:!0}),re(!0),ae(0),ce.current=U.getState().messages.length},[]),fe=(0,V.useCallback)(()=>{T.current?.scrollToIndex(0,{align:`start`,smooth:!0})},[]),[me,he]=(0,V.useState)(null),[ge,_e]=(0,V.useState)(()=>Date.now()),ve=(0,V.useRef)(null),ye=(0,V.useMemo)(()=>{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=me?Math.max(0,Math.floor((ge-me)/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,ge-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{label:r,elapsed:a,speedLabel:o}},[e,ge,me]);(0,V.useEffect)(()=>{t&&me===null&&he(Date.now()),!t&&me!==null&&he(null)},[t,me]),(0,V.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,q.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,q.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,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1 overflow-hidden`,children:[!n&&(0,q.jsx)($,{variant:`ghost`,size:`icon`,className:`h-7 w-7 shrink-0`,onClick:r,title:`Open sidebar (Ctrl+\\\\)`,children:(0,q.jsx)(it,{className:`h-4 w-4`})}),!n&&(0,q.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0 mr-1`,children:(0,q.jsx)(`div`,{className:`w-5 h-5 rounded bg-primary flex items-center justify-center`,children:(0,q.jsx)(Dn,{className:`h-3 w-3 text-primary-foreground`})})}),(0,q.jsxs)(`span`,{className:Z(`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,q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-current animate-pulse`}),(0,q.jsx)(`span`,{children:xe})]}),d&&(h?(0,q.jsx)(`input`,{value:_,onChange:e=>v(e.target.value),onBlur:()=>{_.trim()&&p(d,_),g(!1)},onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),_.trim()&&p(d,_),g(!1)):e.key===`Escape`&&(e.preventDefault(),g(!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,q.jsxs)(`button`,{type:`button`,onClick:()=>{v(f||m||``),g(!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,q.jsx)(ee,{className:`h-2.5 w-2.5 text-muted-foreground shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:f||m||`Untitled`})]}))]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[y.length>1&&(0,q.jsxs)(`div`,{ref:S,className:`relative shrink-0`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>x(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,q.jsx)(Gn,{className:`h-3 w-3`}),(0,q.jsx)(Kn,{className:`h-2.5 w-2.5`})]}),b&&(0,q.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:y.slice(0,15).map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>ue(e.id),className:Z(`w-full text-left px-2 py-1.5 rounded text-xs hover:bg-accent transition-colors`,e.isCurrent&&`bg-primary/10`),children:[(0,q.jsx)(`div`,{className:`font-medium truncate`,children:e.title||`(empty)`}),(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[e.provider,`/`,e.model,` · `,e.tokenTotal.toLocaleString(),` tok`]})]},e.id))})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>K.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,q.jsx)(hn,{className:`h-3 w-3 text-muted-foreground group-hover:text-foreground shrink-0`}),(0,q.jsxs)(`span`,{className:`font-mono truncate max-w-[9rem] xl:max-w-[16rem]`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:C||`no-provider`}),(0,q.jsx)(`span`,{className:`text-muted-foreground/40 mx-0.5`,children:`/`}),(0,q.jsx)(`span`,{className:`font-medium`,children:w||`no-model`})]})]}),(0,q.jsxs)(`div`,{className:`hidden md:flex items-center gap-1.5 shrink-0`,children:[(0,q.jsx)(Ts,{}),(0,q.jsx)(Mo,{})]}),l&&(0,q.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,q.jsx)(ir,{className:`h-3 w-3 animate-pulse`}),`iter `,l.index,l.max>0?`/${l.max}`:``]}),(0,q.jsx)(oo,{value:A,onChange:j,compact:!0})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,q.jsxs)($,{variant:M?`secondary`:`ghost`,size:`icon`,className:Z(`h-7 w-7 relative`,M&&`bg-amber-500/10 text-amber-600 dark:text-amber-400`),onClick:()=>N(e=>!e),title:`Running processes`,children:[(0,q.jsx)(Un,{className:`h-4 w-4`}),M&&(0,q.jsx)(`span`,{className:`absolute -bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-amber-500`})]}),(0,q.jsxs)($,{variant:P?`secondary`:`ghost`,size:`icon`,className:Z(`h-7 w-7 relative`,P&&`bg-violet-500/10 text-violet-600 dark:text-violet-400`),onClick:()=>F(e=>!e),title:`Session checkpoints — rewind`,children:[(0,q.jsx)(Gn,{className:`h-4 w-4`}),P&&(0,q.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,q.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,q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1 tabular-nums`,children:[s>0&&(0,q.jsx)(Vo,{pct:ne,tokens:s,maxTokens:c>0?c:void 0,onClick:()=>L(!0)}),a.input>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:No(a.input)}),(0,q.jsx)(`span`,{children:`in`})]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:No(a.output)}),(0,q.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,q.jsxs)(`span`,{className:`flex items-center gap-1`,title:`Cache hit ratio: ${t}%`,children:[(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:No(a.cacheRead)}),(0,q.jsxs)(`span`,{children:[`cache (`,t,`%)`]})]})})(),(0,q.jsx)(Uo,{})]})]}),o&&(0,q.jsx)(`span`,{className:`text-muted-foreground/70 tabular-nums shrink-0`,children:be(o)})]})]}),(0,q.jsxs)(`div`,{className:`flex-1 relative overflow-hidden`,children:[(0,q.jsx)(Os,{}),!R&&(0,q.jsxs)(`button`,{type:`button`,onClick:de,className:Z(`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,q.jsx)(te,{className:`h-3.5 w-3.5`}),ie>0?`${ie} new message${ie===1?``:`s`}`:`Jump to latest`]}),oe&&(0,q.jsxs)(`button`,{type:`button`,onClick:fe,title:`Scroll to top (oldest)`,className:Z(`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,q.jsx)(pe,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:`Top`})]}),E.length===0&&!t?(0,q.jsx)(`div`,{className:`mx-auto max-w-5xl w-full px-4 pt-4`,children:(0,q.jsx)(Ps,{})}):(0,q.jsxs)(at,{ref:T,className:`h-full`,onScroll:le,children:[E.map((e,n)=>(0,q.jsx)(Is,{row:e,isLoading:t,compactMode:i,isFirstRow:n===0},e.key)),(0,q.jsxs)(`div`,{id:`chat-activity`,className:Z(`mx-auto max-w-5xl w-full px-4`,i?`pb-3`:`pb-8`),children:[(0,q.jsx)(Fs,{}),t&&(0,q.jsxs)(`div`,{className:`flex gap-3 animate-message`,children:[(0,q.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,q.jsx)(Qt,{className:`h-4 w-4`})}),(0,q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:(0,q.jsx)(`div`,{className:`rounded-2xl px-4 py-3 bg-card border text-foreground`,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,q.jsxs)(`span`,{className:`flex gap-1`,children:[(0,q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.3s]`}),(0,q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce [animation-delay:-0.15s]`}),(0,q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-primary/70 animate-bounce`})]}),(0,q.jsx)(`span`,{className:`text-foreground/90`,children:ye.label}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:ye.elapsed}),l&&(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[`· iter `,l.index,l.max>0?`/${l.max}`:``]}),ye.speedLabel&&(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground/80 tabular-nums`,children:[`· `,ye.speedLabel]})]})})})]})]},`__live`)]})]}),(0,q.jsxs)(`div`,{className:`border-t bg-card/50 backdrop-blur supports-[backdrop-filter]:bg-card/50 shrink-0`,children:[(0,q.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,q.jsxs)(`span`,{title:`Enter`,className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{children:`Enter`}),` send`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{title:`Shift+Enter`,className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{children:`Shift`}),`+`,(0,q.jsx)(`kbd`,{children:`↵`}),` newline`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{title:`Ctrl+\\\\`,className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{children:`Ctrl+\\`}),` sidebar`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{title:`Ctrl+F`,className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{children:`Ctrl+F`}),` search`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{title:`Ctrl+K`,className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{children:`Ctrl+K`}),` palette`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{title:`Ctrl+L / Ctrl+N`,className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{children:`Ctrl+L`}),` clear`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{title:`j/k to navigate`,className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{children:`j`}),(0,q.jsx)(`kbd`,{children:`k`}),` navigate`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{title:`Ctrl+M`,className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{children:`Ctrl+M`}),` model`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{title:`Ctrl+Shift+D`,className:`inline-flex items-center gap-1`,children:[(0,q.jsx)(`kbd`,{children:`Ctrl+⇧D`}),` density`]})]}),(0,q.jsx)(`div`,{className:`p-4`,children:(0,q.jsx)(`div`,{className:`max-w-5xl mx-auto`,children:(0,q.jsx)(ko,{onOpenBreakdown:()=>L(!0)})})})]}),(0,q.jsx)(Es,{open:M,onClose:()=>N(!1)}),(0,q.jsx)(Ao,{open:P,onClose:()=>F(!1)}),(0,q.jsx)(Ho,{open:I,onClose:()=>L(!1)})]})}k.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`}}),k.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 Rs(){return typeof document>`u`||document.documentElement.classList.contains(`dark`)?`wrongstack-dark`:`wrongstack-light`}xn.config({monaco:Xe});var zs={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 Bs(e){return zs[e.split(`.`).pop()?.toLowerCase()??``]??`plaintext`}function Vs(){let e=Y(e=>e.openFiles),t=Y(e=>e.activeFilePath),n=Y(e=>e.setActiveFile),r=Y(e=>e.closeFile);return e.length===0?null:(0,q.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,q.jsxs)(`button`,{type:`button`,onClick:()=>n(e.path),onMouseDown:t=>{t.button===1&&(t.preventDefault(),r(e.path))},className:Z(`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,q.jsx)(yn,{className:`h-2 w-2 fill-current text-primary shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:a}),(0,q.jsx)(Gt,{className:Z(`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 Hs(){let e=Y(e=>e.openFiles),t=Y(e=>e.activeFilePath),n=Y(e=>e.updateContent),{theme:r}=Aa(),i=(0,V.useRef)(null),a=(0,V.useMemo)(()=>e.find(e=>e.path===t)??null,[e,t]),o=t?Bs(t):`plaintext`,s=Rs();(0,V.useEffect)(()=>{let e=Rs();k.setTheme(e)},[r]);let c=(0,V.useCallback)(e=>{i.current=e,k.setTheme(Rs())},[]),l=(0,V.useCallback)(e=>{t&&e!==void 0&&n(t,e)},[t,n]);return(0,V.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&&Y.getState().closeFile(t)))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e.length===0?(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,q.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No files open`}),(0,q.jsx)(`p`,{className:`text-[11px] text-muted-foreground/60`,children:`Select a file from the explorer to start editing`})]})}):(0,q.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,q.jsx)(Vs,{}),(0,q.jsx)(`div`,{className:`flex-1 relative`,children:a?(0,q.jsx)(ie,{language:o,value:a.content,onChange:l,theme:s,onMount:c,loading:(0,q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,q.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,q.jsx)(`div`,{className:`flex items-center justify-center h-full`,children:(0,q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`Select a tab to view its content`})})})]})}var Us=Ke,Ws=He,Gs=l,Ks=V.forwardRef(({className:e,...t},n)=>(0,q.jsx)(nr,{ref:n,className:Z(`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}));Ks.displayName=nr.displayName;var qs=V.forwardRef(({className:e,children:t,...n},r)=>(0,q.jsxs)(Gs,{children:[(0,q.jsx)(Ks,{}),(0,q.jsxs)(se,{ref:r,className:Z(`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,q.jsxs)(F,{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,q.jsx)(Gt,{className:`h-4 w-4`}),(0,q.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));qs.displayName=se.displayName;var Js=({className:e,...t})=>(0,q.jsx)(`div`,{className:Z(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});Js.displayName=`DialogHeader`;var Ys=({className:e,...t})=>(0,q.jsx)(`div`,{className:Z(`flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2`,e),...t});Ys.displayName=`DialogFooter`;var Xs=V.forwardRef(({className:e,...t},n)=>(0,q.jsx)(j,{ref:n,className:Z(`text-lg font-semibold leading-none tracking-tight`,e),...t}));Xs.displayName=j.displayName;var Zs=V.forwardRef(({className:e,...t},n)=>(0,q.jsx)(Ae,{ref:n,className:Z(`text-sm text-muted-foreground`,e),...t}));Zs.displayName=Ae.displayName;function Qs(e){return/edit|write|create|patch/i.test(e)?Ue:/bash|shell|exec|run|command/i.test(e)?Un:/fetch|http|web|curl|request/i.test(e)?v:ht}function $s({toolName:e,input:t}){let n=os(e,t);if(n)return(0,q.jsx)(`div`,{className:`rounded-lg overflow-hidden border`,children:(0,q.jsx)(rs,{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,q.jsxs)(`div`,{className:`rounded-lg border bg-background/40 overflow-hidden`,children:[(0,q.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,q.jsx)(Un,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:`Command`})]}),(0,q.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,q.jsxs)(`div`,{className:`rounded-lg border bg-background/40 px-3 py-2 text-xs font-mono`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:(e.method??`GET`).toUpperCase()}),` `,(0,q.jsx)(`span`,{className:`break-all`,children:r})]})}return(0,q.jsxs)(`div`,{className:`p-3 rounded-lg bg-muted/50 border text-xs font-mono`,children:[(0,q.jsx)(`div`,{className:`text-muted-foreground mb-2`,children:`Input:`}),(0,q.jsx)(`pre`,{className:`whitespace-pre-wrap break-all max-h-60 overflow-auto`,children:JSON.stringify(t,null,2)})]})}function ec(){let{showConfirmDialog:e,confirmInfo:t,hideConfirm:n}=K(),{sendConfirm:r}=Da(),i=(0,V.useRef)(null),a=e=>{t&&r(t.id,e),n()};if((0,V.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,q.jsx)(Us,{open:e,onOpenChange:()=>n(),children:(0,q.jsx)(qs,{})});let o=Qs(t.toolName),s=/edit|write/i.test(t.toolName);return(0,q.jsx)(Us,{open:e,onOpenChange:()=>n(),children:(0,q.jsxs)(qs,{className:`sm:max-w-2xl border-yellow-500/50`,ref:i,tabIndex:-1,children:[(0,q.jsxs)(Js,{children:[(0,q.jsxs)(Xs,{className:`flex items-center gap-2`,children:[(0,q.jsx)($t,{className:`h-5 w-5 text-yellow-500 animate-pulse`}),`Approval required: `,t.toolName]}),(0,q.jsxs)(Zs,{children:[`The agent wants to `,s?`modify a file`:`run this tool`,`. Review the request below and decide whether to proceed.`]})]}),(0,q.jsxs)(`div`,{className:`py-2 space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3 p-3 rounded-lg bg-muted`,children:[(0,q.jsx)(o,{className:`h-5 w-5 text-muted-foreground`}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`div`,{className:`font-medium font-mono truncate`,children:t.toolName}),(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[s?`File modification`:`Tool execution`,` — preview below`]})]})]}),t.input!==void 0&&(0,q.jsx)($s,{toolName:t.toolName,input:t.input}),t.suggestedPattern&&(0,q.jsxs)(`div`,{className:`flex items-start gap-2 p-3 rounded-lg bg-yellow-500/10 border border-yellow-500/20`,children:[(0,q.jsx)(bn,{className:`h-4 w-4 text-yellow-600 mt-0.5 shrink-0`}),(0,q.jsxs)(`div`,{className:`text-sm min-w-0`,children:[(0,q.jsx)(`div`,{className:`font-medium text-yellow-800 dark:text-yellow-200`,children:`Trust pattern suggestion`}),(0,q.jsx)(`div`,{className:`font-mono text-xs mt-1 break-all`,children:t.suggestedPattern}),(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Picking `,(0,q.jsx)(`span`,{className:`font-medium`,children:`Always`}),` will whitelist matching calls for this project.`]})]})]})]}),(0,q.jsxs)(Ys,{className:`gap-2 sm:gap-2 flex-wrap`,children:[(0,q.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`deny`),title:`Reject this and all future calls matching the pattern (d)`,children:[`Deny always `,(0,q.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`d`})]}),(0,q.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`no`),title:`Reject this single call (Esc / n)`,children:[`No `,(0,q.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`n`})]}),(0,q.jsxs)($,{variant:`outline`,size:`sm`,onClick:()=>a(`always`),title:`Approve and remember the pattern for the project (a)`,children:[`Always `,(0,q.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background`,children:`a`})]}),(0,q.jsxs)($,{size:`sm`,onClick:()=>a(`yes`),title:`Approve this single call (y)`,children:[`Yes `,(0,q.jsx)(`kbd`,{className:`ml-1 text-[10px] border rounded px-1 bg-background/80`,children:`y`})]})]})]})})}var tc=Je()((e,t)=>({request:null,open:n=>{t().request?.resolve(!1),e({request:n})},settle:n=>{t().request?.resolve(n),e({request:null})}}));function nc(e){return new Promise(t=>{tc.getState().open({...e,resolve:t})})}function rc(){let e=tc(e=>e.request),t=tc(e=>e.settle);return(0,V.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Enter`&&(e.preventDefault(),tc.getState().settle(!0))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,q.jsx)(Us,{open:e!==null,onOpenChange:e=>{e||t(!1)},children:(0,q.jsxs)(qs,{className:`max-w-md`,children:[(0,q.jsxs)(Js,{children:[(0,q.jsx)(Xs,{children:e?.title}),e?.message&&(0,q.jsx)(Zs,{children:e.message})]}),(0,q.jsxs)(Ys,{className:`gap-2`,children:[(0,q.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>t(!1),children:e?.cancelLabel??`Cancel`}),(0,q.jsx)($,{variant:e?.danger?`destructive`:`default`,size:`sm`,autoFocus:!0,onClick:()=>t(!0),children:e?.confirmLabel??`Confirm`})]})]})})}function ic(){let e=W(e=>e.wsStatus),t=W(e=>e.wsUrl),[n,r]=(0,V.useState)(!1),[i,a]=(0,V.useState)(Date.now());if((0,V.useEffect)(()=>{if(e.state!==`reconnecting`)return;let t=setInterval(()=>a(Date.now()),500);return()=>clearInterval(t)},[e.state]),(0,V.useEffect)(()=>{e.state===`open`&&r(!1)},[e.state]),e.state===`open`||e.state===`connecting`||n)return null;let o=()=>H(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,q.jsxs)(`div`,{className:Z(`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,q.jsx)(z,{className:`h-4 w-4 animate-spin shrink-0`}):(0,q.jsx)(jn,{className:`h-4 w-4 shrink-0`}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`font-medium`,children:s?`Reconnecting to backend (attempt ${e.attempt}) — retrying in ${l}s`:`Disconnected from backend`}),c&&(0,q.jsx)(`div`,{className:`text-xs opacity-80 truncate`,children:c})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:o,className:Z(`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,q.jsx)(L,{className:`h-3 w-3`}),`Retry now`]}),(0,q.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,q.jsx)(Gt,{className:`h-4 w-4`})})]})}var ac=class extends V.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,q.jsx)(`div`,{className:`flex items-center justify-center h-screen bg-background`,children:(0,q.jsxs)(`div`,{className:`flex flex-col items-center gap-4 p-8 max-w-md text-center`,children:[(0,q.jsx)(bn,{className:`h-12 w-12 text-destructive`}),(0,q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Something went wrong`}),(0,q.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,q.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,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>window.location.reload(),children:[(0,q.jsx)(ar,{className:`h-4 w-4 mr-1`}),`Reload page`]}),(0,q.jsx)($,{size:`sm`,onClick:this.handleReset,children:`Try again`})]})]})}):this.props.children}};function oc(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 sc(){let e=K(e=>e.modelSwitcherOpen),t=K(e=>e.setModelSwitcherOpen),[n,r]=(0,V.useState)(``),[i,a]=(0,V.useState)(0),[o,s]=(0,V.useState)([]),[c,l]=(0,V.useState)({}),u=(0,V.useRef)(null),d=W(e=>e.wsUrl),f=W(e=>e.provider),p=W(e=>e.model),m=K(e=>e.paletteOpen),{listSavedProviders:h,listProviderModels:g,switchModel:_}=Da();(0,V.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,V.useEffect)(()=>{let e=H(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,V.useEffect)(()=>{e&&(r(``),a(0),h(),requestAnimationFrame(()=>u.current?.focus()))},[e,h]),(0,V.useEffect)(()=>{if(e)for(let e of o)c[e.id]||g(e.id)},[e,o,c,g]);let v=(0,V.useMemo)(()=>oc(o,c,n,f,p),[o,c,n,f,p]);(0,V.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,q.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,q.jsxs)(`div`,{className:`w-full max-w-xl rounded-xl border bg-popover shadow-2xl overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,q.jsx)(ve,{className:`h-4 w-4 text-muted-foreground`}),(0,q.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,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:`↑↓ · Enter · Esc`})]}),(0,q.jsx)(`div`,{className:`max-h-[50vh] overflow-y-auto py-1`,children:v.length===0?(0,q.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,q.jsxs)(`button`,{type:`button`,onClick:()=>y(t),onMouseEnter:()=>a(t),className:Z(`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,q.jsx)(hn,{className:Z(`h-4 w-4 shrink-0`,e.isCurrent?`text-primary`:`text-muted-foreground`)}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`truncate`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:e.provider}),(0,q.jsx)(`span`,{className:`mx-1 text-muted-foreground/40`,children:`·`}),(0,q.jsx)(`span`,{children:e.modelName})]}),e.contextWindow&&(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono`,children:[e.model,` · ctx `,e.contextWindow.toLocaleString()]})]}),e.isCurrent?(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-primary font-semibold`,children:`active`}):(0,q.jsx)(Te,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 group-hover:opacity-100`})]},`${e.provider}:${e.model}`))})]})}):null}var cc=V.forwardRef(({className:e,type:t,...n},r)=>(0,q.jsx)(`input`,{type:t,className:Z(`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}));cc.displayName=`Input`;var lc=V.forwardRef(({className:e,children:t,...n},r)=>(0,q.jsxs)(de,{ref:r,className:Z(`relative overflow-hidden`,e),...n,children:[(0,q.jsx)(T,{className:`h-full w-full rounded-[inherit]`,children:t}),(0,q.jsx)(uc,{}),(0,q.jsx)(Kt,{})]}));lc.displayName=de.displayName;var uc=V.forwardRef(({className:e,orientation:t=`vertical`,...n},r)=>(0,q.jsx)(he,{ref:r,orientation:t,className:Z(`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,q.jsx)(Ce,{className:`relative flex-1 rounded-full bg-border`})}));uc.displayName=he.displayName;var dc=Xt,fc=V.forwardRef(({className:e,...t},n)=>(0,q.jsx)(ye,{ref:n,className:Z(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,e),...t}));fc.displayName=ye.displayName;var pc=V.forwardRef(({className:e,...t},n)=>(0,q.jsx)(a,{ref:n,className:Z(`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}));pc.displayName=a.displayName;var mc=V.forwardRef(({className:e,...t},n)=>(0,q.jsx)(_,{ref:n,className:Z(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));mc.displayName=_.displayName;var hc=De(`inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground hover:bg-primary/80`,secondary:`border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80`,destructive:`border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80`,outline:`text-foreground`}},defaultVariants:{variant:`default`}});function gc({className:e,variant:t,...n}){return(0,q.jsx)(`div`,{className:Z(hc({variant:t}),e),...n})}var _c=[{name:`filesystem`,description:`Read, write, and navigate the local filesystem. Good for exploring projects.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-filesystem`,`.`]},{name:`github`,description:`GitHub API — issues, PRs, repos, search, and file operations.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-github`],requiresEnvVars:[`GITHUB_PERSONAL_ACCESS_TOKEN`],badge:`Popular`},{name:`context7`,description:`Codebase-aware documentation and Q&A grounded in your actual library versions.`,transport:`streamable-http`,url:`https://mcp.context7.com/mcp`,badge:`New`},{name:`brave-search`,description:`Web search via Brave Browser. Free tier: 2,000 queries/month.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-brave-search`],requiresEnvVars:[`BRAVE_SEARCH_API_KEY`]},{name:`google-maps`,description:`Directions, geocoding, places, and distance matrix via Google Maps.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-google-maps`],requiresEnvVars:[`GOOGLE_MAPS_API_KEY`]},{name:`aws`,description:`AWS — EC2, S3, Lambda, IAM, CloudFormation, and cost management.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-aws`],requiresEnvVars:[`AWS_ACCESS_KEY_ID`,`AWS_SECRET_ACCESS_KEY`]},{name:`slack`,description:`Slack — messaging, channels, and search.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-slack`],requiresEnvVars:[`SLACK_BOT_TOKEN`]},{name:`everart`,description:`AI image generation via multiple providers.`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-everart`],requiresEnvVars:[`EVERART_API_KEY`]},{name:`sentinel`,description:`Security vulnerability scanning via Sentinel.`,transport:`streamable-http`,url:`https://mcp.sentinel.ai`,badge:`Security`},{name:`playwright`,description:`Browser automation — navigate, click, type, screenshot, evaluate JS (headless Chromium).`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-playwright`],badge:`Browser`},{name:`zai-vision`,description:`Image analysis, screenshot understanding, and diagram interpretation.`,transport:`stdio`,command:`npx`,args:[`-y`,`@z_ai/mcp-server@latest`],env:{Z_AI_MODE:`ZAI`},requiresEnvVars:[`Z_AI_API_KEY`],allowedTools:[`image_analysis`,`extract_text_from_screenshot`,`diagnose_error_screenshot`,`understand_technical_diagram`,`analyze_data_visualization`,`ui_diff_check`],badge:`Vision`},{name:`minimax-vision`,description:`MiniMax image understanding via understand_image (read-only, safe for auto-run).`,transport:`stdio`,command:`uvx`,args:[`minimax-coding-plan-mcp`,`-y`],env:{MINIMAX_MCP_BASE_PATH:`./.wrongstack/minimax-output`,MINIMAX_API_HOST:`https://api.minimax.io`,MINIMAX_API_RESOURCE_MODE:`url`},requiresEnvVars:[`MINIMAX_API_KEY`],allowedTools:[`understand_image`],badge:`Vision`},{name:`block`,description:`Postgres database access via SQL (Block MCP server).`,transport:`stdio`,command:`npx`,args:[`-y`,`@modelcontextprotocol/server-block`],requiresEnvVars:[`DATABASE_URL`]}];function vc(e,t=!1){return{name:e.name,description:e.description,transport:e.transport,command:e.command,args:e.args,url:e.url,env:e.env,allowedTools:e.allowedTools,enabled:t}}function yc(e){switch(e){case`connected`:return{label:`Connected`,color:`bg-green-500`};case`connecting`:return{label:`Connecting`,color:`bg-yellow-500`};case`sleeping`:return{label:`Sleeping`,color:`bg-blue-500`};case`discovering`:return{label:`Discovering`,color:`bg-purple-500`};case`error`:return{label:`Error`,color:`bg-red-500`};case`stopped`:return{label:`Stopped`,color:`bg-gray-500`};default:return{label:`Unknown`,color:`bg-gray-400`}}}function bc({status:e}){let{color:t}=yc(e);return(0,q.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full ${t}`})}function xc({server:e,onWake:t,onSleep:n,onDiscover:r,onEdit:i,onRemove:a}){let[o,s]=(0,V.useState)(!1),{color:c}=yc(e.status);return(0,q.jsxs)(`div`,{className:`border rounded-lg p-3 bg-card`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`button`,{className:`flex items-center gap-2 flex-1 text-left`,onClick:()=>s(!o),children:[o?(0,q.jsx)(Kn,{className:`w-4 h-4`}):(0,q.jsx)(Ie,{className:`w-4 h-4`}),(0,q.jsx)(bc,{status:e.status}),(0,q.jsx)(`span`,{className:`font-medium`,children:e.name}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.transport}),!e.enabled&&(0,q.jsx)(gc,{variant:`outline`,className:`text-xs`,children:`Disabled`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,onClick:e=>e.stopPropagation(),children:[e.status===`sleeping`&&(0,q.jsx)($,{variant:`ghost`,size:`sm`,onClick:t,title:`Wake server`,children:(0,q.jsx)(yt,{className:`w-4 h-4`})}),(e.status===`connected`||e.status===`connecting`)&&(0,q.jsx)($,{variant:`ghost`,size:`sm`,onClick:n,title:`Sleep server`,children:(0,q.jsx)(Nn,{className:`w-4 h-4`})}),(e.status===`stopped`||e.status===`sleeping`)&&(0,q.jsx)($,{variant:`ghost`,size:`sm`,onClick:r,title:`Discover tools`,children:(0,q.jsx)(ve,{className:`w-4 h-4`})}),(0,q.jsx)($,{variant:`ghost`,size:`sm`,onClick:i,title:`Edit`,children:(0,q.jsx)(oe,{className:`w-4 h-4`})}),(0,q.jsx)($,{variant:`ghost`,size:`sm`,onClick:a,title:`Remove`,className:`text-destructive hover:text-destructive`,children:(0,q.jsx)(Lt,{className:`w-4 h-4`})})]})]}),o&&(0,q.jsxs)(`div`,{className:`mt-3 pl-6 text-sm space-y-2`,children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-1`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Status:`}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full ${c}`}),yc(e.status).label]}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Enabled:`}),(0,q.jsx)(`span`,{children:e.enabled?`Yes`:`No`}),e.description&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Description:`}),(0,q.jsx)(`span`,{children:e.description})]}),e.pid&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`PID:`}),(0,q.jsx)(`span`,{children:e.pid})]}),e.error&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Error:`}),(0,q.jsx)(`span`,{className:`text-destructive`,children:e.error})]})]}),e.tools&&e.tools.length>0&&(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[`Tools (`,e.tools.length,`):`]}),(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:e.tools.map(e=>(0,q.jsx)(gc,{variant:`secondary`,className:`text-xs`,children:e},e))})]}),(!e.tools||e.tools.length===0)&&e.status===`connected`&&(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`No tools discovered yet`})]})]})}function Sc({open:e,onOpenChange:t,server:n,onSave:r,prefillConfig:i}){let[a,o]=(0,V.useState)(n?.name??i?.name??``),[s,c]=(0,V.useState)(n?.transport??i?.transport??`stdio`),[l,u]=(0,V.useState)(n?.description??i?.description??``),[d,f]=(0,V.useState)(i?.command??``),[p,m]=(0,V.useState)(i?.args?.join(` `)??``),[h,g]=(0,V.useState)(``),[_,v]=(0,V.useState)(i?.url??``),[y,b]=(0,V.useState)(n?.enabled??!0);(0,V.useEffect)(()=>{e&&(n?(o(n.name),c(n.transport),u(n.description??``),b(n.enabled),f(``),m(``),g(``),v(``)):i?(o(i.name),c(i.transport),u(i.description??``),b(!0),f(i.command??``),m(i.args?.join(` `)??``),g(i.env?Object.entries(i.env).map(([e,t])=>`${e}=${t}`).join(`
|
|
111
|
-
`):``),v(i.url??``)):(o(``),c(`stdio`),u(``),b(!0),f(``),m(``),g(``),v(``)))},[n,i,e]);let x=()=>{if(!a.trim()){Q.error(`Server name is required`);return}let e={};if(h.trim())for(let t of h.trim().split(`
|
|
112
|
-
`)){let n=t.indexOf(`=`);n>0&&(e[t.slice(0,n).trim()]=t.slice(n+1).trim())}r({name:a.trim(),transport:s,description:l.trim()||void 0,enabled:y,command:d.trim()||void 0,args:p.trim()?p.trim().split(/\s+/):void 0,env:Object.keys(e).length>0?e:void 0,url:_.trim()||void 0}),t(!1)},S=!!n,C=!!i;return(0,q.jsx)(Us,{open:e,onOpenChange:t,children:(0,q.jsxs)(qs,{children:[(0,q.jsx)(Js,{children:(0,q.jsx)(Xs,{children:S?`Edit MCP Server`:C?`Add MCP Server`:`Add Custom MCP Server`})}),(0,q.jsxs)(`div`,{className:`space-y-4 py-4`,children:[(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`label`,{className:`text-sm font-medium`,children:`Name`}),(0,q.jsx)(cc,{value:a,onChange:e=>o(e.target.value),placeholder:`e.g., github, filesystem`,disabled:S||C})]}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`label`,{className:`text-sm font-medium`,children:`Transport`}),(0,q.jsxs)(`select`,{className:`w-full h-10 px-3 rounded-md border border-input bg-background text-sm`,value:s,onChange:e=>c(e.target.value),disabled:C,children:[(0,q.jsx)(`option`,{value:`stdio`,children:`stdio`}),(0,q.jsx)(`option`,{value:`sse`,children:`sse`}),(0,q.jsx)(`option`,{value:`streamable-http`,children:`streamable-http`}),(0,q.jsx)(`option`,{value:`http`,children:`http`})]})]}),(s===`streamable-http`||s===`sse`||s===`http`)&&(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`label`,{className:`text-sm font-medium`,children:`URL`}),(0,q.jsx)(cc,{value:_,onChange:e=>v(e.target.value),placeholder:`https://mcp.example.com/mcp`,disabled:C})]}),s===`stdio`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`label`,{className:`text-sm font-medium`,children:`Command`}),(0,q.jsx)(cc,{value:d,onChange:e=>f(e.target.value),placeholder:`e.g., npx`,disabled:C})]}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`label`,{className:`text-sm font-medium`,children:[`Args `,(0,q.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(space-separated)`})]}),(0,q.jsx)(cc,{value:p,onChange:e=>m(e.target.value),placeholder:`e.g., -y @modelcontextprotocol/server-github`,disabled:C})]})]}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`label`,{className:`text-sm font-medium`,children:[`Env vars`,` `,(0,q.jsx)(`span`,{className:`text-muted-foreground font-normal`,children:`(KEY=value, one per line)`})]}),(0,q.jsx)(`textarea`,{className:`w-full h-20 px-3 py-2 rounded-md border border-input bg-background text-sm font-mono resize-none`,value:h,onChange:e=>g(e.target.value),placeholder:`GITHUB_TOKEN=ghp_...
|
|
113
|
-
AWS_REGION=us-east-1`,disabled:C})]}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`label`,{className:`text-sm font-medium`,children:`Description`}),(0,q.jsx)(cc,{value:l,onChange:e=>u(e.target.value),placeholder:`GitHub MCP server for repository access`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`input`,{type:`checkbox`,id:`server-enabled`,checked:y,onChange:e=>b(e.target.checked),className:`rounded`}),(0,q.jsx)(`label`,{htmlFor:`server-enabled`,className:`text-sm`,children:`Enable server`})]})]}),(0,q.jsxs)(Ys,{children:[(0,q.jsx)($,{variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,q.jsx)($,{onClick:x,children:S?`Save Changes`:`Add Server`})]})]})})}function Cc({server:e,isAdded:t,onAdd:n}){return(0,q.jsxs)(`div`,{className:`border rounded-lg p-3 bg-card flex items-start justify-between gap-3`,children:[(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),e.badge&&(0,q.jsx)(gc,{variant:`secondary`,className:`text-xs shrink-0`,children:e.badge}),(0,q.jsx)(gc,{variant:`outline`,className:`text-xs shrink-0`,children:e.transport})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e.description}),e.requiresEnvVars&&e.requiresEnvVars.length>0&&(0,q.jsxs)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400 mt-1`,children:[`Requires: `,e.requiresEnvVars.join(`, `)]})]}),(0,q.jsx)(`div`,{className:`shrink-0`,children:t?(0,q.jsxs)($,{variant:`ghost`,size:`sm`,disabled:!0,children:[(0,q.jsx)(Be,{className:`w-4 h-4 mr-1`}),`Added`]}):(0,q.jsxs)($,{size:`sm`,variant:`outline`,onClick:n,children:[(0,q.jsx)(Ye,{className:`w-4 h-4 mr-1`}),`Add`]})})]})}function wc(){let e=Da(),[t,n]=(0,V.useState)([]),[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)(`list`),[s,c]=(0,V.useState)(),[l,u]=(0,V.useState)(!1),[d,f]=(0,V.useState)(!1),[p,m]=(0,V.useState)(),[h,g]=(0,V.useState)(null);(0,V.useEffect)(()=>{if(!e.client)return;let t=e=>{if(e.type===`mcp.list`){let t=e.payload;n(t.servers??[]),i(!1)}},r=e=>{if(e.type===`mcp.server.added`){let t=e.payload;n(e=>[...e.filter(e=>e.name!==t.server.name),t.server]),Q.success(`Server "${t.server.name}" added`)}},a=e=>{if(e.type===`mcp.server.removed`){let t=e.payload;n(e=>e.filter(e=>e.name!==t.name)),Q.success(`Server "${t.name}" removed`)}},o=e=>{if(e.type===`mcp.server.updated`){let t=e.payload;n(e=>e.map(e=>e.name===t.server.name?t.server:e))}},s=e=>{if(e.type===`mcp.server.discovered`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`sleeping`,tools:t.tools}:e)),g(null),Q.success(`Discovered ${t.tools.length} tools from "${t.name}"`)}},c=e=>{if(e.type===`mcp.server.sleeping`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`sleeping`}:e)),g(null),Q.info(`Server "${t.name}" is now sleeping`)}},l=e=>{if(e.type===`mcp.server.waking`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`connecting`}:e))}},u=e=>{if(e.type===`mcp.server.connected`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`connected`,pid:t.pid}:e)),g(null),Q.success(`Server "${t.name}" connected`)}},d=e=>{if(e.type===`mcp.server.error`){let t=e.payload;n(e=>e.map(e=>e.name===t.name?{...e,status:`error`,error:t.error}:e)),g(null),Q.error(`Server "${t.name}" error: ${t.error}`)}},f=e=>{if(e.type===`mcp.operation_result`){let t=e.payload;t.success||Q.error(t.message),g(null)}},p=e.client.on(`mcp.list`,t),m=e.client.on(`mcp.server.added`,r),h=e.client.on(`mcp.server.removed`,a),_=e.client.on(`mcp.server.updated`,o),v=e.client.on(`mcp.server.discovered`,s),y=e.client.on(`mcp.server.sleeping`,c),b=e.client.on(`mcp.server.waking`,l),x=e.client.on(`mcp.server.connected`,u),S=e.client.on(`mcp.server.error`,d),C=e.client.on(`mcp.operation_result`,f);return i(!0),e.client?.listMcpServers(),()=>{p?.(),m?.(),h?.(),_?.(),v?.(),y?.(),b?.(),x?.(),S?.(),C?.()}},[e.client]);let _=(0,V.useCallback)(t=>{e.client?.addMcpServer(t)},[e]),v=(0,V.useCallback)(t=>{let n=vc(t,!0);e.client?.addMcpServer(n)},[e]),y=(0,V.useCallback)(t=>{confirm(`Remove server "${t}"?`)&&e.client?.removeMcpServer(t)},[e]),b=(0,V.useCallback)(e=>{c(e),m(void 0),u(!0)},[]),x=(0,V.useCallback)(t=>{e.client?.updateMcpServer(t)},[e]),S=(0,V.useCallback)(t=>{g(t),e.client?.wakeMcpServer(t)},[e]),C=(0,V.useCallback)(t=>{g(t),e.client?.sleepMcpServer(t)},[e]),w=(0,V.useCallback)(t=>{g(t),e.client?.discoverMcpServer(t)},[e]),T=(0,V.useCallback)(()=>{i(!0),e.client?.listMcpServers()},[e]),E=t.filter(e=>e.status===`connected`).length,D=t.filter(e=>e.status===`sleeping`).length,O=new Set(t.map(e=>e.name));return(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Yt,{className:`w-5 h-5`}),(0,q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`MCP Servers`}),t.length>0&&(0,q.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[E,` connected · `,D,` sleeping · `,t.length,` total`]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsxs)($,{variant:`outline`,size:`sm`,onClick:T,disabled:r,children:[r?(0,q.jsx)(z,{className:`w-4 h-4 animate-spin`}):null,`Refresh`]}),(0,q.jsxs)($,{size:`sm`,onClick:()=>{m(void 0),f(!0)},children:[(0,q.jsx)(Ye,{className:`w-4 h-4 mr-1`}),`Add Custom`]})]})]}),(0,q.jsxs)(dc,{value:a,onValueChange:e=>o(e),children:[(0,q.jsxs)(fc,{children:[(0,q.jsxs)(pc,{value:`recommended`,children:[(0,q.jsx)(Le,{className:`w-3.5 h-3.5 mr-1`}),`Recommended`]}),(0,q.jsx)(pc,{value:`list`,children:`Servers`}),(0,q.jsx)(pc,{value:`add`,children:`Add Custom`})]}),(0,q.jsxs)(mc,{value:`recommended`,className:`space-y-3`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`One-click add for popular MCP servers. Click Add to pre-fill the configuration, then confirm. Servers requiring credentials will need their env vars set before use.`}),(0,q.jsx)(`div`,{className:`grid gap-2`,children:_c.map(e=>(0,q.jsx)(Cc,{server:e,isAdded:O.has(e.name),onAdd:()=>v(e)},e.name))})]}),(0,q.jsx)(mc,{value:`list`,className:`space-y-3`,children:r&&t.length===0?(0,q.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground`,children:[(0,q.jsx)(z,{className:`w-5 h-5 animate-spin mr-2`}),`Loading servers...`]}):t.length===0?(0,q.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,q.jsx)(Yt,{className:`w-10 h-10 mx-auto mb-2 opacity-50`}),(0,q.jsx)(`p`,{children:`No MCP servers configured`}),(0,q.jsx)(`p`,{className:`text-sm`,children:`Switch to the Recommended tab to add popular servers, or Add Custom for your own.`})]}):t.map(e=>(0,q.jsx)(xc,{server:e,onWake:()=>S(e.name),onSleep:()=>C(e.name),onDiscover:()=>w(e.name),onEdit:()=>b(e),onRemove:()=>y(e.name)},e.name))}),(0,q.jsxs)(mc,{value:`add`,children:[(0,q.jsx)(Sc,{open:d,onOpenChange:e=>{e||f(!1)},onSave:_}),(0,q.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[(0,q.jsx)(`p`,{children:`Configure a custom MCP server with stdio, SSE, or HTTP transport.`}),(0,q.jsx)(`p`,{className:`mt-1`,children:`For popular servers, use the Recommended tab instead — everything is pre-configured for you.`})]})]})]}),(0,q.jsx)(Sc,{open:l,onOpenChange:u,server:s,onSave:x})]})}function Tc({provider:e,catalogModels:t,currentCatalogProvider:n,isLoadingModels:r,setIsLoadingModels:i,onModelSelect:a,refreshModels:o}){let s=W(e=>e.model);return(0,q.jsx)(`div`,{className:`space-y-4`,children:e?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:n?.name||e}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e})]}),(0,q.jsx)($,{variant:`ghost`,size:`sm`,onClick:()=>{i(!0),o(e)},children:(0,q.jsx)(ar,{className:Z(`h-4 w-4`,r&&`animate-spin`)})})]}),r&&!t[e]?(0,q.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,q.jsx)(z,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,q.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading models...`})]}):(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(t[e]||[]).map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>a(e.id),className:Z(`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,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`font-medium`,children:e.name||e.id}),(0,q.jsx)(`div`,{className:`flex gap-2 mt-1`,children:e.capabilities.map(e=>(0,q.jsx)(`span`,{className:`text-xs bg-muted px-1.5 py-0.5 rounded`,children:e},e))})]}),(0,q.jsxs)(`div`,{className:`text-right text-xs text-muted-foreground`,children:[e.contextWindow&&(0,q.jsxs)(`div`,{children:[e.contextWindow/1e3,`k context`]}),e.inputCost&&e.outputCost&&(0,q.jsxs)(`div`,{children:[`$`,e.inputCost,`/$`,e.outputCost]}),s===e.id&&(0,q.jsx)(ut,{className:`h-4 w-4 text-primary mt-1`})]})]},e.id)),t[e]?.length===0&&(0,q.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,q.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,q.jsx)(hn,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,q.jsx)(`p`,{children:`Select a provider first`})]})})}function Ec({label:e,hint:t,value:n,min:r,max:i,step:a=1,onChange:o,unit:s}){return(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,q.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,q.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-right text-muted-foreground`,children:[n,s??``]})]})]})}function Dc({label:e,hint:t,value:n,options:r,onChange:i}){return(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,q.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,q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Oc({label:e,hint:t,selector:n,onChange:r,configKey:i,value:a}){let o=typeof a==`boolean`,s=K(e=>n?n(e):!1),c=W(e=>i?e[i]:!1),l=o?a:n?s:c;return(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 py-2`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`text-sm font-medium`,children:e}),t&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:t})]}),(0,q.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":l,onClick:()=>{if(o)r?.();else if(n)r?.();else if(i===`soundOnComplete`){let e=!W.getState().soundOnComplete;W.getState().setSoundOnComplete(e),e&&Ni()}},className:Z(`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,q.jsx)(`span`,{className:Z(`absolute top-0.5 left-0.5 h-3.5 w-3.5 rounded-full bg-background shadow transition-transform`,l&&`translate-x-4`)})})]})}var kc=[`anthropic`,`openai`,`google`,`openai-compatible`];function Ac({activeProvider:e,catalogProviders:t,isLoadingCatalog:n,savedProviders:r,isLoadingSaved:i,providerTab:a,setProviderTab:o,onSelectProvider:s,onAddKey:c,onDeleteKey:l,onSetActiveKey:u,onAddProvider:d,onRemoveProvider:f,catalogQuery:p,setCatalogQuery:m}){let[h,g]=(0,V.useState)(null),[_,y]=(0,V.useState)(``),[b,x]=(0,V.useState)(``),[S,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(!1),[E,D]=(0,V.useState)(``),[O,k]=(0,V.useState)(`openai-compatible`),[A,ee]=(0,V.useState)(``),[j,M]=(0,V.useState)(``),N=(0,V.useCallback)(e=>{!_.trim()||!b.trim()||(c(e,_.trim(),b.trim()),y(``),x(``),g(null))},[c,_,b]),P=(0,V.useCallback)(()=>{E.trim()&&(d(E.trim(),O,A||void 0,j||void 0),D(``),k(`openai-compatible`),ee(``),M(``),T(!1))},[d,E,O,A,j]),F=p.trim()?t.filter(e=>{let t=p.trim().toLowerCase();return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||e.family.toLowerCase().includes(t)}):t,I=F.reduce((e,t)=>(e[t.family]||(e[t.family]=[]),e[t.family]?.push(t),e),{});return(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{className:`flex gap-2 mb-4`,children:[(0,q.jsxs)($,{variant:a===`catalog`?`default`:`outline`,size:`sm`,onClick:()=>o(`catalog`),children:[(0,q.jsx)(v,{className:`h-4 w-4 mr-1`}),`Catalog`]}),(0,q.jsxs)($,{variant:a===`saved`?`default`:`outline`,size:`sm`,onClick:()=>o(`saved`),children:[(0,q.jsx)(_t,{className:`h-4 w-4 mr-1`}),`Saved (`,r.length,`)`]})]}),a===`catalog`&&(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsx)(cc,{placeholder:`Search ${t.length} providers (name / id / family)…`,value:p,onChange:e=>m(e.target.value),className:`text-sm`}),n&&t.length===0?(0,q.jsxs)(`div`,{className:`flex items-center justify-center py-8`,children:[(0,q.jsx)(z,{className:`h-6 w-6 animate-spin text-muted-foreground`}),(0,q.jsx)(`span`,{className:`ml-2 text-muted-foreground`,children:`Loading catalog...`})]}):F.length===0&&p?(0,q.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground text-sm`,children:[`No providers match "`,(0,q.jsx)(`span`,{className:`font-mono`,children:p}),`".`]}):(0,q.jsx)(q.Fragment,{children:kc.map(t=>{let n=I[t];return n?.length?(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`h3`,{className:`text-sm font-semibold text-muted-foreground uppercase tracking-wider`,children:t}),(0,q.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:n.map(t=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>s(t.id),className:Z(`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,q.jsxs)(`div`,{className:`flex w-full justify-between items-start`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`font-medium`,children:t.name}),(0,q.jsxs)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:[`(`,t.id,`)`]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t.hasApiKey&&(0,q.jsxs)(`span`,{className:`text-xs bg-green-500/10 text-green-600 px-2 py-0.5 rounded`,children:[(0,q.jsx)(_t,{className:`h-3 w-3 inline mr-1`}),`Configured`]}),t.envVars[0]&&(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`ENV: `,t.envVars[0]]}),e===t.id&&(0,q.jsx)(ut,{className:`h-4 w-4 text-primary`})]})]}),(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[t.modelCount,` models`,t.apiBase&&` · ${t.apiBase}`]})]},t.id))})]},t):null})})]}),a===`saved`&&(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Manage your API keys and provider configurations`}),(0,q.jsxs)($,{size:`sm`,variant:`outline`,onClick:()=>T(!w),children:[(0,q.jsx)(Ye,{className:`h-4 w-4 mr-1`}),`Add Provider`]})]}),w&&(0,q.jsxs)(`div`,{className:`p-4 border rounded-lg space-y-3 bg-muted/50`,children:[(0,q.jsx)(`h4`,{className:`font-medium`,children:`Add Custom Provider`}),(0,q.jsx)(cc,{placeholder:`Provider ID (e.g. my-llm-server)`,value:E,onChange:e=>D(e.target.value)}),(0,q.jsxs)(`select`,{className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm`,value:O,onChange:e=>k(e.target.value),children:[(0,q.jsx)(`option`,{value:`anthropic`,children:`Anthropic`}),(0,q.jsx)(`option`,{value:`openai`,children:`OpenAI`}),(0,q.jsx)(`option`,{value:`openai-compatible`,children:`OpenAI Compatible`}),(0,q.jsx)(`option`,{value:`google`,children:`Google`})]}),(0,q.jsx)(cc,{placeholder:`Base URL (optional, e.g. http://localhost:11434/v1)`,value:A,onChange:e=>ee(e.target.value)}),(0,q.jsx)(cc,{type:`password`,placeholder:`API Key (optional)`,value:j,onChange:e=>M(e.target.value)}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)($,{size:`sm`,onClick:P,disabled:!E.trim(),children:`Add`}),(0,q.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>T(!1),children:`Cancel`})]})]}),i?(0,q.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,q.jsx)(z,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):r.length===0?(0,q.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,q.jsx)(_t,{className:`h-8 w-8 mx-auto mb-2 opacity-50`}),(0,q.jsx)(`p`,{children:`No saved providers yet`}),(0,q.jsx)(`p`,{className:`text-sm`,children:`Add a provider to get started`})]}):r.map(e=>(0,q.jsxs)(`div`,{className:`border rounded-lg p-4 space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between items-start`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h4`,{className:`font-medium`,children:e.id}),e.family&&(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.family})]}),(0,q.jsx)(`div`,{className:`flex gap-2`,children:(0,q.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>f(e.id),children:(0,q.jsx)(Lt,{className:`h-4 w-4 text-destructive`})})})]}),e.baseUrl&&(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,q.jsx)(v,{className:`h-3 w-3 inline mr-1`}),e.baseUrl]}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between items-center`,children:[(0,q.jsx)(`span`,{className:`text-sm font-medium`,children:`API Keys`}),(0,q.jsxs)($,{size:`sm`,variant:`ghost`,onClick:()=>g(h===e.id?null:e.id),children:[(0,q.jsx)(Ye,{className:`h-3 w-3 mr-1`}),`Add Key`]})]}),e.apiKeys.length===0&&!h&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`No keys configured`}),e.apiKeys.map(t=>(0,q.jsxs)(`div`,{className:`flex items-center justify-between p-2 bg-muted/50 rounded`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`text-sm font-medium`,children:t.label}),t.isActive&&(0,q.jsx)(`span`,{className:`ml-2 text-xs bg-green-500/10 text-green-600 px-1.5 py-0.5 rounded`,children:`Active`}),(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.maskedKey})]}),(0,q.jsxs)(`div`,{className:`flex gap-1`,children:[!t.isActive&&(0,q.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>u(e.id,t.label),children:`Set Active`}),(0,q.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>l(e.id,t.label),children:(0,q.jsx)(Lt,{className:`h-3 w-3 text-destructive`})})]})]},t.label)),h===e.id&&(0,q.jsxs)(`div`,{className:`p-3 border rounded space-y-2 bg-background`,children:[(0,q.jsx)(cc,{placeholder:`Key label (e.g. default, production)`,value:_,onChange:e=>y(e.target.value)}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(cc,{type:S?`text`:`password`,placeholder:`API key`,value:b,onChange:e=>x(e.target.value)}),(0,q.jsx)($,{size:`icon`,variant:`ghost`,onClick:()=>C(!S),children:S?(0,q.jsx)(Oe,{className:`h-4 w-4`}):(0,q.jsx)(ot,{className:`h-4 w-4`})})]}),(0,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)($,{size:`sm`,onClick:()=>N(e.id),disabled:!_.trim()||!b.trim(),children:`Save Key`}),(0,q.jsx)($,{size:`sm`,variant:`ghost`,onClick:()=>{g(null),y(``),x(``)},children:`Cancel`})]})]})]})]},e.id))]})]})}function jc(){let{setCurrentView:e}=K(),{provider:t,setProvider:n,setModel:r,wsConnected:a}=W(),{theme:o,setTheme:s}=Aa(),c=Da(),l=c.client,{updatePrefs:u,switchAutonomy:d}=c,p=ni(),m=(0,V.useCallback)((e,t)=>{p.set({[e]:t}),u({[e]:t})},[p,u]),[h,g]=(0,V.useState)([]),[_,y]=(0,V.useState)({}),[b,x]=(0,V.useState)([]),[S,C]=(0,V.useState)(!1),[w,T]=(0,V.useState)(!1),[E,D]=(0,V.useState)(!1),[O,k]=(0,V.useState)(`catalog`),[A,ee]=(0,V.useState)(``),j=h.find(e=>e.id===t);(0,V.useEffect)(()=>{let e=e=>{if(e.type===`provider.catalog`){let t=e.payload;g(t.providers.sort((e,t)=>e.id.localeCompare(t.id))),C(!1)}},t=e=>{if(e.type===`provider.models`){let t=e.payload;y(e=>({...e,[t.provider]:t.models})),T(!1)}},n=e=>{if(e.type===`providers.saved`){let t=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));x(t),D(!1),t.length>0&&k(`saved`)}};if(!a||!l)return;let r=l.on(`provider.catalog`,e),i=l.on(`provider.models`,t),o=l.on(`providers.saved`,n);return C(!0),D(!0),l.listProviders(),l.listSavedProviders(),()=>{r?.(),i?.(),o?.()}},[a,l]);let M=(0,V.useCallback)(e=>{n(e),_[e]||(T(!0),c.listProviderModels?.(e))},[_,n,c]),N=(0,V.useCallback)(e=>{r(e);let t=W.getState().provider;c.switchModel?.(t,e),Q.success(`Switching to ${t} / ${e}…`)},[r,c]),P=(0,V.useCallback)((e,t,n)=>{c.addKey?.(e,t,n)},[c]),F=(0,V.useCallback)((e,t)=>{c.deleteKey?.(e,t)},[c]),I=(0,V.useCallback)((e,t)=>{c.setActiveKey?.(e,t)},[c]),te=(0,V.useCallback)((e,t,n,r)=>{c.addProvider?.(e,t,n,r)},[c]),L=(0,V.useCallback)(e=>{c.removeProvider?.(e)},[c]);return(0,q.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,q.jsxs)(`header`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card shrink-0`,children:[(0,q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Settings`}),(0,q.jsx)($,{variant:`ghost`,size:`icon`,onClick:()=>e(`chat`),children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]}),(0,q.jsx)(lc,{className:`flex-1`,children:(0,q.jsx)(`div`,{className:`p-6 max-w-2xl mx-auto`,children:(0,q.jsxs)(dc,{defaultValue:`provider`,children:[(0,q.jsxs)(fc,{className:`w-full justify-start mb-6 grid grid-cols-6`,children:[(0,q.jsxs)(pc,{value:`provider`,className:`gap-1 text-xs`,children:[(0,q.jsx)(i,{className:`h-3.5 w-3.5`}),`Provider`]}),(0,q.jsxs)(pc,{value:`connection`,className:`gap-1 text-xs`,children:[(0,q.jsx)(v,{className:`h-3.5 w-3.5`}),`Connect`]}),(0,q.jsxs)(pc,{value:`appearance`,className:`gap-1 text-xs`,children:[(0,q.jsx)(st,{className:`h-3.5 w-3.5`}),`Look`]}),(0,q.jsxs)(pc,{value:`agent`,className:`gap-1 text-xs`,children:[(0,q.jsx)(Qt,{className:`h-3.5 w-3.5`}),`Agent`]}),(0,q.jsxs)(pc,{value:`features`,className:`gap-1 text-xs`,children:[(0,q.jsx)(f,{className:`h-3.5 w-3.5`}),`Feat.`]}),(0,q.jsxs)(pc,{value:`mcp`,className:`gap-1 text-xs`,children:[(0,q.jsx)(Yt,{className:`h-3.5 w-3.5`}),`MCP`]})]}),(0,q.jsxs)(mc,{value:`provider`,className:`space-y-4`,children:[(0,q.jsx)(Ac,{activeProvider:t,catalogProviders:h,isLoadingCatalog:S,savedProviders:b,isLoadingSaved:E,providerTab:O,setProviderTab:k,onSelectProvider:M,onAddKey:P,onDeleteKey:F,onSetActiveKey:I,onAddProvider:te,onRemoveProvider:L,catalogQuery:A,setCatalogQuery:ee}),(0,q.jsxs)(`div`,{className:`pt-4 border-t`,children:[(0,q.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,q.jsx)(hn,{className:`h-4 w-4 text-muted-foreground`}),`Model`]}),(0,q.jsx)(Tc,{provider:t,catalogModels:_,currentCatalogProvider:j,isLoadingModels:w,setIsLoadingModels:T,onModelSelect:N,refreshModels:e=>c.listProviderModels?.(e)})]})]}),(0,q.jsxs)(mc,{value:`connection`,className:`space-y-4`,children:[(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsxs)(`label`,{htmlFor:`websocket-url`,className:`text-sm font-medium flex items-center gap-2`,children:[(0,q.jsx)(v,{className:`h-4 w-4 text-muted-foreground`}),`WebSocket Server URL`]}),(0,q.jsx)(cc,{id:`websocket-url`,value:W.getState().wsUrl,onChange:e=>W.getState().setConfig({wsUrl:e.target.value}),placeholder:`ws://localhost:3457`,className:`font-mono text-sm`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`URL of the agent WebSocket server. The server runs alongside the CLI.`})]}),(0,q.jsxs)(`div`,{className:`p-4 rounded-lg border bg-muted/50`,children:[(0,q.jsx)(`h4`,{className:`text-sm font-medium mb-2`,children:`Starting the WebSocket Server`}),(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:[`Standalone: run `,(0,q.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,q.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`node packages/webui/dist/server/entry.js`}),`. Or alongside the CLI:`,` `,(0,q.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`wstack --webui`}),`.`]})]})]}),(0,q.jsxs)(mc,{value:`appearance`,className:`space-y-4`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:`Theme`}),(0,q.jsxs)(`div`,{className:`grid grid-cols-3 gap-2 max-w-md`,children:[(0,q.jsxs)($,{variant:o===`light`?`default`:`outline`,size:`sm`,onClick:()=>s(`light`),children:[(0,q.jsx)(yt,{className:`h-4 w-4 mr-1`}),`Light`]}),(0,q.jsxs)($,{variant:o===`dark`?`default`:`outline`,size:`sm`,onClick:()=>s(`dark`),children:[(0,q.jsx)(Nn,{className:`h-4 w-4 mr-1`}),`Dark`]}),(0,q.jsxs)($,{variant:o===`system`?`default`:`outline`,size:`sm`,onClick:()=>s(`system`),children:[(0,q.jsx)(un,{className:`h-4 w-4 mr-1`}),`System`]})]}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:`System follows your OS-level light/dark preference.`})]}),(0,q.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,q.jsx)(`h3`,{className:`text-sm font-semibold mb-3 mt-3`,children:`Preferences`}),(0,q.jsx)(Oc,{label:`Compact density`,hint:`Tighter spacing throughout the chat.`,selector:e=>e.compactMode,onChange:()=>K.getState().toggleCompactMode()}),(0,q.jsx)(Oc,{label:`Sound on completion`,hint:`Play a soft chime when a run finishes.`,selector:null,configKey:`soundOnComplete`})]})]}),(0,q.jsxs)(mc,{value:`agent`,className:`space-y-4`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,q.jsx)(ir,{className:`h-4 w-4 text-muted-foreground`}),`Autonomy & Behavior`]}),(0,q.jsx)(Dc,{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}),d(e)}}),(0,q.jsx)(Ec,{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,q.jsx)(Oc,{label:`YOLO mode`,hint:`Bypass tool confirmation prompts — the agent runs without asking.`,value:p.yolo,onChange:()=>m(`yolo`,!p.yolo)})]}),(0,q.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,q.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,q.jsx)(Dn,{className:`h-4 w-4 text-muted-foreground`}),`Prompt Refinement`]}),(0,q.jsx)(Oc,{label:`Enable refine`,hint:`Rewrite prompts before sending — clearer instructions, better results.`,value:p.enhanceEnabled,onChange:()=>m(`enhanceEnabled`,!p.enhanceEnabled)}),(0,q.jsx)(Ec,{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,q.jsx)(Dc,{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,q.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,q.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,q.jsx)(Dn,{className:`h-4 w-4 text-muted-foreground`}),`Execution`]}),(0,q.jsx)(Ec,{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,q.jsx)(Ec,{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,q.jsx)(Oc,{label:`Confirm before exit`,hint:`First Ctrl+C aborts work, second confirms exit.`,value:p.confirmExit,onChange:()=>m(`confirmExit`,!p.confirmExit)}),(0,q.jsx)(Oc,{label:`Chime on completion`,hint:`Terminal bell when an agent run finishes.`,value:p.chime,onChange:()=>m(`chime`,!p.chime)})]}),(0,q.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,q.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,q.jsx)(Vn,{className:`h-4 w-4 text-muted-foreground`}),`Fleet & Streaming`]}),(0,q.jsx)(Oc,{label:`Stream fleet events`,hint:`Show live subagent activity in the fleet panel.`,value:p.streamFleet,onChange:()=>m(`streamFleet`,!p.streamFleet)}),(0,q.jsx)(Oc,{label:`Next-step prediction`,hint:`After a turn completes, predict likely next steps.`,value:p.nextPrediction,onChange:()=>m(`nextPrediction`,!p.nextPrediction)})]}),(0,q.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,q.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,q.jsx)(me,{className:`h-4 w-4 text-muted-foreground`}),`Telegram Notifications`]}),p.tgConfigured?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(Oc,{label:`Session end`,hint:`Send a summary when a session ends.`,value:p.tgSessionEnd,onChange:()=>m(`tgSessionEnd`,!p.tgSessionEnd)}),(0,q.jsx)(Oc,{label:`Delegate finished`,hint:`Send a humanized note when a subagent completes.`,value:p.tgDelegate,onChange:()=>m(`tgDelegate`,!p.tgDelegate)}),(0,q.jsx)(Oc,{label:`Long-running tools`,hint:`Notify when a tool exceeds ${p.tgLongToolMs}ms. Set 0 to disable.`,value:p.tgLongToolMs>0,onChange:()=>m(`tgLongToolMs`,p.tgLongToolMs>0?0:3e4)}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-2`,children:`Changes apply immediately.`})]}):(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Telegram is not configured. Run`,` `,(0,q.jsx)(`code`,{className:`bg-muted px-1 py-0.5 rounded`,children:`/telegram-setup`}),` in the CLI to connect a bot first.`]})]})]}),(0,q.jsxs)(mc,{value:`features`,className:`space-y-4`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 flex items-center gap-2`,children:[(0,q.jsx)(f,{className:`h-4 w-4 text-muted-foreground`}),`Feature Flags`]}),(0,q.jsx)(Oc,{label:`MCP servers`,hint:`Enable Model Context Protocol integrations.`,value:p.featureMcp,onChange:()=>m(`featureMcp`,!p.featureMcp)}),(0,q.jsx)(Oc,{label:`Plugins`,hint:`Load and run user-installed plugins.`,value:p.featurePlugins,onChange:()=>m(`featurePlugins`,!p.featurePlugins)}),(0,q.jsx)(Oc,{label:`Memory`,hint:`Persist and recall facts across sessions.`,value:p.featureMemory,onChange:()=>m(`featureMemory`,!p.featureMemory)}),(0,q.jsx)(Oc,{label:`Skills`,hint:`Load domain-specific skill prompts.`,value:p.featureSkills,onChange:()=>m(`featureSkills`,!p.featureSkills)}),(0,q.jsx)(Oc,{label:`Models registry`,hint:`Use the models.dev catalog for provider discovery.`,value:p.featureModelsRegistry,onChange:()=>m(`featureModelsRegistry`,!p.featureModelsRegistry)}),(0,q.jsx)(Oc,{label:`Index on start`,hint:`Build the codebase symbol index at session start.`,value:p.indexOnStart,onChange:()=>m(`indexOnStart`,!p.indexOnStart)})]}),(0,q.jsxs)(`div`,{className:`pt-2 border-t`,children:[(0,q.jsxs)(`h3`,{className:`text-sm font-semibold mb-3 mt-3 flex items-center gap-2`,children:[(0,q.jsx)(Se,{className:`h-4 w-4 text-muted-foreground`}),`Context & Debug`]}),(0,q.jsx)(Oc,{label:`Auto-compact context`,hint:`Automatically trim the context window when near limits.`,value:p.contextAutoCompact,onChange:()=>m(`contextAutoCompact`,!p.contextAutoCompact)}),(0,q.jsx)(Dc,{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,q.jsx)(Dc,{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,q.jsx)(Dc,{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)})]})]}),(0,q.jsx)(mc,{value:`mcp`,className:`space-y-4`,children:p.featureMcp?(0,q.jsx)(wc,{}):(0,q.jsxs)(`div`,{className:`text-center py-8 text-muted-foreground`,children:[(0,q.jsx)(Yt,{className:`w-10 h-10 mx-auto mb-2 opacity-50`}),(0,q.jsx)(`p`,{children:`MCP servers are disabled.`}),(0,q.jsx)(`p`,{className:`text-sm mt-1`,children:`Enable the "MCP servers" feature flag in the Features tab to use this section.`})]})})]})})})]})}function Mc({provider:e,isSelected:t,onSelect:n}){return(0,q.jsx)(`button`,{type:`button`,onClick:n,className:Z(`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,q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`font-semibold text-sm`,children:e.name}),e.hasApiKey&&(0,q.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,q.jsx)(Be,{className:`h-2.5 w-2.5`}),`Key set`]})]}),(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[e.family,` · `,e.modelCount,` models`]})]}),t&&(0,q.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,q.jsx)(Be,{className:`h-3 h-3 text-primary-foreground`})})]})})}function Nc({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,q.jsx)(`button`,{type:`button`,onClick:n,className:Z(`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,q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`span`,{className:`font-medium text-sm`,children:e.name}),(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 mt-1`,children:[a&&(0,q.jsx)(`span`,{className:`text-[10px] px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:a}),r&&i&&(0,q.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,q.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,q.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-primary flex items-center justify-center shrink-0`,children:(0,q.jsx)(Be,{className:`h-3 w-3 text-primary-foreground`})})]})})}function Pc({providerId:e,onSave:t}){let[n,r]=(0,V.useState)(``),[i,a]=(0,V.useState)(`default`),[o,s]=(0,V.useState)(!1);return(0,q.jsxs)(`div`,{className:`space-y-3 p-4 rounded-xl border border-amber-500/30 bg-amber-500/5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-600 dark:text-amber-400`,children:[(0,q.jsx)(Yn,{className:`h-4 w-4`}),(0,q.jsx)(`span`,{className:`text-sm font-medium`,children:`API Key required`})]}),(0,q.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,q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,q.jsx)(cc,{type:`password`,placeholder:`sk-...`,value:n,onChange:e=>r(e.target.value),className:`font-mono text-sm`}),(0,q.jsx)(cc,{placeholder:`Label (optional)`,value:i,onChange:e=>a(e.target.value),className:`w-28 text-sm`})]}),(0,q.jsx)($,{onClick:async()=>{if(n.trim()){s(!0);try{H(W.getState().wsUrl).addKey(e,i.trim()||`default`,n.trim()),t(n.trim()),r(``),Q.success(`API key saved`)}catch{Q.error(`Failed to save API key`)}finally{s(!1)}}},disabled:!n.trim()||o,size:`sm`,children:o?(0,q.jsx)(z,{className:`h-4 w-4 animate-spin`}):`Save Key`})]})}function Fc(){let{setCurrentView:e}=K(),{provider:t,model:n,setProvider:r,setModel:a,wsConnected:o,wsUrl:s}=W();Da();let[c,l]=(0,V.useState)(`provider`),[u,d]=(0,V.useState)([]),[f,p]=(0,V.useState)({}),[m,h]=(0,V.useState)([]),[g,_]=(0,V.useState)(!1),[v,y]=(0,V.useState)(!1),[b,x]=(0,V.useState)(null),[S,C]=(0,V.useState)(null);(0,V.useEffect)(()=>{if(!o)return;let e=H(s),r=e.on(`provider.catalog`,e=>{if(e.type===`provider.catalog`){let n=e.payload.providers.sort((e,t)=>e.id.localeCompare(t.id));d(n),_(!1),t&&n.some(e=>e.id===t)?x(t):n.length===1&&x(n[0].id)}}),i=e.on(`provider.models`,e=>{if(e.type===`provider.models`){let t=e.payload;p(e=>({...e,[t.provider]:t.models})),y(!1),t.models.length===1?C(t.models[0].id):n&&t.models.some(e=>e.id===n)&&C(n)}}),a=e.on(`providers.saved`,e=>{if(e.type===`providers.saved`){let t=e.payload;h(t.providers.sort((e,t)=>e.id.localeCompare(t.id)))}});return _(!0),e.listProviders(),()=>{r?.(),i?.(),a?.()}},[o,s,t,n]),(0,V.useEffect)(()=>{if(!b||!o)return;let e=H(s);f[b]||(y(!0),e.listProviderModels(b))},[b,o,s,f]);let w=u.find(e=>e.id===b),T=m.find(e=>e.id===b)?.apiKeys.some(e=>e.isActive)||w?.hasApiKey,E=(0,V.useCallback)(e=>{x(e),C(null),l(`model`)},[]),D=(0,V.useCallback)(e=>{C(e),l(T?`done`:`apikey`)},[T]),O=(0,V.useCallback)(()=>{l(`done`)},[]),k=(0,V.useCallback)(()=>{if(!b||!S)return;r(b),a(S);let t=H(s);t.switchModel(b,S);let n=null,i=()=>{n&&clearTimeout(n)},o=t.on(`key.operation_result`,n=>{let r=n.payload;i(),o(),r.success?(t.newSession(),e(`chat`)):Q.error(r.message)});n=setTimeout(()=>{i(),o(),Q.error(`Model switch timed out. Please try again.`)},5e3)},[b,S,r,a,s,e]),A=b?f[b]??[]:[];return(0,q.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,q.jsx)(`header`,{className:`flex items-center justify-between px-6 py-4 border-b bg-card shrink-0`,children:(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.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,q.jsx)(Dn,{className:`h-5 w-5 text-primary-foreground`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Welcome to WrongStack`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Configure your AI provider to get started`})]})]})}),(0,q.jsx)(lc,{className:`flex-1`,children:(0,q.jsxs)(`div`,{className:`p-6 max-w-2xl mx-auto space-y-8`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-1.5`,c===`provider`&&`text-primary font-medium`),children:[(0,q.jsx)(i,{className:`h-4 w-4`}),(0,q.jsx)(`span`,{children:`Provider`})]}),(0,q.jsx)(Ie,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-1.5`,c===`model`&&`text-primary font-medium`),children:[(0,q.jsx)(hn,{className:`h-4 w-4`}),(0,q.jsx)(`span`,{children:`Model`})]}),(0,q.jsx)(Ie,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-1.5`,(c===`apikey`||c===`done`)&&`text-primary font-medium`),children:[(0,q.jsx)(Yn,{className:`h-4 w-4`}),(0,q.jsx)(`span`,{children:`API Key`})]})]}),c===`provider`&&(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,q.jsx)(i,{className:`h-4 w-4 text-primary`}),`Choose a Provider`]}),(0,q.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.`})]}),g?(0,q.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,q.jsx)(z,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):(0,q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:u.map(e=>(0,q.jsx)(Mc,{provider:e,isSelected:b===e.id,onSelect:()=>E(e.id)},e.id))})]}),c===`model`&&(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,q.jsx)(hn,{className:`h-4 w-4 text-primary`}),`Choose a Model`]}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:w?`Models available for ${w.name}`:`Loading models...`})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>l(`provider`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change provider`}),v?(0,q.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,q.jsx)(z,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):A.length>0?(0,q.jsx)(`div`,{className:`grid grid-cols-1 gap-2`,children:A.map(e=>(0,q.jsx)(Nc,{model:e,isSelected:S===e.id,onSelect:()=>D(e.id)},e.id))}):(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground py-8 text-center`,children:`No models available. Please check your API key.`})]}),c===`apikey`&&(0,q.jsxs)(`div`,{className:`space-y-4`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`h2`,{className:`text-base font-semibold flex items-center gap-2`,children:[(0,q.jsx)(Yn,{className:`h-4 w-4 text-primary`}),`Add Your API Key`]}),(0,q.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,q.jsx)(`button`,{type:`button`,onClick:()=>l(`model`),className:`text-xs text-muted-foreground hover:text-foreground transition-colors`,children:`← Change model`}),b&&(0,q.jsx)(Pc,{providerId:b,onSave:O})]}),c===`done`&&(0,q.jsxs)(`div`,{className:`space-y-6`,children:[(0,q.jsxs)(`div`,{className:`flex flex-col items-center text-center py-8`,children:[(0,q.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,q.jsx)(Be,{className:`h-8 w-8 text-emerald-500`})}),(0,q.jsx)(`h2`,{className:`text-xl font-semibold`,children:`You're all set!`}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-sm`,children:`Configuration complete. Your agent is ready to start working.`})]}),(0,q.jsxs)(`div`,{className:`rounded-xl border bg-card p-4 space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Provider`}),(0,q.jsx)(`span`,{className:`font-medium`,children:b})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between text-sm`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Model`}),(0,q.jsx)(`span`,{className:`font-medium`,children:S})]})]}),(0,q.jsxs)($,{onClick:k,className:`w-full`,size:`lg`,children:[(0,q.jsx)(Qt,{className:`h-4 w-4 mr-2`}),`Start Session`,(0,q.jsx)(Te,{className:`h-4 w-4 ml-2`})]})]})]})})]})}function Ic(e){switch(e){case`running`:return`▶`;case`streaming`:return`↻`;case`waiting_user`:return`⏳`;case`error`:return`✗`;case`idle`:return`■`;default:return`?`}}function Lc(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 Rc(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 zc(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 Bc(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 Vc(){let[e,t]=(0,V.useState)([]),[n,r]=(0,V.useState)(!0),[i,a]=(0,V.useState)(null),o=(0,V.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,V.useEffect)(()=>{o();let e=setInterval(o,5e3);return()=>clearInterval(e)},[o]),n?(0,q.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-slate-400`,children:[(0,q.jsx)(z,{className:`h-4 w-4 animate-spin`}),`Loading sessions...`]}):i?(0,q.jsxs)(`div`,{className:`p-4 text-slate-500 text-sm`,children:[`Session API unavailable — run `,(0,q.jsx)(`code`,{className:`text-cyan-400`,children:`wstack --webui`}),` with session tracking enabled.`]}):e.length===0?(0,q.jsx)(`div`,{className:`p-4 text-slate-500 text-sm`,children:`No live sessions. Open another wstack instance to see it here.`}):(0,q.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-4`,children:[(0,q.jsxs)(`h2`,{className:`text-sm font-semibold text-slate-200 uppercase tracking-wider`,children:[`Live Sessions (`,e.length,`)`]}),(0,q.jsx)(`span`,{className:`text-xs text-slate-500`,children:`auto-refresh every 5s`})]}),e.map(e=>(0,q.jsxs)(`div`,{className:`rounded-lg border border-slate-700 bg-slate-800/50 p-3 space-y-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsx)(`span`,{className:Rc(e.status),children:e.status===`active`?(0,q.jsx)(gn,{className:`h-3.5 w-3.5 inline`}):e.status===`idle`?(0,q.jsx)(jn,{className:`h-3.5 w-3.5 inline`}):null}),(0,q.jsx)(`span`,{className:`font-medium text-slate-200 text-sm`,children:e.projectName}),(0,q.jsxs)(`span`,{className:`text-slate-500 text-xs`,children:[`[`,e.projectSlug,`]`]}),e.gitBranch?(0,q.jsxs)(`span`,{className:`text-purple-400 text-xs flex items-center gap-1`,children:[(0,q.jsx)(ce,{className:`h-3 w-3`}),e.gitBranch]}):null,(0,q.jsxs)(`span`,{className:`text-slate-500 text-xs ml-auto flex items-center gap-1`,children:[(0,q.jsx)(Et,{className:`h-3 w-3`}),zc(e.startedAt)]}),(0,q.jsxs)(`span`,{className:`text-slate-600 text-xs`,children:[`PID `,e.pid]})]}),(0,q.jsxs)(`div`,{className:`text-slate-500 text-xs flex items-center gap-1`,children:[(0,q.jsx)(hn,{className:`h-3 w-3`}),e.workingDir]}),(0,q.jsxs)(`div`,{className:`space-y-1 mt-2`,children:[e.agents.slice(0,5).map(e=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs pl-2 border-l-2 border-slate-700`,children:[(0,q.jsx)(`span`,{className:Lc(e.status),children:Ic(e.status)}),(0,q.jsx)(`span`,{className:`text-slate-300 font-medium`,children:e.name}),e.currentTool?(0,q.jsxs)(`span`,{className:`text-slate-500`,children:[`[`,e.currentTool,`]`]}):null,(0,q.jsxs)(`span`,{className:`text-slate-600 ml-auto`,children:[e.iterations,` iter · `,e.toolCalls,` tools · `,Bc(e.lastActivityAt)]})]},e.id)),e.agents.length>5?(0,q.jsxs)(`div`,{className:`text-slate-600 text-xs pl-4`,children:[`... and `,e.agents.length-5,` more`]}):null,e.agents.length===0?(0,q.jsx)(`div`,{className:`text-slate-600 text-xs pl-4`,children:`No agents`}):null]})]},e.sessionId))]})}var Hc=[{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:`Fleet & Agents`,items:[{keys:[`Ctrl`,`Shift`,`M`],description:`Open Fleet Monitor overlay`},{keys:[`Ctrl`,`Shift`,`A`],description:`Open Agents Monitor overlay`},{keys:[`↑`,`↓`],description:`Navigate agents in monitor`},{keys:[`Enter`],description:`Select focused agent`},{keys:[`Esc`],description:`Close active overlay`}]},{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 Uc(){let e=K(e=>e.shortcutsOpen),t=K(e=>e.setShortcutsOpen);return(0,V.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(!K.getState().shortcutsOpen);return}e.key===`Escape`&&K.getState().shortcutsOpen&&(e.preventDefault(),t(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t]),e?(0,q.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,q.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,q.jsxs)(`div`,{className:`flex items-center justify-between px-5 py-4 border-b`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)($n,{className:`h-4 w-4 text-muted-foreground`}),(0,q.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Keyboard shortcuts`})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>t(!1),className:`text-muted-foreground hover:text-foreground p-1 rounded hover:bg-muted`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]}),(0,q.jsx)(`div`,{className:`overflow-y-auto px-5 py-4 space-y-6`,children:Hc.map(e=>(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-2`,children:e.section}),(0,q.jsx)(`div`,{className:`grid grid-cols-1 gap-1.5`,children:e.items.map(e=>(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-sm px-2 py-1.5 rounded hover:bg-muted/40`,children:[(0,q.jsx)(`span`,{className:`text-foreground/80`,children:e.description}),(0,q.jsx)(`span`,{className:`flex items-center gap-1 shrink-0`,children:e.keys.map((e,t)=>(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[t>0&&(0,q.jsx)(`span`,{className:`text-muted-foreground/40 text-xs`,children:`+`}),(0,q.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,q.jsxs)(`div`,{className:`border-t px-5 py-3 text-xs text-muted-foreground`,children:[`Press`,` `,(0,q.jsx)(`kbd`,{className:`font-mono text-[10px] border rounded px-1 py-0.5 bg-background`,children:`?`}),` `,`any time to reopen this list.`]})]})}):null}var Wc={ts:R,tsx:R,js:R,jsx:R,mjs:R,cjs:R,json:et,lock:Ze,css:qe,scss:qe,less:qe,html:u,htm:u,svg:A,xml:u,md:qe,mdx:qe,txt:qe,yml:qe,yaml:qe,toml:Sn,env:Sn,gitignore:Sn,editorconfig:Sn,sh:R,bash:R,zsh:R,fish:R,ps1:R,bat:R,py:R,pyi:R,pyx:R,rs:R,go:R,rb:R,java:R,c:R,cpp:R,h:R,hpp:R,sql:R,graphql:R,png:A,jpg:A,jpeg:A,gif:A,webp:A,ico:A};function Gc(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 Kc(e){return Wc[e.split(`.`).pop()?.toLowerCase()??``]??rr}function qc({node:e,depth:t,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a}){let[o,s]=(0,V.useState)(t<1),c=Y(e=>e.activeFilePath),l=e.type===`file`&&e.path===c;if((0,V.useEffect)(()=>{r!==null&&s(r)},[r]),e.type===`directory`){let c=(e.children?.length??0)>0,l=o?E:fe,u=e.name===`.git`,d=Gc(e.name,!0);return(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>s(e=>!e),className:Z(`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,q.jsx)(Ie,{className:Z(`h-3 w-3 shrink-0 text-muted-foreground transition-transform`,o&&`rotate-90`)}),u?(0,q.jsx)(I,{className:Z(`h-3.5 w-3.5 shrink-0`,d)}):(0,q.jsx)(l,{className:Z(`h-3.5 w-3.5 shrink-0`,d)}),(0,q.jsx)(`span`,{className:`truncate font-medium flex-1 min-w-0`,children:e.name})]}),o&&c&&(0,q.jsx)(`div`,{children:(e.children??[]).map(e=>(0,q.jsx)(qc,{node:e,depth:t+1,selectedPath:n,forceExpand:r,onSelect:i,onOpen:a},e.path))}),o&&!c&&(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground italic py-0.5`,style:{paddingLeft:`${(t+1)*14+4}px`},children:`empty`})]})}let u=Kc(e.name),d=Gc(e.name,!1),f=e.path===n;return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>i(e.path),onDoubleClick:t=>{t.preventDefault(),a(e.path)},className:Z(`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,q.jsx)(`span`,{className:`w-3 shrink-0`}),` `,(0,q.jsx)(u,{className:Z(`h-3.5 w-3.5 shrink-0`,d)}),(0,q.jsx)(`span`,{className:`truncate`,children:e.name})]})}function Jc(){let e=Y(e=>e.tree),t=Y(e=>e.treeLoading),n=Y(e=>e.error),r=Y(e=>e.openFiles),i=Y(e=>e.activeFilePath),a=G(e=>e.cwd),o=G(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,V.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,V.useRef)(null);(0,V.useEffect)(()=>{let e=d.current;e&&u.length>1&&(e.scrollLeft=e.scrollWidth)},[u]);let f=(0,V.useCallback)(e=>{H().send({type:`working_dir.set`,payload:{path:e}})},[]),[p,m]=(0,V.useState)(null);(0,V.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,V.useCallback)((e,t)=>{e.preventDefault(),e.stopPropagation(),m({x:e.clientX,y:e.clientY,crumb:t})},[]),g=(0,V.useCallback)(e=>{navigator.clipboard.writeText(e),m(null)},[]),_=(0,V.useCallback)(()=>{if(!i)return;let e=i.replace(/\\/g,`/`).split(`/`).slice(0,-1).join(`/`)||`.`;H().send({type:`working_dir.set`,payload:{path:e}})},[i]),v=(0,V.useCallback)((e,t)=>{H().send({type:`shell.open`,payload:{path:e,target:t}}),m(null)},[]),y=(0,V.useCallback)(()=>{if(!a)return;let e=a.replace(/\\/g,`/`),t=e.split(`/`).slice(0,-1).join(`/`)||e;H().send({type:`working_dir.set`,payload:{path:t}})},[a]),[b,x]=(0,V.useState)(!1),S=(0,V.useRef)(null);(0,V.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,V.useState)(null),[T,E]=(0,V.useState)(null),D=(0,V.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]),O=(0,V.useMemo)(()=>{let t=0,n=0;for(let r of e)r.type===`directory`?n++:t++;return{files:t,dirs:n}},[e]),k={value:!1},A=(0,V.useCallback)(()=>{k.value=!0,E(!1),setTimeout(()=>{k.value=!1},400)},[]),ee=(0,V.useCallback)(()=>{k.value=!0,E(!0),setTimeout(()=>{k.value=!1},400)},[]),j=(0,V.useCallback)(e=>{if(r.find(t=>t.path===e)){Y.getState().setActiveFile(e);return}w(t=>t===e?null:e)},[r]),M=(0,V.useCallback)(e=>{window.dispatchEvent(new CustomEvent(`wrongstack:open-file`,{detail:{filePath:e}})),w(null)},[]);return(0,V.useEffect)(()=>{i&&w(null)},[i]),b?(0,q.jsx)(`div`,{className:`flex items-center justify-center h-full py-8`,children:(0,q.jsx)(z,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):n?(0,q.jsxs)(`div`,{className:`p-3 text-[11px] text-destructive`,children:[`Failed to load files: `,n]}):(0,q.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[e.length>0&&D>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-0.5 px-2 py-0.5 border-b shrink-0`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:ee,className:Z(`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,q.jsx)(qt,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:`Expand all`})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:A,className:Z(`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,q.jsx)(Ut,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:`Collapse`})]}),(0,q.jsxs)(`span`,{className:`ml-auto text-[9px] text-muted-foreground/50 tabular-nums`,children:[D,` folder`,D===1?``:`s`]})]}),(0,q.jsxs)(`div`,{className:`flex-1 overflow-y-auto py-1`,children:[u.length>0&&(0,q.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,q.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,q.jsxs)(`span`,{className:`flex items-center gap-0.5 shrink-0`,children:[t>0&&(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground/40 select-none`,children:s}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>f(e.path),onContextMenu:e=>h(e,{absPath:d,relPath:p}),className:Z(`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,q.jsxs)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground/50 tabular-nums pl-2`,children:[O.files>0&&`${O.files} file${O.files===1?``:`s`}`,O.files>0&&O.dirs>0&&`, `,O.dirs>0&&`${O.dirs} folder${O.dirs===1?``:`s`}`]})]}),i&&(0,q.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,q.jsx)(R,{className:`h-3 w-3 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate`,children:(()=>{let e=i.replace(/\\/g,`/`).split(`/`);return e[e.length-1]??i})()}),(0,q.jsx)(`span`,{className:`ml-auto text-[8px] text-muted-foreground/40 shrink-0`,children:`go to dir`})]}),u.length===0&&!l&&(0,q.jsxs)(`button`,{type:`button`,onClick:y,className:Z(`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,q.jsx)(An,{className:`h-3.5 w-3.5 shrink-0`}),(0,q.jsx)(`span`,{children:`..`}),(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground/50 ml-auto`,children:`parent directory`})]}),e.map(e=>(0,q.jsx)(qc,{node:e,depth:0,selectedPath:C,forceExpand:T,onSelect:j,onOpen:M},e.path)),e.length===0&&(0,q.jsx)(`p`,{className:`text-[11px] text-muted-foreground italic p-2`,children:`No files found`})]}),p&&(0,q.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,q.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,q.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,q.jsx)(`div`,{className:`border-t border-border/50 my-0.5`}),(0,q.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,q.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,q.jsx)(`div`,{className:`border-t border-border/50 mt-0.5 pt-0.5`,children:(0,q.jsx)(`div`,{className:`px-3 py-1 text-[9px] text-muted-foreground/50 truncate max-w-[200px]`,children:p.crumb.absPath})})]})]})}var Yc={note:qe,ask:Bt,assign:me,steer:O,btw:Jt,broadcast:me,status:yn,result:ut};function Xc(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 Zc({className:e}){let t=Ar(e=>e.messages),n=Ar(e=>e.agents),[r,i]=(0,V.useState)(!1),[a,o]=(0,V.useState)(!1),[s,c]=(0,V.useState)(!1),{client:l}=Da(),[u,d]=(0,V.useState)(l.status.state===`open`);(0,V.useEffect)(()=>{let e=l.onStatus(e=>d(e.state===`open`));return()=>e()},[l]),(0,V.useEffect)(()=>{u&&(l.send({type:`mailbox.messages`,payload:{limit:30}}),l.send({type:`mailbox.agents`,payload:{}}))},[u,l]);let f=t.filter(e=>!e.completed).length,p=n.filter(e=>e.online).length;async function m(){t.length!==0&&await nc({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),l.send({type:`mailbox.clear`}))}(0,V.useEffect)(()=>{a&&t.length===0&&o(!1)},[a,t.length]);async function h(){await nc({title:`Purge stale messages?`,message:`Removes completed messages older than 1 day and incomplete messages older than 7 days. Active messages are preserved.`,confirmLabel:`Purge`,danger:!1})&&(c(!0),l.send({type:`mailbox.purge`}))}return(0,V.useEffect)(()=>{if(s){let e=setTimeout(()=>c(!1),3e3);return()=>clearTimeout(e)}},[s]),(0,q.jsxs)(`div`,{className:Z(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,e),children:[(0,q.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,q.jsx)(xt,{className:`h-4 w-4 text-cyan-500`}),(0,q.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Mailbox`}),f>0&&(0,q.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:f}),(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[p,` online`]})]}),!r&&(0,q.jsxs)(`div`,{className:`px-3 pb-3 space-y-2`,children:[t.length>0?(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide`,children:`Messages`}),(0,q.jsxs)(`button`,{type:`button`,onClick:m,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,q.jsx)(Lt,{className:`h-3 w-3`}),a?`Deleting…`:`Delete all`]}),(0,q.jsxs)(`button`,{type:`button`,onClick:h,disabled:s,className:`flex items-center gap-1 text-[10px] text-muted-foreground hover:text-cyan-500 disabled:opacity-40 transition-colors`,title:`Purge stale/orphaned messages`,children:[(0,q.jsx)(qn,{className:`h-3 w-3`}),s?`Purging…`:`Purge`]})]}),t.slice(0,8).map(e=>{let t=Yc[e.type]??pt,n=e.readByCount>0;return(0,q.jsxs)(`div`,{className:Z(`flex items-start gap-2 px-2 py-1.5 rounded text-xs`,!n&&`bg-yellow-50 dark:bg-yellow-950/20`),children:[(0,q.jsx)(t,{className:Z(`h-3.5 w-3.5 mt-0.5 shrink-0`,n?`text-muted-foreground`:`text-yellow-600`)}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:Z(`font-medium truncate`,!n&&`text-yellow-800 dark:text-yellow-300`),children:e.from}),e.completed&&(0,q.jsx)(ut,{className:`h-3 w-3 text-green-500 shrink-0`}),!n&&(0,q.jsx)(`span`,{className:`text-[9px] text-yellow-600 font-bold`,children:`NEW`})]}),(0,q.jsx)(`div`,{className:`text-muted-foreground truncate`,children:e.subject}),(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:[e.body.slice(0,60),e.body.length>60?`…`:``]})]}),(0,q.jsxs)(`div`,{className:`shrink-0 text-[10px] text-muted-foreground flex flex-col items-end gap-0.5`,children:[(0,q.jsx)(`span`,{children:Xc(e.timestamp)}),n&&(0,q.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,q.jsx)(Nt,{className:`h-3 w-3`}),e.readByCount]})]})]},e.id)})]}):(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground py-2 text-center`,children:[(0,q.jsx)(tn,{className:`h-4 w-4 mx-auto mb-1 opacity-40`}),`No messages yet.`]}),n.length>0&&(0,q.jsxs)(`div`,{className:`border-t border-border pt-2`,children:[(0,q.jsxs)(`div`,{className:`text-[10px] font-semibold text-muted-foreground mb-1 flex items-center gap-1`,children:[(0,q.jsx)(zn,{className:`h-3 w-3`}),` Agents`]}),n.filter(e=>e.online).slice(0,5).map(e=>(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground py-0.5`,children:[(0,q.jsx)(`span`,{className:Z(`h-1.5 w-1.5 rounded-full`,e.online?`bg-green-500`:`bg-muted-foreground/30`)}),(0,q.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e.name}),e.role&&(0,q.jsxs)(`span`,{className:`opacity-60`,children:[`(`,e.role,`)`]}),(0,q.jsx)(`span`,{className:`opacity-50`,children:e.status}),e.currentTool&&(0,q.jsx)(`span`,{className:`text-cyan-500`,children:e.currentTool}),(0,q.jsx)(`span`,{className:`ml-auto opacity-50`,children:Xc(e.lastSeenAt)})]},e.agentId)),n.filter(e=>!e.online).length>0&&(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground/50 mt-0.5`,children:[`+`,n.filter(e=>!e.online).length,` offline`]})]})]})]})}function Qc({fullView:e}){let[t,n]=(0,V.useState)([]),[i,a]=(0,V.useState)(!0),[o,s]=(0,V.useState)(!1),[c,l]=(0,V.useState)(``),[u,d]=(0,V.useState)(``),[f,p]=(0,V.useState)(!1),m=(0,V.useRef)(null),[h,g]=(0,V.useState)({open:!1,project:null,agentCount:0}),_=(0,V.useCallback)(()=>{H().send({type:`projects.list`})},[]);(0,V.useEffect)(()=>{a(!0);let e=H(),t=e.on(`projects.list`,e=>{let t=e.payload;n(t.projects??[]),a(!1)}),r=e.on(`projects.added`,e=>{let t=e.payload;t.slug?(Q.success(t.message),_()):Q.error(t.message)});return _(),()=>{t(),r()}},[_]);let v=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`},y=(0,V.useCallback)(e=>{let t=G.getState().session?.id;if(t){let n=J.getState().getAgentsBySession(t).filter(e=>e.status===`running`);if(n.length>0){g({open:!0,project:e,agentCount:n.length});return}}b(e)},[]),b=(0,V.useCallback)(e=>{let t=H();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`),Q.success(`Opening ${t.name} in a new tab...`)):Q.info(t.message)})},[]),x=(0,V.useCallback)(()=>{let e=c.trim();if(!e){Q.error(`Please enter a folder path.`);return}s(!0);let t=H();t.send({type:`projects.add`,payload:{root:e,name:u.trim()||void 0}});let n=t.on(`projects.added`,()=>{n(),s(!1),p(!1),l(``),d(``)})},[c,u]),S=h.open&&h.project&&(0,q.jsx)(Us,{open:!0,onOpenChange:()=>g({open:!1,project:null,agentCount:0}),children:(0,q.jsxs)(qs,{className:`sm:max-w-sm`,children:[(0,q.jsxs)(Js,{children:[(0,q.jsx)(Xs,{children:`Running Agents`}),(0,q.jsxs)(Zs,{children:[h.agentCount,` agent`,h.agentCount===1?` is`:`s are`,` running in the current session. Switching projects will stop them.`]})]}),(0,q.jsxs)(Ys,{children:[(0,q.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>g({open:!1,project:null,agentCount:0}),children:`Cancel`}),(0,q.jsx)($,{size:`sm`,variant:`destructive`,onClick:()=>{let e=h.project;g({open:!1,project:null,agentCount:0}),b(e)},children:`Switch anyway`})]})]})}),C=[...t].sort((e,t)=>e.lastSeen&&t.lastSeen?t.lastSeen.localeCompare(e.lastSeen):e.lastSeen?-1:t.lastSeen?1:e.name.localeCompare(t.name)),w=(0,q.jsxs)(Us,{open:f,onOpenChange:p,children:[(0,q.jsx)(Ws,{asChild:!0,children:(0,q.jsxs)($,{variant:`outline`,size:`sm`,className:`gap-1 h-7 text-xs`,children:[(0,q.jsx)(we,{className:`h-3 w-3`}),`Register Project`]})}),(0,q.jsxs)(qs,{className:`sm:max-w-md`,children:[(0,q.jsxs)(Js,{children:[(0,q.jsx)(Xs,{children:`Register New Project`}),(0,q.jsxs)(Zs,{children:[`Enter the absolute path to a project folder. The project will be added to`,` `,(0,q.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded text-xs`,children:`~/.wrongstack/projects.json`}),`.`]})]}),(0,q.jsxs)(`div`,{className:`space-y-3`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`label`,{htmlFor:`proj-folder`,className:`text-xs font-medium text-muted-foreground mb-1 block`,children:`Folder path`}),(0,q.jsx)(cc,{id:`proj-folder`,placeholder:`/home/user/my-project or C:\\Users\\me\\my-project`,value:c,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&m.current?.focus()}})]}),(0,q.jsxs)(`div`,{children:[(0,q.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,q.jsx)(cc,{id:`proj-name`,ref:m,placeholder:`My Project`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>{e.key===`Enter`&&x()}})]})]}),(0,q.jsxs)(Ys,{children:[(0,q.jsx)($,{variant:`outline`,size:`sm`,onClick:()=>p(!1),children:`Cancel`}),(0,q.jsxs)($,{size:`sm`,onClick:x,disabled:o||!c.trim(),children:[o?(0,q.jsx)(z,{className:`h-3 w-3 animate-spin mr-1`}):null,`Register`]})]})]})]});if(i){let t=(0,q.jsx)(`div`,{className:`flex items-center justify-center py-6`,children:(0,q.jsx)(z,{className:`h-4 w-4 animate-spin text-muted-foreground`})});return e?(0,q.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[(0,q.jsx)(`div`,{className:`px-3 py-2 border-b flex items-center justify-between`,children:(0,q.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`})}),(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:t})]}):t}let T=(0,q.jsx)(`div`,{className:Z(`space-y-1`,e&&`p-2`),children:C.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>y(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,q.jsx)(fe,{className:`h-3.5 w-3.5 shrink-0 mt-0.5 text-muted-foreground`}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`font-medium truncate`,children:e.name}),(0,q.jsx)(`div`,{className:`font-mono text-[10px] text-muted-foreground truncate`,children:e.root}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-[10px] text-muted-foreground/60`,children:[(0,q.jsx)(`span`,{className:`font-mono`,children:e.slug}),e.lastSeen&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(Gn,{className:`h-2.5 w-2.5`}),v(e.lastSeen)]})]})]}),(0,q.jsx)(r,{className:`h-3 w-3 shrink-0 mt-1 text-muted-foreground/40`})]},e.slug))});return e?(0,q.jsxs)(`div`,{className:`h-full flex flex-col overflow-hidden`,children:[S,(0,q.jsxs)(`div`,{className:`px-3 py-2 border-b shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`h2`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`Projects`}),w]}),(0,q.jsxs)(`p`,{className:`text-[10px] text-muted-foreground/60 mt-0.5`,children:[`Known projects from`,` `,(0,q.jsx)(`code`,{className:`font-mono bg-muted/40 px-0.5 rounded`,children:`~/.wrongstack/projects.json`})]})]}),t.length===0?(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center`,children:(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,q.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]})}):(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:T}),(0,q.jsx)(`div`,{className:`px-3 py-2 border-t shrink-0`,children:(0,q.jsx)(`p`,{className:`text-[9px] text-muted-foreground/40 text-center`,children:`Click a project to open it in a new WebUI tab`})})]}):(0,q.jsxs)(`div`,{className:`space-y-2`,children:[S,(0,q.jsx)(`div`,{className:`flex items-center justify-between`,children:w}),t.length===0?(0,q.jsxs)(`div`,{className:`text-xs text-muted-foreground italic py-2`,children:[`No projects registered. Use the button above or run`,` `,(0,q.jsx)(`code`,{className:`font-mono bg-muted/40 px-1 rounded`,children:`wstack`}),` `,`in a directory to register it.`]}):T]})}var $c=[` `,`▁`,`▂`,`▃`,`▄`,`▅`,`▆`,`▇`,`█`],el=12;function tl(e,t){return t===0?0:Math.min(8,Math.round(e/t*8))}function nl({bins:e,className:t,width:n=el}){let r=Array.from({length:el},(t,n)=>e.at(-(el-n))??0),i=Math.max(...r,1);return i===1&&r.every(e=>e===0)?(0,q.jsx)(`span`,{className:t,"aria-label":`No activity`,title:`No activity yet`,children:`—`}):(0,q.jsx)(`span`,{className:t,"aria-label":`Activity sparkline: max ${i} events`,title:`Activity sparkline — peak ${i} events/bucket`,children:r.map((e,t)=>{let n=tl(e,i),r=$c[n];return(0,q.jsx)(`span`,{style:{color:n>=7?`hsl(var(--success))`:`hsl(var(--muted-foreground))`,opacity:n>0?void 0:.3},children:r},t)})})}var rl={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 il(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function al(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function ol(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function sl({agent:e,onClose:t}){let n=rl[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool,a=Date.now()-e.startedAt,[o,s]=(0,V.useState)(!1),c=J(e=>e.leaderId),l=e.id===c,u=(0,V.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),2e3)}catch{}},[]),d=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,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-start justify-center pt-[10vh] bg-black/40 backdrop-blur-sm`,children:(0,q.jsxs)(`div`,{className:`w-full max-w-xl max-h-[80vh] overflow-y-auto rounded-xl border bg-card shadow-2xl`,children:[(0,q.jsxs)(`div`,{className:Z(`flex items-center justify-between px-4 py-3 border-b`,r?`border-primary/20`:`border-border`),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:Z(`led`,n.led,n.pulse&&`led-pulse`)}),(0,q.jsx)(`h3`,{className:`text-sm font-semibold`,children:e.name}),l&&(0,q.jsx)(Wt,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`,"aria-label":`leader`}),(0,q.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:n.label})]}),(0,q.jsx)(`button`,{type:`button`,onClick:t,className:`p-1 rounded-md hover:bg-muted transition-colors`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]}),(0,q.jsxs)(`div`,{className:`p-4 space-y-4`,children:[e.description&&(0,q.jsx)(`div`,{className:`text-xs text-muted-foreground leading-relaxed`,children:e.description}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Provider / Model`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,q.jsx)(hn,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsxs)(`span`,{className:`text-xs font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 mt-0.5`,children:[(0,q.jsx)(Et,{className:`h-3 w-3 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-xs font-mono tabular`,children:ol(a)}),r&&(0,q.jsx)(`span`,{className:`text-[10px] text-[hsl(var(--success))]`,children:`· running`})]})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Iterations`}),(0,q.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.iteration})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Tool Calls`}),(0,q.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:e.toolCalls})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,q.jsx)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:il(e.costUsd)})]}),e.extensions>0&&(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-3 py-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Budget Extensions`}),(0,q.jsxs)(`span`,{className:`block text-xs font-mono font-medium mt-0.5 tabular`,children:[`⚡×`,e.extensions]})]})]}),r&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity`}),(0,q.jsx)(nl,{bins:e.sparklineBins,className:`font-mono`})]}),e.budgetWarning&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,q.jsx)(Dn,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,q.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚡ hitting `,(0,q.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) — extending`]})]}),e.maxContext>0&&(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Context window`}),(0,q.jsxs)(`span`,{className:Z(`tabular font-medium`,d.replace(/bg-\S+\s*/g,``)),children:[e.ctxPct,`%`]})]}),(0,q.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-muted`,children:(0,q.jsx)(`div`,{className:Z(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.min(200,Math.max(2,e.ctxPct))}%`}})}),(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground tabular text-right`,children:[al(e.ctxTokens),` / `,al(e.maxContext),` tokens`]})]}),i&&(0,q.jsxs)(`div`,{className:Z(`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,q.jsx)(ht,{className:Z(`h-3.5 w-3.5`,r?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,q.jsx)(`span`,{className:`text-xs font-mono`,children:i}),(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto`,children:e.currentTool?`running…`:`last tool`})]}),e.error&&(0,q.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-3`,children:[(0,q.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`}),(0,q.jsx)(`p`,{className:`text-xs text-destructive/90 mt-1 leading-relaxed`,children:e.error.message})]}),e.finalText?(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Final Output`}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>u(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,q.jsx)(Be,{className:`h-3 w-3 text-emerald-500`}):(0,q.jsx)(St,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,q.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,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/20 p-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,q.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:`Live Output`}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>u(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,q.jsx)(Be,{className:`h-3 w-3 text-emerald-500`}):(0,q.jsx)(St,{className:`h-3 w-3`}),o?`Copied`:`Copy`]})]}),(0,q.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,q.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-3 text-center`,children:[(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`}),(0,q.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,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider`,children:[`Tool Log (`,e.toolLog.length,`)`]}),(0,q.jsxs)(`div`,{className:`max-h-40 overflow-y-auto space-y-0.5`,children:[e.toolLog.slice(0,15).map((e,t)=>(0,q.jsxs)(`div`,{className:Z(`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,q.jsx)(`span`,{className:Z(`led shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`)}),(0,q.jsx)(`span`,{className:`font-mono truncate flex-1`,children:e.name}),(0,q.jsxs)(`span`,{className:`tabular text-muted-foreground`,children:[e.durationMs,`ms`]}),!e.ok&&(0,q.jsx)(`span`,{className:`text-destructive font-medium`,children:`fail`})]},`${e.name}-${e.at}-${t}`)),e.toolLog.length>15&&(0,q.jsxs)(`p`,{className:`text-[9px] text-muted-foreground text-center px-2 py-0.5`,children:[`+`,e.toolLog.length-15,` more tools`]})]})]})]})]})})}function cl({a:e,onClick:t}){let n=rl[e.status],r=e.status===`running`,i=e.currentTool??e.lastTool;return(0,q.jsxs)(`button`,{type:`button`,onClick:t,className:Z(`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,q.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,q.jsx)(`span`,{className:Z(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,q.jsx)(`span`,{className:`truncate text-[11px] font-semibold text-foreground`,title:e.name,children:e.name}),(0,q.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it · `,e.toolCalls,`t`]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[e.model&&(0,q.jsxs)(`span`,{className:`flex items-center gap-0.5 text-[10px] text-muted-foreground truncate`,title:`${e.provider??``}/${e.model}`,children:[(0,q.jsx)(hn,{className:`h-2.5 w-2.5 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate font-mono`,children:e.model})]}),(0,q.jsx)(`span`,{className:`tabular text-[10px] text-foreground/75 ml-auto`,children:il(e.costUsd)})]}),i&&(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-1 text-[10px] truncate`,r?`text-primary`:`text-muted-foreground`),title:e.currentTool?`running ${i}`:`last: ${i}`,children:[(0,q.jsx)(ht,{className:Z(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse`)}),(0,q.jsx)(`span`,{className:`truncate font-mono`,children:i})]}),r&&e.maxContext>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,title:`Context ${e.ctxPct}%`,children:[(0,q.jsx)(`div`,{className:`h-1 flex-1 overflow-hidden rounded-full bg-muted`,children:(0,q.jsx)(`div`,{className:Z(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-[hsl(var(--warning))]`:`bg-primary`),style:{width:`${Math.min(200,Math.max(2,e.ctxPct))}%`}})}),(0,q.jsx)(`span`,{className:`tabular text-[9px] text-muted-foreground`,children:e.maxContext>0?`${e.ctxPct}%`:`—`})]}),e.error&&(0,q.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 ll({className:e}){let t=J(e=>e.agents),[n,r]=(0,V.useState)(!0),[i,a]=(0,V.useState)(null),o=(0,V.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,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:Z(`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,e),children:[(0,q.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,q.jsx)(Qt,{className:`h-3.5 w-3.5 text-primary`}),(0,q.jsx)(`span`,{className:`text-[11px] font-semibold text-foreground`,children:`Fleet`}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 ml-auto text-[10px]`,children:[c.length>0&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1 text-[hsl(var(--success))]`,children:[(0,q.jsx)(`span`,{className:`led led-pulse text-[hsl(var(--success))]`}),c.length]}),l.length>0&&(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[l.length,` done`]}),u.length>0&&(0,q.jsxs)(`span`,{className:`text-destructive`,children:[u.length,` err`]}),d>0&&(0,q.jsx)(`span`,{className:`tabular text-foreground/70`,children:il(d)})]}),f?(0,q.jsx)(Ie,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,q.jsx)(Kn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!f&&(0,q.jsx)(`div`,{className:`flex gap-2 overflow-x-auto px-2 pb-2`,children:o.map(e=>(0,q.jsx)(cl,{a:e,onClick:()=>a(e.id)},e.id))})]}),s&&(0,q.jsx)(sl,{agent:s,onClose:()=>a(null)})]})}var ul={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 dl(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function fl({agent:e,onClick:t}){let n=ul[e.status],r=e.status===`running`;return(0,q.jsxs)(`button`,{type:`button`,onClick:t,className:Z(`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,q.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,q.jsx)(`span`,{className:Z(`led shrink-0`,n.led,n.pulse&&`led-pulse`)}),(0,q.jsx)(`span`,{className:`truncate text-[11px] font-semibold`,title:e.name,children:e.name}),(0,q.jsxs)(`span`,{className:`tabular ml-auto shrink-0 text-[10px] text-muted-foreground`,children:[e.iteration,`it`]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-0.5 min-w-0`,children:[e.model?(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground truncate font-mono`,children:e.model}):(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`pending…`}),(0,q.jsx)(`span`,{className:`tabular ml-auto text-[10px] text-foreground/70`,children:dl(e.costUsd)})]}),(e.currentTool||e.lastTool)&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1 mt-1 text-[10px] text-muted-foreground truncate`,children:[(0,q.jsx)(ht,{className:Z(`h-2.5 w-2.5 shrink-0`,r&&`animate-pulse text-primary`)}),(0,q.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTool??e.lastTool})]})]})}function pl(){let e=J(e=>e.agents);K(e=>e.setCurrentView);let[t,n]=(0,V.useState)(null),r=(0,V.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]),i=r.filter(e=>e.status===`running`).length,a=t?r.find(e=>e.id===t)??null:null;return r.length===0?(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center p-4`,children:(0,q.jsxs)(`div`,{className:`text-center text-muted-foreground`,children:[(0,q.jsx)(Qt,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents yet`}),(0,q.jsx)(`p`,{className:`text-xs mt-1`,children:`Subagents appear here when the fleet is active.`})]})}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`px-3 py-2 border-b text-[10px] text-muted-foreground flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`font-semibold uppercase tracking-wider`,children:`Fleet`}),(0,q.jsxs)(`span`,{className:`ml-auto tabular-nums`,children:[i>0?`${i} running · `:``,r.length,` total`]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2 space-y-1.5`,children:r.map(e=>(0,q.jsx)(fl,{agent:e,onClick:()=>n(e.id)},e.id))}),(0,q.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,q.jsxs)(`button`,{type:`button`,onClick:()=>K.getState().setAgentsMonitorOpen(!0),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,q.jsx)(lt,{className:`h-3 w-3`}),`Open full agents view`]})}),a&&(0,q.jsx)(sl,{agent:a,onClose:()=>n(null)})]})}var ml=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 hl(e){return e.filter(e=>e.tokenTotal===0&&!e.isCurrent).map(e=>e.id)}function gl({historyQuery:e,setHistoryQuery:t,historyEntries:n,historyLoading:r,historyError:i,wsConnected:a,listSessions:o,resumeSession:s,deleteSession:c}){let l=K(e=>e.favoriteSessionIds),u=K(e=>e.toggleFavoriteSession),d=K(e=>e.sessionNicknames),f=K(e=>e.setSessionNickname),[p,m]=(0,V.useState)(null),[h,g]=(0,V.useState)(``),[_,v]=(0,V.useState)(null);(0,V.useEffect)(()=>{_&&n.some(e=>e.id===_&&e.isCurrent)&&v(null)},[_,n]);let y=(0,V.useCallback)(e=>{v(e),s(e),setTimeout(()=>v(t=>t===e?null:t),1e4)},[s]),b=(0,V.useMemo)(()=>hl(n),[n]),x=(0,V.useCallback)(async()=>{if(b.length!==0&&await nc({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,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b`,children:[(0,q.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground`,children:`Recent sessions`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[b.length>0&&(0,q.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,q.jsx)(Lt,{className:`h-3.5 w-3.5`})}),(0,q.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,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(ar,{className:`h-3.5 w-3.5`})})]})]}),n.length>3&&(0,q.jsx)(`div`,{className:`px-3 py-2 border-b`,children:(0,q.jsxs)(`div`,{className:`relative`,children:[(0,q.jsx)(ve,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground/60`}),(0,q.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,q.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,q.jsx)(Gt,{className:`h-3 w-3`})})]})}),i&&(0,q.jsx)(`div`,{className:`px-4 py-2 text-xs text-destructive bg-destructive/5 border-b`,children:i}),(0,q.jsx)(lc,{className:`flex-1`,children:n.length===0&&!r?(0,q.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,q.jsx)(Gn,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:`No history yet`}),(0,q.jsx)(`p`,{className:`text-xs mt-1`,children:`Your conversations will appear here`})]}):S.length===0?(0,q.jsxs)(`div`,{className:`text-center text-muted-foreground py-8 px-4`,children:[(0,q.jsx)(ve,{className:`h-8 w-8 mx-auto mb-3 opacity-20`}),(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:`No matches`}),(0,q.jsx)(`p`,{className:`text-xs mt-1`,children:`Try a different filter`})]}):(0,q.jsx)(`div`,{className:`p-2 space-y-3`,children:S.map(e=>(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:Z(`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,q.jsx)(Le,{className:`h-3 w-3 fill-current`}),e.label,` `,(0,q.jsxs)(`span`,{className:`text-muted-foreground/50 font-normal normal-case ml-1`,children:[`(`,e.rows.length,`)`]})]}),e.rows.map(e=>(0,q.jsxs)(`div`,{className:Z(`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,q.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,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[p===e.id?(0,q.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,q.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,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate mt-0.5`,children:[e.provider,`/`,e.model]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-muted-foreground/80 mt-0.5`,children:[_===e.id?(0,q.jsxs)(`span`,{className:`flex items-center gap-1 text-primary font-medium`,children:[(0,q.jsx)(z,{className:`h-3 w-3 animate-spin`}),`resuming…`]}):(0,q.jsx)(`span`,{children:ml(e.startedAt)}),e.tokenTotal>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[e.tokenTotal.toLocaleString(),` tok`]})]}),e.isCurrent&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`opacity-50`,children:`·`}),(0,q.jsx)(`span`,{className:`text-primary font-medium`,children:`active`})]})]})]})}),(0,q.jsxs)(`div`,{className:`absolute right-2 top-2 flex items-center gap-1`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>u(e.id),className:Z(`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,q.jsx)(Le,{className:Z(`h-3.5 w-3.5`,l.includes(e.id)&&`fill-current`)})}),!e.isCurrent&&(0,q.jsx)(`button`,{type:`button`,onClick:async()=>{await nc({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,q.jsx)(Lt,{className:`h-3.5 w-3.5`})})]})]},e.id))]},e.label))})})]})}function _l(){let e=W(e=>e.wsConnected),{entries:t,loading:n,error:r}=Nr(),{listSessions:i,resumeSession:a,deleteSession:o}=Da(),s=K(e=>e.setCurrentView),c=G(e=>e.session?.id),[l,u]=(0,V.useState)(``);return(0,V.useEffect)(()=>{e&&i(50)},[e,c,i]),(0,q.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,q.jsx)(gl,{historyQuery:l,setHistoryQuery:u,historyEntries:t,historyLoading:n,historyError:r,wsConnected:e,listSessions:i,resumeSession:a,deleteSession:o}),(0,q.jsx)(`div`,{className:`border-t px-3 py-2 shrink-0`,children:(0,q.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,q.jsx)(lt,{className:`h-3 w-3`}),`Open sessions dashboard`]})})]})}function vl(e){return e<=0?`$0.000`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(4)}`}function yl(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 bl({icon:e,label:t,onClick:n,disabled:r,tone:i,title:a}){return(0,q.jsxs)(`button`,{type:`button`,onClick:n,disabled:r,title:a??t,className:Z(`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 xl({label:e,value:t,sub:n}){return(0,q.jsxs)(`div`,{className:`flex flex-col p-2 rounded-lg bg-muted/40 border border-border/40 min-w-0`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:e}),(0,q.jsx)(`span`,{className:`text-sm font-semibold tabular-nums truncate`,children:t}),n&&(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground/70 truncate`,children:n})]})}function Sl({icon:e,label:t,right:n}){return(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wider text-muted-foreground font-semibold`,children:[e,t]}),n]})}function Cl({label:e,value:t,onChange:n,title:r}){return(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,title:r,children:[(0,q.jsx)(`span`,{className:`text-xs text-foreground/80`,children:e}),(0,q.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":t,onClick:n,className:Z(`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,q.jsx)(`span`,{className:Z(`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 wl(){let{client:e,updatePrefs:t,switchAutonomy:n}=Da(),r=W(e=>e.wsConnected),i=W(e=>e.wsUrl),a=W(e=>e.provider),o=W(e=>e.model),s=W(e=>e.soundOnComplete),c=G(e=>e.session),l=G(e=>e.totalTokens),u=G(e=>e.cost),d=G(e=>e.iteration),f=G(e=>e.todos),p=G(e=>e.lastInputTokens),m=G(e=>e.maxContext),h=U(e=>e.messages),_=U(e=>e.isLoading),v=J(e=>e.agents),y=K(e=>e.pinnedIds),x=K(e=>e.unpinAll),S=K(e=>e.setModelSwitcherOpen),C=ni(),w=(0,V.useCallback)((e,n)=>{C.set({[e]:n}),t({[e]:n})},[C,t]),[T,E]=(0,V.useState)(!1),D=c?.startedAt??null,[O,k]=(0,V.useState)(()=>Date.now());(0,V.useEffect)(()=>{if(!D)return;let e=setInterval(()=>k(Date.now()),1e3);return()=>clearInterval(e)},[D]);let A=(0,V.useMemo)(()=>Array.from(v.values()).filter(e=>e.status===`running`).length,[v]),ee=m>0&&p>0?Math.round(p/m*100):0,j=y.map(e=>h.find(t=>t.id===e)).filter(e=>!!e&&e.content.length>0),M=e=>H(i)?.send?.(e);return(0,q.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[(0,q.jsxs)(`div`,{className:`px-3 py-2.5 border-b grid grid-cols-2 gap-1.5`,children:[_?(0,q.jsx)(bl,{icon:(0,q.jsx)(g,{className:`h-3 w-3`}),label:`Abort`,tone:`danger`,onClick:()=>M({type:`abort`,payload:{}}),disabled:!r}):(0,q.jsx)(bl,{icon:(0,q.jsx)(Ye,{className:`h-3 w-3`}),label:`New session`,tone:`primary`,onClick:()=>{e?.newSession?.(),K.getState().setCurrentView(`chat`)},disabled:!r,title:`Start a new session (Ctrl+N)`}),(0,q.jsx)(bl,{icon:(0,q.jsx)(Pn,{className:`h-3 w-3`}),label:`Export`,onClick:()=>uo(),title:`Export chat as markdown (Ctrl+E)`}),(0,q.jsx)(bl,{icon:(0,q.jsx)(b,{className:`h-3 w-3`}),label:`Compact`,onClick:()=>M({type:`context.compact`,payload:{aggressive:!1}}),disabled:!r,title:`Compact the context window`}),(0,q.jsx)(bl,{icon:(0,q.jsx)(kt,{className:`h-3 w-3`}),label:`Clear`,onClick:()=>M({type:`context.clear`}),disabled:!r,title:`Clear context (Ctrl+L)`})]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>S(!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,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-0.5`,children:`Model`}),(0,q.jsxs)(`div`,{className:`font-mono text-xs truncate`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:a||`—`}),(0,q.jsx)(`span`,{className:`text-muted-foreground/40 mx-1`,children:`/`}),(0,q.jsx)(`span`,{className:`font-medium`,children:o||`—`})]})]}),m>0&&(0,q.jsxs)(`div`,{className:`px-4 py-2.5 border-b space-y-1.5`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>E(!0),className:`w-full block text-left`,title:`Click for a context breakdown`,children:(0,q.jsx)(Sl,{icon:null,label:`Context`,right:(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[No(p),`/`,No(m),` · `,ee,`%`]})})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>E(!0),className:`w-full block`,title:`Click for a context breakdown`,children:(0,q.jsx)(Vo,{pct:ee,tokens:p,maxTokens:m,showTokens:!0})})]}),(0,q.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,q.jsx)(Sl,{icon:(0,q.jsx)(hn,{className:`h-3 w-3`}),label:`Session`}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,q.jsx)(xl,{label:`Messages`,value:h.length}),(0,q.jsx)(xl,{label:`Elapsed`,value:D?yl(O-D):`--`}),(0,q.jsx)(xl,{label:`Tokens`,value:No(l.input+l.output),sub:`${No(l.input)} in / ${No(l.output)} out`}),(0,q.jsx)(xl,{label:`Cost`,value:vl(u)}),d&&(0,q.jsx)(xl,{label:`Iteration`,value:d.index,sub:d.max?`of ${d.max}`:void 0}),v.size>0&&(0,q.jsx)(xl,{label:`Agents`,value:v.size,sub:A>0?`${A} 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,q.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,q.jsx)(Sl,{icon:(0,q.jsx)(vn,{className:`h-3 w-3`}),label:`Plan`,right:(0,q.jsxs)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:[e,`/`,f.length]})}),(0,q.jsx)(`div`,{className:Z(`relative h-1.5 w-full overflow-hidden rounded-full bg-muted`,t>0&&`bar-sweep`),title:`${n}% complete`,children:(0,q.jsx)(`div`,{className:Z(`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,q.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`?ut:e.status===`in_progress`?It:yn,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,q.jsxs)(`li`,{className:Z(`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,q.jsx)(t,{className:Z(`h-3.5 w-3.5 mt-0.5 shrink-0`,n&&`text-primary animate-pulse`)}),(0,q.jsx)(`span`,{className:`break-words`,children:n&&e.activeForm?e.activeForm:e.content})]},e.id)})})]})})(),j.length>0&&(0,q.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1.5`,children:[(0,q.jsx)(Sl,{icon:(0,q.jsx)(Ge,{className:`h-3 w-3 text-amber-500`}),label:`Pinned`,right:(0,q.jsx)(`button`,{type:`button`,onClick:x,className:`text-[10px] text-muted-foreground hover:text-destructive`,children:`Clear`})}),(0,q.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,q.jsx)(`li`,{children:(0,q.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,q.jsxs)(`div`,{className:`px-3 py-2.5 border-b space-y-1`,children:[(0,q.jsx)(Sl,{icon:(0,q.jsx)(Ve,{className:`h-3 w-3`}),label:`Quick settings`}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,q.jsx)(`span`,{className:`text-xs text-foreground/80`,children:`Autonomy`}),(0,q.jsxs)(`select`,{value:C.autonomy,onChange:e=>{let t=e.target.value;C.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,q.jsx)(`option`,{value:`off`,children:`Off`}),(0,q.jsx)(`option`,{value:`suggest`,children:`Suggest`}),(0,q.jsx)(`option`,{value:`auto`,children:`Auto`}),(0,q.jsx)(`option`,{value:`eternal`,children:`Eternal`}),(0,q.jsx)(`option`,{value:`eternal-parallel`,children:`Eternal Parallel`})]})]}),(0,q.jsx)(Cl,{label:`YOLO mode`,title:`Bypass tool confirmation prompts`,value:C.yolo,onChange:()=>w(`yolo`,!C.yolo)}),(0,q.jsx)(Cl,{label:`Refine prompts`,title:`Rewrite prompts before sending`,value:C.enhanceEnabled,onChange:()=>w(`enhanceEnabled`,!C.enhanceEnabled)}),(0,q.jsx)(Cl,{label:`Sound on completion`,title:`Play a soft chime when a run finishes`,value:s,onChange:()=>{let e=!W.getState().soundOnComplete;W.getState().setSoundOnComplete(e),e&&Ni()}})]}),(0,q.jsxs)(`div`,{className:`px-4 py-2.5`,children:[(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-2 text-[11px]`,r?`text-[hsl(var(--success))]`:`text-[hsl(var(--warning))]`),children:[r?(0,q.jsx)(gn,{className:`h-3.5 w-3.5`}):(0,q.jsx)(jn,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`font-medium`,children:r?`Connected`:`Disconnected`}),(0,q.jsx)(`span`,{className:`text-muted-foreground font-mono truncate ml-auto`,title:i,children:i})]}),c&&(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono mt-1 truncate`,title:c.id,children:[`session `,c.id.slice(0,8)]})]}),(0,q.jsx)(Ho,{open:T,onClose:()=>E(!1)})]})}var Tl={project:`Project`,user:`Global`,bundled:`Bundled`};function El({source:e}){let t=`bundled`;return e===`project`?t=`project`:e===`user`&&(t=`user`),(0,q.jsx)(`span`,{className:Z(`inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-semibold uppercase tracking-wide`,t===`project`&&`bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-400`,t===`user`&&`bg-violet-100 text-violet-700 dark:bg-violet-950 dark:text-violet-400`,t===`bundled`&&`bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400`),children:Tl[t]??t})}function Dl({className:e}){let{client:t}=Da(),n=K(e=>e.skillsState),r=K(e=>e.setSkillsState),i=K(e=>e.setCurrentView),[a,o]=(0,V.useState)([]),[s,c]=(0,V.useState)(!1),[l,u]=(0,V.useState)(`all`),[d,f]=(0,V.useState)(``),p=(0,V.useRef)(n);p.current=n;let[m,h]=(0,V.useState)(!1),[g,_]=(0,V.useState)(``),[v,y]=(0,V.useState)(!1),[b,x]=(0,V.useState)(!1),[S,C]=(0,V.useState)(null),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)(!1),[O,k]=(0,V.useState)(``),[A,ee]=(0,V.useState)(``),[j,M]=(0,V.useState)(`project`),[N,P]=(0,V.useState)(!1),[F,I]=(0,V.useState)(null),[te,L]=(0,V.useState)(null),[ne,R]=(0,V.useState)(!1),[re,ie]=(0,V.useState)(!1),ae=(0,V.useCallback)(async()=>{if(!t||!g.trim())return;x(!0),C(null),T(null);let e=n=>{let r=n;x(!1),r.payload.success?(T(`Installed: ${r.payload.results?.map(e=>e.name).join(`, `)??g}`),t.send({type:`skills.list`})):C(r.payload.error??`Installation failed`),t.off(`skills.installed`,e)};t.on(`skills.installed`,e),t.installSkill(g.trim(),v)},[t,g,v]),oe=(0,V.useCallback)(()=>{if(!t||!O.trim()||!A.trim())return;P(!0),I(null),L(null);let e=n=>{let r=n;P(!1),r.payload.success?(L(`Created: ${r.payload.skill?.name}`),t.send({type:`skills.list`})):I(r.payload.error??`Creation failed`),t.off(`skills.created`,e)};t.on(`skills.created`,e),t.createSkill(O.trim(),A.trim(),j)},[t,O,A,j]),se=(0,V.useCallback)(()=>{t&&(ie(!0),t.checkForUpdates(void 0,void 0))},[t]),ce=(0,V.useCallback)(()=>{if(!t)return;R(!0);let e=n=>{let r=n;if(R(!1),r.payload.error)console.error(`[skills.export]`,r.payload.error);else{let e=atob(r.payload.zipBase64),t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n);let n=new Blob([t],{type:`application/zip`}),i=URL.createObjectURL(n),a=document.createElement(`a`);a.href=i,a.download=`wrongstack-skills-${Date.now()}.zip`,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(i)}t.off(`skills.exported`,e)};t.on(`skills.exported`,e),t.exportAllSkills()},[t]);(0,V.useEffect)(()=>{if(!t)return;c(!0);let e=e=>{let t=e;if(t.payload.enabled&&t.payload.skills){o(t.payload.skills);let e=p.current,n=e.knownRefs,i=0,a={...n};for(let e of t.payload.skills){if(e.source===`bundled`)continue;let t=e.ref;if(!t)continue;let r=n[e.name];a[e.name]=t,r&&r!==t&&i++}r({...e,knownRefs:a,updateAvailableCount:i})}c(!1)},n=e=>{let n=e;if(ie(!1),n.payload.success){let e=p.current,i={...e.knownRefs};for(let e of n.payload.updated??[])i[e.name]=e.newRef;r({...e,knownRefs:i,updateAvailableCount:0}),t.send({type:`skills.list`})}};return t.on(`skills.list`,e),t.on(`skills.updated`,n),t.send({type:`skills.list`}),()=>{t.off(`skills.list`,e),t.off(`skills.updated`,n)}},[t,r]);let le=(0,V.useCallback)(e=>{r({...p.current,selectedSkill:e,navHistory:[e],historyIndex:0,detailOpen:!0}),i(`skill`)},[r,i]),ue=(0,V.useMemo)(()=>{let e=a;if(l!==`all`&&(e=e.filter(e=>e.source===l)),d.trim()){let t=d.toLowerCase();e=e.filter(e=>e.name.toLowerCase().includes(t)||e.description.toLowerCase().includes(t)||e.trigger.toLowerCase().includes(t))}return e},[a,l,d]),de=(0,V.useMemo)(()=>{let e={project:[],user:[],bundled:[]};for(let t of ue){let n=t.source||`bundled`;e[n]?e[n].push(t):e.bundled.push(t)}return e},[ue]),fe=n.selectedSkill?.name;return(0,q.jsxs)(`div`,{className:Z(`flex flex-col h-full overflow-hidden`,e),children:[(0,q.jsxs)(`div`,{className:`w-full border-b flex items-center gap-1 px-2 py-2`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>{_(``),C(null),T(null),y(!1),h(!0)},className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,title:`Install skill`,children:(0,q.jsx)(Ye,{className:`h-4 w-4`})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>{k(``),ee(``),M(`project`),I(null),L(null),D(!0)},className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors`,title:`Create skill`,children:(0,q.jsx)(qe,{className:`h-4 w-4`})}),(0,q.jsx)(`button`,{type:`button`,onClick:ce,disabled:ne||a.length===0,className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-40`,title:`Export all skills as .zip`,children:ne?(0,q.jsx)(z,{className:`h-4 w-4 animate-spin`}):(0,q.jsx)(Pn,{className:`h-4 w-4`})}),(0,q.jsxs)(`button`,{type:`button`,onClick:se,disabled:re,className:`flex items-center justify-center w-8 h-8 rounded-lg text-muted-foreground hover:text-foreground hover:bg-accent transition-colors disabled:opacity-40 relative`,title:`Check for updates (all skills)`,children:[re?(0,q.jsx)(z,{className:`h-4 w-4 animate-spin`}):(0,q.jsx)(ar,{className:`h-4 w-4`}),!re&&n.updateAvailableCount>0&&(0,q.jsx)(`span`,{className:`absolute top-0.5 right-0.5 h-2.5 w-2.5 rounded-full bg-primary text-[8px] font-bold text-primary-foreground flex items-center justify-center`,children:n.updateAvailableCount>9?`9+`:n.updateAvailableCount})]})]}),(0,q.jsxs)(`div`,{className:`p-2 space-y-2 border-b shrink-0`,children:[(0,q.jsx)(`input`,{type:`text`,value:d,onChange:e=>f(e.target.value),placeholder:`Search skills…`,className:`w-full px-2 py-1.5 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring`}),(0,q.jsx)(`div`,{className:`flex gap-1 flex-wrap`,children:[`all`,`project`,`user`,`bundled`].map(e=>{let t=e===`all`?ue.length:ue.filter(t=>t.source===e).length;return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>u(e),className:Z(`px-1.5 py-0.5 text-[10px] rounded transition-colors`,l===e?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),children:[e===`all`?`All`:Tl[e],(0,q.jsxs)(`span`,{className:Z(`ml-1 font-medium`,l===e?`opacity-90`:`opacity-60`,t===0&&`line-through`),children:[`(`,t,`)`]})]},e)})})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:s?(0,q.jsx)(`div`,{className:`p-4 text-xs text-muted-foreground text-center`,children:`Loading…`}):ue.length===0?(0,q.jsx)(`div`,{className:`p-4 text-xs text-muted-foreground text-center`,children:a.length===0?`No skills installed`:`No skills match filter`}):(0,q.jsx)(`div`,{className:`py-1`,children:[`project`,`user`,`bundled`].map(e=>{let t=de[e];return t.length===0?null:(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`px-2 py-1 text-[10px] font-semibold text-muted-foreground uppercase tracking-wide flex items-center gap-1`,children:[(0,q.jsx)(El,{source:e}),(0,q.jsx)(`span`,{className:`ml-auto opacity-60`,children:t.length})]}),t.map(e=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>le(e),className:Z(`w-full text-left px-2 py-1.5 text-xs transition-colors`,fe===e.name?`bg-primary/10 text-primary`:`hover:bg-accent/50 text-foreground`),children:[(0,q.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1`,children:[(0,q.jsx)(qn,{className:`h-3 w-3 shrink-0`}),e.name]}),(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground truncate mt-0.5`,children:e.trigger||e.description?.slice(0,50)||`No description`})]},e.name))]},e)})})}),m&&(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,onClick:e=>{e.target===e.currentTarget&&h(!1)},children:(0,q.jsxs)(`div`,{className:`bg-background rounded-lg border shadow-xl w-[420px] max-w-[90vw]`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Pn,{className:`h-4 w-4 text-primary`}),(0,q.jsx)(`span`,{className:`font-semibold text-sm`,children:`Install Skill`})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>h(!1),className:`p-1 rounded hover:bg-accent text-muted-foreground cursor-pointer`,children:`✕`})]}),(0,q.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Enter a GitHub repository reference (`,(0,q.jsx)(`span`,{className:`font-mono text-[10px]`,children:`owner/repo`}),`) or full URL.`]}),(0,q.jsx)(`input`,{type:`text`,value:g,onChange:e=>{_(e.target.value),C(null),T(null)},onKeyDown:e=>{e.key===`Enter`&&!b&&ae()},placeholder:`e.g. wrongstack/skill-name or https://github.com/owner/repo`,className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring`,autoFocus:!0}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:`Install scope:`}),(0,q.jsxs)(`div`,{className:`flex rounded border border-border overflow-hidden`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>y(!1),className:Z(`px-2 py-1 text-[10px] transition-colors`,v?`bg-background hover:bg-accent`:`bg-primary text-primary-foreground`),children:`Project`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>y(!0),className:Z(`px-2 py-1 text-[10px] transition-colors border-l border-border`,v?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:`Global`})]})]}),S&&(0,q.jsx)(`p`,{className:`text-xs text-destructive bg-destructive/10 rounded px-2 py-1`,children:S}),w&&(0,q.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 rounded px-2 py-1`,children:w})]}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t bg-muted/20`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>h(!1),className:`px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors`,children:w?`Close`:`Cancel`}),!w&&(0,q.jsxs)(`button`,{type:`button`,onClick:ae,disabled:b||!g.trim(),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[b&&(0,q.jsx)(z,{className:`h-3 w-3 animate-spin`}),`Install`]})]})]})}),E&&(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,onClick:e=>{e.target===e.currentTarget&&D(!1)},children:(0,q.jsxs)(`div`,{className:`bg-background rounded-lg border shadow-xl w-[480px] max-w-[90vw]`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(qe,{className:`h-4 w-4 text-primary`}),(0,q.jsx)(`span`,{className:`font-semibold text-sm`,children:`Create Skill`})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>D(!1),className:`p-1 rounded hover:bg-accent text-muted-foreground cursor-pointer`,children:`✕`})]}),(0,q.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Scaffold a new skill. The first line is the trigger; additional lines form the description.`}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`block text-xs font-medium mb-1`,children:[`Name `,(0,q.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,q.jsx)(`input`,{type:`text`,value:O,onChange:e=>{k(e.target.value.trim().toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``)),I(null),L(null)},placeholder:`e.g. my-new-skill`,className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring font-mono`,autoFocus:!0})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`label`,{className:`block text-xs font-medium mb-1`,children:[`Description / Trigger `,(0,q.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,q.jsx)(`textarea`,{value:A,onChange:e=>{ee(e.target.value),I(null),L(null)},onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&!N&&oe()},placeholder:`Use this skill when <trigger situation>.
|
|
114
|
-
Triggers: user says "keyword", "another".`,rows:4,className:`w-full px-3 py-2 text-xs rounded border border-border bg-background focus:outline-none focus:ring-1 focus:ring-ring resize-y`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:`Save in:`}),(0,q.jsxs)(`div`,{className:`flex rounded border border-border overflow-hidden`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>M(`project`),className:Z(`px-2 py-1 text-[10px] transition-colors`,j===`project`?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:`Project`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>M(`global`),className:Z(`px-2 py-1 text-[10px] transition-colors border-l border-border`,j===`global`?`bg-primary text-primary-foreground`:`bg-background hover:bg-accent`),children:`Global`})]})]}),F&&(0,q.jsx)(`p`,{className:`text-xs text-destructive bg-destructive/10 rounded px-2 py-1`,children:F}),te&&(0,q.jsx)(`p`,{className:`text-xs text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 rounded px-2 py-1`,children:te})]}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t bg-muted/20`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>D(!1),className:`px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors`,children:te?`Close`:`Cancel`}),!te&&(0,q.jsxs)(`button`,{type:`button`,onClick:oe,disabled:N||!O.trim()||!A.trim(),className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[N&&(0,q.jsx)(z,{className:`h-3 w-3 animate-spin`}),`Create Skill`]})]})]})})]})}function Ol({label:e,checked:t,onChange:n}){return(0,q.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),className:`flex w-full items-center justify-between px-2 py-1.5 rounded text-xs hover:bg-accent/50 transition-colors`,children:[(0,q.jsx)(`span`,{className:`text-foreground`,children:e}),(0,q.jsx)(`span`,{className:Z(`relative inline-flex h-4 w-7 shrink-0 items-center rounded-full transition-colors`,t?`bg-primary`:`bg-muted`),children:(0,q.jsx)(`span`,{className:Z(`inline-block h-3 w-3 transform rounded-full bg-background transition-transform`,t?`translate-x-3.5`:`translate-x-0.5`)})})]})}var kl=[{value:`dots`,label:`Dots`},{value:`lines`,label:`Lines`},{value:`cross`,label:`Cross`},{value:`none`,label:`None`}];function Al(){let{showHud:e,showLegend:t,showMinimap:n,showControls:r,animateEdges:i,background:a,setShowHud:o,setShowLegend:s,setShowMinimap:c,setShowControls:l,setAnimateEdges:u,setBackground:d}=Ci(),{clientCounts:f,currentSession:p,totalAgents:m,activeAgents:h}=mi(),g=f.tui+f.webui+f.repl;return(0,q.jsxs)(`div`,{className:`flex flex-col h-full overflow-y-auto p-3 gap-4`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-2`,children:`Live`}),(0,q.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(zn,{className:`h-3.5 w-3.5`}),` Clients`]}),(0,q.jsx)(`span`,{className:`font-mono`,children:g})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(Qt,{className:`h-3.5 w-3.5`}),` Agents`]}),(0,q.jsxs)(`span`,{className:`font-mono`,children:[h,(0,q.jsxs)(`span`,{className:`text-muted-foreground`,children:[` / `,m]})]})]}),p.model&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(hn,{className:`h-3.5 w-3.5`}),` Model`]}),(0,q.jsx)(`span`,{className:`font-mono truncate max-w-[140px]`,title:p.model,children:p.model.split(`/`).pop()})]}),p.mode&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(Dn,{className:`h-3.5 w-3.5`}),` Mode`]}),(0,q.jsx)(`span`,{className:`font-mono uppercase text-[10px]`,children:p.mode})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-muted-foreground`,children:[(0,q.jsx)(ir,{className:`h-3.5 w-3.5`}),` Tool calls`]}),(0,q.jsx)(`span`,{className:`font-mono`,children:(e=>e?.toLocaleString()??`0`)(p.toolCalls)})]})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1`,children:`Display`}),(0,q.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,q.jsx)(Ol,{label:`Stats HUD`,checked:e,onChange:o}),(0,q.jsx)(Ol,{label:`Legends`,checked:t,onChange:s}),(0,q.jsx)(Ol,{label:`Minimap`,checked:n,onChange:c}),(0,q.jsx)(Ol,{label:`Zoom controls`,checked:r,onChange:l}),(0,q.jsx)(Ol,{label:`Animate wires`,checked:i,onChange:u})]})]}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`div`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1.5 px-2`,children:`Background`}),(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1 px-2`,children:kl.map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>d(e.value),className:Z(`px-2 py-1 text-[10px] rounded transition-colors`,a===e.value?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground hover:bg-accent`),children:e.label},e.value))})]})]})}var jl={chat:`Session`,agents:`Agents`,history:`History`,files:`Files`,projects:`Projects`,mailbox:`Mailbox`,skills:`Skills`,officemap:`Office Map`};function Ml(){let e=K(e=>e.activeActivity),t=K(e=>e.setSidebarOpen),n=K(e=>e.sidebarWidth),r=K(e=>e.setSidebarWidth),i=W(e=>e.wsConnected),{client:a}=Da();return(0,V.useEffect)(()=>{if(e!==`files`||!i)return;Y.getState().setTreeLoading(!0);let t=G.getState().cwd;a?.send({type:`files.tree`,payload:t?{path:t}:{}})},[e,i,a]),(0,q.jsxs)(`aside`,{style:{width:`${n}px`},className:`relative border-r bg-card flex flex-col shrink-0 overflow-hidden animate-slide-in`,children:[(0,q.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,q.jsx)(`div`,{className:`h-full w-px bg-border group-hover/handle:bg-primary/60 group-hover/handle:w-0.5 transition-all`})}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2.5 border-b shrink-0`,children:[(0,q.jsx)(`span`,{className:`text-xs font-semibold tracking-tight text-muted-foreground uppercase`,children:jl[e]}),(0,q.jsx)($,{variant:`ghost`,size:`icon`,className:`h-6 w-6`,onClick:()=>t(!1),title:`Collapse panel (Ctrl+\\)`,children:(0,q.jsx)(tt,{className:`h-3.5 w-3.5`})})]}),(0,q.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[e===`chat`&&(0,q.jsx)(wl,{}),e===`agents`&&(0,q.jsx)(pl,{}),e===`history`&&(0,q.jsx)(_l,{}),e===`files`&&(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,q.jsx)(Jc,{})}),e===`projects`&&(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,q.jsx)(Qc,{})}),e===`mailbox`&&(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,q.jsx)(Zc,{})}),e===`skills`&&(0,q.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,q.jsx)(Dl,{className:`h-full`})}),e===`officemap`&&(0,q.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,q.jsx)(Al,{})})]})]})}function Nl(){let e=Mr(e=>e.info),{client:t}=Da(),n=(0,V.useRef)(null),r=(0,V.useCallback)(()=>{t?.getGitInfo?.()},[t]);return(0,V.useEffect)(()=>(r(),n.current=setInterval(r,3e4),()=>{n.current&&clearInterval(n.current)}),[r]),e}function Pl({sessionId:e,className:t}){let[n,r]=(0,V.useState)([]),[i,a]=(0,V.useState)(!1),[o,s]=(0,V.useState)(null),[c,l]=(0,V.useState)(null),[u,d]=(0,V.useState)(0),[f,p]=(0,V.useState)(!1),m=H(W(e=>e.wsUrl));(0,V.useEffect)(()=>{let t=[];return t.push(m.on(`collab.state`,t=>{let n=t.payload;n.sessionId===e&&r(n.participants??[])})),t.push(m.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(m.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(m.on(`error`,e=>{let t=e.payload;t.phase===`collab`&&(l(t.message),a(!1))})),t.push(m.on(`collab.annotation.added`,t=>{let n=t.payload;n.sessionId===e&&(n.annotation?.resolved||d(e=>e+1))})),t.push(m.on(`collab.annotation.resolved`,t=>{t.payload.sessionId===e&&d(e=>Math.max(0,e-1))})),t.push(m.on(`collab.pause.granted`,t=>{t.payload.sessionId===e&&p(!0)})),t.push(m.on(`collab.pause.released`,t=>{t.payload.sessionId===e&&p(!1)})),()=>{for(let e of t)e()}},[m,e]);let h=(t=`observer`)=>{l(null),m.send({type:`collab.join`,payload:{sessionId:e,role:t}}),a(!0),s(t)};return n.length===0&&!c?(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-2 px-3 py-2 rounded-md border border-dashed border-border bg-card/40`,t),children:[(0,q.jsx)(zn,{className:`w-4 h-4 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`No live observers`}),(0,q.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>h(`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,q.jsx)(Tt,{className:`w-3 h-3`}),`observer`]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>h(`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,q.jsx)(mn,{className:`w-3 h-3`}),`annotator`]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>h(`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,q.jsx)(Cn,{className:`w-3 h-3`}),`controller`]})]})]}):c?(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-2 px-3 py-2 rounded-md border border-destructive/50 bg-destructive/10`,t),role:`alert`,children:[(0,q.jsxs)(`span`,{className:`text-xs text-destructive`,children:[`Collab: `,c]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>{l(null),a(!1)},className:`ml-auto text-xs underline text-destructive`,children:`dismiss`})]}):(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-2 px-3 py-2 rounded-md border border-emerald-500/40 bg-emerald-500/5`,t),children:[(0,q.jsxs)(`span`,{className:`relative flex h-2 w-2`,"aria-label":`Live`,children:[(0,q.jsx)(`span`,{className:`absolute inline-flex h-full w-full rounded-full bg-emerald-400 opacity-75 animate-ping`}),(0,q.jsx)(`span`,{className:`relative inline-flex rounded-full h-2 w-2 bg-emerald-500`})]}),(0,q.jsx)(zn,{className:`w-4 h-4 text-emerald-700 dark:text-emerald-400`}),(0,q.jsxs)(`span`,{className:`text-xs font-medium text-emerald-700 dark:text-emerald-300`,children:[n.length,` `,n.length===1?`observer`:`observers`]}),u>0&&(0,q.jsxs)(`span`,{title:`${u} 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,q.jsx)(mn,{className:`w-3 h-3`}),u,` note`,u===1?``:`s`]}),f&&(0,q.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,q.jsx)(Cn,{className:`w-3 h-3`}),`paused`]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 ml-2`,children:[n.slice(0,3).map(e=>(0,q.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,q.jsx)(ot,{className:`w-3 h-3`}),e.role]},e.participantId)),n.length>3&&(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,n.length-3]})]}),i&&o===`controller`&&(f?(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{m.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,q.jsx)(P,{className:`w-3 h-3`}),`Resume`]}):(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{m.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,q.jsx)(Cn,{className:`w-3 h-3`}),`Pause agent`]})),i&&o!==`controller`&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{m.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,q.jsx)(Ln,{className:`w-3 h-3`}),`Leave`]})]})}var Fl={up:(0,q.jsx)(cn,{className:`h-3.5 w-3.5 text-emerald-500`}),down:(0,q.jsx)(Vt,{className:`h-3.5 w-3.5 text-red-500`}),stable:(0,q.jsx)(Tn,{className:`h-3.5 w-3.5 text-amber-500`})},Il={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 Ll({goal:e,className:t}){let[n,r]=(0,V.useState)(!1);if((0,V.useEffect)(()=>{let e=H();e?.send?.({type:`goal.get`});let t=setInterval(()=>{e?.send?.({type:`goal.get`})},1e4);return()=>clearInterval(t)},[]),(0,V.useEffect)(()=>{(!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)&&r(!0)},[e]),!e||e.goalState===`completed`||e.goalState===`failed`||e.goalState===`abandoned`)return null;let i=Il[e.goalState],a=e.deliverables?.filter(e=>e.status===`done`).length??0,o=e.deliverables?.length??0,s=e.journal?.slice(-5).reverse()??[],c=e.progressTrend?Fl[e.progressTrend]:null;return(0,q.jsxs)(`div`,{className:Z(`rounded-lg border border-border bg-card/60 backdrop-blur-sm`,t),children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>r(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,q.jsx)(tr,{className:`h-4 w-4 text-rose-500`}),(0,q.jsx)(`span`,{className:`text-xs font-semibold text-foreground flex-1 min-w-0 truncate`,children:`Goal`}),(0,q.jsx)(`span`,{className:Z(`inline-flex items-center px-1.5 py-0.5 rounded-full text-[10px] font-medium shrink-0`,i.bg,i.color),children:i.label}),n?(0,q.jsx)(Ie,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,q.jsx)(Kn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]}),!n&&(0,q.jsxs)(`div`,{className:`px-3 pb-3 space-y-3 border-t pt-2`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`text-xs text-foreground leading-relaxed whitespace-pre-wrap break-words`,children:e.goal}),e.refinedGoal&&e.refinedGoal!==e.goal&&(0,q.jsxs)(`div`,{className:`mt-1.5 p-2 rounded bg-accent/40 border border-border/50`,children:[(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground mb-0.5 uppercase tracking-wider font-medium`,children:`Refined`}),(0,q.jsx)(`p`,{className:`text-xs leading-relaxed whitespace-pre-wrap break-words`,children:e.refinedGoal})]})]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between text-[10px]`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground uppercase tracking-wider font-medium`,children:`Progress`}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1 tabular-nums`,children:[c,(0,q.jsxs)(`span`,{className:`font-medium text-foreground`,children:[e.progress,`%`]})]})]}),(0,q.jsx)(`div`,{className:`h-1.5 bg-muted rounded-full overflow-hidden`,children:(0,q.jsx)(`div`,{className:Z(`h-full transition-all duration-700 rounded-full`,e.progress>=80?`bg-emerald-500`:e.progress>=50?`bg-amber-500`:`bg-primary`),style:{width:`${e.progress>0?Math.max(2,e.progress):0}%`}})}),e.progressNote&&(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground italic`,children:e.progressNote})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(Et,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{className:`tabular-nums font-medium`,children:e.iterations}),(0,q.jsx)(`span`,{children:`iterations`}),e.lastStatus&&(0,q.jsx)(`span`,{className:`text-border`,children:`·`}),e.lastStatus&&(0,q.jsx)(`span`,{className:`truncate`,children:e.lastStatus})]}),o>0&&(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:[(0,q.jsx)(`span`,{children:`Deliverables`}),(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[a,`/`,o]})]}),(0,q.jsx)(`ul`,{className:`space-y-0.5`,children:e.deliverables?.map(e=>(0,q.jsxs)(`li`,{className:`flex items-start gap-1.5 text-[11px]`,children:[e.status===`done`?(0,q.jsx)(ut,{className:`h-3 w-3 text-emerald-500 mt-0.5 shrink-0`}):(0,q.jsx)(yn,{className:`h-3 w-3 text-muted-foreground/50 mt-0.5 shrink-0`}),(0,q.jsx)(`span`,{className:Z(`leading-snug`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground`),children:e.text})]},e.id))})]}),s.length>0&&(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider font-medium`,children:`Recent Activity`}),(0,q.jsx)(`div`,{className:`space-y-1`,children:s.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-muted-foreground`,children:[(0,q.jsxs)(`span`,{className:`font-mono tabular-nums shrink-0 text-foreground/60`,children:[`#`,e.iteration]}),(0,q.jsx)(`span`,{className:`truncate`,children:e.task||e.status||e.progressNote||`…`})]},`${e.iteration}-${t}`))})]})]})]})}var Rl={in_progress:0,pending:1,completed:2};function zl(){let[e,t]=(0,V.useState)([]),[n,r]=(0,V.useState)(new Set),i=H(),a=(0,V.useRef)(null);(0,V.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,V.useCallback)(e=>{i.removeTodo(e)},[i]),s=(0,V.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)=>(Rl[e.status]??9)-(Rl[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,q.jsxs)(`div`,{onClick:()=>i&&s(e),className:Z(`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,q.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:r?(0,q.jsx)(ut,{className:`w-3.5 h-3.5 text-emerald-500`}):n?(0,q.jsx)(Et,{className:`w-3.5 h-3.5 text-yellow-500 animate-spin`}):(0,q.jsx)(yn,{className:Z(`w-3.5 h-3.5 transition-colors`,`text-muted-foreground/40 group-hover:text-emerald-400`)})}),(0,q.jsx)(`span`,{className:Z(`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,q.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,q.jsx)(Lt,{className:`w-3 h-3 text-muted-foreground`})})]},e.id)};return e.length===0?null:(0,q.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,q.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Todos`}),(0,q.jsxs)(`span`,{className:`tabular text-[10px] text-muted-foreground ml-auto`,children:[d.length,`/`,e.length]})]}),l.length>0&&(0,q.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:l.map(h)}),u.length>0&&(0,q.jsx)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:u.map(h)}),f&&(0,q.jsxs)(`div`,{children:[(0,q.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,q.jsxs)(`span`,{className:`tabular`,children:[p?`▶`:`▼`,` `,d.length,` completed`]})}),!p&&d.map(h)]})]})}var Bl={pending:{icon:(0,q.jsx)(yn,{className:`w-3.5 h-3.5`}),label:`Pending`,color:`text-muted-foreground/50`},in_progress:{icon:(0,q.jsx)(Et,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},blocked:{icon:(0,q.jsx)(Cn,{className:`w-3.5 h-3.5`}),label:`Blocked`,color:`text-orange-500`},failed:{icon:(0,q.jsx)(sn,{className:`w-3.5 h-3.5`}),label:`Failed`,color:`text-red-500`},review:{icon:(0,q.jsx)(L,{className:`w-3.5 h-3.5`}),label:`Review`,color:`text-blue-500`},completed:{icon:(0,q.jsx)(ut,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}},Vl={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`},Hl={feature:`⚡`,bugfix:`🐛`,refactor:`♻️`,docs:`📝`,test:`🧪`,chore:`🔧`};function Ul(){let[e,t]=(0,V.useState)([]),[n,r]=(0,V.useState)(new Set),i=H(),a=(0,V.useRef)(null);(0,V.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,V.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,V.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,q.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,q.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`Tasks`}),(0,q.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=Bl[e],i=n.has(e);return(0,q.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,q.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,q.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,q.jsxs)(`div`,{className:Z(`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,q.jsx)(`span`,{className:Z(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,q.jsxs)(`span`,{className:`leading-snug flex-1 min-w-0`,children:[(0,q.jsxs)(`span`,{className:Z(e.status===`completed`?`text-muted-foreground line-through`:`text-foreground/80`),children:[Hl[e.type],` `,e.title]}),e.priority!==`medium`&&(0,q.jsx)(`span`,{className:Z(`ml-1 text-[10px]`,Vl[e.priority]),children:e.priority}),e.assignee&&(0,q.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[`@`,e.assignee]}),e.estimateHours&&(0,q.jsxs)(`span`,{className:`ml-1 text-[10px] text-muted-foreground`,children:[e.estimateHours,`h`]})]}),(0,q.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,q.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,q.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,q.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 Wl={open:{icon:(0,q.jsx)(yn,{className:`w-3.5 h-3.5`}),label:`Open`,color:`text-muted-foreground/50`},in_progress:{icon:(0,q.jsx)(Et,{className:`w-3.5 h-3.5 animate-spin`}),label:`In Progress`,color:`text-yellow-500`},done:{icon:(0,q.jsx)(ut,{className:`w-3.5 h-3.5`}),label:`Done`,color:`text-emerald-500`}};function Gl(){let[e,t]=(0,V.useState)([]),[n,r]=(0,V.useState)(new Set),i=H(),a=(0,V.useRef)(null);(0,V.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,V.useCallback)(e=>{r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=(0,V.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,q.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:`px-3 py-1.5 flex items-center gap-2 border-b border-border/50`,children:[(0,q.jsx)(`h2`,{className:`text-[11px] font-semibold text-foreground uppercase tracking-wider`,children:`📋 Plan`}),(0,q.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=Wl[e],i=n.has(e);return(0,q.jsxs)(`div`,{className:`border-b border-border/30 last:border-b-0`,children:[(0,q.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,q.jsxs)(`span`,{className:`tabular`,children:[i?`▶`:`▼`,` `,t.length,` `,r.label]})}),!i&&t.map(e=>(0,q.jsxs)(`div`,{className:Z(`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,q.jsx)(`span`,{className:Z(`mt-0.5 shrink-0`,r.color),children:r.icon}),(0,q.jsx)(`span`,{className:Z(`leading-snug flex-1 min-w-0`,e.status===`done`?`text-muted-foreground line-through`:`text-foreground/80`),children:e.title}),(0,q.jsxs)(`div`,{className:`flex gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0`,children:[e.status===`open`&&(0,q.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,q.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,q.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 Kl=[{id:`todos`,label:`Todos`,icon:`✅`},{id:`tasks`,label:`Tasks`,icon:`📋`},{id:`plan`,label:`Plan`,icon:`🗺️`}];function ql(){let[e,t]=(0,V.useState)(`todos`);return(0,q.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/50 backdrop-blur-sm overflow-hidden`,children:[(0,q.jsx)(`div`,{className:`flex border-b border-border/50 bg-muted/30`,children:Kl.map(n=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>t(n.id),className:Z(`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,q.jsx)(`span`,{className:`text-xs`,children:n.icon}),n.label]},n.id))}),(0,q.jsx)(`div`,{className:Z(e===`todos`?`block`:`hidden`),children:(0,q.jsx)(zl,{})}),(0,q.jsx)(`div`,{className:Z(e===`tasks`?`block`:`hidden`),children:(0,q.jsx)(Ul,{})}),(0,q.jsx)(`div`,{className:Z(e===`plan`?`block`:`hidden`),children:(0,q.jsx)(Gl,{})})]})}var Jl={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 Yl({section:e,icon:t,label:n,value:r,active:i,pulse:a,onClick:o}){let s=Jl[e];return(0,q.jsxs)(`button`,{type:`button`,onClick:o,title:i?`Collapse ${n}`:`Expand ${n}`,className:Z(`flex items-center gap-1.5 h-6 px-2 rounded-full border text-[11px] font-medium shrink-0 transition-colors`,i?s.active:Z(`border-transparent`,s.idle)),children:[(0,q.jsx)(`span`,{className:Z(a&&`animate-pulse`),children:t}),n,r&&(0,q.jsx)(`span`,{className:`tabular-nums opacity-80`,children:r})]})}function Xl({sessionId:e}){let{selectAutoPhase:t,toggleAutoPhaseAutonomous:n}=Da(),r=K(e=>e.dockSection),i=K(e=>e.toggleDockSection),a=K(e=>e.setCurrentView),o=$r(e=>e.goal),s=ei(e=>e),c=Pr(e=>e.worktrees),l=Pr(e=>e.baseBranch),u=G(e=>e.todos),d=J(e=>e.agents),f=Nl(),p=(0,V.useCallback)(e=>t(e),[t]),m=(0,V.useCallback)(()=>n(!s.autonomous),[n,s.autonomous]),[h,g]=(0,V.useState)(`graph`),_=d.size,v=(0,V.useMemo)(()=>Array.from(d.values()).filter(e=>e.status===`running`).length,[d]),y=u.filter(e=>e.status===`completed`).length,b=u.some(e=>e.status===`in_progress`),x=s.phases.length>0,S=(0,V.useRef)(s.phases.length);(0,V.useEffect)(()=>{let e=K.getState();S.current===0&&s.phases.length>0&&e.dockSection===null&&e.setDockSection(`autophase`),s.phases.length===0&&e.dockSection===`autophase`&&e.setDockSection(null),S.current=s.phases.length},[s.phases.length]);let C={autophase:x,goal:o!==null,fleet:_>0,work:!0,worktrees:c.length>0,collab:!0},w=r&&C[r]?r:null;return(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[C.autophase&&(0,q.jsx)(Yl,{section:`autophase`,icon:(0,q.jsx)(ue,{className:`h-3 w-3`}),label:`AutoPhase`,value:`${s.overallPercent}%`,active:w===`autophase`,pulse:s.activePhaseId!=null,onClick:()=>i(`autophase`)}),C.goal&&o&&(0,q.jsx)(Yl,{section:`goal`,icon:(0,q.jsx)(tr,{className:`h-3 w-3`}),label:`Goal`,value:`${o.progress}%`,active:w===`goal`,pulse:o.goalState===`active`,onClick:()=>i(`goal`)}),C.fleet&&(0,q.jsx)(Yl,{section:`fleet`,icon:(0,q.jsx)(Qt,{className:`h-3 w-3`}),label:`Fleet`,value:`${v}/${_}`,active:w===`fleet`,pulse:v>0,onClick:()=>i(`fleet`)}),(0,q.jsx)(Yl,{section:`work`,icon:(0,q.jsx)(vn,{className:`h-3 w-3`}),label:`Work`,value:u.length>0?`${y}/${u.length}`:void 0,active:w===`work`,pulse:b,onClick:()=>i(`work`)}),C.worktrees&&(0,q.jsx)(Yl,{section:`worktrees`,icon:(0,q.jsx)(Zt,{className:`h-3 w-3`}),label:`Worktrees`,value:String(c.length),active:w===`worktrees`,onClick:()=>i(`worktrees`)}),f&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>{},className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md text-[11px] font-mono border border-transparent hover:border-border transition-colors`,children:[(0,q.jsx)(Zt,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`font-semibold text-foreground`,children:f.branch}),f.ahead>0&&(0,q.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,title:`${f.ahead} ahead`,children:[`↑`,f.ahead]}),f.behind>0&&(0,q.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,title:`${f.behind} behind`,children:[`↓`,f.behind]}),f.added>0&&(0,q.jsxs)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,title:`${f.added} lines added`,children:[`+`,f.added]}),f.deleted>0&&(0,q.jsxs)(`span`,{className:`text-red-600 dark:text-red-400`,title:`${f.deleted} lines deleted`,children:[`-`,f.deleted]}),f.untracked>0&&(0,q.jsxs)(`span`,{className:`text-muted-foreground`,title:`${f.untracked} untracked files`,children:[f.untracked,`?`]})]}),(0,q.jsx)(Yl,{section:`collab`,icon:(0,q.jsx)(zn,{className:`h-3 w-3`}),label:`Collab`,active:w===`collab`,onClick:()=>i(`collab`)})]}),w===`autophase`&&x&&(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsx)(`div`,{className:`flex justify-end`,children:(0,q.jsxs)($,{variant:`outline`,size:`sm`,className:`h-6 gap-1 text-[10px]`,onClick:()=>a(`autophase`),children:[(0,q.jsx)(kn,{className:`h-3 w-3`}),`Full view`]})}),(0,q.jsx)(Ha,{phases:s.phases,activePhaseId:s.activePhaseId??void 0,overallPercent:s.overallPercent,autonomous:s.autonomous,onPhaseClick:p,onToggleAutonomous:m,className:`w-72 shrink-0`})]}),w===`goal`&&(0,q.jsx)(Ll,{goal:o}),w===`fleet`&&(0,q.jsx)(ll,{}),w===`worktrees`&&(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsx)(`div`,{className:`flex items-center gap-2`,children:[`graph`,`lanes`].map(e=>(0,q.jsx)(`button`,{type:`button`,onClick:()=>g(e),className:Z(`text-[10px] px-2 py-0.5 rounded-full border transition-colors capitalize`,h===e?`bg-primary/10 border-primary/30 text-primary`:`border-border text-muted-foreground hover:text-foreground`),children:e},e))}),h===`graph`?(0,q.jsx)(Qa,{worktrees:c,baseBranch:l||`HEAD`}):(0,q.jsx)(no,{worktrees:c,baseBranch:l||`HEAD`})]}),(0,q.jsx)(`div`,{className:Z(w===`work`?`block`:`hidden`),id:`panel-work`,children:(0,q.jsx)(ql,{})}),(0,q.jsx)(`div`,{className:Z(w===`collab`?`block`:`hidden`),children:(0,q.jsx)(Pl,{sessionId:e})})]})}function Zl(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function Ql(e){let t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}var $l={running:{led:`bg-[hsl(var(--success))]`,label:`running`,pulse:!0,badge:`bg-[hsl(var(--success))]/15 text-[hsl(var(--success))]`},completed:{led:`bg-[hsl(var(--success))]`,label:`done`,pulse:!1,badge:`bg-muted text-muted-foreground`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,badge:`bg-destructive/15 text-destructive`},timeout:{led:`bg-[hsl(var(--warning))]`,label:`timeout`,pulse:!1,badge:`bg-amber-500/15 text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,badge:`bg-muted text-muted-foreground`}};function eu({agent:e,isLeader:t}){let n=$l[e.status],r=e.status===`running`,i=Date.now()-e.startedAt,a=[...e.toolLog.slice(0,8)].reverse();return(0,q.jsxs)(`div`,{className:Z(`rounded-xl border p-4 space-y-3`,r?`border-primary/20 bg-primary/[0.02]`:`border-border bg-card`,t&&`ring-2 ring-amber-500/30`),children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:Z(`led`,n.led,n.pulse&&`led-pulse`,`mt-0.5`)}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`text-sm font-semibold`,children:e.name}),t&&(0,q.jsx)(Wt,{className:`h-3.5 w-3.5 text-amber-500`,"aria-label":`leader`}),e.extensions>0&&(0,q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-amber-500/15 text-[10px] text-amber-600 dark:text-amber-400 font-medium`,children:[(0,q.jsx)(Dn,{className:`h-2.5 w-2.5`}),`×`,e.extensions]})]}),(0,q.jsx)(`span`,{className:Z(`inline-block mt-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium`,n.badge),children:n.label})]})]}),(0,q.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:t&&(0,q.jsx)(`span`,{className:`text-[9px] bg-amber-500/15 text-amber-600 dark:text-amber-400 px-1.5 py-0.5 rounded`,children:`LEADER`})})]}),e.description&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed line-clamp-2`,children:e.description}),e.budgetWarning&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/20 text-xs`,children:[(0,q.jsx)(Dn,{className:`h-3.5 w-3.5 text-amber-500 shrink-0`}),(0,q.jsxs)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:[`⚡ hitting `,(0,q.jsx)(`strong`,{children:e.budgetWarning.kind}),` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`) — extending`]})]}),e.failureReason&&(0,q.jsx)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-lg bg-destructive/10 border border-destructive/20 text-xs`,children:(0,q.jsxs)(`span`,{className:`text-destructive font-medium`,children:[`✗ `,e.failureReason]})}),(0,q.jsxs)(`div`,{className:`grid grid-cols-4 gap-2`,children:[(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Iters`}),(0,q.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.iteration})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Tools`}),(0,q.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:e.toolCalls})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Cost`}),(0,q.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:Zl(e.costUsd)})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 px-2 py-1.5 text-center`,children:[(0,q.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Elapsed`}),(0,q.jsx)(`div`,{className:`text-xs font-mono font-semibold tabular-nums`,children:Ql(i)})]})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`Activity (12 bins)`}),(0,q.jsx)(nl,{bins:e.sparklineBins,className:`font-mono text-[9px]`})]}),(0,q.jsx)(Bo,{pct:e.ctxPct,tokens:e.ctxTokens,maxTokens:e.maxContext})]}),(e.provider||e.model)&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(hn,{className:`h-3 w-3`}),(0,q.jsxs)(`span`,{className:`font-mono`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(e.currentTool||e.lastTool)&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(ht,{className:Z(`h-3 w-3`,r&&`animate-pulse text-primary`)}),(0,q.jsx)(`span`,{className:`font-mono`,children:e.currentTool??e.lastTool}),r&&(0,q.jsx)(z,{className:`h-3 w-3 animate-spin`})]}),e.partialText&&r&&(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,q.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Streaming output`}),(0,q.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-3 leading-relaxed`,children:e.partialText})]}),a.length>0&&(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Recent tools`}),(0,q.jsx)(`div`,{className:`space-y-0.5`,children:a.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] font-mono`,children:[(0,q.jsx)(`span`,{className:Z(`shrink-0`,e.ok?`text-[hsl(var(--success))]`:`text-destructive`),children:e.ok?`✓`:`✗`}),(0,q.jsx)(`span`,{className:`text-muted-foreground truncate`,children:e.name}),(0,q.jsx)(`span`,{className:`ml-auto tabular-nums text-muted-foreground shrink-0`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(1)}s`:`${e.durationMs}ms`})]},t))})]}),e.finalText&&!r&&(0,q.jsxs)(`div`,{className:`rounded-lg border bg-muted/30 p-2`,children:[(0,q.jsx)(`div`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider mb-1`,children:`Final output`}),(0,q.jsx)(`pre`,{className:`text-[10px] font-mono text-foreground/80 whitespace-pre-wrap line-clamp-4 leading-relaxed`,children:e.finalText})]})]})}function tu({onClose:e}){let t=J(e=>e.agents),n=J(e=>e.leaderId),[r,i]=(0,V.useState)(0),a=(0,V.useMemo)(()=>{let e=Array.from(t.values());return e.sort((e,t)=>{if(e.id===n)return-1;if(t.id===n)return 1;let r=e.status===`running`?0:1,i=t.status===`running`?0:1;return r===i?e.startedAt-t.startedAt:r-i}),e},[t,n]),o=(0,V.useCallback)(t=>{if(t.key===`Escape`){e();return}if(t.key===`ArrowDown`){t.preventDefault(),i(e=>Math.min(e+1,a.length-1));return}if(t.key===`ArrowUp`){t.preventDefault(),i(e=>Math.max(e-1,0));return}},[a.length,e]);(0,V.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]);let s=a[r]??null;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/10 backdrop-blur-[1px]`,onClick:e,"aria-hidden":`true`}),(0,q.jsxs)(`div`,{className:`fixed right-0 top-0 h-full z-50 w-[600px] max-w-[90vw] flex flex-col bg-background border-l shadow-2xl animate-slide-in-right`,onKeyDown:o,tabIndex:-1,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(Qt,{className:`h-5 w-5 text-primary`}),(0,q.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Agents Monitor`}),(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[a.length,` total`]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>i(e=>Math.max(e-1,0)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:r===0,"aria-label":`Previous agent`,children:(0,q.jsx)(h,{className:`h-4 w-4`})}),(0,q.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground font-mono`,children:a.length>0?`${r+1}/${a.length}`:`0/0`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>i(e=>Math.min(e+1,a.length-1)),className:`p-1.5 rounded-md hover:bg-muted transition-colors disabled:opacity-30`,disabled:r>=a.length-1,"aria-label":`Next agent`,children:(0,q.jsx)(Ie,{className:`h-4 w-4`})}),(0,q.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors ml-2`,"aria-label":`Close agents monitor`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4`,children:a.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,q.jsx)(Qt,{className:`h-12 w-12 mb-3 opacity-20`}),(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`})]}):s?(0,q.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,q.jsx)(eu,{agent:s,isLeader:s.id===n})}):null}),a.length>0&&(0,q.jsxs)(`div`,{className:`border-t bg-card/80 backdrop-blur shrink-0`,children:[(0,q.jsx)(`div`,{className:`px-4 py-2 flex items-center gap-2 overflow-x-auto`,children:a.map((e,t)=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>i(t),className:Z(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,t===r?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),children:[(0,q.jsx)(`span`,{className:Z(`led`,$l[e.status].led,$l[e.status].pulse&&`led-pulse`,`shrink-0`)}),(0,q.jsx)(`span`,{children:e.name}),e.id===n&&(0,q.jsx)(Wt,{className:`h-2.5 w-2.5 text-amber-500 shrink-0`})]},e.id))}),(0,q.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,q.jsx)(`span`,{children:`←→ page`}),(0,q.jsx)(`span`,{children:`↑↓ navigate list`}),(0,q.jsx)(`span`,{children:`Esc close`})]})]})]})]})}var nu=V.forwardRef(({className:e,inset:t,children:n,...r},i)=>(0,q.jsxs)(x,{ref:i,className:Z(`flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent`,t&&`pl-8`,e),...r,children:[n,(0,q.jsx)(Ie,{className:`ml-auto h-4 w-4`})]}));nu.displayName=x.displayName;var ru=V.forwardRef(({className:e,...t},n)=>(0,q.jsx)(Re,{ref:n,className:Z(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg 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-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...t}));ru.displayName=Re.displayName;var iu=V.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,q.jsx)(Pe,{children:(0,q.jsx)(Bn,{ref:r,sideOffset:t,className:Z(`z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md 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-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2`,e),...n})}));iu.displayName=Bn.displayName;var au=V.forwardRef(({className:e,inset:t,...n},r)=>(0,q.jsx)(Qn,{ref:r,className:Z(`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0`,t&&`pl-8`,e),...n}));au.displayName=Qn.displayName;var ou=V.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,q.jsxs)(ct,{ref:i,className:Z(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),checked:n,...r,children:[(0,q.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,q.jsx)(gt,{children:(0,q.jsx)(Be,{className:`h-4 w-4`})})}),t]}));ou.displayName=ct.displayName;var su=V.forwardRef(({className:e,children:t,...n},r)=>(0,q.jsxs)(p,{ref:r,className:Z(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,q.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,q.jsx)(gt,{children:(0,q.jsx)(yn,{className:`h-2 w-2 fill-current`})})}),t]}));su.displayName=p.displayName;var cu=V.forwardRef(({className:e,inset:t,...n},r)=>(0,q.jsx)(Jn,{ref:r,className:Z(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));cu.displayName=Jn.displayName;var lu=V.forwardRef(({className:e,...t},n)=>(0,q.jsx)(Wn,{ref:n,className:Z(`-mx-1 my-1 h-px bg-muted`,e),...t}));lu.displayName=Wn.displayName;var uu=({className:e,...t})=>(0,q.jsx)(`span`,{className:Z(`ml-auto text-xs tracking-widest opacity-60`,e),...t});uu.displayName=`DropdownMenuShortcut`;function du({current:e,max:t,className:n,showLabel:r=!0}){let i=Math.min(e,t),a=Math.max(0,t-i),o=t>0?i/t*100:0,s=o>=90?`text-destructive`:o>=70?`text-[hsl(var(--warning))]`:`text-[hsl(var(--success))]`;return(0,q.jsxs)(`span`,{className:n,title:`Fleet concurrency: ${e}/${t}`,children:[(0,q.jsxs)(`span`,{"aria-hidden":`true`,className:`font-mono text-[10px] tracking-tight`,children:[`[`,(0,q.jsx)(`span`,{className:s,children:`█`.repeat(i)}),(0,q.jsx)(`span`,{className:`text-[hsl(var(--muted))]`,children:`░`.repeat(a)}),`]`]}),r&&(0,q.jsxs)(`span`,{className:`ml-1.5 tabular-nums text-[10px] text-muted-foreground font-mono`,children:[e,`/`,t]})]})}function fu(e){let t=Date.now()-e;return t<5e3?`just now`:t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}var pu={spawned:`🚀`,task_started:`▶`,tool_executed:`⚡`,iteration_summary:`🔄`,budget_extended:`⚡`,task_completed:`✅`,ctx_pct:`💬`,leader_updated:`👑`};function mu({events:e,max:t=20,className:n}){let r=e.slice(0,t);return r.length===0?(0,q.jsx)(`div`,{className:`py-4 text-center text-xs text-muted-foreground ${n??``}`,children:`No events yet.`}):(0,q.jsx)(`div`,{className:`space-y-0.5 overflow-y-auto max-h-48 ${n??``}`,children:r.map(e=>(0,q.jsxs)(`div`,{className:`flex items-start gap-2 text-[10px] leading-tight py-0.5 px-1 rounded hover:bg-accent/50 transition-colors`,children:[(0,q.jsx)(`span`,{className:`shrink-0 w-5 text-center`,"aria-hidden":`true`,children:pu[e.kind]??`·`}),(0,q.jsx)(`span`,{className:`shrink-0 w-12 text-right text-muted-foreground font-mono tabular-nums`,children:fu(e.timestamp)}),(0,q.jsx)(`span`,{className:`truncate text-foreground/90`,children:e.message}),e.value!==void 0&&e.kind===`tool_executed`&&(0,q.jsx)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:e.value>=1e3?`${(e.value/1e3).toFixed(1)}s`:`${e.value}ms`}),e.value!==void 0&&e.kind===`ctx_pct`&&(0,q.jsxs)(`span`,{className:`ml-auto shrink-0 tabular-nums text-muted-foreground font-mono`,children:[e.value,`%`]})]},e.id))})}function hu(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function gu(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function _u(e){let t=Math.floor(e/1e3),n=Math.floor(t/60),r=Math.floor(n/60);return r>0?`${r}h ${n%60}m`:n>0?`${n}m ${t%60}s`:`${t}s`}var vu={running:{led:`bg-emerald-500`,label:`running`,pulse:!0,color:`text-emerald-500`},completed:{led:`bg-emerald-500`,label:`done`,pulse:!1,color:`text-emerald-500`},failed:{led:`bg-destructive`,label:`failed`,pulse:!1,color:`text-destructive`},timeout:{led:`bg-amber-500`,label:`timeout`,pulse:!1,color:`text-amber-500`},stopped:{led:`bg-muted-foreground`,label:`stopped`,pulse:!1,color:`text-muted-foreground`}};function yu({agent:e,now:t}){let[n,r]=(0,V.useState)(!1),[i,a]=(0,V.useState)(!1),o=vu[e.status],s=e.status===`running`,c=(0,V.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3)}catch{}},[]),l=e.toolLog.reduce((e,t)=>e+t.durationMs,0),u=e.toolLog.length>0?Math.round(l/e.toolLog.length):0,d=(0,V.useMemo)(()=>{let t=new Set;for(let n of e.toolLog)t.add(n.name);return t.size},[e.toolLog]),f=e.partialText||e.finalText||void 0,p=!e.finalText&&!!e.partialText;return(0,q.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`shrink-0 border-b bg-card p-4 space-y-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(`div`,{className:`flex items-center justify-center w-10 h-10 rounded-lg bg-primary/10`,children:(0,q.jsx)(Qt,{className:`h-5 w-5 text-primary`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-base font-semibold`,children:e.name}),(0,q.jsx)(`span`,{className:Z(`px-2 py-0.5 rounded text-[10px] font-medium uppercase tracking-wider`,e.status===`running`?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:e.status===`failed`||e.status===`timeout`?`bg-destructive/15 text-destructive`:`bg-muted text-muted-foreground`),children:o.label})]}),(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground font-mono`,children:[`session: `,e.sessionId?.slice(0,12),`…`]})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] text-muted-foreground`,children:[s&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(dt,{className:`h-3.5 w-3.5`}),(0,q.jsx)(`span`,{className:`tabular-nums font-mono`,children:_u(Math.max(0,t-e.startedAt))})]}),(0,q.jsx)(`span`,{className:Z(`led`,o.led,s&&`led-pulse`)})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2 rounded-lg bg-muted/30`,children:[(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider`,children:`Activity`}),(0,q.jsx)(nl,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,q.jsxs)(`span`,{className:`ml-auto flex items-center gap-1 text-[10px] text-amber-500`,children:[(0,q.jsx)(Dn,{className:`h-3 w-3`}),`budget warning`]})]}),e.description&&(0,q.jsxs)(`div`,{className:`px-3 py-2 rounded-lg bg-muted/20 border border-border/50`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-muted-foreground uppercase tracking-wider`,children:`Current Task`}),(0,q.jsx)(`p`,{className:`text-xs mt-1 text-foreground/80`,children:e.description})]})]}),(0,q.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 space-y-4`,children:[(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,q.jsx)(hn,{className:`h-3 w-3`}),` Provider / Model`]}),(0,q.jsxs)(`div`,{className:`text-sm font-mono font-medium`,children:[e.provider??`?`,`/`,e.model??`?`]})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,q.jsx)(ir,{className:`h-3 w-3`}),` Performance`]}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Iterations`}),(0,q.jsx)(`span`,{className:`font-mono font-medium`,children:e.iteration})]}),(0,q.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Tool Calls`}),(0,q.jsx)(`span`,{className:`font-mono font-medium`,children:e.toolCalls})]}),(0,q.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Unique Tools`}),(0,q.jsx)(`span`,{className:`font-mono font-medium`,children:d})]})]})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,q.jsx)(dn,{className:`h-3 w-3`}),` Cost`]}),(0,q.jsx)(`div`,{className:`text-lg font-mono font-bold text-emerald-500`,children:hu(e.costUsd)}),(0,q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[`avg `,u,`ms per tool`]})]}),(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card p-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[9px] text-muted-foreground uppercase tracking-wider mb-2`,children:[(0,q.jsx)(En,{className:`h-3 w-3`}),` Context`]}),(0,q.jsxs)(`div`,{className:`space-y-2`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between text-[11px]`,children:[(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Tokens`}),(0,q.jsx)(`span`,{className:`font-mono font-medium`,children:gu(e.ctxTokens)})]}),(0,q.jsx)(`div`,{className:`h-2 w-full rounded-full bg-muted overflow-hidden`,children:(0,q.jsx)(`div`,{className:Z(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${Math.min(200,e.ctxPct)}%`}})}),(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums font-mono`,children:[e.ctxPct,`% used`]})]})]})]}),e.currentTool&&(0,q.jsxs)(`div`,{className:Z(`rounded-lg border px-4 py-3 flex items-center gap-3`,s?`border-primary/30 bg-primary/[0.04]`:`border-border bg-muted/30`),children:[(0,q.jsx)(ht,{className:Z(`h-4 w-4`,s?`text-primary animate-pulse`:`text-muted-foreground`)}),(0,q.jsx)(`span`,{className:`text-sm font-mono font-medium`,children:e.currentTool}),s?(0,q.jsxs)(`span`,{className:`ml-auto flex items-center gap-1.5 text-[10px] text-primary`,children:[(0,q.jsx)(z,{className:`h-3 w-3 animate-spin`}),` running…`]}):(0,q.jsx)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:`completed`})]}),f?(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b bg-muted/30`,children:[(0,q.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:p?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-blue-500 animate-pulse`}),`Live Output`]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(E,{className:`h-3 w-3`}),`Final Output`]})}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>c(f),className:`flex items-center gap-1 px-2 py-1 rounded text-[10px] text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:n?`✓ Copied`:`Copy`})]}),(0,q.jsx)(`pre`,{className:`p-4 text-xs whitespace-pre-wrap font-mono text-foreground/80 leading-relaxed max-h-64 overflow-y-auto`,children:f})]}):s?(0,q.jsxs)(`div`,{className:`rounded-lg border border-dashed border-border p-6 text-center`,children:[(0,q.jsx)(z,{className:`h-6 w-6 mx-auto mb-2 text-muted-foreground/50 animate-spin`}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Waiting for output…`})]}):null,e.budgetWarning&&(0,q.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,q.jsx)(Dn,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`span`,{className:`text-sm font-medium text-amber-600 dark:text-amber-400`,children:`⚡ Budget Warning`}),(0,q.jsxs)(`p`,{className:`text-[11px] text-amber-600/80 dark:text-amber-400/80 mt-0.5`,children:[`Hitting `,e.budgetWarning.kind,` limit (`,e.budgetWarning.used,`/`,e.budgetWarning.limit,`)`]})]})]}),e.extensions>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3 rounded-lg bg-amber-500/10 border border-amber-500/20`,children:[(0,q.jsx)(Dn,{className:`h-5 w-5 text-amber-500 shrink-0`}),(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`span`,{className:`text-sm font-medium`,children:[e.extensions,` Budget Extension`,e.extensions===1?``:`s`]}),(0,q.jsxs)(`p`,{className:`text-[11px] text-muted-foreground mt-0.5`,children:[`Agent extended its budget `,e.extensions,` time`,e.extensions===1?``:`s`,` due to long-running tasks`]})]})]}),e.error&&(0,q.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,q.jsx)(sn,{className:`h-4 w-4 text-destructive`}),(0,q.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Error`})]}),(0,q.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.error.message})]}),e.failureReason&&(0,q.jsxs)(`div`,{className:`rounded-lg border border-destructive/30 bg-destructive/5 p-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,q.jsx)(sn,{className:`h-4 w-4 text-destructive`}),(0,q.jsx)(`span`,{className:`text-[10px] font-semibold text-destructive uppercase tracking-wider`,children:`Failure Reason`})]}),(0,q.jsx)(`p`,{className:`text-sm text-destructive/90`,children:e.failureReason})]}),e.toolLog.length>0&&(0,q.jsxs)(`div`,{className:`rounded-lg border bg-card`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:()=>a(!i),className:`w-full flex items-center justify-between px-4 py-2 border-b bg-muted/30 hover:bg-muted/50 transition-colors`,children:[(0,q.jsxs)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase tracking-wider flex items-center gap-2`,children:[(0,q.jsx)(ht,{className:`h-3 w-3`}),`Tool Log (`,e.toolLog.length,` calls)`]}),(0,q.jsx)(Ie,{className:Z(`h-4 w-4 text-muted-foreground transition-transform`,i&&`rotate-90`)})]}),(0,q.jsx)(`div`,{className:Z(`overflow-hidden transition-all`,i?`max-h-[500px]`:`max-h-48`),children:(0,q.jsx)(`div`,{className:`p-2 space-y-0.5`,children:e.toolLog.map((e,t)=>(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-3 rounded px-3 py-2 text-[11px]`,e.ok?`bg-muted/30 hover:bg-muted/50`:`bg-destructive/5 border border-destructive/20`),children:[(0,q.jsx)(`span`,{className:Z(`led shrink-0`,e.ok?`bg-emerald-500`:`bg-destructive`)}),(0,q.jsx)(`span`,{className:Z(`font-mono font-medium w-20 shrink-0`,e.ok?`text-foreground`:`text-destructive`),children:e.name}),(0,q.jsx)(`span`,{className:`text-muted-foreground tabular-nums text-[10px]`,children:e.durationMs>=1e3?`${(e.durationMs/1e3).toFixed(2)}s`:`${e.durationMs}ms`}),!e.ok&&(0,q.jsx)(`span`,{className:`ml-auto text-[10px] text-destructive font-medium`,children:`Failed`}),(0,q.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground tabular-nums`,children:new Date(e.at).toLocaleTimeString()})]},`${e.name}-${e.at}-${t}`))})})]})]})]})}function bu({agent:e,isSelected:t,isLeader:n,onClick:r}){let i=vu[e.status],a=e.status===`running`;return(0,q.jsxs)(`button`,{type:`button`,onClick:r,className:Z(`w-full text-left grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] items-center gap-x-2 px-3 py-1.5 rounded-md text-xs transition-colors`,t?`bg-primary/15 ring-1 ring-primary/40`:`hover:bg-accent/50`,a&&!t&&`bg-muted/30`),children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,q.jsx)(`span`,{className:Z(`led shrink-0`,i.led,i.pulse&&`led-pulse`)}),(0,q.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),n&&(0,q.jsx)(Wt,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`leader`})]}),(0,q.jsx)(`span`,{className:Z(`text-[10px] tabular-nums`,a?`text-emerald-500`:`text-muted-foreground`),children:i.label}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 min-w-0`,children:[(0,q.jsx)(nl,{bins:e.sparklineBins,className:`font-mono text-[9px]`}),e.budgetWarning&&(0,q.jsx)(`span`,{title:`⚡ hitting ${e.budgetWarning.kind} limit (${e.budgetWarning.used}/${e.budgetWarning.limit})`,children:(0,q.jsx)(Dn,{className:`h-3 w-3 shrink-0 text-amber-500`,"aria-label":`budget warning`})})]}),(0,q.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.iteration,`it`]}),(0,q.jsxs)(`span`,{className:`tabular-nums text-muted-foreground text-[10px]`,children:[e.toolCalls,`tc`]}),(0,q.jsx)(`span`,{className:`tabular-nums font-mono text-[10px]`,children:hu(e.costUsd)}),(0,q.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,q.jsx)(`div`,{className:`h-1.5 w-full rounded-full bg-muted overflow-hidden`,children:(0,q.jsx)(`div`,{className:Z(`h-full rounded-full transition-all`,e.ctxPct>=85?`bg-destructive`:e.ctxPct>=70?`bg-amber-500`:`bg-emerald-500`),style:{width:`${Math.min(200,e.ctxPct)}%`}})}),(0,q.jsx)(`span`,{className:`text-[9px] tabular-nums text-muted-foreground font-mono leading-none`,children:e.maxContext>0?`${e.ctxPct}%`:`—`})]}),(0,q.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:e.extensions>0?`⚡×${e.extensions}`:`—`}),(0,q.jsx)(`span`,{className:`text-[9px] text-destructive truncate`,title:e.failureReason,children:e.failureReason??``})]})}function xu({onClose:e,onSelectAgent:t}){let n=J(e=>e.agents),r=J(e=>e.leaderId),i=J(e=>e.fleetTokensIn),a=J(e=>e.fleetTokensOut),o=J(e=>e.fleetConcurrency),s=J(e=>e.fleetConcurrencyMax),c=J(e=>e.eventTimeline),[l,u]=(0,V.useState)(null),[d,f]=(0,V.useState)(Date.now());(0,V.useEffect)(()=>{let e=setInterval(()=>f(Date.now()),1e3);return()=>clearInterval(e)},[]);let p=(0,V.useMemo)(()=>{let e=Array.from(n.values());return e.sort((e,t)=>{if(e.id===r)return-1;if(t.id===r)return 1;let n=e.status===`running`?0:1,i=t.status===`running`?0:1;return n===i?e.startedAt-t.startedAt:n-i}),e},[n,r]),m=(0,V.useMemo)(()=>Array.from(n.values()).reduce((e,t)=>e+t.costUsd,0),[n]),h=p.filter(e=>e.status===`running`).length,g=l===null?null:p[l],_=(0,V.useCallback)(e=>u(t=>t===e?null:e),[]),v=(0,V.useCallback)(n=>{if(n.key===`Escape`){l===null?e&&e():u(null);return}if(n.key===`ArrowDown`){n.preventDefault(),u(e=>Math.min((e??-1)+1,p.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),u(e=>Math.max((e??0)-1,0));return}n.key===`Enter`&&p[l??0]&&t?.(p[l??0])},[p,l,e,t]);return(0,V.useEffect)(()=>{let t=t=>{t.key===`Escape`&&e()};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e]),(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`div`,{className:`fixed inset-0 z-40 bg-black/10 backdrop-blur-[1px]`,onClick:e,"aria-hidden":`true`}),(0,q.jsxs)(`div`,{className:`fixed right-0 top-0 h-full z-50 w-[720px] max-w-[95vw] flex flex-col bg-background border-l shadow-2xl animate-slide-in-right`,onKeyDown:v,tabIndex:-1,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b bg-card/80 backdrop-blur shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsx)(Qt,{className:`h-5 w-5 text-primary`}),(0,q.jsxs)(`h2`,{className:`text-sm font-semibold flex items-center gap-2`,children:[`FLEET MONITOR`,h>0&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1 text-[11px] text-emerald-500 font-normal`,children:[(0,q.jsx)(`span`,{className:`led led-pulse bg-emerald-500`}),h,` running`]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,q.jsxs)(`span`,{children:[p.length,` total agents`]}),(0,q.jsx)(du,{current:o,max:s,showLabel:!0})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:[`↓`,gu(i),` ↑`,gu(a),` · `,hu(m)]}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums font-mono`,children:r?`👑 ${n.get(r)?.name??r}`:`no leader`}),(0,q.jsx)(`button`,{type:`button`,onClick:e,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,"aria-label":`Close fleet monitor`,children:(0,q.jsx)(sn,{className:`h-4 w-4`})})]})]}),(0,q.jsxs)(`div`,{className:`flex-1 flex overflow-hidden`,children:[(0,q.jsxs)(`div`,{className:Z(`flex flex-col border-r transition-all duration-200`,g?`w-[500px] shrink-0`:`w-full`),children:[(0,q.jsx)(`div`,{className:`border-b bg-card/80 px-3 py-2`,children:(0,q.jsxs)(`div`,{className:`grid grid-cols-[140px_60px_1fr_60px_60px_60px_60px_50px_50px] gap-x-2 text-[9px] uppercase tracking-wider text-muted-foreground font-medium`,children:[(0,q.jsx)(`span`,{children:`Name`}),(0,q.jsx)(`span`,{children:`Status`}),(0,q.jsx)(`span`,{children:`Activity`}),(0,q.jsx)(`span`,{children:`Iters`}),(0,q.jsx)(`span`,{children:`Tools`}),(0,q.jsx)(`span`,{children:`Cost`}),(0,q.jsx)(`span`,{children:`CTX`}),(0,q.jsx)(`span`,{children:`Ext`}),(0,q.jsx)(`span`,{children:`Reason`})]})}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:p.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full text-muted-foreground`,children:[(0,q.jsx)(zn,{className:`h-12 w-12 mb-3 opacity-20`}),(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:`No agents active`}),(0,q.jsx)(`p`,{className:`text-xs mt-1`,children:`Agents appear here when the fleet is active.`})]}):(0,q.jsx)(`div`,{className:`p-2 space-y-0.5`,children:p.map((e,t)=>(0,q.jsx)(bu,{agent:e,isSelected:t===l,isLeader:e.id===r,onClick:()=>_(t)},e.id))})}),(0,q.jsxs)(`div`,{className:`border-t bg-card/80 shrink-0`,children:[(0,q.jsx)(`div`,{className:`px-4 py-2 border-b`,children:(0,q.jsxs)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground font-medium flex items-center gap-2`,children:[(0,q.jsx)(Et,{className:`h-3 w-3`}),`Event Timeline`]})}),(0,q.jsx)(`div`,{className:`px-4 py-2 max-h-32 overflow-y-auto`,children:(0,q.jsx)(mu,{events:c,max:10})}),(0,q.jsxs)(`div`,{className:`px-4 py-1.5 border-t text-[10px] text-muted-foreground flex items-center gap-4`,children:[(0,q.jsx)(`span`,{children:`↑↓ navigate`}),(0,q.jsx)(`span`,{children:`↵ select detail`}),(0,q.jsx)(`span`,{children:`Esc deselect / close`})]})]})]}),g&&(0,q.jsx)(`div`,{className:`flex-1 overflow-hidden bg-card/50`,children:(0,q.jsxs)(`div`,{className:`h-full flex flex-col`,children:[(0,q.jsxs)(`div`,{className:`shrink-0 px-4 py-2 border-b bg-card/80 flex items-center gap-2`,children:[(0,q.jsx)(Te,{className:`h-4 w-4 text-primary`}),(0,q.jsx)(`span`,{className:`text-xs font-semibold text-primary`,children:g.name}),(0,q.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,children:`detailed view`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>u(null),className:`ml-auto text-[10px] text-muted-foreground hover:text-foreground transition-colors flex items-center gap-1`,children:`✕ close`})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,q.jsx)(yu,{agent:g,now:d})})]})}),!g&&p.length>0&&(0,q.jsx)(`div`,{className:`flex-1 flex items-center justify-center bg-muted/20`,children:(0,q.jsxs)(`div`,{className:`text-center space-y-3 max-w-sm`,children:[(0,q.jsx)(zn,{className:`h-12 w-12 text-muted-foreground/30 mx-auto`}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select an agent to view detailed information`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground/60`,children:`Click on any agent in the list to see detailed metrics, tool logs, streaming output, and more — similar to the chat history detailed view.`}),(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-4 pt-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↑`}),(0,q.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`↓`}),(0,q.jsx)(`span`,{children:`navigate`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Enter`}),(0,q.jsx)(`span`,{children:`select`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(`kbd`,{className:`px-1.5 py-0.5 rounded bg-muted border text-[9px]`,children:`Esc`}),(0,q.jsx)(`span`,{children:`deselect`})]})]})]})})]})]})]})}var Su=320;function Cu(e){return e<=0?`$0`:e>=.01?`$${e.toFixed(3)}`:`$${e.toFixed(5)}`.replace(/0+$/,``).replace(/\.$/,``)}function wu(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function Tu(e,t){let n=Array.from(e.values());return n.sort((e,n)=>{if(e.id===t)return-1;if(n.id===t)return 1;let r=e.status===`running`?0:1,i=n.status===`running`?0:1;return r===i?e.startedAt-n.startedAt:r-i}),n}function Eu(){let e=K(e=>e.inspectorOpen),t=K(e=>e.inspectorTab),n=K(e=>e.toggleInspector),r=K(e=>e.setInspectorOpen),i=K(e=>e.setInspectorTab),a=J(e=>e.agents),o=J(e=>e.leaderId),s=J(e=>e.fleetTokensIn),c=J(e=>e.fleetTokensOut),l=J(e=>e.fleetConcurrency),u=J(e=>e.fleetConcurrencyMax),d=J(e=>e.eventTimeline),f=(0,V.useMemo)(()=>Tu(a,o),[a,o]),p=f.filter(e=>e.status===`running`).length,m=f.reduce((e,t)=>e+t.costUsd,0),h=f.length,[g,_]=(0,V.useState)(null),v=(0,V.useMemo)(()=>g?a.get(g)??f[0]??null:f[0]??null,[g,f,a]),y=()=>i(`fleet`),b=()=>i(`agents`);return(0,q.jsxs)(`div`,{className:`shrink-0 border-t bg-card flex flex-col`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:n,className:Z(`group w-full flex items-center justify-between gap-2 px-3 h-7 text-[11px]`,`text-muted-foreground hover:text-foreground hover:bg-accent/40 transition-colors`),title:e?`Hide inspector panel`:`Show inspector panel (Fleet / Agents)`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-2 min-w-0`,children:[e?(0,q.jsx)(Kn,{className:`h-3.5 w-3.5 shrink-0`}):(0,q.jsx)(Xn,{className:`h-3.5 w-3.5 shrink-0`}),(0,q.jsx)(`span`,{className:`font-medium uppercase tracking-wider`,children:`Inspector`}),h>0&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`span`,{className:`opacity-40`,children:`·`}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(`span`,{className:Z(`h-1.5 w-1.5 rounded-full`,p>0?`bg-emerald-500 animate-pulse`:`bg-muted-foreground/50`)}),(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[p,`/`,h]})]}),(0,q.jsx)(`span`,{className:`opacity-40 hidden sm:inline`,children:`·`}),(0,q.jsxs)(`span`,{className:`tabular-nums font-mono hidden sm:inline`,children:[`↓`,wu(s),` ↑`,wu(c),` · `,Cu(m)]})]})]}),(0,q.jsxs)(`span`,{className:`flex items-center gap-1 shrink-0 opacity-70 group-hover:opacity-100`,children:[(0,q.jsx)(Qt,{className:`h-3 w-3`}),(0,q.jsx)(zn,{className:`h-3 w-3`})]})]}),(0,q.jsx)(`div`,{className:`overflow-hidden transition-[height] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]`,style:{height:e?Su:0},children:(0,q.jsxs)(`div`,{className:`flex flex-col`,style:{height:Su},children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1 px-2 h-8 border-b bg-muted/30 shrink-0`,children:[(0,q.jsx)(Du,{active:t===`fleet`,onClick:y,icon:(0,q.jsx)(Qt,{className:`h-3.5 w-3.5`}),label:`Fleet`,count:h,running:p}),(0,q.jsx)(Du,{active:t===`agents`,onClick:b,icon:(0,q.jsx)(zn,{className:`h-3.5 w-3.5`}),label:`Agents`,count:h}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>r(!1),className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,"aria-label":`Collapse inspector panel`,title:`Collapse (Esc)`,children:(0,q.jsx)(Kn,{className:`h-4 w-4`})})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto`,children:t===`fleet`?(0,q.jsx)(Ou,{fleetList:f,leaderId:o,selectedAgentId:g,runningCount:p,fleetConcurrency:l,fleetConcurrencyMax:u,fleetTokensIn:s,fleetTokensOut:c,totalCost:m,eventTimeline:d,onSelectAgent:e=>{_(e.id),b()}}):(0,q.jsx)(ku,{fleetList:f,selectedAgent:v,leaderId:o,selectedAgentId:v?.id??null,onSelectAgent:_})})]})})]})}function Du({active:e,onClick:t,icon:n,label:r,count:i,running:a}){return(0,q.jsxs)(`button`,{type:`button`,onClick:t,className:Z(`flex items-center gap-1.5 px-2.5 h-6 rounded-md text-[11px] font-medium transition-colors`,e?`bg-background text-foreground shadow-sm ring-1 ring-border`:`text-muted-foreground hover:text-foreground hover:bg-background/60`),children:[n,r,i>0&&(0,q.jsx)(`span`,{className:Z(`tabular-nums text-[10px] px-1 rounded-full`,a&&a>0?`bg-emerald-500/15 text-emerald-600 dark:text-emerald-400`:`bg-muted text-muted-foreground`),children:a===void 0?i:`${a}/${i}`})]})}function Ou({fleetList:e,leaderId:t,selectedAgentId:n,runningCount:r,fleetConcurrency:i,fleetConcurrencyMax:a,fleetTokensIn:o,fleetTokensOut:s,totalCost:c,eventTimeline:l,onSelectAgent:u}){return(0,q.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-1.5 border-b text-[11px] text-muted-foreground shrink-0`,children:[(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[r>0&&(0,q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-emerald-500 animate-pulse`}),(0,q.jsxs)(`span`,{className:`tabular-nums`,children:[r,` running · `,e.length,` total`]})]}),(0,q.jsx)(du,{current:i,max:a,showLabel:!0}),(0,q.jsx)(`div`,{className:`flex-1`}),(0,q.jsxs)(`span`,{className:`tabular-nums font-mono`,children:[`↓`,wu(o),` ↑`,wu(s),` · `,Cu(c)]})]}),e.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,q.jsx)(zn,{className:`h-8 w-8 mb-2 opacity-20`}),(0,q.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`}),(0,q.jsx)(`p`,{className:`text-[11px] mt-0.5`,children:`Agents appear here when the fleet is active.`})]}):(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-1.5`,children:e.map(e=>(0,q.jsx)(bu,{agent:e,isSelected:n===e.id,isLeader:e.id===t,onClick:()=>u(e)},e.id))}),l.length>0&&(0,q.jsx)(`div`,{className:`border-t px-3 py-1.5 shrink-0`,children:(0,q.jsx)(mu,{events:l,max:4})})]})}function ku({fleetList:e,selectedAgent:t,leaderId:n,selectedAgentId:r,onSelectAgent:i}){if(e.length===0)return(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground`,children:[(0,q.jsx)(Qt,{className:`h-8 w-8 mb-2 opacity-20`}),(0,q.jsx)(`p`,{className:`text-xs font-medium`,children:`No agents active`})]});if(!t)return null;let a=Math.max(0,e.findIndex(e=>e.id===r));return(0,q.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,q.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto p-3`,children:(0,q.jsx)(`div`,{className:`max-w-2xl mx-auto`,children:(0,q.jsx)(eu,{agent:t,isLeader:t.id===n})})}),(0,q.jsx)(`div`,{className:`border-t px-2 py-1.5 shrink-0`,children:(0,q.jsx)(`div`,{className:`flex items-center gap-1 overflow-x-auto pb-0.5`,children:e.map((e,n)=>(0,q.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:Z(`shrink-0 flex items-center gap-1.5 px-2 py-1 rounded-md text-[10px] transition-colors`,e.id===t?.id?`bg-primary/15 text-primary ring-1 ring-primary/40`:`hover:bg-accent text-muted-foreground`),title:`${e.name}${n===a?` (selected)`:``}`,children:[(0,q.jsx)(`span`,{className:Z(`h-1.5 w-1.5 rounded-full shrink-0`,e.status===`running`?`bg-emerald-500 animate-pulse`:e.status===`failed`?`bg-destructive`:`bg-muted-foreground/50`)}),(0,q.jsx)(`span`,{className:`truncate max-w-[8rem]`,children:e.name})]},e.id))})})]})}function Au({open:e,onClose:t,className:n}){let r=U(e=>e.queue),i=U(e=>e.removeQueued),a=U(e=>e.clearQueue),o=(0,V.useCallback)(e=>{i(e)},[i]);return e?(0,q.jsx)(`div`,{className:Z(`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,q.jsxs)(`div`,{className:`w-full max-w-lg rounded-xl border bg-card shadow-2xl max-h-[70vh] flex flex-col animate-in fade-in zoom-in-95`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-3 border-b shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,q.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-lg bg-indigo-500/10 text-indigo-600 dark:text-indigo-400`,children:(0,q.jsx)(on,{className:`h-4 w-4`})}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`h2`,{className:`text-sm font-semibold`,children:`Message Queue`}),(0,q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground tabular-nums`,children:[r.length,` queued · messages sent before the agent finishes`]})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r.length>0&&(0,q.jsxs)(`button`,{type:`button`,onClick:()=>a(),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`,title:`Clear all queued messages`,children:[(0,q.jsx)(Lt,{className:`h-3 w-3`}),`Clear`]}),(0,q.jsx)(`button`,{type:`button`,onClick:t,className:`p-1.5 rounded-md hover:bg-muted transition-colors`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:r.length===0?(0,q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-16 gap-3 text-muted-foreground`,children:[(0,q.jsx)(on,{className:`h-10 w-10 opacity-15`}),(0,q.jsx)(`p`,{className:`text-sm font-medium`,children:`Queue is empty`}),(0,q.jsx)(`p`,{className:`text-xs text-center max-w-xs`,children:`Type messages while the agent is running to queue them. Queued messages are sent automatically when the agent finishes.`})]}):(0,q.jsx)(`div`,{className:`divide-y`,children:r.map((e,t)=>(0,q.jsxs)(`div`,{className:`flex items-start justify-between px-4 py-3 text-xs hover:bg-muted/30 transition-colors`,children:[(0,q.jsxs)(`div`,{className:`flex items-start gap-3 min-w-0 flex-1`,children:[(0,q.jsxs)(`span`,{className:`mt-0.5 text-[10px] font-mono text-muted-foreground shrink-0 w-5 text-right`,children:[t+1,`.`]}),(0,q.jsx)(`p`,{className:`text-sm text-foreground leading-relaxed min-w-0 break-words`,children:e.length>120?`${e.slice(0,117)}…`:e})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>o(t),className:`ml-3 p-1.5 rounded-md shrink-0 hover:bg-destructive/10 hover:text-destructive transition-colors`,title:`Remove from queue`,children:(0,q.jsx)(Gt,{className:`h-3.5 w-3.5`})})]},t))})}),r.length>0&&(0,q.jsx)(`div`,{className:`px-4 py-2.5 border-t shrink-0`,children:(0,q.jsx)(`p`,{className:`text-[10px] text-muted-foreground text-center`,children:`Messages are sent in order when the current agent run completes.`})})]})}):null}function ju(e){let t=e.match(/^(.+?)\/SKILL(?:\.save)?\.md$/);return t?t[1]:null}function Mu({source:e}){let t=e===`project`?`project`:e===`user`?`user`:`bundled`;return(0,q.jsx)(`span`,{className:Z(`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold uppercase tracking-wide`,t===`project`&&`bg-emerald-100 text-emerald-700 dark:bg-emerald-950 dark:text-emerald-400`,t===`user`&&`bg-violet-100 text-violet-700 dark:bg-violet-950 dark:text-violet-400`,t===`bundled`&&`bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400`),children:{project:`Project`,user:`Global`,bundled:`Bundled`}[t]})}function Nu({className:e}){let{client:t}=Da(),n=K(e=>e.skillsState),r=K(e=>e.setSkillsState),i=K(e=>e.setCurrentView),a=n.selectedSkill,o=n.navHistory,c=n.historyIndex,[l,u]=(0,V.useState)(null),[d,f]=(0,V.useState)(!1),[p,m]=(0,V.useState)(null),[g,_]=(0,V.useState)(!1),[y,b]=(0,V.useState)(``),[x,S]=(0,V.useState)(!1),[C,w]=(0,V.useState)(null),[T,D]=(0,V.useState)(!1),[O,k]=(0,V.useState)(null),[A,j]=(0,V.useState)(!1),M=(0,V.useRef)(``),[N,P]=(0,V.useState)(!1),[F,I]=(0,V.useState)(null),[te,L]=(0,V.useState)(!1),[R,ie]=(0,V.useState)(null),[ae,oe]=(0,V.useState)(!1),[se,ce]=(0,V.useState)([]),le=(0,V.useRef)(n);le.current=n;let ue=(0,V.useRef)(!1),de=(0,V.useMemo)(()=>y?{lines:y.split(`
|
|
115
|
-
`).length,words:y.trim()?y.trim().split(/\s+/).length:0,chars:y.length}:{lines:0,words:0,chars:0},[y]),fe=(0,V.useMemo)(()=>{if(!y)return null;let e=5*1024*1024,t=new Blob([y]).size;return t>=e?{level:`critical`,used:t,limit:e}:t>=4194304?{level:`warn`,used:t,limit:e}:null},[y]);(0,V.useEffect)(()=>{if(!O)return;let e=setTimeout(()=>k(null),2e3);return()=>clearTimeout(e)},[O]),(0,V.useEffect)(()=>{if(!g||!a)return;let e=setInterval(()=>{y&&y!==M.current&&(M.current=y,localStorage.setItem(`skills_draft_${a.name}`,JSON.stringify({content:y,savedAt:Date.now()})),k(Date.now()))},5e3);return()=>clearInterval(e)},[g,y,a]),(0,V.useEffect)(()=>{if(!a||!g)return;let e=localStorage.getItem(`skills_draft_${a.name}`);if(e)try{let{content:t}=JSON.parse(e);t&&t!==y&&t!==M.current&&(b(t),M.current=t,j(!0))}catch{}},[a?.name,g]),(0,V.useEffect)(()=>{if(!t||!a)return;f(!0),u(null),m(null);let e=setTimeout(()=>{f(!1),m(`Request timed out. Please try again.`)},1e4),n=t=>{clearTimeout(e);let n=t;n.payload.error?m(n.payload.error):n.payload.name&&u(n.payload),f(!1)},i=e=>{let n=e;P(!1);let i=le.current;if(n.payload.success){let e={...i.knownRefs};for(let t of n.payload.updated??[])e[t.name]=t.newRef;r({...i,knownRefs:e,updateAvailableCount:0}),I({updated:n.payload.updated??[],unchanged:n.payload.unchanged??[],errors:n.payload.errors??[]}),t.send({type:`skills.list`})}else I({updated:[],unchanged:[],errors:[{name:``,error:n.payload.error??`Update failed`}]})},o=e=>{let t=e;t.payload.skills&&ce(t.payload.skills)};return t.on(`skills.content`,n),t.on(`skills.updated`,i),t.on(`skills.list`,o),t.send({type:`skills.content`,payload:{name:a.name,source:a.source}}),()=>{clearTimeout(e),t.off(`skills.content`,n),t.off(`skills.updated`,i),t.off(`skills.list`,o)}},[t,a?.name,a?.source]),(0,V.useEffect)(()=>{g&&(_(!1),b(``),w(null))},[a?.name]);let pe=(0,V.useCallback)(e=>se.find(t=>t.name.toLowerCase()===e.toLowerCase()),[se]),me=(0,V.useCallback)(e=>{let t=pe(e);if(t){ue.current=!1;let e=o.slice(0,c+1);e.push(t),r({...le.current,selectedSkill:t,navHistory:e,historyIndex:e.length-1}),_(!1),b(``),I(null)}},[pe,o,c,r]),he=(0,V.useCallback)(()=>{if(c<=0)return;ue.current=!0;let e=c-1,t=o[e];r({...le.current,selectedSkill:t,historyIndex:e}),_(!1),b(``),I(null)},[c,o,r]),ge=(0,V.useCallback)(()=>{if(c>=o.length-1)return;ue.current=!0;let e=c+1,t=o[e];r({...le.current,selectedSkill:t,historyIndex:e}),_(!1),b(``),I(null)},[c,o,r]),ve=(0,V.useCallback)(()=>{i(`chat`)},[i]),ye=(0,V.useCallback)(()=>{l&&(b(l.body),M.current=l.body,j(!1),w(null),_(!0),D(!1))},[l]),be=(0,V.useCallback)(()=>{_(!1),b(``),w(null),D(!1),j(!1),a&&localStorage.removeItem(`skills_draft_${a.name}`)},[a]),xe=(0,V.useCallback)(()=>{!a||!l||(j(!1),b(l.body),M.current=l.body,a&&localStorage.removeItem(`skills_draft_${a.name}`))},[a,l]),Se=(0,V.useCallback)(()=>{if(!t||!a||!y.trim())return;S(!0),w(null);let e=n=>{let r=n;S(!1),r.payload.success?(M.current=``,localStorage.removeItem(`skills_draft_${a.name}`),j(!1),_(!1),t.send({type:`skills.content`,payload:{name:a.name,source:a.source}}),t.send({type:`skills.list`})):w(r.payload.error??`Save failed`),t.off(`skills.edited`,e)};t.on(`skills.edited`,e),t.editSkill(a.name,y)},[t,a,y]),Ce=(0,V.useCallback)(()=>{!t||!a||(P(!0),I(null),t.checkForUpdates(a.name,a.source===`user`))},[t,a]),we=(0,V.useCallback)(()=>{a?.sourceUrl&&navigator.clipboard.writeText(a.sourceUrl).then(()=>{L(!0),setTimeout(()=>L(!1),2e3)})},[a]),Te=(0,V.useCallback)(()=>{if(!l?.body)return;let e=new Blob([l.body],{type:`text/markdown`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`${l.name.replace(/\//g,`_`)}-SKILL.md`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(t)},[l]),Ee=(0,V.useCallback)(async e=>{if(!t||!e)return;oe(!0);let n=e=>{let r=e;oe(!1),r.payload.success?(ie(null),t.send({type:`skills.list`}),ve()):w(r.payload.error??`Uninstall failed`),t.off(`skills.uninstalled`,n)};t.on(`skills.uninstalled`,n),t.uninstallSkill(e.name,e.source===`user`)},[t,ve]);return a?(0,q.jsxs)(`div`,{className:Z(`flex flex-col h-full overflow-hidden bg-background`,e),children:[(0,q.jsxs)(`div`,{className:`px-4 py-3 border-b bg-card shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(qn,{className:`h-4 w-4 text-primary shrink-0`}),(0,q.jsx)(`h1`,{className:`text-base font-semibold truncate`,children:a.name}),a.version&&(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`v`,a.version]}),(0,q.jsx)(Mu,{source:a.source})]}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:a.description||a.trigger}),a.sourceUrl&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,q.jsxs)(`a`,{href:`https://${a.sourceUrl.replace(`github:`,``)}`,target:`_blank`,rel:`noopener noreferrer`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors cursor-pointer`,title:`Open source repo`,children:[(0,q.jsx)(v,{className:`h-3 w-3 shrink-0`}),(0,q.jsx)(`span`,{className:`truncate font-mono`,children:a.sourceUrl})]}),(0,q.jsx)(`button`,{type:`button`,onClick:we,className:`flex items-center shrink-0 text-muted-foreground hover:text-foreground transition-colors cursor-pointer`,title:`Copy source URL`,children:te?(0,q.jsx)(Be,{className:`h-3 w-3 text-green-500`}):(0,q.jsx)(St,{className:`h-3 w-3`})})]}),a.scope.length>0&&(0,q.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:a.scope.map(e=>(0,q.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-muted text-muted-foreground`,children:e},e))}),F&&(0,q.jsxs)(`div`,{className:`mt-2 text-xs space-y-1`,children:[F.updated.length>0&&(0,q.jsxs)(`div`,{className:`text-green-600`,children:[`↑ Updated: `,F.updated.map(e=>`${e.name} (${e.oldRef} → ${e.newRef})`).join(`, `)]}),F.unchanged.length>0&&(0,q.jsxs)(`div`,{className:`text-muted-foreground`,children:[`— Up to date: `,F.unchanged.join(`, `)]}),F.errors.length>0&&(0,q.jsxs)(`div`,{className:`text-destructive`,children:[`✗ `,F.errors.map(e=>`${e.name?`${e.name}: `:``}${e.error}`).join(`; `)]})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto shrink-0`,children:[a.source!==`bundled`&&a.sourceUrl&&(0,q.jsx)(`button`,{type:`button`,onClick:Ce,disabled:N,className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors cursor-pointer disabled:opacity-50`,title:`Check for updates`,children:N?(0,q.jsx)(z,{className:`h-3.5 w-3.5 animate-spin`}):(0,q.jsx)(ar,{className:`h-3.5 w-3.5`})}),a.source!==`bundled`&&!g&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`button`,{type:`button`,onClick:Te,className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors cursor-pointer`,title:`Export skill as .md`,children:(0,q.jsx)(Pn,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(`button`,{type:`button`,onClick:ye,className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors cursor-pointer`,title:`Edit skill`,children:(0,q.jsx)(ee,{className:`h-3.5 w-3.5`})})]}),a.source!==`bundled`&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>ie(a),className:`flex items-center gap-1 px-2 py-1.5 text-xs rounded text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors cursor-pointer`,title:`Uninstall skill`,children:(0,q.jsx)(Lt,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(`button`,{type:`button`,onClick:ve,className:`p-1.5 rounded hover:bg-accent text-muted-foreground cursor-pointer`,title:`Close and go to chat`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]})]}),o.length>1&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1 mt-2`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:he,disabled:c<=0,className:Z(`p-1 rounded transition-colors`,c<=0?`text-muted-foreground/40 cursor-not-allowed`:`hover:bg-accent text-muted-foreground cursor-pointer`),title:`Go back`,children:(0,q.jsx)(h,{className:`h-4 w-4`})}),(0,q.jsx)(`button`,{type:`button`,onClick:ge,disabled:c>=o.length-1,className:Z(`p-1 rounded transition-colors`,c>=o.length-1?`text-muted-foreground/40 cursor-not-allowed`:`hover:bg-accent text-muted-foreground cursor-pointer`),title:`Go forward`,children:(0,q.jsx)(Ie,{className:`h-4 w-4`})}),(0,q.jsx)(`div`,{className:`flex items-center gap-0.5 overflow-x-auto text-xs`,children:o.map((e,t)=>(0,q.jsxs)(`span`,{className:`flex items-center shrink-0`,children:[t>0&&(0,q.jsx)(Ie,{className:`h-3 w-3 text-muted-foreground/40 mx-0.5 shrink-0`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>{t<c&&(ue.current=!0,r({...le.current,selectedSkill:e,historyIndex:t}),_(!1),b(``),I(null))},className:Z(`hover:text-primary cursor-pointer transition-colors`,t===c?`text-primary font-medium`:`text-muted-foreground`),children:e.name})]},e.name+t))})]})]}),l&&(l.relatedFiles.length>0||l.references.length>0)&&(0,q.jsxs)(`div`,{className:`px-4 py-2 border-b bg-muted/30 shrink-0 space-y-2`,children:[l.relatedFiles.length>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(E,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{className:`font-medium uppercase tracking-wide`,children:`Related Files`})]}),l.relatedFiles.map(e=>{let t=ju(e);return t&&pe(t)?(0,q.jsxs)(`button`,{type:`button`,onClick:()=>me(t),className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded bg-background border border-border hover:border-primary hover:text-primary transition-colors cursor-pointer`,title:`Go to ${t}`,children:[(0,q.jsx)(_e,{className:`h-2.5 w-2.5`}),e]},e):(0,q.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-background border border-border text-muted-foreground`,children:e},e)})]}),l.references.length>0&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,q.jsx)(qe,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{className:`font-medium uppercase tracking-wide`,children:`References`})]}),l.references.map(e=>{let t=ju(e)??e.replace(/\.md$/,``);return pe(t)?(0,q.jsxs)(`button`,{type:`button`,onClick:()=>me(t),className:`inline-flex items-center gap-1 px-1.5 py-0.5 text-[10px] rounded bg-primary/5 border border-primary/20 text-primary hover:bg-primary/10 hover:border-primary/30 transition-colors cursor-pointer`,title:`Go to ${t}`,children:[(0,q.jsx)(_e,{className:`h-2.5 w-2.5`}),t]},e):(0,q.jsx)(`span`,{className:`px-1.5 py-0.5 text-[10px] rounded bg-muted text-muted-foreground`,children:t},e)})]})]}),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:d?(0,q.jsxs)(`div`,{className:`p-8 text-center text-muted-foreground`,children:[(0,q.jsx)(z,{className:`h-6 w-6 animate-spin mx-auto mb-2`}),(0,q.jsx)(`p`,{children:`Loading skill content…`})]}):g?(0,q.jsxs)(`div`,{className:`flex flex-col h-full`,children:[(0,q.jsxs)(`div`,{className:`px-4 py-2 border-b shrink-0 flex items-center justify-between gap-2`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`Editing `,(0,q.jsx)(`span`,{className:`font-medium text-foreground`,children:a.name})]}),(0,q.jsxs)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:[de.lines,` line`,de.lines===1?``:`s`,` · `,de.words,` word`,de.words===1?``:`s`,` · `,de.chars,` char`,de.chars===1?``:`s`]}),fe&&(0,q.jsxs)(`span`,{className:`text-xs tabular-nums ${fe.level===`critical`?`text-red-500 font-medium`:`text-amber-500`}`,children:[`⚠ `,(fe.used/(1024*1024)).toFixed(1),`\xA0MB / `,(fe.limit/(1024*1024)).toFixed(0),`\xA0MB`]}),O&&(0,q.jsx)(`span`,{className:`text-xs text-green-500 animate-pulse`,children:`Draft saved`}),A&&(0,q.jsx)(`span`,{className:`text-xs text-amber-500 animate-pulse`,children:`Draft restored`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[C&&(0,q.jsx)(`span`,{className:`text-xs text-destructive`,children:C}),A&&(0,q.jsx)(`button`,{type:`button`,onClick:xe,className:`px-2 py-1 text-[10px] rounded border border-amber-500/50 text-amber-600 dark:text-amber-400 hover:bg-amber-500/10 transition-colors cursor-pointer`,children:`Discard draft`}),(0,q.jsx)(`button`,{type:`button`,onClick:be,className:`px-2 py-1 text-xs rounded border border-border hover:bg-accent transition-colors cursor-pointer`,children:`Cancel`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>D(e=>!e),title:T?`Hide preview`:`Split view`,className:`px-2 py-1 text-xs rounded border transition-colors cursor-pointer ${T?`border-primary bg-primary/10 text-primary`:`border-border hover:bg-accent text-muted-foreground`}`,children:(0,q.jsx)(re,{className:`h-3 w-3 inline`})}),(0,q.jsx)(`button`,{type:`button`,onClick:Se,disabled:x||!y.trim(),className:`px-3 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors cursor-pointer`,children:x?(0,q.jsx)(z,{className:`h-3 w-3 animate-spin inline`}):`Save`})]})]}),T?(0,q.jsxs)(`div`,{className:`flex flex-1 min-h-0 gap-0.5`,children:[(0,q.jsx)(`div`,{className:`flex-1 min-w-0 flex flex-col min-h-0`,children:(0,q.jsx)(Pt,{value:y,onChange:e=>b(e.target.value??``),language:`markdown`,className:`flex-1`,style:{fontSize:12,backgroundColor:`transparent`,minHeight:0},placeholder:`Skill content (markdown)...`})}),(0,q.jsx)(`div`,{className:`w-px bg-border flex-shrink-0`}),(0,q.jsx)(`div`,{className:`flex-1 min-w-0 overflow-y-auto p-4 prose prose-sm dark:prose-invert max-w-none`,children:(0,q.jsx)($e,{rehypePlugins:[ne],components:ys,children:y})})]}):(0,q.jsx)(Pt,{value:y,onChange:e=>b(e.target.value??``),language:`markdown`,className:`flex-1`,style:{fontSize:12,backgroundColor:`transparent`,minHeight:0},placeholder:`Skill content (markdown)...`})]}):l?(0,q.jsx)(`div`,{className:`p-6 prose prose-sm dark:prose-invert max-w-none`,children:(0,q.jsx)($e,{rehypePlugins:[ne],components:ys,children:l.body})}):p?(0,q.jsxs)(`div`,{className:`p-8 text-center`,children:[(0,q.jsx)(`p`,{className:`text-destructive mb-2`,children:`Failed to load skill content`}),(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:p}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>{t&&a&&(f(!0),m(null),t.send({type:`skills.content`,payload:{name:a.name,source:a.source}}))},className:`mt-4 px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors`,children:`Retry`})]}):(0,q.jsx)(`div`,{className:`p-8 text-center text-muted-foreground`,children:`No skill content available`})}),R&&(0,q.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,onClick:e=>{e.target===e.currentTarget&&ie(null)},children:(0,q.jsxs)(`div`,{className:`bg-background rounded-lg border shadow-xl w-[380px] max-w-[90vw]`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(Lt,{className:`h-4 w-4 text-destructive`}),(0,q.jsx)(`span`,{className:`font-semibold text-sm`,children:`Uninstall Skill`})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>ie(null),className:`p-1 rounded hover:bg-accent text-muted-foreground cursor-pointer`,children:(0,q.jsx)(Gt,{className:`h-4 w-4`})})]}),(0,q.jsxs)(`div`,{className:`p-4 space-y-2`,children:[(0,q.jsxs)(`p`,{className:`text-sm`,children:[`Uninstall `,(0,q.jsx)(`span`,{className:`font-semibold`,children:R.name}),`?`]}),(0,q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`This will remove the skill from`,` `,(0,q.jsx)(`span`,{className:`font-mono text-[10px]`,children:R.source===`user`?`~/.wrongstack/skills`:`.wrongstack/skills`}),` `,`and cannot be undone.`]})]}),(0,q.jsxs)(`div`,{className:`flex justify-end gap-2 p-4 border-t bg-muted/20`,children:[(0,q.jsx)(`button`,{type:`button`,onClick:()=>ie(null),disabled:ae,className:`px-3 py-1.5 text-xs rounded border border-border hover:bg-accent transition-colors disabled:opacity-50`,children:`Cancel`}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>Ee(R),disabled:ae,className:`flex items-center gap-1.5 px-3 py-1.5 text-xs rounded bg-destructive text-destructive-foreground hover:bg-destructive/90 disabled:opacity-50 disabled:cursor-not-allowed transition-colors`,children:[ae&&(0,q.jsx)(z,{className:`h-3 w-3 animate-spin`}),`Uninstall`]})]})]})})]}):(0,q.jsxs)(`div`,{className:Z(`flex-1 flex flex-col items-center justify-center text-muted-foreground p-8`,e),children:[(0,q.jsx)(s,{className:`h-12 w-12 mb-4 opacity-20`}),(0,q.jsx)(`p`,{className:`text-base font-medium`,children:`No skill selected`}),(0,q.jsx)(`p`,{className:`text-sm mt-1 text-center max-w-[300px]`,children:`Select a skill from the sidebar to view its documentation`}),(0,q.jsx)(`button`,{type:`button`,onClick:ve,className:`mt-4 px-4 py-2 text-sm rounded-md border border-border hover:bg-accent transition-colors`,children:`Go to chat`})]})}var Pu={user:{label:`You`,color:`#3b82f6`},assistant:{label:`Claude`,color:`#a855f7`},tool:{label:`Tool`,color:`#eab308`},system:{label:`System`,color:`#9ca3af`},error:{label:`Error`,color:`#ef4444`}},Fu=[{value:`steer`,label:`🔄 Steer`,hint:`Adjust behavior mid-task`},{value:`ask`,label:`❓ Ask`,hint:`Question — expects a reply`},{value:`assign`,label:`📋 Assign`,hint:`A task to act on`},{value:`note`,label:`💬 Note`,hint:`FYI, non-urgent`}],Iu=2500;function Lu({sessionId:e,limit:t=200}){let[n,r]=(0,V.useState)(null),[i,a]=(0,V.useState)(null),[o,s]=(0,V.useState)(``),[c,l]=(0,V.useState)(!1),[u,d]=(0,V.useState)(null),[f,p]=(0,V.useState)(`steer`),[m,h]=(0,V.useState)(`high`),[g,_]=(0,V.useState)([]),[v,y]=(0,V.useState)(!1),b=(0,V.useRef)(null),x=(0,V.useRef)(!0),S=(0,V.useRef)(!0),C=mi(e=>e.liveSessions),w=(0,V.useMemo)(()=>C.find(t=>t.sessionId===e),[C,e]),T=(0,V.useMemo)(()=>{let e=w;return e?`${e.status}|${e.agents.map(e=>`${e.id}:${e.status}:${e.toolCalls??0}:${e.iterations??0}`).join(`,`)}`:``},[w]),E=w?.status===`active`||(w?.agents.some(e=>e.status===`running`||e.status===`streaming`)??!1),D=(0,V.useMemo)(()=>{if(!w)return null;let e=w.agents.find(e=>e.status===`running`||e.status===`streaming`);return e?.currentTool?`🔧 ${e.currentTool}`:e?`${e.name??e.id} · working`:null},[w]),O=(0,V.useMemo)(()=>{if(!w)return null;let e=w.agents.find(e=>e.partialText&&(e.status===`streaming`||e.status===`running`))??w.agents.find(e=>e.partialText);return e?.partialText?{label:e.id===`leader`?Pu.assistant.label:e.name||e.id,text:e.partialText}:null},[w]),k=(0,V.useCallback)(async()=>{try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/events?limit=${t}`);if(!n.ok)throw Error(`HTTP ${n.status}`);let i=await n.json();S.current&&(r(i),a(null))}catch(e){S.current&&a(e instanceof Error?e.message:String(e))}},[e,t]),A=(0,V.useCallback)(async()=>{try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/mailbox`);if(!t.ok)return;let n=await t.json();S.current&&Array.isArray(n.thread)&&_(n.thread)}catch{}},[e]);(0,V.useEffect)(()=>{S.current=!0,r(null),a(null),_([]),k(),A();let e=setInterval(()=>void k(),Iu),t=setInterval(()=>void A(),Iu);return()=>{S.current=!1,clearInterval(e),clearInterval(t)}},[k,A]),(0,V.useEffect)(()=>{T&&k()},[T,k]),(0,V.useEffect)(()=>{x.current&&b.current&&(b.current.scrollTop=b.current.scrollHeight)},[n,O]);let ee=()=>{let e=b.current;e&&(x.current=e.scrollHeight-e.scrollTop-e.clientHeight<40)},j=async()=>{let t=o.trim();if(!(!t||c)){l(!0),d(null);try{let n=await fetch(`/api/sessions/${encodeURIComponent(e)}/message`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:t,type:f,priority:m})});if(!n.ok)throw Error(`HTTP ${n.status}`);s(``),d(E?`Delivered — the running agent sees it on its next step`:`Delivered — target is idle; appears in its mailbox, read when it next runs`),A()}catch(e){d(`Failed: ${e instanceof Error?e.message:String(e)}`)}finally{l(!1)}}},M=async()=>{if(!v){y(!0),d(null);try{let t=await fetch(`/api/sessions/${encodeURIComponent(e)}/interrupt`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({reason:`Operator requested stop from Fleet HQ`})});if(!t.ok)throw Error(`HTTP ${t.status}`);d(`Interrupt sent — agent stops at its next step (not a kill)`),A()}catch(e){d(`Interrupt failed: ${e instanceof Error?e.message:String(e)}`)}finally{y(!1)}}},N=n?.entries??[];return(0,q.jsxs)(`div`,{className:`flex flex-col h-full min-h-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5 shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase tracking-wide text-cyan-400/80`,children:[(0,q.jsx)(`span`,{className:Z(`h-1.5 w-1.5 rounded-full`,E?`bg-emerald-400 animate-pulse`:`bg-gray-600`)}),`Live stream`]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,q.jsxs)(`div`,{className:`text-[10px] text-gray-500`,children:[n.total,` event`,n.total===1?``:`s`,` · `,n.status]}),E&&(0,q.jsx)(`button`,{type:`button`,onClick:()=>void M(),disabled:v,title:`Cooperatively stop this agent at its next step (not a process kill)`,className:`rounded border border-rose-500/40 bg-rose-500/15 px-1.5 py-0.5 text-[10px] text-rose-300 hover:bg-rose-500/25 disabled:opacity-40 transition-colors`,children:v?`…`:`⏸ Interrupt`})]})]}),D&&(0,q.jsxs)(`div`,{className:`mb-1.5 shrink-0 text-[10px] text-emerald-300/90 truncate`,children:[`▶ `,D]}),i&&(0,q.jsxs)(`div`,{className:`text-[11px] text-red-400 mb-1 shrink-0`,children:[`· `,i]}),(0,q.jsxs)(`div`,{ref:b,onScroll:ee,className:`flex-1 overflow-y-auto space-y-1.5 pr-1 min-h-0`,children:[N.length===0&&!i&&(0,q.jsx)(`div`,{className:`text-[11px] text-gray-500 italic`,children:`Loading session…`}),N.map((e,t)=>{let n=Pu[e.role];return(0,q.jsxs)(`div`,{className:`text-[11px] leading-snug`,children:[(0,q.jsx)(`span`,{className:`font-semibold mr-1.5`,style:{color:n.color},children:e.role===`tool`&&e.tool?`🔧 ${e.tool}`:n.label}),e.text&&(0,q.jsx)(`span`,{className:`text-gray-300 whitespace-pre-wrap break-words`,children:e.text})]},`${e.ts}-${t}`)}),O&&(0,q.jsxs)(`div`,{className:`text-[11px] leading-snug`,children:[(0,q.jsx)(`span`,{className:`font-semibold mr-1.5`,style:{color:Pu.assistant.color},children:O.label}),(0,q.jsxs)(`span`,{className:`text-gray-300 whitespace-pre-wrap break-words`,children:[O.text,(0,q.jsx)(`span`,{className:`animate-pulse text-cyan-400`,children:`▋`})]})]})]}),g.length>0&&(0,q.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-slate-700/70 shrink-0 max-h-28 overflow-y-auto space-y-1`,children:[(0,q.jsx)(`div`,{className:`text-[9px] uppercase tracking-wide text-gray-500`,children:`Messages`}),g.slice(-6).map(e=>{let t=e.completed?`✓✓ done`:e.readByLeader?`✓ read`:`⏳ delivered`;return(0,q.jsxs)(`div`,{className:`text-[10px] leading-snug`,children:[(0,q.jsx)(`span`,{className:`font-semibold mr-1.5`,style:{color:e.fromLeader?Pu.assistant.color:Pu.user.color},children:e.fromLeader?`Agent`:`You`}),(0,q.jsx)(`span`,{className:`text-gray-300 whitespace-pre-wrap break-words`,children:e.body}),!e.fromLeader&&(0,q.jsx)(`span`,{className:Z(`ml-1.5 text-[9px]`,e.completed?`text-emerald-400`:e.readByLeader?`text-cyan-400`:`text-gray-500`),children:t})]},e.id)})]}),(0,q.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-slate-700/70 shrink-0`,children:[(0,q.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5`,children:[(0,q.jsx)(`select`,{value:f,onChange:e=>p(e.target.value),title:Fu.find(e=>e.value===f)?.hint,className:`rounded bg-slate-900/70 border border-slate-700 px-1.5 py-0.5 text-[10px] text-gray-200 focus:outline-none focus:border-cyan-500/50`,children:Fu.map(e=>(0,q.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,q.jsxs)(`select`,{value:m,onChange:e=>h(e.target.value),title:`Priority`,className:`rounded bg-slate-900/70 border border-slate-700 px-1.5 py-0.5 text-[10px] text-gray-200 focus:outline-none focus:border-cyan-500/50`,children:[(0,q.jsx)(`option`,{value:`high`,children:`high`}),(0,q.jsx)(`option`,{value:`normal`,children:`normal`}),(0,q.jsx)(`option`,{value:`low`,children:`low`})]})]}),(0,q.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,q.jsx)(`textarea`,{value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),j())},rows:2,placeholder:`${Fu.find(e=>e.value===f)?.label??`Send`} → this session…`,className:`flex-1 resize-none rounded-md bg-slate-900/70 border border-slate-700 px-2 py-1 text-[11px] text-gray-200 placeholder:text-gray-600 focus:outline-none focus:border-cyan-500/50`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>void j(),disabled:c||!o.trim(),className:`shrink-0 rounded-md bg-cyan-500/20 border border-cyan-500/40 text-cyan-300 px-2.5 py-1.5 text-[11px] hover:bg-cyan-500/30 disabled:opacity-40 disabled:cursor-not-allowed transition-colors`,children:c?`…`:`Send`})]}),u&&(0,q.jsx)(`div`,{className:`mt-1 text-[10px] text-gray-500`,children:u}),(0,q.jsx)(`div`,{className:`mt-0.5 text-[9px] text-gray-600`,children:`⌘/Ctrl+Enter to send · seen on the agent's next iteration`})]})]})}function Ru(e){return e?e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e):`0`}function zu(e,t){if(!e)return`—`;let n=Date.parse(e);if(Number.isNaN(n))return`—`;let r=Math.max(0,Math.round((t-n)/1e3));return r<60?`${r}s ago`:r<3600?`${Math.floor(r/60)}m ago`:`${Math.floor(r/3600)}h ago`}function Bu(e,t){if(!e)return`—`;let n=Date.parse(e);if(Number.isNaN(n))return`—`;let r=Math.max(0,Math.round((t-n)/1e3));return r<60?`${r}s`:r<3600?`${Math.floor(r/60)}m`:`${Math.floor(r/3600)}h ${Math.floor(r%3600/60)}m`}function Vu(e){if(e)return e.split(`/`).pop()?.slice(0,22)}function Hu({status:e,small:t,activity:n=0}){let r=t?`w-2 h-2`:`w-3 h-3`;n>0&&Math.min(.9,.3+n*.6);let i=t?4+n*4:6+n*6;return(0,q.jsx)(`span`,{className:Z(`rounded-full`,r,n>0&&`animate-pulse`,{idle:`bg-gray-500`,active:`bg-emerald-500`,streaming:`bg-blue-500`,completed:`bg-blue-500`,error:`bg-red-500`,offline:`bg-gray-600`}[e]),style:{boxShadow:n>0?`0 0 ${i}px ${{idle:`#9ca3af`,active:`#22c55e`,streaming:`#3b82f6`,completed:`#3b82f6`,error:`#ef4444`,offline:`#6b7280`}[e]}`:void 0}})}function Uu(){let{clientCounts:e,currentSession:t,totalAgents:n,activeAgents:r,aggregate:i}=mi(),a=e.tui+e.webui+e.repl,o=e=>e?.toLocaleString()??`0`;return(0,q.jsxs)(`div`,{className:`absolute top-20 left-4 z-10 bg-slate-800/95 backdrop-blur border border-slate-700 rounded-lg p-3 shadow-xl`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,q.jsx)(ir,{className:`h-3.5 w-3.5 text-emerald-400`}),(0,q.jsx)(`span`,{className:`text-[10px] font-bold text-gray-300 uppercase tracking-wide`,children:`Session Stats`})]}),(0,q.jsxs)(`div`,{className:`space-y-1.5 text-[10px]`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(zn,{className:`h-3 w-3 text-gray-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Clients`})]}),(0,q.jsxs)(`span`,{className:`text-gray-200 font-mono`,children:[r,` `,(0,q.jsx)(`span`,{className:`text-gray-500`,children:`/`}),` `,(0,q.jsx)(`span`,{className:`text-emerald-400`,children:a})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 pl-4 text-[9px]`,children:[e.tui>0&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(Un,{className:`h-2.5 w-2.5 text-emerald-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`TUI`}),(0,q.jsx)(`span`,{className:`text-emerald-400 font-mono`,children:e.tui})]}),e.webui>0&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(un,{className:`h-2.5 w-2.5 text-blue-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`WebUI`}),(0,q.jsx)(`span`,{className:`text-blue-400 font-mono`,children:e.webui})]}),e.repl>0&&(0,q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,q.jsx)(Un,{className:`h-2.5 w-2.5 text-amber-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`REPL`}),(0,q.jsx)(`span`,{className:`text-amber-400 font-mono`,children:e.repl})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(Qt,{className:`h-3 w-3 text-gray-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Agents`})]}),(0,q.jsxs)(`span`,{className:`text-gray-200 font-mono`,children:[r,` `,(0,q.jsx)(`span`,{className:`text-gray-500`,children:`/`}),` `,(0,q.jsx)(`span`,{className:`text-cyan-400`,children:n})]})]}),t.model&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(hn,{className:`h-3 w-3 text-gray-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Model`})]}),(0,q.jsx)(`span`,{className:`text-cyan-400 font-mono truncate max-w-[120px]`,title:t.model,children:t.model.split(`/`).pop()?.slice(0,16)})]}),t.mode&&(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(Dn,{className:`h-3 w-3 text-gray-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Mode`})]}),(0,q.jsx)(`span`,{className:Z(`font-mono uppercase text-[9px] px-1.5 py-0.5 rounded`,t.mode===`auto`&&`bg-purple-500/20 text-purple-400`,t.mode===`suggest`&&`bg-blue-500/20 text-blue-400`,t.mode===`off`&&`bg-gray-500/20 text-gray-400`,![`auto`,`suggest`,`off`].includes(t.mode||``)&&`bg-gray-500/20 text-gray-400`),children:t.mode})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(ze,{className:`h-3 w-3 text-gray-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Tool Calls`})]}),(0,q.jsx)(`span`,{className:`text-yellow-400 font-mono`,children:o(i.toolCalls)})]}),(0,q.jsxs)(`div`,{className:`border-t border-slate-700 pt-1.5 mt-1.5 space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`text-gray-500 text-[8px]`,children:`IN`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Input`})]}),(0,q.jsx)(`span`,{className:`text-gray-300 font-mono text-[9px]`,children:o(i.tokensIn)})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(`span`,{className:`text-gray-500 text-[8px]`,children:`OUT`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Output`})]}),(0,q.jsx)(`span`,{className:`text-gray-300 font-mono text-[9px]`,children:o(i.tokensOut)})]})]}),(0,q.jsxs)(`div`,{className:`flex items-center justify-between gap-4 border-t border-slate-700 pt-1.5 mt-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,q.jsx)(dn,{className:`h-3 w-3 text-gray-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Cost`})]}),(0,q.jsx)(`span`,{className:`text-emerald-400 font-mono font-medium`,children:(e=>e==null?`$0.0000`:`$${e.toFixed(4)}`)(i.costUsd)})]})]})]})}function Wu(){let e={opacity:0,width:1,height:1,minWidth:0,border:`none`,background:`transparent`};return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(ft,{type:`target`,position:an.Top,style:e,isConnectable:!1}),(0,q.jsx)(ft,{type:`source`,position:an.Bottom,style:e,isConnectable:!1})]})}function Gu({data:e}){return(0,q.jsxs)(`div`,{className:`mt-2 flex items-center justify-between border-t border-white/5 pt-1.5 text-[8px] text-gray-500`,children:[(0,q.jsxs)(`span`,{children:[(0,q.jsx)(`span`,{className:`font-mono text-gray-300`,children:e.agentCount??0}),` agents`]}),e.startedAt&&(0,q.jsxs)(`span`,{children:[`up `,Bu(e.startedAt,Date.now())]})]})}function Ku({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.status===`error`,r=e.status===`offline`,i=e.color||`#3b82f6`;return(0,q.jsxs)(`div`,{className:Z(`rounded-xl border-2 p-4 min-w-[180px] transition-all backdrop-blur-sm`,t&&`shadow-lg shadow-blue-500/20`,n&&`border-red-500/50 bg-red-500/10`,r&&`border-gray-500/30 bg-gray-500/5 opacity-60`,!t&&!n&&!r&&`border-blue-500/30 bg-blue-500/10`),children:[(0,q.jsx)(Wu,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,q.jsx)(`div`,{className:Z(`flex items-center justify-center w-10 h-10 rounded-lg`,t?`bg-blue-500/20`:`bg-blue-500/10`),children:(0,q.jsx)(un,{className:`h-5 w-5`,style:{color:i}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:i},children:e.label}),(0,q.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:`WebUI Client`})]}),(0,q.jsx)(Hu,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,q.jsx)(`div`,{className:`text-[10px] text-gray-400 mb-2 truncate`,children:e.sublabel}),(0,q.jsx)(`div`,{className:`flex items-center gap-2 text-[10px] text-gray-500`,children:r?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(jn,{className:`h-3 w-3 text-gray-500`}),(0,q.jsx)(`span`,{children:`Disconnected`})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(gn,{className:`h-3 w-3 text-emerald-500`}),(0,q.jsx)(`span`,{children:`Connected`})]})}),t&&(0,q.jsx)(`div`,{className:`mt-2 h-1 rounded-full bg-blue-500/30 overflow-hidden`,children:(0,q.jsx)(`div`,{className:`h-full bg-blue-500 animate-pulse`,style:{width:`60%`}})}),(0,q.jsx)(Gu,{data:e})]})}function qu({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.status===`error`,r=e.color||`#22c55e`;return(0,q.jsxs)(`div`,{className:Z(`rounded-xl border-2 p-4 min-w-[180px] transition-all backdrop-blur-sm`,t&&`shadow-lg shadow-emerald-500/20`,n&&`border-red-500/50 bg-red-500/10`,!t&&!n&&`border-emerald-500/30 bg-emerald-500/10`),children:[(0,q.jsx)(Wu,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,q.jsx)(`div`,{className:Z(`flex items-center justify-center w-10 h-10 rounded-lg`,t?`bg-emerald-500/20`:`bg-emerald-500/10`),children:(0,q.jsx)(Un,{className:`h-5 w-5`,style:{color:r}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:r},children:e.label}),(0,q.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:`TUI Client`})]}),(0,q.jsx)(Hu,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,q.jsx)(`div`,{className:`text-[10px] text-gray-400 mb-2 truncate`,children:e.sublabel}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-gray-500`,children:[(0,q.jsx)(Un,{className:`h-3 w-3 text-emerald-500`}),(0,q.jsx)(`span`,{children:`Terminal`})]}),(0,q.jsx)(Gu,{data:e})]})}function Ju({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.color||`#f59e0b`;return(0,q.jsxs)(`div`,{className:Z(`rounded-xl border-2 p-4 min-w-[160px] transition-all backdrop-blur-sm`,t&&`shadow-lg shadow-amber-500/20`,!t&&`border-amber-500/30 bg-amber-500/10`),children:[(0,q.jsx)(Wu,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,q.jsx)(`div`,{className:Z(`flex items-center justify-center w-10 h-10 rounded-lg`,t?`bg-amber-500/20`:`bg-amber-500/10`),children:(0,q.jsx)(Un,{className:`h-5 w-5`,style:{color:n}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-xs font-bold truncate`,style:{color:n},children:e.label}),(0,q.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:`REPL`})]}),(0,q.jsx)(Hu,{status:e.status,activity:e.vizActivity??0})]}),e.sublabel&&(0,q.jsx)(`div`,{className:`text-[10px] text-gray-400 mb-1 truncate`,children:e.sublabel}),(0,q.jsx)(Gu,{data:e})]})}function Yu({data:e}){let t=e.status===`active`||e.status===`streaming`;e.status;let n=e.color||`#a855f7`;return(0,q.jsxs)(`div`,{className:`rounded-xl border-2 p-4 min-w-[200px] transition-all backdrop-blur-sm relative bg-slate-900/90`,children:[(0,q.jsx)(Wu,{}),(0,q.jsx)(`div`,{className:`absolute -top-3 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-purple-600 text-white text-[9px] rounded-full font-bold`,children:`COORDINATOR`}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3 mt-2`,children:[(0,q.jsx)(`div`,{className:Z(`flex items-center justify-center w-12 h-12 rounded-xl`,t?`bg-purple-500/20`:`bg-purple-500/10`),children:(0,q.jsx)(hn,{className:`h-6 w-6`,style:{color:n}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-sm font-bold truncate`,style:{color:n},children:e.label}),(0,q.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:e.sublabel||`Fleet summary`})]}),(0,q.jsx)(Hu,{status:e.status,activity:e.vizActivity??0})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-[10px] mb-2`,children:[(0,q.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,q.jsxs)(`div`,{className:`font-mono`,children:[(0,q.jsx)(`span`,{className:`text-emerald-400`,children:e.agentsActive||0}),(0,q.jsx)(`span`,{className:`text-gray-500`,children:` / `}),(0,q.jsx)(`span`,{className:`text-purple-400`,children:e.agentsTotal||0})]}),(0,q.jsx)(`div`,{className:`text-gray-500`,children:`Agents`})]}),(0,q.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,q.jsx)(`div`,{className:`font-mono text-yellow-400`,children:(e.toolCalls||0).toLocaleString()}),(0,q.jsx)(`div`,{className:`text-gray-500`,children:`Tool calls`})]}),(0,q.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,q.jsx)(`div`,{className:`font-mono text-gray-300`,children:Ru(e.tokensIn)}),(0,q.jsx)(`div`,{className:`text-gray-500`,children:`Tokens`})]}),(0,q.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,q.jsxs)(`div`,{className:`font-mono text-emerald-400`,children:[`$`,(e.costUsd||0).toFixed(3)]}),(0,q.jsx)(`div`,{className:`text-gray-500`,children:`Cost`})]})]}),t&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-purple-400`,children:[(0,q.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-purple-400 animate-pulse`}),`Coordinating fleet`]})]})}function Xu({data:e}){let t=e.status===`active`||e.status===`streaming`,n=e.status===`error`,r=e.status===`completed`,i=e.color||`#06b6d4`;return(0,q.jsxs)(`div`,{className:Z(`rounded-lg border p-3 min-w-[150px] transition-all backdrop-blur-sm`,t&&`border-cyan-500/50 bg-cyan-500/10 shadow-lg shadow-cyan-500/10`,n&&`border-red-500/50 bg-red-500/10`,r&&`border-gray-500/30 bg-gray-500/5`,!t&&!n&&!r&&`border-cyan-500/30 bg-cyan-500/10`),children:[(0,q.jsx)(Wu,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,q.jsx)(Qt,{className:`h-4 w-4 shrink-0`,style:{color:i}}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-[11px] font-bold truncate`,style:{color:i},children:e.label}),e.model&&(0,q.jsx)(`div`,{className:`text-[8px] text-gray-500 truncate`,children:Vu(e.model)})]}),(0,q.jsx)(Hu,{status:e.status,small:!0,activity:e.vizActivity??0})]}),e.currentTask&&(0,q.jsxs)(`div`,{className:`flex items-center gap-1 text-[9px] text-cyan-300/90 truncate mb-1.5`,children:[(0,q.jsx)(`span`,{className:Z(`w-1.5 h-1.5 rounded-full bg-cyan-400 shrink-0`,t&&`animate-pulse`)}),(0,q.jsx)(`span`,{className:`truncate font-mono`,children:e.currentTask})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-2 gap-y-0.5 text-[9px] mb-1.5`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:`iter`}),(0,q.jsx)(`span`,{className:`text-gray-300 font-mono`,children:e.iteration||0})]}),(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:`tools`}),(0,q.jsx)(`span`,{className:`text-yellow-400/90 font-mono`,children:e.toolCalls||0})]}),(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:`tok`}),(0,q.jsx)(`span`,{className:`text-gray-300 font-mono`,children:Ru((e.tokensIn||0)+(e.tokensOut||0))})]}),(0,q.jsxs)(`div`,{className:`flex justify-between`,children:[(0,q.jsx)(`span`,{className:`text-gray-500`,children:`cost`}),(0,q.jsxs)(`span`,{className:`text-emerald-400/90 font-mono`,children:[`$`,(e.costUsd||0).toFixed(3)]})]})]}),e.ctxPct!=null&&e.ctxPct>0&&(0,q.jsxs)(`div`,{className:`mb-1`,children:[(0,q.jsxs)(`div`,{className:`flex justify-between text-[8px] text-gray-500 mb-0.5`,children:[(0,q.jsx)(`span`,{children:`ctx`}),(0,q.jsxs)(`span`,{className:Z(`font-mono`,e.ctxPct>=90?`text-red-400`:e.ctxPct>=70?`text-amber-400`:`text-gray-400`),children:[e.ctxPct,`%`]})]}),(0,q.jsx)(`div`,{className:`h-1 rounded-full bg-slate-700/60 overflow-hidden`,children:(0,q.jsx)(`div`,{className:Z(`h-full`,e.ctxPct>=90?`bg-red-500`:e.ctxPct>=70?`bg-amber-500`:`bg-cyan-500`),style:{width:`${Math.min(100,e.ctxPct)}%`}})})]}),e.lastActivityAt&&(0,q.jsxs)(`div`,{className:Z(`flex items-center gap-1 text-[8px]`,t?`text-gray-600`:`text-gray-500`),children:[r&&(0,q.jsx)(`span`,{className:`text-emerald-500/70`,children:`✓ done ·`}),n&&(0,q.jsx)(`span`,{className:`text-red-400/80`,children:`✕ failed ·`}),(0,q.jsxs)(`span`,{children:[`seen `,zu(e.lastActivityAt,Date.now())]})]})]})}function Zu({data:e}){return e.color,(0,q.jsxs)(`div`,{className:Z(`rounded-lg border border-dashed p-3 min-w-[120px] transition-all opacity-40`,`border-gray-600 bg-gray-800/30`),children:[(0,q.jsx)(Wu,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,q.jsx)(le,{className:`h-4 w-4 text-gray-600`}),(0,q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,q.jsx)(`div`,{className:`text-[10px] text-gray-500 truncate`,children:e.label})}),(0,q.jsx)(Hu,{status:e.status,small:!0,activity:e.vizActivity??0})]}),(0,q.jsx)(`div`,{className:`text-[9px] text-gray-600`,children:`Available desk`})]})}function Qu({data:e}){let t=e.color||`#eab308`,n=(e.unreadCount||0)>0;return(0,q.jsxs)(`div`,{className:Z(`rounded-xl border-2 p-4 min-w-[160px] transition-all backdrop-blur-sm`,n&&`border-yellow-500/50 bg-yellow-500/10 shadow-lg shadow-yellow-500/10`,!n&&`border-yellow-500/30 bg-yellow-500/5`),children:[(0,q.jsx)(Wu,{}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3 mb-3`,children:[(0,q.jsx)(`div`,{className:Z(`flex items-center justify-center w-10 h-10 rounded-lg`,n?`bg-yellow-500/20`:`bg-yellow-500/10`),children:(0,q.jsx)(xt,{className:`h-5 w-5`,style:{color:t}})}),(0,q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,q.jsx)(`div`,{className:`text-xs font-bold`,style:{color:t},children:`Mailbox Hub`}),(0,q.jsx)(`div`,{className:`text-[10px] text-gray-500`,children:n?`${e.unreadCount} unread`:`All clear`})]}),n&&(0,q.jsx)(`div`,{className:`w-5 h-5 rounded-full bg-yellow-500 text-black text-[10px] font-bold flex items-center justify-center`,children:e.unreadCount})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 text-[10px]`,children:[(0,q.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-yellow-400`,children:[(0,q.jsx)(me,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e.messageCount||0})]}),(0,q.jsx)(`div`,{className:`text-gray-500`,children:`Total`})]}),(0,q.jsxs)(`div`,{className:`bg-black/20 rounded p-1.5 text-center`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-center gap-1 text-emerald-400`,children:[(0,q.jsx)(m,{className:`h-3 w-3`}),(0,q.jsx)(`span`,{children:e.unreadCount||0})]}),(0,q.jsx)(`div`,{className:`text-gray-500`,children:`Unread`})]})]}),e.sublabel&&(0,q.jsxs)(`div`,{className:`mt-2 truncate border-t border-white/5 pt-1.5 text-[9px] text-gray-400`,children:[`✉ `,e.sublabel]})]})}var $u={webui:Ku,tui:qu,repl:Ju,coordinator:Yu,agent:Xu,mailbox:Qu,desk:Zu},ed={wire:({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:i,targetPosition:a,data:o,selected:s})=>{let c=o?.color||`#6366f1`,l=Ci(e=>e.animateEdges),u=o?.animated&&l?Math.max(.15,o?.intensity??.6):0,[d,f,p]=Rt({sourceX:e,sourceY:t,sourcePosition:i??an.Bottom,targetX:n,targetY:r,targetPosition:a??an.Top,curvature:.28}),m=5+u*7,h=5+u*4,g=m+h,_=`${Math.max(.5,1.6-u).toFixed(2)}s`;return(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(`path`,{d,fill:`none`,stroke:c,strokeWidth:s?2.5:1.4,strokeOpacity:s?.9:.28,className:`react-flow__edge-path`}),u>.05&&(0,q.jsx)(`path`,{d,fill:`none`,stroke:c,strokeWidth:2.2,strokeOpacity:.45+u*.5,strokeDasharray:`${m} ${h}`,strokeLinecap:`round`,style:{filter:`drop-shadow(0 0 ${2+u*4}px ${c})`},children:(0,q.jsx)(`animate`,{attributeName:`stroke-dashoffset`,from:g,to:`0`,dur:_,repeatCount:`indefinite`})}),o?.label&&u>.1&&(0,q.jsx)(Ht,{children:(0,q.jsx)(`div`,{style:{position:`absolute`,transform:`translate(-50%, -50%) translate(${f}px, ${p}px)`},className:`pointer-events-none rounded-full border border-white/15 bg-slate-800/90 px-1.5 py-0.5 text-[8px] font-medium text-white/85 backdrop-blur-sm`,children:o.label})})]})}},td=600,nd=50,rd=230,id=nd,ad=nd,od=370,sd=640,cd=380;function ld(e,t=cd){let n=new Map,r=Math.max(1,e.length);return e.forEach((e,i)=>{n.set(e,td+(i-(r-1)/2)*t)}),n}var ud=3,dd=190,fd=150;function pd(e,t,n){let r=Math.min(ud,n),i=Math.floor(t/r);return{x:e+(t%r-(Math.min(r,n-i*r)-1)/2)*dd,y:sd+i*fd}}function md(e){return e===`tui`?`tui`:e===`cli`||e===`repl`?`repl`:`webui`}function hd(e){return e===`tui`?`Terminal UI`:e===`repl`?`REPL`:`Web UI`}function gd(e){switch(e){case`running`:case`active`:return`active`;case`streaming`:return`streaming`;case`completed`:return`completed`;case`failed`:case`error`:return`error`;default:return`idle`}}function _d(e,t){let n=new Set,r=[];for(let i of e){let e=md(i.clientType),a=`client-${i.pid??i.sessionId}`,o=[],s=!1;for(let e of i.agents){n.add(e.id);let r=t.get(e.id),i=gd(r?.status??e.status);(i===`active`||i===`streaming`)&&(s=!0),o.push({officeId:`${a}__agent-${e.id}`,serverId:e.id,name:r?.name??e.name??e.id,status:i,iteration:r?.iteration??e.iterations??0,toolCalls:r?.toolCalls??e.toolCalls??0,costUsd:r?.costUsd??e.costUsd??0,tokensIn:r?.tokensIn??e.tokensIn??0,tokensOut:r?.tokensOut??e.tokensOut??0,ctxPct:r?.ctxPct??e.ctxPct,model:r?.model??e.model,lastActivityAt:e.lastActivityAt,currentTask:r?.currentTool??r?.lastTool??e.currentTool})}let c=i.status===`closing`||i.status===`stale`?`offline`:s?`active`:`idle`;r.push({id:a,type:e,label:i.projectName||hd(e),sublabel:[hd(e),i.gitBranch?`⎇ ${i.gitBranch}`:``,i.pid?`pid ${i.pid}`:``].filter(Boolean).join(` · `),status:c,sessionId:i.sessionId,pid:i.pid,branch:i.gitBranch,workingDir:i.workingDir,startedAt:i.startedAt,agents:o})}let i=[...t.values()].filter(e=>!n.has(e.id));if(i.length>0){let e=r.find(e=>e.type===`webui`);e||(e={id:`client-self`,type:`webui`,label:`This WebUI`,sublabel:`Web UI`,status:`idle`,agents:[]},r.push(e));for(let t of i){let n=gd(t.status);(n===`active`||n===`streaming`)&&(e.status=`active`),e.agents.push({officeId:`${e.id}__agent-${t.id}`,serverId:t.id,name:t.name,status:n,iteration:t.iteration??0,toolCalls:t.toolCalls??0,costUsd:t.costUsd??0,tokensIn:t.tokensIn??0,tokensOut:t.tokensOut??0,ctxPct:t.ctxPct,model:t.model,currentTask:t.currentTool??t.lastTool})}}return r.length===0&&r.push({id:`client-self`,type:`webui`,label:`This WebUI`,sublabel:`Web UI · connecting…`,status:`idle`,agents:[]}),r}function vd(e){return e.startsWith(`tool`)?`#eab308`:e.startsWith(`mailbox`)?`#06b6d4`:e.startsWith(`provider`)?`#a855f7`:e.startsWith(`agent`)||e.startsWith(`subagent`)?`#22c55e`:e.includes(`error`)?`#ef4444`:`#6366f1`}function yd({events:e,now:t}){let n=e.slice(0,14);return(0,q.jsx)(`div`,{className:`absolute bottom-0 left-0 right-0 z-10 pointer-events-none px-3 pb-3`,children:(0,q.jsxs)(`div`,{className:`pointer-events-auto rounded-lg bg-slate-900/85 border border-slate-700/70 backdrop-blur px-3 py-2 max-w-3xl mx-auto`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 mb-1.5 text-[10px] uppercase tracking-wide text-cyan-400/80`,children:[(0,q.jsx)(ir,{className:`h-3 w-3`}),`Live activity`]}),n.length===0?(0,q.jsx)(`div`,{className:`text-[11px] text-gray-500 italic`,children:`Waiting for activity…`}):(0,q.jsx)(`div`,{className:`flex flex-col gap-0.5 max-h-32 overflow-hidden`,children:n.map(e=>{let n=Math.max(0,Math.round((t-e.timestamp)/1e3));return(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] leading-tight`,children:[(0,q.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0`,style:{backgroundColor:vd(e.kind)}}),(0,q.jsx)(`span`,{className:`text-gray-300 truncate flex-1`,children:e.label}),(0,q.jsx)(`span`,{className:`text-gray-600 shrink-0 tabular-nums`,children:n<1?`now`:`${n}s`})]},e.id)})})]})})}function bd(){let{fitView:e}=_n(),t=li(e=>e.events),n=J(e=>e.agents),r=J(e=>e.leaderId),i=mi(e=>e.liveSessions),a=Ar(e=>e.messages),o=G(e=>e.session),s=(0,V.useMemo)(()=>_d(i,n),[i,n]),c=Ci(e=>e.showHud),l=Ci(e=>e.showLegend),u=Ci(e=>e.showMinimap),d=Ci(e=>e.showControls);Ci(e=>e.animateEdges);let f=Ci(e=>e.showFeed),p=Ci(e=>e.setShowFeed),m=Ci(e=>e.background),[h,g,_]=jt([]),[v,b,x]=wt([]),[S,C]=(0,V.useState)(null),[w,T]=(0,V.useState)(null),[E,D]=(0,V.useState)(!1),[O,k]=(0,V.useState)(``),[A,ee]=(0,V.useState)(!1),[j,M]=(0,V.useState)(null),N=(0,V.useCallback)(async()=>{let e=O.trim();if(!(!e||A)){ee(!0),M(null);try{let t=await fetch(`/api/fleet/broadcast`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({text:e})});if(!t.ok)throw Error(`HTTP ${t.status}`);let n=await t.json();k(``),M(`Delivered to ${n.delivered??0}/${n.targets??0} session(s)`)}catch(e){M(`Failed: ${e instanceof Error?e.message:String(e)}`)}finally{ee(!1)}}},[O,A]),P=(0,V.useRef)(new Map),F=4e3,I=(0,V.useRef)(new Map);li(e=>e.nodes),li(e=>e.edges);let te=(0,V.useRef)(new Map),L=(0,V.useRef)(new Map),ne=(0,V.useRef)(new Map),R=(0,V.useRef)(``);(0,V.useEffect)(()=>{let t=[],i=[],o=Date.now(),c=Math.max(1,...s.map(e=>e.agents.length||1)),l=Math.max(cd,Math.min(ud,c)*dd+80),u=ld(s.map(e=>e.id),l),d=a.filter(e=>!e.completed&&(e.readByCount??0)===0).length,f=a.length?[...a].sort((e,t)=>Date.parse(t.timestamp)-Date.parse(e.timestamp))[0]:void 0;t.push({id:`mailbox`,type:`mailbox`,position:{x:830,y:id},data:{label:`Mailbox Hub`,kind:`mailbox`,status:d>0?`active`:`idle`,unreadCount:d,messageCount:a.length,sublabel:f?`${f.from} → ${f.to}: ${f.subject}`:void 0,color:`#eab308`}});let p=0,m=0,h=0,_=0,v=0;for(let e of s)for(let t of e.agents)m+=1,(t.status===`active`||t.status===`streaming`)&&(p+=1),h+=t.toolCalls,_+=t.costUsd,v+=t.tokensIn+t.tokensOut;let y=r?n.get(r):null,x=p>0;t.push({id:`coordinator`,type:`coordinator`,position:{x:td-rd,y:ad},data:{label:`Fleet HQ`,sublabel:`${s.length} client${s.length===1?``:`s`}`,kind:`coordinator`,status:y?.status===`failed`?`error`:x?`active`:`idle`,connections:s.length,agentsActive:p,agentsTotal:m,toolCalls:h,costUsd:_,tokensIn:v,color:`#a855f7`}});let S={tui:`#22c55e`,webui:`#3b82f6`,repl:`#f59e0b`};for(let e of s){let n=u.get(e.id)??td,r=S[e.type],a=e.status===`active`;if(t.push({id:e.id,type:e.type,position:{x:n,y:od},data:{label:e.label,sublabel:e.sublabel,kind:e.type,status:e.status,sessionId:e.sessionId,pid:e.pid,branch:e.branch,workingDir:e.workingDir,startedAt:e.startedAt,agentCount:e.agents.length,color:r}}),i.push({id:`${e.id}->coordinator`,source:e.id,target:`coordinator`,type:`wire`,animated:a,data:{color:r,animated:a,label:`control`,flowType:`task`}}),i.push({id:`mailbox->${e.id}`,source:`mailbox`,target:e.id,type:`wire`,animated:d>0,data:{color:`#eab308`,animated:d>0,label:d>0?`${d}`:void 0,flowType:`mail`}}),e.agents.length===0){t.push({id:`desk-${e.id}`,type:`desk`,position:{x:n,y:sd},data:{label:`Idle desk`,kind:`agent`,status:`idle`,color:`#374151`}});continue}e.agents.forEach((r,a)=>{let s=r.status===`active`||r.status===`streaming`,c=ne.current.get(r.serverId);if(c&&(r.toolCalls>c.toolCalls||r.iteration>c.iteration)||s){P.current.set(r.officeId,o+F);let t=te.current.get(r.officeId)??0;te.current.set(r.officeId,Math.min(1,t+(1-t)*.5));for(let t of[`${e.id}->${r.officeId}`,`${e.id}->coordinator`]){let e=I.current.get(t)??0;I.current.set(t,Math.min(1,e+.5))}}ne.current.set(r.serverId,{toolCalls:r.toolCalls,iteration:r.iteration}),t.push({id:r.officeId,type:`agent`,position:pd(n,a,e.agents.length),data:{label:r.name,kind:`agent`,status:r.status,sessionId:e.sessionId,currentTask:r.currentTask,iteration:r.iteration,toolCalls:r.toolCalls,costUsd:r.costUsd,tokensIn:r.tokensIn,tokensOut:r.tokensOut,ctxPct:r.ctxPct,model:r.model,lastActivityAt:r.lastActivityAt,color:`#06b6d4`}}),i.push({id:`${e.id}->${r.officeId}`,source:e.id,target:r.officeId,type:`wire`,animated:s,data:{color:`#06b6d4`,animated:s,label:s?r.currentTask??`task`:void 0,flowType:`task`}})})}let C=new Set(s.flatMap(e=>e.agents.map(e=>e.serverId)));for(let e of[...ne.current.keys()])C.has(e)||ne.current.delete(e);let w=t.map(e=>{let t=P.current.get(e.id),n=te.current.get(e.id)??0;return t&&t>o&&e.data.status!==`error`&&e.data.status!==`offline`?{...e,data:{...e.data,status:`active`,vizActivity:n}}:{...e,data:{...e.data,vizActivity:n}}}),T=i.map(e=>{let t=I.current.get(e.id)??0;return t>.05?{...e,animated:!0,data:{...e.data,animated:!0,intensity:t}}:e}),E=new Map;for(let e of w)E.set(e.id,{...e.position});L.current=E,g(w),b(T);let D=w.map(e=>e.id).sort().join(`|`);if(D!==R.current){R.current=D;let t=setTimeout(()=>e({padding:.2,duration:300}),50);return()=>clearTimeout(t)}},[s,r,n,a,o,F,g,b,e]);let re=s.flatMap(e=>e.agents.map(t=>({clientId:e.id,clientType:e.type,officeId:t.officeId,serverId:t.serverId}))),ie=s.map(e=>e.id),ae=new Map;for(let e of re)(!ae.has(e.serverId)||e.clientType===`webui`)&&ae.set(e.serverId,e.officeId);function oe(e){return ae.get(e)??`agent-${e}`}function se(e){let t=e.split(`__agent-`)[0];return t&&t!==e?`${t}->${e}`:`coordinator->${e}`}function ce(e){switch(e.kind){case`mailbox:send`:case`mailbox:deliver`:return{nodes:[`mailbox`],edges:e.kind===`mailbox:send`?ie.map(e=>`mailbox->${e}`):[],status:`active`};case`agent:spawned`:{let t=oe(e.source);return{nodes:[`coordinator`,t],edges:[se(t)],status:`active`}}case`agent:tool`:case`tool:started`:case`tool:progress`:{let t=oe(e.source);return{nodes:[`coordinator`,t],edges:[se(t)],status:e.kind===`tool:progress`||e.kind===`tool:started`?`streaming`:`active`}}case`tool:executed`:{let t=oe(e.target??e.source);return{nodes:[t],edges:[se(t)],status:`active`}}case`provider:call`:case`provider:delta`:case`provider:response`:return{nodes:[`coordinator`],edges:[],status:e.kind===`provider:delta`?`streaming`:`active`};case`iteration:start`:case`iteration:end`:return{nodes:[`coordinator`],edges:re.map(e=>se(e.officeId)),status:e.kind===`iteration:start`?`streaming`:`active`};case`agent:text`:{let t=oe(e.source);return{nodes:[t],edges:[se(t)],status:`streaming`}}case`agent:status`:{let t=oe(e.source);return{nodes:[`coordinator`,t],edges:[se(t)],status:e.data&&typeof e.data==`object`&&`status`in e.data&&String(e.data.status)===`failed`?`error`:`completed`}}case`agent:ctx`:return{nodes:[oe(e.source)],edges:[],status:`active`};case`budget:extended`:return{nodes:[`coordinator`,oe(e.source)],edges:[],status:`active`};case`context:compacted`:case`context:repaired`:return{nodes:[`coordinator`],edges:[],status:`active`};case`error`:return{nodes:e.source?[oe(e.source)]:[],edges:[],status:`error`};case`cost:update`:return{nodes:[`coordinator`],edges:[],status:`active`};case`fleet:snapshot`:{let t=e.data?.sessions??[],n=[`coordinator`];for(let e of t)if(e.agents)for(let t of e.agents){let e=oe(t.id);n.includes(e)||n.push(e)}return{nodes:n,edges:[],status:`active`}}default:return{nodes:[],edges:[],status:`idle`}}}(0,V.useEffect)(()=>{if(t.length===0)return;let e=t[0];if(!e)return;let{nodes:n,edges:r,status:i}=ce(e),a=Date.now();n.length>0&&(n.forEach(e=>{P.current.set(e,a+F);let t=te.current.get(e)??0;te.current.set(e,Math.min(1,t+(1-t)*.5))}),g(e=>e.map(e=>n.includes(e.id)?{...e,data:{...e.data,status:i,vizActivity:te.current.get(e.id)??0}}:e))),r.length>0&&(r.forEach(e=>{let t=I.current.get(e)??0;I.current.set(e,Math.min(1,t+.5))}),b(e=>e.map(e=>r.includes(e.id)?{...e,animated:!0,data:{...e.data,animated:!0,intensity:I.current.get(e.id)??1}}:e)))},[t,g,b,F,n]),(0,V.useEffect)(()=>{let e=setInterval(()=>{for(let[e,t]of I.current){let n=t*.85;n<.05?(I.current.delete(e),b(t=>t.map(t=>t.id===e?{...t,animated:!1,data:{...t.data,animated:!1}}:t))):(I.current.set(e,n),b(t=>t.map(t=>t.id===e?{...t,data:{...t.data,intensity:n}}:t)))}for(let[e,t]of te.current){let n=t*.9;n<.03?(te.current.delete(e),g(t=>t.map(t=>t.id===e?{...t,data:{...t.data,vizActivity:0}}:t))):(te.current.set(e,n),g(t=>t.map(t=>t.id===e?{...t,data:{...t.data,vizActivity:n}}:t)))}},1e3);return()=>clearInterval(e)},[b,g]);let le=(0,V.useCallback)(e=>b(t=>en({...e,type:`wire`},t)),[b]),ue=(0,V.useCallback)((e,t)=>{C(t)},[]),de=(0,V.useCallback)(()=>{C(null)},[]);(0,V.useEffect)(()=>{if(!w)return;let e=e=>{e.key===`Escape`&&T(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[w]);let fe=(0,V.useCallback)(()=>{g(e=>e.map(e=>{let t=L.current.get(e.id);return t?{...e,position:{...t}}:e})),setTimeout(()=>e({padding:.2,duration:300}),50)},[g,e]),[,pe]=(0,V.useState)(0);return(0,V.useEffect)(()=>{let e=setInterval(()=>pe(e=>e+1),2e3);return()=>clearInterval(e)},[]),(0,q.jsxs)(`div`,{className:`w-full h-full bg-gradient-to-br from-slate-900 via-slate-800 to-slate-900 relative overflow-hidden`,children:[(0,q.jsx)(`div`,{className:`absolute inset-0 opacity-[0.03]`,style:{backgroundImage:`
|
|
116
|
-
linear-gradient(rgba(255,255,255,0.1) 1px, transparent 1px),
|
|
117
|
-
linear-gradient(90deg, rgba(255,255,255,0.1) 1px, transparent 1px)
|
|
118
|
-
`,backgroundSize:`40px 40px`}}),c&&(0,q.jsx)(Uu,{}),(0,q.jsx)(`div`,{className:`absolute top-3 left-1/2 -translate-x-1/2 z-10`,children:(0,q.jsx)(`div`,{className:`bg-slate-800/90 backdrop-blur px-4 py-2 rounded-lg border border-slate-700 shadow-xl`,children:(0,q.jsxs)(`div`,{className:`text-xs font-bold text-slate-300 flex items-center gap-2`,children:[(0,q.jsx)(y,{className:`h-4 w-4 text-purple-400`}),`WrongStack Fleet HQ`,(0,q.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-500 animate-pulse ml-2`}),(0,q.jsx)(`span`,{className:`text-[10px] text-gray-400 font-normal`,children:`LIVE`})]})})}),l&&(0,q.jsxs)(`div`,{className:`absolute bottom-4 left-4 z-10 bg-slate-800/90 backdrop-blur rounded-lg border border-slate-700 p-3 text-[10px]`,children:[(0,q.jsx)(`div`,{className:`font-bold text-gray-300 mb-2`,children:`Status`}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-emerald-500 animate-pulse`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Active`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-gray-500`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Idle`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`w-2 h-2 rounded-full bg-red-500 animate-pulse`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Error`})]})]})]}),l&&(0,q.jsxs)(`div`,{className:`absolute bottom-4 right-4 z-10 bg-slate-800/90 backdrop-blur rounded-lg border border-slate-700 p-3 text-[10px]`,children:[(0,q.jsx)(`div`,{className:`font-bold text-gray-300 mb-2`,children:`Connections`}),(0,q.jsxs)(`div`,{className:`space-y-1`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-yellow-400`,children:`✉`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Mail`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-purple-400`,children:`→`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Task`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,q.jsx)(`span`,{className:`text-emerald-400`,children:`●`}),(0,q.jsx)(`span`,{className:`text-gray-400`,children:`Status`})]})]})]}),(0,q.jsxs)(In,{nodes:h,edges:v,onNodesChange:_,onEdgesChange:x,onConnect:le,onNodeClick:ue,onPaneClick:de,nodeTypes:$u,edgeTypes:ed,fitView:!0,fitViewOptions:{padding:.2},minZoom:.3,maxZoom:1.5,defaultEdgeOptions:{type:`wire`},proOptions:{hideAttribution:!0},children:[(0,q.jsxs)(On,{position:`top-right`,className:`flex items-center gap-2`,children:[(0,q.jsxs)(`button`,{type:`button`,onClick:fe,title:`Snap nodes back to the floor plan`,className:`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md bg-slate-800/90 border border-slate-700 text-xs text-slate-200 hover:bg-slate-700 transition-colors`,children:[(0,q.jsx)(lt,{className:`h-3.5 w-3.5`}),`Arrange`]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>p(!f),title:`Toggle the live activity feed`,className:Z(`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md border text-xs transition-colors`,f?`bg-cyan-500/20 border-cyan-500/40 text-cyan-300`:`bg-slate-800/90 border-slate-700 text-slate-300 hover:bg-slate-700`),children:[(0,q.jsx)(Ee,{className:`h-3.5 w-3.5`}),`Feed`]}),(0,q.jsxs)(`button`,{type:`button`,onClick:()=>D(e=>!e),title:`Broadcast a message to every live session in this project`,className:Z(`flex items-center gap-1.5 px-2.5 py-1.5 rounded-md border text-xs transition-colors`,E?`bg-amber-500/20 border-amber-500/40 text-amber-300`:`bg-slate-800/90 border-slate-700 text-slate-300 hover:bg-slate-700`),children:[(0,q.jsx)(me,{className:`h-3.5 w-3.5`}),`Broadcast`]})]}),m!==`none`&&(0,q.jsx)(Mn,{variant:m===`lines`?ln.Lines:m===`cross`?ln.Cross:ln.Dots,gap:20,size:1,color:`rgba(255,255,255,0.05)`}),d&&(0,q.jsx)(wn,{className:`bg-slate-800 border border-slate-700 rounded-lg [&>button]:bg-slate-700 [&>button]:text-slate-200`}),u&&(0,q.jsx)(pn,{className:`bg-slate-800/90 border border-slate-700 rounded-lg`,nodeColor:e=>{switch(e.data.kind){case`coordinator`:return`#a855f7`;case`webui`:return`#3b82f6`;case`tui`:return`#22c55e`;case`repl`:return`#f59e0b`;case`mailbox`:return`#eab308`;case`agent`:return`#06b6d4`;default:return`#6366f1`}},maskColor:`rgba(0,0,0,0.8)`})]}),f&&(0,q.jsx)(yd,{events:t,now:Date.now()}),E&&(0,q.jsxs)(`div`,{className:`absolute top-16 right-4 z-30 w-80 rounded-lg border border-amber-500/40 bg-slate-900/97 p-3 shadow-2xl backdrop-blur`,children:[(0,q.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-semibold text-amber-300`,children:[(0,q.jsx)(me,{className:`h-3.5 w-3.5`}),` Broadcast to all sessions`]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>D(!1),className:`text-gray-400 hover:text-white text-base leading-none`,children:`×`})]}),(0,q.jsx)(`textarea`,{value:O,onChange:e=>k(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),N())},rows:3,placeholder:`Message every live agent in this project…`,className:`w-full resize-none rounded-md border border-slate-700 bg-slate-900/70 px-2 py-1 text-[11px] text-gray-200 placeholder:text-gray-600 focus:border-amber-500/50 focus:outline-none`}),(0,q.jsxs)(`div`,{className:`mt-1.5 flex items-center justify-between`,children:[(0,q.jsx)(`span`,{className:`text-[9px] text-gray-600`,children:`⌘/Ctrl+Enter to send`}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>void N(),disabled:A||!O.trim(),className:`rounded-md border border-amber-500/40 bg-amber-500/20 px-2.5 py-1 text-[11px] text-amber-200 transition-colors hover:bg-amber-500/30 disabled:cursor-not-allowed disabled:opacity-40`,children:A?`…`:`Broadcast`})]}),j&&(0,q.jsx)(`div`,{className:`mt-1 text-[10px] text-gray-400`,children:j})]}),S&&(0,q.jsxs)(`div`,{className:Z(`absolute top-20 right-4 bg-slate-800/95 backdrop-blur border border-slate-700 rounded-lg p-4 shadow-xl z-20`,S.data.sessionId?`w-80`:`w-64`),children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[S.data.kind===`webui`&&(0,q.jsx)(un,{className:`h-4 w-4 text-blue-500`}),S.data.kind===`tui`&&(0,q.jsx)(Un,{className:`h-4 w-4 text-emerald-500`}),S.data.kind===`coordinator`&&(0,q.jsx)(hn,{className:`h-4 w-4 text-purple-500`}),S.data.kind===`agent`&&(0,q.jsx)(Qt,{className:`h-4 w-4 text-cyan-500`}),S.data.kind===`mailbox`&&(0,q.jsx)(xt,{className:`h-4 w-4 text-yellow-500`}),(0,q.jsx)(`span`,{className:`text-sm font-bold text-white`,children:S.data.label})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[S.data.sessionId&&(0,q.jsx)(`button`,{type:`button`,title:`Open full operation view`,onClick:()=>T({sessionId:S.data.sessionId,label:S.data.label}),className:`text-gray-400 hover:text-cyan-300`,children:(0,q.jsx)(kn,{className:`h-3.5 w-3.5`})}),(0,q.jsx)(`button`,{onClick:de,className:`text-gray-400 hover:text-white text-lg leading-none`,children:`×`})]})]}),(()=>{let e=S.data,t=Date.now(),n=({k:e,v:t,accent:n})=>(0,q.jsxs)(`div`,{className:`flex justify-between gap-3`,children:[(0,q.jsx)(`span`,{className:`text-gray-400 shrink-0`,children:e}),(0,q.jsx)(`span`,{className:Z(`font-mono truncate text-right`,n??`text-gray-200`),children:t})]}),r=e.kind===`agent`,i=e.kind===`webui`||e.kind===`tui`||e.kind===`repl`,o=(e.tokensIn||0)+(e.tokensOut||0);return(0,q.jsxs)(`div`,{className:`space-y-1.5 text-xs`,children:[(0,q.jsx)(n,{k:`Status`,v:String(e.status).toUpperCase(),accent:Z(e.status===`active`&&`text-emerald-400`,e.status===`streaming`&&`text-blue-400`,e.status===`error`&&`text-red-400`,e.status===`idle`&&`text-gray-400`,e.status===`offline`&&`text-gray-500`)}),r&&(0,q.jsxs)(q.Fragment,{children:[e.model&&(0,q.jsx)(n,{k:`Model`,v:Vu(e.model),accent:`text-cyan-400`}),e.currentTask&&(0,q.jsx)(n,{k:`Tool`,v:e.currentTask,accent:`text-cyan-300`}),(0,q.jsx)(n,{k:`Iterations`,v:e.iteration||0,accent:`text-cyan-400`}),(0,q.jsx)(n,{k:`Tool calls`,v:e.toolCalls||0,accent:`text-yellow-400`}),(0,q.jsx)(n,{k:`Tokens in`,v:Ru(e.tokensIn)}),(0,q.jsx)(n,{k:`Tokens out`,v:Ru(e.tokensOut)}),(0,q.jsx)(n,{k:`Tokens total`,v:Ru(o)}),e.ctxPct!=null&&e.ctxPct>0&&(0,q.jsx)(n,{k:`Context`,v:`${e.ctxPct}%`,accent:e.ctxPct>=90?`text-red-400`:e.ctxPct>=70?`text-amber-400`:`text-gray-300`}),(0,q.jsx)(n,{k:`Cost`,v:`$${(e.costUsd||0).toFixed(4)}`,accent:`text-emerald-400`}),e.lastActivityAt&&(0,q.jsx)(n,{k:`Last seen`,v:zu(e.lastActivityAt,t),accent:`text-gray-400`})]}),i&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(n,{k:`Surface`,v:hd(e.kind),accent:`text-gray-200`}),e.branch&&(0,q.jsx)(n,{k:`Branch`,v:`⎇ ${e.branch}`,accent:`text-gray-300`}),e.pid!=null&&(0,q.jsx)(n,{k:`PID`,v:e.pid}),e.workingDir&&(0,q.jsx)(n,{k:`Dir`,v:e.workingDir,accent:`text-gray-400`}),(0,q.jsx)(n,{k:`Agents`,v:e.agentCount??0,accent:`text-cyan-400`}),e.startedAt&&(0,q.jsx)(n,{k:`Uptime`,v:Bu(e.startedAt,t),accent:`text-gray-300`})]}),e.kind===`mailbox`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(n,{k:`Total messages`,v:e.messageCount||0,accent:`text-yellow-400`}),(0,q.jsx)(n,{k:`Unread`,v:e.unreadCount||0,accent:`text-yellow-400`}),a.length>0&&(0,q.jsxs)(`div`,{className:`mt-1 space-y-1 border-t border-slate-700 pt-2`,children:[(0,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-gray-500`,children:`Recent`}),[...a].sort((e,t)=>Date.parse(t.timestamp)-Date.parse(e.timestamp)).slice(0,6).map(e=>(0,q.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px]`,children:[(0,q.jsx)(`span`,{className:Z(`mt-1 h-1.5 w-1.5 shrink-0 rounded-full`,!e.completed&&(e.readByCount??0)===0?`bg-yellow-400`:e.completed?`bg-emerald-500`:`bg-gray-600`)}),(0,q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,q.jsx)(`div`,{className:`truncate text-gray-300`,children:e.subject||`(no subject)`}),(0,q.jsxs)(`div`,{className:`truncate font-mono text-[9px] text-gray-500`,children:[e.from,` → `,e.to,` · `,zu(e.timestamp,t)]})]})]},e.id))]})]}),e.kind===`coordinator`&&(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)(n,{k:`Connections`,v:e.connections||0,accent:`text-purple-400`}),(0,q.jsx)(n,{k:`Iterations`,v:e.iteration||0,accent:`text-purple-400`})]}),(r||i)&&e.sessionId&&(0,q.jsx)(`div`,{className:`mt-2 border-t border-slate-700 pt-2 h-72`,children:(0,q.jsx)(Lu,{sessionId:e.sessionId})})]})})()]}),w&&(0,q.jsxs)(`div`,{className:`absolute inset-y-0 right-0 z-30 flex w-[min(680px,92%)] flex-col border-l border-slate-700 bg-slate-900/97 shadow-2xl backdrop-blur`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between border-b border-slate-700 px-4 py-2.5 shrink-0`,children:[(0,q.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,q.jsx)(Qt,{className:`h-4 w-4 text-cyan-400 shrink-0`}),(0,q.jsxs)(`div`,{className:`min-w-0`,children:[(0,q.jsx)(`div`,{className:`truncate text-sm font-bold text-white`,children:w.label}),(0,q.jsx)(`div`,{className:`text-[10px] uppercase tracking-wide text-cyan-400/70`,children:`Full operation stream`})]})]}),(0,q.jsx)(`button`,{type:`button`,onClick:()=>T(null),title:`Close (Esc)`,className:`text-gray-400 hover:text-white text-xl leading-none shrink-0`,children:`×`})]}),(0,q.jsx)(`div`,{className:`flex-1 min-h-0 p-4`,children:(0,q.jsx)(Lu,{sessionId:w.sessionId,limit:500})})]})]})}function xd(){return(0,q.jsx)(bt,{children:(0,q.jsx)(bd,{})})}function Sd({title:e,value:t,subtitle:n,icon:r,color:i=`text-blue-500`,trend:a}){return(0,q.jsxs)(`div`,{className:`bg-card rounded-lg border p-4 shadow-sm`,children:[(0,q.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground font-medium`,children:e}),(0,q.jsx)(`p`,{className:`text-2xl font-bold mt-1 ${i}`,children:t}),n&&(0,q.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:n})]}),(0,q.jsx)(`div`,{className:`p-2 rounded-lg bg-muted ${i}`,children:(0,q.jsx)(r,{className:`w-5 h-5`})})]}),a&&(0,q.jsxs)(`div`,{className:`mt-2 flex items-center gap-1`,children:[a===`up`&&(0,q.jsx)(cn,{className:`w-3 h-3 text-green-500`}),a===`down`&&(0,q.jsx)(cn,{className:`w-3 h-3 text-red-500 rotate-180`}),(0,q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a===`up`?`Increasing`:a===`down`?`Decreasing`:`Stable`})]})]})}function Cd(){let[e,t]=(0,V.useState)({fileWatcher:null,system:null,lastUpdated:null,error:null}),[n,r]=(0,V.useState)(!0),[i,a]=(0,V.useState)(2e3),s=(0,V.useCallback)(async()=>{try{let e=await fetch(`/debug/watcher-metrics`),n=null;e.ok&&(n=await e.json());let r={memoryUsage:{heapUsed:performance.memory?.usedJSHeapSize??0,heapTotal:performance.memory?.totalJSHeapSize??0,external:0,rss:0,arrayBuffers:0},uptime:performance.timeOrigin?performance.now()/1e3:0,cpuUsage:{user:0,system:0}};t({fileWatcher:n,system:r,lastUpdated:new Date,error:null})}catch(e){t(t=>({...t,error:e instanceof Error?e.message:`Failed to fetch metrics`}))}finally{r(!1)}},[]);return(0,V.useEffect)(()=>{s();let e=setInterval(s,i);return()=>clearInterval(e)},[s,i]),(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto bg-background p-6`,children:(0,q.jsxs)(`div`,{className:`max-w-6xl mx-auto space-y-6`,children:[(0,q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,q.jsxs)(`div`,{children:[(0,q.jsxs)(`h1`,{className:`text-2xl font-bold flex items-center gap-2`,children:[(0,q.jsx)(C,{className:`w-7 h-7`}),`Debug Dashboard`]}),(0,q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Real-time monitoring for WrongStack WebUI`})]}),(0,q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,q.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,q.jsx)(ar,{className:`w-4 h-4 text-muted-foreground`}),(0,q.jsx)(`span`,{className:`text-muted-foreground`,children:`Refresh:`}),(0,q.jsxs)(`select`,{value:i,onChange:e=>a(Number(e.target.value)),className:`bg-background border rounded px-2 py-1 text-sm`,children:[(0,q.jsx)(`option`,{value:1e3,children:`1s`}),(0,q.jsx)(`option`,{value:2e3,children:`2s`}),(0,q.jsx)(`option`,{value:5e3,children:`5s`}),(0,q.jsx)(`option`,{value:1e4,children:`10s`})]})]}),(0,q.jsxs)(`button`,{onClick:()=>{r(!0),s()},disabled:n,className:`flex items-center gap-2 px-3 py-1.5 bg-primary text-primary-foreground rounded-lg text-sm font-medium hover:opacity-90 disabled:opacity-50`,children:[(0,q.jsx)(ar,{className:`w-4 h-4 ${n?`animate-spin`:``}`}),`Refresh`]})]})]}),e.lastUpdated&&(0,q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,q.jsx)(Et,{className:`w-4 h-4`}),`Last updated: `,e.lastUpdated.toLocaleTimeString()]}),e.error&&(0,q.jsxs)(`div`,{className:`flex items-center gap-3 p-4 bg-destructive/10 border border-destructive/30 rounded-lg text-destructive`,children:[(0,q.jsx)(Hn,{className:`w-5 h-5 flex-shrink-0`}),(0,q.jsxs)(`div`,{children:[(0,q.jsx)(`p`,{className:`font-medium`,children:`Failed to fetch metrics`}),(0,q.jsx)(`p`,{className:`text-sm opacity-80`,children:e.error})]})]}),(0,q.jsxs)(`section`,{children:[(0,q.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2 mb-4`,children:[(0,q.jsx)(ot,{className:`w-5 h-5`}),`File Watcher`]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,q.jsx)(Sd,{title:`Watcher Status`,value:e.fileWatcher?.watcherActive?`Running`:`Stopped`,icon:Yt,color:e.fileWatcher?.watcherActive?`text-green-500`:`text-red-500`}),(0,q.jsx)(Sd,{title:`Active Projects`,value:e.fileWatcher?.activeProjects??0,subtitle:`Projects being watched`,icon:ae,color:`text-purple-500`}),(0,q.jsx)(Sd,{title:`File Changes`,value:e.fileWatcher?.fileChangesDetected??0,subtitle:`Total detected`,icon:ir,color:`text-blue-500`,trend:`neutral`}),(0,q.jsx)(Sd,{title:`Files Processed`,value:e.fileWatcher?.filesProcessed??0,subtitle:`After hash filter`,icon:o,color:`text-cyan-500`})]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mt-4`,children:[(0,q.jsx)(Sd,{title:`Broadcasts Sent`,value:e.fileWatcher?.broadcastsSent??0,subtitle:`To WebUI clients`,icon:cn,color:`text-green-500`}),(0,q.jsx)(Sd,{title:`Debounce Resets`,value:e.fileWatcher?.debounceResets??0,subtitle:`Rapid successive writes`,icon:ar,color:`text-orange-500`}),(0,q.jsx)(Sd,{title:`Avg Debounce Delay`,value:`${(e.fileWatcher?.averageDebounceDelayMs??0).toFixed(1)}ms`,subtitle:`Actual delay applied`,icon:Et,color:`text-yellow-500`}),(0,q.jsx)(Sd,{title:`Total Delay`,value:`${(e.fileWatcher?.totalDebounceDelayMs??0).toFixed(0)}ms`,subtitle:`Sum of all delays`,icon:C,color:`text-indigo-500`})]})]}),(0,q.jsxs)(`section`,{children:[(0,q.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2 mb-4`,children:[(0,q.jsx)(o,{className:`w-5 h-5`}),`Browser Performance`]}),(0,q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-3 gap-4`,children:[(0,q.jsx)(Sd,{title:`Heap Used`,value:wd(e.system?.memoryUsage?.heapUsed??0),subtitle:`JavaScript heap`,icon:C,color:`text-blue-500`}),(0,q.jsx)(Sd,{title:`Heap Total`,value:wd(e.system?.memoryUsage?.heapTotal??0),subtitle:`Total heap size`,icon:C,color:`text-green-500`}),(0,q.jsx)(Sd,{title:`Page Uptime`,value:Td(e.system?.uptime??0),subtitle:`Since page load`,icon:Et,color:`text-purple-500`})]})]}),(0,q.jsxs)(`section`,{children:[(0,q.jsxs)(`h2`,{className:`text-lg font-semibold flex items-center gap-2 mb-4`,children:[(0,q.jsx)(ir,{className:`w-5 h-5`}),`Raw Data`]}),(0,q.jsx)(`div`,{className:`bg-card rounded-lg border p-4 shadow-sm`,children:(0,q.jsx)(`pre`,{className:`text-xs font-mono overflow-x-auto`,children:JSON.stringify({fileWatcher:e.fileWatcher,browserMemory:e.system?.memoryUsage,pageUptime:e.system?.uptime},null,2)})})]})]})})}function wd(e){if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return`${(e/t**r).toFixed(1)} ${n[r]}`}function Td(e){return e<60?`${e.toFixed(0)}s`:e<3600?`${(e/60).toFixed(1)}m`:`${(e/3600).toFixed(1)}h`}function Ed(){let{theme:e}=Aa(),{currentView:t,sidebarOpen:n,toggleSidebar:r,setSearchOpen:i,setSidebarOpen:a,setCurrentView:o,setInspectorTab:s,toggleInspector:c,fleetMonitorOpen:l,agentsMonitorOpen:u,setFleetMonitorOpen:d,setAgentsMonitorOpen:f,processMonitorOpen:p,setProcessMonitorOpen:m,queuePanelOpen:h,setQueuePanelOpen:g}=K(),_=U(e=>e.isLoading),v=G(e=>e.iteration),y=G(e=>e.projectName),b=G(e=>e.session?.title),x=G(e=>e.session?.id),S=K(e=>x?e.sessionNicknames[x]:void 0);return(0,V.useEffect)(()=>{typeof window<`u`&&window.location.pathname===`/debug`&&o(`debug`)},[o]),(0,V.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=H(W.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,V.useEffect)(()=>{let e=e=>{let{filePath:t}=e.detail,n=Y.getState().openFiles.find(e=>e.path===t);if(!n)return;let r=H(W.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,V.useEffect)(()=>{if(typeof window>`u`)return;let e=window.matchMedia(`(max-width: 768px)`),t=()=>{e.matches&&K.getState().sidebarOpen&&a(!1)};return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[a]),Ea(),(0,V.useEffect)(()=>{let e=[];if(_){let t=v?` iter ${v.index}${v.max?`/${v.max}`:``}`:``;e.push(`●${t}`)}let t=S?.trim()||b?.trim(),n=y?.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=y||`AI Agent`}},[_,v,y,b,S]),(0,V.useEffect)(()=>{let e=e=>{let t=e.target,n=t?.tagName?.toLowerCase(),a=n===`input`||n===`textarea`||t?.isContentEditable,l=e.ctrlKey||e.metaKey;if(l&&e.key===`\\`){e.preventDefault(),r();return}if(l&&!e.shiftKey&&!e.altKey&&e.key>=`1`&&e.key<=String(Fa.length)){let t=Fa[Number(e.key)-1];if(t){e.preventDefault(),Pa(t);return}}if(l&&e.key.toLowerCase()===`f`){e.preventDefault(),i(!0);return}if(l&&e.key.toLowerCase()===`/`){e.preventDefault(),document.querySelector(`textarea`)?.focus();return}if(l&&!a&&(e.key.toLowerCase()===`l`?(e.preventDefault(),U.getState().clearMessages(),H(W.getState().wsUrl)?.clearContext?.()):e.key.toLowerCase()===`n`?(e.preventDefault(),H(W.getState().wsUrl)?.newSession?.(),K.getState().setCurrentView(`chat`)):e.key.toLowerCase()===`e`&&(e.preventDefault(),uo())),l&&e.shiftKey&&e.key.toLowerCase()===`d`&&(e.preventDefault(),K.getState().toggleCompactMode()),l&&e.shiftKey&&e.key.toLowerCase()===`m`){e.preventDefault();let t=K.getState();t.inspectorOpen&&t.inspectorTab===`fleet`?c():(s(`fleet`),t.inspectorOpen||c())}if(l&&e.shiftKey&&e.key.toLowerCase()===`a`){e.preventDefault();let t=K.getState();t.inspectorOpen&&t.inspectorTab===`agents`?c():(s(`agents`),t.inspectorOpen||c())}if(l&&e.shiftKey&&e.key.toLowerCase()===`g`&&(e.preventDefault(),o(`debug`)),e.key===`Escape`&&!l&&K.getState().inspectorOpen&&K.getState().setInspectorOpen(!1),!a&&!l&&!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(B(t[0]));return}if(e.key===`G`||e.key===`g`&&e.shiftKey){e.preventDefault(),i(B(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,q.jsxs)(`div`,{className:Z(`flex h-screen`,e),children:[t!==`setup`&&(0,q.jsx)(Ia,{}),n&&t!==`setup`&&(0,q.jsx)(Ml,{}),(0,q.jsxs)(`main`,{className:`flex-1 flex flex-col overflow-hidden`,children:[t!==`setup`&&(0,q.jsx)(ic,{}),t===`chat`&&(0,q.jsxs)(q.Fragment,{children:[x&&(0,q.jsx)(`div`,{className:`px-4 pt-2`,children:(0,q.jsx)(Xl,{sessionId:x})}),(0,q.jsx)(Ls,{}),(0,q.jsx)(Eu,{})]}),t===`settings`&&(0,q.jsx)(jc,{}),t===`setup`&&(0,q.jsx)(Fc,{}),t===`autophase`&&(0,q.jsx)(io,{onClose:()=>o(`chat`)}),t===`sessions`&&(0,q.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,q.jsx)(Vc,{})}),t===`debug`&&(0,q.jsx)(Cd,{}),t===`files`&&(0,q.jsx)(Hs,{}),t===`skill`&&(0,q.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,q.jsx)(Nu,{className:`h-full`})}),t===`officemap`&&(0,q.jsx)(`div`,{className:`flex-1 overflow-hidden`,children:(0,q.jsx)(xd,{})})]}),l&&(0,q.jsx)(xu,{onClose:()=>d(!1)}),u&&(0,q.jsx)(tu,{onClose:()=>f(!1)}),p&&(0,q.jsx)(Es,{open:p,onClose:()=>m(!1)}),h&&(0,q.jsx)(Au,{open:h,onClose:()=>g(!1)}),(0,q.jsx)(ec,{}),(0,q.jsx)(rc,{}),(0,q.jsx)(po,{}),(0,q.jsx)(Uc,{}),(0,q.jsx)(sc,{}),(0,q.jsx)(ki,{})]})}function Dd(){return(0,q.jsx)(ac,{children:(0,q.jsx)(ka,{defaultTheme:`system`,children:(0,q.jsx)(Ed,{})})})}cr.createRoot(B(document.getElementById(`root`))).render((0,q.jsx)(V.StrictMode,{children:(0,q.jsx)(Dd,{})}));
|