@adhdev/daemon-standalone 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
var rn=Object.defineProperty;var an=(t,s,n)=>s in t?rn(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Re=(t,s,n)=>an(t,typeof s!="symbol"?s+"":s,n);import{r as a,j as e,M as es,a as ts,b as on,c as cn,u as jt,t as ln,d as dn,e as un,f as Ns,R as pn,g as ks,h as xn,B as mn,i as hn,k as qe,N as St,l as fn}from"./vendor-tc3018Wt.js";import{D as gn,o as bn,L as yn}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 o of i)if(o.type==="childList")for(const c of o.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&r(c)}).observe(document,{childList:!0,subtree:!0});function n(i){const o={};return i.integrity&&(o.integrity=i.integrity),i.referrerPolicy&&(o.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?o.credentials="include":i.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(i){if(i.ep)return;i.ep=!0;const o=n(i);fetch(i.href,o)}})();const Ss=a.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}),Cs=a.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function ss(t){var n,r;let s=0;return"activeChat"in t&&(s+=4),(n=t.agentStreams)!=null&&n.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(r=t.agents)!=null&&r.length&&(s+=1),s}function Pt(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},i=s.version??n.version??t.version,o=s.serverVersion??t.serverVersion??n.serverVersion,c=s.versionMismatch===!0||t.versionMismatch===!0;return i&&(r.version=i),o&&(r.serverVersion=o),i&&o&&i===o?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||c&&i&&o&&i!==o)&&(r.versionMismatch=!0),r)}function vn(t,s){var c,d,l,x,u,f,p;const n=Date.now();if(s.length===0)return t.map(b=>({...b,_lastUpdate:n}));const r=new Map;for(const b of s)r.set(b.id,b);for(const b of t){const g=r.get(b.id);if(!g){r.set(b.id,{...b,_lastUpdate:n});continue}const I=ss(b),B=ss(g);if(I>B){const N=(c=b.chats)!=null&&c.length?b.chats:g.chats,j=Pt(g,b,{...g,...b,chats:N,_lastUpdate:n});r.set(b.id,j)}else if(I<B){const N={};if(b.status&&b.status!==g.status&&(N.status=b.status),b.cdpConnected!==void 0&&(N.cdpConnected=b.cdpConnected),(d=b.chats)!=null&&d.length&&!((l=g.chats)!=null&&l.length)&&(N.chats=b.chats),b.machineNickname!==void 0&&b.machineNickname!==g.machineNickname&&(N.machineNickname=b.machineNickname),b.version!==void 0&&(N.version=b.version),b.serverVersion!==void 0&&(N.serverVersion=b.serverVersion),b.versionMismatch===!0&&(N.versionMismatch=!0),Object.keys(N).length>0){const j=Pt(g,b,{...g,...N,_lastUpdate:g._lastUpdate});r.set(b.id,j)}}else{const N=b.timestamp||n,j=g._lastUpdate||g.timestamp||0;if(N>=j){const L=(x=b.chats)!=null&&x.length?b.chats:g.chats,K=Pt(g,b,{...g,...b,chats:L,_lastUpdate:n});r.set(b.id,K)}else(u=b.chats)!=null&&u.length&&!((f=g.chats)!=null&&f.length)&&r.set(b.id,{...g,chats:b.chats})}}const i=new Set(t.map(b=>b.id)),o=new Set;for(const b of t){const g=b.daemonId||((p=b.id)==null?void 0:p.split(":")[0]);g&&o.add(g)}for(const[b,g]of r){const I=g.daemonId||b.split(":")[0];if(!o.has(I))continue;const B=n-(g._lastUpdate||g.timestamp||0);(g.transport==="pty"&&!i.has(b)&&B>1e4||g.transport==="acp"&&!i.has(b)&&B>1e4||g.transport==="cdp-page"&&!i.has(b)&&B>3e4)&&r.delete(b)}for(const[b,g]of r)n-(g._lastUpdate||g.timestamp||0)>3e5&&g.status!=="online"&&r.delete(b);return Array.from(r.values())}function jn({children:t,connectionOverrides:s}){const[n,r]=a.useState([]),[i,o]=a.useState({}),[c,d]=a.useState(!1),[l,x]=a.useState([]),[u,f]=a.useState(void 0),p=a.useCallback((I,B)=>{r(N=>N.map(j=>j.id===I?{...j,chats:B}:j))},[]),b={injectEntries:I=>{r(B=>B.length===0?I:vn(I,B))},markLoaded:()=>d(!0),getIdes:()=>n},g=s;return e.jsx(Cs.Provider,{value:b,children:e.jsx(Ss.Provider,{value:{ides:n,updateIdeChats:p,screenshotMap:i,setScreenshotMap:o,initialLoaded:c,toasts:l,setToasts:x,wsStatus:(g==null?void 0:g.wsStatus)??"connected",isConnected:(g==null?void 0:g.isConnected)??!0,connectionStates:(g==null?void 0:g.connectionStates)??{},connectionTransports:(g==null?void 0:g.connectionTransports)??{},showReconnected:(g==null?void 0:g.showReconnected)??!1,retryConnection:g==null?void 0:g.retryConnection,isP2PActive:(g==null?void 0:g.isP2PActive)??!1,p2pStates:(g==null?void 0:g.p2pStates)??{},userRole:g==null?void 0:g.userRole,userName:u,setUserName:f},children:t})})}function yt(){return a.useContext(Ss)}function ns(){return a.useContext(Cs)}function wn(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;async function i(o,c={}){const d={"Content-Type":"application/json",...c.headers||{}},l=n==null?void 0:n();l&&(d.Authorization=`Bearer ${l}`);const x=o.startsWith("http")?o:`${s}${o.startsWith("/")?"":"/"}${o}`,u=await fetch(x,{...c,headers:d});if(u.status===401)throw r==null||r(),new Error("Unauthorized");if(!u.ok){const f=await u.json().catch(()=>({error:u.statusText}));throw new Error(f.error||`API Error: ${u.status}`)}return u.json()}return{getDaemons:()=>i("/api/v1/daemons"),getDaemonStatus:o=>i(`/api/v1/daemons/${o}/status`),sendCommand:(o,c,d={})=>i(`/api/v1/daemons/${o}/command`,{method:"POST",body:JSON.stringify({type:c,payload:d})}),execTerminal:(o,c,d)=>i(`/api/v1/daemons/${o}/terminal`,{method:"POST",body:JSON.stringify({command:c,name:d})}),sendAgentMessage:(o,c,d)=>i(`/api/v1/shortcuts/${o}/chat`,{method:"POST",body:JSON.stringify({agentType:c,message:d})}),getAgentStatus:o=>i(`/api/v1/shortcuts/${o}/status`),approveAgent:(o,c,d)=>i(`/api/v1/shortcuts/${o}/approve`,{method:"POST",body:JSON.stringify({agentType:c,action:d?"approve":"reject"})}),request:i}}const Nn=wn({baseUrl:"http://localhost:3847"});a.createContext(Nn);const kn={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},Is=a.createContext(kn);function Sn({value:t,children:s}){return e.jsx(Is.Provider,{value:t,children:s})}function st(){return a.useContext(Is)}const Ie={size:18};function Ms({size:t=Ie.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 Ts({size:t=Ie.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 Cn({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M22 21v-2a4 4 0 0 0-3-3.87"}),e.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function In({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"12",cy:"7",r:"4"})]})}function Mn({size:t=Ie.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}function Et({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),e.jsx("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"}),e.jsx("line",{x1:"9",y1:"7",x2:"16",y2:"7"}),e.jsx("line",{x1:"9",y1:"11",x2:"14",y2:"11"})]})}function Tn({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}),e.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"}),e.jsx("line",{x1:"8",y1:"10",x2:"16",y2:"10"}),e.jsx("line",{x1:"8",y1:"14",x2:"14",y2:"14"}),e.jsx("line",{x1:"8",y1:"18",x2:"12",y2:"18"})]})}function Gt({size:t=Ie.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 Es({size:t=Ie.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 As({size:t=Ie.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})})}function dt({size:t=Ie.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}function nt({size:t=Ie.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 _s({size:t=Ie.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 En({size:t=Ie.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 Kt({size:t=Ie.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 $s({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function Jt({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function ut({size:t=Ie.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 Rs({size:t=Ie.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 Ps({size:t=Ie.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 An({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("line",{x1:"18",y1:"20",x2:"18",y2:"10"}),e.jsx("line",{x1:"12",y1:"20",x2:"12",y2:"4"}),e.jsx("line",{x1:"6",y1:"20",x2:"6",y2:"14"})]})}function Zt({size:t=Ie.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 Ls({size:t=Ie.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 Ds({size:t=Ie.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 _n({size:t=Ie.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 $n({size:t=Ie.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 Bs({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),e.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}function Rn({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}function Pn({size:t=Ie.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("polygon",{points:"13 2 3 14 12 14 11 22 21 10 12 10 13 2"})})}function Ln({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("polygon",{points:"11 5 6 9 2 9 2 15 6 15 11 19 11 5"}),e.jsx("path",{d:"M19.07 4.93a10 10 0 0 1 0 14.14M15.54 8.46a5 5 0 0 1 0 7.07"})]})}function Dn({size:t=Ie.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M14.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M9.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M19.35 6.07A16.03 16.03 0 0 0 15 4a.84.84 0 0 0-.46.33 11 11 0 0 0-.74 1.5 15.68 15.68 0 0 0-3.6 0 11.23 11.23 0 0 0-.74-1.5A.84.84 0 0 0 9 4a16.03 16.03 0 0 0-4.35 2.07A16.8 16.8 0 0 0 2 15a16.22 16.22 0 0 0 4 3c.12.08.27.06.37-.04a11.14 11.14 0 0 0 1.2-1.92.35.35 0 0 0-.18-.46 10.4 10.4 0 0 1-1.63-.78.36.36 0 0 1 .03-.6 6.8 6.8 0 0 0 .32-.24.36.36 0 0 1 .37-.04c2.2.98 4.6.98 6.8 0a.36.36 0 0 1 .37.04c.1.08.21.16.32.24a.36.36 0 0 1 .03.6 10.4 10.4 0 0 1-1.63.78.35.35 0 0 0-.18.46c.39.67.8 1.3 1.2 1.92a.37.37 0 0 0 .37.04 16.22 16.22 0 0 0 4-3 16.8 16.8 0 0 0-2.65-8.93z"})]})}function Bn(t){const n=t.split(`
|
|
2
|
-
`).map(d=>{if(!d.includes("\r"))return d;const l=d.split("\r").map(f=>f.trim()).filter(Boolean);if(l.length===0)return"";const x=l.filter(f=>f.startsWith("⏺"));if(x.length>0)return x[x.length-1];const u=l.filter(f=>!(/^[❯›>]\s*$/.test(f)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(f)&&f.length<40||/^[╭╰│├╮╯─═]+$/.test(f)));return u.length>0?u[u.length-1]:l[l.length-1]}).join(`
|
|
3
|
-
`).split(`
|
|
4
|
-
`),r={},i=[];let o=!1;for(const d of n){const l=d.trim();if(l===""){o=!1,i.push("");continue}if(/^❯\s*$/.test(l)||/^>\s*$/.test(l)||/^[✡-✩✪-✿⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇◐◑◒◓]\s*\S+[…\.]{1,3}\s*$/.test(l)||/^◐\s/.test(l)||/\/effort/.test(l)||/^⎿\s+(Tip|Note|Hint):/.test(l)||/^\?\s*(for\s*shortcuts|shortcuts)/.test(l)||/esc\s+to\s+interrupt|shift\+tab\s+to\s+cycle|accept\s+edits\s+on/i.test(l)||/Brewing[…\.]{0,3}\s*\d*$/i.test(l)||/^[✢✳✶✻⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏◆◇✦\s]+$/.test(l)||/^Auto-updating/i.test(l))continue;if(/^[⏺●·⏵]/.test(d)){const u=d.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(u)r[u[1]]=(r[u[1]]||0)+1;else{const f=d.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);f&&(r[f]=(r[f]||0)+1)}o=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(d)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(d)||o&&/^\s{2,}/.test(d))continue;o=!1;const x=d.replace(/^❯\s+/,"");i.push(x)}const c=i.join(`
|
|
5
|
-
`).replace(/\n{3,}/g,`
|
|
6
|
-
|
|
7
|
-
`).trim();return{toolCounts:r,textContent:c,hasTools:Object.keys(r).length>0}}function Lt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}const Wn=a.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:i,isCliMode:o=!1,isWorking:c=!1,contextKey:d="",receivedAtMap:l={},emptyState:x,onLoadMore:u,isLoadingMore:f,hasMoreHistory:p,loadError:b},g){var D;const I=a.useRef(null),B=a.useRef(null),N=a.useRef(0),j=a.useRef(""),L=a.useRef(!1),[K,h]=a.useState(new Set),[T,S]=a.useState(new Set),R=a.useRef(!1),J=()=>{const z=I.current;return z?z.scrollHeight-z.scrollTop-z.clientHeight<200:!0},P=s.length>0?`${s.length}:${(((D=s[s.length-1])==null?void 0:D.content)||"").length}`:"0:0";a.useEffect(()=>{var re,Y;const z=!L.current,V=j.current!==d;if(j.current=d,z||V){L.current=!0,R.current=!1;const ie=()=>{var Ce;(Ce=B.current)==null||Ce.scrollIntoView({behavior:"instant"})};requestAnimationFrame(()=>requestAnimationFrame(ie)),setTimeout(ie,100),setTimeout(ie,300),N.current=s.length;return}s.length>N.current?R.current||(re=B.current)==null||re.scrollIntoView({behavior:"instant"}):J()&&!R.current&&((Y=B.current)==null||Y.scrollIntoView({behavior:"instant"})),N.current=s.length},[P,d,c]),a.useImperativeHandle(g,()=>({scrollToBottom:(z="smooth")=>{var V;(V=B.current)==null||V.scrollIntoView({behavior:z})}})),a.useEffect(()=>{const z=I.current;if(!z)return;let V;const U=()=>{clearTimeout(V),V=setTimeout(()=>{R.current=!J()},50)};return z.addEventListener("scroll",U,{passive:!0}),()=>{z.removeEventListener("scroll",U),clearTimeout(V)}},[]);const M=a.useRef(0),oe=a.useRef(!1);a.useEffect(()=>{const z=I.current;if(!z||!oe.current||M.current===0)return;const V=z.scrollHeight-M.current;V>0&&(z.scrollTop=V),M.current=0,oe.current=!1},[s.length]);const ee=()=>{const z=I.current;z&&(M.current=z.scrollHeight),oe.current=!0,u==null||u()},y=(()=>{const z=s.map((Y,ie)=>({type:"message",data:Y,index:ie,ts:Y.receivedAt||l[Y.id??`i-${ie}`]||0}));if(!n||n.length===0)return z;const V=[...n].sort((Y,ie)=>Y.timestamp-ie.timestamp).map((Y,ie)=>({type:"action",data:Y,index:ie,ts:Y.timestamp})),U=[];let re=0;for(const Y of z){for(;re<V.length&&Y.ts>0&&V[re].ts<Y.ts;)U.push(V[re++]);U.push(Y)}for(;re<V.length;)U.push(V[re++]);return U})(),W=700;return e.jsxs("div",{ref:I,"data-chat-scroll":!0,className:"chat-container",children:[f&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),p&&!f&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:ee,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${b?"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:b?`↻ ${b}`:"↑ Load older messages"})}),y.length===0&&!p&&(x||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),y.map(z=>{var me;if(z.type==="action"){const de=z.data;return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(es,{remarkPlugins:[ts],children:de.text}),e.jsx("span",{className:"action-time",children:Lt(de.timestamp)})]},`action-${z.index}`)}const V=z.data,U=z.index,re=(V.role||"").toLowerCase(),Y=re==="user"||re==="human",ie=V.kind||(re==="tool"?"tool":"standard"),Ce=V.receivedAt||l[V.id??`i-${U}`],xe=`${d}-${U}`,Ee=K.has(xe),v=T.has(xe),m=typeof V.content=="string"?V.content:(V.content||[]).map(de=>de.text||"").join(`
|
|
8
|
-
`);if(ie==="thought"){const de=((me=V.meta)==null?void 0:me.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(_n,{size:13}),e.jsx("span",{children:de})]}),e.jsx("div",{className:"chat-msg-body",children:m})]},`msg-${U}`)}if(ie==="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:m.split(`
|
|
9
|
-
`)[0].slice(0,80)})]},`msg-${U}`);if(ie==="terminal"){const de=V.meta||{},Me=de.isRunning?"⏳":"✅",pe=de.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:Me}),e.jsx("span",{children:pe})]}),e.jsx("pre",{className:"chat-msg-body",children:m})]},`msg-${U}`)}if(ie==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:m.slice(0,100)},`msg-${U}`);const k=!Y&&o?Bn(m):null,E=k?k.textContent:m,ue=k?Object.entries(k.toolCounts):[],le=o&&!Y&&!Ee&&E.length>W,ve=Ee?m:le&&!v?E.slice(0,W):E;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${Y?"self-end":"self-start"}`,children:[ue.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[ue.map(([de,Me])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",de,Me>1?` ×${Me}`:""]},de)),(k==null?void 0:k.hasTools)&&e.jsx("button",{onClick:()=>h(de=>{const Me=new Set(de);return Ee?Me.delete(xe):Me.add(xe),Me}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:Ee?"Collapse":"Original"}),!E&&Ce!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Lt(Ce)})]}),(E||Y)&&e.jsxs("div",{className:`chat-bubble ${Y?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${E?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:Y?i||"You":r}),Ce!=null&&e.jsx("span",{className:"chat-time",children:Lt(Ce)})]}),E&&e.jsx("div",{className:"chat-markdown",children:e.jsx(es,{remarkPlugins:[ts,on,cn],children:ve})}),le&&e.jsx("button",{onClick:()=>S(de=>{const Me=new Set(de);return v?Me.delete(xe):Me.add(xe),Me}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:v?"Collapse ↑":`Show more (${Math.round(E.length/100)*100} chars) ↓`})]})]},`msg-${U}`)}),c&&e.jsx("div",{className:"self-start chat-typing-wrapper",children:e.jsxs("div",{className:"typing-indicator",children:[e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:"Agent generating..."})]})}),e.jsx("div",{className:"min-h-10",ref:B})]})}),rs={background:"#0f1117",foreground:"#cdd6f4",cursor:"#f38ba8",cursorAccent:"#0f1117",selectionBackground:"rgba(166, 227, 161, 0.3)",selectionForeground:"#cdd6f4",black:"#45475a",red:"#f38ba8",green:"#a6e3a1",yellow:"#f9e2af",blue:"#89b4fa",magenta:"#cba6f7",cyan:"#94e2d5",white:"#bac2de",brightBlack:"#585b70",brightRed:"#f38ba8",brightGreen:"#a6e3a1",brightYellow:"#f9e2af",brightBlue:"#89b4fa",brightMagenta:"#cba6f7",brightCyan:"#94e2d5",brightWhite:"#a6adc8"},Ws=a.forwardRef(({onInput:t,onResize:s,fontSize:n=13},r)=>{const i=a.useRef(null),o=a.useRef(null),c=a.useRef(null),[d,l]=a.useState(!1);return a.useImperativeHandle(r,()=>({write:x=>{var u;(u=o.current)==null||u.write(x)},clear:()=>{var x;(x=o.current)==null||x.clear()},fit:()=>{var x;try{(x=c.current)==null||x.fit(),o.current&&(s==null||s(o.current.cols,o.current.rows))}catch{}},bumpResize:()=>{var x;try{(x=c.current)==null||x.fit();const u=o.current;if(!u)return;const f=u.cols,p=u.rows;s==null||s(f+5,p),setTimeout(()=>{s==null||s(f,p)},100)}catch{}}})),a.useEffect(()=>{if(!i.current)return;const x=new gn({cursorBlink:!0,cursorStyle:"bar",fontSize:n,fontFamily:"'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace",fontWeight:"400",letterSpacing:0,lineHeight:1.2,theme:rs,allowTransparency:!0,scrollback:5e3,convertEol:!1}),u=new bn,f=new yn;x.loadAddon(u),x.loadAddon(f),x.open(i.current),requestAnimationFrame(()=>{u.fit(),s==null||s(x.cols,x.rows),l(!0)});const p=x.onData(g=>{t(g)}),b=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{u.fit(),s==null||s(x.cols,x.rows)}catch{}})});return b.observe(i.current),o.current=x,c.current=u,()=>{p.dispose(),b.disconnect(),x.dispose(),o.current=null,c.current=null}},[n]),e.jsx("div",{ref:i,className:"w-full h-full rounded-lg overflow-hidden transition-opacity duration-200",style:{background:rs.background,opacity:d?1:0}})});Ws.displayName="CliTerminal";function wt({label:t,value:s,sub:n,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}),n&&e.jsx("div",{className:"text-[11px] text-text-muted mt-0.5",children:n})]})}function as({value:t,max:s,label:n,color:r="#8b5cf6",detail:i,compact:o=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,d=c>85?"#ef4444":c>60?"#f59e0b":r;return o?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:n}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${c}%`,background:d}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${c}%`,background:`linear-gradient(90deg, ${d}, ${d}cc)`}})}),i&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:i})]})}function On({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:i,transportType:o}){const c=a.useRef(null),d=a.useRef(null),l=a.useRef(null),[x,u]=a.useState(null),[f,p]=a.useState(""),[,b]=a.useState(!1),[g,I]=a.useState([]),B=a.useRef(0),[N,j]=a.useState(!1),[L,K]=a.useState(!1),h=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[T,S]=a.useState(h?"mouse":"touch"),[R,J]=a.useState(1),P=a.useRef(!1),[M,oe]=a.useState(1),[ee,y]=a.useState(0),[W,D]=a.useState(0),z=a.useRef(0),V=a.useRef(t),U=a.useRef(null),re=a.useRef(null),Y=a.useRef(!1),ie=a.useRef(null),Ce=a.useRef(0),xe=a.useRef(null),Ee=a.useRef(1),v=a.useRef({x:0,y:0}),m=a.useRef(!1),k=a.useRef(M),E=a.useRef(ee),ue=a.useRef(W),le=a.useRef(T);a.useEffect(()=>{k.current=M},[M]),a.useEffect(()=>{E.current=ee},[ee]),a.useEffect(()=>{ue.current=W},[W]),a.useEffect(()=>{V.current=t},[t]),a.useEffect(()=>{le.current=T},[T]),a.useEffect(()=>{var O;(O=c.current)==null||O.focus()},[]);const ve=n==="connected",me=r,de=ve?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",Me=ve?"The remote stream is warming up":"Waiting for the remote stream to catch up";a.useEffect(()=>{if(!h||P.current||!me)return;const O=l.current,se=d.current;if(!O||!se)return;const Z=()=>{const je=se.clientWidth,C=se.clientHeight,F=O.naturalWidth,ne=O.naturalHeight;if(!F||!ne||!je||!C)return;const X=Math.min(je/F,C/ne),G=Math.max(je/F,C/ne)/X;G>1.01&&(J(G),oe(G),k.current=G),P.current=!0};O.complete&&O.naturalWidth?Z():O.addEventListener("load",Z,{once:!0})},[me,h]);const pe=.5;a.useEffect(()=>{M<=pe&&(y(0),D(0))},[M,pe]);const he=(O,se,Z)=>{if(Z<=pe)return{x:0,y:0};const je=(Z-1)/(2*Z)*100,C=(Z-1)/(2*Z)*100;return{x:Math.max(-je,Math.min(je,O)),y:Math.max(-C,Math.min(C,se))}},Ne=(O,se)=>{if(!l.current)return null;const Z=l.current.getBoundingClientRect();return!Z.width||!Z.height?null:{nx:Math.max(0,Math.min(1,(O-Z.left)/Z.width)),ny:Math.max(0,Math.min(1,(se-Z.top)/Z.height))}},Pe=(O,se,Z)=>{const je=d.current;if(!je)return;const C=je.getBoundingClientRect(),F=++B.current;I(ne=>[...ne,{id:F,x:O-C.left,y:se-C.top,type:Z}]),setTimeout(()=>I(ne=>ne.filter(X=>X.id!==F)),600)},We=(O,se,Z)=>{const je=l.current,C=d.current;if(!je||!C)return;const F=je.getBoundingClientRect(),ne=C.getBoundingClientRect(),X=je.naturalWidth||F.width,ae=je.naturalHeight||F.height,G=X/ae,q=F.width/F.height;let ge,Q,ke,Te;G>q?(ge=F.width,Q=F.width/G,ke=0,Te=(F.height-Q)/2):(Q=F.height,ge=F.height*G,ke=(F.width-ge)/2,Te=0);const Ae=F.left-ne.left+ke+ge*O,w=F.top-ne.top+Te+Q*se,A=++B.current;I($=>[...$,{id:A,x:Ae,y:w,type:Z}]),setTimeout(()=>I($=>$.filter(_=>_.id!==A)),600)},Oe=async O=>{var Z;const se=Ne(O.clientX,O.clientY);if(se){u(`Click: ${Math.round(se.nx*100)}%, ${Math.round(se.ny*100)}%`),Pe(O.clientX,O.clientY,"left"),(Z=c.current)==null||Z.focus();try{const je=await t("input_click",{nx:se.nx,ny:se.ny});je!=null&&je.success||s(`❌ Click failed: ${je==null?void 0:je.error}`)}catch(je){s(`❌ Click error: ${je.message||je}`)}}},H=async(O,se,Z,je=0)=>{try{await t("input_key",{type:Z?"char":"keyDown",key:O,code:se,text:Z?O:void 0,unmodifiedText:Z?O:void 0,modifiers:je})}catch(C){s(`❌ Key error: ${C.message||C}`)}},be=async O=>{if(O.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(O.key)&&O.preventDefault();let Z=0;O.altKey&&(Z|=1),O.ctrlKey&&(Z|=2),O.metaKey&&(Z|=4),O.shiftKey&&(Z|=8),u(`Key: ${O.key}`),await H(O.key,O.code,O.key.length===1,Z)},fe=async O=>{if(O.key==="Enter"){if(O.nativeEvent.isComposing)return;if(f){const se=f;p(""),u(`IME Sent: ${se}`);try{const Z=await t("input_type",{text:se});Z!=null&&Z.success||s(`❌ IME error: ${Z==null?void 0:Z.error}`)}catch(Z){s(`❌ IME error: ${Z.message}`)}}else u("Key: Enter"),await H("Enter","Enter",!1)}};a.useEffect(()=>{const O=c.current;if(!O)return;const se=Z=>{var je;if((je=l.current)!=null&&je.contains(Z.target)){Z.preventDefault();const C=Date.now();if(C-z.current<40)return;z.current=C;const F=Ne(Z.clientX,Z.clientY);if(!F)return;u(`Scroll: ${Math.round(Z.deltaY)}`),t("input_wheel",{nx:F.nx,ny:F.ny,deltaX:Math.round(Z.deltaX),deltaY:Math.round(Z.deltaY)}).catch(()=>{})}};return O.addEventListener("wheel",se,{passive:!1}),()=>O.removeEventListener("wheel",se)},[t]);const[ye,_e]=a.useState(null),Se=a.useRef(null);return a.useEffect(()=>{if(T==="mouse"&&!Se.current){const O={nx:.5,ny:.5};Se.current=O,_e(O)}},[T]),a.useEffect(()=>{const O=c.current;if(!O)return;const se=X=>{if(!l.current)return null;const ae=l.current.getBoundingClientRect();return!ae.width||!ae.height?null:{nx:Math.max(0,Math.min(1,(X.clientX-ae.left)/ae.width)),ny:Math.max(0,Math.min(1,(X.clientY-ae.top)/ae.height))}},Z=(X,ae)=>{if(!l.current)return{dnx:0,dny:0};const G=l.current,q=G.getBoundingClientRect(),ge=G.naturalWidth||q.width,Q=G.naturalHeight||q.height,ke=ge/Q,Te=q.width/q.height;let Ae,w;return ke>Te?(Ae=q.width,w=q.width/ke):(w=q.height,Ae=q.height*ke),{dnx:X/Ae,dny:ae/w}},je=(X,ae,G)=>{if(G<=1.05)return;const q=-(X-.5)*100,ge=-(ae-.5)*100,Q=he(q,ge,G);(Math.abs(Q.x-E.current)>.1||Math.abs(Q.y-ue.current)>.1)&&(y(Q.x),D(Q.y),E.current=Q.x,ue.current=Q.y)},C=X=>{const ae=d.current;if(ae&&X.target instanceof Node&&ae.contains(X.target))X.preventDefault();else return;if(X.touches.length===1){const G=X.touches[0];U.current={x:G.clientX,y:G.clientY,time:Date.now()},re.current={x:G.clientX,y:G.clientY},m.current||(Y.current=!1),ie.current=setTimeout(()=>{if(!Y.current&&!m.current)if(Y.current=!0,le.current==="mouse"){const q=Se.current||{nx:.5,ny:.5};u("Right Click"),We(q.nx,q.ny,"right"),V.current("input_click",{...q,button:"right"}).catch(()=>{})}else{const q=se(G);q&&(u("Right Click"),We(q.nx,q.ny,"right"),V.current("input_click",{...q,button:"right"}).catch(()=>{}))}},500)}else if(X.touches.length===2){clearTimeout(ie.current),Y.current=!0,m.current=!0;const G=X.touches[1].clientX-X.touches[0].clientX,q=X.touches[1].clientY-X.touches[0].clientY;xe.current=Math.sqrt(G*G+q*q),Ee.current=k.current,v.current={x:(X.touches[0].clientX+X.touches[1].clientX)/2,y:(X.touches[0].clientY+X.touches[1].clientY)/2}}},F=X=>{const ae=d.current;if(ae&&X.target instanceof Node&&ae.contains(X.target)&&X.preventDefault(),X.touches.length===1&&re.current){const G=X.touches[0],q=G.clientX-re.current.x,ge=G.clientY-re.current.y;if(!Y.current&&U.current){const Q=G.clientX-U.current.x,ke=G.clientY-U.current.y;Math.sqrt(Q*Q+ke*ke)>8&&(Y.current=!0,clearTimeout(ie.current))}if(Y.current)if(le.current==="mouse"){const Q=Z(q,ge),ke=Se.current||{nx:.5,ny:.5},Te=Math.max(0,Math.min(1,ke.nx+Q.dnx)),Ae=Math.max(0,Math.min(1,ke.ny+Q.dny));Se.current={nx:Te,ny:Ae},_e({nx:Te,ny:Ae}),u(`Cursor: ${Math.round(Te*100)}%, ${Math.round(Ae*100)}%`),je(Te,Ae,k.current);const w=Date.now();w-z.current>=30&&(z.current=w,V.current("input_mouseMoved",{nx:Te,ny:Ae}).catch(()=>{}))}else if(k.current>1){const Q=d.current;if(Q){const ke=Q.clientWidth,Te=Q.clientHeight,Ae=E.current+q/ke*100,w=ue.current+ge/Te*100,A=he(Ae,w,k.current);y(A.x),D(A.y),E.current=A.x,ue.current=A.y}}else{const Q=se(G);if(Q){const ke=Date.now();ke-z.current>=40&&(z.current=ke,u("Scroll"),V.current("input_wheel",{nx:Q.nx,ny:Q.ny,deltaX:Math.round(-q*2.5),deltaY:Math.round(-ge*2.5)}).catch(()=>{}))}}re.current={x:G.clientX,y:G.clientY}}else if(X.touches.length===2&&xe.current!==null){const G=X.touches[1].clientX-X.touches[0].clientX,q=X.touches[1].clientY-X.touches[0].clientY,Q=Math.sqrt(G*G+q*q)/xe.current,ke=(X.touches[0].clientX+X.touches[1].clientX)/2,Te=(X.touches[0].clientY+X.touches[1].clientY)/2,Ae=ke-v.current.x,w=Te-v.current.y,A=Math.abs(Q-1)>.03;if(le.current==="mouse"){if(A){const $=Math.max(pe,Math.min(5,Ee.current*Q));oe($),k.current=$}else if(Math.abs(Ae)>2||Math.abs(w)>2){const $=Se.current||{nx:.5,ny:.5},_=Date.now();_-z.current>=30&&(z.current=_,u("Scroll"),V.current("input_wheel",{nx:$.nx,ny:$.ny,deltaX:Math.round(-Ae*3),deltaY:Math.round(-w*3)}).catch(()=>{}))}}else{const $=Math.max(pe,Math.min(5,Ee.current*Q));oe($),k.current=$;const _=d.current;if(_&&$>1){const te=_.clientWidth,ce=_.clientHeight,we=E.current+Ae/te*100,$e=ue.current+w/ce*100,ze=he(we,$e,$);y(ze.x),D(ze.y),E.current=ze.x,ue.current=ze.y}}v.current={x:ke,y:Te}}},ne=X=>{var ae;if(clearTimeout(ie.current),xe.current=null,X.touches.length===1&&m.current){const G=X.touches[0];U.current={x:G.clientX,y:G.clientY,time:Date.now()},re.current={x:G.clientX,y:G.clientY},Y.current=!0;return}if(X.touches.length===0){if(m.current){m.current=!1,Y.current=!1;return}if(X.changedTouches.length===1&&!Y.current){const G=X.changedTouches[0],q=Date.now(),ge=q-(((ae=U.current)==null?void 0:ae.time)||0);if(ge<60||ge>400){Y.current=!1;return}if(U.current){const Q=G.clientX-U.current.x,ke=G.clientY-U.current.y;if(Math.sqrt(Q*Q+ke*ke)>12){Y.current=!1;return}}if(le.current==="mouse"){const Q=Se.current||se(G);Q&&(u(`Click: ${Math.round(Q.nx*100)}%, ${Math.round(Q.ny*100)}%`),We(Q.nx,Q.ny,"left"),V.current("input_click",{...Q}).catch(()=>{}))}else{const Q=se(G);if(!Q)return;q-Ce.current<300?(u("Double tap"),We(Q.nx,Q.ny,"double"),V.current("input_click",{...Q,clickCount:2}).catch(()=>{}),Ce.current=0):(u(`Tap: ${Math.round(Q.nx*100)}%, ${Math.round(Q.ny*100)}%`),We(Q.nx,Q.ny,"left"),V.current("input_click",{...Q}).catch(()=>{}),Ce.current=q)}}Y.current=!1}};return O.addEventListener("touchstart",C,{passive:!1}),O.addEventListener("touchmove",F,{passive:!1}),O.addEventListener("touchend",ne,{passive:!1}),()=>{O.removeEventListener("touchstart",C),O.removeEventListener("touchmove",F),O.removeEventListener("touchend",ne),clearTimeout(ie.current)}},[]),e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:be,onContextMenu:O=>O.preventDefault(),onFocus:()=>b(!0),onBlur:()=>b(!1),tabIndex:0,children:[e.jsxs("div",{ref:d,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[me?e.jsx("img",{ref:l,src:me,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${M}) translate(${ee}%, ${W}%)`,transformOrigin:"center center",cursor:T==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:Oe,onContextMenu:O=>O.preventDefault(),onDragStart:O=>O.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:de}),e.jsx("div",{className:"text-[11px] text-white/40",children:Me}),o==="relay"&&e.jsx("div",{className:"text-[10px] text-amber-300/80",children:"TURN relay active"})]}),T==="mouse"&&ye&&me&&l.current&&(()=>{var Ae;const O=l.current,se=O.getBoundingClientRect(),Z=(Ae=d.current)==null?void 0:Ae.getBoundingClientRect();if(!Z)return null;const je=O.naturalWidth||se.width,C=O.naturalHeight||se.height,F=je/C,ne=se.width/se.height;let X,ae,G,q;F>ne?(X=se.width,ae=se.width/F,G=0,q=(se.height-ae)/2):(ae=se.height,X=se.height*F,G=(se.width-X)/2,q=0);const ge=se.left-Z.left+G+X*ye.nx,Q=se.top-Z.top+q+ae*ye.ny,ke=Math.max(8,Math.min(Z.width-8,ge)),Te=Math.max(8,Math.min(Z.height-8,Q));return e.jsxs("div",{style:{position:"absolute",left:ke-8,top:Te-8,width:16,height:16,pointerEvents:"none",zIndex:100},children:[e.jsx("div",{style:{position:"absolute",left:7,top:0,width:2,height:16,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:0,top:7,width:16,height:2,background:"rgba(59,130,246,0.8)"}}),e.jsx("div",{style:{position:"absolute",left:5,top:5,width:6,height:6,borderRadius:"50%",background:"#3b82f6",boxShadow:"0 0 8px rgba(59,130,246,0.6)"}})]})})(),g.map(O=>{const Z={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[O.type];return e.jsxs("div",{style:{position:"absolute",left:O.x,top:O.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${Z}, 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(${Z}, 0.9)`,boxShadow:`0 0 12px rgba(${Z}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},O.id)})]}),e.jsxs("div",{onTouchStart:O=>O.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:()=>{S(O=>{const se=O==="touch"?"mouse":"touch";if(se==="mouse"&&!Se.current){const Z={nx:.5,ny:.5};Se.current=Z,_e(Z)}return se})},className:`h-8 px-2.5 rounded-lg flex items-center gap-[5px] cursor-pointer ${T==="mouse"?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:[e.jsx("span",{className:"text-sm",children:T==="mouse"?"🖱️":"👆"}),e.jsx("span",{className:`text-[10px] font-bold ${T==="mouse"?"text-blue-400":"text-slate-400"}`,children:T==="mouse"?"Mouse":"Touch"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{onClick:()=>{K(!L),j(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${L?"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:"⌨️"})}),L&&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:f,autoFocus:!0,onTouchStart:O=>O.stopPropagation(),onChange:O=>p(O.target.value),onKeyDown:fe,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:()=>{j(!N),K(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${N?"bg-blue-500/25 border border-blue-500/40":"bg-white/[0.08] border border-white/10"}`,children:e.jsx("span",{className:"text-sm",children:"⚙️"})})}),e.jsx("div",{className:"w-px h-[18px] bg-white/10"}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-0.5 px-1.5 py-0.5 rounded-md",style:{background:ve?"rgba(34,197,94,0.12)":"rgba(234,179,8,0.12)"},children:[e.jsx("div",{className:"w-1 h-1 rounded-full",style:{background:ve?"#22c55e":"#eab308",boxShadow:ve?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:ve?"#22c55e":"#eab308"},children:ve?"Connected":"WS"})]}),M>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(M*100),"%"]}),o==="direct"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#22c55e",background:"rgba(34,197,94,0.12)"},title:"Direct P2P connection",children:"Direct"}),o==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"#f59e0b",background:"rgba(245,158,11,0.12)"},title:"TURN relay in use",children:"Relay"}),i&&i.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:i.budgetExhausted?"#ef4444":"#c4b5fd",background:i.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:i.budgetExhausted?"TURN blocked":`TURN ${i.dailyUsedMinutes}/${i.dailyBudgetMinutes}m`}),x&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:x})]})]}),N&&e.jsxs("div",{onTouchStart:O=>O.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: ",M<=(h?R:1)+.01?h?"FILL":"FIT":`${Math.round(M*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:O=>{O.stopPropagation(),oe(se=>Math.max(.5,se-.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:O=>{O.stopPropagation();const se=h?R:1;oe(se),k.current=se,y(0),D(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:h?"FILL":"FIT"}),e.jsx("button",{onClick:O=>{O.stopPropagation(),oe(se=>Math.min(5,se+.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 zn({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:i,onDismiss:o,onClickAt:c,onKeyDown:d,badge:l,emptyMessage:x,aspectRatio:u,className:f,style:p}){const b=a.useRef(null),g=a.useCallback(I=>{if(!r||!c||!b.current)return;const B=b.current,N=B.getBoundingClientRect(),j=(I.clientX-N.left)/N.width*B.naturalWidth,L=(I.clientY-N.top)/N.height*B.naturalHeight;c(j,L,B.naturalWidth,B.naturalHeight)},[r,c]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${f||""}`,style:{aspectRatio:u||"16/9",...p},children:[e.jsx("img",{ref:b,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),o&&e.jsx("button",{onClick:o,className:"absolute top-2.5 right-2.5 bg-black/50 border-none text-white w-5 h-5 rounded-full text-[10px] z-10 cursor-pointer flex items-center justify-center",children:"✕"})]}):null:t?e.jsxs("div",{className:`${r?"screenshot-interactive":""} ${f||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?d:void 0,style:p,children:[e.jsx("img",{ref:b,src:t,alt:"IDE Screenshot",onClick:r?g:void 0,className:"max-w-full max-h-full object-contain",style:{...r?{cursor:"crosshair"}:{},...n!==100?{transform:`scale(${n/100})`,transformOrigin:"center center"}:{}}}),l&&e.jsx("div",{className:"absolute bottom-4 left-1/2 -translate-x-1/2 bg-black/70 text-white px-3.5 py-1.5 rounded-[20px] text-xs font-semibold backdrop-blur-sm",children:l})]}):e.jsxs("div",{className:`flex items-center justify-center flex-col gap-2 h-full text-text-muted ${f||""}`,style:p,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:x||"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 Kn({activeConv:t,onModalButton:s}){const[n,r]=a.useState(null);if(a.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const i=c=>{n||(r(c),s(c))},o=c=>c.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"bg-gradient-to-br from-amber-600 to-amber-700 text-white py-2.5 px-4 shrink-0 z-[5]",children:[t.modalMessage&&e.jsx("div",{className:"text-[11px] opacity-85 mb-1.5 whitespace-nowrap overflow-hidden text-ellipsis max-w-full",children:t.modalMessage.replace(/[\n\r]+/g," ").slice(0,120)}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"font-black text-xs flex items-center gap-2",children:[e.jsx(Jt,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((c,d)=>{const l=o(c).toLowerCase(),x=/^(run|approve|accept|yes|allow|always)/.test(l),u=/^(reject|deny|delete|remove|abort)/.test(l),f=n===c,p=n!==null;return e.jsx("button",{onClick:()=>i(c),disabled:p,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${x?"bg-white text-amber-700 font-extrabold":u?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${p&&!f?"opacity-40":"opacity-100"} ${p?"cursor-not-allowed":"cursor-pointer"}`,children:f?"⏳ ...":o(c)},d)})})]})]})}const Fe=new Map;function Fn({ideId:t,sessionId:s,ideType:n,agentType:r,agentName:i,serverModel:o,serverMode:c,acpConfigOptions:d,acpModes:l}){var Ee;const{sendCommand:x}=st(),u=!!(d||l),f=`${t}:${r}`,p=Fe.get(f),[b,g]=a.useState(!1),[I,B]=a.useState(!1),[N,j]=a.useState((p==null?void 0:p.models)||[]),[L,K]=a.useState((p==null?void 0:p.modes)||[]),h=v=>v?typeof v=="string"?v:typeof v=="object"?v.name||v.id||JSON.stringify(v):String(v):"",[T,S]=a.useState(h(o)),[R,J]=a.useState(h(c)),[P,M]=a.useState(!1),[oe,ee]=a.useState(!1),y=a.useRef(0),W=v=>v.map(m=>typeof m=="string"?m:(m==null?void 0:m.name)||(m==null?void 0:m.id)||String(m));a.useEffect(()=>{if(d){const v=d.find(m=>m.category==="model");if(v){const m=W(v.options.map(E=>E.value));j(m),v.currentValue&&S(h(v.currentValue));const k=Fe.get(f)||{models:[],modes:[]};Fe.set(f,{...k,models:m})}}if(l&&l.length>0){const v=W(l.map(k=>k.id));K(v);const m=Fe.get(f)||{models:[],modes:[]};Fe.set(f,{...m,modes:v})}else if(d){const v=d.find(m=>m.category!=="model");if(v){const m=W(v.options.map(E=>E.value));K(m),v.currentValue&&J(h(v.currentValue));const k=Fe.get(f)||{models:[],modes:[]};Fe.set(f,{...k,modes:m})}}},[d,l,f]),a.useEffect(()=>{g(!1),B(!1),S(h(o)),J(h(c));const v=Fe.get(f);v?(j(v.models),K(v.modes)):(j([]),K([]))},[t,r]),a.useEffect(()=>{o&&Date.now()>y.current&&S(h(o))},[o]),a.useEffect(()=>{c&&Date.now()>y.current&&J(h(c))},[c]);const D=a.useCallback(async(v,m={})=>{const k={...m,...s&&{targetSessionId:s}};return await x(t,v,k)},[t,s,x]),z=async()=>{var v,m;if(N.length>0){g(!b);return}if(u){g(!0);return}M(!0);try{const k=await D("list_extension_models",{agentType:r,ideType:n}),E=(k==null?void 0:k.models)||((v=k==null?void 0:k.result)==null?void 0:v.models)||[],ue=W(E);j(ue),k!=null&&k.current&&S(h(k.current)),(m=k==null?void 0:k.result)!=null&&m.current&&S(h(k.result.current));const le=Fe.get(f)||{models:[],modes:[]};Fe.set(f,{...le,models:ue}),g(!0)}catch{}finally{M(!1)}},V=async()=>{var v,m;if(L.length>0){B(!I);return}if(u){B(!0);return}ee(!0);try{const k=await D("list_extension_modes",{agentType:r,ideType:n}),E=(k==null?void 0:k.modes)||((v=k==null?void 0:k.result)==null?void 0:v.modes)||[],ue=W(E);K(ue),k!=null&&k.current&&J(h(k.current)),(m=k==null?void 0:k.result)!=null&&m.current&&J(h(k.result.current));const le=Fe.get(f)||{models:[],modes:[]};Fe.set(f,{...le,modes:ue}),B(!0)}catch{}finally{ee(!1)}},U=async v=>{g(!1),S(v),y.current=Date.now()+5e3;try{u?await D("change_model",{agentType:r,ideType:n,model:v}):await D("set_extension_model",{agentType:r,ideType:n,model:v})}catch{}},re=u&&!(l&&l.length>0)&&(d==null?void 0:d.some(v=>v.category!=="model")),Y=re?(Ee=d==null?void 0:d.find(v=>v.category!=="model"))==null?void 0:Ee.configId:void 0,ie=async v=>{B(!1),J(v),y.current=Date.now()+5e3;try{u&&re&&Y?await D("set_thought_level",{agentType:r,ideType:n,configId:Y,value:v}):u?await D("set_mode",{agentType:r,ideType:n,mode:v}):await D("set_extension_mode",{agentType:r,ideType:n,mode:v})}catch{}},xe={cline:"#22d3ee","roo-code":"#a78bfa",cursor:"#60a5fa",antigravity:"#f97316",windsurf:"#34d399"}[r]||"#94a3b8";return e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 flex-wrap text-[10px] border-t border-border-subtle bg-[var(--surface-primary)]",children:[e.jsx("span",{className:"text-[9px] font-bold tracking-wide uppercase opacity-70",style:{color:xe},children:i}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:b?`${xe}55`:"transparent",border:"1px solid",color:T?"var(--text-primary)":"var(--text-muted)"},onClick:z,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),P?"...":T||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),b&&N.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>g(!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"}),N.map(v=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:v===T?`${xe}18`:"transparent",color:v===T?xe:"var(--text-secondary)",fontWeight:v===T?600:400,borderLeft:v===T?`2px solid ${xe}`:"2px solid transparent"},onMouseEnter:m=>{m.currentTarget.style.background=`${xe}12`},onMouseLeave:m=>{m.currentTarget.style.background=v===T?`${xe}18`:"transparent"},onClick:()=>U(v),children:v},v))]})]})]}),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:I?`${xe}55`:"transparent",border:"1px solid",color:R?"var(--text-primary)":"var(--text-muted)"},onClick:V,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:re?"🧠":"⚡"}),oe?"...":R||(re?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),I&&L.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>B(!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:re?"SELECT THINKING LEVEL":"SELECT MODE"}),L.map(v=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:v===R?`${xe}18`:"transparent",color:v===R?xe:"var(--text-secondary)",fontWeight:v===R?600:400,borderLeft:v===R?`2px solid ${xe}`:"2px solid transparent"},onMouseEnter:m=>{m.currentTarget.style.background=`${xe}12`},onMouseLeave:m=>{m.currentTarget.style.background=v===R?`${xe}18`:"transparent"},onClick:()=>ie(v),children:v},v))]})]})]})]})}const He=t=>t.transport==="pty",Be=t=>t.transport==="acp";function Os({activeConv:t,ides:s,agentInput:n,setAgentInput:r,handleSendChat:i,isSendingChat:o=!1,handleFocusAgent:c,isFocusingAgent:d,messageReceivedAt:l,actionLogs:x,userName:u}){const f=a.useRef(null),{sendCommand:p}=st(),b=a.useRef(new Map),g=a.useCallback(P=>(b.current.has(P)||b.current.set(P,{messages:[],offset:0,hasMore:!0,error:null}),b.current.get(P)),[]),I=a.useCallback((P,M)=>{const oe=g(P);b.current.set(P,{...oe,...M}),B(ee=>ee+1)},[g]),[,B]=a.useState(0),N=t.tabKey,j=g(N),L=j.messages,K=j.hasMore,h=j.error,[T,S]=a.useState(!1),R=a.useCallback(async()=>{var oe,ee;if(T)return;const P=t.tabKey,M=g(P);S(!0),I(P,{error:null});try{const y=s.find(U=>U.id===t.ideId),W=(y==null?void 0:y.daemonId)||((oe=t.ideId)==null?void 0:oe.split(":")[0])||"";if(!W){I(P,{hasMore:!1});return}const D=t.ideType||t.agentType||"",z=await p(W,"chat_history",{agentType:D,offset:M.offset,limit:30,targetSessionId:t.sessionId}),V=(z==null?void 0:z.result)??z;if(((ee=V.messages)==null?void 0:ee.length)>0){const U=g(P);I(P,{messages:[...V.messages,...U.messages],offset:U.offset+V.messages.length,hasMore:!!V.hasMore})}else I(P,{hasMore:!!V.hasMore})}catch(y){const W=(y==null?void 0:y.message)||"";W.includes("P2P not available")||W.includes("channel not open")||W.includes("P2P not connected")||W.includes("timeout")?I(P,{error:"Connection not ready — tap to retry"}):I(P,{hasMore:!1,error:"Failed to load history"})}finally{S(!1)}},[T,s,t,p,g,I]),J=(()=>{const P=t.messages.map((ee,y)=>{const W=`${t.ideId}-${ee.id??`i-${y}`}`;return{...ee,receivedAt:ee.receivedAt||l[W]||0}});if(L.length===0)return P;const M=new Set(P.map(ee=>`${ee.role}:${(ee.content||"").slice(0,100)}`));return[...L.filter(ee=>!M.has(`${ee.role}:${(ee.content||"").slice(0,100)}`)),...P]})();return e.jsxs(e.Fragment,{children:[e.jsx(Wn,{messages:J,actionLogs:x.filter(P=>P.ideId===t.tabKey).sort((P,M)=>P.timestamp-M.timestamp),agentName:t.agentName||t.displayPrimary||"Agent",userName:u,isCliMode:He(t)||Be(t),isWorking:t.status==="generating",contextKey:t.tabKey,onLoadMore:R,isLoadingMore:T,hasMoreHistory:K,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(ut,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:c,disabled:d,className:"btn btn-primary",children:d?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Kt,{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(Rs,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:c,disabled:d,className:"btn btn-primary",children:d?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Kt,{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"&&!T?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}),!He(t)&&(()=>{var M,oe,ee,y;const P=s.find(W=>W.id===t.ideId);return e.jsx(Fn,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,agentType:t.streamSource==="agent-stream"?t.agentType:((oe=(M=P==null?void 0:P.agents)==null?void 0:M[0])==null?void 0:oe.type)||t.ideType,agentName:t.streamSource==="agent-stream"?t.agentName:((y=(ee=P==null?void 0:P.agents)==null?void 0:ee[0])==null?void 0:y.name)||t.agentName,serverModel:(P==null?void 0:P.currentModel)||void 0,serverMode:(P==null?void 0:P.currentPlan)||void 0,acpConfigOptions:Be(t)?P==null?void 0:P.acpConfigOptions:void 0,acpModes:Be(t)?P==null?void 0:P.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:f,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:n,onChange:P=>r(P.target.value),onPaste:P=>{const M=P.clipboardData.getData("text");M&&r(oe=>oe+M),P.preventDefault()},onKeyDown:P=>{if(P.key==="Enter"){if(P.nativeEvent.isComposing){P.preventDefault();return}P.preventDefault(),i()}},onBlur:P=>{if(window.innerWidth<768){const M=P.relatedTarget;if((M==null?void 0:M.tagName)==="BUTTON")return;setTimeout(()=>{document.documentElement.scrollTop=0},300)}},className:"w-full h-10 rounded-[20px] px-4 bg-bg-secondary text-sm text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:i,disabled:!n.trim()||o,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${n.trim()&&!o?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:n.trim()&&!o?{background:"var(--chat-send-bg, var(--accent-primary))"}:void 0,children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:n.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}const Dt=new Set,zs={emit(t,s){for(const n of Dt)n(t,s)},on(t){return Dt.add(t),()=>{Dt.delete(t)}}};function Hn({activeConv:t,ptyBuffers:s,terminalRef:n,agentInput:r,setAgentInput:i,handleSendChat:o,isSendingChat:c=!1}){const d=a.useRef(null),{sendCommand:l,sendData:x}=st(),u=t.tabKey,f=t.sessionId||"";return a.useEffect(()=>{const p=s.current.get(u);if(p&&p.length>0){const b=setTimeout(()=>{var g;for(const I of p)(g=n.current)==null||g.write(I);requestAnimationFrame(()=>{var I;(I=n.current)==null||I.bumpResize()})},100);return()=>clearTimeout(b)}},[u]),a.useEffect(()=>{const p=zs.on((b,g)=>{var B;if(!g)return;(b===f||b===t.ideId||b===t.tabKey)&&((B=n.current)==null||B.write(g))});return()=>{p()}},[f,t.ideId,t.tabKey]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:e.jsx(Ws,{ref:n,onInput:p=>{const b=t.ideId||t.daemonId||"";x!=null&&x(b,{type:"pty_input",targetSessionId:f,data:p})||l(b,"pty_input",{targetSessionId:f,data:p}).catch(console.error)},onResize:(p,b)=>{const g=t.ideId||t.daemonId||"";x!=null&&x(g,{type:"pty_resize",targetSessionId:f,cols:p,rows:b})||l(g,"pty_resize",{targetSessionId:f,cols:p,rows:b,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:d,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:r,onChange:p=>i(p.target.value),onPaste:p=>{const b=p.clipboardData.getData("text");b&&i(g=>g+b),p.preventDefault()},onKeyDown:p=>{if(p.key==="Enter"){if(p.nativeEvent.isComposing){p.preventDefault();return}p.preventDefault(),o()}},className:"w-full h-9 rounded-[18px] px-4 bg-bg-secondary text-[13px] text-text-primary",style:{border:"1px solid var(--chat-input-border, var(--border-subtle))"}})}),e.jsx("button",{onClick:o,disabled:!r.trim()||c,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${r.trim()&&!c?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:r.trim()&&!c?{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 Un({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",i=t==="auth_failed"?"red":t==="offline"?"orange":"violet",o={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",violet:"linear-gradient(90deg, rgba(139,92,246,0.12), rgba(139,92,246,0.04))"},c={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",violet:"1px solid rgba(139,92,246,0.2)"},d={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:o[i],borderBottom:c[i],color:d[i]},children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-5 h-5",style:{opacity:t==="auth_failed"?.6:1,animation:t==="auth_failed"?void 0:"pulse 2s ease-in-out infinite",filter:t==="auth_failed"?"grayscale(1)":void 0}}),t==="offline"&&"Network offline — waiting for connection...",t==="disconnected"&&"Reconnecting to server...",t==="reconnecting"&&"Reconnecting to server...",t==="auth_failed"&&(n?e.jsxs(e.Fragment,{children:["Session expired."," ",e.jsx("a",{href:n,className:"text-inherit underline",children:"Log in again"})]}):"Connection failed — please restart the server.")]}),s&&t==="connected"&&e.jsxs("div",{className:"py-2 px-4 text-xs font-semibold flex items-center gap-2 justify-center bg-gradient-to-r from-green-500/[0.12] to-green-500/[0.04] text-green-400 border-b border-green-500/15 animate-[fadeIn_0.3s_ease]",children:[e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-4 h-4"}),"Connected"]})]})}let Ks=yt;function $t(){return Ks()}class Vn{constructor(){Re(this,"listeners",new Map)}send(s){}isConnected(){return!1}on(s,n){return this.listeners.has(s)||this.listeners.set(s,new Set),this.listeners.get(s).add(n),()=>{var r;(r=this.listeners.get(s))==null||r.delete(n)}}emit(s,...n){var r;(r=this.listeners.get(s))==null||r.forEach(i=>i(...n))}}let Fs=new Vn;class Yn{constructor(){Re(this,"ptyCallbacks",new Set)}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}async requestChatHistory(s,n,r,i,o){return{messages:[],hasMore:!1}}retryConnection(s){}getState(s){return"disconnected"}sendData(s,n){return!1}get(s){}onScreenshot(s,n){return()=>{}}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,n){this.ptyCallbacks.forEach(r=>r(s,n))}}let Qe=new Yn,Ft=Qe;function Xn(t){t.dashboardWS&&(Fs=t.dashboardWS),t.connectionManager&&(Qe=t.connectionManager,Ft=t.connectionManager),t.p2pManager&&(Ft=t.p2pManager),t.useDaemonsHook&&(Ks=t.useDaemonsHook)}function qn({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,onOpenHistory:i,onStopCli:o}){const c=jt(),d=$t(),l=d.p2pStates||{},x=d.ides||[],u=!!t&&He(t)&&!Be(t),f=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",p=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",b=x.filter(L=>L.type==="adhdev-daemon"),g=Object.values(l),I=g.filter(L=>L==="connected").length,B=g.filter(L=>L==="connecting"||L==="new"||L==="checking").length,j=n!=="connected"||b.length===0?null:B>0&&I===0?"P2P connecting...":I>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(dt,{size:18}),e.jsx("span",{className:"header-title-desktop",children:"Dashboard"}),e.jsx("span",{className:"header-title-mobile",children:(t==null?void 0:t.displayPrimary)||"Dashboard"}),e.jsx("span",{className:"header-count-mobile text-[10px] font-semibold opacity-60 ml-2 tracking-wide",children:e.jsx("span",{className:"inline-block w-[6px] h-[6px] rounded-full align-middle",style:{background:f,boxShadow:p}})})]}),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":n==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:f,boxShadow:p}}),j&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",j]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[u&&o&&e.jsx("button",{onClick:o,className:"btn btn-secondary btn-sm text-red-400 border-red-500/25 hover:bg-red-500/10",title:"Stop CLI process",children:"Stop"}),t&&!u&&!Be(t)&&e.jsxs("button",{onClick:()=>c(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Zt,{size:14})," IDE"]}),t&&!u&&!Be(t)&&e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(_s,{size:16})}),t&&!u&&!Be(t)&&e.jsx("button",{onClick:()=>c(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(nt,{size:16})})]})]})}var Gn=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function Jn(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function Ke(t,s){if(Jn(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":Gn.has(n)?"generating":n==="error"?"error":n==="stopped"?"stopped":n==="starting"?"starting":n==="panel_hidden"?"panel_hidden":n==="not_monitored"?"not_monitored":n==="disconnected"?"disconnected":"idle"}function Hs(t){return Ke(t)==="generating"}function Ue(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function Zn(t){if(t<60)return`${Math.round(t)}s`;const s=Math.floor(t/60);if(s<60)return`${s}m`;const n=Math.floor(s/60),r=s%60;if(n<24)return r>0?`${n}h ${r}m`:`${n}h`;const i=Math.floor(n/24),o=n%24;return`${i}d ${o}h`}function os(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Qn(t){if(t.length>16&&/^[a-f0-9]+$/i.test(t))return`Machine-${t.substring(0,8)}`;if(t.includes("_")){const s=t.split("_"),n=s[s.length-1];return n.length>12?`Machine-${n.substring(0,8)}`:n}return t}function er(t){return Qn(t.trim().replace(/\.local$/i,""))}function tr(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Us(t,s={}){var i,o;const n=[t.hostname,(i=t.machine)==null?void 0:i.hostname,(o=t.system)==null?void 0:o.hostname].find(c=>typeof c=="string"&&c.trim().length>0);if(n&&n!=="Unknown")return er(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function pt(t,s={}){return tr(t)||Us(t,s)}function is(t){return t.transport==="pty"}function cs(t){return t.transport==="acp"}function Ht(t,s){return Ue(t)}function Ut(t){return Ke(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function sr(t){if(!Array.isArray(t)||t.length<=1)return t;const s=new Map,n=["generating","waiting_approval","connected","idle","panel_hidden"];for(const r of t){const i=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),o=s.get(i),c=Ke(r.status);if(!o){s.set(i,{...r,status:c});continue}const d=n.indexOf(o.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(d<0||l<d)&&s.set(i,{...r,status:c})}return Array.from(s.values())}function Vs({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:i,onNewChat:o,onSwitchSession:c,onRefreshHistory:d}){var f;const l=s.find(p=>p.id===t.ideId),x=(l==null?void 0:l.chats)||[],u=(f=l==null?void 0:l.activeChat)==null?void 0:f.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:i,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{className:"card fade-in relative w-[90%] max-w-[500px] max-h-[80vh] flex flex-col p-0 overflow-hidden shadow-[0_20px_40px_rgba(0,0,0,0.4)] rounded-[20px]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle flex justify-between items-center bg-[var(--surface-primary)]",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"m-0 text-lg font-extrabold",children:"Chat History"}),e.jsxs("div",{className:"text-xs text-text-muted mt-0.5",children:[t.displayPrimary," — ",Ue(t.ideType)]})]}),e.jsx("button",{onClick:i,className:"bg-transparent border-none text-xl text-text-muted cursor-pointer",children:"✕"})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 bg-bg-primary",children:[e.jsx("button",{onClick:o,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),x.map(p=>e.jsxs("div",{onClick:()=>{c(t.ideId,p.id),i()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${u===p.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 ${u===p.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:p.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:[p.id.substring(0,12),"..."]}),u===p.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},p.id)),x.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($n,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:d,disabled: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($s,{size:13})," Refresh History"]})})})]})]})}const ls={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function Ys({toasts:t,onDismiss:s,onClickToast:n}){return e.jsx("div",{className:"fixed right-4 z-[9999] flex flex-col gap-2 pointer-events-none",style:{top:"calc(env(safe-area-inset-top, 0px) + 16px)"},children:t.map(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:ls[r.type]||ls.info},onClick:()=>{var i;(i=r.actions)!=null&&i.length||(n&&n(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,o)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${i.variant==="primary"?"bg-white text-amber-700 hover:bg-gray-100":i.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:c=>{c.stopPropagation(),i.onClick(),s(r.id)},children:i.label},o))})]},r.id))})}const nr=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function rr(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function ds(t,s){const n=new Set,r=[];for(const i of s)if(i)for(const o of t[i]||[]){const c=o._localId||`${o.role}:${o.timestamp}:${o.content}`;n.has(c)||(n.add(c),r.push(o))}return r.sort((i,o)=>i.timestamp-o.timestamp)}function ar(t,s,n,r){const i={};if(n)for(const o of n){const c=o;(c.type==="adhdev-daemon"||c.daemonMode)&&(i[c.id]=pt(c,{fallbackId:c.id}))}return t.flatMap(o=>{var N,j,L,K,h,T;const c=[],d=o.daemonId&&i[o.daemonId]||void 0,l=o.daemonId||((N=o.id)==null?void 0:N.split(":")[0])||o.id,x=r?r[l]||"new":void 0,u=rr(o),f=Ue(o.type),p=o.agentStreams,b=Array.isArray(p)?p.map(S=>({...S,activeModal:S.activeModal??void 0})):[],g=nr(o),I=o.activeChat||{title:""},B=I.title&&String(I.title).trim()?String(I.title).trim():"";if(g){const S=o.sessionId||o.instanceId,R=Ht(o.type),J=(j=o.agents)==null?void 0:j[0],P=(L=o.activeChat)==null?void 0:L.activeModal,M=P&&Array.isArray(P.buttons)&&P.buttons.length>0,oe=Ke((K=o.activeChat)==null?void 0:K.status,{activeModal:(h=o.activeChat)==null?void 0:h.activeModal})||Ke(J==null?void 0:J.status)||"idle",ee=o.activeChat||{title:"",messages:[]};let y=ee.title&&String(ee.title).trim()?String(ee.title).trim():"";const W=(T=o.activeChat)==null?void 0:T.id,D=o.chats;if(W&&Array.isArray(D)&&D.length>0){const Y=D.find(ie=>ie.id===W||ie.id&&String(ie.id)===String(W));Y!=null&&Y.title&&String(Y.title).trim()&&(y=String(Y.title).trim())}const z=ee.messages||[],V=ds(s,[o.id,S]),U=new Map;z.filter(Y=>Y.role==="user").forEach(Y=>{U.set(Y.content,(U.get(Y.content)||0)+1)});const re=V.filter(Y=>{const ie=U.get(Y.content)||0;return ie>0?(U.set(Y.content,ie-1),!1):!0});c.push({ideId:o.id,sessionId:S,transport:o.transport,daemonId:o.daemonId||void 0,mode:He(o)?o.mode||"terminal":"chat",agentName:R,agentType:He(o)||Be(o)?o.cliType||o.acpType||o.type:(J==null?void 0:J.type)||"ide-native",status:oe,title:y,messages:[...z,...re],ideType:o.cliType||o.acpType||o.type,workspaceName:u,displayPrimary:y||u||(He(o)||Be(o)?"Terminal":R),displaySecondary:f,cdpConnected:o.cdpConnected,modalButtons:M?P.buttons:void 0,modalMessage:M?P.message:void 0,streamSource:"native",tabKey:o.id,machineName:d,connectionState:x})}if(g&&(He(o)||Be(o)))return c;for(const S of b){const R=S.activeModal&&Array.isArray(S.activeModal.buttons)&&S.activeModal.buttons.length>0,J=Ut(S),P=`${o.id}:${S.agentType}`,M=S.messages||[],oe=ds(s,[P,S.sessionId]),ee=new Map;M.filter(W=>W.role==="user").forEach(W=>{ee.set(W.content,(ee.get(W.content)||0)+1)});const y=oe.filter(W=>{const D=ee.get(W.content)||0;return D>0?(ee.set(W.content,D-1),!1):!0});c.push({ideId:o.id,sessionId:S.sessionId||S.instanceId,transport:S.transport||"cdp-webview",daemonId:o.daemonId||void 0,mode:"chat",agentName:S.agentName,agentType:S.agentType,status:J,title:"",messages:[...M,...y],ideType:S.agentType,workspaceName:u,displayPrimary:B||u||S.agentName,displaySecondary:`${f}·${S.agentName}`,cdpConnected:o.cdpConnected,modalButtons:R?S.activeModal.buttons:void 0,modalMessage:R?S.activeModal.message:void 0,streamSource:"agent-stream",tabKey:P,machineName:d,connectionState:x})}return c.length===0&&c.push({ideId:o.id,sessionId:o.sessionId||o.instanceId,transport:o.transport,daemonId:o.daemonId||void 0,mode:"chat",agentName:Ht(o.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:o.type,workspaceName:u,displayPrimary:u||f,displaySecondary:f,cdpConnected:o.cdpConnected,streamSource:"native",tabKey:o.id,connectionState:x}),c})}function or(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const i=n.get(r.parentId)||[];i.push(r),n.set(r.parentId,i)}else s.push(r);return{topLevel:s,childrenByParent:n}}function ir(t,s){var b,g,I,B,N,j,L,K;const n=[],{daemonId:r,existingDaemon:i,timestamp:o}=s,c=o||t.timestamp||Date.now(),d=t.sessions||[],{topLevel:l,childrenByParent:x}=or(d),u=l.filter(h=>h.kind==="workspace"&&h.transport==="cdp-page"),f=l.filter(h=>h.kind==="agent"&&h.transport==="pty"),p=l.filter(h=>h.kind==="agent"&&h.transport==="acp");n.push({...i||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:c,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},...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:u.some(h=>!!h.cdpConnected)});for(const h of u){const T=x.get(h.id)||[];n.push({id:`${r}:ide:${h.id}`,sessionId:h.id,parentSessionId:h.parentId,sessionKind:h.kind,transport:h.transport,sessionCapabilities:h.capabilities,type:h.providerType,ideType:h.providerType,status:h.cdpConnected?"online":"detected",daemonId:r,instanceId:h.id,workspace:h.workspace,terminals:0,agents:T.map(S=>({id:S.id,name:S.providerName,type:S.providerType,status:S.status})),activeChat:h.activeChat,chats:[],agentStreams:T.map(S=>{var R,J,P,M;return{sessionId:S.id,parentSessionId:S.parentId,agentType:S.providerType,agentName:S.providerName,extensionId:S.providerType,transport:S.transport,status:Ke(S.status,{activeModal:(R=S.activeChat)==null?void 0:R.activeModal}),messages:((J=S.activeChat)==null?void 0:J.messages)||[],inputContent:((P=S.activeChat)==null?void 0:P.inputContent)||"",activeModal:((M=S.activeChat)==null?void 0:M.activeModal)||null,model:S.currentModel}}),cdpConnected:h.cdpConnected,currentModel:h.currentModel,currentPlan:h.currentPlan,currentAutoApprove:h.currentAutoApprove,timestamp:c})}for(const h of f)n.push({id:`${r}:cli:${h.id}`,sessionId:h.id,parentSessionId:h.parentId,sessionKind:h.kind,transport:h.transport,sessionCapabilities:h.capabilities,type:h.providerType,ideType:h.providerType,agentType:h.providerType,status:h.status||"running",daemonId:r,instanceId:h.id,cliName:h.providerName,mode:"terminal",workspace:h.workspace||"",activeChat:h.activeChat,agentStreams:[{sessionId:h.id,parentSessionId:h.parentId,agentType:h.providerType,agentName:h.providerName,extensionId:"cli-agent",transport:h.transport,status:Ke(h.status,{activeModal:(b=h.activeChat)==null?void 0:b.activeModal}),messages:((g=h.activeChat)==null?void 0:g.messages)||[],inputContent:((I=h.activeChat)==null?void 0:I.inputContent)||"",activeModal:(B=h.activeChat)==null?void 0:B.activeModal}],timestamp:c,_isCli:!0});for(const h of p)n.push({id:`${r}:acp:${h.id}`,sessionId:h.id,parentSessionId:h.parentId,sessionKind:h.kind,transport:h.transport,sessionCapabilities:h.capabilities,type:h.providerType,ideType:h.providerType,agentType:h.providerType,status:h.status||"running",daemonId:r,instanceId:h.id,cliName:h.providerName,mode:"chat",workspace:h.workspace||"",activeChat:h.activeChat,currentModel:h.currentModel,currentPlan:h.currentPlan,acpConfigOptions:h.acpConfigOptions,acpModes:h.acpModes,agentStreams:[{sessionId:h.id,parentSessionId:h.parentId,agentType:h.providerType,agentName:h.providerName,extensionId:"acp-agent",transport:h.transport,status:Ke(h.status,{activeModal:(N=h.activeChat)==null?void 0:N.activeModal}),messages:((j=h.activeChat)==null?void 0:j.messages)||[],inputContent:((L=h.activeChat)==null?void 0:L.inputContent)||"",activeModal:(K=h.activeChat)==null?void 0:K.activeModal}],timestamp:c,_isAcp:!0});return n}const Xs=[{id:"vscode",name:"VS Code",icon:"💙"},{id:"cursor",name:"Cursor",icon:"⚡"},{id:"windsurf",name:"Windsurf",icon:"🏄"},{id:"antigravity",name:"Antigravity",icon:"🌀"},{id:"trae",name:"Trae",icon:"🔮"},{id:"kiro",name:"Kiro",icon:"🎯"},{id:"pearai",name:"PearAI",icon:"🍐"},{id:"vscodium",name:"VSCodium",icon:"💚"}],qs=[{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"codex-cli",name:"Codex CLI",icon:"📦"},{id:"aider-cli",name:"Aider",icon:"🛠️"},{id:"cursor-cli",name:"Cursor CLI",icon:"⚡"},{id:"github-copilot-cli",name:"GitHub Copilot CLI",icon:"🤖"},{id:"goose-cli",name:"Goose CLI",icon:"🪿"},{id:"opencode-cli",name:"OpenCode CLI",icon:"🧩"}],Gs=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Js="adhdev_notification_prefs",us={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function cr(){try{const t=localStorage.getItem(Js);if(t){const s=JSON.parse(t);return{...us,...s}}}catch{}return{...us}}function lr(t){try{localStorage.setItem(Js,JSON.stringify(t))}catch{}}let Xe=cr(),Ct=[];function dr(){Ct.forEach(t=>t())}function ur(){return{...Xe}}function pr(t){Xe={...Xe,...t},lr(Xe),dr()}function xr(){const[,t]=a.useState(0);a.useEffect(()=>{const n=()=>t(r=>r+1);return Ct.push(n),()=>{Ct=Ct.filter(r=>r!==n)}},[]);const s=a.useCallback(n=>{pr(n)},[]);return[{...Xe},s]}function ft(t){if(!Xe.globalEnabled)return!1;switch(t){case"disconnect":return Xe.disconnectAlert;case"completion":return Xe.completionAlert;case"approval":return Xe.approvalAlert;case"browser":return Xe.browserNotifications;default:return!0}}const mr={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function hr(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Zs(){return"Notification"in window&&Notification.permission==="granted"}let rt=null;async function fr(){if(rt!==null)return rt;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return rt=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(rt=!!await t.pushManager.getSubscription(),rt):(rt=!1,!1)}catch{return rt=!1,!1}}function Vt(t,s,n){if(Zs())try{const r=new Notification(t,{body:s,icon:"/otter-logo.png",tag:n||`adhdev-${Date.now()}`,silent:!1});setTimeout(()=>r.close(),8e3),r.onclick=()=>{window.focus(),r.close()}}catch{}}function gr(t,s={}){const n={...mr,...s},r=a.useRef(new Map),i=a.useRef(0),o=a.useRef(null);a.useEffect(()=>{fr().then(d=>{o.current=d})},[]);const c=a.useCallback((d,l,x)=>{const u=Date.now();u-i.current<n.throttleMs||(i.current=u,Vt(d,l,x))},[n.throttleMs]);a.useEffect(()=>{var d;if(!(!n.enabled||!Zs())&&ft("browser")&&o.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,Ke(l.status,{activeModal:l.activeModal}));return}for(const l of t){const x=r.current.get(l.id),u=Ke(l.status,{activeModal:l.activeModal}),f=l.name||l.id;if(n.onApproval&&ft("approval")&&u==="waiting_approval"&&x!=="waiting_approval"){const p=((d=l.activeModal)==null?void 0:d.message)||"Action requires your approval";c(`🔔 ${f} — Approval needed`,p.slice(0,120),`approval-${l.id}`)}n.onComplete&&ft("completion")&&Hs(x)&&u==="idle"&&c(`✅ ${f} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&u==="error"&&x!=="error"&&c(`⚠️ ${f} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,u)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class br{constructor(){Re(this,"dedupMap",new Map);Re(this,"DEDUP_WINDOW_MS",5e3);Re(this,"DEDUP_MAX_SIZE",50);Re(this,"DEDUP_CLEANUP_AGE_MS",1e4);Re(this,"toastCallbacks",[]);Re(this,"systemMessageCallbacks",[]);Re(this,"clearSystemMessageCallbacks",[]);Re(this,"resolveActionFn",null);Re(this,"viewRequestRespondFn",null);Re(this,"ides",[])}onToast(s){return this.toastCallbacks.push(s),()=>{this.toastCallbacks=this.toastCallbacks.filter(n=>n!==s)}}onSystemMessage(s){return this.systemMessageCallbacks.push(s),()=>{this.systemMessageCallbacks=this.systemMessageCallbacks.filter(n=>n!==s)}}onClearSystemMessage(s){return this.clearSystemMessageCallbacks.push(s),()=>{this.clearSystemMessageCallbacks=this.clearSystemMessageCallbacks.filter(n=>n!==s)}}setResolveAction(s){this.resolveActionFn=s}setIdes(s){this.ides=s}setViewRequestRespond(s){this.viewRequestRespondFn=s}emitToast(s){for(const n of this.toastCallbacks)n(s)}showToast(s,n="info",r){const i=(r==null?void 0:r.id)||Date.now();this.emitToast({id:i,message:s,type:n,timestamp:i,duration:5e3,...r})}emitSystemMessage(s,n){for(const r of this.systemMessageCallbacks)r(s,n)}emitClearSystemMessage(s,n){for(const r of this.clearSystemMessageCallbacks)r(s,n)}isDuplicate(s){const n=Date.now(),r=this.dedupMap.get(s)||0;if(n-r<this.DEDUP_WINDOW_MS)return!0;if(this.dedupMap.set(s,n),this.dedupMap.size>this.DEDUP_MAX_SIZE)for(const[i,o]of this.dedupMap)n-o>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(i);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const i=this.ides.find(o=>o.id===s.ideId&&o.type==="adhdev-daemon");if(i)return i}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(i=>i.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(i=>i.id.endsWith(`:ide:${s.instanceId}`)||i.id.endsWith(`:cli:${s.instanceId}`))),n){const i=n.daemonId;if(i){const o=this.ides.find(c=>c.id===i&&c.type==="adhdev-daemon");if(o)return o}}const r=this.ides.filter(i=>i.type==="adhdev-daemon");return r.length===1?r[0]:null}resolveRouteId(s,n){for(const r of this.ides)if(r.id.startsWith(s)&&(!n||n===r.type))return r.id;return s}findOwningSession(s){for(const n of this.ides)if(n.id===s||n.sessionId===s||(Array.isArray(n.agentStreams)?n.agentStreams:[]).some(i=>(i==null?void 0:i.sessionId)===s))return n;return null}resolveActionRouteTarget(s){if(s.ideId){const n=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,n)}if(s.targetSessionId){const n=this.findOwningSession(s.targetSessionId);return(n==null?void 0:n.id)||(n==null?void 0:n.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,n){var u,f;if(!s.ideId&&s.instanceId){for(const p of this.ides)if(p.id.endsWith(`:ide:${s.instanceId}`)||p.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=p.id;break}}const r=this.resolveConversationKey(s),o=`${r||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(o))return;let c=Ue(s.ideType||"");const d=this.resolveOwningDaemon(s);if(d){const p=pt(d,{fallbackId:d.id});p&&(c=s.ideType==="adhdev-daemon"?p:`${p}/${c}`)}let l="",x="info";if(s.event==="agent:generating_completed"){const p=s.duration?` (${s.duration}s)`:"";l=`✅ ${c} agent task completed${p}`,x="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&ur().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${p}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")r&&this.emitClearSystemMessage(r,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(l=`⚡ ${c} approval needed`,x="warning",r){const p=s.modalMessage||"Approval requested",b=(u=s.modalButtons)!=null&&u.length?s.modalButtons.map(g=>`[${g}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${p}
|
|
39
|
-
${b}`,_localId:`sys_approval_${Date.now()}`})}if((f=s.modalButtons)!=null&&f.length&&this.resolveActionFn){const p=this.resolveActionRouteTarget(s);if(!p)return;const b=s.agentType||s.ideType||"",g=s.ideType||"",I=s.modalButtons,B=h=>h.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),N=this.resolveActionFn,j=I.map((h,T)=>{const S=B(h).toLowerCase(),R=/^(run|approve|accept|yes|allow|always)/.test(S),J=/^(reject|deny|delete|remove|abort|cancel|no)/.test(S);return{label:B(h),variant:R?"primary":J?"danger":"default",onClick:()=>{const P=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(S);N(p,"resolve_action",{action:P?"approve":"reject",button:h,buttonIndex:T,agentType:b,ideType:g,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),L=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,K=Date.now();this.emitToast({id:K,message:L,type:x,timestamp:K,targetKey:r||p,actions:j,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const p=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${c} agent is taking a long time${p}`,x="warning",ft("browser")&&!document.hasFocus()&&Vt(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${p.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const p=s.requesterName||"A team member",b=s.requestId,g=s.orgId;if(l=`👁️ ${p} wants to view your session`,x="warning",b&&g&&this.viewRequestRespondFn){const I=this.viewRequestRespondFn,B=Date.now(),N=[{label:"Approve",variant:"primary",onClick:()=>{I(g,b,"approve").catch(j=>console.error("[EventManager] approve view request failed:",j))}},{label:"Decline",variant:"danger",onClick:()=>{I(g,b,"reject").catch(j=>console.error("[EventManager] reject view request failed:",j))}}];this.emitToast({id:B,message:l,type:x,timestamp:B,actions:N,duration:3e4}),l=""}ft("browser")&&!document.hasFocus()&&Vt("👁️ View Request",`${p} wants to view your session`,`view-request-${b}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",x="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,x="warning");if(l){const p=Date.now();this.emitToast({id:p,message:l,type:x,timestamp:p,targetKey:r||s.ideId,duration:5e3})}}}const et=new br;function ct(...t){return ln(dn(t))}function yr({icon:t,title:s,subtitle:n,badge:r,actions:i,className:o}){return e.jsxs("div",{className:ct("dashboard-header",o),children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"header-title flex items-center gap-2",children:[e.jsx("span",{className:"flex items-center text-lg",children:t})," ",s,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]})]}),n&&e.jsx("div",{className:"header-subtitle mt-1 text-xs text-text-muted",children:n})]}),i&&e.jsx("div",{className:"flex gap-2",children:i})]})}function At({icon:t,title:s,subtitle:n,badge:r,actions:i,widthClassName:o="max-w-6xl",contentClassName:c,children:d}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(yr,{icon:t,title:s,subtitle:n,badge:r,actions:i}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:ct("mx-auto flex w-full flex-col gap-4",o,c),children:d})})]})}function De({title:t,icon:s,description:n,accentColor:r,className:i,children:o}){return e.jsxs("div",{className:ct("bg-bg-card border border-border-subtle rounded-2xl p-5 backdrop-blur-xl transition-all","hover:border-border-default hover:shadow-glow",r&&"border-l-[3px]",i),style:r?{borderLeftColor:r}:void 0,children:[(t||n)&&e.jsxs("div",{className:"mb-4",children:[t&&e.jsxs("h3",{className:"text-base font-semibold text-text-primary",children:[s&&e.jsx("span",{className:"mr-1.5",children:s}),t]}),n&&e.jsx("p",{className:"text-[13px] text-text-muted mt-1",children:n})]}),o]})}function Qt({icon:t,title:s,description:n,action:r,className:i}){return e.jsxs("div",{className:ct("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",i),children:[e.jsx("div",{className:"text-5xl mb-4 opacity-50",children:t}),e.jsx("h3",{className:"text-lg font-bold text-text-secondary mb-2",children:s}),e.jsx("p",{className:"text-sm text-text-muted max-w-sm mx-auto mb-5 leading-relaxed",children:n}),r]})}const vr={error:"bg-red-500/10 border-red-500/30 text-red-400",warning:"bg-yellow-500/10 border-yellow-500/30 text-yellow-400",success:"bg-green-500/10 border-green-500/30 text-green-400",info:"bg-indigo-500/10 border-indigo-500/30 text-indigo-400"},jr={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function wr({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:ct("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",vr[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:jr[t]}),e.jsx("span",{children:s})]}),n&&e.jsx("button",{onClick:n,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const Nr={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"},kr={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Sr({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:ct("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Nr[t],n),children:[e.jsx("span",{className:ct("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",kr[t])}),r]})}function Cr(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function ps(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function Bt(t){return t==="system"?Cr():t}function Ir(){const[t,s]=a.useState(ps),[n,r]=a.useState(()=>Bt(ps()));a.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),a.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),d=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",d),()=>c.removeEventListener("change",d)},[t]);const i=a.useCallback(c=>{s(c),r(Bt(c));try{localStorage.setItem("theme",c)}catch{}},[]),o=a.useCallback(()=>{s(c=>{const d=c==="dark"?"light":c==="light"?"system":"dark";r(Bt(d));try{localStorage.setItem("theme",d)}catch{}return d})},[]);return{theme:n,preference:t,setPreference:i,cycleTheme:o,isDark:n==="dark"}}function ot({label:t,description:s,checked:n,disabled:r,onChange:i,extra:o}){return e.jsxs("label",{className:"flex justify-between items-center cursor-pointer",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:t}),e.jsx("div",{className:"text-[11px] text-text-muted",children:s})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[o,e.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:c=>i(c.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function Mr({onPrefChange:t}){const[s,n]=xr(),r=(i,o)=>{n({[i]:o}),t==null||t(i,o)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Bs,{size:15})," 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(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(nt,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:i=>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(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rn,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:i=>r("completionAlert",i)}),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Pn,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:i=>r("approvalAlert",i)}),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ut,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:i=>r("disconnectAlert",i)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(dt,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:i=>r("chatTaskCompletionBubble",i)}),!s.globalEnabled&&e.jsx("p",{className:"text-[11px] text-text-muted italic",children:"All notifications are disabled. Enable the master toggle to configure individual alerts."})]})}function Tr({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){const o=t.filter(c=>c.type==="adhdev-daemon");return o.length===0?e.jsx(Qt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-12 h-12 object-contain mx-auto opacity-90"}),title:"No machines connected",description:s||"Run 'adhdev-standalone' to connect a local daemon instance."}):e.jsx("div",{className:"flex flex-col gap-2",children:o.map(c=>e.jsx(Ar,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i},c.id))})}function xs({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:i,onCancel:o}){const c=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 un.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:o,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:d=>d.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:o,className:"text-xs px-3 py-1.5 rounded-lg font-medium bg-bg-secondary text-text-secondary border border-border-subtle hover:bg-bg-glass transition-colors",children:"Cancel"}),e.jsx("button",{onClick:i,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,children:n})]})]})}),document.body)}function Er(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...Xs,...qs,...Gs].find(i=>i.id===s||s.includes(i.id)||i.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function Ar({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:i}){var y,W;const[o,c]=a.useState("idle"),[d,l]=a.useState(""),[x,u]=a.useState(null),[f,p]=a.useState("idle"),[b,g]=a.useState(""),I=t,B=I.version||I.daemonVersion||null,N=((y=I.machine)==null?void 0:y.platform)||((W=I.system)==null?void 0:W.platform)||"",j=pt(I,{fallbackId:t.id}),L=N==="win32"?"🪟":N==="darwin"?"🍎":"🐧",K=s.filter(D=>D.daemonId===t.id&&D.transport==="cdp-page"),h=s.filter(D=>D.daemonId===t.id&&D.transport==="pty"),T=s.filter(D=>D.daemonId===t.id&&D.transport==="acp"),S=I.p2p,R=async()=>{var D,z,V;if(n){c("upgrading"),l("Installing latest version...");try{const U=await n(t.id,"daemon_upgrade",{});(D=U==null?void 0:U.result)!=null&&D.upgraded||(z=U==null?void 0:U.result)!=null&&z.success?(c("done"),l(`Upgraded to v${U.result.version||"latest"}. Daemon is restarting...`)):(c("error"),l(((V=U==null?void 0:U.result)==null?void 0:V.error)||"Upgrade failed"))}catch(U){c("error"),l((U==null?void 0:U.message)||"Connection lost during upgrade")}}},J=async()=>{if(u(null),!!r){p("loading");try{await r(t.id),p("done"),g("Machine disconnected.")}catch(D){p("error"),g((D==null?void 0:D.message)||"Failed to disconnect")}}},P=async()=>{if(u(null),!!i){p("loading");try{await i(t.id),p("done"),g('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(D){p("error"),g((D==null?void 0:D.message)||"Failed to revoke token")}}},M="0.7.1",oe=!B||B!==M,ee=K.length+h.length+T.length;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"bg-bg-glass rounded-lg px-4 py-3 border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xl",children:L}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:j}),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),"…"]}),B&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${oe?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",B,!oe&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&oe&&e.jsx("button",{onClick:R,disabled:o==="upgrading"||o==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${M}`,children:o==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):o==="done"?"✓ Updated":`↑ Update${` to v${M}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:f==="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:()=>u("revoke"),disabled:f==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Sr,{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:[S&&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 ${S.state==="connected"?"bg-green-400":S.state==="connecting"||S.state==="new"?"bg-amber-400 animate-pulse":"bg-text-muted/30"}`}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",S.state==="connected"?"connected":S.state==="connecting"||S.state==="new"?"connecting...":S.state||"off"]}),S.peers!==void 0&&S.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",S.peers," peer",S.peers!==1?"s":"",")"]})]}),S&&ee>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),ee>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[K.map(D=>{const z=Er(D.type),V=D.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:z.icon}),e.jsx("span",{children:z.name}),V!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${V?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:V?"CDP connected":"CDP connecting..."})]},D.id)}),h.map(D=>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:D.cliName||"CLI"})]},D.id)),T.map(D=>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:D.cliName||"ACP"})]},D.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(d||b)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${o==="error"||f==="error"?"text-red-400":o==="done"||f==="done"?"text-green-400":"text-text-muted"}`,children:b||d})]}),x==="disconnect"&&e.jsx(xs,{title:"🔌 Disconnect Machine",message:`Disconnect "${j}" 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:J,onCancel:()=>u(null)}),x==="revoke"&&e.jsx(xs,{title:"⚠️ Remove Machine",message:`Remove "${j}" from your dashboard?
|
|
44
|
-
|
|
45
|
-
This will:
|
|
46
|
-
• Immediately disconnect the machine
|
|
47
|
-
• Delete the machine registration
|
|
48
|
-
• Require restarting "adhdev-standalone" on that machine
|
|
49
|
-
|
|
50
|
-
Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:P,onCancel:()=>u(null)})]})}const _r=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function $r(){const{preference:t,setPreference:s}=Ir();return e.jsx("div",{className:"flex gap-2",children:_r.map(n=>e.jsxs("button",{onClick:()=>s(n.id),className:`px-3 py-1.5 rounded-lg border text-sm font-medium transition-colors flex items-center gap-1.5 ${t===n.id?"bg-accent border-accent text-white":"bg-bg-glass border-border-subtle hover:bg-bg-secondary text-text-muted hover:text-text-primary"}`,children:[e.jsx("span",{children:n.icon}),n.label]},n.id))})}const Yt={bgPrimary:"#0f0f13",bgSecondary:"#18181d",surfacePrimary:"#111116",textPrimary:"#fafafa",textSecondary:"#a8a8b3",textMuted:"#7e7e8a",borderSubtle:"#1a1a22",borderDefault:"#2a2a35",accentColor:"#8b5cf6",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#1e1e24",assistantText:"#e0e0e0",containerBg:"#111114",sendButton:"#6366f1",inputBorder:"#2a2a35",bubbleRadius:16},Xt={bgPrimary:"#f0f1f5",bgSecondary:"#e8eaf0",surfacePrimary:"#ffffff",textPrimary:"#1a1a2e",textSecondary:"#3f3f50",textMuted:"#5c5c6e",borderSubtle:"#d8d8e0",borderDefault:"#c0c0cc",accentColor:"#7c3aed",userBubble:"#6366f1",userText:"#ffffff",assistantBubble:"#f3f4f6",assistantText:"#1f2937",containerBg:"#f0f1f5",sendButton:"#6366f1",inputBorder:"#d1d5db",bubbleRadius:16},Rr=[{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"}}}],Qs="adhdev-chat-theme",en="adhdev-chat-theme-custom";function It(){return typeof window>"u"?"midnight":localStorage.getItem(Qs)||"midnight"}function Ve(t){try{const s=localStorage.getItem(en);if(s){const n=JSON.parse(s);return{...t==="dark"?Yt:Xt,...n[t]}}}catch{}return t==="dark"?Yt:Xt}function Nt(t,s){localStorage.setItem(en,JSON.stringify({dark:t,light:s}))}function Ge(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function ms(t,s){const n=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`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${i.toString(16).padStart(2,"0")}`}function it(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ge(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ge(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ge(t.borderSubtle,.25)),s.style.setProperty("--text-primary",t.textPrimary),s.style.setProperty("--text-secondary",t.textSecondary),s.style.setProperty("--text-muted",t.textMuted),s.style.setProperty("--border-subtle",Ge(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ge(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",ms(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${ms(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ge(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ge(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ge(t.accentColor,.06)}`),s.style.setProperty("--chat-user-bg",t.userBubble),s.style.setProperty("--chat-user-color",t.userText),s.style.setProperty("--chat-user-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px 4px ${t.bubbleRadius}px`),s.style.setProperty("--chat-assistant-bg",t.assistantBubble),s.style.setProperty("--chat-assistant-color",t.assistantText),s.style.setProperty("--chat-assistant-radius",`${t.bubbleRadius}px ${t.bubbleRadius}px ${t.bubbleRadius}px 4px`),s.style.setProperty("--chat-assistant-border",`1px solid ${Ge(t.accentColor,.12)}`),s.style.setProperty("--chat-container-bg",t.containerBg),s.style.setProperty("--chat-thought-accent",t.accentColor),s.style.setProperty("--chat-tool-accent",t.accentColor),s.style.setProperty("--chat-action-color",t.accentColor),s.style.setProperty("--chat-send-bg",t.sendButton),s.style.setProperty("--chat-input-border",t.inputBorder)}function Pr(){const t=document.documentElement;["--bg-primary","--bg-secondary","--bg-card","--surface-primary","--surface-secondary","--bg-glass","--bg-glass-hover","--text-primary","--text-secondary","--text-muted","--border-subtle","--border-default","--accent-primary","--accent-primary-light","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow","--chat-user-bg","--chat-user-color","--chat-user-radius","--chat-assistant-bg","--chat-assistant-color","--chat-assistant-radius","--chat-assistant-border","--chat-container-bg","--chat-thought-accent","--chat-tool-accent","--chat-action-color","--chat-send-bg","--chat-input-border"].forEach(n=>t.style.removeProperty(n))}function Lr(t){if(localStorage.setItem(Qs,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=gt()?"dark":"light";it(Ve(s))}else Pr()}function Dr(){const t=It();if(t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=gt()?"dark":"light";it(Ve(s))}}function gt(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function Le({label:t,value:s,onChange:n}){return e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:t}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("input",{type:"color",value:s,onChange:r=>n(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)&&n(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 mt({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 Br({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,i]=a.useState(()=>Ve(n));a.useEffect(()=>{i(Ve(n))},[n]);const o=a.useCallback((c,d)=>{i(l=>{const x={...l,[c]:d},f=Ve(n==="dark"?"light":"dark");return n==="dark"?Nt(x,f):Nt(f,x),it(x),s(x),x})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(mt,{title:"App Background",children:[e.jsx(Le,{label:"Background",value:r.bgPrimary,onChange:c=>o("bgPrimary",c)}),e.jsx(Le,{label:"Surface",value:r.bgSecondary,onChange:c=>o("bgSecondary",c)}),e.jsx(Le,{label:"Card",value:r.surfacePrimary,onChange:c=>o("surfacePrimary",c)})]}),e.jsxs(mt,{title:"App Text",children:[e.jsx(Le,{label:"Primary",value:r.textPrimary,onChange:c=>o("textPrimary",c)}),e.jsx(Le,{label:"Secondary",value:r.textSecondary,onChange:c=>o("textSecondary",c)}),e.jsx(Le,{label:"Muted",value:r.textMuted,onChange:c=>o("textMuted",c)})]}),e.jsxs(mt,{title:"Borders & Accent",children:[e.jsx(Le,{label:"Border subtle",value:r.borderSubtle,onChange:c=>o("borderSubtle",c)}),e.jsx(Le,{label:"Border default",value:r.borderDefault,onChange:c=>o("borderDefault",c)}),e.jsx(Le,{label:"Accent",value:r.accentColor,onChange:c=>o("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(mt,{title:"Chat Bubbles",children:[e.jsx(Le,{label:"User bubble",value:r.userBubble,onChange:c=>o("userBubble",c)}),e.jsx(Le,{label:"User text",value:r.userText,onChange:c=>o("userText",c)}),e.jsx(Le,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>o("assistantBubble",c)}),e.jsx(Le,{label:"Agent text",value:r.assistantText,onChange:c=>o("assistantText",c)})]}),e.jsxs(mt,{title:"Chat Layout",children:[e.jsx(Le,{label:"Chat BG",value:r.containerBg,onChange:c=>o("containerBg",c)}),e.jsx(Le,{label:"Send button",value:r.sendButton,onChange:c=>o("sendButton",c)}),e.jsx(Le,{label:"Input border",value:r.inputBorder,onChange:c=>o("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:r.bubbleRadius,onChange:c=>o("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Yt:Xt,l=Ve(t?"light":"dark");t?Nt(c,l):Nt(l,c),i(c),it(c),s(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function Wr(){const[t,s]=a.useState(It),[n,r]=a.useState(!0),[i,o]=a.useState(()=>Ve("dark"));a.useEffect(()=>{r(gt());const l=new MutationObserver(()=>{const f=gt();r(f),It()==="custom"&&it(Ve(f?"dark":"light"))});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const x=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const f=gt();r(f),It()==="custom"&&it(Ve(f?"dark":"light"))};return x.addEventListener("change",u),()=>{l.disconnect(),x.removeEventListener("change",u)}},[]),a.useEffect(()=>{t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"&&it(Ve(n?"dark":"light"))},[]),a.useEffect(()=>{o(Ve(n?"dark":"light"))},[n]);const c=l=>{s(l),Lr(l),l==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},d=[...Rr,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText},light:{userBubble:i.userBubble,assistantBubble:i.assistantBubble,assistantBorder:`1px solid ${i.accentColor}22`,containerBg:i.containerBg,textColor:i.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:d.map(l=>{const x=t===l.id,u=n?l.preview.dark:l.preview.light,f=l.id==="honey"?"#1a1a1a":l.id==="custom"?i.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:x?"var(--bg-glass-hover)":"var(--bg-glass)",border:x?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:x?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:u.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.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:u.userBubble,color:f},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:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[x&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(Br,{dark:n,onColorsChange:l=>o(l)})]})}const qt="adhdev-accent-color",Or=[{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"}],vt="#8b5cf6";function zr(t){const s=parseInt(t.slice(1,3),16)/255,n=parseInt(t.slice(3,5),16)/255,r=parseInt(t.slice(5,7),16)/255,i=Math.max(s,n,r),o=Math.min(s,n,r);let c=0,d=0;const l=(i+o)/2;if(i!==o){const x=i-o;switch(d=l>.5?x/(2-i-o):x/(i+o),i){case s:c=((n-r)/x+(n<r?6:0))/6;break;case n:c=((r-s)/x+2)/6;break;case r:c=((s-n)/x+4)/6;break}}return{h:Math.round(c*360),s:Math.round(d*100),l:Math.round(l*100)}}function hs(t,s){const{h:n,s:r,l:i}=zr(t),o=Math.min(100,i+s);return`hsl(${n}, ${r}%, ${o}%)`}function Mt(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),i=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${i}, ${s})`}function fs(){return typeof window>"u"?vt:localStorage.getItem(qt)||vt}function Kr(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",hs(t,15)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${hs(t,20)})`),s.style.setProperty("--border-accent",Mt(t,.4)),s.style.setProperty("--nav-active-bg",Mt(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${Mt(t,.06)}`)}function Fr(){const t=document.documentElement;["--accent-primary","--accent-primary-light","--accent-gradient","--border-accent","--nav-active-bg","--nav-active-shadow"].forEach(n=>t.style.removeProperty(n))}function Hr(t){t===vt?(localStorage.removeItem(qt),Fr()):(localStorage.setItem(qt,t),Kr(t))}function Ur(){const[t,s]=a.useState(fs),[n,r]=a.useState("");a.useEffect(()=>{s(fs())},[]);const i=o=>{s(o),Hr(o)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:Or.map(o=>{const c=t===o.color;return e.jsx("button",{onClick:()=>i(o.color),title:o.name,style:{width:36,height:36,borderRadius:10,background:o.color,border:c?"3px solid var(--text-primary)":"3px solid transparent",cursor:"pointer",position:"relative",transition:"transform 0.15s, border-color 0.15s",transform:c?"scale(1.1)":"scale(1)",boxShadow:c?`0 0 12px ${Mt(o.color,.4)}`:"none"},children:c&&e.jsx("span",{style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:14,fontWeight:700,textShadow:"0 1px 2px rgba(0,0,0,0.5)"},children:"✓"})},o.color)})}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)"},children:"Custom:"}),e.jsx("input",{type:"color",value:t,onChange:o=>i(o.target.value),style:{width:28,height:28,border:"none",borderRadius:6,cursor:"pointer",background:"transparent",padding:0}}),e.jsx("input",{type:"text",value:n||t,onChange:o=>{r(o.target.value),/^#[0-9a-fA-F]{6}$/.test(o.target.value)&&i(o.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!==vt&&e.jsx("button",{onClick:()=>i(vt),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 tn="adhdev_hiddenTabs";function Vr(){try{const t=localStorage.getItem(tn);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function ht(t){try{localStorage.setItem(tn,JSON.stringify([...t]))}catch{}}function Yr(){const[t,s]=a.useState(Vr),n=a.useCallback(l=>{s(x=>{const u=new Set(x);return u.has(l)?u.delete(l):u.add(l),ht(u),u})},[]),r=a.useCallback(l=>{s(x=>{if(x.has(l))return x;const u=new Set(x);return u.add(l),ht(u),u})},[]),i=a.useCallback(l=>{s(x=>{if(!x.has(l))return x;const u=new Set(x);return u.delete(l),ht(u),u})},[]),o=a.useCallback((l,x)=>{s(u=>{const f=new Set(u);for(const p of x)f.add(p);return ht(f),f})},[]),c=a.useCallback((l,x)=>{s(u=>{const f=new Set(u);for(const p of x)f.delete(p);return ht(f),f})},[]),d=a.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:i,hideAllForDaemon:o,showAllForDaemon:c,isHidden:d}}function sn({sendDaemonCommand:t,activeConv:s,ides:n,updateIdeChats:r,setToasts:i,setLocalUserMessages:o,setClearedTabs:c,setActionLogs:d,pinTab:l,isStandalone:x}){const[u,f]=a.useState(""),[p,b]=a.useState(!1),[g,I]=a.useState(!1),[B,N]=a.useState(!1),[j,L]=a.useState(!1),K=a.useRef(!1),h=a.useCallback(y=>{if(!y)return{};const W=y.sessionId?{targetSessionId:y.sessionId}:{};return He(y)||Be(y)?{...W,agentType:y.agentType||y.ideType}:y.streamSource==="agent-stream"?{...W,agentType:y.agentType}:W},[]),T=a.useCallback(async()=>{if(!s)return;const y=u.trim();if(!y||K.current)return;const W=s.ideId,D=s.tabKey;K.current=!0,L(!0),f(""),l(D,[100,500,1500,3e3]);const z=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,V={role:"user",content:y,timestamp:Date.now(),_localId:z};o(U=>({...U,[D]:[...U[D]||[],V]}));try{const U=W||s.daemonId||"";if(!U)return;await t(U,"send_chat",{message:y,text:y,...h(s)}),setTimeout(()=>{const re=Date.now()-6e4;o(Y=>{const ie=Y[D];if(!ie)return Y;const Ce=ie.filter(xe=>xe.timestamp>re);return Ce.length===ie.length?Y:{...Y,[D]:Ce}})},6e4)}catch(U){console.error("Send failed",U),f(y),o(re=>({...re,[D]:(re[D]||[]).filter(Y=>Y._localId!==z)}))}finally{K.current=!1,L(!1)}},[s,u,t,o,l,h]),S=a.useCallback(async()=>{if(s)try{x?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(y){console.error("Relaunch failed",y)}},[s,x,t]),R=a.useCallback(async y=>{try{await t("standalone","launch_ide",{ideType:y,enableCdp:!0})}catch(W){console.error("Launch failed",W)}},[t]),J=a.useCallback(async y=>{if(s){console.log("[ModalButton] ideId:",s.ideId,"button:",y),d(W=>[...W,{ideId:s.tabKey,text:`🖱️ **${y}** clicked`,timestamp:Date.now()}]);try{const D=(s.modalButtons||[]).indexOf(y),z=y.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),V=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(z),U=s.ideId||s.daemonId||"";(await t(U,"resolve_action",{button:y,action:V?"approve":"reject",...D>=0&&{buttonIndex:D},...h(s)})).success||d(Y=>[...Y,{ideId:s.tabKey,text:`⚠️ **${y}** failed — button not found`,timestamp:Date.now()}])}catch(W){console.error("[ModalButton] Error:",W),d(D=>[...D,{ideId:s.tabKey,text:`❌ **${y}** error`,timestamp:Date.now()}])}}},[s,t,d,h]),P=a.useCallback(async(y,W)=>{try{const D=y||(s==null?void 0:s.daemonId)||"",z=await t(D,"switch_chat",{id:W,sessionId:W,...h(s)}),V=z==null?void 0:z.result;(z==null?void 0:z.success)===!0||V==="switched"||V==="switched-by-title"||(V===!1||V==="not_found"?i(re=>[...re,{id:Date.now(),message:"⚠️ Session tab not found — try refreshing history",type:"warning",timestamp:Date.now()}]):typeof V=="string"&&V.startsWith("error:")?i(re=>[...re,{id:Date.now(),message:`⚠️ Switch error: ${V}`,type:"warning",timestamp:Date.now()}]):i(re=>[...re,{id:Date.now(),message:"⚠️ Session switch failed",type:"warning",timestamp:Date.now()}]))}catch(D){console.error("Switch failed",D),i(z=>[...z,{id:Date.now(),message:`❌ Switch failed: ${D.message||"connection error"}`,type:"warning",timestamp:Date.now()}])}},[s,t,i,h]),M=a.useCallback(async()=>{if(!(!s||p)){b(!0);try{const y=s.ideId||s.daemonId||"";await t(y,"new_chat",{...h(s)}),c(W=>({...W,[s.tabKey]:Date.now()})),o(W=>({...W,[s.tabKey]:[]}))}catch(y){console.error("New chat failed",y)}finally{b(!1)}}},[s,p,t,c,o,h]),oe=a.useCallback(async()=>{if(!s||B)return;N(!0);const y=s.tabKey;try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}}),l(y,[200,1500,3e3])}catch(W){console.error("Focus agent failed",W)}finally{N(!1)}},[s,B,t,l]),ee=a.useCallback(async()=>{var y;if(!(!s||g)){I(!0);try{const W=s.ideId||s.daemonId||"",D=await t(W,"list_chats",{forceExpand:!0,...h(s)}),z=(D==null?void 0:D.chats)||((y=D==null?void 0:D.result)==null?void 0:y.chats);D!=null&&D.success&&Array.isArray(z)&&r(s.ideId,z)}catch(W){console.error("Refresh history failed",W)}finally{I(!1)}}},[s,g,t,r,h]);return{agentInput:u,setAgentInput:f,isSendingChat:j,isCreatingChat:p,isRefreshingHistory:g,isFocusingAgent:B,handleSendChat:T,handleRelaunch:S,handleLaunchIde:R,handleModalButton:J,handleSwitchSession:P,handleNewChat:M,handleFocusAgent:oe,handleRefreshHistory:ee}}const Wt={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 Xr(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function qr(){const[t,s]=a.useState("unix"),[n,r]=a.useState("powershell"),[i,o]=a.useState(!1),c=t==="unix"?"unix":n;a.useEffect(()=>{s(Xr())},[]);const d=a.useCallback(()=>{navigator.clipboard.writeText(Wt[c].cmd).catch(()=>{}),o(!0),setTimeout(()=>o(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:d,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Wt[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Wt[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-text-muted opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:i?"✓":"📋"})]}),e.jsxs("div",{className:"text-text-muted text-[10px] font-sans mt-2",children:["Or via npm: ",e.jsx("span",{className:"text-text-secondary font-mono",children:"npm i -g @adhdev/daemon-standalone && adhdev-standalone"})]})]})}function Gr({conversations:t,ides:s,messageReceivedAt:n,actionLogs:r,ptyBuffers:i,screenshotMap:o,setScreenshotMap:c,sendDaemonCommand:d,updateIdeChats:l,setToasts:x,setLocalUserMessages:u,setClearedTabs:f,setActionLogs:p,pinTab:b,isStandalone:g,userName:I,groupIndex:B,isFocused:N,onFocus:j,isSplitMode:L,numGroups:K,onMoveTab:h,onClose:T,onReceiveTab:S,style:R,detectedIdes:J,handleLaunchIde:P,onActiveTabChange:M,initialActiveTabId:oe,initialTabOrder:ee,onTabOrderChange:y,onHideTab:W}){const{sendCommand:D}=st(),z=a.useRef(null),[V,U]=a.useState(!1),[re,Y]=a.useState(null),ie=a.useRef(0),Ce=a.useRef(null),[xe,Ee]=a.useState(oe??null);a.useEffect(()=>{oe&&oe!==xe&&Ee(oe)},[oe]);const[v,m]=a.useState(ee??[]),[k,E]=a.useState(null),ue=a.useRef(null),le=a.useRef(null);a.useEffect(()=>{const C=new Set(t.map(F=>F.tabKey));m(F=>{const ne=F.filter(G=>C.has(G)),X=t.filter(G=>!F.includes(G.tabKey)).map(G=>G.tabKey),ae=[...ne,...X];return ae.length===F.length&&ae.every((G,q)=>G===F[q])?F:ae})},[t]);const ve=k??v,me=a.useMemo(()=>{if(ve.length===0)return t;const C=new Map(ve.map((F,ne)=>[F,ne]));return[...t].sort((F,ne)=>{const X=C.get(F.tabKey)??999,ae=C.get(ne.tabKey)??999;return X-ae})},[t,ve]);a.useEffect(()=>{if(me.length===0){Ee(null),M==null||M(null);return}xe&&me.some(C=>C.tabKey===xe)||(Ee(me[0].tabKey),M==null||M(me[0].tabKey))},[me,xe]);const de=me.find(C=>C.tabKey===xe),Me=a.useCallback((C,F,ne)=>{m(X=>{const ae=X.filter(ge=>ge!==C),G=ae.indexOf(F);if(G<0)return X;const q=ne==="left"?G:G+1;return ae.splice(q,0,C),y==null||y(ae),ae}),E(null)},[y]),pe=a.useCallback((C,F,ne)=>{const ae=(v.length>0?v:t.map(ge=>ge.tabKey)).filter(ge=>ge!==C),G=ae.indexOf(F);if(G<0)return;const q=ne==="left"?G:G+1;ae.splice(q,0,C),ue.current=ae,E(ae)},[v,t]),he=sn({sendDaemonCommand:d,activeConv:de,ides:s,updateIdeChats:l,setToasts:x,setLocalUserMessages:u,setClearedTabs:f,setActionLogs:p,pinTab:b,isStandalone:g}),[Ne,Pe]=a.useState(null);a.useEffect(()=>{if(!Ne)return;const C=F=>{const ne=document.querySelector("[data-pane-context-menu]");ne&&ne.contains(F.target)||Pe(null)};return window.addEventListener("mousedown",C,!0),()=>window.removeEventListener("mousedown",C,!0)},[Ne]);const We="adhdev-tab-shortcuts",Oe=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[H,be]=a.useState(()=>{try{return JSON.parse(localStorage.getItem(We)||"{}")}catch{return{}}}),[fe,ye]=a.useState(null),_e=a.useCallback(C=>{const F=[];C.metaKey&&F.push(Oe?"⌘":"Meta"),C.ctrlKey&&F.push("Ctrl"),C.altKey&&F.push(Oe?"⌥":"Alt"),C.shiftKey&&F.push(Oe?"⇧":"Shift");const ne=C.key;if(["Control","Alt","Shift","Meta"].includes(ne))return null;const X=ne.length===1?ne.toUpperCase():ne;return F.push(X),F.join("+")},[Oe]),Se=a.useCallback((C,F)=>_e(C)===F,[_e]),O=a.useCallback(C=>{be(C),localStorage.setItem(We,JSON.stringify(C))},[]);a.useEffect(()=>{if(!fe)return;const C=F=>{if(F.preventDefault(),F.stopPropagation(),F.key==="Escape"){ye(null);return}const ne=_e(F);if(!ne)return;const X={...H};for(const[ae,G]of Object.entries(X))G===ne&&delete X[ae];X[fe]=ne,O(X),ye(null)};return window.addEventListener("keydown",C,!0),()=>window.removeEventListener("keydown",C,!0)},[fe,H,O,_e]),a.useEffect(()=>{const C=F=>{if(!(!F.ctrlKey&&!F.metaKey&&!F.altKey)){for(const[ne,X]of Object.entries(H))if(Se(F,X)&&me.some(ae=>ae.tabKey===ne)){F.preventDefault(),j(),Ee(ne),M==null||M(ne);return}}};return window.addEventListener("keydown",C),()=>window.removeEventListener("keydown",C)},[H,me,j,M,Se]);const se=de&&He(de)&&!Be(de),Z=se?"terminal":"chat";a.useEffect(()=>{const C=()=>{ie.current=0,U(!1),Y(null)};return window.addEventListener("dragend",C),window.addEventListener("drop",C),()=>{window.removeEventListener("dragend",C),window.removeEventListener("drop",C)}},[]);const je=a.useRef(null);return a.useEffect(()=>{const C=je.current;if(!C)return;const F=ne=>{Math.abs(ne.deltaY)>Math.abs(ne.deltaX)&&(ne.preventDefault(),C.scrollLeft+=ne.deltaY)};return C.addEventListener("wheel",F,{passive:!1}),()=>C.removeEventListener("wheel",F)},[]),e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:j,style:{...R,outline:V?"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:je,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:[me.map((C,F)=>{const ne=xe===C.tabKey,X=C.status==="generating"?"agent-tab-generating":C.status==="waiting_approval"?"agent-tab-waiting":"",ae=C.connectionState==="failed"||C.connectionState==="closed",G=le.current===C.tabKey;return e.jsxs("div",{"data-tabkey":C.tabKey,className:`${X} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:q=>{le.current=C.tabKey,q.dataTransfer.setData("text/tab-key",C.tabKey),q.dataTransfer.effectAllowed="move"},onDragEnd:()=>{le.current=null;const q=ue.current;q&&(m(q),y==null||y(q)),ue.current=null,E(null),ie.current=0,U(!1)},onDragOver:q=>{const ge=le.current;if(!(!ge||ge===C.tabKey)&&q.dataTransfer.types.includes("text/tab-key")){q.preventDefault(),q.stopPropagation();const Q=q.currentTarget.getBoundingClientRect(),ke=Q.left+Q.width/2,Te=q.clientX<ke?"left":"right";pe(ge,C.tabKey,Te)}},onDrop:q=>{q.preventDefault(),q.stopPropagation();const ge=q.dataTransfer.getData("text/tab-key");if(ge&&ge!==C.tabKey){const Q=q.currentTarget.getBoundingClientRect(),ke=Q.left+Q.width/2,Te=q.clientX<ke?"left":"right";me.some(Ae=>Ae.tabKey===ge)?Me(ge,C.tabKey,Te):S&&S(ge)}E(null)},onClick:q=>{q.stopPropagation(),j(),Ee(C.tabKey),M==null||M(C.tabKey),C.streamSource==="agent-stream"&&C.agentType&&D(C.ideId,"focus_session",{agentType:C.agentType,...C.sessionId&&{targetSessionId:C.sessionId}}).catch(()=>{}),He(C)&&setTimeout(()=>{var ge,Q;return(Q=(ge=z.current)==null?void 0:ge.bumpResize)==null?void 0:Q.call(ge)},100)},onContextMenu:q=>{q.preventDefault(),Pe({x:q.clientX,y:q.clientY,tabKey:C.tabKey})},onTouchStart:q=>{const ge=q.touches[0],Q=ge.clientX,ke=ge.clientY;Ce.current=setTimeout(()=>{Pe({x:Q,y:ke,tabKey:C.tabKey})},600)},onTouchEnd:()=>{Ce.current&&clearTimeout(Ce.current)},onTouchMove:()=>{Ce.current&&clearTimeout(Ce.current)},style:{background:ne?"var(--bg-primary)":"var(--bg-glass)",borderTop:ne?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:ne?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:ne?"1px solid var(--border-subtle)":"1px solid transparent",opacity:G?.4:ae?ne?.6:.3:ne?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[C.status==="generating"?e.jsx("div",{className:"tab-spinner"}):C.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):ae?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):C.connectionState==="connecting"||C.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):C.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:C.displayPrimary,children:C.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:ae?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):C.connectionState==="connecting"||C.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[C.displaySecondary,C.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",C.machineName]})]})]})})]}),H[C.tabKey]&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${H[C.tabKey]}`,children:H[C.tabKey]})]},C.tabKey)}),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:C=>{C.dataTransfer.types.includes("text/tab-key")&&(ie.current++,U(!0))},onDragOver:C=>{if(!C.dataTransfer.types.includes("text/tab-key"))return;C.preventDefault();const F=C.currentTarget.getBoundingClientRect(),ne=C.clientX-F.left;if(K<4&&h&&window.innerWidth>=768){const X=F.width/3;ne<X?Y("split-left"):ne>X*2?Y("split-right"):Y("merge");return}Y("merge")},onDragLeave:()=>{ie.current--,ie.current<=0&&(ie.current=0,U(!1),Y(null))},onDrop:C=>{ie.current=0,U(!1);const F=C.dataTransfer.getData("text/tab-key"),ne=F?t.some(ae=>ae.tabKey===F):!1,X=re;if(Y(null),E(null),!!F){if(C.preventDefault(),X==="split-left"&&h&&K<4&&window.innerWidth>=768){h(F,"split-left");return}if(X==="split-right"&&h&&K<4&&window.innerWidth>=768){h(F,"split-right");return}ne?m(ae=>{const G=ae.filter(q=>q!==F);return G.push(F),y==null||y(G),G}):S&&S(F)}},children:[V&&e.jsxs("div",{className:"absolute inset-0 z-10 pointer-events-none hidden md:flex",children:[e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:re==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:re==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:K<4&&h?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Left"})}),e.jsx("div",{className:"flex-1 border-r border-white/10 transition-all duration-150 flex items-center justify-center",style:{background:re==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:re==="merge"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)"},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Move Here"})}),e.jsx("div",{className:"flex-1 transition-all duration-150 flex items-center justify-center",style:{background:re==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:re==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:K<4&&h?1:.45},children:e.jsx("div",{className:"px-3 py-1.5 rounded-full text-[11px] font-semibold text-white bg-black/45 backdrop-blur-sm",children:"Split Right"})})]}),de?e.jsxs(e.Fragment,{children:[e.jsx(Kn,{activeConv:de,onModalButton:he.handleModalButton}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!se&&!Be(de)&&o[de.ideId]?e.jsx(zn,{screenshotUrl:o[de.ideId],mode:"preview",onDismiss:()=>{const C={...o};delete C[de.ideId],c(C)}}):!se&&!Be(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(Jt,{size:14})}),e.jsx("span",{className:"flex-1",children:"CDP not connected — chat history & screenshots unavailable."}),e.jsx("button",{className:"btn btn-sm bg-yellow-500/15 text-yellow-500 border border-yellow-500/30 text-[10px] whitespace-nowrap shrink-0",onClick:he.handleRelaunch,children:"Relaunch with CDP"})]}):null}),Z==="terminal"?e.jsx(Hn,{activeConv:de,ptyBuffers:i,terminalRef:z,agentInput:he.agentInput,setAgentInput:he.setAgentInput,handleSendChat:he.handleSendChat,isSendingChat:he.isSendingChat}):e.jsx(Os,{activeConv:de,ides:s,agentInput:he.agentInput,setAgentInput:he.setAgentInput,handleSendChat:he.handleSendChat,isSendingChat:he.isSendingChat,handleFocusAgent:he.handleFocusAgent,isFocusingAgent:he.isFocusingAgent,messageReceivedAt:n,actionLogs:r,userName:I})]}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:t.length===0&&!L&&J&&P?e.jsxs("div",{className:"empty-dashboard flex-1 flex flex-col items-center justify-center -mt-8",children:[e.jsx("div",{className:"glow-orb mb-6 opacity-90 animate-bounce",style:{animationDuration:"3s"},children:e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-16 h-16 object-contain"})}),e.jsxs("div",{className:"text-center max-w-lg",children:[e.jsx("h2",{className:"font-bold text-2xl mb-2.5 tracking-tight text-text-primary",children:"Waiting for your IDE"}),e.jsx("p",{className:"text-[14px] text-text-secondary mb-8 leading-relaxed max-w-md mx-auto",children:g?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!g&&e.jsx(qr,{}),g&&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(C=>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:()=>P&&P(C.type),children:[e.jsx(Ls,{size:14,className:"opacity-70"})," Launch ",C.name]},C.type))})]}),!g&&e.jsx("div",{className:"mt-8",children:e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"text-sm font-medium text-accent hover:opacity-80 transition-colors flex items-center justify-center gap-1.5",children:"📚 Read the documentation →"})})]})]}):e.jsx("div",{className:"text-sm text-text-muted opacity-50",children:L?"Move a tab here to view":"No active agent"})})]}),Ne&&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:Ne.x,top:Ne.y},children:[h&&B>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{h(Ne.tabKey,"left"),Pe(null)},children:"← Move to Left Group"}),h&&B<K-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{h(Ne.tabKey,"right"),Pe(null)},children:"Move to Right Group →"}),h&&K<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{h(Ne.tabKey,"split-left"),Pe(null)},children:"⇤ Split Left"}),h&&K<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{h(Ne.tabKey,"split-right"),Pe(null)},children:"Split Right ⇥"}),e.jsx("div",{className:"border-t border-border-subtle my-1 "}),e.jsxs("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:C=>{C.stopPropagation(),ye(Ne.tabKey),Pe(null)},children:["⌨ ",H[Ne.tabKey]?`Change shortcut (${H[Ne.tabKey]})`:"Set shortcut"]}),H[Ne.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 C={...H};delete C[Ne.tabKey],O(C),Pe(null)},children:"✕ Remove shortcut"}),W&&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:()=>{W(Ne.tabKey),Pe(null)},children:"🚫 Hide from Dashboard"})]}),!h&&!W&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),fe&&e.jsx("div",{className:"fixed inset-0 z-[60] flex items-center justify-center",style:{background:"rgba(0,0,0,0.5)",backdropFilter:"blur(2px)"},onClick:()=>ye(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:C=>C.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. ",Oe?"⌘+1":"Ctrl+1",", ",Oe?"⌥+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 Ot=[{icon:"🦦",title:"Welcome to ADHDev",desc:"Monitor and control your AI coding agents from anywhere — web, mobile, or CLI.",visual:"🎉"},{icon:"💬",title:"Real-time chat",desc:"See what your AI agent is doing in real-time. Send messages, approve or reject actions — all from your browser or phone.",visual:"📱"},{icon:"🖥️",title:"Remote desktop",desc:"View and control your IDE screen via P2P connection. Click, type, scroll — just like being there.",visual:"🖱️"},{icon:"🚀",title:"Get started",desc:"Install the daemon and link it to your dashboard. It connects automatically.",code:"npm install -g @adhdev/daemon-standalone && adhdev-standalone"}];function Jr({onClose:t}){const[s,n]=a.useState(0),r=Ot[s],i=s===Ot.length-1;return e.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:o=>{o.target===o.currentTarget&&t()},children:[e.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[e.jsx("button",{onClick:t,style:{position:"absolute",top:12,right:16,background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"1.2rem",cursor:"pointer"},children:"✕"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:Ot.map((o,c)=>e.jsx("div",{style:{width:c===s?24:8,height:8,borderRadius:4,background:c===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},c))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children: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():n(o=>o+1),className:"transition-opacity hover:opacity-90",style:{background:"linear-gradient(135deg, #7c3aed, #6366f1)",color:"#fff",border:"none",borderRadius:"0.5rem",padding:"0.55rem 1.5rem",fontSize:"0.9rem",fontWeight:600,cursor:"pointer"},children:i?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
|
|
51
|
-
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
|
|
52
|
-
@keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
|
|
53
|
-
`})]})}function Zr(t,s){if(t.size!==s.size)return!1;for(const[n,r]of t)if(s.get(n)!==r)return!1;return!0}function Qr(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function gs(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(i=>s[i]===t[i])}function kt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,d]of t)!n.has(c)||d<=0||r.includes(d)||r.push(d);r.sort((c,d)=>c-d);const i={};r.forEach((c,d)=>{i[c]=d}),r.length===0&&(i[0]=0);const o=new Map;for(const[c,d]of t){if(!n.has(c)||d<=0)continue;const l=i[d];typeof l=="number"&&l>0&&o.set(c,l)}return{assignments:o,groupCount:Math.max(1,r.length),mapping:i,usedGroups:r}}function bs(t,s){const n={};for(const[r,i]of Object.entries(t)){const o=s[Number(r)];typeof o=="number"&&(n[o]=i)}return n}function ea(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(i=>i<t)??s[0];return n[r]??0}function ta(t,s,n){if(s.length<=1)return[];const r=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),i=r.length===s.length?r:Array(n).fill(100/n),o=i.reduce((c,d)=>c+d,0);return o>0?i.map(c=>c/o*100):Array(n).fill(100/n)}function sa(){const{sendCommand:t}=st(),[s,n]=Ns(),r=s.get("activeTab"),i=$t(),{updateIdeChats:o,screenshotMap:c,setScreenshotMap:d}=i,l=i.ides||[],[x,u]=a.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),f=i.toasts||[],p=i.setToasts||(()=>{}),b=i.wsStatus||"connected",g=i.isConnected??!0,I=i.connectionStates||{};i.retryConnection;const B=i.showReconnected||!1,[N,j]=a.useState(()=>{try{const w=localStorage.getItem("adhdev_splitGroups");if(w){const A=JSON.parse(w);return new Map(A)}}catch{}return new Map}),[L,K]=a.useState(()=>{try{const w=localStorage.getItem("adhdev_focusedGroup");if(w)return parseInt(w,10)||0}catch{}return 0}),[h,T]=a.useState(()=>{try{const w=localStorage.getItem("adhdev_groupActiveTabs");if(w)return JSON.parse(w)}catch{}return{}}),S=a.useRef(!1),[R,J]=a.useState(()=>{try{const w=localStorage.getItem("adhdev_groupTabOrders");if(w)return JSON.parse(w)}catch{}return{}}),[P,M]=a.useState(()=>{try{const w=localStorage.getItem("adhdev_splitSizes");if(w)return JSON.parse(w)}catch{}return[]});a.useEffect(()=>{try{N.size===0?localStorage.removeItem("adhdev_splitGroups"):localStorage.setItem("adhdev_splitGroups",JSON.stringify([...N.entries()]))}catch{}},[N]),a.useEffect(()=>{try{P.length>0?localStorage.setItem("adhdev_splitSizes",JSON.stringify(P)):localStorage.removeItem("adhdev_splitSizes")}catch{}},[P]),a.useEffect(()=>{try{localStorage.setItem("adhdev_focusedGroup",String(L))}catch{}},[L]),a.useEffect(()=>{try{localStorage.setItem("adhdev_groupActiveTabs",JSON.stringify(h))}catch{}},[h]),a.useEffect(()=>{try{localStorage.setItem("adhdev_groupTabOrders",JSON.stringify(R))}catch{}},[R]);const[oe,ee]=a.useState(()=>typeof window<"u"&&window.innerWidth<768);a.useEffect(()=>{const w=window.matchMedia("(max-width: 767px)"),A=$=>ee($.matches);return w.addEventListener("change",A),()=>w.removeEventListener("change",A)},[]);const[y,W]=a.useState({}),[D,z]=a.useState(!1),[V,U]=a.useState([]),[re,Y]=a.useState({}),[ie,Ce]=a.useState({}),xe=l.find(w=>w.type==="adhdev-daemon"),Ee=(xe==null?void 0:xe.detectedIdes)||[],v=!!xe,m=a.useMemo(()=>{const w=l.filter($=>$.type!=="adhdev-daemon"),A=new Map;for(const $ of w){const _=A.get($.id);if(!_)A.set($.id,$);else{const te=(_.workspace?1:0)+(_.activeChat?1:0);(($.workspace?1:0)+($.activeChat?1:0)>te||($.timestamp||0)>(_.timestamp||0))&&A.set($.id,$)}}return Array.from(A.values())},[l]),k=a.useMemo(()=>{const w=ar(m,re,l,I),A=Date.now();return w.map($=>{const _=ie[$.tabKey];return _&&A-_<5e3?{...$,messages:[],title:""}:$})},[m,re,ie,l]),E=a.useCallback(w=>{if(w)return k.find(A=>A.sessionId===w||A.ideId===w||A.tabKey===w||A.ideType===w||A.agentType===w)},[k]),{hiddenTabs:ue,toggleTab:le}=Yr(),ve=a.useMemo(()=>k.filter(w=>!ue.has(w.tabKey)),[k,ue]),me=a.useMemo(()=>ve.map(w=>w.tabKey),[ve]),de=a.useMemo(()=>kt(N,me),[N,me]),Me=de.assignments,pe=a.useMemo(()=>oe?1:de.groupCount,[de.groupCount,oe]),he=pe>1,Ne=a.useCallback((w,A)=>{const $={};for(const[_,te]of Object.entries(w)){const ce=Number(_);$[ce>=A?ce+1:ce]=te}return $},[]),Pe=a.useCallback(w=>Array(w).fill(100/w),[]),We=a.useCallback((w,A)=>{j($=>{const _=new Map(kt($,me).assignments);return A===0?_.delete(w):_.set(w,A),_}),T($=>({...$,[A]:w})),K(A)},[me]),Oe=a.useCallback(w=>{j(A=>{const $=kt(A,me).assignments,_=new Map;for(const[te,ce]of $)ce!==w&&(ce>w?_.set(te,ce-1):_.set(te,ce));return _}),M(A=>{if(A.length<=1)return[];const $=[...A];$.splice(w,1);const _=$.reduce((te,ce)=>te+ce,0);return _>0?$.map(te=>te/_*100):[]}),K(0)},[me]),H=a.useRef(null),be=a.useCallback((w,A)=>{A.preventDefault();const $=H.current;if(!$)return;const _=A.clientX,te=$.offsetWidth,ce=P.length===pe?[...P]:Array(pe).fill(100/pe),we=ze=>{const Ye=(ze.clientX-_)/te*100,xt=[...ce];xt[w]=Math.max(15,ce[w]+Ye),xt[w+1]=Math.max(15,ce[w+1]-Ye),M(xt)},$e=()=>{document.removeEventListener("mousemove",we),document.removeEventListener("mouseup",$e),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",we),document.addEventListener("mouseup",$e)},[P,pe]),fe=a.useCallback((w,A,$)=>{const _=pe;if(_>=4)return;const te=$==="left"?A:A+1;j(ce=>{const we=kt(ce,me).assignments,$e=new Map;for(const ze of ve){const lt=we.get(ze.tabKey)??0,Ye=lt>=te?lt+1:lt;Ye>0&&$e.set(ze.tabKey,Ye)}return te>0&&$e.set(w,te),$e}),M(ce=>{const we=ce.length===_?[...ce]:Pe(_),$e=we[A]??100/_,ze=Math.max(15,$e/2),lt=Math.max(15,$e/2),Ye=[...we];Ye[A]=ze,Ye.splice(te,0,lt);const xt=Ye.reduce((Rt,nn)=>Rt+nn,0);return Ye.map(Rt=>Rt/xt*100)}),T(ce=>{const we=Ne(ce,te);return we[te]=w,we}),J(ce=>{const we=Ne(ce,te);return we[te]=[w],we}),K(te)},[pe,ve,me,Pe,Ne]);a.useEffect(()=>{hr()},[]);const ye=a.useMemo(()=>ve.map(w=>({id:w.tabKey,name:w.title||w.agentName||w.ideId,status:w.status,activeModal:w.modalMessage?{message:w.modalMessage,buttons:w.modalButtons}:null})),[ve]);gr(ye),a.useEffect(()=>{Zr(N,Me)||j(Me)},[N,Me]),a.useEffect(()=>{const{mapping:w,usedGroups:A}=de;T($=>{const _=bs($,w);return gs($,_)?$:_}),J($=>{const _=bs($,w);return gs($,_)?$:_}),K($=>{const _=oe?0:ea($,A,w);return $===_?$:_}),M($=>{const _=oe?[]:ta($,A,de.groupCount);return Qr($,_)?$:_})},[de,oe]);const _e=a.useMemo(()=>{const w=Array.from({length:pe},()=>[]);for(const A of ve){const $=Me.get(A.tabKey)??0,_=Math.min($,pe-1);w[_].push(A)}return w},[ve,Me,pe]);a.useEffect(()=>{if(!r||S.current||k.length===0)return;const w=E(r);if(w){const A=Me.get(w.tabKey)??0;T($=>({...$,[A]:w.tabKey})),K(A),S.current=!0,n($=>{const _=new URLSearchParams($);return _.delete("activeTab"),_},{replace:!0})}},[r,k,Me,E]),a.useEffect(()=>{if(Object.keys(ie).length===0)return;const A=setTimeout(()=>{Ce($=>{const _=Date.now(),te={};for(const[ce,we]of Object.entries($))_-we<5e3&&(te[ce]=we);return Object.keys(te).length===Object.keys($).length?$:te})},5500);return()=>clearTimeout(A)},[ie]);const Se=a.useMemo(()=>{var A,$;const w=h[L];if(w){const _=k.find(te=>te.tabKey===w);if(_)return _}return((A=_e[L])==null?void 0:A[0])||(($=_e[0])==null?void 0:$[0])},[h,L,k,_e]),O=a.useCallback((w,A)=>{},[]);a.useEffect(()=>{var _;const w=Date.now();let A=!1;const $={...y};for(const te of k)(_=te.messages)!=null&&_.length&&te.messages.forEach((ce,we)=>{const $e=`${te.ideId}-${ce.id??`i-${we}`}`;$[$e]==null&&($[$e]=w,A=!0)});A&&W($)},[k]);const se=a.useRef(!1);a.useEffect(()=>{if(!D){se.current=!1;return}if(!Se||se.current||C)return;const w=l.find(A=>A.id===Se.ideId);w&&(!w.chats||w.chats.length===0)&&(se.current=!0,ae())},[D,Se==null?void 0:Se.ideId]),a.useEffect(()=>{const w=setInterval(()=>{const A=Date.now()-3e5;U($=>{const _=$.filter(te=>te.timestamp>A).slice(-100);return _.length===$.length?$:_})},6e4);return()=>clearInterval(w)},[]);const Z=a.useRef(new Map);a.useEffect(()=>{const w=($,_)=>{if(_){zs.emit($,_);for(const te of k){if(!He(te))continue;if($===te.sessionId||$===te.ideId||$===te.tabKey){const we=Z.current.get(te.tabKey)||[];we.push(_),we.length>1e4&&we.splice(0,we.length-5e3),Z.current.set(te.tabKey,we)}}}},A=Ft.onPtyOutput(w);return()=>{A()}},[k]),a.useEffect(()=>{const w=A=>{if(A.ctrlKey&&A.key==="\\"){if(A.preventDefault(),he)j(new Map),K(0);else{const $=k[1];$&&fe($.tabKey,0,"right")}return}A.ctrlKey&&(A.key==="["||A.key==="]")&&he&&(A.preventDefault(),K($=>A.key==="]"?Math.min($+1,pe-1):Math.max($-1,0)))};return window.addEventListener("keydown",w),()=>window.removeEventListener("keydown",w)},[he,k,fe,pe]),a.useEffect(()=>{et.setIdes(l)},[l]),a.useEffect(()=>{et.setResolveAction((w,A,$)=>{t(w,A,$).catch(()=>{})})},[t]),a.useEffect(()=>{const w=et.onToast(_=>{p(ce=>ce.some($e=>$e.message===_.message&&_.timestamp-$e.timestamp<3e3)?ce:[...ce.slice(-4),{id:_.id,message:_.message,type:_.type,timestamp:_.timestamp,targetKey:_.targetKey,actions:_.actions}]);const te=_.duration||5e3;setTimeout(()=>p(ce=>ce.filter(we=>we.id!==_.id)),te)}),A=et.onSystemMessage((_,te)=>{Y(ce=>({...ce,[_]:[...ce[_]||[],te]}))}),$=et.onClearSystemMessage((_,te)=>{Y(ce=>{var we;return(we=ce[_])!=null&&we.length?{...ce,[_]:ce[_].filter($e=>{var ze;return!($e.role==="system"&&((ze=$e._localId)!=null&&ze.startsWith(te)))})}:ce})});return()=>{w(),A(),$()}},[]),a.useEffect(()=>{const w=Fs.on("status_event",A=>et.handleRawEvent(A,"ws"));return()=>{w()}},[]),a.useEffect(()=>{var A;const w=$=>{const _=$.data;if((_==null?void 0:_.type)==="notification_action"&&_.action==="approve"&&(_.ideId||_.targetSessionId||_.targetKey)){const te=_.targetSessionId||_.targetKey||_.ideId,ce=E(te),we=(ce==null?void 0:ce.ideId)||_.ideId;if(!we)return;t(we,"resolve_action",{action:"approve",button:"Approve",...(ce==null?void 0:ce.sessionId)&&{targetSessionId:ce.sessionId},..._.targetSessionId&&{targetSessionId:_.targetSessionId}}).catch($e=>console.error("[SW Action] approve failed:",$e))}};return(A=navigator.serviceWorker)==null||A.addEventListener("message",w),()=>{var $;return($=navigator.serviceWorker)==null?void 0:$.removeEventListener("message",w)}},[E,t]);const{isCreatingChat:je,isRefreshingHistory:C,handleLaunchIde:F,handleSwitchSession:ne,handleNewChat:X,handleRefreshHistory:ae}=sn({sendDaemonCommand:t,activeConv:Se,ides:l,updateIdeChats:o,setToasts:p,setLocalUserMessages:Y,setClearedTabs:Ce,setActionLogs:U,pinTab:O,isStandalone:v}),G=a.useCallback(async()=>{if(!Se||!He(Se)||Be(Se))return;const w=Se.ideType||Se.agentType||"";if(!window.confirm(`Stop ${w}?
|
|
54
|
-
This will terminate the CLI process.`))return;const A=Se.ideId||Se.daemonId||"";try{await t(A,"stop_cli",{cliType:w,targetSessionId:Se.sessionId})}catch($){console.error("Stop CLI failed:",$)}},[Se,t]),q=a.useMemo(()=>l.filter(w=>w.type==="adhdev-daemon"&&w.versionMismatch),[l]),[ge,Q]=a.useState(!1),[ke,Te]=a.useState({}),Ae=a.useCallback(async w=>{var A,$;Te(_=>({..._,[w]:"upgrading"}));try{const _=await t(w,"daemon_upgrade",{});(A=_==null?void 0:_.result)!=null&&A.upgraded||($=_==null?void 0:_.result)!=null&&$.success?Te(te=>({...te,[w]:"done"})):Te(te=>({...te,[w]:"error"}))}catch{Te(_=>({..._,[w]:"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(Un,{wsStatus:b,showReconnected:B}),q.length>0&&!ge&&e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 bg-amber-500/[0.08] border-b border-amber-500/20 text-xs text-text-secondary shrink-0 flex-wrap",children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",children:e.jsx($s,{size:14,className:"text-amber-500"})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available: ",e.jsxs("strong",{children:["v",q[0].version]})," → ",e.jsxs("strong",{children:["v",q[0].serverVersion]})]}),q.map(w=>{const A=pt(w,{fallbackId:w.id}),$=ke[w.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:A}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",w.version]}),$==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):$==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):$==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>Ae(w.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:()=>Ae(w.id),children:"Upgrade"})]},w.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:()=>Q(!0),title:"Dismiss",children:"✕"})]}),e.jsx(qn,{activeConv:Se,agentCount:m.length,wsStatus:b,isConnected:g,onOpenHistory:()=>z(!0),onStopCli:G}),e.jsx("div",{ref:H,className:`flex-1 min-h-0 flex ${he?"flex-row":"flex-col"} overflow-hidden`,children:_e.map((w,A)=>{const $=he&&P.length===pe?`${P[A]}%`:void 0;return e.jsxs(pn.Fragment,{children:[he&&A>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:_=>be(A-1,_),onDoubleClick:()=>Oe(A),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(Gr,{style:he?{flexBasis:$??`${100/pe}%`,flexGrow:$?0:1,flexShrink:$?0:1}:void 0,conversations:w,ides:l,messageReceivedAt:y,actionLogs:V,ptyBuffers:Z,screenshotMap:c,setScreenshotMap:d,sendDaemonCommand:t,updateIdeChats:o,setToasts:p,setLocalUserMessages:Y,setClearedTabs:Ce,setActionLogs:U,pinTab:O,isStandalone:v,userName:i.userName,groupIndex:A,isFocused:L===A,onFocus:()=>K(A),isSplitMode:he,numGroups:pe,onMoveTab:(_,te)=>{te==="left"&&A>0?We(_,A-1):te==="right"&&A<pe-1?We(_,A+1):te==="split-left"&&pe<4?fe(_,A,"left"):te==="split-right"&&pe<4&&fe(_,A,"right")},onClose:he?()=>Oe(A):void 0,onReceiveTab:_=>We(_,A),detectedIdes:A===0?Ee:void 0,handleLaunchIde:A===0?F:void 0,onActiveTabChange:_=>T(te=>({...te,[A]:_})),initialActiveTabId:h[A],initialTabOrder:R[A],onTabOrderChange:_=>J(te=>({...te,[A]:_})),onHideTab:le})]},A)})}),D&&Se&&e.jsx(Vs,{activeConv:Se,ides:l,isCreatingChat:je,isRefreshingHistory:C,onClose:()=>z(!1),onNewChat:X,onSwitchSession:ne,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(Ys,{toasts:f,onDismiss:w=>p(A=>A.filter($=>$.id!==w)),onClickToast:w=>{if(w.targetKey){const A=E(w.targetKey);A&&K(Me.get(A.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
|
-
`}),x&&e.jsx(Jr,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}u(!1)}})]})}function na(t){return t.split(":")[0]||""}function ra({renderHeaderActions:t}={}){var Oe;const{id:s}=ks(),n=jt(),r=$t(),i=r.ides||[],o=r.updateIdeChats||(()=>{}),c=r.connectionStates||{},{sendCommand:d}=st(),l=a.useMemo(()=>na(s||""),[s]),x=a.useMemo(()=>i.find(H=>H.id===s),[i,s]),u=(x==null?void 0:x.type)||void 0,f=u?u.charAt(0).toUpperCase()+u.slice(1):"IDE",p=(x==null?void 0:x.activeChat)||null,b=(x==null?void 0:x.agentStreams)||[],g=r.isConnected??!0,I=c[l]||(g?"connected":"new"),B=((Oe=r.connectionTransports)==null?void 0:Oe[l])||"unknown",N=a.useMemo(()=>i.find(H=>H.id===l||H.daemonId===l),[i,l]),j=N?pt(N,{fallbackId:l}):"",L=(x==null?void 0:x.workspace)||"",[K]=Ns(),h=typeof window<"u"&&window.innerWidth<=768,T=K.get("view")||(h?"chat":"split"),[S,R]=a.useState(T),[J,P]=a.useState("native"),[M,oe]=a.useState(!1),[ee,y]=a.useState(!1),[W,D]=a.useState(!1),[z,V]=a.useState(""),[U,re]=a.useState(!1),[Y,ie]=a.useState(null),[Ce,xe]=a.useState(null),[Ee,v]=a.useState([]),m=a.useRef(!1),k=Ke(p==null?void 0:p.status,{activeModal:p==null?void 0:p.activeModal}),E=a.useMemo(()=>{var H,be;return{ideId:s||"",sessionId:(x==null?void 0:x.sessionId)||(x==null?void 0:x.instanceId),daemonId:l,agentName:Ht(u||""),agentType:u||"",status:k,title:(p==null?void 0:p.title)||"",messages:(p==null?void 0:p.messages)||[],ideType:u||"",workspaceName:(x==null?void 0:x.workspaceName)||"",displayPrimary:f,displaySecondary:(x==null?void 0:x.workspaceName)||"",cdpConnected:!0,modalButtons:(H=p==null?void 0:p.activeModal)==null?void 0:H.buttons,modalMessage:(be=p==null?void 0:p.activeModal)==null?void 0:be.message,streamSource:"native",tabKey:`ide-${s}`}},[s,l,u,p,x,f,k]),ue=a.useMemo(()=>b.map(H=>{var fe,ye;const be=Ut(H);return{ideId:s||"",sessionId:H.sessionId||H.instanceId,daemonId:l,agentName:H.agentName,agentType:H.agentType,status:be,title:"",messages:H.messages.map((_e,Se)=>({role:_e.role,content:_e.content,kind:_e.kind,id:`${H.agentType}-${Se}`,receivedAt:_e.timestamp})),ideType:H.agentType,workspaceName:"",displayPrimary:H.agentName,displaySecondary:"",cdpConnected:!0,modalButtons:(fe=H.activeModal)==null?void 0:fe.buttons,modalMessage:(ye=H.activeModal)==null?void 0:ye.message,streamSource:"agent-stream",tabKey:`agent-stream-${H.agentType}`}}),[b,s,l]),le=a.useMemo(()=>J==="native"?E:ue.find(H=>H.agentType===J)||E,[J,E,ue]),ve=a.useCallback(()=>le.streamSource==="agent-stream"?{targetSessionId:le.sessionId,agentType:le.agentType}:le.sessionId?{targetSessionId:le.sessionId}:{},[le]);a.useEffect(()=>l?Qe.onScreenshot("ide-page",(be,fe)=>{if(be!==l)return;const ye=new FileReader;ye.onload=()=>ie(ye.result),ye.readAsDataURL(fe)}):void 0,[l]),a.useEffect(()=>{I!=="connected"&&ie(null)},[I]),a.useEffect(()=>{var be;return l?((be=Qe.onStatus)==null?void 0:be.call(Qe,(fe,ye)=>{fe===l&&ye!=null&&ye.screenshotUsage&&xe(ye.screenshotUsage)}))||(()=>{}):void 0},[l]);const me=a.useMemo(()=>{if(!s)return u;const H=s.split(":");return H.length>=3&&H[1]==="ide"?H.slice(2).join(":"):u},[s,u]);a.useEffect(()=>{ie(null)},[l,s,me]),a.useEffect(()=>{const H=l?Qe.get(l):null;!H||!(I==="connected")||(S!=="chat"&&me?H.startScreenshots(me):H.stopScreenshots(me))},[S,I,me,l]);const de=a.useCallback(async(H,be={})=>{if(!s)throw new Error("No IDE ID");return await d(s,H,be)},[s]),Me=async()=>{const H=z.trim();if(!(!H||!s||U)){V(""),re(!0);try{await de("send_chat",{message:H,text:H,waitForResponse:!0,...le.sessionId&&{targetSessionId:le.sessionId},...J!=="native"&&{agentType:J}})}catch(be){console.error("[IDE] Send failed:",be)}finally{re(!1)}}},pe=a.useCallback((H,be="warning")=>{const fe=Date.now()+Math.floor(Math.random()*1e3);v(ye=>[...ye,{id:fe,message:H,type:be}]),window.setTimeout(()=>{v(ye=>ye.filter(_e=>_e.id!==fe))},5e3)},[]),he=a.useCallback(async()=>{var H;if(!(!s||W)){D(!0);try{const be=await d(s,"list_chats",{forceExpand:!0,...ve()}),fe=(be==null?void 0:be.chats)||((H=be==null?void 0:be.result)==null?void 0:H.chats);be!=null&&be.success&&Array.isArray(fe)&&o(s,fe)}catch(be){console.error("[IDE] Refresh history failed:",be),pe("히스토리 새로고침에 실패했습니다.","warning")}finally{D(!1)}}},[s,W,d,ve,o,pe]),Ne=a.useCallback(async(H,be)=>{if(s)try{const fe=await d(s,"switch_chat",{id:be,sessionId:be,...ve()}),ye=fe==null?void 0:fe.result;(fe==null?void 0:fe.success)===!0||ye==="switched"||ye==="switched-by-title"||(ye===!1||ye==="not_found"?pe("세션 탭을 찾지 못했습니다. 히스토리를 새로고침해 보세요.","warning"):typeof ye=="string"&&ye.startsWith("error:")?pe(`세션 전환 오류: ${ye}`,"warning"):pe("세션 전환에 실패했습니다.","warning"))}catch(fe){console.error("[IDE] Switch session failed:",fe),pe(`세션 전환 실패: ${(fe==null?void 0:fe.message)||"connection error"}`,"warning")}},[s,d,ve,pe]),Pe=a.useCallback(async()=>{if(!(!s||ee)){y(!0);try{await d(s,"new_chat",{...ve()})}catch(H){console.error("[IDE] New chat failed:",H),pe("새 채팅 생성에 실패했습니다.","warning")}finally{y(!1)}}},[s,ee,d,ve,pe]);a.useEffect(()=>{if(!M){m.current=!1;return}m.current||W||(!(x!=null&&x.chats)||x.chats.length===0)&&(m.current=!0,he())},[M,x==null?void 0:x.chats,W,he]);const We=b.length>0;return s?e.jsxs("div",{className:"ide-page",children:[e.jsxs("header",{className:"ide-header",children:[e.jsxs("div",{className:"ide-header-left",children:[e.jsxs("div",{className:"ide-title",children:[e.jsx(dt,{size:16}),e.jsx("span",{className:"ide-name",children:f}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),L&&e.jsx("span",{className:"ide-workspace",children:L}),e.jsx("span",{className:"ide-badge",children:"REMOTE"})]}),e.jsxs("div",{className:"ide-status-pill",children:[e.jsx("span",{className:`ide-dot ${I==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:I==="connected"?"Connected":I==="connecting"?"Connecting":"WS"})]}),j&&e.jsx("span",{className:"ide-machine-label",children:j})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(H=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:S===H?"1px solid var(--accent-primary)":"none",background:S===H?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:S===H?"var(--accent-primary)":void 0},onClick:()=>R(H),children:H==="chat"?e.jsx(dt,{size:14}):H==="split"?"⊞":e.jsx(nt,{size:14})},H)),e.jsx("button",{className:"btn btn-secondary btn-sm flex items-center justify-center shrink-0",onClick:()=>oe(!0),title:"Chat History",children:e.jsx(_s,{size:14})}),t&&t({daemonId:l,ideInstanceId:s||""}),e.jsxs("button",{className:"btn btn-primary btn-sm flex items-center justify-center shrink-0",onClick:()=>n(-1),children:["←",e.jsx("span",{className:"hidden md:inline ml-1",children:"Back"})]})]})]}),e.jsxs("div",{className:"ide-content",children:[e.jsxs("div",{className:`ide-chat-panel ${S==="chat"?"full":""} ${S==="remote"?"hidden":""}`,children:[We&&e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${J==="native"?"active":""}`,onClick:()=>P("native"),children:f}),b.map(H=>{const be=J===H.agentType,fe=Ut(H),ye=fe==="waiting_approval",_e=fe==="generating";return e.jsxs("button",{className:`ide-chat-tab ${be?"active":""}`,onClick:()=>P(H.agentType),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:ye?"#f59e0b":_e?"var(--accent-primary)":"#64748b",boxShadow:_e?"0 0 6px var(--accent-primary)":"none"}}),H.agentName,ye&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},H.agentType)})]}),e.jsx(Os,{activeConv:le,ides:i,agentInput:z,setAgentInput:V,handleSendChat:Me,handleFocusAgent:()=>{},isFocusingAgent:!1,messageReceivedAt:{},actionLogs:[],userName:r.userName})]}),e.jsx("div",{className:`ide-remote-panel ${S==="remote"?"full":""} ${S==="chat"?"hidden":""}`,children:e.jsx(On,{addLog:()=>{},connState:I,connScreenshot:Y,screenshotUsage:Ce,transportType:B,onAction:async(H,be)=>{const fe=l?Qe.get(l):null;if(!fe||I!=="connected")return console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"};const ye=(x==null?void 0:x.instanceId)||me;return await fe.sendInput(H,be,ye)}})})]}),Ee.length>0&&e.jsx("div",{className:"ide-toasts",children:Ee.map(H=>e.jsx("div",{className:`ide-toast ${H.type}`,onClick:()=>v(be=>be.filter(fe=>fe.id!==H.id)),children:H.message},H.id))}),M&&e.jsx(Vs,{activeConv:le,ides:i,isCreatingChat:ee,isRefreshingHistory:W,onClose:()=>oe(!1),onNewChat:Pe,onSwitchSession:Ne,onRefreshHistory:he})]}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function aa({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:i}){const[o,c]=a.useState([]),[d,l]=a.useState(null),[x,u]=a.useState(!1),[f,p]=a.useState(!1),[b,g]=a.useState(!1),[I,B]=a.useState([]),[N,j]=a.useState([]),[L,K]=a.useState(null),[h,T]=a.useState(!1),[S,R]=a.useState(""),J=a.useRef(null),P=a.useCallback(v=>{J.current=v},[]),M=a.useCallback((v,m,k=!1)=>{c(E=>[...E.slice(-100),{timestamp:Date.now(),level:v,message:m}]),setTimeout(()=>{var E;return(E=i.current)==null?void 0:E.scrollIntoView({behavior:"smooth"})},100),k&&et.showToast(m,v==="error"||v==="warn"?"warning":"success")},[i]),oe=a.useCallback(async(v,m)=>{var k;if(!(!t||d)){l(v),M("info",`Launching ${Ue(v)}${m!=null&&m.workspace?` in ${m.workspace}`:""}...`);try{const E={ideType:v,enableCdp:!0};(k=m==null?void 0:m.workspace)!=null&&k.trim()?E.workspace=m.workspace.trim():m!=null&&m.useDefaultWorkspace&&(E.useDefaultWorkspace=!0);const ue=await n(t,"launch_ide",E);M(ue!=null&&ue.success?"info":"error",ue!=null&&ue.success?`${Ue(v)} launched`:`Failed: ${ue==null?void 0:ue.error}`,!0)}catch(E){M("error",`Launch error: ${E.message}`,!0)}finally{l(null)}}},[t,d,M,n]),ee=a.useCallback(async v=>{if(!t)return;const{cliType:m,dir:k,workspaceId:E,useDefaultWorkspace:ue,useHome:le,argsStr:ve,model:me}=v;if(!m){M("warn","Select a CLI or ACP provider first",!0);return}const de=ve?ve.split(/\s+/).filter(Boolean):void 0,Me=(k==null?void 0:k.trim())||(E?"(saved id)":ue?"(default workspace)":le?"(home)":"");M("info",`Launching ${m}${Me?` in ${Me}`:""}${me?` (model: ${me})`:""}...`);try{const pe={cliType:m,cliArgs:de,initialModel:me||void 0};k!=null&&k.trim()?pe.dir=k.trim():E?pe.workspaceId=E:ue?pe.useDefaultWorkspace=!0:le&&(pe.useHome=!0);const he=await n(t,"launch_cli",pe),Ne=(he==null?void 0:he.result)||he;he!=null&&he.success?(M("info",`${m} launched`,!0),(Ne==null?void 0:Ne.launchSource)==="home"?M("info","📂 Running in home directory (explicit choice)"):(Ne==null?void 0:Ne.launchSource)==="defaultWorkspace"&&M("info","📂 Using default workspace (explicit choice)")):(M("error",`Failed: ${(he==null?void 0:he.error)||(Ne==null?void 0:Ne.error)}`,!0),(he==null?void 0:he.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&K({cliType:m,argsStr:ve,model:me}))}catch(pe){M("error",`Launch error: ${pe.message}`,!0)}},[t,M,n]),y=a.useCallback((v,m,k,E)=>{if(t){if(!v){M("warn","Select a provider",!0);return}if(!m.trim()){K({cliType:v,argsStr:k,model:E});return}ee({cliType:v,dir:m,argsStr:k,model:E})}},[t,M,ee]),W=a.useCallback(async(v,m,k)=>{if(t&&window.confirm(`Stop ${v}?
|
|
68
|
-
This will terminate the process.`))try{const E=await n(t,"stop_cli",{cliType:v,dir:m,targetSessionId:k});E!=null&&E.success?M("info",`${v} stopped`,!0):M("error",`Stop failed: ${(E==null?void 0:E.error)||"Unknown error"}`,!0)}catch(E){M("error",`Stop failed: ${E.message}`,!0)}},[t,M,n]),D=a.useCallback(async v=>{try{await n(v.daemonId,"restart_ide",{ideType:v.type}),M("info",`${Ue(v.type)} restart initiated`,!0)}catch(m){M("error",`Restart failed: ${m.message}`,!0)}},[M,n]),z=a.useCallback(async v=>{if(window.confirm(`Stop ${Ue(v.type)}?
|
|
69
|
-
This will disconnect CDP and optionally kill the process.`))try{const m=await n(v.daemonId,"stop_ide",{ideType:v.type,killProcess:!0});m!=null&&m.success?M("info",`${Ue(v.type)} stopped`,!0):M("error",`Stop failed: ${(m==null?void 0:m.error)||"Unknown error"}`,!0)}catch(m){M("error",`Stop failed: ${m.message}`,!0)}},[M,n]),V=a.useCallback(async()=>{if(t)try{const v=await n(t,"detect_ides",{});M("info",`Found ${((v==null?void 0:v.result)||[]).length} IDE(s)`,!0)}catch(v){M("error",`Detection failed: ${v.message}`,!0)}},[t,M,n]),U=a.useCallback(async()=>{if(t){u(!0);try{const v=await n(t,"get_recent_workspaces",{});v!=null&&v.success&&Array.isArray(v==null?void 0:v.result)&&j(v.result)}catch(v){M("error",`Failed: ${v.message}`)}finally{u(!1)}}},[t,M,n]),re=a.useCallback(async v=>{if(!(!t||!v.trim())){p(!0);try{const m=await n(t,"workspace_add",{path:v.trim()});m!=null&&m.success?M("info",`Workspace added: ${v.trim()}`):M("error",(m==null?void 0:m.error)||"workspace_add failed")}catch(m){M("error",m.message)}finally{p(!1)}return!0}},[t,M,n]),Y=a.useCallback(async v=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){p(!0);try{const m=await n(t,"workspace_remove",{id:v});m!=null&&m.success?M("info","Workspace removed",!0):M("error",(m==null?void 0:m.error)||"workspace_remove failed",!0)}catch(m){M("error",m.message,!0)}finally{p(!1)}}},[t,M,n]),ie=a.useCallback(async v=>{var m;if(t){p(!0);try{const k=await n(t,"workspace_set_default",v===null?{clear:!0}:{id:v});if(k!=null&&k.success){M("info",v?"Default workspace updated":"Default workspace cleared",!0);const E=typeof k.defaultWorkspacePath=="string"?k.defaultWorkspacePath:"";E&&((m=J.current)==null||m.call(J,E))}else M("error",(k==null?void 0:k.error)||"workspace_set_default failed",!0)}catch(k){M("error",k.message,!0)}finally{p(!1)}}},[t,M,n]),Ce=a.useCallback(async v=>{var k;if(!t||!v.trim())return;const m=v.trim();p(!0);try{const E=await n(t,"workspace_set_default",{path:m});E!=null&&E.success?(M("info","Default workspace set from history"),(k=J.current)==null||k.call(J,m)):M("error",(E==null?void 0:E.error)||"Could not set default (path missing on disk?)")}catch(E){M("error",E.message)}finally{p(!1)}},[t,M,n]),xe=a.useCallback(async()=>{var v;if(t){g(!0);try{const m=await n(t,"get_cli_history",{}),k=(m==null?void 0:m.history)??((v=m==null?void 0:m.result)==null?void 0:v.history);m!=null&&m.success&&Array.isArray(k)&&B(k)}catch{}g(!1)}},[t,n]),Ee=a.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:S}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:S})}catch(v){M("warn",`Live nickname updated, but account sync failed: ${v.message}`)}M("info",`Nickname set to "${S||"(cleared)"}"`),T(!1)}catch(v){M("error",`Failed: ${v.message}`)}},[t,S,s,M,r,n]);return{logs:o,launchingIde:d,loadingWorkspaces:x,workspaceBusy:f,loadingHistory:b,cliHistory:I,recentWorkspaces:N,launchPick:L,setLaunchPick:K,editingNickname:h,setEditingNickname:T,nicknameInput:S,setNicknameInput:R,addLog:M,handleLaunchIde:oe,runLaunchCliCore:ee,handleLaunchCli:y,handleStopCli:W,handleRestartIde:D,handleStopIde:z,handleDetectIdes:V,handleLoadRecentWorkspaces:U,handleWorkspaceAdd:re,handleWorkspaceRemove:Y,handleWorkspaceSetDefault:ie,handleWorkspaceResumePath:Ce,loadCliHistory:xe,handleSaveNickname:Ee,setOnDefaultWorkspaceChanged:P}}function oa({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:i}){const{workspaceBusy:o,handleWorkspaceAdd:c,handleWorkspaceRemove:d,handleWorkspaceSetDefault:l}=i,[x,u]=a.useState(""),f=t.availableMem??t.freeMem,p=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-f)/t.totalMem*100))):0,b=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(wt,{icon:e.jsx(Ps,{size:16}),label:"Uptime",value:Zn(t.uptime)}),e.jsx(wt,{icon:e.jsx(nt,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(wt,{icon:e.jsx(Zt,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(wt,{icon:e.jsx(Ds,{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(as,{value:Math.min(Math.round(b/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${b.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(as,{value:p,max:100,label:"Memory",color:"#3b82f6",detail:`${os(t.totalMem-f)} / ${os(t.totalMem)}${t.platform==="darwin"?" (approx.)":""}`})]})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider flex items-center gap-1.5 mb-3",children:[e.jsx(Kt,{size:14})," Workspaces"]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center mb-3",children:[e.jsx("span",{className:"text-[10px] text-text-muted",children:"Default:"}),e.jsxs("select",{className:"text-xs bg-bg-primary border border-border-subtle rounded-lg px-2 py-1 max-w-[min(100%,420px)]",disabled:o,value:t.defaultWorkspaceId||"",onChange:g=>void l(g.target.value===""?null:g.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(g=>e.jsx("option",{value:g.id,children:g.label||g.path},g.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:x,disabled:o,onChange:g=>u(g.target.value),onKeyDown:g=>g.key==="Enter"&&void(async()=>{await c(x)&&u("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:o,onClick:async()=>{await c(x)&&u("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1 max-h-32 overflow-y-auto",children:(t.workspaces||[]).map(g=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[g.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:g.path,children:g.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:o,onClick:()=>void d(g.id),children:"Remove"})]},g.id))})]})]})}const ia={ide:{label:"IDE",plural:"IDEs",accent:"border-blue-500/[0.12]"},cli:{label:"CLI",plural:"CLIs",accent:"border-violet-500/[0.12]"},acp:{label:"ACP Agent",plural:"ACP agents",accent:"border-emerald-500/[0.12]"}};function zt({category:t,machine:s,machineId:n,providers:r,managedEntries:i,getIcon:o,actions:c,sendDaemonCommand:d}){const l=jt(),{handleLaunchIde:x,handleLaunchCli:u,handleStopCli:f,handleRestartIde:p,handleStopIde:b,handleDetectIdes:g,cliHistory:I,loadingHistory:B,loadCliHistory:N,launchingIde:j}=c,L=ia[t],K=t==="ide",h=t==="acp",T=r.filter(m=>m.category===t),[S,R]=a.useState(""),[J,P]=a.useState(""),[M,oe]=a.useState(""),[ee,y]=a.useState(s.defaultWorkspaceId||""),[W,D]=a.useState("");a.useEffect(()=>{!S&&T.length>0&&R(T[0].type)},[S,T.length]),a.useEffect(()=>{s.defaultWorkspaceId&&!ee&&y(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const z=(()=>{if(ee==="__custom__")return W.trim();if(!ee)return"";const m=(s.workspaces||[]).find(k=>k.id===ee);return(m==null?void 0:m.path)||""})(),[V,U]=a.useState({}),[re,Y]=a.useState(null);a.useEffect(()=>{if(!K||!n||!d)return;(async()=>{try{const k=await d(n,"get_ide_extensions",{}),E=(k==null?void 0:k.result)||k;E!=null&&E.success&&(E!=null&&E.ideExtensions)&&U(E.ideExtensions)}catch{}})()},[K,n,d]);const ie=m=>K?Ue(m.type):t==="cli"?m.cliName:m.acpName,Ce=K?s.detectedIdes||[]:[],xe=()=>{K?x(S,z?{workspace:z}:void 0):u(S,z,J||void 0,h&&M||void 0)},Ee=m=>{K?b(m):f(m.type,m.workspace,m.id)},v=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:ee,onChange:m=>{y(m.target.value),m.target.value!=="__custom__"&&D("")},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(m=>e.jsxs("option",{value:m.id,children:[m.id===s.defaultWorkspaceId?"⭐ ":"",m.label||m.path.split("/").filter(Boolean).pop()||m.path," — ",m.path]},m.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…"})]})}),ee==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:W,onChange:m=>D(m.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 ${L.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",L.label]}),v,K?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[Ce.map(m=>{const k=m.running||i.some(E=>(E.type||"").toLowerCase()===(m.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>x(m.type||m.id||"",z?{workspace:z}:void 0),disabled:!!j,className:`machine-btn-primary flex items-center gap-1.5 ${k?"!border-green-500/30":""}`,style:{opacity:j&&j!==m.type?.4:1},children:[e.jsx("span",{children:o(m.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)]"}),j===m.type?"⏳ Launching...":`▶ ${m.name||Ue(m.type)}`,k&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},m.type)}),Ce.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:g,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(En,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:S,onChange:m=>R(m.target.value),className:"machine-input",children:T.length>0?T.map(m=>e.jsxs("option",{value:m.type,children:[m.icon," ",m.displayName]},m.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),h&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:M,onChange:m=>oe(m.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:J,onChange:m=>P(m.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:xe,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 ",L.plural," running"]}):e.jsx("div",{className:"flex flex-col gap-2.5 mb-5",children:i.map(m=>{const k=K?m:null,E=h?m:null,ue=Ke(m.status);return e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:o(m.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ie(m),(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:m.workspace||"—"}),(E==null?void 0:E.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",E.currentModel]}),(E==null?void 0:E.currentPlan)&&e.jsxs("span",{className:"text-amber-500",children:["📋 ",E.currentPlan]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${ue==="stopped"?"bg-red-500/[0.08] text-red-500":ue==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:ue}),K&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>l(`/ide/${m.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(nt,{size:13})," Control"]}),e.jsx("button",{onClick:()=>p(m),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),h&&e.jsx("button",{onClick:()=>l(`/ide/${m.id}`),className:"machine-btn",title:"View chat",children:e.jsx(dt,{size:14})}),ue==="stopped"?e.jsx("button",{onClick:()=>K?x(m.type,m.workspace?{workspace:m.workspace}:void 0):u(m.type,m.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>Ee(m),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(le=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${Hs(le.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[le.name," · ",Ke(le.status)]},le.id))}),k&&(V[k.type]||[]).length>0&&d&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(V[k.type]||[]).map(le=>e.jsxs("button",{disabled:re===`${k.type}.${le.type}`,onClick:async()=>{const ve=`${k.type}.${le.type}`;Y(ve);try{await d(n,"set_ide_extension",{ideType:k.type,extensionType:le.type,enabled:!le.enabled}),U(me=>({...me,[k.type]:(me[k.type]||[]).map(de=>de.type===le.type?{...de,enabled:!de.enabled}:de)}))}catch(me){console.error("Extension toggle failed:",me)}finally{Y(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 ${le.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 ${le.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),le.name,e.jsx("span",{className:"text-[9px] font-normal",children:le.enabled?"ON":"OFF"})]},le.type))})]})]},m.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:N,disabled:B,className:"machine-btn",children:B?"⏳":"↻ Load"})]}),(()=>{const m=new Set(T.map(E=>E.type)),k=I.filter(E=>(E.category||"cli")!==t?!1:t==="ide"?!0:m.has(E.cliType));return k.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:k.map((E,ue)=>{var le,ve;return e.jsxs("div",{onClick:()=>{R(E.cliType),(E.workspace||E.dir)&&(y("__custom__"),D(E.workspace||E.dir)),P((E.cliArgs||[]).join(" ")),oe(E.model||""),K&&x(E.cliType,E.workspace?{workspace:E.workspace}:void 0)},className:"flex justify-between items-center px-2.5 py-1.5 rounded-md cursor-pointer bg-bg-glass border border-border-subtle text-xs transition-colors duration-150 hover:bg-bg-glass-hover",children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-text-secondary",children:[e.jsx("span",{children:o(E.cliType)}),e.jsx("span",{children:((le=E.workspace||E.dir)==null?void 0:le.split("/").filter(Boolean).pop())||E.cliType||"root"}),E.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",E.model]}),E.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((ve=E.cliArgs)==null?void 0:ve.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:E.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:E.timestamp?new Date(E.timestamp).toLocaleDateString():""})]},ue)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",L.label," launch history yet."]})})()]})]})}const ys=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],ca=[{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 la({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[i,o]=a.useState("config"),[c,d]=a.useState("codex-cli"),[l,x]=a.useState([]),[u,f]=a.useState(""),[p,b]=a.useState([]),[g,I]=a.useState(""),B=a.useRef(null),N=a.useRef(null),j=R=>{x(J=>J.includes(R)?J.filter(P=>P!==R):[...J,R])},L=()=>x([...ys]),K=()=>x([]);a.useEffect(()=>{var R;(R=B.current)==null||R.scrollIntoView({behavior:"smooth"})},[p]),a.useEffect(()=>()=>{N.current&&clearInterval(N.current)},[]);const h=a.useCallback(()=>{N.current&&clearInterval(N.current),N.current=setInterval(async()=>{try{const R=await n(t,"provider_auto_fix_status",{providerType:s.type});(R==null?void 0:R.running)===!1&&i==="running"&&(o("done"),b(J=>[...J,`
|
|
70
|
-
✅ Auto-fix completed!`]),N.current&&clearInterval(N.current))}catch{}},3e3)},[t,s.type,n,i]),T=async()=>{if(l.length!==0){o("running"),b(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,u?`💬 Comment: ${u}`:"",""]),I("");try{const R=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...u?{comment:u}:{}});R!=null&&R.success&&(R!=null&&R.started||R!=null&&R.running)?(b(J=>[...J,"✅ Agent started. Monitoring progress..."]),h()):(o("error"),I((R==null?void 0:R.error)||"Failed to start auto-fix"))}catch(R){o("error"),I((R==null?void 0:R.message)||"Connection failed")}}},S=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),b(R=>[...R,`
|
|
71
|
-
⚠️ Auto-fix cancelled.`]),o("done"),N.current&&clearInterval(N.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:R=>R.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:ca.map(R=>e.jsxs("button",{onClick:()=>d(R.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===R.value?R.color+"66":"var(--border-subtle)",background:c===R.value?R.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===R.value?R.color:"var(--text-primary)"},children:R.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:R.desc})]},R.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:L,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:K,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:ys.map(R=>e.jsxs("button",{onClick:()=>j(R),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(R)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:l.includes(R)?"rgba(139,92,246,0.08)":"transparent",color:l.includes(R)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(R)?"☑ ":"☐ ",R]},R))})]}),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:u,onChange:R=>f(R.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:[p.map((R,J)=>e.jsx("div",{className:R.startsWith("✅")?"text-green-400":R.startsWith("❌")||R.startsWith("⚠")?"text-amber-400":"",children:R},J)),i==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:B})]}),g&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:g})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[i==="config"&&l.length>0&&`${l.length} script(s) selected`,i==="running"&&"Agent is generating...",i==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[i==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:T,disabled:l.length===0,className:"machine-btn",style:{background:l.length>0?"rgba(139,92,246,0.15)":void 0,borderColor:l.length>0?"rgba(139,92,246,0.4)":void 0,color:l.length>0?"#a78bfa":void 0,opacity:l.length===0?.4:1},children:"🚀 Start Fix"})]}),i==="running"&&e.jsx("button",{onClick:S,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(i==="done"||i==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{o("config"),b([]),I("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function da({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:i}){var h;const o=s.filter(T=>T.category==="ide"),[c,d]=a.useState(((h=o[0])==null?void 0:h.type)||""),[l,x]=a.useState(""),[u,f]=a.useState(""),[p,b]=a.useState(!1),[g,I]=a.useState(""),[B,N]=a.useState(!1),j=T=>{const S=T.toLowerCase().replace(/[^a-z0-9-]/g,"");x(S),(!u||u===L(l))&&f(L(S))},L=T=>T.split("-").map(S=>S.charAt(0).toUpperCase()+S.slice(1)).join(" "),K=async()=>{if(!(!l||!u||!c)){b(!0),I("");try{const T=await n(t,"provider_clone",{type:l,name:u,category:"ide",location:"user",cloneFrom:c});T!=null&&T.success||T!=null&&T.created?(N(!0),i==null||i(l)):I((T==null?void 0:T.error)||"Failed to create provider")}catch(T){I((T==null?void 0:T.message)||"Connection failed")}b(!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:T=>T.stopPropagation(),children:[e.jsxs("div",{className:"px-5 py-4 border-b border-border-subtle",children:[e.jsx("h2",{className:"text-[15px] font-semibold text-text-primary",children:"✨ Create User Provider"}),e.jsx("p",{className:"text-[11px] text-text-muted mt-0.5",children:"Clone an upstream IDE provider to customize"})]}),e.jsx("div",{className:"px-5 py-4 flex flex-col gap-4",children:B?e.jsxs("div",{className:"text-center py-6",children:[e.jsx("div",{className:"text-3xl mb-2",children:"🎉"}),e.jsx("h3",{className:"text-[14px] font-semibold text-text-primary",children:"Provider Created!"}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-1",children:[e.jsx("code",{className:"text-violet-400",children:l})," has been created at ",e.jsxs("code",{className:"text-green-400",children:["~/.adhdev/providers/",l,"/"]})]}),e.jsxs("p",{className:"text-[11px] text-text-muted mt-2",children:["Run ",e.jsxs("code",{className:"text-violet-400",children:["adhdev provider fix ",l]})," or use Auto-Fix to implement scripts."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Base Provider"}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:o.map(T=>e.jsxs("button",{onClick:()=>d(T.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===T.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:c===T.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:T.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:c===T.type?"#a78bfa":"var(--text-secondary)"},children:T.displayName})]},T.type))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Provider Type (ID)"}),e.jsx("input",{value:l,onChange:T=>j(T.target.value),placeholder:"my-cursor, custom-windsurf...",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"}),e.jsxs("p",{className:"text-[10px] text-text-muted mt-1",children:["Lowercase, alphanumeric + hyphens only. Will be created at ",e.jsxs("code",{className:"text-violet-400",children:["~/.adhdev/providers/",l||"...","/"]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Display Name"}),e.jsx("input",{value:u,onChange:T=>f(T.target.value),placeholder:"My Custom IDE",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]}),g&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:g})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:B?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:K,disabled:!l||!u||p,className:"machine-btn",style:{background:l&&u?"rgba(34,197,94,0.12)":void 0,borderColor:l&&u?"rgba(34,197,94,0.3)":void 0,color:l&&u?"#86efac":void 0,opacity:!l||!u||p?.4:1},children:p?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function ua({machineId:t,providers:s,sendDaemonCommand:n}){const[r,i]=a.useState([]),[o,c]=a.useState(!1),[d,l]=a.useState(null),[x,u]=a.useState("all"),[f,p]=a.useState(null),[b,g]=a.useState(!1),I=a.useCallback(async()=>{var N;if(t){c(!0);try{const j=await n(t,"get_provider_settings",{}),L=(j==null?void 0:j.result)||j;if(j!=null&&j.success&&(L!=null&&L.settings)){const K=[];for(const[h,T]of Object.entries(L.settings)){const S=s.find(R=>R.type===h);K.push({type:h,displayName:(S==null?void 0:S.displayName)||h,icon:(S==null?void 0:S.icon)||"",category:(S==null?void 0:S.category)||"unknown",schema:T,values:((N=L.values)==null?void 0:N[h])||{}})}K.sort((h,T)=>h.category.localeCompare(T.category)||h.displayName.localeCompare(T.displayName)),i(K)}}catch{}c(!1)}},[t,s,n]);a.useEffect(()=>{r.length===0&&I()},[]);const B=async(N,j,L)=>{l(`${N}.${j}`),i(K=>K.map(h=>h.type===N?{...h,values:{...h.values,[j]:L}}:h));try{const K=await n(t,"set_provider_setting",{providerType:N,key:j,value:L});K!=null&&K.success||I()}catch{I()}l(null)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Filter"}),["all","acp","cli","ide","extension"].map(N=>e.jsx("button",{onClick:()=>u(N),className:`machine-btn text-[10px] px-2 py-0.5 ${x===N?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:N.toUpperCase()},N))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>g(!0),className:"machine-btn text-[10px] bg-green-500/[0.06] border-green-500/20 text-green-400 hover:bg-green-500/[0.12]",children:"✨ Create Provider"}),e.jsx("button",{onClick:I,disabled:o,className:"machine-btn",children:o?"⏳ Loading...":"↻ Refresh"})]})]}),x!=="all"&&r.filter(N=>N.category===x).length>1&&(()=>{const N=r.filter(h=>h.category===x),j=new Map;for(const h of N)for(const T of h.schema){if(T.type!=="boolean")continue;const S=j.get(T.key),R=!!(h.values[T.key]??T.default);S?(S.onCount+=R?1:0,S.total+=1):j.set(T.key,{label:T.label||T.key,onCount:R?1:0,total:1})}const L=[...j.entries()].filter(([,h])=>h.total===N.length);if(L.length===0)return null;const K=async(h,T)=>{for(const S of N)await B(S.type,h,T)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",x.toUpperCase()," providers (",N.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:L.map(([h,T])=>{const S=T.onCount===T.total,R=T.onCount===0;return e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[e.jsx("span",{className:"text-text-secondary font-medium",children:T.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",T.onCount,"/",T.total,")"]}),e.jsx("button",{onClick:()=>void K(h,!0),disabled:S,className:`machine-btn text-[9px] px-1.5 py-px ${S?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void K(h,!1),disabled:R,className:`machine-btn text-[9px] px-1.5 py-px ${R?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},h)})})]})})(),o&&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(N=>x==="all"||N.category===x).map(N=>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:N.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:N.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:N.category==="acp"?"rgba(139,92,246,0.08)":N.category==="cli"?"rgba(59,130,246,0.08)":N.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:N.category==="acp"?"#a78bfa":N.category==="cli"?"#60a5fa":N.category==="ide"?"#86efac":"#fbbf24"},children:N.category}),N.category==="ide"&&e.jsx("button",{onClick:()=>p(s.find(j=>j.type===N.type)||{type:N.type,displayName:N.displayName,icon:N.icon,category:N.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:N.schema.map(j=>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:[j.label||j.key,d===`${N.type}.${j.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),j.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:j.description})]}),e.jsx("div",{className:"shrink-0",children:j.type==="boolean"?e.jsx("button",{onClick:()=>B(N.type,j.key,!(N.values[j.key]??j.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:N.values[j.key]??j.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:N.values[j.key]??j.default?21:3}})}):j.type==="number"?e.jsx("input",{type:"number",value:N.values[j.key]??j.default??0,min:j.min,max:j.max,onChange:L=>{const K=parseInt(L.target.value)||0;j.min!==void 0&&K<j.min||j.max!==void 0&&K>j.max||B(N.type,j.key,K)},className:"machine-input w-20 text-center text-[11px]"}):j.type==="select"&&j.options?e.jsx("select",{value:N.values[j.key]??j.default??"",onChange:L=>B(N.type,j.key,L.target.value),className:"machine-input text-[11px]",children:j.options.map(L=>e.jsx("option",{value:L,children:L},L))}):e.jsx("input",{type:"text",value:N.values[j.key]??j.default??"",onBlur:L=>B(N.type,j.key,L.target.value),className:"machine-input w-[120px] text-[11px]"})})]},j.key))})]},N.type))}),f&&e.jsx(la,{machineId:t,provider:f,sendDaemonCommand:n,onClose:()=>p(null)}),b&&e.jsx(da,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>g(!1),onCreated:()=>{g(!1),I()}})]})}function pa({machineId:t,sendDaemonCommand:s}){const[n,r]=a.useState([]),[i,o]=a.useState(0),[c,d]=a.useState(!0),[l,x]=a.useState("debug"),u=a.useRef(null),f=a.useRef(!1);return a.useEffect(()=>{if(!t||!c)return;const p=async()=>{try{const g=await s(t,"get_logs",{count:200,minLevel:l,since:i}),I=(g==null?void 0:g.result)||g;if(g!=null&&g.success&&Array.isArray(I==null?void 0:I.logs)&&I.logs.length>0){r(N=>[...N,...I.logs.map(L=>({timestamp:L.ts,level:L.level,message:`[${L.category}] ${L.message}`}))].slice(-300));const B=Math.max(...I.logs.map(N=>N.ts));o(B)}}catch{}};p();const b=setInterval(p,3e3);return()=>clearInterval(b)},[t,c,i,l,s]),a.useEffect(()=>{if(c&&n.length>0){const p=f.current?"smooth":"instant";setTimeout(()=>{var b;(b=u.current)==null||b.scrollIntoView({behavior:p}),f.current=!0},50)}},[n.length,c]),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Level"}),["debug","info","warn","error"].map(p=>e.jsx("button",{onClick:()=>{x(p),r([]),o(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===p?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:p.toUpperCase()},p))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[n.length," entries"]}),e.jsx("button",{onClick:()=>d(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),o(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[n.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),n.map((p,b)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:p.level==="error"?"#ef4444":p.level==="warn"?"#f59e0b":p.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(p.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:p.level==="error"?"#ef4444":p.level==="warn"?"#f59e0b":p.level==="debug"?"#475569":"#8b5cf6"},children:p.level==="error"?"ERR":p.level==="warn"?"WRN":p.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:p.message})]},b)),e.jsx("div",{ref:u})]})]})}function xa({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:i}=n;return e.jsx("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/55 backdrop-blur-[2px]",role:"dialog","aria-modal":"true","aria-labelledby":"launch-pick-title",children:e.jsxs("div",{className:"w-full max-w-md rounded-xl border border-border-subtle bg-bg-secondary shadow-xl p-5",children:[e.jsx("h2",{id:"launch-pick-title",className:"text-sm font-semibold text-text-primary m-0 mb-1",children:"Where should this run?"}),e.jsx("p",{className:"text-[11px] text-text-muted m-0 mb-4",children:"Nothing is assumed. Pick a saved workspace, your default workspace, or home — or cancel and type a path."}),e.jsx("div",{className:"flex flex-col gap-2 mb-4 max-h-48 overflow-y-auto",children:(t.workspaces||[]).length===0?e.jsx("span",{className:"text-[11px] text-text-muted",children:"No saved workspaces yet. Add one in Overview or type a path above."}):(t.workspaces||[]).map(o=>e.jsxs("button",{type:"button",className:"text-left text-xs px-3 py-2 rounded-lg border border-border-subtle bg-bg-primary hover:bg-violet-500/10 transition-colors",onClick:()=>{i(null),r({cliType:s.cliType,workspaceId:o.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:o.label||o.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:o.path})]},o.id))}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",className:"machine-btn text-[11px] flex-1 min-w-[120px]",disabled:!t.defaultWorkspacePath,onClick:()=>{i(null),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 ma({onNicknameSynced:t}={}){var h,T,S,R,J,P,M,oe,ee;const{id:s}=ks(),n=jt(),{sendCommand:r}=st(),i=$t(),o=i.ides||[],c=i.initialLoaded??!0,d=o.find(y=>y.id===s&&y.daemonMode),[l,x]=a.useState("overview"),u=a.useRef(null),f=aa({machineId:s,registeredMachineId:(d==null?void 0:d.machineId)||null,sendDaemonCommand:r,onNicknameSynced:t,logsEndRef:u});a.useEffect(()=>et.onToast(W=>{i.setToasts(z=>{if(z.some(re=>re.message===W.message&&W.timestamp-re.timestamp<3e3))return z;const U={id:W.id,message:W.message,type:W.type,timestamp:W.timestamp,targetKey:W.targetKey,actions:W.actions};return[...z.slice(-4),U]});const D=W.duration||5e3;setTimeout(()=>i.setToasts(z=>z.filter(V=>V.id!==W.id)),D)}),[i]);const p=((d==null?void 0:d.availableProviders)||[]).map(y=>({type:y.type,displayName:y.displayName,icon:y.icon,category:y.category})),b={};for(const y of p)b[y.type]=y.icon;const g=y=>b[y]||"",I=d?{id:d.id,hostname:Us(d,{fallbackId:d.id}),platform:((h=d.machine)==null?void 0:h.platform)||"unknown",arch:((T=d.machine)==null?void 0:T.arch)||"",cpus:((S=d.machine)==null?void 0:S.cpus)||0,totalMem:((R=d.machine)==null?void 0:R.totalMem)||0,freeMem:((J=d.machine)==null?void 0:J.freeMem)||0,availableMem:(P=d.machine)==null?void 0:P.availableMem,loadavg:((M=d.machine)==null?void 0:M.loadavg)||[],uptime:((oe=d.machine)==null?void 0:oe.uptime)||0,release:((ee=d.machine)==null?void 0:ee.release)||"",cdpConnected:!!d.cdpConnected,machineNickname:d.machineNickname||null,p2p:d.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:d.detectedIdes||[],workspaces:d.workspaces||[],defaultWorkspaceId:d.defaultWorkspaceId??d.activeWorkspaceId??null,defaultWorkspacePath:d.defaultWorkspacePath??d.activeWorkspacePath??null,workspaceActivity:d.workspaceActivity||[]}:null,B=o.filter(y=>y.daemonId===s&&!y.daemonMode).filter(y=>!is(y)&&!cs(y)).map(y=>({id:y.id,type:y.type,version:y.version||"",instanceId:y.instanceId||"",status:y.status,workspace:y.workspace||null,terminals:y.terminals||0,aiAgents:sr(y.aiAgents||y.agents||[]),activeChat:y.activeChat||null,chats:y.chats||[],agentStreams:y.agentStreams||[],cdpConnected:y.cdpConnected||!1,daemonId:s})),N=o.filter(y=>y.daemonId===s&&is(y)).map(y=>({id:y.id,type:y.type,cliName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,daemonId:s})),j=o.filter(y=>y.daemonId===s&&cs(y)).map(y=>({id:y.id,type:y.type,acpName:y.cliName||y.type,status:y.status,workspace:y.workspace||"",activeChat:y.activeChat||null,currentModel:y.currentModel,currentPlan:y.currentPlan,daemonId:s}));if(!I)return c?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:()=>n("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const L=pt(d,{fallbackId:I.id}),K=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(An,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(nt,{size:14})," IDEs"]}),count:B.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ut,{size:14})," CLIs"]}),count:N.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ds,{size:14})," ACP Agents"]}),count:j.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Gt,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Tn,{size:14})," Logs"]})}];return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsxs("div",{className:"dashboard-header !flex-col !items-stretch",children:[e.jsx("div",{className:"flex items-center justify-between w-full",children:e.jsxs("div",{className:"flex items-center gap-2 md:gap-3.5 w-full min-w-0",children:[e.jsx("button",{onClick:()=>n("/machines"),className:"machine-btn-back flex shrink-0",children:"←"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[f.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:f.nicknameInput,onChange:y=>f.setNicknameInput(y.target.value),onKeyDown:y=>{y.key==="Enter"&&f.handleSaveNickname(),y.key==="Escape"&&f.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:f.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>f.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{f.setEditingNickname(!0),f.setNicknameInput(I.machineNickname||"")},title:"Click to set nickname",children:L}),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:[I.platform," · ",I.arch," · ",I.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 r(s,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",d.serverVersion]}),I.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:I.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:I.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",I.p2p.state==="connected"?`● ${I.p2p.peers}`:"○"]}),I.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 ●"}),I.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",I.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:K.map(y=>e.jsxs("button",{onClick:()=>x(y.id),className:`machine-tab shrink-0${l===y.id?" active":""}`,children:[y.label,y.count!==void 0&&e.jsx("span",{className:"tab-count",children:y.count})]},y.id))})]}),e.jsxs("div",{className:"page-content",children:[l==="overview"&&e.jsx(oa,{machine:I,ideSessions:B,cliSessions:N,acpSessions:j,actions:f}),l==="ides"&&e.jsx(zt,{category:"ide",machine:I,machineId:s,providers:p,managedEntries:B,getIcon:g,actions:f,sendDaemonCommand:r}),l==="clis"&&e.jsx(zt,{category:"cli",machine:I,machineId:s,providers:p,managedEntries:N,getIcon:g,actions:f}),l==="acps"&&e.jsx(zt,{category:"acp",machine:I,machineId:s,providers:p,managedEntries:j,getIcon:g,actions:f}),l==="providers"&&e.jsx(ua,{machineId:s,providers:p,sendDaemonCommand:r}),l==="logs"&&e.jsx(pa,{machineId:s,sendDaemonCommand:r})]}),f.launchPick&&I&&e.jsx(xa,{machine:I,launchPick:f.launchPick,actions:f}),e.jsx(Ys,{toasts:i.toasts||[],onDismiss:y=>i.setToasts(W=>W.filter(D=>D.id!==y)),onClickToast:y=>{y.targetKey}}),e.jsx("style",{children:`
|
|
72
|
-
@keyframes toast-in {
|
|
73
|
-
from { opacity: 0; transform: translateX(40px); }
|
|
74
|
-
to { opacity: 1; transform: translateX(0); }
|
|
75
|
-
}
|
|
76
|
-
`})]})}function ha(){const[t,s]=a.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=a.useState(!0);a.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const d=[],l=[],x=[],u=[];Object.values(c.providers||{}).forEach(p=>{const b={name:p.name||"Unknown",status:p.status||"Stable",details:p.details||"Community Provider"};p.category==="ide"?d.push(b):p.category==="cli"?l.push(b):p.category==="extension"?x.push(b):p.category==="acp"&&u.push(b)});const f=(p,b)=>{const g={Stable:1,Beta:2,WIP:3},I=g[p.status]||99,B=g[b.status]||99;return I!==B?I-B:p.name.localeCompare(b.name)};s({ide:d.sort(f),cli:l.sort(f),ext:x.sort(f),acp:u.sort(f)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const i=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(As,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):c==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Jt,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Beta"})]}):e.jsxs("div",{className:"flex items-center gap-1.5 text-text-muted",children:[e.jsx(Ps,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),o=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((d,l)=>e.jsxs("tr",{className:"hover:bg-bg-subtle/50 transition-colors",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-text-main",children:d.name}),e.jsx("td",{className:"py-3 px-4",children:i(d.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:d.details})]},l))})]})});return n?e.jsx(At,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Et,{}),widthClassName:"max-w-5xl",children:e.jsx(Qt,{icon:e.jsx("div",{className:"w-8 h-8 border-4 border-accent border-t-transparent rounded-full animate-spin mx-auto"}),title:"Loading provider registry",description:"Fetching the latest support matrix from the shared provider registry."})}):e.jsxs(At,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(Et,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(De,{title:"Registry overview",description:"Support status is loaded from the shared provider registry used across OSS and cloud surfaces.",children:e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"IDEs"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ide.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"CLI"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.cli.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"Extensions"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.ext.length})]}),e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wider text-text-muted mb-1",children:"ACP"}),e.jsx("div",{className:"text-2xl font-semibold text-text-primary",children:t.acp.length})]})]})}),e.jsx(De,{title:"IDE support",icon:e.jsx(nt,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:o(t.ide)}),e.jsx(De,{title:"Standalone CLI agents",icon:e.jsx(Zt,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:o(t.cli)}),e.jsx(De,{title:"AI extensions",icon:e.jsx(ut,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:o(t.ext)}),e.jsx(De,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(ut,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:o(t.acp)})]})}class fa{constructor(){Re(this,"adapters",new Map);Re(this,"states",new Map);Re(this,"ptyCallbacks",new Set);Re(this,"screenshotCallbacks",new Map);Re(this,"statusCallbacks",new Set)}resolveDaemonId(s){if(this.adapters.has(s))return s;if(s.startsWith("standalone")){for(const n of this.adapters.keys())if(n.startsWith("standalone"))return n}return null}register(s,n){this.adapters.set(s,n),this.states.set(s,n.connectionState)}unregister(s){this.adapters.delete(s),this.states.delete(s)}setState(s,n){this.states.set(s,n)}retryConnection(s){}get(s){const n=this.resolveDaemonId(s);return n?this.adapters.get(n):void 0}getState(s){const n=this.resolveDaemonId(s);return n&&this.states.get(n)||"disconnected"}sendData(s,n){return!1}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,i){return!1}async requestChatHistory(s,n,r,i,o){return{messages:[],hasMore:!1}}onScreenshot(s,n){return this.screenshotCallbacks.set(s,n),()=>{this.screenshotCallbacks.delete(s)}}emitScreenshot(s,n){this.screenshotCallbacks.forEach(r=>r(s,n))}onStatus(s){return this.statusCallbacks.add(s),()=>{this.statusCallbacks.delete(s)}}emitStatus(s,n){this.statusCallbacks.forEach(r=>r(s,n))}onPtyOutput(s){return this.ptyCallbacks.add(s),()=>{this.ptyCallbacks.delete(s)}}emitPtyOutput(s,n){this.ptyCallbacks.forEach(r=>r(s,n))}}const Je=new fa;function ga(){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 vs=ga(),js=3e3,ba=3e4;let Ze=null,ya=0;const _t=new Map;let at=null,bt=null;function va(t,s={}){const n=t.split(":");return n.length>=3&&(n[1]==="ide"||n[1]==="cli"||n[1]==="acp")?{daemonId:n[0],payload:{...s,targetSessionId:s.targetSessionId||n.slice(2).join(":")}}:{daemonId:t,payload:s}}async function Tt(t,s,n){const r=va(t,n||{}),i=Ze;if(i&&i.readyState===WebSocket.OPEN){const c=`req_${++ya}_${Date.now()}`;return new Promise((d,l)=>{const x=setTimeout(()=>{_t.delete(c),l(new Error(`WS command timeout: ${s}`))},3e4);_t.set(c,{resolve:u=>{clearTimeout(x),d(u)},reject:u=>{clearTimeout(x),l(u)}}),i.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:r.payload}}))})}const o=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:r.payload})});if(!o.ok)throw new Error(`HTTP ${o.status}`);return o.json()}class ja{constructor(s){Re(this,"daemonId");Re(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ze==null?void 0:Ze.readyState)===WebSocket.OPEN}get connectionState(){return(Ze==null?void 0:Ze.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return Tt(this.daemonId,s,n)}async sendInput(s,n){return Tt(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,at&&(clearInterval(at),at=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await Tt(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const i=await fetch(`data:image/jpeg;base64,${r.base64}`).then(o=>o.blob());Je.emitScreenshot(this.daemonId,i)}}catch{}};n(),at=setInterval(n,2e3)}stopScreenshots(s){at&&(clearInterval(at),at=null)}}let tt=null;function wa(t){return(!tt||tt.daemonId!==t)&&(tt=new ja(t)),tt}function Na({children:t}){const s=a.useRef(ns()),n=ns();s.current=n;const{setUserName:r}=yt(),i=a.useRef(r);i.current=r;const[,o]=a.useState("disconnected"),c=a.useCallback((f,p)=>{o(f),bt==null||bt(f,p)},[]),d=a.useRef(null),l=a.useRef(),x=a.useRef(js),u=a.useRef(!0);return a.useEffect(()=>{u.current=!0;function f(){var g,I;if(!u.current||((g=d.current)==null?void 0:g.readyState)===WebSocket.OPEN||((I=d.current)==null?void 0:I.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${vs}...`);let b;try{b=new WebSocket(vs)}catch(B){console.error("[Standalone WS] Failed to create WebSocket:",B),p();return}d.current=b,b.onopen=()=>{if(!u.current){b.close();return}c("connected"),x.current=js,console.log("[Standalone WS] Connected")},Ze=b,b.onmessage=B=>{var N;try{const j=JSON.parse(B.data);if((j.type==="command_result"||j.type==="error")&&j.requestId){const L=_t.get(j.requestId);L&&(_t.delete(j.requestId),j.type==="error"?L.reject(new Error(((N=j.data)==null?void 0:N.message)||"Command failed")):L.resolve(j.data));return}if(j.type==="pty_output"){Je.emitPtyOutput(j.cliId,j.data);return}if(j.type==="status"||j.type==="initial_state"){const L=j.data;if(!L)return;const{injectEntries:K,markLoaded:h}=s.current,T=L.id||"standalone",S=wa(T);Je.register(T,S),Je.setState(T,"connected"),c("connected",T),Je.emitStatus(T,L);const R=ir(L,{daemonId:T});R.length>0&&K(R),h(),L.userName&&i.current&&i.current(L.userName)}}catch(j){console.error("[Standalone WS] Parse error:",j)}},b.onclose=()=>{u.current&&(tt&&Je.setState(tt.daemonId,"disconnected"),c("disconnected"),d.current=null,p())},b.onerror=B=>{console.warn("[Standalone WS] Error, will reconnect:",B)}}function p(){if(!u.current)return;clearTimeout(l.current);const b=x.current;console.log(`[Standalone WS] Reconnecting in ${b}ms...`),l.current=setTimeout(()=>{x.current=Math.min(x.current*1.5,ba),f()},b)}return f(),()=>{u.current=!1,clearTimeout(l.current),d.current&&(d.current.onclose=null,d.current.close(),d.current=null,Ze=null),tt&&Je.unregister(tt.daemonId)}},[]),e.jsx(e.Fragment,{children:t})}function ka({children:t}){const[s,n]=a.useState("disconnected"),[r,i]=a.useState(null);a.useEffect(()=>(bt=(c,d)=>{n(c),d&&i(d)},()=>{bt=null}),[]);const o=a.useMemo(()=>{const c=s==="connected",d={};return r&&(d[r]=c?"connected":"connecting"),d.standalone=c?"connected":"connecting",{wsStatus:s,isConnected:c,connectionStates:d}},[s,r]);return e.jsx(jn,{connectionOverrides:o,children:e.jsx(Na,{children:t})})}const Sa=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Ms,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(Ts,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Gt,{}),label:"Settings"}];function Ca({children:t}){const s=jt(),n=xn(),[r,i]=a.useState(!1),[o,c]=a.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),d=u=>{s(u),i(!1)},l=()=>{c(u=>{const f=!u;try{localStorage.setItem("sidebar-collapsed",f?"1":"0")}catch{}return f})},x=u=>`nav-item${n.pathname.startsWith(u)?" active":""} cursor-pointer ${o?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${o?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>i(!0),children:[e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"}),e.jsx("span",{className:"mobile-menu-icon"})]}),r&&e.jsx("div",{className:"sidebar-overlay",role:"button",tabIndex:0,"aria-label":"Close menu",onClick:()=>i(!1),onKeyDown:u=>u.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 ${o?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!o&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>i(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:Sa.map(u=>e.jsxs("div",{className:x(u.path),id:`nav-${u.id}`,onClick:()=>d(u.path),title:o?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!o&&u.label]},u.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:o?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Et,{})}),!o&&e.jsxs(e.Fragment,{children:["Docs",e.jsx("span",{className:"ml-auto text-[9px] text-text-muted",children:"↗"})]})]}),e.jsxs("div",{className:`nav-item cursor-pointer${n.pathname==="/about"?" active":""} ${o?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:o?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Es,{})}),!o&&"About"]}),!o&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.1"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${o?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:o?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:o?"›":"‹"}),!o&&e.jsx("span",{className:"text-xs",children:"Collapse"})]})]})]}),e.jsx("main",{className:"main-content relative",children:e.jsx("div",{className:"main-content-inner",children:t})})]})}const Ia=[{icon:e.jsx(Ts,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(dt,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Rs,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(nt,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(ut,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(Et,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Ma=[{icon:e.jsx(Ls,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Ms,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Bs,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Mn,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Cn,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(As,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Ta=[{feature:"Agent chat relay",selfhost:!0,cloud:!0},{feature:"Live IDE screenshots",selfhost:!0,cloud:!0},{feature:"Remote IDE control",selfhost:!0,cloud:!0},{feature:"Multi-IDE monitoring",selfhost:!0,cloud:!0},{feature:"Extension and CLI agents",selfhost:!0,cloud:!0},{feature:"Access from any network",selfhost:!1,cloud:!0},{feature:"WebRTC P2P streaming",selfhost:!1,cloud:!0},{feature:"Mobile push notifications",selfhost:!1,cloud:!0},{feature:"REST API and webhooks",selfhost:!1,cloud:!0},{feature:"Team collaboration",selfhost:!1,cloud:!0},{feature:"Multi-machine burrows",selfhost:!1,cloud:!0},{feature:"SSO, RBAC, audit logs",selfhost:!1,cloud:!0}];function Ea(){return e.jsxs(At,{icon:e.jsx(Es,{className:"text-text-primary"}),title:"About",subtitle:"Self-hosted ADHDev overview, supported surfaces, and what changes in Cloud",widthClassName:"max-w-5xl",actions:e.jsxs("div",{className:"px-3 py-1 text-[11px] font-semibold tracking-wide rounded-full bg-emerald-500/10 text-emerald-500 border border-emerald-500/20",children:["SELFHOST v","0.7.1"]}),children:[e.jsx(De,{children:e.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("div",{className:"text-[11px] font-semibold tracking-[0.18em] uppercase text-emerald-400 mb-2",children:"Self-hosted edition"}),e.jsx("h2",{className:"text-2xl font-semibold tracking-tight text-text-primary mb-2",children:"Keep the same dashboard experience, with the runtime fully on-device."}),e.jsx("p",{className:"text-sm text-text-muted leading-relaxed",children:"Standalone keeps the browser, daemon, screenshots, and control path on your own machine. It is the same core product shape as cloud, just without the remote networking and team layers."})]}),e.jsxs("div",{className:"grid gap-2 min-w-[220px]",children:[e.jsx("a",{href:"https://docs.adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"Docs ↗"}),e.jsx("a",{href:"https://github.com/vilmire/adhdev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm inline-flex justify-center no-underline",children:"GitHub ↗"}),e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm inline-flex justify-center no-underline",children:"Try Cloud ↗"})]})]})}),e.jsx(De,{title:"Included in standalone",description:"The local-first feature set available without the cloud control plane.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Ia.map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4 transition-colors hover:border-border-default",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-accent/10 text-accent-light",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(De,{title:"Compatible with",description:"Supported editors and agent surfaces exposed in the standalone dashboard.",children:e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{label:"IDEs",items:Xs.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Gs.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:qs.map(t=>`${t.icon} ${t.name}`)}].map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4",children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-3 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1.5",children:t.items.map(s=>e.jsx("div",{className:"rounded-md border border-border-subtle bg-bg-card px-2.5 py-1.5 text-[12px] text-text-secondary",children:s},s))})]},t.label))})}),e.jsx(De,{title:"Cloud-only extras",description:"Capabilities that need the hosted control plane or team infrastructure.",children:e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:Ma.map(t=>e.jsxs("div",{className:"rounded-xl border border-violet-500/20 bg-violet-500/[0.04] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-text-primary mb-2",children:[e.jsx("span",{className:"flex h-8 w-8 items-center justify-center rounded-lg bg-violet-500/10 text-violet-400",children:t.icon}),t.title]}),e.jsx("p",{className:"text-[13px] leading-relaxed text-text-muted",children:t.desc})]},t.title))})}),e.jsx(De,{title:"Self-hosted vs Cloud",description:"The product split at a glance.",children:e.jsx("div",{className:"overflow-x-auto rounded-xl border border-border-subtle",children:e.jsxs("table",{className:"w-full text-[13px]",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary",children:[e.jsx("th",{className:"text-left px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider",children:"Feature"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-text-muted text-[11px] uppercase tracking-wider w-[110px]",children:"Selfhost"}),e.jsx("th",{className:"text-center px-4 py-3 font-semibold text-violet-400 text-[11px] uppercase tracking-wider w-[110px]",children:"Cloud"})]})}),e.jsx("tbody",{children:Ta.map((t,s)=>e.jsxs("tr",{className:s%2===0?"bg-bg-glass":"bg-transparent",children:[e.jsx("td",{className:"px-4 py-2.5 text-text-secondary",children:t.feature}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:t.selfhost?e.jsx("span",{className:"text-emerald-500",children:"✓"}):e.jsx("span",{className:"text-text-muted opacity-40",children:"—"})}),e.jsx("td",{className:"px-4 py-2.5 text-center",children:e.jsx("span",{className:"text-emerald-500",children:"✓"})})]},t.feature))})]})})}),e.jsx(Qt,{icon:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"mx-auto h-12 w-12 opacity-80"}),title:"Cloud is optional, not required",description:"You can stay fully local in standalone, and move to cloud later without changing how you use the dashboard.",action:e.jsxs("div",{className:"flex flex-wrap justify-center gap-3",children:[e.jsx("a",{href:"https://adhf.dev",target:"_blank",rel:"noopener noreferrer",className:"btn btn-primary btn-sm no-underline",children:"Compare Cloud ↗"}),e.jsxs("a",{href:"https://discord.gg/WJD3tCfBzk",target:"_blank",rel:"noopener noreferrer",className:"btn btn-secondary btn-sm no-underline",children:[e.jsx(Dn,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Aa(){const{ides:t}=yt(),s=t.find(f=>f.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=st(),{userName:i}=yt(),[o,c]=a.useState(i||"");a.useEffect(()=>{i!==void 0&&c(i)},[i]);const d=f=>{const p=f.target.value.trim();s!=null&&s.id&&p!==i&&r(s.id,"set_user_name",{userName:p}).catch(console.error)},[l,x]=a.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=f=>{x(f);try{localStorage.setItem("adhdev_sound",f?"1":"0")}catch{}};return e.jsxs(At,{icon:e.jsx(Gt,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(wr,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(De,{title:"Daemon",description:"Connection health and local endpoints for the self-hosted runtime.",children:e.jsxs("div",{className:"grid grid-cols-[100px_1fr] gap-x-4 gap-y-2.5 text-sm",children:[e.jsx("span",{className:"text-text-muted",children:"Version"}),e.jsxs("span",{className:"font-mono text-xs",children:["v","0.7.1"]}),e.jsx("span",{className:"text-text-muted",children:"Status"}),e.jsx("span",{className:s?"text-green-400":"text-yellow-400",children:s?"● Running":"○ Not connected"}),e.jsx("span",{className:"text-text-muted",children:"WebSocket"}),e.jsx("span",{className:"font-mono text-xs",children:"ws://localhost:19222"}),e.jsx("span",{className:"text-text-muted",children:"HTTP"}),e.jsx("span",{className:"font-mono text-xs",children:"http://localhost:19280"})]})}),e.jsx(De,{title:"Detected IDEs",description:"Editors discovered by the local daemon on this machine.",children:n.length===0?e.jsx("p",{className:"text-sm text-text-muted",children:"No IDEs detected. Start an IDE to see it here."}):e.jsx("div",{className:"flex flex-col gap-1.5",children:n.map(f=>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 ${f.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:f.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:f.type})]},f.type))})}),e.jsx(De,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Tr,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(De,{title:"Appearance",description:"Match the rest of the dashboard with a single place for mode, theme, and accent.",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-text-muted mb-2 font-medium",children:"Mode"}),e.jsx($r,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Theme"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Choose a preset or create a custom surface and chat palette for the standalone UI."}),e.jsx(Wr,{})]}),e.jsxs("div",{className:"border-t border-border-subtle pt-4",children:[e.jsx("div",{className:"text-xs text-text-muted mb-1 font-medium",children:"Accent color override"}),e.jsx("p",{className:"text-[11px] text-text-muted mb-3",children:"Override preset accents without changing your full theme definition."}),e.jsx(Ur,{})]})]})}),e.jsx(De,{title:"Notifications",description:"Browser prompts and local sound cues for agent activity.",children:e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Mr,{}),e.jsx(ot,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ln,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:u})]})}),e.jsx(De,{title:"Profile",description:"How your name appears in local chat threads and dashboard views.",children:e.jsx("div",{className:"flex flex-col gap-3",children:e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-4 bg-bg-glass rounded-xl border border-border-subtle hover:border-border-default transition-colors",children:[e.jsxs("div",{className:"flex flex-col gap-1 pr-4 max-w-[500px]",children:[e.jsxs("span",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(In,{size:16,className:"text-text-secondary"})," Display Name"]}),e.jsx("span",{className:"text-[12px] text-text-muted leading-relaxed",children:"Your name shown in chat threads and on the team dashboard."})]}),e.jsx("input",{type:"text",className:"bg-bg-primary border border-border-strong rounded-lg px-3 py-1.5 text-sm w-48 text-right focus:border-accent focus:outline-none transition-colors",placeholder:"Anonymous",value:o,onChange:f=>c(f.target.value),onBlur:d,onKeyDown:f=>{f.key==="Enter"&&f.currentTarget.blur()}})]})})})]})}Dr();function ws(){const{ides:t}=yt(),s=t.find(n=>{var r;return n.daemonMode||((r=n.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(St,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(St,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(St,{to:"/dashboard",replace:!0})}function _a(){return e.jsx(mn,{children:e.jsx(ka,{children:e.jsx(Sn,{value:{sendCommand:Tt,sendData:()=>!1},children:e.jsx(Ca,{children:e.jsxs(hn,{children:[e.jsx(qe,{path:"/dashboard",element:e.jsx(sa,{})}),e.jsx(qe,{path:"/ide/:id",element:e.jsx(ra,{})}),e.jsx(qe,{path:"/machine",element:e.jsx(ws,{})}),e.jsx(qe,{path:"/machines/:id",element:e.jsx(ma,{})}),e.jsx(qe,{path:"/machines",element:e.jsx(ws,{})}),e.jsx(qe,{path:"/capabilities",element:e.jsx(ha,{})}),e.jsx(qe,{path:"/about",element:e.jsx(Ea,{})}),e.jsx(qe,{path:"/settings",element:e.jsx(Aa,{})}),e.jsx(qe,{path:"*",element:e.jsx(St,{to:"/dashboard",replace:!0})})]})})})})})}Xn({connectionManager:Je,p2pManager:Je});fn(document.getElementById("root")).render(e.jsx(a.StrictMode,{children:e.jsx(_a,{})}));
|