@adhdev/daemon-standalone 0.6.61 → 0.6.62

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 Cs=Object.defineProperty;var Is=(t,s,a)=>s in t?Cs(t,s,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[s]=a;var Ee=(t,s,a)=>Is(t,typeof s!="symbol"?s+"":s,a);import{r as n,j as e,M as Kt,a as Ft,b as Ms,c as Ts,u as ut,t as Es,d as $s,e as As,f as is,R as _s,g as cs,h as Rs,B as Ps,i as Ls,k as Ye,N as ft,l as Ds}from"./vendor-Df99lqBA.js";import{D as Bs,o as Ws,L as Os}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"]'))r(i);new MutationObserver(i=>{for(const c of i)if(c.type==="childList")for(const o of c.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function a(i){const c={};return i.integrity&&(c.integrity=i.integrity),i.referrerPolicy&&(c.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?c.credentials="include":i.crossOrigin==="anonymous"?c.credentials="omit":c.credentials="same-origin",c}function r(i){if(i.ep)return;i.ep=!0;const c=a(i);fetch(i.href,c)}})();const ls=n.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}),ds=n.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Ht(t){var a,r;let s=0;return"activeChat"in t&&(s+=4),(a=t.agentStreams)!=null&&a.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(r=t.agents)!=null&&r.length&&(s+=1),s}function Ks(t,s){var o,x,u,p,d,l,w;const a=Date.now();if(s.length===0)return t.map(f=>({...f,_lastUpdate:a}));const r=new Map;for(const f of s)r.set(f.id,f);for(const f of t){const m=r.get(f.id);if(!m){r.set(f.id,{...f,_lastUpdate:a});continue}const E=Ht(f),A=Ht(m);if(E>A){const b=(o=f.chats)!=null&&o.length?f.chats:m.chats;r.set(f.id,{...m,...f,chats:b,_lastUpdate:a})}else if(E<A){const b={};f.status&&f.status!==m.status&&(b.status=f.status),f.cdpConnected!==void 0&&(b.cdpConnected=f.cdpConnected),(x=f.chats)!=null&&x.length&&!((u=m.chats)!=null&&u.length)&&(b.chats=f.chats),f.machineNickname!==void 0&&f.machineNickname!==m.machineNickname&&(b.machineNickname=f.machineNickname),Object.keys(b).length>0&&r.set(f.id,{...m,...b,_lastUpdate:m._lastUpdate})}else{const b=f.timestamp||a,S=m._lastUpdate||m.timestamp||0;if(b>=S){const W=(p=f.chats)!=null&&p.length?f.chats:m.chats;r.set(f.id,{...m,...f,chats:W,_lastUpdate:a})}else(d=f.chats)!=null&&d.length&&!((l=m.chats)!=null&&l.length)&&r.set(f.id,{...m,chats:f.chats})}}const i=new Set(t.map(f=>f.id)),c=new Set;for(const f of t){const m=f.daemonId||((w=f.id)==null?void 0:w.split(":")[0]);m&&c.add(m)}for(const[f,m]of r){const E=m.daemonId||f.split(":")[0];if(!c.has(E))continue;const A=a-(m._lastUpdate||m.timestamp||0);(f.includes(":cli:")&&!i.has(f)&&A>1e4||f.includes(":acp:")&&!i.has(f)&&A>1e4||f.includes(":ide:")&&!i.has(f)&&A>3e4)&&r.delete(f)}for(const[f,m]of r)a-(m._lastUpdate||m.timestamp||0)>3e5&&m.status!=="online"&&r.delete(f);return Array.from(r.values())}function Fs({children:t,connectionOverrides:s}){const[a,r]=n.useState([]),[i,c]=n.useState({}),[o,x]=n.useState(!1),[u,p]=n.useState([]),[d,l]=n.useState(void 0),w=n.useCallback((E,A)=>{r(b=>b.map(S=>S.id===E?{...S,chats:A}:S))},[]),f={injectEntries:E=>{r(A=>A.length===0?E:Ks(E,A))},markLoaded:()=>x(!0),getIdes:()=>a},m=s;return e.jsx(ds.Provider,{value:f,children:e.jsx(ls.Provider,{value:{ides:a,updateIdeChats:w,screenshotMap:i,setScreenshotMap:c,initialLoaded:o,toasts:u,setToasts:p,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:d,setUserName:l},children:t})})}function ct(){return n.useContext(ls)}function Ut(){return n.useContext(ds)}function Hs(t){const{baseUrl:s,getToken:a,onUnauthorized:r}=t;async function i(c,o={}){const x={"Content-Type":"application/json",...o.headers||{}},u=a==null?void 0:a();u&&(x.Authorization=`Bearer ${u}`);const p=c.startsWith("http")?c:`${s}${c.startsWith("/")?"":"/"}${c}`,d=await fetch(p,{...o,headers:x});if(d.status===401)throw r==null||r(),new Error("Unauthorized");if(!d.ok){const l=await d.json().catch(()=>({error:d.statusText}));throw new Error(l.error||`API Error: ${d.status}`)}return d.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:c=>i(`/api/v1/daemons/${c}/status`),sendCommand:(c,o,x={})=>i(`/api/v1/daemons/${c}/command`,{method:"POST",body:JSON.stringify({type:o,payload:x})}),execTerminal:(c,o,x)=>i(`/api/v1/daemons/${c}/terminal`,{method:"POST",body:JSON.stringify({command:o,name:x})}),sendAgentMessage:(c,o,x)=>i(`/api/v1/shortcuts/${c}/chat`,{method:"POST",body:JSON.stringify({agentType:o,message:x})}),getAgentStatus:c=>i(`/api/v1/shortcuts/${c}/status`),approveAgent:(c,o,x)=>i(`/api/v1/shortcuts/${c}/approve`,{method:"POST",body:JSON.stringify({agentType:o,action:x?"approve":"reject"})}),request:i}}const Us=Hs({baseUrl:"http://localhost:3847"});n.createContext(Us);const zs={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},us=n.createContext(zs);function Ys({value:t,children:s}){return e.jsx(us.Provider,{value:t,children:s})}function Ge(){return n.useContext(us)}const Se={size:18};function Gs({size:t=Se.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 Vs({size:t=Se.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 Xs({size:t=Se.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 xs({size:t=Se.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 qs({size:t=Se.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 jt({size:t=Se.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 xt({size:t=Se.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 Js({size:t=Se.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 Zs({size:t=Se.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 Rt({size:t=Se.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 Qs({size:t=Se.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 ms({size:t=Se.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 ps({size:t=Se.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 en({size:t=Se.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 tn({size:t=Se.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 sn({size:t=Se.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 hs({size:t=Se.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 nn({size:t=Se.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 fs({size:t=Se.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 rn({size:t=Se.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 an({size:t=Se.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 on(t){const a=t.split(`
2
- `).map(x=>{if(!x.includes("\r"))return x;const u=x.split("\r").map(l=>l.trim()).filter(Boolean);if(u.length===0)return"";const p=u.filter(l=>l.startsWith("⏺"));if(p.length>0)return p[p.length-1];const d=u.filter(l=>!(/^[❯›>]\s*$/.test(l)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(l)&&l.length<40||/^[╭╰│├╮╯─═]+$/.test(l)));return d.length>0?d[d.length-1]:u[u.length-1]}).join(`
3
- `).split(`
4
- `),r={},i=[];let c=!1;for(const x of a){const u=x.trim();if(u===""){c=!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(x)){const d=x.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(d)r[d[1]]=(r[d[1]]||0)+1;else{const l=x.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);l&&(r[l]=(r[l]||0)+1)}c=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(x)||/^[╭╰│├╮╯─]+/.test(u)||/^\s+[⊙✓✗○◎▸►✦]/.test(x)||c&&/^\s{2,}/.test(x))continue;c=!1;const p=x.replace(/^❯\s+/,"");i.push(p)}const o=i.join(`
5
- `).replace(/\n{3,}/g,`
6
-
7
- `).trim();return{toolCounts:r,textContent:o,hasTools:Object.keys(r).length>0}}function kt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}const cn=n.forwardRef(function({messages:s,actionLogs:a,agentName:r="Agent",userName:i,isCliMode:c=!1,isWorking:o=!1,contextKey:x="",receivedAtMap:u={},emptyState:p,onLoadMore:d,isLoadingMore:l,hasMoreHistory:w,loadError:f},m){var xe;const E=n.useRef(null),A=n.useRef(null),b=n.useRef(0),S=n.useRef(""),W=n.useRef(!1),[H,D]=n.useState(new Set),[I,_]=n.useState(new Set),C=n.useRef(!1),j=()=>{const V=E.current;return V?V.scrollHeight-V.scrollTop-V.clientHeight<200:!0},se=s.length>0?`${s.length}:${(((xe=s[s.length-1])==null?void 0:xe.content)||"").length}`:"0:0";n.useEffect(()=>{var oe,ee;const V=!W.current,X=S.current!==x;if(S.current=x,V||X){W.current=!0,C.current=!1;const le=()=>{var ce;(ce=A.current)==null||ce.scrollIntoView({behavior:"instant"})};requestAnimationFrame(()=>requestAnimationFrame(le)),setTimeout(le,100),setTimeout(le,300),b.current=s.length;return}s.length>b.current?C.current||(oe=A.current)==null||oe.scrollIntoView({behavior:"instant"}):j()&&!C.current&&((ee=A.current)==null||ee.scrollIntoView({behavior:"instant"})),b.current=s.length},[se,x,o]),n.useImperativeHandle(m,()=>({scrollToBottom:(V="smooth")=>{var X;(X=A.current)==null||X.scrollIntoView({behavior:V})}})),n.useEffect(()=>{const V=E.current;if(!V)return;let X;const O=()=>{clearTimeout(X),X=setTimeout(()=>{C.current=!j()},50)};return V.addEventListener("scroll",O,{passive:!0}),()=>{V.removeEventListener("scroll",O),clearTimeout(X)}},[]);const $=n.useRef(0),Y=n.useRef(!1);n.useEffect(()=>{const V=E.current;if(!V||!Y.current||$.current===0)return;const X=V.scrollHeight-$.current;X>0&&(V.scrollTop=X),$.current=0,Y.current=!1},[s.length]);const G=()=>{const V=E.current;V&&($.current=V.scrollHeight),Y.current=!0,d==null||d()},g=(()=>{const V=s.map((ee,le)=>({type:"message",data:ee,index:le,ts:ee.receivedAt||u[ee.id??`i-${le}`]||0}));if(!a||a.length===0)return V;const X=[...a].sort((ee,le)=>ee.timestamp-le.timestamp).map((ee,le)=>({type:"action",data:ee,index:le,ts:ee.timestamp})),O=[];let oe=0;for(const ee of V){for(;oe<X.length&&ee.ts>0&&X[oe].ts<ee.ts;)O.push(X[oe++]);O.push(ee)}for(;oe<X.length;)O.push(X[oe++]);return O})(),Q=700;return e.jsxs("div",{ref:E,"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..."}),w&&!l&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:G,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"})}),g.length===0&&!w&&(p||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),g.map(V=>{var ke;if(V.type==="action"){const ve=V.data;return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Kt,{remarkPlugins:[Ft],children:ve.text}),e.jsx("span",{className:"action-time",children:kt(ve.timestamp)})]},`action-${V.index}`)}const X=V.data,O=V.index,oe=(X.role||"").toLowerCase(),ee=oe==="user"||oe==="human",le=X.kind||(oe==="tool"?"tool":"standard"),ce=X.receivedAt||u[X.id??`i-${O}`],R=`${x}-${O}`,y=H.has(R),L=I.has(R),h=typeof X.content=="string"?X.content:(X.content||[]).map(ve=>ve.text||"").join(`
8
- `);if(le==="thought"){const ve=((ke=X.meta)==null?void 0:ke.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(rn,{size:13}),e.jsx("span",{children:ve})]}),e.jsx("div",{className:"chat-msg-body",children:h})]},`msg-${O}`)}if(le==="tool")return e.jsxs("div",{className:"self-start chat-msg-tool",children:[e.jsx("span",{className:"tool-icon",children:"⏺"}),e.jsx("span",{className:"tool-text",children:h.split(`
9
- `)[0].slice(0,80)})]},`msg-${O}`);if(le==="terminal"){const ve=X.meta||{},pe=ve.isRunning?"⏳":"✅",P=ve.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:pe}),e.jsx("span",{children:P})]}),e.jsx("pre",{className:"chat-msg-body",children:h})]},`msg-${O}`)}if(le==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:h.slice(0,100)},`msg-${O}`);const K=!ee&&c?on(h):null,z=K?K.textContent:h,me=K?Object.entries(K.toolCounts):[],ye=c&&!ee&&!y&&z.length>Q,de=y?h:ye&&!L?z.slice(0,Q):z;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${ee?"self-end":"self-start"}`,children:[me.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[me.map(([ve,pe])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",ve,pe>1?` ×${pe}`:""]},ve)),(K==null?void 0:K.hasTools)&&e.jsx("button",{onClick:()=>D(ve=>{const pe=new Set(ve);return y?pe.delete(R):pe.add(R),pe}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:y?"Collapse":"Original"}),!z&&ce!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:kt(ce)})]}),(z||ee)&&e.jsxs("div",{className:`chat-bubble ${ee?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${z?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:ee?i||"You":r}),ce!=null&&e.jsx("span",{className:"chat-time",children:kt(ce)})]}),z&&e.jsx("div",{className:"chat-markdown",children:e.jsx(Kt,{remarkPlugins:[Ft,Ms,Ts],children:de})}),ye&&e.jsx("button",{onClick:()=>_(ve=>{const pe=new Set(ve);return L?pe.delete(R):pe.add(R),pe}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:L?"Collapse ↑":`Show more (${Math.round(z.length/100)*100} chars) ↓`})]})]},`msg-${O}`)}),o&&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:A})]})}),zt={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"},gs=n.forwardRef(({onInput:t,onResize:s,fontSize:a=13},r)=>{const i=n.useRef(null),c=n.useRef(null),o=n.useRef(null),[x,u]=n.useState(!1);return n.useImperativeHandle(r,()=>({write:p=>{var d;(d=c.current)==null||d.write(p)},clear:()=>{var p;(p=c.current)==null||p.clear()},fit:()=>{var p;try{(p=o.current)==null||p.fit(),c.current&&(s==null||s(c.current.cols,c.current.rows))}catch{}},bumpResize:()=>{var p;try{(p=o.current)==null||p.fit();const d=c.current;if(!d)return;const l=d.cols,w=d.rows;s==null||s(l+5,w),setTimeout(()=>{s==null||s(l,w)},100)}catch{}}})),n.useEffect(()=>{if(!i.current)return;const p=new Bs({cursorBlink:!0,cursorStyle:"bar",fontSize:a,fontFamily:"'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace",fontWeight:"400",letterSpacing:0,lineHeight:1.2,theme:zt,allowTransparency:!0,scrollback:5e3,convertEol:!1}),d=new Ws,l=new Os;p.loadAddon(d),p.loadAddon(l),p.open(i.current),requestAnimationFrame(()=>{d.fit(),s==null||s(p.cols,p.rows),u(!0)});const w=p.onData(m=>{t(m)}),f=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{d.fit(),s==null||s(p.cols,p.rows)}catch{}})});return f.observe(i.current),c.current=p,o.current=d,()=>{w.dispose(),f.disconnect(),p.dispose(),c.current=null,o.current=null}},[a]),e.jsx("div",{ref:i,className:"w-full h-full rounded-lg overflow-hidden transition-opacity duration-200",style:{background:zt.background,opacity:x?1:0}})});gs.displayName="CliTerminal";function pt({label:t,value:s,sub:a,icon:r}){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:r}),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}),a&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:a})]})}function Yt({value:t,max:s,label:a,color:r="#8b5cf6",detail:i,compact:c=!1}){const o=s>0?Math.min(Math.round(t/s*100),100):0,x=o>85?"#ef4444":o>60?"#f59e0b":r;return c?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:a}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[o,"%"]})]}),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:`${o}%`,background:x}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:a}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[o,"%"]})]}),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:`${o}%`,background:`linear-gradient(90deg, ${x}, ${x}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function ln({onAction:t,addLog:s,connState:a,connScreenshot:r,screenshotUsage:i,transportType:c}){const o=n.useRef(null),x=n.useRef(null),u=n.useRef(null),[p,d]=n.useState(null),[l,w]=n.useState(""),[,f]=n.useState(!1),[m,E]=n.useState([]),A=n.useRef(0),[b,S]=n.useState(!1),[W,H]=n.useState(!1),D=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[I,_]=n.useState(D?"mouse":"touch"),[C,j]=n.useState(1),se=n.useRef(!1),[$,Y]=n.useState(1),[G,g]=n.useState(0),[Q,xe]=n.useState(0),V=n.useRef(0),X=n.useRef(t),O=n.useRef(null),oe=n.useRef(null),ee=n.useRef(!1),le=n.useRef(null),ce=n.useRef(0),R=n.useRef(null),y=n.useRef(1),L=n.useRef({x:0,y:0}),h=n.useRef(!1),K=n.useRef($),z=n.useRef(G),me=n.useRef(Q),ye=n.useRef(I);n.useEffect(()=>{K.current=$},[$]),n.useEffect(()=>{z.current=G},[G]),n.useEffect(()=>{me.current=Q},[Q]),n.useEffect(()=>{X.current=t},[t]),n.useEffect(()=>{ye.current=I},[I]),n.useEffect(()=>{var B;(B=o.current)==null||B.focus()},[]);const de=a==="connected",ke=r,ve=de?"Connected. Waiting for first frame...":a==="connecting"?"Connecting to Host...":"Reconnecting to Host...",pe=de?"The remote stream is warming up":"Waiting for the remote stream to catch up";n.useEffect(()=>{if(!D||se.current||!ke)return;const B=u.current,re=x.current;if(!B||!re)return;const q=()=>{const ge=re.clientWidth,k=re.clientHeight,F=B.naturalWidth,ae=B.naturalHeight;if(!F||!ae||!ge||!k)return;const U=Math.min(ge/F,k/ae),Z=Math.max(ge/F,k/ae)/U;Z>1.01&&(j(Z),Y(Z),K.current=Z),se.current=!0};B.complete&&B.naturalWidth?q():B.addEventListener("load",q,{once:!0})},[ke,D]);const P=.5;n.useEffect(()=>{$<=P&&(g(0),xe(0))},[$,P]);const be=(B,re,q)=>{if(q<=P)return{x:0,y:0};const ge=(q-1)/(2*q)*100,k=(q-1)/(2*q)*100;return{x:Math.max(-ge,Math.min(ge,B)),y:Math.max(-k,Math.min(k,re))}},Ne=(B,re)=>{if(!u.current)return null;const q=u.current.getBoundingClientRect();return!q.width||!q.height?null:{nx:Math.max(0,Math.min(1,(B-q.left)/q.width)),ny:Math.max(0,Math.min(1,(re-q.top)/q.height))}},fe=(B,re,q)=>{const ge=x.current;if(!ge)return;const k=ge.getBoundingClientRect(),F=++A.current;E(ae=>[...ae,{id:F,x:B-k.left,y:re-k.top,type:q}]),setTimeout(()=>E(ae=>ae.filter(U=>U.id!==F)),600)},we=(B,re,q)=>{const ge=u.current,k=x.current;if(!ge||!k)return;const F=ge.getBoundingClientRect(),ae=k.getBoundingClientRect(),U=ge.naturalWidth||F.width,ie=ge.naturalHeight||F.height,Z=U/ie,J=F.width/F.height;let he,te,v,N;Z>J?(he=F.width,te=F.width/Z,v=0,N=(F.height-te)/2):(te=F.height,he=F.height*Z,v=(F.width-he)/2,N=0);const M=F.left-ae.left+v+he*B,T=F.top-ae.top+N+te*re,ne=++A.current;E(ue=>[...ue,{id:ne,x:M,y:T,type:q}]),setTimeout(()=>E(ue=>ue.filter(je=>je.id!==ne)),600)},Ve=async B=>{var q;const re=Ne(B.clientX,B.clientY);if(re){d(`Click: ${Math.round(re.nx*100)}%, ${Math.round(re.ny*100)}%`),fe(B.clientX,B.clientY,"left"),(q=o.current)==null||q.focus();try{const ge=await t("input_click",{nx:re.nx,ny:re.ny});ge!=null&&ge.success||s(`❌ Click failed: ${ge==null?void 0:ge.error}`)}catch(ge){s(`❌ Click error: ${ge.message||ge}`)}}},Ae=async(B,re,q,ge=0)=>{try{await t("input_key",{type:q?"char":"keyDown",key:B,code:re,text:q?B:void 0,unmodifiedText:q?B:void 0,modifiers:ge})}catch(k){s(`❌ Key error: ${k.message||k}`)}},Ue=async B=>{if(B.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(B.key)&&B.preventDefault();let q=0;B.altKey&&(q|=1),B.ctrlKey&&(q|=2),B.metaKey&&(q|=4),B.shiftKey&&(q|=8),d(`Key: ${B.key}`),await Ae(B.key,B.code,B.key.length===1,q)},Pe=async B=>{if(B.key==="Enter"){if(B.nativeEvent.isComposing)return;if(l){const re=l;w(""),d(`IME Sent: ${re}`);try{const q=await t("input_type",{text:re});q!=null&&q.success||s(`❌ IME error: ${q==null?void 0:q.error}`)}catch(q){s(`❌ IME error: ${q.message}`)}}else d("Key: Enter"),await Ae("Enter","Enter",!1)}};n.useEffect(()=>{const B=o.current;if(!B)return;const re=q=>{var ge;if((ge=u.current)!=null&&ge.contains(q.target)){q.preventDefault();const k=Date.now();if(k-V.current<40)return;V.current=k;const F=Ne(q.clientX,q.clientY);if(!F)return;d(`Scroll: ${Math.round(q.deltaY)}`),t("input_wheel",{nx:F.nx,ny:F.ny,deltaX:Math.round(q.deltaX),deltaY:Math.round(q.deltaY)}).catch(()=>{})}};return B.addEventListener("wheel",re,{passive:!1}),()=>B.removeEventListener("wheel",re)},[t]);const[Ce,Be]=n.useState(null),Me=n.useRef(null);return n.useEffect(()=>{if(I==="mouse"&&!Me.current){const B={nx:.5,ny:.5};Me.current=B,Be(B)}},[I]),n.useEffect(()=>{const B=o.current;if(!B)return;const re=U=>{if(!u.current)return null;const ie=u.current.getBoundingClientRect();return!ie.width||!ie.height?null:{nx:Math.max(0,Math.min(1,(U.clientX-ie.left)/ie.width)),ny:Math.max(0,Math.min(1,(U.clientY-ie.top)/ie.height))}},q=(U,ie)=>{if(!u.current)return{dnx:0,dny:0};const Z=u.current,J=Z.getBoundingClientRect(),he=Z.naturalWidth||J.width,te=Z.naturalHeight||J.height,v=he/te,N=J.width/J.height;let M,T;return v>N?(M=J.width,T=J.width/v):(T=J.height,M=J.height*v),{dnx:U/M,dny:ie/T}},ge=(U,ie,Z)=>{if(Z<=1.05)return;const J=-(U-.5)*100,he=-(ie-.5)*100,te=be(J,he,Z);(Math.abs(te.x-z.current)>.1||Math.abs(te.y-me.current)>.1)&&(g(te.x),xe(te.y),z.current=te.x,me.current=te.y)},k=U=>{const ie=x.current;if(ie&&U.target instanceof Node&&ie.contains(U.target))U.preventDefault();else return;if(U.touches.length===1){const Z=U.touches[0];O.current={x:Z.clientX,y:Z.clientY,time:Date.now()},oe.current={x:Z.clientX,y:Z.clientY},h.current||(ee.current=!1),le.current=setTimeout(()=>{if(!ee.current&&!h.current)if(ee.current=!0,ye.current==="mouse"){const J=Me.current||{nx:.5,ny:.5};d("Right Click"),we(J.nx,J.ny,"right"),X.current("input_click",{...J,button:"right"}).catch(()=>{})}else{const J=re(Z);J&&(d("Right Click"),we(J.nx,J.ny,"right"),X.current("input_click",{...J,button:"right"}).catch(()=>{}))}},500)}else if(U.touches.length===2){clearTimeout(le.current),ee.current=!0,h.current=!0;const Z=U.touches[1].clientX-U.touches[0].clientX,J=U.touches[1].clientY-U.touches[0].clientY;R.current=Math.sqrt(Z*Z+J*J),y.current=K.current,L.current={x:(U.touches[0].clientX+U.touches[1].clientX)/2,y:(U.touches[0].clientY+U.touches[1].clientY)/2}}},F=U=>{const ie=x.current;if(ie&&U.target instanceof Node&&ie.contains(U.target)&&U.preventDefault(),U.touches.length===1&&oe.current){const Z=U.touches[0],J=Z.clientX-oe.current.x,he=Z.clientY-oe.current.y;if(!ee.current&&O.current){const te=Z.clientX-O.current.x,v=Z.clientY-O.current.y;Math.sqrt(te*te+v*v)>8&&(ee.current=!0,clearTimeout(le.current))}if(ee.current)if(ye.current==="mouse"){const te=q(J,he),v=Me.current||{nx:.5,ny:.5},N=Math.max(0,Math.min(1,v.nx+te.dnx)),M=Math.max(0,Math.min(1,v.ny+te.dny));Me.current={nx:N,ny:M},Be({nx:N,ny:M}),d(`Cursor: ${Math.round(N*100)}%, ${Math.round(M*100)}%`),ge(N,M,K.current);const T=Date.now();T-V.current>=30&&(V.current=T,X.current("input_mouseMoved",{nx:N,ny:M}).catch(()=>{}))}else if(K.current>1){const te=x.current;if(te){const v=te.clientWidth,N=te.clientHeight,M=z.current+J/v*100,T=me.current+he/N*100,ne=be(M,T,K.current);g(ne.x),xe(ne.y),z.current=ne.x,me.current=ne.y}}else{const te=re(Z);if(te){const v=Date.now();v-V.current>=40&&(V.current=v,d("Scroll"),X.current("input_wheel",{nx:te.nx,ny:te.ny,deltaX:Math.round(-J*2.5),deltaY:Math.round(-he*2.5)}).catch(()=>{}))}}oe.current={x:Z.clientX,y:Z.clientY}}else if(U.touches.length===2&&R.current!==null){const Z=U.touches[1].clientX-U.touches[0].clientX,J=U.touches[1].clientY-U.touches[0].clientY,te=Math.sqrt(Z*Z+J*J)/R.current,v=(U.touches[0].clientX+U.touches[1].clientX)/2,N=(U.touches[0].clientY+U.touches[1].clientY)/2,M=v-L.current.x,T=N-L.current.y,ne=Math.abs(te-1)>.03;if(ye.current==="mouse"){if(ne){const ue=Math.max(P,Math.min(5,y.current*te));Y(ue),K.current=ue}else if(Math.abs(M)>2||Math.abs(T)>2){const ue=Me.current||{nx:.5,ny:.5},je=Date.now();je-V.current>=30&&(V.current=je,d("Scroll"),X.current("input_wheel",{nx:ue.nx,ny:ue.ny,deltaX:Math.round(-M*3),deltaY:Math.round(-T*3)}).catch(()=>{}))}}else{const ue=Math.max(P,Math.min(5,y.current*te));Y(ue),K.current=ue;const je=x.current;if(je&&ue>1){const Te=je.clientWidth,_e=je.clientHeight,st=z.current+M/Te*100,mt=me.current+T/_e*100,ze=be(st,mt,ue);g(ze.x),xe(ze.y),z.current=ze.x,me.current=ze.y}}L.current={x:v,y:N}}},ae=U=>{var ie;if(clearTimeout(le.current),R.current=null,U.touches.length===1&&h.current){const Z=U.touches[0];O.current={x:Z.clientX,y:Z.clientY,time:Date.now()},oe.current={x:Z.clientX,y:Z.clientY},ee.current=!0;return}if(U.touches.length===0){if(h.current){h.current=!1,ee.current=!1;return}if(U.changedTouches.length===1&&!ee.current){const Z=U.changedTouches[0],J=Date.now(),he=J-(((ie=O.current)==null?void 0:ie.time)||0);if(he<60||he>400){ee.current=!1;return}if(O.current){const te=Z.clientX-O.current.x,v=Z.clientY-O.current.y;if(Math.sqrt(te*te+v*v)>12){ee.current=!1;return}}if(ye.current==="mouse"){const te=Me.current||re(Z);te&&(d(`Click: ${Math.round(te.nx*100)}%, ${Math.round(te.ny*100)}%`),we(te.nx,te.ny,"left"),X.current("input_click",{...te}).catch(()=>{}))}else{const te=re(Z);if(!te)return;J-ce.current<300?(d("Double tap"),we(te.nx,te.ny,"double"),X.current("input_click",{...te,clickCount:2}).catch(()=>{}),ce.current=0):(d(`Tap: ${Math.round(te.nx*100)}%, ${Math.round(te.ny*100)}%`),we(te.nx,te.ny,"left"),X.current("input_click",{...te}).catch(()=>{}),ce.current=J)}}ee.current=!1}};return B.addEventListener("touchstart",k,{passive:!1}),B.addEventListener("touchmove",F,{passive:!1}),B.addEventListener("touchend",ae,{passive:!1}),()=>{B.removeEventListener("touchstart",k),B.removeEventListener("touchmove",F),B.removeEventListener("touchend",ae),clearTimeout(le.current)}},[]),e.jsxs("div",{ref:o,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:Ue,onContextMenu:B=>B.preventDefault(),onFocus:()=>f(!0),onBlur:()=>f(!1),tabIndex:0,children:[e.jsxs("div",{ref:x,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[ke?e.jsx("img",{ref:u,src:ke,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${$}) translate(${G}%, ${Q}%)`,transformOrigin:"center center",cursor:I==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:Ve,onContextMenu:B=>B.preventDefault(),onDragStart:B=>B.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:ve}),e.jsx("div",{className:"text-[11px] text-white/40",children:pe}),c==="relay"&&e.jsx("div",{className:"text-[10px] text-amber-300/80",children:"TURN relay active"})]}),I==="mouse"&&Ce&&ke&&u.current&&(()=>{var M;const B=u.current,re=B.getBoundingClientRect(),q=(M=x.current)==null?void 0:M.getBoundingClientRect();if(!q)return null;const ge=B.naturalWidth||re.width,k=B.naturalHeight||re.height,F=ge/k,ae=re.width/re.height;let U,ie,Z,J;F>ae?(U=re.width,ie=re.width/F,Z=0,J=(re.height-ie)/2):(ie=re.height,U=re.height*F,Z=(re.width-U)/2,J=0);const he=re.left-q.left+Z+U*Ce.nx,te=re.top-q.top+J+ie*Ce.ny,v=Math.max(8,Math.min(q.width-8,he)),N=Math.max(8,Math.min(q.height-8,te));return e.jsxs("div",{style:{position:"absolute",left:v-8,top:N-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(B=>{const q={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[B.type];return e.jsxs("div",{style:{position:"absolute",left:B.x,top:B.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}})]},B.id)})]}),e.jsxs("div",{onTouchStart:B=>B.stopPropagation(),className:"absolute bottom-0 left-0 right-0 z-20 flex items-center justify-center gap-1.5 px-3 py-2 bg-black/75 backdrop-blur-xl border-t border-white/[0.08] touch-none",children:[e.jsxs("div",{onClick:()=>{_(B=>{const re=B==="touch"?"mouse":"touch";if(re==="mouse"&&!Me.current){const q={nx:.5,ny:.5};Me.current=q,Be(q)}return re})},className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${I==="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:I==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${I==="mouse"?"text-blue-400":"text-slate-400"}`,children:I==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{H(!W),S(!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:B=>B.stopPropagation(),onChange:B=>w(B.target.value),onKeyDown:Pe,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:()=>{S(!b),H(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${b?"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:de?"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:de?"#22c55e":"#eab308",boxShadow:de?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:de?"#22c55e":"#eab308"},children:de?"Connected":"WS"})]}),$>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round($*100),"%"]}),c==="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"}),c==="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`}),p&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:p})]})]}),b&&e.jsxs("div",{onTouchStart:B=>B.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: ",$<=(D?C:1)+.01?D?"FILL":"FIT":`${Math.round($*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:B=>{B.stopPropagation(),Y(re=>Math.max(.5,re-.25))},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"−"}),e.jsx("button",{onClick:B=>{B.stopPropagation();const re=D?C:1;Y(re),K.current=re,g(0),xe(0)},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:9,fontWeight:800,cursor:"pointer"},children:D?"FILL":"FIT"}),e.jsx("button",{onClick:B=>{B.stopPropagation(),Y(re=>Math.min(5,re+.25))},style:{flex:1,background:"rgba(255,255,255,0.1)",color:"#fff",border:"none",padding:"6px",borderRadius:6,fontSize:12,fontWeight:800,cursor:"pointer"},children:"+"})]})]})]}),e.jsx("style",{children:`
10
- @keyframes slideUp {
11
- from { opacity: 0; transform: translateY(6px); }
12
- to { opacity: 1; transform: translateY(0); }
13
- }
14
- @keyframes slideUpSidebar {
15
- from { opacity: 0; transform: translateY(6px); }
16
- to { opacity: 1; transform: translateY(0); }
17
- }
18
- @keyframes click-ripple-ring {
19
- 0% { transform: scale(0.3); opacity: 1; }
20
- 100% { transform: scale(2.2); opacity: 0; }
21
- }
22
- @keyframes click-ripple-dot {
23
- 0% { transform: scale(1); opacity: 0.9; }
24
- 50% { transform: scale(1.8); opacity: 0.6; }
25
- 100% { transform: scale(0.5); opacity: 0; }
26
- }
27
- @keyframes remote-float {
28
- 0% { transform: translateY(0px); }
29
- 50% { transform: translateY(-7px); }
30
- 100% { transform: translateY(0px); }
31
- }
32
- `})]})}function dn({screenshotUrl:t,mode:s="preview",zoom:a=100,interactive:r=!1,connectionState:i,onDismiss:c,onClickAt:o,onKeyDown:x,badge:u,emptyMessage:p,aspectRatio:d,className:l,style:w}){const f=n.useRef(null),m=n.useCallback(E=>{if(!r||!o||!f.current)return;const A=f.current,b=A.getBoundingClientRect(),S=(E.clientX-b.left)/b.width*A.naturalWidth,W=(E.clientY-b.top)/b.height*A.naturalHeight;o(S,W,A.naturalWidth,A.naturalHeight)},[r,o]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${l||""}`,style:{aspectRatio:d||"16/9",...w},children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),c&&e.jsx("button",{onClick:c,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:`${r?"screenshot-interactive":""} ${l||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?x:void 0,style:w,children:[e.jsx("img",{ref:f,src:t,alt:"IDE Screenshot",onClick:r?m:void 0,className:"max-w-full max-h-full object-contain",style:{...r?{cursor:"crosshair"}:{},...a!==100?{transform:`scale(${a/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:w,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:p||"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 un({activeConv:t,onModalButton:s}){const[a,r]=n.useState(null);if(n.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const i=o=>{a||(r(o),s(o))},c=o=>o.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(ms,{size:14})," ",a?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((o,x)=>{const u=c(o).toLowerCase(),p=/^(run|approve|accept|yes|allow|always)/.test(u),d=/^(reject|deny|delete|remove|abort)/.test(u),l=a===o,w=a!==null;return e.jsx("button",{onClick:()=>i(o),disabled:w,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${p?"bg-white text-amber-700 font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${w&&!l?"opacity-40":"opacity-100"} ${w?"cursor-not-allowed":"cursor-pointer"}`,children:l?"⏳ ...":c(o)},x)})})]})]})}const Re=new Map;function xn({ideId:t,ideType:s,agentType:a,agentName:r,serverModel:i,serverMode:c,acpConfigOptions:o,acpModes:x}){var R;const{sendCommand:u}=Ge(),p=!!(o||x),d=`${t}:${a}`,l=Re.get(d),[w,f]=n.useState(!1),[m,E]=n.useState(!1),[A,b]=n.useState((l==null?void 0:l.models)||[]),[S,W]=n.useState((l==null?void 0:l.modes)||[]),H=y=>y?typeof y=="string"?y:typeof y=="object"?y.name||y.id||JSON.stringify(y):String(y):"",[D,I]=n.useState(H(i)),[_,C]=n.useState(H(c)),[j,se]=n.useState(!1),[$,Y]=n.useState(!1),G=n.useRef(0),g=y=>y.map(L=>typeof L=="string"?L:(L==null?void 0:L.name)||(L==null?void 0:L.id)||String(L));n.useEffect(()=>{if(o){const y=o.find(L=>L.category==="model");if(y){const L=g(y.options.map(K=>K.value));b(L),y.currentValue&&I(H(y.currentValue));const h=Re.get(d)||{models:[],modes:[]};Re.set(d,{...h,models:L})}}if(x&&x.length>0){const y=g(x.map(h=>h.id));W(y);const L=Re.get(d)||{models:[],modes:[]};Re.set(d,{...L,modes:y})}else if(o){const y=o.find(L=>L.category!=="model");if(y){const L=g(y.options.map(K=>K.value));W(L),y.currentValue&&C(H(y.currentValue));const h=Re.get(d)||{models:[],modes:[]};Re.set(d,{...h,modes:L})}}},[o,x,d]),n.useEffect(()=>{f(!1),E(!1),I(H(i)),C(H(c));const y=Re.get(d);y?(b(y.models),W(y.modes)):(b([]),W([]))},[t,a]),n.useEffect(()=>{i&&Date.now()>G.current&&I(H(i))},[i]),n.useEffect(()=>{c&&Date.now()>G.current&&C(H(c))},[c]);const Q=n.useCallback(async(y,L={})=>{const h={...L},K=t.split(":");return K.length>=3&&(K[1]==="ide"||K[1]==="cli"||K[1]==="acp")&&(h._targetInstance=K.slice(2).join(":"),h._targetType=K[1]),await u(t,y,h)},[t]),xe=async()=>{var y,L;if(A.length>0){f(!w);return}if(p){f(!0);return}se(!0);try{const h=await Q("list_extension_models",{agentType:a,ideType:s}),K=(h==null?void 0:h.models)||((y=h==null?void 0:h.result)==null?void 0:y.models)||[],z=g(K);b(z),h!=null&&h.current&&I(H(h.current)),(L=h==null?void 0:h.result)!=null&&L.current&&I(H(h.result.current));const me=Re.get(d)||{models:[],modes:[]};Re.set(d,{...me,models:z}),f(!0)}catch{}finally{se(!1)}},V=async()=>{var y,L;if(S.length>0){E(!m);return}if(p){E(!0);return}Y(!0);try{const h=await Q("list_extension_modes",{agentType:a,ideType:s}),K=(h==null?void 0:h.modes)||((y=h==null?void 0:h.result)==null?void 0:y.modes)||[],z=g(K);W(z),h!=null&&h.current&&C(H(h.current)),(L=h==null?void 0:h.result)!=null&&L.current&&C(H(h.result.current));const me=Re.get(d)||{models:[],modes:[]};Re.set(d,{...me,modes:z}),E(!0)}catch{}finally{Y(!1)}},X=async y=>{f(!1),I(y),G.current=Date.now()+5e3;try{p?await Q("change_model",{agentType:a,ideType:s,model:y}):await Q("set_extension_model",{agentType:a,ideType:s,model:y})}catch{}},O=p&&!(x&&x.length>0)&&(o==null?void 0:o.some(y=>y.category!=="model")),oe=O?(R=o==null?void 0:o.find(y=>y.category!=="model"))==null?void 0:R.configId:void 0,ee=async y=>{E(!1),C(y),G.current=Date.now()+5e3;try{p&&O&&oe?await Q("set_thought_level",{agentType:a,ideType:s,configId:oe,value:y}):p?await Q("set_mode",{agentType:a,ideType:s,mode:y}):await Q("set_extension_mode",{agentType:a,ideType:s,mode:y})}catch{}},ce={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"}[a]||"#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:ce},children:r}),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:w?`${ce}55`:"transparent",border:"1px solid",color:D?"var(--text-primary)":"var(--text-muted)"},onClick:xe,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),j?"...":D||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),w&&A.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"}),A.map(y=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:y===D?`${ce}18`:"transparent",color:y===D?ce:"var(--text-secondary)",fontWeight:y===D?600:400,borderLeft:y===D?`2px solid ${ce}`:"2px solid transparent"},onMouseEnter:L=>{L.currentTarget.style.background=`${ce}12`},onMouseLeave:L=>{L.currentTarget.style.background=y===D?`${ce}18`:"transparent"},onClick:()=>X(y),children:y},y))]})]})]}),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?`${ce}55`:"transparent",border:"1px solid",color:_?"var(--text-primary)":"var(--text-muted)"},onClick:V,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:O?"🧠":"⚡"}),$?"...":_||(O?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),m&&S.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>E(!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:O?"SELECT THINKING LEVEL":"SELECT MODE"}),S.map(y=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:y===_?`${ce}18`:"transparent",color:y===_?ce:"var(--text-secondary)",fontWeight:y===_?600:400,borderLeft:y===_?`2px solid ${ce}`:"2px solid transparent"},onMouseEnter:L=>{L.currentTarget.style.background=`${ce}12`},onMouseLeave:L=>{L.currentTarget.style.background=y===_?`${ce}18`:"transparent"},onClick:()=>ee(y),children:y},y))]})]})]})]})}const We=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),Oe=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function bs({activeConv:t,ides:s,agentInput:a,setAgentInput:r,handleSendChat:i,handleFocusAgent:c,isFocusingAgent:o,messageReceivedAt:x,actionLogs:u,userName:p}){const d=n.useRef(null),{sendCommand:l}=Ge(),w=n.useRef(new Map),f=n.useCallback(j=>(w.current.has(j)||w.current.set(j,{messages:[],offset:0,hasMore:!0,error:null}),w.current.get(j)),[]),m=n.useCallback((j,se)=>{const $=f(j);w.current.set(j,{...$,...se}),E(Y=>Y+1)},[f]),[,E]=n.useState(0),A=t.tabKey,b=f(A),S=b.messages,W=b.hasMore,H=b.error,[D,I]=n.useState(!1),_=n.useCallback(async()=>{var $,Y;if(D)return;const j=t.tabKey,se=f(j);I(!0),m(j,{error:null});try{const G=s.find(oe=>oe.id===t.ideId),g=(G==null?void 0:G.daemonId)||(($=t.ideId)==null?void 0:$.split(":")[0])||"";if(!g){m(j,{hasMore:!1});return}const Q=t.ideType||t.agentType||"",xe=(t.ideId||"").split(":"),V=xe.length>=3?xe.slice(2).join(":"):void 0,X=await l(g,"chat_history",{agentType:Q,offset:se.offset,limit:30,instanceId:V}),O=(X==null?void 0:X.result)??X;if(((Y=O.messages)==null?void 0:Y.length)>0){const oe=f(j);m(j,{messages:[...O.messages,...oe.messages],offset:oe.offset+O.messages.length,hasMore:!!O.hasMore})}else m(j,{hasMore:!!O.hasMore})}catch(G){const g=(G==null?void 0:G.message)||"";g.includes("P2P not available")||g.includes("channel not open")||g.includes("P2P not connected")||g.includes("timeout")?m(j,{error:"Connection not ready — tap to retry"}):m(j,{hasMore:!1,error:"Failed to load history"})}finally{I(!1)}},[D,s,t,l,f,m]),C=(()=>{const j=t.messages.map((Y,G)=>{const g=`${t.ideId}-${Y.id??`i-${G}`}`;return{...Y,receivedAt:Y.receivedAt||x[g]||0}});if(S.length===0)return j;const se=new Set(j.map(Y=>`${Y.role}:${(Y.content||"").slice(0,100)}`));return[...S.filter(Y=>!se.has(`${Y.role}:${(Y.content||"").slice(0,100)}`)),...j]})();return e.jsxs(e.Fragment,{children:[e.jsx(cn,{messages:C,actionLogs:u.filter(j=>j.ideId===t.tabKey).sort((j,se)=>j.timestamp-se.timestamp),agentName:t.agentName||t.displayPrimary||"Agent",userName:p,isCliMode:We(t)||Oe(t),isWorking:t.status==="working",contextKey:t.tabKey,onLoadMore:_,isLoadingMore:D,hasMoreHistory:W,loadError:H??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(ps,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:c,disabled:o,className:"btn btn-primary",children:o?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rt,{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(en,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:c,disabled:o,className:"btn btn-primary",children:o?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rt,{size:14})," Open ",t.displayPrimary," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Open the agent panel or chat view in the app you are using to start viewing messages"})]}):t.status==="idle"&&!D?e.jsxs("div",{className:"text-center mt-16 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"text-2xl opacity-40 animate-pulse",children:"💬"}),e.jsx("div",{className:"text-[13px] opacity-40",children:"Loading chat..."})]}):void 0:void 0}),!We(t)&&(()=>{var se,$,Y,G;const j=s.find(g=>g.id===t.ideId);return e.jsx(xn,{ideId:t.ideId,ideType:t.ideType,agentType:t.streamSource==="agent-stream"?t.agentType:(($=(se=j==null?void 0:j.agents)==null?void 0:se[0])==null?void 0:$.type)||t.ideType,agentName:t.streamSource==="agent-stream"?t.agentName:((G=(Y=j==null?void 0:j.agents)==null?void 0:Y[0])==null?void 0:G.name)||t.agentName,serverModel:(j==null?void 0:j.currentModel)||void 0,serverMode:(j==null?void 0:j.currentPlan)||void 0,acpConfigOptions:Oe(t)?j==null?void 0:j.acpConfigOptions:void 0,acpModes:Oe(t)?j==null?void 0:j.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:d,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:a,onChange:j=>r(j.target.value),onPaste:j=>{const se=j.clipboardData.getData("text");se&&r($=>$+se),j.preventDefault()},onKeyDown:j=>{if(j.key==="Enter"){if(j.nativeEvent.isComposing){j.preventDefault();return}j.preventDefault(),i()}},onBlur:j=>{if(window.innerWidth<768){const se=j.relatedTarget;if((se==null?void 0:se.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:i,disabled:!a.trim(),className:`w-10 h-10 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:"18",height:"18",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"})})})]})})]})}const St=new Set,ys={emit(t,s){for(const a of St)a(t,s)},on(t){return St.add(t),()=>{St.delete(t)}}};function mn({activeConv:t,ptyBuffers:s,terminalRef:a,agentInput:r,setAgentInput:i,handleSendChat:c}){var w;const o=n.useRef(null),{sendCommand:x,sendData:u}=Ge(),p=(w=t.ideId)!=null&&w.includes(":cli:")?t.ideId.split(":cli:")[1]:"",d=t.tabKey,l=t.ideType||t.agentType||"";return n.useEffect(()=>{const f=s.current.get(d);if(f&&f.length>0){const m=setTimeout(()=>{var E;for(const A of f)(E=a.current)==null||E.write(A);requestAnimationFrame(()=>{var A;(A=a.current)==null||A.bumpResize()})},100);return()=>clearTimeout(m)}},[d]),n.useEffect(()=>{const f=ys.on((m,E)=>{var b;if(!E)return;(m===p||m===l||m===t.ideId||m===t.tabKey)&&((b=a.current)==null||b.write(E))});return()=>{f()}},[p,l]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:e.jsx(gs,{ref:a,onInput:f=>{var A;const m=t.ideId||t.daemonId||"",E=(A=t.ideId)!=null&&A.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";u!=null&&u(m,{type:"pty_input",cliType:E,data:f})||x(m,"pty_input",{cliType:E,data:f}).catch(console.error)},onResize:(f,m)=>{var b;const E=t.ideId||t.daemonId||"",A=(b=t.ideId)!=null&&b.includes(":cli:")?t.ideId.split(":cli:")[1]:t.ideType||t.agentType||"";u!=null&&u(E,{type:"pty_resize",cliType:A,cols:f,rows:m})||x(E,"pty_resize",{cliType:A,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:o,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:r,onChange:f=>i(f.target.value),onPaste:f=>{const m=f.clipboardData.getData("text");m&&i(E=>E+m),f.preventDefault()},onKeyDown:f=>{if(f.key==="Enter"){if(f.nativeEvent.isComposing){f.preventDefault();return}f.preventDefault(),c()}},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:c,disabled:!r.trim(),className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${r.trim()?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:r.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:r.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function pn({wsStatus:t,showReconnected:s,loginUrl:a}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"violet",c={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))"},o={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",violet:"1px solid rgba(139,92,246,0.2)"},x={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:c[i],borderBottom:o[i],color:x[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(a?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:a,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 hn=ct;function Nt(){return hn()}class fn{constructor(){Ee(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,a){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(a),()=>{var r;(r=this.listeners.get(s))==null||r.delete(a)}}emit(s,...a){var r;(r=this.listeners.get(s))==null||r.forEach(i=>i(...a))}}let gn=new fn;class bn{constructor(){Ee(this,"ptyCallbacks",new Set)}sendPtyInput(s,a,r){return!1}sendPtyResize(s,a,r,i){return!1}async requestChatHistory(s,a,r,i,c){return{messages:[],hasMore:!1}}retryConnection(s){}getState(s){return"disconnected"}sendData(s,a){return!1}get(s){}onScreenshot(s,a){return()=>{}}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,a){this.ptyCallbacks.forEach(r=>r(s,a))}}let $e=new bn,yn=$e;const Ct=t=>(t.ideId||t.tabKey||t.id||"").includes(":cli:"),It=t=>(t.ideId||t.tabKey||t.id||"").includes(":acp:");function vn({activeConv:t,agentCount:s,wsStatus:a,isConnected:r,onOpenHistory:i}){const c=ut(),o=Nt(),x=o.p2pStates||{},u=o.ides||[],p=r?"#22c55e":a==="connected"?"#eab308":"#ef4444",d=r?"0 0 4px #22c55e80":a==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",l=u.filter(b=>b.type==="adhdev-daemon"),w=Object.values(x),f=w.filter(b=>b==="connected").length,m=w.filter(b=>b==="connecting"||b==="new"||b==="checking").length,A=a!=="connected"||l.length===0?null:m>0&&f===0?"P2P connecting...":f>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(jt,{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:p,boxShadow:d}})})]}),e.jsxs("div",{className:"header-subtitle text-xs items-center gap-1",children:[s," agent",s!==1?"s":""," active",e.jsx("span",{title:r?"Connected":a==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:p,boxShadow:d}}),A&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",A]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[t&&!Ct(t)&&!It(t)&&e.jsxs("button",{onClick:()=>c(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(hs,{size:14})," IDE"]}),t&&!Ct(t)&&!It(t)&&e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Js,{size:16})}),t&&!Ct(t)&&!It(t)&&e.jsx("button",{onClick:()=>c(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(xt,{size:16})})]})]})}function Le(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function jn(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const a=Math.floor(s/60),r=s%60;if(a<24)return r>0?`${a}h ${r}m`:`${a}h`;const i=Math.floor(a/24),c=a%24;return`${i}d ${c}h`}function Gt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Vt(t){return(t.id||"").includes(":cli:")}function Xt(t){return(t.id||"").includes(":acp:")}function Pt(t,s){return Le(t)}function wn(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,a=["generating","streaming","active","connected","idle","panel_hidden"];for(const r of t){const i=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),c=s.get(i);if(!c){s.set(i,r);continue}const o=a.indexOf(c.status||"idle"),x=a.indexOf(r.status||"idle");x>=0&&(o<0||x<o)&&s.set(i,r)}return Array.from(s.values())}function Nn({activeConv:t,ides:s,isCreatingChat:a,isRefreshingHistory:r,onClose:i,onNewChat:c,onSwitchSession:o,onRefreshHistory:x}){var l;const u=s.find(w=>w.id===t.ideId),p=(u==null?void 0:u.chats)||[],d=(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," — ",Le(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:c,disabled:a,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:a?"⌛ Creating...":"+ Start New Chat Session"}),p.map(w=>e.jsxs("div",{onClick:()=>{o(t.ideId,w.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===w.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 ${d===w.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:w.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:[w.id.substring(0,12),"..."]}),d===w.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},w.id)),p.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(an,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:x,disabled:r,className:"btn btn-secondary btn-sm rounded-[10px]",children:r?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Qs,{size:13})," Refresh History"]})})})]})]})}const qt={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function kn({toasts:t,onDismiss:s,onClickToast:a}){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(r=>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:qt[r.type]||qt.info},onClick:()=>{var i;(i=r.actions)!=null&&i.length||(a&&a(r),s(r.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(r.id)},"aria-label":"Dismiss",children:"×"}),e.jsx("div",{className:"pr-4",children:r.message}),r.actions&&r.actions.length>0&&e.jsx("div",{className:"flex gap-2 mt-2",children:r.actions.map((i,c)=>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:o=>{o.stopPropagation(),i.onClick(),s(r.id)},children:i.label},c))})]},r.id))})}const Sn=t=>(t.id||"").includes(":cli:")||(t.id||"").includes(":acp:")||(t.id||"").includes(":ide:")?!0:t.daemonId!==t.id;function Cn(t){const s=t.workspace||"";if(!s)return"";const a=s.split(/[/\\]/).filter(Boolean);return a.length>0?a[a.length-1]:s}function In(t,s,a,r){var c;const i={};if(a)for(const o of a){const x=o;if(x.type==="adhdev-daemon"||x.daemonMode){const u=x.machine||{},p=x.machineNickname,d=u.hostname||((c=x.system)==null?void 0:c.hostname)||"",l=p||(d&&d!=="Unknown"?d.replace(/\.local$/,""):null)||`Machine ${(x.id||"").substring(0,6)}`;i[x.id]=l}}return t.flatMap(o=>{var S,W,H,D,I;const x=[],u=o.daemonId&&i[o.daemonId]||void 0,p=o.daemonId||((S=o.id)==null?void 0:S.split(":")[0])||o.id,d=r?r[p]||"new":void 0,l=Cn(o),w=Le(o.type),f=o.agentStreams,m=Array.isArray(f)?f.map(_=>({..._,activeModal:_.activeModal??void 0})):[],E=Sn(o),A=o.activeChat||{title:""},b=A.title&&String(A.title).trim()?String(A.title).trim():"";if(E){const _=Pt(o.type),C=(W=o.agents)==null?void 0:W[0],j=(H=o.activeChat)==null?void 0:H.activeModal,se=j&&Array.isArray(j.buttons)&&j.buttons.length>0,$=(D=o.activeChat)==null?void 0:D.status,Y=$==="generating"||$==="loading"||$&&$.toLowerCase()==="thinking",g=se||$==="waiting_approval"?"waiting_approval":Y?"working":(C==null?void 0:C.status)||"idle",Q=o.activeChat||{title:"",messages:[]};let xe=Q.title&&String(Q.title).trim()?String(Q.title).trim():"";const V=(I=o.activeChat)==null?void 0:I.id,X=o.chats;if(V&&Array.isArray(X)&&X.length>0){const ce=X.find(R=>R.id===V||R.id&&String(R.id)===String(V));ce!=null&&ce.title&&String(ce.title).trim()&&(xe=String(ce.title).trim())}const O=Q.messages||[],oe=s[o.id]||[],ee=new Map;O.filter(ce=>ce.role==="user").forEach(ce=>{ee.set(ce.content,(ee.get(ce.content)||0)+1)});const le=oe.filter(ce=>{const R=ee.get(ce.content)||0;return R>0?(ee.set(ce.content,R-1),!1):!0});x.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:We(o)?o.mode||"terminal":"chat",agentName:_,agentType:We(o)||Oe(o)?o.cliType||o.acpType||o.type:(C==null?void 0:C.type)||"ide-native",status:g,title:xe,messages:[...O,...le],ideType:o.cliType||o.acpType||o.type,workspaceName:l,displayPrimary:xe||l||(We(o)||Oe(o)?"Terminal":_),displaySecondary:w,cdpConnected:o.cdpConnected,modalButtons:se?j.buttons:void 0,modalMessage:se?j.message:void 0,streamSource:"native",tabKey:o.id,machineName:u,connectionState:d})}if(E&&(We(o)||Oe(o)))return x;for(const _ of m){const C=_.activeModal&&Array.isArray(_.activeModal.buttons)&&_.activeModal.buttons.length>0,j=C?"waiting_approval":_.status==="streaming"?"working":_.status,se=`${o.id}:${_.agentType}`,$=_.messages||[],Y=s[se]||[],G=new Map;$.filter(Q=>Q.role==="user").forEach(Q=>{G.set(Q.content,(G.get(Q.content)||0)+1)});const g=Y.filter(Q=>{const xe=G.get(Q.content)||0;return xe>0?(G.set(Q.content,xe-1),!1):!0});x.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:"chat",agentName:_.agentName,agentType:_.agentType,status:j,title:"",messages:[...$,...g],ideType:_.agentType,workspaceName:l,displayPrimary:b||l||_.agentName,displaySecondary:`${w}·${_.agentName}`,cdpConnected:o.cdpConnected,modalButtons:C?_.activeModal.buttons:void 0,modalMessage:C?_.activeModal.message:void 0,streamSource:"agent-stream",tabKey:se,machineName:u,connectionState:d})}return x.length===0&&x.push({ideId:o.id,daemonId:o.daemonId||void 0,mode:"chat",agentName:Pt(o.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:o.type,workspaceName:l,displayPrimary:l||w,displaySecondary:w,cdpConnected:o.cdpConnected,streamSource:"native",tabKey:o.id,connectionState:d}),x})}function Mn(t,s){var x,u,p,d;const a=[],{daemonId:r,existingDaemon:i,timestamp:c}=s,o=c||t.timestamp||Date.now();a.push({...i||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:o,...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=>`${r}:ide:${l.instanceId}`),managedCliIds:t.managedClis.map(l=>l.id?`${r}:cli:${l.id}`:`${r}:cli:${l.cliType}`),managedAcpIds:t.managedAcps.map(l=>l.id?`${r}:acp:${l.id}`:`${r}:acp:${l.acpType}`)});for(const l of t.managedIdes)a.push({id:`${r}:ide:${l.instanceId}`,type:l.ideType,ideType:l.ideType,version:l.ideVersion,status:l.cdpConnected?"online":"detected",daemonId:r,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:o});for(const l of t.managedClis){const w=l.id?`${r}:cli:${l.id}`:`${r}:cli:${l.cliType}`;a.push({id:w,type:l.cliType,ideType:l.cliType,agentType:l.cliType,status:l.status||"running",daemonId:r,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:((x=l.activeChat)==null?void 0:x.messages)||[],inputContent:"",activeModal:(u=l.activeChat)==null?void 0:u.activeModal}],timestamp:o,_isCli:!0})}for(const l of t.managedAcps){const w=l.id?`${r}:acp:${l.id}`:`${r}:acp:${l.acpType}`;a.push({id:w,type:l.acpType,ideType:l.acpType,agentType:l.acpType,status:l.status||"running",daemonId:r,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:((p=l.activeChat)==null?void 0:p.messages)||[],inputContent:"",activeModal:(d=l.activeChat)==null?void 0:d.activeModal}],timestamp:o,_isAcp:!0})}return a}const vs="adhdev_notification_prefs",Jt={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0};function Tn(){try{const t=localStorage.getItem(vs);if(t){const s=JSON.parse(t);return{...Jt,...s}}}catch{}return{...Jt}}function En(t){try{localStorage.setItem(vs,JSON.stringify(t))}catch{}}let He=Tn(),gt=[];function $n(){gt.forEach(t=>t())}function An(t){He={...He,...t},En(He),$n()}function _n(){const[,t]=n.useState(0);n.useEffect(()=>{const a=()=>t(r=>r+1);return gt.push(a),()=>{gt=gt.filter(r=>r!==a)}},[]);const s=n.useCallback(a=>{An(a)},[]);return[{...He},s]}function at(t){if(!He.globalEnabled)return!1;switch(t){case"disconnect":return He.disconnectAlert;case"completion":return He.completionAlert;case"approval":return He.approvalAlert;case"browser":return He.browserNotifications;default:return!0}}const Rn={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function Pn(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function js(){return"Notification"in window&&Notification.permission==="granted"}let Xe=null;async function Ln(){if(Xe!==null)return Xe;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Xe=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Xe=!!await t.pushManager.getSubscription(),Xe):(Xe=!1,!1)}catch{return Xe=!1,!1}}function Lt(t,s,a){if(js())try{const r=new Notification(t,{body:s,icon:"/otter-logo.png",tag:a||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>r.close(),8e3),r.onclick=()=>{window.focus(),r.close()}}catch{}}function Dn(t,s={}){const a={...Rn,...s},r=n.useRef(new Map),i=n.useRef(0),c=n.useRef(null);n.useEffect(()=>{Ln().then(x=>{c.current=x})},[]);const o=n.useCallback((x,u,p)=>{const d=Date.now();d-i.current<a.throttleMs||(i.current=d,Lt(x,u,p))},[a.throttleMs]);n.useEffect(()=>{var x;if(!(!a.enabled||!js())&&at("browser")&&c.current!==!0){if(document.hasFocus()){for(const u of t)r.current.set(u.id,u.status||"idle");return}for(const u of t){const p=r.current.get(u.id),d=u.status||"idle",l=u.name||u.id;if(a.onApproval&&at("approval")&&d==="waiting_approval"&&p!=="waiting_approval"){const w=((x=u.activeModal)==null?void 0:x.message)||"Action requires your approval";o(`🔔 ${l} — Approval needed`,w.slice(0,120),`approval-${u.id}`)}a.onComplete&&at("completion")&&p==="generating"&&d==="idle"&&o(`✅ ${l} — Task complete`,"Agent has finished working",`complete-${u.id}`),a.onError&&d==="error"&&p!=="error"&&o(`⚠️ ${l} — Error`,"Agent encountered an error",`error-${u.id}`),r.current.set(u.id,d)}}},[t,a.enabled,a.onApproval,a.onComplete,a.onError,o])}class Bn{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(a=>a!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(a=>a!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(a=>a!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const a of this.toastCallbacks)a(s)}emitSystemMessage(s,a){for(const r of this.systemMessageCallbacks)r(s,a)}emitClearSystemMessage(s,a){for(const r of this.clearSystemMessageCallbacks)r(s,a)}isDuplicate(s){const a=Date.now(),r=this.dedupMap.get(s)||0;if(a-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,a),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,c]of this.dedupMap)a-c>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(c=>c.id===s.ideId&&c.type==="adhdev-daemon");if(i)return i}let a;if(s.ideId&&(a=this.ides.find(i=>i.id===s.ideId)),!a&&s.instanceId&&(a=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),a){const i=a.daemonId;if(i){const c=this.ides.find(o=>o.id===i&&o.type==="adhdev-daemon");if(c)return c}}const r=this.ides.filter(i=>i.type==="adhdev-daemon");return r.length===1?r[0]:null}resolveRouteId(s,a){for(const r of this.ides)if(r.id.startsWith(s)&&(!a||a===r.type))return r.id;return s}handleRawEvent(s,a){var u,p,d;const r=`${s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(r))return;if(!s.ideId&&s.instanceId){for(const l of this.ides)if(l.id.endsWith(`:ide:${s.instanceId}`)||l.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=l.id;break}}let i=Le(s.ideType||"");const c=this.resolveOwningDaemon(s);if(c){const l=c.machineNickname||((u=c.machine)==null?void 0:u.hostname);l&&(i=s.ideType==="adhdev-daemon"?l:`${l}/${i}`)}let o="",x="info";if(s.event==="agent:generating_completed"){const l=s.duration?` (${s.duration}s)`:"";o=`✅ ${i} agent task completed${l}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}s.ideId&&this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`✅ Task completed${l}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")s.ideId&&this.emitClearSystemMessage(s.ideId,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(o=`⚡ ${i} approval needed`,x="warning",s.ideId){const l=s.modalMessage||"Approval requested",w=(p=s.modalButtons)!=null&&p.length?s.modalButtons.map(f=>`[${f}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(s.ideId,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${l}
39
- ${w}`,_localId:`sys_approval_${Date.now()}`})}if(s.ideId&&((d=s.modalButtons)!=null&&d.length)&&this.resolveActionFn){const l=s.ideId,w=s.agentType||s.ideType||"",f=s.ideType||"",m=s.modalButtons,E=H=>H.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),A=this.resolveActionFn,b=m.map((H,D)=>{const I=E(H).toLowerCase(),_=/^(run|approve|accept|yes|allow|always)/.test(I),C=/^(reject|deny|delete|remove|abort|cancel|no)/.test(I);return{label:E(H),variant:_?"primary":C?"danger":"default",onClick:()=>{const j=this.resolveRouteId(l,w),se=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(I);A(j,"resolve_action",{action:se?"approve":"reject",button:H,buttonIndex:D,agentType:w,ideType:f})}}}),S=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:o,W=Date.now();this.emitToast({id:W,message:S,type:x,timestamp:W,ideId:l,actions:b,duration:15e3}),o=""}}else if(s.event==="monitor:long_generating"){const l=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";o=`⚠️ ${i} agent is taking a long time${l}`,x="warning",at("browser")&&!document.hasFocus()&&Lt(`⚠️ ${i} — Long Running`,`Agent has been generating for over ${l.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const l=s.requesterName||"A team member",w=s.requestId,f=s.orgId;if(o=`👁️ ${l} wants to view your session`,x="warning",w&&f&&this.viewRequestRespondFn){const m=this.viewRequestRespondFn,E=Date.now(),A=[{label:"Approve",variant:"primary",onClick:()=>{m(f,w,"approve").catch(b=>console.error("[EventManager] approve view request failed:",b))}},{label:"Decline",variant:"danger",onClick:()=>{m(f,w,"reject").catch(b=>console.error("[EventManager] reject view request failed:",b))}}];this.emitToast({id:E,message:o,type:x,timestamp:E,actions:A,duration:3e4}),o=""}at("browser")&&!document.hasFocus()&&Lt("👁️ View Request",`${l} wants to view your session`,`view-request-${w}`)}else s.event==="team:view_request_approved"?(o="✅ View request approved",x="success"):s.event==="team:view_request_rejected"&&(o=`❌ ${s.targetName||"Team member"} declined your view request`,x="warning");if(o){const l=Date.now();this.emitToast({id:l,message:o,type:x,timestamp:l,ideId:s.ideId,duration:5e3})}}}const Qe=new Bn;function lt(...t){return Es($s(t))}function Wn({icon:t,title:s,subtitle:a,badge:r,actions:i,className:c}){return e.jsxs("div",{className:lt("dashboard-header",c),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,r&&e.jsxs("span",{className:"text-[10px] font-semibold px-1.5 py-px rounded-full bg-accent/10 text-accent-light",children:[r.count!==void 0?r.count:""," ",r.text]})]}),a&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:a})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function et({title:t,icon:s,description:a,accentColor:r,className:i,children:c}){return e.jsxs("div",{className:lt("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||a)&&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]}),a&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:a})]}),c]})}function On({icon:t,title:s,description:a,action:r,className:i}){return e.jsxs("div",{className:lt("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:a}),r]})}const Kn={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"},Fn={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Hn({status:t,label:s,className:a}){const r=s||t;return e.jsxs("span",{className:lt("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Kn[t],a),children:[e.jsx("span",{className:lt("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Fn[t])}),r]})}function Un(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Zt(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function Mt(t){return t==="system"?Un():t}function zn(){const[t,s]=n.useState(Zt),[a,r]=n.useState(()=>Mt(Zt()));n.useEffect(()=>{document.documentElement.setAttribute("data-theme",a)},[a]),n.useEffect(()=>{const o=window.matchMedia("(prefers-color-scheme: light)"),x=u=>{t==="system"&&r(u.matches?"light":"dark")};return o.addEventListener("change",x),()=>o.removeEventListener("change",x)},[t]);const i=n.useCallback(o=>{s(o),r(Mt(o));try{localStorage.setItem("theme",o)}catch{}},[]),c=n.useCallback(()=>{s(o=>{const x=o==="dark"?"light":o==="light"?"system":"dark";r(Mt(x));try{localStorage.setItem("theme",x)}catch{}return x})},[]);return{theme:a,preference:t,setPreference:i,cycleTheme:c,isDark:a==="dark"}}function tt({label:t,description:s,checked:a,disabled:r,onChange:i,extra:c}){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:[c,e.jsx("input",{type:"checkbox",checked:a,disabled:r,onChange:o=>i(o.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function Yn({onPrefChange:t}){const[s,a]=_n(),r=(i,c)=>{a({[i]:c}),t==null||t(i,c)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(tt,{label:"🔔 Notifications",description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:i=>r("globalEnabled",i)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(tt,{label:"🖥️ Browser Notifications",description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>r("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(tt,{label:"✅ Completion Alerts",description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(tt,{label:"⚡ Approval Alerts",description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(tt,{label:"📡 Connection Alerts",description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("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 Gn({ides:t,emptyMessage:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){const c=t.filter(o=>o.type==="adhdev-daemon");return c.length===0?e.jsx(On,{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 setup' once, then 'adhdev daemon' to connect this machine."}):e.jsx("div",{className:"flex flex-col gap-2",children:c.map(o=>e.jsx(qn,{ide:o,allIdes:t,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i},o.id))})}function Qt({title:t,message:s,confirmLabel:a,confirmColor:r,onConfirm:i,onCancel:c}){const o=r==="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 As.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:c,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:x=>x.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:c,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 ${o}`,children:a})]})]})}),document.body)}const Vn={vscode:{icon:"💠",name:"VS Code"},cursor:{icon:"⚡",name:"Cursor"},windsurf:{icon:"🏄",name:"Windsurf"},codex:{icon:"🤖",name:"Codex"},"claude-code":{icon:"🟠",name:"Claude Code"},aider:{icon:"🔧",name:"Aider"}};function Xn(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase();return Vn[s]||{icon:"📝",name:t}}function qn({ide:t,allIdes:s,sendDaemonCommand:a,onDisconnect:r,onRevokeToken:i}){var Q,xe,V,X;const[c,o]=n.useState("idle"),[x,u]=n.useState(""),[p,d]=n.useState(null),[l,w]=n.useState("idle"),[f,m]=n.useState(""),E=t,A=E.version||E.daemonVersion||null,b=((Q=E.machine)==null?void 0:Q.hostname)||((xe=E.system)==null?void 0:xe.hostname)||"",S=((V=E.machine)==null?void 0:V.platform)||((X=E.system)==null?void 0:X.platform)||"",W=E.machineNickname||(b==null?void 0:b.replace(/\.local$/,""))||"Machine",H=S==="win32"?"🪟":S==="darwin"?"🍎":"🐧",D=s.filter(O=>O.daemonId===t.id&&O.id.includes(":ide:")),I=s.filter(O=>O.daemonId===t.id&&O.id.includes(":cli:")),_=s.filter(O=>O.daemonId===t.id&&O.id.includes(":acp:")),C=E.p2p,j=async()=>{var O,oe,ee;if(a){o("upgrading"),u("Installing latest version...");try{const le=await a(t.id,"daemon_upgrade",{});(O=le==null?void 0:le.result)!=null&&O.upgraded||(oe=le==null?void 0:le.result)!=null&&oe.success?(o("done"),u(`Upgraded to v${le.result.version||"latest"}. Daemon is restarting...`)):(o("error"),u(((ee=le==null?void 0:le.result)==null?void 0:ee.error)||"Upgrade failed"))}catch(le){o("error"),u((le==null?void 0:le.message)||"Connection lost during upgrade")}}},se=async()=>{if(d(null),!!r){w("loading");try{await r(t.id),w("done"),m("Machine disconnected.")}catch(O){w("error"),m((O==null?void 0:O.message)||"Failed to disconnect")}}},$=async()=>{if(d(null),!!i){w("loading");try{await i(t.id),w("done"),m('Token revoked. Machine must run "adhdev setup" to reconnect.')}catch(O){w("error"),m((O==null?void 0:O.message)||"Failed to revoke token")}}},Y="0.6.61",G=!A||A!==Y,g=D.length+I.length+_.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:H}),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),"…"]}),A&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${G?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",A,!G&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[a&&G&&e.jsx("button",{onClick:j,disabled:c==="upgrading"||c==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${Y}`,children:c==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):c==="done"?"✓ Updated":`↑ Update${` to v${Y}`}`}),r&&e.jsx("button",{onClick:()=>d("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:()=>d("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(Hn,{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:[C&&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 ${C.state==="connected"?"bg-green-400":C.state==="connecting"||C.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",C.state==="connected"?"connected":C.state==="connecting"||C.state==="new"?"connecting...":C.state||"off"]}),C.peers!==void 0&&C.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",C.peers," peer",C.peers!==1?"s":"",")"]})]}),C&&g>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),g>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[D.map(O=>{const oe=Xn(O.type),ee=O.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:oe.icon}),e.jsx("span",{children:oe.name}),ee!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${ee?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:ee?"CDP connected":"CDP connecting..."})]},O.id)}),I.map(O=>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:O.cliName||"CLI"})]},O.id)),_.map(O=>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:O.cliName||"ACP"})]},O.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(x||f)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${c==="error"||l==="error"?"text-red-400":c==="done"||l==="done"?"text-green-400":"text-text-muted"}`,children:f||x})]}),p==="disconnect"&&e.jsx(Qt,{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:se,onCancel:()=>d(null)}),p==="revoke"&&e.jsx(Qt,{title:"⚠️ Remove Machine",message:`Remove "${W}" from your account?
44
-
45
- This will:
46
- • Immediately disconnect the machine
47
- • Delete the machine registration
48
- • Require running "adhdev setup" again on that machine
49
-
50
- Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:$,onCancel:()=>d(null)})]})}const Jn=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Zn(){const{preference:t,setPreference:s}=zn();return e.jsx("div",{className:"flex gap-2",children:Jn.map(a=>e.jsxs("button",{onClick:()=>s(a.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===a.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:a.icon}),a.label]},a.id))})}const Dt={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},Bt={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},Qn=[{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"}}}],ws="adhdev-chat-theme",Ns="adhdev-chat-theme-custom";function bt(){return typeof window>"u"?"midnight":localStorage.getItem(ws)||"midnight"}function De(t){try{const s=localStorage.getItem(Ns);if(s){const a=JSON.parse(s);return{...t==="dark"?Dt:Bt,...a[t]}}}catch{}return t==="dark"?Dt:Bt}function ht(t,s){localStorage.setItem(Ns,JSON.stringify({dark:t,light:s}))}function Ke(t,s){const a=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${a}, ${r}, ${i}, ${s})`}function es(t,s){const a=Math.min(255,parseInt(t.slice(1,3),16)+s),r=Math.min(255,parseInt(t.slice(3,5),16)+s),i=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${a.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}function Ze(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ke(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ke(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ke(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",Ke(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ke(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",es(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${es(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ke(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ke(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ke(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 ${Ke(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 er(){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(a=>t.style.removeProperty(a))}function tr(t){if(localStorage.setItem(ws,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ot()?"dark":"light";Ze(De(s))}else er()}function sr(){const t=bt();if(t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ot()?"dark":"light";Ze(De(s))}}function ot(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Ie({label:t,value:s,onChange:a}){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:r=>a(r.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:r=>{/^#[0-9a-fA-F]{0,6}$/.test(r.target.value)&&a(r.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 nt({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 nr({dark:t,onColorsChange:s}){const a=t?"dark":"light",[r,i]=n.useState(()=>De(a));n.useEffect(()=>{i(De(a))},[a]);const c=n.useCallback((o,x)=>{i(u=>{const p={...u,[o]:x},l=De(a==="dark"?"light":"dark");return a==="dark"?ht(p,l):ht(l,p),Ze(p),s(p),p})},[a,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(nt,{title:"App Background",children:[e.jsx(Ie,{label:"Background",value:r.bgPrimary,onChange:o=>c("bgPrimary",o)}),e.jsx(Ie,{label:"Surface",value:r.bgSecondary,onChange:o=>c("bgSecondary",o)}),e.jsx(Ie,{label:"Card",value:r.surfacePrimary,onChange:o=>c("surfacePrimary",o)})]}),e.jsxs(nt,{title:"App Text",children:[e.jsx(Ie,{label:"Primary",value:r.textPrimary,onChange:o=>c("textPrimary",o)}),e.jsx(Ie,{label:"Secondary",value:r.textSecondary,onChange:o=>c("textSecondary",o)}),e.jsx(Ie,{label:"Muted",value:r.textMuted,onChange:o=>c("textMuted",o)})]}),e.jsxs(nt,{title:"Borders & Accent",children:[e.jsx(Ie,{label:"Border subtle",value:r.borderSubtle,onChange:o=>c("borderSubtle",o)}),e.jsx(Ie,{label:"Border default",value:r.borderDefault,onChange:o=>c("borderDefault",o)}),e.jsx(Ie,{label:"Accent",value:r.accentColor,onChange:o=>c("accentColor",o)})]})]}),e.jsxs("div",{children:[e.jsxs(nt,{title:"Chat Bubbles",children:[e.jsx(Ie,{label:"User bubble",value:r.userBubble,onChange:o=>c("userBubble",o)}),e.jsx(Ie,{label:"User text",value:r.userText,onChange:o=>c("userText",o)}),e.jsx(Ie,{label:"Agent bubble",value:r.assistantBubble,onChange:o=>c("assistantBubble",o)}),e.jsx(Ie,{label:"Agent text",value:r.assistantText,onChange:o=>c("assistantText",o)})]}),e.jsxs(nt,{title:"Chat Layout",children:[e.jsx(Ie,{label:"Chat BG",value:r.containerBg,onChange:o=>c("containerBg",o)}),e.jsx(Ie,{label:"Send button",value:r.sendButton,onChange:o=>c("sendButton",o)}),e.jsx(Ie,{label:"Input border",value:r.inputBorder,onChange:o=>c("inputBorder",o)}),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:r.bubbleRadius,onChange:o=>c("bubbleRadius",Number(o.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:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const o=t?Dt:Bt,u=De(t?"light":"dark");t?ht(o,u):ht(u,o),i(o),Ze(o),s(o)},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 rr(){const[t,s]=n.useState(bt),[a,r]=n.useState(!0),[i,c]=n.useState(()=>De("dark"));n.useEffect(()=>{r(ot());const u=new MutationObserver(()=>{const l=ot();r(l),bt()==="custom"&&Ze(De(l?"dark":"light"))});u.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const p=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const l=ot();r(l),bt()==="custom"&&Ze(De(l?"dark":"light"))};return p.addEventListener("change",d),()=>{u.disconnect(),p.removeEventListener("change",d)}},[]),n.useEffect(()=>{t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"&&Ze(De(a?"dark":"light"))},[]),n.useEffect(()=>{c(De(a?"dark":"light"))},[a]);const o=u=>{s(u),tr(u),u==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},x=[...Qn,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:x.map(u=>{const p=t===u.id,d=a?u.preview.dark:u.preview.light,l=u.id==="honey"?"#1a1a1a":u.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>o(u.id),className:"text-left rounded-xl p-3 transition-all",style:{background:p?"var(--bg-glass-hover)":"var(--bg-glass)",border:p?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:p?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:d.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.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:d.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:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[p&&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(nr,{dark:a,onColorsChange:u=>c(u)})]})}const Wt="adhdev-accent-color",ar=[{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"}],dt="#8b5cf6";function or(t){const s=parseInt(t.slice(1,3),16)/255,a=parseInt(t.slice(3,5),16)/255,r=parseInt(t.slice(5,7),16)/255,i=Math.max(s,a,r),c=Math.min(s,a,r);let o=0,x=0;const u=(i+c)/2;if(i!==c){const p=i-c;switch(x=u>.5?p/(2-i-c):p/(i+c),i){case s:o=((a-r)/p+(a<r?6:0))/6;break;case a:o=((r-s)/p+2)/6;break;case r:o=((s-a)/p+4)/6;break}}return{h:Math.round(o*360),s:Math.round(x*100),l:Math.round(u*100)}}function ts(t,s){const{h:a,s:r,l:i}=or(t),c=Math.min(100,i+s);return`hsl(${a}, ${r}%, ${c}%)`}function yt(t,s){const a=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${a}, ${r}, ${i}, ${s})`}function ss(){return typeof window>"u"?dt:localStorage.getItem(Wt)||dt}function ir(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",ts(t,15)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${ts(t,20)})`),s.style.setProperty("--border-accent",yt(t,.4)),s.style.setProperty("--nav-active-bg",yt(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${yt(t,.06)}`)}function cr(){const t=document.documentElement;["--accent-primary","--accent-primary-light","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow"].forEach(a=>t.style.removeProperty(a))}function lr(t){t===dt?(localStorage.removeItem(Wt),cr()):(localStorage.setItem(Wt,t),ir(t))}function dr(){const[t,s]=n.useState(ss),[a,r]=n.useState("");n.useEffect(()=>{s(ss())},[]);const i=c=>{s(c),lr(c)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:ar.map(c=>{const o=t===c.color;return e.jsx("button",{onClick:()=>i(c.color),title:c.name,style:{width:36,height:36,borderRadius:10,background:c.color,border:o?"3px solid var(--text-primary)":"3px solid transparent",cursor:"pointer",position:"relative",transition:"transform 0.15s, border-color 0.15s",transform:o?"scale(1.1)":"scale(1)",boxShadow:o?`0 0 12px ${yt(c.color,.4)}`:"none"},children:o&&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:"✓"})},c.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:c=>i(c.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:a||t,onChange:c=>{r(c.target.value),/^#[0-9a-fA-F]{6}$/.test(c.target.value)&&i(c.target.value)},onBlur:()=>r(""),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!==dt&&e.jsx("button",{onClick:()=>i(dt),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 ks="adhdev_hiddenTabs";function ur(){try{const t=localStorage.getItem(ks);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function rt(t){try{localStorage.setItem(ks,JSON.stringify([...t]))}catch{}}function xr(){const[t,s]=n.useState(ur),a=n.useCallback(u=>{s(p=>{const d=new Set(p);return d.has(u)?d.delete(u):d.add(u),rt(d),d})},[]),r=n.useCallback(u=>{s(p=>{if(p.has(u))return p;const d=new Set(p);return d.add(u),rt(d),d})},[]),i=n.useCallback(u=>{s(p=>{if(!p.has(u))return p;const d=new Set(p);return d.delete(u),rt(d),d})},[]),c=n.useCallback((u,p)=>{s(d=>{const l=new Set(d);for(const w of p)l.add(w);return rt(l),l})},[]),o=n.useCallback((u,p)=>{s(d=>{const l=new Set(d);for(const w of p)l.delete(w);return rt(l),l})},[]),x=n.useCallback(u=>t.has(u),[t]);return{hiddenTabs:t,toggleTab:a,hideTab:r,showTab:i,hideAllForDaemon:c,showAllForDaemon:o,isHidden:x}}function Ss({sendDaemonCommand:t,activeConv:s,ides:a,updateIdeChats:r,setToasts:i,setLocalUserMessages:c,setClearedTabs:o,setActionLogs:x,pinTab:u,isStandalone:p}){const[d,l]=n.useState(""),[w,f]=n.useState(!1),[m,E]=n.useState(!1),[A,b]=n.useState(!1),S=n.useCallback($=>$?We($)||Oe($)?{agentType:$.agentType||$.ideType}:$.streamSource==="agent-stream"?{agentType:$.agentType}:{}:{},[]),W=n.useCallback(async()=>{if(!s)return;const $=d.trim();if(!$)return;const Y=s.ideId,G=s.tabKey;l(""),u(G,[100,500,1500,3e3]);const g=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,Q={role:"user",content:$,timestamp:Date.now(),_localId:g};c(xe=>({...xe,[G]:[...xe[G]||[],Q]}));try{const xe=Y||s.daemonId||"";if(!xe)return;await t(xe,"send_chat",{message:$,text:$,...S(s)}),setTimeout(()=>{const V=Date.now()-6e4;c(X=>{const O=X[G];if(!O)return X;const oe=O.filter(ee=>ee.timestamp>V);return oe.length===O.length?X:{...X,[G]:oe}})},6e4)}catch(xe){console.error("Send failed",xe),l($),c(V=>({...V,[G]:(V[G]||[]).filter(X=>X._localId!==g)}))}},[s,d,t,c,u,S]),H=n.useCallback(async()=>{if(s)try{p?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($){console.error("Relaunch failed",$)}},[s,p,t]),D=n.useCallback(async $=>{try{await t("standalone","launch_ide",{ideType:$,enableCdp:!0})}catch(Y){console.error("Launch failed",Y)}},[t]),I=n.useCallback(async $=>{if(s){console.log("[ModalButton] ideId:",s.ideId,"button:",$),x(Y=>[...Y,{ideId:s.tabKey,text:`🖱️ **${$}** clicked`,timestamp:Date.now()}]);try{const G=(s.modalButtons||[]).indexOf($),g=$.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),Q=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(g),xe=s.ideId||s.daemonId||"";(await t(xe,"resolve_action",{button:$,action:Q?"approve":"reject",...G>=0&&{buttonIndex:G},...S(s)})).success||x(X=>[...X,{ideId:s.tabKey,text:`⚠️ **${$}** failed — button not found`,timestamp:Date.now()}])}catch(Y){console.error("[ModalButton] Error:",Y),x(G=>[...G,{ideId:s.tabKey,text:`❌ **${$}** error`,timestamp:Date.now()}])}}},[s,t,x,S]),_=n.useCallback(async($,Y)=>{try{const G=$||(s==null?void 0:s.daemonId)||"",g=await t(G,"switch_chat",{id:Y,sessionId:Y,...S(s)}),Q=g==null?void 0:g.result;(g==null?void 0:g.success)===!0||Q==="switched"||Q==="switched-by-title"||(Q===!1||Q==="not_found"?i(V=>[...V,{id:Date.now(),message:"⚠️ Session tab not found — try refreshing history",type:"warning",timestamp:Date.now()}]):typeof Q=="string"&&Q.startsWith("error:")?i(V=>[...V,{id:Date.now(),message:`⚠️ Switch error: ${Q}`,type:"warning",timestamp:Date.now()}]):i(V=>[...V,{id:Date.now(),message:"⚠️ Session switch failed",type:"warning",timestamp:Date.now()}]))}catch(G){console.error("Switch failed",G),i(g=>[...g,{id:Date.now(),message:`❌ Switch failed: ${G.message||"connection error"}`,type:"warning",timestamp:Date.now()}])}},[s,t,i,S]),C=n.useCallback(async()=>{if(!(!s||w)){f(!0);try{const $=s.ideId||s.daemonId||"";await t($,"new_chat",{...S(s)}),o(Y=>({...Y,[s.tabKey]:Date.now()})),c(Y=>({...Y,[s.tabKey]:[]}))}catch($){console.error("New chat failed",$)}finally{f(!1)}}},[s,w,t,o,c,S]),j=n.useCallback(async()=>{if(!s||A)return;b(!0);const $=s.tabKey;try{await t(s.ideId,"agent_stream_focus",{agentType:s.agentType}),u($,[200,1500,3e3])}catch(Y){console.error("Focus agent failed",Y)}finally{b(!1)}},[s,A,t,u]),se=n.useCallback(async()=>{var $;if(!(!s||m)){E(!0);try{const Y=s.ideId||s.daemonId||"",G=await t(Y,"list_chats",{forceExpand:!0,...S(s)}),g=(G==null?void 0:G.chats)||(($=G==null?void 0:G.result)==null?void 0:$.chats);G!=null&&G.success&&Array.isArray(g)&&r(s.ideId,g)}catch(Y){console.error("Refresh history failed",Y)}finally{E(!1)}}},[s,m,t,r,S]);return{agentInput:d,setAgentInput:l,isCreatingChat:w,isRefreshingHistory:m,isFocusingAgent:A,handleSendChat:W,handleRelaunch:H,handleLaunchIde:D,handleModalButton:I,handleSwitchSession:_,handleNewChat:C,handleFocusAgent:j,handleRefreshHistory:se}}const Tt={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 mr(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function pr(){const[t,s]=n.useState("unix"),[a,r]=n.useState("powershell"),[i,c]=n.useState(!1),o=t==="unix"?"unix":a;n.useEffect(()=>{s(mr())},[]);const x=n.useCallback(()=>{navigator.clipboard.writeText(Tt[o].cmd).catch(()=>{}),c(!0),setTimeout(()=>c(!1),2e3)},[o]);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 ${a==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${a==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:x,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Tt[o].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Tt[o].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 && adhdev setup"})]})]})}let Et=null;function hr({conversations:t,ides:s,messageReceivedAt:a,actionLogs:r,ptyBuffers:i,screenshotMap:c,setScreenshotMap:o,sendDaemonCommand:x,updateIdeChats:u,setToasts:p,setLocalUserMessages:d,setClearedTabs:l,setActionLogs:w,pinTab:f,isStandalone:m,userName:E,groupIndex:A,isFocused:b,onFocus:S,isSplitMode:W,numGroups:H,onMoveTab:D,onClose:I,onReceiveTab:_,style:C,detectedIdes:j,handleLaunchIde:se,onActiveTabChange:$,initialActiveTabId:Y,initialTabOrder:G,onTabOrderChange:g,onHideTab:Q}){const{sendCommand:xe}=Ge(),V=n.useRef(null),[X,O]=n.useState(!1),oe=n.useRef(0),ee=n.useRef(null),[le,ce]=n.useState(Y??null);n.useEffect(()=>{Y&&Y!==le&&ce(Y)},[Y]);const[R,y]=n.useState(G??[]),[L,h]=n.useState(null),K=n.useRef(null),z=n.useRef(null);n.useEffect(()=>{const k=new Set(t.map(F=>F.tabKey));y(F=>{const ae=F.filter(Z=>k.has(Z)),U=t.filter(Z=>!F.includes(Z.tabKey)).map(Z=>Z.tabKey),ie=[...ae,...U];return ie.length===F.length&&ie.every((Z,J)=>Z===F[J])?F:ie})},[t]);const me=L??R,ye=n.useMemo(()=>{if(me.length===0)return t;const k=new Map(me.map((F,ae)=>[F,ae]));return[...t].sort((F,ae)=>{const U=k.get(F.tabKey)??999,ie=k.get(ae.tabKey)??999;return U-ie})},[t,me]);n.useEffect(()=>{if(ye.length===0){ce(null),$==null||$(null);return}le&&ye.some(k=>k.tabKey===le)||(ce(ye[0].tabKey),$==null||$(ye[0].tabKey))},[ye,le]);const de=ye.find(k=>k.tabKey===le),ke=n.useCallback((k,F,ae)=>{y(U=>{const ie=U.filter(he=>he!==k),Z=ie.indexOf(F);if(Z<0)return U;const J=ae==="left"?Z:Z+1;return ie.splice(J,0,k),g==null||g(ie),ie}),h(null)},[g]),ve=n.useCallback((k,F,ae)=>{const ie=(R.length>0?R:t.map(he=>he.tabKey)).filter(he=>he!==k),Z=ie.indexOf(F);if(Z<0)return;const J=ae==="left"?Z:Z+1;ie.splice(J,0,k),K.current=ie,h(ie)},[R,t]),pe=Ss({sendDaemonCommand:x,activeConv:de,ides:s,updateIdeChats:u,setToasts:p,setLocalUserMessages:d,setClearedTabs:l,setActionLogs:w,pinTab:f,isStandalone:m}),[P,be]=n.useState(null);n.useEffect(()=>{if(!P)return;const k=F=>{const ae=document.querySelector("[data-pane-context-menu]");ae&&ae.contains(F.target)||be(null)};return window.addEventListener("mousedown",k,!0),()=>window.removeEventListener("mousedown",k,!0)},[P]);const Ne="adhdev-tab-shortcuts",fe=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[we,Ve]=n.useState(()=>{try{return JSON.parse(localStorage.getItem(Ne)||"{}")}catch{return{}}}),[Ae,Ue]=n.useState(null),Pe=n.useCallback(k=>{const F=[];k.metaKey&&F.push(fe?"⌘":"Meta"),k.ctrlKey&&F.push("Ctrl"),k.altKey&&F.push(fe?"⌥":"Alt"),k.shiftKey&&F.push(fe?"⇧":"Shift");const ae=k.key;if(["Control","Alt","Shift","Meta"].includes(ae))return null;const U=ae.length===1?ae.toUpperCase():ae;return F.push(U),F.join("+")},[fe]),Ce=n.useCallback((k,F)=>Pe(k)===F,[Pe]),Be=n.useCallback(k=>{Ve(k),localStorage.setItem(Ne,JSON.stringify(k))},[]);n.useEffect(()=>{if(!Ae)return;const k=F=>{if(F.preventDefault(),F.stopPropagation(),F.key==="Escape"){Ue(null);return}const ae=Pe(F);if(!ae)return;const U={...we};for(const[ie,Z]of Object.entries(U))Z===ae&&delete U[ie];U[Ae]=ae,Be(U),Ue(null)};return window.addEventListener("keydown",k,!0),()=>window.removeEventListener("keydown",k,!0)},[Ae,we,Be,Pe]),n.useEffect(()=>{const k=F=>{if(!(!F.ctrlKey&&!F.metaKey&&!F.altKey)){for(const[ae,U]of Object.entries(we))if(Ce(F,U)&&ye.some(ie=>ie.tabKey===ae)){F.preventDefault(),S(),ce(ae),$==null||$(ae);return}}};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[we,ye,S,$,Ce]);const[Me,B]=n.useState({}),re=de&&We(de)&&!Oe(de),q=re?Me[de.tabKey]??de.mode??"terminal":"chat";n.useEffect(()=>{const k=()=>{oe.current=0,O(!1)};return window.addEventListener("dragend",k),window.addEventListener("drop",k),()=>{window.removeEventListener("dragend",k),window.removeEventListener("drop",k)}},[]);const ge=n.useRef(null);return n.useEffect(()=>{const k=ge.current;if(!k)return;const F=ae=>{Math.abs(ae.deltaY)>Math.abs(ae.deltaX)&&(ae.preventDefault(),k.scrollLeft+=ae.deltaY)};return k.addEventListener("wheel",F,{passive:!1}),()=>k.removeEventListener("wheel",F)},[]),e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:S,onDragEnter:k=>{if(k.dataTransfer.types.includes("text/tab-key")){oe.current++;const F=Et;F&&t.some(U=>U.tabKey===F)||O(!0)}},onDragOver:k=>{k.dataTransfer.types.includes("text/tab-key")&&k.preventDefault()},onDragLeave:()=>{oe.current--,oe.current<=0&&(oe.current=0,O(!1))},onDrop:k=>{oe.current=0,O(!1),h(null);const F=k.dataTransfer.getData("text/tab-key");if(!F)return;k.preventDefault(),t.some(U=>U.tabKey===F)?y(U=>{const ie=U.filter(Z=>Z!==F);return ie.push(F),g==null||g(ie),ie}):_&&_(F)},style:{...C,outline:X?"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:ge,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:[ye.map((k,F)=>{const ae=le===k.tabKey,U=k.status==="working"?"agent-tab-working":k.status==="waiting_approval"?"agent-tab-waiting":"",ie=k.connectionState==="failed"||k.connectionState==="closed",Z=z.current===k.tabKey;return e.jsxs("div",{"data-tabkey":k.tabKey,className:`${U} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:J=>{Et=k.tabKey,z.current=k.tabKey,J.dataTransfer.setData("text/tab-key",k.tabKey),J.dataTransfer.effectAllowed="move"},onDragEnd:()=>{Et=null,z.current=null;const J=K.current;J&&(y(J),g==null||g(J)),K.current=null,h(null),oe.current=0,O(!1)},onDragOver:J=>{const he=z.current;if(!(!he||he===k.tabKey)&&J.dataTransfer.types.includes("text/tab-key")){J.preventDefault(),J.stopPropagation();const te=J.currentTarget.getBoundingClientRect(),v=te.left+te.width/2,N=J.clientX<v?"left":"right";ve(he,k.tabKey,N)}},onDrop:J=>{J.preventDefault(),J.stopPropagation();const he=J.dataTransfer.getData("text/tab-key");if(he&&he!==k.tabKey){const te=J.currentTarget.getBoundingClientRect(),v=te.left+te.width/2,N=J.clientX<v?"left":"right";ye.some(M=>M.tabKey===he)?ke(he,k.tabKey,N):_&&_(he)}h(null)},onClick:J=>{J.stopPropagation(),S(),ce(k.tabKey),$==null||$(k.tabKey),k.streamSource==="agent-stream"&&k.agentType&&xe(k.ideId,"agent_stream_focus",{agentType:k.agentType}).catch(()=>{}),We(k)&&setTimeout(()=>{var he,te;return(te=(he=V.current)==null?void 0:he.bumpResize)==null?void 0:te.call(he)},100)},onContextMenu:J=>{J.preventDefault(),be({x:J.clientX,y:J.clientY,tabKey:k.tabKey})},onTouchStart:J=>{const he=J.touches[0],te=he.clientX,v=he.clientY;ee.current=setTimeout(()=>{be({x:te,y:v,tabKey:k.tabKey})},600)},onTouchEnd:()=>{ee.current&&clearTimeout(ee.current)},onTouchMove:()=>{ee.current&&clearTimeout(ee.current)},style:{background:ae?"var(--bg-primary)":"var(--bg-glass)",borderTop:ae?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:ae?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:ae?"1px solid var(--border-subtle)":"1px solid transparent",opacity:Z?.4:ie?ae?.6:.3:ae?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[k.status==="working"?e.jsx("div",{className:"tab-spinner"}):k.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):ie?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):k.connectionState==="connecting"||k.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):k.connectionState==="connected"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-green-400",children:"●"}):e.jsx("span",{className:"text-[8px] px-[5px] py-px text-text-muted animate-pulse",children:"○"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-xs font-bold whitespace-nowrap overflow-hidden text-ellipsis",style:{maxWidth:"10ch"},title:k.displayPrimary,children:k.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:ie?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):k.connectionState==="connecting"||k.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[k.displaySecondary,k.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",k.machineName]})]})]})})]}),we[k.tabKey]&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${we[k.tabKey]}`,children:we[k.tabKey]})]},k.tabKey)}),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),e.jsx("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",children:de?e.jsxs(e.Fragment,{children:[re&&e.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-bg-primary border-b border-border-subtle shrink-0 gap-3",children:[e.jsxs("div",{className:"flex bg-bg-secondary rounded items-center p-0.5 border border-border-subtle text-[11px] shadow-sm",children:[e.jsx("button",{className:`px-2 py-[2px] rounded transition-all outline-none ${q==="chat"?"bg-[var(--surface-primary)] shadow-sm font-semibold text-text-primary":"bg-transparent text-text-muted hover:text-text-primary"}`,onClick:()=>{q!=="chat"&&B(k=>({...k,[de.tabKey]:"chat"}))},children:"💬 Chat"}),e.jsx("button",{className:`px-2 py-[2px] rounded transition-all outline-none ${q==="terminal"?"bg-[var(--surface-primary)] shadow-sm font-semibold text-text-primary":"bg-transparent text-text-muted hover:text-text-primary"}`,onClick:()=>{q!=="terminal"&&B(k=>({...k,[de.tabKey]:"terminal"}))},children:"🖥 Terminal"})]}),q==="terminal"&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>{if(!V.current)return;const k=i.current.get(de.tabKey);if(k&&k.length>0)for(const F of k)V.current.write(F);requestAnimationFrame(()=>{requestAnimationFrame(()=>{var F;(F=V.current)==null||F.bumpResize()})})},title:"Refresh terminal (replay buffer + TUI redraw)",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-bg-secondary text-text-secondary border border-border-subtle cursor-pointer leading-none",children:"↺"}),e.jsx("button",{onClick:async()=>{var ae;const k=(ae=de.ideId)!=null&&ae.includes(":cli:")?de.ideId.split(":cli:")[1]:de.ideType||de.agentType||"";if(!window.confirm(`Stop ${k}?
51
- This will terminate the CLI process.`))return;const F=de.ideId||de.daemonId||"";try{await xe(F,"stop_cli",{cliType:k})}catch(U){console.error("Stop CLI failed:",U)}},title:"Stop CLI process",className:"px-2 py-0.5 rounded-[5px] text-[11px] bg-red-500/[0.08] text-red-400 border border-red-500/30 cursor-pointer leading-none font-semibold",children:"■ Stop"})]})]}),e.jsx(un,{activeConv:de,onModalButton:pe.handleModalButton}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!re&&!Oe(de)&&c[de.ideId]?e.jsx(dn,{screenshotUrl:c[de.ideId],mode:"preview",onDismiss:()=>{const k={...c};delete k[de.ideId],o(k)}}):!re&&!Oe(de)&&de.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(ms,{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}),q==="terminal"?e.jsx(mn,{activeConv:de,ptyBuffers:i,terminalRef:V,agentInput:pe.agentInput,setAgentInput:pe.setAgentInput,handleSendChat:pe.handleSendChat}):e.jsx(bs,{activeConv:de,ides:s,agentInput:pe.agentInput,setAgentInput:pe.setAgentInput,handleSendChat:pe.handleSendChat,handleFocusAgent:pe.handleFocusAgent,isFocusingAgent:pe.isFocusingAgent,messageReceivedAt:a,actionLogs:r,userName:E})]}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:t.length===0&&!W&&j&&se?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:"Waiting for your IDE"}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children: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(pr,{}),m&&j&&j.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:j.map(k=>e.jsxs("button",{className:"btn btn-sm bg-accent/10 border border-accent/25 text-accent text-xs font-medium px-4 py-2.5 rounded-lg cursor-pointer flex items-center gap-2 transition-all hover:bg-accent/20 hover:scale-105 active:scale-95",onClick:()=>se&&se(k.type),children:[e.jsx(nn,{size:14,className:"opacity-70"})," Launch ",k.name]},k.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"})})}),P&&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:P.x,top:P.y},children:[D&&A>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{D(P.tabKey,"left"),be(null)},children:"← Move to Left Group"}),D&&A<H-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{D(P.tabKey,"right"),be(null)},children:"Move to Right Group →"}),D&&H<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{D(P.tabKey,"new"),be(null)},children:"Split to New Group ◨"}),e.jsx("div",{className:"border-t border-border-subtle my-1 "}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:k=>{k.stopPropagation(),Ue(P.tabKey),be(null)},children:["⌨ ",we[P.tabKey]?`Change shortcut (${we[P.tabKey]})`:"Set shortcut"]}),we[P.tabKey]&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors text-text-muted ",onClick:()=>{const k={...we};delete k[P.tabKey],Be(k),be(null)},children:"✕ Remove shortcut"}),Q&&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:()=>{Q(P.tabKey),be(null)},children:"🚫 Hide from Dashboard"})]}),!D&&!Q&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),Ae&&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:()=>Ue(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:k=>k.stopPropagation(),children:[e.jsx("div",{className:"text-sm font-bold text-text-primary mb-2",children:"⌨ Set shortcut"}),e.jsxs("div",{className:"text-xs text-text-secondary mb-4",children:["Press a key combo (e.g. ",fe?"⌘+1":"Ctrl+1",", ",fe?"⌥+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 $t=[{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 && adhdev setup"}];function fr({onClose:t}){const[s,a]=n.useState(0),r=$t[s],i=s===$t.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:c=>{c.target===c.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:$t.map((c,o)=>e.jsx("div",{style:{width:o===s?24:8,height:8,borderRadius:4,background:o===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},o))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:r.visual||r.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:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.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:"$"}),r.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():a(c=>c+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:`
52
- @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
53
- @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
54
- `})]})}function gr(){const{sendCommand:t}=Ge(),[s,a]=is(),r=s.get("activeTab"),i=Nt(),{updateIdeChats:c,screenshotMap:o,setScreenshotMap:x}=i,u=i.ides||[],[p,d]=n.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),l=i.toasts||[],w=i.setToasts||(()=>{}),f=i.wsStatus||"connected",m=i.isConnected??!0,E=i.connectionStates||{};i.retryConnection;const A=i.showReconnected||!1,[b,S]=n.useState(()=>{try{const v=localStorage.getItem("adhdev_splitGroups");if(v){const N=JSON.parse(v);return new Map(N)}}catch{}return new Map}),[W,H]=n.useState(()=>{try{const v=localStorage.getItem("adhdev_focusedGroup");if(v)return parseInt(v,10)||0}catch{}return 0}),[D,I]=n.useState(()=>{try{const v=localStorage.getItem("adhdev_groupActiveTabs");if(v)return JSON.parse(v)}catch{}return{}}),_=n.useRef(!1),[C,j]=n.useState(()=>{try{const v=localStorage.getItem("adhdev_groupTabOrders");if(v)return JSON.parse(v)}catch{}return{}}),[se,$]=n.useState(()=>{try{const v=localStorage.getItem("adhdev_splitSizes");if(v)return JSON.parse(v)}catch{}return[]});n.useEffect(()=>{try{b.size===0?localStorage.removeItem("adhdev_splitGroups"):localStorage.setItem("adhdev_splitGroups",JSON.stringify([...b.entries()]))}catch{}},[b]),n.useEffect(()=>{try{se.length>0?localStorage.setItem("adhdev_splitSizes",JSON.stringify(se)):localStorage.removeItem("adhdev_splitSizes")}catch{}},[se]),n.useEffect(()=>{try{localStorage.setItem("adhdev_focusedGroup",String(W))}catch{}},[W]),n.useEffect(()=>{try{localStorage.setItem("adhdev_groupActiveTabs",JSON.stringify(D))}catch{}},[D]),n.useEffect(()=>{try{localStorage.setItem("adhdev_groupTabOrders",JSON.stringify(C))}catch{}},[C]);const[Y,G]=n.useState(()=>typeof window<"u"&&window.innerWidth<768);n.useEffect(()=>{const v=window.matchMedia("(max-width: 767px)"),N=M=>G(M.matches);return v.addEventListener("change",N),()=>v.removeEventListener("change",N)},[]);const g=n.useMemo(()=>Y||b.size===0?1:Math.max(1,...b.values())+1,[b,Y]),Q=g>1,xe=n.useCallback((v,N)=>{S(M=>{const T=new Map(M);return N===0?T.delete(v):T.set(v,N),T}),H(N)},[]),V=n.useCallback(v=>{S(N=>{const T=(N.size===0?0:Math.max(0,...N.values()))+1;if(T>=4)return N;const ne=new Map(N);return ne.set(v,T),ne}),H(N=>N+1)},[]),X=n.useCallback(v=>{S(N=>{const M=new Map;for(const[T,ne]of N)ne!==v&&(ne>v?M.set(T,ne-1):M.set(T,ne));return M}),$(N=>{if(N.length<=1)return[];const M=[...N];M.splice(v,1);const T=M.reduce((ne,ue)=>ne+ue,0);return M.map(ne=>ne/T*100)}),H(0)},[]),O=n.useRef(null),oe=n.useCallback((v,N)=>{N.preventDefault();const M=O.current;if(!M)return;const T=N.clientX,ne=M.offsetWidth,ue=se.length===g?[...se]:Array(g).fill(100/g),je=_e=>{const mt=(_e.clientX-T)/ne*100,ze=[...ue];ze[v]=Math.max(15,ue[v]+mt),ze[v+1]=Math.max(15,ue[v+1]-mt),$(ze)},Te=()=>{document.removeEventListener("mousemove",je),document.removeEventListener("mouseup",Te),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",je),document.addEventListener("mouseup",Te)},[se,g]),[ee,le]=n.useState({}),[ce,R]=n.useState(!1),[y,L]=n.useState([]),[h,K]=n.useState({}),[z,me]=n.useState({}),[ye,de]=n.useState(!1),[ke,ve]=n.useState(!1);n.useEffect(()=>{const v=M=>{var T;(T=M.dataTransfer)!=null&&T.types.includes("text/tab-key")&&ve(!0)},N=()=>{ve(!1),de(!1)};return window.addEventListener("dragstart",v),window.addEventListener("dragend",N),window.addEventListener("drop",N),()=>{window.removeEventListener("dragstart",v),window.removeEventListener("dragend",N),window.removeEventListener("drop",N)}},[]);const pe=u.find(v=>v.type==="adhdev-daemon"),P=(pe==null?void 0:pe.detectedIdes)||[],be=!!pe,Ne=n.useMemo(()=>{const v=u.filter(M=>M.type!=="adhdev-daemon"),N=new Map;for(const M of v){const T=N.get(M.id);if(!T)N.set(M.id,M);else{const ne=(T.workspace?1:0)+(T.activeChat?1:0);((M.workspace?1:0)+(M.activeChat?1:0)>ne||(M.timestamp||0)>(T.timestamp||0))&&N.set(M.id,M)}}return Array.from(N.values())},[u]),fe=n.useMemo(()=>{const v=In(Ne,h,u,E),N=Date.now();return v.map(M=>{const T=z[M.tabKey];return T&&N-T<5e3?{...M,messages:[],title:""}:M})},[Ne,h,z,u]),{hiddenTabs:we,toggleTab:Ve}=xr(),Ae=n.useMemo(()=>fe.filter(v=>!we.has(v.tabKey)),[fe,we]);n.useEffect(()=>{Pn()},[]);const Ue=n.useMemo(()=>Ae.map(v=>({id:v.tabKey,name:v.title||v.agentName||v.ideId,status:v.status,activeModal:v.modalMessage?{message:v.modalMessage,buttons:v.modalButtons}:null})),[Ae]);Dn(Ue);const Pe=n.useMemo(()=>{const v=Array.from({length:g},()=>[]);for(const N of Ae){const M=b.get(N.tabKey)??0,T=Math.min(M,g-1);v[T].push(N)}return v},[Ae,b,g]);n.useEffect(()=>{const v=new Set(Ae.map(N=>N.tabKey));S(N=>{let M=!1;const T=new Map;for(const[ne,ue]of N)v.has(ne)?T.set(ne,ue):M=!0;return M?T:N})},[fe]),n.useEffect(()=>{if(Q)for(let v=g-1;v>=1;v--)[...b.values()].some(M=>M===v)||X(v)},[b,g,Q,X]),n.useEffect(()=>{if(!r||_.current||fe.length===0)return;const v=fe.find(N=>N.tabKey===r)||fe.find(N=>N.ideId===r)||fe.find(N=>N.ideType===r||N.agentType===r);if(v){const N=b.get(v.tabKey)??0;I(M=>({...M,[N]:v.tabKey})),H(N),_.current=!0,a(M=>{const T=new URLSearchParams(M);return T.delete("activeTab"),T},{replace:!0})}},[r,fe,b]),n.useEffect(()=>{if(Object.keys(z).length===0)return;const N=setTimeout(()=>{me(M=>{const T=Date.now(),ne={};for(const[ue,je]of Object.entries(M))T-je<5e3&&(ne[ue]=je);return Object.keys(ne).length===Object.keys(M).length?M:ne})},5500);return()=>clearTimeout(N)},[z]);const Ce=n.useMemo(()=>{var N,M;const v=D[W];if(v){const T=fe.find(ne=>ne.tabKey===v);if(T)return T}return((N=Pe[W])==null?void 0:N[0])||((M=Pe[0])==null?void 0:M[0])},[D,W,fe,Pe]),Be=n.useCallback((v,N)=>{},[]);n.useEffect(()=>{var T;const v=Date.now();let N=!1;const M={...ee};for(const ne of fe)(T=ne.messages)!=null&&T.length&&ne.messages.forEach((ue,je)=>{const Te=`${ne.ideId}-${ue.id??`i-${je}`}`;M[Te]==null&&(M[Te]=v,N=!0)});N&&le(M)},[fe]);const Me=n.useRef(!1);n.useEffect(()=>{if(!ce){Me.current=!1;return}if(!Ce||Me.current||q)return;const v=u.find(N=>N.id===Ce.ideId);v&&(!v.chats||v.chats.length===0)&&(Me.current=!0,ae())},[ce,Ce==null?void 0:Ce.ideId]),n.useEffect(()=>{const v=setInterval(()=>{const N=Date.now()-3e5;L(M=>{const T=M.filter(ne=>ne.timestamp>N).slice(-100);return T.length===M.length?M:T})},6e4);return()=>clearInterval(v)},[]);const B=n.useRef(new Map);n.useEffect(()=>{const v=(M,T)=>{var ne;if(T){ys.emit(M,T);for(const ue of fe){if(!We(ue))continue;const je=(ne=ue.ideId)!=null&&ne.includes(":cli:")?ue.ideId.split(":cli:")[1]:"";if(M===je||M===ue.agentType||M===ue.ideType||M===ue.ideId||M===ue.tabKey){const _e=B.current.get(ue.tabKey)||[];_e.push(T),_e.length>1e4&&_e.splice(0,_e.length-5e3),B.current.set(ue.tabKey,_e)}}}},N=yn.onPtyOutput(v);return()=>{N()}},[fe]),n.useEffect(()=>{const v=N=>{if(N.ctrlKey&&N.key==="\\"){if(N.preventDefault(),Q)S(new Map),H(0);else{const M=fe[1];M&&V(M.tabKey)}return}N.ctrlKey&&(N.key==="["||N.key==="]")&&Q&&(N.preventDefault(),H(M=>N.key==="]"?Math.min(M+1,g-1):Math.max(M-1,0)))};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[Q,fe,V,g]),n.useEffect(()=>{Qe.setIdes(u)},[u]),n.useEffect(()=>{Qe.setResolveAction((v,N,M)=>{t(v,N,M).catch(()=>{})})},[t]),n.useEffect(()=>{const v=Qe.onToast(T=>{w(ue=>ue.some(Te=>Te.message===T.message&&T.timestamp-Te.timestamp<3e3)?ue:[...ue.slice(-4),{id:T.id,message:T.message,type:T.type,timestamp:T.timestamp,ideId:T.ideId,actions:T.actions}]);const ne=T.duration||5e3;setTimeout(()=>w(ue=>ue.filter(je=>je.id!==T.id)),ne)}),N=Qe.onSystemMessage((T,ne)=>{K(ue=>{for(const je of Object.keys(ue))if(je.includes(T))return{...ue,[je]:[...ue[je]||[],ne]};return ue})}),M=Qe.onClearSystemMessage((T,ne)=>{K(ue=>{const je={...ue};for(const Te of Object.keys(je))Te.includes(T)&&(je[Te]=(je[Te]||[]).filter(_e=>{var st;return!(_e.role==="system"&&((st=_e._localId)!=null&&st.startsWith(ne)))}));return je})});return()=>{v(),N(),M()}},[]),n.useEffect(()=>{const v=gn.on("status_event",N=>Qe.handleRawEvent(N,"ws"));return()=>{v()}},[]),n.useEffect(()=>{var N;const v=M=>{const T=M.data;(T==null?void 0:T.type)==="notification_action"&&T.action==="approve"&&T.ideId&&t(T.ideId,"resolve_action",{action:"approve",button:"Approve"}).catch(ne=>console.error("[SW Action] approve failed:",ne))};return(N=navigator.serviceWorker)==null||N.addEventListener("message",v),()=>{var M;return(M=navigator.serviceWorker)==null?void 0:M.removeEventListener("message",v)}},[]);const{isCreatingChat:re,isRefreshingHistory:q,handleLaunchIde:ge,handleSwitchSession:k,handleNewChat:F,handleRefreshHistory:ae}=Ss({sendDaemonCommand:t,activeConv:Ce,ides:u,updateIdeChats:c,setToasts:w,setLocalUserMessages:K,setClearedTabs:me,setActionLogs:L,pinTab:Be,isStandalone:be}),U=n.useMemo(()=>u.filter(v=>v.type==="adhdev-daemon"&&v.versionMismatch),[u]),[ie,Z]=n.useState(!1),[J,he]=n.useState({}),te=n.useCallback(async v=>{var N,M;he(T=>({...T,[v]:"upgrading"}));try{const T=await t(v,"daemon_upgrade",{});(N=T==null?void 0:T.result)!=null&&N.upgraded||(M=T==null?void 0:T.result)!=null&&M.success?he(ne=>({...ne,[v]:"done"})):he(ne=>({...ne,[v]:"error"}))}catch{he(T=>({...T,[v]:"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(pn,{wsStatus:f,showReconnected:A}),U.length>0&&!ie&&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",children:"🔄"}),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",U[0].version]})," → ",e.jsxs("strong",{children:["v",U[0].serverVersion]})]}),U.map(v=>{var T;const N=v.machineNickname||((T=v.machine)==null?void 0:T.hostname)||v.hostname||"Machine",M=J[v.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:N}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",v.version]}),M==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):M==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):M==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>te(v.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:()=>te(v.id),children:"Upgrade"})]},v.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:()=>Z(!0),title:"Dismiss",children:"✕"})]}),e.jsx(vn,{activeConv:Ce,agentCount:Ne.length,wsStatus:f,isConnected:m,onOpenHistory:()=>R(!0)}),e.jsxs("div",{ref:O,className:`flex-1 min-h-0 flex ${Q?"flex-row":"flex-col"} overflow-hidden`,children:[Pe.map((v,N)=>{const M=Q&&se.length===g?`${se[N]}%`:void 0;return e.jsxs(_s.Fragment,{children:[Q&&N>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:T=>oe(N-1,T),onDoubleClick:()=>X(N),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:Q?{flexBasis:M??`${100/g}%`,flexGrow:M?0:1,flexShrink:M?0:1}:void 0,conversations:v,ides:u,messageReceivedAt:ee,actionLogs:y,ptyBuffers:B,screenshotMap:o,setScreenshotMap:x,sendDaemonCommand:t,updateIdeChats:c,setToasts:w,setLocalUserMessages:K,setClearedTabs:me,setActionLogs:L,pinTab:Be,isStandalone:be,userName:i.userName,groupIndex:N,isFocused:W===N,onFocus:()=>H(N),isSplitMode:Q,numGroups:g,onMoveTab:(T,ne)=>{ne==="left"&&N>0?xe(T,N-1):ne==="right"&&N<g-1?xe(T,N+1):ne==="new"&&g<4&&V(T)},onClose:Q?()=>X(N):void 0,onReceiveTab:T=>xe(T,N),detectedIdes:N===0?P:void 0,handleLaunchIde:N===0?ge:void 0,onActiveTabChange:T=>I(ne=>({...ne,[N]:T})),initialActiveTabId:D[N],initialTabOrder:C[N],onTabOrderChange:T=>j(ne=>({...ne,[N]:T})),onHideTab:Ve})]},N)}),!Y&&g<4&&e.jsxs("div",{className:"relative shrink-0 w-0 z-50",children:[e.jsx("div",{className:"fixed right-0 top-0 bottom-0 w-16",style:{pointerEvents:ke?"auto":"none"},onDragOver:v=>{v.dataTransfer.types.includes("text/tab-key")&&(v.preventDefault(),de(!0))},onDragLeave:()=>de(!1),onDrop:v=>{v.preventDefault(),de(!1);const N=v.dataTransfer.getData("text/tab-key");N&&V(N)}}),e.jsx("div",{className:"fixed right-0 top-0 bottom-0 pointer-events-none transition-all duration-200",style:{width:ye?"120px":"0px",background:"var(--accent-primary)",opacity:ye?.15:0,borderLeft:ye?"2px dashed var(--accent-primary)":"none"}})]})]}),ce&&Ce&&e.jsx(Nn,{activeConv:Ce,ides:u,isCreatingChat:re,isRefreshingHistory:q,onClose:()=>R(!1),onNewChat:F,onSwitchSession:k,onRefreshHistory:ae}),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(kn,{toasts:l,onDismiss:v=>w(N=>N.filter(M=>M.id!==v)),onClickToast:v=>{if(v.ideId){const N=fe.find(M=>M.ideId===v.ideId||M.tabKey===v.ideId);N&&H(b.get(N.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
- `}),p&&e.jsx(fr,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}d(!1)}})]})}function br(t){return t.split(":")[0]||""}function yr({renderHeaderActions:t}={}){var de,ke,ve,pe;const{id:s}=cs(),a=ut(),r=Nt(),i=r.ides||[],c=r.connectionStates||{},{sendCommand:o}=Ge(),x=n.useMemo(()=>br(s||""),[s]),u=n.useMemo(()=>i.find(P=>P.id===s),[i,s]),p=(u==null?void 0:u.type)||void 0,d=p?p.charAt(0).toUpperCase()+p.slice(1):"IDE",l=(u==null?void 0:u.activeChat)||null,w=(u==null?void 0:u.agentStreams)||[],f=r.isConnected??!0,m=c[x]||(f?"connected":"new"),E=((de=r.connectionTransports)==null?void 0:de[x])||"unknown",A=n.useMemo(()=>i.find(P=>P.id===x||P.daemonId===x),[i,x]),b=(A==null?void 0:A.machineNickname)||((ke=A==null?void 0:A.machine)==null?void 0:ke.hostname)||"",S=(u==null?void 0:u.workspace)||"",[W]=is(),H=typeof window<"u"&&window.innerWidth<=768,D=W.get("view")||(H?"chat":"split"),[I,_]=n.useState(D),[C,j]=n.useState("native"),[se,$]=n.useState(""),[Y,G]=n.useState(!1),[g,Q]=n.useState(null),[xe,V]=n.useState(null),[X,O]=n.useState([]),oe=l==null?void 0:l.status,ee=(((pe=(ve=l==null?void 0:l.activeModal)==null?void 0:ve.buttons)==null?void 0:pe.length)??0)>0,le=oe==="generating"||oe==="loading"||oe&&oe.toLowerCase()==="thinking",R=ee||oe==="waiting_approval"?"waiting_approval":le?"working":oe||"idle",y=n.useMemo(()=>{var P,be;return{ideId:s||"",daemonId:x,agentName:Pt(p||""),agentType:p||"",status:R,title:(l==null?void 0:l.title)||"",messages:(l==null?void 0:l.messages)||[],ideType:p||"",workspaceName:(u==null?void 0:u.workspaceName)||"",displayPrimary:d,displaySecondary:(u==null?void 0:u.workspaceName)||"",cdpConnected:!0,modalButtons:(P=l==null?void 0:l.activeModal)==null?void 0:P.buttons,modalMessage:(be=l==null?void 0:l.activeModal)==null?void 0:be.message,streamSource:"native",tabKey:`ide-${s}`}},[s,x,p,l,u,d,R]),L=n.useMemo(()=>w.map(P=>{var Ne,fe;const be=P.activeModal?"waiting_approval":P.status==="streaming"?"working":P.status||"idle";return{ideId:s||"",daemonId:x,agentName:P.agentName,agentType:P.agentType,status:be,title:"",messages:P.messages.map((we,Ve)=>({role:we.role,content:we.content,kind:we.kind,id:`${P.agentType}-${Ve}`,receivedAt:we.timestamp})),ideType:P.agentType,workspaceName:"",displayPrimary:P.agentName,displaySecondary:"",cdpConnected:!0,modalButtons:(Ne=P.activeModal)==null?void 0:Ne.buttons,modalMessage:(fe=P.activeModal)==null?void 0:fe.message,streamSource:"agent-stream",tabKey:`agent-stream-${P.agentType}`}}),[w,s,x]),h=n.useMemo(()=>C==="native"?y:L.find(P=>P.agentType===C)||y,[C,y,L]);n.useEffect(()=>x?$e.onScreenshot("ide-page",(be,Ne)=>{if(be!==x)return;const fe=new FileReader;fe.onload=()=>Q(fe.result),fe.readAsDataURL(Ne)}):void 0,[x]),n.useEffect(()=>{m!=="connected"&&Q(null)},[m]),n.useEffect(()=>{var be;return x?((be=$e.onStatus)==null?void 0:be.call($e,(Ne,fe)=>{Ne===x&&fe!=null&&fe.screenshotUsage&&V(fe.screenshotUsage)}))||(()=>{}):void 0},[x]);const K=n.useMemo(()=>{if(!s)return p;const P=s.split(":");return P.length>=3&&P[1]==="ide"?P.slice(2).join(":"):p},[s,p]);n.useEffect(()=>{Q(null)},[x,s,K]),n.useEffect(()=>{const P=x?$e.get(x):null;!P||!(m==="connected")||(I!=="chat"&&K?P.startScreenshots(K):P.stopScreenshots(K))},[I,m,K,x]);const z=n.useCallback(async(P,be={})=>{if(!s)throw new Error("No IDE ID");return await o(s,P,be)},[s]),me=async()=>{const P=se.trim();if(!(!P||!s||Y)){$(""),G(!0);try{await z("send_chat",{message:P,text:P,waitForResponse:!0,...C!=="native"&&{agentType:C}})}catch(be){console.error("[IDE] Send failed:",be)}finally{G(!1)}}},ye=w.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(jt,{size:16}),e.jsx("span",{className:"ide-name",children:d}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),S&&e.jsx("span",{className:"ide-workspace",children:S}),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"})]}),b&&e.jsx("span",{className:"ide-machine-label",children:b})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(P=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:I===P?"1px solid var(--accent-primary)":"none",background:I===P?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:I===P?"var(--accent-primary)":void 0},onClick:()=>_(P),children:P==="chat"?e.jsx(jt,{size:14}):P==="split"?"⊞":e.jsx(xt,{size:14})},P)),t&&t({daemonId:x,ideInstanceId:s||""}),e.jsxs("button",{className:"btn btn-primary btn-sm flex items-center justify-center shrink-0",onClick:()=>a(-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 ${I==="chat"?"full":""} ${I==="remote"?"hidden":""}`,children:[ye&&e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${C==="native"?"active":""}`,onClick:()=>j("native"),children:d}),w.map(P=>{const be=C===P.agentType,Ne=P.status==="waiting_approval"||!!P.activeModal,fe=P.status==="streaming";return e.jsxs("button",{className:`ide-chat-tab ${be?"active":""}`,onClick:()=>j(P.agentType),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:Ne?"#f59e0b":fe?"var(--accent-primary)":"#64748b",boxShadow:fe?"0 0 6px var(--accent-primary)":"none"}}),P.agentName,Ne&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},P.agentType)})]}),e.jsx(bs,{activeConv:h,ides:i,agentInput:se,setAgentInput:$,handleSendChat:me,handleFocusAgent:()=>{},isFocusingAgent:!1,messageReceivedAt:{},actionLogs:[],userName:r.userName})]}),e.jsx("div",{className:`ide-remote-panel ${I==="remote"?"full":""} ${I==="chat"?"hidden":""}`,children:e.jsx(ln,{addLog:()=>{},connState:m,connScreenshot:g,screenshotUsage:xe,transportType:E,onAction:async(P,be)=>{const Ne=x?$e.get(x):null;if(!Ne||m!=="connected")return console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"};const fe=(u==null?void 0:u.instanceId)||K;return await Ne.sendInput(P,be,fe)}})})]}),X.length>0&&e.jsx("div",{className:"ide-toasts",children:X.map(P=>e.jsx("div",{className:`ide-toast ${P.type}`,onClick:()=>O(be=>be.filter(Ne=>Ne.id!==P.id)),children:P.message},P.id))})]}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function vr({machineId:t,sendDaemonCommand:s,logsEndRef:a}){const[r,i]=n.useState([]),[c,o]=n.useState(null),[x,u]=n.useState(!1),[p,d]=n.useState(!1),[l,w]=n.useState(!1),[f,m]=n.useState([]),[E,A]=n.useState([]),[b,S]=n.useState(null),[W,H]=n.useState(!1),[D,I]=n.useState(""),_=n.useRef(null),C=n.useCallback(R=>{_.current=R},[]),j=n.useCallback((R,y)=>{i(L=>[...L.slice(-100),{timestamp:Date.now(),level:R,message:y}]),setTimeout(()=>{var L;return(L=a.current)==null?void 0:L.scrollIntoView({behavior:"smooth"})},100)},[a]),se=n.useCallback(async(R,y)=>{var L;if(!(!t||c)){o(R),j("info",`Launching ${Le(R)}${y!=null&&y.workspace?` in ${y.workspace}`:""}...`);try{const h={ideType:R,enableCdp:!0};(L=y==null?void 0:y.workspace)!=null&&L.trim()?h.workspace=y.workspace.trim():y!=null&&y.useDefaultWorkspace&&(h.useDefaultWorkspace=!0);const K=await s(t,"launch_ide",h);j(K!=null&&K.success?"info":"error",K!=null&&K.success?`${Le(R)} launched`:`Failed: ${K==null?void 0:K.error}`)}catch(h){j("error",`Launch error: ${h.message}`)}finally{o(null)}}},[t,c,j,s]),$=n.useCallback(async R=>{if(!t)return;const{cliType:y,dir:L,workspaceId:h,useDefaultWorkspace:K,useHome:z,argsStr:me,model:ye}=R;if(!y){j("warn","Select a CLI or ACP provider first");return}const de=me?me.split(/\s+/).filter(Boolean):void 0,ke=(L==null?void 0:L.trim())||(h?"(saved id)":K?"(default workspace)":z?"(home)":"");j("info",`Launching ${y}${ke?` in ${ke}`:""}${ye?` (model: ${ye})`:""}...`);try{const ve={cliType:y,cliArgs:de,initialModel:ye||void 0};L!=null&&L.trim()?ve.dir=L.trim():h?ve.workspaceId=h:K?ve.useDefaultWorkspace=!0:z&&(ve.useHome=!0);const pe=await s(t,"launch_cli",ve),P=(pe==null?void 0:pe.result)||pe;pe!=null&&pe.success?(j("info",`${y} launched`),(P==null?void 0:P.launchSource)==="home"?j("info","📂 Running in home directory (explicit choice)"):(P==null?void 0:P.launchSource)==="defaultWorkspace"&&j("info","📂 Using default workspace (explicit choice)")):(j("error",`Failed: ${(pe==null?void 0:pe.error)||(P==null?void 0:P.error)}`),(pe==null?void 0:pe.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&S({cliType:y,argsStr:me,model:ye}))}catch(ve){j("error",`Launch error: ${ve.message}`)}},[t,j,s]),Y=n.useCallback((R,y,L,h)=>{if(t){if(!R){j("warn","Select a provider");return}if(!y.trim()){S({cliType:R,argsStr:L,model:h});return}$({cliType:R,dir:y,argsStr:L,model:h})}},[t,j,$]),G=n.useCallback(async(R,y,L)=>{if(t&&window.confirm(`Stop ${R}?
68
- This will terminate the process.`))try{const h=await s(t,"stop_cli",{cliType:R,dir:y,_targetInstance:L});h!=null&&h.success?j("info",`${R} stopped`):j("error",`Stop failed: ${(h==null?void 0:h.error)||"Unknown error"}`)}catch(h){j("error",`Stop failed: ${h.message}`)}},[t,j,s]),g=n.useCallback(async R=>{try{await s(R.daemonId,"restart_ide",{ideType:R.type}),j("info",`${Le(R.type)} restart initiated`)}catch(y){j("error",`Restart failed: ${y.message}`)}},[j,s]),Q=n.useCallback(async R=>{if(window.confirm(`Stop ${Le(R.type)}?
69
- This will disconnect CDP and optionally kill the process.`))try{const y=await s(R.daemonId,"stop_ide",{ideType:R.type,killProcess:!0});y!=null&&y.success?j("info",`${Le(R.type)} stopped`):j("error",`Stop failed: ${(y==null?void 0:y.error)||"Unknown error"}`)}catch(y){j("error",`Stop failed: ${y.message}`)}},[j,s]),xe=n.useCallback(async()=>{if(t)try{const R=await s(t,"detect_ides",{});j("info",`Found ${((R==null?void 0:R.result)||[]).length} IDE(s)`)}catch(R){j("error",`Detection failed: ${R.message}`)}},[t,j,s]),V=n.useCallback(async()=>{if(t){u(!0);try{const R=await s(t,"get_recent_workspaces",{});R!=null&&R.success&&Array.isArray(R==null?void 0:R.result)&&A(R.result)}catch(R){j("error",`Failed: ${R.message}`)}finally{u(!1)}}},[t,j,s]),X=n.useCallback(async R=>{if(!(!t||!R.trim())){d(!0);try{const y=await s(t,"workspace_add",{path:R.trim()});y!=null&&y.success?j("info",`Workspace added: ${R.trim()}`):j("error",(y==null?void 0:y.error)||"workspace_add failed")}catch(y){j("error",y.message)}finally{d(!1)}return!0}},[t,j,s]),O=n.useCallback(async R=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){d(!0);try{const y=await s(t,"workspace_remove",{id:R});y!=null&&y.success?j("info","Workspace removed"):j("error",(y==null?void 0:y.error)||"workspace_remove failed")}catch(y){j("error",y.message)}finally{d(!1)}}},[t,j,s]),oe=n.useCallback(async R=>{var y;if(t){d(!0);try{const L=await s(t,"workspace_set_default",R===null?{clear:!0}:{id:R});if(L!=null&&L.success){j("info",R?"Default workspace updated":"Default workspace cleared");const h=typeof L.defaultWorkspacePath=="string"?L.defaultWorkspacePath:"";h&&((y=_.current)==null||y.call(_,h))}else j("error",(L==null?void 0:L.error)||"workspace_set_default failed")}catch(L){j("error",L.message)}finally{d(!1)}}},[t,j,s]),ee=n.useCallback(async R=>{var L;if(!t||!R.trim())return;const y=R.trim();d(!0);try{const h=await s(t,"workspace_set_default",{path:y});h!=null&&h.success?(j("info","Default workspace set from history"),(L=_.current)==null||L.call(_,y)):j("error",(h==null?void 0:h.error)||"Could not set default (path missing on disk?)")}catch(h){j("error",h.message)}finally{d(!1)}},[t,j,s]),le=n.useCallback(async()=>{var R;if(t){w(!0);try{const y=await s(t,"get_cli_history",{}),L=(y==null?void 0:y.history)??((R=y==null?void 0:y.result)==null?void 0:R.history);y!=null&&y.success&&Array.isArray(L)&&m(L)}catch{}w(!1)}},[t,s]),ce=n.useCallback(async()=>{if(t)try{await s(t,"set_machine_nickname",{nickname:D}),j("info",`Nickname set to "${D||"(cleared)"}"`),H(!1)}catch(R){j("error",`Failed: ${R.message}`)}},[t,D,j,s]);return{logs:r,launchingIde:c,loadingWorkspaces:x,workspaceBusy:p,loadingHistory:l,cliHistory:f,recentWorkspaces:E,launchPick:b,setLaunchPick:S,editingNickname:W,setEditingNickname:H,nicknameInput:D,setNicknameInput:I,addLog:j,handleLaunchIde:se,runLaunchCliCore:$,handleLaunchCli:Y,handleStopCli:G,handleRestartIde:g,handleStopIde:Q,handleDetectIdes:xe,handleLoadRecentWorkspaces:V,handleWorkspaceAdd:X,handleWorkspaceRemove:O,handleWorkspaceSetDefault:oe,handleWorkspaceResumePath:ee,loadCliHistory:le,handleSaveNickname:ce,setOnDefaultWorkspaceChanged:C}}function jr({machine:t,managedIdes:s,managedClis:a,managedAcps:r,actions:i}){const{workspaceBusy:c,handleWorkspaceAdd:o,handleWorkspaceRemove:x,handleWorkspaceSetDefault:u}=i,[p,d]=n.useState(""),l=t.availableMem??t.freeMem,w=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(pt,{icon:e.jsx(tn,{size:16}),label:"Uptime",value:jn(t.uptime)}),e.jsx(pt,{icon:e.jsx(xt,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(pt,{icon:e.jsx(hs,{size:16}),label:"CLIs",value:`${a.length}`}),e.jsx(pt,{icon:e.jsx(fs,{size:16}),label:"ACPs",value:`${r.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(Yt,{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(Yt,{value:w,max:100,label:"Memory",color:"#3b82f6",detail:`${Gt(t.totalMem-l)} / ${Gt(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(Rt,{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:c,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:p,disabled:c,onChange:m=>d(m.target.value),onKeyDown:m=>m.key==="Enter"&&void(async()=>{await o(p)&&d("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:c,onClick:async()=>{await o(p)&&d("")},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:c,onClick:()=>void x(m.id),children:"Remove"})]},m.id))})]})]})}const wr={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 At({category:t,machine:s,machineId:a,providers:r,managedEntries:i,getIcon:c,actions:o,sendDaemonCommand:x}){const u=ut(),{handleLaunchIde:p,handleLaunchCli:d,handleStopCli:l,handleRestartIde:w,handleStopIde:f,handleDetectIdes:m,cliHistory:E,loadingHistory:A,loadCliHistory:b,launchingIde:S}=o,W=wr[t],H=t==="ide",D=t==="acp",I=r.filter(h=>h.category===t),[_,C]=n.useState(""),[j,se]=n.useState(""),[$,Y]=n.useState(""),[G,g]=n.useState(s.defaultWorkspaceId||""),[Q,xe]=n.useState("");n.useEffect(()=>{!_&&I.length>0&&C(I[0].type)},[_,I.length]),n.useEffect(()=>{s.defaultWorkspaceId&&!G&&g(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const V=(()=>{if(G==="__custom__")return Q.trim();if(!G)return"";const h=(s.workspaces||[]).find(K=>K.id===G);return(h==null?void 0:h.path)||""})(),[X,O]=n.useState({}),[oe,ee]=n.useState(null);n.useEffect(()=>{if(!H||!a||!x)return;(async()=>{try{const K=await x(a,"get_ide_extensions",{}),z=(K==null?void 0:K.result)||K;z!=null&&z.success&&(z!=null&&z.ides)&&O(z.ides)}catch{}})()},[H,a,x]);const le=h=>H?Le(h.type):t==="cli"?h.cliName:h.acpName,ce=H?s.detectedIdes||[]:[],R=()=>{H?p(_,V?{workspace:V}:void 0):d(_,V,j||void 0,D&&$||void 0)},y=h=>{H?f(h):l(h.type,h.workspace,h.id)},L=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:G,onChange:h=>{g(h.target.value),h.target.value!=="__custom__"&&xe("")},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(h=>e.jsxs("option",{value:h.id,children:[h.id===s.defaultWorkspaceId?"⭐ ":"",h.label||h.path.split("/").filter(Boolean).pop()||h.path," — ",h.path]},h.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…"})]})}),G==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:Q,onChange:h=>xe(h.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${W.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",W.label]}),L,H?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ce.map(h=>{const K=h.running||i.some(z=>(z.type||"").toLowerCase()===(h.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>p(h.type||h.id||"",V?{workspace:V}:void 0),disabled:!!S,className:`machine-btn-primary flex items-center gap-1.5 ${K?"!border-green-500/30":""}`,style:{opacity:S&&S!==h.type?.4:1},children:[e.jsx("span",{children:c(h.type)}),K&&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)]"}),S===h.type?"⏳ Launching...":`▶ ${h.name||Le(h.type)}`,K&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},h.type)}),ce.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(Zs,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:_,onChange:h=>C(h.target.value),className:"machine-input",children:I.length>0?I.map(h=>e.jsxs("option",{value:h.type,children:[h.icon," ",h.displayName]},h.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),D&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:$,onChange:h=>Y(h.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:j,onChange:h=>se(h.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:R,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(h=>{const K=H?h:null,z=D?h: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:c(h.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[le(h),(K==null?void 0:K.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",K.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:h.workspace||"—"}),(z==null?void 0:z.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",z.currentModel]}),(z==null?void 0:z.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",z.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 ${h.status==="stopped"?"bg-red-500/[0.08] text-red-500":h.status==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:h.status}),H&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>u(`/ide/${h.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(xt,{size:13})," Control"]}),e.jsx("button",{onClick:()=>w(h),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),D&&e.jsx("button",{onClick:()=>u(`/ide/${h.id}`),className:"machine-btn",title:"View chat",children:e.jsx(jt,{size:14})}),h.status==="stopped"?e.jsx("button",{onClick:()=>H?p(h.type,h.workspace?{workspace:h.workspace}:void 0):d(h.type,h.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>y(h),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),K&&K.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:K.aiAgents.map(me=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${me.status==="generating"||me.status==="streaming"?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[me.name," · ",me.status]},me.id))}),K&&(X[K.type]||[]).length>0&&x&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(X[K.type]||[]).map(me=>e.jsxs("button",{disabled:oe===`${K.type}.${me.type}`,onClick:async()=>{const ye=`${K.type}.${me.type}`;ee(ye);try{await x(a,"set_ide_extension",{ideType:K.type,extensionType:me.type,enabled:!me.enabled}),O(de=>({...de,[K.type]:(de[K.type]||[]).map(ke=>ke.type===me.type?{...ke,enabled:!ke.enabled}:ke)}))}catch(de){console.error("Extension toggle failed:",de)}finally{ee(null)}},className:`flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-[11px] font-medium border transition-colors duration-150 cursor-pointer ${me.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 ${me.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),me.name,e.jsx("span",{className:"text-[9px] font-normal",children:me.enabled?"ON":"OFF"})]},me.type))})]})]},h.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:b,disabled:A,className:"machine-btn",children:A?"⏳":"↻ Load"})]}),(()=>{const h=new Set(I.map(z=>z.type)),K=E.filter(z=>(z.category||"cli")!==t?!1:t==="ide"?!0:h.has(z.cliType));return K.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:K.map((z,me)=>{var ye,de;return e.jsxs("div",{onClick:()=>{C(z.cliType),(z.workspace||z.dir)&&(g("__custom__"),xe(z.workspace||z.dir)),se((z.cliArgs||[]).join(" ")),Y(z.model||""),H&&p(z.cliType,z.workspace?{workspace:z.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:c(z.cliType)}),e.jsx("span",{children:((ye=z.workspace||z.dir)==null?void 0:ye.split("/").filter(Boolean).pop())||z.cliType||"root"}),z.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",z.model]}),z.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((de=z.cliArgs)==null?void 0:de.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:z.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:z.timestamp?new Date(z.timestamp).toLocaleDateString():""})]},me)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",W.label," launch history yet."]})})()]})]})}const ns=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],Nr=[{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 kr({machineId:t,provider:s,sendDaemonCommand:a,onClose:r}){const[i,c]=n.useState("config"),[o,x]=n.useState("codex-cli"),[u,p]=n.useState([]),[d,l]=n.useState(""),[w,f]=n.useState([]),[m,E]=n.useState(""),A=n.useRef(null),b=n.useRef(null),S=C=>{p(j=>j.includes(C)?j.filter(se=>se!==C):[...j,C])},W=()=>p([...ns]),H=()=>p([]);n.useEffect(()=>{var C;(C=A.current)==null||C.scrollIntoView({behavior:"smooth"})},[w]),n.useEffect(()=>()=>{b.current&&clearInterval(b.current)},[]);const D=n.useCallback(()=>{b.current&&clearInterval(b.current),b.current=setInterval(async()=>{try{const C=await a(t,"provider_auto_fix_status",{providerType:s.type});(C==null?void 0:C.running)===!1&&i==="running"&&(c("done"),f(j=>[...j,`
70
- ✅ Auto-fix completed!`]),b.current&&clearInterval(b.current))}catch{}},3e3)},[t,s.type,a,i]),I=async()=>{if(u.length!==0){c("running"),f(["🚀 Starting auto-fix...",`Agent: ${o}`,`Scripts: ${u.join(", ")}`,d?`💬 Comment: ${d}`:"",""]),E("");try{const C=await a(t,"provider_auto_fix",{providerType:s.type,functions:u,agent:o,...d?{comment:d}:{}});C!=null&&C.success&&(C!=null&&C.started||C!=null&&C.running)?(f(j=>[...j,"✅ Agent started. Monitoring progress..."]),D()):(c("error"),E((C==null?void 0:C.error)||"Failed to start auto-fix"))}catch(C){c("error"),E((C==null?void 0:C.message)||"Connection failed")}}},_=async()=>{try{await a(t,"provider_auto_fix_cancel",{providerType:s.type}),f(C=>[...C,`
71
- ⚠️ Auto-fix cancelled.`]),c("done"),b.current&&clearInterval(b.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:r,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:C=>C.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:r,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:Nr.map(C=>e.jsxs("button",{onClick:()=>x(C.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:o===C.value?C.color+"66":"var(--border-subtle)",background:o===C.value?C.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:o===C.value?C.color:"var(--text-primary)"},children:C.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:C.desc})]},C.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:H,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:ns.map(C=>e.jsxs("button",{onClick:()=>S(C),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:u.includes(C)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:u.includes(C)?"rgba(139,92,246,0.08)":"transparent",color:u.includes(C)?"#a78bfa":"var(--text-secondary)"},children:[u.includes(C)?"☑ ":"☐ ",C]},C))})]}),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:d,onChange:C=>l(C.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:[w.map((C,j)=>e.jsx("div",{className:C.startsWith("✅")?"text-green-400":C.startsWith("❌")||C.startsWith("⚠")?"text-amber-400":"",children:C},j)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:A})]}),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:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:I,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:_,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:()=>{c("config"),f([]),E("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function Sr({machineId:t,providers:s,sendDaemonCommand:a,onClose:r,onCreated:i}){var D;const c=s.filter(I=>I.category==="ide"),[o,x]=n.useState(((D=c[0])==null?void 0:D.type)||""),[u,p]=n.useState(""),[d,l]=n.useState(""),[w,f]=n.useState(!1),[m,E]=n.useState(""),[A,b]=n.useState(!1),S=I=>{const _=I.toLowerCase().replace(/[^a-z0-9-]/g,"");p(_),(!d||d===W(u))&&l(W(_))},W=I=>I.split("-").map(_=>_.charAt(0).toUpperCase()+_.slice(1)).join(" "),H=async()=>{if(!(!u||!d||!o)){f(!0),E("");try{const I=await a(t,"provider_clone",{type:u,name:d,category:"ide",location:"user",cloneFrom:o});I!=null&&I.success||I!=null&&I.created?(b(!0),i==null||i(u)):E((I==null?void 0:I.error)||"Failed to create provider")}catch(I){E((I==null?void 0:I.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:r,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:I=>I.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:A?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:c.map(I=>e.jsxs("button",{onClick:()=>x(I.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:o===I.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:o===I.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:I.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:o===I.type?"#a78bfa":"var(--text-secondary)"},children:I.displayName})]},I.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:I=>S(I.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:d,onChange:I=>l(I.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:A?e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"}):e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:H,disabled:!u||!d||w,className:"machine-btn",style:{background:u&&d?"rgba(34,197,94,0.12)":void 0,borderColor:u&&d?"rgba(34,197,94,0.3)":void 0,color:u&&d?"#86efac":void 0,opacity:!u||!d||w?.4:1},children:w?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Cr({machineId:t,providers:s,sendDaemonCommand:a}){const[r,i]=n.useState([]),[c,o]=n.useState(!1),[x,u]=n.useState(null),[p,d]=n.useState("all"),[l,w]=n.useState(null),[f,m]=n.useState(!1),E=n.useCallback(async()=>{var b;if(t){o(!0);try{const S=await a(t,"get_provider_settings",{}),W=(S==null?void 0:S.result)||S;if(S!=null&&S.success&&(W!=null&&W.settings)){const H=[];for(const[D,I]of Object.entries(W.settings)){const _=s.find(C=>C.type===D);H.push({type:D,displayName:(_==null?void 0:_.displayName)||D,icon:(_==null?void 0:_.icon)||"",category:(_==null?void 0:_.category)||"unknown",schema:I,values:((b=W.values)==null?void 0:b[D])||{}})}H.sort((D,I)=>D.category.localeCompare(I.category)||D.displayName.localeCompare(I.displayName)),i(H)}}catch{}o(!1)}},[t,s,a]);n.useEffect(()=>{r.length===0&&E()},[]);const A=async(b,S,W)=>{u(`${b}.${S}`),i(H=>H.map(D=>D.type===b?{...D,values:{...D.values,[S]:W}}:D));try{const H=await a(t,"set_provider_setting",{providerType:b,key:S,value:W});H!=null&&H.success||E()}catch{E()}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(b=>e.jsx("button",{onClick:()=>d(b),className:`machine-btn text-[10px] px-2 py-0.5 ${p===b?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:b.toUpperCase()},b))]}),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:E,disabled:c,className:"machine-btn",children:c?"⏳ Loading...":"↻ Refresh"})]})]}),p!=="all"&&r.filter(b=>b.category===p).length>1&&(()=>{const b=r.filter(D=>D.category===p),S=new Map;for(const D of b)for(const I of D.schema){if(I.type!=="boolean")continue;const _=S.get(I.key),C=!!(D.values[I.key]??I.default);_?(_.onCount+=C?1:0,_.total+=1):S.set(I.key,{label:I.label||I.key,onCount:C?1:0,total:1})}const W=[...S.entries()].filter(([,D])=>D.total===b.length);if(W.length===0)return null;const H=async(D,I)=>{for(const _ of b)await A(_.type,D,I)};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 ",p.toUpperCase()," providers (",b.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:W.map(([D,I])=>{const _=I.onCount===I.total,C=I.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:I.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",I.onCount,"/",I.total,")"]}),e.jsx("button",{onClick:()=>void H(D,!0),disabled:_,className:`machine-btn text-[9px] px-1.5 py-px ${_?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void H(D,!1),disabled:C,className:`machine-btn text-[9px] px-1.5 py-px ${C?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},D)})})]})})(),c&&r.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:r.filter(b=>p==="all"||b.category===p).map(b=>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:b.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:b.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:b.category==="acp"?"rgba(139,92,246,0.08)":b.category==="cli"?"rgba(59,130,246,0.08)":b.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:b.category==="acp"?"#a78bfa":b.category==="cli"?"#60a5fa":b.category==="ide"?"#86efac":"#fbbf24"},children:b.category}),b.category==="ide"&&e.jsx("button",{onClick:()=>w(s.find(S=>S.type===b.type)||{type:b.type,displayName:b.displayName,icon:b.icon,category:b.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:b.schema.map(S=>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:[S.label||S.key,x===`${b.type}.${S.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),S.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:S.description})]}),e.jsx("div",{className:"shrink-0",children:S.type==="boolean"?e.jsx("button",{onClick:()=>A(b.type,S.key,!(b.values[S.key]??S.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:b.values[S.key]??S.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:b.values[S.key]??S.default?21:3}})}):S.type==="number"?e.jsx("input",{type:"number",value:b.values[S.key]??S.default??0,min:S.min,max:S.max,onChange:W=>{const H=parseInt(W.target.value)||0;S.min!==void 0&&H<S.min||S.max!==void 0&&H>S.max||A(b.type,S.key,H)},className:"machine-input w-20 text-center text-[11px]"}):S.type==="select"&&S.options?e.jsx("select",{value:b.values[S.key]??S.default??"",onChange:W=>A(b.type,S.key,W.target.value),className:"machine-input text-[11px]",children:S.options.map(W=>e.jsx("option",{value:W,children:W},W))}):e.jsx("input",{type:"text",value:b.values[S.key]??S.default??"",onBlur:W=>A(b.type,S.key,W.target.value),className:"machine-input w-[120px] text-[11px]"})})]},S.key))})]},b.type))}),l&&e.jsx(kr,{machineId:t,provider:l,sendDaemonCommand:a,onClose:()=>w(null)}),f&&e.jsx(Sr,{machineId:t,providers:s,sendDaemonCommand:a,onClose:()=>m(!1),onCreated:()=>{m(!1),E()}})]})}function Ir({machineId:t,sendDaemonCommand:s}){const[a,r]=n.useState([]),[i,c]=n.useState(0),[o,x]=n.useState(!0),[u,p]=n.useState("debug"),d=n.useRef(null),l=n.useRef(!1);return n.useEffect(()=>{if(!t||!o)return;const w=async()=>{try{const m=await s(t,"get_logs",{count:200,minLevel:u,since:i}),E=(m==null?void 0:m.result)||m;if(m!=null&&m.success&&Array.isArray(E==null?void 0:E.logs)&&E.logs.length>0){r(b=>[...b,...E.logs.map(W=>({timestamp:W.ts,level:W.level,message:`[${W.category}] ${W.message}`}))].slice(-300));const A=Math.max(...E.logs.map(b=>b.ts));c(A)}}catch{}};w();const f=setInterval(w,3e3);return()=>clearInterval(f)},[t,o,i,u,s]),n.useEffect(()=>{if(o&&a.length>0){const w=l.current?"smooth":"instant";setTimeout(()=>{var f;(f=d.current)==null||f.scrollIntoView({behavior:w}),l.current=!0},50)}},[a.length,o]),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(w=>e.jsx("button",{onClick:()=>{p(w),r([]),c(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${u===w?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:w.toUpperCase()},w))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[a.length," entries"]}),e.jsx("button",{onClick:()=>x(!o),className:`machine-btn ${o?"text-green-500 border-green-500/30":""}`,children:o?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),c(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:[a.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),a.map((w,f)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:w.level==="error"?"#ef4444":w.level==="warn"?"#f59e0b":w.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(w.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:w.level==="error"?"#ef4444":w.level==="warn"?"#f59e0b":w.level==="debug"?"#475569":"#8b5cf6"},children:w.level==="error"?"ERR":w.level==="warn"?"WRN":w.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:w.message})]},f)),e.jsx("div",{ref:d})]})]})}function Mr({machine:t,launchPick:s,actions:a}){const{runLaunchCliCore:r,setLaunchPick:i}=a;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(c=>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),r({cliType:s.cliType,workspaceId:c.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:c.label||c.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:c.path})]},c.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),r({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),r({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 Tr(){var H,D,I,_,C,j,se,$,Y,G;const{id:t}=cs(),s=ut(),{sendCommand:a}=Ge(),r=Nt(),i=r.ides||[],c=r.initialLoaded??!0,[o,x]=n.useState("overview"),u=n.useRef(null),p=vr({machineId:t,sendDaemonCommand:a,logsEndRef:u}),d=i.find(g=>g.id===t&&g.daemonMode),l=((d==null?void 0:d.availableProviders)||[]).map(g=>({type:g.type,displayName:g.displayName,icon:g.icon,category:g.category})),w={};for(const g of l)w[g.type]=g.icon;const f=g=>w[g]||"",m=d?{id:d.id,hostname:((H=d.machine)==null?void 0:H.hostname)||d.id,platform:((D=d.machine)==null?void 0:D.platform)||"unknown",arch:((I=d.machine)==null?void 0:I.arch)||"",cpus:((_=d.machine)==null?void 0:_.cpus)||0,totalMem:((C=d.machine)==null?void 0:C.totalMem)||0,freeMem:((j=d.machine)==null?void 0:j.freeMem)||0,availableMem:(se=d.machine)==null?void 0:se.availableMem,loadavg:(($=d.machine)==null?void 0:$.loadavg)||[],uptime:((Y=d.machine)==null?void 0:Y.uptime)||0,release:((G=d.machine)==null?void 0:G.release)||"",cdpConnected:!!(d.ides||[]).some(g=>g.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,E=i.filter(g=>g.daemonId===t&&!g.daemonMode).filter(g=>!Vt(g)&&!Xt(g)).map(g=>({id:g.id,type:g.type,version:g.version||"",instanceId:g.instanceId||"",status:g.status,workspace:g.workspace||null,terminals:g.terminals||0,aiAgents:wn(g.aiAgents||g.agents||[]),activeChat:g.activeChat||null,chats:g.chats||[],agentStreams:g.agentStreams||[],cdpConnected:g.cdpConnected||!1,daemonId:t})),A=i.filter(g=>g.daemonId===t&&Vt(g)).map(g=>({id:g.id,type:g.type,cliName:g.cliName||g.type,status:g.status,workspace:g.workspace||"",activeChat:g.activeChat||null,daemonId:t})),b=i.filter(g=>g.daemonId===t&&Xt(g)).map(g=>({id:g.id,type:g.type,acpName:g.cliName||g.type,status:g.status,workspace:g.workspace||"",activeChat:g.activeChat||null,currentModel:g.currentModel,currentPlan:g.currentPlan,daemonId:t}));if(!m)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:()=>s("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const S=m.machineNickname||m.hostname,W=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(sn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(xt,{size:14})," IDEs"]}),count:E.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ps,{size:14})," CLIs"]}),count:A.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(fs,{size:14})," ACP Agents"]}),count:b.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(xs,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Xs,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"dashboard-header !flex-col !items-stretch",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-2 md:gap-3.5 w-full min-w-0",children:[e.jsx("button",{onClick:()=>s("/machines"),className:"machine-btn-back flex shrink-0",children:"←"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[p.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:p.nicknameInput,onChange:g=>p.setNicknameInput(g.target.value),onKeyDown:g=>{g.key==="Enter"&&p.handleSaveNickname(),g.key==="Escape"&&p.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:p.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>p.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{p.setEditingNickname(!0),p.setNicknameInput(m.machineNickname||"")},title:"Click to set nickname",children:S}),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:[m.platform," · ",m.arch," · ",m.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(t,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",d.serverVersion]}),m.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:m.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:m.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",m.p2p.state==="connected"?`● ${m.p2p.peers}`:"○"]}),m.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 ●"}),m.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",m.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:W.map(g=>e.jsxs("button",{onClick:()=>x(g.id),className:`machine-tab shrink-0${o===g.id?" active":""}`,children:[g.label,g.count!==void 0&&e.jsx("span",{className:"tab-count",children:g.count})]},g.id))})]}),e.jsxs("div",{className:"page-content",children:[o==="overview"&&e.jsx(jr,{machine:m,managedIdes:E,managedClis:A,managedAcps:b,actions:p}),o==="ides"&&e.jsx(At,{category:"ide",machine:m,machineId:t,providers:l,managedEntries:E,getIcon:f,actions:p,sendDaemonCommand:a}),o==="clis"&&e.jsx(At,{category:"cli",machine:m,machineId:t,providers:l,managedEntries:A,getIcon:f,actions:p}),o==="acps"&&e.jsx(At,{category:"acp",machine:m,machineId:t,providers:l,managedEntries:b,getIcon:f,actions:p}),o==="providers"&&e.jsx(Cr,{machineId:t,providers:l,sendDaemonCommand:a}),o==="logs"&&e.jsx(Ir,{machineId:t,sendDaemonCommand:a})]}),p.launchPick&&m&&e.jsx(Mr,{machine:m,launchPick:p.launchPick,actions:p})]})}function Er(){if(typeof window>"u")return"ws://localhost:3847/ws";const s=`${window.location.protocol==="https:"?"wss":"ws"}://${window.location.host}/ws`,r=new URLSearchParams(window.location.search).get("token");return r?`${s}?token=${encodeURIComponent(r)}`:s}const rs=Er(),as=3e3,$r=3e4;let Fe=null,Ar=0;const wt=new Map,Ot=new Set;let qe=null,_r=null,it=null;async function vt(t,s,a){const r=Fe;if(r&&r.readyState===WebSocket.OPEN){const c=`req_${++Ar}_${Date.now()}`;return new Promise((o,x)=>{const u=setTimeout(()=>{wt.delete(c),x(new Error(`WS command timeout: ${s}`))},3e4);wt.set(c,{resolve:p=>{clearTimeout(u),o(p)},reject:p=>{clearTimeout(u),x(p)}}),r.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:a||{},target:t}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:a||{},target:t})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class Rr{constructor(s){Ee(this,"daemonId");Ee(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Fe==null?void 0:Fe.readyState)===WebSocket.OPEN}get connectionState(){return(Fe==null?void 0:Fe.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,a){return vt(this.daemonId,s,a)}async sendInput(s,a){const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId;return vt(r,"cdp_remote_action",{action:s,params:a})}startScreenshots(s){this.screenshotIdeType=s||null,qe&&(clearInterval(qe),qe=null);const a=async()=>{if(this.hasCommandChannel)try{const r=this.screenshotIdeType?`${this.daemonId}:ide:${this.screenshotIdeType}`:this.daemonId,i=await vt(r,"screenshot",{width:1280});if(i!=null&&i.success&&(i!=null&&i.base64)){const c=await fetch(`data:image/jpeg;base64,${i.base64}`).then(o=>o.blob());Ot.forEach(o=>o(this.daemonId,c))}}catch{}};a(),qe=setInterval(a,2e3)}stopScreenshots(s){qe&&(clearInterval(qe),qe=null)}}let Je=null;function Pr(t){(!Je||Je.daemonId!==t)&&(Je=new Rr(t));const s=$e._originalGet||$e.get.bind($e);$e._originalGet=s,$e.get=a=>a===t||a.startsWith("standalone")?Je:s(a),$e.getState=a=>(a===t||a.startsWith("standalone"))&&(Je==null?void 0:Je.connectionState)||"disconnected",$e.onScreenshot=(a,r)=>(Ot.add(r),()=>{Ot.delete(r)})}function Lr({children:t}){const s=n.useRef(Ut()),a=Ut();s.current=a;const{setUserName:r}=ct(),i=n.useRef(r);i.current=r;const[,c]=n.useState("disconnected"),o=n.useCallback((l,w)=>{c(l),it==null||it(l,w)},[]),x=n.useRef(null),u=n.useRef(),p=n.useRef(as),d=n.useRef(!0);return n.useEffect(()=>{d.current=!0;function l(){var m,E;if(!d.current||((m=x.current)==null?void 0:m.readyState)===WebSocket.OPEN||((E=x.current)==null?void 0:E.readyState)===WebSocket.CONNECTING)return;o("connecting"),console.log(`[Standalone WS] Connecting to ${rs}...`);let f;try{f=new WebSocket(rs)}catch(A){console.error("[Standalone WS] Failed to create WebSocket:",A),w();return}x.current=f,f.onopen=()=>{if(!d.current){f.close();return}o("connected"),p.current=as,console.log("[Standalone WS] Connected")},Fe=f,f.onmessage=A=>{var b;try{const S=JSON.parse(A.data);if((S.type==="command_result"||S.type==="error")&&S.requestId){const W=wt.get(S.requestId);W&&(wt.delete(S.requestId),S.type==="error"?W.reject(new Error(((b=S.data)==null?void 0:b.message)||"Command failed")):W.resolve(S.data));return}if(S.type==="pty_output"){$e.emitPtyOutput(S.cliId,S.data);return}if(S.type==="status"||S.type==="initial_state"){const W=S.data;if(!W)return;const{injectEntries:H,markLoaded:D}=s.current,I=W.id||"standalone";_r=I,Pr(I),o("connected",I);const _=Mn(W,{daemonId:I});_.length>0&&H(_),D(),W.userName&&i.current&&i.current(W.userName)}}catch(S){console.error("[Standalone WS] Parse error:",S)}},f.onclose=()=>{d.current&&(o("disconnected"),x.current=null,w())},f.onerror=A=>{console.warn("[Standalone WS] Error, will reconnect:",A)}}function w(){if(!d.current)return;clearTimeout(u.current);const f=p.current;console.log(`[Standalone WS] Reconnecting in ${f}ms...`),u.current=setTimeout(()=>{p.current=Math.min(p.current*1.5,$r),l()},f)}return l(),()=>{d.current=!1,clearTimeout(u.current),x.current&&(x.current.onclose=null,x.current.close(),x.current=null,Fe=null)}},[]),e.jsx(e.Fragment,{children:t})}function Dr({children:t}){const[s,a]=n.useState("disconnected"),[r,i]=n.useState(null);n.useEffect(()=>(it=(o,x)=>{a(o),x&&i(x)},()=>{it=null}),[]);const c=n.useMemo(()=>{const o=s==="connected",x={};return r&&(x[r]=o?"connected":"connecting"),x.standalone=o?"connected":"connecting",{wsStatus:s,isConnected:o,connectionStates:x}},[s,r]);return e.jsx(Fs,{connectionOverrides:c,children:e.jsx(Lr,{children:t})})}const Br=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Gs,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Vs,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(xs,{}),label:"Settings"}];function Wr({children:t}){const s=ut(),a=Rs(),[r,i]=n.useState(!1),[c,o]=n.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),x=d=>{s(d),i(!1)},u=()=>{o(d=>{const l=!d;try{localStorage.setItem("sidebar-collapsed",l?"1":"0")}catch{}return l})},p=d=>`nav-item${a.pathname.startsWith(d)?" active":""} cursor-pointer ${c?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${c?" 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"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:d=>d.key==="Escape"&&i(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${c?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!c&&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:Br.map(d=>e.jsxs("div",{className:p(d.path),id:`nav-${d.id}`,onClick:()=>x(d.path),title:c?d.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:d.icon}),!c&&d.label]},d.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer${a.pathname==="/about"?" active":""} ${c?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:c?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(qs,{})}),!c&&"About"]}),!c&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.6.61"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${c?"justify-center py-2.5 px-0":"mt-1"}`,onClick:u,title:c?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:c?"›":"‹"}),!c&&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 Or=[{icon:"🏠",title:"Local-first",desc:"Everything runs on your machine. No data leaves your network. Full privacy by design."},{icon:"💬",title:"Agent chat relay",desc:"Read and respond to AI conversations in real-time across all connected IDEs."},{icon:"📸",title:"Live screenshots",desc:"View your IDE screens directly in the browser via local WebSocket streaming."},{icon:"🎛️",title:"Remote control",desc:"Click, type, and interact with your IDE from the dashboard — no window switching."},{icon:"🔌",title:"Multi-IDE support",desc:"Monitor and control multiple IDEs simultaneously — VS Code, Cursor, Windsurf, and more."},{icon:"⚡",title:"Extension agents",desc:"Manage extension-based agents like Cline and Roo Code alongside native IDE agents."}],Kr=[{icon:"🌍",title:"Access from anywhere",desc:"Control your agents from any device, any network. No VPN or port forwarding needed."},{icon:"🔗",title:"WebRTC P2P streaming",desc:"End-to-end encrypted peer-to-peer connection for zero-latency remote screenshots and control."},{icon:"📱",title:"Mobile notifications",desc:"Get push notifications when agents need approval. Quick approve/reject from your phone."},{icon:"📡",title:"REST API access",desc:"Integrate with Slack, CI/CD pipelines, or custom tools. Scoped API keys with granular permissions."},{icon:"👥",title:"Team dashboard",desc:"Share a unified view across your team. See who's running what, where, in real time."},{icon:"🔐",title:"Enterprise security",desc:"SSO, RBAC, audit logs, and SLA guarantees for production teams."}],Fr=[{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 agent support",selfhost:!0,cloud:!0},{feature:"CLI agent support",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 & 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}],_t={ides:["VS Code","Cursor","Antigravity","Windsurf","Trae","PearAI","Kiro","VSCodium","VS Code Insiders"],agents:["GitHub Copilot","Cline","Roo Code"],cli:["Gemini CLI","Claude Code","Codex CLI"]};function Hr(){return e.jsxs("div",{className:"py-8 px-6 max-w-[860px] mx-auto text-text-primary",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-14 h-14 mb-3 mx-auto"}),e.jsx("h1",{className:"text-[26px] font-extrabold mb-1.5 text-text-primary",children:"ADHDev"}),e.jsx("p",{className:"text-[13px] text-text-muted",children:"Agent Dashboard Hub for Dev — Self-hosted Edition"}),e.jsxs("div",{className:"inline-block mt-3 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.61"]})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"✅"})," What's included"]}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(250px,1fr))] gap-3",children:Or.map(t=>e.jsxs("div",{className:"bg-bg-glass border border-border-subtle rounded-xl px-4 py-4 transition-colors hover:border-border-default",children:[e.jsx("div",{className:"text-xl mb-1.5",children:t.icon}),e.jsx("div",{className:"font-semibold text-[13px] mb-1",children:t.title}),e.jsx("div",{className:"text-[12px] text-text-muted leading-relaxed",children:t.desc})]},t.title))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsx("h2",{className:"text-lg font-bold mb-4",children:"Compatible with"}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(180px,1fr))] gap-5",children:[{label:"IDEs",items:_t.ides},{label:"Extension agents",items:_t.agents},{label:"CLI agents",items:_t.cli}].map(t=>e.jsxs("div",{children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-2 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1",children:t.items.map(s=>e.jsx("div",{className:"text-[12px] px-2.5 py-1.5 bg-bg-glass rounded-md border border-border-subtle",children:s},s))})]},t.label))})]}),e.jsxs("section",{className:"mb-10",children:[e.jsxs("h2",{className:"text-lg font-bold mb-4 flex items-center gap-2",children:[e.jsx("span",{className:"text-base",children:"⚖️"})," Self-hosted vs Cloud"]}),e.jsx("div",{className:"rounded-xl border border-border-subtle overflow-hidden",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-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[100px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-2.5 font-semibold text-[11px] uppercase tracking-wider w-[100px] text-violet-500",children:"Cloud"})]})}),e.jsx("tbody",{children:Fr.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"",children:[e.jsx("td",{className:"px-4 py-2 text-text-secondary",children:t.feature}),e.jsx("td",{className:"text-center px-4 py-2",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:"text-center px-4 py-2",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})]}),e.jsx("section",{className:"mb-10",children:e.jsx("div",{className:"rounded-2xl border border-violet-500/20 bg-violet-500/[0.04] px-6 py-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"text-3xl shrink-0",children:"🚀"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-bold text-[15px] mb-1.5",children:"Unlock more with ADHDev Cloud"}),e.jsx("p",{className:"text-[13px] text-text-muted leading-relaxed mb-4",children:"Access your agents from anywhere — your phone, another laptop, or a coffee shop. Cloud adds WebRTC P2P streaming, mobile push notifications, REST API, team collaboration, and multi-machine support. Your local setup stays exactly the same."}),e.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(220px,1fr))] gap-2.5 mb-5",children:Kr.map(t=>e.jsxs("div",{className:"flex gap-2.5 items-start",children:[e.jsx("span",{className:"text-base shrink-0 mt-0.5",children:t.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[12px]",children:t.title}),e.jsx("div",{className:"text-[11px] text-text-muted leading-snug",children:t.desc})]})]},t.title))}),e.jsxs("div",{className:"flex gap-3 flex-wrap",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Try ADHDev Cloud →"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"GitHub"}),e.jsx("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex items-center gap-1.5 no-underline",children:"Discord"})]})]})]})})}),e.jsxs("div",{className:"text-center text-xs text-text-muted pt-4 border-t border-border-subtle",children:[e.jsx("p",{children:"© 2026 RacoLab · ADHDev, Your AI sidekick otter 🦦"}),e.jsx("p",{className:"mt-1 opacity-60",children:"Self-hosted edition — all data stays on your machine"})]})]})}function Ur(){const{ides:t}=ct(),s=t.find(l=>l.type==="adhdev-daemon"),a=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=Ge(),{userName:i}=ct(),[c,o]=n.useState(i||"");n.useEffect(()=>{i!==void 0&&o(i)},[i]);const x=l=>{const w=l.target.value.trim();s!=null&&s.id&&w!==i&&r(s.id,"set_user_name",{userName:w}).catch(console.error)},[u,p]=n.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=l=>{p(l);try{localStorage.setItem("adhdev_sound",l?"1":"0")}catch{}};return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Wn,{icon:"⚙️",title:"Settings",subtitle:"Local daemon configuration & preferences"}),e.jsxs("div",{className:"page-content",children:[e.jsx(et,{title:"Daemon",className:"mb-4",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.61"]}),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(et,{title:"Detected IDEs",className:"mb-4",children:a.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:a.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(et,{title:"Machine",className:"mb-4",children:e.jsx(Gn,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(et,{title:"Theme",className:"mb-4",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:"Site theme"}),e.jsx(Zn,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Chat theme"}),e.jsx(rr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Accent color"}),e.jsx(dr,{})]})]})}),e.jsx(et,{title:"Notifications",className:"mb-4",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Yn,{}),e.jsx(tt,{label:"🔊 Sound Effects",description:"Play a sound when agent completes or needs approval",checked:u,onChange:d})]})}),e.jsx(et,{title:"Preferences",className:"mb-4",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.jsx("span",{className:"text-sm font-semibold flex items-center gap-2",children:"👤 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:c,onChange:l=>o(l.target.value),onBlur:x,onKeyDown:l=>{l.key==="Enter"&&l.currentTarget.blur()}})]})})})]})]})}sr();function os(){const{ides:t}=ct(),s=t.find(a=>{var r;return a.daemonMode||((r=a.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(ft,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(ft,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(ft,{to:"/dashboard",replace:!0})}function zr(){return e.jsx(Ps,{children:e.jsx(Dr,{children:e.jsx(Ys,{value:{sendCommand:vt,sendData:()=>!1},children:e.jsx(Wr,{children:e.jsxs(Ls,{children:[e.jsx(Ye,{path:"/dashboard",element:e.jsx(gr,{})}),e.jsx(Ye,{path:"/ide/:id",element:e.jsx(yr,{})}),e.jsx(Ye,{path:"/machine",element:e.jsx(os,{})}),e.jsx(Ye,{path:"/machines/:id",element:e.jsx(Tr,{})}),e.jsx(Ye,{path:"/machines",element:e.jsx(os,{})}),e.jsx(Ye,{path:"/about",element:e.jsx(Hr,{})}),e.jsx(Ye,{path:"/settings",element:e.jsx(Ur,{})}),e.jsx(Ye,{path:"*",element:e.jsx(ft,{to:"/dashboard",replace:!0})})]})})})})})}Ds(document.getElementById("root")).render(e.jsx(n.StrictMode,{children:e.jsx(zr,{})}));