@adhdev/daemon-standalone 0.7.4 → 0.7.6

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,65 +0,0 @@
1
- var sn=Object.defineProperty;var nn=(t,s,n)=>s in t?sn(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var ce=(t,s,n)=>nn(t,typeof s!="symbol"?s+"":s,n);import{r as c,j as e,M as Ht,a as zt,b as rn,c as an,u as nt,t as on,d as cn,e as ln,R as dn,f as ms,g as fs,h as un,B as xn,i as pn,k as ke,N as ut,l as hn}from"./vendor-tc3018Wt.js";import{D as mn,o as fn,L as gn}from"./terminal-Dm9LBRva.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const a of o)if(a.type==="childList")for(const i of a.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(o){const a={};return o.integrity&&(a.integrity=o.integrity),o.referrerPolicy&&(a.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?a.credentials="include":o.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function r(o){if(o.ep)return;o.ep=!0;const a=n(o);fetch(o.href,a)}})();const gs=c.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}),bs=c.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function Ft(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 kt(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},o=s.version??n.version??t.version,a=s.serverVersion??t.serverVersion??n.serverVersion,i=s.versionMismatch===!0||t.versionMismatch===!0;return o&&(r.version=o),a&&(r.serverVersion=a),o&&a&&o===a?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||i&&o&&a&&o!==a)&&(r.versionMismatch=!0),r)}function bn(t,s){var i,u,l,h,d,x,p;const n=Date.now();if(s.length===0)return t.map(g=>({...g,_lastUpdate:n}));const r=new Map;for(const g of s)r.set(g.id,g);for(const g of t){const m=r.get(g.id);if(!m){r.set(g.id,{...g,_lastUpdate:n});continue}const y=Ft(g),I=Ft(m);if(y>I){const w=(i=g.chats)!=null&&i.length?g.chats:m.chats,v=kt(m,g,{...m,...g,chats:w,_lastUpdate:n});r.set(g.id,v)}else if(y<I){const w={};if(g.status&&g.status!==m.status&&(w.status=g.status),g.cdpConnected!==void 0&&(w.cdpConnected=g.cdpConnected),(u=g.chats)!=null&&u.length&&!((l=m.chats)!=null&&l.length)&&(w.chats=g.chats),g.machineNickname!==void 0&&g.machineNickname!==m.machineNickname&&(w.machineNickname=g.machineNickname),g.version!==void 0&&(w.version=g.version),g.serverVersion!==void 0&&(w.serverVersion=g.serverVersion),g.versionMismatch===!0&&(w.versionMismatch=!0),Object.keys(w).length>0){const v=kt(m,g,{...m,...w,_lastUpdate:m._lastUpdate});r.set(g.id,v)}}else{const w=g.timestamp||n,v=m._lastUpdate||m.timestamp||0;if(w>=v){const N=(h=g.chats)!=null&&h.length?g.chats:m.chats,L=kt(m,g,{...m,...g,chats:N,_lastUpdate:n});r.set(g.id,L)}else(d=g.chats)!=null&&d.length&&!((x=m.chats)!=null&&x.length)&&r.set(g.id,{...m,chats:g.chats})}}const o=new Set(t.map(g=>g.id)),a=new Set;for(const g of t){const m=g.daemonId||((p=g.id)==null?void 0:p.split(":")[0]);m&&a.add(m)}for(const[g,m]of r){const y=m.daemonId||g.split(":")[0];if(!a.has(y))continue;const I=n-(m._lastUpdate||m.timestamp||0);(m.transport==="pty"&&!o.has(g)&&I>1e4||m.transport==="acp"&&!o.has(g)&&I>1e4||m.transport==="cdp-page"&&!o.has(g)&&I>3e4)&&r.delete(g)}for(const[g,m]of r)n-(m._lastUpdate||m.timestamp||0)>3e5&&m.status!=="online"&&r.delete(g);return Array.from(r.values())}function yn({children:t,connectionOverrides:s}){const[n,r]=c.useState([]),[o,a]=c.useState({}),[i,u]=c.useState(!1),[l,h]=c.useState([]),[d,x]=c.useState(void 0),p=c.useCallback((y,I)=>{r(w=>w.map(v=>v.id===y?{...v,chats:I}:v))},[]),g={injectEntries:y=>{r(I=>I.length===0?y:bn(y,I))},markLoaded:()=>u(!0),getIdes:()=>n},m=s;return e.jsx(bs.Provider,{value:g,children:e.jsx(gs.Provider,{value:{ides:n,updateIdeChats:p,screenshotMap:o,setScreenshotMap:a,initialLoaded:i,toasts:l,setToasts:h,wsStatus:(m==null?void 0:m.wsStatus)??"connected",isConnected:(m==null?void 0:m.isConnected)??!0,connectionStates:(m==null?void 0:m.connectionStates)??{},connectionTransports:(m==null?void 0:m.connectionTransports)??{},showReconnected:(m==null?void 0:m.showReconnected)??!1,retryConnection:m==null?void 0:m.retryConnection,isP2PActive:(m==null?void 0:m.isP2PActive)??!1,p2pStates:(m==null?void 0:m.p2pStates)??{},userRole:m==null?void 0:m.userRole,userName:d,setUserName:x},children:t})})}function tt(){return c.useContext(gs)}function Ut(){return c.useContext(bs)}function jn(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;async function o(a,i={}){const u={"Content-Type":"application/json",...i.headers||{}},l=n==null?void 0:n();l&&(u.Authorization=`Bearer ${l}`);const h=a.startsWith("http")?a:`${s}${a.startsWith("/")?"":"/"}${a}`,d=await fetch(h,{...i,headers:u});if(d.status===401)throw r==null||r(),new Error("Unauthorized");if(!d.ok){const x=await d.json().catch(()=>({error:d.statusText}));throw new Error(x.error||`API Error: ${d.status}`)}return d.json()}return{getDaemons:()=>o("/api/v1/daemons"),getDaemonStatus:a=>o(`/api/v1/daemons/${a}/status`),sendCommand:(a,i,u={})=>o(`/api/v1/daemons/${a}/command`,{method:"POST",body:JSON.stringify({type:i,payload:u})}),execTerminal:(a,i,u)=>o(`/api/v1/daemons/${a}/terminal`,{method:"POST",body:JSON.stringify({command:i,name:u})}),sendAgentMessage:(a,i,u)=>o(`/api/v1/shortcuts/${a}/chat`,{method:"POST",body:JSON.stringify({agentType:i,message:u})}),getAgentStatus:a=>o(`/api/v1/shortcuts/${a}/status`),approveAgent:(a,i,u)=>o(`/api/v1/shortcuts/${a}/approve`,{method:"POST",body:JSON.stringify({agentType:i,action:u?"approve":"reject"})}),request:o}}const vn=jn({baseUrl:"http://localhost:3847"});c.createContext(vn);const wn={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},ys=c.createContext(wn);function Nn({value:t,children:s}){return e.jsx(ys.Provider,{value:t,children:s})}function $e(){return c.useContext(ys)}const re={size:18};function js({size:t=re.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7",rx:"1"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7",rx:"1"})]})}function vs({size:t=re.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 kn({size:t=re.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 Sn({size:t=re.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 Cn({size:t=re.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 ft({size:t=re.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 In({size:t=re.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 Dt({size:t=re.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 ws({size:t=re.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 Ns({size:t=re.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 He({size:t=re.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 _e({size:t=re.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 ks({size:t=re.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 Mn({size:t=re.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 $t({size:t=re.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 Ss({size:t=re.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 Bt({size:t=re.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 ze({size:t=re.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 Cs({size:t=re.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 Is({size:t=re.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 Tn({size:t=re.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 Wt({size:t=re.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 Ms({size:t=re.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 Ts({size:t=re.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 En({size:t=re.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})})}function An({size:t=re.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 Es({size:t=re.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 $n({size:t=re.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M22 11.08V12a10 10 0 1 1-5.93-9.14"}),e.jsx("polyline",{points:"22 4 12 14.01 9 11.01"})]})}function _n({size:t=re.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=re.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 Pn({size:t=re.size,className:s}){return e.jsxs("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:[e.jsx("path",{d:"M14.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M9.5 10c-.83 0-1.5-.89-1.5-2s.67-2 1.5-2 1.5.89 1.5 2-.67 2-1.5 2z"}),e.jsx("path",{d:"M19.35 6.07A16.03 16.03 0 0 0 15 4a.84.84 0 0 0-.46.33 11 11 0 0 0-.74 1.5 15.68 15.68 0 0 0-3.6 0 11.23 11.23 0 0 0-.74-1.5A.84.84 0 0 0 9 4a16.03 16.03 0 0 0-4.35 2.07A16.8 16.8 0 0 0 2 15a16.22 16.22 0 0 0 4 3c.12.08.27.06.37-.04a11.14 11.14 0 0 0 1.2-1.92.35.35 0 0 0-.18-.46 10.4 10.4 0 0 1-1.63-.78.36.36 0 0 1 .03-.6 6.8 6.8 0 0 0 .32-.24.36.36 0 0 1 .37-.04c2.2.98 4.6.98 6.8 0a.36.36 0 0 1 .37.04c.1.08.21.16.32.24a.36.36 0 0 1 .03.6 10.4 10.4 0 0 1-1.63.78.35.35 0 0 0-.18.46c.39.67.8 1.3 1.2 1.92a.37.37 0 0 0 .37.04 16.22 16.22 0 0 0 4-3 16.8 16.8 0 0 0-2.65-8.93z"})]})}function Rn(t){const n=t.split(`
2
- `).map(u=>{if(!u.includes("\r"))return u;const l=u.split("\r").map(x=>x.trim()).filter(Boolean);if(l.length===0)return"";const h=l.filter(x=>x.startsWith("⏺"));if(h.length>0)return h[h.length-1];const d=l.filter(x=>!(/^[❯›>]\s*$/.test(x)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(x)&&x.length<40||/^[╭╰│├╮╯─═]+$/.test(x)));return d.length>0?d[d.length-1]:l[l.length-1]}).join(`
3
- `).split(`
4
- `),r={},o=[];let a=!1;for(const u of n){const l=u.trim();if(l===""){a=!1,o.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(u)){const d=u.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(d)r[d[1]]=(r[d[1]]||0)+1;else{const x=u.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);x&&(r[x]=(r[x]||0)+1)}a=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(u)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(u)||a&&/^\s{2,}/.test(u))continue;a=!1;const h=u.replace(/^❯\s+/,"");o.push(h)}const i=o.join(`
5
- `).replace(/\n{3,}/g,`
6
-
7
- `).trim();return{toolCounts:r,textContent:i,hasTools:Object.keys(r).length>0}}function St(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}const Dn=c.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:o,isCliMode:a=!1,isWorking:i=!1,contextKey:u="",receivedAtMap:l={},emptyState:h,onLoadMore:d,isLoadingMore:x,hasMoreHistory:p,loadError:g},m){var _;const y=c.useRef(null),I=c.useRef(null),w=c.useRef(0),v=c.useRef(""),N=c.useRef(!1),[L,f]=c.useState(new Set),[k,S]=c.useState(new Set),j=c.useRef(!1),P=()=>{const R=y.current;return R?R.scrollHeight-R.scrollTop-R.clientHeight<200:!0},W=s.length>0?`${s.length}:${(((_=s[s.length-1])==null?void 0:_.content)||"").length}`:"0:0";c.useEffect(()=>{var Y,F;const R=!N.current,O=v.current!==u;if(v.current=u,R||O){N.current=!0,j.current=!1;const J=()=>{var ae;(ae=I.current)==null||ae.scrollIntoView({behavior:"instant"})};requestAnimationFrame(()=>requestAnimationFrame(J)),setTimeout(J,100),setTimeout(J,300),w.current=s.length;return}s.length>w.current?j.current||(Y=I.current)==null||Y.scrollIntoView({behavior:"instant"}):P()&&!j.current&&((F=I.current)==null||F.scrollIntoView({behavior:"instant"})),w.current=s.length},[W,u,i]),c.useImperativeHandle(m,()=>({scrollToBottom:(R="smooth")=>{var O;(O=I.current)==null||O.scrollIntoView({behavior:R})}})),c.useEffect(()=>{const R=y.current;if(!R)return;let O;const K=()=>{clearTimeout(O),O=setTimeout(()=>{j.current=!P()},50)};return R.addEventListener("scroll",K,{passive:!0}),()=>{R.removeEventListener("scroll",K),clearTimeout(O)}},[]);const C=c.useRef(0),V=c.useRef(!1);c.useEffect(()=>{const R=y.current;if(!R||!V.current||C.current===0)return;const O=R.scrollHeight-C.current;O>0&&(R.scrollTop=O),C.current=0,V.current=!1},[s.length]);const A=()=>{const R=y.current;R&&(C.current=R.scrollHeight),V.current=!0,d==null||d()},M=(()=>{const R=s.map((F,J)=>({type:"message",data:F,index:J,ts:F.receivedAt||l[F.id??`i-${J}`]||0}));if(!n||n.length===0)return R;const O=[...n].sort((F,J)=>F.timestamp-J.timestamp).map((F,J)=>({type:"action",data:F,index:J,ts:F.timestamp})),K=[];let Y=0;for(const F of R){for(;Y<O.length&&F.ts>0&&O[Y].ts<F.ts;)K.push(O[Y++]);K.push(F)}for(;Y<O.length;)K.push(O[Y++]);return K})(),D=700;return e.jsxs("div",{ref:y,"data-chat-scroll":!0,className:"chat-container",children:[x&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),p&&!x&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:A,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${g?"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:g?`↻ ${g}`:"↑ Load older messages"})}),M.length===0&&!p&&(h||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),M.map(R=>{var ee;if(R.type==="action"){const X=R.data;return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(Ht,{remarkPlugins:[zt],children:X.text}),e.jsx("span",{className:"action-time",children:St(X.timestamp)})]},`action-${R.index}`)}const O=R.data,K=R.index,Y=(O.role||"").toLowerCase(),F=Y==="user"||Y==="human",J=O.kind||(Y==="tool"?"tool":"standard"),ae=O.receivedAt||l[O.id??`i-${K}`],Q=`${u}-${K}`,oe=L.has(Q),T=k.has(Q),b=typeof O.content=="string"?O.content:(O.content||[]).map(X=>X.text||"").join(`
8
- `);if(J==="thought"){const X=((ee=O.meta)==null?void 0:ee.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(En,{size:13}),e.jsx("span",{children:X})]}),e.jsx("div",{className:"chat-msg-body",children:b})]},`msg-${K}`)}if(J==="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:b.split(`
9
- `)[0].slice(0,80)})]},`msg-${K}`);if(J==="terminal"){const X=O.meta||{},Z=X.isRunning?"⏳":"✅",ne=X.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:Z}),e.jsx("span",{children:ne})]}),e.jsx("pre",{className:"chat-msg-body",children:b})]},`msg-${K}`)}if(J==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:b.slice(0,100)},`msg-${K}`);const $=!F&&a?Rn(b):null,E=$?$.textContent:b,z=$?Object.entries($.toolCounts):[],G=a&&!F&&!oe&&E.length>D,U=oe?b:G&&!T?E.slice(0,D):E;return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${F?"self-end":"self-start"}`,children:[z.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[z.map(([X,Z])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",X,Z>1?` ×${Z}`:""]},X)),($==null?void 0:$.hasTools)&&e.jsx("button",{onClick:()=>f(X=>{const Z=new Set(X);return oe?Z.delete(Q):Z.add(Q),Z}),className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:oe?"Collapse":"Original"}),!E&&ae!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:St(ae)})]}),(E||F)&&e.jsxs("div",{className:`chat-bubble ${F?"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:F?o||"You":r}),ae!=null&&e.jsx("span",{className:"chat-time",children:St(ae)})]}),E&&e.jsx("div",{className:"chat-markdown",children:e.jsx(Ht,{remarkPlugins:[zt,rn,an],children:U})}),G&&e.jsx("button",{onClick:()=>S(X=>{const Z=new Set(X);return T?Z.delete(Q):Z.add(Q),Z}),className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:T?"Collapse ↑":`Show more (${Math.round(E.length/100)*100} chars) ↓`})]})]},`msg-${K}`)}),i&&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:I})]})}),Bn=c.memo(Dn,(t,s)=>t.messages===s.messages&&t.actionLogs===s.actionLogs&&t.agentName===s.agentName&&t.userName===s.userName&&t.isCliMode===s.isCliMode&&t.isWorking===s.isWorking&&t.contextKey===s.contextKey&&t.receivedAtMap===s.receivedAtMap&&t.emptyState===s.emptyState&&t.onLoadMore===s.onLoadMore&&t.isLoadingMore===s.isLoadingMore&&t.hasMoreHistory===s.hasMoreHistory&&t.loadError===s.loadError),Vt={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"},As=c.forwardRef(({onInput:t,onResize:s,fontSize:n=13},r)=>{const o=c.useRef(null),a=c.useRef(null),i=c.useRef(null),[u,l]=c.useState(!1);return c.useImperativeHandle(r,()=>({write:h=>{var d;(d=a.current)==null||d.write(h)},clear:()=>{var h;(h=a.current)==null||h.clear()},fit:()=>{var h;try{(h=i.current)==null||h.fit(),a.current&&(s==null||s(a.current.cols,a.current.rows))}catch{}},bumpResize:()=>{var h;try{(h=i.current)==null||h.fit();const d=a.current;if(!d)return;const x=d.cols,p=d.rows;s==null||s(x+5,p),setTimeout(()=>{s==null||s(x,p)},100)}catch{}}})),c.useEffect(()=>{if(!o.current)return;const h=new mn({cursorBlink:!0,cursorStyle:"bar",fontSize:n,fontFamily:"'JetBrains Mono', 'Fira Code', 'SF Mono', 'Menlo', monospace",fontWeight:"400",letterSpacing:0,lineHeight:1.2,theme:Vt,allowTransparency:!0,scrollback:5e3,convertEol:!1}),d=new fn,x=new gn;h.loadAddon(d),h.loadAddon(x),h.open(o.current),requestAnimationFrame(()=>{d.fit(),s==null||s(h.cols,h.rows),l(!0)});const p=h.onData(m=>{t(m)}),g=new ResizeObserver(()=>{requestAnimationFrame(()=>{try{d.fit(),s==null||s(h.cols,h.rows)}catch{}})});return g.observe(o.current),a.current=h,i.current=d,()=>{p.dispose(),g.disconnect(),h.dispose(),a.current=null,i.current=null}},[n]),e.jsx("div",{ref:o,className:"w-full h-full rounded-lg overflow-hidden transition-opacity duration-200",style:{background:Vt.background,opacity:u?1:0}})});As.displayName="CliTerminal";function ot({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 Yt({value:t,max:s,label:n,color:r="#8b5cf6",detail:o,compact:a=!1}){const i=s>0?Math.min(Math.round(t/s*100),100):0,u=i>85?"#ef4444":i>60?"#f59e0b":r;return a?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:[i,"%"]})]}),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:`${i}%`,background:u}})})]}):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:[i,"%"]})]}),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:`${i}%`,background:`linear-gradient(90deg, ${u}, ${u}cc)`}})}),o&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:o})]})}function Wn({cursorPos:t,viewportRef:s,imgRef:n}){var v;if(!t||!n.current)return null;const r=n.current,o=r.getBoundingClientRect(),a=(v=s.current)==null?void 0:v.getBoundingClientRect();if(!a)return null;const i=r.naturalWidth||o.width,u=r.naturalHeight||o.height,l=i/u,h=o.width/o.height;let d,x,p,g;l>h?(d=o.width,x=o.width/l,p=0,g=(o.height-x)/2):(x=o.height,d=o.height*l,p=(o.width-d)/2,g=0);const m=o.left-a.left+p+d*t.nx,y=o.top-a.top+g+x*t.ny,I=Math.max(8,Math.min(a.width-8,m)),w=Math.max(8,Math.min(a.height-8,y));return e.jsxs("div",{style:{position:"absolute",left:I-8,top:w-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)"}})]})}function On({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:o,setIsMenuOpen:a,imeText:i,setImeText:u,handleImeSubmit:l,isConnActive:h,zoom:d,isMobile:x,mobileFillZoom:p,onZoomOut:g,onZoomReset:m,onZoomIn:y,transportType:I,screenshotUsage:w,lastActionStatus:v}){return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onTouchStart:N=>N.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,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:()=>{r(N=>!N),a(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${n?"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:"⌨️"})}),n&&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:i,autoFocus:!0,onTouchStart:N=>N.stopPropagation(),onChange:N=>u(N.target.value),onKeyDown:N=>{l(N)},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:()=>{a(N=>!N),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${o?"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:h?"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:h?"#22c55e":"#eab308",boxShadow:h?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:h?"#22c55e":"#eab308"},children:h?"Connected":"WS"})]}),d>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(d*100),"%"]}),I==="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"}),I==="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"}),w&&w.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:w.budgetExhausted?"#ef4444":"#c4b5fd",background:w.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:w.budgetExhausted?"TURN blocked":`TURN ${w.dailyUsedMinutes}/${w.dailyBudgetMinutes}m`}),v&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:v})]})]}),o&&e.jsxs("div",{onTouchStart:N=>N.stopPropagation(),style:{position:"absolute",bottom:56,left:"50%",transform:"translateX(-50%)",width:220,background:"rgba(23, 23, 23, 0.95)",backdropFilter:"blur(25px)",borderRadius:14,border:"1px solid rgba(255,255,255,0.1)",padding:14,boxShadow:"0 12px 40px rgba(0,0,0,0.6)",display:"flex",flexDirection:"column",gap:12,zIndex:20,touchAction:"none",animation:"slideUpSidebar 0.15s ease-out"},children:[e.jsx("div",{style:{fontSize:9,fontWeight:900,color:"#3b82f6",letterSpacing:1.5},children:"SETTINGS"}),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[e.jsxs("div",{style:{fontSize:10,color:"#888",fontWeight:700},children:["ZOOM: ",d<=(x?p:1)+.01?x?"FILL":"FIT":`${Math.round(d*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:N=>{N.stopPropagation(),g()},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:N=>{N.stopPropagation(),m()},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:x?"FILL":"FIT"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),y()},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:"+"})]})]})]})]})}function Kn({waitingLabel:t,waitingHint:s,transportType:n}){return 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:t}),e.jsx("div",{className:"text-[11px] text-white/40",children:s}),n==="relay"&&e.jsx("div",{className:"text-[10px] text-amber-300/80",children:"TURN relay active"})]})}function Hn(){if(typeof window>"u")return!1;try{return window.__ADHDEV_DEBUG_RENDERS__===!0||window.localStorage.getItem("adhdev_debug_renders")==="1"}catch{return window.__ADHDEV_DEBUG_RENDERS__===!0}}function qt(t){return t==null||typeof t=="number"||typeof t=="boolean"?t:typeof t=="string"?t.length>64?`${t.slice(0,61)}...`:t:Array.isArray(t)?`Array(${t.length})`:typeof t=="object"?"Object":typeof t}function rt(t,s){const n=c.useRef(null),r=c.useRef(0);c.useEffect(()=>{if(!Hn())return;r.current+=1;const o=n.current;if(!o){console.debug(`[render-trace] ${t}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([i,u])=>[i,qt(u)]))}),n.current=s;return}const a=Object.keys({...o,...s}).filter(i=>!Object.is(o[i],s[i]));a.length>0&&console.debug(`[render-trace] ${t}#${r.current}`,{changed:a,snapshot:Object.fromEntries(a.map(i=>[i,qt(s[i])]))}),n.current=s})}function zn({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:o,minZoom:a,zoomRef:i,panXRef:u,panYRef:l,setPanX:h,setPanY:d,setZoom:x,lastWheelTimeRef:p,onAction:g,setLastActionStatus:m,spawnRippleFromNormalized:y,clampPan:I,isMobile:w,mobileFillZoom:v}){const[N,L]=c.useState(null),f=c.useRef(null),k=c.useRef(null),S=c.useRef(null),j=c.useRef(!1),P=c.useRef(null),W=c.useRef(0),C=c.useRef(null),V=c.useRef(1),A=c.useRef({x:0,y:0}),M=c.useRef(!1),D=c.useRef(r),_=c.useRef(g),R=()=>{if(f.current)return;const Y={nx:.5,ny:.5};f.current=Y,L(Y)};return c.useEffect(()=>{D.current=r,r==="mouse"&&R()},[r]),c.useEffect(()=>{_.current=g},[g]),c.useEffect(()=>{const Y=t.current;if(!Y)return;const F=b=>{if(!n.current)return null;const $=n.current.getBoundingClientRect();return!$.width||!$.height?null:{nx:Math.max(0,Math.min(1,(b.clientX-$.left)/$.width)),ny:Math.max(0,Math.min(1,(b.clientY-$.top)/$.height))}},J=(b,$)=>{if(!n.current)return{dnx:0,dny:0};const E=n.current,z=E.getBoundingClientRect(),G=E.naturalWidth||z.width,U=E.naturalHeight||z.height,ee=G/U,X=z.width/z.height;let Z,ne;return ee>X?(Z=z.width,ne=z.width/ee):(ne=z.height,Z=z.height*ee),{dnx:b/Z,dny:$/ne}},ae=(b,$,E)=>{if(E<=1.05)return;const z=-(b-.5)*100,G=-($-.5)*100,U=I(z,G,E);(Math.abs(U.x-u.current)>.1||Math.abs(U.y-l.current)>.1)&&(h(U.x),d(U.y),u.current=U.x,l.current=U.y)},Q=b=>{const $=s.current;if($&&b.target instanceof Node&&$.contains(b.target))b.preventDefault();else return;if(b.touches.length===1){const E=b.touches[0];k.current={x:E.clientX,y:E.clientY,time:Date.now()},S.current={x:E.clientX,y:E.clientY},M.current||(j.current=!1),P.current=setTimeout(()=>{if(!j.current&&!M.current)if(j.current=!0,D.current==="mouse"){const z=f.current||{nx:.5,ny:.5};m("Right Click"),y(z.nx,z.ny,"right"),_.current("input_click",{...z,button:"right"}).catch(()=>{})}else{const z=F(E);z&&(m("Right Click"),y(z.nx,z.ny,"right"),_.current("input_click",{...z,button:"right"}).catch(()=>{}))}},500);return}if(b.touches.length===2){P.current&&clearTimeout(P.current),j.current=!0,M.current=!0;const E=b.touches[1].clientX-b.touches[0].clientX,z=b.touches[1].clientY-b.touches[0].clientY;C.current=Math.sqrt(E*E+z*z),V.current=i.current,A.current={x:(b.touches[0].clientX+b.touches[1].clientX)/2,y:(b.touches[0].clientY+b.touches[1].clientY)/2}}},oe=b=>{const $=s.current;if($&&b.target instanceof Node&&$.contains(b.target)&&b.preventDefault(),b.touches.length===1&&S.current){const E=b.touches[0],z=E.clientX-S.current.x,G=E.clientY-S.current.y;if(!j.current&&k.current){const U=E.clientX-k.current.x,ee=E.clientY-k.current.y;Math.sqrt(U*U+ee*ee)>8&&(j.current=!0,P.current&&clearTimeout(P.current))}if(j.current)if(D.current==="mouse"){const U=J(z,G),ee=f.current||{nx:.5,ny:.5},X=Math.max(0,Math.min(1,ee.nx+U.dnx)),Z=Math.max(0,Math.min(1,ee.ny+U.dny));f.current={nx:X,ny:Z},L({nx:X,ny:Z}),m(`Cursor: ${Math.round(X*100)}%, ${Math.round(Z*100)}%`),ae(X,Z,i.current);const ne=Date.now();ne-p.current>=30&&(p.current=ne,_.current("input_mouseMoved",{nx:X,ny:Z}).catch(()=>{}))}else if(i.current>1){const U=s.current;if(U){const ee=U.clientWidth,X=U.clientHeight,Z=u.current+z/ee*100,ne=l.current+G/X*100,B=I(Z,ne,i.current);h(B.x),d(B.y),u.current=B.x,l.current=B.y}}else{const U=F(E);if(U){const ee=Date.now();ee-p.current>=40&&(p.current=ee,m("Scroll"),_.current("input_wheel",{nx:U.nx,ny:U.ny,deltaX:Math.round(-z*2.5),deltaY:Math.round(-G*2.5)}).catch(()=>{}))}}S.current={x:E.clientX,y:E.clientY};return}if(b.touches.length===2&&C.current!==null){const E=b.touches[1].clientX-b.touches[0].clientX,z=b.touches[1].clientY-b.touches[0].clientY,U=Math.sqrt(E*E+z*z)/C.current,ee=(b.touches[0].clientX+b.touches[1].clientX)/2,X=(b.touches[0].clientY+b.touches[1].clientY)/2,Z=ee-A.current.x,ne=X-A.current.y,B=Math.abs(U-1)>.03;if(D.current==="mouse"){if(B){const q=Math.max(a,Math.min(5,V.current*U));x(q),i.current=q}else if(Math.abs(Z)>2||Math.abs(ne)>2){const q=f.current||{nx:.5,ny:.5},H=Date.now();H-p.current>=30&&(p.current=H,m("Scroll"),_.current("input_wheel",{nx:q.nx,ny:q.ny,deltaX:Math.round(-Z*3),deltaY:Math.round(-ne*3)}).catch(()=>{}))}}else{const q=Math.max(a,Math.min(5,V.current*U));x(q),i.current=q;const H=s.current;if(H&&q>1){const te=H.clientWidth,ie=H.clientHeight,se=u.current+Z/te*100,xe=l.current+ne/ie*100,me=I(se,xe,q);h(me.x),d(me.y),u.current=me.x,l.current=me.y}}A.current={x:ee,y:X}}},T=b=>{var $;if(P.current&&clearTimeout(P.current),C.current=null,b.touches.length===1&&M.current){const E=b.touches[0];k.current={x:E.clientX,y:E.clientY,time:Date.now()},S.current={x:E.clientX,y:E.clientY},j.current=!0;return}if(b.touches.length===0){if(M.current){M.current=!1,j.current=!1;return}if(b.changedTouches.length===1&&!j.current){const E=b.changedTouches[0],z=Date.now(),G=z-((($=k.current)==null?void 0:$.time)||0);if(G<60||G>400){j.current=!1;return}if(k.current){const U=E.clientX-k.current.x,ee=E.clientY-k.current.y;if(Math.sqrt(U*U+ee*ee)>12){j.current=!1;return}}if(D.current==="mouse"){const U=f.current||F(E);U&&(m(`Click: ${Math.round(U.nx*100)}%, ${Math.round(U.ny*100)}%`),y(U.nx,U.ny,"left"),_.current("input_click",{...U}).catch(()=>{}))}else{const U=F(E);if(!U)return;z-W.current<300?(m("Double tap"),y(U.nx,U.ny,"double"),_.current("input_click",{...U,clickCount:2}).catch(()=>{}),W.current=0):(m(`Tap: ${Math.round(U.nx*100)}%, ${Math.round(U.ny*100)}%`),y(U.nx,U.ny,"left"),_.current("input_click",{...U}).catch(()=>{}),W.current=z)}}j.current=!1}};return Y.addEventListener("touchstart",Q,{passive:!1}),Y.addEventListener("touchmove",oe,{passive:!1}),Y.addEventListener("touchend",T,{passive:!1}),()=>{Y.removeEventListener("touchstart",Q),Y.removeEventListener("touchmove",oe),Y.removeEventListener("touchend",T),P.current&&clearTimeout(P.current)}},[t,s,n,a,i,u,l,h,d,x,p,m,y,I]),{cursorPos:N,cursorPosRef:f,handleToggleInputMode:()=>{o(Y=>{const F=Y==="touch"?"mouse":"touch";return F==="mouse"&&R(),F})},handleZoomReset:()=>{const Y=w?v:1;x(Y),i.current=Y,h(0),d(0),u.current=0,l.current=0}}}function Fn({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:o,transportType:a}){const i=c.useRef(null),u=c.useRef(null),l=c.useRef(null),[h,d]=c.useState(null),[x,p]=c.useState(""),[,g]=c.useState(!1),[m,y]=c.useState([]),I=c.useRef(0),[w,v]=c.useState(!1),[N,L]=c.useState(!1),f=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[k,S]=c.useState(f?"mouse":"touch"),[j,P]=c.useState(1),W=c.useRef(!1),[C,V]=c.useState(1),[A,M]=c.useState(0),[D,_]=c.useState(0);rt("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:k,zoom:C,panX:A,panY:D,isMenuOpen:w,isImeOpen:N});const R=c.useRef(0),O=c.useRef(C),K=c.useRef(A),Y=c.useRef(D);c.useEffect(()=>{O.current=C},[C]),c.useEffect(()=>{K.current=A},[A]),c.useEffect(()=>{Y.current=D},[D]),c.useEffect(()=>{var B;(B=i.current)==null||B.focus()},[]);const F=n==="connected",J=r,ae=F?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",Q=F?"The remote stream is warming up":"Waiting for the remote stream to catch up";c.useEffect(()=>{if(!f||W.current||!J)return;const B=l.current,q=u.current;if(!B||!q)return;const H=()=>{const te=q.clientWidth,ie=q.clientHeight,se=B.naturalWidth,xe=B.naturalHeight;if(!se||!xe||!te||!ie)return;const me=Math.min(te/se,ie/xe),je=Math.max(te/se,ie/xe)/me;je>1.01&&(P(je),V(je),O.current=je),W.current=!0};B.complete&&B.naturalWidth?H():B.addEventListener("load",H,{once:!0})},[J,f]);const oe=.5;c.useEffect(()=>{C<=oe&&(M(0),_(0))},[C,oe]);const T=(B,q,H)=>{if(H<=oe)return{x:0,y:0};const te=(H-1)/(2*H)*100,ie=(H-1)/(2*H)*100;return{x:Math.max(-te,Math.min(te,B)),y:Math.max(-ie,Math.min(ie,q))}},b=(B,q)=>{if(!l.current)return null;const H=l.current.getBoundingClientRect();return!H.width||!H.height?null:{nx:Math.max(0,Math.min(1,(B-H.left)/H.width)),ny:Math.max(0,Math.min(1,(q-H.top)/H.height))}},$=(B,q,H)=>{const te=u.current;if(!te)return;const ie=te.getBoundingClientRect(),se=++I.current;y(xe=>[...xe,{id:se,x:B-ie.left,y:q-ie.top,type:H}]),setTimeout(()=>y(xe=>xe.filter(me=>me.id!==se)),600)},E=(B,q,H)=>{const te=l.current,ie=u.current;if(!te||!ie)return;const se=te.getBoundingClientRect(),xe=ie.getBoundingClientRect(),me=te.naturalWidth||se.width,Ue=te.naturalHeight||se.height,je=me/Ue,vt=se.width/se.height;let Oe,Le,Ve,Ye;je>vt?(Oe=se.width,Le=se.width/je,Ve=0,Ye=(se.height-Le)/2):(Le=se.height,Oe=se.height*je,Ve=(se.width-Oe)/2,Ye=0);const wt=se.left-xe.left+Ve+Oe*B,Nt=se.top-xe.top+Ye+Le*q,at=++I.current;y(qe=>[...qe,{id:at,x:wt,y:Nt,type:H}]),setTimeout(()=>y(qe=>qe.filter(pe=>pe.id!==at)),600)},z=async B=>{var H;const q=b(B.clientX,B.clientY);if(q){d(`Click: ${Math.round(q.nx*100)}%, ${Math.round(q.ny*100)}%`),$(B.clientX,B.clientY,"left"),(H=i.current)==null||H.focus();try{const te=await t("input_click",{nx:q.nx,ny:q.ny});te!=null&&te.success||s(`❌ Click failed: ${te==null?void 0:te.error}`)}catch(te){s(`❌ Click error: ${te.message||te}`)}}},G=async(B,q,H,te=0)=>{try{await t("input_key",{type:H?"char":"keyDown",key:B,code:q,text:H?B:void 0,unmodifiedText:H?B:void 0,modifiers:te})}catch(ie){s(`❌ Key error: ${ie.message||ie}`)}},U=async B=>{if(B.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(B.key)&&B.preventDefault();let H=0;B.altKey&&(H|=1),B.ctrlKey&&(H|=2),B.metaKey&&(H|=4),B.shiftKey&&(H|=8),d(`Key: ${B.key}`),await G(B.key,B.code,B.key.length===1,H)},ee=async B=>{if(B.key==="Enter"){if(B.nativeEvent.isComposing)return;if(x){const q=x;p(""),d(`IME Sent: ${q}`);try{const H=await t("input_type",{text:q});H!=null&&H.success||s(`❌ IME error: ${H==null?void 0:H.error}`)}catch(H){s(`❌ IME error: ${H.message}`)}}else d("Key: Enter"),await G("Enter","Enter",!1)}};c.useEffect(()=>{const B=i.current;if(!B)return;const q=H=>{var te;if((te=l.current)!=null&&te.contains(H.target)){H.preventDefault();const ie=Date.now();if(ie-R.current<40)return;R.current=ie;const se=b(H.clientX,H.clientY);if(!se)return;d(`Scroll: ${Math.round(H.deltaY)}`),t("input_wheel",{nx:se.nx,ny:se.ny,deltaX:Math.round(H.deltaX),deltaY:Math.round(H.deltaY)}).catch(()=>{})}};return B.addEventListener("wheel",q,{passive:!1}),()=>B.removeEventListener("wheel",q)},[t]);const{cursorPos:X,handleToggleInputMode:Z,handleZoomReset:ne}=zn({containerRef:i,viewportRef:u,imgRef:l,inputMode:k,setInputMode:S,minZoom:oe,zoomRef:O,panXRef:K,panYRef:Y,setPanX:M,setPanY:_,setZoom:V,lastWheelTimeRef:R,onAction:t,setLastActionStatus:d,spawnRippleFromNormalized:E,clampPan:T,isMobile:f,mobileFillZoom:j});return e.jsxs("div",{ref:i,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:U,onContextMenu:B=>B.preventDefault(),onFocus:()=>g(!0),onBlur:()=>g(!1),tabIndex:0,children:[e.jsxs("div",{ref:u,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[J?e.jsx("img",{ref:l,src:J,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${C}) translate(${A}%, ${D}%)`,transformOrigin:"center center",cursor:k==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:z,onContextMenu:B=>B.preventDefault(),onDragStart:B=>B.preventDefault()}):e.jsx(Kn,{waitingLabel:ae,waitingHint:Q,transportType:a}),k==="mouse"&&J&&e.jsx(Wn,{cursorPos:X,viewportRef:u,imgRef:l}),m.map(B=>{const H={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[B.type];return e.jsxs("div",{style:{position:"absolute",left:B.x,top:B.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${H}, 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(${H}, 0.9)`,boxShadow:`0 0 12px rgba(${H}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},B.id)})]}),e.jsx(On,{inputMode:k,onToggleInputMode:Z,isImeOpen:N,setIsImeOpen:L,isMenuOpen:w,setIsMenuOpen:v,imeText:x,setImeText:p,handleImeSubmit:ee,isConnActive:F,zoom:C,isMobile:f,mobileFillZoom:j,onZoomOut:()=>V(B=>Math.max(.5,B-.25)),onZoomReset:ne,onZoomIn:()=>V(B=>Math.min(5,B+.25)),transportType:a,screenshotUsage:o,lastActionStatus:h}),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 Un({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:o,onDismiss:a,onClickAt:i,onKeyDown:u,badge:l,emptyMessage:h,aspectRatio:d,className:x,style:p}){const g=c.useRef(null),m=c.useCallback(y=>{if(!r||!i||!g.current)return;const I=g.current,w=I.getBoundingClientRect(),v=(y.clientX-w.left)/w.width*I.naturalWidth,N=(y.clientY-w.top)/w.height*I.naturalHeight;i(v,N,I.naturalWidth,I.naturalHeight)},[r,i]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${x||""}`,style:{aspectRatio:d||"16/9",...p},children:[e.jsx("img",{ref:g,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),a&&e.jsx("button",{onClick:a,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":""} ${x||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?u:void 0,style:p,children:[e.jsx("img",{ref:g,src:t,alt:"IDE Screenshot",onClick:r?m: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 ${x||""}`,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:h||"Waiting for screenshot stream..."}),o&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",o]}),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 $s({activeConv:t,onModalButton:s}){const[n,r]=c.useState(null);if(c.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const o=i=>{n||(r(i),s(i))},a=i=>i.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(Bt,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((i,u)=>{const l=a(i).toLowerCase(),h=/^(run|approve|accept|yes|allow|always)/.test(l),d=/^(reject|deny|delete|remove|abort)/.test(l),x=n===i,p=n!==null;return e.jsx("button",{onClick:()=>o(i),disabled:p,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${h?"bg-white text-amber-700 font-extrabold":d?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${p&&!x?"opacity-40":"opacity-100"} ${p?"cursor-not-allowed":"cursor-pointer"}`,children:x?"⏳ ...":a(i)},u)})})]})]})}const fe=new Map;function Vn({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:o,serverModel:a,serverMode:i,acpConfigOptions:u,acpModes:l}){var oe;const{sendCommand:h}=$e(),d=!!(u||l),x=`${t}:${s||r}`,p=fe.get(x),[g,m]=c.useState(!1),[y,I]=c.useState(!1),[w,v]=c.useState((p==null?void 0:p.models)||[]),[N,L]=c.useState((p==null?void 0:p.modes)||[]),f=T=>T?typeof T=="string"?T:typeof T=="object"?T.name||T.id||JSON.stringify(T):String(T):"",[k,S]=c.useState(f(a)),[j,P]=c.useState(f(i)),[W,C]=c.useState(!1),[V,A]=c.useState(!1),M=c.useRef(0),D=T=>T.map(b=>typeof b=="string"?b:(b==null?void 0:b.name)||(b==null?void 0:b.id)||String(b));c.useEffect(()=>{if(u){const T=u.find(b=>b.category==="model");if(T){const b=D(T.options.map(E=>E.value));v(b),T.currentValue&&S(f(T.currentValue));const $=fe.get(x)||{models:[],modes:[]};fe.set(x,{...$,models:b})}}if(l&&l.length>0){const T=D(l.map($=>$.id));L(T);const b=fe.get(x)||{models:[],modes:[]};fe.set(x,{...b,modes:T})}else if(u){const T=u.find(b=>b.category!=="model");if(T){const b=D(T.options.map(E=>E.value));L(b),T.currentValue&&P(f(T.currentValue));const $=fe.get(x)||{models:[],modes:[]};fe.set(x,{...$,modes:b})}}},[u,l,x]),c.useEffect(()=>{m(!1),I(!1),S(f(a)),P(f(i));const T=fe.get(x);T?(v(T.models),L(T.modes)):(v([]),L([]))},[t,r,s]),c.useEffect(()=>{a&&Date.now()>M.current&&S(f(a))},[a]),c.useEffect(()=>{i&&Date.now()>M.current&&P(f(i))},[i]);const _=c.useCallback(async(T,b={})=>{const $={...b,...s&&{targetSessionId:s}};return await h(t,T,$)},[t,s,h]),R=async()=>{var T,b;if(w.length>0){m(!g);return}if(d){m(!0);return}C(!0);try{const $=await _("list_extension_models",{agentType:r,ideType:n}),E=($==null?void 0:$.models)||((T=$==null?void 0:$.result)==null?void 0:T.models)||[],z=D(E);v(z),$!=null&&$.current&&S(f($.current)),(b=$==null?void 0:$.result)!=null&&b.current&&S(f($.result.current));const G=fe.get(x)||{models:[],modes:[]};fe.set(x,{...G,models:z}),m(!0)}catch{}finally{C(!1)}},O=async()=>{var T,b;if(N.length>0){I(!y);return}if(d){I(!0);return}A(!0);try{const $=await _("list_extension_modes",{agentType:r,ideType:n}),E=($==null?void 0:$.modes)||((T=$==null?void 0:$.result)==null?void 0:T.modes)||[],z=D(E);L(z),$!=null&&$.current&&P(f($.current)),(b=$==null?void 0:$.result)!=null&&b.current&&P(f($.result.current));const G=fe.get(x)||{models:[],modes:[]};fe.set(x,{...G,modes:z}),I(!0)}catch{}finally{A(!1)}},K=async T=>{m(!1),S(T),M.current=Date.now()+5e3;try{d?await _("change_model",{agentType:r,ideType:n,model:T}):await _("set_extension_model",{agentType:r,ideType:n,model:T})}catch{}},Y=d&&!(l&&l.length>0)&&(u==null?void 0:u.some(T=>T.category!=="model")),F=Y?(oe=u==null?void 0:u.find(T=>T.category!=="model"))==null?void 0:oe.configId:void 0,J=async T=>{I(!1),P(T),M.current=Date.now()+5e3;try{d&&Y&&F?await _("set_thought_level",{agentType:r,ideType:n,configId:F,value:T}):d?await _("set_mode",{agentType:r,ideType:n,mode:T}):await _("set_extension_mode",{agentType:r,ideType:n,mode:T})}catch{}},Q={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 opacity-70",style:{color:Q},children:o}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:g?`${Q}55`:"transparent",border:"1px solid",color:k?"var(--text-primary)":"var(--text-muted)"},onClick:R,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),W?"...":k||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),g&&w.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>m(!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"}),w.map(T=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:T===k?`${Q}18`:"transparent",color:T===k?Q:"var(--text-secondary)",fontWeight:T===k?600:400,borderLeft:T===k?`2px solid ${Q}`:"2px solid transparent"},onMouseEnter:b=>{b.currentTarget.style.background=`${Q}12`},onMouseLeave:b=>{b.currentTarget.style.background=T===k?`${Q}18`:"transparent"},onClick:()=>K(T),children:T},T))]})]})]}),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:y?`${Q}55`:"transparent",border:"1px solid",color:j?"var(--text-primary)":"var(--text-muted)"},onClick:O,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:Y?"🧠":"⚡"}),V?"...":j||(Y?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),y&&N.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>I(!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:Y?"SELECT THINKING LEVEL":"SELECT MODE"}),N.map(T=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:T===j?`${Q}18`:"transparent",color:T===j?Q:"var(--text-secondary)",fontWeight:T===j?600:400,borderLeft:T===j?`2px solid ${Q}`:"2px solid transparent"},onMouseEnter:b=>{b.currentTarget.style.background=`${Q}12`},onMouseLeave:b=>{b.currentTarget.style.background=T===j?`${Q}18`:"transparent"},onClick:()=>J(T),children:T},T))]})]})]})]})}const ge=t=>t.transport==="pty",he=t=>t.transport==="acp";var Yn=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function qn(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function be(t,s){if(qn(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":Yn.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 _s(t){return be(t)==="generating"}function ue(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function Xn(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 o=Math.floor(n/24),a=n%24;return`${o}d ${a}h`}function Xt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Gn(t){if(t.length>16&&/^[a-f0-9]+$/i.test(t))return`Machine-${t.substring(0,8)}`;if(t.includes("_")){const s=t.split("_"),n=s[s.length-1];return n.length>12?`Machine-${n.substring(0,8)}`:n}return t}function Jn(t){return Gn(t.trim().replace(/\.local$/i,""))}function Zn(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Ls(t,s={}){var o,a;const n=[t.hostname,(o=t.machine)==null?void 0:o.hostname,(a=t.system)==null?void 0:a.hostname].find(i=>typeof i=="string"&&i.trim().length>0);if(n&&n!=="Unknown")return Jn(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function Fe(t,s={}){return Zn(t)||Ls(t,s)}function Gt(t){return t.transport==="pty"}function Jt(t){return t.transport==="acp"}function Zt(t,s){return ue(t)}function Qn(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const o=(s||"").trim().toLowerCase(),a=(n||"").trim().toLowerCase(),i=ue(n||"").trim().toLowerCase();return r===o||r===a||r===i}function er(t){return be(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function tr(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 o=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),a=s.get(o),i=be(r.status);if(!a){s.set(o,{...r,status:i});continue}const u=n.indexOf(a.status||"idle"),l=n.indexOf(i||"idle");l>=0&&(u<0||l<u)&&s.set(o,{...r,status:i})}return Array.from(s.values())}function Ps({activeConv:t,ides:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:o,isFocusingAgent:a,messageReceivedAt:i,actionLogs:u,userName:l}){const h=c.useRef(null),{sendCommand:d}=$e(),[x,p]=c.useState("");rt("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:u.length,draftLength:x.length,isSendingChat:r});const g=c.useRef(new Map),m=c.useCallback(A=>(g.current.has(A)||g.current.set(A,{messages:[],offset:0,hasMore:!0,error:null}),g.current.get(A)),[]),y=c.useCallback((A,M)=>{const D=m(A);g.current.set(A,{...D,...M}),I(_=>_+1)},[m]),[,I]=c.useState(0),w=t.tabKey,v=m(w),N=v.messages,L=v.hasMore,f=v.error,[k,S]=c.useState(!1),j=c.useCallback(async()=>{var D,_;if(k)return;const A=t.tabKey,M=m(A);S(!0),y(A,{error:null});try{const R=s.find(J=>J.id===t.ideId),O=(R==null?void 0:R.daemonId)||((D=t.ideId)==null?void 0:D.split(":")[0])||"";if(!O){y(A,{hasMore:!1});return}const K=t.ideType||t.agentType||"",Y=await d(O,"chat_history",{agentType:K,offset:M.offset,limit:30,targetSessionId:t.sessionId}),F=(Y==null?void 0:Y.result)??Y;if(((_=F.messages)==null?void 0:_.length)>0){const J=m(A);y(A,{messages:[...F.messages,...J.messages],offset:J.offset+F.messages.length,hasMore:!!F.hasMore})}else y(A,{hasMore:!!F.hasMore})}catch(R){const O=(R==null?void 0:R.message)||"";O.includes("P2P not available")||O.includes("channel not open")||O.includes("P2P not connected")||O.includes("timeout")?y(A,{error:"Connection not ready — tap to retry"}):y(A,{hasMore:!1,error:"Failed to load history"})}finally{S(!1)}},[k,s,t,d,m,y]);c.useEffect(()=>{p("")},[t.tabKey]);const P=c.useMemo(()=>{const A=t.messages.map((_,R)=>{const O=`${t.ideId}-${_.id??`i-${R}`}`;return{..._,receivedAt:_.receivedAt||i[O]||0}});if(N.length===0)return A;const M=new Set(A.map(_=>`${_.role}:${(_.content||"").slice(0,100)}`));return[...N.filter(_=>!M.has(`${_.role}:${(_.content||"").slice(0,100)}`)),...A]},[t.messages,t.ideId,N,i]),W=c.useMemo(()=>u.filter(A=>A.ideId===t.tabKey).sort((A,M)=>A.timestamp-M.timestamp),[u,t.tabKey]),C=t.displayPrimary||t.agentName||"Agent",V=c.useMemo(()=>{if(t.messages.length===0){if(t.connectionState==="connecting"||t.connectionState==="new")return 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"})]})]});if(t.status==="not_monitored")return 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(ze,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:o,disabled:a,className:"btn btn-primary",children:a?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($t,{size:14})," Open ",C," Panel"]})}),e.jsx("div",{className:"text-[11px] opacity-35 max-w-[280px]",children:"Click to switch monitoring to this agent"})]});if(t.status==="panel_hidden")return 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(Cs,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:o,disabled:a,className:"btn btn-primary",children:a?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($t,{size:14})," Open ",C," 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"})]});if(t.status==="idle"&&!k)return 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..."})]})}},[t.messages.length,t.connectionState,t.status,o,a,k,C]);return e.jsxs(e.Fragment,{children:[e.jsx(Bn,{messages:P,actionLogs:W,agentName:t.agentName||t.displayPrimary||"Agent",userName:l,isCliMode:ge(t)||he(t),isWorking:t.status==="generating",contextKey:t.tabKey,onLoadMore:j,isLoadingMore:k,hasMoreHistory:L,loadError:f??void 0,emptyState:V}),!ge(t)&&(()=>{const A=s.find(R=>R.id===t.ideId),M=t.streamSource!=="agent-stream",D=M?t.ideType:t.agentType,_=M?A!=null&&A.type?ue(A.type):ue(t.ideType||""):t.agentName||ue(t.agentType||"");return e.jsx(Vn,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:D,displayLabel:_,serverModel:(A==null?void 0:A.currentModel)||void 0,serverMode:(A==null?void 0:A.currentPlan)||void 0,acpConfigOptions:he(t)?A==null?void 0:A.acpConfigOptions:void 0,acpModes:he(t)?A==null?void 0:A.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:h,type:"text",placeholder:`Send message to ${C}...`,value:x,onChange:A=>p(A.target.value),onPaste:A=>{const M=A.clipboardData.getData("text");M&&p(D=>D+M),A.preventDefault()},onKeyDown:A=>{if(A.key!=="Enter")return;if(A.nativeEvent.isComposing){A.preventDefault();return}A.preventDefault();const M=x.trim();!M||r||(p(""),n(M))},onBlur:A=>{if(window.innerWidth<768){const M=A.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:()=>{const A=x.trim();!A||r||(p(""),n(A))},disabled:!x.trim()||r,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${x.trim()&&!r?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:x.trim()&&!r?{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:x.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}const Ct=new Set,Rs={emit(t,s){for(const n of Ct)n(t,s)},on(t){return Ct.add(t),()=>{Ct.delete(t)}}};function sr({activeConv:t,ptyBuffers:s,terminalRef:n,handleSendChat:r,isSendingChat:o=!1}){const a=c.useRef(null),{sendCommand:i,sendData:u}=$e(),[l,h]=c.useState(""),d=t.tabKey,x=t.sessionId||"";return c.useEffect(()=>{const p=s.current.get(d);if(p&&p.length>0){const g=setTimeout(()=>{var m;for(const y of p)(m=n.current)==null||m.write(y);requestAnimationFrame(()=>{var y;(y=n.current)==null||y.bumpResize()})},100);return()=>clearTimeout(g)}},[d]),c.useEffect(()=>{const p=Rs.on((g,m)=>{var I;if(!m)return;(g===x||g===t.ideId||g===t.tabKey)&&((I=n.current)==null||I.write(m))});return()=>{p()}},[x,t.ideId,t.tabKey]),c.useEffect(()=>{h("")},[t.tabKey]),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:e.jsx(As,{ref:n,onInput:p=>{const g=t.ideId||t.daemonId||"";u!=null&&u(g,{type:"pty_input",targetSessionId:x,data:p})||i(g,"pty_input",{targetSessionId:x,data:p}).catch(console.error)},onResize:(p,g)=>{const m=t.ideId||t.daemonId||"";u!=null&&u(m,{type:"pty_resize",targetSessionId:x,cols:p,rows:g})||i(m,"pty_resize",{targetSessionId:x,cols:p,rows:g,force:!0}).catch(()=>{})}},t.tabKey)}),e.jsx("div",{className:"px-3 py-2 bg-[var(--surface-primary)] border-t border-border-subtle shrink-0",children:e.jsxs("div",{className:"flex gap-2.5 items-center",children:[e.jsx("div",{className:"flex-1 relative",children:e.jsx("input",{ref:a,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:l,onChange:p=>h(p.target.value),onPaste:p=>{const g=p.clipboardData.getData("text");g&&h(m=>m+g),p.preventDefault()},onKeyDown:p=>{if(p.key!=="Enter")return;if(p.nativeEvent.isComposing){p.preventDefault();return}p.preventDefault();const g=l.trim();!g||o||(h(""),r(g))},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:()=>{const p=l.trim();!p||o||(h(""),r(p))},disabled:!l.trim()||o,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${l.trim()&&!o?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:l.trim()&&!o?{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:l.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})]})}function nr({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",o=t==="auth_failed"?"red":t==="offline"?"orange":"violet",a={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))"},i={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)"},u={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:a[o],borderBottom:i[o],color:u[o]},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 Ds=tt;function jt(){return Ds()}class rr{constructor(){ce(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(o=>o(...n))}}let Bs=new rr;class ar{constructor(){ce(this,"ptyCallbacks",new Set)}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,o){return!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 Me=new ar;function or(t){t.dashboardWS&&(Bs=t.dashboardWS),t.connectionManager&&(Me=t.connectionManager),t.useDaemonsHook&&(Ds=t.useDaemonsHook)}function ir({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,onOpenHistory:o,onStopCli:a}){const i=nt(),u=jt(),l=u.p2pStates||{},h=u.ides||[],d=!!t&&ge(t)&&!he(t),x=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",p=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",g=h.filter(N=>N.type==="adhdev-daemon"),m=Object.values(l),y=m.filter(N=>N==="connected").length,I=m.filter(N=>N==="connecting"||N==="new"||N==="checking").length,v=n!=="connected"||g.length===0?null:I>0&&y===0?"P2P connecting...":y>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(He,{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:x,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:x,boxShadow:p}}),v&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",v]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[d&&a&&e.jsx("button",{onClick:a,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&&!d&&!he(t)&&e.jsxs("button",{onClick:()=>i(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Wt,{size:14})," IDE"]}),t&&!d&&!he(t)&&e.jsx("button",{onClick:o,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(ks,{size:16})}),t&&!d&&!he(t)&&e.jsx("button",{onClick:()=>i(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(_e,{size:16})})]})]})}function Ws({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:o,onNewChat:a,onSwitchSession:i,onRefreshHistory:u}){var x;const l=s.find(p=>p.id===t.ideId),h=(l==null?void 0:l.chats)||[],d=(x=l==null?void 0:l.activeChat)==null?void 0:x.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:o,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:o,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:a,disabled:n,className:"w-full p-3.5 rounded-xl mb-3 bg-indigo-500/10 border border-dashed border-accent text-accent font-bold text-sm cursor-pointer",children:n?"⌛ Creating...":"+ Start New Chat Session"}),h.map(p=>e.jsxs("div",{onClick:()=>{i(t.ideId,p.id),o()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${d===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 ${d===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),"..."]}),d===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)),h.length===0&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx(An,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:u,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(Ss,{size:13})," Refresh History"]})})})]})]})}const Qt={success:"rgba(16, 185, 129, 0.95)",warning:"rgba(245, 158, 11, 0.95)",info:"rgba(99, 102, 241, 0.95)"};function Os({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:Qt[r.type]||Qt.info},onClick:()=>{var o;(o=r.actions)!=null&&o.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:o=>{o.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((o,a)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${o.variant==="primary"?"bg-white text-amber-700 hover:bg-gray-100":o.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:i=>{i.stopPropagation(),o.onClick(),s(r.id)},children:o.label},a))})]},r.id))})}const cr=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function lr(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function dr(t){return t.sessionId||t.instanceId||t.agentType}function es(t,s){const n=new Set,r=[];for(const o of s)if(o)for(const a of t[o]||[]){const i=a._localId||`${a.role}:${a.timestamp}:${a.content}`;n.has(i)||(n.add(i),r.push(a))}return r.sort((o,a)=>o.timestamp-a.timestamp)}function Ks(t,s,n,r){const o={};if(n)for(const a of n){const i=a;(i.type==="adhdev-daemon"||i.daemonMode)&&(o[i.id]=Fe(i,{fallbackId:i.id}))}return t.flatMap(a=>{var w,v,N,L,f,k,S;const i=[],u=a.daemonId&&o[a.daemonId]||void 0,l=a.daemonId||((w=a.id)==null?void 0:w.split(":")[0])||a.id,h=r?r[l]||"new":void 0,d=lr(a),x=ue(a.type),p=a.agentStreams,g=Array.isArray(p)?p.map(j=>({...j,activeModal:j.activeModal??void 0})):[],m=cr(a),y=a.activeChat||{title:""},I=y.title&&String(y.title).trim()?String(y.title).trim():"";if(m){const j=a.sessionId||a.instanceId,P=Zt(a.type),W=(v=a.activeChat)==null?void 0:v.activeModal,C=W&&Array.isArray(W.buttons)&&W.buttons.length>0,V=be((N=a.activeChat)==null?void 0:N.status,{activeModal:(L=a.activeChat)==null?void 0:L.activeModal})||be((k=(f=a.agents)==null?void 0:f[0])==null?void 0:k.status)||"idle",A=a.activeChat||{title:"",messages:[]};let M=A.title&&String(A.title).trim()?String(A.title).trim():"";const D=(S=a.activeChat)==null?void 0:S.id,_=a.chats;if(D&&Array.isArray(_)&&_.length>0){const F=_.find(J=>J.id===D||J.id&&String(J.id)===String(D));F!=null&&F.title&&String(F.title).trim()&&(M=String(F.title).trim())}const R=A.messages||[],O=es(s,[a.id,j]),K=new Map;R.filter(F=>F.role==="user").forEach(F=>{K.set(F.content,(K.get(F.content)||0)+1)});const Y=O.filter(F=>{const J=K.get(F.content)||0;return J>0?(K.set(F.content,J-1),!1):!0});i.push({ideId:a.id,sessionId:j,transport:a.transport,daemonId:a.daemonId||void 0,mode:ge(a)?a.mode||"terminal":"chat",agentName:P,agentType:(ge(a)||he(a))&&(a.cliType||a.acpType)||a.type,status:V,title:M,messages:[...R,...Y],ideType:a.cliType||a.acpType||a.type,workspaceName:d,displayPrimary:M||d||(ge(a)||he(a)?"Terminal":P),displaySecondary:x,cdpConnected:a.cdpConnected,modalButtons:C?W.buttons:void 0,modalMessage:C?W.message:void 0,streamSource:"native",tabKey:a.id,machineName:u,connectionState:h})}if(m&&(ge(a)||he(a)))return i;for(const j of g){const P=j.activeModal&&Array.isArray(j.activeModal.buttons)&&j.activeModal.buttons.length>0,W=er(j),C=dr(j),V=`${a.id}:${C}`,A=j.title&&String(j.title).trim()||"",M=Qn(A,j.agentName,j.agentType)?"":A,D=j.messages||[],_=es(s,[V,j.sessionId,j.instanceId]),R=new Map;D.filter(K=>K.role==="user").forEach(K=>{R.set(K.content,(R.get(K.content)||0)+1)});const O=_.filter(K=>{const Y=R.get(K.content)||0;return Y>0?(R.set(K.content,Y-1),!1):!0});i.push({ideId:a.id,sessionId:j.sessionId||j.instanceId,transport:j.transport||"cdp-webview",daemonId:a.daemonId||void 0,mode:"chat",agentName:j.agentName,agentType:j.agentType,status:W,title:M,messages:[...D,...O],ideType:j.agentType,workspaceName:d,displayPrimary:M||I||d||x,displaySecondary:`${x}·${j.agentName}`,cdpConnected:a.cdpConnected,modalButtons:P?j.activeModal.buttons:void 0,modalMessage:P?j.activeModal.message:void 0,streamSource:"agent-stream",tabKey:V,machineName:u,connectionState:h})}return i.length===0&&i.push({ideId:a.id,sessionId:a.sessionId||a.instanceId,transport:a.transport,daemonId:a.daemonId||void 0,mode:"chat",agentName:Zt(a.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:a.type,workspaceName:d,displayPrimary:d||x,displaySecondary:x,cdpConnected:a.cdpConnected,streamSource:"native",tabKey:a.id,connectionState:h}),i})}function ur(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const o=n.get(r.parentId)||[];o.push(r),n.set(r.parentId,o)}else s.push(r);return{topLevel:s,childrenByParent:n}}function xr(t,s){var g,m,y,I,w,v,N,L;const n=[],{daemonId:r,existingDaemon:o,timestamp:a}=s,i=a||t.timestamp||Date.now(),u=t.sessions||[],{topLevel:l,childrenByParent:h}=ur(u),d=l.filter(f=>f.kind==="workspace"&&f.transport==="cdp-page"),x=l.filter(f=>f.kind==="agent"&&f.transport==="pty"),p=l.filter(f=>f.kind==="agent"&&f.transport==="acp");n.push({...o||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:i,...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:d.some(f=>!!f.cdpConnected)});for(const f of d){const k=h.get(f.id)||[];n.push({id:`${r}:ide:${f.id}`,sessionId:f.id,parentSessionId:f.parentId,sessionKind:f.kind,transport:f.transport,sessionCapabilities:f.capabilities,type:f.providerType,ideType:f.providerType,status:f.cdpConnected?"online":"detected",daemonId:r,instanceId:f.id,workspace:f.workspace,terminals:0,agents:k.map(S=>({id:S.id,name:S.providerName,type:S.providerType,status:S.status})),activeChat:f.activeChat,chats:[],agentStreams:k.map(S=>{var j,P,W,C;return{sessionId:S.id,instanceId:S.id,parentSessionId:S.parentId,agentType:S.providerType,agentName:S.providerName,extensionId:S.providerType,transport:S.transport,status:be(S.status,{activeModal:(j=S.activeChat)==null?void 0:j.activeModal}),title:S.title,messages:((P=S.activeChat)==null?void 0:P.messages)||[],inputContent:((W=S.activeChat)==null?void 0:W.inputContent)||"",activeModal:((C=S.activeChat)==null?void 0:C.activeModal)||null,model:S.currentModel}}),cdpConnected:f.cdpConnected,currentModel:f.currentModel,currentPlan:f.currentPlan,currentAutoApprove:f.currentAutoApprove,timestamp:i})}for(const f of x)n.push({id:`${r}:cli:${f.id}`,sessionId:f.id,parentSessionId:f.parentId,sessionKind:f.kind,transport:f.transport,sessionCapabilities:f.capabilities,type:f.providerType,ideType:f.providerType,agentType:f.providerType,status:f.status||"running",daemonId:r,instanceId:f.id,cliName:f.providerName,mode:"terminal",workspace:f.workspace||"",activeChat:f.activeChat,agentStreams:[{sessionId:f.id,instanceId:f.id,parentSessionId:f.parentId,agentType:f.providerType,agentName:f.providerName,extensionId:"cli-agent",transport:f.transport,status:be(f.status,{activeModal:(g=f.activeChat)==null?void 0:g.activeModal}),title:f.title,messages:((m=f.activeChat)==null?void 0:m.messages)||[],inputContent:((y=f.activeChat)==null?void 0:y.inputContent)||"",activeModal:(I=f.activeChat)==null?void 0:I.activeModal}],timestamp:i,_isCli:!0});for(const f of p)n.push({id:`${r}:acp:${f.id}`,sessionId:f.id,parentSessionId:f.parentId,sessionKind:f.kind,transport:f.transport,sessionCapabilities:f.capabilities,type:f.providerType,ideType:f.providerType,agentType:f.providerType,status:f.status||"running",daemonId:r,instanceId:f.id,cliName:f.providerName,mode:"chat",workspace:f.workspace||"",activeChat:f.activeChat,currentModel:f.currentModel,currentPlan:f.currentPlan,acpConfigOptions:f.acpConfigOptions,acpModes:f.acpModes,agentStreams:[{sessionId:f.id,instanceId:f.id,parentSessionId:f.parentId,agentType:f.providerType,agentName:f.providerName,extensionId:"acp-agent",transport:f.transport,status:be(f.status,{activeModal:(w=f.activeChat)==null?void 0:w.activeModal}),title:f.title,messages:((v=f.activeChat)==null?void 0:v.messages)||[],inputContent:((N=f.activeChat)==null?void 0:N.inputContent)||"",activeModal:(L=f.activeChat)==null?void 0:L.activeModal}],timestamp:i,_isAcp:!0});return n}function Hs(t){const s=t.split(":");return s.length>=3&&(s[1]==="ide"||s[1]==="cli"||s[1]==="acp")?{daemonId:s[0],targetSessionId:s.slice(2).join(":")||void 0}:{daemonId:t}}function pr(t,s){const n=Hs(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const zs=[{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:"💚"}],Fs=[{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:"🧩"}],Us=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Vs="adhdev_notification_prefs",ts={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function hr(){try{const t=localStorage.getItem(Vs);if(t){const s=JSON.parse(t);return{...ts,...s}}}catch{}return{...ts}}function mr(t){try{localStorage.setItem(Vs,JSON.stringify(t))}catch{}}let we=hr(),xt=[];function fr(){xt.forEach(t=>t())}function gr(){return{...we}}function br(t){we={...we,...t},mr(we),fr()}function yr(){const[,t]=c.useState(0);c.useEffect(()=>{const n=()=>t(r=>r+1);return xt.push(n),()=>{xt=xt.filter(r=>r!==n)}},[]);const s=c.useCallback(n=>{br(n)},[]);return[{...we},s]}function Ze(t){if(!we.globalEnabled)return!1;switch(t){case"disconnect":return we.disconnectAlert;case"completion":return we.completionAlert;case"approval":return we.approvalAlert;case"browser":return we.browserNotifications;default:return!0}}const jr={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function vr(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Ys(){return"Notification"in window&&Notification.permission==="granted"}let Pe=null;async function wr(){if(Pe!==null)return Pe;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Pe=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Pe=!!await t.pushManager.getSubscription(),Pe):(Pe=!1,!1)}catch{return Pe=!1,!1}}function _t(t,s,n){if(Ys())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 Nr(t,s={}){const n={...jr,...s},r=c.useRef(new Map),o=c.useRef(0),a=c.useRef(null);c.useEffect(()=>{wr().then(u=>{a.current=u})},[]);const i=c.useCallback((u,l,h)=>{const d=Date.now();d-o.current<n.throttleMs||(o.current=d,_t(u,l,h))},[n.throttleMs]);c.useEffect(()=>{var u;if(!(!n.enabled||!Ys())&&Ze("browser")&&a.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,be(l.status,{activeModal:l.activeModal}));return}for(const l of t){const h=r.current.get(l.id),d=be(l.status,{activeModal:l.activeModal}),x=l.name||l.id;if(n.onApproval&&Ze("approval")&&d==="waiting_approval"&&h!=="waiting_approval"){const p=((u=l.activeModal)==null?void 0:u.message)||"Action requires your approval";i(`🔔 ${x} — Approval needed`,p.slice(0,120),`approval-${l.id}`)}n.onComplete&&Ze("completion")&&_s(h)&&d==="idle"&&i(`✅ ${x} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&d==="error"&&h!=="error"&&i(`⚠️ ${x} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,d)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,i])}class kr{constructor(){ce(this,"dedupMap",new Map);ce(this,"DEDUP_WINDOW_MS",5e3);ce(this,"DEDUP_MAX_SIZE",50);ce(this,"DEDUP_CLEANUP_AGE_MS",1e4);ce(this,"toastCallbacks",[]);ce(this,"systemMessageCallbacks",[]);ce(this,"clearSystemMessageCallbacks",[]);ce(this,"resolveActionFn",null);ce(this,"viewRequestRespondFn",null);ce(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 o=(r==null?void 0:r.id)||Date.now();this.emitToast({id:o,message:s,type:n,timestamp:o,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[o,a]of this.dedupMap)n-a>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(o);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const o=this.ides.find(a=>a.id===s.ideId&&a.type==="adhdev-daemon");if(o)return o}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(o=>o.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(o=>o.id.endsWith(`:ide:${s.instanceId}`)||o.id.endsWith(`:cli:${s.instanceId}`))),n){const o=n.daemonId;if(o){const a=this.ides.find(i=>i.id===o&&i.type==="adhdev-daemon");if(a)return a}}const r=this.ides.filter(o=>o.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(o=>(o==null?void 0:o.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 d,x;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),a=`${r||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(a))return;let i=ue(s.ideType||"");const u=this.resolveOwningDaemon(s);if(u){const p=Fe(u,{fallbackId:u.id});p&&(i=s.ideType==="adhdev-daemon"?p:`${p}/${i}`)}let l="",h="info";if(s.event==="agent:generating_completed"){const p=s.duration?` (${s.duration}s)`:"";l=`✅ ${i} agent task completed${p}`,h="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&gr().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=`⚡ ${i} approval needed`,h="warning",r){const p=s.modalMessage||"Approval requested",g=(d=s.modalButtons)!=null&&d.length?s.modalButtons.map(m=>`[${m}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${p}
39
- ${g}`,_localId:`sys_approval_${Date.now()}`})}if((x=s.modalButtons)!=null&&x.length&&this.resolveActionFn){const p=this.resolveActionRouteTarget(s);if(!p)return;const g=s.agentType||s.ideType||"",m=s.ideType||"",y=s.modalButtons,I=f=>f.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),w=this.resolveActionFn,v=y.map((f,k)=>{const S=I(f).toLowerCase(),j=/^(run|approve|accept|yes|allow|always)/.test(S),P=/^(reject|deny|delete|remove|abort|cancel|no)/.test(S);return{label:I(f),variant:j?"primary":P?"danger":"default",onClick:()=>{const W=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(S);w(p,"resolve_action",{action:W?"approve":"reject",button:f,buttonIndex:k,agentType:g,ideType:m,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),N=s.modalMessage?`⚡ ${i}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,L=Date.now();this.emitToast({id:L,message:N,type:h,timestamp:L,targetKey:r||p,actions:v,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const p=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${i} agent is taking a long time${p}`,h="warning",Ze("browser")&&!document.hasFocus()&&_t(`⚠️ ${i} — 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",g=s.requestId,m=s.orgId;if(l=`👁️ ${p} wants to view your session`,h="warning",g&&m&&this.viewRequestRespondFn){const y=this.viewRequestRespondFn,I=Date.now(),w=[{label:"Approve",variant:"primary",onClick:()=>{y(m,g,"approve").catch(v=>console.error("[EventManager] approve view request failed:",v))}},{label:"Decline",variant:"danger",onClick:()=>{y(m,g,"reject").catch(v=>console.error("[EventManager] reject view request failed:",v))}}];this.emitToast({id:I,message:l,type:h,timestamp:I,actions:w,duration:3e4}),l=""}Ze("browser")&&!document.hasFocus()&&_t("👁️ View Request",`${p} wants to view your session`,`view-request-${g}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",h="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,h="warning");if(l){const p=Date.now();this.emitToast({id:p,message:l,type:h,timestamp:p,targetKey:r||s.ideId,duration:5e3})}}}const Te=new kr;function We(...t){return on(cn(t))}function Sr({icon:t,title:s,subtitle:n,badge:r,actions:o,className:a}){return e.jsxs("div",{className:We("dashboard-header",a),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})]}),o&&e.jsx("div",{className:"flex gap-2",children:o})]})}function gt({icon:t,title:s,subtitle:n,badge:r,actions:o,widthClassName:a="max-w-6xl",contentClassName:i,children:u}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Sr,{icon:t,title:s,subtitle:n,badge:r,actions:o}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:We("mx-auto flex w-full flex-col gap-4",a,i),children:u})})]})}function de({title:t,icon:s,description:n,accentColor:r,className:o,children:a}){return e.jsxs("div",{className:We("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]",o),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})]}),a]})}function Ot({icon:t,title:s,description:n,action:r,className:o}){return e.jsxs("div",{className:We("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",o),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 Cr={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"},Ir={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function Mr({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:We("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Cr[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:Ir[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 Tr={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"},Er={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Ar({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:We("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Tr[t],n),children:[e.jsx("span",{className:We("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Er[t])}),r]})}function $r(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function ss(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"system"}function It(t){return t==="system"?$r():t}function _r(){const[t,s]=c.useState(ss),[n,r]=c.useState(()=>It(ss()));c.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),c.useEffect(()=>{const i=window.matchMedia("(prefers-color-scheme: light)"),u=l=>{t==="system"&&r(l.matches?"light":"dark")};return i.addEventListener("change",u),()=>i.removeEventListener("change",u)},[t]);const o=c.useCallback(i=>{s(i),r(It(i));try{localStorage.setItem("theme",i)}catch{}},[]),a=c.useCallback(()=>{s(i=>{const u=i==="dark"?"light":i==="light"?"system":"dark";r(It(u));try{localStorage.setItem("theme",u)}catch{}return u})},[]);return{theme:n,preference:t,setPreference:o,cycleTheme:a,isDark:n==="dark"}}function De({label:t,description:s,checked:n,disabled:r,onChange:o,extra:a}){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:[a,e.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:i=>o(i.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function Lr({onPrefChange:t}){const[s,n]=yr(),r=(o,a)=>{n({[o]:a}),t==null||t(o,a)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(De,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Es,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:o=>r("globalEnabled",o)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(De,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_e,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:o=>r("browserNotifications",o)}),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(De,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($n,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:o=>r("completionAlert",o)}),e.jsx(De,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_n,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:o=>r("approvalAlert",o)}),e.jsx(De,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ze,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:o=>r("disconnectAlert",o)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(De,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(He,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:o=>r("chatTaskCompletionBubble",o)}),!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 Pr({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:o}){const a=t.filter(i=>i.type==="adhdev-daemon");return a.length===0?e.jsx(Ot,{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:a.map(i=>e.jsx(Dr,{ide:i,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:o},i.id))})}function ns({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:o,onCancel:a}){const i=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 ln.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:a,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:u=>u.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:a,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:o,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${i}`,children:n})]})]})}),document.body)}function Rr(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...zs,...Fs,...Us].find(o=>o.id===s||s.includes(o.id)||o.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function Dr({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:o}){var M,D;const[a,i]=c.useState("idle"),[u,l]=c.useState(""),[h,d]=c.useState(null),[x,p]=c.useState("idle"),[g,m]=c.useState(""),y=t,I=y.version||y.daemonVersion||null,w=((M=y.machine)==null?void 0:M.platform)||((D=y.system)==null?void 0:D.platform)||"",v=Fe(y,{fallbackId:t.id}),N=w==="win32"?"🪟":w==="darwin"?"🍎":"🐧",L=s.filter(_=>_.daemonId===t.id&&_.transport==="cdp-page"),f=s.filter(_=>_.daemonId===t.id&&_.transport==="pty"),k=s.filter(_=>_.daemonId===t.id&&_.transport==="acp"),S=y.p2p,j=async()=>{var _,R,O;if(n){i("upgrading"),l("Installing latest version...");try{const K=await n(t.id,"daemon_upgrade",{});(_=K==null?void 0:K.result)!=null&&_.upgraded||(R=K==null?void 0:K.result)!=null&&R.success?(i("done"),l(`Upgraded to v${K.result.version||"latest"}. Daemon is restarting...`)):(i("error"),l(((O=K==null?void 0:K.result)==null?void 0:O.error)||"Upgrade failed"))}catch(K){i("error"),l((K==null?void 0:K.message)||"Connection lost during upgrade")}}},P=async()=>{if(d(null),!!r){p("loading");try{await r(t.id),p("done"),m("Machine disconnected.")}catch(_){p("error"),m((_==null?void 0:_.message)||"Failed to disconnect")}}},W=async()=>{if(d(null),!!o){p("loading");try{await o(t.id),p("done"),m('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(_){p("error"),m((_==null?void 0:_.message)||"Failed to revoke token")}}},C="0.7.4",V=!I||I!==C,A=L.length+f.length+k.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:N}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:v}),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),"…"]}),I&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${V?"bg-amber-500/15 text-amber-400":"bg-bg-secondary"}`,children:["v",I,!V&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&V&&e.jsx("button",{onClick:j,disabled:a==="upgrading"||a==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${C}`,children:a==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):a==="done"?"✓ Updated":`↑ Update${` to v${C}`}`}),r&&e.jsx("button",{onClick:()=>d("disconnect"),disabled:x==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),o&&e.jsx("button",{onClick:()=>d("revoke"),disabled:x==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Ar,{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&&A>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),A>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[L.map(_=>{const R=Rr(_.type),O=_.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:R.icon}),e.jsx("span",{children:R.name}),O!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${O?"bg-green-400":"bg-amber-400 animate-pulse"}`,title:O?"CDP connected":"CDP connecting..."})]},_.id)}),f.map(_=>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:_.cliName||"CLI"})]},_.id)),k.map(_=>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:_.cliName||"ACP"})]},_.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(u||g)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${a==="error"||x==="error"?"text-red-400":a==="done"||x==="done"?"text-green-400":"text-text-muted"}`,children:g||u})]}),h==="disconnect"&&e.jsx(ns,{title:"🔌 Disconnect Machine",message:`Disconnect "${v}" 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:P,onCancel:()=>d(null)}),h==="revoke"&&e.jsx(ns,{title:"⚠️ Remove Machine",message:`Remove "${v}" 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:W,onCancel:()=>d(null)})]})}const Br=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function Wr(){const{preference:t,setPreference:s}=_r();return e.jsx("div",{className:"flex gap-2",children:Br.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 Lt={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},Pt={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},Or=[{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",Xs="adhdev-chat-theme-custom";function pt(){return typeof window>"u"?"midnight":localStorage.getItem(qs)||"midnight"}function ye(t){try{const s=localStorage.getItem(Xs);if(s){const n=JSON.parse(s);return{...t==="dark"?Lt:Pt,...n[t]}}}catch{}return t==="dark"?Lt:Pt}function it(t,s){localStorage.setItem(Xs,JSON.stringify({dark:t,light:s}))}function Se(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${o}, ${s})`}function rs(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),o=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${o.toString(16).padStart(2,"0")}`}function Be(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Se(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Se(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Se(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",Se(t.borderSubtle,.5)),s.style.setProperty("--border-default",Se(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",rs(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${rs(t.accentColor,40)})`),s.style.setProperty("--border-accent",Se(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Se(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Se(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 ${Se(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 Kr(){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 Hr(t){if(localStorage.setItem(qs,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Qe()?"dark":"light";Be(ye(s))}else Kr()}function zr(){const t=pt();if(t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=Qe()?"dark":"light";Be(ye(s))}}function Qe(){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 Xe({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 Fr({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,o]=c.useState(()=>ye(n));c.useEffect(()=>{o(ye(n))},[n]);const a=c.useCallback((i,u)=>{o(l=>{const h={...l,[i]:u},x=ye(n==="dark"?"light":"dark");return n==="dark"?it(h,x):it(x,h),Be(h),s(h),h})},[n,s]);return e.jsxs("div",{style:{marginTop:12,padding:"16px 18px",background:"var(--bg-glass)",border:"1px solid var(--border-subtle)",borderRadius:12},children:[e.jsxs("div",{style:{fontSize:"0.75rem",fontWeight:700,color:"var(--text-primary)",marginBottom:14,display:"flex",alignItems:"center",gap:8},children:["🎨 Custom Theme Editor",e.jsxs("span",{style:{fontSize:"0.65rem",fontWeight:500,color:"var(--text-muted)",background:"var(--bg-glass)",padding:"2px 8px",borderRadius:4},children:[t?"🌙 Dark":"☀️ Light"," mode"]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsxs("div",{children:[e.jsxs(Xe,{title:"App Background",children:[e.jsx(le,{label:"Background",value:r.bgPrimary,onChange:i=>a("bgPrimary",i)}),e.jsx(le,{label:"Surface",value:r.bgSecondary,onChange:i=>a("bgSecondary",i)}),e.jsx(le,{label:"Card",value:r.surfacePrimary,onChange:i=>a("surfacePrimary",i)})]}),e.jsxs(Xe,{title:"App Text",children:[e.jsx(le,{label:"Primary",value:r.textPrimary,onChange:i=>a("textPrimary",i)}),e.jsx(le,{label:"Secondary",value:r.textSecondary,onChange:i=>a("textSecondary",i)}),e.jsx(le,{label:"Muted",value:r.textMuted,onChange:i=>a("textMuted",i)})]}),e.jsxs(Xe,{title:"Borders & Accent",children:[e.jsx(le,{label:"Border subtle",value:r.borderSubtle,onChange:i=>a("borderSubtle",i)}),e.jsx(le,{label:"Border default",value:r.borderDefault,onChange:i=>a("borderDefault",i)}),e.jsx(le,{label:"Accent",value:r.accentColor,onChange:i=>a("accentColor",i)})]})]}),e.jsxs("div",{children:[e.jsxs(Xe,{title:"Chat Bubbles",children:[e.jsx(le,{label:"User bubble",value:r.userBubble,onChange:i=>a("userBubble",i)}),e.jsx(le,{label:"User text",value:r.userText,onChange:i=>a("userText",i)}),e.jsx(le,{label:"Agent bubble",value:r.assistantBubble,onChange:i=>a("assistantBubble",i)}),e.jsx(le,{label:"Agent text",value:r.assistantText,onChange:i=>a("assistantText",i)})]}),e.jsxs(Xe,{title:"Chat Layout",children:[e.jsx(le,{label:"Chat BG",value:r.containerBg,onChange:i=>a("containerBg",i)}),e.jsx(le,{label:"Send button",value:r.sendButton,onChange:i=>a("sendButton",i)}),e.jsx(le,{label:"Input border",value:r.inputBorder,onChange:i=>a("inputBorder",i)}),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:i=>a("bubbleRadius",Number(i.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 i=t?Lt:Pt,l=ye(t?"light":"dark");t?it(i,l):it(l,i),o(i),Be(i),s(i)},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 Ur(){const[t,s]=c.useState(pt),[n,r]=c.useState(!0),[o,a]=c.useState(()=>ye("dark"));c.useEffect(()=>{r(Qe());const l=new MutationObserver(()=>{const x=Qe();r(x),pt()==="custom"&&Be(ye(x?"dark":"light"))});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const h=window.matchMedia("(prefers-color-scheme: dark)"),d=()=>{const x=Qe();r(x),pt()==="custom"&&Be(ye(x?"dark":"light"))};return h.addEventListener("change",d),()=>{l.disconnect(),h.removeEventListener("change",d)}},[]),c.useEffect(()=>{t!=="midnight"&&document.documentElement.setAttribute("data-chat-theme",t),t==="custom"&&Be(ye(n?"dark":"light"))},[]),c.useEffect(()=>{a(ye(n?"dark":"light"))},[n]);const i=l=>{s(l),Hr(l),l==="midnight"&&document.documentElement.removeAttribute("data-chat-theme")},u=[...Or,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText},light:{userBubble:o.userBubble,assistantBubble:o.assistantBubble,assistantBorder:`1px solid ${o.accentColor}22`,containerBg:o.containerBg,textColor:o.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:u.map(l=>{const h=t===l.id,d=n?l.preview.dark:l.preview.light,x=l.id==="honey"?"#1a1a1a":l.id==="custom"?o.userText:"#fff";return e.jsxs("button",{onClick:()=>i(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:h?"var(--bg-glass-hover)":"var(--bg-glass)",border:h?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:h?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:d.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.userBubble,color:x},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:d.assistantBubble,border:d.assistantBorder,color:d.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[h&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(Fr,{dark:n,onColorsChange:l=>a(l)})]})}const Rt="adhdev-accent-color",Vr=[{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"}],st="#8b5cf6";function Yr(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,o=Math.max(s,n,r),a=Math.min(s,n,r);let i=0,u=0;const l=(o+a)/2;if(o!==a){const h=o-a;switch(u=l>.5?h/(2-o-a):h/(o+a),o){case s:i=((n-r)/h+(n<r?6:0))/6;break;case n:i=((r-s)/h+2)/6;break;case r:i=((s-n)/h+4)/6;break}}return{h:Math.round(i*360),s:Math.round(u*100),l:Math.round(l*100)}}function as(t,s){const{h:n,s:r,l:o}=Yr(t),a=Math.min(100,o+s);return`hsl(${n}, ${r}%, ${a}%)`}function ht(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),o=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${o}, ${s})`}function os(){return typeof window>"u"?st:localStorage.getItem(Rt)||st}function qr(t){const s=document.documentElement;s.style.setProperty("--accent-primary",t),s.style.setProperty("--accent-primary-light",as(t,15)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t}, ${as(t,20)})`),s.style.setProperty("--border-accent",ht(t,.4)),s.style.setProperty("--nav-active-bg",ht(t,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t}, 0 0 12px ${ht(t,.06)}`)}function Xr(){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 Gr(t){t===st?(localStorage.removeItem(Rt),Xr()):(localStorage.setItem(Rt,t),qr(t))}function Jr(){const[t,s]=c.useState(os),[n,r]=c.useState("");c.useEffect(()=>{s(os())},[]);const o=a=>{s(a),Gr(a)};return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:12},children:[e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8},children:Vr.map(a=>{const i=t===a.color;return e.jsx("button",{onClick:()=>o(a.color),title:a.name,style:{width:36,height:36,borderRadius:10,background:a.color,border:i?"3px solid var(--text-primary)":"3px solid transparent",cursor:"pointer",position:"relative",transition:"transform 0.15s, border-color 0.15s",transform:i?"scale(1.1)":"scale(1)",boxShadow:i?`0 0 12px ${ht(a.color,.4)}`:"none"},children:i&&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:"✓"})},a.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:a=>o(a.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:a=>{r(a.target.value),/^#[0-9a-fA-F]{6}$/.test(a.target.value)&&o(a.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!==st&&e.jsx("button",{onClick:()=>o(st),style:{fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:5,padding:"3px 8px",cursor:"pointer"},children:"Reset"})]})]})}const Gs="adhdev_hiddenTabs";function Zr(){try{const t=localStorage.getItem(Gs);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function Ge(t){try{localStorage.setItem(Gs,JSON.stringify([...t]))}catch{}}function Qr(){const[t,s]=c.useState(Zr),n=c.useCallback(l=>{s(h=>{const d=new Set(h);return d.has(l)?d.delete(l):d.add(l),Ge(d),d})},[]),r=c.useCallback(l=>{s(h=>{if(h.has(l))return h;const d=new Set(h);return d.add(l),Ge(d),d})},[]),o=c.useCallback(l=>{s(h=>{if(!h.has(l))return h;const d=new Set(h);return d.delete(l),Ge(d),d})},[]),a=c.useCallback((l,h)=>{s(d=>{const x=new Set(d);for(const p of h)x.add(p);return Ge(x),x})},[]),i=c.useCallback((l,h)=>{s(d=>{const x=new Set(d);for(const p of h)x.delete(p);return Ge(x),x})},[]),u=c.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:o,hideAllForDaemon:a,showAllForDaemon:i,isHidden:u}}function Js({conversations:t,visibleConversations:s,clearedTabs:n,setClearedTabs:r,setMessageReceivedAt:o,setActionLogs:a}){const i=c.useRef(new Map);c.useEffect(()=>{vr()},[]);const u=c.useMemo(()=>s.map(l=>({id:l.tabKey,name:l.title||l.agentName||l.ideId,status:l.status,activeModal:l.modalMessage?{message:l.modalMessage,buttons:l.modalButtons}:null})),[s]);return Nr(u),c.useEffect(()=>{o(l=>{var p;const h=Date.now();let d=!1;const x={...l};for(const g of t)(p=g.messages)!=null&&p.length&&g.messages.forEach((m,y)=>{const I=`${g.ideId}-${m.id??`i-${y}`}`;x[I]==null&&(x[I]=h,d=!0)});return d?x:l})},[t,o]),c.useEffect(()=>{if(Object.keys(n).length===0)return;const h=setTimeout(()=>{r(d=>{const x=Date.now(),p={};for(const[g,m]of Object.entries(d))x-m<5e3&&(p[g]=m);return Object.keys(p).length===Object.keys(d).length?d:p})},5500);return()=>clearTimeout(h)},[n,r]),c.useEffect(()=>{const l=setInterval(()=>{const h=Date.now()-3e5;a(d=>{const x=d.filter(p=>p.timestamp>h).slice(-100);return x.length===d.length?d:x})},6e4);return()=>clearInterval(l)},[a]),c.useEffect(()=>{const l=(d,x)=>{if(x){Rs.emit(d,x);for(const p of t){if(!ge(p)||!(d===p.sessionId||d===p.ideId||d===p.tabKey))continue;const m=i.current.get(p.tabKey)||[];m.push(x),m.length>1e4&&m.splice(0,m.length-5e3),i.current.set(p.tabKey,m)}}},h=Me.onPtyOutput(l);return()=>{h()}},[t]),{ptyBuffers:i}}function ea(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const o=n.get(r.id);if(!o){n.set(r.id,r);continue}const a=(o.workspace?1:0)+(o.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>a||(r.timestamp||0)>(o.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function ta(t,s){const n=Date.now();return t.map(r=>{const o=s[r.tabKey];return o&&n-o<5e3?{...r,messages:[],title:""}:r})}function sa({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:o}){const a=c.useMemo(()=>ea(t),[t]),i=c.useMemo(()=>{const d=Ks(a,n,t,s);return ta(d,r)},[a,n,t,s,r]),u=c.useCallback(d=>{if(d)return i.find(x=>x.sessionId===d||x.ideId===d||x.tabKey===d||x.ideType===d||x.agentType===d)},[i]),l=c.useMemo(()=>i.filter(d=>!o.has(d.tabKey)),[i,o]),h=c.useMemo(()=>l.map(d=>d.tabKey),[l]);return{chatIdes:a,conversations:i,visibleConversations:l,visibleTabKeys:h,resolveConversationByTarget:u}}function Zs({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:o}){c.useEffect(()=>{Te.setIdes(t)},[t]),c.useEffect(()=>{Te.setResolveAction((a,i,u)=>{s(a,i,u).catch(()=>{})})},[s]),c.useEffect(()=>{const a=Te.onToast(l=>{n(d=>d.some(p=>p.message===l.message&&l.timestamp-p.timestamp<3e3)?d:[...d.slice(-4),{id:l.id,message:l.message,type:l.type,timestamp:l.timestamp,targetKey:l.targetKey,actions:l.actions}]);const h=l.duration||5e3;setTimeout(()=>n(d=>d.filter(x=>x.id!==l.id)),h)}),i=Te.onSystemMessage((l,h)=>{r(d=>({...d,[l]:[...d[l]||[],h]}))}),u=Te.onClearSystemMessage((l,h)=>{r(d=>{var x;return(x=d[l])!=null&&x.length?{...d,[l]:d[l].filter(p=>{var g;return!(p.role==="system"&&((g=p._localId)!=null&&g.startsWith(h)))})}:d})});return()=>{a(),i(),u()}},[n,r]),c.useEffect(()=>{const a=Bs.on("status_event",i=>Te.handleRawEvent(i,"ws"));return()=>{a()}},[]),c.useEffect(()=>{var i;const a=u=>{const l=u.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const h=l.targetSessionId||l.targetKey||l.ideId,d=o(h),x=(d==null?void 0:d.ideId)||l.ideId;x&&s(x,"resolve_action",{action:"approve",button:"Approve",...(d==null?void 0:d.sessionId)&&{targetSessionId:d.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(p=>console.error("[SW Action] approve failed:",p))};return(i=navigator.serviceWorker)==null||i.addEventListener("message",a),()=>{var u;return(u=navigator.serviceWorker)==null?void 0:u.removeEventListener("message",a)}},[o,s])}const ve={splitGroups:"adhdev_splitGroups",focusedGroup:"adhdev_focusedGroup",groupActiveTabs:"adhdev_groupActiveTabs",groupTabOrders:"adhdev_groupTabOrders",splitSizes:"adhdev_splitSizes"};function ct(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function Je(t,s){try{s==null?localStorage.removeItem(t):localStorage.setItem(t,s)}catch{}}function na(){const[t,s]=c.useState(()=>{const p=ct(ve.splitGroups,[]);return new Map(p)}),[n,r]=c.useState(()=>{try{const p=localStorage.getItem(ve.focusedGroup);if(p)return parseInt(p,10)||0}catch{}return 0}),[o,a]=c.useState(()=>ct(ve.groupActiveTabs,{})),[i,u]=c.useState(()=>ct(ve.groupTabOrders,{})),[l,h]=c.useState(()=>ct(ve.splitSizes,[])),[d,x]=c.useState(()=>typeof window<"u"&&window.innerWidth<768);return c.useEffect(()=>{Je(ve.splitGroups,t.size===0?null:JSON.stringify([...t.entries()]))},[t]),c.useEffect(()=>{Je(ve.splitSizes,l.length>0?JSON.stringify(l):null)},[l]),c.useEffect(()=>{Je(ve.focusedGroup,String(n))},[n]),c.useEffect(()=>{Je(ve.groupActiveTabs,JSON.stringify(o))},[o]),c.useEffect(()=>{Je(ve.groupTabOrders,JSON.stringify(i))},[i]),c.useEffect(()=>{const p=window.matchMedia("(max-width: 767px)"),g=m=>x(m.matches);return p.addEventListener("change",g),()=>p.removeEventListener("change",g)},[]),{groupAssignments:t,setGroupAssignments:s,focusedGroup:n,setFocusedGroup:r,groupActiveTabIds:o,setGroupActiveTabIds:a,groupTabOrders:i,setGroupTabOrders:u,groupSizes:l,setGroupSizes:h,isMobile:d}}function ra({urlActiveTab:t,conversations:s,resolveConversationByTarget:n,normalizedGroupAssignments:r,setGroupActiveTabIds:o,setFocusedGroup:a,setSearchParams:i,historyModalOpen:u,activeConv:l,isRefreshingHistory:h,ides:d,handleRefreshHistory:x,isSplitMode:p,splitTabRelative:g,numGroups:m,clearAllSplits:y}){const I=c.useRef(!1),w=c.useRef(!1);c.useEffect(()=>{if(!t||I.current||s.length===0)return;const v=n(t);if(!v)return;const N=r.get(v.tabKey)??0;o(L=>({...L,[N]:v.tabKey})),a(N),I.current=!0,i(L=>{const f=new URLSearchParams(L);return f.delete("activeTab"),f},{replace:!0})},[t,s,n,r,o,a,i]),c.useEffect(()=>{if(!u){w.current=!1;return}if(!l||w.current||h)return;const v=d.find(N=>N.id===l.ideId);v&&(!v.chats||v.chats.length===0)&&(w.current=!0,x())},[u,l,h,d,x]),c.useEffect(()=>{const v=N=>{if(N.ctrlKey&&N.key==="\\"){if(N.preventDefault(),p)y();else{const L=s[1];L&&g(L.tabKey,0,"right")}return}N.ctrlKey&&(N.key==="["||N.key==="]")&&p&&(N.preventDefault(),a(L=>N.key==="]"?Math.min(L+1,m-1):Math.max(L-1,0)))};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[p,s,g,m,y,a])}function Ie(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return ge(t)||he(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function bt(t){return t&&(t.ideId||t.daemonId)||""}function lt(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function aa({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:o,setClearedTabs:a}){const[i,u]=c.useState(!1),[l,h]=c.useState(!1),d=c.useCallback(async m=>{try{await t("standalone","launch_ide",{ideType:m,enableCdp:!0})}catch(y){console.error("Launch failed",y)}},[t]),x=c.useCallback(async(m,y)=>{try{const I=m||(s==null?void 0:s.daemonId)||"",w=await t(I,"switch_chat",{id:y,sessionId:y,...Ie(s)}),v=w==null?void 0:w.result;if((w==null?void 0:w.success)===!0||v==="switched"||v==="switched-by-title")return;v===!1||v==="not_found"?lt(r,"⚠️ Session tab not found — try refreshing history"):typeof v=="string"&&v.startsWith("error:")?lt(r,`⚠️ Switch error: ${v}`):lt(r,"⚠️ Session switch failed")}catch(I){console.error("Switch failed",I),lt(r,`❌ Switch failed: ${I.message||"connection error"}`)}},[s,t,r]),p=c.useCallback(async()=>{if(!(!s||i)){u(!0);try{const m=bt(s);await t(m,"new_chat",{...Ie(s)}),a(y=>({...y,[s.tabKey]:Date.now()})),o(y=>({...y,[s.tabKey]:[]}))}catch(m){console.error("New chat failed",m)}finally{u(!1)}}},[s,i,t,a,o]),g=c.useCallback(async()=>{var m;if(!(!s||l)){h(!0);try{const y=bt(s),I=await t(y,"list_chats",{forceExpand:!0,...Ie(s)}),w=(I==null?void 0:I.chats)||((m=I==null?void 0:I.result)==null?void 0:m.chats);I!=null&&I.success&&Array.isArray(w)&&n(s.ideId,w)}catch(y){console.error("Refresh history failed",y)}finally{h(!1)}}},[s,l,t,n]);return{isCreatingChat:i,isRefreshingHistory:l,handleLaunchIde:d,handleSwitchSession:x,handleNewChat:p,handleRefreshHistory:g}}function oa(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 ia(t,s){return t.length!==s.length?!1:t.every((n,r)=>n===s[r])}function is(t,s){const n=Object.keys(t),r=Object.keys(s);return n.length!==r.length?!1:n.every(o=>s[Number(o)]===t[Number(o)])}function dt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[i,u]of t)!n.has(i)||u<=0||r.includes(u)||r.push(u);r.sort((i,u)=>i-u);const o={};r.forEach((i,u)=>{o[i]=u}),r.length===0&&(o[0]=0);const a=new Map;for(const[i,u]of t){if(!n.has(i)||u<=0)continue;const l=o[u];typeof l=="number"&&l>0&&a.set(i,l)}return{assignments:a,groupCount:Math.max(1,r.length),mapping:o,usedGroups:r}}function cs(t,s){const n={};for(const[r,o]of Object.entries(t)){const a=s[Number(r)];typeof a=="number"&&(n[a]=o)}return n}function ca(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(o=>o<t)??s[0];return n[r]??0}function la(t,s,n){if(s.length<=1)return[];const r=s.map(i=>t[i]).filter(i=>Number.isFinite(i)),o=r.length===s.length?r:Array(n).fill(100/n),a=o.reduce((i,u)=>i+u,0);return a>0?o.map(i=>i/a*100):Array(n).fill(100/n)}function ls(t,s){const n={};for(const[r,o]of Object.entries(t)){const a=Number(r);n[a>=s?a+1:a]=o}return n}function ds(t){return Array(t).fill(100/t)}function da({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:o,groupSizes:a,setGroupSizes:i,isMobile:u,visibleConversations:l,visibleTabKeys:h}){const d=c.useRef(null),x=c.useMemo(()=>dt(t,h),[t,h]),p=x.assignments,g=c.useMemo(()=>u?1:x.groupCount,[x.groupCount,u]),m=g>1,y=c.useCallback((f,k)=>{s(S=>{const j=new Map(dt(S,h).assignments);return k===0?j.delete(f):j.set(f,k),j}),r(S=>({...S,[k]:f})),n(k)},[s,h,r,n]),I=c.useCallback(f=>{s(k=>{const S=dt(k,h).assignments,j=new Map;for(const[P,W]of S)W!==f&&(W>f?j.set(P,W-1):j.set(P,W));return j}),i(k=>{if(k.length<=1)return[];const S=[...k];S.splice(f,1);const j=S.reduce((P,W)=>P+W,0);return j>0?S.map(P=>P/j*100):[]}),n(0)},[s,h,i,n]),w=c.useCallback((f,k)=>{k.preventDefault();const S=d.current;if(!S)return;const j=k.clientX,P=S.offsetWidth,W=a.length===g?[...a]:ds(g),C=A=>{const D=(A.clientX-j)/P*100,_=[...W];_[f]=Math.max(15,W[f]+D),_[f+1]=Math.max(15,W[f+1]-D),i(_)},V=()=>{document.removeEventListener("mousemove",C),document.removeEventListener("mouseup",V),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",C),document.addEventListener("mouseup",V)},[a,g,i]),v=c.useCallback((f,k,S)=>{if(g>=4)return;const j=S==="left"?k:k+1;s(P=>{const W=dt(P,h).assignments,C=new Map;for(const V of l){const A=W.get(V.tabKey)??0,M=A>=j?A+1:A;M>0&&C.set(V.tabKey,M)}return j>0&&C.set(f,j),C}),i(P=>{const W=P.length===g?[...P]:ds(g),C=W[k]??100/g,V=Math.max(15,C/2),A=Math.max(15,C/2),M=[...W];M[k]=V,M.splice(j,0,A);const D=M.reduce((_,R)=>_+R,0);return M.map(_=>_/D*100)}),r(P=>{const W=ls(P,j);return W[j]=f,W}),o(P=>{const W=ls(P,j);return W[j]=[f],W}),n(j)},[g,s,h,l,i,r,o,n]);c.useEffect(()=>{oa(t,p)||s(p)},[t,p,s]),c.useEffect(()=>{const{mapping:f,usedGroups:k}=x;r(S=>{const j=cs(S,f);return is(S,j)?S:j}),o(S=>{const j=cs(S,f);return is(S,j)?S:j}),n(S=>{const j=u?0:ca(S,k,f);return S===j?S:j}),i(S=>{const j=u?[]:la(S,k,x.groupCount);return ia(S,j)?S:j})},[x,u,r,o,n,i]);const N=c.useMemo(()=>{const f=Array.from({length:g},()=>[]);for(const k of l){const S=p.get(k.tabKey)??0,j=Math.min(S,g-1);f[j].push(k)}return f},[l,p,g]),L=c.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:d,normalizedGroupAssignments:p,numGroups:g,isSplitMode:m,groupedConvs:N,moveTabToGroup:y,closeGroup:I,handleResizeStart:w,splitTabRelative:v,clearAllSplits:L}}function ua({ides:t,sendDaemonCommand:s}){const n=c.useMemo(()=>t.filter(l=>l.type==="adhdev-daemon"&&l.versionMismatch),[t]),[r,o]=c.useState(!1),[a,i]=c.useState({}),u=c.useCallback(async l=>{var h,d;i(x=>({...x,[l]:"upgrading"}));try{const x=await s(l,"daemon_upgrade",{});(h=x==null?void 0:x.result)!=null&&h.upgraded||(d=x==null?void 0:x.result)!=null&&d.success?i(p=>({...p,[l]:"done"})):i(p=>({...p,[l]:"error"}))}catch{i(x=>({...x,[l]:"error"}))}},[s]);return{versionMismatchDaemons:n,versionBannerDismissed:r,setVersionBannerDismissed:o,upgradingDaemons:a,handleBannerUpgrade:u}}function Qs({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:o}){const[a,i]=c.useState(!1),[u,l]=c.useState(!1),h=c.useRef(!1),d=c.useCallback(async m=>{if(!s)return;const y=m.trim();if(!y||h.current)return;const I=s.tabKey;h.current=!0,l(!0);const w=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,v={role:"user",content:y,timestamp:Date.now(),_localId:w};n(N=>({...N,[I]:[...N[I]||[],v]}));try{const N=bt(s);if(!N)return;await t(N,"send_chat",{message:y,text:y,...Ie(s)}),setTimeout(()=>{const L=Date.now()-6e4;n(f=>{const k=f[I];if(!k)return f;const S=k.filter(j=>j.timestamp>L);return S.length===k.length?f:{...f,[I]:S}})},6e4)}catch(N){console.error("Send failed",N),n(L=>({...L,[I]:(L[I]||[]).filter(f=>f._localId!==w)}))}finally{h.current=!1,l(!1)}},[s,t,n]),x=c.useCallback(async()=>{if(s)try{if(o){await t(s.ideId,"launch_ide",{ideType:s.ideType,enableCdp:!0});return}await t(s.ideId,"vscode_command_exec",{commandId:"adhdev.relaunchWithCdp",args:[{force:!0}]})}catch(m){console.error("Relaunch failed",m)}},[s,o,t]),p=c.useCallback(async m=>{if(s){r(y=>[...y,{ideId:s.tabKey,text:`🖱️ **${m}** clicked`,timestamp:Date.now()}]);try{const I=(s.modalButtons||[]).indexOf(m),w=m.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),v=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(w),N=bt(s);if(!N)return;(await t(N,"resolve_action",{button:m,action:v?"approve":"reject",...I>=0&&{buttonIndex:I},...Ie(s)})).success||r(f=>[...f,{ideId:s.tabKey,text:`⚠️ **${m}** failed — button not found`,timestamp:Date.now()}])}catch(y){console.error("[ModalButton] Error:",y),r(I=>[...I,{ideId:s.tabKey,text:`❌ **${m}** error`,timestamp:Date.now()}])}}},[s,t,r]),g=c.useCallback(async()=>{if(!(!s||a)){i(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(m){console.error("Focus agent failed",m)}finally{i(!1)}}},[s,a,t]);return{isSendingChat:u,isFocusingAgent:a,handleSendChat:d,handleRelaunch:x,handleModalButton:p,handleFocusAgent:g}}function Mt(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function xa({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:o,onClearPreviewOrder:a}){const i=c.useRef(0),[u,l]=c.useState(!1),[h,d]=c.useState(null),x=c.useCallback(()=>{i.current=0,l(!1),d(null)},[]);c.useEffect(()=>(window.addEventListener("dragend",x),window.addEventListener("drop",x),()=>{window.removeEventListener("dragend",x),window.removeEventListener("drop",x)}),[x]);const p=c.useCallback(I=>{I.dataTransfer.types.includes("text/tab-key")&&(i.current+=1,l(!0))},[]),g=c.useCallback(I=>{if(!I.dataTransfer.types.includes("text/tab-key"))return;if(I.preventDefault(),!Mt(s,n)){d("merge");return}const w=I.currentTarget.getBoundingClientRect(),v=I.clientX-w.left,N=w.width/3;v<N?d("split-left"):v>N*2?d("split-right"):d("merge")},[s,n]),m=c.useCallback(()=>{i.current-=1,!(i.current>0)&&(i.current=0,l(!1),d(null))},[]),y=c.useCallback(I=>{i.current=0,l(!1);const w=I.dataTransfer.getData("text/tab-key"),v=w?t.some(L=>L.tabKey===w):!1,N=h;if(d(null),a(),!!w){if(I.preventDefault(),N==="split-left"&&Mt(s,n)){n==null||n(w,"split-left");return}if(N==="split-right"&&Mt(s,n)){n==null||n(w,"split-right");return}if(v){o(w);return}r==null||r(w)}},[t,h,s,n,r,o,a]);return{dragOver:u,dropAction:h,resetDragState:x,handleDragEnter:p,handleDragOver:g,handleDragLeave:m,handleDrop:y}}function pa(t,s){const n=new Set(s.map(a=>a.tabKey)),r=t.filter(a=>n.has(a)),o=s.filter(a=>!t.includes(a.tabKey)).map(a=>a.tabKey);return[...r,...o]}function ha({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:o}){const[a,i]=c.useState(s??null),[u,l]=c.useState(n??[]),[h,d]=c.useState(null),x=c.useRef(null),p=c.useRef(null);c.useEffect(()=>{s&&s!==a&&i(s)},[s,a]),c.useEffect(()=>{l(f=>{const k=pa(f,t);return k.length===f.length&&k.every((S,j)=>S===f[j])?f:k})},[t]);const g=c.useMemo(()=>{const f=h??u;if(f.length===0)return t;const k=new Map(f.map((S,j)=>[S,j]));return[...t].sort((S,j)=>{const P=k.get(S.tabKey)??999,W=k.get(j.tabKey)??999;return P-W})},[t,h,u]);c.useEffect(()=>{if(g.length===0){i(null),r==null||r(null);return}if(a&&g.some(k=>k.tabKey===a))return;const f=g[0].tabKey;i(f),r==null||r(f)},[g,a,r]);const m=c.useMemo(()=>g.find(f=>f.tabKey===a),[g,a]),y=c.useCallback(f=>{i(f),r==null||r(f)},[r]),I=c.useCallback((f,k,S)=>{l(j=>{const P=j.filter(V=>V!==f),W=P.indexOf(k);if(W<0)return j;const C=S==="left"?W:W+1;return P.splice(C,0,f),o==null||o(P),P}),d(null)},[o]),w=c.useCallback((f,k,S)=>{const P=(u.length>0?u:t.map(V=>V.tabKey)).filter(V=>V!==f),W=P.indexOf(k);if(W<0)return;const C=S==="left"?W:W+1;P.splice(C,0,f),x.current=P,d(P)},[u,t]),v=c.useCallback(()=>{const f=x.current;f&&(l(f),o==null||o(f))},[o]),N=c.useCallback(()=>{x.current=null,d(null)},[]),L=c.useCallback(f=>{l(k=>{const S=k.filter(j=>j!==f);return S.push(f),o==null||o(S),S})},[o]);return{activeTabId:a,activeConv:m,sortedConversations:g,previewOrderRef:x,draggingTabRef:p,selectTab:y,handleTabReorder:I,updatePreviewOrder:w,commitPreviewOrder:v,clearPreviewOrder:N,moveTabToEnd:L,setDraggingTabKey:f=>{p.current=f}}}function ma({activeConv:t,isCli:s,ides:n,screenshotMap:r,setScreenshotMap:o,ptyBuffers:a,terminalRef:i,handleModalButton:u,handleRelaunch:l,handleSendChat:h,isSendingChat:d,handleFocusAgent:x,isFocusingAgent:p,messageReceivedAt:g,actionLogs:m,userName:y}){return e.jsxs(e.Fragment,{children:[e.jsx($s,{activeConv:t,onModalButton:u}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!s&&t.transport!=="acp"&&r[t.ideId]?e.jsx(Un,{screenshotUrl:r[t.ideId],mode:"preview",onDismiss:()=>{const I={...r};delete I[t.ideId],o(I)}}):!s&&t.transport!=="acp"&&t.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(Bt,{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:l,children:"Relaunch with CDP"})]}):null}),s?e.jsx(sr,{activeConv:t,ptyBuffers:a,terminalRef:i,handleSendChat:h,isSendingChat:d}):e.jsx(Ps,{activeConv:t,ides:n,handleSendChat:h,isSendingChat:d,handleFocusAgent:x,isFocusingAgent:p,messageReceivedAt:g,actionLogs:m,userName:y})]})}function fa({dropAction:t,canSplit:s}){return 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:t==="split-left"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-left"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?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:t==="merge"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="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:t==="split-right"?"rgba(255,255,255,0.1)":"rgba(255,255,255,0.04)",boxShadow:t==="split-right"?"inset 0 0 0 2px var(--accent-primary)":"inset 0 0 0 1px rgba(255,255,255,0.05)",opacity:s?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"})})]})}const Tt={unix:{cmd:"curl -fsSL https://adhf.dev/install | sh",shell:"Terminal",prompt:"$ "},powershell:{cmd:"irm https://adhf.dev/install.ps1 | iex",shell:"PowerShell",prompt:"PS> "},cmd:{cmd:"curl -fsSL https://adhf.dev/install.cmd -o %TEMP%\\adhdev.cmd && %TEMP%\\adhdev.cmd",shell:"CMD",prompt:"> "}};function ga(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function ba(){const[t,s]=c.useState("unix"),[n,r]=c.useState("powershell"),[o,a]=c.useState(!1),i=t==="unix"?"unix":n;c.useEffect(()=>{s(ga())},[]);const u=c.useCallback(()=>{navigator.clipboard.writeText(Tt[i].cmd).catch(()=>{}),a(!0),setTimeout(()=>a(!1),2e3)},[i]);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:u,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Tt[i].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Tt[i].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:o?"✓":"📋"})]}),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 ya({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:o}){return t===0&&!s&&r&&o?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:n?"Launch any supported IDE or CLI agent to start monitoring automatically.":"Install the ADHDev daemon and link your dashboard to start."}),!n&&e.jsx(ba,{}),n&&r.length>0&&e.jsxs("div",{className:"flex flex-col gap-3 items-center",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Fast Launch"}),e.jsx("div",{className:"flex flex-wrap gap-2.5 justify-center mt-1",children:r.map(a=>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:()=>o(a.type),children:[e.jsx(Ms,{size:14,className:"opacity-70"})," Launch ",a.name]},a.type))})]}),!n&&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:s?"Move a tab here to view":"No active agent"})}const en="adhdev-tab-shortcuts";function ja(){try{return JSON.parse(localStorage.getItem(en)||"{}")}catch{return{}}}function va({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[o,a]=c.useState(()=>ja()),[i,u]=c.useState(null),l=c.useCallback(d=>{const x=[];return d.metaKey&&x.push(r?"⌘":"Meta"),d.ctrlKey&&x.push("Ctrl"),d.altKey&&x.push(r?"⌥":"Alt"),d.shiftKey&&x.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(d.key)?null:(x.push(d.key.length===1?d.key.toUpperCase():d.key),x.join("+"))},[r]),h=c.useCallback(d=>{a(d);try{localStorage.setItem(en,JSON.stringify(d))}catch{}},[]);return c.useEffect(()=>{if(!i)return;const d=x=>{if(x.preventDefault(),x.stopPropagation(),x.key==="Escape"){u(null);return}const p=l(x);if(!p)return;const g={...o};for(const[m,y]of Object.entries(g))y===p&&delete g[m];g[i]=p,h(g),u(null)};return window.addEventListener("keydown",d,!0),()=>window.removeEventListener("keydown",d,!0)},[i,o,h,l]),c.useEffect(()=>{const d=x=>{if(!(!x.ctrlKey&&!x.metaKey&&!x.altKey)){for(const[p,g]of Object.entries(o))if(t.includes(p)&&l(x)===g){x.preventDefault(),s(),n(p);return}}};return window.addEventListener("keydown",d),()=>window.removeEventListener("keydown",d)},[o,t,s,n,l]),{isMac:r,tabShortcuts:o,shortcutListening:i,setShortcutListening:u,saveShortcuts:h}}function wa({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,draggingTabRef:o,previewOrderRef:a,onFocus:i,onSelectTab:u,onConversationActivated:l,onPreviewReorder:h,onReorderTab:d,onCommitPreviewOrder:x,onClearPreviewOrder:p,onDragStateReset:g,onDragTabKeyChange:m,onMoveTab:y,onReceiveTab:I,onHideTab:w}){const[v,N]=c.useState(null),L=c.useRef(null),f=c.useRef(null);rt("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(v==null?void 0:v.tabKey)||null});const{isMac:k,tabShortcuts:S,shortcutListening:j,setShortcutListening:P,saveShortcuts:W}=va({sortedTabKeys:t.map(C=>C.tabKey),onFocus:i,onSelectTab:u});return c.useEffect(()=>{if(!v)return;const C=V=>{const A=document.querySelector("[data-pane-context-menu]");A&&A.contains(V.target)||N(null)};return window.addEventListener("mousedown",C,!0),()=>window.removeEventListener("mousedown",C,!0)},[v]),c.useEffect(()=>{const C=f.current;if(!C)return;const V=A=>{Math.abs(A.deltaY)>Math.abs(A.deltaX)&&(A.preventDefault(),C.scrollLeft+=A.deltaY)};return C.addEventListener("wheel",V,{passive:!1}),()=>C.removeEventListener("wheel",V)},[]),e.jsxs(e.Fragment,{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:f,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:[t.map(C=>{const V=s===C.tabKey,A=C.status==="generating"?"agent-tab-generating":C.status==="waiting_approval"?"agent-tab-waiting":"",M=C.connectionState==="failed"||C.connectionState==="closed",D=o.current===C.tabKey;return e.jsxs("div",{"data-tabkey":C.tabKey,className:`${A} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:_=>{o.current=C.tabKey,m(C.tabKey),_.dataTransfer.setData("text/tab-key",C.tabKey),_.dataTransfer.effectAllowed="move"},onDragEnd:()=>{o.current=null,m(null),x(),a.current=null,p(),g()},onDragOver:_=>{const R=o.current;if(!(!R||R===C.tabKey)&&_.dataTransfer.types.includes("text/tab-key")){_.preventDefault(),_.stopPropagation();const O=_.currentTarget.getBoundingClientRect(),K=_.clientX<O.left+O.width/2?"left":"right";h(R,C.tabKey,K)}},onDrop:_=>{_.preventDefault(),_.stopPropagation();const R=_.dataTransfer.getData("text/tab-key");if(R&&R!==C.tabKey){const O=_.currentTarget.getBoundingClientRect(),K=_.clientX<O.left+O.width/2?"left":"right";t.some(Y=>Y.tabKey===R)?d(R,C.tabKey,K):I&&I(R)}p()},onClick:_=>{_.stopPropagation(),i(),u(C.tabKey),l(C)},onContextMenu:_=>{_.preventDefault(),N({x:_.clientX,y:_.clientY,tabKey:C.tabKey})},onTouchStart:_=>{const R=_.touches[0];L.current=setTimeout(()=>{N({x:R.clientX,y:R.clientY,tabKey:C.tabKey})},600)},onTouchEnd:()=>{L.current&&clearTimeout(L.current)},onTouchMove:()=>{L.current&&clearTimeout(L.current)},style:{background:V?"var(--bg-primary)":"var(--bg-glass)",borderTop:V?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:V?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:V?"1px solid var(--border-subtle)":"1px solid transparent",opacity:D?.4:M?V?.6:.3:V?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:"▲"}):M?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:M?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]})]})]})})]}),S[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+${S[C.tabKey]}`,children:S[C.tabKey]})]},C.tabKey)}),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),v&&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:v.x,top:v.y},children:[y&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{y(v.tabKey,"left"),N(null)},children:"← Move to Left Group"}),y&&n<r-1&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{y(v.tabKey,"right"),N(null)},children:"Move to Right Group →"}),y&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{y(v.tabKey,"split-left"),N(null)},children:"⇤ Split Left"}),y&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{y(v.tabKey,"split-right"),N(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(),P(v.tabKey),N(null)},children:["⌨ ",S[v.tabKey]?`Change shortcut (${S[v.tabKey]})`:"Set shortcut"]}),S[v.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={...S};delete C[v.tabKey],W(C),N(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(v.tabKey),N(null)},children:"🚫 Hide from Dashboard"})]}),!y&&!w&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),j&&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:()=>P(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. ",k?"⌘+1":"Ctrl+1",", ",k?"⌥+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"})]})})]})}function Na({conversations:t,ides:s,messageReceivedAt:n,actionLogs:r,ptyBuffers:o,screenshotMap:a,setScreenshotMap:i,sendDaemonCommand:u,setLocalUserMessages:l,setActionLogs:h,isStandalone:d,userName:x,groupIndex:p,onFocus:g,isSplitMode:m,numGroups:y,onMoveTab:I,onReceiveTab:w,style:v,detectedIdes:N,handleLaunchIde:L,onActiveTabChange:f,initialActiveTabId:k,initialTabOrder:S,onTabOrderChange:j,onHideTab:P}){const{sendCommand:W}=$e(),C=c.useRef(null),{activeTabId:V,activeConv:A,sortedConversations:M,previewOrderRef:D,draggingTabRef:_,selectTab:R,handleTabReorder:O,updatePreviewOrder:K,commitPreviewOrder:Y,clearPreviewOrder:F,moveTabToEnd:J,setDraggingTabKey:ae}=ha({conversations:t,initialActiveTabId:k,initialTabOrder:S,onActiveTabChange:f,onTabOrderChange:j}),Q=Qs({sendDaemonCommand:u,activeConv:A,setLocalUserMessages:l,setActionLogs:h,isStandalone:d}),{dragOver:oe,dropAction:T,resetDragState:b,handleDragEnter:$,handleDragOver:E,handleDragLeave:z,handleDrop:G}=xa({conversations:t,numGroups:y,onMoveTab:I,onReceiveTab:w,onOwnTabDrop:J,onClearPreviewOrder:F}),U=A&&ge(A)&&!he(A);rt("PaneGroup",{groupIndex:p,conversationCount:t.length,activeTabId:V,dragOver:oe});const ee=c.useCallback(X=>{X.streamSource==="agent-stream"&&X.agentType&&W(X.ideId,"focus_session",{agentType:X.agentType,...X.sessionId&&{targetSessionId:X.sessionId}}).catch(()=>{}),ge(X)&&setTimeout(()=>{var Z,ne;return(ne=(Z=C.current)==null?void 0:Z.bumpResize)==null?void 0:ne.call(Z)},100)},[W]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:g,style:{...v,outline:oe?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(wa,{conversations:M,activeTabId:V,groupIndex:p,numGroups:y,draggingTabRef:_,previewOrderRef:D,onFocus:g,onSelectTab:R,onConversationActivated:ee,onPreviewReorder:K,onReorderTab:O,onCommitPreviewOrder:Y,onClearPreviewOrder:F,onDragStateReset:b,onDragTabKeyChange:ae,onMoveTab:I,onReceiveTab:w,onHideTab:P}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:$,onDragOver:E,onDragLeave:z,onDrop:G,children:[oe&&e.jsx(fa,{dropAction:T,canSplit:!!(y<4&&I)}),A?e.jsx(ma,{activeConv:A,isCli:!!U,ides:s,screenshotMap:a,setScreenshotMap:i,ptyBuffers:o,terminalRef:C,handleModalButton:Q.handleModalButton,handleRelaunch:Q.handleRelaunch,handleSendChat:Q.handleSendChat,isSendingChat:Q.isSendingChat,handleFocusAgent:Q.handleFocusAgent,isFocusingAgent:Q.isFocusingAgent,messageReceivedAt:n,actionLogs:r,userName:x}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(ya,{conversationsCount:t.length,isSplitMode:m,isStandalone:d,detectedIdes:N,handleLaunchIde:L})})]})]})}function ka({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:o,ides:a,messageReceivedAt:i,actionLogs:u,ptyBuffers:l,screenshotMap:h,setScreenshotMap:d,sendDaemonCommand:x,setLocalUserMessages:p,setActionLogs:g,isStandalone:m,userName:y,setFocusedGroup:I,moveTabToGroup:w,splitTabRelative:v,closeGroup:N,handleResizeStart:L,detectedIdes:f,handleLaunchIde:k,groupActiveTabIds:S,setGroupActiveTabIds:j,groupTabOrders:P,setGroupTabOrders:W,toggleHiddenTab:C}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:o.map((V,A)=>{const M=s&&r.length===n?`${r[A]}%`:void 0;return e.jsxs(dn.Fragment,{children:[s&&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:D=>L(A-1,D),onDoubleClick:()=>N(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(Na,{style:s?{flexBasis:M??`${100/n}%`,flexGrow:M?0:1,flexShrink:M?0:1}:void 0,conversations:V,ides:a,messageReceivedAt:i,actionLogs:u,ptyBuffers:l,screenshotMap:h,setScreenshotMap:d,sendDaemonCommand:x,setLocalUserMessages:p,setActionLogs:g,isStandalone:m,userName:y,groupIndex:A,onFocus:()=>I(A),isSplitMode:s,numGroups:n,onMoveTab:(D,_)=>{_==="left"&&A>0?w(D,A-1):_==="right"&&A<n-1?w(D,A+1):_==="split-left"&&n<4?v(D,A,"left"):_==="split-right"&&n<4&&v(D,A,"right")},onReceiveTab:D=>w(D,A),detectedIdes:A===0?f:void 0,handleLaunchIde:A===0?k:void 0,onActiveTabChange:D=>j(_=>({..._,[A]:D})),initialActiveTabId:S[A],initialTabOrder:P[A],onTabOrderChange:D=>W(_=>({..._,[A]:D})),onHideTab:C})]},A)})})}function Sa({daemons:t,upgradingDaemons:s,onUpgrade:n,onDismiss:r}){if(t.length===0)return null;const o=t[0];return 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(Ss,{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",o.version]})," → ",e.jsxs("strong",{children:["v",o.serverVersion]})]}),t.map(a=>{const i=Fe(a,{fallbackId:a.id}),u=s[a.id];return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md bg-amber-500/[0.08] border border-amber-500/15",children:[e.jsx("span",{className:"font-medium text-text-primary",children:i}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",a.version]}),u==="upgrading"?e.jsx("span",{className:"text-[10px] text-amber-400 animate-pulse",children:"upgrading…"}):u==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):u==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>n(a.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:()=>n(a.id),children:"Upgrade"})]},a.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:r,title:"Dismiss",children:"✕"})]})}const Et=[{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 Ca({onClose:t}){const[s,n]=c.useState(0),r=Et[s],o=s===Et.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:a=>{a.target===a.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:Et.map((a,i)=>e.jsx("div",{style:{width:i===s?24:8,height:8,borderRadius:4,background:i===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},i))}),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]}),o&&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:()=>o?t():n(a=>a+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:o?"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 Ia(){const{sendCommand:t}=$e(),[s,n]=ms(),r=s.get("activeTab"),o=jt(),{updateIdeChats:a,screenshotMap:i,setScreenshotMap:u}=o,l=o.ides||[],[h,d]=c.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),x=o.toasts||[],p=o.setToasts||(()=>{}),g=o.wsStatus||"connected",m=o.isConnected??!0,y=o.connectionStates||{},I=o.showReconnected||!1,{groupAssignments:w,setGroupAssignments:v,focusedGroup:N,setFocusedGroup:L,groupActiveTabIds:f,setGroupActiveTabIds:k,groupTabOrders:S,setGroupTabOrders:j,groupSizes:P,setGroupSizes:W,isMobile:C}=na(),[V,A]=c.useState({}),[M,D]=c.useState(!1),[_,R]=c.useState([]),[O,K]=c.useState({}),[Y,F]=c.useState({});rt("Dashboard",{ideCount:l.length,toastCount:x.length,focusedGroup:N,groupCount:Object.keys(w).length,localMessageTabs:Object.keys(O).length,actionLogCount:_.length});const J=l.find(pe=>pe.type==="adhdev-daemon"),ae=(J==null?void 0:J.detectedIdes)||[],Q=!!J,{hiddenTabs:oe,toggleTab:T}=Qr(),{chatIdes:b,conversations:$,visibleConversations:E,visibleTabKeys:z,resolveConversationByTarget:G}=sa({ides:l,connectionStates:y,localUserMessages:O,clearedTabs:Y,hiddenTabs:oe}),{containerRef:U,normalizedGroupAssignments:ee,numGroups:X,isSplitMode:Z,groupedConvs:ne,moveTabToGroup:B,closeGroup:q,handleResizeStart:H,splitTabRelative:te,clearAllSplits:ie}=da({groupAssignments:w,setGroupAssignments:v,setFocusedGroup:L,setGroupActiveTabIds:k,setGroupTabOrders:j,groupSizes:P,setGroupSizes:W,isMobile:C,visibleConversations:E,visibleTabKeys:z}),se=c.useMemo(()=>{var Ne,Ke;const pe=f[N];if(pe){const Kt=$.find(tn=>tn.tabKey===pe);if(Kt)return Kt}return((Ne=ne[N])==null?void 0:Ne[0])||((Ke=ne[0])==null?void 0:Ke[0])},[f,N,$,ne]),{ptyBuffers:xe}=Js({conversations:$,visibleConversations:E,clearedTabs:Y,setClearedTabs:F,setMessageReceivedAt:A,setActionLogs:R});Zs({ides:l,sendDaemonCommand:t,setToasts:p,setLocalUserMessages:K,resolveConversationByTarget:G});const{isCreatingChat:me,isRefreshingHistory:Ue,handleLaunchIde:je,handleSwitchSession:vt,handleNewChat:Oe,handleRefreshHistory:Le}=aa({sendDaemonCommand:t,activeConv:se,updateIdeChats:a,setToasts:p,setLocalUserMessages:K,setClearedTabs:F});ra({urlActiveTab:r,conversations:$,resolveConversationByTarget:G,normalizedGroupAssignments:ee,setGroupActiveTabIds:k,setFocusedGroup:L,setSearchParams:n,historyModalOpen:M,activeConv:se,isRefreshingHistory:Ue,ides:l,handleRefreshHistory:Le,isSplitMode:Z,splitTabRelative:te,numGroups:X,clearAllSplits:ie});const Ve=c.useCallback(async()=>{if(!se||!ge(se)||he(se))return;const pe=se.ideType||se.agentType||"";if(!window.confirm(`Stop ${pe}?
54
- This will terminate the CLI process.`))return;const Ne=se.ideId||se.daemonId||"";try{await t(Ne,"stop_cli",{cliType:pe,targetSessionId:se.sessionId})}catch(Ke){console.error("Stop CLI failed:",Ke)}},[se,t]),{versionMismatchDaemons:Ye,versionBannerDismissed:wt,setVersionBannerDismissed:Nt,upgradingDaemons:at,handleBannerUpgrade:qe}=ua({ides:l,sendDaemonCommand: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(nr,{wsStatus:g,showReconnected:I}),!wt&&e.jsx(Sa,{daemons:Ye,upgradingDaemons:at,onUpgrade:qe,onDismiss:()=>Nt(!0)}),e.jsx(ir,{activeConv:se,agentCount:b.length,wsStatus:g,isConnected:m,onOpenHistory:()=>D(!0),onStopCli:Ve}),e.jsx(ka,{containerRef:U,isSplitMode:Z,numGroups:X,groupSizes:P,groupedConvs:ne,ides:l,messageReceivedAt:V,actionLogs:_,ptyBuffers:xe,screenshotMap:i,setScreenshotMap:u,sendDaemonCommand:t,setLocalUserMessages:K,setActionLogs:R,isStandalone:Q,userName:o.userName,focusedGroup:N,setFocusedGroup:L,moveTabToGroup:B,splitTabRelative:te,closeGroup:q,handleResizeStart:H,detectedIdes:ae,handleLaunchIde:je,groupActiveTabIds:f,setGroupActiveTabIds:k,groupTabOrders:S,setGroupTabOrders:j,toggleHiddenTab:T}),M&&se&&e.jsx(Ws,{activeConv:se,ides:l,isCreatingChat:me,isRefreshingHistory:Ue,onClose:()=>D(!1),onNewChat:Oe,onSwitchSession:vt,onRefreshHistory:Le}),e.jsx("style",{children:`
55
- body { overflow: hidden; overscroll-behavior: none; }
56
- `}),e.jsx(Os,{toasts:x,onDismiss:pe=>p(Ne=>Ne.filter(Ke=>Ke.id!==pe)),onClickToast:pe=>{if(pe.targetKey){const Ne=G(pe.targetKey);Ne&&L(ee.get(Ne.tabKey)??0)}}}),h&&e.jsx(Ca,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}d(!1)}})]})}function Ma({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:o}){return t?e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${n==="native"?"active":""}`,onClick:()=>o("native"),children:s}),r.map(a=>{const i=n===a.tabKey,u=a.status==="waiting_approval",l=a.status==="generating";return e.jsxs("button",{className:`ide-chat-tab ${i?"active":""}`,onClick:()=>o(a.tabKey),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:u?"#f59e0b":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),a.title,u&&e.jsx("span",{className:"ide-ext-badge",style:{background:"#f59e0b22",color:"#f59e0b",marginLeft:4},children:"!"})]},a.tabKey)})]}):null}function Ta({ideName:t,workspaceName:s,connState:n,machineName:r,viewMode:o,onChangeView:a,onOpenHistory:i,headerActions:u,onBack:l}){return e.jsxs("header",{className:"ide-header",children:[e.jsxs("div",{className:"ide-header-left",children:[e.jsxs("div",{className:"ide-title",children:[e.jsx(He,{size:16}),e.jsx("span",{className:"ide-name",children:t}),e.jsx("span",{className:"ide-name-mobile",children:"IDE"}),s&&e.jsx("span",{className:"ide-workspace",children:s}),e.jsx("span",{className:"ide-badge",children:"REMOTE"})]}),e.jsxs("div",{className:"ide-status-pill",children:[e.jsx("span",{className:`ide-dot ${n==="connected"?"online":"connecting"}`}),e.jsx("span",{className:"ide-status-text",children:n==="connected"?"Connected":n==="connecting"?"Connecting":"WS"})]}),r&&e.jsx("span",{className:"ide-machine-label",children:r})]}),e.jsxs("div",{className:"ide-header-right",children:[["chat","split","remote"].map(h=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:o===h?"1px solid var(--accent-primary)":"none",background:o===h?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:o===h?"var(--accent-primary)":void 0},onClick:()=>a(h),children:h==="chat"?e.jsx(He,{size:14}):h==="split"?"⊞":e.jsx(_e,{size:14})},h)),e.jsx("button",{className:"btn btn-secondary btn-sm flex items-center justify-center shrink-0",onClick:i,title:"Chat History",children:e.jsx(ks,{size:14})}),u,e.jsxs("button",{className:"btn btn-primary btn-sm flex items-center justify-center shrink-0",onClick:l,children:["←",e.jsx("span",{className:"hidden md:inline ml-1",children:"Back"})]})]})]})}function Ea({toasts:t,onDismiss:s}){return t.length===0?null:e.jsx("div",{className:"ide-toasts",children:t.map(n=>e.jsx("div",{className:`ide-toast ${n.type}`,onClick:()=>s(n.id),children:n.message},n.id))})}function Aa({ideId:t,activeConv:s,historyModalOpen:n,chats:r,sendDaemonCommand:o,updateIdeChats:a,pushToast:i}){const[u,l]=c.useState(!1),[h,d]=c.useState(!1),[x,p]=c.useState(!1),g=c.useRef(!1),m=c.useCallback(async v=>{const N=v.trim();if(!(!N||!t||x||!s)){p(!0);try{await o(t,"send_chat",{message:N,text:N,waitForResponse:!0,...Ie(s)})}catch(L){console.error("[IDE] Send failed:",L)}finally{p(!1)}}},[t,x,o,s]),y=c.useCallback(async()=>{var v;if(!(!t||h||!s)){d(!0);try{const N=await o(t,"list_chats",{forceExpand:!0,...Ie(s)}),L=(N==null?void 0:N.chats)||((v=N==null?void 0:N.result)==null?void 0:v.chats);N!=null&&N.success&&Array.isArray(L)&&a(t,L)}catch(N){console.error("[IDE] Refresh history failed:",N),i("히스토리 새로고침에 실패했습니다.","warning")}finally{d(!1)}}},[t,h,o,s,a,i]),I=c.useCallback(async(v,N)=>{if(!(!t||!s))try{const L=await o(t,"switch_chat",{id:N,sessionId:N,...Ie(s)}),f=L==null?void 0:L.result;if((L==null?void 0:L.success)===!0||f==="switched"||f==="switched-by-title")return;f===!1||f==="not_found"?i("세션 탭을 찾지 못했습니다. 히스토리를 새로고침해 보세요.","warning"):typeof f=="string"&&f.startsWith("error:")?i(`세션 전환 오류: ${f}`,"warning"):i("세션 전환에 실패했습니다.","warning")}catch(L){console.error("[IDE] Switch session failed:",L),i(`세션 전환 실패: ${(L==null?void 0:L.message)||"connection error"}`,"warning")}},[t,o,s,i]),w=c.useCallback(async()=>{if(!(!t||u||!s)){l(!0);try{await o(t,"new_chat",{...Ie(s)})}catch(v){console.error("[IDE] New chat failed:",v),i("새 채팅 생성에 실패했습니다.","warning")}finally{l(!1)}}},[t,u,o,s,i]);return c.useEffect(()=>{if(!n){g.current=!1;return}g.current||h||(!r||r.length===0)&&(g.current=!0,y())},[n,r,h,y]),{isSendingChat:x,isCreatingChat:u,isRefreshingHistory:h,handleSendAgent:m,handleRefreshHistory:y,handleSwitchSession:I,handleNewChat:w}}function $a({ideId:t,ideData:s,allIdes:n,connectionStates:r,localUserMessages:o,ideName:a}){const[i,u]=c.useState("native"),l=c.useMemo(()=>s?Ks([s],o,n,r):[],[s,o,n,r]),h=c.useMemo(()=>l.find(m=>m.streamSource==="native"),[l]),d=c.useMemo(()=>l.filter(m=>m.streamSource==="agent-stream"),[l]);c.useEffect(()=>{var m;i!=="native"&&(d.some(y=>y.tabKey===i)||u(((m=d[0])==null?void 0:m.tabKey)||"native"))},[i,d]),c.useEffect(()=>{i==="native"&&(h||d[0]&&u(d[0].tabKey))},[i,h,d]);const x=c.useMemo(()=>i==="native"&&h?h:d.find(m=>m.tabKey===i)||h||d[0],[i,h,d]),p=c.useMemo(()=>d.map(m=>({tabKey:m.tabKey,title:m.title||m.agentName||a,status:m.status})),[d,a]),g=c.useCallback(m=>{if(m)return l.find(y=>y.sessionId===m||y.ideId===m||y.tabKey===m||y.ideType===m||y.agentType===m)},[l]);return{activeChatTab:i,setActiveChatTab:u,activeConv:x,conversations:l,extensionTabs:p,hasExtensions:p.length>0,resolveConversationByTarget:g}}function _a({doId:t,ideId:s,ideType:n,connState:r,viewMode:o,instanceId:a}){const[i,u]=c.useState(null),[l,h]=c.useState(null),d=c.useMemo(()=>{if(!s)return n;const p=s.split(":");return p.length>=3&&p[1]==="ide"?p.slice(2).join(":"):n},[s,n]);c.useEffect(()=>t?Me.onScreenshot("ide-page",(g,m)=>{if(g!==t)return;const y=new FileReader;y.onload=()=>u(y.result),y.readAsDataURL(m)}):void 0,[t]),c.useEffect(()=>{r!=="connected"&&u(null)},[r]),c.useEffect(()=>{var g;return t?((g=Me.onStatus)==null?void 0:g.call(Me,(m,y)=>{m===t&&y!=null&&y.screenshotUsage&&h(y.screenshotUsage)}))||(()=>{}):void 0},[t]),c.useEffect(()=>{u(null)},[t,s,d]),c.useEffect(()=>{const p=t?Me.get(t):null;!p||r!=="connected"||(o!=="chat"&&d?p.startScreenshots(d):p.stopScreenshots(d))},[o,r,d,t]);const x=c.useCallback(async(p,g)=>{const m=t?Me.get(t):null;return!m||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):m.sendInput(p,g,a||d)},[t,r,a,d]);return{connScreenshot:i,screenshotUsage:l,handleRemoteAction:x}}function La(){const[t,s]=c.useState([]),n=c.useCallback(o=>{s(a=>a.filter(i=>i.id!==o))},[]),r=c.useCallback((o,a="warning")=>{const i=Date.now()+Math.floor(Math.random()*1e3);s(u=>[...u,{id:i,message:o,type:a}]),window.setTimeout(()=>{s(u=>u.filter(l=>l.id!==i))},5e3)},[]);return{toasts:t,setToasts:s,dismissToast:n,pushToast:r}}function Pa({renderHeaderActions:t}={}){var q;const{id:s}=fs(),n=nt(),r=jt(),o=r.ides||[],a=r.updateIdeChats||(()=>{}),i=r.connectionStates||{},{sendCommand:u}=$e(),l=c.useMemo(()=>Hs(s||"").daemonId,[s]),h=c.useMemo(()=>o.find(H=>H.id===s),[o,s]),d=(h==null?void 0:h.type)||void 0,x=d?d.charAt(0).toUpperCase()+d.slice(1):"IDE",p=r.isConnected??!0,g=i[l]||(p?"connected":"new"),m=((q=r.connectionTransports)==null?void 0:q[l])||"unknown",y=c.useMemo(()=>o.find(H=>H.id===l||H.daemonId===l),[o,l]),I=y?Fe(y,{fallbackId:l}):"",w=(h==null?void 0:h.workspace)||"",[v]=ms(),N=typeof window<"u"&&window.innerWidth<=768,L=v.get("view")||(N?"chat":"split"),[f,k]=c.useState(L),[S,j]=c.useState(!1),{toasts:P,setToasts:W,dismissToast:C,pushToast:V}=La(),[A,M]=c.useState({}),[D,_]=c.useState([]),[R,O]=c.useState({}),[K,Y]=c.useState({}),{activeChatTab:F,setActiveChatTab:J,activeConv:ae,conversations:Q,extensionTabs:oe,hasExtensions:T,resolveConversationByTarget:b}=$a({ideId:s||"",ideData:h,allIdes:o,connectionStates:i,localUserMessages:R,ideName:x});Js({conversations:Q,visibleConversations:Q,clearedTabs:K,setClearedTabs:Y,setMessageReceivedAt:M,setActionLogs:_});const{connScreenshot:$,screenshotUsage:E,handleRemoteAction:z}=_a({doId:l,ideId:s||"",ideType:d,connState:g,viewMode:f,instanceId:h==null?void 0:h.instanceId}),G=!!o.find(H=>H.type==="adhdev-daemon"),U=Qs({sendDaemonCommand:u,activeConv:ae,setLocalUserMessages:O,setActionLogs:_,isStandalone:G}),{isCreatingChat:ee,isRefreshingHistory:X,handleRefreshHistory:Z,handleSwitchSession:ne,handleNewChat:B}=Aa({ideId:s||"",activeConv:ae,historyModalOpen:S,chats:h==null?void 0:h.chats,sendDaemonCommand:u,updateIdeChats:a,pushToast:V});return Zs({ides:o,sendDaemonCommand:u,setToasts:W,setLocalUserMessages:O,resolveConversationByTarget:b}),s?ae?e.jsxs("div",{className:"ide-page",children:[e.jsx(Ta,{ideName:x,workspaceName:w,connState:g,machineName:I,viewMode:f,onChangeView:k,onOpenHistory:()=>j(!0),headerActions:t==null?void 0:t({daemonId:l,ideInstanceId:s||""}),onBack:()=>n(-1)}),e.jsxs("div",{className:"ide-content",children:[e.jsxs("div",{className:`ide-chat-panel ${f==="chat"?"full":""} ${f==="remote"?"hidden":""}`,children:[e.jsx(Ma,{hasExtensions:T,ideName:x,activeChatTab:F,extensionTabs:oe,onSelectTab:H=>{J(H);const te=Q.find(ie=>ie.tabKey===H);(te==null?void 0:te.streamSource)==="agent-stream"&&u(te.ideId,"focus_session",{agentType:te.agentType,...te.sessionId&&{targetSessionId:te.sessionId}}).catch(()=>{})}}),e.jsx($s,{activeConv:ae,onModalButton:U.handleModalButton}),e.jsx(Ps,{activeConv:ae,ides:o,handleSendChat:U.handleSendChat,isSendingChat:U.isSendingChat,handleFocusAgent:U.handleFocusAgent,isFocusingAgent:U.isFocusingAgent,messageReceivedAt:A,actionLogs:D,userName:r.userName})]}),e.jsx("div",{className:`ide-remote-panel ${f==="remote"?"full":""} ${f==="chat"?"hidden":""}`,children:e.jsx(Fn,{addLog:()=>{},connState:g,connScreenshot:$,screenshotUsage:E,transportType:m,onAction:z})})]}),e.jsx(Ea,{toasts:P,onDismiss:C}),S&&e.jsx(Ws,{activeConv:ae,ides:o,isCreatingChat:ee,isRefreshingHistory:X,onClose:()=>j(!1),onNewChat:B,onSwitchSession:ne,onRefreshHistory:Z})]}):e.jsx("div",{className:"ide-empty",children:"IDE session not available"}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function Ra({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:o}){const[a,i]=c.useState([]),[u,l]=c.useState(null),[h,d]=c.useState(!1),[x,p]=c.useState(!1),[g,m]=c.useState(!1),[y,I]=c.useState([]),[w,v]=c.useState([]),[N,L]=c.useState(null),[f,k]=c.useState(!1),[S,j]=c.useState(""),P=c.useRef(null),W=c.useCallback(T=>{P.current=T},[]),C=c.useCallback((T,b,$=!1)=>{i(E=>[...E.slice(-100),{timestamp:Date.now(),level:T,message:b}]),setTimeout(()=>{var E;return(E=o.current)==null?void 0:E.scrollIntoView({behavior:"smooth"})},100),$&&Te.showToast(b,T==="error"||T==="warn"?"warning":"success")},[o]),V=c.useCallback(async(T,b)=>{var $;if(!(!t||u)){l(T),C("info",`Launching ${ue(T)}${b!=null&&b.workspace?` in ${b.workspace}`:""}...`);try{const E={ideType:T,enableCdp:!0};($=b==null?void 0:b.workspace)!=null&&$.trim()?E.workspace=b.workspace.trim():b!=null&&b.useDefaultWorkspace&&(E.useDefaultWorkspace=!0);const z=await n(t,"launch_ide",E);C(z!=null&&z.success?"info":"error",z!=null&&z.success?`${ue(T)} launched`:`Failed: ${z==null?void 0:z.error}`,!0)}catch(E){C("error",`Launch error: ${E.message}`,!0)}finally{l(null)}}},[t,u,C,n]),A=c.useCallback(async T=>{if(!t)return;const{cliType:b,dir:$,workspaceId:E,useDefaultWorkspace:z,useHome:G,argsStr:U,model:ee}=T;if(!b){C("warn","Select a CLI or ACP provider first",!0);return}const X=U?U.split(/\s+/).filter(Boolean):void 0,Z=($==null?void 0:$.trim())||(E?"(saved id)":z?"(default workspace)":G?"(home)":"");C("info",`Launching ${b}${Z?` in ${Z}`:""}${ee?` (model: ${ee})`:""}...`);try{const ne={cliType:b,cliArgs:X,initialModel:ee||void 0};$!=null&&$.trim()?ne.dir=$.trim():E?ne.workspaceId=E:z?ne.useDefaultWorkspace=!0:G&&(ne.useHome=!0);const B=await n(t,"launch_cli",ne),q=(B==null?void 0:B.result)||B;B!=null&&B.success?(C("info",`${b} launched`,!0),(q==null?void 0:q.launchSource)==="home"?C("info","📂 Running in home directory (explicit choice)"):(q==null?void 0:q.launchSource)==="defaultWorkspace"&&C("info","📂 Using default workspace (explicit choice)")):(C("error",`Failed: ${(B==null?void 0:B.error)||(q==null?void 0:q.error)}`,!0),(B==null?void 0:B.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&L({cliType:b,argsStr:U,model:ee}))}catch(ne){C("error",`Launch error: ${ne.message}`,!0)}},[t,C,n]),M=c.useCallback((T,b,$,E)=>{if(t){if(!T){C("warn","Select a provider",!0);return}if(!b.trim()){L({cliType:T,argsStr:$,model:E});return}A({cliType:T,dir:b,argsStr:$,model:E})}},[t,C,A]),D=c.useCallback(async(T,b,$)=>{if(t&&window.confirm(`Stop ${T}?
57
- This will terminate the process.`))try{const E=await n(t,"stop_cli",{cliType:T,dir:b,targetSessionId:$});E!=null&&E.success?C("info",`${T} stopped`,!0):C("error",`Stop failed: ${(E==null?void 0:E.error)||"Unknown error"}`,!0)}catch(E){C("error",`Stop failed: ${E.message}`,!0)}},[t,C,n]),_=c.useCallback(async T=>{try{await n(T.daemonId,"restart_ide",{ideType:T.type}),C("info",`${ue(T.type)} restart initiated`,!0)}catch(b){C("error",`Restart failed: ${b.message}`,!0)}},[C,n]),R=c.useCallback(async T=>{if(window.confirm(`Stop ${ue(T.type)}?
58
- This will disconnect CDP and optionally kill the process.`))try{const b=await n(T.daemonId,"stop_ide",{ideType:T.type,killProcess:!0});b!=null&&b.success?C("info",`${ue(T.type)} stopped`,!0):C("error",`Stop failed: ${(b==null?void 0:b.error)||"Unknown error"}`,!0)}catch(b){C("error",`Stop failed: ${b.message}`,!0)}},[C,n]),O=c.useCallback(async()=>{if(t)try{const T=await n(t,"detect_ides",{});C("info",`Found ${((T==null?void 0:T.result)||[]).length} IDE(s)`,!0)}catch(T){C("error",`Detection failed: ${T.message}`,!0)}},[t,C,n]),K=c.useCallback(async()=>{if(t){d(!0);try{const T=await n(t,"get_recent_workspaces",{});T!=null&&T.success&&Array.isArray(T==null?void 0:T.result)&&v(T.result)}catch(T){C("error",`Failed: ${T.message}`)}finally{d(!1)}}},[t,C,n]),Y=c.useCallback(async T=>{if(!(!t||!T.trim())){p(!0);try{const b=await n(t,"workspace_add",{path:T.trim()});b!=null&&b.success?C("info",`Workspace added: ${T.trim()}`):C("error",(b==null?void 0:b.error)||"workspace_add failed")}catch(b){C("error",b.message)}finally{p(!1)}return!0}},[t,C,n]),F=c.useCallback(async T=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){p(!0);try{const b=await n(t,"workspace_remove",{id:T});b!=null&&b.success?C("info","Workspace removed",!0):C("error",(b==null?void 0:b.error)||"workspace_remove failed",!0)}catch(b){C("error",b.message,!0)}finally{p(!1)}}},[t,C,n]),J=c.useCallback(async T=>{var b;if(t){p(!0);try{const $=await n(t,"workspace_set_default",T===null?{clear:!0}:{id:T});if($!=null&&$.success){C("info",T?"Default workspace updated":"Default workspace cleared",!0);const E=typeof $.defaultWorkspacePath=="string"?$.defaultWorkspacePath:"";E&&((b=P.current)==null||b.call(P,E))}else C("error",($==null?void 0:$.error)||"workspace_set_default failed",!0)}catch($){C("error",$.message,!0)}finally{p(!1)}}},[t,C,n]),ae=c.useCallback(async T=>{var $;if(!t||!T.trim())return;const b=T.trim();p(!0);try{const E=await n(t,"workspace_set_default",{path:b});E!=null&&E.success?(C("info","Default workspace set from history"),($=P.current)==null||$.call(P,b)):C("error",(E==null?void 0:E.error)||"Could not set default (path missing on disk?)")}catch(E){C("error",E.message)}finally{p(!1)}},[t,C,n]),Q=c.useCallback(async()=>{var T;if(t){m(!0);try{const b=await n(t,"get_cli_history",{}),$=(b==null?void 0:b.history)??((T=b==null?void 0:b.result)==null?void 0:T.history);b!=null&&b.success&&Array.isArray($)&&I($)}catch{}m(!1)}},[t,n]),oe=c.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(T){C("warn",`Live nickname updated, but account sync failed: ${T.message}`)}C("info",`Nickname set to "${S||"(cleared)"}"`),k(!1)}catch(T){C("error",`Failed: ${T.message}`)}},[t,S,s,C,r,n]);return{logs:a,launchingIde:u,loadingWorkspaces:h,workspaceBusy:x,loadingHistory:g,cliHistory:y,recentWorkspaces:w,launchPick:N,setLaunchPick:L,editingNickname:f,setEditingNickname:k,nicknameInput:S,setNicknameInput:j,addLog:C,handleLaunchIde:V,runLaunchCliCore:A,handleLaunchCli:M,handleStopCli:D,handleRestartIde:_,handleStopIde:R,handleDetectIdes:O,handleLoadRecentWorkspaces:K,handleWorkspaceAdd:Y,handleWorkspaceRemove:F,handleWorkspaceSetDefault:J,handleWorkspaceResumePath:ae,loadCliHistory:Q,handleSaveNickname:oe,setOnDefaultWorkspaceChanged:W}}function Da({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:o}){const{workspaceBusy:a,handleWorkspaceAdd:i,handleWorkspaceRemove:u,handleWorkspaceSetDefault:l}=o,[h,d]=c.useState(""),x=t.availableMem??t.freeMem,p=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-x)/t.totalMem*100))):0,g=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(ot,{icon:e.jsx(Is,{size:16}),label:"Uptime",value:Xn(t.uptime)}),e.jsx(ot,{icon:e.jsx(_e,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(ot,{icon:e.jsx(Wt,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(ot,{icon:e.jsx(Ts,{size:16}),label:"ACPs",value:`${r.length}`})]}),e.jsxs("div",{className:"px-5 py-4 rounded-xl mb-5 bg-bg-secondary border border-border-subtle",children:[e.jsx("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-3",children:"Resource Usage"}),e.jsxs("div",{className:"flex gap-6",children:[e.jsx(Yt,{value:Math.min(Math.round(g/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${g.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Yt,{value:p,max:100,label:"Memory",color:"#3b82f6",detail:`${Xt(t.totalMem-x)} / ${Xt(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($t,{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:a,value:t.defaultWorkspaceId||"",onChange:m=>void l(m.target.value===""?null:m.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(m=>e.jsx("option",{value:m.id,children:m.label||m.path},m.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:h,disabled:a,onChange:m=>d(m.target.value),onKeyDown:m=>m.key==="Enter"&&void(async()=>{await i(h)&&d("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:a,onClick:async()=>{await i(h)&&d("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1 max-h-32 overflow-y-auto",children:(t.workspaces||[]).map(m=>e.jsxs("li",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[m.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-mono truncate flex-1",title:m.path,children:m.path}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline",disabled:a,onClick:()=>void u(m.id),children:"Remove"})]},m.id))})]})]})}const Ba={ide:{label:"IDE",plural:"IDEs",accent:"border-blue-500/[0.12]"},cli:{label:"CLI",plural:"CLIs",accent:"border-violet-500/[0.12]"},acp:{label:"ACP Agent",plural:"ACP agents",accent:"border-emerald-500/[0.12]"}};function At({category:t,machine:s,machineId:n,providers:r,managedEntries:o,getIcon:a,actions:i,sendDaemonCommand:u}){const l=nt(),{handleLaunchIde:h,handleLaunchCli:d,handleStopCli:x,handleRestartIde:p,handleStopIde:g,handleDetectIdes:m,cliHistory:y,loadingHistory:I,loadCliHistory:w,launchingIde:v}=i,N=Ba[t],L=t==="ide",f=t==="acp",k=r.filter(b=>b.category===t),[S,j]=c.useState(""),[P,W]=c.useState(""),[C,V]=c.useState(""),[A,M]=c.useState(s.defaultWorkspaceId||""),[D,_]=c.useState("");c.useEffect(()=>{!S&&k.length>0&&j(k[0].type)},[S,k.length]),c.useEffect(()=>{s.defaultWorkspaceId&&!A&&M(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const R=(()=>{if(A==="__custom__")return D.trim();if(!A)return"";const b=(s.workspaces||[]).find($=>$.id===A);return(b==null?void 0:b.path)||""})(),[O,K]=c.useState({}),[Y,F]=c.useState(null);c.useEffect(()=>{if(!L||!n||!u)return;(async()=>{try{const $=await u(n,"get_ide_extensions",{}),E=($==null?void 0:$.result)||$;E!=null&&E.success&&(E!=null&&E.ideExtensions)&&K(E.ideExtensions)}catch{}})()},[L,n,u]);const J=b=>L?ue(b.type):t==="cli"?b.cliName:b.acpName,ae=L?s.detectedIdes||[]:[],Q=()=>{L?h(S,R?{workspace:R}:void 0):d(S,R,P||void 0,f&&C||void 0)},oe=b=>{L?g(b):x(b.type,b.workspace,b.id)},T=e.jsxs("div",{className:"flex gap-2 items-center flex-wrap mb-3",children:[e.jsx("select",{value:A,onChange:b=>{M(b.target.value),b.target.value!=="__custom__"&&_("")},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(b=>e.jsxs("option",{value:b.id,children:[b.id===s.defaultWorkspaceId?"⭐ ":"",b.label||b.path.split("/").filter(Boolean).pop()||b.path," — ",b.path]},b.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…"})]})}),A==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:D,onChange:b=>_(b.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 ${N.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",N.label]}),T,L?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ae.map(b=>{const $=b.running||o.some(E=>(E.type||"").toLowerCase()===(b.type||"").toLowerCase());return e.jsxs("button",{onClick:()=>h(b.type||b.id||"",R?{workspace:R}:void 0),disabled:!!v,className:`machine-btn-primary flex items-center gap-1.5 ${$?"!border-green-500/30":""}`,style:{opacity:v&&v!==b.type?.4:1},children:[e.jsx("span",{children:a(b.type)}),$&&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)]"}),v===b.type?"⏳ Launching...":`▶ ${b.name||ue(b.type)}`,$&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"+ window"})]},b.type)}),ae.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:m,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Mn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:S,onChange:b=>j(b.target.value),className:"machine-input",children:k.length>0?k.map(b=>e.jsxs("option",{value:b.type,children:[b.icon," ",b.displayName]},b.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),f&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:C,onChange:b=>V(b.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:P,onChange:b=>W(b.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:Q,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 (",o.length,")"]}),o.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 ",N.plural," running"]}):e.jsx("div",{className:"flex flex-col gap-2.5 mb-5",children:o.map(b=>{const $=L?b:null,E=f?b:null,z=be(b.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:a(b.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[J(b),($==null?void 0:$.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",$.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:b.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 ${z==="stopped"?"bg-red-500/[0.08] text-red-500":z==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:z}),L&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>l(`/ide/${b.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(_e,{size:13})," Control"]}),e.jsx("button",{onClick:()=>p(b),className:"machine-btn text-amber-500 border-amber-500/30",children:"↻"})]}),f&&e.jsx("button",{onClick:()=>l(`/ide/${b.id}`),className:"machine-btn",title:"View chat",children:e.jsx(He,{size:14})}),z==="stopped"?e.jsx("button",{onClick:()=>L?h(b.type,b.workspace?{workspace:b.workspace}:void 0):d(b.type,b.workspace),className:"machine-btn text-green-500 border-green-500/30",children:"▶"}):e.jsx("button",{onClick:()=>oe(b),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),$&&$.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:$.aiAgents.map(G=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${_s(G.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[G.name," · ",be(G.status)]},G.id))}),$&&(O[$.type]||[]).length>0&&u&&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:(O[$.type]||[]).map(G=>e.jsxs("button",{disabled:Y===`${$.type}.${G.type}`,onClick:async()=>{const U=`${$.type}.${G.type}`;F(U);try{await u(n,"set_ide_extension",{ideType:$.type,extensionType:G.type,enabled:!G.enabled}),K(ee=>({...ee,[$.type]:(ee[$.type]||[]).map(X=>X.type===G.type?{...X,enabled:!X.enabled}:X)}))}catch(ee){console.error("Extension toggle failed:",ee)}finally{F(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 ${G.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 ${G.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),G.name,e.jsx("span",{className:"text-[9px] font-normal",children:G.enabled?"ON":"OFF"})]},G.type))})]})]},b.id)})}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:w,disabled:I,className:"machine-btn",children:I?"⏳":"↻ Load"})]}),(()=>{const b=new Set(k.map(E=>E.type)),$=y.filter(E=>(E.category||"cli")!==t?!1:t==="ide"?!0:b.has(E.cliType));return $.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:$.map((E,z)=>{var G,U;return e.jsxs("div",{onClick:()=>{j(E.cliType),(E.workspace||E.dir)&&(M("__custom__"),_(E.workspace||E.dir)),W((E.cliArgs||[]).join(" ")),V(E.model||""),L&&h(E.cliType,E.workspace?{workspace:E.workspace}:void 0)},className:"flex justify-between items-center px-2.5 py-1.5 rounded-md cursor-pointer bg-bg-glass border border-border-subtle text-xs transition-colors duration-150 hover:bg-bg-glass-hover",children:[e.jsxs("div",{className:"flex gap-1.5 items-center text-text-secondary",children:[e.jsx("span",{children:a(E.cliType)}),e.jsx("span",{children:((G=E.workspace||E.dir)==null?void 0:G.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"}),((U=E.cliArgs)==null?void 0:U.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():""})]},z)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",N.label," launch history yet."]})})()]})]})}const us=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],Wa=[{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 Oa({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[o,a]=c.useState("config"),[i,u]=c.useState("codex-cli"),[l,h]=c.useState([]),[d,x]=c.useState(""),[p,g]=c.useState([]),[m,y]=c.useState(""),I=c.useRef(null),w=c.useRef(null),v=j=>{h(P=>P.includes(j)?P.filter(W=>W!==j):[...P,j])},N=()=>h([...us]),L=()=>h([]);c.useEffect(()=>{var j;(j=I.current)==null||j.scrollIntoView({behavior:"smooth"})},[p]),c.useEffect(()=>()=>{w.current&&clearInterval(w.current)},[]);const f=c.useCallback(()=>{w.current&&clearInterval(w.current),w.current=setInterval(async()=>{try{const j=await n(t,"provider_auto_fix_status",{providerType:s.type});(j==null?void 0:j.running)===!1&&o==="running"&&(a("done"),g(P=>[...P,`
59
- ✅ Auto-fix completed!`]),w.current&&clearInterval(w.current))}catch{}},3e3)},[t,s.type,n,o]),k=async()=>{if(l.length!==0){a("running"),g(["🚀 Starting auto-fix...",`Agent: ${i}`,`Scripts: ${l.join(", ")}`,d?`💬 Comment: ${d}`:"",""]),y("");try{const j=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:i,...d?{comment:d}:{}});j!=null&&j.success&&(j!=null&&j.started||j!=null&&j.running)?(g(P=>[...P,"✅ Agent started. Monitoring progress..."]),f()):(a("error"),y((j==null?void 0:j.error)||"Failed to start auto-fix"))}catch(j){a("error"),y((j==null?void 0:j.message)||"Connection failed")}}},S=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),g(j=>[...j,`
60
- ⚠️ Auto-fix cancelled.`]),a("done"),w.current&&clearInterval(w.current)}catch{}};return e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick: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:j=>j.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:[o==="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:Wa.map(j=>e.jsxs("button",{onClick:()=>u(j.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:i===j.value?j.color+"66":"var(--border-subtle)",background:i===j.value?j.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:i===j.value?j.color:"var(--text-primary)"},children:j.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:j.desc})]},j.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:N,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:L,className:"text-[10px] text-text-muted hover:text-text-secondary",children:"None"})]})]}),e.jsx("div",{className:"grid grid-cols-3 gap-1.5",children:us.map(j=>e.jsxs("button",{onClick:()=>v(j),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(j)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:l.includes(j)?"rgba(139,92,246,0.08)":"transparent",color:l.includes(j)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(j)?"☑ ":"☐ ",j]},j))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:d,onChange:j=>x(j.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"})]})]}),(o==="running"||o==="done"||o==="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((j,P)=>e.jsx("div",{className:j.startsWith("✅")?"text-green-400":j.startsWith("❌")||j.startsWith("⚠")?"text-amber-400":"",children:j},P)),o==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:I})]}),m&&e.jsx("div",{className:"mt-2 px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:m})]})]}),e.jsxs("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-between items-center",children:[e.jsxs("div",{className:"text-[10px] text-text-muted",children:[o==="config"&&l.length>0&&`${l.length} script(s) selected`,o==="running"&&"Agent is generating...",o==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[o==="config"&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:r,className:"machine-btn",children:"Cancel"}),e.jsx("button",{onClick:k,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"})]}),o==="running"&&e.jsx("button",{onClick:S,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(o==="done"||o==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{a("config"),g([]),y("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function Ka({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:o}){var f;const a=s.filter(k=>k.category==="ide"),[i,u]=c.useState(((f=a[0])==null?void 0:f.type)||""),[l,h]=c.useState(""),[d,x]=c.useState(""),[p,g]=c.useState(!1),[m,y]=c.useState(""),[I,w]=c.useState(!1),v=k=>{const S=k.toLowerCase().replace(/[^a-z0-9-]/g,"");h(S),(!d||d===N(l))&&x(N(S))},N=k=>k.split("-").map(S=>S.charAt(0).toUpperCase()+S.slice(1)).join(" "),L=async()=>{if(!(!l||!d||!i)){g(!0),y("");try{const k=await n(t,"provider_clone",{type:l,name:d,category:"ide",location:"user",cloneFrom:i});k!=null&&k.success||k!=null&&k.created?(w(!0),o==null||o(l)):y((k==null?void 0:k.error)||"Failed to create provider")}catch(k){y((k==null?void 0:k.message)||"Connection failed")}g(!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:k=>k.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:I?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:a.map(k=>e.jsxs("button",{onClick:()=>u(k.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:i===k.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:i===k.type?"rgba(139,92,246,0.08)":"transparent"},children:[e.jsx("div",{className:"text-lg",children:k.icon}),e.jsx("div",{className:"text-[10px] font-medium mt-0.5",style:{color:i===k.type?"#a78bfa":"var(--text-secondary)"},children:k.displayName})]},k.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:k=>v(k.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:d,onChange:k=>x(k.target.value),placeholder:"My Custom IDE",className:"w-full px-3 py-2 rounded-lg border border-border-subtle bg-bg-secondary text-text-primary text-[12px] placeholder:text-text-muted/50 focus:outline-none focus:border-violet-500/40"})]}),m&&e.jsx("div",{className:"px-3 py-2 rounded-lg bg-red-500/[0.06] border border-red-500/20 text-red-400 text-[11px]",children:m})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:I?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:L,disabled:!l||!d||p,className:"machine-btn",style:{background:l&&d?"rgba(34,197,94,0.12)":void 0,borderColor:l&&d?"rgba(34,197,94,0.3)":void 0,color:l&&d?"#86efac":void 0,opacity:!l||!d||p?.4:1},children:p?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function Ha({machineId:t,providers:s,sendDaemonCommand:n}){const[r,o]=c.useState([]),[a,i]=c.useState(!1),[u,l]=c.useState(null),[h,d]=c.useState("all"),[x,p]=c.useState(null),[g,m]=c.useState(!1),y=c.useCallback(async()=>{var w;if(t){i(!0);try{const v=await n(t,"get_provider_settings",{}),N=(v==null?void 0:v.result)||v;if(v!=null&&v.success&&(N!=null&&N.settings)){const L=[];for(const[f,k]of Object.entries(N.settings)){const S=s.find(j=>j.type===f);L.push({type:f,displayName:(S==null?void 0:S.displayName)||f,icon:(S==null?void 0:S.icon)||"",category:(S==null?void 0:S.category)||"unknown",schema:k,values:((w=N.values)==null?void 0:w[f])||{}})}L.sort((f,k)=>f.category.localeCompare(k.category)||f.displayName.localeCompare(k.displayName)),o(L)}}catch{}i(!1)}},[t,s,n]);c.useEffect(()=>{r.length===0&&y()},[]);const I=async(w,v,N)=>{l(`${w}.${v}`),o(L=>L.map(f=>f.type===w?{...f,values:{...f.values,[v]:N}}:f));try{const L=await n(t,"set_provider_setting",{providerType:w,key:v,value:N});L!=null&&L.success||y()}catch{y()}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(w=>e.jsx("button",{onClick:()=>d(w),className:`machine-btn text-[10px] px-2 py-0.5 ${h===w?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:w.toUpperCase()},w))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>m(!0),className:"machine-btn text-[10px] bg-green-500/[0.06] border-green-500/20 text-green-400 hover:bg-green-500/[0.12]",children:"✨ Create Provider"}),e.jsx("button",{onClick:y,disabled:a,className:"machine-btn",children:a?"⏳ Loading...":"↻ Refresh"})]})]}),h!=="all"&&r.filter(w=>w.category===h).length>1&&(()=>{const w=r.filter(f=>f.category===h),v=new Map;for(const f of w)for(const k of f.schema){if(k.type!=="boolean")continue;const S=v.get(k.key),j=!!(f.values[k.key]??k.default);S?(S.onCount+=j?1:0,S.total+=1):v.set(k.key,{label:k.label||k.key,onCount:j?1:0,total:1})}const N=[...v.entries()].filter(([,f])=>f.total===w.length);if(N.length===0)return null;const L=async(f,k)=>{for(const S of w)await I(S.type,f,k)};return e.jsxs("div",{className:"px-4 py-3 rounded-xl bg-violet-500/[0.04] border border-violet-500/10 mb-4",children:[e.jsxs("div",{className:"text-[10px] text-violet-400 font-semibold uppercase tracking-wider mb-2",children:["Bulk — Apply to all ",h.toUpperCase()," providers (",w.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(([f,k])=>{const S=k.onCount===k.total,j=k.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:k.label}),e.jsxs("span",{className:"text-[9px] text-text-muted",children:["(",k.onCount,"/",k.total,")"]}),e.jsx("button",{onClick:()=>void L(f,!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 L(f,!1),disabled:j,className:`machine-btn text-[9px] px-1.5 py-px ${j?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},f)})})]})})(),a&&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(w=>h==="all"||w.category===h).map(w=>e.jsxs("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary border border-border-subtle",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-lg",children:w.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:w.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:w.category==="acp"?"rgba(139,92,246,0.08)":w.category==="cli"?"rgba(59,130,246,0.08)":w.category==="ide"?"rgba(34,197,94,0.08)":"rgba(245,158,11,0.08)",color:w.category==="acp"?"#a78bfa":w.category==="cli"?"#60a5fa":w.category==="ide"?"#86efac":"#fbbf24"},children:w.category}),w.category==="ide"&&e.jsx("button",{onClick:()=>p(s.find(v=>v.type===w.type)||{type:w.type,displayName:w.displayName,icon:w.icon,category:w.category}),className:"ml-auto machine-btn text-[9px] px-2 py-0.5 bg-violet-500/[0.06] border-violet-500/20 text-violet-400 hover:bg-violet-500/[0.12]",children:"🔧 Auto-Fix"})]}),e.jsx("div",{className:"flex flex-col gap-2",children:w.schema.map(v=>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:[v.label||v.key,u===`${w.type}.${v.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),v.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:v.description})]}),e.jsx("div",{className:"shrink-0",children:v.type==="boolean"?e.jsx("button",{onClick:()=>I(w.type,v.key,!(w.values[v.key]??v.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:w.values[v.key]??v.default?"#8b5cf6":"var(--border-subtle)"},children:e.jsx("div",{className:"w-4 h-4 rounded-full bg-white absolute top-[3px] transition-[left] duration-200 shadow-[0_1px_3px_rgba(0,0,0,0.3)]",style:{left:w.values[v.key]??v.default?21:3}})}):v.type==="number"?e.jsx("input",{type:"number",value:w.values[v.key]??v.default??0,min:v.min,max:v.max,onChange:N=>{const L=parseInt(N.target.value)||0;v.min!==void 0&&L<v.min||v.max!==void 0&&L>v.max||I(w.type,v.key,L)},className:"machine-input w-20 text-center text-[11px]"}):v.type==="select"&&v.options?e.jsx("select",{value:w.values[v.key]??v.default??"",onChange:N=>I(w.type,v.key,N.target.value),className:"machine-input text-[11px]",children:v.options.map(N=>e.jsx("option",{value:N,children:N},N))}):e.jsx("input",{type:"text",value:w.values[v.key]??v.default??"",onBlur:N=>I(w.type,v.key,N.target.value),className:"machine-input w-[120px] text-[11px]"})})]},v.key))})]},w.type))}),x&&e.jsx(Oa,{machineId:t,provider:x,sendDaemonCommand:n,onClose:()=>p(null)}),g&&e.jsx(Ka,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>m(!1),onCreated:()=>{m(!1),y()}})]})}function za({machineId:t,sendDaemonCommand:s}){const[n,r]=c.useState([]),[o,a]=c.useState(0),[i,u]=c.useState(!0),[l,h]=c.useState("debug"),d=c.useRef(null),x=c.useRef(!1);return c.useEffect(()=>{if(!t||!i)return;const p=async()=>{try{const m=await s(t,"get_logs",{count:200,minLevel:l,since:o}),y=(m==null?void 0:m.result)||m;if(m!=null&&m.success&&Array.isArray(y==null?void 0:y.logs)&&y.logs.length>0){r(w=>[...w,...y.logs.map(N=>({timestamp:N.ts,level:N.level,message:`[${N.category}] ${N.message}`}))].slice(-300));const I=Math.max(...y.logs.map(w=>w.ts));a(I)}}catch{}};p();const g=setInterval(p,3e3);return()=>clearInterval(g)},[t,i,o,l,s]),c.useEffect(()=>{if(i&&n.length>0){const p=x.current?"smooth":"instant";setTimeout(()=>{var g;(g=d.current)==null||g.scrollIntoView({behavior:p}),x.current=!0},50)}},[n.length,i]),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:()=>{h(p),r([]),a(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:()=>u(!i),className:`machine-btn ${i?"text-green-500 border-green-500/30":""}`,children:i?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),a(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,g)=>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})]},g)),e.jsx("div",{ref:d})]})]})}function Fa({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:o}=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(a=>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:()=>{o(null),r({cliType:s.cliType,workspaceId:a.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:a.label||a.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:a.path})]},a.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:()=>{o(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:()=>{o(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:()=>o(null),children:"Cancel"})]})]})})}function Ua({onNicknameSynced:t}={}){var f,k,S,j,P,W,C,V,A;const{id:s}=fs(),n=nt(),{sendCommand:r}=$e(),o=jt(),a=o.ides||[],i=o.initialLoaded??!0,u=a.find(M=>M.id===s&&M.daemonMode),[l,h]=c.useState("overview"),d=c.useRef(null),x=Ra({machineId:s,registeredMachineId:(u==null?void 0:u.machineId)||null,sendDaemonCommand:r,onNicknameSynced:t,logsEndRef:d});c.useEffect(()=>Te.onToast(D=>{o.setToasts(R=>{if(R.some(Y=>Y.message===D.message&&D.timestamp-Y.timestamp<3e3))return R;const K={id:D.id,message:D.message,type:D.type,timestamp:D.timestamp,targetKey:D.targetKey,actions:D.actions};return[...R.slice(-4),K]});const _=D.duration||5e3;setTimeout(()=>o.setToasts(R=>R.filter(O=>O.id!==D.id)),_)}),[o]);const p=((u==null?void 0:u.availableProviders)||[]).map(M=>({type:M.type,displayName:M.displayName,icon:M.icon,category:M.category})),g={};for(const M of p)g[M.type]=M.icon;const m=M=>g[M]||"",y=u?{id:u.id,hostname:Ls(u,{fallbackId:u.id}),platform:((f=u.machine)==null?void 0:f.platform)||"unknown",arch:((k=u.machine)==null?void 0:k.arch)||"",cpus:((S=u.machine)==null?void 0:S.cpus)||0,totalMem:((j=u.machine)==null?void 0:j.totalMem)||0,freeMem:((P=u.machine)==null?void 0:P.freeMem)||0,availableMem:(W=u.machine)==null?void 0:W.availableMem,loadavg:((C=u.machine)==null?void 0:C.loadavg)||[],uptime:((V=u.machine)==null?void 0:V.uptime)||0,release:((A=u.machine)==null?void 0:A.release)||"",cdpConnected:!!u.cdpConnected,machineNickname:u.machineNickname||null,p2p:u.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:u.detectedIdes||[],workspaces:u.workspaces||[],defaultWorkspaceId:u.defaultWorkspaceId??u.activeWorkspaceId??null,defaultWorkspacePath:u.defaultWorkspacePath??u.activeWorkspacePath??null,workspaceActivity:u.workspaceActivity||[]}:null,I=a.filter(M=>M.daemonId===s&&!M.daemonMode).filter(M=>!Gt(M)&&!Jt(M)).map(M=>({id:M.id,type:M.type,version:M.version||"",instanceId:M.instanceId||"",status:M.status,workspace:M.workspace||null,terminals:M.terminals||0,aiAgents:tr(M.aiAgents||M.agents||[]),activeChat:M.activeChat||null,chats:M.chats||[],agentStreams:M.agentStreams||[],cdpConnected:M.cdpConnected||!1,daemonId:s})),w=a.filter(M=>M.daemonId===s&&Gt(M)).map(M=>({id:M.id,type:M.type,cliName:M.cliName||M.type,status:M.status,workspace:M.workspace||"",activeChat:M.activeChat||null,daemonId:s})),v=a.filter(M=>M.daemonId===s&&Jt(M)).map(M=>({id:M.id,type:M.type,acpName:M.cliName||M.type,status:M.status,workspace:M.workspace||"",activeChat:M.activeChat||null,currentModel:M.currentModel,currentPlan:M.currentPlan,daemonId:s}));if(!y)return i?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 N=Fe(u,{fallbackId:y.id}),L=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Tn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_e,{size:14})," IDEs"]}),count:I.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(ze,{size:14})," CLIs"]}),count:w.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ts,{size:14})," ACP Agents"]}),count:v.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Dt,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(In,{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:[x.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:x.nicknameInput,onChange:M=>x.setNicknameInput(M.target.value),onKeyDown:M=>{M.key==="Enter"&&x.handleSaveNickname(),M.key==="Escape"&&x.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:x.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>x.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{x.setEditingNickname(!0),x.setNicknameInput(y.machineNickname||"")},title:"Click to set nickname",children:N}),e.jsx("span",{className:"status-dot-md online shrink-0"})]}),e.jsxs("div",{className:"header-subtitle mt-1 flex-wrap gap-1 md:gap-2 items-center display-none-mobile",children:[e.jsxs("span",{children:[y.platform," · ",y.arch," · ",y.cpus," cores"]}),(u==null?void 0:u.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",u.version]}),(u==null?void 0:u.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",u.serverVersion]}),y.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:y.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:y.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",y.p2p.state==="connected"?`● ${y.p2p.peers}`:"○"]}),y.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 ●"}),y.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",y.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:L.map(M=>e.jsxs("button",{onClick:()=>h(M.id),className:`machine-tab shrink-0${l===M.id?" active":""}`,children:[M.label,M.count!==void 0&&e.jsx("span",{className:"tab-count",children:M.count})]},M.id))})]}),e.jsxs("div",{className:"page-content",children:[l==="overview"&&e.jsx(Da,{machine:y,ideSessions:I,cliSessions:w,acpSessions:v,actions:x}),l==="ides"&&e.jsx(At,{category:"ide",machine:y,machineId:s,providers:p,managedEntries:I,getIcon:m,actions:x,sendDaemonCommand:r}),l==="clis"&&e.jsx(At,{category:"cli",machine:y,machineId:s,providers:p,managedEntries:w,getIcon:m,actions:x}),l==="acps"&&e.jsx(At,{category:"acp",machine:y,machineId:s,providers:p,managedEntries:v,getIcon:m,actions:x}),l==="providers"&&e.jsx(Ha,{machineId:s,providers:p,sendDaemonCommand:r}),l==="logs"&&e.jsx(za,{machineId:s,sendDaemonCommand:r})]}),x.launchPick&&y&&e.jsx(Fa,{machine:y,launchPick:x.launchPick,actions:x}),e.jsx(Os,{toasts:o.toasts||[],onDismiss:M=>o.setToasts(D=>D.filter(_=>_.id!==M)),onClickToast:M=>{M.targetKey}}),e.jsx("style",{children:`
61
- @keyframes toast-in {
62
- from { opacity: 0; transform: translateX(40px); }
63
- to { opacity: 1; transform: translateX(0); }
64
- }
65
- `})]})}function Va(){const[t,s]=c.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=c.useState(!0);c.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(i=>i.json()).then(i=>{const u=[],l=[],h=[],d=[];Object.values(i.providers||{}).forEach(p=>{const g={name:p.name||"Unknown",status:p.status||"Stable",details:p.details||"Community Provider"};p.category==="ide"?u.push(g):p.category==="cli"?l.push(g):p.category==="extension"?h.push(g):p.category==="acp"&&d.push(g)});const x=(p,g)=>{const m={Stable:1,Beta:2,WIP:3},y=m[p.status]||99,I=m[g.status]||99;return y!==I?y-I:p.name.localeCompare(g.name)};s({ide:u.sort(x),cli:l.sort(x),ext:h.sort(x),acp:d.sort(x)})}).catch(i=>console.error("Failed to load capabilities:",i)).finally(()=>r(!1))},[]);const o=i=>i==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Ns,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):i==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Bt,{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(Is,{className:"w-4 h-4"})," ",e.jsx("span",{children:i})]}),a=i=>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:i.map((u,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:u.name}),e.jsx("td",{className:"py-3 px-4",children:o(u.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:u.details})]},l))})]})});return n?e.jsx(gt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ft,{}),widthClassName:"max-w-5xl",children:e.jsx(Ot,{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(gt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(ft,{}),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(_e,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:a(t.ide)}),e.jsx(de,{title:"Standalone CLI agents",icon:e.jsx(Wt,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:a(t.cli)}),e.jsx(de,{title:"AI extensions",icon:e.jsx(ze,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:a(t.ext)}),e.jsx(de,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(ze,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:a(t.acp)})]})}class Ya{constructor(){ce(this,"adapters",new Map);ce(this,"states",new Map);ce(this,"ptyCallbacks",new Set);ce(this,"screenshotCallbacks",new Map);ce(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,o){return!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 Ee=new Ya;function qa(){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 xs=qa(),ps=3e3,Xa=3e4;let Ce=null,Ga=0;const yt=new Map;let Re=null,et=null;function Ja(t){return t==="connected"?"connected":t}async function mt(t,s,n){const r=pr(t,n||{}),o=Ce;if(o&&o.readyState===WebSocket.OPEN){const i=`req_${++Ga}_${Date.now()}`;return new Promise((u,l)=>{const h=setTimeout(()=>{yt.delete(i),l(new Error(`WS command timeout: ${s}`))},3e4);yt.set(i,{resolve:d=>{clearTimeout(h),u(d)},reject:d=>{clearTimeout(h),l(d)}}),o.send(JSON.stringify({type:"command",requestId:i,data:{type:s,payload:r.payload}}))})}const a=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:r.payload})});if(!a.ok)throw new Error(`HTTP ${a.status}`);return a.json()}class Za{constructor(s){ce(this,"daemonId");ce(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Ce==null?void 0:Ce.readyState)===WebSocket.OPEN}get connectionState(){return(Ce==null?void 0:Ce.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return mt(this.daemonId,s,n)}async sendInput(s,n){return mt(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,Re&&(clearInterval(Re),Re=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await mt(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const o=await fetch(`data:image/jpeg;base64,${r.base64}`).then(a=>a.blob());Ee.emitScreenshot(this.daemonId,o)}}catch{}};n(),Re=setInterval(n,2e3)}stopScreenshots(s){Re&&(clearInterval(Re),Re=null)}}let Ae=null;function Qa(t){return(!Ae||Ae.daemonId!==t)&&(Ae=new Za(t)),Ae}function eo({children:t}){const s=c.useRef(Ut()),n=Ut();s.current=n;const{setUserName:r}=tt(),o=c.useRef(r);o.current=r;const[,a]=c.useState("disconnected"),i=c.useCallback((x,p)=>{a(x),et==null||et(x,p)},[]),u=c.useRef(null),l=c.useRef(),h=c.useRef(ps),d=c.useRef(!0);return c.useEffect(()=>{d.current=!0;function x(){var m,y;if(!d.current||((m=u.current)==null?void 0:m.readyState)===WebSocket.OPEN||((y=u.current)==null?void 0:y.readyState)===WebSocket.CONNECTING)return;i("connecting"),console.log(`[Standalone WS] Connecting to ${xs}...`);let g;try{g=new WebSocket(xs)}catch(I){console.error("[Standalone WS] Failed to create WebSocket:",I),p();return}u.current=g,g.onopen=()=>{if(!d.current){g.close();return}i("connected"),h.current=ps,console.log("[Standalone WS] Connected")},Ce=g,g.onmessage=I=>{var w;try{const v=JSON.parse(I.data);if((v.type==="command_result"||v.type==="error")&&v.requestId){const N=yt.get(v.requestId);N&&(yt.delete(v.requestId),v.type==="error"?N.reject(new Error(((w=v.data)==null?void 0:w.message)||"Command failed")):N.resolve(v.data));return}if(v.type==="pty_output"){Ee.emitPtyOutput(v.cliId,v.data);return}if(v.type==="status"||v.type==="initial_state"){const N=v.data;if(!N)return;const{injectEntries:L,markLoaded:f}=s.current,k=N.id||"standalone",S=Qa(k);Ee.register(k,S),Ee.setState(k,"connected"),i("connected",k),Ee.emitStatus(k,N);const j=xr(N,{daemonId:k});j.length>0&&L(j),f(),N.userName&&o.current&&o.current(N.userName)}}catch(v){console.error("[Standalone WS] Parse error:",v)}},g.onclose=()=>{d.current&&(Ae&&Ee.setState(Ae.daemonId,"disconnected"),i("disconnected"),u.current=null,p())},g.onerror=I=>{console.warn("[Standalone WS] Error, will reconnect:",I)}}function p(){if(!d.current)return;clearTimeout(l.current);const g=h.current;console.log(`[Standalone WS] Reconnecting in ${g}ms...`),l.current=setTimeout(()=>{h.current=Math.min(h.current*1.5,Xa),x()},g)}return x(),()=>{d.current=!1,clearTimeout(l.current),u.current&&(u.current.onclose=null,u.current.close(),u.current=null,Ce=null),Ae&&Ee.unregister(Ae.daemonId)}},[]),e.jsx(e.Fragment,{children:t})}function to({children:t}){const[s,n]=c.useState("disconnected"),[r,o]=c.useState(null);c.useEffect(()=>(et=(i,u)=>{n(i),u&&o(u)},()=>{et=null}),[]);const a=c.useMemo(()=>{const i=s==="connected",u=Ja(s),l={};return r&&(l[r]=u),l.standalone=u,{wsStatus:s,isConnected:i,connectionStates:l}},[s,r]);return e.jsx(yn,{connectionOverrides:a,children:e.jsx(eo,{children:t})})}const so=[{id:"dashboard",path:"/dashboard",icon:e.jsx(js,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(vs,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(Dt,{}),label:"Settings"}];function no({children:t}){const s=nt(),n=un(),[r,o]=c.useState(!1),[a,i]=c.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),u=d=>{s(d),o(!1)},l=()=>{i(d=>{const x=!d;try{localStorage.setItem("sidebar-collapsed",x?"1":"0")}catch{}return x})},h=d=>`nav-item${n.pathname.startsWith(d)?" active":""} cursor-pointer ${a?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${a?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>o(!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:()=>o(!1),onKeyDown:d=>d.key==="Escape"&&o(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${a?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!a&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>o(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:so.map(d=>e.jsxs("div",{className:h(d.path),id:`nav-${d.id}`,onClick:()=>u(d.path),title:a?d.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:d.icon}),!a&&d.label]},d.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${a?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:a?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(ft,{})}),!a&&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":""} ${a?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:a?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(ws,{})}),!a&&"About"]}),!a&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.4"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${a?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:a?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:a?"›":"‹"}),!a&&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 ro=[{icon:e.jsx(vs,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(He,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Cs,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(_e,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(ze,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(ft,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],ao=[{icon:e.jsx(Ms,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(js,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(Es,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Cn,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(kn,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Ns,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],oo=[{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 io(){return e.jsxs(gt,{icon:e.jsx(ws,{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.4"]}),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:ro.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:zs.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Us.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:Fs.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:ao.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:oo.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(Ot,{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(Pn,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function co(){const{ides:t}=tt(),s=t.find(x=>x.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=$e(),{userName:o}=tt(),[a,i]=c.useState(o||"");c.useEffect(()=>{o!==void 0&&i(o)},[o]);const u=x=>{const p=x.target.value.trim();s!=null&&s.id&&p!==o&&r(s.id,"set_user_name",{userName:p}).catch(console.error)},[l,h]=c.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),d=x=>{h(x);try{localStorage.setItem("adhdev_sound",x?"1":"0")}catch{}};return e.jsxs(gt,{icon:e.jsx(Dt,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(Mr,{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.4"]}),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(x=>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 ${x.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:x.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:x.type})]},x.type))})}),e.jsx(de,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Pr,{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(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:"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(Ur,{})]}),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(Jr,{})]})]})}),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(Lr,{}),e.jsx(De,{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:d})]})}),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(Sn,{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:a,onChange:x=>i(x.target.value),onBlur:u,onKeyDown:x=>{x.key==="Enter"&&x.currentTarget.blur()}})]})})})]})}zr();function hs(){const{ides:t}=tt(),s=t.find(n=>{var r;return n.daemonMode||((r=n.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(ut,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(ut,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(ut,{to:"/dashboard",replace:!0})}function lo(){return e.jsx(xn,{children:e.jsx(to,{children:e.jsx(Nn,{value:{sendCommand:mt,sendData:()=>!1},children:e.jsx(no,{children:e.jsxs(pn,{children:[e.jsx(ke,{path:"/dashboard",element:e.jsx(Ia,{})}),e.jsx(ke,{path:"/ide/:id",element:e.jsx(Pa,{})}),e.jsx(ke,{path:"/machine",element:e.jsx(hs,{})}),e.jsx(ke,{path:"/machines/:id",element:e.jsx(Ua,{})}),e.jsx(ke,{path:"/machines",element:e.jsx(hs,{})}),e.jsx(ke,{path:"/capabilities",element:e.jsx(Va,{})}),e.jsx(ke,{path:"/about",element:e.jsx(io,{})}),e.jsx(ke,{path:"/settings",element:e.jsx(co,{})}),e.jsx(ke,{path:"*",element:e.jsx(ut,{to:"/dashboard",replace:!0})})]})})})})})}or({connectionManager:Ee});hn(document.getElementById("root")).render(e.jsx(c.StrictMode,{children:e.jsx(lo,{})}));