@adhdev/daemon-standalone 0.6.68 → 0.6.70

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.
@@ -0,0 +1,71 @@
1
+ var Qs=Object.defineProperty;var en=(t,s,n)=>s in t?Qs(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Ee=(t,s,n)=>en(t,typeof s!="symbol"?s+"":s,n);import{r,j as e,M as es,a as ts,b as tn,c as sn,u as kt,t as nn,d as rn,e as an,f as ws,R as on,g as Ns,h as cn,B as ln,i as dn,k as qe,N as Mt,l as un}from"./vendor-tc3018Wt.js";import{D as xn,o as pn,L as mn}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 ks=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}),Ss=r.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function ss(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 hn(t,s){var c,x,d,m,l,u,b;const n=Date.now();if(s.length===0)return t.map(h=>({...h,_lastUpdate:n}));const a=new Map;for(const h of s)a.set(h.id,h);for(const h of t){const p=a.get(h.id);if(!p){a.set(h.id,{...h,_lastUpdate:n});continue}const _=ss(h),P=ss(p);if(_>P){const w=(c=h.chats)!=null&&c.length?h.chats:p.chats;a.set(h.id,{...p,...h,chats:w,_lastUpdate:n})}else if(_<P){const w={};h.status&&h.status!==p.status&&(w.status=h.status),h.cdpConnected!==void 0&&(w.cdpConnected=h.cdpConnected),(x=h.chats)!=null&&x.length&&!((d=p.chats)!=null&&d.length)&&(w.chats=h.chats),h.machineNickname!==void 0&&h.machineNickname!==p.machineNickname&&(w.machineNickname=h.machineNickname),Object.keys(w).length>0&&a.set(h.id,{...p,...w,_lastUpdate:p._lastUpdate})}else{const w=h.timestamp||n,N=p._lastUpdate||p.timestamp||0;if(w>=N){const W=(m=h.chats)!=null&&m.length?h.chats:p.chats;a.set(h.id,{...p,...h,chats:W,_lastUpdate:n})}else(l=h.chats)!=null&&l.length&&!((u=p.chats)!=null&&u.length)&&a.set(h.id,{...p,chats:h.chats})}}const i=new Set(t.map(h=>h.id)),o=new Set;for(const h of t){const p=h.daemonId||((b=h.id)==null?void 0:b.split(":")[0]);p&&o.add(p)}for(const[h,p]of a){const _=p.daemonId||h.split(":")[0];if(!o.has(_))continue;const P=n-(p._lastUpdate||p.timestamp||0);(h.includes(":cli:")&&!i.has(h)&&P>1e4||h.includes(":acp:")&&!i.has(h)&&P>1e4||h.includes(":ide:")&&!i.has(h)&&P>3e4)&&a.delete(h)}for(const[h,p]of a)n-(p._lastUpdate||p.timestamp||0)>3e5&&p.status!=="online"&&a.delete(h);return Array.from(a.values())}function fn({children:t,connectionOverrides:s}){const[n,a]=r.useState([]),[i,o]=r.useState({}),[c,x]=r.useState(!1),[d,m]=r.useState([]),[l,u]=r.useState(void 0),b=r.useCallback((_,P)=>{a(w=>w.map(N=>N.id===_?{...N,chats:P}:N))},[]),h={injectEntries:_=>{a(P=>P.length===0?_:hn(_,P))},markLoaded:()=>x(!0),getIdes:()=>n},p=s;return e.jsx(Ss.Provider,{value:h,children:e.jsx(ks.Provider,{value:{ides:n,updateIdeChats:b,screenshotMap:i,setScreenshotMap:o,initialLoaded:c,toasts:d,setToasts:m,wsStatus:(p==null?void 0:p.wsStatus)??"connected",isConnected:(p==null?void 0:p.isConnected)??!0,connectionStates:(p==null?void 0:p.connectionStates)??{},connectionTransports:(p==null?void 0:p.connectionTransports)??{},showReconnected:(p==null?void 0:p.showReconnected)??!1,retryConnection:p==null?void 0:p.retryConnection,isP2PActive:(p==null?void 0:p.isP2PActive)??!1,p2pStates:(p==null?void 0:p.p2pStates)??{},userRole:p==null?void 0:p.userRole,userName:l,setUserName:u},children:t})})}function jt(){return r.useContext(ks)}function ns(){return r.useContext(Ss)}function gn(t){const{baseUrl:s,getToken:n,onUnauthorized:a}=t;async function i(o,c={}){const x={"Content-Type":"application/json",...c.headers||{}},d=n==null?void 0:n();d&&(x.Authorization=`Bearer ${d}`);const m=o.startsWith("http")?o:`${s}${o.startsWith("/")?"":"/"}${o}`,l=await fetch(m,{...c,headers:x});if(l.status===401)throw a==null||a(),new Error("Unauthorized");if(!l.ok){const u=await l.json().catch(()=>({error:l.statusText}));throw new Error(u.error||`API Error: ${l.status}`)}return l.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:o=>i(`/api/v1/daemons/${o}/status`),sendCommand:(o,c,x={})=>i(`/api/v1/daemons/${o}/command`,{method:"POST",body:JSON.stringify({type:c,payload:x})}),execTerminal:(o,c,x)=>i(`/api/v1/daemons/${o}/terminal`,{method:"POST",body:JSON.stringify({command:c,name:x})}),sendAgentMessage:(o,c,x)=>i(`/api/v1/shortcuts/${o}/chat`,{method:"POST",body:JSON.stringify({agentType:c,message:x})}),getAgentStatus:o=>i(`/api/v1/shortcuts/${o}/status`),approveAgent:(o,c,x)=>i(`/api/v1/shortcuts/${o}/approve`,{method:"POST",body:JSON.stringify({agentType:c,action:x?"approve":"reject"})}),request:i}}const bn=gn({baseUrl:"http://localhost:3847"});r.createContext(bn);const yn={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Cs=r.createContext(yn);function jn({value:t,children:s}){return e.jsx(Cs.Provider,{value:t,children:s})}function nt(){return r.useContext(Cs)}const we={size:18};function Is({size:t=we.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 Ms({size:t=we.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 vn({size:t=we.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 wn({size:t=we.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 Nn({size:t=we.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 vt({size:t=we.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 kn({size:t=we.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 Gt({size:t=we.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 Ts({size:t=we.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 Es({size:t=we.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 wt({size:t=we.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 rt({size:t=we.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 Sn({size:t=we.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 Cn({size:t=we.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 Ft({size:t=we.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 As({size:t=we.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 Jt({size:t=we.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 ut({size:t=we.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 $s({size:t=we.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=we.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 In({size:t=we.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 Zt({size:t=we.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 Rs({size:t=we.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 Ps({size:t=we.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 Mn({size:t=we.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 Tn({size:t=we.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 Ls({size:t=we.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 En({size:t=we.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 An({size:t=we.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=we.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 _n(t){const n=t.split(`
2
+ `).map(x=>{if(!x.includes("\r"))return x;const d=x.split("\r").map(u=>u.trim()).filter(Boolean);if(d.length===0)return"";const m=d.filter(u=>u.startsWith("⏺"));if(m.length>0)return m[m.length-1];const l=d.filter(u=>!(/^[❯›>]\s*$/.test(u)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(u)&&u.length<40||/^[╭╰│├╮╯─═]+$/.test(u)));return l.length>0?l[l.length-1]:d[d.length-1]}).join(`
3
+ `).split(`
4
+ `),a={},i=[];let o=!1;for(const x of n){const d=x.trim();if(d===""){o=!1,i.push("");continue}if(/^❯\s*$/.test(d)||/^>\s*$/.test(d)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(d)||/^◐\s/.test(d)||/\/effort/.test(d)||/^⎿\s+(Tip|Note|Hint):/.test(d)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(d)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(d)||/Brewing[…\.]{0,3}\s*\d*$/i.test(d)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(d)||/^Auto-updating/i.test(d))continue;if(/^[⏺●·⏵]/.test(x)){const l=x.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(l)a[l[1]]=(a[l[1]]||0)+1;else{const u=x.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);u&&(a[u]=(a[u]||0)+1)}o=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(x)||/^[╭╰│├╮╯─]+/.test(d)||/^\s+[⊙✓✗○◎▸►✦]/.test(x)||o&&/^\s{2,}/.test(x))continue;o=!1;const m=x.replace(/^❯\s+/,"");i.push(m)}const c=i.join(`
5
+ `).replace(/\n{3,}/g,`
6
+
7
+ `).trim();return{toolCounts:a,textContent:c,hasTools:Object.keys(a).length>0}}function Dt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}const Rn=r.forwardRef(function({messages:s,actionLogs:n,agentName:a="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:x="",receivedAtMap:d={},emptyState:m,onLoadMore:l,isLoadingMore:u,hasMoreHistory:b,loadError:h},p){var J;const _=r.useRef(null),P=r.useRef(null),w=r.useRef(0),N=r.useRef(""),W=r.useRef(!1),[O,A]=r.useState(new Set),[v,B]=r.useState(new Set),I=r.useRef(!1),y=()=>{const X=_.current;return X?X.scrollHeight-X.scrollTop-X.clientHeight<200:!0},se=s.length>0?`${s.length}:${(((J=s[s.length-1])==null?void 0:J.content)||"").length}`:"0:0";r.useEffect(()=>{var ce,ne;const X=!W.current,q=N.current!==x;if(N.current=x,X||q){W.current=!0,I.current=!1;const le=()=>{var xe;(xe=P.current)==null||xe.scrollIntoView({behavior:"instant"})};requestAnimationFrame(()=>requestAnimationFrame(le)),setTimeout(le,100),setTimeout(le,300),w.current=s.length;return}s.length>w.current?I.current||(ce=P.current)==null||ce.scrollIntoView({behavior:"instant"}):y()&&!I.current&&((ne=P.current)==null||ne.scrollIntoView({behavior:"instant"})),w.current=s.length},[se,x,c]),r.useImperativeHandle(p,()=>({scrollToBottom:(X="smooth")=>{var q;(q=P.current)==null||q.scrollIntoView({behavior:X})}})),r.useEffect(()=>{const X=_.current;if(!X)return;let q;const G=()=>{clearTimeout(q),q=setTimeout(()=>{I.current=!y()},50)};return X.addEventListener("scroll",G,{passive:!0}),()=>{X.removeEventListener("scroll",G),clearTimeout(q)}},[]);const R=r.useRef(0),F=r.useRef(!1);r.useEffect(()=>{const X=_.current;if(!X||!F.current||R.current===0)return;const q=X.scrollHeight-R.current;q>0&&(X.scrollTop=q),R.current=0,F.current=!1},[s.length]);const j=()=>{const X=_.current;X&&(R.current=X.scrollHeight),F.current=!0,l==null||l()},H=(()=>{const X=s.map((ne,le)=>({type:"message",data:ne,index:le,ts:ne.receivedAt||d[ne.id??`i-${le}`]||0}));if(!n||n.length===0)return X;const q=[...n].sort((ne,le)=>ne.timestamp-le.timestamp).map((ne,le)=>({type:"action",data:ne,index:le,ts:ne.timestamp})),G=[];let ce=0;for(const ne of X){for(;ce<q.length&&ne.ts>0&&q[ce].ts<ne.ts;)G.push(q[ce++]);G.push(ne)}for(;ce<q.length;)G.push(q[ce++]);return G})(),ie=700;return e.jsxs("div",{ref:_,"data-chat-scroll":!0,className:"chat-container",children:[u&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),b&&!u&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:j,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${h?"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:h?`↻ ${h}`:"↑ Load older messages"})}),H.length===0&&!b&&(m||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),H.map(X=>{var ye;if(X.type==="action"){const pe=X.data;return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(es,{remarkPlugins:[ts],children:pe.text}),e.jsx("span",{className:"action-time",children:Dt(pe.timestamp)})]},`action-${X.index}`)}const q=X.data,G=X.index,ce=(q.role||"").toLowerCase(),ne=ce==="user"||ce==="human",le=q.kind||(ce==="tool"?"tool":"standard"),xe=q.receivedAt||d[q.id??`i-${G}`],K=`${x}-${G}`,g=O.has(K),L=v.has(K),f=typeof q.content=="string"?q.content:(q.content||[]).map(pe=>pe.text||"").join(`
8
+ `);if(le==="thought"){const pe=((ye=q.meta)==null?void 0:ye.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Mn,{size:13}),e.jsx("span",{children:pe})]}),e.jsx("div",{className:"chat-msg-body",children:f})]},`msg-${G}`)}if(le==="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:f.split(`
9
+ `)[0].slice(0,80)})]},`msg-${G}`);if(le==="terminal"){const pe=q.meta||{},E=pe.isRunning?"⏳":"✅",me=pe.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:E}),e.jsx("span",{children:me})]}),e.jsx("pre",{className:"chat-msg-body",children:f})]},`msg-${G}`)}if(le==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:f.slice(0,100)},`msg-${G}`);const z=!ne&&o?_n(f):null,U=z?z.textContent:f,te=z?Object.entries(z.toolCounts):[],ke=o&&!ne&&!g&&U.length>ie,Ne=g?f:ke&&!L?U.slice(0,ie):U;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${ne?"self-end":"self-start"}`,children:[te.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[te.map(([pe,E])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",pe,E>1?` ×${E}`:""]},pe)),(z==null?void 0:z.hasTools)&&e.jsx("button",{onClick:()=>A(pe=>{const E=new Set(pe);return g?E.delete(K):E.add(K),E}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:g?"Collapse":"Original"}),!U&&xe!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Dt(xe)})]}),(U||ne)&&e.jsxs("div",{className:`chat-bubble ${ne?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${U?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:ne?i||"You":a}),xe!=null&&e.jsx("span",{className:"chat-time",children:Dt(xe)})]}),U&&e.jsx("div",{className:"chat-markdown",children:e.jsx(es,{remarkPlugins:[ts,tn,sn],children:Ne})}),ke&&e.jsx("button",{onClick:()=>B(pe=>{const E=new Set(pe);return L?E.delete(K):E.add(K),E}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:L?"Collapse ↑":`Show more (${Math.round(U.length/100)*100} chars) ↓`})]})]},`msg-${G}`)}),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 working..."})]})}),e.jsx("div",{className:"min-h-10",ref:P})]})}),rs={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"},Ds=r.forwardRef(({onInput:t,onResize:s,fontSize:n=13},a)=>{const i=r.useRef(null),o=r.useRef(null),c=r.useRef(null),[x,d]=r.useState(!1);return r.useImperativeHandle(a,()=>({write:m=>{var l;(l=o.current)==null||l.write(m)},clear:()=>{var m;(m=o.current)==null||m.clear()},fit:()=>{var m;try{(m=c.current)==null||m.fit(),o.current&&(s==null||s(o.current.cols,o.current.rows))}catch{}},bumpResize:()=>{var m;try{(m=c.current)==null||m.fit();const l=o.current;if(!l)return;const u=l.cols,b=l.rows;s==null||s(u+5,b),setTimeout(()=>{s==null||s(u,b)},100)}catch{}}})),r.useEffect(()=>{if(!i.current)return;const m=new xn({cursorBlink:!0,cursorStyle:"bar",fontSize:n,fontFamily:"'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace",fontWeight:"400",letterSpacing:0,lineHeight:1.2,theme:rs,allowTransparency:!0,scrollback:5e3,convertEol:!1}),l=new pn,u=new mn;m.loadAddon(l),m.loadAddon(u),m.open(i.current),requestAnimationFrame(()=>{l.fit(),s==null||s(m.cols,m.rows),d(!0)});const b=m.onData(p=>{t(p)}),h=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{l.fit(),s==null||s(m.cols,m.rows)}catch{}})});return h.observe(i.current),o.current=m,c.current=l,()=>{b.dispose(),h.disconnect(),m.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:rs.background,opacity:x?1:0}})});Ds.displayName="CliTerminal";function St({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 as({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,x=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:x}})})]}):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, ${x}, ${x}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function Pn({onAction:t,addLog:s,connState:n,connScreenshot:a,screenshotUsage:i,transportType:o}){const c=r.useRef(null),x=r.useRef(null),d=r.useRef(null),[m,l]=r.useState(null),[u,b]=r.useState(""),[,h]=r.useState(!1),[p,_]=r.useState([]),P=r.useRef(0),[w,N]=r.useState(!1),[W,O]=r.useState(!1),A=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[v,B]=r.useState(A?"mouse":"touch"),[I,y]=r.useState(1),se=r.useRef(!1),[R,F]=r.useState(1),[j,H]=r.useState(0),[ie,J]=r.useState(0),X=r.useRef(0),q=r.useRef(t),G=r.useRef(null),ce=r.useRef(null),ne=r.useRef(!1),le=r.useRef(null),xe=r.useRef(0),K=r.useRef(null),g=r.useRef(1),L=r.useRef({x:0,y:0}),f=r.useRef(!1),z=r.useRef(R),U=r.useRef(j),te=r.useRef(ie),ke=r.useRef(v);r.useEffect(()=>{z.current=R},[R]),r.useEffect(()=>{U.current=j},[j]),r.useEffect(()=>{te.current=ie},[ie]),r.useEffect(()=>{q.current=t},[t]),r.useEffect(()=>{ke.current=v},[v]),r.useEffect(()=>{var M;(M=c.current)==null||M.focus()},[]);const Ne=n==="connected",ye=a,pe=Ne?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",E=Ne?"The remote stream is warming up":"Waiting for the remote stream to catch up";r.useEffect(()=>{if(!A||se.current||!ye)return;const M=d.current,re=x.current;if(!M||!re)return;const Q=()=>{const be=re.clientWidth,ve=re.clientHeight,k=M.naturalWidth,Z=M.naturalHeight;if(!k||!Z||!be||!ve)return;const D=Math.min(be/k,ve/Z),Y=Math.max(be/k,ve/Z)/D;Y>1.01&&(y(Y),F(Y),z.current=Y),se.current=!0};M.complete&&M.naturalWidth?Q():M.addEventListener("load",Q,{once:!0})},[ye,A]);const me=.5;r.useEffect(()=>{R<=me&&(H(0),J(0))},[R,me]);const ge=(M,re,Q)=>{if(Q<=me)return{x:0,y:0};const be=(Q-1)/(2*Q)*100,ve=(Q-1)/(2*Q)*100;return{x:Math.max(-be,Math.min(be,M)),y:Math.max(-ve,Math.min(ve,re))}},fe=(M,re)=>{if(!d.current)return null;const Q=d.current.getBoundingClientRect();return!Q.width||!Q.height?null:{nx:Math.max(0,Math.min(1,(M-Q.left)/Q.width)),ny:Math.max(0,Math.min(1,(re-Q.top)/Q.height))}},Ce=(M,re,Q)=>{const be=x.current;if(!be)return;const ve=be.getBoundingClientRect(),k=++P.current;_(Z=>[...Z,{id:k,x:M-ve.left,y:re-ve.top,type:Q}]),setTimeout(()=>_(Z=>Z.filter(D=>D.id!==k)),600)},Me=(M,re,Q)=>{const be=d.current,ve=x.current;if(!be||!ve)return;const k=be.getBoundingClientRect(),Z=ve.getBoundingClientRect(),D=be.naturalWidth||k.width,ue=be.naturalHeight||k.height,Y=D/ue,ee=k.width/k.height;let de,V,he,Se;Y>ee?(de=k.width,V=k.width/Y,he=0,Se=(k.height-V)/2):(V=k.height,de=k.height*Y,he=(k.width-de)/2,Se=0);const Ie=k.left-Z.left+he+de*M,$e=k.top-Z.top+Se+V*re,We=++P.current;_(_e=>[..._e,{id:We,x:Ie,y:$e,type:Q}]),setTimeout(()=>_(_e=>_e.filter(S=>S.id!==We)),600)},et=async M=>{var Q;const re=fe(M.clientX,M.clientY);if(re){l(`Click: ${Math.round(re.nx*100)}%, ${Math.round(re.ny*100)}%`),Ce(M.clientX,M.clientY,"left"),(Q=c.current)==null||Q.focus();try{const be=await t("input_click",{nx:re.nx,ny:re.ny});be!=null&&be.success||s(`❌ Click failed: ${be==null?void 0:be.error}`)}catch(be){s(`❌ Click error: ${be.message||be}`)}}},ze=async(M,re,Q,be=0)=>{try{await t("input_key",{type:Q?"char":"keyDown",key:M,code:re,text:Q?M:void 0,unmodifiedText:Q?M:void 0,modifiers:be})}catch(ve){s(`❌ Key error: ${ve.message||ve}`)}},Pe=async M=>{if(M.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(M.key)&&M.preventDefault();let Q=0;M.altKey&&(Q|=1),M.ctrlKey&&(Q|=2),M.metaKey&&(Q|=4),M.shiftKey&&(Q|=8),l(`Key: ${M.key}`),await ze(M.key,M.code,M.key.length===1,Q)},pt=async M=>{if(M.key==="Enter"){if(M.nativeEvent.isComposing)return;if(u){const re=u;b(""),l(`IME Sent: ${re}`);try{const Q=await t("input_type",{text:re});Q!=null&&Q.success||s(`❌ IME error: ${Q==null?void 0:Q.error}`)}catch(Q){s(`❌ IME error: ${Q.message}`)}}else l("Key: Enter"),await ze("Enter","Enter",!1)}};r.useEffect(()=>{const M=c.current;if(!M)return;const re=Q=>{var be;if((be=d.current)!=null&&be.contains(Q.target)){Q.preventDefault();const ve=Date.now();if(ve-X.current<40)return;X.current=ve;const k=fe(Q.clientX,Q.clientY);if(!k)return;l(`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 M.addEventListener("wheel",re,{passive:!1}),()=>M.removeEventListener("wheel",re)},[t]);const[Ke,Ye]=r.useState(null),Ae=r.useRef(null);return r.useEffect(()=>{if(v==="mouse"&&!Ae.current){const M={nx:.5,ny:.5};Ae.current=M,Ye(M)}},[v]),r.useEffect(()=>{const M=c.current;if(!M)return;const re=D=>{if(!d.current)return null;const ue=d.current.getBoundingClientRect();return!ue.width||!ue.height?null:{nx:Math.max(0,Math.min(1,(D.clientX-ue.left)/ue.width)),ny:Math.max(0,Math.min(1,(D.clientY-ue.top)/ue.height))}},Q=(D,ue)=>{if(!d.current)return{dnx:0,dny:0};const Y=d.current,ee=Y.getBoundingClientRect(),de=Y.naturalWidth||ee.width,V=Y.naturalHeight||ee.height,he=de/V,Se=ee.width/ee.height;let Ie,$e;return he>Se?(Ie=ee.width,$e=ee.width/he):($e=ee.height,Ie=ee.height*he),{dnx:D/Ie,dny:ue/$e}},be=(D,ue,Y)=>{if(Y<=1.05)return;const ee=-(D-.5)*100,de=-(ue-.5)*100,V=ge(ee,de,Y);(Math.abs(V.x-U.current)>.1||Math.abs(V.y-te.current)>.1)&&(H(V.x),J(V.y),U.current=V.x,te.current=V.y)},ve=D=>{const ue=x.current;if(ue&&D.target instanceof Node&&ue.contains(D.target))D.preventDefault();else return;if(D.touches.length===1){const Y=D.touches[0];G.current={x:Y.clientX,y:Y.clientY,time:Date.now()},ce.current={x:Y.clientX,y:Y.clientY},f.current||(ne.current=!1),le.current=setTimeout(()=>{if(!ne.current&&!f.current)if(ne.current=!0,ke.current==="mouse"){const ee=Ae.current||{nx:.5,ny:.5};l("Right Click"),Me(ee.nx,ee.ny,"right"),q.current("input_click",{...ee,button:"right"}).catch(()=>{})}else{const ee=re(Y);ee&&(l("Right Click"),Me(ee.nx,ee.ny,"right"),q.current("input_click",{...ee,button:"right"}).catch(()=>{}))}},500)}else if(D.touches.length===2){clearTimeout(le.current),ne.current=!0,f.current=!0;const Y=D.touches[1].clientX-D.touches[0].clientX,ee=D.touches[1].clientY-D.touches[0].clientY;K.current=Math.sqrt(Y*Y+ee*ee),g.current=z.current,L.current={x:(D.touches[0].clientX+D.touches[1].clientX)/2,y:(D.touches[0].clientY+D.touches[1].clientY)/2}}},k=D=>{const ue=x.current;if(ue&&D.target instanceof Node&&ue.contains(D.target)&&D.preventDefault(),D.touches.length===1&&ce.current){const Y=D.touches[0],ee=Y.clientX-ce.current.x,de=Y.clientY-ce.current.y;if(!ne.current&&G.current){const V=Y.clientX-G.current.x,he=Y.clientY-G.current.y;Math.sqrt(V*V+he*he)>8&&(ne.current=!0,clearTimeout(le.current))}if(ne.current)if(ke.current==="mouse"){const V=Q(ee,de),he=Ae.current||{nx:.5,ny:.5},Se=Math.max(0,Math.min(1,he.nx+V.dnx)),Ie=Math.max(0,Math.min(1,he.ny+V.dny));Ae.current={nx:Se,ny:Ie},Ye({nx:Se,ny:Ie}),l(`Cursor: ${Math.round(Se*100)}%, ${Math.round(Ie*100)}%`),be(Se,Ie,z.current);const $e=Date.now();$e-X.current>=30&&(X.current=$e,q.current("input_mouseMoved",{nx:Se,ny:Ie}).catch(()=>{}))}else if(z.current>1){const V=x.current;if(V){const he=V.clientWidth,Se=V.clientHeight,Ie=U.current+ee/he*100,$e=te.current+de/Se*100,We=ge(Ie,$e,z.current);H(We.x),J(We.y),U.current=We.x,te.current=We.y}}else{const V=re(Y);if(V){const he=Date.now();he-X.current>=40&&(X.current=he,l("Scroll"),q.current("input_wheel",{nx:V.nx,ny:V.ny,deltaX:Math.round(-ee*2.5),deltaY:Math.round(-de*2.5)}).catch(()=>{}))}}ce.current={x:Y.clientX,y:Y.clientY}}else if(D.touches.length===2&&K.current!==null){const Y=D.touches[1].clientX-D.touches[0].clientX,ee=D.touches[1].clientY-D.touches[0].clientY,V=Math.sqrt(Y*Y+ee*ee)/K.current,he=(D.touches[0].clientX+D.touches[1].clientX)/2,Se=(D.touches[0].clientY+D.touches[1].clientY)/2,Ie=he-L.current.x,$e=Se-L.current.y,We=Math.abs(V-1)>.03;if(ke.current==="mouse"){if(We){const _e=Math.max(me,Math.min(5,g.current*V));F(_e),z.current=_e}else if(Math.abs(Ie)>2||Math.abs($e)>2){const _e=Ae.current||{nx:.5,ny:.5},S=Date.now();S-X.current>=30&&(X.current=S,l("Scroll"),q.current("input_wheel",{nx:_e.nx,ny:_e.ny,deltaX:Math.round(-Ie*3),deltaY:Math.round(-$e*3)}).catch(()=>{}))}}else{const _e=Math.max(me,Math.min(5,g.current*V));F(_e),z.current=_e;const S=x.current;if(S&&_e>1){const C=S.clientWidth,T=S.clientHeight,$=U.current+Ie/C*100,ae=te.current+$e/T*100,oe=ge($,ae,_e);H(oe.x),J(oe.y),U.current=oe.x,te.current=oe.y}}L.current={x:he,y:Se}}},Z=D=>{var ue;if(clearTimeout(le.current),K.current=null,D.touches.length===1&&f.current){const Y=D.touches[0];G.current={x:Y.clientX,y:Y.clientY,time:Date.now()},ce.current={x:Y.clientX,y:Y.clientY},ne.current=!0;return}if(D.touches.length===0){if(f.current){f.current=!1,ne.current=!1;return}if(D.changedTouches.length===1&&!ne.current){const Y=D.changedTouches[0],ee=Date.now(),de=ee-(((ue=G.current)==null?void 0:ue.time)||0);if(de<60||de>400){ne.current=!1;return}if(G.current){const V=Y.clientX-G.current.x,he=Y.clientY-G.current.y;if(Math.sqrt(V*V+he*he)>12){ne.current=!1;return}}if(ke.current==="mouse"){const V=Ae.current||re(Y);V&&(l(`Click: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),Me(V.nx,V.ny,"left"),q.current("input_click",{...V}).catch(()=>{}))}else{const V=re(Y);if(!V)return;ee-xe.current<300?(l("Double tap"),Me(V.nx,V.ny,"double"),q.current("input_click",{...V,clickCount:2}).catch(()=>{}),xe.current=0):(l(`Tap: ${Math.round(V.nx*100)}%, ${Math.round(V.ny*100)}%`),Me(V.nx,V.ny,"left"),q.current("input_click",{...V}).catch(()=>{}),xe.current=ee)}}ne.current=!1}};return M.addEventListener("touchstart",ve,{passive:!1}),M.addEventListener("touchmove",k,{passive:!1}),M.addEventListener("touchend",Z,{passive:!1}),()=>{M.removeEventListener("touchstart",ve),M.removeEventListener("touchmove",k),M.removeEventListener("touchend",Z),clearTimeout(le.current)}},[]),e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:Pe,onContextMenu:M=>M.preventDefault(),onFocus:()=>h(!0),onBlur:()=>h(!1),tabIndex:0,children:[e.jsxs("div",{ref:x,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[ye?e.jsx("img",{ref:d,src:ye,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${R}) translate(${j}%, ${ie}%)`,transformOrigin:"center center",cursor:v==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:et,onContextMenu:M=>M.preventDefault(),onDragStart:M=>M.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:pe}),e.jsx("div",{className:"text-[11px] text-white/40",children:E}),o==="relay"&&e.jsx("div",{className:"text-[10px] text-amber-300/80",children:"TURN relay active"})]}),v==="mouse"&&Ke&&ye&&d.current&&(()=>{var Ie;const M=d.current,re=M.getBoundingClientRect(),Q=(Ie=x.current)==null?void 0:Ie.getBoundingClientRect();if(!Q)return null;const be=M.naturalWidth||re.width,ve=M.naturalHeight||re.height,k=be/ve,Z=re.width/re.height;let D,ue,Y,ee;k>Z?(D=re.width,ue=re.width/k,Y=0,ee=(re.height-ue)/2):(ue=re.height,D=re.height*k,Y=(re.width-D)/2,ee=0);const de=re.left-Q.left+Y+D*Ke.nx,V=re.top-Q.top+ee+ue*Ke.ny,he=Math.max(8,Math.min(Q.width-8,de)),Se=Math.max(8,Math.min(Q.height-8,V));return e.jsxs("div",{style:{position:"absolute",left:he-8,top:Se-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)"}})]})})(),p.map(M=>{const Q={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[M.type];return e.jsxs("div",{style:{position:"absolute",left:M.x,top:M.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}})]},M.id)})]}),e.jsxs("div",{onTouchStart:M=>M.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:()=>{B(M=>{const re=M==="touch"?"mouse":"touch";if(re==="mouse"&&!Ae.current){const Q={nx:.5,ny:.5};Ae.current=Q,Ye(Q)}return re})},className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${v==="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:v==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${v==="mouse"?"text-blue-400":"text-slate-400"}`,children:v==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{O(!W),N(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${W?"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:"⌨️"})}),W&&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:u,autoFocus:!0,onTouchStart:M=>M.stopPropagation(),onChange:M=>b(M.target.value),onKeyDown:pt,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:()=>{N(!w),O(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${w?"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:Ne?"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:Ne?"#22c55e":"#eab308",boxShadow:Ne?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:Ne?"#22c55e":"#eab308"},children:Ne?"Connected":"WS"})]}),R>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(R*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`}),m&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:m})]})]}),w&&e.jsxs("div",{onTouchStart:M=>M.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: ",R<=(A?I:1)+.01?A?"FILL":"FIT":`${Math.round(R*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:M=>{M.stopPropagation(),F(re=>Math.max(.5,re-.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:M=>{M.stopPropagation();const re=A?I:1;F(re),z.current=re,H(0),J(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:A?"FILL":"FIT"}),e.jsx("button",{onClick:M=>{M.stopPropagation(),F(re=>Math.min(5,re+.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 Ln({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:a=!1,connectionState:i,onDismiss:o,onClickAt:c,onKeyDown:x,badge:d,emptyMessage:m,aspectRatio:l,className:u,style:b}){const h=r.useRef(null),p=r.useCallback(_=>{if(!a||!c||!h.current)return;const P=h.current,w=P.getBoundingClientRect(),N=(_.clientX-w.left)/w.width*P.naturalWidth,W=(_.clientY-w.top)/w.height*P.naturalHeight;c(N,W,P.naturalWidth,P.naturalHeight)},[a,c]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${u||""}`,style:{aspectRatio:l||"16/9",...b},children:[e.jsx("img",{ref:h,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":""} ${u||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:a?0:void 0,onKeyDown:a?x:void 0,style:b,children:[e.jsx("img",{ref:h,src:t,alt:"IDE Screenshot",onClick:a?p:void 0,className:"max-w-full max-h-full object-contain",style:{...a?{cursor:"crosshair"}:{},...n!==100?{transform:`scale(${n/100})`,transformOrigin:"center center"}:{}}}),d&&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:d})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${u||""}`,style:b,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:m||"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 Dn({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(Jt,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((c,x)=>{const d=o(c).toLowerCase(),m=/^(run|approve|accept|yes|allow|always)/.test(d),l=/^(reject|deny|delete|remove|abort)/.test(d),u=n===c,b=n!==null;return e.jsx("button",{onClick:()=>i(c),disabled:b,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${m?"bg-white text-amber-700 font-extrabold":l?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${b&&!u?"opacity-40":"opacity-100"} ${b?"cursor-not-allowed":"cursor-pointer"}`,children:u?"⏳ ...":o(c)},x)})})]})]})}const Fe=new Map;function Bn({ideId:t,ideType:s,agentType:n,agentName:a,serverModel:i,serverMode:o,acpConfigOptions:c,acpModes:x}){var K;const{sendCommand:d}=nt(),m=!!(c||x),l=`${t}:${n}`,u=Fe.get(l),[b,h]=r.useState(!1),[p,_]=r.useState(!1),[P,w]=r.useState((u==null?void 0:u.models)||[]),[N,W]=r.useState((u==null?void 0:u.modes)||[]),O=g=>g?typeof g=="string"?g:typeof g=="object"?g.name||g.id||JSON.stringify(g):String(g):"",[A,v]=r.useState(O(i)),[B,I]=r.useState(O(o)),[y,se]=r.useState(!1),[R,F]=r.useState(!1),j=r.useRef(0),H=g=>g.map(L=>typeof L=="string"?L:(L==null?void 0:L.name)||(L==null?void 0:L.id)||String(L));r.useEffect(()=>{if(c){const g=c.find(L=>L.category==="model");if(g){const L=H(g.options.map(z=>z.value));w(L),g.currentValue&&v(O(g.currentValue));const f=Fe.get(l)||{models:[],modes:[]};Fe.set(l,{...f,models:L})}}if(x&&x.length>0){const g=H(x.map(f=>f.id));W(g);const L=Fe.get(l)||{models:[],modes:[]};Fe.set(l,{...L,modes:g})}else if(c){const g=c.find(L=>L.category!=="model");if(g){const L=H(g.options.map(z=>z.value));W(L),g.currentValue&&I(O(g.currentValue));const f=Fe.get(l)||{models:[],modes:[]};Fe.set(l,{...f,modes:L})}}},[c,x,l]),r.useEffect(()=>{h(!1),_(!1),v(O(i)),I(O(o));const g=Fe.get(l);g?(w(g.models),W(g.modes)):(w([]),W([]))},[t,n]),r.useEffect(()=>{i&&Date.now()>j.current&&v(O(i))},[i]),r.useEffect(()=>{o&&Date.now()>j.current&&I(O(o))},[o]);const ie=r.useCallback(async(g,L={})=>{const f={...L},z=t.split(":");return z.length>=3&&(z[1]==="ide"||z[1]==="cli"||z[1]==="acp")&&(f._targetInstance=z.slice(2).join(":"),f._targetType=z[1]),await d(t,g,f)},[t]),J=async()=>{var g,L;if(P.length>0){h(!b);return}if(m){h(!0);return}se(!0);try{const f=await ie("list_extension_models",{agentType:n,ideType:s}),z=(f==null?void 0:f.models)||((g=f==null?void 0:f.result)==null?void 0:g.models)||[],U=H(z);w(U),f!=null&&f.current&&v(O(f.current)),(L=f==null?void 0:f.result)!=null&&L.current&&v(O(f.result.current));const te=Fe.get(l)||{models:[],modes:[]};Fe.set(l,{...te,models:U}),h(!0)}catch{}finally{se(!1)}},X=async()=>{var g,L;if(N.length>0){_(!p);return}if(m){_(!0);return}F(!0);try{const f=await ie("list_extension_modes",{agentType:n,ideType:s}),z=(f==null?void 0:f.modes)||((g=f==null?void 0:f.result)==null?void 0:g.modes)||[],U=H(z);W(U),f!=null&&f.current&&I(O(f.current)),(L=f==null?void 0:f.result)!=null&&L.current&&I(O(f.result.current));const te=Fe.get(l)||{models:[],modes:[]};Fe.set(l,{...te,modes:U}),_(!0)}catch{}finally{F(!1)}},q=async g=>{h(!1),v(g),j.current=Date.now()+5e3;try{m?await ie("change_model",{agentType:n,ideType:s,model:g}):await ie("set_extension_model",{agentType:n,ideType:s,model:g})}catch{}},G=m&&!(x&&x.length>0)&&(c==null?void 0:c.some(g=>g.category!=="model")),ce=G?(K=c==null?void 0:c.find(g=>g.category!=="model"))==null?void 0:K.configId:void 0,ne=async g=>{_(!1),I(g),j.current=Date.now()+5e3;try{m&&G&&ce?await ie("set_thought_level",{agentType:n,ideType:s,configId:ce,value:g}):m?await ie("set_mode",{agentType:n,ideType:s,mode:g}):await ie("set_extension_mode",{agentType:n,ideType:s,mode:g})}catch{}},xe={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:xe},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:b?`${xe}55`:"transparent",border:"1px solid",color:A?"var(--text-primary)":"var(--text-muted)"},onClick:J,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),y?"...":A||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),b&&P.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>h(!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"}),P.map(g=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:g===A?`${xe}18`:"transparent",color:g===A?xe:"var(--text-secondary)",fontWeight:g===A?600:400,borderLeft:g===A?`2px solid ${xe}`:"2px solid transparent"},onMouseEnter:L=>{L.currentTarget.style.background=`${xe}12`},onMouseLeave:L=>{L.currentTarget.style.background=g===A?`${xe}18`:"transparent"},onClick:()=>q(g),children:g},g))]})]})]}),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:p?`${xe}55`:"transparent",border:"1px solid",color:B?"var(--text-primary)":"var(--text-muted)"},onClick:X,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:G?"🧠":"⚡"}),R?"...":B||(G?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),p&&N.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>_(!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:G?"SELECT THINKING LEVEL":"SELECT MODE"}),N.map(g=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:g===B?`${xe}18`:"transparent",color:g===B?xe:"var(--text-secondary)",fontWeight:g===B?600:400,borderLeft:g===B?`2px solid ${xe}`:"2px solid transparent"},onMouseEnter:L=>{L.currentTarget.style.background=`${xe}12`},onMouseLeave:L=>{L.currentTarget.style.background=g===B?`${xe}18`:"transparent"},onClick:()=>ne(g),children:g},g))]})]})]})]})}const Oe=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),Re=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function Bs({activeConv:t,ides:s,agentInput:n,setAgentInput:a,handleSendChat:i,handleFocusAgent:o,isFocusingAgent:c,messageReceivedAt:x,actionLogs:d,userName:m}){const l=r.useRef(null),{sendCommand:u}=nt(),b=r.useRef(new Map),h=r.useCallback(y=>(b.current.has(y)||b.current.set(y,{messages:[],offset:0,hasMore:!0,error:null}),b.current.get(y)),[]),p=r.useCallback((y,se)=>{const R=h(y);b.current.set(y,{...R,...se}),_(F=>F+1)},[h]),[,_]=r.useState(0),P=t.tabKey,w=h(P),N=w.messages,W=w.hasMore,O=w.error,[A,v]=r.useState(!1),B=r.useCallback(async()=>{var R,F;if(A)return;const y=t.tabKey,se=h(y);v(!0),p(y,{error:null});try{const j=s.find(ce=>ce.id===t.ideId),H=(j==null?void 0:j.daemonId)||((R=t.ideId)==null?void 0:R.split(":")[0])||"";if(!H){p(y,{hasMore:!1});return}const ie=t.ideType||t.agentType||"",J=(t.ideId||"").split(":"),X=J.length>=3?J.slice(2).join(":"):void 0,q=await u(H,"chat_history",{agentType:ie,offset:se.offset,limit:30,instanceId:X}),G=(q==null?void 0:q.result)??q;if(((F=G.messages)==null?void 0:F.length)>0){const ce=h(y);p(y,{messages:[...G.messages,...ce.messages],offset:ce.offset+G.messages.length,hasMore:!!G.hasMore})}else p(y,{hasMore:!!G.hasMore})}catch(j){const H=(j==null?void 0:j.message)||"";H.includes("P2P not available")||H.includes("channel not open")||H.includes("P2P not connected")||H.includes("timeout")?p(y,{error:"Connection not ready — tap to retry"}):p(y,{hasMore:!1,error:"Failed to load history"})}finally{v(!1)}},[A,s,t,u,h,p]),I=(()=>{const y=t.messages.map((F,j)=>{const H=`${t.ideId}-${F.id??`i-${j}`}`;return{...F,receivedAt:F.receivedAt||x[H]||0}});if(N.length===0)return y;const se=new Set(y.map(F=>`${F.role}:${(F.content||"").slice(0,100)}`));return[...N.filter(F=>!se.has(`${F.role}:${(F.content||"").slice(0,100)}`)),...y]})();return e.jsxs(e.Fragment,{children:[e.jsx(Rn,{messages:I,actionLogs:d.filter(y=>y.ideId===t.tabKey).sort((y,se)=>y.timestamp-se.timestamp),agentName:t.agentName||t.displayPrimary||"Agent",userName:m,isCliMode:Oe(t)||Re(t),isWorking:t.status==="working",contextKey:t.tabKey,onLoadMore:B,isLoadingMore:A,hasMoreHistory:W,loadError:O??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(ut,{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(Ft,{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($s,{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(Ft,{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"&&!A?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}),!Oe(t)&&(()=>{var se,R,F,j;const y=s.find(H=>H.id===t.ideId);return e.jsx(Bn,{ideId:t.ideId,ideType:t.ideType,agentType:t.streamSource==="agent-stream"?t.agentType:((R=(se=y==null?void 0:y.agents)==null?void 0:se[0])==null?void 0:R.type)||t.ideType,agentName:t.streamSource==="agent-stream"?t.agentName:((j=(F=y==null?void 0:y.agents)==null?void 0:F[0])==null?void 0:j.name)||t.agentName,serverModel:(y==null?void 0:y.currentModel)||void 0,serverMode:(y==null?void 0:y.currentPlan)||void 0,acpConfigOptions:Re(t)?y==null?void 0:y.acpConfigOptions:void 0,acpModes:Re(t)?y==null?void 0:y.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:l,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:n,onChange:y=>a(y.target.value),onPaste:y=>{const se=y.clipboardData.getData("text");se&&a(R=>R+se),y.preventDefault()},onKeyDown:y=>{if(y.key==="Enter"){if(y.nativeEvent.isComposing){y.preventDefault();return}y.preventDefault(),i()}},onBlur:y=>{if(window.innerWidth<768){const se=y.relatedTarget;if((se==null?void 0:se.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 Bt=new Set,Ws={emit(t,s){for(const n of Bt)n(t,s)},on(t){return Bt.add(t),()=>{Bt.delete(t)}}};function Wn({activeConv:t,ptyBuffers:s,terminalRef:n,agentInput:a,setAgentInput:i,handleSendChat:o}){var b;const c=r.useRef(null),{sendCommand:x,sendData:d}=nt(),m=(b=t.ideId)!=null&&b.includes(":cli:")?t.ideId.split(":cli:")[1]:"",l=t.tabKey,u=t.ideType||t.agentType||"";return r.useEffect(()=>{const h=s.current.get(l);if(h&&h.length>0){const p=setTimeout(()=>{var _;for(const P of h)(_=n.current)==null||_.write(P);requestAnimationFrame(()=>{var P;(P=n.current)==null||P.bumpResize()})},100);return()=>clearTimeout(p)}},[l]),r.useEffect(()=>{const h=Ws.on((p,_)=>{var w;if(!_)return;(p===m||p===u||p===t.ideId||p===t.tabKey)&&((w=n.current)==null||w.write(_))});return()=>{h()}},[m,u]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:e.jsx(Ds,{ref:n,onInput:h=>{var P;const p=t.ideId||t.daemonId||"",_=(P=t.ideId)!=null&&P.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";d!=null&&d(p,{type:"pty_input",cliType:_,data:h})||x(p,"pty_input",{cliType:_,data:h}).catch(console.error)},onResize:(h,p)=>{var w;const _=t.ideId||t.daemonId||"",P=(w=t.ideId)!=null&&w.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";d!=null&&d(_,{type:"pty_resize",cliType:P,cols:h,rows:p})||x(_,"pty_resize",{cliType:P,cols:h,rows:p,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:h=>i(h.target.value),onPaste:h=>{const p=h.clipboardData.getData("text");p&&i(_=>_+p),h.preventDefault()},onKeyDown:h=>{if(h.key==="Enter"){if(h.nativeEvent.isComposing){h.preventDefault();return}h.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 On({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)"},x={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:x[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 Os=jt;function Pt(){return Os()}class Kn{constructor(){Ee(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 Ks=new Kn;class zn{constructor(){Ee(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 tt=new zn,Ht=tt;function Fn(t){t.dashboardWS&&(Ks=t.dashboardWS),t.connectionManager&&(tt=t.connectionManager,Ht=t.connectionManager),t.p2pManager&&(Ht=t.p2pManager),t.useDaemonsHook&&(Os=t.useDaemonsHook)}function Hn({activeConv:t,agentCount:s,wsStatus:n,isConnected:a,onOpenHistory:i,cliViewMode:o,onSetCliViewMode:c,onStopCli:x}){const d=kt(),m=Pt(),l=m.p2pStates||{},u=m.ides||[],b=!!t&&Oe(t)&&!Re(t),h=a?"#22c55e":n==="connected"?"#eab308":"#ef4444",p=a?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",_=u.filter(A=>A.type==="adhdev-daemon"),P=Object.values(l),w=P.filter(A=>A==="connected").length,N=P.filter(A=>A==="connecting"||A==="new"||A==="checking").length,O=n!=="connected"||_.length===0?null:N>0&&w===0?"P2P connecting...":w>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(wt,{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:h,boxShadow:p}})})]}),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:h,boxShadow:p}}),O&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",O]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[b&&o&&c&&e.jsxs("div",{className:"flex items-center rounded-lg border border-border-subtle bg-bg-secondary p-0.5",children:[e.jsx("button",{onClick:()=>c("chat"),className:`px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors ${o==="chat"?"bg-bg-primary text-text-primary shadow-sm":"text-text-muted hover:text-text-primary"}`,title:"Chat mode",children:"Chat"}),e.jsx("button",{onClick:()=>c("terminal"),className:`px-2.5 py-1 text-[11px] font-medium rounded-md transition-colors ${o==="terminal"?"bg-bg-primary text-text-primary shadow-sm":"text-text-muted hover:text-text-primary"}`,title:"Terminal mode",children:"Terminal"})]}),b&&x&&e.jsx("button",{onClick:x,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&&!b&&!Re(t)&&e.jsxs("button",{onClick:()=>d(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Zt,{size:14})," IDE"]}),t&&!b&&!Re(t)&&e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Sn,{size:16})}),t&&!b&&!Re(t)&&e.jsx("button",{onClick:()=>d(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(rt,{size:16})})]})]})}function He(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function Un(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 os(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Yn(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 Vn(t){return Yn(t.trim().replace(/\.local$/i,""))}function Xn(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function zs(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 Vn(n);const a=s.fallbackId||t.id;return a?`Machine-${a.substring(0,8)}`:s.fallbackLabel||"Machine"}function xt(t,s={}){return Xn(t)||zs(t,s)}function is(t){return(t.id||"").includes(":cli:")}function cs(t){return(t.id||"").includes(":acp:")}function Ut(t,s){return He(t)}function qn(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,n=["generating","streaming","active","connected","idle","panel_hidden"];for(const a of t){const i=(a.name||a.id||"").toLowerCase().replace(/\s+/g,"-"),o=s.get(i);if(!o){s.set(i,a);continue}const c=n.indexOf(o.status||"idle"),x=n.indexOf(a.status||"idle");x>=0&&(c<0||x<c)&&s.set(i,a)}return Array.from(s.values())}function Gn({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:a,onClose:i,onNewChat:o,onSwitchSession:c,onRefreshHistory:x}){var u;const d=s.find(b=>b.id===t.ideId),m=(d==null?void 0:d.chats)||[],l=(u=d==null?void 0:d.activeChat)==null?void 0:u.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," — ",He(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"}),m.map(b=>e.jsxs("div",{onClick:()=>{c(t.ideId,b.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${l===b.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 ${l===b.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:b.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:[b.id.substring(0,12),"..."]}),l===b.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},b.id)),m.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(Tn,{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:x,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(As,{size:13})," Refresh History"]})})})]})]})}const ls={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function Jn({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:ls[a.type]||ls.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 Zn=t=>(t.id||"").includes(":cli:")||(t.id||"").includes(":acp:")||(t.id||"").includes(":ide:")?!0:t.daemonId!==t.id;function Qn(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function er(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]=xt(c,{fallbackId:c.id}))}return t.flatMap(o=>{var w,N,W,O,A;const c=[],x=o.daemonId&&i[o.daemonId]||void 0,d=o.daemonId||((w=o.id)==null?void 0:w.split(":")[0])||o.id,m=a?a[d]||"new":void 0,l=Qn(o),u=He(o.type),b=o.agentStreams,h=Array.isArray(b)?b.map(v=>({...v,activeModal:v.activeModal??void 0})):[],p=Zn(o),_=o.activeChat||{title:""},P=_.title&&String(_.title).trim()?String(_.title).trim():"";if(p){const v=Ut(o.type),B=(N=o.agents)==null?void 0:N[0],I=(W=o.activeChat)==null?void 0:W.activeModal,y=I&&Array.isArray(I.buttons)&&I.buttons.length>0,se=(O=o.activeChat)==null?void 0:O.status,R=se==="generating"||se==="loading"||se&&se.toLowerCase()==="thinking",j=y||se==="waiting_approval"?"waiting_approval":R?"working":(B==null?void 0:B.status)||"idle",H=o.activeChat||{title:"",messages:[]};let ie=H.title&&String(H.title).trim()?String(H.title).trim():"";const J=(A=o.activeChat)==null?void 0:A.id,X=o.chats;if(J&&Array.isArray(X)&&X.length>0){const le=X.find(xe=>xe.id===J||xe.id&&String(xe.id)===String(J));le!=null&&le.title&&String(le.title).trim()&&(ie=String(le.title).trim())}const q=H.messages||[],G=s[o.id]||[],ce=new Map;q.filter(le=>le.role==="user").forEach(le=>{ce.set(le.content,(ce.get(le.content)||0)+1)});const ne=G.filter(le=>{const xe=ce.get(le.content)||0;return xe>0?(ce.set(le.content,xe-1),!1):!0});c.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:Oe(o)?o.mode||"terminal":"chat",agentName:v,agentType:Oe(o)||Re(o)?o.cliType||o.acpType||o.type:(B==null?void 0:B.type)||"ide-native",status:j,title:ie,messages:[...q,...ne],ideType:o.cliType||o.acpType||o.type,workspaceName:l,displayPrimary:ie||l||(Oe(o)||Re(o)?"Terminal":v),displaySecondary:u,cdpConnected:o.cdpConnected,modalButtons:y?I.buttons:void 0,modalMessage:y?I.message:void 0,streamSource:"native",tabKey:o.id,machineName:x,connectionState:m})}if(p&&(Oe(o)||Re(o)))return c;for(const v of h){const B=v.activeModal&&Array.isArray(v.activeModal.buttons)&&v.activeModal.buttons.length>0,I=B?"waiting_approval":v.status==="streaming"?"working":v.status,y=`${o.id}:${v.agentType}`,se=v.messages||[],R=s[y]||[],F=new Map;se.filter(H=>H.role==="user").forEach(H=>{F.set(H.content,(F.get(H.content)||0)+1)});const j=R.filter(H=>{const ie=F.get(H.content)||0;return ie>0?(F.set(H.content,ie-1),!1):!0});c.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:"chat",agentName:v.agentName,agentType:v.agentType,status:I,title:"",messages:[...se,...j],ideType:v.agentType,workspaceName:l,displayPrimary:P||l||v.agentName,displaySecondary:`${u}·${v.agentName}`,cdpConnected:o.cdpConnected,modalButtons:B?v.activeModal.buttons:void 0,modalMessage:B?v.activeModal.message:void 0,streamSource:"agent-stream",tabKey:y,machineName:x,connectionState:m})}return c.length===0&&c.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:"chat",agentName:Ut(o.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:o.type,workspaceName:l,displayPrimary:l||u,displaySecondary:u,cdpConnected:o.cdpConnected,streamSource:"native",tabKey:o.id,connectionState:m}),c})}function tr(t,s){var x,d,m,l;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 b=u.id?`${a}:cli:${u.id}`:`${a}:cli:${u.cliType}`;n.push({id:b,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:u.status==="generating"?"streaming":u.status==="waiting_approval"?"waiting_approval":"idle",messages:((x=u.activeChat)==null?void 0:x.messages)||[],inputContent:"",activeModal:(d=u.activeChat)==null?void 0:d.activeModal}],timestamp:c,_isCli:!0})}for(const u of t.managedAcps){const b=u.id?`${a}:acp:${u.id}`:`${a}:acp:${u.acpType}`;n.push({id:b,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:u.status==="generating"?"streaming":u.status==="waiting_approval"?"waiting_approval":"idle",messages:((m=u.activeChat)==null?void 0:m.messages)||[],inputContent:"",activeModal:(l=u.activeChat)==null?void 0:l.activeModal}],timestamp:c,_isAcp:!0})}return n}const Fs=[{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:"💚"}],Hs=[{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"codex-cli",name:"Codex CLI",icon:"📦"}],Us=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Ys="adhdev_notification_prefs",ds={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0};function sr(){try{const t=localStorage.getItem(Ys);if(t){const s=JSON.parse(t);return{...ds,...s}}}catch{}return{...ds}}function nr(t){try{localStorage.setItem(Ys,JSON.stringify(t))}catch{}}let Qe=sr(),Tt=[];function rr(){Tt.forEach(t=>t())}function ar(t){Qe={...Qe,...t},nr(Qe),rr()}function or(){const[,t]=r.useState(0);r.useEffect(()=>{const n=()=>t(a=>a+1);return Tt.push(n),()=>{Tt=Tt.filter(a=>a!==n)}},[]);const s=r.useCallback(n=>{ar(n)},[]);return[{...Qe},s]}function gt(t){if(!Qe.globalEnabled)return!1;switch(t){case"disconnect":return Qe.disconnectAlert;case"completion":return Qe.completionAlert;case"approval":return Qe.approvalAlert;case"browser":return Qe.browserNotifications;default:return!0}}const ir={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function cr(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Vs(){return"Notification"in window&&Notification.permission==="granted"}let at=null;async function lr(){if(at!==null)return at;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return at=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(at=!!await t.pushManager.getSubscription(),at):(at=!1,!1)}catch{return at=!1,!1}}function Yt(t,s,n){if(Vs())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 dr(t,s={}){const n={...ir,...s},a=r.useRef(new Map),i=r.useRef(0),o=r.useRef(null);r.useEffect(()=>{lr().then(x=>{o.current=x})},[]);const c=r.useCallback((x,d,m)=>{const l=Date.now();l-i.current<n.throttleMs||(i.current=l,Yt(x,d,m))},[n.throttleMs]);r.useEffect(()=>{var x;if(!(!n.enabled||!Vs())&&gt("browser")&&o.current!==!0){if(document.hasFocus()){for(const d of t)a.current.set(d.id,d.status||"idle");return}for(const d of t){const m=a.current.get(d.id),l=d.status||"idle",u=d.name||d.id;if(n.onApproval&&gt("approval")&&l==="waiting_approval"&&m!=="waiting_approval"){const b=((x=d.activeModal)==null?void 0:x.message)||"Action requires your approval";c(`🔔 ${u} — Approval needed`,b.slice(0,120),`approval-${d.id}`)}n.onComplete&&gt("completion")&&m==="generating"&&l==="idle"&&c(`✅ ${u} — Task complete`,"Agent has finished working",`complete-${d.id}`),n.onError&&l==="error"&&m!=="error"&&c(`⚠️ ${u} — Error`,"Agent encountered an error",`error-${d.id}`),a.current.set(d.id,l)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class ur{constructor(){Ee(this,"dedupMap",new Map);Ee(this,"DEDUP_WINDOW_MS",5e3);Ee(this,"DEDUP_MAX_SIZE",50);Ee(this,"DEDUP_CLEANUP_AGE_MS",1e4);Ee(this,"toastCallbacks",[]);Ee(this,"systemMessageCallbacks",[]);Ee(this,"clearSystemMessageCallbacks",[]);Ee(this,"resolveActionFn",null);Ee(this,"viewRequestRespondFn",null);Ee(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)}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}handleRawEvent(s,n){var d,m;const a=`${s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(a))return;if(!s.ideId&&s.instanceId){for(const l of this.ides)if(l.id.endsWith(`:ide:${s.instanceId}`)||l.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=l.id;break}}let i=He(s.ideType||"");const o=this.resolveOwningDaemon(s);if(o){const l=xt(o,{fallbackId:o.id});l&&(i=s.ideType==="adhdev-daemon"?l:`${l}/${i}`)}let c="",x="info";if(s.event==="agent:generating_completed"){const l=s.duration?` (${s.duration}s)`:"";c=`✅ ${i} agent task completed${l}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}s.ideId&&this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`✅ Task completed${l}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")s.ideId&&this.emitClearSystemMessage(s.ideId,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(c=`⚡ ${i} approval needed`,x="warning",s.ideId){const l=s.modalMessage||"Approval requested",u=(d=s.modalButtons)!=null&&d.length?s.modalButtons.map(b=>`[${b}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${l}
39
+ ${u}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((m=s.modalButtons)!=null&&m.length)&&this.resolveActionFn){const l=s.ideId,u=s.agentType||s.ideType||"",b=s.ideType||"",h=s.modalButtons,p=W=>W.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),_=this.resolveActionFn,P=h.map((W,O)=>{const A=p(W).toLowerCase(),v=/^(run|approve|accept|yes|allow|always)/.test(A),B=/^(reject|deny|delete|remove|abort|cancel|no)/.test(A);return{label:p(W),variant:v?"primary":B?"danger":"default",onClick:()=>{const I=this.resolveRouteId(l,u),y=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(A);_(I,"resolve_action",{action:y?"approve":"reject",button:W,buttonIndex:O,agentType:u,ideType:b})}}}),w=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:c,N=Date.now();this.emitToast({id:N,message:w,type:x,timestamp:N,ideId:l,actions:P,duration:15e3}),c=""}}else if(s.event==="monitor:long_generating"){const l=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";c=`⚠️ ${i} agent is taking a long time${l}`,x="warning",gt("browser")&&!document.hasFocus()&&Yt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${l.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const l=s.requesterName||"A team member",u=s.requestId,b=s.orgId;if(c=`👁️ ${l} wants to view your session`,x="warning",u&&b&&this.viewRequestRespondFn){const h=this.viewRequestRespondFn,p=Date.now(),_=[{label:"Approve",variant:"primary",onClick:()=>{h(b,u,"approve").catch(P=>console.error("[EventManager] approve view request failed:",P))}},{label:"Decline",variant:"danger",onClick:()=>{h(b,u,"reject").catch(P=>console.error("[EventManager] reject view request failed:",P))}}];this.emitToast({id:p,message:c,type:x,timestamp:p,actions:_,duration:3e4}),c=""}gt("browser")&&!document.hasFocus()&&Yt("👁️ View Request",`${l} wants to view your session`,`view-request-${u}`)}else s.event==="team:view_request_approved"?(c="✅ View request approved",x="success"):s.event==="team:view_request_rejected"&&(c=`❌ ${s.targetName||"Team member"} declined your view request`,x="warning");if(c){const l=Date.now();this.emitToast({id:l,message:c,type:x,timestamp:l,ideId:s.ideId,duration:5e3})}}}const lt=new ur;function ct(...t){return nn(rn(t))}function xr({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 _t({icon:t,title:s,subtitle:n,badge:a,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:x}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(xr,{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:x})})]})}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 Qt({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 pr={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"},mr={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function hr({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]",pr[t],a),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:mr[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 fr={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"},gr={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function br({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",fr[t],n),children:[e.jsx("span",{className:ct("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",gr[t])}),a]})}function yr(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function us(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function Wt(t){return t==="system"?yr():t}function jr(){const[t,s]=r.useState(us),[n,a]=r.useState(()=>Wt(us()));r.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),r.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),x=d=>{t==="system"&&a(d.matches?"light":"dark")};return c.addEventListener("change",x),()=>c.removeEventListener("change",x)},[t]);const i=r.useCallback(c=>{s(c),a(Wt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=r.useCallback(()=>{s(c=>{const x=c==="dark"?"light":c==="light"?"system":"dark";a(Wt(x));try{localStorage.setItem("theme",x)}catch{}return x})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function dt({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 vr({onPrefChange:t}){const[s,n]=or(),a=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ls,{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(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(rt,{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(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(En,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>a("completionAlert",i)}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(An,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>a("approvalAlert",i)}),e.jsx(dt,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ut,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>a("disconnectAlert",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 wr({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(Qt,{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(kr,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:a,onRevokeToken:i},c.id))})}function xs({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 an.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:x=>x.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 Nr(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),a=[...Fs,...Hs,...Us].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 kr({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:a,onRevokeToken:i}){var H,ie;const[o,c]=r.useState("idle"),[x,d]=r.useState(""),[m,l]=r.useState(null),[u,b]=r.useState("idle"),[h,p]=r.useState(""),_=t,P=_.version||_.daemonVersion||null,w=((H=_.machine)==null?void 0:H.platform)||((ie=_.system)==null?void 0:ie.platform)||"",N=xt(_,{fallbackId:t.id}),W=w==="win32"?"🪟":w==="darwin"?"🍎":"🐧",O=s.filter(J=>J.daemonId===t.id&&J.id.includes(":ide:")),A=s.filter(J=>J.daemonId===t.id&&J.id.includes(":cli:")),v=s.filter(J=>J.daemonId===t.id&&J.id.includes(":acp:")),B=_.p2p,I=async()=>{var J,X,q;if(n){c("upgrading"),d("Installing latest version...");try{const G=await n(t.id,"daemon_upgrade",{});(J=G==null?void 0:G.result)!=null&&J.upgraded||(X=G==null?void 0:G.result)!=null&&X.success?(c("done"),d(`Upgraded to v${G.result.version||"latest"}. Daemon is restarting...`)):(c("error"),d(((q=G==null?void 0:G.result)==null?void 0:q.error)||"Upgrade failed"))}catch(G){c("error"),d((G==null?void 0:G.message)||"Connection lost during upgrade")}}},y=async()=>{if(l(null),!!a){b("loading");try{await a(t.id),b("done"),p("Machine disconnected.")}catch(J){b("error"),p((J==null?void 0:J.message)||"Failed to disconnect")}}},se=async()=>{if(l(null),!!i){b("loading");try{await i(t.id),b("done"),p('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(J){b("error"),p((J==null?void 0:J.message)||"Failed to revoke token")}}},R="0.6.70",F=!P||P!==R,j=O.length+A.length+v.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:W}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:N}),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),"…"]}),P&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${F?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",P,!F&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&F&&e.jsx("button",{onClick:I,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${R}`,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${R}`}`}),a&&e.jsx("button",{onClick:()=>l("disconnect"),disabled:u==="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:()=>l("revoke"),disabled:u==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(br,{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:[B&&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 ${B.state==="connected"?"bg-green-400":B.state==="connecting"||B.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",B.state==="connected"?"connected":B.state==="connecting"||B.state==="new"?"connecting...":B.state||"off"]}),B.peers!==void 0&&B.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",B.peers," peer",B.peers!==1?"s":"",")"]})]}),B&&j>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),j>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[O.map(J=>{const X=Nr(J.type),q=J.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:X.icon}),e.jsx("span",{children:X.name}),q!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${q?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:q?"CDP connected":"CDP connecting..."})]},J.id)}),A.map(J=>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:J.cliName||"CLI"})]},J.id)),v.map(J=>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:J.cliName||"ACP"})]},J.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(x||h)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||u==="error"?"text-red-400":o==="done"||u==="done"?"text-green-400":"text-text-muted"}`,children:h||x})]}),m==="disconnect"&&e.jsx(xs,{title:"🔌 Disconnect Machine",message:`Disconnect "${N}" 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:y,onCancel:()=>l(null)}),m==="revoke"&&e.jsx(xs,{title:"⚠️ Remove Machine",message:`Remove "${N}" 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:se,onCancel:()=>l(null)})]})}const Sr=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Cr(){const{preference:t,setPreference:s}=jr();return e.jsx("div",{className:"flex gap-2",children:Sr.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 Vt={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},Xt={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},Ir=[{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"}}}],Xs="adhdev-chat-theme",qs="adhdev-chat-theme-custom";function Et(){return typeof window>"u"?"midnight":localStorage.getItem(Xs)||"midnight"}function Ue(t){try{const s=localStorage.getItem(qs);if(s){const n=JSON.parse(s);return{...t==="dark"?Vt:Xt,...n[t]}}}catch{}return t==="dark"?Vt:Xt}function Ct(t,s){localStorage.setItem(qs,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 ps(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",ps(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${ps(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 Mr(){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 Tr(t){if(localStorage.setItem(Xs,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=bt()?"dark":"light";it(Ue(s))}else Mr()}function Er(){const t=Et();if(t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=bt()?"dark":"light";it(Ue(s))}}function bt(){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 ht({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 Ar({dark:t,onColorsChange:s}){const n=t?"dark":"light",[a,i]=r.useState(()=>Ue(n));r.useEffect(()=>{i(Ue(n))},[n]);const o=r.useCallback((c,x)=>{i(d=>{const m={...d,[c]:x},u=Ue(n==="dark"?"light":"dark");return n==="dark"?Ct(m,u):Ct(u,m),it(m),s(m),m})},[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(ht,{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(ht,{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(ht,{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(ht,{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(ht,{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?Vt:Xt,d=Ue(t?"light":"dark");t?Ct(c,d):Ct(d,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 $r(){const[t,s]=r.useState(Et),[n,a]=r.useState(!0),[i,o]=r.useState(()=>Ue("dark"));r.useEffect(()=>{a(bt());const d=new MutationObserver(()=>{const u=bt();a(u),Et()==="custom"&&it(Ue(u?"dark":"light"))});d.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const m=window.matchMedia("(prefers-color-scheme: dark)"),l=()=>{const u=bt();a(u),Et()==="custom"&&it(Ue(u?"dark":"light"))};return m.addEventListener("change",l),()=>{d.disconnect(),m.removeEventListener("change",l)}},[]),r.useEffect(()=>{t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"&&it(Ue(n?"dark":"light"))},[]),r.useEffect(()=>{o(Ue(n?"dark":"light"))},[n]);const c=d=>{s(d),Tr(d),d==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},x=[...Ir,{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:x.map(d=>{const m=t===d.id,l=n?d.preview.dark:d.preview.light,u=d.id==="honey"?"#1a1a1a":d.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(d.id),className:"text-left rounded-xl p-3 transition-all",style:{background:m?"var(--bg-glass-hover)":"var(--bg-glass)",border:m?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:m?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:l.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:l.assistantBubble,border:l.assistantBorder,color:l.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:l.userBubble,color:u},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:l.assistantBubble,border:l.assistantBorder,color:l.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[m&&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:d.id==="custom"?"🎨 Custom":d.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:d.description})]})]})]},d.id)})}),t==="custom"&&e.jsx(Ar,{dark:n,onColorsChange:d=>o(d)})]})}const qt="adhdev-accent-color",_r=[{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"}],Nt="#8b5cf6";function Rr(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,x=0;const d=(i+o)/2;if(i!==o){const m=i-o;switch(x=d>.5?m/(2-i-o):m/(i+o),i){case s:c=((n-a)/m+(n<a?6:0))/6;break;case n:c=((a-s)/m+2)/6;break;case a:c=((s-n)/m+4)/6;break}}return{h:Math.round(c*360),s:Math.round(x*100),l:Math.round(d*100)}}function ms(t,s){const{h:n,s:a,l:i}=Rr(t),o=Math.min(100,i+s);return`hsl(${n}, ${a}%, ${o}%)`}function At(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 hs(){return typeof window>"u"?Nt:localStorage.getItem(qt)||Nt}function Pr(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",ms(t,15)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${ms(t,20)})`),s.style.setProperty("--border-accent",At(t,.4)),s.style.setProperty("--nav-active-bg",At(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${At(t,.06)}`)}function Lr(){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 Dr(t){t===Nt?(localStorage.removeItem(qt),Lr()):(localStorage.setItem(qt,t),Pr(t))}function Br(){const[t,s]=r.useState(hs),[n,a]=r.useState("");r.useEffect(()=>{s(hs())},[]);const i=o=>{s(o),Dr(o)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:_r.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 ${At(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!==Nt&&e.jsx("button",{onClick:()=>i(Nt),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 Gs="adhdev_hiddenTabs";function Wr(){try{const t=localStorage.getItem(Gs);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function ft(t){try{localStorage.setItem(Gs,JSON.stringify([...t]))}catch{}}function Or(){const[t,s]=r.useState(Wr),n=r.useCallback(d=>{s(m=>{const l=new Set(m);return l.has(d)?l.delete(d):l.add(d),ft(l),l})},[]),a=r.useCallback(d=>{s(m=>{if(m.has(d))return m;const l=new Set(m);return l.add(d),ft(l),l})},[]),i=r.useCallback(d=>{s(m=>{if(!m.has(d))return m;const l=new Set(m);return l.delete(d),ft(l),l})},[]),o=r.useCallback((d,m)=>{s(l=>{const u=new Set(l);for(const b of m)u.add(b);return ft(u),u})},[]),c=r.useCallback((d,m)=>{s(l=>{const u=new Set(l);for(const b of m)u.delete(b);return ft(u),u})},[]),x=r.useCallback(d=>t.has(d),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:a,showTab:i,hideAllForDaemon:o,showAllForDaemon:c,isHidden:x}}function Js({sendDaemonCommand:t,activeConv:s,ides:n,updateIdeChats:a,setToasts:i,setLocalUserMessages:o,setClearedTabs:c,setActionLogs:x,pinTab:d,isStandalone:m}){const[l,u]=r.useState(""),[b,h]=r.useState(!1),[p,_]=r.useState(!1),[P,w]=r.useState(!1),N=r.useCallback(R=>R?Oe(R)||Re(R)?{agentType:R.agentType||R.ideType}:R.streamSource==="agent-stream"?{agentType:R.agentType}:{}:{},[]),W=r.useCallback(async()=>{if(!s)return;const R=l.trim();if(!R)return;const F=s.ideId,j=s.tabKey;u(""),d(j,[100,500,1500,3e3]);const H=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,ie={role:"user",content:R,timestamp:Date.now(),_localId:H};o(J=>({...J,[j]:[...J[j]||[],ie]}));try{const J=F||s.daemonId||"";if(!J)return;await t(J,"send_chat",{message:R,text:R,...N(s)}),setTimeout(()=>{const X=Date.now()-6e4;o(q=>{const G=q[j];if(!G)return q;const ce=G.filter(ne=>ne.timestamp>X);return ce.length===G.length?q:{...q,[j]:ce}})},6e4)}catch(J){console.error("Send failed",J),u(R),o(X=>({...X,[j]:(X[j]||[]).filter(q=>q._localId!==H)}))}},[s,l,t,o,d,N]),O=r.useCallback(async()=>{if(s)try{m?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(R){console.error("Relaunch failed",R)}},[s,m,t]),A=r.useCallback(async R=>{try{await t("standalone","launch_ide",{ideType:R,enableCdp:!0})}catch(F){console.error("Launch failed",F)}},[t]),v=r.useCallback(async R=>{if(s){console.log("[ModalButton] ideId:",s.ideId,"button:",R),x(F=>[...F,{ideId:s.tabKey,text:`🖱️ **${R}** clicked`,timestamp:Date.now()}]);try{const j=(s.modalButtons||[]).indexOf(R),H=R.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),ie=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(H),J=s.ideId||s.daemonId||"";(await t(J,"resolve_action",{button:R,action:ie?"approve":"reject",...j>=0&&{buttonIndex:j},...N(s)})).success||x(q=>[...q,{ideId:s.tabKey,text:`⚠️ **${R}** failed — button not found`,timestamp:Date.now()}])}catch(F){console.error("[ModalButton] Error:",F),x(j=>[...j,{ideId:s.tabKey,text:`❌ **${R}** error`,timestamp:Date.now()}])}}},[s,t,x,N]),B=r.useCallback(async(R,F)=>{try{const j=R||(s==null?void 0:s.daemonId)||"",H=await t(j,"switch_chat",{id:F,sessionId:F,...N(s)}),ie=H==null?void 0:H.result;(H==null?void 0:H.success)===!0||ie==="switched"||ie==="switched-by-title"||(ie===!1||ie==="not_found"?i(X=>[...X,{id:Date.now(),message:"⚠️ Session tab not found — try refreshing history",type:"warning",timestamp:Date.now()}]):typeof ie=="string"&&ie.startsWith("error:")?i(X=>[...X,{id:Date.now(),message:`⚠️ Switch error: ${ie}`,type:"warning",timestamp:Date.now()}]):i(X=>[...X,{id:Date.now(),message:"⚠️ Session switch failed",type:"warning",timestamp:Date.now()}]))}catch(j){console.error("Switch failed",j),i(H=>[...H,{id:Date.now(),message:`❌ Switch failed: ${j.message||"connection error"}`,type:"warning",timestamp:Date.now()}])}},[s,t,i,N]),I=r.useCallback(async()=>{if(!(!s||b)){h(!0);try{const R=s.ideId||s.daemonId||"";await t(R,"new_chat",{...N(s)}),c(F=>({...F,[s.tabKey]:Date.now()})),o(F=>({...F,[s.tabKey]:[]}))}catch(R){console.error("New chat failed",R)}finally{h(!1)}}},[s,b,t,c,o,N]),y=r.useCallback(async()=>{if(!s||P)return;w(!0);const R=s.tabKey;try{await t(s.ideId,"agent_stream_focus",{agentType:s.agentType}),d(R,[200,1500,3e3])}catch(F){console.error("Focus agent failed",F)}finally{w(!1)}},[s,P,t,d]),se=r.useCallback(async()=>{var R;if(!(!s||p)){_(!0);try{const F=s.ideId||s.daemonId||"",j=await t(F,"list_chats",{forceExpand:!0,...N(s)}),H=(j==null?void 0:j.chats)||((R=j==null?void 0:j.result)==null?void 0:R.chats);j!=null&&j.success&&Array.isArray(H)&&a(s.ideId,H)}catch(F){console.error("Refresh history failed",F)}finally{_(!1)}}},[s,p,t,a,N]);return{agentInput:l,setAgentInput:u,isCreatingChat:b,isRefreshingHistory:p,isFocusingAgent:P,handleSendChat:W,handleRelaunch:O,handleLaunchIde:A,handleModalButton:v,handleSwitchSession:B,handleNewChat:I,handleFocusAgent:y,handleRefreshHistory:se}}const Ot={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 Kr(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function zr(){const[t,s]=r.useState("unix"),[n,a]=r.useState("powershell"),[i,o]=r.useState(!1),c=t==="unix"?"unix":n;r.useEffect(()=>{s(Kr())},[]);const x=r.useCallback(()=>{navigator.clipboard.writeText(Ot[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:x,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Ot[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Ot[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 Fr({conversations:t,ides:s,messageReceivedAt:n,actionLogs:a,ptyBuffers:i,screenshotMap:o,setScreenshotMap:c,sendDaemonCommand:x,updateIdeChats:d,setToasts:m,setLocalUserMessages:l,setClearedTabs:u,setActionLogs:b,pinTab:h,isStandalone:p,userName:_,groupIndex:P,isFocused:w,onFocus:N,isSplitMode:W,numGroups:O,onMoveTab:A,onClose:v,onReceiveTab:B,style:I,detectedIdes:y,handleLaunchIde:se,onActiveTabChange:R,initialActiveTabId:F,initialTabOrder:j,onTabOrderChange:H,onHideTab:ie,cliViewModes:J}){const{sendCommand:X}=nt(),q=r.useRef(null),[G,ce]=r.useState(!1),[ne,le]=r.useState(null),xe=r.useRef(0),K=r.useRef(null),[g,L]=r.useState(F??null);r.useEffect(()=>{F&&F!==g&&L(F)},[F]);const[f,z]=r.useState(j??[]),[U,te]=r.useState(null),ke=r.useRef(null),Ne=r.useRef(null);r.useEffect(()=>{const k=new Set(t.map(Z=>Z.tabKey));z(Z=>{const D=Z.filter(ee=>k.has(ee)),ue=t.filter(ee=>!Z.includes(ee.tabKey)).map(ee=>ee.tabKey),Y=[...D,...ue];return Y.length===Z.length&&Y.every((ee,de)=>ee===Z[de])?Z:Y})},[t]);const ye=U??f,pe=r.useMemo(()=>{if(ye.length===0)return t;const k=new Map(ye.map((Z,D)=>[Z,D]));return[...t].sort((Z,D)=>{const ue=k.get(Z.tabKey)??999,Y=k.get(D.tabKey)??999;return ue-Y})},[t,ye]);r.useEffect(()=>{if(pe.length===0){L(null),R==null||R(null);return}g&&pe.some(k=>k.tabKey===g)||(L(pe[0].tabKey),R==null||R(pe[0].tabKey))},[pe,g]);const E=pe.find(k=>k.tabKey===g),me=r.useCallback((k,Z,D)=>{z(ue=>{const Y=ue.filter(V=>V!==k),ee=Y.indexOf(Z);if(ee<0)return ue;const de=D==="left"?ee:ee+1;return Y.splice(de,0,k),H==null||H(Y),Y}),te(null)},[H]),ge=r.useCallback((k,Z,D)=>{const Y=(f.length>0?f:t.map(V=>V.tabKey)).filter(V=>V!==k),ee=Y.indexOf(Z);if(ee<0)return;const de=D==="left"?ee:ee+1;Y.splice(de,0,k),ke.current=Y,te(Y)},[f,t]),fe=Js({sendDaemonCommand:x,activeConv:E,ides:s,updateIdeChats:d,setToasts:m,setLocalUserMessages:l,setClearedTabs:u,setActionLogs:b,pinTab:h,isStandalone:p}),[Ce,Me]=r.useState(null);r.useEffect(()=>{if(!Ce)return;const k=Z=>{const D=document.querySelector("[data-pane-context-menu]");D&&D.contains(Z.target)||Me(null)};return window.addEventListener("mousedown",k,!0),()=>window.removeEventListener("mousedown",k,!0)},[Ce]);const et="adhdev-tab-shortcuts",ze=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[Pe,pt]=r.useState(()=>{try{return JSON.parse(localStorage.getItem(et)||"{}")}catch{return{}}}),[Ke,Ye]=r.useState(null),Ae=r.useCallback(k=>{const Z=[];k.metaKey&&Z.push(ze?"⌘":"Meta"),k.ctrlKey&&Z.push("Ctrl"),k.altKey&&Z.push(ze?"⌥":"Alt"),k.shiftKey&&Z.push(ze?"⇧":"Shift");const D=k.key;if(["Control","Alt","Shift","Meta"].includes(D))return null;const ue=D.length===1?D.toUpperCase():D;return Z.push(ue),Z.join("+")},[ze]),M=r.useCallback((k,Z)=>Ae(k)===Z,[Ae]),re=r.useCallback(k=>{pt(k),localStorage.setItem(et,JSON.stringify(k))},[]);r.useEffect(()=>{if(!Ke)return;const k=Z=>{if(Z.preventDefault(),Z.stopPropagation(),Z.key==="Escape"){Ye(null);return}const D=Ae(Z);if(!D)return;const ue={...Pe};for(const[Y,ee]of Object.entries(ue))ee===D&&delete ue[Y];ue[Ke]=D,re(ue),Ye(null)};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[Ke,Pe,re,Ae]),r.useEffect(()=>{const k=Z=>{if(!(!Z.ctrlKey&&!Z.metaKey&&!Z.altKey)){for(const[D,ue]of Object.entries(Pe))if(M(Z,ue)&&pe.some(Y=>Y.tabKey===D)){Z.preventDefault(),N(),L(D),R==null||R(D);return}}};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[Pe,pe,N,R,M]);const Q=E&&Oe(E)&&!Re(E),be=Q?J[E.tabKey]??E.mode??"terminal":"chat";r.useEffect(()=>{const k=()=>{xe.current=0,ce(!1),le(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 Z=D=>{Math.abs(D.deltaY)>Math.abs(D.deltaX)&&(D.preventDefault(),k.scrollLeft+=D.deltaY)};return k.addEventListener("wheel",Z,{passive:!1}),()=>k.removeEventListener("wheel",Z)},[]),e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:N,style:{...I,outline:G?"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:[pe.map((k,Z)=>{const D=g===k.tabKey,ue=k.status==="working"?"agent-tab-working":k.status==="waiting_approval"?"agent-tab-waiting":"",Y=k.connectionState==="failed"||k.connectionState==="closed",ee=Ne.current===k.tabKey;return e.jsxs("div",{"data-tabkey":k.tabKey,className:`${ue} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:de=>{Ne.current=k.tabKey,de.dataTransfer.setData("text/tab-key",k.tabKey),de.dataTransfer.effectAllowed="move"},onDragEnd:()=>{Ne.current=null;const de=ke.current;de&&(z(de),H==null||H(de)),ke.current=null,te(null),xe.current=0,ce(!1)},onDragOver:de=>{const V=Ne.current;if(!(!V||V===k.tabKey)&&de.dataTransfer.types.includes("text/tab-key")){de.preventDefault(),de.stopPropagation();const he=de.currentTarget.getBoundingClientRect(),Se=he.left+he.width/2,Ie=de.clientX<Se?"left":"right";ge(V,k.tabKey,Ie)}},onDrop:de=>{de.preventDefault(),de.stopPropagation();const V=de.dataTransfer.getData("text/tab-key");if(V&&V!==k.tabKey){const he=de.currentTarget.getBoundingClientRect(),Se=he.left+he.width/2,Ie=de.clientX<Se?"left":"right";pe.some($e=>$e.tabKey===V)?me(V,k.tabKey,Ie):B&&B(V)}te(null)},onClick:de=>{de.stopPropagation(),N(),L(k.tabKey),R==null||R(k.tabKey),k.streamSource==="agent-stream"&&k.agentType&&X(k.ideId,"agent_stream_focus",{agentType:k.agentType}).catch(()=>{}),Oe(k)&&setTimeout(()=>{var V,he;return(he=(V=q.current)==null?void 0:V.bumpResize)==null?void 0:he.call(V)},100)},onContextMenu:de=>{de.preventDefault(),Me({x:de.clientX,y:de.clientY,tabKey:k.tabKey})},onTouchStart:de=>{const V=de.touches[0],he=V.clientX,Se=V.clientY;K.current=setTimeout(()=>{Me({x:he,y:Se,tabKey:k.tabKey})},600)},onTouchEnd:()=>{K.current&&clearTimeout(K.current)},onTouchMove:()=>{K.current&&clearTimeout(K.current)},style:{background:D?"var(--bg-primary)":"var(--bg-glass)",borderTop:D?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:D?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:D?"1px solid var(--border-subtle)":"1px solid transparent",opacity:ee?.4:Y?D?.6:.3:D?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[k.status==="working"?e.jsx("div",{className:"tab-spinner"}):k.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):Y?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:Y?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]})]})]})})]}),Pe[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+${Pe[k.tabKey]}`,children:Pe[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")&&(xe.current++,ce(!0))},onDragOver:k=>{if(!k.dataTransfer.types.includes("text/tab-key"))return;k.preventDefault();const Z=k.currentTarget.getBoundingClientRect(),D=k.clientX-Z.left;if(O<4&&A){const ue=Z.width/3;D<ue?le("split-left"):D>ue*2?le("split-right"):le("merge");return}le("merge")},onDragLeave:()=>{xe.current--,xe.current<=0&&(xe.current=0,ce(!1),le(null))},onDrop:k=>{xe.current=0,ce(!1);const Z=k.dataTransfer.getData("text/tab-key"),D=Z?t.some(Y=>Y.tabKey===Z):!1,ue=ne;if(le(null),te(null),!!Z){if(k.preventDefault(),ue==="split-left"&&A&&O<4){A(Z,"split-left");return}if(ue==="split-right"&&A&&O<4){A(Z,"split-right");return}D?z(Y=>{const ee=Y.filter(de=>de!==Z);return ee.push(Z),H==null||H(ee),ee}):B&&B(Z)}},children:[G&&e.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none 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:O<4&&A?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:O<4&&A?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"})})]}),E?e.jsxs(e.Fragment,{children:[e.jsx(Dn,{activeConv:E,onModalButton:fe.handleModalButton}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!Q&&!Re(E)&&o[E.ideId]?e.jsx(Ln,{screenshotUrl:o[E.ideId],mode:"preview",onDismiss:()=>{const k={...o};delete k[E.ideId],c(k)}}):!Q&&!Re(E)&&E.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(Jt,{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:fe.handleRelaunch,children:"Relaunch with CDP"})]}):null}),be==="terminal"?e.jsx(Wn,{activeConv:E,ptyBuffers:i,terminalRef:q,agentInput:fe.agentInput,setAgentInput:fe.setAgentInput,handleSendChat:fe.handleSendChat}):e.jsx(Bs,{activeConv:E,ides:s,agentInput:fe.agentInput,setAgentInput:fe.setAgentInput,handleSendChat:fe.handleSendChat,handleFocusAgent:fe.handleFocusAgent,isFocusingAgent:fe.isFocusingAgent,messageReceivedAt:n,actionLogs:a,userName:_})]}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:t.length===0&&!W&&y&&se?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:p?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!p&&e.jsx(zr,{}),p&&y&&y.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:y.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:()=>se&&se(k.type),children:[e.jsx(Rs,{size:14,className:"opacity-70"})," Launch ",k.name]},k.type))})]}),!p&&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:W?"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:[A&&P>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{A(Ce.tabKey,"left"),Me(null)},children:"← Move to Left Group"}),A&&P<O-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{A(Ce.tabKey,"right"),Me(null)},children:"Move to Right Group →"}),A&&O<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{A(Ce.tabKey,"split-left"),Me(null)},children:"⇤ Split Left"}),A&&O<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{A(Ce.tabKey,"split-right"),Me(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(),Ye(Ce.tabKey),Me(null)},children:["⌨ ",Pe[Ce.tabKey]?`Change shortcut (${Pe[Ce.tabKey]})`:"Set shortcut"]}),Pe[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={...Pe};delete k[Ce.tabKey],re(k),Me(null)},children:"✕ Remove shortcut"}),ie&&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:()=>{ie(Ce.tabKey),Me(null)},children:"🚫 Hide from Dashboard"})]}),!A&&!ie&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),Ke&&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:()=>Ye(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. ",ze?"⌘+1":"Ctrl+1",", ",ze?"⌥+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 Kt=[{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 Hr({onClose:t}){const[s,n]=r.useState(0),a=Kt[s],i=s===Kt.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:Kt.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 Ur(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 Yr(t,s){return t.length!==s.length?!1:t.every((n,a)=>n===s[a])}function fs(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 It(t,s){const n=new Set(s),a=s.length>0?[0]:[];for(const[c,x]of t)!n.has(c)||x<=0||a.includes(x)||a.push(x);a.sort((c,x)=>c-x);const i={};a.forEach((c,x)=>{i[c]=x}),a.length===0&&(i[0]=0);const o=new Map;for(const[c,x]of t){if(!n.has(c)||x<=0)continue;const d=i[x];typeof d=="number"&&d>0&&o.set(c,d)}return{assignments:o,groupCount:Math.max(1,a.length),mapping:i,usedGroups:a}}function gs(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 Vr(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 Xr(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,x)=>c+x,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function qr(){const{sendCommand:t}=nt(),[s,n]=ws(),a=s.get("activeTab"),i=Pt(),{updateIdeChats:o,screenshotMap:c,setScreenshotMap:x}=i,d=i.ides||[],[m,l]=r.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),u=i.toasts||[],b=i.setToasts||(()=>{}),h=i.wsStatus||"connected",p=i.isConnected??!0,_=i.connectionStates||{};i.retryConnection;const P=i.showReconnected||!1,[w,N]=r.useState(()=>{try{const S=localStorage.getItem("adhdev_splitGroups");if(S){const C=JSON.parse(S);return new Map(C)}}catch{}return new Map}),[W,O]=r.useState(()=>{try{const S=localStorage.getItem("adhdev_focusedGroup");if(S)return parseInt(S,10)||0}catch{}return 0}),[A,v]=r.useState(()=>{try{const S=localStorage.getItem("adhdev_groupActiveTabs");if(S)return JSON.parse(S)}catch{}return{}}),B=r.useRef(!1),[I,y]=r.useState(()=>{try{const S=localStorage.getItem("adhdev_groupTabOrders");if(S)return JSON.parse(S)}catch{}return{}}),[se,R]=r.useState(()=>{try{const S=localStorage.getItem("adhdev_splitSizes");if(S)return JSON.parse(S)}catch{}return[]});r.useEffect(()=>{try{w.size===0?localStorage.removeItem("adhdev_splitGroups"):localStorage.setItem("adhdev_splitGroups",JSON.stringify([...w.entries()]))}catch{}},[w]),r.useEffect(()=>{try{se.length>0?localStorage.setItem("adhdev_splitSizes",JSON.stringify(se)):localStorage.removeItem("adhdev_splitSizes")}catch{}},[se]),r.useEffect(()=>{try{localStorage.setItem("adhdev_focusedGroup",String(W))}catch{}},[W]),r.useEffect(()=>{try{localStorage.setItem("adhdev_groupActiveTabs",JSON.stringify(A))}catch{}},[A]),r.useEffect(()=>{try{localStorage.setItem("adhdev_groupTabOrders",JSON.stringify(I))}catch{}},[I]);const[F,j]=r.useState(()=>typeof window<"u"&&window.innerWidth<768);r.useEffect(()=>{const S=window.matchMedia("(max-width: 767px)"),C=T=>j(T.matches);return S.addEventListener("change",C),()=>S.removeEventListener("change",C)},[]);const[H,ie]=r.useState({}),[J,X]=r.useState(!1),[q,G]=r.useState([]),[ce,ne]=r.useState({}),[le,xe]=r.useState({}),[K,g]=r.useState({}),L=d.find(S=>S.type==="adhdev-daemon"),f=(L==null?void 0:L.detectedIdes)||[],z=!!L,U=r.useMemo(()=>{const S=d.filter(T=>T.type!=="adhdev-daemon"),C=new Map;for(const T of S){const $=C.get(T.id);if(!$)C.set(T.id,T);else{const ae=($.workspace?1:0)+($.activeChat?1:0);((T.workspace?1:0)+(T.activeChat?1:0)>ae||(T.timestamp||0)>($.timestamp||0))&&C.set(T.id,T)}}return Array.from(C.values())},[d]),te=r.useMemo(()=>{const S=er(U,ce,d,_),C=Date.now();return S.map(T=>{const $=le[T.tabKey];return $&&C-$<5e3?{...T,messages:[],title:""}:T})},[U,ce,le,d]),{hiddenTabs:ke,toggleTab:Ne}=Or(),ye=r.useMemo(()=>te.filter(S=>!ke.has(S.tabKey)),[te,ke]),pe=r.useMemo(()=>ye.map(S=>S.tabKey),[ye]),E=r.useMemo(()=>It(w,pe),[w,pe]),me=E.assignments,ge=r.useMemo(()=>F?1:E.groupCount,[E.groupCount,F]),fe=ge>1,Ce=r.useCallback((S,C)=>{const T={};for(const[$,ae]of Object.entries(S)){const oe=Number($);T[oe>=C?oe+1:oe]=ae}return T},[]),Me=r.useCallback(S=>Array(S).fill(100/S),[]),et=r.useCallback((S,C)=>{N(T=>{const $=new Map(It(T,pe).assignments);return C===0?$.delete(S):$.set(S,C),$}),v(T=>({...T,[C]:S})),O(C)},[pe]),ze=r.useCallback(S=>{N(C=>{const T=It(C,pe).assignments,$=new Map;for(const[ae,oe]of T)oe!==S&&(oe>S?$.set(ae,oe-1):$.set(ae,oe));return $}),R(C=>{if(C.length<=1)return[];const T=[...C];T.splice(S,1);const $=T.reduce((ae,oe)=>ae+oe,0);return $>0?T.map(ae=>ae/$*100):[]}),O(0)},[pe]),Pe=r.useRef(null),pt=r.useCallback((S,C)=>{C.preventDefault();const T=Pe.current;if(!T)return;const $=C.clientX,ae=T.offsetWidth,oe=se.length===ge?[...se]:Array(ge).fill(100/ge),je=Be=>{const Ve=(Be.clientX-$)/ae*100,mt=[...oe];mt[S]=Math.max(15,oe[S]+Ve),mt[S+1]=Math.max(15,oe[S+1]-Ve),R(mt)},Te=()=>{document.removeEventListener("mousemove",je),document.removeEventListener("mouseup",Te),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",je),document.addEventListener("mouseup",Te)},[se,ge]),Ke=r.useCallback((S,C,T)=>{const $=ge;if($>=4)return;const ae=T==="left"?C:C+1;N(oe=>{const je=It(oe,pe).assignments,Te=new Map;for(const Be of ye){const Xe=je.get(Be.tabKey)??0,Ve=Xe>=ae?Xe+1:Xe;Ve>0&&Te.set(Be.tabKey,Ve)}return ae>0&&Te.set(S,ae),Te}),R(oe=>{const je=oe.length===$?[...oe]:Me($),Te=je[C]??100/$,Be=Math.max(15,Te/2),Xe=Math.max(15,Te/2),Ve=[...je];Ve[C]=Be,Ve.splice(ae,0,Xe);const mt=Ve.reduce((Lt,Zs)=>Lt+Zs,0);return Ve.map(Lt=>Lt/mt*100)}),v(oe=>{const je=Ce(oe,ae);return je[ae]=S,je}),y(oe=>{const je=Ce(oe,ae);return je[ae]=[S],je}),O(ae)},[ge,ye,pe,Me,Ce]);r.useEffect(()=>{cr()},[]);const Ye=r.useMemo(()=>ye.map(S=>({id:S.tabKey,name:S.title||S.agentName||S.ideId,status:S.status,activeModal:S.modalMessage?{message:S.modalMessage,buttons:S.modalButtons}:null})),[ye]);dr(Ye),r.useEffect(()=>{Ur(w,me)||N(me)},[w,me]),r.useEffect(()=>{const{mapping:S,usedGroups:C}=E;v(T=>{const $=gs(T,S);return fs(T,$)?T:$}),y(T=>{const $=gs(T,S);return fs(T,$)?T:$}),O(T=>{const $=F?0:Vr(T,C,S);return T===$?T:$}),R(T=>{const $=F?[]:Xr(T,C,E.groupCount);return Yr(T,$)?T:$})},[E,F]);const Ae=r.useMemo(()=>{const S=Array.from({length:ge},()=>[]);for(const C of ye){const T=me.get(C.tabKey)??0,$=Math.min(T,ge-1);S[$].push(C)}return S},[ye,me,ge]);r.useEffect(()=>{if(!a||B.current||te.length===0)return;const S=te.find(C=>C.tabKey===a)||te.find(C=>C.ideId===a)||te.find(C=>C.ideType===a||C.agentType===a);if(S){const C=me.get(S.tabKey)??0;v(T=>({...T,[C]:S.tabKey})),O(C),B.current=!0,n(T=>{const $=new URLSearchParams(T);return $.delete("activeTab"),$},{replace:!0})}},[a,te,me]),r.useEffect(()=>{if(Object.keys(le).length===0)return;const C=setTimeout(()=>{xe(T=>{const $=Date.now(),ae={};for(const[oe,je]of Object.entries(T))$-je<5e3&&(ae[oe]=je);return Object.keys(ae).length===Object.keys(T).length?T:ae})},5500);return()=>clearTimeout(C)},[le]);const M=r.useMemo(()=>{var C,T;const S=A[W];if(S){const $=te.find(ae=>ae.tabKey===S);if($)return $}return((C=Ae[W])==null?void 0:C[0])||((T=Ae[0])==null?void 0:T[0])},[A,W,te,Ae]),re=r.useMemo(()=>!M||!Oe(M)||Re(M)?null:K[M.tabKey]??M.mode??"terminal",[M,K]),Q=r.useCallback((S,C)=>{},[]);r.useEffect(()=>{const S=new Set(te.map(C=>C.tabKey));g(C=>{const T=Object.fromEntries(Object.entries(C).filter(([$])=>S.has($)));return Object.keys(T).length===Object.keys(C).length?C:T})},[te]),r.useEffect(()=>{var $;const S=Date.now();let C=!1;const T={...H};for(const ae of te)($=ae.messages)!=null&&$.length&&ae.messages.forEach((oe,je)=>{const Te=`${ae.ideId}-${oe.id??`i-${je}`}`;T[Te]==null&&(T[Te]=S,C=!0)});C&&ie(T)},[te]);const be=r.useRef(!1);r.useEffect(()=>{if(!J){be.current=!1;return}if(!M||be.current||Z)return;const S=d.find(C=>C.id===M.ideId);S&&(!S.chats||S.chats.length===0)&&(be.current=!0,ee())},[J,M==null?void 0:M.ideId]),r.useEffect(()=>{const S=setInterval(()=>{const C=Date.now()-3e5;G(T=>{const $=T.filter(ae=>ae.timestamp>C).slice(-100);return $.length===T.length?T:$})},6e4);return()=>clearInterval(S)},[]);const ve=r.useRef(new Map);r.useEffect(()=>{const S=(T,$)=>{var ae;if($){Ws.emit(T,$);for(const oe of te){if(!Oe(oe))continue;const je=(ae=oe.ideId)!=null&&ae.includes(":cli:")?oe.ideId.split(":cli:")[1]:"";if(T===je||T===oe.agentType||T===oe.ideType||T===oe.ideId||T===oe.tabKey){const Be=ve.current.get(oe.tabKey)||[];Be.push($),Be.length>1e4&&Be.splice(0,Be.length-5e3),ve.current.set(oe.tabKey,Be)}}}},C=Ht.onPtyOutput(S);return()=>{C()}},[te]),r.useEffect(()=>{const S=C=>{if(C.ctrlKey&&C.key==="\\"){if(C.preventDefault(),fe)N(new Map),O(0);else{const T=te[1];T&&Ke(T.tabKey,0,"right")}return}C.ctrlKey&&(C.key==="["||C.key==="]")&&fe&&(C.preventDefault(),O(T=>C.key==="]"?Math.min(T+1,ge-1):Math.max(T-1,0)))};return window.addEventListener("keydown",S),()=>window.removeEventListener("keydown",S)},[fe,te,Ke,ge]),r.useEffect(()=>{lt.setIdes(d)},[d]),r.useEffect(()=>{lt.setResolveAction((S,C,T)=>{t(S,C,T).catch(()=>{})})},[t]),r.useEffect(()=>{const S=lt.onToast($=>{b(oe=>oe.some(Te=>Te.message===$.message&&$.timestamp-Te.timestamp<3e3)?oe:[...oe.slice(-4),{id:$.id,message:$.message,type:$.type,timestamp:$.timestamp,ideId:$.ideId,actions:$.actions}]);const ae=$.duration||5e3;setTimeout(()=>b(oe=>oe.filter(je=>je.id!==$.id)),ae)}),C=lt.onSystemMessage(($,ae)=>{ne(oe=>{for(const je of Object.keys(oe))if(je.includes($))return{...oe,[je]:[...oe[je]||[],ae]};return oe})}),T=lt.onClearSystemMessage(($,ae)=>{ne(oe=>{const je={...oe};for(const Te of Object.keys(je))Te.includes($)&&(je[Te]=(je[Te]||[]).filter(Be=>{var Xe;return!(Be.role==="system"&&((Xe=Be._localId)!=null&&Xe.startsWith(ae)))}));return je})});return()=>{S(),C(),T()}},[]),r.useEffect(()=>{const S=Ks.on("status_event",C=>lt.handleRawEvent(C,"ws"));return()=>{S()}},[]),r.useEffect(()=>{var C;const S=T=>{const $=T.data;($==null?void 0:$.type)==="notification_action"&&$.action==="approve"&&$.ideId&&t($.ideId,"resolve_action",{action:"approve",button:"Approve"}).catch(ae=>console.error("[SW Action] approve failed:",ae))};return(C=navigator.serviceWorker)==null||C.addEventListener("message",S),()=>{var T;return(T=navigator.serviceWorker)==null?void 0:T.removeEventListener("message",S)}},[]);const{isCreatingChat:k,isRefreshingHistory:Z,handleLaunchIde:D,handleSwitchSession:ue,handleNewChat:Y,handleRefreshHistory:ee}=Js({sendDaemonCommand:t,activeConv:M,ides:d,updateIdeChats:o,setToasts:b,setLocalUserMessages:ne,setClearedTabs:xe,setActionLogs:G,pinTab:Q,isStandalone:z}),de=r.useCallback(S=>{!M||!Oe(M)||Re(M)||g(C=>({...C,[M.tabKey]:S}))},[M]),V=r.useCallback(async()=>{var T;if(!M||!Oe(M)||Re(M))return;const S=(T=M.ideId)!=null&&T.includes(":cli:")?M.ideId.split(":cli:")[1]:M.ideType||M.agentType||"";if(!window.confirm(`Stop ${S}?
54
+ This will terminate the CLI process.`))return;const C=M.ideId||M.daemonId||"";try{await t(C,"stop_cli",{cliType:S})}catch($){console.error("Stop CLI failed:",$)}},[M,t]),he=r.useMemo(()=>d.filter(S=>S.type==="adhdev-daemon"&&S.versionMismatch),[d]),[Se,Ie]=r.useState(!1),[$e,We]=r.useState({}),_e=r.useCallback(async S=>{var C,T;We($=>({...$,[S]:"upgrading"}));try{const $=await t(S,"daemon_upgrade",{});(C=$==null?void 0:$.result)!=null&&C.upgraded||(T=$==null?void 0:$.result)!=null&&T.success?We(ae=>({...ae,[S]:"done"})):We(ae=>({...ae,[S]:"error"}))}catch{We($=>({...$,[S]:"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(On,{wsStatus:h,showReconnected:P}),he.length>0&&!Se&&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(As,{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",he[0].version]})," → ",e.jsxs("strong",{children:["v",he[0].serverVersion]})]}),he.map(S=>{const C=xt(S,{fallbackId:S.id}),T=$e[S.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:C}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",S.version]}),T==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):T==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):T==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>_e(S.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:()=>_e(S.id),children:"Upgrade"})]},S.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:()=>Ie(!0),title:"Dismiss",children:"✕"})]}),e.jsx(Hn,{activeConv:M,agentCount:U.length,wsStatus:h,isConnected:p,onOpenHistory:()=>X(!0),cliViewMode:re,onSetCliViewMode:de,onStopCli:V}),e.jsx("div",{ref:Pe,className:`flex-1 min-h-0 flex ${fe?"flex-row":"flex-col"} overflow-hidden`,children:Ae.map((S,C)=>{const T=fe&&se.length===ge?`${se[C]}%`:void 0;return e.jsxs(on.Fragment,{children:[fe&&C>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:$=>pt(C-1,$),onDoubleClick:()=>ze(C),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(Fr,{style:fe?{flexBasis:T??`${100/ge}%`,flexGrow:T?0:1,flexShrink:T?0:1}:void 0,conversations:S,ides:d,messageReceivedAt:H,actionLogs:q,ptyBuffers:ve,screenshotMap:c,setScreenshotMap:x,sendDaemonCommand:t,updateIdeChats:o,setToasts:b,setLocalUserMessages:ne,setClearedTabs:xe,setActionLogs:G,pinTab:Q,isStandalone:z,userName:i.userName,groupIndex:C,isFocused:W===C,onFocus:()=>O(C),isSplitMode:fe,numGroups:ge,onMoveTab:($,ae)=>{ae==="left"&&C>0?et($,C-1):ae==="right"&&C<ge-1?et($,C+1):ae==="split-left"&&ge<4?Ke($,C,"left"):ae==="split-right"&&ge<4&&Ke($,C,"right")},onClose:fe?()=>ze(C):void 0,onReceiveTab:$=>et($,C),detectedIdes:C===0?f:void 0,handleLaunchIde:C===0?D:void 0,onActiveTabChange:$=>v(ae=>({...ae,[C]:$})),initialActiveTabId:A[C],initialTabOrder:I[C],onTabOrderChange:$=>y(ae=>({...ae,[C]:$})),onHideTab:Ne,cliViewModes:K})]},C)})}),J&&M&&e.jsx(Gn,{activeConv:M,ides:d,isCreatingChat:k,isRefreshingHistory:Z,onClose:()=>X(!1),onNewChat:Y,onSwitchSession:ue,onRefreshHistory:ee}),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(Jn,{toasts:u,onDismiss:S=>b(C=>C.filter(T=>T.id!==S)),onClickToast:S=>{if(S.ideId){const C=te.find(T=>T.ideId===S.ideId||T.tabKey===S.ideId);C&&O(me.get(C.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
+ `}),m&&e.jsx(Hr,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}l(!1)}})]})}function Gr(t){return t.split(":")[0]||""}function Jr({renderHeaderActions:t}={}){var Ne,ye,pe;const{id:s}=Ns(),n=kt(),a=Pt(),i=a.ides||[],o=a.connectionStates||{},{sendCommand:c}=nt(),x=r.useMemo(()=>Gr(s||""),[s]),d=r.useMemo(()=>i.find(E=>E.id===s),[i,s]),m=(d==null?void 0:d.type)||void 0,l=m?m.charAt(0).toUpperCase()+m.slice(1):"IDE",u=(d==null?void 0:d.activeChat)||null,b=(d==null?void 0:d.agentStreams)||[],h=a.isConnected??!0,p=o[x]||(h?"connected":"new"),_=((Ne=a.connectionTransports)==null?void 0:Ne[x])||"unknown",P=r.useMemo(()=>i.find(E=>E.id===x||E.daemonId===x),[i,x]),w=P?xt(P,{fallbackId:x}):"",N=(d==null?void 0:d.workspace)||"",[W]=ws(),O=typeof window<"u"&&window.innerWidth<=768,A=W.get("view")||(O?"chat":"split"),[v,B]=r.useState(A),[I,y]=r.useState("native"),[se,R]=r.useState(""),[F,j]=r.useState(!1),[H,ie]=r.useState(null),[J,X]=r.useState(null),[q,G]=r.useState([]),ce=u==null?void 0:u.status,ne=(((pe=(ye=u==null?void 0:u.activeModal)==null?void 0:ye.buttons)==null?void 0:pe.length)??0)>0,le=ce==="generating"||ce==="loading"||ce&&ce.toLowerCase()==="thinking",K=ne||ce==="waiting_approval"?"waiting_approval":le?"working":ce||"idle",g=r.useMemo(()=>{var E,me;return{ideId:s||"",daemonId:x,agentName:Ut(m||""),agentType:m||"",status:K,title:(u==null?void 0:u.title)||"",messages:(u==null?void 0:u.messages)||[],ideType:m||"",workspaceName:(d==null?void 0:d.workspaceName)||"",displayPrimary:l,displaySecondary:(d==null?void 0:d.workspaceName)||"",cdpConnected:!0,modalButtons:(E=u==null?void 0:u.activeModal)==null?void 0:E.buttons,modalMessage:(me=u==null?void 0:u.activeModal)==null?void 0:me.message,streamSource:"native",tabKey:`ide-${s}`}},[s,x,m,u,d,l,K]),L=r.useMemo(()=>b.map(E=>{var ge,fe;const me=E.activeModal?"waiting_approval":E.status==="streaming"?"working":E.status||"idle";return{ideId:s||"",daemonId:x,agentName:E.agentName,agentType:E.agentType,status:me,title:"",messages:E.messages.map((Ce,Me)=>({role:Ce.role,content:Ce.content,kind:Ce.kind,id:`${E.agentType}-${Me}`,receivedAt:Ce.timestamp})),ideType:E.agentType,workspaceName:"",displayPrimary:E.agentName,displaySecondary:"",cdpConnected:!0,modalButtons:(ge=E.activeModal)==null?void 0:ge.buttons,modalMessage:(fe=E.activeModal)==null?void 0:fe.message,streamSource:"agent-stream",tabKey:`agent-stream-${E.agentType}`}}),[b,s,x]),f=r.useMemo(()=>I==="native"?g:L.find(E=>E.agentType===I)||g,[I,g,L]);r.useEffect(()=>x?tt.onScreenshot("ide-page",(me,ge)=>{if(me!==x)return;const fe=new FileReader;fe.onload=()=>ie(fe.result),fe.readAsDataURL(ge)}):void 0,[x]),r.useEffect(()=>{p!=="connected"&&ie(null)},[p]),r.useEffect(()=>{var me;return x?((me=tt.onStatus)==null?void 0:me.call(tt,(ge,fe)=>{ge===x&&fe!=null&&fe.screenshotUsage&&X(fe.screenshotUsage)}))||(()=>{}):void 0},[x]);const z=r.useMemo(()=>{if(!s)return m;const E=s.split(":");return E.length>=3&&E[1]==="ide"?E.slice(2).join(":"):m},[s,m]);r.useEffect(()=>{ie(null)},[x,s,z]),r.useEffect(()=>{const E=x?tt.get(x):null;!E||!(p==="connected")||(v!=="chat"&&z?E.startScreenshots(z):E.stopScreenshots(z))},[v,p,z,x]);const U=r.useCallback(async(E,me={})=>{if(!s)throw new Error("No IDE ID");return await c(s,E,me)},[s]),te=async()=>{const E=se.trim();if(!(!E||!s||F)){R(""),j(!0);try{await U("send_chat",{message:E,text:E,waitForResponse:!0,...I!=="native"&&{agentType:I}})}catch(me){console.error("[IDE] Send failed:",me)}finally{j(!1)}}},ke=b.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(wt,{size:16}),e.jsx("span",{className:"ide-name",children:l}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),N&&e.jsx("span",{className:"ide-workspace",children:N}),e.jsx("span",{className:"ide-badge",children:"REMOTE"})]}),e.jsxs("div",{className:"ide-status-pill",children:[e.jsx("span",{className:`ide-dot ${p==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:p==="connected"?"Connected":p==="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(E=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:v===E?"1px solid var(--accent-primary)":"none",background:v===E?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:v===E?"var(--accent-primary)":void 0},onClick:()=>B(E),children:E==="chat"?e.jsx(wt,{size:14}):E==="split"?"⊞":e.jsx(rt,{size:14})},E)),t&&t({daemonId:x,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 ${v==="chat"?"full":""} ${v==="remote"?"hidden":""}`,children:[ke&&e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${I==="native"?"active":""}`,onClick:()=>y("native"),children:l}),b.map(E=>{const me=I===E.agentType,ge=E.status==="waiting_approval"||!!E.activeModal,fe=E.status==="streaming";return e.jsxs("button",{className:`ide-chat-tab ${me?"active":""}`,onClick:()=>y(E.agentType),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:ge?"#f59e0b":fe?"var(--accent-primary)":"#64748b",boxShadow:fe?"0 0 6px var(--accent-primary)":"none"}}),E.agentName,ge&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},E.agentType)})]}),e.jsx(Bs,{activeConv:f,ides:i,agentInput:se,setAgentInput:R,handleSendChat:te,handleFocusAgent:()=>{},isFocusingAgent:!1,messageReceivedAt:{},actionLogs:[],userName:a.userName})]}),e.jsx("div",{className:`ide-remote-panel ${v==="remote"?"full":""} ${v==="chat"?"hidden":""}`,children:e.jsx(Pn,{addLog:()=>{},connState:p,connScreenshot:H,screenshotUsage:J,transportType:_,onAction:async(E,me)=>{const ge=x?tt.get(x):null;if(!ge||p!=="connected")return console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"};const fe=(d==null?void 0:d.instanceId)||z;return await ge.sendInput(E,me,fe)}})})]}),q.length>0&&e.jsx("div",{className:"ide-toasts",children:q.map(E=>e.jsx("div",{className:`ide-toast ${E.type}`,onClick:()=>G(me=>me.filter(ge=>ge.id!==E.id)),children:E.message},E.id))})]}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function Zr({machineId:t,sendDaemonCommand:s,logsEndRef:n}){const[a,i]=r.useState([]),[o,c]=r.useState(null),[x,d]=r.useState(!1),[m,l]=r.useState(!1),[u,b]=r.useState(!1),[h,p]=r.useState([]),[_,P]=r.useState([]),[w,N]=r.useState(null),[W,O]=r.useState(!1),[A,v]=r.useState(""),B=r.useRef(null),I=r.useCallback(K=>{B.current=K},[]),y=r.useCallback((K,g)=>{i(L=>[...L.slice(-100),{timestamp:Date.now(),level:K,message:g}]),setTimeout(()=>{var L;return(L=n.current)==null?void 0:L.scrollIntoView({behavior:"smooth"})},100)},[n]),se=r.useCallback(async(K,g)=>{var L;if(!(!t||o)){c(K),y("info",`Launching ${He(K)}${g!=null&&g.workspace?` in ${g.workspace}`:""}...`);try{const f={ideType:K,enableCdp:!0};(L=g==null?void 0:g.workspace)!=null&&L.trim()?f.workspace=g.workspace.trim():g!=null&&g.useDefaultWorkspace&&(f.useDefaultWorkspace=!0);const z=await s(t,"launch_ide",f);y(z!=null&&z.success?"info":"error",z!=null&&z.success?`${He(K)} launched`:`Failed: ${z==null?void 0:z.error}`)}catch(f){y("error",`Launch error: ${f.message}`)}finally{c(null)}}},[t,o,y,s]),R=r.useCallback(async K=>{if(!t)return;const{cliType:g,dir:L,workspaceId:f,useDefaultWorkspace:z,useHome:U,argsStr:te,model:ke}=K;if(!g){y("warn","Select a CLI or ACP provider first");return}const Ne=te?te.split(/\s+/).filter(Boolean):void 0,ye=(L==null?void 0:L.trim())||(f?"(saved id)":z?"(default workspace)":U?"(home)":"");y("info",`Launching ${g}${ye?` in ${ye}`:""}${ke?` (model: ${ke})`:""}...`);try{const pe={cliType:g,cliArgs:Ne,initialModel:ke||void 0};L!=null&&L.trim()?pe.dir=L.trim():f?pe.workspaceId=f:z?pe.useDefaultWorkspace=!0:U&&(pe.useHome=!0);const E=await s(t,"launch_cli",pe),me=(E==null?void 0:E.result)||E;E!=null&&E.success?(y("info",`${g} launched`),(me==null?void 0:me.launchSource)==="home"?y("info","📂 Running in home directory (explicit choice)"):(me==null?void 0:me.launchSource)==="defaultWorkspace"&&y("info","📂 Using default workspace (explicit choice)")):(y("error",`Failed: ${(E==null?void 0:E.error)||(me==null?void 0:me.error)}`),(E==null?void 0:E.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&N({cliType:g,argsStr:te,model:ke}))}catch(pe){y("error",`Launch error: ${pe.message}`)}},[t,y,s]),F=r.useCallback((K,g,L,f)=>{if(t){if(!K){y("warn","Select a provider");return}if(!g.trim()){N({cliType:K,argsStr:L,model:f});return}R({cliType:K,dir:g,argsStr:L,model:f})}},[t,y,R]),j=r.useCallback(async(K,g,L)=>{if(t&&window.confirm(`Stop ${K}?
68
+ This will terminate the process.`))try{const f=await s(t,"stop_cli",{cliType:K,dir:g,_targetInstance:L});f!=null&&f.success?y("info",`${K} stopped`):y("error",`Stop failed: ${(f==null?void 0:f.error)||"Unknown error"}`)}catch(f){y("error",`Stop failed: ${f.message}`)}},[t,y,s]),H=r.useCallback(async K=>{try{await s(K.daemonId,"restart_ide",{ideType:K.type}),y("info",`${He(K.type)} restart initiated`)}catch(g){y("error",`Restart failed: ${g.message}`)}},[y,s]),ie=r.useCallback(async K=>{if(window.confirm(`Stop ${He(K.type)}?
69
+ This will disconnect CDP and optionally kill the process.`))try{const g=await s(K.daemonId,"stop_ide",{ideType:K.type,killProcess:!0});g!=null&&g.success?y("info",`${He(K.type)} stopped`):y("error",`Stop failed: ${(g==null?void 0:g.error)||"Unknown error"}`)}catch(g){y("error",`Stop failed: ${g.message}`)}},[y,s]),J=r.useCallback(async()=>{if(t)try{const K=await s(t,"detect_ides",{});y("info",`Found ${((K==null?void 0:K.result)||[]).length} IDE(s)`)}catch(K){y("error",`Detection failed: ${K.message}`)}},[t,y,s]),X=r.useCallback(async()=>{if(t){d(!0);try{const K=await s(t,"get_recent_workspaces",{});K!=null&&K.success&&Array.isArray(K==null?void 0:K.result)&&P(K.result)}catch(K){y("error",`Failed: ${K.message}`)}finally{d(!1)}}},[t,y,s]),q=r.useCallback(async K=>{if(!(!t||!K.trim())){l(!0);try{const g=await s(t,"workspace_add",{path:K.trim()});g!=null&&g.success?y("info",`Workspace added: ${K.trim()}`):y("error",(g==null?void 0:g.error)||"workspace_add failed")}catch(g){y("error",g.message)}finally{l(!1)}return!0}},[t,y,s]),G=r.useCallback(async K=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){l(!0);try{const g=await s(t,"workspace_remove",{id:K});g!=null&&g.success?y("info","Workspace removed"):y("error",(g==null?void 0:g.error)||"workspace_remove failed")}catch(g){y("error",g.message)}finally{l(!1)}}},[t,y,s]),ce=r.useCallback(async K=>{var g;if(t){l(!0);try{const L=await s(t,"workspace_set_default",K===null?{clear:!0}:{id:K});if(L!=null&&L.success){y("info",K?"Default workspace updated":"Default workspace cleared");const f=typeof L.defaultWorkspacePath=="string"?L.defaultWorkspacePath:"";f&&((g=B.current)==null||g.call(B,f))}else y("error",(L==null?void 0:L.error)||"workspace_set_default failed")}catch(L){y("error",L.message)}finally{l(!1)}}},[t,y,s]),ne=r.useCallback(async K=>{var L;if(!t||!K.trim())return;const g=K.trim();l(!0);try{const f=await s(t,"workspace_set_default",{path:g});f!=null&&f.success?(y("info","Default workspace set from history"),(L=B.current)==null||L.call(B,g)):y("error",(f==null?void 0:f.error)||"Could not set default (path missing on disk?)")}catch(f){y("error",f.message)}finally{l(!1)}},[t,y,s]),le=r.useCallback(async()=>{var K;if(t){b(!0);try{const g=await s(t,"get_cli_history",{}),L=(g==null?void 0:g.history)??((K=g==null?void 0:g.result)==null?void 0:K.history);g!=null&&g.success&&Array.isArray(L)&&p(L)}catch{}b(!1)}},[t,s]),xe=r.useCallback(async()=>{if(t)try{await s(t,"set_machine_nickname",{nickname:A}),y("info",`Nickname set to "${A||"(cleared)"}"`),O(!1)}catch(K){y("error",`Failed: ${K.message}`)}},[t,A,y,s]);return{logs:a,launchingIde:o,loadingWorkspaces:x,workspaceBusy:m,loadingHistory:u,cliHistory:h,recentWorkspaces:_,launchPick:w,setLaunchPick:N,editingNickname:W,setEditingNickname:O,nicknameInput:A,setNicknameInput:v,addLog:y,handleLaunchIde:se,runLaunchCliCore:R,handleLaunchCli:F,handleStopCli:j,handleRestartIde:H,handleStopIde:ie,handleDetectIdes:J,handleLoadRecentWorkspaces:X,handleWorkspaceAdd:q,handleWorkspaceRemove:G,handleWorkspaceSetDefault:ce,handleWorkspaceResumePath:ne,loadCliHistory:le,handleSaveNickname:xe,setOnDefaultWorkspaceChanged:I}}function Qr({machine:t,managedIdes:s,managedClis:n,managedAcps:a,actions:i}){const{workspaceBusy:o,handleWorkspaceAdd:c,handleWorkspaceRemove:x,handleWorkspaceSetDefault:d}=i,[m,l]=r.useState(""),u=t.availableMem??t.freeMem,b=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-u)/t.totalMem*100))):0,h=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(St,{icon:e.jsx(_s,{size:16}),label:"Uptime",value:Un(t.uptime)}),e.jsx(St,{icon:e.jsx(rt,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(St,{icon:e.jsx(Zt,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(St,{icon:e.jsx(Ps,{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(as,{value:Math.min(Math.round(h/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${h.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(as,{value:b,max:100,label:"Memory",color:"#3b82f6",detail:`${os(t.totalMem-u)} / ${os(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(Ft,{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:p=>void d(p.target.value===""?null:p.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(p=>e.jsx("option",{value:p.id,children:p.label||p.path},p.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:m,disabled:o,onChange:p=>l(p.target.value),onKeyDown:p=>p.key==="Enter"&&void(async()=>{await c(m)&&l("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:o,onClick:async()=>{await c(m)&&l("")},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(p=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[p.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:p.path,children:p.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:o,onClick:()=>void x(p.id),children:"Remove"})]},p.id))})]})]})}const ea={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 zt({category:t,machine:s,machineId:n,providers:a,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:x}){const d=kt(),{handleLaunchIde:m,handleLaunchCli:l,handleStopCli:u,handleRestartIde:b,handleStopIde:h,handleDetectIdes:p,cliHistory:_,loadingHistory:P,loadCliHistory:w,launchingIde:N}=c,W=ea[t],O=t==="ide",A=t==="acp",v=a.filter(f=>f.category===t),[B,I]=r.useState(""),[y,se]=r.useState(""),[R,F]=r.useState(""),[j,H]=r.useState(s.defaultWorkspaceId||""),[ie,J]=r.useState("");r.useEffect(()=>{!B&&v.length>0&&I(v[0].type)},[B,v.length]),r.useEffect(()=>{s.defaultWorkspaceId&&!j&&H(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const X=(()=>{if(j==="__custom__")return ie.trim();if(!j)return"";const f=(s.workspaces||[]).find(z=>z.id===j);return(f==null?void 0:f.path)||""})(),[q,G]=r.useState({}),[ce,ne]=r.useState(null);r.useEffect(()=>{if(!O||!n||!x)return;(async()=>{try{const z=await x(n,"get_ide_extensions",{}),U=(z==null?void 0:z.result)||z;U!=null&&U.success&&(U!=null&&U.ides)&&G(U.ides)}catch{}})()},[O,n,x]);const le=f=>O?He(f.type):t==="cli"?f.cliName:f.acpName,xe=O?s.detectedIdes||[]:[],K=()=>{O?m(B,X?{workspace:X}:void 0):l(B,X,y||void 0,A&&R||void 0)},g=f=>{O?h(f):u(f.type,f.workspace,f.id)},L=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:j,onChange:f=>{H(f.target.value),f.target.value!=="__custom__"&&J("")},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(f=>e.jsxs("option",{value:f.id,children:[f.id===s.defaultWorkspaceId?"⭐ ":"",f.label||f.path.split("/").filter(Boolean).pop()||f.path," — ",f.path]},f.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…"})]})}),j==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:ie,onChange:f=>J(f.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 ${W.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",W.label]}),L,O?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[xe.map(f=>{const z=f.running||i.some(U=>(U.type||"").toLowerCase()===(f.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>m(f.type||f.id||"",X?{workspace:X}:void 0),disabled:!!N,className:`machine-btn-primary flex items-center gap-1.5 ${z?"!border-green-500/30":""}`,style:{opacity:N&&N!==f.type?.4:1},children:[e.jsx("span",{children:o(f.type)}),z&&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)]"}),N===f.type?"⏳ Launching...":`▶ ${f.name||He(f.type)}`,z&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},f.type)}),xe.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:p,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Cn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:B,onChange:f=>I(f.target.value),className:"machine-input",children:v.length>0?v.map(f=>e.jsxs("option",{value:f.type,children:[f.icon," ",f.displayName]},f.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),A&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:R,onChange:f=>F(f.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:y,onChange:f=>se(f.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:K,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 ",W.plural," running"]}):e.jsx("div",{className:"flex flex-col gap-2.5 mb-5",children:i.map(f=>{const z=O?f:null,U=A?f:null;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(f.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[le(f),(z==null?void 0:z.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",z.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:f.workspace||"—"}),(U==null?void 0:U.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",U.currentModel]}),(U==null?void 0:U.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",U.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 ${f.status==="stopped"?"bg-red-500/[0.08] text-red-500":f.status==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:f.status}),O&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>d(`/ide/${f.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(rt,{size:13})," Control"]}),e.jsx("button",{onClick:()=>b(f),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),A&&e.jsx("button",{onClick:()=>d(`/ide/${f.id}`),className:"machine-btn",title:"View chat",children:e.jsx(wt,{size:14})}),f.status==="stopped"?e.jsx("button",{onClick:()=>O?m(f.type,f.workspace?{workspace:f.workspace}:void 0):l(f.type,f.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>g(f),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),z&&z.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:z.aiAgents.map(te=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${te.status==="generating"||te.status==="streaming"?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[te.name," · ",te.status]},te.id))}),z&&(q[z.type]||[]).length>0&&x&&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:(q[z.type]||[]).map(te=>e.jsxs("button",{disabled:ce===`${z.type}.${te.type}`,onClick:async()=>{const ke=`${z.type}.${te.type}`;ne(ke);try{await x(n,"set_ide_extension",{ideType:z.type,extensionType:te.type,enabled:!te.enabled}),G(Ne=>({...Ne,[z.type]:(Ne[z.type]||[]).map(ye=>ye.type===te.type?{...ye,enabled:!ye.enabled}:ye)}))}catch(Ne){console.error("Extension toggle failed:",Ne)}finally{ne(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 ${te.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 ${te.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),te.name,e.jsx("span",{className:"text-[9px] font-normal",children:te.enabled?"ON":"OFF"})]},te.type))})]})]},f.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:w,disabled:P,className:"machine-btn",children:P?"⏳":"↻ Load"})]}),(()=>{const f=new Set(v.map(U=>U.type)),z=_.filter(U=>(U.category||"cli")!==t?!1:t==="ide"?!0:f.has(U.cliType));return z.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:z.map((U,te)=>{var ke,Ne;return e.jsxs("div",{onClick:()=>{I(U.cliType),(U.workspace||U.dir)&&(H("__custom__"),J(U.workspace||U.dir)),se((U.cliArgs||[]).join(" ")),F(U.model||""),O&&m(U.cliType,U.workspace?{workspace:U.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(U.cliType)}),e.jsx("span",{children:((ke=U.workspace||U.dir)==null?void 0:ke.split("/").filter(Boolean).pop())||U.cliType||"root"}),U.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",U.model]}),U.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((Ne=U.cliArgs)==null?void 0:Ne.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:U.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:U.timestamp?new Date(U.timestamp).toLocaleDateString():""})]},te)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",W.label," launch history yet."]})})()]})]})}const bs=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],ta=[{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 sa({machineId:t,provider:s,sendDaemonCommand:n,onClose:a}){const[i,o]=r.useState("config"),[c,x]=r.useState("codex-cli"),[d,m]=r.useState([]),[l,u]=r.useState(""),[b,h]=r.useState([]),[p,_]=r.useState(""),P=r.useRef(null),w=r.useRef(null),N=I=>{m(y=>y.includes(I)?y.filter(se=>se!==I):[...y,I])},W=()=>m([...bs]),O=()=>m([]);r.useEffect(()=>{var I;(I=P.current)==null||I.scrollIntoView({behavior:"smooth"})},[b]),r.useEffect(()=>()=>{w.current&&clearInterval(w.current)},[]);const A=r.useCallback(()=>{w.current&&clearInterval(w.current),w.current=setInterval(async()=>{try{const I=await n(t,"provider_auto_fix_status",{providerType:s.type});(I==null?void 0:I.running)===!1&&i==="running"&&(o("done"),h(y=>[...y,`
70
+ ✅ Auto-fix completed!`]),w.current&&clearInterval(w.current))}catch{}},3e3)},[t,s.type,n,i]),v=async()=>{if(d.length!==0){o("running"),h(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${d.join(", ")}`,l?`💬 Comment: ${l}`:"",""]),_("");try{const I=await n(t,"provider_auto_fix",{providerType:s.type,functions:d,agent:c,...l?{comment:l}:{}});I!=null&&I.success&&(I!=null&&I.started||I!=null&&I.running)?(h(y=>[...y,"✅ Agent started. Monitoring progress..."]),A()):(o("error"),_((I==null?void 0:I.error)||"Failed to start auto-fix"))}catch(I){o("error"),_((I==null?void 0:I.message)||"Connection failed")}}},B=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),h(I=>[...I,`
71
+ ⚠️ Auto-fix cancelled.`]),o("done"),w.current&&clearInterval(w.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:I=>I.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:ta.map(I=>e.jsxs("button",{onClick:()=>x(I.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===I.value?I.color+"66":"var(--border-subtle)",background:c===I.value?I.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===I.value?I.color:"var(--text-primary)"},children:I.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:I.desc})]},I.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:W,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:O,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:bs.map(I=>e.jsxs("button",{onClick:()=>N(I),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:d.includes(I)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:d.includes(I)?"rgba(139,92,246,0.08)":"transparent",color:d.includes(I)?"#a78bfa":"var(--text-secondary)"},children:[d.includes(I)?"☑ ":"☐ ",I]},I))})]}),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:l,onChange:I=>u(I.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:[b.map((I,y)=>e.jsx("div",{className:I.startsWith("✅")?"text-green-400":I.startsWith("❌")||I.startsWith("⚠")?"text-amber-400":"",children:I},y)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:P})]}),p&&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:p})]})]}),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"&&d.length>0&&`${d.length} script(s) selected`,i==="running"&&"Agent is working...",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:v,disabled:d.length===0,className:"machine-btn",style:{background:d.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:d.length>0?"rgba(139,92,246,0.4)":void 0,color:d.length>0?"#a78bfa":void 0,opacity:d.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:B,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"),h([]),_("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:a,className:"machine-btn",children:"Close"})]})]})]})]})})}function na({machineId:t,providers:s,sendDaemonCommand:n,onClose:a,onCreated:i}){var A;const o=s.filter(v=>v.category==="ide"),[c,x]=r.useState(((A=o[0])==null?void 0:A.type)||""),[d,m]=r.useState(""),[l,u]=r.useState(""),[b,h]=r.useState(!1),[p,_]=r.useState(""),[P,w]=r.useState(!1),N=v=>{const B=v.toLowerCase().replace(/[^a-z0-9-]/g,"");m(B),(!l||l===W(d))&&u(W(B))},W=v=>v.split("-").map(B=>B.charAt(0).toUpperCase()+B.slice(1)).join(" "),O=async()=>{if(!(!d||!l||!c)){h(!0),_("");try{const v=await n(t,"provider_clone",{type:d,name:l,category:"ide",location:"user",cloneFrom:c});v!=null&&v.success||v!=null&&v.created?(w(!0),i==null||i(d)):_((v==null?void 0:v.error)||"Failed to create provider")}catch(v){_((v==null?void 0:v.message)||"Connection failed")}h(!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:v=>v.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:P?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:d})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",d,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",d]})," 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(v=>e.jsxs("button",{onClick:()=>x(v.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===v.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:c===v.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:v.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===v.type?"#a78bfa":"var(--text-secondary)"},children:v.displayName})]},v.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:d,onChange:v=>N(v.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/",d||"...","/"]})]})]}),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:l,onChange:v=>u(v.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"})]}),p&&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:p})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:P?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:O,disabled:!d||!l||b,className:"machine-btn",style:{background:d&&l?"rgba(34,197,94,0.12)":void 0,borderColor:d&&l?"rgba(34,197,94,0.3)":void 0,color:d&&l?"#86efac":void 0,opacity:!d||!l||b?.4:1},children:b?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function ra({machineId:t,providers:s,sendDaemonCommand:n}){const[a,i]=r.useState([]),[o,c]=r.useState(!1),[x,d]=r.useState(null),[m,l]=r.useState("all"),[u,b]=r.useState(null),[h,p]=r.useState(!1),_=r.useCallback(async()=>{var w;if(t){c(!0);try{const N=await n(t,"get_provider_settings",{}),W=(N==null?void 0:N.result)||N;if(N!=null&&N.success&&(W!=null&&W.settings)){const O=[];for(const[A,v]of Object.entries(W.settings)){const B=s.find(I=>I.type===A);O.push({type:A,displayName:(B==null?void 0:B.displayName)||A,icon:(B==null?void 0:B.icon)||"",category:(B==null?void 0:B.category)||"unknown",schema:v,values:((w=W.values)==null?void 0:w[A])||{}})}O.sort((A,v)=>A.category.localeCompare(v.category)||A.displayName.localeCompare(v.displayName)),i(O)}}catch{}c(!1)}},[t,s,n]);r.useEffect(()=>{a.length===0&&_()},[]);const P=async(w,N,W)=>{d(`${w}.${N}`),i(O=>O.map(A=>A.type===w?{...A,values:{...A.values,[N]:W}}:A));try{const O=await n(t,"set_provider_setting",{providerType:w,key:N,value:W});O!=null&&O.success||_()}catch{_()}d(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(w=>e.jsx("button",{onClick:()=>l(w),className:`machine-btn text-[10px] px-2 py-0.5 ${m===w?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:w.toUpperCase()},w))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>p(!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:_,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),m!=="all"&&a.filter(w=>w.category===m).length>1&&(()=>{const w=a.filter(A=>A.category===m),N=new Map;for(const A of w)for(const v of A.schema){if(v.type!=="boolean")continue;const B=N.get(v.key),I=!!(A.values[v.key]??v.default);B?(B.onCount+=I?1:0,B.total+=1):N.set(v.key,{label:v.label||v.key,onCount:I?1:0,total:1})}const W=[...N.entries()].filter(([,A])=>A.total===w.length);if(W.length===0)return null;const O=async(A,v)=>{for(const B of w)await P(B.type,A,v)};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 ",m.toUpperCase()," providers (",w.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:W.map(([A,v])=>{const B=v.onCount===v.total,I=v.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:v.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",v.onCount,"/",v.total,")"]}),e.jsx("button",{onClick:()=>void O(A,!0),disabled:B,className:`machine-btn text-[9px] px-1.5 py-px ${B?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void O(A,!1),disabled:I,className:`machine-btn text-[9px] px-1.5 py-px ${I?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},A)})})]})})(),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(w=>m==="all"||w.category===m).map(w=>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:w.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:w.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:w.category==="acp"?"rgba(139,92,246,0.08)":w.category==="cli"?"rgba(59,130,246,0.08)":w.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:w.category==="acp"?"#a78bfa":w.category==="cli"?"#60a5fa":w.category==="ide"?"#86efac":"#fbbf24"},children:w.category}),w.category==="ide"&&e.jsx("button",{onClick:()=>b(s.find(N=>N.type===w.type)||{type:w.type,displayName:w.displayName,icon:w.icon,category:w.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:w.schema.map(N=>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:[N.label||N.key,x===`${w.type}.${N.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),N.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:N.description})]}),e.jsx("div",{className:"shrink-0",children:N.type==="boolean"?e.jsx("button",{onClick:()=>P(w.type,N.key,!(w.values[N.key]??N.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:w.values[N.key]??N.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:w.values[N.key]??N.default?21:3}})}):N.type==="number"?e.jsx("input",{type:"number",value:w.values[N.key]??N.default??0,min:N.min,max:N.max,onChange:W=>{const O=parseInt(W.target.value)||0;N.min!==void 0&&O<N.min||N.max!==void 0&&O>N.max||P(w.type,N.key,O)},className:"machine-input w-20 text-center text-[11px]"}):N.type==="select"&&N.options?e.jsx("select",{value:w.values[N.key]??N.default??"",onChange:W=>P(w.type,N.key,W.target.value),className:"machine-input text-[11px]",children:N.options.map(W=>e.jsx("option",{value:W,children:W},W))}):e.jsx("input",{type:"text",value:w.values[N.key]??N.default??"",onBlur:W=>P(w.type,N.key,W.target.value),className:"machine-input w-[120px] text-[11px]"})})]},N.key))})]},w.type))}),u&&e.jsx(sa,{machineId:t,provider:u,sendDaemonCommand:n,onClose:()=>b(null)}),h&&e.jsx(na,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>p(!1),onCreated:()=>{p(!1),_()}})]})}function aa({machineId:t,sendDaemonCommand:s}){const[n,a]=r.useState([]),[i,o]=r.useState(0),[c,x]=r.useState(!0),[d,m]=r.useState("debug"),l=r.useRef(null),u=r.useRef(!1);return r.useEffect(()=>{if(!t||!c)return;const b=async()=>{try{const p=await s(t,"get_logs",{count:200,minLevel:d,since:i}),_=(p==null?void 0:p.result)||p;if(p!=null&&p.success&&Array.isArray(_==null?void 0:_.logs)&&_.logs.length>0){a(w=>[...w,..._.logs.map(W=>({timestamp:W.ts,level:W.level,message:`[${W.category}] ${W.message}`}))].slice(-300));const P=Math.max(..._.logs.map(w=>w.ts));o(P)}}catch{}};b();const h=setInterval(b,3e3);return()=>clearInterval(h)},[t,c,i,d,s]),r.useEffect(()=>{if(c&&n.length>0){const b=u.current?"smooth":"instant";setTimeout(()=>{var h;(h=l.current)==null||h.scrollIntoView({behavior:b}),u.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(b=>e.jsx("button",{onClick:()=>{m(b),a([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${d===b?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:b.toUpperCase()},b))]}),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:()=>x(!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((b,h)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:b.level==="error"?"#ef4444":b.level==="warn"?"#f59e0b":b.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(b.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:b.level==="error"?"#ef4444":b.level==="warn"?"#f59e0b":b.level==="debug"?"#475569":"#8b5cf6"},children:b.level==="error"?"ERR":b.level==="warn"?"WRN":b.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:b.message})]},h)),e.jsx("div",{ref:l})]})]})}function oa({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 ia(){var O,A,v,B,I,y,se,R,F;const{id:t}=Ns(),s=kt(),{sendCommand:n}=nt(),a=Pt(),i=a.ides||[],o=a.initialLoaded??!0,[c,x]=r.useState("overview"),d=r.useRef(null),m=Zr({machineId:t,sendDaemonCommand:n,logsEndRef:d}),l=i.find(j=>j.id===t&&j.daemonMode),u=((l==null?void 0:l.availableProviders)||[]).map(j=>({type:j.type,displayName:j.displayName,icon:j.icon,category:j.category})),b={};for(const j of u)b[j.type]=j.icon;const h=j=>b[j]||"",p=l?{id:l.id,hostname:zs(l,{fallbackId:l.id}),platform:((O=l.machine)==null?void 0:O.platform)||"unknown",arch:((A=l.machine)==null?void 0:A.arch)||"",cpus:((v=l.machine)==null?void 0:v.cpus)||0,totalMem:((B=l.machine)==null?void 0:B.totalMem)||0,freeMem:((I=l.machine)==null?void 0:I.freeMem)||0,availableMem:(y=l.machine)==null?void 0:y.availableMem,loadavg:((se=l.machine)==null?void 0:se.loadavg)||[],uptime:((R=l.machine)==null?void 0:R.uptime)||0,release:((F=l.machine)==null?void 0:F.release)||"",cdpConnected:!!(l.ides||[]).some(j=>j.cdpConnected),machineNickname:l.machineNickname||null,p2p:l.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:l.detectedIdes||[],managedIdeIds:l.managedIdeIds||[],managedCliIds:l.managedCliIds||[],workspaces:l.workspaces||[],defaultWorkspaceId:l.defaultWorkspaceId??l.activeWorkspaceId??null,defaultWorkspacePath:l.defaultWorkspacePath??l.activeWorkspacePath??null,workspaceActivity:l.workspaceActivity||[]}:null,_=i.filter(j=>j.daemonId===t&&!j.daemonMode).filter(j=>!is(j)&&!cs(j)).map(j=>({id:j.id,type:j.type,version:j.version||"",instanceId:j.instanceId||"",status:j.status,workspace:j.workspace||null,terminals:j.terminals||0,aiAgents:qn(j.aiAgents||j.agents||[]),activeChat:j.activeChat||null,chats:j.chats||[],agentStreams:j.agentStreams||[],cdpConnected:j.cdpConnected||!1,daemonId:t})),P=i.filter(j=>j.daemonId===t&&is(j)).map(j=>({id:j.id,type:j.type,cliName:j.cliName||j.type,status:j.status,workspace:j.workspace||"",activeChat:j.activeChat||null,daemonId:t})),w=i.filter(j=>j.daemonId===t&&cs(j)).map(j=>({id:j.id,type:j.type,acpName:j.cliName||j.type,status:j.status,workspace:j.workspace||"",activeChat:j.activeChat||null,currentModel:j.currentModel,currentPlan:j.currentPlan,daemonId:t}));if(!p)return o?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:()=>s("/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 N=xt(l,{fallbackId:p.id}),W=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(In,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(rt,{size:14})," IDEs"]}),count:_.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ut,{size:14})," CLIs"]}),count:P.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ps,{size:14})," ACP Agents"]}),count:w.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Gt,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(kn,{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:()=>s("/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:j=>m.setNicknameInput(j.target.value),onKeyDown:j=>{j.key==="Enter"&&m.handleSaveNickname(),j.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(p.machineNickname||"")},title:"Click to set nickname",children:N}),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:[p.platform," · ",p.arch," · ",p.cpus," cores"]}),(l==null?void 0:l.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",l.version]}),(l==null?void 0:l.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 n(t,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",l.serverVersion]}),p.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:p.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:p.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",p.p2p.state==="connected"?`● ${p.p2p.peers}`:"○"]}),p.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 ●"}),p.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",p.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:W.map(j=>e.jsxs("button",{onClick:()=>x(j.id),className:`machine-tab shrink-0${c===j.id?" active":""}`,children:[j.label,j.count!==void 0&&e.jsx("span",{className:"tab-count",children:j.count})]},j.id))})]}),e.jsxs("div",{className:"page-content",children:[c==="overview"&&e.jsx(Qr,{machine:p,managedIdes:_,managedClis:P,managedAcps:w,actions:m}),c==="ides"&&e.jsx(zt,{category:"ide",machine:p,machineId:t,providers:u,managedEntries:_,getIcon:h,actions:m,sendDaemonCommand:n}),c==="clis"&&e.jsx(zt,{category:"cli",machine:p,machineId:t,providers:u,managedEntries:P,getIcon:h,actions:m}),c==="acps"&&e.jsx(zt,{category:"acp",machine:p,machineId:t,providers:u,managedEntries:w,getIcon:h,actions:m}),c==="providers"&&e.jsx(ra,{machineId:t,providers:u,sendDaemonCommand:n}),c==="logs"&&e.jsx(aa,{machineId:t,sendDaemonCommand:n})]}),m.launchPick&&p&&e.jsx(oa,{machine:p,launchPick:m.launchPick,actions:m})]})}function ca(){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 x=[],d=[],m=[],l=[];Object.values(c.providers||{}).forEach(b=>{const h={name:b.name||"Unknown",status:b.status||"Stable",details:b.details||"Community Provider"};b.category==="ide"?x.push(h):b.category==="cli"?d.push(h):b.category==="extension"?m.push(h):b.category==="acp"&&l.push(h)});const u=(b,h)=>{const p={Stable:1,Beta:2,WIP:3},_=p[b.status]||99,P=p[h.status]||99;return _!==P?_-P:b.name.localeCompare(h.name)};s({ide:x.sort(u),cli:d.sort(u),ext:m.sort(u),acp:l.sort(u)})}).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(Es,{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(Jt,{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((x,d)=>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:x.name}),e.jsx("td",{className:"py-3 px-4",children:i(x.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:x.details})]},d))})]})});return n?e.jsx(_t,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(vt,{}),widthClassName:"max-w-5xl",children:e.jsx(Qt,{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(_t,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(vt,{}),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(rt,{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(Zt,{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(ut,{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(ut,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class la{constructor(){Ee(this,"adapters",new Map);Ee(this,"states",new Map);Ee(this,"ptyCallbacks",new Set);Ee(this,"screenshotCallbacks",new Map);Ee(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 la;function da(){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 ys=da(),js=3e3,ua=3e4;let Ze=null,xa=0;const Rt=new Map;let ot=null,yt=null;async function $t(t,s,n){const a=Ze;if(a&&a.readyState===WebSocket.OPEN){const o=`req_${++xa}_${Date.now()}`;return new Promise((c,x)=>{const d=setTimeout(()=>{Rt.delete(o),x(new Error(`WS command timeout: ${s}`))},3e4);Rt.set(o,{resolve:m=>{clearTimeout(d),c(m)},reject:m=>{clearTimeout(d),x(m)}}),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 pa{constructor(s){Ee(this,"daemonId");Ee(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 $t(this.daemonId,s,n)}async sendInput(s,n){const a=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId;return $t(a,"cdp_remote_action",{action:s,params:n})}startScreenshots(s){this.screenshotIdeType=s||null,ot&&(clearInterval(ot),ot=null);const n=async()=>{if(this.hasCommandChannel)try{const a=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId,i=await $t(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(),ot=setInterval(n,2e3)}stopScreenshots(s){ot&&(clearInterval(ot),ot=null)}}let st=null;function ma(t){return(!st||st.daemonId!==t)&&(st=new pa(t)),st}function ha({children:t}){const s=r.useRef(ns()),n=ns();s.current=n;const{setUserName:a}=jt(),i=r.useRef(a);i.current=a;const[,o]=r.useState("disconnected"),c=r.useCallback((u,b)=>{o(u),yt==null||yt(u,b)},[]),x=r.useRef(null),d=r.useRef(),m=r.useRef(js),l=r.useRef(!0);return r.useEffect(()=>{l.current=!0;function u(){var p,_;if(!l.current||((p=x.current)==null?void 0:p.readyState)===WebSocket.OPEN||((_=x.current)==null?void 0:_.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${ys}...`);let h;try{h=new WebSocket(ys)}catch(P){console.error("[Standalone WS] Failed to create WebSocket:",P),b();return}x.current=h,h.onopen=()=>{if(!l.current){h.close();return}c("connected"),m.current=js,console.log("[Standalone WS] Connected")},Ze=h,h.onmessage=P=>{var w;try{const N=JSON.parse(P.data);if((N.type==="command_result"||N.type==="error")&&N.requestId){const W=Rt.get(N.requestId);W&&(Rt.delete(N.requestId),N.type==="error"?W.reject(new Error(((w=N.data)==null?void 0:w.message)||"Command failed")):W.resolve(N.data));return}if(N.type==="pty_output"){Je.emitPtyOutput(N.cliId,N.data);return}if(N.type==="status"||N.type==="initial_state"){const W=N.data;if(!W)return;const{injectEntries:O,markLoaded:A}=s.current,v=W.id||"standalone",B=ma(v);Je.register(v,B),Je.setState(v,"connected"),c("connected",v),Je.emitStatus(v,W);const I=tr(W,{daemonId:v});I.length>0&&O(I),A(),W.userName&&i.current&&i.current(W.userName)}}catch(N){console.error("[Standalone WS] Parse error:",N)}},h.onclose=()=>{l.current&&(st&&Je.setState(st.daemonId,"disconnected"),c("disconnected"),x.current=null,b())},h.onerror=P=>{console.warn("[Standalone WS] Error, will reconnect:",P)}}function b(){if(!l.current)return;clearTimeout(d.current);const h=m.current;console.log(`[Standalone WS] Reconnecting in ${h}ms...`),d.current=setTimeout(()=>{m.current=Math.min(m.current*1.5,ua),u()},h)}return u(),()=>{l.current=!1,clearTimeout(d.current),x.current&&(x.current.onclose=null,x.current.close(),x.current=null,Ze=null),st&&Je.unregister(st.daemonId)}},[]),e.jsx(e.Fragment,{children:t})}function fa({children:t}){const[s,n]=r.useState("disconnected"),[a,i]=r.useState(null);r.useEffect(()=>(yt=(c,x)=>{n(c),x&&i(x)},()=>{yt=null}),[]);const o=r.useMemo(()=>{const c=s==="connected",x={};return a&&(x[a]=c?"connected":"connecting"),x.standalone=c?"connected":"connecting",{wsStatus:s,isConnected:c,connectionStates:x}},[s,a]);return e.jsx(fn,{connectionOverrides:o,children:e.jsx(ha,{children:t})})}const ga=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Is,{}),label:"Dashboard"},{id:"capabilities",path:"/capabilities",icon:e.jsx(vt,{}),label:"Capabilities"},{id:"machine",path:"/machines",icon:e.jsx(Ms,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Gt,{}),label:"Settings"}];function ba({children:t}){const s=kt(),n=cn(),[a,i]=r.useState(!1),[o,c]=r.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),x=l=>{s(l),i(!1)},d=()=>{c(l=>{const u=!l;try{localStorage.setItem("sidebar-collapsed",u?"1":"0")}catch{}return u})},m=l=>`nav-item${n.pathname.startsWith(l)?" 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:l=>l.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:ga.map(l=>e.jsxs("div",{className:m(l.path),id:`nav-${l.id}`,onClick:()=>x(l.path),title:o?l.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:l.icon}),!o&&l.label]},l.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(vt,{})}),!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(Ts,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.6.70"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:d,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 ya=[{icon:e.jsx(Ms,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(wt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx($s,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(rt,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(ut,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(vt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],ja=[{icon:e.jsx(Rs,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Is,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Ls,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Nn,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(vn,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Es,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],va=[{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 wa(){return e.jsxs(_t,{icon:e.jsx(Ts,{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.70"]}),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:ya.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:Fs.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Us.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:Hs.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:ja.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:va.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(Qt,{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.jsx("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm no-underline",children:"Discord ↗"})]})})]})}function Na(){const{ides:t}=jt(),s=t.find(u=>u.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:a}=nt(),{userName:i}=jt(),[o,c]=r.useState(i||"");r.useEffect(()=>{i!==void 0&&c(i)},[i]);const x=u=>{const b=u.target.value.trim();s!=null&&s.id&&b!==i&&a(s.id,"set_user_name",{userName:b}).catch(console.error)},[d,m]=r.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),l=u=>{m(u);try{localStorage.setItem("adhdev_sound",u?"1":"0")}catch{}};return e.jsxs(_t,{icon:e.jsx(Gt,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(hr,{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.70"]}),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(u=>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 ${u.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:u.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:u.type})]},u.type))})}),e.jsx(De,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(wr,{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(Cr,{})]}),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($r,{})]}),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(Br,{})]})]})}),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(vr,{}),e.jsx(dt,{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:d,onChange:l})]})}),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(wn,{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:u=>c(u.target.value),onBlur:x,onKeyDown:u=>{u.key==="Enter"&&u.currentTarget.blur()}})]})})})]})}Er();function vs(){const{ides:t}=jt(),s=t.find(n=>{var a;return n.daemonMode||((a=n.id)==null?void 0:a.startsWith("standalone"))});return s?e.jsx(Mt,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(Mt,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(Mt,{to:"/dashboard",replace:!0})}function ka(){return e.jsx(ln,{children:e.jsx(fa,{children:e.jsx(jn,{value:{sendCommand:$t,sendData:()=>!1},children:e.jsx(ba,{children:e.jsxs(dn,{children:[e.jsx(qe,{path:"/dashboard",element:e.jsx(qr,{})}),e.jsx(qe,{path:"/ide/:id",element:e.jsx(Jr,{})}),e.jsx(qe,{path:"/machine",element:e.jsx(vs,{})}),e.jsx(qe,{path:"/machines/:id",element:e.jsx(ia,{})}),e.jsx(qe,{path:"/machines",element:e.jsx(vs,{})}),e.jsx(qe,{path:"/capabilities",element:e.jsx(ca,{})}),e.jsx(qe,{path:"/about",element:e.jsx(wa,{})}),e.jsx(qe,{path:"/settings",element:e.jsx(Na,{})}),e.jsx(qe,{path:"*",element:e.jsx(Mt,{to:"/dashboard",replace:!0})})]})})})})})}Fn({connectionManager:Je,p2pManager:Je});un(document.getElementById("root")).render(e.jsx(r.StrictMode,{children:e.jsx(ka,{})}));