@adhdev/daemon-standalone 0.6.79 → 0.7.1

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.
@@ -1,76 +0,0 @@
1
- var tn=Object.defineProperty;var sn=(t,s,n)=>s in t?tn(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var $e=(t,s,n)=>sn(t,typeof s!="symbol"?s+"":s,n);import{r,j as e,M as Zt,a as Qt,b as nn,c as rn,u as jt,t as an,d as on,e as cn,f as js,R as ln,g as vs,h as dn,B as un,i as xn,k as qe,N as kt,l as pn}from"./vendor-tc3018Wt.js";import{D as mn,o as hn,L as fn}from"./terminal-Dm9LBRva.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))a(i);new MutationObserver(i=>{for(const o of i)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&a(c)}).observe(document,{childList:!0,subtree:!0});function n(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function a(i){if(i.ep)return;i.ep=!0;const o=n(i);fetch(i.href,o)}})();const ws=r.createContext({ides:[],updateIdeChats:()=>{},screenshotMap:{},setScreenshotMap:()=>{},initialLoaded:!1,toasts:[],setToasts:()=>{},wsStatus:"connected",isConnected:!0,connectionStates:{},connectionTransports:{},showReconnected:!1,userName:void 0,setUserName:()=>{},isP2PActive:!1,p2pStates:{},userRole:void 0}),Ns=r.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function es(t){var n,a;let s=0;return"activeChat"in t&&(s+=4),(n=t.agentStreams)!=null&&n.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(a=t.agents)!=null&&a.length&&(s+=1),s}function gn(t,s){var c,d,l,h,x,m,f;const n=Date.now();if(s.length===0)return t.map(u=>({...u,_lastUpdate:n}));const a=new Map;for(const u of s)a.set(u.id,u);for(const u of t){const g=a.get(u.id);if(!g){a.set(u.id,{...u,_lastUpdate:n});continue}const N=es(u),L=es(g);if(N>L){const v=(c=u.chats)!=null&&c.length?u.chats:g.chats;a.set(u.id,{...g,...u,chats:v,_lastUpdate:n})}else if(N<L){const v={};u.status&&u.status!==g.status&&(v.status=u.status),u.cdpConnected!==void 0&&(v.cdpConnected=u.cdpConnected),(d=u.chats)!=null&&d.length&&!((l=g.chats)!=null&&l.length)&&(v.chats=u.chats),u.machineNickname!==void 0&&u.machineNickname!==g.machineNickname&&(v.machineNickname=u.machineNickname),Object.keys(v).length>0&&a.set(u.id,{...g,...v,_lastUpdate:g._lastUpdate})}else{const v=u.timestamp||n,w=g._lastUpdate||g.timestamp||0;if(v>=w){const P=(h=u.chats)!=null&&h.length?u.chats:g.chats;a.set(u.id,{...g,...u,chats:P,_lastUpdate:n})}else(x=u.chats)!=null&&x.length&&!((m=g.chats)!=null&&m.length)&&a.set(u.id,{...g,chats:u.chats})}}const i=new Set(t.map(u=>u.id)),o=new Set;for(const u of t){const g=u.daemonId||((f=u.id)==null?void 0:f.split(":")[0]);g&&o.add(g)}for(const[u,g]of a){const N=g.daemonId||u.split(":")[0];if(!o.has(N))continue;const L=n-(g._lastUpdate||g.timestamp||0);(u.includes(":cli:")&&!i.has(u)&&L>1e4||u.includes(":acp:")&&!i.has(u)&&L>1e4||u.includes(":ide:")&&!i.has(u)&&L>3e4)&&a.delete(u)}for(const[u,g]of a)n-(g._lastUpdate||g.timestamp||0)>3e5&&g.status!=="online"&&a.delete(u);return Array.from(a.values())}function bn({children:t,connectionOverrides:s}){const[n,a]=r.useState([]),[i,o]=r.useState({}),[c,d]=r.useState(!1),[l,h]=r.useState([]),[x,m]=r.useState(void 0),f=r.useCallback((N,L)=>{a(v=>v.map(w=>w.id===N?{...w,chats:L}:w))},[]),u={injectEntries:N=>{a(L=>L.length===0?N:gn(N,L))},markLoaded:()=>d(!0),getIdes:()=>n},g=s;return e.jsx(Ns.Provider,{value:u,children:e.jsx(ws.Provider,{value:{ides:n,updateIdeChats:f,screenshotMap:i,setScreenshotMap:o,initialLoaded:c,toasts:l,setToasts:h,wsStatus:(g==null?void 0:g.wsStatus)??"connected",isConnected:(g==null?void 0:g.isConnected)??!0,connectionStates:(g==null?void 0:g.connectionStates)??{},connectionTransports:(g==null?void 0:g.connectionTransports)??{},showReconnected:(g==null?void 0:g.showReconnected)??!1,retryConnection:g==null?void 0:g.retryConnection,isP2PActive:(g==null?void 0:g.isP2PActive)??!1,p2pStates:(g==null?void 0:g.p2pStates)??{},userRole:g==null?void 0:g.userRole,userName:x,setUserName:m},children:t})})}function bt(){return r.useContext(ws)}function ts(){return r.useContext(Ns)}function yn(t){const{baseUrl:s,getToken:n,onUnauthorized:a}=t;async function i(o,c={}){const d={"Content-Type":"application/json",...c.headers||{}},l=n==null?void 0:n();l&&(d.Authorization=`Bearer ${l}`);const h=o.startsWith("http")?o:`${s}${o.startsWith("/")?"":"/"}${o}`,x=await fetch(h,{...c,headers:d});if(x.status===401)throw a==null||a(),new Error("Unauthorized");if(!x.ok){const m=await x.json().catch(()=>({error:x.statusText}));throw new Error(m.error||`API Error: ${x.status}`)}return x.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:o=>i(`/api/v1/daemons/${o}/status`),sendCommand:(o,c,d={})=>i(`/api/v1/daemons/${o}/command`,{method:"POST",body:JSON.stringify({type:c,payload:d})}),execTerminal:(o,c,d)=>i(`/api/v1/daemons/${o}/terminal`,{method:"POST",body:JSON.stringify({command:c,name:d})}),sendAgentMessage:(o,c,d)=>i(`/api/v1/shortcuts/${o}/chat`,{method:"POST",body:JSON.stringify({agentType:c,message:d})}),getAgentStatus:o=>i(`/api/v1/shortcuts/${o}/status`),approveAgent:(o,c,d)=>i(`/api/v1/shortcuts/${o}/approve`,{method:"POST",body:JSON.stringify({agentType:c,action:d?"approve":"reject"})}),request:i}}const jn=yn({baseUrl:"http://localhost:3847"});r.createContext(jn);const vn={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},ks=r.createContext(vn);function wn({value:t,children:s}){return e.jsx(ks.Provider,{value:t,children:s})}function st(){return r.useContext(ks)}const Me={size:18};function Ss({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]})}function Cs({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2"}),e.jsx("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2"}),e.jsx("circle",{cx:"6",cy:"6",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"6",cy:"18",r:"1",fill:"currentColor",stroke:"none"}),e.jsx("line",{x1:"10",y1:"6",x2:"18",y2:"6"}),e.jsx("line",{x1:"10",y1:"18",x2:"18",y2:"18"})]})}function Nn({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function kn({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"12",cy:"7",r:"4"})]})}function Sn({size:t=Me.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}function Tt({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),e.jsx("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"}),e.jsx("line",{x1:"9",y1:"7",x2:"16",y2:"7"}),e.jsx("line",{x1:"9",y1:"11",x2:"14",y2:"11"})]})}function Cn({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}),e.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"}),e.jsx("line",{x1:"8",y1:"10",x2:"16",y2:"10"}),e.jsx("line",{x1:"8",y1:"14",x2:"14",y2:"14"}),e.jsx("line",{x1:"8",y1:"18",x2:"12",y2:"18"})]})}function Vt({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06A1.65 1.65 0 0 0 4.68 15a1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06A1.65 1.65 0 0 0 9 4.68a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06A1.65 1.65 0 0 0 19.4 9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function Is({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),e.jsx("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function Ms({size:t=Me.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})})}function lt({size:t=Me.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function nt({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),e.jsx("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function Ts({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"}),e.jsx("line",{x1:"8",y1:"13",x2:"16",y2:"13"}),e.jsx("line",{x1:"8",y1:"17",x2:"13",y2:"17"})]})}function In({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function Ot({size:t=Me.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}function Es({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function qt({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function dt({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}function As({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}function $s({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polyline",{points:"12 6 12 12 16 14"})]})}function Mn({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]})}function Gt({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polyline",{points:"4 17 10 11 4 5"}),e.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function _s({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"}),e.jsx("path",{d:"M12 15l-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"}),e.jsx("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),e.jsx("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}function Rs({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"3",y:"8",width:"18",height:"12",rx:"2"}),e.jsx("path",{d:"M12 2v6"}),e.jsx("circle",{cx:"8.5",cy:"14",r:"1.5",fill:"currentColor",stroke:"none"}),e.jsx("circle",{cx:"15.5",cy:"14",r:"1.5",fill:"currentColor",stroke:"none"})]})}function Tn({size:t=Me.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})})}function En({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"9",y:"10",width:"6",height:"12",rx:"1"}),e.jsx("path",{d:"M12 2c-1.5 2-3 3.5-3 5a3 3 0 0 0 6 0c0-1.5-1.5-3-3-5z"})]})}function Ps({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),e.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}function An({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}function $n({size:t=Me.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}function _n({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"})]})}function Rn({size:t=Me.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M14.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M9.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M19.35 6.07A16.03 16.03 0 0 0 15 4a.84.84 0 0 0-.46.33 11 11 0 0 0-.74 1.5 15.68 15.68 0 0 0-3.6 0 11.23 11.23 0 0 0-.74-1.5A.84.84 0 0 0 9 4a16.03 16.03 0 0 0-4.35 2.07A16.8 16.8 0 0 0 2 15a16.22 16.22 0 0 0 4 3c.12.08.27.06.37-.04a11.14 11.14 0 0 0 1.2-1.92.35.35 0 0 0-.18-.46 10.4 10.4 0 0 1-1.63-.78.36.36 0 0 1 .03-.6 6.8 6.8 0 0 0 .32-.24.36.36 0 0 1 .37-.04c2.2.98 4.6.98 6.8 0a.36.36 0 0 1 .37.04c.1.08.21.16.32.24a.36.36 0 0 1 .03.6 10.4 10.4 0 0 1-1.63.78.35.35 0 0 0-.18.46c.39.67.8 1.3 1.2 1.92a.37.37 0 0 0 .37.04 16.22 16.22 0 0 0 4-3 16.8 16.8 0 0 0-2.65-8.93z"})]})}function Pn(t){const n=t.split(`
2
- `).map(d=>{if(!d.includes("\r"))return d;const l=d.split("\r").map(m=>m.trim()).filter(Boolean);if(l.length===0)return"";const h=l.filter(m=>m.startsWith("⏺"));if(h.length>0)return h[h.length-1];const x=l.filter(m=>!(/^[❯›>]\s*$/.test(m)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(m)&&m.length<40||/^[╭╰│├╮╯─═]+$/.test(m)));return x.length>0?x[x.length-1]:l[l.length-1]}).join(`
3
- `).split(`
4
- `),a={},i=[];let o=!1;for(const d of n){const l=d.trim();if(l===""){o=!1,i.push("");continue}if(/^❯\s*$/.test(l)||/^>\s*$/.test(l)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(l)||/^◐\s/.test(l)||/\/effort/.test(l)||/^⎿\s+(Tip|Note|Hint):/.test(l)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(l)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(l)||/Brewing[…\.]{0,3}\s*\d*$/i.test(l)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(l)||/^Auto-updating/i.test(l))continue;if(/^[⏺●·⏵]/.test(d)){const x=d.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(x)a[x[1]]=(a[x[1]]||0)+1;else{const m=d.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);m&&(a[m]=(a[m]||0)+1)}o=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(d)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(d)||o&&/^\s{2,}/.test(d))continue;o=!1;const h=d.replace(/^❯\s+/,"");i.push(h)}const c=i.join(`
5
- `).replace(/\n{3,}/g,`
6
-
7
- `).trim();return{toolCounts:a,textContent:c,hasTools:Object.keys(a).length>0}}function Rt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}const Ln=r.forwardRef(function({messages:s,actionLogs:n,agentName:a="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:d="",receivedAtMap:l={},emptyState:h,onLoadMore:x,isLoadingMore:m,hasMoreHistory:f,loadError:u},g){var V;const N=r.useRef(null),L=r.useRef(null),v=r.useRef(0),w=r.useRef(""),P=r.useRef(!1),[B,D]=r.useState(new Set),[T,R]=r.useState(new Set),$=r.useRef(!1),_=()=>{const H=N.current;return H?H.scrollHeight-H.scrollTop-H.clientHeight<200:!0},re=s.length>0?`${s.length}:${(((V=s[s.length-1])==null?void 0:V.content)||"").length}`:"0:0";r.useEffect(()=>{var ne,ee;const H=!P.current,Y=w.current!==d;if(w.current=d,H||Y){P.current=!0,$.current=!1;const me=()=>{var fe;(fe=L.current)==null||fe.scrollIntoView({behavior:"instant"})};requestAnimationFrame(()=>requestAnimationFrame(me)),setTimeout(me,100),setTimeout(me,300),v.current=s.length;return}s.length>v.current?$.current||(ne=L.current)==null||ne.scrollIntoView({behavior:"instant"}):_()&&!$.current&&((ee=L.current)==null||ee.scrollIntoView({behavior:"instant"})),v.current=s.length},[re,d,c]),r.useImperativeHandle(g,()=>({scrollToBottom:(H="smooth")=>{var Y;(Y=L.current)==null||Y.scrollIntoView({behavior:H})}})),r.useEffect(()=>{const H=N.current;if(!H)return;let Y;const q=()=>{clearTimeout(Y),Y=setTimeout(()=>{$.current=!_()},50)};return H.addEventListener("scroll",q,{passive:!0}),()=>{H.removeEventListener("scroll",q),clearTimeout(Y)}},[]);const b=r.useRef(0),z=r.useRef(!1);r.useEffect(()=>{const H=N.current;if(!H||!z.current||b.current===0)return;const Y=H.scrollHeight-b.current;Y>0&&(H.scrollTop=Y),b.current=0,z.current=!1},[s.length]);const F=()=>{const H=N.current;H&&(b.current=H.scrollHeight),z.current=!0,x==null||x()},y=(()=>{const H=s.map((ee,me)=>({type:"message",data:ee,index:me,ts:ee.receivedAt||l[ee.id??`i-${me}`]||0}));if(!n||n.length===0)return H;const Y=[...n].sort((ee,me)=>ee.timestamp-me.timestamp).map((ee,me)=>({type:"action",data:ee,index:me,ts:ee.timestamp})),q=[];let ne=0;for(const ee of H){for(;ne<Y.length&&ee.ts>0&&Y[ne].ts<ee.ts;)q.push(Y[ne++]);q.push(ee)}for(;ne<Y.length;)q.push(Y[ne++]);return q})(),Z=700;return e.jsxs("div",{ref:N,"data-chat-scroll":!0,className:"chat-container",children:[m&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),f&&!m&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:F,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${u?"bg-transparent border-yellow-500/30 text-yellow-400 opacity-80 hover:opacity-100":"bg-transparent border-border-subtle text-text-muted opacity-70 hover:opacity-100 hover:border-accent/40"}`,children:u?`↻ ${u}`:"↑ Load older messages"})}),y.length===0&&!f&&(h||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),y.map(H=>{var he;if(H.type==="action"){const le=H.data;return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Zt,{remarkPlugins:[Qt],children:le.text}),e.jsx("span",{className:"action-time",children:Rt(le.timestamp)})]},`action-${H.index}`)}const Y=H.data,q=H.index,ne=(Y.role||"").toLowerCase(),ee=ne==="user"||ne==="human",me=Y.kind||(ne==="tool"?"tool":"standard"),fe=Y.receivedAt||l[Y.id??`i-${q}`],Ie=`${d}-${q}`,O=B.has(Ie),C=T.has(Ie),p=typeof Y.content=="string"?Y.content:(Y.content||[]).map(le=>le.text||"").join(`
8
- `);if(me==="thought"){const le=((he=Y.meta)==null?void 0:he.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Tn,{size:13}),e.jsx("span",{children:le})]}),e.jsx("div",{className:"chat-msg-body",children:p})]},`msg-${q}`)}if(me==="tool")return e.jsxs("div",{className:"self-start chat-msg-tool",children:[e.jsx("span",{className:"tool-icon",children:"⏺"}),e.jsx("span",{className:"tool-text",children:p.split(`
9
- `)[0].slice(0,80)})]},`msg-${q}`);if(me==="terminal"){const le=Y.meta||{},ye=le.isRunning?"⏳":"✅",Ne=le.label||"Ran command";return e.jsxs("div",{className:"self-start chat-msg-terminal",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx("span",{children:ye}),e.jsx("span",{children:Ne})]}),e.jsx("pre",{className:"chat-msg-body",children:p})]},`msg-${q}`)}if(me==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:p.slice(0,100)},`msg-${q}`);const A=!ee&&o?Pn(p):null,E=A?A.textContent:p,xe=A?Object.entries(A.toolCounts):[],de=o&&!ee&&!O&&E.length>Z,we=O?p:de&&!C?E.slice(0,Z):E;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${ee?"self-end":"self-start"}`,children:[xe.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[xe.map(([le,ye])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",le,ye>1?` ×${ye}`:""]},le)),(A==null?void 0:A.hasTools)&&e.jsx("button",{onClick:()=>D(le=>{const ye=new Set(le);return O?ye.delete(Ie):ye.add(Ie),ye}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:O?"Collapse":"Original"}),!E&&fe!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Rt(fe)})]}),(E||ee)&&e.jsxs("div",{className:`chat-bubble ${ee?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${E?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:ee?i||"You":a}),fe!=null&&e.jsx("span",{className:"chat-time",children:Rt(fe)})]}),E&&e.jsx("div",{className:"chat-markdown",children:e.jsx(Zt,{remarkPlugins:[Qt,nn,rn],children:we})}),de&&e.jsx("button",{onClick:()=>R(le=>{const ye=new Set(le);return C?ye.delete(Ie):ye.add(Ie),ye}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:C?"Collapse ↑":`Show more (${Math.round(E.length/100)*100} chars) ↓`})]})]},`msg-${q}`)}),c&&e.jsx("div",{className:"self-start chat-typing-wrapper",children:e.jsxs("div",{className:"typing-indicator",children:[e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:"Agent generating..."})]})}),e.jsx("div",{className:"min-h-10",ref:L})]})}),ss={background:"#0f1117",foreground:"#cdd6f4",cursor:"#f38ba8",cursorAccent:"#0f1117",selectionBackground:"rgba(166, 227, 161, 0.3)",selectionForeground:"#cdd6f4",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#cba6f7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#cba6f7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},Ls=r.forwardRef(({onInput:t,onResize:s,fontSize:n=13},a)=>{const i=r.useRef(null),o=r.useRef(null),c=r.useRef(null),[d,l]=r.useState(!1);return r.useImperativeHandle(a,()=>({write:h=>{var x;(x=o.current)==null||x.write(h)},clear:()=>{var h;(h=o.current)==null||h.clear()},fit:()=>{var h;try{(h=c.current)==null||h.fit(),o.current&&(s==null||s(o.current.cols,o.current.rows))}catch{}},bumpResize:()=>{var h;try{(h=c.current)==null||h.fit();const x=o.current;if(!x)return;const m=x.cols,f=x.rows;s==null||s(m+5,f),setTimeout(()=>{s==null||s(m,f)},100)}catch{}}})),r.useEffect(()=>{if(!i.current)return;const h=new mn({cursorBlink:!0,cursorStyle:"bar",fontSize:n,fontFamily:"'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace",fontWeight:"400",letterSpacing:0,lineHeight:1.2,theme:ss,allowTransparency:!0,scrollback:5e3,convertEol:!1}),x=new hn,m=new fn;h.loadAddon(x),h.loadAddon(m),h.open(i.current),requestAnimationFrame(()=>{x.fit(),s==null||s(h.cols,h.rows),l(!0)});const f=h.onData(g=>{t(g)}),u=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{x.fit(),s==null||s(h.cols,h.rows)}catch{}})});return u.observe(i.current),o.current=h,c.current=x,()=>{f.dispose(),u.disconnect(),h.dispose(),o.current=null,c.current=null}},[n]),e.jsx("div",{ref:i,className:"w-full h-full rounded-lg overflow-hidden transition-opacity duration-200",style:{background:ss.background,opacity:d?1:0}})});Ls.displayName="CliTerminal";function vt({label:t,value:s,sub:n,icon:a}){return e.jsxs("div",{className:"px-4 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[e.jsx("span",{className:"text-base flex items-center",children:a}),e.jsx("span",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold",children:t})]}),e.jsx("div",{className:"text-[22px] font-bold text-text-primary tracking-tight",children:s}),n&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:n})]})}function ns({value:t,max:s,label:n,color:a="#8b5cf6",detail:i,compact:o=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,d=c>85?"#ef4444":c>60?"#f59e0b":a;return o?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:n}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${c}%`,background:d}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${c}%`,background:`linear-gradient(90deg, ${d}, ${d}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function Dn({onAction:t,addLog:s,connState:n,connScreenshot:a,screenshotUsage:i,transportType:o}){const c=r.useRef(null),d=r.useRef(null),l=r.useRef(null),[h,x]=r.useState(null),[m,f]=r.useState(""),[,u]=r.useState(!1),[g,N]=r.useState([]),L=r.useRef(0),[v,w]=r.useState(!1),[P,B]=r.useState(!1),D=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[T,R]=r.useState(D?"mouse":"touch"),[$,_]=r.useState(1),re=r.useRef(!1),[b,z]=r.useState(1),[F,y]=r.useState(0),[Z,V]=r.useState(0),H=r.useRef(0),Y=r.useRef(t),q=r.useRef(null),ne=r.useRef(null),ee=r.useRef(!1),me=r.useRef(null),fe=r.useRef(0),Ie=r.useRef(null),O=r.useRef(1),C=r.useRef({x:0,y:0}),p=r.useRef(!1),A=r.useRef(b),E=r.useRef(F),xe=r.useRef(Z),de=r.useRef(T);r.useEffect(()=>{A.current=b},[b]),r.useEffect(()=>{E.current=F},[F]),r.useEffect(()=>{xe.current=Z},[Z]),r.useEffect(()=>{Y.current=t},[t]),r.useEffect(()=>{de.current=T},[T]),r.useEffect(()=>{var W;(W=c.current)==null||W.focus()},[]);const we=n==="connected",he=a,le=we?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ye=we?"The remote stream is warming up":"Waiting for the remote stream to catch up";r.useEffect(()=>{if(!D||re.current||!he)return;const W=l.current,ae=d.current;if(!W||!ae)return;const Q=()=>{const ve=ae.clientWidth,k=ae.clientHeight,K=W.naturalWidth,oe=W.naturalHeight;if(!K||!oe||!ve||!k)return;const X=Math.min(ve/K,k/oe),G=Math.max(ve/K,k/oe)/X;G>1.01&&(_(G),z(G),A.current=G),re.current=!0};W.complete&&W.naturalWidth?Q():W.addEventListener("load",Q,{once:!0})},[he,D]);const Ne=.5;r.useEffect(()=>{b<=Ne&&(y(0),V(0))},[b,Ne]);const Se=(W,ae,Q)=>{if(Q<=Ne)return{x:0,y:0};const ve=(Q-1)/(2*Q)*100,k=(Q-1)/(2*Q)*100;return{x:Math.max(-ve,Math.min(ve,W)),y:Math.max(-k,Math.min(k,ae))}},Ce=(W,ae)=>{if(!l.current)return null;const Q=l.current.getBoundingClientRect();return!Q.width||!Q.height?null:{nx:Math.max(0,Math.min(1,(W-Q.left)/Q.width)),ny:Math.max(0,Math.min(1,(ae-Q.top)/Q.height))}},_e=(W,ae,Q)=>{const ve=d.current;if(!ve)return;const k=ve.getBoundingClientRect(),K=++L.current;N(oe=>[...oe,{id:K,x:W-k.left,y:ae-k.top,type:Q}]),setTimeout(()=>N(oe=>oe.filter(X=>X.id!==K)),600)},Oe=(W,ae,Q)=>{const ve=l.current,k=d.current;if(!ve||!k)return;const K=ve.getBoundingClientRect(),oe=k.getBoundingClientRect(),X=ve.naturalWidth||K.width,ie=ve.naturalHeight||K.height,G=X/ie,J=K.width/K.height;let pe,se,ke,Ee;G>J?(pe=K.width,se=K.width/G,ke=0,Ee=(K.height-se)/2):(se=K.height,pe=K.height*G,ke=(K.width-pe)/2,Ee=0);const j=K.left-oe.left+ke+pe*W,S=K.top-oe.top+Ee+se*ae,M=++L.current;N(I=>[...I,{id:M,x:j,y:S,type:Q}]),setTimeout(()=>N(I=>I.filter(te=>te.id!==M)),600)},We=async W=>{var Q;const ae=Ce(W.clientX,W.clientY);if(ae){x(`Click: ${Math.round(ae.nx*100)}%, ${Math.round(ae.ny*100)}%`),_e(W.clientX,W.clientY,"left"),(Q=c.current)==null||Q.focus();try{const ve=await t("input_click",{nx:ae.nx,ny:ae.ny});ve!=null&&ve.success||s(`❌ Click failed: ${ve==null?void 0:ve.error}`)}catch(ve){s(`❌ Click error: ${ve.message||ve}`)}}},U=async(W,ae,Q,ve=0)=>{try{await t("input_key",{type:Q?"char":"keyDown",key:W,code:ae,text:Q?W:void 0,unmodifiedText:Q?W:void 0,modifiers:ve})}catch(k){s(`❌ Key error: ${k.message||k}`)}},ue=async W=>{if(W.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(W.key)&&W.preventDefault();let Q=0;W.altKey&&(Q|=1),W.ctrlKey&&(Q|=2),W.metaKey&&(Q|=4),W.shiftKey&&(Q|=8),x(`Key: ${W.key}`),await U(W.key,W.code,W.key.length===1,Q)},be=async W=>{if(W.key==="Enter"){if(W.nativeEvent.isComposing)return;if(m){const ae=m;f(""),x(`IME Sent: ${ae}`);try{const Q=await t("input_type",{text:ae});Q!=null&&Q.success||s(`❌ IME error: ${Q==null?void 0:Q.error}`)}catch(Q){s(`❌ IME error: ${Q.message}`)}}else x("Key: Enter"),await U("Enter","Enter",!1)}};r.useEffect(()=>{const W=c.current;if(!W)return;const ae=Q=>{var ve;if((ve=l.current)!=null&&ve.contains(Q.target)){Q.preventDefault();const k=Date.now();if(k-H.current<40)return;H.current=k;const K=Ce(Q.clientX,Q.clientY);if(!K)return;x(`Scroll: ${Math.round(Q.deltaY)}`),t("input_wheel",{nx:K.nx,ny:K.ny,deltaX:Math.round(Q.deltaX),deltaY:Math.round(Q.deltaY)}).catch(()=>{})}};return W.addEventListener("wheel",ae,{passive:!1}),()=>W.removeEventListener("wheel",ae)},[t]);const[ge,je]=r.useState(null),Re=r.useRef(null);return r.useEffect(()=>{if(T==="mouse"&&!Re.current){const W={nx:.5,ny:.5};Re.current=W,je(W)}},[T]),r.useEffect(()=>{const W=c.current;if(!W)return;const ae=X=>{if(!l.current)return null;const ie=l.current.getBoundingClientRect();return!ie.width||!ie.height?null:{nx:Math.max(0,Math.min(1,(X.clientX-ie.left)/ie.width)),ny:Math.max(0,Math.min(1,(X.clientY-ie.top)/ie.height))}},Q=(X,ie)=>{if(!l.current)return{dnx:0,dny:0};const G=l.current,J=G.getBoundingClientRect(),pe=G.naturalWidth||J.width,se=G.naturalHeight||J.height,ke=pe/se,Ee=J.width/J.height;let j,S;return ke>Ee?(j=J.width,S=J.width/ke):(S=J.height,j=J.height*ke),{dnx:X/j,dny:ie/S}},ve=(X,ie,G)=>{if(G<=1.05)return;const J=-(X-.5)*100,pe=-(ie-.5)*100,se=Se(J,pe,G);(Math.abs(se.x-E.current)>.1||Math.abs(se.y-xe.current)>.1)&&(y(se.x),V(se.y),E.current=se.x,xe.current=se.y)},k=X=>{const ie=d.current;if(ie&&X.target instanceof Node&&ie.contains(X.target))X.preventDefault();else return;if(X.touches.length===1){const G=X.touches[0];q.current={x:G.clientX,y:G.clientY,time:Date.now()},ne.current={x:G.clientX,y:G.clientY},p.current||(ee.current=!1),me.current=setTimeout(()=>{if(!ee.current&&!p.current)if(ee.current=!0,de.current==="mouse"){const J=Re.current||{nx:.5,ny:.5};x("Right Click"),Oe(J.nx,J.ny,"right"),Y.current("input_click",{...J,button:"right"}).catch(()=>{})}else{const J=ae(G);J&&(x("Right Click"),Oe(J.nx,J.ny,"right"),Y.current("input_click",{...J,button:"right"}).catch(()=>{}))}},500)}else if(X.touches.length===2){clearTimeout(me.current),ee.current=!0,p.current=!0;const G=X.touches[1].clientX-X.touches[0].clientX,J=X.touches[1].clientY-X.touches[0].clientY;Ie.current=Math.sqrt(G*G+J*J),O.current=A.current,C.current={x:(X.touches[0].clientX+X.touches[1].clientX)/2,y:(X.touches[0].clientY+X.touches[1].clientY)/2}}},K=X=>{const ie=d.current;if(ie&&X.target instanceof Node&&ie.contains(X.target)&&X.preventDefault(),X.touches.length===1&&ne.current){const G=X.touches[0],J=G.clientX-ne.current.x,pe=G.clientY-ne.current.y;if(!ee.current&&q.current){const se=G.clientX-q.current.x,ke=G.clientY-q.current.y;Math.sqrt(se*se+ke*ke)>8&&(ee.current=!0,clearTimeout(me.current))}if(ee.current)if(de.current==="mouse"){const se=Q(J,pe),ke=Re.current||{nx:.5,ny:.5},Ee=Math.max(0,Math.min(1,ke.nx+se.dnx)),j=Math.max(0,Math.min(1,ke.ny+se.dny));Re.current={nx:Ee,ny:j},je({nx:Ee,ny:j}),x(`Cursor: ${Math.round(Ee*100)}%, ${Math.round(j*100)}%`),ve(Ee,j,A.current);const S=Date.now();S-H.current>=30&&(H.current=S,Y.current("input_mouseMoved",{nx:Ee,ny:j}).catch(()=>{}))}else if(A.current>1){const se=d.current;if(se){const ke=se.clientWidth,Ee=se.clientHeight,j=E.current+J/ke*100,S=xe.current+pe/Ee*100,M=Se(j,S,A.current);y(M.x),V(M.y),E.current=M.x,xe.current=M.y}}else{const se=ae(G);if(se){const ke=Date.now();ke-H.current>=40&&(H.current=ke,x("Scroll"),Y.current("input_wheel",{nx:se.nx,ny:se.ny,deltaX:Math.round(-J*2.5),deltaY:Math.round(-pe*2.5)}).catch(()=>{}))}}ne.current={x:G.clientX,y:G.clientY}}else if(X.touches.length===2&&Ie.current!==null){const G=X.touches[1].clientX-X.touches[0].clientX,J=X.touches[1].clientY-X.touches[0].clientY,se=Math.sqrt(G*G+J*J)/Ie.current,ke=(X.touches[0].clientX+X.touches[1].clientX)/2,Ee=(X.touches[0].clientY+X.touches[1].clientY)/2,j=ke-C.current.x,S=Ee-C.current.y,M=Math.abs(se-1)>.03;if(de.current==="mouse"){if(M){const I=Math.max(Ne,Math.min(5,O.current*se));z(I),A.current=I}else if(Math.abs(j)>2||Math.abs(S)>2){const I=Re.current||{nx:.5,ny:.5},te=Date.now();te-H.current>=30&&(H.current=te,x("Scroll"),Y.current("input_wheel",{nx:I.nx,ny:I.ny,deltaX:Math.round(-j*3),deltaY:Math.round(-S*3)}).catch(()=>{}))}}else{const I=Math.max(Ne,Math.min(5,O.current*se));z(I),A.current=I;const te=d.current;if(te&&I>1){const ce=te.clientWidth,Te=te.clientHeight,Ae=E.current+j/ce*100,Pe=xe.current+S/Te*100,He=Se(Ae,Pe,I);y(He.x),V(He.y),E.current=He.x,xe.current=He.y}}C.current={x:ke,y:Ee}}},oe=X=>{var ie;if(clearTimeout(me.current),Ie.current=null,X.touches.length===1&&p.current){const G=X.touches[0];q.current={x:G.clientX,y:G.clientY,time:Date.now()},ne.current={x:G.clientX,y:G.clientY},ee.current=!0;return}if(X.touches.length===0){if(p.current){p.current=!1,ee.current=!1;return}if(X.changedTouches.length===1&&!ee.current){const G=X.changedTouches[0],J=Date.now(),pe=J-(((ie=q.current)==null?void 0:ie.time)||0);if(pe<60||pe>400){ee.current=!1;return}if(q.current){const se=G.clientX-q.current.x,ke=G.clientY-q.current.y;if(Math.sqrt(se*se+ke*ke)>12){ee.current=!1;return}}if(de.current==="mouse"){const se=Re.current||ae(G);se&&(x(`Click: ${Math.round(se.nx*100)}%, ${Math.round(se.ny*100)}%`),Oe(se.nx,se.ny,"left"),Y.current("input_click",{...se}).catch(()=>{}))}else{const se=ae(G);if(!se)return;J-fe.current<300?(x("Double tap"),Oe(se.nx,se.ny,"double"),Y.current("input_click",{...se,clickCount:2}).catch(()=>{}),fe.current=0):(x(`Tap: ${Math.round(se.nx*100)}%, ${Math.round(se.ny*100)}%`),Oe(se.nx,se.ny,"left"),Y.current("input_click",{...se}).catch(()=>{}),fe.current=J)}}ee.current=!1}};return W.addEventListener("touchstart",k,{passive:!1}),W.addEventListener("touchmove",K,{passive:!1}),W.addEventListener("touchend",oe,{passive:!1}),()=>{W.removeEventListener("touchstart",k),W.removeEventListener("touchmove",K),W.removeEventListener("touchend",oe),clearTimeout(me.current)}},[]),e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:ue,onContextMenu:W=>W.preventDefault(),onFocus:()=>u(!0),onBlur:()=>u(!1),tabIndex:0,children:[e.jsxs("div",{ref:d,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[he?e.jsx("img",{ref:l,src:he,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${b}) translate(${F}%, ${Z}%)`,transformOrigin:"center center",cursor:T==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:We,onContextMenu:W=>W.preventDefault(),onDragStart:W=>W.preventDefault()}):e.jsxs("div",{className:"text-center flex flex-col items-center gap-3 px-6",children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.35)]",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("div",{className:"text-white/85 text-[13px] font-semibold tracking-wide",children:le}),e.jsx("div",{className:"text-[11px] text-white/40",children:ye}),o==="relay"&&e.jsx("div",{className:"text-[10px] text-amber-300/80",children:"TURN relay active"})]}),T==="mouse"&&ge&&he&&l.current&&(()=>{var j;const W=l.current,ae=W.getBoundingClientRect(),Q=(j=d.current)==null?void 0:j.getBoundingClientRect();if(!Q)return null;const ve=W.naturalWidth||ae.width,k=W.naturalHeight||ae.height,K=ve/k,oe=ae.width/ae.height;let X,ie,G,J;K>oe?(X=ae.width,ie=ae.width/K,G=0,J=(ae.height-ie)/2):(ie=ae.height,X=ae.height*K,G=(ae.width-X)/2,J=0);const pe=ae.left-Q.left+G+X*ge.nx,se=ae.top-Q.top+J+ie*ge.ny,ke=Math.max(8,Math.min(Q.width-8,pe)),Ee=Math.max(8,Math.min(Q.height-8,se));return e.jsxs("div",{style:{position:"absolute",left:ke-8,top:Ee-8,width:16,height:16,pointerEvents:"none",zIndex:100},children:[e.jsx("div",{style:{position:"absolute",left:7,top:0,width:2,height:16,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:0,top:7,width:16,height:2,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:5,top:5,width:6,height:6,borderRadius:"50%",background:"#3b82f6",boxShadow:"0 0 8px rgba(59,130,246,0.6)"}})]})})(),g.map(W=>{const Q={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[W.type];return e.jsxs("div",{style:{position:"absolute",left:W.x,top:W.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${Q}, 0.8)`,animation:"click-ripple-ring 0.5s ease-out forwards",position:"absolute",left:-20,top:-20}}),e.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:`rgba(${Q}, 0.9)`,boxShadow:`0 0 12px rgba(${Q}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},W.id)})]}),e.jsxs("div",{onTouchStart:W=>W.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[e.jsxs("div",{onClick:()=>{R(W=>{const ae=W==="touch"?"mouse":"touch";if(ae==="mouse"&&!Re.current){const Q={nx:.5,ny:.5};Re.current=Q,je(Q)}return ae})},className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${T==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[e.jsx("span",{className:"text-sm",children:T==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${T==="mouse"?"text-blue-400":"text-slate-400"}`,children:T==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{B(!P),w(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${P?"bg-emerald-500/25 border border-emerald-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⌨️"})}),P&&e.jsx("div",{className:"absolute bottom-10 left-1/2 -translate-x-1/2 w-[220px] bg-neutral-950/[0.98] backdrop-blur-[30px] rounded-xl border border-white/20 p-[10px_12px] shadow-[0_10px_30px_rgba(0,0,0,0.8)] flex flex-col gap-2 z-20",style:{animation:"slideUp 0.15s ease-out"},children:e.jsx("input",{type:"text",placeholder:"Type & Enter...",value:m,autoFocus:!0,onTouchStart:W=>W.stopPropagation(),onChange:W=>f(W.target.value),onKeyDown:be,className:"w-full bg-black/60 border border-white/15 rounded-lg px-2.5 py-2 text-white text-[13px] outline-none"})})]}),e.jsx("div",{className:"relative",children:e.jsx("div",{onClick:()=>{w(!v),B(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${v?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:we?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:we?"#22c55e":"#eab308",boxShadow:we?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:we?"#22c55e":"#eab308"},children:we?"Connected":"WS"})]}),b>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(b*100),"%"]}),o==="direct"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:"Direct P2P connection",children:"Direct"}),o==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#f59e0b",background:"rgba(245,158,11,0.12)"},title:"TURN relay in use",children:"Relay"}),i&&i.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:i.budgetExhausted?"#ef4444":"#c4b5fd",background:i.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:i.budgetExhausted?"TURN blocked":`TURN ${i.dailyUsedMinutes}/${i.dailyBudgetMinutes}m`}),h&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:h})]})]}),v&&e.jsxs("div",{onTouchStart:W=>W.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",b<=(D?$:1)+.01?D?"FILL":"FIT":`${Math.round(b*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:W=>{W.stopPropagation(),z(ae=>Math.max(.5,ae-.25))},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:W=>{W.stopPropagation();const ae=D?$:1;z(ae),A.current=ae,y(0),V(0)},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:D?"FILL":"FIT"}),e.jsx("button",{onClick:W=>{W.stopPropagation(),z(ae=>Math.min(5,ae+.25))},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"+"})]})]})]}),e.jsx("style",{children:`
10
- @keyframes slideUp {
11
- from { opacity: 0; transform: translateY(6px); }
12
- to { opacity: 1; transform: translateY(0); }
13
- }
14
- @keyframes slideUpSidebar {
15
- from { opacity: 0; transform: translateY(6px); }
16
- to { opacity: 1; transform: translateY(0); }
17
- }
18
- @keyframes click-ripple-ring {
19
- 0% { transform: scale(0.3); opacity: 1; }
20
- 100% { transform: scale(2.2); opacity: 0; }
21
- }
22
- @keyframes click-ripple-dot {
23
- 0% { transform: scale(1); opacity: 0.9; }
24
- 50% { transform: scale(1.8); opacity: 0.6; }
25
- 100% { transform: scale(0.5); opacity: 0; }
26
- }
27
- @keyframes remote-float {
28
- 0% { transform: translateY(0px); }
29
- 50% { transform: translateY(-7px); }
30
- 100% { transform: translateY(0px); }
31
- }
32
- `})]})}function Bn({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:a=!1,connectionState:i,onDismiss:o,onClickAt:c,onKeyDown:d,badge:l,emptyMessage:h,aspectRatio:x,className:m,style:f}){const u=r.useRef(null),g=r.useCallback(N=>{if(!a||!c||!u.current)return;const L=u.current,v=L.getBoundingClientRect(),w=(N.clientX-v.left)/v.width*L.naturalWidth,P=(N.clientY-v.top)/v.height*L.naturalHeight;c(w,P,L.naturalWidth,L.naturalHeight)},[a,c]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${m||""}`,style:{aspectRatio:x||"16/9",...f},children:[e.jsx("img",{ref:u,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),o&&e.jsx("button",{onClick:o,className:"absolute top-2.5 right-2.5 bg-black/50 border-none text-white w-5 h-5 rounded-full text-[10px] z-10 cursor-pointer flex items-center justify-center",children:"✕"})]}):null:t?e.jsxs("div",{className:`${a?"screenshot-interactive":""} ${m||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:a?0:void 0,onKeyDown:a?d:void 0,style:f,children:[e.jsx("img",{ref:u,src:t,alt:"IDE Screenshot",onClick:a?g:void 0,className:"max-w-full max-h-full object-contain",style:{...a?{cursor:"crosshair"}:{},...n!==100?{transform:`scale(${n/100})`,transformOrigin:"center center"}:{}}}),l&&e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 bg-black/70 text-white px-3.5 py-1.5 rounded-[20px] text-xs font-semibold backdrop-blur-sm",children:l})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${m||""}`,style:f,children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.22)] mb-1",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("p",{className:"text-base",children:h||"Waiting for screenshot stream..."}),i&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",i]}),e.jsx("style",{children:`
33
- @keyframes remote-float {
34
- 0% { transform: translateY(0px); }
35
- 50% { transform: translateY(-7px); }
36
- 100% { transform: translateY(0px); }
37
- }
38
- `})]})}function Wn({activeConv:t,onModalButton:s}){const[n,a]=r.useState(null);if(r.useEffect(()=>{a(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const i=c=>{n||(a(c),s(c))},o=c=>c.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"bg-gradient-to-br from-amber-600 to-amber-700 text-white py-2.5 px-4 shrink-0 z-[5]",children:[t.modalMessage&&e.jsx("div",{className:"text-[11px] opacity-85 mb-1.5 whitespace-nowrap overflow-hidden text-ellipsis max-w-full",children:t.modalMessage.replace(/[\n\r]+/g," ").slice(0,120)}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"font-black text-xs flex items-center gap-2",children:[e.jsx(qt,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((c,d)=>{const l=o(c).toLowerCase(),h=/^(run|approve|accept|yes|allow|always)/.test(l),x=/^(reject|deny|delete|remove|abort)/.test(l),m=n===c,f=n!==null;return e.jsx("button",{onClick:()=>i(c),disabled:f,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${h?"bg-white text-amber-700 font-extrabold":x?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${f&&!m?"opacity-40":"opacity-100"} ${f?"cursor-not-allowed":"cursor-pointer"}`,children:m?"⏳ ...":o(c)},d)})})]})]})}const ze=new Map;function On({ideId:t,ideType:s,agentType:n,agentName:a,serverModel:i,serverMode:o,acpConfigOptions:c,acpModes:d}){var Ie;const{sendCommand:l}=st(),h=!!(c||d),x=`${t}:${n}`,m=ze.get(x),[f,u]=r.useState(!1),[g,N]=r.useState(!1),[L,v]=r.useState((m==null?void 0:m.models)||[]),[w,P]=r.useState((m==null?void 0:m.modes)||[]),B=O=>O?typeof O=="string"?O:typeof O=="object"?O.name||O.id||JSON.stringify(O):String(O):"",[D,T]=r.useState(B(i)),[R,$]=r.useState(B(o)),[_,re]=r.useState(!1),[b,z]=r.useState(!1),F=r.useRef(0),y=O=>O.map(C=>typeof C=="string"?C:(C==null?void 0:C.name)||(C==null?void 0:C.id)||String(C));r.useEffect(()=>{if(c){const O=c.find(C=>C.category==="model");if(O){const C=y(O.options.map(A=>A.value));v(C),O.currentValue&&T(B(O.currentValue));const p=ze.get(x)||{models:[],modes:[]};ze.set(x,{...p,models:C})}}if(d&&d.length>0){const O=y(d.map(p=>p.id));P(O);const C=ze.get(x)||{models:[],modes:[]};ze.set(x,{...C,modes:O})}else if(c){const O=c.find(C=>C.category!=="model");if(O){const C=y(O.options.map(A=>A.value));P(C),O.currentValue&&$(B(O.currentValue));const p=ze.get(x)||{models:[],modes:[]};ze.set(x,{...p,modes:C})}}},[c,d,x]),r.useEffect(()=>{u(!1),N(!1),T(B(i)),$(B(o));const O=ze.get(x);O?(v(O.models),P(O.modes)):(v([]),P([]))},[t,n]),r.useEffect(()=>{i&&Date.now()>F.current&&T(B(i))},[i]),r.useEffect(()=>{o&&Date.now()>F.current&&$(B(o))},[o]);const Z=r.useCallback(async(O,C={})=>{const p={...C},A=t.split(":");return A.length>=3&&(A[1]==="ide"||A[1]==="cli"||A[1]==="acp")&&(p._targetInstance=A.slice(2).join(":"),p._targetType=A[1]),await l(t,O,p)},[t]),V=async()=>{var O,C;if(L.length>0){u(!f);return}if(h){u(!0);return}re(!0);try{const p=await Z("list_extension_models",{agentType:n,ideType:s}),A=(p==null?void 0:p.models)||((O=p==null?void 0:p.result)==null?void 0:O.models)||[],E=y(A);v(E),p!=null&&p.current&&T(B(p.current)),(C=p==null?void 0:p.result)!=null&&C.current&&T(B(p.result.current));const xe=ze.get(x)||{models:[],modes:[]};ze.set(x,{...xe,models:E}),u(!0)}catch{}finally{re(!1)}},H=async()=>{var O,C;if(w.length>0){N(!g);return}if(h){N(!0);return}z(!0);try{const p=await Z("list_extension_modes",{agentType:n,ideType:s}),A=(p==null?void 0:p.modes)||((O=p==null?void 0:p.result)==null?void 0:O.modes)||[],E=y(A);P(E),p!=null&&p.current&&$(B(p.current)),(C=p==null?void 0:p.result)!=null&&C.current&&$(B(p.result.current));const xe=ze.get(x)||{models:[],modes:[]};ze.set(x,{...xe,modes:E}),N(!0)}catch{}finally{z(!1)}},Y=async O=>{u(!1),T(O),F.current=Date.now()+5e3;try{h?await Z("change_model",{agentType:n,ideType:s,model:O}):await Z("set_extension_model",{agentType:n,ideType:s,model:O})}catch{}},q=h&&!(d&&d.length>0)&&(c==null?void 0:c.some(O=>O.category!=="model")),ne=q?(Ie=c==null?void 0:c.find(O=>O.category!=="model"))==null?void 0:Ie.configId:void 0,ee=async O=>{N(!1),$(O),F.current=Date.now()+5e3;try{h&&q&&ne?await Z("set_thought_level",{agentType:n,ideType:s,configId:ne,value:O}):h?await Z("set_mode",{agentType:n,ideType:s,mode:O}):await Z("set_extension_mode",{agentType:n,ideType:s,mode:O})}catch{}},fe={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"}[n]||"#94a3b8";return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 flex-wrap text-[10px] border-t border-border-subtle bg-[var(--surface-primary)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide uppercase opacity-70",style:{color:fe},children:a}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:f?`${fe}55`:"transparent",border:"1px solid",color:D?"var(--text-primary)":"var(--text-muted)"},onClick:V,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),_?"...":D||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),f&&L.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>u(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:"SELECT MODEL"}),L.map(O=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:O===D?`${fe}18`:"transparent",color:O===D?fe:"var(--text-secondary)",fontWeight:O===D?600:400,borderLeft:O===D?`2px solid ${fe}`:"2px solid transparent"},onMouseEnter:C=>{C.currentTarget.style.background=`${fe}12`},onMouseLeave:C=>{C.currentTarget.style.background=O===D?`${fe}18`:"transparent"},onClick:()=>Y(O),children:O},O))]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:g?`${fe}55`:"transparent",border:"1px solid",color:R?"var(--text-primary)":"var(--text-muted)"},onClick:H,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:q?"🧠":"⚡"}),b?"...":R||(q?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),g&&w.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>N(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:q?"SELECT THINKING LEVEL":"SELECT MODE"}),w.map(O=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:O===R?`${fe}18`:"transparent",color:O===R?fe:"var(--text-secondary)",fontWeight:O===R?600:400,borderLeft:O===R?`2px solid ${fe}`:"2px solid transparent"},onMouseEnter:C=>{C.currentTarget.style.background=`${fe}12`},onMouseLeave:C=>{C.currentTarget.style.background=O===R?`${fe}18`:"transparent"},onClick:()=>ee(O),children:O},O))]})]})]})]})}const Fe=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),Be=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function Ds({activeConv:t,ides:s,agentInput:n,setAgentInput:a,handleSendChat:i,handleFocusAgent:o,isFocusingAgent:c,messageReceivedAt:d,actionLogs:l,userName:h}){const x=r.useRef(null),{sendCommand:m}=st(),f=r.useRef(new Map),u=r.useCallback(_=>(f.current.has(_)||f.current.set(_,{messages:[],offset:0,hasMore:!0,error:null}),f.current.get(_)),[]),g=r.useCallback((_,re)=>{const b=u(_);f.current.set(_,{...b,...re}),N(z=>z+1)},[u]),[,N]=r.useState(0),L=t.tabKey,v=u(L),w=v.messages,P=v.hasMore,B=v.error,[D,T]=r.useState(!1),R=r.useCallback(async()=>{var b,z;if(D)return;const _=t.tabKey,re=u(_);T(!0),g(_,{error:null});try{const F=s.find(ne=>ne.id===t.ideId),y=(F==null?void 0:F.daemonId)||((b=t.ideId)==null?void 0:b.split(":")[0])||"";if(!y){g(_,{hasMore:!1});return}const Z=t.ideType||t.agentType||"",V=(t.ideId||"").split(":"),H=V.length>=3?V.slice(2).join(":"):void 0,Y=await m(y,"chat_history",{agentType:Z,offset:re.offset,limit:30,instanceId:H}),q=(Y==null?void 0:Y.result)??Y;if(((z=q.messages)==null?void 0:z.length)>0){const ne=u(_);g(_,{messages:[...q.messages,...ne.messages],offset:ne.offset+q.messages.length,hasMore:!!q.hasMore})}else g(_,{hasMore:!!q.hasMore})}catch(F){const y=(F==null?void 0:F.message)||"";y.includes("P2P not available")||y.includes("channel not open")||y.includes("P2P not connected")||y.includes("timeout")?g(_,{error:"Connection not ready — tap to retry"}):g(_,{hasMore:!1,error:"Failed to load history"})}finally{T(!1)}},[D,s,t,m,u,g]),$=(()=>{const _=t.messages.map((z,F)=>{const y=`${t.ideId}-${z.id??`i-${F}`}`;return{...z,receivedAt:z.receivedAt||d[y]||0}});if(w.length===0)return _;const re=new Set(_.map(z=>`${z.role}:${(z.content||"").slice(0,100)}`));return[...w.filter(z=>!re.has(`${z.role}:${(z.content||"").slice(0,100)}`)),..._]})();return e.jsxs(e.Fragment,{children:[e.jsx(Ln,{messages:$,actionLogs:l.filter(_=>_.ideId===t.tabKey).sort((_,re)=>_.timestamp-re.timestamp),agentName:t.agentName||t.displayPrimary||"Agent",userName:h,isCliMode:Fe(t)||Be(t),isWorking:t.status==="generating",contextKey:t.tabKey,onLoadMore:R,isLoadingMore:D,hasMoreHistory:P,loadError:B??void 0,emptyState:t.messages.length===0?t.connectionState==="connecting"||t.connectionState==="new"?e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"connecting-logo-float",children:e.jsx("div",{style:{width:64,height:64,borderRadius:"50%",background:"radial-gradient(circle, rgba(96,165,250,0.12), transparent 70%)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 0 40px rgba(96,165,250,0.08)"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",style:{width:40,height:40,borderRadius:"50%",opacity:.85}})})}),e.jsxs("div",{className:"flex flex-col items-center gap-1.5",children:[e.jsxs("div",{className:"text-[13px] text-blue-400 font-medium",children:["Connecting to your machine",e.jsx("span",{className:"connecting-dots"})]}),e.jsx("div",{className:"text-[11px] opacity-35",children:"Establishing P2P connection"})]})]}):t.status==="not_monitored"?e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(dt,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:o,disabled:c,className:"btn btn-primary",children:c?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{size:14})," Open ",t.displayPrimary," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]}):t.status==="panel_hidden"?e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-3xl opacity-60",children:e.jsx(As,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:o,disabled:c,className:"btn btn-primary",children:c?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ot,{size:14})," Open ",t.displayPrimary," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Open the agent panel or chat view in the app you are using to start viewing messages"})]}):t.status==="idle"&&!D?e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-2xl opacity-40 animate-pulse",children:"💬"}),e.jsx("div",{className:"text-[13px] opacity-40",children:"Loading chat..."})]}):void 0:void 0}),!Fe(t)&&(()=>{var re,b,z,F;const _=s.find(y=>y.id===t.ideId);return e.jsx(On,{ideId:t.ideId,ideType:t.ideType,agentType:t.streamSource==="agent-stream"?t.agentType:((b=(re=_==null?void 0:_.agents)==null?void 0:re[0])==null?void 0:b.type)||t.ideType,agentName:t.streamSource==="agent-stream"?t.agentName:((F=(z=_==null?void 0:_.agents)==null?void 0:z[0])==null?void 0:F.name)||t.agentName,serverModel:(_==null?void 0:_.currentModel)||void 0,serverMode:(_==null?void 0:_.currentPlan)||void 0,acpConfigOptions:Be(t)?_==null?void 0:_.acpConfigOptions:void 0,acpModes:Be(t)?_==null?void 0:_.acpModes:void 0})})(),e.jsx("div",{className:"dashboard-input-area px-3 py-2.5 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:x,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:n,onChange:_=>a(_.target.value),onPaste:_=>{const re=_.clipboardData.getData("text");re&&a(b=>b+re),_.preventDefault()},onKeyDown:_=>{if(_.key==="Enter"){if(_.nativeEvent.isComposing){_.preventDefault();return}_.preventDefault(),i()}},onBlur:_=>{if(window.innerWidth<768){const re=_.relatedTarget;if((re==null?void 0:re.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:i,disabled:!n.trim(),className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${n.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:n.trim()?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:n.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}const Pt=new Set,Bs={emit(t,s){for(const n of Pt)n(t,s)},on(t){return Pt.add(t),()=>{Pt.delete(t)}}};function zn({activeConv:t,ptyBuffers:s,terminalRef:n,agentInput:a,setAgentInput:i,handleSendChat:o}){var f;const c=r.useRef(null),{sendCommand:d,sendData:l}=st(),h=(f=t.ideId)!=null&&f.includes(":cli:")?t.ideId.split(":cli:")[1]:"",x=t.tabKey,m=t.ideType||t.agentType||"";return r.useEffect(()=>{const u=s.current.get(x);if(u&&u.length>0){const g=setTimeout(()=>{var N;for(const L of u)(N=n.current)==null||N.write(L);requestAnimationFrame(()=>{var L;(L=n.current)==null||L.bumpResize()})},100);return()=>clearTimeout(g)}},[x]),r.useEffect(()=>{const u=Bs.on((g,N)=>{var v;if(!N)return;(g===h||g===m||g===t.ideId||g===t.tabKey)&&((v=n.current)==null||v.write(N))});return()=>{u()}},[h,m]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:e.jsx(Ls,{ref:n,onInput:u=>{var L;const g=t.ideId||t.daemonId||"",N=(L=t.ideId)!=null&&L.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";l!=null&&l(g,{type:"pty_input",cliType:N,data:u})||d(g,"pty_input",{cliType:N,data:u}).catch(console.error)},onResize:(u,g)=>{var v;const N=t.ideId||t.daemonId||"",L=(v=t.ideId)!=null&&v.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";l!=null&&l(N,{type:"pty_resize",cliType:L,cols:u,rows:g})||d(N,"pty_resize",{cliType:L,cols:u,rows:g,force:!0}).catch(()=>{})}},t.tabKey)}),e.jsx("div",{className:"px-3 py-2 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:c,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:a,onChange:u=>i(u.target.value),onPaste:u=>{const g=u.clipboardData.getData("text");g&&i(N=>N+g),u.preventDefault()},onKeyDown:u=>{if(u.key==="Enter"){if(u.nativeEvent.isComposing){u.preventDefault();return}u.preventDefault(),o()}},className:"w-full h-9 rounded-[18px] px-4 bg-bg-secondary text-[13px] text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:o,disabled:!a.trim(),className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${a.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:a.trim()?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:a.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function Fn({wsStatus:t,showReconnected:s,loginUrl:n}){const a=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"violet",o={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",violet:"linear-gradient(90deg, rgba(139,92,246,0.12), rgba(139,92,246,0.04))"},c={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",violet:"1px solid rgba(139,92,246,0.2)"},d={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[a&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:o[i],borderBottom:c[i],color:d[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(n?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:n,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — please restart the server.")]}),s&&t==="connected"&&e.jsxs("div",{className:"py-2 px-4 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-b border-green-500/15 animate-[fadeIn_0.3s_ease]",children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})]})}let Ws=bt;function $t(){return Ws()}class Kn{constructor(){$e(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,n){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(n),()=>{var a;(a=this.listeners.get(s))==null||a.delete(n)}}emit(s,...n){var a;(a=this.listeners.get(s))==null||a.forEach(i=>i(...n))}}let Os=new Kn;class Hn{constructor(){$e(this,"ptyCallbacks",new Set)}sendPtyInput(s,n,a){return!1}sendPtyResize(s,n,a,i){return!1}async requestChatHistory(s,n,a,i,o){return{messages:[],hasMore:!1}}retryConnection(s){}getState(s){return"disconnected"}sendData(s,n){return!1}get(s){}onScreenshot(s,n){return()=>{}}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,n){this.ptyCallbacks.forEach(a=>a(s,n))}}let Qe=new Hn,zt=Qe;function Un(t){t.dashboardWS&&(Os=t.dashboardWS),t.connectionManager&&(Qe=t.connectionManager,zt=t.connectionManager),t.p2pManager&&(zt=t.p2pManager),t.useDaemonsHook&&(Ws=t.useDaemonsHook)}function Yn({activeConv:t,agentCount:s,wsStatus:n,isConnected:a,onOpenHistory:i,onStopCli:o}){const c=jt(),d=$t(),l=d.p2pStates||{},h=d.ides||[],x=!!t&&Fe(t)&&!Be(t),m=a?"#22c55e":n==="connected"?"#eab308":"#ef4444",f=a?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",u=h.filter(P=>P.type==="adhdev-daemon"),g=Object.values(l),N=g.filter(P=>P==="connected").length,L=g.filter(P=>P==="connecting"||P==="new"||P==="checking").length,w=n!=="connected"||u.length===0?null:L>0&&N===0?"P2P connecting...":N>0&&s===0?"Waiting for IDE...":null;return e.jsxs("div",{className:"dashboard-header",children:[e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs("div",{className:"leading-tight",children:[e.jsxs("h1",{className:"header-title m-0 flex items-center gap-1.5",children:[e.jsx(lt,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:(t==null?void 0:t.displayPrimary)||"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:m,boxShadow:f}})})]}),e.jsxs("div",{className:"header-subtitle text-xs items-center gap-1",children:[s," agent",s!==1?"s":""," active",e.jsx("span",{title:a?"Connected":n==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:m,boxShadow:f}}),w&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",w]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[x&&o&&e.jsx("button",{onClick:o,className:"btn btn-secondary btn-sm text-red-400 border-red-500/25 hover:bg-red-500/10",title:"Stop CLI process",children:"Stop"}),t&&!x&&!Be(t)&&e.jsxs("button",{onClick:()=>c(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Gt,{size:14})," IDE"]}),t&&!x&&!Be(t)&&e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Ts,{size:16})}),t&&!x&&!Be(t)&&e.jsx("button",{onClick:()=>c(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(nt,{size:16})})]})]})}var Xn=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function Vn(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function Ke(t,s){if(Vn(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":Xn.has(n)?"generating":n==="error"?"error":n==="stopped"?"stopped":n==="starting"?"starting":n==="panel_hidden"?"panel_hidden":n==="not_monitored"?"not_monitored":n==="disconnected"?"disconnected":"idle"}function zs(t){return Ke(t)==="generating"}function Ue(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function qn(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const n=Math.floor(s/60),a=s%60;if(n<24)return a>0?`${n}h ${a}m`:`${n}h`;const i=Math.floor(n/24),o=n%24;return`${i}d ${o}h`}function rs(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Gn(t){if(t.length>16&&/^[a-f0-9]+$/i.test(t))return`Machine-${t.substring(0,8)}`;if(t.includes("_")){const s=t.split("_"),n=s[s.length-1];return n.length>12?`Machine-${n.substring(0,8)}`:n}return t}function Jn(t){return Gn(t.trim().replace(/\.local$/i,""))}function Zn(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Fs(t,s={}){var i,o;const n=[t.hostname,(i=t.machine)==null?void 0:i.hostname,(o=t.system)==null?void 0:o.hostname].find(c=>typeof c=="string"&&c.trim().length>0);if(n&&n!=="Unknown")return Jn(n);const a=s.fallbackId||t.id;return a?`Machine-${a.substring(0,8)}`:s.fallbackLabel||"Machine"}function ut(t,s={}){return Zn(t)||Fs(t,s)}function as(t){return(t.id||"").includes(":cli:")}function os(t){return(t.id||"").includes(":acp:")}function Ft(t,s){return Ue(t)}function Kt(t){return Ke(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function Qn(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,n=["generating","waiting_approval","connected","idle","panel_hidden"];for(const a of t){const i=(a.name||a.id||"").toLowerCase().replace(/\s+/g,"-"),o=s.get(i),c=Ke(a.status);if(!o){s.set(i,{...a,status:c});continue}const d=n.indexOf(o.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(d<0||l<d)&&s.set(i,{...a,status:c})}return Array.from(s.values())}function Ks({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:a,onClose:i,onNewChat:o,onSwitchSession:c,onRefreshHistory:d}){var m;const l=s.find(f=>f.id===t.ideId),h=(l==null?void 0:l.chats)||[],x=(m=l==null?void 0:l.activeChat)==null?void 0:m.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:i,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"card fade-in relative w-[90%] max-w-[500px] max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[20px]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"m-0 text-lg font-extrabold",children:"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Ue(t.ideType)]})]}),e.jsx("button",{onClick:i,className:"bg-transparent border-none text-xl text-text-muted cursor-pointer",children:"✕"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[e.jsx("button",{onClick:o,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),h.map(f=>e.jsxs("div",{onClick:()=>{c(t.ideId,f.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${x===f.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${x===f.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:f.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[f.id.substring(0,12),"..."]}),x===f.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},f.id)),h.length===0&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx(En,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:d,disabled:a,className:"btn btn-secondary btn-sm rounded-[10px]",children:a?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Es,{size:13})," Refresh History"]})})})]})]})}const is={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function Hs({toasts:t,onDismiss:s,onClickToast:n}){return e.jsx("div",{className:"fixed right-4 z-[9999] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:t.map(a=>e.jsxs("div",{className:"fade-in text-white px-5 py-3 rounded-xl text-[13px] font-semibold shadow-[0_8px_32px_rgba(0,0,0,0.3)] backdrop-blur-lg pointer-events-auto cursor-pointer animate-[toast-in_0.3s_ease-out] max-w-[360px] relative group",style:{background:is[a.type]||is.info},onClick:()=>{var i;(i=a.actions)!=null&&i.length||(n&&n(a),s(a.id))},children:[e.jsx("button",{className:"absolute top-1.5 right-1.5 w-5 h-5 rounded-full flex items-center justify-center text-white/50 hover:text-white hover:bg-white/20 transition-all text-[11px] leading-none opacity-0 group-hover:opacity-100 cursor-pointer",onClick:i=>{i.stopPropagation(),s(a.id)},"aria-label":"Dismiss",children:"×"}),e.jsx("div",{className:"pr-4",children:a.message}),a.actions&&a.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:a.actions.map((i,o)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-amber-700 hover:bg-gray-100":i.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:c=>{c.stopPropagation(),i.onClick(),s(a.id)},children:i.label},o))})]},a.id))})}const er=t=>(t.id||"").includes(":cli:")||(t.id||"").includes(":acp:")||(t.id||"").includes(":ide:")?!0:t.daemonId!==t.id;function tr(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function sr(t,s,n,a){const i={};if(n)for(const o of n){const c=o;(c.type==="adhdev-daemon"||c.daemonMode)&&(i[c.id]=ut(c,{fallbackId:c.id}))}return t.flatMap(o=>{var v,w,P,B,D,T;const c=[],d=o.daemonId&&i[o.daemonId]||void 0,l=o.daemonId||((v=o.id)==null?void 0:v.split(":")[0])||o.id,h=a?a[l]||"new":void 0,x=tr(o),m=Ue(o.type),f=o.agentStreams,u=Array.isArray(f)?f.map(R=>({...R,activeModal:R.activeModal??void 0})):[],g=er(o),N=o.activeChat||{title:""},L=N.title&&String(N.title).trim()?String(N.title).trim():"";if(g){const R=Ft(o.type),$=(w=o.agents)==null?void 0:w[0],_=(P=o.activeChat)==null?void 0:P.activeModal,re=_&&Array.isArray(_.buttons)&&_.buttons.length>0,b=Ke((B=o.activeChat)==null?void 0:B.status,{activeModal:(D=o.activeChat)==null?void 0:D.activeModal})||Ke($==null?void 0:$.status)||"idle",z=o.activeChat||{title:"",messages:[]};let F=z.title&&String(z.title).trim()?String(z.title).trim():"";const y=(T=o.activeChat)==null?void 0:T.id,Z=o.chats;if(y&&Array.isArray(Z)&&Z.length>0){const ne=Z.find(ee=>ee.id===y||ee.id&&String(ee.id)===String(y));ne!=null&&ne.title&&String(ne.title).trim()&&(F=String(ne.title).trim())}const V=z.messages||[],H=s[o.id]||[],Y=new Map;V.filter(ne=>ne.role==="user").forEach(ne=>{Y.set(ne.content,(Y.get(ne.content)||0)+1)});const q=H.filter(ne=>{const ee=Y.get(ne.content)||0;return ee>0?(Y.set(ne.content,ee-1),!1):!0});c.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:Fe(o)?o.mode||"terminal":"chat",agentName:R,agentType:Fe(o)||Be(o)?o.cliType||o.acpType||o.type:($==null?void 0:$.type)||"ide-native",status:b,title:F,messages:[...V,...q],ideType:o.cliType||o.acpType||o.type,workspaceName:x,displayPrimary:F||x||(Fe(o)||Be(o)?"Terminal":R),displaySecondary:m,cdpConnected:o.cdpConnected,modalButtons:re?_.buttons:void 0,modalMessage:re?_.message:void 0,streamSource:"native",tabKey:o.id,machineName:d,connectionState:h})}if(g&&(Fe(o)||Be(o)))return c;for(const R of u){const $=R.activeModal&&Array.isArray(R.activeModal.buttons)&&R.activeModal.buttons.length>0,_=Kt(R),re=`${o.id}:${R.agentType}`,b=R.messages||[],z=s[re]||[],F=new Map;b.filter(Z=>Z.role==="user").forEach(Z=>{F.set(Z.content,(F.get(Z.content)||0)+1)});const y=z.filter(Z=>{const V=F.get(Z.content)||0;return V>0?(F.set(Z.content,V-1),!1):!0});c.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:"chat",agentName:R.agentName,agentType:R.agentType,status:_,title:"",messages:[...b,...y],ideType:R.agentType,workspaceName:x,displayPrimary:L||x||R.agentName,displaySecondary:`${m}·${R.agentName}`,cdpConnected:o.cdpConnected,modalButtons:$?R.activeModal.buttons:void 0,modalMessage:$?R.activeModal.message:void 0,streamSource:"agent-stream",tabKey:re,machineName:d,connectionState:h})}return c.length===0&&c.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:"chat",agentName:Ft(o.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:o.type,workspaceName:x,displayPrimary:x||m,displaySecondary:m,cdpConnected:o.cdpConnected,streamSource:"native",tabKey:o.id,connectionState:h}),c})}function nr(t,s){var d,l,h,x,m,f;const n=[],{daemonId:a,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now();n.push({...i||{},id:a,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:c,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},..."system"in t&&{system:t.system},..."hostname"in t&&{hostname:t.hostname},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.workspaceActivity&&{workspaceActivity:t.workspaceActivity},...t.detectedIdes&&{detectedIdes:t.detectedIdes},..."availableProviders"in t&&{availableProviders:t.availableProviders},cdpConnected:t.managedIdes.some(u=>u.cdpConnected),managedIdeIds:t.managedIdes.map(u=>`${a}:ide:${u.instanceId}`),managedCliIds:t.managedClis.map(u=>u.id?`${a}:cli:${u.id}`:`${a}:cli:${u.cliType}`),managedAcpIds:t.managedAcps.map(u=>u.id?`${a}:acp:${u.id}`:`${a}:acp:${u.acpType}`)});for(const u of t.managedIdes)n.push({id:`${a}:ide:${u.instanceId}`,type:u.ideType,ideType:u.ideType,version:u.ideVersion,status:u.cdpConnected?"online":"detected",daemonId:a,instanceId:u.instanceId,workspace:u.workspace,terminals:u.terminals,agents:u.aiAgents,activeChat:u.activeChat,chats:u.chats,agentStreams:u.agentStreams,cdpConnected:u.cdpConnected,currentModel:u.currentModel,currentPlan:u.currentPlan,currentAutoApprove:u.currentAutoApprove,timestamp:c});for(const u of t.managedClis){const g=u.id?`${a}:cli:${u.id}`:`${a}:cli:${u.cliType}`;n.push({id:g,type:u.cliType,ideType:u.cliType,agentType:u.cliType,status:u.status||"running",daemonId:a,instanceId:u.id,cliName:u.cliName,mode:u.mode||"terminal",workspace:u.workspace,activeChat:u.activeChat,agentStreams:[{agentType:u.cliType,agentName:u.cliName,extensionId:"cli-agent",status:Ke(u.status,{activeModal:(d=u.activeChat)==null?void 0:d.activeModal}),messages:((l=u.activeChat)==null?void 0:l.messages)||[],inputContent:"",activeModal:(h=u.activeChat)==null?void 0:h.activeModal}],timestamp:c,_isCli:!0})}for(const u of t.managedAcps){const g=u.id?`${a}:acp:${u.id}`:`${a}:acp:${u.acpType}`;n.push({id:g,type:u.acpType,ideType:u.acpType,agentType:u.acpType,status:u.status||"running",daemonId:a,instanceId:u.id,cliName:u.acpName,mode:"chat",workspace:u.workspace,activeChat:u.activeChat,currentModel:u.currentModel,currentPlan:u.currentPlan,acpConfigOptions:u.acpConfigOptions,acpModes:u.acpModes,agentStreams:[{agentType:u.acpType,agentName:u.acpName,extensionId:"acp-agent",status:Ke(u.status,{activeModal:(x=u.activeChat)==null?void 0:x.activeModal}),messages:((m=u.activeChat)==null?void 0:m.messages)||[],inputContent:"",activeModal:(f=u.activeChat)==null?void 0:f.activeModal}],timestamp:c,_isAcp:!0})}return n}const Us=[{id:"vscode",name:"VS Code",icon:"💙"},{id:"cursor",name:"Cursor",icon:"⚡"},{id:"windsurf",name:"Windsurf",icon:"🏄"},{id:"antigravity",name:"Antigravity",icon:"🌀"},{id:"trae",name:"Trae",icon:"🔮"},{id:"kiro",name:"Kiro",icon:"🎯"},{id:"pearai",name:"PearAI",icon:"🍐"},{id:"vscodium",name:"VSCodium",icon:"💚"}],Ys=[{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"codex-cli",name:"Codex CLI",icon:"📦"}],Xs=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Vs="adhdev_notification_prefs",cs={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function rr(){try{const t=localStorage.getItem(Vs);if(t){const s=JSON.parse(t);return{...cs,...s}}}catch{}return{...cs}}function ar(t){try{localStorage.setItem(Vs,JSON.stringify(t))}catch{}}let Ve=rr(),St=[];function or(){St.forEach(t=>t())}function ir(){return{...Ve}}function cr(t){Ve={...Ve,...t},ar(Ve),or()}function lr(){const[,t]=r.useState(0);r.useEffect(()=>{const n=()=>t(a=>a+1);return St.push(n),()=>{St=St.filter(a=>a!==n)}},[]);const s=r.useCallback(n=>{cr(n)},[]);return[{...Ve},s]}function ht(t){if(!Ve.globalEnabled)return!1;switch(t){case"disconnect":return Ve.disconnectAlert;case"completion":return Ve.completionAlert;case"approval":return Ve.approvalAlert;case"browser":return Ve.browserNotifications;default:return!0}}const dr={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function ur(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function qs(){return"Notification"in window&&Notification.permission==="granted"}let rt=null;async function xr(){if(rt!==null)return rt;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return rt=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(rt=!!await t.pushManager.getSubscription(),rt):(rt=!1,!1)}catch{return rt=!1,!1}}function Ht(t,s,n){if(qs())try{const a=new Notification(t,{body:s,icon:"/otter-logo.png",tag:n||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>a.close(),8e3),a.onclick=()=>{window.focus(),a.close()}}catch{}}function pr(t,s={}){const n={...dr,...s},a=r.useRef(new Map),i=r.useRef(0),o=r.useRef(null);r.useEffect(()=>{xr().then(d=>{o.current=d})},[]);const c=r.useCallback((d,l,h)=>{const x=Date.now();x-i.current<n.throttleMs||(i.current=x,Ht(d,l,h))},[n.throttleMs]);r.useEffect(()=>{var d;if(!(!n.enabled||!qs())&&ht("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)a.current.set(l.id,Ke(l.status,{activeModal:l.activeModal}));return}for(const l of t){const h=a.current.get(l.id),x=Ke(l.status,{activeModal:l.activeModal}),m=l.name||l.id;if(n.onApproval&&ht("approval")&&x==="waiting_approval"&&h!=="waiting_approval"){const f=((d=l.activeModal)==null?void 0:d.message)||"Action requires your approval";c(`🔔 ${m} — Approval needed`,f.slice(0,120),`approval-${l.id}`)}n.onComplete&&ht("completion")&&zs(h)&&x==="idle"&&c(`✅ ${m} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&x==="error"&&h!=="error"&&c(`⚠️ ${m} — Error`,"Agent encountered an error",`error-${l.id}`),a.current.set(l.id,x)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class mr{constructor(){$e(this,"dedupMap",new Map);$e(this,"DEDUP_WINDOW_MS",5e3);$e(this,"DEDUP_MAX_SIZE",50);$e(this,"DEDUP_CLEANUP_AGE_MS",1e4);$e(this,"toastCallbacks",[]);$e(this,"systemMessageCallbacks",[]);$e(this,"clearSystemMessageCallbacks",[]);$e(this,"resolveActionFn",null);$e(this,"viewRequestRespondFn",null);$e(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(n=>n!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(n=>n!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(n=>n!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const n of this.toastCallbacks)n(s)}showToast(s,n="info",a){const i=(a==null?void 0:a.id)||Date.now();this.emitToast({id:i,message:s,type:n,timestamp:i,duration:5e3,...a})}emitSystemMessage(s,n){for(const a of this.systemMessageCallbacks)a(s,n)}emitClearSystemMessage(s,n){for(const a of this.clearSystemMessageCallbacks)a(s,n)}isDuplicate(s){const n=Date.now(),a=this.dedupMap.get(s)||0;if(n-a<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,n),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,o]of this.dedupMap)n-o>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(i);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const i=this.ides.find(o=>o.id===s.ideId&&o.type==="adhdev-daemon");if(i)return i}let n;if(s.ideId&&(n=this.ides.find(i=>i.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),n){const i=n.daemonId;if(i){const o=this.ides.find(c=>c.id===i&&c.type==="adhdev-daemon");if(o)return o}}const a=this.ides.filter(i=>i.type==="adhdev-daemon");return a.length===1?a[0]:null}resolveRouteId(s,n){for(const a of this.ides)if(a.id.startsWith(s)&&(!n||n===a.type))return a.id;return s}resolveConversationKey(s){if(!s.ideId)return null;if(s.providerCategory==="extension"){const n=s.agentType||s.providerType;if(n)return`${s.ideId}:${n}`}return s.ideId}handleRawEvent(s,n){var h,x;const a=`${s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(a))return;if(!s.ideId&&s.instanceId){for(const m of this.ides)if(m.id.endsWith(`:ide:${s.instanceId}`)||m.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=m.id;break}}const i=this.resolveConversationKey(s);let o=Ue(s.ideType||"");const c=this.resolveOwningDaemon(s);if(c){const m=ut(c,{fallbackId:c.id});m&&(o=s.ideType==="adhdev-daemon"?m:`${m}/${o}`)}let d="",l="info";if(s.event==="agent:generating_completed"){const m=s.duration?` (${s.duration}s)`:"";d=`✅ ${o} agent task completed${m}`,l="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}i&&ir().chatTaskCompletionBubble&&this.emitSystemMessage(i,{role:"system",timestamp:Date.now(),content:`✅ Task completed${m}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")i&&this.emitClearSystemMessage(i,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(d=`⚡ ${o} approval needed`,l="warning",i){const m=s.modalMessage||"Approval requested",f=(h=s.modalButtons)!=null&&h.length?s.modalButtons.map(u=>`[${u}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(i,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${m}
39
- ${f}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((x=s.modalButtons)!=null&&x.length)&&this.resolveActionFn){const m=s.ideId,f=s.agentType||s.ideType||"",u=s.ideType||"",g=s.modalButtons,N=B=>B.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),L=this.resolveActionFn,v=g.map((B,D)=>{const T=N(B).toLowerCase(),R=/^(run|approve|accept|yes|allow|always)/.test(T),$=/^(reject|deny|delete|remove|abort|cancel|no)/.test(T);return{label:N(B),variant:R?"primary":$?"danger":"default",onClick:()=>{const _=this.resolveRouteId(m,f),re=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(T);L(_,"resolve_action",{action:re?"approve":"reject",button:B,buttonIndex:D,agentType:f,ideType:u})}}}),w=s.modalMessage?`⚡ ${o}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:d,P=Date.now();this.emitToast({id:P,message:w,type:l,timestamp:P,ideId:i||m,actions:v,duration:15e3}),d=""}}else if(s.event==="monitor:long_generating"){const m=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";d=`⚠️ ${o} agent is taking a long time${m}`,l="warning",ht("browser")&&!document.hasFocus()&&Ht(`⚠️ ${o} — Long Running`,`Agent has been generating for over ${m.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const m=s.requesterName||"A team member",f=s.requestId,u=s.orgId;if(d=`👁️ ${m} wants to view your session`,l="warning",f&&u&&this.viewRequestRespondFn){const g=this.viewRequestRespondFn,N=Date.now(),L=[{label:"Approve",variant:"primary",onClick:()=>{g(u,f,"approve").catch(v=>console.error("[EventManager] approve view request failed:",v))}},{label:"Decline",variant:"danger",onClick:()=>{g(u,f,"reject").catch(v=>console.error("[EventManager] reject view request failed:",v))}}];this.emitToast({id:N,message:d,type:l,timestamp:N,actions:L,duration:3e4}),d=""}ht("browser")&&!document.hasFocus()&&Ht("👁️ View Request",`${m} wants to view your session`,`view-request-${f}`)}else s.event==="team:view_request_approved"?(d="✅ View request approved",l="success"):s.event==="team:view_request_rejected"&&(d=`❌ ${s.targetName||"Team member"} declined your view request`,l="warning");if(d){const m=Date.now();this.emitToast({id:m,message:d,type:l,timestamp:m,ideId:i||s.ideId,duration:5e3})}}}const et=new mr;function ct(...t){return an(on(t))}function hr({icon:t,title:s,subtitle:n,badge:a,actions:i,className:o}){return e.jsxs("div",{className:ct("dashboard-header",o),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,a&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[a.count!==void 0?a.count:""," ",a.text]})]}),n&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:n})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function Et({icon:t,title:s,subtitle:n,badge:a,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:d}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(hr,{icon:t,title:s,subtitle:n,badge:a,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ct("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function De({title:t,icon:s,description:n,accentColor:a,className:i,children:o}){return e.jsxs("div",{className:ct("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",a&&"border-l-[3px]",i),style:a?{borderLeftColor:a}:void 0,children:[(t||n)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),n&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:n})]}),o]})}function Jt({icon:t,title:s,description:n,action:a,className:i}){return e.jsxs("div",{className:ct("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:n}),a]})}const fr={error:"bg-red-500/10 border-red-500/30 text-red-400",warning:"bg-yellow-500/10 border-yellow-500/30 text-yellow-400",success:"bg-green-500/10 border-green-500/30 text-green-400",info:"bg-indigo-500/10 border-indigo-500/30 text-indigo-400"},gr={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function br({variant:t,children:s,onDismiss:n,className:a}){return e.jsxs("div",{className:ct("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",fr[t],a),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:gr[t]}),e.jsx("span",{children:s})]}),n&&e.jsx("button",{onClick:n,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const yr={online:"bg-green-500/10 text-green-400 border-green-500/30",idle:"bg-yellow-500/10 text-yellow-400 border-yellow-500/30",busy:"bg-orange-500/10 text-orange-400 border-orange-500/30",error:"bg-red-500/10 text-red-400 border-red-500/30",offline:"bg-gray-500/10 text-text-secondary border-gray-500/30"},jr={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function vr({status:t,label:s,className:n}){const a=s||t;return e.jsxs("span",{className:ct("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",yr[t],n),children:[e.jsx("span",{className:ct("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",jr[t])}),a]})}function wr(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function ls(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function Lt(t){return t==="system"?wr():t}function Nr(){const[t,s]=r.useState(ls),[n,a]=r.useState(()=>Lt(ls()));r.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),r.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),d=l=>{t==="system"&&a(l.matches?"light":"dark")};return c.addEventListener("change",d),()=>c.removeEventListener("change",d)},[t]);const i=r.useCallback(c=>{s(c),a(Lt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=r.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";a(Lt(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function ot({label:t,description:s,checked:n,disabled:a,onChange:i,extra:o}){return e.jsxs("label",{className:"flex justify-between items-center cursor-pointer",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted",children:s})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o,e.jsx("input",{type:"checkbox",checked:n,disabled:a,onChange:c=>i(c.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function kr({onPrefChange:t}){const[s,n]=lr(),a=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ps,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>a("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(nt,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>a("browserNotifications",i)}),s.globalEnabled&&s.browserNotifications&&e.jsxs("div",{className:"ml-5 pl-3 border-l-2 border-border-subtle flex flex-col gap-2",children:[e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(An,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>a("completionAlert",i)}),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($n,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>a("approvalAlert",i)}),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(dt,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>a("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(lt,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>a("chatTaskCompletionBubble",i)}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function Sr({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:a,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(Jt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:s||"Run 'adhdev-standalone' to connect a local daemon instance."}):e.jsx("div",{className:"flex flex-col gap-2",children:o.map(c=>e.jsx(Ir,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:a,onRevokeToken:i},c.id))})}function ds({title:t,message:s,confirmLabel:n,confirmColor:a,onConfirm:i,onCancel:o}){const c=a==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"bg-amber-500/20 text-amber-400 border-amber-500/30 hover:bg-amber-500/30";return cn.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:o,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,children:n})]})]})}),document.body)}function Cr(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),a=[...Us,...Ys,...Xs].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return a?{icon:a.icon,name:a.name}:{icon:"📝",name:t}}function Ir({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:a,onRevokeToken:i}){var y,Z;const[o,c]=r.useState("idle"),[d,l]=r.useState(""),[h,x]=r.useState(null),[m,f]=r.useState("idle"),[u,g]=r.useState(""),N=t,L=N.version||N.daemonVersion||null,v=((y=N.machine)==null?void 0:y.platform)||((Z=N.system)==null?void 0:Z.platform)||"",w=ut(N,{fallbackId:t.id}),P=v==="win32"?"🪟":v==="darwin"?"🍎":"🐧",B=s.filter(V=>V.daemonId===t.id&&V.id.includes(":ide:")),D=s.filter(V=>V.daemonId===t.id&&V.id.includes(":cli:")),T=s.filter(V=>V.daemonId===t.id&&V.id.includes(":acp:")),R=N.p2p,$=async()=>{var V,H,Y;if(n){c("upgrading"),l("Installing latest version...");try{const q=await n(t.id,"daemon_upgrade",{});(V=q==null?void 0:q.result)!=null&&V.upgraded||(H=q==null?void 0:q.result)!=null&&H.success?(c("done"),l(`Upgraded to v${q.result.version||"latest"}. Daemon is restarting...`)):(c("error"),l(((Y=q==null?void 0:q.result)==null?void 0:Y.error)||"Upgrade failed"))}catch(q){c("error"),l((q==null?void 0:q.message)||"Connection lost during upgrade")}}},_=async()=>{if(x(null),!!a){f("loading");try{await a(t.id),f("done"),g("Machine disconnected.")}catch(V){f("error"),g((V==null?void 0:V.message)||"Failed to disconnect")}}},re=async()=>{if(x(null),!!i){f("loading");try{await i(t.id),f("done"),g('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(V){f("error"),g((V==null?void 0:V.message)||"Failed to revoke token")}}},b="0.6.79",z=!L||L!==b,F=B.length+D.length+T.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:P}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:w}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),L&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${z?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",L,!z&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&z&&e.jsx("button",{onClick:$,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${b}`,children:o==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`↑ Update${` to v${b}`}`}),a&&e.jsx("button",{onClick:()=>x("disconnect"),disabled:m==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>x("revoke"),disabled:m==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(vr,{status:t.status==="online"?"online":"error"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-2.5 pt-2.5 border-t border-border-subtle/50",children:[R&&e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${R.state==="connected"?"bg-green-400":R.state==="connecting"||R.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",R.state==="connected"?"connected":R.state==="connecting"||R.state==="new"?"connecting...":R.state||"off"]}),R.peers!==void 0&&R.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",R.peers," peer",R.peers!==1?"s":"",")"]})]}),R&&F>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),F>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[B.map(V=>{const H=Cr(V.type),Y=V.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:H.icon}),e.jsx("span",{children:H.name}),Y!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Y?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:Y?"CDP connected":"CDP connecting..."})]},V.id)}),D.map(V=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"⌨️"}),e.jsx("span",{children:V.cliName||"CLI"})]},V.id)),T.map(V=>e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:"🔗"}),e.jsx("span",{children:V.cliName||"ACP"})]},V.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(d||u)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||m==="error"?"text-red-400":o==="done"||m==="done"?"text-green-400":"text-text-muted"}`,children:u||d})]}),h==="disconnect"&&e.jsx(ds,{title:"🔌 Disconnect Machine",message:`Disconnect "${w}" from ADHDev?
40
-
41
- This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
42
-
43
- Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:_,onCancel:()=>x(null)}),h==="revoke"&&e.jsx(ds,{title:"⚠️ Remove Machine",message:`Remove "${w}" from your dashboard?
44
-
45
- This will:
46
- • Immediately disconnect the machine
47
- • Delete the machine registration
48
- • Require restarting "adhdev-standalone" on that machine
49
-
50
- Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:re,onCancel:()=>x(null)})]})}const Mr=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Tr(){const{preference:t,setPreference:s}=Nr();return e.jsx("div",{className:"flex gap-2",children:Mr.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===n.id?"bg-accent border-accent text-white":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,children:[e.jsx("span",{children:n.icon}),n.label]},n.id))})}const Ut={bgPrimary:"#0f0f13",bgSecondary:"#18181d",surfacePrimary:"#111116",textPrimary:"#fafafa",textSecondary:"#a8a8b3",textMuted:"#7e7e8a",borderSubtle:"#1a1a22",borderDefault:"#2a2a35",accentColor:"#8b5cf6",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#1e1e24",assistantText:"#e0e0e0",containerBg:"#111114",sendButton:"#6366f1",inputBorder:"#2a2a35",bubbleRadius:16},Yt={bgPrimary:"#f0f1f5",bgSecondary:"#e8eaf0",surfacePrimary:"#ffffff",textPrimary:"#1a1a2e",textSecondary:"#3f3f50",textMuted:"#5c5c6e",borderSubtle:"#d8d8e0",borderDefault:"#c0c0cc",accentColor:"#7c3aed",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#f3f4f6",assistantText:"#1f2937",containerBg:"#f0f1f5",sendButton:"#6366f1",inputBorder:"#d1d5db",bubbleRadius:16},Er=[{id:"midnight",name:"Midnight",description:"Default violet theme",preview:{dark:{userBubble:"linear-gradient(135deg, #8b5cf6, #4f46e5)",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #7c3aed, #0ea5e9)",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"aurora",name:"Aurora",description:"Pink-orange gradient",preview:{dark:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"linear-gradient(135deg, #ec4899, #f97316)",assistantBubble:"#fef2f8",assistantBorder:"1px solid rgba(236,72,153,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}},{id:"honey",name:"Honey",description:"Warm yellow accents",preview:{dark:{userBubble:"#fbbf24",assistantBubble:"#1c1c1e",assistantBorder:"1px solid rgba(255,255,255,0.06)",containerBg:"#111113",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#fbbf24",assistantBubble:"#fffbeb",assistantBorder:"1px solid rgba(251,191,36,0.15)",containerBg:"#f0f1f5",textColor:"#1a1a2e"}}}],Gs="adhdev-chat-theme",Js="adhdev-chat-theme-custom";function Ct(){return typeof window>"u"?"midnight":localStorage.getItem(Gs)||"midnight"}function Ye(t){try{const s=localStorage.getItem(Js);if(s){const n=JSON.parse(s);return{...t==="dark"?Ut:Yt,...n[t]}}}catch{}return t==="dark"?Ut:Yt}function wt(t,s){localStorage.setItem(Js,JSON.stringify({dark:t,light:s}))}function Ge(t,s){const n=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${a}, ${i}, ${s})`}function us(t,s){const n=Math.min(255,parseInt(t.slice(1,3),16)+s),a=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}function it(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ge(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ge(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ge(t.borderSubtle,.25)),s.style.setProperty("--text-primary",t.textPrimary),s.style.setProperty("--text-secondary",t.textSecondary),s.style.setProperty("--text-muted",t.textMuted),s.style.setProperty("--border-subtle",Ge(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ge(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",us(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${us(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ge(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ge(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ge(t.accentColor,.06)}`),s.style.setProperty("--chat-user-bg",t.userBubble),s.style.setProperty("--chat-user-color",t.userText),s.style.setProperty("--chat-user-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px 4px ${t.bubbleRadius}px`),s.style.setProperty("--chat-assistant-bg",t.assistantBubble),s.style.setProperty("--chat-assistant-color",t.assistantText),s.style.setProperty("--chat-assistant-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px ${t.bubbleRadius}px 4px`),s.style.setProperty("--chat-assistant-border",`1px solid ${Ge(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--chat-thought-accent",t.accentColor),s.style.setProperty("--chat-tool-accent",t.accentColor),s.style.setProperty("--chat-action-color",t.accentColor),s.style.setProperty("--chat-send-bg",t.sendButton),s.style.setProperty("--chat-input-border",t.inputBorder)}function Ar(){const t=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(n=>t.style.removeProperty(n))}function $r(t){if(localStorage.setItem(Gs,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ft()?"dark":"light";it(Ye(s))}else Ar()}function _r(){const t=Ct();if(t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ft()?"dark":"light";it(Ye(s))}}function ft(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Le({label:t,value:s,onChange:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"color",value:s,onChange:a=>n(a.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:s,onChange:a=>{/^#[0-9a-fA-F]{0,6}$/.test(a.target.value)&&n(a.target.value)},style:{width:72,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}})]})]})}function pt({title:t,children:s}){return e.jsxs("div",{style:{marginBottom:14},children:[e.jsx("div",{style:{fontSize:"0.65rem",fontWeight:700,textTransform:"uppercase",color:"var(--text-muted)",letterSpacing:"0.08em",marginBottom:8,borderBottom:"1px solid var(--border-subtle)",paddingBottom:4},children:t}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s})]})}function Rr({dark:t,onColorsChange:s}){const n=t?"dark":"light",[a,i]=r.useState(()=>Ye(n));r.useEffect(()=>{i(Ye(n))},[n]);const o=r.useCallback((c,d)=>{i(l=>{const h={...l,[c]:d},m=Ye(n==="dark"?"light":"dark");return n==="dark"?wt(h,m):wt(m,h),it(h),s(h),h})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(pt,{title:"App Background",children:[e.jsx(Le,{label:"Background",value:a.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Le,{label:"Surface",value:a.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Le,{label:"Card",value:a.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(pt,{title:"App Text",children:[e.jsx(Le,{label:"Primary",value:a.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Le,{label:"Secondary",value:a.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Le,{label:"Muted",value:a.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(pt,{title:"Borders & Accent",children:[e.jsx(Le,{label:"Border subtle",value:a.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Le,{label:"Border default",value:a.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Le,{label:"Accent",value:a.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(pt,{title:"Chat Bubbles",children:[e.jsx(Le,{label:"User bubble",value:a.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Le,{label:"User text",value:a.userText,onChange:c=>o("userText",c)}),e.jsx(Le,{label:"Agent bubble",value:a.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Le,{label:"Agent text",value:a.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(pt,{title:"Chat Layout",children:[e.jsx(Le,{label:"Chat BG",value:a.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Le,{label:"Send button",value:a.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Le,{label:"Input border",value:a.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:a.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[a.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Ut:Yt,l=Ye(t?"light":"dark");t?wt(c,l):wt(l,c),i(c),it(c),s(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function Pr(){const[t,s]=r.useState(Ct),[n,a]=r.useState(!0),[i,o]=r.useState(()=>Ye("dark"));r.useEffect(()=>{a(ft());const l=new MutationObserver(()=>{const m=ft();a(m),Ct()==="custom"&&it(Ye(m?"dark":"light"))});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const h=window.matchMedia("(prefers-color-scheme: dark)"),x=()=>{const m=ft();a(m),Ct()==="custom"&&it(Ye(m?"dark":"light"))};return h.addEventListener("change",x),()=>{l.disconnect(),h.removeEventListener("change",x)}},[]),r.useEffect(()=>{t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"&&it(Ye(n?"dark":"light"))},[]),r.useEffect(()=>{o(Ye(n?"dark":"light"))},[n]);const c=l=>{s(l),$r(l),l==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},d=[...Er,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:d.map(l=>{const h=t===l.id,x=n?l.preview.dark:l.preview.light,m=l.id==="honey"?"#1a1a1a":l.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:h?"var(--bg-glass-hover)":"var(--bg-glass)",border:h?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:h?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:x.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:x.assistantBubble,border:x.assistantBorder,color:x.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:x.userBubble,color:m},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:x.assistantBubble,border:x.assistantBorder,color:x.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[h&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(Rr,{dark:n,onColorsChange:l=>o(l)})]})}const Xt="adhdev-accent-color",Lr=[{name:"Violet",color:"#8b5cf6"},{name:"Indigo",color:"#6366f1"},{name:"Blue",color:"#3b82f6"},{name:"Cyan",color:"#06b6d4"},{name:"Emerald",color:"#10b981"},{name:"Rose",color:"#f43f5e"},{name:"Orange",color:"#f97316"},{name:"Amber",color:"#f59e0b"}],yt="#8b5cf6";function Dr(t){const s=parseInt(t.slice(1,3),16)/255,n=parseInt(t.slice(3,5),16)/255,a=parseInt(t.slice(5,7),16)/255,i=Math.max(s,n,a),o=Math.min(s,n,a);let c=0,d=0;const l=(i+o)/2;if(i!==o){const h=i-o;switch(d=l>.5?h/(2-i-o):h/(i+o),i){case s:c=((n-a)/h+(n<a?6:0))/6;break;case n:c=((a-s)/h+2)/6;break;case a:c=((s-n)/h+4)/6;break}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(l*100)}}function xs(t,s){const{h:n,s:a,l:i}=Dr(t),o=Math.min(100,i+s);return`hsl(${n}, ${a}%, ${o}%)`}function It(t,s){const n=parseInt(t.slice(1,3),16),a=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${a}, ${i}, ${s})`}function ps(){return typeof window>"u"?yt:localStorage.getItem(Xt)||yt}function Br(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",xs(t,15)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${xs(t,20)})`),s.style.setProperty("--border-accent",It(t,.4)),s.style.setProperty("--nav-active-bg",It(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${It(t,.06)}`)}function Wr(){const t=document.documentElement;["--accent-primary","--accent-primary-light","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow"].forEach(n=>t.style.removeProperty(n))}function Or(t){t===yt?(localStorage.removeItem(Xt),Wr()):(localStorage.setItem(Xt,t),Br(t))}function zr(){const[t,s]=r.useState(ps),[n,a]=r.useState("");r.useEffect(()=>{s(ps())},[]);const i=o=>{s(o),Or(o)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:Lr.map(o=>{const c=t===o.color;return e.jsx("button",{onClick:()=>i(o.color),title:o.name,style:{width:36,height:36,borderRadius:10,background:o.color,border:c?"3px solid var(--text-primary)":"3px solid transparent",cursor:"pointer",position:"relative",transition:"transform 0.15s, border-color 0.15s",transform:c?"scale(1.1)":"scale(1)",boxShadow:c?`0 0 12px ${It(o.color,.4)}`:"none"},children:c&&e.jsx("span",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:14,fontWeight:700,textShadow:"0 1px 2px rgba(0,0,0,0.5)"},children:"✓"})},o.color)})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Custom:"}),e.jsx("input",{type:"color",value:t,onChange:o=>i(o.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:n||t,onChange:o=>{a(o.target.value),/^#[0-9a-fA-F]{6}$/.test(o.target.value)&&i(o.target.value)},onBlur:()=>a(""),style:{width:80,fontSize:"0.7rem",fontFamily:"monospace",background:"var(--bg-primary)",border:"1px solid var(--border-subtle)",borderRadius:4,padding:"3px 6px",color:"var(--text-primary)"}}),t!==yt&&e.jsx("button",{onClick:()=>i(yt),style:{fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:5,padding:"3px 8px",cursor:"pointer"},children:"Reset"})]})]})}const Zs="adhdev_hiddenTabs";function Fr(){try{const t=localStorage.getItem(Zs);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function mt(t){try{localStorage.setItem(Zs,JSON.stringify([...t]))}catch{}}function Kr(){const[t,s]=r.useState(Fr),n=r.useCallback(l=>{s(h=>{const x=new Set(h);return x.has(l)?x.delete(l):x.add(l),mt(x),x})},[]),a=r.useCallback(l=>{s(h=>{if(h.has(l))return h;const x=new Set(h);return x.add(l),mt(x),x})},[]),i=r.useCallback(l=>{s(h=>{if(!h.has(l))return h;const x=new Set(h);return x.delete(l),mt(x),x})},[]),o=r.useCallback((l,h)=>{s(x=>{const m=new Set(x);for(const f of h)m.add(f);return mt(m),m})},[]),c=r.useCallback((l,h)=>{s(x=>{const m=new Set(x);for(const f of h)m.delete(f);return mt(m),m})},[]),d=r.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:a,showTab:i,hideAllForDaemon:o,showAllForDaemon:c,isHidden:d}}function Qs({sendDaemonCommand:t,activeConv:s,ides:n,updateIdeChats:a,setToasts:i,setLocalUserMessages:o,setClearedTabs:c,setActionLogs:d,pinTab:l,isStandalone:h}){const[x,m]=r.useState(""),[f,u]=r.useState(!1),[g,N]=r.useState(!1),[L,v]=r.useState(!1),w=r.useCallback(b=>b?Fe(b)||Be(b)?{agentType:b.agentType||b.ideType}:b.streamSource==="agent-stream"?{agentType:b.agentType}:{}:{},[]),P=r.useCallback(async()=>{if(!s)return;const b=x.trim();if(!b)return;const z=s.ideId,F=s.tabKey;m(""),l(F,[100,500,1500,3e3]);const y=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,Z={role:"user",content:b,timestamp:Date.now(),_localId:y};o(V=>({...V,[F]:[...V[F]||[],Z]}));try{const V=z||s.daemonId||"";if(!V)return;await t(V,"send_chat",{message:b,text:b,...w(s)}),setTimeout(()=>{const H=Date.now()-6e4;o(Y=>{const q=Y[F];if(!q)return Y;const ne=q.filter(ee=>ee.timestamp>H);return ne.length===q.length?Y:{...Y,[F]:ne}})},6e4)}catch(V){console.error("Send failed",V),m(b),o(H=>({...H,[F]:(H[F]||[]).filter(Y=>Y._localId!==y)}))}},[s,x,t,o,l,w]),B=r.useCallback(async()=>{if(s)try{h?await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0}):await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(b){console.error("Relaunch failed",b)}},[s,h,t]),D=r.useCallback(async b=>{try{await t("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(z){console.error("Launch failed",z)}},[t]),T=r.useCallback(async b=>{if(s){console.log("[ModalButton] ideId:",s.ideId,"button:",b),d(z=>[...z,{ideId:s.tabKey,text:`🖱️ **${b}** clicked`,timestamp:Date.now()}]);try{const F=(s.modalButtons||[]).indexOf(b),y=b.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),Z=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(y),V=s.ideId||s.daemonId||"";(await t(V,"resolve_action",{button:b,action:Z?"approve":"reject",...F>=0&&{buttonIndex:F},...w(s)})).success||d(Y=>[...Y,{ideId:s.tabKey,text:`⚠️ **${b}** failed — button not found`,timestamp:Date.now()}])}catch(z){console.error("[ModalButton] Error:",z),d(F=>[...F,{ideId:s.tabKey,text:`❌ **${b}** error`,timestamp:Date.now()}])}}},[s,t,d,w]),R=r.useCallback(async(b,z)=>{try{const F=b||(s==null?void 0:s.daemonId)||"",y=await t(F,"switch_chat",{id:z,sessionId:z,...w(s)}),Z=y==null?void 0:y.result;(y==null?void 0:y.success)===!0||Z==="switched"||Z==="switched-by-title"||(Z===!1||Z==="not_found"?i(H=>[...H,{id:Date.now(),message:"⚠️ Session tab not found — try refreshing history",type:"warning",timestamp:Date.now()}]):typeof Z=="string"&&Z.startsWith("error:")?i(H=>[...H,{id:Date.now(),message:`⚠️ Switch error: ${Z}`,type:"warning",timestamp:Date.now()}]):i(H=>[...H,{id:Date.now(),message:"⚠️ Session switch failed",type:"warning",timestamp:Date.now()}]))}catch(F){console.error("Switch failed",F),i(y=>[...y,{id:Date.now(),message:`❌ Switch failed: ${F.message||"connection error"}`,type:"warning",timestamp:Date.now()}])}},[s,t,i,w]),$=r.useCallback(async()=>{if(!(!s||f)){u(!0);try{const b=s.ideId||s.daemonId||"";await t(b,"new_chat",{...w(s)}),c(z=>({...z,[s.tabKey]:Date.now()})),o(z=>({...z,[s.tabKey]:[]}))}catch(b){console.error("New chat failed",b)}finally{u(!1)}}},[s,f,t,c,o,w]),_=r.useCallback(async()=>{if(!s||L)return;v(!0);const b=s.tabKey;try{await t(s.ideId,"agent_stream_focus",{agentType:s.agentType}),l(b,[200,1500,3e3])}catch(z){console.error("Focus agent failed",z)}finally{v(!1)}},[s,L,t,l]),re=r.useCallback(async()=>{var b;if(!(!s||g)){N(!0);try{const z=s.ideId||s.daemonId||"",F=await t(z,"list_chats",{forceExpand:!0,...w(s)}),y=(F==null?void 0:F.chats)||((b=F==null?void 0:F.result)==null?void 0:b.chats);F!=null&&F.success&&Array.isArray(y)&&a(s.ideId,y)}catch(z){console.error("Refresh history failed",z)}finally{N(!1)}}},[s,g,t,a,w]);return{agentInput:x,setAgentInput:m,isCreatingChat:f,isRefreshingHistory:g,isFocusingAgent:L,handleSendChat:P,handleRelaunch:B,handleLaunchIde:D,handleModalButton:T,handleSwitchSession:R,handleNewChat:$,handleFocusAgent:_,handleRefreshHistory:re}}const Dt={unix:{cmd:"curl -fsSL https://adhf.dev/install | sh",shell:"Terminal",prompt:"$ "},powershell:{cmd:"irm https://adhf.dev/install.ps1 | iex",shell:"PowerShell",prompt:"PS> "},cmd:{cmd:"curl -fsSL https://adhf.dev/install.cmd -o %TEMP%\\adhdev.cmd && %TEMP%\\adhdev.cmd",shell:"CMD",prompt:"> "}};function Hr(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function Ur(){const[t,s]=r.useState("unix"),[n,a]=r.useState("powershell"),[i,o]=r.useState(!1),c=t==="unix"?"unix":n;r.useEffect(()=>{s(Hr())},[]);const d=r.useCallback(()=>{navigator.clipboard.writeText(Dt[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>a("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>a("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:d,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Dt[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Dt[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-text-muted opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function Yr({conversations:t,ides:s,messageReceivedAt:n,actionLogs:a,ptyBuffers:i,screenshotMap:o,setScreenshotMap:c,sendDaemonCommand:d,updateIdeChats:l,setToasts:h,setLocalUserMessages:x,setClearedTabs:m,setActionLogs:f,pinTab:u,isStandalone:g,userName:N,groupIndex:L,isFocused:v,onFocus:w,isSplitMode:P,numGroups:B,onMoveTab:D,onClose:T,onReceiveTab:R,style:$,detectedIdes:_,handleLaunchIde:re,onActiveTabChange:b,initialActiveTabId:z,initialTabOrder:F,onTabOrderChange:y,onHideTab:Z}){const{sendCommand:V}=st(),H=r.useRef(null),[Y,q]=r.useState(!1),[ne,ee]=r.useState(null),me=r.useRef(0),fe=r.useRef(null),[Ie,O]=r.useState(z??null);r.useEffect(()=>{z&&z!==Ie&&O(z)},[z]);const[C,p]=r.useState(F??[]),[A,E]=r.useState(null),xe=r.useRef(null),de=r.useRef(null);r.useEffect(()=>{const k=new Set(t.map(K=>K.tabKey));p(K=>{const oe=K.filter(G=>k.has(G)),X=t.filter(G=>!K.includes(G.tabKey)).map(G=>G.tabKey),ie=[...oe,...X];return ie.length===K.length&&ie.every((G,J)=>G===K[J])?K:ie})},[t]);const we=A??C,he=r.useMemo(()=>{if(we.length===0)return t;const k=new Map(we.map((K,oe)=>[K,oe]));return[...t].sort((K,oe)=>{const X=k.get(K.tabKey)??999,ie=k.get(oe.tabKey)??999;return X-ie})},[t,we]);r.useEffect(()=>{if(he.length===0){O(null),b==null||b(null);return}Ie&&he.some(k=>k.tabKey===Ie)||(O(he[0].tabKey),b==null||b(he[0].tabKey))},[he,Ie]);const le=he.find(k=>k.tabKey===Ie),ye=r.useCallback((k,K,oe)=>{p(X=>{const ie=X.filter(pe=>pe!==k),G=ie.indexOf(K);if(G<0)return X;const J=oe==="left"?G:G+1;return ie.splice(J,0,k),y==null||y(ie),ie}),E(null)},[y]),Ne=r.useCallback((k,K,oe)=>{const ie=(C.length>0?C:t.map(pe=>pe.tabKey)).filter(pe=>pe!==k),G=ie.indexOf(K);if(G<0)return;const J=oe==="left"?G:G+1;ie.splice(J,0,k),xe.current=ie,E(ie)},[C,t]),Se=Qs({sendDaemonCommand:d,activeConv:le,ides:s,updateIdeChats:l,setToasts:h,setLocalUserMessages:x,setClearedTabs:m,setActionLogs:f,pinTab:u,isStandalone:g}),[Ce,_e]=r.useState(null);r.useEffect(()=>{if(!Ce)return;const k=K=>{const oe=document.querySelector("[data-pane-context-menu]");oe&&oe.contains(K.target)||_e(null)};return window.addEventListener("mousedown",k,!0),()=>window.removeEventListener("mousedown",k,!0)},[Ce]);const Oe="adhdev-tab-shortcuts",We=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[U,ue]=r.useState(()=>{try{return JSON.parse(localStorage.getItem(Oe)||"{}")}catch{return{}}}),[be,ge]=r.useState(null),je=r.useCallback(k=>{const K=[];k.metaKey&&K.push(We?"⌘":"Meta"),k.ctrlKey&&K.push("Ctrl"),k.altKey&&K.push(We?"⌥":"Alt"),k.shiftKey&&K.push(We?"⇧":"Shift");const oe=k.key;if(["Control","Alt","Shift","Meta"].includes(oe))return null;const X=oe.length===1?oe.toUpperCase():oe;return K.push(X),K.join("+")},[We]),Re=r.useCallback((k,K)=>je(k)===K,[je]),W=r.useCallback(k=>{ue(k),localStorage.setItem(Oe,JSON.stringify(k))},[]);r.useEffect(()=>{if(!be)return;const k=K=>{if(K.preventDefault(),K.stopPropagation(),K.key==="Escape"){ge(null);return}const oe=je(K);if(!oe)return;const X={...U};for(const[ie,G]of Object.entries(X))G===oe&&delete X[ie];X[be]=oe,W(X),ge(null)};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[be,U,W,je]),r.useEffect(()=>{const k=K=>{if(!(!K.ctrlKey&&!K.metaKey&&!K.altKey)){for(const[oe,X]of Object.entries(U))if(Re(K,X)&&he.some(ie=>ie.tabKey===oe)){K.preventDefault(),w(),O(oe),b==null||b(oe);return}}};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[U,he,w,b,Re]);const ae=le&&Fe(le)&&!Be(le),Q=ae?"terminal":"chat";r.useEffect(()=>{const k=()=>{me.current=0,q(!1),ee(null)};return window.addEventListener("dragend",k),window.addEventListener("drop",k),()=>{window.removeEventListener("dragend",k),window.removeEventListener("drop",k)}},[]);const ve=r.useRef(null);return r.useEffect(()=>{const k=ve.current;if(!k)return;const K=oe=>{Math.abs(oe.deltaY)>Math.abs(oe.deltaX)&&(oe.preventDefault(),k.scrollLeft+=oe.deltaY)};return k.addEventListener("wheel",K,{passive:!1}),()=>k.removeEventListener("wheel",K)},[]),e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:w,style:{...$,outline:Y?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx("div",{className:"flex items-center bg-bg-secondary border-b border-border-subtle shrink-0 gap-0",children:e.jsxs("div",{ref:ve,className:"flex-1 flex overflow-x-auto overflow-y-visible pt-1.5 pb-0 gap-1 select-none",style:{paddingLeft:8,paddingRight:4,scrollbarWidth:"none"},children:[he.map((k,K)=>{const oe=Ie===k.tabKey,X=k.status==="generating"?"agent-tab-generating":k.status==="waiting_approval"?"agent-tab-waiting":"",ie=k.connectionState==="failed"||k.connectionState==="closed",G=de.current===k.tabKey;return e.jsxs("div",{"data-tabkey":k.tabKey,className:`${X} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:J=>{de.current=k.tabKey,J.dataTransfer.setData("text/tab-key",k.tabKey),J.dataTransfer.effectAllowed="move"},onDragEnd:()=>{de.current=null;const J=xe.current;J&&(p(J),y==null||y(J)),xe.current=null,E(null),me.current=0,q(!1)},onDragOver:J=>{const pe=de.current;if(!(!pe||pe===k.tabKey)&&J.dataTransfer.types.includes("text/tab-key")){J.preventDefault(),J.stopPropagation();const se=J.currentTarget.getBoundingClientRect(),ke=se.left+se.width/2,Ee=J.clientX<ke?"left":"right";Ne(pe,k.tabKey,Ee)}},onDrop:J=>{J.preventDefault(),J.stopPropagation();const pe=J.dataTransfer.getData("text/tab-key");if(pe&&pe!==k.tabKey){const se=J.currentTarget.getBoundingClientRect(),ke=se.left+se.width/2,Ee=J.clientX<ke?"left":"right";he.some(j=>j.tabKey===pe)?ye(pe,k.tabKey,Ee):R&&R(pe)}E(null)},onClick:J=>{J.stopPropagation(),w(),O(k.tabKey),b==null||b(k.tabKey),k.streamSource==="agent-stream"&&k.agentType&&V(k.ideId,"agent_stream_focus",{agentType:k.agentType}).catch(()=>{}),Fe(k)&&setTimeout(()=>{var pe,se;return(se=(pe=H.current)==null?void 0:pe.bumpResize)==null?void 0:se.call(pe)},100)},onContextMenu:J=>{J.preventDefault(),_e({x:J.clientX,y:J.clientY,tabKey:k.tabKey})},onTouchStart:J=>{const pe=J.touches[0],se=pe.clientX,ke=pe.clientY;fe.current=setTimeout(()=>{_e({x:se,y:ke,tabKey:k.tabKey})},600)},onTouchEnd:()=>{fe.current&&clearTimeout(fe.current)},onTouchMove:()=>{fe.current&&clearTimeout(fe.current)},style:{background:oe?"var(--bg-primary)":"var(--bg-glass)",borderTop:oe?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:oe?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:oe?"1px solid var(--border-subtle)":"1px solid transparent",opacity:G?.4:ie?oe?.6:.3:oe?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[k.status==="generating"?e.jsx("div",{className:"tab-spinner"}):k.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):ie?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):k.connectionState==="connecting"||k.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):k.connectionState==="connected"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-green-400",children:"●"}):e.jsx("span",{className:"text-[8px] px-[5px] py-px text-text-muted animate-pulse",children:"○"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-bold whitespace-nowrap overflow-hidden text-ellipsis",style:{maxWidth:"10ch"},title:k.displayPrimary,children:k.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:ie?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):k.connectionState==="connecting"||k.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[k.displaySecondary,k.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",k.machineName]})]})]})})]}),U[k.tabKey]&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${U[k.tabKey]}`,children:U[k.tabKey]})]},k.tabKey)}),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:k=>{k.dataTransfer.types.includes("text/tab-key")&&(me.current++,q(!0))},onDragOver:k=>{if(!k.dataTransfer.types.includes("text/tab-key"))return;k.preventDefault();const K=k.currentTarget.getBoundingClientRect(),oe=k.clientX-K.left;if(B<4&&D&&window.innerWidth>=768){const X=K.width/3;oe<X?ee("split-left"):oe>X*2?ee("split-right"):ee("merge");return}ee("merge")},onDragLeave:()=>{me.current--,me.current<=0&&(me.current=0,q(!1),ee(null))},onDrop:k=>{me.current=0,q(!1);const K=k.dataTransfer.getData("text/tab-key"),oe=K?t.some(ie=>ie.tabKey===K):!1,X=ne;if(ee(null),E(null),!!K){if(k.preventDefault(),X==="split-left"&&D&&B<4&&window.innerWidth>=768){D(K,"split-left");return}if(X==="split-right"&&D&&B<4&&window.innerWidth>=768){D(K,"split-right");return}oe?p(ie=>{const G=ie.filter(J=>J!==K);return G.push(K),y==null||y(G),G}):R&&R(K)}},children:[Y&&e.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:ne==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:ne==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:B<4&&D?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:ne==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:ne==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),e.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:ne==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:ne==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:B<4&&D?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]}),le?e.jsxs(e.Fragment,{children:[e.jsx(Wn,{activeConv:le,onModalButton:Se.handleModalButton}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!ae&&!Be(le)&&o[le.ideId]?e.jsx(Bn,{screenshotUrl:o[le.ideId],mode:"preview",onDismiss:()=>{const k={...o};delete k[le.ideId],c(k)}}):!ae&&!Be(le)&&le.cdpConnected===!1?e.jsxs("div",{className:"flex items-center gap-2.5 px-3.5 py-2 bg-yellow-500/[0.08] border border-yellow-500/20 rounded-lg text-xs text-text-secondary",children:[e.jsx("span",{className:"text-sm",children:e.jsx(qt,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:Se.handleRelaunch,children:"Relaunch with CDP"})]}):null}),Q==="terminal"?e.jsx(zn,{activeConv:le,ptyBuffers:i,terminalRef:H,agentInput:Se.agentInput,setAgentInput:Se.setAgentInput,handleSendChat:Se.handleSendChat}):e.jsx(Ds,{activeConv:le,ides:s,agentInput:Se.agentInput,setAgentInput:Se.setAgentInput,handleSendChat:Se.handleSendChat,handleFocusAgent:Se.handleFocusAgent,isFocusingAgent:Se.isFocusingAgent,messageReceivedAt:n,actionLogs:a,userName:N})]}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:t.length===0&&!P&&_&&re?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:"Waiting for your IDE"}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:g?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!g&&e.jsx(Ur,{}),g&&_&&_.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Fast Launch"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:_.map(k=>e.jsxs("button",{className:"btn btn-sm bg-accent/10 border border-accent/25 text-accent text-xs font-medium px-4 py-2.5 rounded-lg cursor-pointer flex items-center gap-2 transition-all hover:bg-accent/20 hover:scale-105 active:scale-95",onClick:()=>re&&re(k.type),children:[e.jsx(_s,{size:14,className:"opacity-70"})," Launch ",k.name]},k.type))})]}),!g&&e.jsx("div",{className:"mt-8",children:e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):e.jsx("div",{className:"text-sm text-text-muted opacity-50",children:P?"Move a tab here to view":"No active agent"})})]}),Ce&&e.jsxs("div",{"data-pane-context-menu":!0,className:"fixed z-50 bg-bg-primary border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",style:{left:Ce.x,top:Ce.y},children:[D&&L>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{D(Ce.tabKey,"left"),_e(null)},children:"← Move to Left Group"}),D&&L<B-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{D(Ce.tabKey,"right"),_e(null)},children:"Move to Right Group →"}),D&&B<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{D(Ce.tabKey,"split-left"),_e(null)},children:"⇤ Split Left"}),D&&B<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{D(Ce.tabKey,"split-right"),_e(null)},children:"Split Right ⇥"}),e.jsx("div",{className:"border-t border-border-subtle my-1 "}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:k=>{k.stopPropagation(),ge(Ce.tabKey),_e(null)},children:["⌨ ",U[Ce.tabKey]?`Change shortcut (${U[Ce.tabKey]})`:"Set shortcut"]}),U[Ce.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onClick:()=>{const k={...U};delete k[Ce.tabKey],W(k),_e(null)},children:"✕ Remove shortcut"}),Z&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"border-t border-border-subtle my-1"}),e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted",onClick:()=>{Z(Ce.tabKey),_e(null)},children:"🚫 Hide from Dashboard"})]}),!D&&!Z&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),be&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>ge(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:k=>k.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",We?"⌘+1":"Ctrl+1",", ",We?"⌥+A":"Alt+A",")"]}),e.jsx("div",{className:"text-lg font-mono text-accent animate-pulse",children:"Listening..."}),e.jsx("div",{className:"text-[10px] text-text-muted mt-3",children:"Press Esc to cancel"})]})})]})}const Bt=[{icon:"🦦",title:"Welcome to ADHDev",desc:"Monitor and control your AI coding agents from anywhere — web, mobile, or CLI.",visual:"🎉"},{icon:"💬",title:"Real-time chat",desc:"See what your AI agent is doing in real-time. Send messages, approve or reject actions — all from your browser or phone.",visual:"📱"},{icon:"🖥️",title:"Remote desktop",desc:"View and control your IDE screen via P2P connection. Click, type, scroll — just like being there.",visual:"🖱️"},{icon:"🚀",title:"Get started",desc:"Install the daemon and link it to your dashboard. It connects automatically.",code:"npm install -g @adhdev/daemon-standalone && adhdev-standalone"}];function Xr({onClose:t}){const[s,n]=r.useState(0),a=Bt[s],i=s===Bt.length-1;return e.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:o=>{o.target===o.currentTarget&&t()},children:[e.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[e.jsx("button",{onClick:t,style:{position:"absolute",top:12,right:16,background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"1.2rem",cursor:"pointer"},children:"✕"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:Bt.map((o,c)=>e.jsx("div",{style:{width:c===s?24:8,height:8,borderRadius:4,background:c===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},c))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:a.visual||a.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:a.icon})," ",a.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:a.desc}),a.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),a.code]}),i&&e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",style:{fontSize:"0.75rem",color:"var(--accent, #a78bfa)",textDecoration:"none"},children:"📚 Learn more in the docs →"})]}),e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginTop:"1.5rem"},children:[e.jsx("button",{onClick:t,style:{background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"0.85rem",cursor:"pointer"},children:"Skip"}),e.jsx("button",{onClick:()=>i?t():n(o=>o+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
51
- @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
52
- @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
53
- `})]})}function Vr(t,s){if(t.size!==s.size)return!1;for(const[n,a]of t)if(s.get(n)!==a)return!1;return!0}function qr(t,s){return t.length!==s.length?!1:t.every((n,a)=>n===s[a])}function ms(t,s){const n=Object.keys(t),a=Object.keys(s);return n.length!==a.length?!1:n.every(i=>s[i]===t[i])}function Nt(t,s){const n=new Set(s),a=s.length>0?[0]:[];for(const[c,d]of t)!n.has(c)||d<=0||a.includes(d)||a.push(d);a.sort((c,d)=>c-d);const i={};a.forEach((c,d)=>{i[c]=d}),a.length===0&&(i[0]=0);const o=new Map;for(const[c,d]of t){if(!n.has(c)||d<=0)continue;const l=i[d];typeof l=="number"&&l>0&&o.set(c,l)}return{assignments:o,groupCount:Math.max(1,a.length),mapping:i,usedGroups:a}}function hs(t,s){const n={};for(const[a,i]of Object.entries(t)){const o=s[Number(a)];typeof o=="number"&&(n[o]=i)}return n}function Gr(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const a=[...s].reverse().find(i=>i<t)??s[0];return n[a]??0}function Jr(t,s,n){if(s.length<=1)return[];const a=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=a.length===s.length?a:Array(n).fill(100/n),o=i.reduce((c,d)=>c+d,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function Zr(){const{sendCommand:t}=st(),[s,n]=js(),a=s.get("activeTab"),i=$t(),{updateIdeChats:o,screenshotMap:c,setScreenshotMap:d}=i,l=i.ides||[],[h,x]=r.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),m=i.toasts||[],f=i.setToasts||(()=>{}),u=i.wsStatus||"connected",g=i.isConnected??!0,N=i.connectionStates||{};i.retryConnection;const L=i.showReconnected||!1,[v,w]=r.useState(()=>{try{const j=localStorage.getItem("adhdev_splitGroups");if(j){const S=JSON.parse(j);return new Map(S)}}catch{}return new Map}),[P,B]=r.useState(()=>{try{const j=localStorage.getItem("adhdev_focusedGroup");if(j)return parseInt(j,10)||0}catch{}return 0}),[D,T]=r.useState(()=>{try{const j=localStorage.getItem("adhdev_groupActiveTabs");if(j)return JSON.parse(j)}catch{}return{}}),R=r.useRef(!1),[$,_]=r.useState(()=>{try{const j=localStorage.getItem("adhdev_groupTabOrders");if(j)return JSON.parse(j)}catch{}return{}}),[re,b]=r.useState(()=>{try{const j=localStorage.getItem("adhdev_splitSizes");if(j)return JSON.parse(j)}catch{}return[]});r.useEffect(()=>{try{v.size===0?localStorage.removeItem("adhdev_splitGroups"):localStorage.setItem("adhdev_splitGroups",JSON.stringify([...v.entries()]))}catch{}},[v]),r.useEffect(()=>{try{re.length>0?localStorage.setItem("adhdev_splitSizes",JSON.stringify(re)):localStorage.removeItem("adhdev_splitSizes")}catch{}},[re]),r.useEffect(()=>{try{localStorage.setItem("adhdev_focusedGroup",String(P))}catch{}},[P]),r.useEffect(()=>{try{localStorage.setItem("adhdev_groupActiveTabs",JSON.stringify(D))}catch{}},[D]),r.useEffect(()=>{try{localStorage.setItem("adhdev_groupTabOrders",JSON.stringify($))}catch{}},[$]);const[z,F]=r.useState(()=>typeof window<"u"&&window.innerWidth<768);r.useEffect(()=>{const j=window.matchMedia("(max-width: 767px)"),S=M=>F(M.matches);return j.addEventListener("change",S),()=>j.removeEventListener("change",S)},[]);const[y,Z]=r.useState({}),[V,H]=r.useState(!1),[Y,q]=r.useState([]),[ne,ee]=r.useState({}),[me,fe]=r.useState({}),Ie=l.find(j=>j.type==="adhdev-daemon"),O=(Ie==null?void 0:Ie.detectedIdes)||[],C=!!Ie,p=r.useMemo(()=>{const j=l.filter(M=>M.type!=="adhdev-daemon"),S=new Map;for(const M of j){const I=S.get(M.id);if(!I)S.set(M.id,M);else{const te=(I.workspace?1:0)+(I.activeChat?1:0);((M.workspace?1:0)+(M.activeChat?1:0)>te||(M.timestamp||0)>(I.timestamp||0))&&S.set(M.id,M)}}return Array.from(S.values())},[l]),A=r.useMemo(()=>{const j=sr(p,ne,l,N),S=Date.now();return j.map(M=>{const I=me[M.tabKey];return I&&S-I<5e3?{...M,messages:[],title:""}:M})},[p,ne,me,l]),{hiddenTabs:E,toggleTab:xe}=Kr(),de=r.useMemo(()=>A.filter(j=>!E.has(j.tabKey)),[A,E]),we=r.useMemo(()=>de.map(j=>j.tabKey),[de]),he=r.useMemo(()=>Nt(v,we),[v,we]),le=he.assignments,ye=r.useMemo(()=>z?1:he.groupCount,[he.groupCount,z]),Ne=ye>1,Se=r.useCallback((j,S)=>{const M={};for(const[I,te]of Object.entries(j)){const ce=Number(I);M[ce>=S?ce+1:ce]=te}return M},[]),Ce=r.useCallback(j=>Array(j).fill(100/j),[]),_e=r.useCallback((j,S)=>{w(M=>{const I=new Map(Nt(M,we).assignments);return S===0?I.delete(j):I.set(j,S),I}),T(M=>({...M,[S]:j})),B(S)},[we]),Oe=r.useCallback(j=>{w(S=>{const M=Nt(S,we).assignments,I=new Map;for(const[te,ce]of M)ce!==j&&(ce>j?I.set(te,ce-1):I.set(te,ce));return I}),b(S=>{if(S.length<=1)return[];const M=[...S];M.splice(j,1);const I=M.reduce((te,ce)=>te+ce,0);return I>0?M.map(te=>te/I*100):[]}),B(0)},[we]),We=r.useRef(null),U=r.useCallback((j,S)=>{S.preventDefault();const M=We.current;if(!M)return;const I=S.clientX,te=M.offsetWidth,ce=re.length===ye?[...re]:Array(ye).fill(100/ye),Te=Pe=>{const Xe=(Pe.clientX-I)/te*100,xt=[...ce];xt[j]=Math.max(15,ce[j]+Xe),xt[j+1]=Math.max(15,ce[j+1]-Xe),b(xt)},Ae=()=>{document.removeEventListener("mousemove",Te),document.removeEventListener("mouseup",Ae),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",Te),document.addEventListener("mouseup",Ae)},[re,ye]),ue=r.useCallback((j,S,M)=>{const I=ye;if(I>=4)return;const te=M==="left"?S:S+1;w(ce=>{const Te=Nt(ce,we).assignments,Ae=new Map;for(const Pe of de){const He=Te.get(Pe.tabKey)??0,Xe=He>=te?He+1:He;Xe>0&&Ae.set(Pe.tabKey,Xe)}return te>0&&Ae.set(j,te),Ae}),b(ce=>{const Te=ce.length===I?[...ce]:Ce(I),Ae=Te[S]??100/I,Pe=Math.max(15,Ae/2),He=Math.max(15,Ae/2),Xe=[...Te];Xe[S]=Pe,Xe.splice(te,0,He);const xt=Xe.reduce((_t,en)=>_t+en,0);return Xe.map(_t=>_t/xt*100)}),T(ce=>{const Te=Se(ce,te);return Te[te]=j,Te}),_(ce=>{const Te=Se(ce,te);return Te[te]=[j],Te}),B(te)},[ye,de,we,Ce,Se]);r.useEffect(()=>{ur()},[]);const be=r.useMemo(()=>de.map(j=>({id:j.tabKey,name:j.title||j.agentName||j.ideId,status:j.status,activeModal:j.modalMessage?{message:j.modalMessage,buttons:j.modalButtons}:null})),[de]);pr(be),r.useEffect(()=>{Vr(v,le)||w(le)},[v,le]),r.useEffect(()=>{const{mapping:j,usedGroups:S}=he;T(M=>{const I=hs(M,j);return ms(M,I)?M:I}),_(M=>{const I=hs(M,j);return ms(M,I)?M:I}),B(M=>{const I=z?0:Gr(M,S,j);return M===I?M:I}),b(M=>{const I=z?[]:Jr(M,S,he.groupCount);return qr(M,I)?M:I})},[he,z]);const ge=r.useMemo(()=>{const j=Array.from({length:ye},()=>[]);for(const S of de){const M=le.get(S.tabKey)??0,I=Math.min(M,ye-1);j[I].push(S)}return j},[de,le,ye]);r.useEffect(()=>{if(!a||R.current||A.length===0)return;const j=A.find(S=>S.tabKey===a)||A.find(S=>S.ideId===a)||A.find(S=>S.ideType===a||S.agentType===a);if(j){const S=le.get(j.tabKey)??0;T(M=>({...M,[S]:j.tabKey})),B(S),R.current=!0,n(M=>{const I=new URLSearchParams(M);return I.delete("activeTab"),I},{replace:!0})}},[a,A,le]),r.useEffect(()=>{if(Object.keys(me).length===0)return;const S=setTimeout(()=>{fe(M=>{const I=Date.now(),te={};for(const[ce,Te]of Object.entries(M))I-Te<5e3&&(te[ce]=Te);return Object.keys(te).length===Object.keys(M).length?M:te})},5500);return()=>clearTimeout(S)},[me]);const je=r.useMemo(()=>{var S,M;const j=D[P];if(j){const I=A.find(te=>te.tabKey===j);if(I)return I}return((S=ge[P])==null?void 0:S[0])||((M=ge[0])==null?void 0:M[0])},[D,P,A,ge]),Re=r.useCallback((j,S)=>{},[]);r.useEffect(()=>{var I;const j=Date.now();let S=!1;const M={...y};for(const te of A)(I=te.messages)!=null&&I.length&&te.messages.forEach((ce,Te)=>{const Ae=`${te.ideId}-${ce.id??`i-${Te}`}`;M[Ae]==null&&(M[Ae]=j,S=!0)});S&&Z(M)},[A]);const W=r.useRef(!1);r.useEffect(()=>{if(!V){W.current=!1;return}if(!je||W.current||ve)return;const j=l.find(S=>S.id===je.ideId);j&&(!j.chats||j.chats.length===0)&&(W.current=!0,X())},[V,je==null?void 0:je.ideId]),r.useEffect(()=>{const j=setInterval(()=>{const S=Date.now()-3e5;q(M=>{const I=M.filter(te=>te.timestamp>S).slice(-100);return I.length===M.length?M:I})},6e4);return()=>clearInterval(j)},[]);const ae=r.useRef(new Map);r.useEffect(()=>{const j=(M,I)=>{var te;if(I){Bs.emit(M,I);for(const ce of A){if(!Fe(ce))continue;const Te=(te=ce.ideId)!=null&&te.includes(":cli:")?ce.ideId.split(":cli:")[1]:"";if(M===Te||M===ce.agentType||M===ce.ideType||M===ce.ideId||M===ce.tabKey){const Pe=ae.current.get(ce.tabKey)||[];Pe.push(I),Pe.length>1e4&&Pe.splice(0,Pe.length-5e3),ae.current.set(ce.tabKey,Pe)}}}},S=zt.onPtyOutput(j);return()=>{S()}},[A]),r.useEffect(()=>{const j=S=>{if(S.ctrlKey&&S.key==="\\"){if(S.preventDefault(),Ne)w(new Map),B(0);else{const M=A[1];M&&ue(M.tabKey,0,"right")}return}S.ctrlKey&&(S.key==="["||S.key==="]")&&Ne&&(S.preventDefault(),B(M=>S.key==="]"?Math.min(M+1,ye-1):Math.max(M-1,0)))};return window.addEventListener("keydown",j),()=>window.removeEventListener("keydown",j)},[Ne,A,ue,ye]),r.useEffect(()=>{et.setIdes(l)},[l]),r.useEffect(()=>{et.setResolveAction((j,S,M)=>{t(j,S,M).catch(()=>{})})},[t]),r.useEffect(()=>{const j=et.onToast(I=>{f(ce=>ce.some(Ae=>Ae.message===I.message&&I.timestamp-Ae.timestamp<3e3)?ce:[...ce.slice(-4),{id:I.id,message:I.message,type:I.type,timestamp:I.timestamp,ideId:I.ideId,actions:I.actions}]);const te=I.duration||5e3;setTimeout(()=>f(ce=>ce.filter(Te=>Te.id!==I.id)),te)}),S=et.onSystemMessage((I,te)=>{ee(ce=>({...ce,[I]:[...ce[I]||[],te]}))}),M=et.onClearSystemMessage((I,te)=>{ee(ce=>{var Te;return(Te=ce[I])!=null&&Te.length?{...ce,[I]:ce[I].filter(Ae=>{var Pe;return!(Ae.role==="system"&&((Pe=Ae._localId)!=null&&Pe.startsWith(te)))})}:ce})});return()=>{j(),S(),M()}},[]),r.useEffect(()=>{const j=Os.on("status_event",S=>et.handleRawEvent(S,"ws"));return()=>{j()}},[]),r.useEffect(()=>{var S;const j=M=>{const I=M.data;(I==null?void 0:I.type)==="notification_action"&&I.action==="approve"&&I.ideId&&t(I.ideId,"resolve_action",{action:"approve",button:"Approve"}).catch(te=>console.error("[SW Action] approve failed:",te))};return(S=navigator.serviceWorker)==null||S.addEventListener("message",j),()=>{var M;return(M=navigator.serviceWorker)==null?void 0:M.removeEventListener("message",j)}},[]);const{isCreatingChat:Q,isRefreshingHistory:ve,handleLaunchIde:k,handleSwitchSession:K,handleNewChat:oe,handleRefreshHistory:X}=Qs({sendDaemonCommand:t,activeConv:je,ides:l,updateIdeChats:o,setToasts:f,setLocalUserMessages:ee,setClearedTabs:fe,setActionLogs:q,pinTab:Re,isStandalone:C}),ie=r.useCallback(async()=>{var M;if(!je||!Fe(je)||Be(je))return;const j=(M=je.ideId)!=null&&M.includes(":cli:")?je.ideId.split(":cli:")[1]:je.ideType||je.agentType||"";if(!window.confirm(`Stop ${j}?
54
- This will terminate the CLI process.`))return;const S=je.ideId||je.daemonId||"";try{await t(S,"stop_cli",{cliType:j})}catch(I){console.error("Stop CLI failed:",I)}},[je,t]),G=r.useMemo(()=>l.filter(j=>j.type==="adhdev-daemon"&&j.versionMismatch),[l]),[J,pe]=r.useState(!1),[se,ke]=r.useState({}),Ee=r.useCallback(async j=>{var S,M;ke(I=>({...I,[j]:"upgrading"}));try{const I=await t(j,"daemon_upgrade",{});(S=I==null?void 0:I.result)!=null&&S.upgraded||(M=I==null?void 0:I.result)!=null&&M.success?ke(te=>({...te,[j]:"done"})):ke(te=>({...te,[j]:"error"}))}catch{ke(I=>({...I,[j]:"error"}))}},[t]);return e.jsxs("div",{className:"page-dashboard flex-1 min-h-0 bg-bg-primary text-text-primary flex flex-col overflow-hidden",children:[e.jsx(Fn,{wsStatus:u,showReconnected:L}),G.length>0&&!J&&e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 bg-amber-500/[0.08] border-b border-amber-500/20 text-xs text-text-secondary shrink-0 flex-wrap",children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",children:e.jsx(Es,{size:14,className:"text-amber-500"})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available: ",e.jsxs("strong",{children:["v",G[0].version]})," → ",e.jsxs("strong",{children:["v",G[0].serverVersion]})]}),G.map(j=>{const S=ut(j,{fallbackId:j.id}),M=se[j.id];return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-amber-500/[0.08] border border-amber-500/15",children:[e.jsx("span",{className:"font-medium text-text-primary",children:S}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",j.version]}),M==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):M==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):M==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>Ee(j.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold text-amber-400 hover:text-amber-300 cursor-pointer px-1.5 py-px rounded bg-amber-500/10 border border-amber-500/20 transition-colors",onClick:()=>Ee(j.id),children:"Upgrade"})]},j.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:()=>pe(!0),title:"Dismiss",children:"✕"})]}),e.jsx(Yn,{activeConv:je,agentCount:p.length,wsStatus:u,isConnected:g,onOpenHistory:()=>H(!0),onStopCli:ie}),e.jsx("div",{ref:We,className:`flex-1 min-h-0 flex ${Ne?"flex-row":"flex-col"} overflow-hidden`,children:ge.map((j,S)=>{const M=Ne&&re.length===ye?`${re[S]}%`:void 0;return e.jsxs(ln.Fragment,{children:[Ne&&S>0&&e.jsx("div",{className:"shrink-0 w-1 cursor-col-resize hover:bg-accent/30 transition-colors relative group",style:{background:"var(--border-subtle)"},onMouseDown:I=>U(S-1,I),onDoubleClick:()=>Oe(S),title:"Drag to resize · Double-click to merge",children:e.jsx("div",{className:"absolute inset-y-0 -left-1 -right-1 group-hover:bg-accent/10"})}),e.jsx(Yr,{style:Ne?{flexBasis:M??`${100/ye}%`,flexGrow:M?0:1,flexShrink:M?0:1}:void 0,conversations:j,ides:l,messageReceivedAt:y,actionLogs:Y,ptyBuffers:ae,screenshotMap:c,setScreenshotMap:d,sendDaemonCommand:t,updateIdeChats:o,setToasts:f,setLocalUserMessages:ee,setClearedTabs:fe,setActionLogs:q,pinTab:Re,isStandalone:C,userName:i.userName,groupIndex:S,isFocused:P===S,onFocus:()=>B(S),isSplitMode:Ne,numGroups:ye,onMoveTab:(I,te)=>{te==="left"&&S>0?_e(I,S-1):te==="right"&&S<ye-1?_e(I,S+1):te==="split-left"&&ye<4?ue(I,S,"left"):te==="split-right"&&ye<4&&ue(I,S,"right")},onClose:Ne?()=>Oe(S):void 0,onReceiveTab:I=>_e(I,S),detectedIdes:S===0?O:void 0,handleLaunchIde:S===0?k:void 0,onActiveTabChange:I=>T(te=>({...te,[S]:I})),initialActiveTabId:D[S],initialTabOrder:$[S],onTabOrderChange:I=>_(te=>({...te,[S]:I})),onHideTab:xe})]},S)})}),V&&je&&e.jsx(Ks,{activeConv:je,ides:l,isCreatingChat:Q,isRefreshingHistory:ve,onClose:()=>H(!1),onNewChat:oe,onSwitchSession:K,onRefreshHistory:X}),e.jsx("style",{children:`
55
- body { overflow: hidden; overscroll-behavior: none; }
56
- .pulse-amber { animation: pulse-amber 2s infinite ease-in-out; }
57
- @keyframes pulse-amber {
58
- 0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.7); }
59
- 70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(245, 158, 11, 0); }
60
- 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
61
- }
62
- `}),e.jsx(Hs,{toasts:m,onDismiss:j=>f(S=>S.filter(M=>M.id!==j)),onClickToast:j=>{if(j.ideId){const S=A.find(M=>M.ideId===j.ideId||M.tabKey===j.ideId);S&&B(le.get(S.tabKey)??0)}}}),e.jsx("style",{children:`
63
- @keyframes toast -in {
64
- from { opacity: 0; transform: translateX(40px); }
65
- to { opacity: 1; transform: translateX(0); }
66
- }
67
- `}),h&&e.jsx(Xr,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}x(!1)}})]})}function Qr(t){return t.split(":")[0]||""}function ea({renderHeaderActions:t}={}){var We;const{id:s}=vs(),n=jt(),a=$t(),i=a.ides||[],o=a.updateIdeChats||(()=>{}),c=a.connectionStates||{},{sendCommand:d}=st(),l=r.useMemo(()=>Qr(s||""),[s]),h=r.useMemo(()=>i.find(U=>U.id===s),[i,s]),x=(h==null?void 0:h.type)||void 0,m=x?x.charAt(0).toUpperCase()+x.slice(1):"IDE",f=(h==null?void 0:h.activeChat)||null,u=(h==null?void 0:h.agentStreams)||[],g=a.isConnected??!0,N=c[l]||(g?"connected":"new"),L=((We=a.connectionTransports)==null?void 0:We[l])||"unknown",v=r.useMemo(()=>i.find(U=>U.id===l||U.daemonId===l),[i,l]),w=v?ut(v,{fallbackId:l}):"",P=(h==null?void 0:h.workspace)||"",[B]=js(),D=typeof window<"u"&&window.innerWidth<=768,T=B.get("view")||(D?"chat":"split"),[R,$]=r.useState(T),[_,re]=r.useState("native"),[b,z]=r.useState(!1),[F,y]=r.useState(!1),[Z,V]=r.useState(!1),[H,Y]=r.useState(""),[q,ne]=r.useState(!1),[ee,me]=r.useState(null),[fe,Ie]=r.useState(null),[O,C]=r.useState([]),p=r.useRef(!1),A=Ke(f==null?void 0:f.status,{activeModal:f==null?void 0:f.activeModal}),E=r.useMemo(()=>{var U,ue;return{ideId:s||"",daemonId:l,agentName:Ft(x||""),agentType:x||"",status:A,title:(f==null?void 0:f.title)||"",messages:(f==null?void 0:f.messages)||[],ideType:x||"",workspaceName:(h==null?void 0:h.workspaceName)||"",displayPrimary:m,displaySecondary:(h==null?void 0:h.workspaceName)||"",cdpConnected:!0,modalButtons:(U=f==null?void 0:f.activeModal)==null?void 0:U.buttons,modalMessage:(ue=f==null?void 0:f.activeModal)==null?void 0:ue.message,streamSource:"native",tabKey:`ide-${s}`}},[s,l,x,f,h,m,A]),xe=r.useMemo(()=>u.map(U=>{var be,ge;const ue=Kt(U);return{ideId:s||"",daemonId:l,agentName:U.agentName,agentType:U.agentType,status:ue,title:"",messages:U.messages.map((je,Re)=>({role:je.role,content:je.content,kind:je.kind,id:`${U.agentType}-${Re}`,receivedAt:je.timestamp})),ideType:U.agentType,workspaceName:"",displayPrimary:U.agentName,displaySecondary:"",cdpConnected:!0,modalButtons:(be=U.activeModal)==null?void 0:be.buttons,modalMessage:(ge=U.activeModal)==null?void 0:ge.message,streamSource:"agent-stream",tabKey:`agent-stream-${U.agentType}`}}),[u,s,l]),de=r.useMemo(()=>_==="native"?E:xe.find(U=>U.agentType===_)||E,[_,E,xe]),we=r.useCallback(()=>de.streamSource==="agent-stream"?{agentType:de.agentType}:{},[de]);r.useEffect(()=>l?Qe.onScreenshot("ide-page",(ue,be)=>{if(ue!==l)return;const ge=new FileReader;ge.onload=()=>me(ge.result),ge.readAsDataURL(be)}):void 0,[l]),r.useEffect(()=>{N!=="connected"&&me(null)},[N]),r.useEffect(()=>{var ue;return l?((ue=Qe.onStatus)==null?void 0:ue.call(Qe,(be,ge)=>{be===l&&ge!=null&&ge.screenshotUsage&&Ie(ge.screenshotUsage)}))||(()=>{}):void 0},[l]);const he=r.useMemo(()=>{if(!s)return x;const U=s.split(":");return U.length>=3&&U[1]==="ide"?U.slice(2).join(":"):x},[s,x]);r.useEffect(()=>{me(null)},[l,s,he]),r.useEffect(()=>{const U=l?Qe.get(l):null;!U||!(N==="connected")||(R!=="chat"&&he?U.startScreenshots(he):U.stopScreenshots(he))},[R,N,he,l]);const le=r.useCallback(async(U,ue={})=>{if(!s)throw new Error("No IDE ID");return await d(s,U,ue)},[s]),ye=async()=>{const U=H.trim();if(!(!U||!s||q)){Y(""),ne(!0);try{await le("send_chat",{message:U,text:U,waitForResponse:!0,..._!=="native"&&{agentType:_}})}catch(ue){console.error("[IDE] Send failed:",ue)}finally{ne(!1)}}},Ne=r.useCallback((U,ue="warning")=>{const be=Date.now()+Math.floor(Math.random()*1e3);C(ge=>[...ge,{id:be,message:U,type:ue}]),window.setTimeout(()=>{C(ge=>ge.filter(je=>je.id!==be))},5e3)},[]),Se=r.useCallback(async()=>{var U;if(!(!s||Z)){V(!0);try{const ue=await d(s,"list_chats",{forceExpand:!0,...we()}),be=(ue==null?void 0:ue.chats)||((U=ue==null?void 0:ue.result)==null?void 0:U.chats);ue!=null&&ue.success&&Array.isArray(be)&&o(s,be)}catch(ue){console.error("[IDE] Refresh history failed:",ue),Ne("히스토리 새로고침에 실패했습니다.","warning")}finally{V(!1)}}},[s,Z,d,we,o,Ne]),Ce=r.useCallback(async(U,ue)=>{if(s)try{const be=await d(s,"switch_chat",{id:ue,sessionId:ue,...we()}),ge=be==null?void 0:be.result;(be==null?void 0:be.success)===!0||ge==="switched"||ge==="switched-by-title"||(ge===!1||ge==="not_found"?Ne("세션 탭을 찾지 못했습니다. 히스토리를 새로고침해 보세요.","warning"):typeof ge=="string"&&ge.startsWith("error:")?Ne(`세션 전환 오류: ${ge}`,"warning"):Ne("세션 전환에 실패했습니다.","warning"))}catch(be){console.error("[IDE] Switch session failed:",be),Ne(`세션 전환 실패: ${(be==null?void 0:be.message)||"connection error"}`,"warning")}},[s,d,we,Ne]),_e=r.useCallback(async()=>{if(!(!s||F)){y(!0);try{await d(s,"new_chat",{...we()})}catch(U){console.error("[IDE] New chat failed:",U),Ne("새 채팅 생성에 실패했습니다.","warning")}finally{y(!1)}}},[s,F,d,we,Ne]);r.useEffect(()=>{if(!b){p.current=!1;return}p.current||Z||(!(h!=null&&h.chats)||h.chats.length===0)&&(p.current=!0,Se())},[b,h==null?void 0:h.chats,Z,Se]);const Oe=u.length>0;return s?e.jsxs("div",{className:"ide-page",children:[e.jsxs("header",{className:"ide-header",children:[e.jsxs("div",{className:"ide-header-left",children:[e.jsxs("div",{className:"ide-title",children:[e.jsx(lt,{size:16}),e.jsx("span",{className:"ide-name",children:m}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),P&&e.jsx("span",{className:"ide-workspace",children:P}),e.jsx("span",{className:"ide-badge",children:"REMOTE"})]}),e.jsxs("div",{className:"ide-status-pill",children:[e.jsx("span",{className:`ide-dot ${N==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:N==="connected"?"Connected":N==="connecting"?"Connecting":"WS"})]}),w&&e.jsx("span",{className:"ide-machine-label",children:w})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(U=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:R===U?"1px solid var(--accent-primary)":"none",background:R===U?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:R===U?"var(--accent-primary)":void 0},onClick:()=>$(U),children:U==="chat"?e.jsx(lt,{size:14}):U==="split"?"⊞":e.jsx(nt,{size:14})},U)),e.jsx("button",{className:"btn btn-secondary btn-sm flex items-center justify-center shrink-0",onClick:()=>z(!0),title:"Chat History",children:e.jsx(Ts,{size:14})}),t&&t({daemonId:l,ideInstanceId:s||""}),e.jsxs("button",{className:"btn btn-primary btn-sm flex items-center justify-center shrink-0",onClick:()=>n(-1),children:["←",e.jsx("span",{className:"hidden md:inline ml-1",children:"Back"})]})]})]}),e.jsxs("div",{className:"ide-content",children:[e.jsxs("div",{className:`ide-chat-panel ${R==="chat"?"full":""} ${R==="remote"?"hidden":""}`,children:[Oe&&e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${_==="native"?"active":""}`,onClick:()=>re("native"),children:m}),u.map(U=>{const ue=_===U.agentType,be=Kt(U),ge=be==="waiting_approval",je=be==="generating";return e.jsxs("button",{className:`ide-chat-tab ${ue?"active":""}`,onClick:()=>re(U.agentType),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:ge?"#f59e0b":je?"var(--accent-primary)":"#64748b",boxShadow:je?"0 0 6px var(--accent-primary)":"none"}}),U.agentName,ge&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},U.agentType)})]}),e.jsx(Ds,{activeConv:de,ides:i,agentInput:H,setAgentInput:Y,handleSendChat:ye,handleFocusAgent:()=>{},isFocusingAgent:!1,messageReceivedAt:{},actionLogs:[],userName:a.userName})]}),e.jsx("div",{className:`ide-remote-panel ${R==="remote"?"full":""} ${R==="chat"?"hidden":""}`,children:e.jsx(Dn,{addLog:()=>{},connState:N,connScreenshot:ee,screenshotUsage:fe,transportType:L,onAction:async(U,ue)=>{const be=l?Qe.get(l):null;if(!be||N!=="connected")return console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"};const ge=(h==null?void 0:h.instanceId)||he;return await be.sendInput(U,ue,ge)}})})]}),O.length>0&&e.jsx("div",{className:"ide-toasts",children:O.map(U=>e.jsx("div",{className:`ide-toast ${U.type}`,onClick:()=>C(ue=>ue.filter(be=>be.id!==U.id)),children:U.message},U.id))}),b&&e.jsx(Ks,{activeConv:de,ides:i,isCreatingChat:F,isRefreshingHistory:Z,onClose:()=>z(!1),onNewChat:_e,onSwitchSession:Ce,onRefreshHistory:Se})]}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function ta({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:a,logsEndRef:i}){const[o,c]=r.useState([]),[d,l]=r.useState(null),[h,x]=r.useState(!1),[m,f]=r.useState(!1),[u,g]=r.useState(!1),[N,L]=r.useState([]),[v,w]=r.useState([]),[P,B]=r.useState(null),[D,T]=r.useState(!1),[R,$]=r.useState(""),_=r.useRef(null),re=r.useCallback(C=>{_.current=C},[]),b=r.useCallback((C,p,A=!1)=>{c(E=>[...E.slice(-100),{timestamp:Date.now(),level:C,message:p}]),setTimeout(()=>{var E;return(E=i.current)==null?void 0:E.scrollIntoView({behavior:"smooth"})},100),A&&et.showToast(p,C==="error"||C==="warn"?"warning":"success")},[i]),z=r.useCallback(async(C,p)=>{var A;if(!(!t||d)){l(C),b("info",`Launching ${Ue(C)}${p!=null&&p.workspace?` in ${p.workspace}`:""}...`);try{const E={ideType:C,enableCdp:!0};(A=p==null?void 0:p.workspace)!=null&&A.trim()?E.workspace=p.workspace.trim():p!=null&&p.useDefaultWorkspace&&(E.useDefaultWorkspace=!0);const xe=await n(t,"launch_ide",E);b(xe!=null&&xe.success?"info":"error",xe!=null&&xe.success?`${Ue(C)} launched`:`Failed: ${xe==null?void 0:xe.error}`,!0)}catch(E){b("error",`Launch error: ${E.message}`,!0)}finally{l(null)}}},[t,d,b,n]),F=r.useCallback(async C=>{if(!t)return;const{cliType:p,dir:A,workspaceId:E,useDefaultWorkspace:xe,useHome:de,argsStr:we,model:he}=C;if(!p){b("warn","Select a CLI or ACP provider first",!0);return}const le=we?we.split(/\s+/).filter(Boolean):void 0,ye=(A==null?void 0:A.trim())||(E?"(saved id)":xe?"(default workspace)":de?"(home)":"");b("info",`Launching ${p}${ye?` in ${ye}`:""}${he?` (model: ${he})`:""}...`);try{const Ne={cliType:p,cliArgs:le,initialModel:he||void 0};A!=null&&A.trim()?Ne.dir=A.trim():E?Ne.workspaceId=E:xe?Ne.useDefaultWorkspace=!0:de&&(Ne.useHome=!0);const Se=await n(t,"launch_cli",Ne),Ce=(Se==null?void 0:Se.result)||Se;Se!=null&&Se.success?(b("info",`${p} launched`,!0),(Ce==null?void 0:Ce.launchSource)==="home"?b("info","📂 Running in home directory (explicit choice)"):(Ce==null?void 0:Ce.launchSource)==="defaultWorkspace"&&b("info","📂 Using default workspace (explicit choice)")):(b("error",`Failed: ${(Se==null?void 0:Se.error)||(Ce==null?void 0:Ce.error)}`,!0),(Se==null?void 0:Se.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&B({cliType:p,argsStr:we,model:he}))}catch(Ne){b("error",`Launch error: ${Ne.message}`,!0)}},[t,b,n]),y=r.useCallback((C,p,A,E)=>{if(t){if(!C){b("warn","Select a provider",!0);return}if(!p.trim()){B({cliType:C,argsStr:A,model:E});return}F({cliType:C,dir:p,argsStr:A,model:E})}},[t,b,F]),Z=r.useCallback(async(C,p,A)=>{if(t&&window.confirm(`Stop ${C}?
68
- This will terminate the process.`))try{const E=await n(t,"stop_cli",{cliType:C,dir:p,_targetInstance:A});E!=null&&E.success?b("info",`${C} stopped`,!0):b("error",`Stop failed: ${(E==null?void 0:E.error)||"Unknown error"}`,!0)}catch(E){b("error",`Stop failed: ${E.message}`,!0)}},[t,b,n]),V=r.useCallback(async C=>{try{await n(C.daemonId,"restart_ide",{ideType:C.type}),b("info",`${Ue(C.type)} restart initiated`,!0)}catch(p){b("error",`Restart failed: ${p.message}`,!0)}},[b,n]),H=r.useCallback(async C=>{if(window.confirm(`Stop ${Ue(C.type)}?
69
- This will disconnect CDP and optionally kill the process.`))try{const p=await n(C.daemonId,"stop_ide",{ideType:C.type,killProcess:!0});p!=null&&p.success?b("info",`${Ue(C.type)} stopped`,!0):b("error",`Stop failed: ${(p==null?void 0:p.error)||"Unknown error"}`,!0)}catch(p){b("error",`Stop failed: ${p.message}`,!0)}},[b,n]),Y=r.useCallback(async()=>{if(t)try{const C=await n(t,"detect_ides",{});b("info",`Found ${((C==null?void 0:C.result)||[]).length} IDE(s)`,!0)}catch(C){b("error",`Detection failed: ${C.message}`,!0)}},[t,b,n]),q=r.useCallback(async()=>{if(t){x(!0);try{const C=await n(t,"get_recent_workspaces",{});C!=null&&C.success&&Array.isArray(C==null?void 0:C.result)&&w(C.result)}catch(C){b("error",`Failed: ${C.message}`)}finally{x(!1)}}},[t,b,n]),ne=r.useCallback(async C=>{if(!(!t||!C.trim())){f(!0);try{const p=await n(t,"workspace_add",{path:C.trim()});p!=null&&p.success?b("info",`Workspace added: ${C.trim()}`):b("error",(p==null?void 0:p.error)||"workspace_add failed")}catch(p){b("error",p.message)}finally{f(!1)}return!0}},[t,b,n]),ee=r.useCallback(async C=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){f(!0);try{const p=await n(t,"workspace_remove",{id:C});p!=null&&p.success?b("info","Workspace removed",!0):b("error",(p==null?void 0:p.error)||"workspace_remove failed",!0)}catch(p){b("error",p.message,!0)}finally{f(!1)}}},[t,b,n]),me=r.useCallback(async C=>{var p;if(t){f(!0);try{const A=await n(t,"workspace_set_default",C===null?{clear:!0}:{id:C});if(A!=null&&A.success){b("info",C?"Default workspace updated":"Default workspace cleared",!0);const E=typeof A.defaultWorkspacePath=="string"?A.defaultWorkspacePath:"";E&&((p=_.current)==null||p.call(_,E))}else b("error",(A==null?void 0:A.error)||"workspace_set_default failed",!0)}catch(A){b("error",A.message,!0)}finally{f(!1)}}},[t,b,n]),fe=r.useCallback(async C=>{var A;if(!t||!C.trim())return;const p=C.trim();f(!0);try{const E=await n(t,"workspace_set_default",{path:p});E!=null&&E.success?(b("info","Default workspace set from history"),(A=_.current)==null||A.call(_,p)):b("error",(E==null?void 0:E.error)||"Could not set default (path missing on disk?)")}catch(E){b("error",E.message)}finally{f(!1)}},[t,b,n]),Ie=r.useCallback(async()=>{var C;if(t){g(!0);try{const p=await n(t,"get_cli_history",{}),A=(p==null?void 0:p.history)??((C=p==null?void 0:p.result)==null?void 0:C.history);p!=null&&p.success&&Array.isArray(A)&&L(A)}catch{}g(!1)}},[t,n]),O=r.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:R}),a)try{await a({machineRuntimeId:t,registeredMachineId:s,nickname:R})}catch(C){b("warn",`Live nickname updated, but account sync failed: ${C.message}`)}b("info",`Nickname set to "${R||"(cleared)"}"`),T(!1)}catch(C){b("error",`Failed: ${C.message}`)}},[t,R,s,b,a,n]);return{logs:o,launchingIde:d,loadingWorkspaces:h,workspaceBusy:m,loadingHistory:u,cliHistory:N,recentWorkspaces:v,launchPick:P,setLaunchPick:B,editingNickname:D,setEditingNickname:T,nicknameInput:R,setNicknameInput:$,addLog:b,handleLaunchIde:z,runLaunchCliCore:F,handleLaunchCli:y,handleStopCli:Z,handleRestartIde:V,handleStopIde:H,handleDetectIdes:Y,handleLoadRecentWorkspaces:q,handleWorkspaceAdd:ne,handleWorkspaceRemove:ee,handleWorkspaceSetDefault:me,handleWorkspaceResumePath:fe,loadCliHistory:Ie,handleSaveNickname:O,setOnDefaultWorkspaceChanged:re}}function sa({machine:t,managedIdes:s,managedClis:n,managedAcps:a,actions:i}){const{workspaceBusy:o,handleWorkspaceAdd:c,handleWorkspaceRemove:d,handleWorkspaceSetDefault:l}=i,[h,x]=r.useState(""),m=t.availableMem??t.freeMem,f=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-m)/t.totalMem*100))):0,u=t.loadavg[0]||0;return e.jsxs("div",{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-2.5 mb-5",children:[e.jsx(vt,{icon:e.jsx($s,{size:16}),label:"Uptime",value:qn(t.uptime)}),e.jsx(vt,{icon:e.jsx(nt,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(vt,{icon:e.jsx(Gt,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(vt,{icon:e.jsx(Rs,{size:16}),label:"ACPs",value:`${a.length}`})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsx("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-3",children:"Resource Usage"}),e.jsxs("div",{className:"flex gap-6",children:[e.jsx(ns,{value:Math.min(Math.round(u/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${u.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(ns,{value:f,max:100,label:"Memory",color:"#3b82f6",detail:`${rs(t.totalMem-m)} / ${rs(t.totalMem)}${t.platform==="darwin"?" (approx.)":""}`})]})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-3",children:[e.jsx(Ot,{size:14})," Workspaces"]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center mb-3",children:[e.jsx("span",{className:"text-[10px] text-text-muted",children:"Default:"}),e.jsxs("select",{className:"text-xs bg-bg-primary border border-border-subtle rounded-lg px-2 py-1 max-w-[min(100%,420px)]",disabled:o,value:t.defaultWorkspaceId||"",onChange:g=>void l(g.target.value===""?null:g.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(g=>e.jsx("option",{value:g.id,children:g.label||g.path},g.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:h,disabled:o,onChange:g=>x(g.target.value),onKeyDown:g=>g.key==="Enter"&&void(async()=>{await c(h)&&x("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:o,onClick:async()=>{await c(h)&&x("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1 max-h-32 overflow-y-auto",children:(t.workspaces||[]).map(g=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[g.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:g.path,children:g.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:o,onClick:()=>void d(g.id),children:"Remove"})]},g.id))})]})]})}const na={ide:{label:"IDE",plural:"IDEs",accent:"border-blue-500/[0.12]"},cli:{label:"CLI",plural:"CLIs",accent:"border-violet-500/[0.12]"},acp:{label:"ACP Agent",plural:"ACP agents",accent:"border-emerald-500/[0.12]"}};function Wt({category:t,machine:s,machineId:n,providers:a,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:d}){const l=jt(),{handleLaunchIde:h,handleLaunchCli:x,handleStopCli:m,handleRestartIde:f,handleStopIde:u,handleDetectIdes:g,cliHistory:N,loadingHistory:L,loadCliHistory:v,launchingIde:w}=c,P=na[t],B=t==="ide",D=t==="acp",T=a.filter(p=>p.category===t),[R,$]=r.useState(""),[_,re]=r.useState(""),[b,z]=r.useState(""),[F,y]=r.useState(s.defaultWorkspaceId||""),[Z,V]=r.useState("");r.useEffect(()=>{!R&&T.length>0&&$(T[0].type)},[R,T.length]),r.useEffect(()=>{s.defaultWorkspaceId&&!F&&y(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const H=(()=>{if(F==="__custom__")return Z.trim();if(!F)return"";const p=(s.workspaces||[]).find(A=>A.id===F);return(p==null?void 0:p.path)||""})(),[Y,q]=r.useState({}),[ne,ee]=r.useState(null);r.useEffect(()=>{if(!B||!n||!d)return;(async()=>{try{const A=await d(n,"get_ide_extensions",{}),E=(A==null?void 0:A.result)||A;E!=null&&E.success&&(E!=null&&E.ides)&&q(E.ides)}catch{}})()},[B,n,d]);const me=p=>B?Ue(p.type):t==="cli"?p.cliName:p.acpName,fe=B?s.detectedIdes||[]:[],Ie=()=>{B?h(R,H?{workspace:H}:void 0):x(R,H,_||void 0,D&&b||void 0)},O=p=>{B?u(p):m(p.type,p.workspace,p.id)},C=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:F,onChange:p=>{y(p.target.value),p.target.value!=="__custom__"&&V("")},className:"machine-input min-w-[200px] flex-1",children:(s.workspaces||[]).length>0?e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspace — launch in home)"}),(s.workspaces||[]).map(p=>e.jsxs("option",{value:p.id,children:[p.id===s.defaultWorkspaceId?"⭐ ":"",p.label||p.path.split("/").filter(Boolean).pop()||p.path," — ",p.path]},p.id)),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]})}),F==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:Z,onChange:p=>V(p.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${P.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",P.label]}),C,B?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[fe.map(p=>{const A=p.running||i.some(E=>(E.type||"").toLowerCase()===(p.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>h(p.type||p.id||"",H?{workspace:H}:void 0),disabled:!!w,className:`machine-btn-primary flex items-center gap-1.5 ${A?"!border-green-500/30":""}`,style:{opacity:w&&w!==p.type?.4:1},children:[e.jsx("span",{children:o(p.type)}),A&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 shadow-[0_0_4px_rgba(34,197,94,0.4)]"}),w===p.type?"⏳ Launching...":`▶ ${p.name||Ue(p.type)}`,A&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},p.type)}),fe.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:g,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(In,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:R,onChange:p=>$(p.target.value),className:"machine-input",children:T.length>0?T.map(p=>e.jsxs("option",{value:p.type,children:[p.icon," ",p.displayName]},p.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),D&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:b,onChange:p=>z(p.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:_,onChange:p=>re(p.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:Ie,className:"machine-btn-primary",children:"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",i.length,")"]}),i.length===0?e.jsxs("div",{className:"py-7.5 px-5 text-center rounded-xl bg-bg-secondary border border-dashed border-border-subtle text-text-muted text-[13px] mb-5",children:["No ",P.plural," running"]}):e.jsx("div",{className:"flex flex-col gap-2.5 mb-5",children:i.map(p=>{const A=B?p:null,E=D?p:null,xe=Ke(p.status);return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:o(p.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[me(p),(A==null?void 0:A.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",A.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:p.workspace||"—"}),(E==null?void 0:E.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",E.currentModel]}),(E==null?void 0:E.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",E.currentPlan]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${xe==="stopped"?"bg-red-500/[0.08] text-red-500":xe==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:xe}),B&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>l(`/ide/${p.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(nt,{size:13})," Control"]}),e.jsx("button",{onClick:()=>f(p),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),D&&e.jsx("button",{onClick:()=>l(`/ide/${p.id}`),className:"machine-btn",title:"View chat",children:e.jsx(lt,{size:14})}),xe==="stopped"?e.jsx("button",{onClick:()=>B?h(p.type,p.workspace?{workspace:p.workspace}:void 0):x(p.type,p.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>O(p),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),A&&A.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:A.aiAgents.map(de=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${zs(de.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[de.name," · ",Ke(de.status)]},de.id))}),A&&(Y[A.type]||[]).length>0&&d&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(Y[A.type]||[]).map(de=>e.jsxs("button",{disabled:ne===`${A.type}.${de.type}`,onClick:async()=>{const we=`${A.type}.${de.type}`;ee(we);try{await d(n,"set_ide_extension",{ideType:A.type,extensionType:de.type,enabled:!de.enabled}),q(he=>({...he,[A.type]:(he[A.type]||[]).map(le=>le.type===de.type?{...le,enabled:!le.enabled}:le)}))}catch(he){console.error("Extension toggle failed:",he)}finally{ee(null)}},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium border transition-colors duration-150 cursor-pointer ${de.enabled?"bg-violet-500/[0.08] border-violet-500/20 text-violet-400":"bg-bg-glass border-border-subtle text-text-muted"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${de.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),de.name,e.jsx("span",{className:"text-[9px] font-normal",children:de.enabled?"ON":"OFF"})]},de.type))})]})]},p.id)})}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:v,disabled:L,className:"machine-btn",children:L?"⏳":"↻ Load"})]}),(()=>{const p=new Set(T.map(E=>E.type)),A=N.filter(E=>(E.category||"cli")!==t?!1:t==="ide"?!0:p.has(E.cliType));return A.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:A.map((E,xe)=>{var de,we;return e.jsxs("div",{onClick:()=>{$(E.cliType),(E.workspace||E.dir)&&(y("__custom__"),V(E.workspace||E.dir)),re((E.cliArgs||[]).join(" ")),z(E.model||""),B&&h(E.cliType,E.workspace?{workspace:E.workspace}:void 0)},className:"flex justify-between items-center px-2.5 py-1.5 rounded-md cursor-pointer bg-bg-glass border border-border-subtle text-xs transition-colors duration-150 hover:bg-bg-glass-hover",children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-text-secondary",children:[e.jsx("span",{children:o(E.cliType)}),e.jsx("span",{children:((de=E.workspace||E.dir)==null?void 0:de.split("/").filter(Boolean).pop())||E.cliType||"root"}),E.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",E.model]}),E.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((we=E.cliArgs)==null?void 0:we.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:E.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:E.timestamp?new Date(E.timestamp).toLocaleDateString():""})]},xe)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",P.label," launch history yet."]})})()]})]})}const fs=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],ra=[{value:"codex-cli",label:"Codex CLI",desc:"OpenAI o3/gpt-5.4",color:"#22c55e"},{value:"claude-cli",label:"Claude Code",desc:"Anthropic Claude",color:"#a855f7"},{value:"gemini-cli",label:"Gemini CLI",desc:"Google Gemini",color:"#3b82f6"}];function aa({machineId:t,provider:s,sendDaemonCommand:n,onClose:a}){const[i,o]=r.useState("config"),[c,d]=r.useState("codex-cli"),[l,h]=r.useState([]),[x,m]=r.useState(""),[f,u]=r.useState([]),[g,N]=r.useState(""),L=r.useRef(null),v=r.useRef(null),w=$=>{h(_=>_.includes($)?_.filter(re=>re!==$):[..._,$])},P=()=>h([...fs]),B=()=>h([]);r.useEffect(()=>{var $;($=L.current)==null||$.scrollIntoView({behavior:"smooth"})},[f]),r.useEffect(()=>()=>{v.current&&clearInterval(v.current)},[]);const D=r.useCallback(()=>{v.current&&clearInterval(v.current),v.current=setInterval(async()=>{try{const $=await n(t,"provider_auto_fix_status",{providerType:s.type});($==null?void 0:$.running)===!1&&i==="running"&&(o("done"),u(_=>[..._,`
70
- ✅ Auto-fix completed!`]),v.current&&clearInterval(v.current))}catch{}},3e3)},[t,s.type,n,i]),T=async()=>{if(l.length!==0){o("running"),u(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,x?`💬 Comment: ${x}`:"",""]),N("");try{const $=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...x?{comment:x}:{}});$!=null&&$.success&&($!=null&&$.started||$!=null&&$.running)?(u(_=>[..._,"✅ Agent started. Monitoring progress..."]),D()):(o("error"),N(($==null?void 0:$.error)||"Failed to start auto-fix"))}catch($){o("error"),N(($==null?void 0:$.message)||"Connection failed")}}},R=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),u($=>[...$,`
71
- ⚠️ Auto-fix cancelled.`]),o("done"),v.current&&clearInterval(v.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:a,children:e.jsxs("div",{className:"w-full max-w-[560px] max-h-[85vh] overflow-hidden rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:$=>$.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:s.icon||"🔧"}),e.jsxs("div",{children:[e.jsxs("h2",{className:"text-[15px] font-semibold text-text-primary",children:["Auto-Fix: ",s.displayName]}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"AI agent will implement provider scripts"})]})]}),e.jsx("button",{onClick:a,className:"text-text-muted hover:text-text-primary text-lg leading-none",children:"×"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[i==="config"&&e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"AI Agent"}),e.jsx("div",{className:"flex gap-2",children:ra.map($=>e.jsxs("button",{onClick:()=>d($.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===$.value?$.color+"66":"var(--border-subtle)",background:c===$.value?$.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===$.value?$.color:"var(--text-primary)"},children:$.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:$.desc})]},$.value))})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1.5",children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"Scripts to Fix"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:P,className:"text-[10px] text-violet-400 hover:text-violet-300",children:"All"}),e.jsx("span",{className:"text-[10px] text-text-muted",children:"|"}),e.jsx("button",{onClick:B,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:fs.map($=>e.jsxs("button",{onClick:()=>w($),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes($)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:l.includes($)?"rgba(139,92,246,0.08)":"transparent",color:l.includes($)?"#a78bfa":"var(--text-secondary)"},children:[l.includes($)?"☑ ":"☐ ",$]},$))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:x,onChange:$=>m($.target.value),placeholder:"e.g. Also search buttons inside Shadow DOM, preserve code block formatting in readChat...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(i==="running"||i==="done"||i==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[f.map(($,_)=>e.jsx("div",{className:$.startsWith("✅")?"text-green-400":$.startsWith("❌")||$.startsWith("⚠")?"text-amber-400":"",children:$},_)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:L})]}),g&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:g})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[i==="config"&&l.length>0&&`${l.length} script(s) selected`,i==="running"&&"Agent is generating...",i==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[i==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:a,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:T,disabled:l.length===0,className:"machine-btn",style:{background:l.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:l.length>0?"rgba(139,92,246,0.4)":void 0,color:l.length>0?"#a78bfa":void 0,opacity:l.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:R,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(i==="done"||i==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{o("config"),u([]),N("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:a,className:"machine-btn",children:"Close"})]})]})]})]})})}function oa({machineId:t,providers:s,sendDaemonCommand:n,onClose:a,onCreated:i}){var D;const o=s.filter(T=>T.category==="ide"),[c,d]=r.useState(((D=o[0])==null?void 0:D.type)||""),[l,h]=r.useState(""),[x,m]=r.useState(""),[f,u]=r.useState(!1),[g,N]=r.useState(""),[L,v]=r.useState(!1),w=T=>{const R=T.toLowerCase().replace(/[^a-z0-9-]/g,"");h(R),(!x||x===P(l))&&m(P(R))},P=T=>T.split("-").map(R=>R.charAt(0).toUpperCase()+R.slice(1)).join(" "),B=async()=>{if(!(!l||!x||!c)){u(!0),N("");try{const T=await n(t,"provider_clone",{type:l,name:x,category:"ide",location:"user",cloneFrom:c});T!=null&&T.success||T!=null&&T.created?(v(!0),i==null||i(l)):N((T==null?void 0:T.error)||"Failed to create provider")}catch(T){N((T==null?void 0:T.message)||"Connection failed")}u(!1)}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:a,children:e.jsxs("div",{className:"w-full max-w-[480px] rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:T=>T.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-text-primary",children:"✨ Create User Provider"}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"Clone an upstream IDE provider to customize"})]}),e.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:L?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:l})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",l,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",l]})," or use Auto-Fix to implement scripts."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Base Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:o.map(T=>e.jsxs("button",{onClick:()=>d(T.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===T.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:c===T.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:T.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===T.type?"#a78bfa":"var(--text-secondary)"},children:T.displayName})]},T.type))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Provider Type (ID)"}),e.jsx("input",{value:l,onChange:T=>w(T.target.value),placeholder:"my-cursor, custom-windsurf...",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-1",children:["Lowercase, alphanumeric + hyphens only. Will be created at ",e.jsxs("code",{className:"text-violet-400",children:["~/.adhdev/providers/",l||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:x,onChange:T=>m(T.target.value),placeholder:"My Custom IDE",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]}),g&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:g})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:L?e.jsx("button",{onClick:a,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:a,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:B,disabled:!l||!x||f,className:"machine-btn",style:{background:l&&x?"rgba(34,197,94,0.12)":void 0,borderColor:l&&x?"rgba(34,197,94,0.3)":void 0,color:l&&x?"#86efac":void 0,opacity:!l||!x||f?.4:1},children:f?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function ia({machineId:t,providers:s,sendDaemonCommand:n}){const[a,i]=r.useState([]),[o,c]=r.useState(!1),[d,l]=r.useState(null),[h,x]=r.useState("all"),[m,f]=r.useState(null),[u,g]=r.useState(!1),N=r.useCallback(async()=>{var v;if(t){c(!0);try{const w=await n(t,"get_provider_settings",{}),P=(w==null?void 0:w.result)||w;if(w!=null&&w.success&&(P!=null&&P.settings)){const B=[];for(const[D,T]of Object.entries(P.settings)){const R=s.find($=>$.type===D);B.push({type:D,displayName:(R==null?void 0:R.displayName)||D,icon:(R==null?void 0:R.icon)||"",category:(R==null?void 0:R.category)||"unknown",schema:T,values:((v=P.values)==null?void 0:v[D])||{}})}B.sort((D,T)=>D.category.localeCompare(T.category)||D.displayName.localeCompare(T.displayName)),i(B)}}catch{}c(!1)}},[t,s,n]);r.useEffect(()=>{a.length===0&&N()},[]);const L=async(v,w,P)=>{l(`${v}.${w}`),i(B=>B.map(D=>D.type===v?{...D,values:{...D.values,[w]:P}}:D));try{const B=await n(t,"set_provider_setting",{providerType:v,key:w,value:P});B!=null&&B.success||N()}catch{N()}l(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(v=>e.jsx("button",{onClick:()=>x(v),className:`machine-btn text-[10px] px-2 py-0.5 ${h===v?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:v.toUpperCase()},v))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>g(!0),className:"machine-btn text-[10px] bg-green-500/[0.06] border-green-500/20 text-green-400 hover:bg-green-500/[0.12]",children:"✨ Create Provider"}),e.jsx("button",{onClick:N,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),h!=="all"&&a.filter(v=>v.category===h).length>1&&(()=>{const v=a.filter(D=>D.category===h),w=new Map;for(const D of v)for(const T of D.schema){if(T.type!=="boolean")continue;const R=w.get(T.key),$=!!(D.values[T.key]??T.default);R?(R.onCount+=$?1:0,R.total+=1):w.set(T.key,{label:T.label||T.key,onCount:$?1:0,total:1})}const P=[...w.entries()].filter(([,D])=>D.total===v.length);if(P.length===0)return null;const B=async(D,T)=>{for(const R of v)await L(R.type,D,T)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",h.toUpperCase()," providers (",v.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:P.map(([D,T])=>{const R=T.onCount===T.total,$=T.onCount===0;return e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:"text-text-secondary font-medium",children:T.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",T.onCount,"/",T.total,")"]}),e.jsx("button",{onClick:()=>void B(D,!0),disabled:R,className:`machine-btn text-[9px] px-1.5 py-px ${R?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void B(D,!1),disabled:$,className:`machine-btn text-[9px] px-1.5 py-px ${$?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},D)})})]})})(),o&&a.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:a.filter(v=>h==="all"||v.category===h).map(v=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:v.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:v.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:v.category==="acp"?"rgba(139,92,246,0.08)":v.category==="cli"?"rgba(59,130,246,0.08)":v.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:v.category==="acp"?"#a78bfa":v.category==="cli"?"#60a5fa":v.category==="ide"?"#86efac":"#fbbf24"},children:v.category}),v.category==="ide"&&e.jsx("button",{onClick:()=>f(s.find(w=>w.type===v.type)||{type:v.type,displayName:v.displayName,icon:v.icon,category:v.category}),className:"ml-auto machine-btn text-[9px] px-2 py-0.5 bg-violet-500/[0.06] border-violet-500/20 text-violet-400 hover:bg-violet-500/[0.12]",children:"🔧 Auto-Fix"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:v.schema.map(w=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs font-medium text-text-primary",children:[w.label||w.key,d===`${v.type}.${w.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),w.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:w.description})]}),e.jsx("div",{className:"shrink-0",children:w.type==="boolean"?e.jsx("button",{onClick:()=>L(v.type,w.key,!(v.values[w.key]??w.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:v.values[w.key]??w.default?"#8b5cf6":"var(--border-subtle)"},children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white absolute top-[3px] transition-[left] duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.3)]",style:{left:v.values[w.key]??w.default?21:3}})}):w.type==="number"?e.jsx("input",{type:"number",value:v.values[w.key]??w.default??0,min:w.min,max:w.max,onChange:P=>{const B=parseInt(P.target.value)||0;w.min!==void 0&&B<w.min||w.max!==void 0&&B>w.max||L(v.type,w.key,B)},className:"machine-input w-20 text-center text-[11px]"}):w.type==="select"&&w.options?e.jsx("select",{value:v.values[w.key]??w.default??"",onChange:P=>L(v.type,w.key,P.target.value),className:"machine-input text-[11px]",children:w.options.map(P=>e.jsx("option",{value:P,children:P},P))}):e.jsx("input",{type:"text",value:v.values[w.key]??w.default??"",onBlur:P=>L(v.type,w.key,P.target.value),className:"machine-input w-[120px] text-[11px]"})})]},w.key))})]},v.type))}),m&&e.jsx(aa,{machineId:t,provider:m,sendDaemonCommand:n,onClose:()=>f(null)}),u&&e.jsx(oa,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>g(!1),onCreated:()=>{g(!1),N()}})]})}function ca({machineId:t,sendDaemonCommand:s}){const[n,a]=r.useState([]),[i,o]=r.useState(0),[c,d]=r.useState(!0),[l,h]=r.useState("debug"),x=r.useRef(null),m=r.useRef(!1);return r.useEffect(()=>{if(!t||!c)return;const f=async()=>{try{const g=await s(t,"get_logs",{count:200,minLevel:l,since:i}),N=(g==null?void 0:g.result)||g;if(g!=null&&g.success&&Array.isArray(N==null?void 0:N.logs)&&N.logs.length>0){a(v=>[...v,...N.logs.map(P=>({timestamp:P.ts,level:P.level,message:`[${P.category}] ${P.message}`}))].slice(-300));const L=Math.max(...N.logs.map(v=>v.ts));o(L)}}catch{}};f();const u=setInterval(f,3e3);return()=>clearInterval(u)},[t,c,i,l,s]),r.useEffect(()=>{if(c&&n.length>0){const f=m.current?"smooth":"instant";setTimeout(()=>{var u;(u=x.current)==null||u.scrollIntoView({behavior:f}),m.current=!0},50)}},[n.length,c]),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Level"}),["debug","info","warn","error"].map(f=>e.jsx("button",{onClick:()=>{h(f),a([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===f?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:f.toUpperCase()},f))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[n.length," entries"]}),e.jsx("button",{onClick:()=>d(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{a([]),o(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[n.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),n.map((f,u)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:f.level==="error"?"#ef4444":f.level==="warn"?"#f59e0b":f.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(f.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:f.level==="error"?"#ef4444":f.level==="warn"?"#f59e0b":f.level==="debug"?"#475569":"#8b5cf6"},children:f.level==="error"?"ERR":f.level==="warn"?"WRN":f.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:f.message})]},u)),e.jsx("div",{ref:x})]})]})}function la({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:a,setLaunchPick:i}=n;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(o=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{i(null),a({cliType:s.cliType,workspaceId:o.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:o.label||o.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:o.path})]},o.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{i(null),a({cliType:s.cliType,useDefaultWorkspace:!0,argsStr:s.argsStr,model:s.model})},children:"Default workspace"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",onClick:()=>{i(null),a({cliType:s.cliType,useHome:!0,argsStr:s.argsStr,model:s.model})},children:"Home directory"}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[80px]",onClick:()=>i(null),children:"Cancel"})]})]})})}function da({onNicknameSynced:t}={}){var D,T,R,$,_,re,b,z,F;const{id:s}=vs(),n=jt(),{sendCommand:a}=st(),i=$t(),o=i.ides||[],c=i.initialLoaded??!0,d=o.find(y=>y.id===s&&y.daemonMode),[l,h]=r.useState("overview"),x=r.useRef(null),m=ta({machineId:s,registeredMachineId:(d==null?void 0:d.machineId)||null,sendDaemonCommand:a,onNicknameSynced:t,logsEndRef:x});r.useEffect(()=>et.onToast(Z=>{i.setToasts(H=>{if(H.some(ne=>ne.message===Z.message&&Z.timestamp-ne.timestamp<3e3))return H;const q={id:Z.id,message:Z.message,type:Z.type,timestamp:Z.timestamp,ideId:Z.ideId,actions:Z.actions};return[...H.slice(-4),q]});const V=Z.duration||5e3;setTimeout(()=>i.setToasts(H=>H.filter(Y=>Y.id!==Z.id)),V)}),[i]);const f=((d==null?void 0:d.availableProviders)||[]).map(y=>({type:y.type,displayName:y.displayName,icon:y.icon,category:y.category})),u={};for(const y of f)u[y.type]=y.icon;const g=y=>u[y]||"",N=d?{id:d.id,hostname:Fs(d,{fallbackId:d.id}),platform:((D=d.machine)==null?void 0:D.platform)||"unknown",arch:((T=d.machine)==null?void 0:T.arch)||"",cpus:((R=d.machine)==null?void 0:R.cpus)||0,totalMem:(($=d.machine)==null?void 0:$.totalMem)||0,freeMem:((_=d.machine)==null?void 0:_.freeMem)||0,availableMem:(re=d.machine)==null?void 0:re.availableMem,loadavg:((b=d.machine)==null?void 0:b.loadavg)||[],uptime:((z=d.machine)==null?void 0:z.uptime)||0,release:((F=d.machine)==null?void 0:F.release)||"",cdpConnected:!!(d.ides||[]).some(y=>y.cdpConnected),machineNickname:d.machineNickname||null,p2p:d.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:d.detectedIdes||[],managedIdeIds:d.managedIdeIds||[],managedCliIds:d.managedCliIds||[],workspaces:d.workspaces||[],defaultWorkspaceId:d.defaultWorkspaceId??d.activeWorkspaceId??null,defaultWorkspacePath:d.defaultWorkspacePath??d.activeWorkspacePath??null,workspaceActivity:d.workspaceActivity||[]}:null,L=o.filter(y=>y.daemonId===s&&!y.daemonMode).filter(y=>!as(y)&&!os(y)).map(y=>({id:y.id,type:y.type,version:y.version||"",instanceId:y.instanceId||"",status:y.status,workspace:y.workspace||null,terminals:y.terminals||0,aiAgents:Qn(y.aiAgents||y.agents||[]),activeChat:y.activeChat||null,chats:y.chats||[],agentStreams:y.agentStreams||[],cdpConnected:y.cdpConnected||!1,daemonId:s})),v=o.filter(y=>y.daemonId===s&&as(y)).map(y=>({id:y.id,type:y.type,cliName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,daemonId:s})),w=o.filter(y=>y.daemonId===s&&os(y)).map(y=>({id:y.id,type:y.type,acpName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,currentModel:y.currentModel,currentPlan:y.currentPlan,daemonId:s}));if(!N)return c?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:()=>n("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const P=ut(d,{fallbackId:N.id}),B=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Mn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(nt,{size:14})," IDEs"]}),count:L.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(dt,{size:14})," CLIs"]}),count:v.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rs,{size:14})," ACP Agents"]}),count:w.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Vt,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Cn,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"dashboard-header !flex-col !items-stretch",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-2 md:gap-3.5 w-full min-w-0",children:[e.jsx("button",{onClick:()=>n("/machines"),className:"machine-btn-back flex shrink-0",children:"←"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[m.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:m.nicknameInput,onChange:y=>m.setNicknameInput(y.target.value),onKeyDown:y=>{y.key==="Enter"&&m.handleSaveNickname(),y.key==="Escape"&&m.setEditingNickname(!1)},placeholder:"Machine nickname...",className:"px-2.5 py-1 rounded-md border border-violet-500/30 bg-bg-secondary text-text-primary text-sm font-semibold w-[140px] md:w-[200px]"}),e.jsx("button",{onClick:m.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>m.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{m.setEditingNickname(!0),m.setNicknameInput(N.machineNickname||"")},title:"Click to set nickname",children:P}),e.jsx("span",{className:"status-dot-md online shrink-0"})]}),e.jsxs("div",{className:"header-subtitle mt-1 flex-wrap gap-1 md:gap-2 items-center display-none-mobile",children:[e.jsxs("span",{children:[N.platform," · ",N.arch," · ",N.cpus," cores"]}),(d==null?void 0:d.version)&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-bg-glass border border-border-subtle text-text-muted shrink-0",children:["v",d.version]}),(d==null?void 0:d.versionMismatch)&&e.jsxs("button",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-amber-500/[0.08] border border-amber-500/20 text-amber-400 cursor-pointer hover:bg-amber-500/[0.15] transition-colors shrink-0",onClick:async()=>{try{await a(s,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",d.serverVersion]}),N.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:N.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:N.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",N.p2p.state==="connected"?`● ${N.p2p.peers}`:"○"]}),N.cdpConnected&&e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-green-500/[0.08] text-green-500 shrink-0",children:"CDP ●"}),N.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",N.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:B.map(y=>e.jsxs("button",{onClick:()=>h(y.id),className:`machine-tab shrink-0${l===y.id?" active":""}`,children:[y.label,y.count!==void 0&&e.jsx("span",{className:"tab-count",children:y.count})]},y.id))})]}),e.jsxs("div",{className:"page-content",children:[l==="overview"&&e.jsx(sa,{machine:N,managedIdes:L,managedClis:v,managedAcps:w,actions:m}),l==="ides"&&e.jsx(Wt,{category:"ide",machine:N,machineId:s,providers:f,managedEntries:L,getIcon:g,actions:m,sendDaemonCommand:a}),l==="clis"&&e.jsx(Wt,{category:"cli",machine:N,machineId:s,providers:f,managedEntries:v,getIcon:g,actions:m}),l==="acps"&&e.jsx(Wt,{category:"acp",machine:N,machineId:s,providers:f,managedEntries:w,getIcon:g,actions:m}),l==="providers"&&e.jsx(ia,{machineId:s,providers:f,sendDaemonCommand:a}),l==="logs"&&e.jsx(ca,{machineId:s,sendDaemonCommand:a})]}),m.launchPick&&N&&e.jsx(la,{machine:N,launchPick:m.launchPick,actions:m}),e.jsx(Hs,{toasts:i.toasts||[],onDismiss:y=>i.setToasts(Z=>Z.filter(V=>V.id!==y)),onClickToast:y=>{y.ideId}}),e.jsx("style",{children:`
72
- @keyframes toast-in {
73
- from { opacity: 0; transform: translateX(40px); }
74
- to { opacity: 1; transform: translateX(0); }
75
- }
76
- `})]})}function ua(){const[t,s]=r.useState({ide:[],cli:[],ext:[],acp:[]}),[n,a]=r.useState(!0);r.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const d=[],l=[],h=[],x=[];Object.values(c.providers||{}).forEach(f=>{const u={name:f.name||"Unknown",status:f.status||"Stable",details:f.details||"Community Provider"};f.category==="ide"?d.push(u):f.category==="cli"?l.push(u):f.category==="extension"?h.push(u):f.category==="acp"&&x.push(u)});const m=(f,u)=>{const g={Stable:1,Beta:2,WIP:3},N=g[f.status]||99,L=g[u.status]||99;return N!==L?N-L:f.name.localeCompare(u.name)};s({ide:d.sort(m),cli:l.sort(m),ext:h.sort(m),acp:x.sort(m)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>a(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Ms,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):c==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(qt,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Beta"})]}):e.jsxs("div",{className:"flex items-center gap-1.5 text-text-muted",children:[e.jsx($s,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),o=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((d,l)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:d.name}),e.jsx("td",{className:"py-3 px-4",children:i(d.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:d.details})]},l))})]})});return n?e.jsx(Et,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Tt,{}),widthClassName:"max-w-5xl",children:e.jsx(Jt,{icon:e.jsx("div",{className:"w-8 h-8 border-4 border-accent border-t-transparent rounded-full animate-spin mx-auto"}),title:"Loading provider registry",description:"Fetching the latest support matrix from the shared provider registry."})}):e.jsxs(Et,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Tt,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(De,{title:"Registry overview",description:"Support status is loaded from the shared provider registry used across OSS and cloud surfaces.",children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"IDEs"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ide.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"CLI"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.cli.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"Extensions"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ext.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"ACP"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.acp.length})]})]})}),e.jsx(De,{title:"IDE support",icon:e.jsx(nt,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(De,{title:"Standalone CLI agents",icon:e.jsx(Gt,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(De,{title:"AI extensions",icon:e.jsx(dt,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(De,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(dt,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class xa{constructor(){$e(this,"adapters",new Map);$e(this,"states",new Map);$e(this,"ptyCallbacks",new Set);$e(this,"screenshotCallbacks",new Map);$e(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const n of this.adapters.keys())if(n.startsWith("standalone"))return n}return null}register(s,n){this.adapters.set(s,n),this.states.set(s,n.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,n){this.states.set(s,n)}retryConnection(s){}get(s){const n=this.resolveDaemonId(s);return n?this.adapters.get(n):void 0}getState(s){const n=this.resolveDaemonId(s);return n&&this.states.get(n)||"disconnected"}sendData(s,n){return!1}sendPtyInput(s,n,a){return!1}sendPtyResize(s,n,a,i){return!1}async requestChatHistory(s,n,a,i,o){return{messages:[],hasMore:!1}}onScreenshot(s,n){return this.screenshotCallbacks.set(s,n),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,n){this.screenshotCallbacks.forEach(a=>a(s,n))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,n){this.statusCallbacks.forEach(a=>a(s,n))}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,n){this.ptyCallbacks.forEach(a=>a(s,n))}}const Je=new xa;function pa(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,a=new URLSearchParams(window.location.search).get("token");return a?`${s}?token=${encodeURIComponent(a)}`:s}const gs=pa(),bs=3e3,ma=3e4;let Ze=null,ha=0;const At=new Map;let at=null,gt=null;async function Mt(t,s,n){const a=Ze;if(a&&a.readyState===WebSocket.OPEN){const o=`req_${++ha}_${Date.now()}`;return new Promise((c,d)=>{const l=setTimeout(()=>{At.delete(o),d(new Error(`WS command timeout: ${s}`))},3e4);At.set(o,{resolve:h=>{clearTimeout(l),c(h)},reject:h=>{clearTimeout(l),d(h)}}),a.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:n||{},target:t}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:n||{},target:t})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class fa{constructor(s){$e(this,"daemonId");$e(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ze==null?void 0:Ze.readyState)===WebSocket.OPEN}get connectionState(){return(Ze==null?void 0:Ze.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return Mt(this.daemonId,s,n)}async sendInput(s,n){const a=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId;return Mt(a,"cdp_remote_action",{action:s,params:n})}startScreenshots(s){this.screenshotIdeType=s||null,at&&(clearInterval(at),at=null);const n=async()=>{if(this.hasCommandChannel)try{const a=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId,i=await Mt(a,"screenshot",{width:1280});if(i!=null&&i.success&&(i!=null&&i.base64)){const o=await fetch(`data:image/jpeg;base64,${i.base64}`).then(c=>c.blob());Je.emitScreenshot(this.daemonId,o)}}catch{}};n(),at=setInterval(n,2e3)}stopScreenshots(s){at&&(clearInterval(at),at=null)}}let tt=null;function ga(t){return(!tt||tt.daemonId!==t)&&(tt=new fa(t)),tt}function ba({children:t}){const s=r.useRef(ts()),n=ts();s.current=n;const{setUserName:a}=bt(),i=r.useRef(a);i.current=a;const[,o]=r.useState("disconnected"),c=r.useCallback((m,f)=>{o(m),gt==null||gt(m,f)},[]),d=r.useRef(null),l=r.useRef(),h=r.useRef(bs),x=r.useRef(!0);return r.useEffect(()=>{x.current=!0;function m(){var g,N;if(!x.current||((g=d.current)==null?void 0:g.readyState)===WebSocket.OPEN||((N=d.current)==null?void 0:N.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${gs}...`);let u;try{u=new WebSocket(gs)}catch(L){console.error("[Standalone WS] Failed to create WebSocket:",L),f();return}d.current=u,u.onopen=()=>{if(!x.current){u.close();return}c("connected"),h.current=bs,console.log("[Standalone WS] Connected")},Ze=u,u.onmessage=L=>{var v;try{const w=JSON.parse(L.data);if((w.type==="command_result"||w.type==="error")&&w.requestId){const P=At.get(w.requestId);P&&(At.delete(w.requestId),w.type==="error"?P.reject(new Error(((v=w.data)==null?void 0:v.message)||"Command failed")):P.resolve(w.data));return}if(w.type==="pty_output"){Je.emitPtyOutput(w.cliId,w.data);return}if(w.type==="status"||w.type==="initial_state"){const P=w.data;if(!P)return;const{injectEntries:B,markLoaded:D}=s.current,T=P.id||"standalone",R=ga(T);Je.register(T,R),Je.setState(T,"connected"),c("connected",T),Je.emitStatus(T,P);const $=nr(P,{daemonId:T});$.length>0&&B($),D(),P.userName&&i.current&&i.current(P.userName)}}catch(w){console.error("[Standalone WS] Parse error:",w)}},u.onclose=()=>{x.current&&(tt&&Je.setState(tt.daemonId,"disconnected"),c("disconnected"),d.current=null,f())},u.onerror=L=>{console.warn("[Standalone WS] Error, will reconnect:",L)}}function f(){if(!x.current)return;clearTimeout(l.current);const u=h.current;console.log(`[Standalone WS] Reconnecting in ${u}ms...`),l.current=setTimeout(()=>{h.current=Math.min(h.current*1.5,ma),m()},u)}return m(),()=>{x.current=!1,clearTimeout(l.current),d.current&&(d.current.onclose=null,d.current.close(),d.current=null,Ze=null),tt&&Je.unregister(tt.daemonId)}},[]),e.jsx(e.Fragment,{children:t})}function ya({children:t}){const[s,n]=r.useState("disconnected"),[a,i]=r.useState(null);r.useEffect(()=>(gt=(c,d)=>{n(c),d&&i(d)},()=>{gt=null}),[]);const o=r.useMemo(()=>{const c=s==="connected",d={};return a&&(d[a]=c?"connected":"connecting"),d.standalone=c?"connected":"connecting",{wsStatus:s,isConnected:c,connectionStates:d}},[s,a]);return e.jsx(bn,{connectionOverrides:o,children:e.jsx(ba,{children:t})})}const ja=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Ss,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Cs,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Vt,{}),label:"Settings"}];function va({children:t}){const s=jt(),n=dn(),[a,i]=r.useState(!1),[o,c]=r.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),d=x=>{s(x),i(!1)},l=()=>{c(x=>{const m=!x;try{localStorage.setItem("sidebar-collapsed",m?"1":"0")}catch{}return m})},h=x=>`nav-item${n.pathname.startsWith(x)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${a?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),a&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:x=>x.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${a?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:ja.map(x=>e.jsxs("div",{className:h(x.path),id:`nav-${x.id}`,onClick:()=>d(x.path),title:o?x.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:x.icon}),!o&&x.label]},x.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Tt,{})}),!o&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${n.pathname==="/about"?" active":""} ${o?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:o?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Is,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.6.79"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:o?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:o?"›":"‹"}),!o&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const wa=[{icon:e.jsx(Cs,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(lt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(As,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(nt,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(dt,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Tt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Na=[{icon:e.jsx(_s,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Ss,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Ps,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Sn,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Nn,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Ms,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],ka=[{feature:"Agent chat relay",selfhost:!0,cloud:!0},{feature:"Live IDE screenshots",selfhost:!0,cloud:!0},{feature:"Remote IDE control",selfhost:!0,cloud:!0},{feature:"Multi-IDE monitoring",selfhost:!0,cloud:!0},{feature:"Extension and CLI agents",selfhost:!0,cloud:!0},{feature:"Access from any network",selfhost:!1,cloud:!0},{feature:"WebRTC P2P streaming",selfhost:!1,cloud:!0},{feature:"Mobile push notifications",selfhost:!1,cloud:!0},{feature:"REST API and webhooks",selfhost:!1,cloud:!0},{feature:"Team collaboration",selfhost:!1,cloud:!0},{feature:"Multi-machine burrows",selfhost:!1,cloud:!0},{feature:"SSO, RBAC, audit logs",selfhost:!1,cloud:!0}];function Sa(){return e.jsxs(Et,{icon:e.jsx(Is,{className:"text-text-primary"}),title:"About",subtitle:"Self-hosted ADHDev overview, supported surfaces, and what changes in Cloud",widthClassName:"max-w-5xl",actions:e.jsxs("div",{className:"px-3 py-1 text-[11px] font-semibold tracking-wide rounded-full bg-emerald-500/10 text-emerald-500 border border-emerald-500/20",children:["SELFHOST v","0.6.79"]}),children:[e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"text-[11px] font-semibold tracking-[0.18em] uppercase text-emerald-400 mb-2",children:"Self-hosted edition"}),e.jsx("h2",{className:"text-2xl font-semibold tracking-tight text-text-primary mb-2",children:"Keep the same dashboard experience, with the runtime fully on-device."}),e.jsx("p",{className:"text-sm text-text-muted leading-relaxed",children:"Standalone keeps the browser, daemon, screenshots, and control path on your own machine. It is the same core product shape as cloud, just without the remote networking and team layers."})]}),e.jsxs("div",{className:"grid gap-2 min-w-[220px]",children:[e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"Docs ↗"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"GitHub ↗"}),e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex justify-center no-underline",children:"Try Cloud ↗"})]})]})}),e.jsx(De,{title:"Included in standalone",description:"The local-first feature set available without the cloud control plane.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:wa.map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4 transition-colors hover:border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-accent/10 text-accent-light",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(De,{title:"Compatible with",description:"Supported editors and agent surfaces exposed in the standalone dashboard.",children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{label:"IDEs",items:Us.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Xs.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:Ys.map(t=>`${t.icon} ${t.name}`)}].map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4",children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-3 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1.5",children:t.items.map(s=>e.jsx("div",{className:"rounded-md border border-border-subtle bg-bg-card px-2.5 py-1.5 text-[12px] text-text-secondary",children:s},s))})]},t.label))})}),e.jsx(De,{title:"Cloud-only extras",description:"Capabilities that need the hosted control plane or team infrastructure.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Na.map(t=>e.jsxs("div",{className:"rounded-xl border border-violet-500/20 bg-violet-500/[0.04] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-violet-500/10 text-violet-400",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(De,{title:"Self-hosted vs Cloud",description:"The product split at a glance.",children:e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border-subtle",children:e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary",children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[110px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-violet-400 text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:ka.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"bg-transparent",children:[e.jsx("td",{className:"px-4 py-2.5 text-text-secondary",children:t.feature}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:t.selfhost?e.jsx("span",{className:"text-emerald-500",children:"✓"}):e.jsx("span",{className:"text-text-muted opacity-40",children:"—"})}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})}),e.jsx(Jt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"mx-auto h-12 w-12 opacity-80"}),title:"Cloud is optional, not required",description:"You can stay fully local in standalone, and move to cloud later without changing how you use the dashboard.",action:e.jsxs("div",{className:"flex flex-wrap justify-center gap-3",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm no-underline",children:"Compare Cloud ↗"}),e.jsxs("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm no-underline",children:[e.jsx(Rn,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Ca(){const{ides:t}=bt(),s=t.find(m=>m.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:a}=st(),{userName:i}=bt(),[o,c]=r.useState(i||"");r.useEffect(()=>{i!==void 0&&c(i)},[i]);const d=m=>{const f=m.target.value.trim();s!=null&&s.id&&f!==i&&a(s.id,"set_user_name",{userName:f}).catch(console.error)},[l,h]=r.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),x=m=>{h(m);try{localStorage.setItem("adhdev_sound",m?"1":"0")}catch{}};return e.jsxs(Et,{icon:e.jsx(Vt,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(br,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(De,{title:"Daemon",description:"Connection health and local endpoints for the self-hosted runtime.",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-x-4 gap-y-2.5 text-sm",children:[e.jsx("span",{className:"text-text-muted",children:"Version"}),e.jsxs("span",{className:"font-mono text-xs",children:["v","0.6.79"]}),e.jsx("span",{className:"text-text-muted",children:"Status"}),e.jsx("span",{className:s?"text-green-400":"text-yellow-400",children:s?"● Running":"○ Not connected"}),e.jsx("span",{className:"text-text-muted",children:"WebSocket"}),e.jsx("span",{className:"font-mono text-xs",children:"ws://localhost:19222"}),e.jsx("span",{className:"text-text-muted",children:"HTTP"}),e.jsx("span",{className:"font-mono text-xs",children:"http://localhost:19280"})]})}),e.jsx(De,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:n.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:n.map(m=>e.jsxs("div",{className:"flex justify-between items-center bg-bg-glass rounded-lg px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:`w-2 h-2 rounded-full ${m.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:m.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:m.type})]},m.type))})}),e.jsx(De,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Sr,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(De,{title:"Appearance",description:"Match the rest of the dashboard with a single place for mode, theme, and accent.",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Mode"}),e.jsx(Tr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Theme"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Choose a preset or create a custom surface and chat palette for the standalone UI."}),e.jsx(Pr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Accent color override"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Override preset accents without changing your full theme definition."}),e.jsx(zr,{})]})]})}),e.jsx(De,{title:"Notifications",description:"Browser prompts and local sound cues for agent activity.",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(kr,{}),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_n,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:x})]})}),e.jsx(De,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(kn,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:m=>c(m.target.value),onBlur:d,onKeyDown:m=>{m.key==="Enter"&&m.currentTarget.blur()}})]})})})]})}_r();function ys(){const{ides:t}=bt(),s=t.find(n=>{var a;return n.daemonMode||((a=n.id)==null?void 0:a.startsWith("standalone"))});return s?e.jsx(kt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(kt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(kt,{to:"/dashboard",replace:!0})}function Ia(){return e.jsx(un,{children:e.jsx(ya,{children:e.jsx(wn,{value:{sendCommand:Mt,sendData:()=>!1},children:e.jsx(va,{children:e.jsxs(xn,{children:[e.jsx(qe,{path:"/dashboard",element:e.jsx(Zr,{})}),e.jsx(qe,{path:"/ide/:id",element:e.jsx(ea,{})}),e.jsx(qe,{path:"/machine",element:e.jsx(ys,{})}),e.jsx(qe,{path:"/machines/:id",element:e.jsx(da,{})}),e.jsx(qe,{path:"/machines",element:e.jsx(ys,{})}),e.jsx(qe,{path:"/capabilities",element:e.jsx(ua,{})}),e.jsx(qe,{path:"/about",element:e.jsx(Sa,{})}),e.jsx(qe,{path:"/settings",element:e.jsx(Ca,{})}),e.jsx(qe,{path:"*",element:e.jsx(kt,{to:"/dashboard",replace:!0})})]})})})})})}Un({connectionManager:Je,p2pManager:Je});pn(document.getElementById("root")).render(e.jsx(r.StrictMode,{children:e.jsx(Ia,{})}));