@adhdev/daemon-standalone 0.6.73 → 0.6.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,71 +0,0 @@
|
|
|
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,d,u,h,x,l,g;const n=Date.now();if(s.length===0)return t.map(f=>({...f,_lastUpdate:n}));const a=new Map;for(const f of s)a.set(f.id,f);for(const f of t){const m=a.get(f.id);if(!m){a.set(f.id,{...f,_lastUpdate:n});continue}const S=ss(f),L=ss(m);if(S>L){const v=(c=f.chats)!=null&&c.length?f.chats:m.chats;a.set(f.id,{...m,...f,chats:v,_lastUpdate:n})}else if(S<L){const v={};f.status&&f.status!==m.status&&(v.status=f.status),f.cdpConnected!==void 0&&(v.cdpConnected=f.cdpConnected),(d=f.chats)!=null&&d.length&&!((u=m.chats)!=null&&u.length)&&(v.chats=f.chats),f.machineNickname!==void 0&&f.machineNickname!==m.machineNickname&&(v.machineNickname=f.machineNickname),Object.keys(v).length>0&&a.set(f.id,{...m,...v,_lastUpdate:m._lastUpdate})}else{const v=f.timestamp||n,w=m._lastUpdate||m.timestamp||0;if(v>=w){const W=(h=f.chats)!=null&&h.length?f.chats:m.chats;a.set(f.id,{...m,...f,chats:W,_lastUpdate:n})}else(x=f.chats)!=null&&x.length&&!((l=m.chats)!=null&&l.length)&&a.set(f.id,{...m,chats:f.chats})}}const i=new Set(t.map(f=>f.id)),o=new Set;for(const f of t){const m=f.daemonId||((g=f.id)==null?void 0:g.split(":")[0]);m&&o.add(m)}for(const[f,m]of a){const S=m.daemonId||f.split(":")[0];if(!o.has(S))continue;const L=n-(m._lastUpdate||m.timestamp||0);(f.includes(":cli:")&&!i.has(f)&&L>1e4||f.includes(":acp:")&&!i.has(f)&&L>1e4||f.includes(":ide:")&&!i.has(f)&&L>3e4)&&a.delete(f)}for(const[f,m]of a)n-(m._lastUpdate||m.timestamp||0)>3e5&&m.status!=="online"&&a.delete(f);return Array.from(a.values())}function fn({children:t,connectionOverrides:s}){const[n,a]=r.useState([]),[i,o]=r.useState({}),[c,d]=r.useState(!1),[u,h]=r.useState([]),[x,l]=r.useState(void 0),g=r.useCallback((S,L)=>{a(v=>v.map(w=>w.id===S?{...w,chats:L}:w))},[]),f={injectEntries:S=>{a(L=>L.length===0?S:hn(S,L))},markLoaded:()=>d(!0),getIdes:()=>n},m=s;return e.jsx(Ss.Provider,{value:f,children:e.jsx(ks.Provider,{value:{ides:n,updateIdeChats:g,screenshotMap:i,setScreenshotMap:o,initialLoaded:c,toasts:u,setToasts:h,wsStatus:(m==null?void 0:m.wsStatus)??"connected",isConnected:(m==null?void 0:m.isConnected)??!0,connectionStates:(m==null?void 0:m.connectionStates)??{},connectionTransports:(m==null?void 0:m.connectionTransports)??{},showReconnected:(m==null?void 0:m.showReconnected)??!1,retryConnection:m==null?void 0:m.retryConnection,isP2PActive:(m==null?void 0:m.isP2PActive)??!1,p2pStates:(m==null?void 0:m.p2pStates)??{},userRole:m==null?void 0:m.userRole,userName:x,setUserName:l},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 d={"Content-Type":"application/json",...c.headers||{}},u=n==null?void 0:n();u&&(d.Authorization=`Bearer ${u}`);const h=o.startsWith("http")?o:`${s}${o.startsWith("/")?"":"/"}${o}`,x=await fetch(h,{...c,headers:d});if(x.status===401)throw a==null||a(),new Error("Unauthorized");if(!x.ok){const l=await x.json().catch(()=>({error:x.statusText}));throw new Error(l.error||`API Error: ${x.status}`)}return x.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:o=>i(`/api/v1/daemons/${o}/status`),sendCommand:(o,c,d={})=>i(`/api/v1/daemons/${o}/command`,{method:"POST",body:JSON.stringify({type:c,payload:d})}),execTerminal:(o,c,d)=>i(`/api/v1/daemons/${o}/terminal`,{method:"POST",body:JSON.stringify({command:c,name:d})}),sendAgentMessage:(o,c,d)=>i(`/api/v1/shortcuts/${o}/chat`,{method:"POST",body:JSON.stringify({agentType:c,message:d})}),getAgentStatus:o=>i(`/api/v1/shortcuts/${o}/status`),approveAgent:(o,c,d)=>i(`/api/v1/shortcuts/${o}/approve`,{method:"POST",body:JSON.stringify({agentType:c,action:d?"approve":"reject"})}),request:i}}const 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({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.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M9.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M19.35 6.07A16.03 16.03 0 0 0 15 4a.84.84 0 0 0-.46.33 11 11 0 0 0-.74 1.5 15.68 15.68 0 0 0-3.6 0 11.23 11.23 0 0 0-.74-1.5A.84.84 0 0 0 9 4a16.03 16.03 0 0 0-4.35 2.07A16.8 16.8 0 0 0 2 15a16.22 16.22 0 0 0 4 3c.12.08.27.06.37-.04a11.14 11.14 0 0 0 1.2-1.92.35.35 0 0 0-.18-.46 10.4 10.4 0 0 1-1.63-.78.36.36 0 0 1 .03-.6 6.8 6.8 0 0 0 .32-.24.36.36 0 0 1 .37-.04c2.2.98 4.6.98 6.8 0a.36.36 0 0 1 .37.04c.1.08.21.16.32.24a.36.36 0 0 1 .03.6 10.4 10.4 0 0 1-1.63.78.35.35 0 0 0-.18.46c.39.67.8 1.3 1.2 1.92a.37.37 0 0 0 .37.04 16.22 16.22 0 0 0 4-3 16.8 16.8 0 0 0-2.65-8.93z"})]})}function Rn(t){const n=t.split(`
|
|
2
|
-
`).map(d=>{if(!d.includes("\r"))return d;const u=d.split("\r").map(l=>l.trim()).filter(Boolean);if(u.length===0)return"";const h=u.filter(l=>l.startsWith("⏺"));if(h.length>0)return h[h.length-1];const x=u.filter(l=>!(/^[❯›>]\s*$/.test(l)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(l)&&l.length<40||/^[╭╰│├╮╯─═]+$/.test(l)));return x.length>0?x[x.length-1]:u[u.length-1]}).join(`
|
|
3
|
-
`).split(`
|
|
4
|
-
`),a={},i=[];let o=!1;for(const d of n){const u=d.trim();if(u===""){o=!1,i.push("");continue}if(/^❯\s*$/.test(u)||/^>\s*$/.test(u)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(u)||/^◐\s/.test(u)||/\/effort/.test(u)||/^⎿\s+(Tip|Note|Hint):/.test(u)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(u)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(u)||/Brewing[…\.]{0,3}\s*\d*$/i.test(u)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(u)||/^Auto-updating/i.test(u))continue;if(/^[⏺●·⏵]/.test(d)){const x=d.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(x)a[x[1]]=(a[x[1]]||0)+1;else{const l=d.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);l&&(a[l]=(a[l]||0)+1)}o=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(d)||/^[╭╰│├╮╯─]+/.test(u)||/^\s+[⊙✓✗○◎▸►✦]/.test(d)||o&&/^\s{2,}/.test(d))continue;o=!1;const h=d.replace(/^❯\s+/,"");i.push(h)}const c=i.join(`
|
|
5
|
-
`).replace(/\n{3,}/g,`
|
|
6
|
-
|
|
7
|
-
`).trim();return{toolCounts:a,textContent:c,hasTools:Object.keys(a).length>0}}function Dt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}const Pn=r.forwardRef(function({messages:s,actionLogs:n,agentName:a="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:d="",receivedAtMap:u={},emptyState:h,onLoadMore:x,isLoadingMore:l,hasMoreHistory:g,loadError:f},m){var J;const S=r.useRef(null),L=r.useRef(null),v=r.useRef(0),w=r.useRef(""),W=r.useRef(!1),[z,_]=r.useState(new Set),[j,O]=r.useState(new Set),M=r.useRef(!1),R=()=>{const V=S.current;return V?V.scrollHeight-V.scrollTop-V.clientHeight<200:!0},te=s.length>0?`${s.length}:${(((J=s[s.length-1])==null?void 0:J.content)||"").length}`:"0:0";r.useEffect(()=>{var ie,se;const V=!W.current,X=w.current!==d;if(w.current=d,V||X){W.current=!0,M.current=!1;const ce=()=>{var xe;(xe=L.current)==null||xe.scrollIntoView({behavior:"instant"})};requestAnimationFrame(()=>requestAnimationFrame(ce)),setTimeout(ce,100),setTimeout(ce,300),v.current=s.length;return}s.length>v.current?M.current||(ie=L.current)==null||ie.scrollIntoView({behavior:"instant"}):R()&&!M.current&&((se=L.current)==null||se.scrollIntoView({behavior:"instant"})),v.current=s.length},[te,d,c]),r.useImperativeHandle(m,()=>({scrollToBottom:(V="smooth")=>{var X;(X=L.current)==null||X.scrollIntoView({behavior:V})}})),r.useEffect(()=>{const V=S.current;if(!V)return;let X;const G=()=>{clearTimeout(X),X=setTimeout(()=>{M.current=!R()},50)};return V.addEventListener("scroll",G,{passive:!0}),()=>{V.removeEventListener("scroll",G),clearTimeout(X)}},[]);const b=r.useRef(0),F=r.useRef(!1);r.useEffect(()=>{const V=S.current;if(!V||!F.current||b.current===0)return;const X=V.scrollHeight-b.current;X>0&&(V.scrollTop=X),b.current=0,F.current=!1},[s.length]);const H=()=>{const V=S.current;V&&(b.current=V.scrollHeight),F.current=!0,x==null||x()},y=(()=>{const V=s.map((se,ce)=>({type:"message",data:se,index:ce,ts:se.receivedAt||u[se.id??`i-${ce}`]||0}));if(!n||n.length===0)return V;const X=[...n].sort((se,ce)=>se.timestamp-ce.timestamp).map((se,ce)=>({type:"action",data:se,index:ce,ts:se.timestamp})),G=[];let ie=0;for(const se of V){for(;ie<X.length&&se.ts>0&&X[ie].ts<se.ts;)G.push(X[ie++]);G.push(se)}for(;ie<X.length;)G.push(X[ie++]);return G})(),oe=700;return e.jsxs("div",{ref:S,"data-chat-scroll":!0,className:"chat-container",children:[l&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),g&&!l&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:H,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${f?"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:f?`↻ ${f}`:"↑ Load older messages"})}),y.length===0&&!g&&(h||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),y.map(V=>{var be;if(V.type==="action"){const he=V.data;return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(es,{remarkPlugins:[ts],children:he.text}),e.jsx("span",{className:"action-time",children:Dt(he.timestamp)})]},`action-${V.index}`)}const X=V.data,G=V.index,ie=(X.role||"").toLowerCase(),se=ie==="user"||ie==="human",ce=X.kind||(ie==="tool"?"tool":"standard"),xe=X.receivedAt||u[X.id??`i-${G}`],je=`${d}-${G}`,K=z.has(je),C=j.has(je),p=typeof X.content=="string"?X.content:(X.content||[]).map(he=>he.text||"").join(`
|
|
8
|
-
`);if(ce==="thought"){const he=((be=X.meta)==null?void 0:be.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:he})]}),e.jsx("div",{className:"chat-msg-body",children:p})]},`msg-${G}`)}if(ce==="tool")return e.jsxs("div",{className:"self-start chat-msg-tool",children:[e.jsx("span",{className:"tool-icon",children:"⏺"}),e.jsx("span",{className:"tool-text",children:p.split(`
|
|
9
|
-
`)[0].slice(0,80)})]},`msg-${G}`);if(ce==="terminal"){const he=X.meta||{},D=he.isRunning?"⏳":"✅",me=he.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:D}),e.jsx("span",{children:me})]}),e.jsx("pre",{className:"chat-msg-body",children:p})]},`msg-${G}`)}if(ce==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:p.slice(0,100)},`msg-${G}`);const A=!se&&o?Rn(p):null,P=A?A.textContent:p,q=A?Object.entries(A.toolCounts):[],Ie=o&&!se&&!K&&P.length>oe,ve=K?p:Ie&&!C?P.slice(0,oe):P;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${se?"self-end":"self-start"}`,children:[q.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[q.map(([he,D])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",he,D>1?` ×${D}`:""]},he)),(A==null?void 0:A.hasTools)&&e.jsx("button",{onClick:()=>_(he=>{const D=new Set(he);return K?D.delete(je):D.add(je),D}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:K?"Collapse":"Original"}),!P&&xe!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Dt(xe)})]}),(P||se)&&e.jsxs("div",{className:`chat-bubble ${se?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${P?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:se?i||"You":a}),xe!=null&&e.jsx("span",{className:"chat-time",children:Dt(xe)})]}),P&&e.jsx("div",{className:"chat-markdown",children:e.jsx(es,{remarkPlugins:[ts,tn,sn],children:ve})}),Ie&&e.jsx("button",{onClick:()=>O(he=>{const D=new Set(he);return C?D.delete(je):D.add(je),D}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:C?"Collapse ↑":`Show more (${Math.round(P.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:L})]})}),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),[d,u]=r.useState(!1);return r.useImperativeHandle(a,()=>({write:h=>{var x;(x=o.current)==null||x.write(h)},clear:()=>{var h;(h=o.current)==null||h.clear()},fit:()=>{var h;try{(h=c.current)==null||h.fit(),o.current&&(s==null||s(o.current.cols,o.current.rows))}catch{}},bumpResize:()=>{var h;try{(h=c.current)==null||h.fit();const x=o.current;if(!x)return;const l=x.cols,g=x.rows;s==null||s(l+5,g),setTimeout(()=>{s==null||s(l,g)},100)}catch{}}})),r.useEffect(()=>{if(!i.current)return;const h=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}),x=new pn,l=new mn;h.loadAddon(x),h.loadAddon(l),h.open(i.current),requestAnimationFrame(()=>{x.fit(),s==null||s(h.cols,h.rows),u(!0)});const g=h.onData(m=>{t(m)}),f=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{x.fit(),s==null||s(h.cols,h.rows)}catch{}})});return f.observe(i.current),o.current=h,c.current=x,()=>{g.dispose(),f.disconnect(),h.dispose(),o.current=null,c.current=null}},[n]),e.jsx("div",{ref:i,className:"w-full h-full rounded-lg overflow-hidden transition-opacity duration-200",style:{background:rs.background,opacity:d?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,d=c>85?"#ef4444":c>60?"#f59e0b":a;return o?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:n}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${c}%`,background:d}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${c}%`,background:`linear-gradient(90deg, ${d}, ${d}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function Ln({onAction:t,addLog:s,connState:n,connScreenshot:a,screenshotUsage:i,transportType:o}){const c=r.useRef(null),d=r.useRef(null),u=r.useRef(null),[h,x]=r.useState(null),[l,g]=r.useState(""),[,f]=r.useState(!1),[m,S]=r.useState([]),L=r.useRef(0),[v,w]=r.useState(!1),[W,z]=r.useState(!1),_=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[j,O]=r.useState(_?"mouse":"touch"),[M,R]=r.useState(1),te=r.useRef(!1),[b,F]=r.useState(1),[H,y]=r.useState(0),[oe,J]=r.useState(0),V=r.useRef(0),X=r.useRef(t),G=r.useRef(null),ie=r.useRef(null),se=r.useRef(!1),ce=r.useRef(null),xe=r.useRef(0),je=r.useRef(null),K=r.useRef(1),C=r.useRef({x:0,y:0}),p=r.useRef(!1),A=r.useRef(b),P=r.useRef(H),q=r.useRef(oe),Ie=r.useRef(j);r.useEffect(()=>{A.current=b},[b]),r.useEffect(()=>{P.current=H},[H]),r.useEffect(()=>{q.current=oe},[oe]),r.useEffect(()=>{X.current=t},[t]),r.useEffect(()=>{Ie.current=j},[j]),r.useEffect(()=>{var T;(T=c.current)==null||T.focus()},[]);const ve=n==="connected",be=a,he=ve?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",D=ve?"The remote stream is warming up":"Waiting for the remote stream to catch up";r.useEffect(()=>{if(!_||te.current||!be)return;const T=u.current,ne=d.current;if(!T||!ne)return;const Q=()=>{const ge=ne.clientWidth,Ne=ne.clientHeight,N=T.naturalWidth,Z=T.naturalHeight;if(!N||!Z||!ge||!Ne)return;const B=Math.min(ge/N,Ne/Z),U=Math.max(ge/N,Ne/Z)/B;U>1.01&&(R(U),F(U),A.current=U),te.current=!0};T.complete&&T.naturalWidth?Q():T.addEventListener("load",Q,{once:!0})},[be,_]);const me=.5;r.useEffect(()=>{b<=me&&(y(0),J(0))},[b,me]);const ue=(T,ne,Q)=>{if(Q<=me)return{x:0,y:0};const ge=(Q-1)/(2*Q)*100,Ne=(Q-1)/(2*Q)*100;return{x:Math.max(-ge,Math.min(ge,T)),y:Math.max(-Ne,Math.min(Ne,ne))}},pe=(T,ne)=>{if(!u.current)return null;const Q=u.current.getBoundingClientRect();return!Q.width||!Q.height?null:{nx:Math.max(0,Math.min(1,(T-Q.left)/Q.width)),ny:Math.max(0,Math.min(1,(ne-Q.top)/Q.height))}},Se=(T,ne,Q)=>{const ge=d.current;if(!ge)return;const Ne=ge.getBoundingClientRect(),N=++L.current;S(Z=>[...Z,{id:N,x:T-Ne.left,y:ne-Ne.top,type:Q}]),setTimeout(()=>S(Z=>Z.filter(B=>B.id!==N)),600)},Me=(T,ne,Q)=>{const ge=u.current,Ne=d.current;if(!ge||!Ne)return;const N=ge.getBoundingClientRect(),Z=Ne.getBoundingClientRect(),B=ge.naturalWidth||N.width,de=ge.naturalHeight||N.height,U=B/de,ee=N.width/N.height;let le,Y,fe,ke;U>ee?(le=N.width,Y=N.width/U,fe=0,ke=(N.height-Y)/2):(Y=N.height,le=N.height*U,fe=(N.width-le)/2,ke=0);const Ce=N.left-Z.left+fe+le*T,$e=N.top-Z.top+ke+Y*ne,We=++L.current;S(_e=>[..._e,{id:We,x:Ce,y:$e,type:Q}]),setTimeout(()=>S(_e=>_e.filter(k=>k.id!==We)),600)},et=async T=>{var Q;const ne=pe(T.clientX,T.clientY);if(ne){x(`Click: ${Math.round(ne.nx*100)}%, ${Math.round(ne.ny*100)}%`),Se(T.clientX,T.clientY,"left"),(Q=c.current)==null||Q.focus();try{const ge=await t("input_click",{nx:ne.nx,ny:ne.ny});ge!=null&&ge.success||s(`❌ Click failed: ${ge==null?void 0:ge.error}`)}catch(ge){s(`❌ Click error: ${ge.message||ge}`)}}},Ke=async(T,ne,Q,ge=0)=>{try{await t("input_key",{type:Q?"char":"keyDown",key:T,code:ne,text:Q?T:void 0,unmodifiedText:Q?T:void 0,modifiers:ge})}catch(Ne){s(`❌ Key error: ${Ne.message||Ne}`)}},Pe=async T=>{if(T.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(T.key)&&T.preventDefault();let Q=0;T.altKey&&(Q|=1),T.ctrlKey&&(Q|=2),T.metaKey&&(Q|=4),T.shiftKey&&(Q|=8),x(`Key: ${T.key}`),await Ke(T.key,T.code,T.key.length===1,Q)},pt=async T=>{if(T.key==="Enter"){if(T.nativeEvent.isComposing)return;if(l){const ne=l;g(""),x(`IME Sent: ${ne}`);try{const Q=await t("input_type",{text:ne});Q!=null&&Q.success||s(`❌ IME error: ${Q==null?void 0:Q.error}`)}catch(Q){s(`❌ IME error: ${Q.message}`)}}else x("Key: Enter"),await Ke("Enter","Enter",!1)}};r.useEffect(()=>{const T=c.current;if(!T)return;const ne=Q=>{var ge;if((ge=u.current)!=null&&ge.contains(Q.target)){Q.preventDefault();const Ne=Date.now();if(Ne-V.current<40)return;V.current=Ne;const N=pe(Q.clientX,Q.clientY);if(!N)return;x(`Scroll: ${Math.round(Q.deltaY)}`),t("input_wheel",{nx:N.nx,ny:N.ny,deltaX:Math.round(Q.deltaX),deltaY:Math.round(Q.deltaY)}).catch(()=>{})}};return T.addEventListener("wheel",ne,{passive:!1}),()=>T.removeEventListener("wheel",ne)},[t]);const[ze,Ye]=r.useState(null),Ae=r.useRef(null);return r.useEffect(()=>{if(j==="mouse"&&!Ae.current){const T={nx:.5,ny:.5};Ae.current=T,Ye(T)}},[j]),r.useEffect(()=>{const T=c.current;if(!T)return;const ne=B=>{if(!u.current)return null;const de=u.current.getBoundingClientRect();return!de.width||!de.height?null:{nx:Math.max(0,Math.min(1,(B.clientX-de.left)/de.width)),ny:Math.max(0,Math.min(1,(B.clientY-de.top)/de.height))}},Q=(B,de)=>{if(!u.current)return{dnx:0,dny:0};const U=u.current,ee=U.getBoundingClientRect(),le=U.naturalWidth||ee.width,Y=U.naturalHeight||ee.height,fe=le/Y,ke=ee.width/ee.height;let Ce,$e;return fe>ke?(Ce=ee.width,$e=ee.width/fe):($e=ee.height,Ce=ee.height*fe),{dnx:B/Ce,dny:de/$e}},ge=(B,de,U)=>{if(U<=1.05)return;const ee=-(B-.5)*100,le=-(de-.5)*100,Y=ue(ee,le,U);(Math.abs(Y.x-P.current)>.1||Math.abs(Y.y-q.current)>.1)&&(y(Y.x),J(Y.y),P.current=Y.x,q.current=Y.y)},Ne=B=>{const de=d.current;if(de&&B.target instanceof Node&&de.contains(B.target))B.preventDefault();else return;if(B.touches.length===1){const U=B.touches[0];G.current={x:U.clientX,y:U.clientY,time:Date.now()},ie.current={x:U.clientX,y:U.clientY},p.current||(se.current=!1),ce.current=setTimeout(()=>{if(!se.current&&!p.current)if(se.current=!0,Ie.current==="mouse"){const ee=Ae.current||{nx:.5,ny:.5};x("Right Click"),Me(ee.nx,ee.ny,"right"),X.current("input_click",{...ee,button:"right"}).catch(()=>{})}else{const ee=ne(U);ee&&(x("Right Click"),Me(ee.nx,ee.ny,"right"),X.current("input_click",{...ee,button:"right"}).catch(()=>{}))}},500)}else if(B.touches.length===2){clearTimeout(ce.current),se.current=!0,p.current=!0;const U=B.touches[1].clientX-B.touches[0].clientX,ee=B.touches[1].clientY-B.touches[0].clientY;je.current=Math.sqrt(U*U+ee*ee),K.current=A.current,C.current={x:(B.touches[0].clientX+B.touches[1].clientX)/2,y:(B.touches[0].clientY+B.touches[1].clientY)/2}}},N=B=>{const de=d.current;if(de&&B.target instanceof Node&&de.contains(B.target)&&B.preventDefault(),B.touches.length===1&&ie.current){const U=B.touches[0],ee=U.clientX-ie.current.x,le=U.clientY-ie.current.y;if(!se.current&&G.current){const Y=U.clientX-G.current.x,fe=U.clientY-G.current.y;Math.sqrt(Y*Y+fe*fe)>8&&(se.current=!0,clearTimeout(ce.current))}if(se.current)if(Ie.current==="mouse"){const Y=Q(ee,le),fe=Ae.current||{nx:.5,ny:.5},ke=Math.max(0,Math.min(1,fe.nx+Y.dnx)),Ce=Math.max(0,Math.min(1,fe.ny+Y.dny));Ae.current={nx:ke,ny:Ce},Ye({nx:ke,ny:Ce}),x(`Cursor: ${Math.round(ke*100)}%, ${Math.round(Ce*100)}%`),ge(ke,Ce,A.current);const $e=Date.now();$e-V.current>=30&&(V.current=$e,X.current("input_mouseMoved",{nx:ke,ny:Ce}).catch(()=>{}))}else if(A.current>1){const Y=d.current;if(Y){const fe=Y.clientWidth,ke=Y.clientHeight,Ce=P.current+ee/fe*100,$e=q.current+le/ke*100,We=ue(Ce,$e,A.current);y(We.x),J(We.y),P.current=We.x,q.current=We.y}}else{const Y=ne(U);if(Y){const fe=Date.now();fe-V.current>=40&&(V.current=fe,x("Scroll"),X.current("input_wheel",{nx:Y.nx,ny:Y.ny,deltaX:Math.round(-ee*2.5),deltaY:Math.round(-le*2.5)}).catch(()=>{}))}}ie.current={x:U.clientX,y:U.clientY}}else if(B.touches.length===2&&je.current!==null){const U=B.touches[1].clientX-B.touches[0].clientX,ee=B.touches[1].clientY-B.touches[0].clientY,Y=Math.sqrt(U*U+ee*ee)/je.current,fe=(B.touches[0].clientX+B.touches[1].clientX)/2,ke=(B.touches[0].clientY+B.touches[1].clientY)/2,Ce=fe-C.current.x,$e=ke-C.current.y,We=Math.abs(Y-1)>.03;if(Ie.current==="mouse"){if(We){const _e=Math.max(me,Math.min(5,K.current*Y));F(_e),A.current=_e}else if(Math.abs(Ce)>2||Math.abs($e)>2){const _e=Ae.current||{nx:.5,ny:.5},k=Date.now();k-V.current>=30&&(V.current=k,x("Scroll"),X.current("input_wheel",{nx:_e.nx,ny:_e.ny,deltaX:Math.round(-Ce*3),deltaY:Math.round(-$e*3)}).catch(()=>{}))}}else{const _e=Math.max(me,Math.min(5,K.current*Y));F(_e),A.current=_e;const k=d.current;if(k&&_e>1){const I=k.clientWidth,E=k.clientHeight,$=P.current+Ce/I*100,re=q.current+$e/E*100,ae=ue($,re,_e);y(ae.x),J(ae.y),P.current=ae.x,q.current=ae.y}}C.current={x:fe,y:ke}}},Z=B=>{var de;if(clearTimeout(ce.current),je.current=null,B.touches.length===1&&p.current){const U=B.touches[0];G.current={x:U.clientX,y:U.clientY,time:Date.now()},ie.current={x:U.clientX,y:U.clientY},se.current=!0;return}if(B.touches.length===0){if(p.current){p.current=!1,se.current=!1;return}if(B.changedTouches.length===1&&!se.current){const U=B.changedTouches[0],ee=Date.now(),le=ee-(((de=G.current)==null?void 0:de.time)||0);if(le<60||le>400){se.current=!1;return}if(G.current){const Y=U.clientX-G.current.x,fe=U.clientY-G.current.y;if(Math.sqrt(Y*Y+fe*fe)>12){se.current=!1;return}}if(Ie.current==="mouse"){const Y=Ae.current||ne(U);Y&&(x(`Click: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),Me(Y.nx,Y.ny,"left"),X.current("input_click",{...Y}).catch(()=>{}))}else{const Y=ne(U);if(!Y)return;ee-xe.current<300?(x("Double tap"),Me(Y.nx,Y.ny,"double"),X.current("input_click",{...Y,clickCount:2}).catch(()=>{}),xe.current=0):(x(`Tap: ${Math.round(Y.nx*100)}%, ${Math.round(Y.ny*100)}%`),Me(Y.nx,Y.ny,"left"),X.current("input_click",{...Y}).catch(()=>{}),xe.current=ee)}}se.current=!1}};return T.addEventListener("touchstart",Ne,{passive:!1}),T.addEventListener("touchmove",N,{passive:!1}),T.addEventListener("touchend",Z,{passive:!1}),()=>{T.removeEventListener("touchstart",Ne),T.removeEventListener("touchmove",N),T.removeEventListener("touchend",Z),clearTimeout(ce.current)}},[]),e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:Pe,onContextMenu:T=>T.preventDefault(),onFocus:()=>f(!0),onBlur:()=>f(!1),tabIndex:0,children:[e.jsxs("div",{ref:d,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[be?e.jsx("img",{ref:u,src:be,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${b}) translate(${H}%, ${oe}%)`,transformOrigin:"center center",cursor:j==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:et,onContextMenu:T=>T.preventDefault(),onDragStart:T=>T.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:he}),e.jsx("div",{className:"text-[11px] text-white/40",children:D}),o==="relay"&&e.jsx("div",{className:"text-[10px] text-amber-300/80",children:"TURN relay active"})]}),j==="mouse"&&ze&&be&&u.current&&(()=>{var Ce;const T=u.current,ne=T.getBoundingClientRect(),Q=(Ce=d.current)==null?void 0:Ce.getBoundingClientRect();if(!Q)return null;const ge=T.naturalWidth||ne.width,Ne=T.naturalHeight||ne.height,N=ge/Ne,Z=ne.width/ne.height;let B,de,U,ee;N>Z?(B=ne.width,de=ne.width/N,U=0,ee=(ne.height-de)/2):(de=ne.height,B=ne.height*N,U=(ne.width-B)/2,ee=0);const le=ne.left-Q.left+U+B*ze.nx,Y=ne.top-Q.top+ee+de*ze.ny,fe=Math.max(8,Math.min(Q.width-8,le)),ke=Math.max(8,Math.min(Q.height-8,Y));return e.jsxs("div",{style:{position:"absolute",left:fe-8,top:ke-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)"}})]})})(),m.map(T=>{const Q={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[T.type];return e.jsxs("div",{style:{position:"absolute",left:T.x,top:T.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}})]},T.id)})]}),e.jsxs("div",{onTouchStart:T=>T.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:()=>{O(T=>{const ne=T==="touch"?"mouse":"touch";if(ne==="mouse"&&!Ae.current){const Q={nx:.5,ny:.5};Ae.current=Q,Ye(Q)}return ne})},className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${j==="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:j==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${j==="mouse"?"text-blue-400":"text-slate-400"}`,children:j==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{z(!W),w(!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:l,autoFocus:!0,onTouchStart:T=>T.stopPropagation(),onChange:T=>g(T.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:()=>{w(!v),z(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${v?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:ve?"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:ve?"#22c55e":"#eab308",boxShadow:ve?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:ve?"#22c55e":"#eab308"},children:ve?"Connected":"WS"})]}),b>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(b*100),"%"]}),o==="direct"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:"Direct P2P connection",children:"Direct"}),o==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#f59e0b",background:"rgba(245,158,11,0.12)"},title:"TURN relay in use",children:"Relay"}),i&&i.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:i.budgetExhausted?"#ef4444":"#c4b5fd",background:i.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:i.budgetExhausted?"TURN blocked":`TURN ${i.dailyUsedMinutes}/${i.dailyBudgetMinutes}m`}),h&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:h})]})]}),v&&e.jsxs("div",{onTouchStart:T=>T.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",b<=(_?M:1)+.01?_?"FILL":"FIT":`${Math.round(b*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:T=>{T.stopPropagation(),F(ne=>Math.max(.5,ne-.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:T=>{T.stopPropagation();const ne=_?M:1;F(ne),A.current=ne,y(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:_?"FILL":"FIT"}),e.jsx("button",{onClick:T=>{T.stopPropagation(),F(ne=>Math.min(5,ne+.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 Dn({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:a=!1,connectionState:i,onDismiss:o,onClickAt:c,onKeyDown:d,badge:u,emptyMessage:h,aspectRatio:x,className:l,style:g}){const f=r.useRef(null),m=r.useCallback(S=>{if(!a||!c||!f.current)return;const L=f.current,v=L.getBoundingClientRect(),w=(S.clientX-v.left)/v.width*L.naturalWidth,W=(S.clientY-v.top)/v.height*L.naturalHeight;c(w,W,L.naturalWidth,L.naturalHeight)},[a,c]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${l||""}`,style:{aspectRatio:x||"16/9",...g},children:[e.jsx("img",{ref:f,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":""} ${l||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:a?0:void 0,onKeyDown:a?d:void 0,style:g,children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",onClick:a?m:void 0,className:"max-w-full max-h-full object-contain",style:{...a?{cursor:"crosshair"}:{},...n!==100?{transform:`scale(${n/100})`,transformOrigin:"center center"}:{}}}),u&&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:u})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${l||""}`,style:g,children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.22)] mb-1",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("p",{className:"text-base",children:h||"Waiting for screenshot stream..."}),i&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",i]}),e.jsx("style",{children:`
|
|
33
|
-
@keyframes remote-float {
|
|
34
|
-
0% { transform: translateY(0px); }
|
|
35
|
-
50% { transform: translateY(-7px); }
|
|
36
|
-
100% { transform: translateY(0px); }
|
|
37
|
-
}
|
|
38
|
-
`})]})}function Bn({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,d)=>{const u=o(c).toLowerCase(),h=/^(run|approve|accept|yes|allow|always)/.test(u),x=/^(reject|deny|delete|remove|abort)/.test(u),l=n===c,g=n!==null;return e.jsx("button",{onClick:()=>i(c),disabled:g,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${h?"bg-white text-amber-700 font-extrabold":x?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${g&&!l?"opacity-40":"opacity-100"} ${g?"cursor-not-allowed":"cursor-pointer"}`,children:l?"⏳ ...":o(c)},d)})})]})]})}const Fe=new Map;function Wn({ideId:t,ideType:s,agentType:n,agentName:a,serverModel:i,serverMode:o,acpConfigOptions:c,acpModes:d}){var je;const{sendCommand:u}=nt(),h=!!(c||d),x=`${t}:${n}`,l=Fe.get(x),[g,f]=r.useState(!1),[m,S]=r.useState(!1),[L,v]=r.useState((l==null?void 0:l.models)||[]),[w,W]=r.useState((l==null?void 0:l.modes)||[]),z=K=>K?typeof K=="string"?K:typeof K=="object"?K.name||K.id||JSON.stringify(K):String(K):"",[_,j]=r.useState(z(i)),[O,M]=r.useState(z(o)),[R,te]=r.useState(!1),[b,F]=r.useState(!1),H=r.useRef(0),y=K=>K.map(C=>typeof C=="string"?C:(C==null?void 0:C.name)||(C==null?void 0:C.id)||String(C));r.useEffect(()=>{if(c){const K=c.find(C=>C.category==="model");if(K){const C=y(K.options.map(A=>A.value));v(C),K.currentValue&&j(z(K.currentValue));const p=Fe.get(x)||{models:[],modes:[]};Fe.set(x,{...p,models:C})}}if(d&&d.length>0){const K=y(d.map(p=>p.id));W(K);const C=Fe.get(x)||{models:[],modes:[]};Fe.set(x,{...C,modes:K})}else if(c){const K=c.find(C=>C.category!=="model");if(K){const C=y(K.options.map(A=>A.value));W(C),K.currentValue&&M(z(K.currentValue));const p=Fe.get(x)||{models:[],modes:[]};Fe.set(x,{...p,modes:C})}}},[c,d,x]),r.useEffect(()=>{f(!1),S(!1),j(z(i)),M(z(o));const K=Fe.get(x);K?(v(K.models),W(K.modes)):(v([]),W([]))},[t,n]),r.useEffect(()=>{i&&Date.now()>H.current&&j(z(i))},[i]),r.useEffect(()=>{o&&Date.now()>H.current&&M(z(o))},[o]);const oe=r.useCallback(async(K,C={})=>{const p={...C},A=t.split(":");return A.length>=3&&(A[1]==="ide"||A[1]==="cli"||A[1]==="acp")&&(p._targetInstance=A.slice(2).join(":"),p._targetType=A[1]),await u(t,K,p)},[t]),J=async()=>{var K,C;if(L.length>0){f(!g);return}if(h){f(!0);return}te(!0);try{const p=await oe("list_extension_models",{agentType:n,ideType:s}),A=(p==null?void 0:p.models)||((K=p==null?void 0:p.result)==null?void 0:K.models)||[],P=y(A);v(P),p!=null&&p.current&&j(z(p.current)),(C=p==null?void 0:p.result)!=null&&C.current&&j(z(p.result.current));const q=Fe.get(x)||{models:[],modes:[]};Fe.set(x,{...q,models:P}),f(!0)}catch{}finally{te(!1)}},V=async()=>{var K,C;if(w.length>0){S(!m);return}if(h){S(!0);return}F(!0);try{const p=await oe("list_extension_modes",{agentType:n,ideType:s}),A=(p==null?void 0:p.modes)||((K=p==null?void 0:p.result)==null?void 0:K.modes)||[],P=y(A);W(P),p!=null&&p.current&&M(z(p.current)),(C=p==null?void 0:p.result)!=null&&C.current&&M(z(p.result.current));const q=Fe.get(x)||{models:[],modes:[]};Fe.set(x,{...q,modes:P}),S(!0)}catch{}finally{F(!1)}},X=async K=>{f(!1),j(K),H.current=Date.now()+5e3;try{h?await oe("change_model",{agentType:n,ideType:s,model:K}):await oe("set_extension_model",{agentType:n,ideType:s,model:K})}catch{}},G=h&&!(d&&d.length>0)&&(c==null?void 0:c.some(K=>K.category!=="model")),ie=G?(je=c==null?void 0:c.find(K=>K.category!=="model"))==null?void 0:je.configId:void 0,se=async K=>{S(!1),M(K),H.current=Date.now()+5e3;try{h&&G&&ie?await oe("set_thought_level",{agentType:n,ideType:s,configId:ie,value:K}):h?await oe("set_mode",{agentType:n,ideType:s,mode:K}):await oe("set_extension_mode",{agentType:n,ideType:s,mode:K})}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:g?`${xe}55`:"transparent",border:"1px solid",color:_?"var(--text-primary)":"var(--text-muted)"},onClick:J,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),R?"...":_||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),g&&L.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>f(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:"SELECT MODEL"}),L.map(K=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:K===_?`${xe}18`:"transparent",color:K===_?xe:"var(--text-secondary)",fontWeight:K===_?600:400,borderLeft:K===_?`2px solid ${xe}`:"2px solid transparent"},onMouseEnter:C=>{C.currentTarget.style.background=`${xe}12`},onMouseLeave:C=>{C.currentTarget.style.background=K===_?`${xe}18`:"transparent"},onClick:()=>X(K),children:K},K))]})]})]}),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:m?`${xe}55`:"transparent",border:"1px solid",color:O?"var(--text-primary)":"var(--text-muted)"},onClick:V,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:G?"🧠":"⚡"}),b?"...":O||(G?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),m&&w.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>S(!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"}),w.map(K=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:K===O?`${xe}18`:"transparent",color:K===O?xe:"var(--text-secondary)",fontWeight:K===O?600:400,borderLeft:K===O?`2px solid ${xe}`:"2px solid transparent"},onMouseEnter:C=>{C.currentTarget.style.background=`${xe}12`},onMouseLeave:C=>{C.currentTarget.style.background=K===O?`${xe}18`:"transparent"},onClick:()=>se(K),children:K},K))]})]})]})]})}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:d,actionLogs:u,userName:h}){const x=r.useRef(null),{sendCommand:l}=nt(),g=r.useRef(new Map),f=r.useCallback(R=>(g.current.has(R)||g.current.set(R,{messages:[],offset:0,hasMore:!0,error:null}),g.current.get(R)),[]),m=r.useCallback((R,te)=>{const b=f(R);g.current.set(R,{...b,...te}),S(F=>F+1)},[f]),[,S]=r.useState(0),L=t.tabKey,v=f(L),w=v.messages,W=v.hasMore,z=v.error,[_,j]=r.useState(!1),O=r.useCallback(async()=>{var b,F;if(_)return;const R=t.tabKey,te=f(R);j(!0),m(R,{error:null});try{const H=s.find(ie=>ie.id===t.ideId),y=(H==null?void 0:H.daemonId)||((b=t.ideId)==null?void 0:b.split(":")[0])||"";if(!y){m(R,{hasMore:!1});return}const oe=t.ideType||t.agentType||"",J=(t.ideId||"").split(":"),V=J.length>=3?J.slice(2).join(":"):void 0,X=await l(y,"chat_history",{agentType:oe,offset:te.offset,limit:30,instanceId:V}),G=(X==null?void 0:X.result)??X;if(((F=G.messages)==null?void 0:F.length)>0){const ie=f(R);m(R,{messages:[...G.messages,...ie.messages],offset:ie.offset+G.messages.length,hasMore:!!G.hasMore})}else m(R,{hasMore:!!G.hasMore})}catch(H){const y=(H==null?void 0:H.message)||"";y.includes("P2P not available")||y.includes("channel not open")||y.includes("P2P not connected")||y.includes("timeout")?m(R,{error:"Connection not ready — tap to retry"}):m(R,{hasMore:!1,error:"Failed to load history"})}finally{j(!1)}},[_,s,t,l,f,m]),M=(()=>{const R=t.messages.map((F,H)=>{const y=`${t.ideId}-${F.id??`i-${H}`}`;return{...F,receivedAt:F.receivedAt||d[y]||0}});if(w.length===0)return R;const te=new Set(R.map(F=>`${F.role}:${(F.content||"").slice(0,100)}`));return[...w.filter(F=>!te.has(`${F.role}:${(F.content||"").slice(0,100)}`)),...R]})();return e.jsxs(e.Fragment,{children:[e.jsx(Pn,{messages:M,actionLogs:u.filter(R=>R.ideId===t.tabKey).sort((R,te)=>R.timestamp-te.timestamp),agentName:t.agentName||t.displayPrimary||"Agent",userName:h,isCliMode:Oe(t)||Re(t),isWorking:t.status==="working",contextKey:t.tabKey,onLoadMore:O,isLoadingMore:_,hasMoreHistory:W,loadError:z??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"&&!_?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 te,b,F,H;const R=s.find(y=>y.id===t.ideId);return e.jsx(Wn,{ideId:t.ideId,ideType:t.ideType,agentType:t.streamSource==="agent-stream"?t.agentType:((b=(te=R==null?void 0:R.agents)==null?void 0:te[0])==null?void 0:b.type)||t.ideType,agentName:t.streamSource==="agent-stream"?t.agentName:((H=(F=R==null?void 0:R.agents)==null?void 0:F[0])==null?void 0:H.name)||t.agentName,serverModel:(R==null?void 0:R.currentModel)||void 0,serverMode:(R==null?void 0:R.currentPlan)||void 0,acpConfigOptions:Re(t)?R==null?void 0:R.acpConfigOptions:void 0,acpModes:Re(t)?R==null?void 0:R.acpModes:void 0})})(),e.jsx("div",{className:"dashboard-input-area px-3 py-2.5 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:x,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:n,onChange:R=>a(R.target.value),onPaste:R=>{const te=R.clipboardData.getData("text");te&&a(b=>b+te),R.preventDefault()},onKeyDown:R=>{if(R.key==="Enter"){if(R.nativeEvent.isComposing){R.preventDefault();return}R.preventDefault(),i()}},onBlur:R=>{if(window.innerWidth<768){const te=R.relatedTarget;if((te==null?void 0:te.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 On({activeConv:t,ptyBuffers:s,terminalRef:n,agentInput:a,setAgentInput:i,handleSendChat:o}){var g;const c=r.useRef(null),{sendCommand:d,sendData:u}=nt(),h=(g=t.ideId)!=null&&g.includes(":cli:")?t.ideId.split(":cli:")[1]:"",x=t.tabKey,l=t.ideType||t.agentType||"";return r.useEffect(()=>{const f=s.current.get(x);if(f&&f.length>0){const m=setTimeout(()=>{var S;for(const L of f)(S=n.current)==null||S.write(L);requestAnimationFrame(()=>{var L;(L=n.current)==null||L.bumpResize()})},100);return()=>clearTimeout(m)}},[x]),r.useEffect(()=>{const f=Ws.on((m,S)=>{var v;if(!S)return;(m===h||m===l||m===t.ideId||m===t.tabKey)&&((v=n.current)==null||v.write(S))});return()=>{f()}},[h,l]),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:f=>{var L;const m=t.ideId||t.daemonId||"",S=(L=t.ideId)!=null&&L.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";u!=null&&u(m,{type:"pty_input",cliType:S,data:f})||d(m,"pty_input",{cliType:S,data:f}).catch(console.error)},onResize:(f,m)=>{var v;const S=t.ideId||t.daemonId||"",L=(v=t.ideId)!=null&&v.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";u!=null&&u(S,{type:"pty_resize",cliType:L,cols:f,rows:m})||d(S,"pty_resize",{cliType:L,cols:f,rows:m,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:f=>i(f.target.value),onPaste:f=>{const m=f.clipboardData.getData("text");m&&i(S=>S+m),f.preventDefault()},onKeyDown:f=>{if(f.key==="Enter"){if(f.nativeEvent.isComposing){f.preventDefault();return}f.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 zn({wsStatus:t,showReconnected:s,loginUrl:n}){const a=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"violet",o={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",violet:"linear-gradient(90deg, rgba(139,92,246,0.12), rgba(139,92,246,0.04))"},c={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",violet:"1px solid rgba(139,92,246,0.2)"},d={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[a&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:o[i],borderBottom:c[i],color:d[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(n?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:n,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — please restart the server.")]}),s&&t==="connected"&&e.jsxs("div",{className:"py-2 px-4 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-b border-green-500/15 animate-[fadeIn_0.3s_ease]",children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})]})}let 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 zs=new Kn;class Fn{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 Fn,Ht=tt;function Hn(t){t.dashboardWS&&(zs=t.dashboardWS),t.connectionManager&&(tt=t.connectionManager,Ht=t.connectionManager),t.p2pManager&&(Ht=t.p2pManager),t.useDaemonsHook&&(Os=t.useDaemonsHook)}function Un({activeConv:t,agentCount:s,wsStatus:n,isConnected:a,onOpenHistory:i,cliViewMode:o,onSetCliViewMode:c,onStopCli:d}){const u=kt(),h=Pt(),x=h.p2pStates||{},l=h.ides||[],g=!!t&&Oe(t)&&!Re(t),f=a?"#22c55e":n==="connected"?"#eab308":"#ef4444",m=a?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",S=l.filter(_=>_.type==="adhdev-daemon"),L=Object.values(x),v=L.filter(_=>_==="connected").length,w=L.filter(_=>_==="connecting"||_==="new"||_==="checking").length,z=n!=="connected"||S.length===0?null:w>0&&v===0?"P2P connecting...":v>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:f,boxShadow:m}})})]}),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:f,boxShadow:m}}),z&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",z]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[g&&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"})]}),g&&d&&e.jsx("button",{onClick:d,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&&!g&&!Re(t)&&e.jsxs("button",{onClick:()=>u(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Zt,{size:14})," IDE"]}),t&&!g&&!Re(t)&&e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Sn,{size:16})}),t&&!g&&!Re(t)&&e.jsx("button",{onClick:()=>u(`/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 Yn(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 Vn(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 Xn(t){return Vn(t.trim().replace(/\.local$/i,""))}function qn(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Ks(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 Xn(n);const a=s.fallbackId||t.id;return a?`Machine-${a.substring(0,8)}`:s.fallbackLabel||"Machine"}function xt(t,s={}){return qn(t)||Ks(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 Gn(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"),d=n.indexOf(a.status||"idle");d>=0&&(c<0||d<c)&&s.set(i,a)}return Array.from(s.values())}function Jn({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:a,onClose:i,onNewChat:o,onSwitchSession:c,onRefreshHistory:d}){var l;const u=s.find(g=>g.id===t.ideId),h=(u==null?void 0:u.chats)||[],x=(l=u==null?void 0:u.activeChat)==null?void 0:l.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"}),h.map(g=>e.jsxs("div",{onClick:()=>{c(t.ideId,g.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${x===g.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${x===g.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:g.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:[g.id.substring(0,12),"..."]}),x===g.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},g.id)),h.length===0&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx(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:d,disabled:a,className:"btn btn-secondary btn-sm rounded-[10px]",children:a?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(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 Zn({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 Qn=t=>(t.id||"").includes(":cli:")||(t.id||"").includes(":acp:")||(t.id||"").includes(":ide:")?!0:t.daemonId!==t.id;function er(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function tr(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 v,w,W,z,_;const c=[],d=o.daemonId&&i[o.daemonId]||void 0,u=o.daemonId||((v=o.id)==null?void 0:v.split(":")[0])||o.id,h=a?a[u]||"new":void 0,x=er(o),l=He(o.type),g=o.agentStreams,f=Array.isArray(g)?g.map(j=>({...j,activeModal:j.activeModal??void 0})):[],m=Qn(o),S=o.activeChat||{title:""},L=S.title&&String(S.title).trim()?String(S.title).trim():"";if(m){const j=Ut(o.type),O=(w=o.agents)==null?void 0:w[0],M=(W=o.activeChat)==null?void 0:W.activeModal,R=M&&Array.isArray(M.buttons)&&M.buttons.length>0,te=(z=o.activeChat)==null?void 0:z.status,b=te==="generating"||te==="loading"||te&&te.toLowerCase()==="thinking",H=R||te==="waiting_approval"?"waiting_approval":b?"working":(O==null?void 0:O.status)||"idle",y=o.activeChat||{title:"",messages:[]};let oe=y.title&&String(y.title).trim()?String(y.title).trim():"";const J=(_=o.activeChat)==null?void 0:_.id,V=o.chats;if(J&&Array.isArray(V)&&V.length>0){const ce=V.find(xe=>xe.id===J||xe.id&&String(xe.id)===String(J));ce!=null&&ce.title&&String(ce.title).trim()&&(oe=String(ce.title).trim())}const X=y.messages||[],G=s[o.id]||[],ie=new Map;X.filter(ce=>ce.role==="user").forEach(ce=>{ie.set(ce.content,(ie.get(ce.content)||0)+1)});const se=G.filter(ce=>{const xe=ie.get(ce.content)||0;return xe>0?(ie.set(ce.content,xe-1),!1):!0});c.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:Oe(o)?o.mode||"terminal":"chat",agentName:j,agentType:Oe(o)||Re(o)?o.cliType||o.acpType||o.type:(O==null?void 0:O.type)||"ide-native",status:H,title:oe,messages:[...X,...se],ideType:o.cliType||o.acpType||o.type,workspaceName:x,displayPrimary:oe||x||(Oe(o)||Re(o)?"Terminal":j),displaySecondary:l,cdpConnected:o.cdpConnected,modalButtons:R?M.buttons:void 0,modalMessage:R?M.message:void 0,streamSource:"native",tabKey:o.id,machineName:d,connectionState:h})}if(m&&(Oe(o)||Re(o)))return c;for(const j of f){const O=j.activeModal&&Array.isArray(j.activeModal.buttons)&&j.activeModal.buttons.length>0,M=O?"waiting_approval":j.status==="streaming"?"working":j.status,R=`${o.id}:${j.agentType}`,te=j.messages||[],b=s[R]||[],F=new Map;te.filter(y=>y.role==="user").forEach(y=>{F.set(y.content,(F.get(y.content)||0)+1)});const H=b.filter(y=>{const oe=F.get(y.content)||0;return oe>0?(F.set(y.content,oe-1),!1):!0});c.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:"chat",agentName:j.agentName,agentType:j.agentType,status:M,title:"",messages:[...te,...H],ideType:j.agentType,workspaceName:x,displayPrimary:L||x||j.agentName,displaySecondary:`${l}·${j.agentName}`,cdpConnected:o.cdpConnected,modalButtons:O?j.activeModal.buttons:void 0,modalMessage:O?j.activeModal.message:void 0,streamSource:"agent-stream",tabKey:R,machineName:d,connectionState:h})}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:x,displayPrimary:x||l,displaySecondary:l,cdpConnected:o.cdpConnected,streamSource:"native",tabKey:o.id,connectionState:h}),c})}function sr(t,s){var d,u,h,x;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(l=>l.cdpConnected),managedIdeIds:t.managedIdes.map(l=>`${a}:ide:${l.instanceId}`),managedCliIds:t.managedClis.map(l=>l.id?`${a}:cli:${l.id}`:`${a}:cli:${l.cliType}`),managedAcpIds:t.managedAcps.map(l=>l.id?`${a}:acp:${l.id}`:`${a}:acp:${l.acpType}`)});for(const l of t.managedIdes)n.push({id:`${a}:ide:${l.instanceId}`,type:l.ideType,ideType:l.ideType,version:l.ideVersion,status:l.cdpConnected?"online":"detected",daemonId:a,instanceId:l.instanceId,workspace:l.workspace,terminals:l.terminals,agents:l.aiAgents,activeChat:l.activeChat,chats:l.chats,agentStreams:l.agentStreams,cdpConnected:l.cdpConnected,currentModel:l.currentModel,currentPlan:l.currentPlan,currentAutoApprove:l.currentAutoApprove,timestamp:c});for(const l of t.managedClis){const g=l.id?`${a}:cli:${l.id}`:`${a}:cli:${l.cliType}`;n.push({id:g,type:l.cliType,ideType:l.cliType,agentType:l.cliType,status:l.status||"running",daemonId:a,instanceId:l.id,cliName:l.cliName,mode:l.mode||"terminal",workspace:l.workspace,activeChat:l.activeChat,agentStreams:[{agentType:l.cliType,agentName:l.cliName,extensionId:"cli-agent",status:l.status==="generating"?"streaming":l.status==="waiting_approval"?"waiting_approval":"idle",messages:((d=l.activeChat)==null?void 0:d.messages)||[],inputContent:"",activeModal:(u=l.activeChat)==null?void 0:u.activeModal}],timestamp:c,_isCli:!0})}for(const l of t.managedAcps){const g=l.id?`${a}:acp:${l.id}`:`${a}:acp:${l.acpType}`;n.push({id:g,type:l.acpType,ideType:l.acpType,agentType:l.acpType,status:l.status||"running",daemonId:a,instanceId:l.id,cliName:l.acpName,mode:"chat",workspace:l.workspace,activeChat:l.activeChat,currentModel:l.currentModel,currentPlan:l.currentPlan,acpConfigOptions:l.acpConfigOptions,acpModes:l.acpModes,agentStreams:[{agentType:l.acpType,agentName:l.acpName,extensionId:"acp-agent",status:l.status==="generating"?"streaming":l.status==="waiting_approval"?"waiting_approval":"idle",messages:((h=l.activeChat)==null?void 0:h.messages)||[],inputContent:"",activeModal:(x=l.activeChat)==null?void 0:x.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 nr(){try{const t=localStorage.getItem(Ys);if(t){const s=JSON.parse(t);return{...ds,...s}}}catch{}return{...ds}}function rr(t){try{localStorage.setItem(Ys,JSON.stringify(t))}catch{}}let Qe=nr(),Tt=[];function ar(){Tt.forEach(t=>t())}function or(t){Qe={...Qe,...t},rr(Qe),ar()}function ir(){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=>{or(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 cr={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function lr(){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 dr(){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 ur(t,s={}){const n={...cr,...s},a=r.useRef(new Map),i=r.useRef(0),o=r.useRef(null);r.useEffect(()=>{dr().then(d=>{o.current=d})},[]);const c=r.useCallback((d,u,h)=>{const x=Date.now();x-i.current<n.throttleMs||(i.current=x,Yt(d,u,h))},[n.throttleMs]);r.useEffect(()=>{var d;if(!(!n.enabled||!Vs())&>("browser")&&o.current!==!0){if(document.hasFocus()){for(const u of t)a.current.set(u.id,u.status||"idle");return}for(const u of t){const h=a.current.get(u.id),x=u.status||"idle",l=u.name||u.id;if(n.onApproval&>("approval")&&x==="waiting_approval"&&h!=="waiting_approval"){const g=((d=u.activeModal)==null?void 0:d.message)||"Action requires your approval";c(`🔔 ${l} — Approval needed`,g.slice(0,120),`approval-${u.id}`)}n.onComplete&>("completion")&&h==="generating"&&x==="idle"&&c(`✅ ${l} — Task complete`,"Agent has finished working",`complete-${u.id}`),n.onError&&x==="error"&&h!=="error"&&c(`⚠️ ${l} — Error`,"Agent encountered an error",`error-${u.id}`),a.current.set(u.id,x)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class xr{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 u,h;const a=`${s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(a))return;if(!s.ideId&&s.instanceId){for(const x of this.ides)if(x.id.endsWith(`:ide:${s.instanceId}`)||x.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=x.id;break}}let i=He(s.ideType||"");const o=this.resolveOwningDaemon(s);if(o){const x=xt(o,{fallbackId:o.id});x&&(i=s.ideType==="adhdev-daemon"?x:`${x}/${i}`)}let c="",d="info";if(s.event==="agent:generating_completed"){const x=s.duration?` (${s.duration}s)`:"";c=`✅ ${i} agent task completed${x}`,d="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${x}`,_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`,d="warning",s.ideId){const x=s.modalMessage||"Approval requested",l=(u=s.modalButtons)!=null&&u.length?s.modalButtons.map(g=>`[${g}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${x}
|
|
39
|
-
${l}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((h=s.modalButtons)!=null&&h.length)&&this.resolveActionFn){const x=s.ideId,l=s.agentType||s.ideType||"",g=s.ideType||"",f=s.modalButtons,m=W=>W.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),S=this.resolveActionFn,L=f.map((W,z)=>{const _=m(W).toLowerCase(),j=/^(run|approve|accept|yes|allow|always)/.test(_),O=/^(reject|deny|delete|remove|abort|cancel|no)/.test(_);return{label:m(W),variant:j?"primary":O?"danger":"default",onClick:()=>{const M=this.resolveRouteId(x,l),R=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(_);S(M,"resolve_action",{action:R?"approve":"reject",button:W,buttonIndex:z,agentType:l,ideType:g})}}}),v=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:c,w=Date.now();this.emitToast({id:w,message:v,type:d,timestamp:w,ideId:x,actions:L,duration:15e3}),c=""}}else if(s.event==="monitor:long_generating"){const x=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";c=`⚠️ ${i} agent is taking a long time${x}`,d="warning",gt("browser")&&!document.hasFocus()&&Yt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${x.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const x=s.requesterName||"A team member",l=s.requestId,g=s.orgId;if(c=`👁️ ${x} wants to view your session`,d="warning",l&&g&&this.viewRequestRespondFn){const f=this.viewRequestRespondFn,m=Date.now(),S=[{label:"Approve",variant:"primary",onClick:()=>{f(g,l,"approve").catch(L=>console.error("[EventManager] approve view request failed:",L))}},{label:"Decline",variant:"danger",onClick:()=>{f(g,l,"reject").catch(L=>console.error("[EventManager] reject view request failed:",L))}}];this.emitToast({id:m,message:c,type:d,timestamp:m,actions:S,duration:3e4}),c=""}gt("browser")&&!document.hasFocus()&&Yt("👁️ View Request",`${x} wants to view your session`,`view-request-${l}`)}else s.event==="team:view_request_approved"?(c="✅ View request approved",d="success"):s.event==="team:view_request_rejected"&&(c=`❌ ${s.targetName||"Team member"} declined your view request`,d="warning");if(c){const x=Date.now();this.emitToast({id:x,message:c,type:d,timestamp:x,ideId:s.ideId,duration:5e3})}}}const lt=new xr;function ct(...t){return nn(rn(t))}function pr({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:d}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(pr,{icon:t,title:s,subtitle:n,badge:a,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ct("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function De({title:t,icon:s,description:n,accentColor:a,className:i,children:o}){return e.jsxs("div",{className:ct("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",a&&"border-l-[3px]",i),style:a?{borderLeftColor:a}:void 0,children:[(t||n)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),n&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:n})]}),o]})}function 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 mr={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"},hr={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function fr({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]",mr[t],a),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:hr[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 gr={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"},br={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function yr({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",gr[t],n),children:[e.jsx("span",{className:ct("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",br[t])}),a]})}function jr(){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"?jr():t}function vr(){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)"),d=u=>{t==="system"&&a(u.matches?"light":"dark")};return c.addEventListener("change",d),()=>c.removeEventListener("change",d)},[t]);const i=r.useCallback(c=>{s(c),a(Wt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=r.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";a(Wt(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);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 wr({onPrefChange:t}){const[s,n]=ir(),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 Nr({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(Sr,{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:d=>d.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,children:n})]})]})}),document.body)}function kr(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 Sr({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:a,onRevokeToken:i}){var y,oe;const[o,c]=r.useState("idle"),[d,u]=r.useState(""),[h,x]=r.useState(null),[l,g]=r.useState("idle"),[f,m]=r.useState(""),S=t,L=S.version||S.daemonVersion||null,v=((y=S.machine)==null?void 0:y.platform)||((oe=S.system)==null?void 0:oe.platform)||"",w=xt(S,{fallbackId:t.id}),W=v==="win32"?"🪟":v==="darwin"?"🍎":"🐧",z=s.filter(J=>J.daemonId===t.id&&J.id.includes(":ide:")),_=s.filter(J=>J.daemonId===t.id&&J.id.includes(":cli:")),j=s.filter(J=>J.daemonId===t.id&&J.id.includes(":acp:")),O=S.p2p,M=async()=>{var J,V,X;if(n){c("upgrading"),u("Installing latest version...");try{const G=await n(t.id,"daemon_upgrade",{});(J=G==null?void 0:G.result)!=null&&J.upgraded||(V=G==null?void 0:G.result)!=null&&V.success?(c("done"),u(`Upgraded to v${G.result.version||"latest"}. Daemon is restarting...`)):(c("error"),u(((X=G==null?void 0:G.result)==null?void 0:X.error)||"Upgrade failed"))}catch(G){c("error"),u((G==null?void 0:G.message)||"Connection lost during upgrade")}}},R=async()=>{if(x(null),!!a){g("loading");try{await a(t.id),g("done"),m("Machine disconnected.")}catch(J){g("error"),m((J==null?void 0:J.message)||"Failed to disconnect")}}},te=async()=>{if(x(null),!!i){g("loading");try{await i(t.id),g("done"),m('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(J){g("error"),m((J==null?void 0:J.message)||"Failed to revoke token")}}},b="0.6.73",F=!L||L!==b,H=z.length+_.length+j.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:w}),e.jsxs("div",{className:"text-xs text-text-muted font-mono flex items-center gap-2",children:[e.jsxs("span",{children:[t.id.substring(0,12),"…"]}),L&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${F?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",L,!F&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&F&&e.jsx("button",{onClick:M,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${b}`,children:o==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`↑ Update${` to v${b}`}`}),a&&e.jsx("button",{onClick:()=>x("disconnect"),disabled:l==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),i&&e.jsx("button",{onClick:()=>x("revoke"),disabled:l==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(yr,{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:[O&&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 ${O.state==="connected"?"bg-green-400":O.state==="connecting"||O.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",O.state==="connected"?"connected":O.state==="connecting"||O.state==="new"?"connecting...":O.state||"off"]}),O.peers!==void 0&&O.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",O.peers," peer",O.peers!==1?"s":"",")"]})]}),O&&H>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),H>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[z.map(J=>{const V=kr(J.type),X=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:V.icon}),e.jsx("span",{children:V.name}),X!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${X?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:X?"CDP connected":"CDP connecting..."})]},J.id)}),_.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)),j.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"})]}),(d||f)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||l==="error"?"text-red-400":o==="done"||l==="done"?"text-green-400":"text-text-muted"}`,children:f||d})]}),h==="disconnect"&&e.jsx(xs,{title:"🔌 Disconnect Machine",message:`Disconnect "${w}" from ADHDev?
|
|
40
|
-
|
|
41
|
-
This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
|
|
42
|
-
|
|
43
|
-
Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:R,onCancel:()=>x(null)}),h==="revoke"&&e.jsx(xs,{title:"⚠️ Remove Machine",message:`Remove "${w}" from your dashboard?
|
|
44
|
-
|
|
45
|
-
This will:
|
|
46
|
-
• Immediately disconnect the machine
|
|
47
|
-
• Delete the machine registration
|
|
48
|
-
• Require restarting "adhdev-standalone" on that machine
|
|
49
|
-
|
|
50
|
-
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:te,onCancel:()=>x(null)})]})}const Cr=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Ir(){const{preference:t,setPreference:s}=vr();return e.jsx("div",{className:"flex gap-2",children:Cr.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},Mr=[{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 Tr(){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 Er(t){if(localStorage.setItem(Xs,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=bt()?"dark":"light";it(Ue(s))}else Tr()}function Ar(){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 $r({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,d)=>{i(u=>{const h={...u,[c]:d},l=Ue(n==="dark"?"light":"dark");return n==="dark"?Ct(h,l):Ct(l,h),it(h),s(h),h})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(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,u=Ue(t?"light":"dark");t?Ct(c,u):Ct(u,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 u=new MutationObserver(()=>{const l=bt();a(l),Et()==="custom"&&it(Ue(l?"dark":"light"))});u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const h=window.matchMedia("(prefers-color-scheme: dark)"),x=()=>{const l=bt();a(l),Et()==="custom"&&it(Ue(l?"dark":"light"))};return h.addEventListener("change",x),()=>{u.disconnect(),h.removeEventListener("change",x)}},[]),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=u=>{s(u),Er(u),u==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},d=[...Mr,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:d.map(u=>{const h=t===u.id,x=n?u.preview.dark:u.preview.light,l=u.id==="honey"?"#1a1a1a":u.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(u.id),className:"text-left rounded-xl p-3 transition-all",style:{background:h?"var(--bg-glass-hover)":"var(--bg-glass)",border:h?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:h?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:x.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:x.assistantBubble,border:x.assistantBorder,color:x.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:x.userBubble,color:l},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:x.assistantBubble,border:x.assistantBorder,color:x.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[h&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:u.id==="custom"?"🎨 Custom":u.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:u.description})]})]})]},u.id)})}),t==="custom"&&e.jsx($r,{dark:n,onColorsChange:u=>o(u)})]})}const qt="adhdev-accent-color",Rr=[{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 Pr(t){const s=parseInt(t.slice(1,3),16)/255,n=parseInt(t.slice(3,5),16)/255,a=parseInt(t.slice(5,7),16)/255,i=Math.max(s,n,a),o=Math.min(s,n,a);let c=0,d=0;const u=(i+o)/2;if(i!==o){const h=i-o;switch(d=u>.5?h/(2-i-o):h/(i+o),i){case s:c=((n-a)/h+(n<a?6:0))/6;break;case n:c=((a-s)/h+2)/6;break;case a:c=((s-n)/h+4)/6;break}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(u*100)}}function ms(t,s){const{h:n,s:a,l:i}=Pr(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 Lr(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 Dr(){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 Br(t){t===Nt?(localStorage.removeItem(qt),Dr()):(localStorage.setItem(qt,t),Lr(t))}function Wr(){const[t,s]=r.useState(hs),[n,a]=r.useState("");r.useEffect(()=>{s(hs())},[]);const i=o=>{s(o),Br(o)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:Rr.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 Or(){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 zr(){const[t,s]=r.useState(Or),n=r.useCallback(u=>{s(h=>{const x=new Set(h);return x.has(u)?x.delete(u):x.add(u),ft(x),x})},[]),a=r.useCallback(u=>{s(h=>{if(h.has(u))return h;const x=new Set(h);return x.add(u),ft(x),x})},[]),i=r.useCallback(u=>{s(h=>{if(!h.has(u))return h;const x=new Set(h);return x.delete(u),ft(x),x})},[]),o=r.useCallback((u,h)=>{s(x=>{const l=new Set(x);for(const g of h)l.add(g);return ft(l),l})},[]),c=r.useCallback((u,h)=>{s(x=>{const l=new Set(x);for(const g of h)l.delete(g);return ft(l),l})},[]),d=r.useCallback(u=>t.has(u),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:a,showTab:i,hideAllForDaemon:o,showAllForDaemon:c,isHidden:d}}function Js({sendDaemonCommand:t,activeConv:s,ides:n,updateIdeChats:a,setToasts:i,setLocalUserMessages:o,setClearedTabs:c,setActionLogs:d,pinTab:u,isStandalone:h}){const[x,l]=r.useState(""),[g,f]=r.useState(!1),[m,S]=r.useState(!1),[L,v]=r.useState(!1),w=r.useCallback(b=>b?Oe(b)||Re(b)?{agentType:b.agentType||b.ideType}:b.streamSource==="agent-stream"?{agentType:b.agentType}:{}:{},[]),W=r.useCallback(async()=>{if(!s)return;const b=x.trim();if(!b)return;const F=s.ideId,H=s.tabKey;l(""),u(H,[100,500,1500,3e3]);const y=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,oe={role:"user",content:b,timestamp:Date.now(),_localId:y};o(J=>({...J,[H]:[...J[H]||[],oe]}));try{const J=F||s.daemonId||"";if(!J)return;await t(J,"send_chat",{message:b,text:b,...w(s)}),setTimeout(()=>{const V=Date.now()-6e4;o(X=>{const G=X[H];if(!G)return X;const ie=G.filter(se=>se.timestamp>V);return ie.length===G.length?X:{...X,[H]:ie}})},6e4)}catch(J){console.error("Send failed",J),l(b),o(V=>({...V,[H]:(V[H]||[]).filter(X=>X._localId!==y)}))}},[s,x,t,o,u,w]),z=r.useCallback(async()=>{if(s)try{h?await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0}):await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(b){console.error("Relaunch failed",b)}},[s,h,t]),_=r.useCallback(async b=>{try{await t("standalone","launch_ide",{ideType:b,enableCdp:!0})}catch(F){console.error("Launch failed",F)}},[t]),j=r.useCallback(async b=>{if(s){console.log("[ModalButton] ideId:",s.ideId,"button:",b),d(F=>[...F,{ideId:s.tabKey,text:`🖱️ **${b}** clicked`,timestamp:Date.now()}]);try{const H=(s.modalButtons||[]).indexOf(b),y=b.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),oe=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(y),J=s.ideId||s.daemonId||"";(await t(J,"resolve_action",{button:b,action:oe?"approve":"reject",...H>=0&&{buttonIndex:H},...w(s)})).success||d(X=>[...X,{ideId:s.tabKey,text:`⚠️ **${b}** failed — button not found`,timestamp:Date.now()}])}catch(F){console.error("[ModalButton] Error:",F),d(H=>[...H,{ideId:s.tabKey,text:`❌ **${b}** error`,timestamp:Date.now()}])}}},[s,t,d,w]),O=r.useCallback(async(b,F)=>{try{const H=b||(s==null?void 0:s.daemonId)||"",y=await t(H,"switch_chat",{id:F,sessionId:F,...w(s)}),oe=y==null?void 0:y.result;(y==null?void 0:y.success)===!0||oe==="switched"||oe==="switched-by-title"||(oe===!1||oe==="not_found"?i(V=>[...V,{id:Date.now(),message:"⚠️ Session tab not found — try refreshing history",type:"warning",timestamp:Date.now()}]):typeof oe=="string"&&oe.startsWith("error:")?i(V=>[...V,{id:Date.now(),message:`⚠️ Switch error: ${oe}`,type:"warning",timestamp:Date.now()}]):i(V=>[...V,{id:Date.now(),message:"⚠️ Session switch failed",type:"warning",timestamp:Date.now()}]))}catch(H){console.error("Switch failed",H),i(y=>[...y,{id:Date.now(),message:`❌ Switch failed: ${H.message||"connection error"}`,type:"warning",timestamp:Date.now()}])}},[s,t,i,w]),M=r.useCallback(async()=>{if(!(!s||g)){f(!0);try{const b=s.ideId||s.daemonId||"";await t(b,"new_chat",{...w(s)}),c(F=>({...F,[s.tabKey]:Date.now()})),o(F=>({...F,[s.tabKey]:[]}))}catch(b){console.error("New chat failed",b)}finally{f(!1)}}},[s,g,t,c,o,w]),R=r.useCallback(async()=>{if(!s||L)return;v(!0);const b=s.tabKey;try{await t(s.ideId,"agent_stream_focus",{agentType:s.agentType}),u(b,[200,1500,3e3])}catch(F){console.error("Focus agent failed",F)}finally{v(!1)}},[s,L,t,u]),te=r.useCallback(async()=>{var b;if(!(!s||m)){S(!0);try{const F=s.ideId||s.daemonId||"",H=await t(F,"list_chats",{forceExpand:!0,...w(s)}),y=(H==null?void 0:H.chats)||((b=H==null?void 0:H.result)==null?void 0:b.chats);H!=null&&H.success&&Array.isArray(y)&&a(s.ideId,y)}catch(F){console.error("Refresh history failed",F)}finally{S(!1)}}},[s,m,t,a,w]);return{agentInput:x,setAgentInput:l,isCreatingChat:g,isRefreshingHistory:m,isFocusingAgent:L,handleSendChat:W,handleRelaunch:z,handleLaunchIde:_,handleModalButton:j,handleSwitchSession:O,handleNewChat:M,handleFocusAgent:R,handleRefreshHistory:te}}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 Fr(){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 d=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:d,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 Hr({conversations:t,ides:s,messageReceivedAt:n,actionLogs:a,ptyBuffers:i,screenshotMap:o,setScreenshotMap:c,sendDaemonCommand:d,updateIdeChats:u,setToasts:h,setLocalUserMessages:x,setClearedTabs:l,setActionLogs:g,pinTab:f,isStandalone:m,userName:S,groupIndex:L,isFocused:v,onFocus:w,isSplitMode:W,numGroups:z,onMoveTab:_,onClose:j,onReceiveTab:O,style:M,detectedIdes:R,handleLaunchIde:te,onActiveTabChange:b,initialActiveTabId:F,initialTabOrder:H,onTabOrderChange:y,onHideTab:oe,cliViewModes:J}){const{sendCommand:V}=nt(),X=r.useRef(null),[G,ie]=r.useState(!1),[se,ce]=r.useState(null),xe=r.useRef(0),je=r.useRef(null),[K,C]=r.useState(F??null);r.useEffect(()=>{F&&F!==K&&C(F)},[F]);const[p,A]=r.useState(H??[]),[P,q]=r.useState(null),Ie=r.useRef(null),ve=r.useRef(null);r.useEffect(()=>{const N=new Set(t.map(Z=>Z.tabKey));A(Z=>{const B=Z.filter(ee=>N.has(ee)),de=t.filter(ee=>!Z.includes(ee.tabKey)).map(ee=>ee.tabKey),U=[...B,...de];return U.length===Z.length&&U.every((ee,le)=>ee===Z[le])?Z:U})},[t]);const be=P??p,he=r.useMemo(()=>{if(be.length===0)return t;const N=new Map(be.map((Z,B)=>[Z,B]));return[...t].sort((Z,B)=>{const de=N.get(Z.tabKey)??999,U=N.get(B.tabKey)??999;return de-U})},[t,be]);r.useEffect(()=>{if(he.length===0){C(null),b==null||b(null);return}K&&he.some(N=>N.tabKey===K)||(C(he[0].tabKey),b==null||b(he[0].tabKey))},[he,K]);const D=he.find(N=>N.tabKey===K),me=r.useCallback((N,Z,B)=>{A(de=>{const U=de.filter(Y=>Y!==N),ee=U.indexOf(Z);if(ee<0)return de;const le=B==="left"?ee:ee+1;return U.splice(le,0,N),y==null||y(U),U}),q(null)},[y]),ue=r.useCallback((N,Z,B)=>{const U=(p.length>0?p:t.map(Y=>Y.tabKey)).filter(Y=>Y!==N),ee=U.indexOf(Z);if(ee<0)return;const le=B==="left"?ee:ee+1;U.splice(le,0,N),Ie.current=U,q(U)},[p,t]),pe=Js({sendDaemonCommand:d,activeConv:D,ides:s,updateIdeChats:u,setToasts:h,setLocalUserMessages:x,setClearedTabs:l,setActionLogs:g,pinTab:f,isStandalone:m}),[Se,Me]=r.useState(null);r.useEffect(()=>{if(!Se)return;const N=Z=>{const B=document.querySelector("[data-pane-context-menu]");B&&B.contains(Z.target)||Me(null)};return window.addEventListener("mousedown",N,!0),()=>window.removeEventListener("mousedown",N,!0)},[Se]);const et="adhdev-tab-shortcuts",Ke=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[Pe,pt]=r.useState(()=>{try{return JSON.parse(localStorage.getItem(et)||"{}")}catch{return{}}}),[ze,Ye]=r.useState(null),Ae=r.useCallback(N=>{const Z=[];N.metaKey&&Z.push(Ke?"⌘":"Meta"),N.ctrlKey&&Z.push("Ctrl"),N.altKey&&Z.push(Ke?"⌥":"Alt"),N.shiftKey&&Z.push(Ke?"⇧":"Shift");const B=N.key;if(["Control","Alt","Shift","Meta"].includes(B))return null;const de=B.length===1?B.toUpperCase():B;return Z.push(de),Z.join("+")},[Ke]),T=r.useCallback((N,Z)=>Ae(N)===Z,[Ae]),ne=r.useCallback(N=>{pt(N),localStorage.setItem(et,JSON.stringify(N))},[]);r.useEffect(()=>{if(!ze)return;const N=Z=>{if(Z.preventDefault(),Z.stopPropagation(),Z.key==="Escape"){Ye(null);return}const B=Ae(Z);if(!B)return;const de={...Pe};for(const[U,ee]of Object.entries(de))ee===B&&delete de[U];de[ze]=B,ne(de),Ye(null)};return window.addEventListener("keydown",N,!0),()=>window.removeEventListener("keydown",N,!0)},[ze,Pe,ne,Ae]),r.useEffect(()=>{const N=Z=>{if(!(!Z.ctrlKey&&!Z.metaKey&&!Z.altKey)){for(const[B,de]of Object.entries(Pe))if(T(Z,de)&&he.some(U=>U.tabKey===B)){Z.preventDefault(),w(),C(B),b==null||b(B);return}}};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[Pe,he,w,b,T]);const Q=D&&Oe(D)&&!Re(D),ge=Q?J[D.tabKey]??D.mode??"terminal":"chat";r.useEffect(()=>{const N=()=>{xe.current=0,ie(!1),ce(null)};return window.addEventListener("dragend",N),window.addEventListener("drop",N),()=>{window.removeEventListener("dragend",N),window.removeEventListener("drop",N)}},[]);const Ne=r.useRef(null);return r.useEffect(()=>{const N=Ne.current;if(!N)return;const Z=B=>{Math.abs(B.deltaY)>Math.abs(B.deltaX)&&(B.preventDefault(),N.scrollLeft+=B.deltaY)};return N.addEventListener("wheel",Z,{passive:!1}),()=>N.removeEventListener("wheel",Z)},[]),e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:w,style:{...M,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:Ne,className:"flex-1 flex overflow-x-auto overflow-y-visible pt-1.5 pb-0 gap-1 select-none",style:{paddingLeft:8,paddingRight:4,scrollbarWidth:"none"},children:[he.map((N,Z)=>{const B=K===N.tabKey,de=N.status==="working"?"agent-tab-working":N.status==="waiting_approval"?"agent-tab-waiting":"",U=N.connectionState==="failed"||N.connectionState==="closed",ee=ve.current===N.tabKey;return e.jsxs("div",{"data-tabkey":N.tabKey,className:`${de} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:le=>{ve.current=N.tabKey,le.dataTransfer.setData("text/tab-key",N.tabKey),le.dataTransfer.effectAllowed="move"},onDragEnd:()=>{ve.current=null;const le=Ie.current;le&&(A(le),y==null||y(le)),Ie.current=null,q(null),xe.current=0,ie(!1)},onDragOver:le=>{const Y=ve.current;if(!(!Y||Y===N.tabKey)&&le.dataTransfer.types.includes("text/tab-key")){le.preventDefault(),le.stopPropagation();const fe=le.currentTarget.getBoundingClientRect(),ke=fe.left+fe.width/2,Ce=le.clientX<ke?"left":"right";ue(Y,N.tabKey,Ce)}},onDrop:le=>{le.preventDefault(),le.stopPropagation();const Y=le.dataTransfer.getData("text/tab-key");if(Y&&Y!==N.tabKey){const fe=le.currentTarget.getBoundingClientRect(),ke=fe.left+fe.width/2,Ce=le.clientX<ke?"left":"right";he.some($e=>$e.tabKey===Y)?me(Y,N.tabKey,Ce):O&&O(Y)}q(null)},onClick:le=>{le.stopPropagation(),w(),C(N.tabKey),b==null||b(N.tabKey),N.streamSource==="agent-stream"&&N.agentType&&V(N.ideId,"agent_stream_focus",{agentType:N.agentType}).catch(()=>{}),Oe(N)&&setTimeout(()=>{var Y,fe;return(fe=(Y=X.current)==null?void 0:Y.bumpResize)==null?void 0:fe.call(Y)},100)},onContextMenu:le=>{le.preventDefault(),Me({x:le.clientX,y:le.clientY,tabKey:N.tabKey})},onTouchStart:le=>{const Y=le.touches[0],fe=Y.clientX,ke=Y.clientY;je.current=setTimeout(()=>{Me({x:fe,y:ke,tabKey:N.tabKey})},600)},onTouchEnd:()=>{je.current&&clearTimeout(je.current)},onTouchMove:()=>{je.current&&clearTimeout(je.current)},style:{background:B?"var(--bg-primary)":"var(--bg-glass)",borderTop:B?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:B?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:B?"1px solid var(--border-subtle)":"1px solid transparent",opacity:ee?.4:U?B?.6:.3:B?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[N.status==="working"?e.jsx("div",{className:"tab-spinner"}):N.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):U?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):N.connectionState==="connecting"||N.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):N.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:N.displayPrimary,children:N.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:U?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):N.connectionState==="connecting"||N.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[N.displaySecondary,N.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",N.machineName]})]})]})})]}),Pe[N.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[N.tabKey]}`,children:Pe[N.tabKey]})]},N.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:N=>{N.dataTransfer.types.includes("text/tab-key")&&(xe.current++,ie(!0))},onDragOver:N=>{if(!N.dataTransfer.types.includes("text/tab-key"))return;N.preventDefault();const Z=N.currentTarget.getBoundingClientRect(),B=N.clientX-Z.left;if(z<4&&_){const de=Z.width/3;B<de?ce("split-left"):B>de*2?ce("split-right"):ce("merge");return}ce("merge")},onDragLeave:()=>{xe.current--,xe.current<=0&&(xe.current=0,ie(!1),ce(null))},onDrop:N=>{xe.current=0,ie(!1);const Z=N.dataTransfer.getData("text/tab-key"),B=Z?t.some(U=>U.tabKey===Z):!1,de=se;if(ce(null),q(null),!!Z){if(N.preventDefault(),de==="split-left"&&_&&z<4){_(Z,"split-left");return}if(de==="split-right"&&_&&z<4){_(Z,"split-right");return}B?A(U=>{const ee=U.filter(le=>le!==Z);return ee.push(Z),y==null||y(ee),ee}):O&&O(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:se==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:se==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:z<4&&_?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:se==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:se==="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:se==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:se==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:z<4&&_?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"})})]}),D?e.jsxs(e.Fragment,{children:[e.jsx(Bn,{activeConv:D,onModalButton:pe.handleModalButton}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!Q&&!Re(D)&&o[D.ideId]?e.jsx(Dn,{screenshotUrl:o[D.ideId],mode:"preview",onDismiss:()=>{const N={...o};delete N[D.ideId],c(N)}}):!Q&&!Re(D)&&D.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:pe.handleRelaunch,children:"Relaunch with CDP"})]}):null}),ge==="terminal"?e.jsx(On,{activeConv:D,ptyBuffers:i,terminalRef:X,agentInput:pe.agentInput,setAgentInput:pe.setAgentInput,handleSendChat:pe.handleSendChat}):e.jsx(Bs,{activeConv:D,ides:s,agentInput:pe.agentInput,setAgentInput:pe.setAgentInput,handleSendChat:pe.handleSendChat,handleFocusAgent:pe.handleFocusAgent,isFocusingAgent:pe.isFocusingAgent,messageReceivedAt:n,actionLogs:a,userName:S})]}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:t.length===0&&!W&&R&&te?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:m?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!m&&e.jsx(Fr,{}),m&&R&&R.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:R.map(N=>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:()=>te&&te(N.type),children:[e.jsx(Rs,{size:14,className:"opacity-70"})," Launch ",N.name]},N.type))})]}),!m&&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"})})]}),Se&&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:Se.x,top:Se.y},children:[_&&L>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{_(Se.tabKey,"left"),Me(null)},children:"← Move to Left Group"}),_&&L<z-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{_(Se.tabKey,"right"),Me(null)},children:"Move to Right Group →"}),_&&z<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{_(Se.tabKey,"split-left"),Me(null)},children:"⇤ Split Left"}),_&&z<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{_(Se.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:N=>{N.stopPropagation(),Ye(Se.tabKey),Me(null)},children:["⌨ ",Pe[Se.tabKey]?`Change shortcut (${Pe[Se.tabKey]})`:"Set shortcut"]}),Pe[Se.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 N={...Pe};delete N[Se.tabKey],ne(N),Me(null)},children:"✕ Remove shortcut"}),oe&&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:()=>{oe(Se.tabKey),Me(null)},children:"🚫 Hide from Dashboard"})]}),!_&&!oe&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),ze&&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:N=>N.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. ",Ke?"⌘+1":"Ctrl+1",", ",Ke?"⌥+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 zt=[{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 Ur({onClose:t}){const[s,n]=r.useState(0),a=zt[s],i=s===zt.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:zt.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 Yr(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 Vr(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,d]of t)!n.has(c)||d<=0||a.includes(d)||a.push(d);a.sort((c,d)=>c-d);const i={};a.forEach((c,d)=>{i[c]=d}),a.length===0&&(i[0]=0);const o=new Map;for(const[c,d]of t){if(!n.has(c)||d<=0)continue;const u=i[d];typeof u=="number"&&u>0&&o.set(c,u)}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 Xr(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 qr(t,s,n){if(s.length<=1)return[];const a=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=a.length===s.length?a:Array(n).fill(100/n),o=i.reduce((c,d)=>c+d,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function Gr(){const{sendCommand:t}=nt(),[s,n]=ws(),a=s.get("activeTab"),i=Pt(),{updateIdeChats:o,screenshotMap:c,setScreenshotMap:d}=i,u=i.ides||[],[h,x]=r.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),l=i.toasts||[],g=i.setToasts||(()=>{}),f=i.wsStatus||"connected",m=i.isConnected??!0,S=i.connectionStates||{};i.retryConnection;const L=i.showReconnected||!1,[v,w]=r.useState(()=>{try{const k=localStorage.getItem("adhdev_splitGroups");if(k){const I=JSON.parse(k);return new Map(I)}}catch{}return new Map}),[W,z]=r.useState(()=>{try{const k=localStorage.getItem("adhdev_focusedGroup");if(k)return parseInt(k,10)||0}catch{}return 0}),[_,j]=r.useState(()=>{try{const k=localStorage.getItem("adhdev_groupActiveTabs");if(k)return JSON.parse(k)}catch{}return{}}),O=r.useRef(!1),[M,R]=r.useState(()=>{try{const k=localStorage.getItem("adhdev_groupTabOrders");if(k)return JSON.parse(k)}catch{}return{}}),[te,b]=r.useState(()=>{try{const k=localStorage.getItem("adhdev_splitSizes");if(k)return JSON.parse(k)}catch{}return[]});r.useEffect(()=>{try{v.size===0?localStorage.removeItem("adhdev_splitGroups"):localStorage.setItem("adhdev_splitGroups",JSON.stringify([...v.entries()]))}catch{}},[v]),r.useEffect(()=>{try{te.length>0?localStorage.setItem("adhdev_splitSizes",JSON.stringify(te)):localStorage.removeItem("adhdev_splitSizes")}catch{}},[te]),r.useEffect(()=>{try{localStorage.setItem("adhdev_focusedGroup",String(W))}catch{}},[W]),r.useEffect(()=>{try{localStorage.setItem("adhdev_groupActiveTabs",JSON.stringify(_))}catch{}},[_]),r.useEffect(()=>{try{localStorage.setItem("adhdev_groupTabOrders",JSON.stringify(M))}catch{}},[M]);const[F,H]=r.useState(()=>typeof window<"u"&&window.innerWidth<768);r.useEffect(()=>{const k=window.matchMedia("(max-width: 767px)"),I=E=>H(E.matches);return k.addEventListener("change",I),()=>k.removeEventListener("change",I)},[]);const[y,oe]=r.useState({}),[J,V]=r.useState(!1),[X,G]=r.useState([]),[ie,se]=r.useState({}),[ce,xe]=r.useState({}),[je,K]=r.useState({}),C=u.find(k=>k.type==="adhdev-daemon"),p=(C==null?void 0:C.detectedIdes)||[],A=!!C,P=r.useMemo(()=>{const k=u.filter(E=>E.type!=="adhdev-daemon"),I=new Map;for(const E of k){const $=I.get(E.id);if(!$)I.set(E.id,E);else{const re=($.workspace?1:0)+($.activeChat?1:0);((E.workspace?1:0)+(E.activeChat?1:0)>re||(E.timestamp||0)>($.timestamp||0))&&I.set(E.id,E)}}return Array.from(I.values())},[u]),q=r.useMemo(()=>{const k=tr(P,ie,u,S),I=Date.now();return k.map(E=>{const $=ce[E.tabKey];return $&&I-$<5e3?{...E,messages:[],title:""}:E})},[P,ie,ce,u]),{hiddenTabs:Ie,toggleTab:ve}=zr(),be=r.useMemo(()=>q.filter(k=>!Ie.has(k.tabKey)),[q,Ie]),he=r.useMemo(()=>be.map(k=>k.tabKey),[be]),D=r.useMemo(()=>It(v,he),[v,he]),me=D.assignments,ue=r.useMemo(()=>F?1:D.groupCount,[D.groupCount,F]),pe=ue>1,Se=r.useCallback((k,I)=>{const E={};for(const[$,re]of Object.entries(k)){const ae=Number($);E[ae>=I?ae+1:ae]=re}return E},[]),Me=r.useCallback(k=>Array(k).fill(100/k),[]),et=r.useCallback((k,I)=>{w(E=>{const $=new Map(It(E,he).assignments);return I===0?$.delete(k):$.set(k,I),$}),j(E=>({...E,[I]:k})),z(I)},[he]),Ke=r.useCallback(k=>{w(I=>{const E=It(I,he).assignments,$=new Map;for(const[re,ae]of E)ae!==k&&(ae>k?$.set(re,ae-1):$.set(re,ae));return $}),b(I=>{if(I.length<=1)return[];const E=[...I];E.splice(k,1);const $=E.reduce((re,ae)=>re+ae,0);return $>0?E.map(re=>re/$*100):[]}),z(0)},[he]),Pe=r.useRef(null),pt=r.useCallback((k,I)=>{I.preventDefault();const E=Pe.current;if(!E)return;const $=I.clientX,re=E.offsetWidth,ae=te.length===ue?[...te]:Array(ue).fill(100/ue),ye=Be=>{const Ve=(Be.clientX-$)/re*100,mt=[...ae];mt[k]=Math.max(15,ae[k]+Ve),mt[k+1]=Math.max(15,ae[k+1]-Ve),b(mt)},Te=()=>{document.removeEventListener("mousemove",ye),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",ye),document.addEventListener("mouseup",Te)},[te,ue]),ze=r.useCallback((k,I,E)=>{const $=ue;if($>=4)return;const re=E==="left"?I:I+1;w(ae=>{const ye=It(ae,he).assignments,Te=new Map;for(const Be of be){const Xe=ye.get(Be.tabKey)??0,Ve=Xe>=re?Xe+1:Xe;Ve>0&&Te.set(Be.tabKey,Ve)}return re>0&&Te.set(k,re),Te}),b(ae=>{const ye=ae.length===$?[...ae]:Me($),Te=ye[I]??100/$,Be=Math.max(15,Te/2),Xe=Math.max(15,Te/2),Ve=[...ye];Ve[I]=Be,Ve.splice(re,0,Xe);const mt=Ve.reduce((Lt,Zs)=>Lt+Zs,0);return Ve.map(Lt=>Lt/mt*100)}),j(ae=>{const ye=Se(ae,re);return ye[re]=k,ye}),R(ae=>{const ye=Se(ae,re);return ye[re]=[k],ye}),z(re)},[ue,be,he,Me,Se]);r.useEffect(()=>{lr()},[]);const Ye=r.useMemo(()=>be.map(k=>({id:k.tabKey,name:k.title||k.agentName||k.ideId,status:k.status,activeModal:k.modalMessage?{message:k.modalMessage,buttons:k.modalButtons}:null})),[be]);ur(Ye),r.useEffect(()=>{Yr(v,me)||w(me)},[v,me]),r.useEffect(()=>{const{mapping:k,usedGroups:I}=D;j(E=>{const $=gs(E,k);return fs(E,$)?E:$}),R(E=>{const $=gs(E,k);return fs(E,$)?E:$}),z(E=>{const $=F?0:Xr(E,I,k);return E===$?E:$}),b(E=>{const $=F?[]:qr(E,I,D.groupCount);return Vr(E,$)?E:$})},[D,F]);const Ae=r.useMemo(()=>{const k=Array.from({length:ue},()=>[]);for(const I of be){const E=me.get(I.tabKey)??0,$=Math.min(E,ue-1);k[$].push(I)}return k},[be,me,ue]);r.useEffect(()=>{if(!a||O.current||q.length===0)return;const k=q.find(I=>I.tabKey===a)||q.find(I=>I.ideId===a)||q.find(I=>I.ideType===a||I.agentType===a);if(k){const I=me.get(k.tabKey)??0;j(E=>({...E,[I]:k.tabKey})),z(I),O.current=!0,n(E=>{const $=new URLSearchParams(E);return $.delete("activeTab"),$},{replace:!0})}},[a,q,me]),r.useEffect(()=>{if(Object.keys(ce).length===0)return;const I=setTimeout(()=>{xe(E=>{const $=Date.now(),re={};for(const[ae,ye]of Object.entries(E))$-ye<5e3&&(re[ae]=ye);return Object.keys(re).length===Object.keys(E).length?E:re})},5500);return()=>clearTimeout(I)},[ce]);const T=r.useMemo(()=>{var I,E;const k=_[W];if(k){const $=q.find(re=>re.tabKey===k);if($)return $}return((I=Ae[W])==null?void 0:I[0])||((E=Ae[0])==null?void 0:E[0])},[_,W,q,Ae]),ne=r.useMemo(()=>!T||!Oe(T)||Re(T)?null:je[T.tabKey]??T.mode??"terminal",[T,je]),Q=r.useCallback((k,I)=>{},[]);r.useEffect(()=>{const k=new Set(q.map(I=>I.tabKey));K(I=>{const E=Object.fromEntries(Object.entries(I).filter(([$])=>k.has($)));return Object.keys(E).length===Object.keys(I).length?I:E})},[q]),r.useEffect(()=>{var $;const k=Date.now();let I=!1;const E={...y};for(const re of q)($=re.messages)!=null&&$.length&&re.messages.forEach((ae,ye)=>{const Te=`${re.ideId}-${ae.id??`i-${ye}`}`;E[Te]==null&&(E[Te]=k,I=!0)});I&&oe(E)},[q]);const ge=r.useRef(!1);r.useEffect(()=>{if(!J){ge.current=!1;return}if(!T||ge.current||Z)return;const k=u.find(I=>I.id===T.ideId);k&&(!k.chats||k.chats.length===0)&&(ge.current=!0,ee())},[J,T==null?void 0:T.ideId]),r.useEffect(()=>{const k=setInterval(()=>{const I=Date.now()-3e5;G(E=>{const $=E.filter(re=>re.timestamp>I).slice(-100);return $.length===E.length?E:$})},6e4);return()=>clearInterval(k)},[]);const Ne=r.useRef(new Map);r.useEffect(()=>{const k=(E,$)=>{var re;if($){Ws.emit(E,$);for(const ae of q){if(!Oe(ae))continue;const ye=(re=ae.ideId)!=null&&re.includes(":cli:")?ae.ideId.split(":cli:")[1]:"";if(E===ye||E===ae.agentType||E===ae.ideType||E===ae.ideId||E===ae.tabKey){const Be=Ne.current.get(ae.tabKey)||[];Be.push($),Be.length>1e4&&Be.splice(0,Be.length-5e3),Ne.current.set(ae.tabKey,Be)}}}},I=Ht.onPtyOutput(k);return()=>{I()}},[q]),r.useEffect(()=>{const k=I=>{if(I.ctrlKey&&I.key==="\\"){if(I.preventDefault(),pe)w(new Map),z(0);else{const E=q[1];E&&ze(E.tabKey,0,"right")}return}I.ctrlKey&&(I.key==="["||I.key==="]")&&pe&&(I.preventDefault(),z(E=>I.key==="]"?Math.min(E+1,ue-1):Math.max(E-1,0)))};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[pe,q,ze,ue]),r.useEffect(()=>{lt.setIdes(u)},[u]),r.useEffect(()=>{lt.setResolveAction((k,I,E)=>{t(k,I,E).catch(()=>{})})},[t]),r.useEffect(()=>{const k=lt.onToast($=>{g(ae=>ae.some(Te=>Te.message===$.message&&$.timestamp-Te.timestamp<3e3)?ae:[...ae.slice(-4),{id:$.id,message:$.message,type:$.type,timestamp:$.timestamp,ideId:$.ideId,actions:$.actions}]);const re=$.duration||5e3;setTimeout(()=>g(ae=>ae.filter(ye=>ye.id!==$.id)),re)}),I=lt.onSystemMessage(($,re)=>{se(ae=>{for(const ye of Object.keys(ae))if(ye.includes($))return{...ae,[ye]:[...ae[ye]||[],re]};return ae})}),E=lt.onClearSystemMessage(($,re)=>{se(ae=>{const ye={...ae};for(const Te of Object.keys(ye))Te.includes($)&&(ye[Te]=(ye[Te]||[]).filter(Be=>{var Xe;return!(Be.role==="system"&&((Xe=Be._localId)!=null&&Xe.startsWith(re)))}));return ye})});return()=>{k(),I(),E()}},[]),r.useEffect(()=>{const k=zs.on("status_event",I=>lt.handleRawEvent(I,"ws"));return()=>{k()}},[]),r.useEffect(()=>{var I;const k=E=>{const $=E.data;($==null?void 0:$.type)==="notification_action"&&$.action==="approve"&&$.ideId&&t($.ideId,"resolve_action",{action:"approve",button:"Approve"}).catch(re=>console.error("[SW Action] approve failed:",re))};return(I=navigator.serviceWorker)==null||I.addEventListener("message",k),()=>{var E;return(E=navigator.serviceWorker)==null?void 0:E.removeEventListener("message",k)}},[]);const{isCreatingChat:N,isRefreshingHistory:Z,handleLaunchIde:B,handleSwitchSession:de,handleNewChat:U,handleRefreshHistory:ee}=Js({sendDaemonCommand:t,activeConv:T,ides:u,updateIdeChats:o,setToasts:g,setLocalUserMessages:se,setClearedTabs:xe,setActionLogs:G,pinTab:Q,isStandalone:A}),le=r.useCallback(k=>{!T||!Oe(T)||Re(T)||K(I=>({...I,[T.tabKey]:k}))},[T]),Y=r.useCallback(async()=>{var E;if(!T||!Oe(T)||Re(T))return;const k=(E=T.ideId)!=null&&E.includes(":cli:")?T.ideId.split(":cli:")[1]:T.ideType||T.agentType||"";if(!window.confirm(`Stop ${k}?
|
|
54
|
-
This will terminate the CLI process.`))return;const I=T.ideId||T.daemonId||"";try{await t(I,"stop_cli",{cliType:k})}catch($){console.error("Stop CLI failed:",$)}},[T,t]),fe=r.useMemo(()=>u.filter(k=>k.type==="adhdev-daemon"&&k.versionMismatch),[u]),[ke,Ce]=r.useState(!1),[$e,We]=r.useState({}),_e=r.useCallback(async k=>{var I,E;We($=>({...$,[k]:"upgrading"}));try{const $=await t(k,"daemon_upgrade",{});(I=$==null?void 0:$.result)!=null&&I.upgraded||(E=$==null?void 0:$.result)!=null&&E.success?We(re=>({...re,[k]:"done"})):We(re=>({...re,[k]:"error"}))}catch{We($=>({...$,[k]:"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(zn,{wsStatus:f,showReconnected:L}),fe.length>0&&!ke&&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",fe[0].version]})," → ",e.jsxs("strong",{children:["v",fe[0].serverVersion]})]}),fe.map(k=>{const I=xt(k,{fallbackId:k.id}),E=$e[k.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:I}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",k.version]}),E==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):E==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):E==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>_e(k.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(k.id),children:"Upgrade"})]},k.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:()=>Ce(!0),title:"Dismiss",children:"✕"})]}),e.jsx(Un,{activeConv:T,agentCount:P.length,wsStatus:f,isConnected:m,onOpenHistory:()=>V(!0),cliViewMode:ne,onSetCliViewMode:le,onStopCli:Y}),e.jsx("div",{ref:Pe,className:`flex-1 min-h-0 flex ${pe?"flex-row":"flex-col"} overflow-hidden`,children:Ae.map((k,I)=>{const E=pe&&te.length===ue?`${te[I]}%`:void 0;return e.jsxs(on.Fragment,{children:[pe&&I>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(I-1,$),onDoubleClick:()=>Ke(I),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(Hr,{style:pe?{flexBasis:E??`${100/ue}%`,flexGrow:E?0:1,flexShrink:E?0:1}:void 0,conversations:k,ides:u,messageReceivedAt:y,actionLogs:X,ptyBuffers:Ne,screenshotMap:c,setScreenshotMap:d,sendDaemonCommand:t,updateIdeChats:o,setToasts:g,setLocalUserMessages:se,setClearedTabs:xe,setActionLogs:G,pinTab:Q,isStandalone:A,userName:i.userName,groupIndex:I,isFocused:W===I,onFocus:()=>z(I),isSplitMode:pe,numGroups:ue,onMoveTab:($,re)=>{re==="left"&&I>0?et($,I-1):re==="right"&&I<ue-1?et($,I+1):re==="split-left"&&ue<4?ze($,I,"left"):re==="split-right"&&ue<4&&ze($,I,"right")},onClose:pe?()=>Ke(I):void 0,onReceiveTab:$=>et($,I),detectedIdes:I===0?p:void 0,handleLaunchIde:I===0?B:void 0,onActiveTabChange:$=>j(re=>({...re,[I]:$})),initialActiveTabId:_[I],initialTabOrder:M[I],onTabOrderChange:$=>R(re=>({...re,[I]:$})),onHideTab:ve,cliViewModes:je})]},I)})}),J&&T&&e.jsx(Jn,{activeConv:T,ides:u,isCreatingChat:N,isRefreshingHistory:Z,onClose:()=>V(!1),onNewChat:U,onSwitchSession:de,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(Zn,{toasts:l,onDismiss:k=>g(I=>I.filter(E=>E.id!==k)),onClickToast:k=>{if(k.ideId){const I=q.find(E=>E.ideId===k.ideId||E.tabKey===k.ideId);I&&z(me.get(I.tabKey)??0)}}}),e.jsx("style",{children:`
|
|
63
|
-
@keyframes toast -in {
|
|
64
|
-
from { opacity: 0; transform: translateX(40px); }
|
|
65
|
-
to { opacity: 1; transform: translateX(0); }
|
|
66
|
-
}
|
|
67
|
-
`}),h&&e.jsx(Ur,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}x(!1)}})]})}function Jr(t){return t.split(":")[0]||""}function Zr({renderHeaderActions:t}={}){var ve,be,he;const{id:s}=Ns(),n=kt(),a=Pt(),i=a.ides||[],o=a.connectionStates||{},{sendCommand:c}=nt(),d=r.useMemo(()=>Jr(s||""),[s]),u=r.useMemo(()=>i.find(D=>D.id===s),[i,s]),h=(u==null?void 0:u.type)||void 0,x=h?h.charAt(0).toUpperCase()+h.slice(1):"IDE",l=(u==null?void 0:u.activeChat)||null,g=(u==null?void 0:u.agentStreams)||[],f=a.isConnected??!0,m=o[d]||(f?"connected":"new"),S=((ve=a.connectionTransports)==null?void 0:ve[d])||"unknown",L=r.useMemo(()=>i.find(D=>D.id===d||D.daemonId===d),[i,d]),v=L?xt(L,{fallbackId:d}):"",w=(u==null?void 0:u.workspace)||"",[W]=ws(),z=typeof window<"u"&&window.innerWidth<=768,_=W.get("view")||(z?"chat":"split"),[j,O]=r.useState(_),[M,R]=r.useState("native"),[te,b]=r.useState(""),[F,H]=r.useState(!1),[y,oe]=r.useState(null),[J,V]=r.useState(null),[X,G]=r.useState([]),ie=l==null?void 0:l.status,se=(((he=(be=l==null?void 0:l.activeModal)==null?void 0:be.buttons)==null?void 0:he.length)??0)>0,ce=ie==="generating"||ie==="loading"||ie&&ie.toLowerCase()==="thinking",je=se||ie==="waiting_approval"?"waiting_approval":ce?"working":ie||"idle",K=r.useMemo(()=>{var D,me;return{ideId:s||"",daemonId:d,agentName:Ut(h||""),agentType:h||"",status:je,title:(l==null?void 0:l.title)||"",messages:(l==null?void 0:l.messages)||[],ideType:h||"",workspaceName:(u==null?void 0:u.workspaceName)||"",displayPrimary:x,displaySecondary:(u==null?void 0:u.workspaceName)||"",cdpConnected:!0,modalButtons:(D=l==null?void 0:l.activeModal)==null?void 0:D.buttons,modalMessage:(me=l==null?void 0:l.activeModal)==null?void 0:me.message,streamSource:"native",tabKey:`ide-${s}`}},[s,d,h,l,u,x,je]),C=r.useMemo(()=>g.map(D=>{var ue,pe;const me=D.activeModal?"waiting_approval":D.status==="streaming"?"working":D.status||"idle";return{ideId:s||"",daemonId:d,agentName:D.agentName,agentType:D.agentType,status:me,title:"",messages:D.messages.map((Se,Me)=>({role:Se.role,content:Se.content,kind:Se.kind,id:`${D.agentType}-${Me}`,receivedAt:Se.timestamp})),ideType:D.agentType,workspaceName:"",displayPrimary:D.agentName,displaySecondary:"",cdpConnected:!0,modalButtons:(ue=D.activeModal)==null?void 0:ue.buttons,modalMessage:(pe=D.activeModal)==null?void 0:pe.message,streamSource:"agent-stream",tabKey:`agent-stream-${D.agentType}`}}),[g,s,d]),p=r.useMemo(()=>M==="native"?K:C.find(D=>D.agentType===M)||K,[M,K,C]);r.useEffect(()=>d?tt.onScreenshot("ide-page",(me,ue)=>{if(me!==d)return;const pe=new FileReader;pe.onload=()=>oe(pe.result),pe.readAsDataURL(ue)}):void 0,[d]),r.useEffect(()=>{m!=="connected"&&oe(null)},[m]),r.useEffect(()=>{var me;return d?((me=tt.onStatus)==null?void 0:me.call(tt,(ue,pe)=>{ue===d&&pe!=null&&pe.screenshotUsage&&V(pe.screenshotUsage)}))||(()=>{}):void 0},[d]);const A=r.useMemo(()=>{if(!s)return h;const D=s.split(":");return D.length>=3&&D[1]==="ide"?D.slice(2).join(":"):h},[s,h]);r.useEffect(()=>{oe(null)},[d,s,A]),r.useEffect(()=>{const D=d?tt.get(d):null;!D||!(m==="connected")||(j!=="chat"&&A?D.startScreenshots(A):D.stopScreenshots(A))},[j,m,A,d]);const P=r.useCallback(async(D,me={})=>{if(!s)throw new Error("No IDE ID");return await c(s,D,me)},[s]),q=async()=>{const D=te.trim();if(!(!D||!s||F)){b(""),H(!0);try{await P("send_chat",{message:D,text:D,waitForResponse:!0,...M!=="native"&&{agentType:M}})}catch(me){console.error("[IDE] Send failed:",me)}finally{H(!1)}}},Ie=g.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:x}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),w&&e.jsx("span",{className:"ide-workspace",children:w}),e.jsx("span",{className:"ide-badge",children:"REMOTE"})]}),e.jsxs("div",{className:"ide-status-pill",children:[e.jsx("span",{className:`ide-dot ${m==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:m==="connected"?"Connected":m==="connecting"?"Connecting":"WS"})]}),v&&e.jsx("span",{className:"ide-machine-label",children:v})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(D=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:j===D?"1px solid var(--accent-primary)":"none",background:j===D?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:j===D?"var(--accent-primary)":void 0},onClick:()=>O(D),children:D==="chat"?e.jsx(wt,{size:14}):D==="split"?"⊞":e.jsx(rt,{size:14})},D)),t&&t({daemonId:d,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 ${j==="chat"?"full":""} ${j==="remote"?"hidden":""}`,children:[Ie&&e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${M==="native"?"active":""}`,onClick:()=>R("native"),children:x}),g.map(D=>{const me=M===D.agentType,ue=D.status==="waiting_approval"||!!D.activeModal,pe=D.status==="streaming";return e.jsxs("button",{className:`ide-chat-tab ${me?"active":""}`,onClick:()=>R(D.agentType),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:ue?"#f59e0b":pe?"var(--accent-primary)":"#64748b",boxShadow:pe?"0 0 6px var(--accent-primary)":"none"}}),D.agentName,ue&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},D.agentType)})]}),e.jsx(Bs,{activeConv:p,ides:i,agentInput:te,setAgentInput:b,handleSendChat:q,handleFocusAgent:()=>{},isFocusingAgent:!1,messageReceivedAt:{},actionLogs:[],userName:a.userName})]}),e.jsx("div",{className:`ide-remote-panel ${j==="remote"?"full":""} ${j==="chat"?"hidden":""}`,children:e.jsx(Ln,{addLog:()=>{},connState:m,connScreenshot:y,screenshotUsage:J,transportType:S,onAction:async(D,me)=>{const ue=d?tt.get(d):null;if(!ue||m!=="connected")return console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"};const pe=(u==null?void 0:u.instanceId)||A;return await ue.sendInput(D,me,pe)}})})]}),X.length>0&&e.jsx("div",{className:"ide-toasts",children:X.map(D=>e.jsx("div",{className:`ide-toast ${D.type}`,onClick:()=>G(me=>me.filter(ue=>ue.id!==D.id)),children:D.message},D.id))})]}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function Qr({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:a,logsEndRef:i}){const[o,c]=r.useState([]),[d,u]=r.useState(null),[h,x]=r.useState(!1),[l,g]=r.useState(!1),[f,m]=r.useState(!1),[S,L]=r.useState([]),[v,w]=r.useState([]),[W,z]=r.useState(null),[_,j]=r.useState(!1),[O,M]=r.useState(""),R=r.useRef(null),te=r.useCallback(C=>{R.current=C},[]),b=r.useCallback((C,p)=>{c(A=>[...A.slice(-100),{timestamp:Date.now(),level:C,message:p}]),setTimeout(()=>{var A;return(A=i.current)==null?void 0:A.scrollIntoView({behavior:"smooth"})},100)},[i]),F=r.useCallback(async(C,p)=>{var A;if(!(!t||d)){u(C),b("info",`Launching ${He(C)}${p!=null&&p.workspace?` in ${p.workspace}`:""}...`);try{const P={ideType:C,enableCdp:!0};(A=p==null?void 0:p.workspace)!=null&&A.trim()?P.workspace=p.workspace.trim():p!=null&&p.useDefaultWorkspace&&(P.useDefaultWorkspace=!0);const q=await n(t,"launch_ide",P);b(q!=null&&q.success?"info":"error",q!=null&&q.success?`${He(C)} launched`:`Failed: ${q==null?void 0:q.error}`)}catch(P){b("error",`Launch error: ${P.message}`)}finally{u(null)}}},[t,d,b,n]),H=r.useCallback(async C=>{if(!t)return;const{cliType:p,dir:A,workspaceId:P,useDefaultWorkspace:q,useHome:Ie,argsStr:ve,model:be}=C;if(!p){b("warn","Select a CLI or ACP provider first");return}const he=ve?ve.split(/\s+/).filter(Boolean):void 0,D=(A==null?void 0:A.trim())||(P?"(saved id)":q?"(default workspace)":Ie?"(home)":"");b("info",`Launching ${p}${D?` in ${D}`:""}${be?` (model: ${be})`:""}...`);try{const me={cliType:p,cliArgs:he,initialModel:be||void 0};A!=null&&A.trim()?me.dir=A.trim():P?me.workspaceId=P:q?me.useDefaultWorkspace=!0:Ie&&(me.useHome=!0);const ue=await n(t,"launch_cli",me),pe=(ue==null?void 0:ue.result)||ue;ue!=null&&ue.success?(b("info",`${p} launched`),(pe==null?void 0:pe.launchSource)==="home"?b("info","📂 Running in home directory (explicit choice)"):(pe==null?void 0:pe.launchSource)==="defaultWorkspace"&&b("info","📂 Using default workspace (explicit choice)")):(b("error",`Failed: ${(ue==null?void 0:ue.error)||(pe==null?void 0:pe.error)}`),(ue==null?void 0:ue.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&z({cliType:p,argsStr:ve,model:be}))}catch(me){b("error",`Launch error: ${me.message}`)}},[t,b,n]),y=r.useCallback((C,p,A,P)=>{if(t){if(!C){b("warn","Select a provider");return}if(!p.trim()){z({cliType:C,argsStr:A,model:P});return}H({cliType:C,dir:p,argsStr:A,model:P})}},[t,b,H]),oe=r.useCallback(async(C,p,A)=>{if(t&&window.confirm(`Stop ${C}?
|
|
68
|
-
This will terminate the process.`))try{const P=await n(t,"stop_cli",{cliType:C,dir:p,_targetInstance:A});P!=null&&P.success?b("info",`${C} stopped`):b("error",`Stop failed: ${(P==null?void 0:P.error)||"Unknown error"}`)}catch(P){b("error",`Stop failed: ${P.message}`)}},[t,b,n]),J=r.useCallback(async C=>{try{await n(C.daemonId,"restart_ide",{ideType:C.type}),b("info",`${He(C.type)} restart initiated`)}catch(p){b("error",`Restart failed: ${p.message}`)}},[b,n]),V=r.useCallback(async C=>{if(window.confirm(`Stop ${He(C.type)}?
|
|
69
|
-
This will disconnect CDP and optionally kill the process.`))try{const p=await n(C.daemonId,"stop_ide",{ideType:C.type,killProcess:!0});p!=null&&p.success?b("info",`${He(C.type)} stopped`):b("error",`Stop failed: ${(p==null?void 0:p.error)||"Unknown error"}`)}catch(p){b("error",`Stop failed: ${p.message}`)}},[b,n]),X=r.useCallback(async()=>{if(t)try{const C=await n(t,"detect_ides",{});b("info",`Found ${((C==null?void 0:C.result)||[]).length} IDE(s)`)}catch(C){b("error",`Detection failed: ${C.message}`)}},[t,b,n]),G=r.useCallback(async()=>{if(t){x(!0);try{const C=await n(t,"get_recent_workspaces",{});C!=null&&C.success&&Array.isArray(C==null?void 0:C.result)&&w(C.result)}catch(C){b("error",`Failed: ${C.message}`)}finally{x(!1)}}},[t,b,n]),ie=r.useCallback(async C=>{if(!(!t||!C.trim())){g(!0);try{const p=await n(t,"workspace_add",{path:C.trim()});p!=null&&p.success?b("info",`Workspace added: ${C.trim()}`):b("error",(p==null?void 0:p.error)||"workspace_add failed")}catch(p){b("error",p.message)}finally{g(!1)}return!0}},[t,b,n]),se=r.useCallback(async C=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){g(!0);try{const p=await n(t,"workspace_remove",{id:C});p!=null&&p.success?b("info","Workspace removed"):b("error",(p==null?void 0:p.error)||"workspace_remove failed")}catch(p){b("error",p.message)}finally{g(!1)}}},[t,b,n]),ce=r.useCallback(async C=>{var p;if(t){g(!0);try{const A=await n(t,"workspace_set_default",C===null?{clear:!0}:{id:C});if(A!=null&&A.success){b("info",C?"Default workspace updated":"Default workspace cleared");const P=typeof A.defaultWorkspacePath=="string"?A.defaultWorkspacePath:"";P&&((p=R.current)==null||p.call(R,P))}else b("error",(A==null?void 0:A.error)||"workspace_set_default failed")}catch(A){b("error",A.message)}finally{g(!1)}}},[t,b,n]),xe=r.useCallback(async C=>{var A;if(!t||!C.trim())return;const p=C.trim();g(!0);try{const P=await n(t,"workspace_set_default",{path:p});P!=null&&P.success?(b("info","Default workspace set from history"),(A=R.current)==null||A.call(R,p)):b("error",(P==null?void 0:P.error)||"Could not set default (path missing on disk?)")}catch(P){b("error",P.message)}finally{g(!1)}},[t,b,n]),je=r.useCallback(async()=>{var C;if(t){m(!0);try{const p=await n(t,"get_cli_history",{}),A=(p==null?void 0:p.history)??((C=p==null?void 0:p.result)==null?void 0:C.history);p!=null&&p.success&&Array.isArray(A)&&L(A)}catch{}m(!1)}},[t,n]),K=r.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:O}),a)try{await a({machineRuntimeId:t,registeredMachineId:s,nickname:O})}catch(C){b("warn",`Live nickname updated, but account sync failed: ${C.message}`)}b("info",`Nickname set to "${O||"(cleared)"}"`),j(!1)}catch(C){b("error",`Failed: ${C.message}`)}},[t,O,s,b,a,n]);return{logs:o,launchingIde:d,loadingWorkspaces:h,workspaceBusy:l,loadingHistory:f,cliHistory:S,recentWorkspaces:v,launchPick:W,setLaunchPick:z,editingNickname:_,setEditingNickname:j,nicknameInput:O,setNicknameInput:M,addLog:b,handleLaunchIde:F,runLaunchCliCore:H,handleLaunchCli:y,handleStopCli:oe,handleRestartIde:J,handleStopIde:V,handleDetectIdes:X,handleLoadRecentWorkspaces:G,handleWorkspaceAdd:ie,handleWorkspaceRemove:se,handleWorkspaceSetDefault:ce,handleWorkspaceResumePath:xe,loadCliHistory:je,handleSaveNickname:K,setOnDefaultWorkspaceChanged:te}}function ea({machine:t,managedIdes:s,managedClis:n,managedAcps:a,actions:i}){const{workspaceBusy:o,handleWorkspaceAdd:c,handleWorkspaceRemove:d,handleWorkspaceSetDefault:u}=i,[h,x]=r.useState(""),l=t.availableMem??t.freeMem,g=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-l)/t.totalMem*100))):0,f=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:Yn(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(f/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${f.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(as,{value:g,max:100,label:"Memory",color:"#3b82f6",detail:`${os(t.totalMem-l)} / ${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:m=>void u(m.target.value===""?null:m.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(m=>e.jsx("option",{value:m.id,children:m.label||m.path},m.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:h,disabled:o,onChange:m=>x(m.target.value),onKeyDown:m=>m.key==="Enter"&&void(async()=>{await c(h)&&x("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:o,onClick:async()=>{await c(h)&&x("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1 max-h-32 overflow-y-auto",children:(t.workspaces||[]).map(m=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[m.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:m.path,children:m.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:o,onClick:()=>void d(m.id),children:"Remove"})]},m.id))})]})]})}const ta={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 Kt({category:t,machine:s,machineId:n,providers:a,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:d}){const u=kt(),{handleLaunchIde:h,handleLaunchCli:x,handleStopCli:l,handleRestartIde:g,handleStopIde:f,handleDetectIdes:m,cliHistory:S,loadingHistory:L,loadCliHistory:v,launchingIde:w}=c,W=ta[t],z=t==="ide",_=t==="acp",j=a.filter(p=>p.category===t),[O,M]=r.useState(""),[R,te]=r.useState(""),[b,F]=r.useState(""),[H,y]=r.useState(s.defaultWorkspaceId||""),[oe,J]=r.useState("");r.useEffect(()=>{!O&&j.length>0&&M(j[0].type)},[O,j.length]),r.useEffect(()=>{s.defaultWorkspaceId&&!H&&y(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const V=(()=>{if(H==="__custom__")return oe.trim();if(!H)return"";const p=(s.workspaces||[]).find(A=>A.id===H);return(p==null?void 0:p.path)||""})(),[X,G]=r.useState({}),[ie,se]=r.useState(null);r.useEffect(()=>{if(!z||!n||!d)return;(async()=>{try{const A=await d(n,"get_ide_extensions",{}),P=(A==null?void 0:A.result)||A;P!=null&&P.success&&(P!=null&&P.ides)&&G(P.ides)}catch{}})()},[z,n,d]);const ce=p=>z?He(p.type):t==="cli"?p.cliName:p.acpName,xe=z?s.detectedIdes||[]:[],je=()=>{z?h(O,V?{workspace:V}:void 0):x(O,V,R||void 0,_&&b||void 0)},K=p=>{z?f(p):l(p.type,p.workspace,p.id)},C=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:H,onChange:p=>{y(p.target.value),p.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(p=>e.jsxs("option",{value:p.id,children:[p.id===s.defaultWorkspaceId?"⭐ ":"",p.label||p.path.split("/").filter(Boolean).pop()||p.path," — ",p.path]},p.id)),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]})}),H==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:oe,onChange:p=>J(p.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${W.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",W.label]}),C,z?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[xe.map(p=>{const A=p.running||i.some(P=>(P.type||"").toLowerCase()===(p.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>h(p.type||p.id||"",V?{workspace:V}:void 0),disabled:!!w,className:`machine-btn-primary flex items-center gap-1.5 ${A?"!border-green-500/30":""}`,style:{opacity:w&&w!==p.type?.4:1},children:[e.jsx("span",{children:o(p.type)}),A&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 shadow-[0_0_4px_rgba(34,197,94,0.4)]"}),w===p.type?"⏳ Launching...":`▶ ${p.name||He(p.type)}`,A&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},p.type)}),xe.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:m,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:O,onChange:p=>M(p.target.value),className:"machine-input",children:j.length>0?j.map(p=>e.jsxs("option",{value:p.type,children:[p.icon," ",p.displayName]},p.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),_&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:b,onChange:p=>F(p.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:R,onChange:p=>te(p.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:je,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(p=>{const A=z?p:null,P=_?p: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(p.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ce(p),(A==null?void 0:A.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",A.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:p.workspace||"—"}),(P==null?void 0:P.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",P.currentModel]}),(P==null?void 0:P.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",P.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 ${p.status==="stopped"?"bg-red-500/[0.08] text-red-500":p.status==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:p.status}),z&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>u(`/ide/${p.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(rt,{size:13})," Control"]}),e.jsx("button",{onClick:()=>g(p),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),_&&e.jsx("button",{onClick:()=>u(`/ide/${p.id}`),className:"machine-btn",title:"View chat",children:e.jsx(wt,{size:14})}),p.status==="stopped"?e.jsx("button",{onClick:()=>z?h(p.type,p.workspace?{workspace:p.workspace}:void 0):x(p.type,p.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>K(p),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),A&&A.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:A.aiAgents.map(q=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${q.status==="generating"||q.status==="streaming"?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[q.name," · ",q.status]},q.id))}),A&&(X[A.type]||[]).length>0&&d&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(X[A.type]||[]).map(q=>e.jsxs("button",{disabled:ie===`${A.type}.${q.type}`,onClick:async()=>{const Ie=`${A.type}.${q.type}`;se(Ie);try{await d(n,"set_ide_extension",{ideType:A.type,extensionType:q.type,enabled:!q.enabled}),G(ve=>({...ve,[A.type]:(ve[A.type]||[]).map(be=>be.type===q.type?{...be,enabled:!be.enabled}:be)}))}catch(ve){console.error("Extension toggle failed:",ve)}finally{se(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 ${q.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 ${q.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),q.name,e.jsx("span",{className:"text-[9px] font-normal",children:q.enabled?"ON":"OFF"})]},q.type))})]})]},p.id)})}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:v,disabled:L,className:"machine-btn",children:L?"⏳":"↻ Load"})]}),(()=>{const p=new Set(j.map(P=>P.type)),A=S.filter(P=>(P.category||"cli")!==t?!1:t==="ide"?!0:p.has(P.cliType));return A.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:A.map((P,q)=>{var Ie,ve;return e.jsxs("div",{onClick:()=>{M(P.cliType),(P.workspace||P.dir)&&(y("__custom__"),J(P.workspace||P.dir)),te((P.cliArgs||[]).join(" ")),F(P.model||""),z&&h(P.cliType,P.workspace?{workspace:P.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(P.cliType)}),e.jsx("span",{children:((Ie=P.workspace||P.dir)==null?void 0:Ie.split("/").filter(Boolean).pop())||P.cliType||"root"}),P.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",P.model]}),P.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((ve=P.cliArgs)==null?void 0:ve.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:P.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:P.timestamp?new Date(P.timestamp).toLocaleDateString():""})]},q)})}):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"],sa=[{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 na({machineId:t,provider:s,sendDaemonCommand:n,onClose:a}){const[i,o]=r.useState("config"),[c,d]=r.useState("codex-cli"),[u,h]=r.useState([]),[x,l]=r.useState(""),[g,f]=r.useState([]),[m,S]=r.useState(""),L=r.useRef(null),v=r.useRef(null),w=M=>{h(R=>R.includes(M)?R.filter(te=>te!==M):[...R,M])},W=()=>h([...bs]),z=()=>h([]);r.useEffect(()=>{var M;(M=L.current)==null||M.scrollIntoView({behavior:"smooth"})},[g]),r.useEffect(()=>()=>{v.current&&clearInterval(v.current)},[]);const _=r.useCallback(()=>{v.current&&clearInterval(v.current),v.current=setInterval(async()=>{try{const M=await n(t,"provider_auto_fix_status",{providerType:s.type});(M==null?void 0:M.running)===!1&&i==="running"&&(o("done"),f(R=>[...R,`
|
|
70
|
-
✅ Auto-fix completed!`]),v.current&&clearInterval(v.current))}catch{}},3e3)},[t,s.type,n,i]),j=async()=>{if(u.length!==0){o("running"),f(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${u.join(", ")}`,x?`💬 Comment: ${x}`:"",""]),S("");try{const M=await n(t,"provider_auto_fix",{providerType:s.type,functions:u,agent:c,...x?{comment:x}:{}});M!=null&&M.success&&(M!=null&&M.started||M!=null&&M.running)?(f(R=>[...R,"✅ Agent started. Monitoring progress..."]),_()):(o("error"),S((M==null?void 0:M.error)||"Failed to start auto-fix"))}catch(M){o("error"),S((M==null?void 0:M.message)||"Connection failed")}}},O=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),f(M=>[...M,`
|
|
71
|
-
⚠️ Auto-fix cancelled.`]),o("done"),v.current&&clearInterval(v.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:a,children:e.jsxs("div",{className:"w-full max-w-[560px] max-h-[85vh] overflow-hidden rounded-2xl bg-bg-primary border border-border-subtle shadow-2xl flex flex-col",onClick:M=>M.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:sa.map(M=>e.jsxs("button",{onClick:()=>d(M.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===M.value?M.color+"66":"var(--border-subtle)",background:c===M.value?M.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===M.value?M.color:"var(--text-primary)"},children:M.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:M.desc})]},M.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:z,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(M=>e.jsxs("button",{onClick:()=>w(M),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:u.includes(M)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:u.includes(M)?"rgba(139,92,246,0.08)":"transparent",color:u.includes(M)?"#a78bfa":"var(--text-secondary)"},children:[u.includes(M)?"☑ ":"☐ ",M]},M))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:x,onChange:M=>l(M.target.value),placeholder:"e.g. Also search buttons inside Shadow DOM, preserve code block formatting in readChat...",rows:2,className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] resize-none placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]})]}),(i==="running"||i==="done"||i==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[g.map((M,R)=>e.jsx("div",{className:M.startsWith("✅")?"text-green-400":M.startsWith("❌")||M.startsWith("⚠")?"text-amber-400":"",children:M},R)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:L})]}),m&&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:m})]})]}),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"&&u.length>0&&`${u.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:j,disabled:u.length===0,className:"machine-btn",style:{background:u.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:u.length>0?"rgba(139,92,246,0.4)":void 0,color:u.length>0?"#a78bfa":void 0,opacity:u.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:O,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"),f([]),S("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:a,className:"machine-btn",children:"Close"})]})]})]})]})})}function ra({machineId:t,providers:s,sendDaemonCommand:n,onClose:a,onCreated:i}){var _;const o=s.filter(j=>j.category==="ide"),[c,d]=r.useState(((_=o[0])==null?void 0:_.type)||""),[u,h]=r.useState(""),[x,l]=r.useState(""),[g,f]=r.useState(!1),[m,S]=r.useState(""),[L,v]=r.useState(!1),w=j=>{const O=j.toLowerCase().replace(/[^a-z0-9-]/g,"");h(O),(!x||x===W(u))&&l(W(O))},W=j=>j.split("-").map(O=>O.charAt(0).toUpperCase()+O.slice(1)).join(" "),z=async()=>{if(!(!u||!x||!c)){f(!0),S("");try{const j=await n(t,"provider_clone",{type:u,name:x,category:"ide",location:"user",cloneFrom:c});j!=null&&j.success||j!=null&&j.created?(v(!0),i==null||i(u)):S((j==null?void 0:j.error)||"Failed to create provider")}catch(j){S((j==null?void 0:j.message)||"Connection failed")}f(!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:j=>j.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-text-primary",children:"✨ Create User Provider"}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"Clone an upstream IDE provider to customize"})]}),e.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:L?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:u})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",u,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",u]})," 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(j=>e.jsxs("button",{onClick:()=>d(j.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===j.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:c===j.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:j.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===j.type?"#a78bfa":"var(--text-secondary)"},children:j.displayName})]},j.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:u,onChange:j=>w(j.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/",u||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:x,onChange:j=>l(j.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"})]}),m&&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:m})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:L?e.jsx("button",{onClick:a,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:a,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:z,disabled:!u||!x||g,className:"machine-btn",style:{background:u&&x?"rgba(34,197,94,0.12)":void 0,borderColor:u&&x?"rgba(34,197,94,0.3)":void 0,color:u&&x?"#86efac":void 0,opacity:!u||!x||g?.4:1},children:g?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function aa({machineId:t,providers:s,sendDaemonCommand:n}){const[a,i]=r.useState([]),[o,c]=r.useState(!1),[d,u]=r.useState(null),[h,x]=r.useState("all"),[l,g]=r.useState(null),[f,m]=r.useState(!1),S=r.useCallback(async()=>{var v;if(t){c(!0);try{const w=await n(t,"get_provider_settings",{}),W=(w==null?void 0:w.result)||w;if(w!=null&&w.success&&(W!=null&&W.settings)){const z=[];for(const[_,j]of Object.entries(W.settings)){const O=s.find(M=>M.type===_);z.push({type:_,displayName:(O==null?void 0:O.displayName)||_,icon:(O==null?void 0:O.icon)||"",category:(O==null?void 0:O.category)||"unknown",schema:j,values:((v=W.values)==null?void 0:v[_])||{}})}z.sort((_,j)=>_.category.localeCompare(j.category)||_.displayName.localeCompare(j.displayName)),i(z)}}catch{}c(!1)}},[t,s,n]);r.useEffect(()=>{a.length===0&&S()},[]);const L=async(v,w,W)=>{u(`${v}.${w}`),i(z=>z.map(_=>_.type===v?{..._,values:{..._.values,[w]:W}}:_));try{const z=await n(t,"set_provider_setting",{providerType:v,key:w,value:W});z!=null&&z.success||S()}catch{S()}u(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(v=>e.jsx("button",{onClick:()=>x(v),className:`machine-btn text-[10px] px-2 py-0.5 ${h===v?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:v.toUpperCase()},v))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>m(!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:S,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),h!=="all"&&a.filter(v=>v.category===h).length>1&&(()=>{const v=a.filter(_=>_.category===h),w=new Map;for(const _ of v)for(const j of _.schema){if(j.type!=="boolean")continue;const O=w.get(j.key),M=!!(_.values[j.key]??j.default);O?(O.onCount+=M?1:0,O.total+=1):w.set(j.key,{label:j.label||j.key,onCount:M?1:0,total:1})}const W=[...w.entries()].filter(([,_])=>_.total===v.length);if(W.length===0)return null;const z=async(_,j)=>{for(const O of v)await L(O.type,_,j)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",h.toUpperCase()," providers (",v.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:W.map(([_,j])=>{const O=j.onCount===j.total,M=j.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:j.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",j.onCount,"/",j.total,")"]}),e.jsx("button",{onClick:()=>void z(_,!0),disabled:O,className:`machine-btn text-[9px] px-1.5 py-px ${O?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void z(_,!1),disabled:M,className:`machine-btn text-[9px] px-1.5 py-px ${M?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},_)})})]})})(),o&&a.length===0?e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading provider settings..."}):e.jsx("div",{className:"flex flex-col gap-2",children:a.filter(v=>h==="all"||v.category===h).map(v=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:v.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:v.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:v.category==="acp"?"rgba(139,92,246,0.08)":v.category==="cli"?"rgba(59,130,246,0.08)":v.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:v.category==="acp"?"#a78bfa":v.category==="cli"?"#60a5fa":v.category==="ide"?"#86efac":"#fbbf24"},children:v.category}),v.category==="ide"&&e.jsx("button",{onClick:()=>g(s.find(w=>w.type===v.type)||{type:v.type,displayName:v.displayName,icon:v.icon,category:v.category}),className:"ml-auto machine-btn text-[9px] px-2 py-0.5 bg-violet-500/[0.06] border-violet-500/20 text-violet-400 hover:bg-violet-500/[0.12]",children:"🔧 Auto-Fix"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:v.schema.map(w=>e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-xs font-medium text-text-primary",children:[w.label||w.key,d===`${v.type}.${w.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),w.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:w.description})]}),e.jsx("div",{className:"shrink-0",children:w.type==="boolean"?e.jsx("button",{onClick:()=>L(v.type,w.key,!(v.values[w.key]??w.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:v.values[w.key]??w.default?"#8b5cf6":"var(--border-subtle)"},children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white absolute top-[3px] transition-[left] duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.3)]",style:{left:v.values[w.key]??w.default?21:3}})}):w.type==="number"?e.jsx("input",{type:"number",value:v.values[w.key]??w.default??0,min:w.min,max:w.max,onChange:W=>{const z=parseInt(W.target.value)||0;w.min!==void 0&&z<w.min||w.max!==void 0&&z>w.max||L(v.type,w.key,z)},className:"machine-input w-20 text-center text-[11px]"}):w.type==="select"&&w.options?e.jsx("select",{value:v.values[w.key]??w.default??"",onChange:W=>L(v.type,w.key,W.target.value),className:"machine-input text-[11px]",children:w.options.map(W=>e.jsx("option",{value:W,children:W},W))}):e.jsx("input",{type:"text",value:v.values[w.key]??w.default??"",onBlur:W=>L(v.type,w.key,W.target.value),className:"machine-input w-[120px] text-[11px]"})})]},w.key))})]},v.type))}),l&&e.jsx(na,{machineId:t,provider:l,sendDaemonCommand:n,onClose:()=>g(null)}),f&&e.jsx(ra,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>m(!1),onCreated:()=>{m(!1),S()}})]})}function oa({machineId:t,sendDaemonCommand:s}){const[n,a]=r.useState([]),[i,o]=r.useState(0),[c,d]=r.useState(!0),[u,h]=r.useState("debug"),x=r.useRef(null),l=r.useRef(!1);return r.useEffect(()=>{if(!t||!c)return;const g=async()=>{try{const m=await s(t,"get_logs",{count:200,minLevel:u,since:i}),S=(m==null?void 0:m.result)||m;if(m!=null&&m.success&&Array.isArray(S==null?void 0:S.logs)&&S.logs.length>0){a(v=>[...v,...S.logs.map(W=>({timestamp:W.ts,level:W.level,message:`[${W.category}] ${W.message}`}))].slice(-300));const L=Math.max(...S.logs.map(v=>v.ts));o(L)}}catch{}};g();const f=setInterval(g,3e3);return()=>clearInterval(f)},[t,c,i,u,s]),r.useEffect(()=>{if(c&&n.length>0){const g=l.current?"smooth":"instant";setTimeout(()=>{var f;(f=x.current)==null||f.scrollIntoView({behavior:g}),l.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(g=>e.jsx("button",{onClick:()=>{h(g),a([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${u===g?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:g.toUpperCase()},g))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[n.length," entries"]}),e.jsx("button",{onClick:()=>d(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{a([]),o(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[n.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),n.map((g,f)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"#f59e0b":g.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(g.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"#f59e0b":g.level==="debug"?"#475569":"#8b5cf6"},children:g.level==="error"?"ERR":g.level==="warn"?"WRN":g.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:g.message})]},f)),e.jsx("div",{ref:x})]})]})}function ia({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 ca({onNicknameSynced:t}={}){var _,j,O,M,R,te,b,F,H;const{id:s}=Ns(),n=kt(),{sendCommand:a}=nt(),i=Pt(),o=i.ides||[],c=i.initialLoaded??!0,d=o.find(y=>y.id===s&&y.daemonMode),[u,h]=r.useState("overview"),x=r.useRef(null),l=Qr({machineId:s,registeredMachineId:(d==null?void 0:d.machineId)||null,sendDaemonCommand:a,onNicknameSynced:t,logsEndRef:x}),g=((d==null?void 0:d.availableProviders)||[]).map(y=>({type:y.type,displayName:y.displayName,icon:y.icon,category:y.category})),f={};for(const y of g)f[y.type]=y.icon;const m=y=>f[y]||"",S=d?{id:d.id,hostname:Ks(d,{fallbackId:d.id}),platform:((_=d.machine)==null?void 0:_.platform)||"unknown",arch:((j=d.machine)==null?void 0:j.arch)||"",cpus:((O=d.machine)==null?void 0:O.cpus)||0,totalMem:((M=d.machine)==null?void 0:M.totalMem)||0,freeMem:((R=d.machine)==null?void 0:R.freeMem)||0,availableMem:(te=d.machine)==null?void 0:te.availableMem,loadavg:((b=d.machine)==null?void 0:b.loadavg)||[],uptime:((F=d.machine)==null?void 0:F.uptime)||0,release:((H=d.machine)==null?void 0:H.release)||"",cdpConnected:!!(d.ides||[]).some(y=>y.cdpConnected),machineNickname:d.machineNickname||null,p2p:d.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:d.detectedIdes||[],managedIdeIds:d.managedIdeIds||[],managedCliIds:d.managedCliIds||[],workspaces:d.workspaces||[],defaultWorkspaceId:d.defaultWorkspaceId??d.activeWorkspaceId??null,defaultWorkspacePath:d.defaultWorkspacePath??d.activeWorkspacePath??null,workspaceActivity:d.workspaceActivity||[]}:null,L=o.filter(y=>y.daemonId===s&&!y.daemonMode).filter(y=>!is(y)&&!cs(y)).map(y=>({id:y.id,type:y.type,version:y.version||"",instanceId:y.instanceId||"",status:y.status,workspace:y.workspace||null,terminals:y.terminals||0,aiAgents:Gn(y.aiAgents||y.agents||[]),activeChat:y.activeChat||null,chats:y.chats||[],agentStreams:y.agentStreams||[],cdpConnected:y.cdpConnected||!1,daemonId:s})),v=o.filter(y=>y.daemonId===s&&is(y)).map(y=>({id:y.id,type:y.type,cliName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,daemonId:s})),w=o.filter(y=>y.daemonId===s&&cs(y)).map(y=>({id:y.id,type:y.type,acpName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,currentModel:y.currentModel,currentPlan:y.currentPlan,daemonId:s}));if(!S)return c?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:()=>n("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const W=xt(d,{fallbackId:S.id}),z=[{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:L.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ut,{size:14})," CLIs"]}),count:v.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:()=>n("/machines"),className:"machine-btn-back flex shrink-0",children:"←"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:l.nicknameInput,onChange:y=>l.setNicknameInput(y.target.value),onKeyDown:y=>{y.key==="Enter"&&l.handleSaveNickname(),y.key==="Escape"&&l.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:l.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>l.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{l.setEditingNickname(!0),l.setNicknameInput(S.machineNickname||"")},title:"Click to set nickname",children:W}),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:[S.platform," · ",S.arch," · ",S.cpus," cores"]}),(d==null?void 0:d.version)&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-bg-glass border border-border-subtle text-text-muted shrink-0",children:["v",d.version]}),(d==null?void 0:d.versionMismatch)&&e.jsxs("button",{className:"px-1.5 py-px rounded text-[9px] font-semibold bg-amber-500/[0.08] border border-amber-500/20 text-amber-400 cursor-pointer hover:bg-amber-500/[0.15] transition-colors shrink-0",onClick:async()=>{try{await a(s,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",d.serverVersion]}),S.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:S.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:S.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",S.p2p.state==="connected"?`● ${S.p2p.peers}`:"○"]}),S.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 ●"}),S.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",S.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:z.map(y=>e.jsxs("button",{onClick:()=>h(y.id),className:`machine-tab shrink-0${u===y.id?" active":""}`,children:[y.label,y.count!==void 0&&e.jsx("span",{className:"tab-count",children:y.count})]},y.id))})]}),e.jsxs("div",{className:"page-content",children:[u==="overview"&&e.jsx(ea,{machine:S,managedIdes:L,managedClis:v,managedAcps:w,actions:l}),u==="ides"&&e.jsx(Kt,{category:"ide",machine:S,machineId:s,providers:g,managedEntries:L,getIcon:m,actions:l,sendDaemonCommand:a}),u==="clis"&&e.jsx(Kt,{category:"cli",machine:S,machineId:s,providers:g,managedEntries:v,getIcon:m,actions:l}),u==="acps"&&e.jsx(Kt,{category:"acp",machine:S,machineId:s,providers:g,managedEntries:w,getIcon:m,actions:l}),u==="providers"&&e.jsx(aa,{machineId:s,providers:g,sendDaemonCommand:a}),u==="logs"&&e.jsx(oa,{machineId:s,sendDaemonCommand:a})]}),l.launchPick&&S&&e.jsx(ia,{machine:S,launchPick:l.launchPick,actions:l})]})}function la(){const[t,s]=r.useState({ide:[],cli:[],ext:[],acp:[]}),[n,a]=r.useState(!0);r.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const d=[],u=[],h=[],x=[];Object.values(c.providers||{}).forEach(g=>{const f={name:g.name||"Unknown",status:g.status||"Stable",details:g.details||"Community Provider"};g.category==="ide"?d.push(f):g.category==="cli"?u.push(f):g.category==="extension"?h.push(f):g.category==="acp"&&x.push(f)});const l=(g,f)=>{const m={Stable:1,Beta:2,WIP:3},S=m[g.status]||99,L=m[f.status]||99;return S!==L?S-L:g.name.localeCompare(f.name)};s({ide:d.sort(l),cli:u.sort(l),ext:h.sort(l),acp:x.sort(l)})}).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((d,u)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:d.name}),e.jsx("td",{className:"py-3 px-4",children:i(d.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:d.details})]},u))})]})});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 da{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 da;function ua(){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=ua(),js=3e3,xa=3e4;let Ze=null,pa=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_${++pa}_${Date.now()}`;return new Promise((c,d)=>{const u=setTimeout(()=>{Rt.delete(o),d(new Error(`WS command timeout: ${s}`))},3e4);Rt.set(o,{resolve:h=>{clearTimeout(u),c(h)},reject:h=>{clearTimeout(u),d(h)}}),a.send(JSON.stringify({type:"command",requestId:o,data:{type:s,payload:n||{},target:t}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:n||{},target:t})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class ma{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 ha(t){return(!st||st.daemonId!==t)&&(st=new ma(t)),st}function fa({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((l,g)=>{o(l),yt==null||yt(l,g)},[]),d=r.useRef(null),u=r.useRef(),h=r.useRef(js),x=r.useRef(!0);return r.useEffect(()=>{x.current=!0;function l(){var m,S;if(!x.current||((m=d.current)==null?void 0:m.readyState)===WebSocket.OPEN||((S=d.current)==null?void 0:S.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${ys}...`);let f;try{f=new WebSocket(ys)}catch(L){console.error("[Standalone WS] Failed to create WebSocket:",L),g();return}d.current=f,f.onopen=()=>{if(!x.current){f.close();return}c("connected"),h.current=js,console.log("[Standalone WS] Connected")},Ze=f,f.onmessage=L=>{var v;try{const w=JSON.parse(L.data);if((w.type==="command_result"||w.type==="error")&&w.requestId){const W=Rt.get(w.requestId);W&&(Rt.delete(w.requestId),w.type==="error"?W.reject(new Error(((v=w.data)==null?void 0:v.message)||"Command failed")):W.resolve(w.data));return}if(w.type==="pty_output"){Je.emitPtyOutput(w.cliId,w.data);return}if(w.type==="status"||w.type==="initial_state"){const W=w.data;if(!W)return;const{injectEntries:z,markLoaded:_}=s.current,j=W.id||"standalone",O=ha(j);Je.register(j,O),Je.setState(j,"connected"),c("connected",j),Je.emitStatus(j,W);const M=sr(W,{daemonId:j});M.length>0&&z(M),_(),W.userName&&i.current&&i.current(W.userName)}}catch(w){console.error("[Standalone WS] Parse error:",w)}},f.onclose=()=>{x.current&&(st&&Je.setState(st.daemonId,"disconnected"),c("disconnected"),d.current=null,g())},f.onerror=L=>{console.warn("[Standalone WS] Error, will reconnect:",L)}}function g(){if(!x.current)return;clearTimeout(u.current);const f=h.current;console.log(`[Standalone WS] Reconnecting in ${f}ms...`),u.current=setTimeout(()=>{h.current=Math.min(h.current*1.5,xa),l()},f)}return l(),()=>{x.current=!1,clearTimeout(u.current),d.current&&(d.current.onclose=null,d.current.close(),d.current=null,Ze=null),st&&Je.unregister(st.daemonId)}},[]),e.jsx(e.Fragment,{children:t})}function ga({children:t}){const[s,n]=r.useState("disconnected"),[a,i]=r.useState(null);r.useEffect(()=>(yt=(c,d)=>{n(c),d&&i(d)},()=>{yt=null}),[]);const o=r.useMemo(()=>{const c=s==="connected",d={};return a&&(d[a]=c?"connected":"connecting"),d.standalone=c?"connected":"connecting",{wsStatus:s,isConnected:c,connectionStates:d}},[s,a]);return e.jsx(fn,{connectionOverrides:o,children:e.jsx(fa,{children:t})})}const ba=[{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 ya({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}}),d=x=>{s(x),i(!1)},u=()=>{c(x=>{const l=!x;try{localStorage.setItem("sidebar-collapsed",l?"1":"0")}catch{}return l})},h=x=>`nav-item${n.pathname.startsWith(x)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${a?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),a&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:x=>x.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${a?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:ba.map(x=>e.jsxs("div",{className:h(x.path),id:`nav-${x.id}`,onClick:()=>d(x.path),title:o?x.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:x.icon}),!o&&x.label]},x.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(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.73"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:u,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 ja=[{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."}],va=[{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."}],wa=[{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 Na(){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.73"]}),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:ja.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:va.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:wa.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.jsxs("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm no-underline",children:[e.jsx(_n,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function ka(){const{ides:t}=jt(),s=t.find(l=>l.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 d=l=>{const g=l.target.value.trim();s!=null&&s.id&&g!==i&&a(s.id,"set_user_name",{userName:g}).catch(console.error)},[u,h]=r.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),x=l=>{h(l);try{localStorage.setItem("adhdev_sound",l?"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(fr,{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.73"]}),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(l=>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 ${l.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:l.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:l.type})]},l.type))})}),e.jsx(De,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Nr,{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(Ir,{})]}),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(Wr,{})]})]})}),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(wr,{}),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:u,onChange:x})]})}),e.jsx(De,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(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:l=>c(l.target.value),onBlur:d,onKeyDown:l=>{l.key==="Enter"&&l.currentTarget.blur()}})]})})})]})}Ar();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 Sa(){return e.jsx(ln,{children:e.jsx(ga,{children:e.jsx(jn,{value:{sendCommand:$t,sendData:()=>!1},children:e.jsx(ya,{children:e.jsxs(dn,{children:[e.jsx(qe,{path:"/dashboard",element:e.jsx(Gr,{})}),e.jsx(qe,{path:"/ide/:id",element:e.jsx(Zr,{})}),e.jsx(qe,{path:"/machine",element:e.jsx(vs,{})}),e.jsx(qe,{path:"/machines/:id",element:e.jsx(ca,{})}),e.jsx(qe,{path:"/machines",element:e.jsx(vs,{})}),e.jsx(qe,{path:"/capabilities",element:e.jsx(la,{})}),e.jsx(qe,{path:"/about",element:e.jsx(Na,{})}),e.jsx(qe,{path:"/settings",element:e.jsx(ka,{})}),e.jsx(qe,{path:"*",element:e.jsx(Mt,{to:"/dashboard",replace:!0})})]})})})})})}Hn({connectionManager:Je,p2pManager:Je});un(document.getElementById("root")).render(e.jsx(r.StrictMode,{children:e.jsx(Sa,{})}));
|