@adhdev/daemon-standalone 0.7.31 → 0.7.35

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,68 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/terminal-CpvHTiWU.js","assets/vendor-tc3018Wt.js"])))=>i.map(i=>d[i]);
2
- var un=Object.defineProperty;var xn=(t,s,n)=>s in t?un(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var xe=(t,s,n)=>xn(t,typeof s!="symbol"?s+"":s,n);import{r as o,j as e,M as ms,a as fs,b as pn,c as hn,u as ot,t as mn,d as fn,e as gn,R as bn,f as gs,g as bs,h as yn,B as jn,i as vn,k as Ee,N as ft,l as wn}from"./vendor-tc3018Wt.js";import{_ as Nn}from"./terminal-CpvHTiWU.js";(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))r(a);new MutationObserver(a=>{for(const i of a)if(i.type==="childList")for(const c of i.addedNodes)c.tagName==="LINK"&&c.rel==="modulepreload"&&r(c)}).observe(document,{childList:!0,subtree:!0});function n(a){const i={};return a.integrity&&(i.integrity=a.integrity),a.referrerPolicy&&(i.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?i.credentials="include":a.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(a){if(a.ep)return;a.ep=!0;const i=n(a);fetch(a.href,i)}})();const ys=o.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}),js=o.createContext({injectEntries:()=>{},markLoaded:()=>{},getIdes:()=>[]});function qt(t){var n,r;let s=0;return"activeChat"in t&&(s+=4),(n=t.childSessions)!=null&&n.length&&(s+=2),t.workspace&&(s+=1),t.machine&&(s+=1),(r=t.agents)!=null&&r.length&&(s+=1),s}function Et(t,s,n){if(n.type!=="adhdev-daemon")return n;const r={...n},a=s.version??n.version??t.version,i=s.serverVersion??t.serverVersion??n.serverVersion,c=s.versionMismatch===!0||t.versionMismatch===!0;return a&&(r.version=a),i&&(r.serverVersion=i),a&&i&&a===i?(delete r.versionMismatch,delete r.serverVersion,r):((s.versionMismatch===!0||c&&a&&i&&a!==i)&&(r.versionMismatch=!0),r)}function kn(t,s){var c,x,l,p,u,b,g;const n=Date.now();if(s.length===0)return t.map(d=>({...d,_lastUpdate:n}));const r=new Map;for(const d of s)r.set(d.id,d);for(const d of t){const h=r.get(d.id);if(!h){r.set(d.id,{...d,_lastUpdate:n});continue}const w=qt(d),S=qt(h);if(w>S){const f=(c=d.chats)!=null&&c.length?d.chats:h.chats,m=Et(h,d,{...h,...d,chats:f,_lastUpdate:n});r.set(d.id,m)}else if(w<S){const f={};if(d.status&&d.status!==h.status&&(f.status=d.status),d.cdpConnected!==void 0&&(f.cdpConnected=d.cdpConnected),(x=d.chats)!=null&&x.length&&!((l=h.chats)!=null&&l.length)&&(f.chats=d.chats),d.machineNickname!==void 0&&d.machineNickname!==h.machineNickname&&(f.machineNickname=d.machineNickname),d.version!==void 0&&(f.version=d.version),d.serverVersion!==void 0&&(f.serverVersion=d.serverVersion),d.versionMismatch===!0&&(f.versionMismatch=!0),Object.keys(f).length>0){const m=Et(h,d,{...h,...f,_lastUpdate:h._lastUpdate});r.set(d.id,m)}}else{const f=d.timestamp||n,m=h._lastUpdate||h.timestamp||0;if(f>=m){const N=(p=d.chats)!=null&&p.length?d.chats:h.chats,T=Et(h,d,{...h,...d,chats:N,_lastUpdate:n});r.set(d.id,T)}else(u=d.chats)!=null&&u.length&&!((b=h.chats)!=null&&b.length)&&r.set(d.id,{...h,chats:d.chats})}}const a=new Set(t.map(d=>d.id)),i=new Set;for(const d of t){const h=d.daemonId||((g=d.id)==null?void 0:g.split(":")[0]);h&&i.add(h)}for(const[d,h]of r){const w=h.daemonId||d.split(":")[0];if(!i.has(w))continue;const S=n-(h._lastUpdate||h.timestamp||0);(h.transport==="pty"&&!a.has(d)&&S>1e4||h.transport==="acp"&&!a.has(d)&&S>1e4||h.transport==="cdp-page"&&!a.has(d)&&S>3e4)&&r.delete(d)}for(const[d,h]of r)n-(h._lastUpdate||h.timestamp||0)>3e5&&h.status!=="online"&&r.delete(d);return Array.from(r.values())}function Sn(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==s[n])return!1;return!0}function Cn({children:t,connectionOverrides:s}){const[n,r]=o.useState([]),[a,i]=o.useState({}),[c,x]=o.useState(!1),[l,p]=o.useState([]),[u,b]=o.useState(void 0),g=o.useRef(n);o.useEffect(()=>{g.current=n},[n]);const d=o.useCallback((N,T)=>{r(j=>{let k=!1;const v=j.map(y=>y.id!==N||y.chats===T?y:(k=!0,{...y,chats:T}));return k?v:j})},[]),h=o.useCallback(N=>{r(T=>{const j=T.length===0?N:kn(N,T);return Sn(T,j)?T:j})},[]),w=o.useCallback(()=>x(!0),[]),S=o.useMemo(()=>({injectEntries:h,markLoaded:w,getIdes:()=>g.current}),[h,w]),f=s,m=o.useMemo(()=>({ides:n,updateIdeChats:d,screenshotMap:a,setScreenshotMap:i,initialLoaded:c,toasts:l,setToasts:p,wsStatus:(f==null?void 0:f.wsStatus)??"connected",isConnected:(f==null?void 0:f.isConnected)??!0,connectionStates:(f==null?void 0:f.connectionStates)??{},connectionTransports:(f==null?void 0:f.connectionTransports)??{},showReconnected:(f==null?void 0:f.showReconnected)??!1,retryConnection:f==null?void 0:f.retryConnection,isP2PActive:(f==null?void 0:f.isP2PActive)??!1,p2pStates:(f==null?void 0:f.p2pStates)??{},userRole:f==null?void 0:f.userRole,userName:u,setUserName:b}),[n,d,a,c,l,f==null?void 0:f.wsStatus,f==null?void 0:f.isConnected,f==null?void 0:f.connectionStates,f==null?void 0:f.connectionTransports,f==null?void 0:f.showReconnected,f==null?void 0:f.retryConnection,f==null?void 0:f.isP2PActive,f==null?void 0:f.p2pStates,f==null?void 0:f.userRole,u]);return e.jsx(js.Provider,{value:S,children:e.jsx(ys.Provider,{value:m,children:t})})}function at(){return o.useContext(ys)}function Yt(){return o.useContext(js)}function vs(t){const{baseUrl:s,getToken:n,onUnauthorized:r}=t;function a(x){return x.startsWith("http")?x:`${s}${x.startsWith("/")?"":"/"}${x}`}function i(x){const l=n==null?void 0:n(),p=a(x),u=x.startsWith("http")?new URL(p):new URL(p,typeof window<"u"?window.location.origin:"http://localhost");return l&&u.searchParams.set("token",l),!x.startsWith("http")&&!s?`${u.pathname}${u.search}${u.hash}`:u.toString()}async function c(x,l={}){const p={"Content-Type":"application/json",...l.headers||{}},u=n==null?void 0:n();u&&(p.Authorization=`Bearer ${u}`);const b=a(x),g=await fetch(b,{...l,headers:p});if(g.status===401)throw r==null||r(),new Error("Unauthorized");if(!g.ok){const d=await g.json().catch(()=>({error:g.statusText}));throw new Error(d.error||`API Error: ${g.status}`)}return g.json()}return{getDaemons:()=>c("/api/v1/daemons"),getDaemonStatus:x=>c(`/api/v1/daemons/${x}/status`),sendCommand:(x,l,p={})=>c(`/api/v1/daemons/${x}/command`,{method:"POST",body:JSON.stringify({type:l,payload:p})}),execTerminal:(x,l,p)=>c(`/api/v1/daemons/${x}/terminal`,{method:"POST",body:JSON.stringify({command:l,name:p})}),sendAgentMessage:(x,l,p)=>c(`/api/v1/shortcuts/${x}/chat`,{method:"POST",body:JSON.stringify({agentType:l,message:p})}),getAgentStatus:x=>c(`/api/v1/shortcuts/${x}/status`),approveAgent:(x,l,p)=>c(`/api/v1/shortcuts/${x}/approve`,{method:"POST",body:JSON.stringify({agentType:l,action:p?"approve":"reject"})}),getMuxState:x=>c(`/api/v1/mux/${encodeURIComponent(x)}/state`),getMuxSocketInfo:x=>c(`/api/v1/mux/${encodeURIComponent(x)}/socket-info`),controlMux:(x,l,p={})=>c(`/api/v1/mux/${encodeURIComponent(x)}/control`,{method:"POST",body:JSON.stringify({type:l,payload:p})}),getMuxEventsUrl:x=>i(`/api/v1/mux/${encodeURIComponent(x)}/events`),getRuntimeEventsUrl:x=>i(`/api/v1/runtime/${encodeURIComponent(x)}/events`),request:c}}const In=vs({baseUrl:"http://localhost:3847"}),Mn=o.createContext(In);function Tn({client:t,children:s}){return e.jsx(Mn.Provider,{value:t,children:s})}const En={sendCommand:async()=>{throw new Error("TransportContext not initialized")}},ws=o.createContext(En);function An({value:t,children:s}){return e.jsx(ws.Provider,{value:t,children:s})}function De(){return o.useContext(ws)}const le={size:18};function Ns({size:t=le.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 ks({size:t=le.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 Rn({size:t=le.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 _n({size:t=le.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 Ln({size:t=le.size,className:s}){return e.jsx("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",className:s,children:e.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}function vt({size:t=le.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 $n({size:t=le.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 zt({size:t=le.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 Ss({size:t=le.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 Cs({size:t=le.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 qe({size:t=le.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 Le({size:t=le.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 Is({size:t=le.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 Pn({size:t=le.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=le.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 Ms({size:t=le.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 Ft({size:t=le.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 Ye({size:t=le.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 Ts({size:t=le.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 Es({size:t=le.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 Dn({size:t=le.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 Ht({size:t=le.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 As({size:t=le.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 Rs({size:t=le.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 Bn({size:t=le.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 Wn({size:t=le.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 _s({size:t=le.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 On({size:t=le.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 Kn({size:t=le.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 zn({size:t=le.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 Fn({size:t=le.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 Hn(t){const n=t.split(`
3
- `).map(x=>{if(!x.includes("\r"))return x;const l=x.split("\r").map(b=>b.trim()).filter(Boolean);if(l.length===0)return"";const p=l.filter(b=>b.startsWith("⏺"));if(p.length>0)return p[p.length-1];const u=l.filter(b=>!(/^[❯›>]\s*$/.test(b)||/^[^a-zA-Z0-9\s]\s*\S+[…\.]{1,3}\s*$/.test(b)&&b.length<40||/^[╭╰│├╮╯─═]+$/.test(b)));return u.length>0?u[u.length-1]:l[l.length-1]}).join(`
4
- `).split(`
5
- `),r={},a=[];let i=!1;for(const x of n){const l=x.trim();if(l===""){i=!1,a.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(x)){const u=x.match(/^[⏺●·]\s*([A-Za-z][A-Za-z0-9_]*)\s*[\(\[]/);if(u)r[u[1]]=(r[u[1]]||0)+1;else{const b=x.replace(/^[⏺●·⏵]\s*/,"").trim().slice(0,40);b&&(r[b]=(r[b]||0)+1)}i=!0;continue}if(/^[\s]*[╭╰│├╮╯]/.test(x)||/^[╭╰│├╮╯─]+/.test(l)||/^\s+[⊙✓✗○◎▸►✦]/.test(x)||i&&/^\s{2,}/.test(x))continue;i=!1;const p=x.replace(/^❯\s+/,"");a.push(p)}const c=a.join(`
6
- `).replace(/\n{3,}/g,`
7
-
8
- `).trim();return{toolCounts:r,textContent:c,hasTools:Object.keys(r).length>0}}function Pt(t){return t?new Date(t).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}):""}function Un(t){return/[`*_#[\]()>-]|https?:\/\/|\n\s*[-*]\s|\n\s*\d+\.\s|\|/.test(t)}function Ve(t,s){const n=t,r=typeof n.content=="string"?n.content:Array.isArray(n.content)?n.content.map(i=>(i==null?void 0:i.text)||"").join(`
9
- `):String(n.content||"");return[n.id?`id:${n.id}`:"",n._localId?`local:${n._localId}`:"",n._turnKey?`turn:${n._turnKey}`:"",typeof n.index=="number"?`msgIndex:${n.index}`:"",n.timestamp?`ts:${n.timestamp}`:"",n.role?`role:${n.role}`:"",r?`content:${r.slice(0,80)}`:"",`fallback:${s}`].filter(Boolean).join("|")}const Xt=700,Vn=o.memo(function({log:s}){return e.jsxs("div",{className:"self-center chat-msg-action",children:[e.jsx(ms,{remarkPlugins:[fs],children:s.text}),e.jsx("span",{className:"action-time",children:Pt(s.timestamp)})]})},(t,s)=>t.log===s.log),qn=o.memo(function({message:s,receivedAt:n,agentName:r,userName:a,isCliMode:i,isExpanded:c,isTextExpanded:x,onToggleExpanded:l,onToggleTextExpanded:p}){var T;const u=(s.role||"").toLowerCase(),b=u==="user"||u==="human",g=s.kind||(u==="tool"?"tool":"standard"),d=typeof s.content=="string"?s.content:(s.content||[]).map(j=>j.text||"").join(`
10
- `);if(g==="thought"){const j=((T=s.meta)==null?void 0:T.label)||"Thought";return e.jsxs("div",{className:"self-start chat-msg-thought",children:[e.jsxs("div",{className:"chat-msg-header",children:[e.jsx(Bn,{size:13}),e.jsx("span",{children:j})]}),e.jsx("div",{className:"chat-msg-body",children:d})]})}if(g==="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:d.split(`
11
- `)[0].slice(0,80)})]});if(g==="terminal"){const j=s.meta||{},k=j.isRunning?"⏳":"✅",v=j.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:k}),e.jsx("span",{children:v})]}),e.jsx("pre",{className:"chat-msg-body",children:d})]})}if(g==="system")return e.jsx("div",{className:"self-center chat-msg-system",children:d.slice(0,100)});const h=!b&&i?Hn(d):null,w=h?h.textContent:d,S=h?Object.entries(h.toolCounts):[],f=i&&!b&&!c&&w.length>Xt,m=c?d:f&&!x?w.slice(0,Xt):w,N=Un(m);return e.jsxs("div",{className:`max-w-[88%] min-w-0 flex flex-col gap-1 ${b?"self-end":"self-start"}`,children:[S.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 items-center mb-0.5",children:[S.map(([j,k])=>e.jsxs("span",{className:"chat-tool-badge",children:["⏺ ",j,k>1?` ×${k}`:""]},j)),(h==null?void 0:h.hasTools)&&e.jsx("button",{onClick:l,className:"text-[10px] text-text-muted px-1 py-px opacity-50",children:c?"Collapse":"Original"}),!w&&n!=null&&e.jsx("span",{className:"text-[10px] opacity-35 ml-0.5",children:Pt(n)})]}),(w||b)&&e.jsxs("div",{className:`chat-bubble ${b?"chat-bubble-user":"chat-bubble-assistant"}`,children:[e.jsxs("div",{className:`chat-bubble-header ${w?"mb-1.5":"mb-0"}`,children:[e.jsx("span",{className:"chat-sender",children:b?a||"You":r}),n!=null&&e.jsx("span",{className:"chat-time",children:Pt(n)})]}),w&&e.jsx("div",{className:"chat-markdown",children:N?e.jsx(ms,{remarkPlugins:[fs,pn,hn],children:m}):e.jsx("div",{style:{whiteSpace:"pre-wrap"},children:m})}),f&&e.jsx("button",{onClick:p,className:"mt-1.5 text-[11px] font-semibold text-[var(--accent-primary)] p-0 opacity-80",children:x?"Collapse ↑":`Show more (${Math.round(w.length/100)*100} chars) ↓`})]})]})},(t,s)=>t.message===s.message&&t.receivedAt===s.receivedAt&&t.agentName===s.agentName&&t.userName===s.userName&&t.isCliMode===s.isCliMode&&t.isExpanded===s.isExpanded&&t.isTextExpanded===s.isTextExpanded),Yn=o.forwardRef(function({messages:s,actionLogs:n,agentName:r="Agent",userName:a,isCliMode:i=!1,isWorking:c=!1,contextKey:x="",receivedAtMap:l={},emptyState:p,onLoadMore:u,isLoadingMore:b,hasMoreHistory:g,hiddenLiveCount:d=0,loadError:h},w){var te;const S=o.useRef(null),f=o.useRef(null),m=o.useRef(0),N=o.useRef(""),T=o.useRef(!1),j=o.useRef(null),[k,v]=o.useState(new Set),[y,_]=o.useState(new Set),P=o.useRef(!1),W=()=>{const Y=S.current;return Y?Y.scrollHeight-Y.scrollTop-Y.clientHeight<200:!0},M=o.useCallback((Y="auto")=>{const se=S.current;se&&se.scrollTo({top:se.scrollHeight,behavior:Y})},[]),E=o.useCallback((Y="auto")=>{j.current!=null&&cancelAnimationFrame(j.current),j.current=requestAnimationFrame(()=>{j.current=null,M(Y)})},[M]),L=s.length>0?`${s.length}:${(((te=s[s.length-1])==null?void 0:te.content)||"").length}`:"0:0";o.useEffect(()=>{const Y=!T.current,se=N.current!==x;if(N.current=x,Y||se){T.current=!0,P.current=!1,E("auto"),m.current=s.length;return}s.length>m.current?P.current||E("auto"):W()&&!P.current&&E("auto"),m.current=s.length},[L,x,c,s.length,E]),o.useEffect(()=>()=>{j.current!=null&&cancelAnimationFrame(j.current)},[]),o.useImperativeHandle(w,()=>({scrollToBottom:(Y="smooth")=>{M(Y)}}),[M]),o.useEffect(()=>{const Y=S.current;if(!Y)return;let se;const ee=()=>{clearTimeout(se),se=setTimeout(()=>{P.current=!W()},50)};return Y.addEventListener("scroll",ee,{passive:!0}),()=>{Y.removeEventListener("scroll",ee),clearTimeout(se)}},[]);const O=o.useRef(0),C=o.useRef(!1);o.useEffect(()=>{const Y=S.current;if(!Y||!C.current||O.current===0)return;const se=Y.scrollHeight-O.current;se>0&&(Y.scrollTop=se),O.current=0,C.current=!1},[s.length]);const V=()=>{const Y=S.current;Y&&(O.current=Y.scrollHeight),C.current=!0,u==null||u()},Q=o.useMemo(()=>{const Y=s.map((B,$)=>({type:"message",data:B,index:$,ts:B.receivedAt||l[Ve(B,$)]||0}));if(!n||n.length===0)return Y;const se=[...n].sort((B,$)=>B.timestamp-$.timestamp).map((B,$)=>({type:"action",data:B,index:$,ts:B.timestamp})),ee=[];let ie=0;for(const B of Y){for(;ie<se.length&&B.ts>0&&se[ie].ts<B.ts;)ee.push(se[ie++]);ee.push(B)}for(;ie<se.length;)ee.push(se[ie++]);return ee},[s,n,l]),Z=d>0||!!g,G=d>0?`↑ Show ${Math.min(d,80)} earlier messages${d>80?` (${d} hidden)`:""}`:h?`↻ ${h}`:"↑ Load older messages";return e.jsxs("div",{ref:S,"data-chat-scroll":!0,className:"chat-container",children:[b&&e.jsx("div",{className:"text-center py-3 text-text-muted text-xs opacity-60 animate-pulse",children:"Loading older messages..."}),Z&&!b&&e.jsx("div",{className:"text-center py-2",children:e.jsx("button",{onClick:V,className:`text-[11px] rounded-xl px-4 py-1.5 cursor-pointer border transition-all ${h&&d===0?"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})}),Q.length===0&&!Z&&(p||e.jsx("div",{className:"text-center mt-16 opacity-20 text-[13px]",children:"Waiting for messages..."})),Q.map(Y=>{if(Y.type==="action"){const D=Y.data;return e.jsx(Vn,{log:D},`action-${Y.index}`)}const se=Y.data,ee=Y.index,ie=Ve(se,ee),B=se.receivedAt||l[ie],$=`${x}-${ie}`,A=k.has($),R=y.has($);return e.jsx(qn,{message:se,receivedAt:B,agentName:r,userName:a,isCliMode:i,isExpanded:A,isTextExpanded:R,onToggleExpanded:()=>v(D=>{const H=new Set(D);return A?H.delete($):H.add($),H}),onToggleTextExpanded:()=>_(D=>{const H=new Set(D);return R?H.delete($):H.add($),H})},`msg-${ie}`)}),c&&e.jsx("div",{className:"self-start chat-typing-wrapper",children:e.jsxs("div",{className:"typing-indicator",children:[e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("div",{className:"dot"}),e.jsx("span",{className:"text-[11px] text-text-muted ml-1",children:"Agent generating..."})]})}),e.jsx("div",{className:"min-h-10",ref:f})]})}),Xn=o.memo(Yn,(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.hiddenLiveCount===s.hiddenLiveCount&&t.loadError===s.loadError);let Gt=!1;const Ls=o.forwardRef(({onInput:t,onResize:s,fontSize:n=13,readOnly:r=!1},a)=>{const i=o.useRef(null),[c,x]=o.useState(null),l=o.useRef([]),p=o.useRef(!1),u=o.useRef(!1),b=o.useRef(!1),g=()=>{const d=i.current;if(d){p.current&&(d.clear(),p.current=!1);for(const h of l.current)d.write(h);l.current=[],u.current&&(d.fit(),u.current=!1),b.current&&(d.bumpResize(),b.current=!1)}};return o.useImperativeHandle(a,()=>({write:d=>{i.current?i.current.write(d):l.current.push(d)},clear:()=>{i.current?i.current.clear():(l.current=[],p.current=!0)},fit:()=>{i.current?i.current.fit():u.current=!0},bumpResize:()=>{i.current?i.current.bumpResize():b.current=!0}}),[]),o.useEffect(()=>{if(!c)return;const d=requestAnimationFrame(()=>{var h;g(),(h=i.current)==null||h.fit()});return()=>cancelAnimationFrame(d)},[c]),o.useEffect(()=>{let d=!1;return Nn(()=>import("./terminal-CpvHTiWU.js").then(h=>h.i),__vite__mapDeps([0,1])).then(h=>{Gt||(Gt=!0,console.info("[CliTerminal] renderer module loaded: ghostty-web")),d||x(()=>h.GhosttyTerminalView)}).catch(h=>{console.error("[CliTerminal] failed to load terminal renderer",h)}),()=>{d=!0}},[]),c?e.jsx(c,{ref:i,onInput:t,onResize:s,fontSize:n,readOnly:r,className:"w-full h-full rounded-lg overflow-hidden"}):e.jsx("div",{className:"w-full h-full rounded-lg overflow-hidden animate-pulse",style:{background:"#0f1117"}})});Ls.displayName="CliTerminal";function dt({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 Jt({value:t,max:s,label:n,color:r="#8b5cf6",detail:a,compact:i=!1}){const c=s>0?Math.min(Math.round(t/s*100),100):0,x=c>85?"#ef4444":c>60?"var(--status-warning)":r;return i?e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-0.5",children:[e.jsx("span",{className:"text-[9px] text-text-muted uppercase tracking-wide font-semibold",children:n}),e.jsxs("span",{className:"text-[10px] text-text-secondary font-semibold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-500",style:{width:`${c}%`,background:x}})})]}):e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between mb-1.5",children:[e.jsx("span",{className:"text-[11px] text-text-secondary font-medium",children:n}),e.jsxs("span",{className:"text-[13px] text-text-primary font-bold",children:[c,"%"]})]}),e.jsx("div",{className:"h-1.5 bg-white/[0.04] rounded-sm overflow-hidden",children:e.jsx("div",{className:"h-full rounded-sm transition-[width] duration-[600ms]",style:{width:`${c}%`,background:`linear-gradient(90deg, ${x}, ${x}cc)`}})}),a&&e.jsx("div",{className:"text-[10px] text-text-muted mt-0.5",children:a})]})}function Gn({cursorPos:t,viewportRef:s,imgRef:n}){var m;if(!t||!n.current)return null;const r=n.current,a=r.getBoundingClientRect(),i=(m=s.current)==null?void 0:m.getBoundingClientRect();if(!i)return null;const c=r.naturalWidth||a.width,x=r.naturalHeight||a.height,l=c/x,p=a.width/a.height;let u,b,g,d;l>p?(u=a.width,b=a.width/l,g=0,d=(a.height-b)/2):(b=a.height,u=a.height*l,g=(a.width-u)/2,d=0);const h=a.left-i.left+g+u*t.nx,w=a.top-i.top+d+b*t.ny,S=Math.max(8,Math.min(i.width-8,h)),f=Math.max(8,Math.min(i.height-8,w));return e.jsxs("div",{style:{position:"absolute",left:S-8,top:f-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 Jn({inputMode:t,onToggleInputMode:s,isImeOpen:n,setIsImeOpen:r,isMenuOpen:a,setIsMenuOpen:i,imeText:c,setImeText:x,handleImeSubmit:l,isConnActive:p,zoom:u,isMobile:b,mobileFillZoom:g,onZoomOut:d,onZoomReset:h,onZoomIn:w,transportType:S,screenshotUsage:f,lastActionStatus:m}){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),i(!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:c,autoFocus:!0,onTouchStart:N=>N.stopPropagation(),onChange:N=>x(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:()=>{i(N=>!N),r(!1)},className:`w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer ${a?"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:p?"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:p?"#22c55e":"#eab308",boxShadow:p?"0 0 4px #22c55e80":"0 0 4px #eab30880"}}),e.jsx("span",{className:"text-[8px] font-extrabold",style:{color:p?"#22c55e":"#eab308"},children:p?"Connected":"WS"})]}),u>1&&e.jsxs("span",{className:"text-[8px] font-bold text-indigo-400",children:[Math.round(u*100),"%"]}),S==="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"}),S==="relay"&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 12%, transparent)"},title:"TURN relay in use",children:"Relay"}),f&&f.dailyBudgetMinutes>0&&e.jsx("span",{className:"text-[8px] font-bold px-1 py-0.5 rounded",style:{color:f.budgetExhausted?"#ef4444":"#c4b5fd",background:f.budgetExhausted?"rgba(239,68,68,0.1)":"rgba(139,92,246,0.14)"},title:"Daily TURN relay usage",children:f.budgetExhausted?"TURN blocked":`TURN ${f.dailyUsedMinutes}/${f.dailyBudgetMinutes}m`}),m&&e.jsx("span",{className:"text-[8px] text-neutral-500 font-semibold max-w-[100px] overflow-hidden text-ellipsis whitespace-nowrap",children:m})]})]}),a&&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: ",u<=(b?g:1)+.01?b?"FILL":"FIT":`${Math.round(u*100)}%`]}),e.jsxs("div",{style:{display:"flex",gap:4},children:[e.jsx("button",{onClick:N=>{N.stopPropagation(),d()},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(),h()},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:b?"FILL":"FIT"}),e.jsx("button",{onClick:N=>{N.stopPropagation(),w()},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 Zn({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] font-medium",style:{color:"var(--status-warning)",opacity:.8},children:"TURN relay active"})]})}function Qn(){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 Zt(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 it(t,s){const n=o.useRef(null),r=o.useRef(0);o.useEffect(()=>{if(!Qn())return;r.current+=1;const a=n.current;if(!a){console.debug(`[render-trace] ${t}#${r.current}`,{changed:["mount"],snapshot:Object.fromEntries(Object.entries(s).map(([c,x])=>[c,Zt(x)]))}),n.current=s;return}const i=Object.keys({...a,...s}).filter(c=>!Object.is(a[c],s[c]));i.length>0&&console.debug(`[render-trace] ${t}#${r.current}`,{changed:i,snapshot:Object.fromEntries(i.map(c=>[c,Zt(s[c])]))}),n.current=s})}function er({containerRef:t,viewportRef:s,imgRef:n,inputMode:r,setInputMode:a,minZoom:i,zoomRef:c,panXRef:x,panYRef:l,setPanX:p,setPanY:u,setZoom:b,lastWheelTimeRef:g,onAction:d,setLastActionStatus:h,spawnRippleFromNormalized:w,clampPan:S,isMobile:f,mobileFillZoom:m}){const[N,T]=o.useState(null),j=o.useRef(null),k=o.useRef(null),v=o.useRef(null),y=o.useRef(!1),_=o.useRef(null),P=o.useRef(0),W=o.useRef(null),M=o.useRef(1),E=o.useRef({x:0,y:0}),L=o.useRef(!1),O=o.useRef(r),C=o.useRef(d),V=()=>{if(j.current)return;const G={nx:.5,ny:.5};j.current=G,T(G)};return o.useEffect(()=>{O.current=r,r==="mouse"&&V()},[r]),o.useEffect(()=>{C.current=d},[d]),o.useEffect(()=>{const G=t.current;if(!G)return;const te=$=>{if(!n.current)return null;const A=n.current.getBoundingClientRect();return!A.width||!A.height?null:{nx:Math.max(0,Math.min(1,($.clientX-A.left)/A.width)),ny:Math.max(0,Math.min(1,($.clientY-A.top)/A.height))}},Y=($,A)=>{if(!n.current)return{dnx:0,dny:0};const R=n.current,D=R.getBoundingClientRect(),H=R.naturalWidth||D.width,U=R.naturalHeight||D.height,ae=H/U,de=D.width/D.height;let ce,re;return ae>de?(ce=D.width,re=D.width/ae):(re=D.height,ce=D.height*ae),{dnx:$/ce,dny:A/re}},se=($,A,R)=>{if(R<=1.05)return;const D=-($-.5)*100,H=-(A-.5)*100,U=S(D,H,R);(Math.abs(U.x-x.current)>.1||Math.abs(U.y-l.current)>.1)&&(p(U.x),u(U.y),x.current=U.x,l.current=U.y)},ee=$=>{const A=s.current;if(A&&$.target instanceof Node&&A.contains($.target))$.preventDefault();else return;if($.touches.length===1){const R=$.touches[0];k.current={x:R.clientX,y:R.clientY,time:Date.now()},v.current={x:R.clientX,y:R.clientY},L.current||(y.current=!1),_.current=setTimeout(()=>{if(!y.current&&!L.current)if(y.current=!0,O.current==="mouse"){const D=j.current||{nx:.5,ny:.5};h("Right Click"),w(D.nx,D.ny,"right"),C.current("input_click",{...D,button:"right"}).catch(()=>{})}else{const D=te(R);D&&(h("Right Click"),w(D.nx,D.ny,"right"),C.current("input_click",{...D,button:"right"}).catch(()=>{}))}},500);return}if($.touches.length===2){_.current&&clearTimeout(_.current),y.current=!0,L.current=!0;const R=$.touches[1].clientX-$.touches[0].clientX,D=$.touches[1].clientY-$.touches[0].clientY;W.current=Math.sqrt(R*R+D*D),M.current=c.current,E.current={x:($.touches[0].clientX+$.touches[1].clientX)/2,y:($.touches[0].clientY+$.touches[1].clientY)/2}}},ie=$=>{const A=s.current;if(A&&$.target instanceof Node&&A.contains($.target)&&$.preventDefault(),$.touches.length===1&&v.current){const R=$.touches[0],D=R.clientX-v.current.x,H=R.clientY-v.current.y;if(!y.current&&k.current){const U=R.clientX-k.current.x,ae=R.clientY-k.current.y;Math.sqrt(U*U+ae*ae)>8&&(y.current=!0,_.current&&clearTimeout(_.current))}if(y.current)if(O.current==="mouse"){const U=Y(D,H),ae=j.current||{nx:.5,ny:.5},de=Math.max(0,Math.min(1,ae.nx+U.dnx)),ce=Math.max(0,Math.min(1,ae.ny+U.dny));j.current={nx:de,ny:ce},T({nx:de,ny:ce}),h(`Cursor: ${Math.round(de*100)}%, ${Math.round(ce*100)}%`),se(de,ce,c.current);const re=Date.now();re-g.current>=30&&(g.current=re,C.current("input_mouseMoved",{nx:de,ny:ce}).catch(()=>{}))}else if(c.current>1){const U=s.current;if(U){const ae=U.clientWidth,de=U.clientHeight,ce=x.current+D/ae*100,re=l.current+H/de*100,K=S(ce,re,c.current);p(K.x),u(K.y),x.current=K.x,l.current=K.y}}else{const U=te(R);if(U){const ae=Date.now();ae-g.current>=40&&(g.current=ae,h("Scroll"),C.current("input_wheel",{nx:U.nx,ny:U.ny,deltaX:Math.round(-D*2.5),deltaY:Math.round(-H*2.5)}).catch(()=>{}))}}v.current={x:R.clientX,y:R.clientY};return}if($.touches.length===2&&W.current!==null){const R=$.touches[1].clientX-$.touches[0].clientX,D=$.touches[1].clientY-$.touches[0].clientY,U=Math.sqrt(R*R+D*D)/W.current,ae=($.touches[0].clientX+$.touches[1].clientX)/2,de=($.touches[0].clientY+$.touches[1].clientY)/2,ce=ae-E.current.x,re=de-E.current.y,K=Math.abs(U-1)>.03;if(O.current==="mouse"){if(K){const X=Math.max(i,Math.min(5,M.current*U));b(X),c.current=X}else if(Math.abs(ce)>2||Math.abs(re)>2){const X=j.current||{nx:.5,ny:.5},F=Date.now();F-g.current>=30&&(g.current=F,h("Scroll"),C.current("input_wheel",{nx:X.nx,ny:X.ny,deltaX:Math.round(-ce*3),deltaY:Math.round(-re*3)}).catch(()=>{}))}}else{const X=Math.max(i,Math.min(5,M.current*U));b(X),c.current=X;const F=s.current;if(F&&X>1){const I=F.clientWidth,q=F.clientHeight,z=x.current+ce/I*100,ne=l.current+re/q*100,J=S(z,ne,X);p(J.x),u(J.y),x.current=J.x,l.current=J.y}}E.current={x:ae,y:de}}},B=$=>{var A;if(_.current&&clearTimeout(_.current),W.current=null,$.touches.length===1&&L.current){const R=$.touches[0];k.current={x:R.clientX,y:R.clientY,time:Date.now()},v.current={x:R.clientX,y:R.clientY},y.current=!0;return}if($.touches.length===0){if(L.current){L.current=!1,y.current=!1;return}if($.changedTouches.length===1&&!y.current){const R=$.changedTouches[0],D=Date.now(),H=D-(((A=k.current)==null?void 0:A.time)||0);if(H<60||H>400){y.current=!1;return}if(k.current){const U=R.clientX-k.current.x,ae=R.clientY-k.current.y;if(Math.sqrt(U*U+ae*ae)>12){y.current=!1;return}}if(O.current==="mouse"){const U=j.current||te(R);U&&(h(`Click: ${Math.round(U.nx*100)}%, ${Math.round(U.ny*100)}%`),w(U.nx,U.ny,"left"),C.current("input_click",{...U}).catch(()=>{}))}else{const U=te(R);if(!U)return;D-P.current<300?(h("Double tap"),w(U.nx,U.ny,"double"),C.current("input_click",{...U,clickCount:2}).catch(()=>{}),P.current=0):(h(`Tap: ${Math.round(U.nx*100)}%, ${Math.round(U.ny*100)}%`),w(U.nx,U.ny,"left"),C.current("input_click",{...U}).catch(()=>{}),P.current=D)}}y.current=!1}};return G.addEventListener("touchstart",ee,{passive:!1}),G.addEventListener("touchmove",ie,{passive:!1}),G.addEventListener("touchend",B,{passive:!1}),()=>{G.removeEventListener("touchstart",ee),G.removeEventListener("touchmove",ie),G.removeEventListener("touchend",B),_.current&&clearTimeout(_.current)}},[t,s,n,i,c,x,l,p,u,b,g,h,w,S]),{cursorPos:N,cursorPosRef:j,handleToggleInputMode:()=>{a(G=>{const te=G==="touch"?"mouse":"touch";return te==="mouse"&&V(),te})},handleZoomReset:()=>{const G=f?m:1;b(G),c.current=G,p(0),u(0),x.current=0,l.current=0}}}function tr({onAction:t,addLog:s,connState:n,connScreenshot:r,screenshotUsage:a,transportType:i}){const c=o.useRef(null),x=o.useRef(null),l=o.useRef(null),[p,u]=o.useState(null),[b,g]=o.useState(""),[,d]=o.useState(!1),[h,w]=o.useState([]),S=o.useRef(0),[f,m]=o.useState(!1),[N,T]=o.useState(!1),j=typeof window<"u"&&window.matchMedia("(max-width: 768px)").matches,[k,v]=o.useState(j?"mouse":"touch"),[y,_]=o.useState(1),P=o.useRef(!1),[W,M]=o.useState(1),[E,L]=o.useState(0),[O,C]=o.useState(0);it("RemoteView",{connState:n,hasScreenshot:!!r,inputMode:k,zoom:W,panX:E,panY:O,isMenuOpen:f,isImeOpen:N});const V=o.useRef(0),Q=o.useRef(W),Z=o.useRef(E),G=o.useRef(O);o.useEffect(()=>{Q.current=W},[W]),o.useEffect(()=>{Z.current=E},[E]),o.useEffect(()=>{G.current=O},[O]),o.useEffect(()=>{var K;(K=c.current)==null||K.focus()},[]);const te=n==="connected",Y=r,se=te?"Connected. Waiting for first frame...":n==="connecting"?"Connecting to Host...":"Reconnecting to Host...",ee=te?"The remote stream is warming up":"Waiting for the remote stream to catch up";o.useEffect(()=>{if(!j||P.current||!Y)return;const K=l.current,X=x.current;if(!K||!X)return;const F=()=>{const I=X.clientWidth,q=X.clientHeight,z=K.naturalWidth,ne=K.naturalHeight;if(!z||!ne||!I||!q)return;const J=Math.min(I/z,q/ne),oe=Math.max(I/z,q/ne)/J;oe>1.01&&(_(oe),M(oe),Q.current=oe),P.current=!0};K.complete&&K.naturalWidth?F():K.addEventListener("load",F,{once:!0})},[Y,j]);const ie=.5;o.useEffect(()=>{W<=ie&&(L(0),C(0))},[W,ie]);const B=(K,X,F)=>{if(F<=ie)return{x:0,y:0};const I=(F-1)/(2*F)*100,q=(F-1)/(2*F)*100;return{x:Math.max(-I,Math.min(I,K)),y:Math.max(-q,Math.min(q,X))}},$=(K,X)=>{if(!l.current)return null;const F=l.current.getBoundingClientRect();return!F.width||!F.height?null:{nx:Math.max(0,Math.min(1,(K-F.left)/F.width)),ny:Math.max(0,Math.min(1,(X-F.top)/F.height))}},A=(K,X,F)=>{const I=x.current;if(!I)return;const q=I.getBoundingClientRect(),z=++S.current;w(ne=>[...ne,{id:z,x:K-q.left,y:X-q.top,type:F}]),setTimeout(()=>w(ne=>ne.filter(J=>J.id!==z)),600)},R=(K,X,F)=>{const I=l.current,q=x.current;if(!I||!q)return;const z=I.getBoundingClientRect(),ne=q.getBoundingClientRect(),J=I.naturalWidth||z.width,ge=I.naturalHeight||z.height,oe=J/ge,Te=z.width/z.height;let Se,Ce,He,$e;oe>Te?(Se=z.width,Ce=z.width/oe,He=0,$e=(z.height-Ce)/2):(Ce=z.height,Se=z.height*oe,He=(z.width-Se)/2,$e=0);const It=z.left-ne.left+He+Se*K,Mt=z.top-ne.top+$e+Ce*X,ct=++S.current;w(Ge=>[...Ge,{id:ct,x:It,y:Mt,type:F}]),setTimeout(()=>w(Ge=>Ge.filter(Tt=>Tt.id!==ct)),600)},D=async K=>{var F;const X=$(K.clientX,K.clientY);if(X){u(`Click: ${Math.round(X.nx*100)}%, ${Math.round(X.ny*100)}%`),A(K.clientX,K.clientY,"left"),(F=c.current)==null||F.focus();try{const I=await t("input_click",{nx:X.nx,ny:X.ny});I!=null&&I.success||s(`❌ Click failed: ${I==null?void 0:I.error}`)}catch(I){s(`❌ Click error: ${I.message||I}`)}}},H=async(K,X,F,I=0)=>{try{await t("input_key",{type:F?"char":"keyDown",key:K,code:X,text:F?K:void 0,unmodifiedText:F?K:void 0,modifiers:I})}catch(q){s(`❌ Key error: ${q.message||q}`)}},U=async K=>{if(K.target.tagName==="INPUT")return;["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Backspace","Tab","Enter","Escape"].includes(K.key)&&K.preventDefault();let F=0;K.altKey&&(F|=1),K.ctrlKey&&(F|=2),K.metaKey&&(F|=4),K.shiftKey&&(F|=8),u(`Key: ${K.key}`),await H(K.key,K.code,K.key.length===1,F)},ae=async K=>{if(K.key==="Enter"){if(K.nativeEvent.isComposing)return;if(b){const X=b;g(""),u(`IME Sent: ${X}`);try{const F=await t("input_type",{text:X});F!=null&&F.success||s(`❌ IME error: ${F==null?void 0:F.error}`)}catch(F){s(`❌ IME error: ${F.message}`)}}else u("Key: Enter"),await H("Enter","Enter",!1)}};o.useEffect(()=>{const K=c.current;if(!K)return;const X=F=>{var I;if((I=l.current)!=null&&I.contains(F.target)){F.preventDefault();const q=Date.now();if(q-V.current<40)return;V.current=q;const z=$(F.clientX,F.clientY);if(!z)return;u(`Scroll: ${Math.round(F.deltaY)}`),t("input_wheel",{nx:z.nx,ny:z.ny,deltaX:Math.round(F.deltaX),deltaY:Math.round(F.deltaY)}).catch(()=>{})}};return K.addEventListener("wheel",X,{passive:!1}),()=>K.removeEventListener("wheel",X)},[t]);const{cursorPos:de,handleToggleInputMode:ce,handleZoomReset:re}=er({containerRef:c,viewportRef:x,imgRef:l,inputMode:k,setInputMode:v,minZoom:ie,zoomRef:Q,panXRef:Z,panYRef:G,setPanX:L,setPanY:C,setZoom:M,lastWheelTimeRef:V,onAction:t,setLastActionStatus:u,spawnRippleFromNormalized:R,clampPan:B,isMobile:j,mobileFillZoom:y});return e.jsxs("div",{ref:c,className:"flex-1 flex flex-col bg-black relative overflow-hidden outline-none touch-none",onKeyDown:U,onContextMenu:K=>K.preventDefault(),onFocus:()=>d(!0),onBlur:()=>d(!1),tabIndex:0,children:[e.jsxs("div",{ref:x,className:"flex-1 relative overflow-hidden flex items-center justify-center bg-black",children:[Y?e.jsx("img",{ref:l,src:Y,alt:"Remote View",style:{display:"block",maxWidth:"100%",maxHeight:"100%",width:"auto",height:"auto",transform:`scale(${W}) translate(${E}%, ${O}%)`,transformOrigin:"center center",cursor:k==="mouse"?"default":"crosshair",userSelect:"none",WebkitTouchCallout:"none"},onClick:D,onContextMenu:K=>K.preventDefault(),onDragStart:K=>K.preventDefault()}):e.jsx(Zn,{waitingLabel:se,waitingHint:ee,transportType:i}),k==="mouse"&&Y&&e.jsx(Gn,{cursorPos:de,viewportRef:x,imgRef:l}),h.map(K=>{const F={left:"59,130,246",right:"239,68,68",double:"34,197,94"}[K.type];return e.jsxs("div",{style:{position:"absolute",left:K.x,top:K.y,pointerEvents:"none",zIndex:200,transform:"translate(-50%, -50%)"},children:[e.jsx("div",{style:{width:40,height:40,borderRadius:"50%",border:`2px solid rgba(${F}, 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(${F}, 0.9)`,boxShadow:`0 0 12px rgba(${F}, 0.6)`,animation:"click-ripple-dot 0.4s ease-out forwards",position:"absolute",left:-4,top:-4}})]},K.id)})]}),e.jsx(Jn,{inputMode:k,onToggleInputMode:ce,isImeOpen:N,setIsImeOpen:T,isMenuOpen:f,setIsMenuOpen:m,imeText:b,setImeText:g,handleImeSubmit:ae,isConnActive:te,zoom:W,isMobile:j,mobileFillZoom:y,onZoomOut:()=>M(K=>Math.max(.5,K-.25)),onZoomReset:re,onZoomIn:()=>M(K=>Math.min(5,K+.25)),transportType:i,screenshotUsage:a,lastActionStatus:p}),e.jsx("style",{children:`
12
- @keyframes slideUp {
13
- from { opacity: 0; transform: translateY(6px); }
14
- to { opacity: 1; transform: translateY(0); }
15
- }
16
- @keyframes slideUpSidebar {
17
- from { opacity: 0; transform: translateY(6px); }
18
- to { opacity: 1; transform: translateY(0); }
19
- }
20
- @keyframes click-ripple-ring {
21
- 0% { transform: scale(0.3); opacity: 1; }
22
- 100% { transform: scale(2.2); opacity: 0; }
23
- }
24
- @keyframes click-ripple-dot {
25
- 0% { transform: scale(1); opacity: 0.9; }
26
- 50% { transform: scale(1.8); opacity: 0.6; }
27
- 100% { transform: scale(0.5); opacity: 0; }
28
- }
29
- @keyframes remote-float {
30
- 0% { transform: translateY(0px); }
31
- 50% { transform: translateY(-7px); }
32
- 100% { transform: translateY(0px); }
33
- }
34
- `})]})}function sr({screenshotUrl:t,mode:s="preview",zoom:n=100,interactive:r=!1,connectionState:a,onDismiss:i,onClickAt:c,onKeyDown:x,badge:l,emptyMessage:p,aspectRatio:u,className:b,style:g}){const d=o.useRef(null),h=o.useCallback(w=>{if(!r||!c||!d.current)return;const S=d.current,f=S.getBoundingClientRect(),m=(w.clientX-f.left)/f.width*S.naturalWidth,N=(w.clientY-f.top)/f.height*S.naturalHeight;c(m,N,S.naturalWidth,S.naturalHeight)},[r,c]);return s==="preview"?t?e.jsxs("div",{className:`relative rounded-xl overflow-hidden border border-border-subtle bg-bg-secondary ${b||""}`,style:{aspectRatio:u||"16/9",...g},children:[e.jsx("img",{ref:d,src:t,alt:"IDE Screenshot",className:"w-full h-full object-cover"}),i&&e.jsx("button",{onClick:i,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":""} ${b||""} relative h-full flex items-center justify-center overflow-auto`,tabIndex:r?0:void 0,onKeyDown:r?x:void 0,style:g,children:[e.jsx("img",{ref:d,src:t,alt:"IDE Screenshot",onClick:r?h: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 ${b||""}`,style:g,children:[e.jsx("div",{className:"w-14 h-14 rounded-2xl flex items-center justify-center border border-white/10 bg-white/[0.04] shadow-[0_10px_30px_rgba(0,0,0,0.22)] mb-1",style:{animation:"remote-float 2.8s ease-in-out infinite"},children:e.jsx("img",{src:"/otter-logo.png",alt:"",className:"w-8 h-8 opacity-90"})}),e.jsx("p",{className:"text-base",children:p||"Waiting for screenshot stream..."}),a&&e.jsxs("p",{className:"text-[13px] mt-2 opacity-50",children:["P2P: ",a]}),e.jsx("style",{children:`
35
- @keyframes remote-float {
36
- 0% { transform: translateY(0px); }
37
- 50% { transform: translateY(-7px); }
38
- 100% { transform: translateY(0px); }
39
- }
40
- `})]})}function $s({activeConv:t,onModalButton:s}){const[n,r]=o.useState(null);if(o.useEffect(()=>{r(null)},[t.modalMessage,t.status]),t.status!=="waiting_approval"||!t.modalButtons)return null;const a=c=>{n||(r(c),s(c))},i=c=>c.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim();return e.jsxs("div",{className:"text-white py-2.5 px-4 shrink-0 z-[5]",style:{background:"linear-gradient(135deg, var(--status-warning), color-mix(in srgb, var(--status-warning) 85%, #000))"},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(Ft,{size:14})," ",n?"PROCESSING...":"ACTION REQUIRED"]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:t.modalButtons.map((c,x)=>{const l=i(c).toLowerCase(),p=/^(run|approve|accept|yes|allow|always)/.test(l),u=/^(reject|deny|delete|remove|abort)/.test(l),b=n===c,g=n!==null;return e.jsx("button",{onClick:()=>a(c),disabled:g,className:`btn btn-sm border-none rounded-md text-xs px-3 py-1 ${p?"bg-white font-extrabold":u?"bg-red-500/30 text-white font-semibold":"bg-white/15 text-white font-semibold"} ${g&&!b?"opacity-40":"opacity-100"} ${g?"cursor-not-allowed":"cursor-pointer"}`,style:p?{color:"var(--status-warning)"}:void 0,children:b?"⏳ ...":i(c)},x)})})]})]})}const we=new Map;function nr({ideId:t,sessionId:s,ideType:n,providerType:r,displayLabel:a,serverModel:i,serverMode:c,acpConfigOptions:x,acpModes:l}){var ie;const{sendCommand:p}=De(),u=!!(x||l),b=`${t}:${s||r}`,g=we.get(b),[d,h]=o.useState(!1),[w,S]=o.useState(!1),[f,m]=o.useState((g==null?void 0:g.models)||[]),[N,T]=o.useState((g==null?void 0:g.modes)||[]),j=B=>B?typeof B=="string"?B:typeof B=="object"?B.name||B.id||JSON.stringify(B):String(B):"",[k,v]=o.useState(j(i)),[y,_]=o.useState(j(c)),[P,W]=o.useState(!1),[M,E]=o.useState(!1),L=o.useRef(0),O=B=>B.map($=>typeof $=="string"?$:($==null?void 0:$.name)||($==null?void 0:$.id)||String($));o.useEffect(()=>{if(x){const B=x.find($=>$.category==="model");if(B){const $=O(B.options.map(R=>R.value));m($),B.currentValue&&v(j(B.currentValue));const A=we.get(b)||{models:[],modes:[]};we.set(b,{...A,models:$})}}if(l&&l.length>0){const B=O(l.map(A=>A.id));T(B);const $=we.get(b)||{models:[],modes:[]};we.set(b,{...$,modes:B})}else if(x){const B=x.find($=>$.category!=="model");if(B){const $=O(B.options.map(R=>R.value));T($),B.currentValue&&_(j(B.currentValue));const A=we.get(b)||{models:[],modes:[]};we.set(b,{...A,modes:$})}}},[x,l,b]),o.useEffect(()=>{h(!1),S(!1),v(j(i)),_(j(c));const B=we.get(b);B?(m(B.models),T(B.modes)):(m([]),T([]))},[t,r,s]),o.useEffect(()=>{i&&Date.now()>L.current&&v(j(i))},[i]),o.useEffect(()=>{c&&Date.now()>L.current&&_(j(c))},[c]);const C=o.useCallback(async(B,$={})=>{const A={...$,...s&&{targetSessionId:s}};return await p(t,B,A)},[t,s,p]),V=async()=>{var B,$;if(f.length>0){h(!d);return}if(u){h(!0);return}W(!0);try{const A=await C("list_extension_models",{agentType:r,ideType:n}),R=(A==null?void 0:A.models)||((B=A==null?void 0:A.result)==null?void 0:B.models)||[],D=O(R);m(D),A!=null&&A.current&&v(j(A.current)),($=A==null?void 0:A.result)!=null&&$.current&&v(j(A.result.current));const H=we.get(b)||{models:[],modes:[]};we.set(b,{...H,models:D}),h(!0)}catch{}finally{W(!1)}},Q=async()=>{var B,$;if(N.length>0){S(!w);return}if(u){S(!0);return}E(!0);try{const A=await C("list_extension_modes",{agentType:r,ideType:n}),R=(A==null?void 0:A.modes)||((B=A==null?void 0:A.result)==null?void 0:B.modes)||[],D=O(R);T(D),A!=null&&A.current&&_(j(A.current)),($=A==null?void 0:A.result)!=null&&$.current&&_(j(A.result.current));const H=we.get(b)||{models:[],modes:[]};we.set(b,{...H,modes:D}),S(!0)}catch{}finally{E(!1)}},Z=async B=>{h(!1),v(B),L.current=Date.now()+5e3;try{u?await C("change_model",{agentType:r,ideType:n,model:B}):await C("set_extension_model",{agentType:r,ideType:n,model:B})}catch{}},G=u&&!(l&&l.length>0)&&(x==null?void 0:x.some(B=>B.category!=="model")),te=G?(ie=x==null?void 0:x.find(B=>B.category!=="model"))==null?void 0:ie.configId:void 0,Y=async B=>{S(!1),_(B),L.current=Date.now()+5e3;try{u&&G&&te?await C("set_thought_level",{agentType:r,ideType:n,configId:te,value:B}):u?await C("set_mode",{agentType:r,ideType:n,mode:B}):await C("set_extension_mode",{agentType:r,ideType:n,mode:B})}catch{}},ee={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:ee},children:a}),e.jsx("span",{className:"text-border-subtle text-[10px]",children:"│"}),e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:d?`${ee}55`:"transparent",border:"1px solid",color:k?"var(--text-primary)":"var(--text-muted)"},onClick:V,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:"🤖"}),P?"...":k||"Model",e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),d&&f.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>h(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:"SELECT MODEL"}),f.map(B=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:B===k?`${ee}18`:"transparent",color:B===k?ee:"var(--text-secondary)",fontWeight:B===k?600:400,borderLeft:B===k?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:$=>{$.currentTarget.style.background=`${ee}12`},onMouseLeave:$=>{$.currentTarget.style.background=B===k?`${ee}18`:"transparent"},onClick:()=>Z(B),children:B},B))]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-xl text-[10px] font-medium cursor-pointer transition-all bg-[var(--surface-tertiary)] whitespace-nowrap max-w-40 overflow-hidden text-ellipsis",style:{borderColor:w?`${ee}55`:"transparent",border:"1px solid",color:y?"var(--text-primary)":"var(--text-muted)"},onClick:Q,children:[e.jsx("span",{className:"text-[9px] opacity-60",children:G?"🧠":"⚡"}),M?"...":y||(G?"Thinking":"Mode"),e.jsx("span",{className:"text-[7px] opacity-50",children:"▼"})]}),w&&N.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-[59]",onClick:()=>S(!1)}),e.jsxs("div",{className:"absolute bottom-full left-0 z-[60] bg-[var(--surface-primary)] border border-border-subtle rounded-lg mb-1 max-h-[220px] overflow-y-auto min-w-40 shadow-[0_-4px_16px_rgba(0,0,0,0.3)]",children:[e.jsx("div",{className:"px-3 py-1.5 text-[9px] font-bold text-text-muted tracking-wider border-b border-border-subtle",children:G?"SELECT THINKING LEVEL":"SELECT MODE"}),N.map(B=>e.jsx("div",{className:"px-3 py-[7px] text-[11px] cursor-pointer whitespace-nowrap overflow-hidden text-ellipsis",style:{background:B===y?`${ee}18`:"transparent",color:B===y?ee:"var(--text-secondary)",fontWeight:B===y?600:400,borderLeft:B===y?`2px solid ${ee}`:"2px solid transparent"},onMouseEnter:$=>{$.currentTarget.style.background=`${ee}12`},onMouseLeave:$=>{$.currentTarget.style.background=B===y?`${ee}18`:"transparent"},onClick:()=>Y(B),children:B},B))]})]})]})]})}const rr=o.memo(function({contextKey:s,panelLabel:n,isSending:r,onSend:a}){const i=o.useRef(null),[c,x]=o.useState("");o.useEffect(()=>{x("")},[s]);const l=()=>{const p=c.trim();!p||r||(x(""),a(p))};return 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:i,type:"text",placeholder:`Send message to ${n}...`,value:c,onChange:p=>x(p.target.value),onPaste:p=>{const u=p.clipboardData.getData("text");u&&x(b=>b+u),p.preventDefault()},onKeyDown:p=>{if(p.key==="Enter"){if(p.nativeEvent.isComposing){p.preventDefault();return}p.preventDefault(),l()}},onBlur:p=>{if(window.innerWidth<768){const u=p.relatedTarget;if((u==null?void 0:u.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:l,disabled:!c.trim()||r,className:`w-10 h-10 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${c.trim()&&!r?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:c.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:c.trim()?"text-white":"text-text-muted",children:e.jsx("path",{d:"M22 2L11 13M22 2l-7 20-4-9-9-4 20-7z"})})})]})})}),je=t=>t.transport==="pty",fe=t=>t.transport==="acp";var ar=new Set(["generating","streaming","loading","loading_reference","thinking","active"]);function or(t){var s;return(((s=t==null?void 0:t.buttons)==null?void 0:s.length)??0)>0}function ye(t,s){if(or(s==null?void 0:s.activeModal))return"waiting_approval";const n=String(t||"idle").trim().toLowerCase();return n==="waiting_approval"?"waiting_approval":ar.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 Ps(t){return ye(t)==="generating"}function pe(t){return t?t.charAt(0).toUpperCase()+t.slice(1).toLowerCase():"IDE"}function ir(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 a=Math.floor(n/24),i=n%24;return`${a}d ${i}h`}function Qt(t){return t<1024*1024*1024?`${(t/(1024*1024)).toFixed(0)} MB`:`${(t/(1024*1024*1024)).toFixed(1)} GB`}function Dt(t,s){const n=typeof s=="string"?s.trim():"";if(n)return n;const r=typeof t=="string"?t.trim():"";if(!r)return"";const a=r.replace(/[\\/]+$/,""),i=a.split(/[\\/]/).filter(Boolean);return i[i.length-1]||a}function cr(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 lr(t){return cr(t.trim().replace(/\.local$/i,""))}function dr(t){const s=t.machineNickname??t.nickname;return typeof s!="string"?null:s.trim()||null}function Ds(t,s={}){var a,i;const n=[t.hostname,(a=t.machine)==null?void 0:a.hostname,(i=t.system)==null?void 0:i.hostname].find(c=>typeof c=="string"&&c.trim().length>0);if(n&&n!=="Unknown")return lr(n);const r=s.fallbackId||t.id;return r?`Machine-${r.substring(0,8)}`:s.fallbackLabel||"Machine"}function Xe(t,s={}){return dr(t)||Ds(t,s)}function es(t){return t.transport==="pty"}function ts(t){return t.transport==="acp"}function ss(t,s){return pe(t)}function ur(t,s,n){const r=(t||"").trim().toLowerCase();if(!r)return!0;const a=(s||"").trim().toLowerCase(),i=(n||"").trim().toLowerCase(),c=pe(n||"").trim().toLowerCase();return r===a||r===i||r===c}function xr(t){return ye(t==null?void 0:t.status,{activeModal:t==null?void 0:t.activeModal})}function pr(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 a=(r.name||r.id||"").toLowerCase().replace(/\s+/g,"-"),i=s.get(a),c=ye(r.status);if(!i){s.set(a,{...r,status:c});continue}const x=n.indexOf(i.status||"idle"),l=n.indexOf(c||"idle");l>=0&&(x<0||l<x)&&s.set(a,{...r,status:c})}return Array.from(s.values())}const hr=60,mr=60;function Bs({activeConv:t,ideEntry:s,handleSendChat:n,isSendingChat:r=!1,handleFocusAgent:a,isFocusingAgent:i,actionLogs:c,userName:x}){const l=o.useRef(new Map),{sendCommand:p}=De();it("ChatPane",{tabKey:t.tabKey,messageCount:t.messages.length,actionLogCount:c.length,isSendingChat:r});const u=o.useRef(new Map),b=o.useCallback(M=>(u.current.has(M)||u.current.set(M,{messages:[],offset:0,hasMore:!0,error:null,visibleLiveCount:hr}),u.current.get(M)),[]),g=o.useCallback((M,E)=>{const L=b(M);u.current.set(M,{...L,...E}),d(O=>O+1)},[b]),[,d]=o.useState(0),h=t.tabKey,w=b(h),S=w.messages,f=w.hasMore,m=w.error,N=Math.max(0,t.messages.length-w.visibleLiveCount),[T,j]=o.useState(!1),k=o.useCallback(async()=>{var L,O;if(T)return;const M=t.tabKey,E=b(M);if(t.messages.length>E.visibleLiveCount){g(M,{visibleLiveCount:Math.min(t.messages.length,E.visibleLiveCount+mr),error:null});return}j(!0),g(M,{error:null});try{const C=(s==null?void 0:s.daemonId)||((L=t.ideId)==null?void 0:L.split(":")[0])||"";if(!C){g(M,{hasMore:!1});return}const V=t.ideType||t.agentType||"",Q=await p(C,"chat_history",{agentType:V,offset:E.offset,limit:30,targetSessionId:t.sessionId}),Z=(Q==null?void 0:Q.result)??Q;if(((O=Z.messages)==null?void 0:O.length)>0){const G=b(M);g(M,{messages:[...Z.messages,...G.messages],offset:G.offset+Z.messages.length,hasMore:!!Z.hasMore})}else g(M,{hasMore:!!Z.hasMore})}catch(C){const V=(C==null?void 0:C.message)||"";V.includes("P2P not available")||V.includes("channel not open")||V.includes("P2P not connected")||V.includes("timeout")?g(M,{error:"Connection not ready — tap to retry"}):g(M,{hasMore:!1,error:"Failed to load history"})}finally{j(!1)}},[T,s,t,p,b,g]),{allMessages:v,receivedAtMap:y}=o.useMemo(()=>{const M=N>0?t.messages.slice(-w.visibleLiveCount):t.messages;if(S.length===0){const V={};return M.forEach((Q,Z)=>{const G=`${t.tabKey}:${Ve(Q,Z)}`;let te=Q.receivedAt||l.current.get(G)||0;te||(te=Date.now(),l.current.set(G,te)),V[Ve(Q,Z)]=te}),{allMessages:M,receivedAtMap:V}}const E=new Set(M.map(V=>`${V.role}:${(V.content||"").slice(0,100)}`)),O=[...S.filter(V=>!E.has(`${V.role}:${(V.content||"").slice(0,100)}`)),...M],C={};return O.forEach((V,Q)=>{const Z=`${t.tabKey}:${Ve(V,Q)}`;let G=V.receivedAt||l.current.get(Z)||0;G||(G=Date.now(),l.current.set(Z,G)),C[Ve(V,Q)]=G}),{allMessages:O,receivedAtMap:C}},[t.messages,t.tabKey,N,S,w.visibleLiveCount]),_=o.useMemo(()=>c.filter(M=>M.ideId===t.tabKey).sort((M,E)=>M.timestamp-E.timestamp),[c,t.tabKey]),P=t.displayPrimary||t.agentName||"Agent",W=o.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(Ye,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent not monitored"}),e.jsx("button",{onClick:a,disabled:i,className:"btn btn-primary",children:i?"⌛ Switching...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($t,{size:14})," Open ",P," 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(Ts,{size:28})}),e.jsx("div",{className:"text-[13px] opacity-50",children:"Agent panel is not visible yet"}),e.jsx("button",{onClick:a,disabled:i,className:"btn btn-primary",children:i?"⌛ Opening...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($t,{size:14})," Open ",P," 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"&&!T)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,a,i,T,P]);return e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col",children:[e.jsx(Xn,{messages:v,actionLogs:_,agentName:t.agentName||t.displayPrimary||"Agent",userName:x,isCliMode:je(t)||fe(t),isWorking:t.status==="generating",contextKey:t.tabKey,receivedAtMap:y,onLoadMore:k,isLoadingMore:T,hasMoreHistory:f,hiddenLiveCount:N,loadError:m??void 0,emptyState:W}),!je(t)&&(()=>{const M=t.streamSource!=="agent-stream",E=M?t.ideType:t.agentType,L=M?s!=null&&s.type?pe(s.type):pe(t.ideType||""):t.agentName||pe(t.agentType||"");return e.jsx(nr,{ideId:t.ideId,sessionId:t.sessionId,ideType:t.ideType,providerType:E,displayLabel:L,serverModel:(s==null?void 0:s.currentModel)||void 0,serverMode:(s==null?void 0:s.currentPlan)||void 0,acpConfigOptions:fe(t)?s==null?void 0:s.acpConfigOptions:void 0,acpModes:fe(t)?s==null?void 0:s.acpModes:void 0})})(),e.jsx(rr,{contextKey:t.tabKey,panelLabel:P,isSending:r,onSend:n})]})}let Ws=at;function Ct(){return Ws()}class fr{constructor(){xe(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(a=>a(...n))}}let Os=new fr;class gr{constructor(){xe(this,"ptyCallbacks",new Set)}sendPtyInput(s,n,r){return!1}sendPtyResize(s,n,r,a){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,r){this.ptyCallbacks.forEach(a=>a(s,n,r))}onRuntimeEvent(s,n){return()=>{}}requestRuntimeSnapshot(s,n){return Promise.resolve()}}let ue=new gr;function br(t){t.dashboardWS&&(Os=t.dashboardWS),t.connectionManager&&(ue=t.connectionManager),t.useDaemonsHook&&(Ws=t.useDaemonsHook)}function yr({activeConv:t,clearToken:s=0,terminalRef:n,handleSendChat:r,isSendingChat:a=!1}){var T;const i=o.useRef(null),{sendCommand:c,sendData:x}=De(),[l,p]=o.useState(""),[u,b]=o.useState(!1),g=o.useRef(0),d=o.useRef(!1),h=t.tabKey,w=t.sessionId||"",S=t.daemonId||((T=t.ideId)==null?void 0:T.split(":")[0])||t.ideId||"",f=()=>{var j;g.current=0,d.current=!1,b(!1),(j=n.current)==null||j.clear()},m=()=>{var j;g.current=0,d.current=!1,b(!0),(j=n.current)==null||j.clear()},N=(j,k=0)=>{var v,y;d.current||g.current>=k&&g.current!==0||(g.current=k,b(!0),(v=n.current)==null||v.clear(),j&&((y=n.current)==null||y.write(j)))};return o.useEffect(()=>{f()},[w]),o.useEffect(()=>{var k,v;if(!w)return;const j=((k=ue.onRuntimeEvent)==null?void 0:k.call(ue,w,y=>{var _;if(!(!y||y.sessionId!==w)){if(y.type==="runtime_snapshot"){N(y.text||"",y.seq||0);return}if(y.type==="session_output"){d.current=!0,typeof y.seq=="number"&&(g.current=Math.max(g.current,y.seq)),b(!0),typeof y.data=="string"&&((_=n.current)==null||_.write(y.data));return}y.type==="session_cleared"&&m()}}))||(()=>{});return(v=ue.requestRuntimeSnapshot)==null||v.call(ue,S,w).catch(()=>{}),()=>{j()}},[S,w,n]),o.useEffect(()=>{var k,v,y;if(!w)return;S&&((k=ue.getState)==null?void 0:k.call(ue,S))==="connected"&&(b(!0),(v=ue.requestRuntimeSnapshot)==null||v.call(ue,S,w).catch(()=>{}));const j=(y=ue.onStateChange)==null?void 0:y.call(ue,(_,P)=>{var W;_!==S||P!=="connected"||(b(!0),(W=ue.requestRuntimeSnapshot)==null||W.call(ue,S,w).catch(()=>{}))});return()=>{j==null||j()}},[S,w,n]),o.useEffect(()=>{s&&f()},[s,h,n]),o.useEffect(()=>{p("")},[t.tabKey]),o.useEffect(()=>{const j=k=>{var y;const v=k.detail;v!=null&&v.sessionId&&v.sessionId!==w||u&&((y=n.current)==null||y.fit())};return window.addEventListener("adhdev:fit-cli-terminal",j),()=>{window.removeEventListener("adhdev:fit-cli-terminal",j)}},[u,w,n]),o.useEffect(()=>{if(!u)return;const j=requestAnimationFrame(()=>{var k;(k=n.current)==null||k.fit()});return()=>cancelAnimationFrame(j)},[u,w,n]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-h-0 p-2 bg-[#0f1117]",children:[e.jsx(Ls,{ref:n,readOnly:!u,onInput:j=>{u&&(x!=null&&x(S,{type:"pty_input",targetSessionId:w,data:j})||c(S,"pty_input",{targetSessionId:w,data:j}).catch(console.error))},onResize:(j,k)=>{u&&(x!=null&&x(S,{type:"pty_resize",targetSessionId:w,cols:j,rows:k})||c(S,"pty_resize",{targetSessionId:w,cols:j,rows:k,force:!0}).catch(()=>{}))}},t.tabKey),!u&&e.jsx("div",{className:"absolute inset-x-2 top-2 rounded-md border border-red-500/30 bg-red-500/10 px-3 py-2 text-[11px] text-red-300 pointer-events-none",children:"Runtime terminal unavailable"})]}),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:i,type:"text",placeholder:`Send message to ${t.displayPrimary}...`,value:l,onChange:j=>p(j.target.value),onPaste:j=>{const k=j.clipboardData.getData("text");k&&p(v=>v+k),j.preventDefault()},onKeyDown:j=>{if(j.key!=="Enter")return;if(j.nativeEvent.isComposing){j.preventDefault();return}j.preventDefault();const k=l.trim();!u||!k||a||(p(""),r(k))},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 j=l.trim();!u||!j||a||(p(""),r(j))},disabled:!u||!l.trim()||a,className:`w-9 h-9 rounded-full flex items-center justify-center border-none shrink-0 transition-all duration-300 ${l.trim()&&!a?"cursor-pointer":"bg-bg-secondary cursor-default"}`,style:l.trim()&&!a?{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 jr({wsStatus:t,showReconnected:s,loginUrl:n}){const r=t==="disconnected"||t==="reconnecting"||t==="offline"||t==="auth_failed",a=t==="auth_failed"?"red":t==="offline"?"orange":"violet",i={red:"linear-gradient(90deg, rgba(239,68,68,0.12), rgba(239,68,68,0.04))",orange:"linear-gradient(90deg, rgba(255,107,53,0.12), rgba(255,107,53,0.04))",violet:"linear-gradient(90deg, rgba(139,92,246,0.12), rgba(139,92,246,0.04))"},c={red:"1px solid rgba(239,68,68,0.2)",orange:"1px solid rgba(255,107,53,0.2)",violet:"1px solid rgba(139,92,246,0.2)"},x={red:"#ef4444",orange:"#ff6b35",violet:"#a78bfa"};return e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{className:"py-2.5 px-5 text-[13px] font-semibold flex items-center gap-2.5 justify-center",style:{background:i[a],borderBottom:c[a],color:x[a]},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"]})]})}function vr({activeConv:t,agentCount:s,wsStatus:n,isConnected:r,onOpenHistory:a,onStopCli:i,onFitCli:c}){const x=ot(),l=Ct(),p=l.p2pStates||{},u=l.ides||[],b=!!t&&je(t)&&!fe(t),g=r?"#22c55e":n==="connected"?"#eab308":"#ef4444",d=r?"0 0 4px #22c55e80":n==="connected"?"0 0 4px #eab30880":"0 0 4px #ef444480",h=u.filter(T=>T.type==="adhdev-daemon"),w=Object.values(p),S=w.filter(T=>T==="connected").length,f=w.filter(T=>T==="connecting"||T==="new"||T==="checking").length,N=n!=="connected"||h.length===0?null:f>0&&S===0?"P2P connecting...":S>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(qe,{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:g,boxShadow:d}})})]}),e.jsxs("div",{className:"header-subtitle text-xs items-center gap-1",children:[s," agent",s!==1?"s":""," active",e.jsx("span",{title:r?"Connected":n==="connected"?"Partial":"Disconnected",className:"inline-block w-1.5 h-1.5 rounded-full shrink-0",style:{background:g,boxShadow:d}}),N&&e.jsxs("span",{className:"text-[10px] text-text-muted animate-pulse ml-1",children:["· ",N]})]})]})}),e.jsxs("div",{className:"flex gap-2 items-center",children:[b&&i&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:c,className:"btn btn-secondary btn-sm",title:"Fit terminal to current view",children:"Fit"}),e.jsx("button",{onClick:i,className:"btn btn-secondary btn-sm text-red-400 border-red-500/25 hover:bg-red-500/10",title:"Stop CLI process",children:"Stop"})]}),t&&!b&&!fe(t)&&e.jsxs("button",{onClick:()=>x(`/ide/${t.ideId}`),className:"btn btn-primary btn-sm",title:"IDE View",children:[e.jsx(Ht,{size:14})," IDE"]}),t&&!b&&!fe(t)&&e.jsx("button",{onClick:a,className:"btn btn-secondary btn-sm",title:"Chat History",children:e.jsx(Is,{size:16})}),t&&!b&&!fe(t)&&e.jsx("button",{onClick:()=>x(`/ide/${t.ideId}?view=remote`),className:"btn btn-secondary btn-sm",title:"Remote Control",children:e.jsx(Le,{size:16})})]})]})}function Ks({activeConv:t,ides:s,isCreatingChat:n,isRefreshingHistory:r,onClose:a,onNewChat:i,onSwitchSession:c,onRefreshHistory:x}){var b;const l=s.find(g=>g.id===t.ideId),p=(l==null?void 0:l.chats)||[],u=(b=l==null?void 0:l.activeChat)==null?void 0:b.id;return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:a,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," — ",pe(t.ideType)]})]}),e.jsx("button",{onClick:a,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:i,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"}),p.map(g=>e.jsxs("div",{onClick:()=>{c(t.ideId,g.id),a()},className:`p-4 rounded-xl mb-2 cursor-pointer border transition-all ${u===g.id?"bg-[var(--bg-glass-hover)] border-accent":"bg-[var(--surface-secondary)] border-border-subtle"}`,children:[e.jsx("div",{className:`font-bold text-sm mb-1 ${u===g.id?"text-[var(--accent-primary-light)]":"text-text-primary"}`,children:g.title||"Untitled Session"}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-mono",children:[g.id.substring(0,12),"..."]}),u===g.id&&e.jsx("span",{className:"text-[10px] bg-accent text-white px-2 py-0.5 rounded-[10px] font-extrabold",children:"ACTIVE"})]})]},g.id)),p.length===0&&e.jsxs("div",{className:"py-10 px-5 text-center text-text-muted",children:[e.jsx("div",{className:"text-3xl mb-3 opacity-60",children:e.jsx(Wn,{size:32})}),e.jsx("div",{className:"text-[13px]",children:"No recent chat sessions found."})]})]}),e.jsx("div",{className:"px-5 py-4 bg-[var(--surface-tertiary)] border-t border-border-subtle text-right",children:e.jsx("button",{onClick:x,disabled:r,className:"btn btn-secondary btn-sm rounded-[10px]",children:r?"⌛ Refreshing...":e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ms,{size:13})," Refresh History"]})})})]})]})}const ns={success:"rgba(16, 185, 129, 0.95)",warning:"color-mix(in srgb, var(--status-warning) 95%, transparent)",info:"rgba(99, 102, 241, 0.95)"};function zs({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:ns[r.type]||ns.info},onClick:()=>{var a;(a=r.actions)!=null&&a.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:a=>{a.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((a,i)=>e.jsx("button",{className:`text-xs px-3 py-1 rounded-md font-bold transition-all cursor-pointer ${a.variant==="primary"?"bg-white text-text-primary hover:bg-gray-100":a.variant==="danger"?"bg-red-500/30 text-white hover:bg-red-500/50":"bg-white/20 text-white hover:bg-white/30"}`,onClick:c=>{c.stopPropagation(),a.onClick(),s(r.id)},children:a.label},i))})]},r.id))})}const wr=t=>t.transport==="pty"||t.transport==="acp"||t.transport==="cdp-page"?!0:t.daemonId!==t.id;function Nr(t){const s=t.workspace||"";if(!s)return"";const n=s.split(/[/\\]/).filter(Boolean);return n.length>0?n[n.length-1]:s}function kr(t){return t.sessionId||t.instanceId||t.agentType}function ut(t){return typeof t=="string"?t.replace(/\s+/g," ").trim():Array.isArray(t)?t.map(s=>typeof s=="string"?s:s&&typeof s=="object"&&"text"in s?String(s.text||""):"").join(`
41
- `).replace(/\s+/g," ").trim():t&&typeof t=="object"&&"text"in t?String(t.text||"").replace(/\s+/g," ").trim():String(t||"").replace(/\s+/g," ").trim()}function rs(t,s){const n=new Set,r=[];for(const a of s)if(a)for(const i of t[a]||[]){const c=i._localId||`${i.role}:${i.timestamp}:${i.content}`;n.has(c)||(n.add(c),r.push(i))}return r.sort((a,i)=>a.timestamp-i.timestamp)}function Fs(t=[]){const s={};for(const n of t){const r=n;(r.type==="adhdev-daemon"||r.daemonMode)&&(s[r.id]=Xe(r,{fallbackId:r.id}))}return s}function Hs(t,s,n={}){var g,d,h,w,S,f;const r=[],a=n.machineName,i=n.connectionState,c=Nr(t),x=pe(t.type),l=Array.isArray(t.childSessions)?t.childSessions.map(m=>{var N,T;return{sessionId:m.id,instanceId:m.id,agentType:m.providerType,agentName:m.providerName,status:m.status,title:m.title,messages:((N=m.activeChat)==null?void 0:N.messages)||[],activeModal:((T=m.activeChat)==null?void 0:T.activeModal)||void 0}}):[],p=wr(t),u=t.activeChat||{title:""},b=u.title&&String(u.title).trim()?String(u.title).trim():"";if(p){const m=t.sessionId||t.instanceId,N=ss(t.type),T=(g=t.activeChat)==null?void 0:g.activeModal,j=T&&Array.isArray(T.buttons)&&T.buttons.length>0,k=ye((d=t.activeChat)==null?void 0:d.status,{activeModal:(h=t.activeChat)==null?void 0:h.activeModal})||ye((S=(w=t.agents)==null?void 0:w[0])==null?void 0:S.status)||"idle",v=t.activeChat||{title:"",messages:[]};let y=v.title&&String(v.title).trim()?String(v.title).trim():"";const _=(f=t.activeChat)==null?void 0:f.id,P=t.chats;if(_&&Array.isArray(P)&&P.length>0){const O=P.find(C=>C.id===_||C.id&&String(C.id)===String(_));O!=null&&O.title&&String(O.title).trim()&&(y=String(O.title).trim())}const W=v.messages||[],M=rs(s,[t.id,m]),E=new Map;W.filter(O=>O.role==="user").forEach(O=>{const C=ut(O.content);C&&E.set(C,(E.get(C)||0)+1)});const L=M.filter(O=>{const C=ut(O.content),V=E.get(C)||0;return V>0?(E.set(C,V-1),!1):!0});r.push({ideId:t.id,sessionId:m,transport:t.transport,daemonId:t.daemonId||void 0,mode:je(t)?t.mode||"terminal":"chat",agentName:N,agentType:(je(t)||fe(t))&&(t.cliType||t.acpType)||t.type,status:k,title:y,messages:[...W,...L],resume:t.resume,ideType:t.cliType||t.acpType||t.type,workspaceName:c,displayPrimary:y||c||(je(t)||fe(t)?"Terminal":N),displaySecondary:x,cdpConnected:t.cdpConnected,modalButtons:j?T.buttons:void 0,modalMessage:j?T.message:void 0,streamSource:"native",tabKey:t.id,machineName:a,connectionState:i})}if(p&&(je(t)||fe(t)))return r;for(const m of l){const N=m.activeModal&&Array.isArray(m.activeModal.buttons)&&m.activeModal.buttons.length>0,T=xr(m),j=kr(m),k=`${t.id}:${j}`,v=m.title&&String(m.title).trim()||"",y=ur(v,m.agentName,m.agentType)?"":v,_=m.messages||[],P=rs(s,[k,m.sessionId,m.instanceId]),W=new Map;_.filter(E=>E.role==="user").forEach(E=>{const L=ut(E.content);L&&W.set(L,(W.get(L)||0)+1)});const M=P.filter(E=>{const L=ut(E.content),O=W.get(L)||0;return O>0?(W.set(L,O-1),!1):!0});r.push({ideId:t.id,sessionId:m.sessionId||m.instanceId,transport:m.transport||"cdp-webview",daemonId:t.daemonId||void 0,mode:"chat",agentName:m.agentName,agentType:m.agentType,status:T,title:y,messages:[..._,...M],ideType:m.agentType,workspaceName:c,displayPrimary:y||b||c||x,displaySecondary:`${x}·${m.agentName}`,cdpConnected:t.cdpConnected,modalButtons:N?m.activeModal.buttons:void 0,modalMessage:N?m.activeModal.message:void 0,streamSource:"agent-stream",tabKey:k,machineName:a,connectionState:i})}return r.length===0&&r.push({ideId:t.id,sessionId:t.sessionId||t.instanceId,transport:t.transport,daemonId:t.daemonId||void 0,mode:"chat",agentName:ss(t.type),agentType:"ide-native",status:"idle",title:"",messages:[],ideType:t.type,workspaceName:c,displayPrimary:c||x,displaySecondary:x,cdpConnected:t.cdpConnected,streamSource:"native",tabKey:t.id,connectionState:i}),r}function Sr(t){const s=[],n=new Map;for(const r of t)if(r.parentId){const a=n.get(r.parentId)||[];a.push(r),n.set(r.parentId,a)}else s.push(r);return{topLevel:s,childrenByParent:n}}function Cr(t,s){const n=[],{daemonId:r,existingDaemon:a,timestamp:i}=s,c=i||t.timestamp||Date.now(),x=t.sessions||[],{topLevel:l,childrenByParent:p}=Sr(x),u=l.filter(d=>d.kind==="workspace"&&d.transport==="cdp-page"),b=l.filter(d=>d.kind==="agent"&&d.transport==="pty"),g=l.filter(d=>d.kind==="agent"&&d.transport==="acp");n.push({...a||{},id:r,type:"adhdev-daemon",status:"online",daemonMode:!0,timestamp:c,...t.version&&{version:t.version},...t.machine&&{machine:t.machine,platform:t.machine.platform},...t.instanceId&&{instanceId:t.instanceId},...t.machineNickname!==void 0&&{machineNickname:t.machineNickname},...t.p2p&&{p2p:t.p2p},...t.workspaces&&{workspaces:t.workspaces},...t.defaultWorkspaceId!==void 0&&{defaultWorkspaceId:t.defaultWorkspaceId},...t.defaultWorkspacePath!==void 0&&{defaultWorkspacePath:t.defaultWorkspacePath},...t.workspaceActivity&&{workspaceActivity:t.workspaceActivity},...t.detectedIdes&&{detectedIdes:t.detectedIdes},..."availableProviders"in t&&{availableProviders:t.availableProviders},cdpConnected:u.some(d=>!!d.cdpConnected)});for(const d of u){const h=p.get(d.id)||[];n.push({id:`${r}:ide:${d.id}`,sessionId:d.id,parentSessionId:d.parentId,sessionKind:d.kind,transport:d.transport,sessionCapabilities:d.capabilities,type:d.providerType,ideType:d.providerType,status:d.cdpConnected?"online":"detected",daemonId:r,instanceId:d.id,workspace:d.workspace,terminals:0,childSessions:h,agents:h.map(w=>({id:w.id,name:w.providerName,type:w.providerType,status:w.status})),activeChat:d.activeChat,chats:[],cdpConnected:d.cdpConnected,currentModel:d.currentModel,currentPlan:d.currentPlan,currentAutoApprove:d.currentAutoApprove,timestamp:c})}for(const d of b){const h=d.runtime;n.push({id:`${r}:cli:${d.id}`,sessionId:d.id,parentSessionId:d.parentId,sessionKind:d.kind,transport:d.transport,sessionCapabilities:d.capabilities,type:d.providerType,ideType:d.providerType,agentType:d.providerType,status:d.status||"running",daemonId:r,instanceId:d.id,cliName:d.providerName,mode:"terminal",workspace:d.workspace||"",activeChat:d.activeChat,resume:d.resume,runtimeKey:d.runtimeKey??(h==null?void 0:h.runtimeKey),runtimeDisplayName:d.runtimeDisplayName??(h==null?void 0:h.displayName),runtimeWorkspaceLabel:d.runtimeWorkspaceLabel??(h==null?void 0:h.workspaceLabel),runtimeWriteOwner:d.runtimeWriteOwner??(h==null?void 0:h.writeOwner)??null,runtimeAttachedClients:d.runtimeAttachedClients??(h==null?void 0:h.attachedClients)??[],timestamp:c,_isCli:!0})}for(const d of g){const h=d.runtime;n.push({id:`${r}:acp:${d.id}`,sessionId:d.id,parentSessionId:d.parentId,sessionKind:d.kind,transport:d.transport,sessionCapabilities:d.capabilities,type:d.providerType,ideType:d.providerType,agentType:d.providerType,status:d.status||"running",daemonId:r,instanceId:d.id,cliName:d.providerName,mode:"chat",workspace:d.workspace||"",activeChat:d.activeChat,runtimeKey:d.runtimeKey??(h==null?void 0:h.runtimeKey),runtimeDisplayName:d.runtimeDisplayName??(h==null?void 0:h.displayName),runtimeWorkspaceLabel:d.runtimeWorkspaceLabel??(h==null?void 0:h.workspaceLabel),runtimeWriteOwner:d.runtimeWriteOwner??(h==null?void 0:h.writeOwner)??null,runtimeAttachedClients:d.runtimeAttachedClients??(h==null?void 0:h.attachedClients)??[],currentModel:d.currentModel,currentPlan:d.currentPlan,acpConfigOptions:d.acpConfigOptions,acpModes:d.acpModes,timestamp:c,_isAcp:!0})}return n}function Us(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 Ir(t,s){const n=Us(t);return{daemonId:n.daemonId,payload:{...s,...n.targetSessionId&&!s.targetSessionId?{targetSessionId:n.targetSessionId}:{}}}}const Vs=[{id:"vscode",name:"VS Code",icon:"💙"},{id:"cursor",name:"Cursor",icon:"⚡"},{id:"windsurf",name:"Windsurf",icon:"🏄"},{id:"antigravity",name:"Antigravity",icon:"🌀"},{id:"trae",name:"Trae",icon:"🔮"},{id:"kiro",name:"Kiro",icon:"🎯"},{id:"pearai",name:"PearAI",icon:"🍐"},{id:"vscodium",name:"VSCodium",icon:"💚"}],qs=[{id:"claude-cli",name:"Claude Code",icon:"🟠"},{id:"gemini-cli",name:"Gemini CLI",icon:"✨"},{id:"codex-cli",name:"Codex CLI",icon:"📦"},{id:"aider-cli",name:"Aider",icon:"🛠️"},{id:"cursor-cli",name:"Cursor CLI",icon:"⚡"},{id:"github-copilot-cli",name:"GitHub Copilot CLI",icon:"🤖"},{id:"goose-cli",name:"Goose CLI",icon:"🪿"},{id:"opencode-cli",name:"OpenCode CLI",icon:"🧩"}],Ys=[{id:"copilot",name:"GitHub Copilot",icon:"🤖"},{id:"cline",name:"Cline",icon:"🧠"},{id:"roo-code",name:"Roo Code",icon:"🦘"},{id:"continue",name:"Continue",icon:"▶️"}],Xs="adhdev_notification_prefs",as={globalEnabled:!0,disconnectAlert:!0,browserNotifications:!0,completionAlert:!0,approvalAlert:!0,chatTaskCompletionBubble:!1};function Mr(){try{const t=localStorage.getItem(Xs);if(t){const s=JSON.parse(t);return{...as,...s}}}catch{}return{...as}}function Tr(t){try{localStorage.setItem(Xs,JSON.stringify(t))}catch{}}let Me=Mr(),gt=[];function Er(){gt.forEach(t=>t())}function Ar(){return{...Me}}function Rr(t){Me={...Me,...t},Tr(Me),Er()}function _r(){const[,t]=o.useState(0);o.useEffect(()=>{const n=()=>t(r=>r+1);return gt.push(n),()=>{gt=gt.filter(r=>r!==n)}},[]);const s=o.useCallback(n=>{Rr(n)},[]);return[{...Me},s]}function st(t){if(!Me.globalEnabled)return!1;switch(t){case"disconnect":return Me.disconnectAlert;case"completion":return Me.completionAlert;case"approval":return Me.approvalAlert;case"browser":return Me.browserNotifications;default:return!0}}const Lr={enabled:!0,onApproval:!0,onComplete:!0,onError:!0,throttleMs:5e3};async function $r(){return"Notification"in window?Notification.permission==="granted"?"granted":Notification.permission==="denied"?"denied":Notification.requestPermission():"denied"}function Gs(){return"Notification"in window&&Notification.permission==="granted"}let Be=null;async function Pr(){if(Be!==null)return Be;try{if(!("serviceWorker"in navigator)||!("PushManager"in window))return Be=!1,!1;const t=await navigator.serviceWorker.getRegistration();return t?(Be=!!await t.pushManager.getSubscription(),Be):(Be=!1,!1)}catch{return Be=!1,!1}}function Bt(t,s,n){if(Gs())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 Dr(t,s={}){const n={...Lr,...s},r=o.useRef(new Map),a=o.useRef(0),i=o.useRef(null);o.useEffect(()=>{Pr().then(x=>{i.current=x})},[]);const c=o.useCallback((x,l,p)=>{const u=Date.now();u-a.current<n.throttleMs||(a.current=u,Bt(x,l,p))},[n.throttleMs]);o.useEffect(()=>{var x;if(!(!n.enabled||!Gs())&&st("browser")&&i.current!==!0){if(document.hasFocus()){for(const l of t)r.current.set(l.id,ye(l.status,{activeModal:l.activeModal}));return}for(const l of t){const p=r.current.get(l.id),u=ye(l.status,{activeModal:l.activeModal}),b=l.name||l.id;if(n.onApproval&&st("approval")&&u==="waiting_approval"&&p!=="waiting_approval"){const g=((x=l.activeModal)==null?void 0:x.message)||"Action requires your approval";c(`🔔 ${b} — Approval needed`,g.slice(0,120),`approval-${l.id}`)}n.onComplete&&st("completion")&&Ps(p)&&u==="idle"&&c(`✅ ${b} — Task complete`,"Agent has finished generating",`complete-${l.id}`),n.onError&&u==="error"&&p!=="error"&&c(`⚠️ ${b} — Error`,"Agent encountered an error",`error-${l.id}`),r.current.set(l.id,u)}}},[t,n.enabled,n.onApproval,n.onComplete,n.onError,c])}class Br{constructor(){xe(this,"dedupMap",new Map);xe(this,"DEDUP_WINDOW_MS",5e3);xe(this,"DEDUP_MAX_SIZE",50);xe(this,"DEDUP_CLEANUP_AGE_MS",1e4);xe(this,"toastCallbacks",[]);xe(this,"systemMessageCallbacks",[]);xe(this,"clearSystemMessageCallbacks",[]);xe(this,"resolveActionFn",null);xe(this,"viewRequestRespondFn",null);xe(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 a=(r==null?void 0:r.id)||Date.now();this.emitToast({id:a,message:s,type:n,timestamp:a,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[a,i]of this.dedupMap)n-i>this.DEDUP_CLEANUP_AGE_MS&&this.dedupMap.delete(a);return!1}resolveOwningDaemon(s){if(s.ideType==="adhdev-daemon"&&s.ideId){const a=this.ides.find(i=>i.id===s.ideId&&i.type==="adhdev-daemon");if(a)return a}let n;if(s.targetSessionId&&(n=this.findOwningSession(s.targetSessionId)||void 0),s.ideId&&(n=n||this.ides.find(a=>a.id===s.ideId)),!n&&s.instanceId&&(n=this.ides.find(a=>a.id.endsWith(`:ide:${s.instanceId}`)||a.id.endsWith(`:cli:${s.instanceId}`))),n){const a=n.daemonId;if(a){const i=this.ides.find(c=>c.id===a&&c.type==="adhdev-daemon");if(i)return i}}const r=this.ides.filter(a=>a.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.childSessions)?n.childSessions:[]).some(a=>(a==null?void 0:a.id)===s))return n;return null}resolveActionRouteTarget(s){if(s.ideId){const n=s.agentType||s.ideType||"";return this.resolveRouteId(s.ideId,n)}if(s.targetSessionId){const n=this.findOwningSession(s.targetSessionId);return(n==null?void 0:n.id)||(n==null?void 0:n.daemonId)||null}return null}resolveConversationKey(s){return s.targetSessionId?s.targetSessionId:s.ideId?s.ideId:null}handleRawEvent(s,n){var u,b;if(!s.ideId&&s.instanceId){for(const g of this.ides)if(g.id.endsWith(`:ide:${s.instanceId}`)||g.id.endsWith(`:cli:${s.instanceId}`)){s.ideId=g.id;break}}const r=this.resolveConversationKey(s),i=`${r||s.instanceId||s.ideType||s.providerType||""}:${s.event}:${s.chatTitle||""}`;if(this.isDuplicate(i))return;let c=pe(s.ideType||"");const x=this.resolveOwningDaemon(s);if(x){const g=Xe(x,{fallbackId:x.id});g&&(c=s.ideType==="adhdev-daemon"?g:`${g}/${c}`)}let l="",p="info";if(s.event==="agent:generating_completed"){const g=s.duration?` (${s.duration}s)`:"";l=`✅ ${c} agent task completed${g}`,p="success";try{new Audio("data:audio/wav;base64,UklGRigAAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQQAAAB/f39/").play().catch(()=>{})}catch{}r&&Ar().chatTaskCompletionBubble&&this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`✅ Task completed${g}`,_localId:`sys_complete_${Date.now()}`})}else if(s.event==="agent:generating_started")r&&this.emitClearSystemMessage(r,"sys_complete_");else if(s.event==="agent:waiting_approval"){if(l=`⚡ ${c} approval needed`,p="warning",r){const g=s.modalMessage||"Approval requested",d=(u=s.modalButtons)!=null&&u.length?s.modalButtons.map(h=>`[${h}]`).join(" "):"[Approve] [Reject]";this.emitSystemMessage(r,{role:"system",timestamp:Date.now(),content:`⚡ Approval requested: ${g}
42
- ${d}`,_localId:`sys_approval_${Date.now()}`})}if((b=s.modalButtons)!=null&&b.length&&this.resolveActionFn){const g=this.resolveActionRouteTarget(s);if(!g)return;const d=s.agentType||s.ideType||"",h=s.ideType||"",w=s.modalButtons,S=j=>j.replace(/[⌥⏎⇧⌫⌘⌃↵]/g,"").replace(/\s*(Alt|Ctrl|Shift|Cmd|Enter|Return|Esc|Tab|Backspace)(\+\s*\w+)*/gi,"").trim(),f=this.resolveActionFn,m=w.map((j,k)=>{const v=S(j).toLowerCase(),y=/^(run|approve|accept|yes|allow|always)/.test(v),_=/^(reject|deny|delete|remove|abort|cancel|no)/.test(v);return{label:S(j),variant:y?"primary":_?"danger":"default",onClick:()=>{const P=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(v);f(g,"resolve_action",{action:P?"approve":"reject",button:j,buttonIndex:k,agentType:d,ideType:h,...s.targetSessionId&&{targetSessionId:s.targetSessionId}})}}}),N=s.modalMessage?`⚡ ${c}: ${s.modalMessage.replace(/[\n\r]+/g," ").slice(0,80)}`:l,T=Date.now();this.emitToast({id:T,message:N,type:p,timestamp:T,targetKey:r||g,actions:m,duration:15e3}),l=""}}else if(s.event==="monitor:long_generating"){const g=s.elapsedSec?` (${Math.round(s.elapsedSec/60)}m)`:"";l=`⚠️ ${c} agent is taking a long time${g}`,p="warning",st("browser")&&!document.hasFocus()&&Bt(`⚠️ ${c} — Long Running`,`Agent has been generating for over ${g.replace(/[()]/g,"")}`,`long-${s.ideId||s.agentType}`)}else if(s.event==="team:view_request"){const g=s.requesterName||"A team member",d=s.requestId,h=s.orgId;if(l=`👁️ ${g} wants to view your session`,p="warning",d&&h&&this.viewRequestRespondFn){const w=this.viewRequestRespondFn,S=Date.now(),f=[{label:"Approve",variant:"primary",onClick:()=>{w(h,d,"approve").catch(m=>console.error("[EventManager] approve view request failed:",m))}},{label:"Decline",variant:"danger",onClick:()=>{w(h,d,"reject").catch(m=>console.error("[EventManager] reject view request failed:",m))}}];this.emitToast({id:S,message:l,type:p,timestamp:S,actions:f,duration:3e4}),l=""}st("browser")&&!document.hasFocus()&&Bt("👁️ View Request",`${g} wants to view your session`,`view-request-${d}`)}else s.event==="team:view_request_approved"?(l="✅ View request approved",p="success"):s.event==="team:view_request_rejected"&&(l=`❌ ${s.targetName||"Team member"} declined your view request`,p="warning");if(l){const g=Date.now();this.emitToast({id:g,message:l,type:p,timestamp:g,targetKey:r||s.ideId,duration:5e3})}}}const Pe=new Br;function Fe(...t){return mn(fn(t))}function Wr({icon:t,title:s,subtitle:n,badge:r,actions:a,className:i}){return e.jsxs("div",{className:Fe("dashboard-header",i),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})]}),a&&e.jsx("div",{className:"flex gap-2",children:a})]})}function wt({icon:t,title:s,subtitle:n,badge:r,actions:a,widthClassName:i="max-w-6xl",contentClassName:c,children:x}){return e.jsxs("div",{className:"flex flex-col h-full",children:[e.jsx(Wr,{icon:t,title:s,subtitle:n,badge:r,actions:a}),e.jsx("div",{className:"page-content",children:e.jsx("div",{className:Fe("mx-auto flex w-full flex-col gap-4",i,c),children:x})})]})}function me({title:t,icon:s,description:n,accentColor:r,className:a,children:i}){return e.jsxs("div",{className:Fe("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]",a),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})]}),i]})}function Ut({icon:t,title:s,description:n,action:r,className:a}){return e.jsxs("div",{className:Fe("py-16 px-5 text-center bg-bg-glass border-2 border-dashed border-border-subtle rounded-2xl",a),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 Or={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"},Kr={error:"⚠️",warning:"🧪",success:"✅",info:"💡"};function zr({variant:t,children:s,onDismiss:n,className:r}){return e.jsxs("div",{className:Fe("flex items-center justify-between gap-3 px-4 py-3 rounded-xl border text-[13px]",Or[t],r),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:Kr[t]}),e.jsx("span",{children:s})]}),n&&e.jsx("button",{onClick:n,className:"cursor-pointer border-none bg-transparent text-current text-base opacity-70 hover:opacity-100 transition-opacity",children:"✕"})]})}const Fr={online:"bg-green-500/10 text-green-400 border-green-500/30",idle:"bg-yellow-500/10 text-yellow-400 border-yellow-500/30",busy:"bg-orange-500/10 text-orange-400 border-orange-500/30",error:"bg-red-500/10 text-red-400 border-red-500/30",offline:"bg-gray-500/10 text-text-secondary border-gray-500/30"},Hr={online:"bg-green-500",idle:"bg-yellow-500",busy:"bg-orange-500",error:"bg-red-500",offline:"bg-gray-500"};function Ur({status:t,label:s,className:n}){const r=s||t;return e.jsxs("span",{className:Fe("inline-flex items-center gap-1.5 text-xs font-medium px-2.5 py-1 rounded-full border",Fr[t],n),children:[e.jsx("span",{className:Fe("w-2 h-2 rounded-full animate-[pulse-dot_2s_ease-in-out_infinite]",Hr[t])}),r]})}function Vr(){return typeof window>"u"?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"dark"}function Wt(){try{const t=localStorage.getItem("theme");if(t==="dark"||t==="light"||t==="system")return t}catch{}return"dark"}function bt(t){return t==="system"?Vr():t}function qr(){typeof document>"u"||document.documentElement.setAttribute("data-theme",bt(Wt()))}function Yr(){const[t,s]=o.useState(Wt),[n,r]=o.useState(()=>bt(Wt()));o.useEffect(()=>{document.documentElement.setAttribute("data-theme",n)},[n]),o.useEffect(()=>{const c=window.matchMedia("(prefers-color-scheme: light)"),x=l=>{t==="system"&&r(l.matches?"light":"dark")};return c.addEventListener("change",x),()=>c.removeEventListener("change",x)},[t]);const a=o.useCallback(c=>{s(c),r(bt(c));try{localStorage.setItem("theme",c)}catch{}},[]),i=o.useCallback(()=>{s(c=>{const x=c==="dark"?"light":c==="light"?"system":"dark";r(bt(x));try{localStorage.setItem("theme",x)}catch{}return x})},[]);return{theme:n,preference:t,setPreference:a,cycleTheme:i,isDark:n==="dark"}}function Oe({label:t,description:s,checked:n,disabled:r,onChange:a,extra:i}){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:[i,e.jsx("input",{type:"checkbox",checked:n,disabled:r,onChange:c=>a(c.target.checked),className:"w-5 h-5 accent-accent"})]})]})}function Xr({onPrefChange:t}){const[s,n]=_r(),r=(a,i)=>{n({[a]:i}),t==null||t(a,i)};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(_s,{size:15})," Notifications"]}),description:"Master toggle for all alerts",checked:s.globalEnabled,onChange:a=>r("globalEnabled",a)}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-0.5"}),s.globalEnabled&&e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{size:15})," Browser Notifications"]}),description:"Desktop alerts when tab is inactive",checked:s.browserNotifications,onChange:a=>r("browserNotifications",a)}),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(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(On,{size:15})," Completion Alerts"]}),description:"Notify when agent finishes a task",checked:s.completionAlert,onChange:a=>r("completionAlert",a)}),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Kn,{size:15})," Approval Alerts"]}),description:"Notify when agent needs approval",checked:s.approvalAlert,onChange:a=>r("approvalAlert",a)}),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ye,{size:15})," Connection Alerts"]}),description:"Alert when a daemon disconnects",checked:s.disconnectAlert,onChange:a=>r("disconnectAlert",a)})]}),s.globalEnabled&&e.jsx("div",{className:"border-t border-border-subtle my-2"}),s.globalEnabled&&e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(qe,{size:15})," Task Completion Bubble"]}),description:"Show a system message bubble in chat when an agent finishes a task",checked:s.chatTaskCompletionBubble,onChange:a=>r("chatTaskCompletionBubble",a)}),!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 Gr({ides:t,emptyMessage:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:a}){const i=t.filter(c=>c.type==="adhdev-daemon");return i.length===0?e.jsx(Ut,{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:i.map(c=>e.jsx(Zr,{ide:c,allIdes:t,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:a},c.id))})}function os({title:t,message:s,confirmLabel:n,confirmColor:r,onConfirm:a,onCancel:i}){const c=r==="red"?"bg-red-500/20 text-red-400 border-red-500/30 hover:bg-red-500/30":"";return gn.createPortal(e.jsx("div",{className:"fixed inset-0 flex items-center justify-center bg-black/60 backdrop-blur-sm",style:{zIndex:9999},onClick:i,children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl p-5 max-w-sm w-full mx-4 shadow-2xl",onClick:x=>x.stopPropagation(),children:[e.jsx("div",{className:"font-semibold text-sm mb-3",children:t}),e.jsx("div",{className:"text-xs text-text-muted leading-relaxed mb-5 whitespace-pre-line",children:s}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx("button",{onClick:i,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:a,className:`text-xs px-3 py-1.5 rounded-lg font-medium border transition-colors ${c}`,style:r==="amber"?{background:"color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"}:void 0,children:n})]})]})}),document.body)}function Jr(t){const s=t.replace(/^ide-/,"").replace(/-provider$/,"").toLowerCase(),r=[...Vs,...qs,...Ys].find(a=>a.id===s||s.includes(a.id)||a.id.includes(s));return r?{icon:r.icon,name:r.name}:{icon:"📝",name:t}}function Zr({ide:t,allIdes:s,sendDaemonCommand:n,onDisconnect:r,onRevokeToken:a}){var L,O;const[i,c]=o.useState("idle"),[x,l]=o.useState(""),[p,u]=o.useState(null),[b,g]=o.useState("idle"),[d,h]=o.useState(""),w=t,S=w.version||w.daemonVersion||null,f=((L=w.machine)==null?void 0:L.platform)||((O=w.system)==null?void 0:O.platform)||"",m=Xe(w,{fallbackId:t.id}),N=f==="win32"?"🪟":f==="darwin"?"🍎":"🐧",T=s.filter(C=>C.daemonId===t.id&&C.transport==="cdp-page"),j=s.filter(C=>C.daemonId===t.id&&C.transport==="pty"),k=s.filter(C=>C.daemonId===t.id&&C.transport==="acp"),v=w.p2p,y=async()=>{var C,V,Q;if(n){c("upgrading"),l("Installing latest version...");try{const Z=await n(t.id,"daemon_upgrade",{});(C=Z==null?void 0:Z.result)!=null&&C.upgraded||(V=Z==null?void 0:Z.result)!=null&&V.success?(c("done"),l(`Upgraded to v${Z.result.version||"latest"}. Daemon is restarting...`)):(c("error"),l(((Q=Z==null?void 0:Z.result)==null?void 0:Q.error)||"Upgrade failed"))}catch(Z){c("error"),l((Z==null?void 0:Z.message)||"Connection lost during upgrade")}}},_=async()=>{if(u(null),!!r){g("loading");try{await r(t.id),g("done"),h("Machine disconnected.")}catch(C){g("error"),h((C==null?void 0:C.message)||"Failed to disconnect")}}},P=async()=>{if(u(null),!!a){g("loading");try{await a(t.id),g("done"),h('Token revoked. Machine must restart "adhdev-standalone" to reconnect.')}catch(C){g("error"),h((C==null?void 0:C.message)||"Failed to revoke token")}}},W="0.7.31",M=!S||S!==W,E=T.length+j.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:m}),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),"…"]}),S&&e.jsxs("span",{className:`px-1.5 py-0.5 rounded text-[10px] ${M?"":"bg-bg-secondary"}`,style:M?{background:"color-mix(in srgb, var(--status-warning) 15%, transparent)",color:"var(--status-warning)"}:void 0,children:["v",S,!M&&" ✓"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[n&&M&&e.jsx("button",{onClick:y,disabled:i==="upgrading"||i==="done",className:"btn btn-sm btn-primary disabled:opacity-50 disabled:cursor-not-allowed",title:`Update to v${W}`,children:i==="upgrading"?e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"animate-spin",children:"⟳"})," Upgrading..."]}):i==="done"?"✓ Updated":`↑ Update${` to v${W}`}`}),r&&e.jsx("button",{onClick:()=>u("disconnect"),disabled:b==="loading",className:"btn btn-sm btn-warning disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect this machine",children:"Disconnect"}),a&&e.jsx("button",{onClick:()=>u("revoke"),disabled:b==="loading",className:"btn btn-sm btn-danger disabled:opacity-50 disabled:cursor-not-allowed",title:"Remove machine (requires re-setup)",children:"Remove"}),e.jsx(Ur,{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:[v&&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 ${v.state==="connected"?"bg-green-400":"bg-text-muted/30"} ${v.state==="connecting"||v.state==="new"?"animate-pulse":""}`,style:v.state==="connecting"||v.state==="new"?{background:"var(--status-warning)"}:void 0}),e.jsxs("span",{className:"text-text-muted",children:["P2P ",v.state==="connected"?"connected":v.state==="connecting"||v.state==="new"?"connecting...":v.state||"off"]}),v.peers!==void 0&&v.peers>0&&e.jsxs("span",{className:"text-text-muted/60",children:["(",v.peers," peer",v.peers!==1?"s":"",")"]})]}),v&&E>0&&e.jsx("span",{className:"text-border-subtle",children:"·"}),E>0?e.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-text-muted",children:[T.map(C=>{const V=Jr(C.type),Q=C.cdpConnected;return e.jsxs("span",{className:"flex items-center gap-1 bg-bg-secondary px-1.5 py-0.5 rounded",children:[e.jsx("span",{children:V.icon}),e.jsx("span",{children:V.name}),Q!==void 0&&e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${Q?"bg-green-400":"animate-pulse"}`,style:Q?void 0:{background:"var(--status-warning)"},title:Q?"CDP connected":"CDP connecting..."})]},C.id)}),j.map(C=>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:C.cliName||"CLI"})]},C.id)),k.map(C=>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:C.cliName||"ACP"})]},C.id))]}):e.jsx("span",{className:"text-[11px] text-text-muted/60 italic",children:"No IDEs connected"})]}),(x||d)&&e.jsx("div",{className:`text-xs mt-2 px-1 ${i==="error"||b==="error"?"text-red-400":i==="done"||b==="done"?"text-green-400":"text-text-muted"}`,children:d||x})]}),p==="disconnect"&&e.jsx(os,{title:"🔌 Disconnect Machine",message:`Disconnect "${m}" from ADHDev?
43
-
44
- This will close the server connection. The daemon process will continue running on the machine and will automatically reconnect.
45
-
46
- Use this if you want to temporarily stop remote control.`,confirmLabel:"Disconnect",confirmColor:"amber",onConfirm:_,onCancel:()=>u(null)}),p==="revoke"&&e.jsx(os,{title:"⚠️ Remove Machine",message:`Remove "${m}" from your dashboard?
47
-
48
- This will:
49
- • Immediately disconnect the machine
50
- • Delete the machine registration
51
- • Require restarting "adhdev-standalone" on that machine
52
-
53
- Use this if you want to permanently remove a machine.`,confirmLabel:"Remove Machine",confirmColor:"red",onConfirm:P,onCancel:()=>u(null)})]})}const Qr=[{id:"dark",label:"Dark",icon:"🌙"},{id:"light",label:"Light",icon:"☀️"},{id:"system",label:"System",icon:"💻"}];function ea(){const{preference:t,setPreference:s}=Yr();return e.jsx("div",{className:"flex gap-2",children:Qr.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 Ot={bgPrimary:"#0a0e1a",bgSecondary:"#0f1320",surfacePrimary:"#111726",textPrimary:"#f0f0f5",textSecondary:"#9ca3af",textMuted:"#6b7280",borderSubtle:"#1d2536",borderDefault:"#313c52",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#111726",assistantText:"#f0f0f5",containerBg:"#0f1320",sendButton:"#d97706",inputBorder:"#313c52",bubbleRadius:16},Kt={bgPrimary:"#fff8ee",bgSecondary:"#fff1de",surfacePrimary:"#ffffff",textPrimary:"#24160f",textSecondary:"#6f6255",textMuted:"#938374",borderSubtle:"#e7d3ba",borderDefault:"#d7b892",accentColor:"#d97706",userBubble:"#f59e0b",userText:"#1a1a1a",assistantBubble:"#fffaf4",assistantText:"#24160f",containerBg:"#fff8ee",sendButton:"#d97706",inputBorder:"#d7b892",bubbleRadius:16},ta=[{id:"midnight",name:"Midnight",description:"Classic violet theme",preview:{dark:{userBubble:"#8b5cf6",assistantBubble:"#18181d",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0f0f13",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#7c3aed",assistantBubble:"#ffffff",assistantBorder:"1px solid rgba(0,0,0,0.08)",containerBg:"#f0f1f5",textColor:"#52525b"}}},{id:"ember",name:"Ember",description:"Default landing-inspired amber theme",preview:{dark:{userBubble:"#f59e0b",assistantBubble:"#111726",assistantBorder:"1px solid rgba(255,255,255,0.08)",containerBg:"#0a0e1a",textColor:"#9ca3af"},light:{userBubble:"#f59e0b",assistantBubble:"#fffaf4",assistantBorder:"1px solid rgba(146,64,14,0.10)",containerBg:"#fff8ee",textColor:"#6f6255"}}},{id:"aurora",name:"Aurora",description:"Pink accent theme",preview:{dark:{userBubble:"#ec4899",assistantBubble:"#1e1b2e",assistantBorder:"1px solid rgba(236,72,153,0.12)",containerBg:"#0f0d17",textColor:"rgba(255,255,255,0.7)"},light:{userBubble:"#ec4899",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"}}}],Js="adhdev-chat-theme",Zs="adhdev-chat-theme-custom";function yt(){return typeof window>"u"?"ember":localStorage.getItem(Js)||"ember"}function Ie(t){try{const s=localStorage.getItem(Zs);if(s){const n=JSON.parse(s);return{...t==="dark"?Ot:Kt,...n[t]}}}catch{}return t==="dark"?Ot:Kt}function xt(t,s){localStorage.setItem(Zs,JSON.stringify({dark:t,light:s}))}function Ne(t,s){const n=parseInt(t.slice(1,3),16),r=parseInt(t.slice(3,5),16),a=parseInt(t.slice(5,7),16);return`rgba(${n}, ${r}, ${a}, ${s})`}function Nt(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),a=Math.min(255,parseInt(t.slice(5,7),16)+s);return`#${n.toString(16).padStart(2,"0")}${r.toString(16).padStart(2,"0")}${a.toString(16).padStart(2,"0")}`}const sa={midnight:{dark:"#8b5cf6",light:"#7c3aed"},ember:{dark:"#d97706",light:"#d97706"},aurora:{dark:"#ec4899",light:"#ec4899"},honey:{dark:"#fbbf24",light:"#fbbf24"}};function nt(t,s){var a;const n=(a=sa[t])==null?void 0:a[s];if(!n)return;const r=document.documentElement;r.style.setProperty("--accent-primary",n),r.style.setProperty("--accent-primary-light",Nt(n,24)),r.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${n}, ${Nt(n,18)})`),r.style.setProperty("--border-accent",Ne(n,.35)),r.style.setProperty("--nav-active-bg",Ne(n,.1)),r.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${n}, 0 0 12px ${Ne(n,.06)}`)}function Ke(t){const s=document.documentElement;s.style.setProperty("--bg-primary",t.bgPrimary),s.style.setProperty("--bg-secondary",t.bgSecondary),s.style.setProperty("--bg-card",Ne(t.surfacePrimary,.92)),s.style.setProperty("--surface-primary",t.surfacePrimary),s.style.setProperty("--surface-secondary",t.bgSecondary),s.style.setProperty("--bg-glass",Ne(t.borderSubtle,.15)),s.style.setProperty("--bg-glass-hover",Ne(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",Ne(t.borderSubtle,.5)),s.style.setProperty("--border-default",Ne(t.borderDefault,.5)),s.style.setProperty("--accent-primary",t.accentColor),s.style.setProperty("--accent-primary-light",Nt(t.accentColor,30)),s.style.setProperty("--accent-gradient",`linear-gradient(135deg, ${t.accentColor}, ${Nt(t.accentColor,40)})`),s.style.setProperty("--border-accent",Ne(t.accentColor,.35)),s.style.setProperty("--nav-active-bg",Ne(t.accentColor,.1)),s.style.setProperty("--nav-active-shadow",`inset 3px 0 0 ${t.accentColor}, 0 0 12px ${Ne(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 ${Ne(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 Vt(){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 na(t){if(localStorage.setItem(Js,t),document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ze()?"dark":"light";Ke(Ie(s))}else Vt(),nt(t,ze()?"dark":"light")}function ra(){const t=yt();if(document.documentElement.setAttribute("data-chat-theme",t),t==="custom"){const s=ze()?"dark":"light";Ke(Ie(s))}else Vt(),nt(t,ze()?"dark":"light")}function ze(){const t=document.documentElement.getAttribute("data-theme");return t?t==="dark":window.matchMedia("(prefers-color-scheme: dark)").matches}function he({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 Je({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 aa({dark:t,onColorsChange:s}){const n=t?"dark":"light",[r,a]=o.useState(()=>Ie(n));o.useEffect(()=>{a(Ie(n))},[n]);const i=o.useCallback((c,x)=>{a(l=>{const p={...l,[c]:x},b=Ie(n==="dark"?"light":"dark");return n==="dark"?xt(p,b):xt(b,p),Ke(p),s(p),p})},[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(Je,{title:"App Background",children:[e.jsx(he,{label:"Background",value:r.bgPrimary,onChange:c=>i("bgPrimary",c)}),e.jsx(he,{label:"Surface",value:r.bgSecondary,onChange:c=>i("bgSecondary",c)}),e.jsx(he,{label:"Card",value:r.surfacePrimary,onChange:c=>i("surfacePrimary",c)})]}),e.jsxs(Je,{title:"App Text",children:[e.jsx(he,{label:"Primary",value:r.textPrimary,onChange:c=>i("textPrimary",c)}),e.jsx(he,{label:"Secondary",value:r.textSecondary,onChange:c=>i("textSecondary",c)}),e.jsx(he,{label:"Muted",value:r.textMuted,onChange:c=>i("textMuted",c)})]}),e.jsxs(Je,{title:"Borders & Accent",children:[e.jsx(he,{label:"Border subtle",value:r.borderSubtle,onChange:c=>i("borderSubtle",c)}),e.jsx(he,{label:"Border default",value:r.borderDefault,onChange:c=>i("borderDefault",c)}),e.jsx(he,{label:"Accent",value:r.accentColor,onChange:c=>i("accentColor",c)})]})]}),e.jsxs("div",{children:[e.jsxs(Je,{title:"Chat Bubbles",children:[e.jsx(he,{label:"User bubble",value:r.userBubble,onChange:c=>i("userBubble",c)}),e.jsx(he,{label:"User text",value:r.userText,onChange:c=>i("userText",c)}),e.jsx(he,{label:"Agent bubble",value:r.assistantBubble,onChange:c=>i("assistantBubble",c)}),e.jsx(he,{label:"Agent text",value:r.assistantText,onChange:c=>i("assistantText",c)})]}),e.jsxs(Je,{title:"Chat Layout",children:[e.jsx(he,{label:"Chat BG",value:r.containerBg,onChange:c=>i("containerBg",c)}),e.jsx(he,{label:"Send button",value:r.sendButton,onChange:c=>i("sendButton",c)}),e.jsx(he,{label:"Input border",value:r.inputBorder,onChange:c=>i("inputBorder",c)}),e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsx("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",minWidth:110},children:"Bubble radius"}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,flex:1},children:[e.jsx("input",{type:"range",min:4,max:24,value:r.bubbleRadius,onChange:c=>i("bubbleRadius",Number(c.target.value)),style:{flex:1,accentColor:"var(--accent-primary)"}}),e.jsxs("span",{style:{fontSize:"0.7rem",color:"var(--text-muted)",width:28,textAlign:"right"},children:[r.bubbleRadius,"px"]})]})]})]})]})]}),e.jsx("button",{onClick:()=>{const c=t?Ot:Kt,l=Ie(t?"light":"dark");t?xt(c,l):xt(l,c),a(c),Ke(c),s(c)},style:{marginTop:10,fontSize:"0.7rem",color:"var(--text-muted)",background:"transparent",border:"1px solid var(--border-subtle)",borderRadius:6,padding:"4px 10px",cursor:"pointer"},children:"Reset to defaults"})]})}function oa(){const[t,s]=o.useState(yt),[n,r]=o.useState(!0),[a,i]=o.useState(()=>Ie("dark"));o.useEffect(()=>{r(ze());const l=new MutationObserver(()=>{const b=ze();r(b);const g=yt();g==="custom"?Ke(Ie(b?"dark":"light")):nt(g,b?"dark":"light")});l.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]});const p=window.matchMedia("(prefers-color-scheme: dark)"),u=()=>{const b=ze();r(b);const g=yt();g==="custom"?Ke(Ie(b?"dark":"light")):nt(g,b?"dark":"light")};return p.addEventListener("change",u),()=>{l.disconnect(),p.removeEventListener("change",u)}},[]),o.useEffect(()=>{document.documentElement.setAttribute("data-chat-theme",t),t==="custom"?Ke(Ie(n?"dark":"light")):(Vt(),nt(t,n?"dark":"light"))},[t,n]),o.useEffect(()=>{i(Ie(n?"dark":"light"))},[n]);const c=l=>{s(l),na(l)},x=[...ta,{id:"custom",name:"Custom",description:"Full app + chat customization",preview:{dark:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText},light:{userBubble:a.userBubble,assistantBubble:a.assistantBubble,assistantBorder:`1px solid ${a.accentColor}22`,containerBg:a.containerBg,textColor:a.assistantText}}}];return e.jsxs("div",{children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-4 gap-3",children:x.map(l=>{const p=t===l.id,u=n?l.preview.dark:l.preview.light,b=l.id==="honey"||l.id==="ember"?"#1a1a1a":l.id==="custom"?a.userText:"#fff";return e.jsxs("button",{onClick:()=>c(l.id),className:"text-left rounded-xl p-3 transition-all",style:{background:p?"var(--bg-glass-hover)":"var(--bg-glass)",border:p?"2px solid var(--accent-primary)":"2px solid var(--border-subtle)",opacity:p?1:.75},children:[e.jsxs("div",{className:"rounded-lg p-3 mb-2.5 flex flex-col gap-1.5",style:{background:u.containerBg},children:[e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"Hello! How can I help?"}),e.jsx("div",{className:"self-end rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.userBubble,color:b},children:"Fix the bug please"}),e.jsx("div",{className:"self-start rounded-xl px-3 py-1.5 text-[10px] max-w-[75%]",style:{background:u.assistantBubble,border:u.assistantBorder,color:u.textColor},children:"On it! ✨"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[p&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-accent shrink-0"}),e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-bold text-text-primary",children:l.id==="custom"?"🎨 Custom":l.name}),e.jsx("div",{className:"text-[10px] text-text-muted",children:l.description})]})]})]},l.id)})}),t==="custom"&&e.jsx(aa,{dark:n,onColorsChange:l=>i(l)})]})}const Qs="adhdev_hiddenTabs";function ia(){try{const t=localStorage.getItem(Qs);if(t)return new Set(JSON.parse(t))}catch{}return new Set}function Ze(t){try{localStorage.setItem(Qs,JSON.stringify([...t]))}catch{}}function en(){const[t,s]=o.useState(ia),n=o.useCallback(l=>{s(p=>{const u=new Set(p);return u.has(l)?u.delete(l):u.add(l),Ze(u),u})},[]),r=o.useCallback(l=>{s(p=>{if(p.has(l))return p;const u=new Set(p);return u.add(l),Ze(u),u})},[]),a=o.useCallback(l=>{s(p=>{if(!p.has(l))return p;const u=new Set(p);return u.delete(l),Ze(u),u})},[]),i=o.useCallback((l,p)=>{s(u=>{const b=new Set(u);for(const g of p)b.add(g);return Ze(b),b})},[]),c=o.useCallback((l,p)=>{s(u=>{const b=new Set(u);for(const g of p)b.delete(g);return Ze(b),b})},[]),x=o.useCallback(l=>t.has(l),[t]);return{hiddenTabs:t,toggleTab:n,hideTab:r,showTab:a,hideAllForDaemon:i,showAllForDaemon:c,isHidden:x}}function tn({visibleConversations:t,clearedTabs:s,setClearedTabs:n,setActionLogs:r}){o.useEffect(()=>{$r()},[]);const a=o.useMemo(()=>t.map(i=>({id:i.tabKey,name:i.title||i.agentName||i.ideId,status:i.status,activeModal:i.modalMessage?{message:i.modalMessage,buttons:i.modalButtons}:null})),[t]);return Dr(a),o.useEffect(()=>{if(Object.keys(s).length===0)return;const c=setTimeout(()=>{n(x=>{const l=Date.now(),p={};for(const[u,b]of Object.entries(x))l-b<5e3&&(p[u]=b);return Object.keys(p).length===Object.keys(x).length?x:p})},5500);return()=>clearTimeout(c)},[s,n]),o.useEffect(()=>{const i=setInterval(()=>{const c=Date.now()-3e5;r(x=>{const l=x.filter(p=>p.timestamp>c).slice(-100);return l.length===x.length?x:l})},6e4);return()=>clearInterval(i)},[r]),null}function ca(t){const s=t.filter(r=>r.type!=="adhdev-daemon"),n=new Map;for(const r of s){const a=n.get(r.id);if(!a){n.set(r.id,r);continue}const i=(a.workspace?1:0)+(a.activeChat?1:0);((r.workspace?1:0)+(r.activeChat?1:0)>i||(r.timestamp||0)>(a.timestamp||0))&&n.set(r.id,r)}return Array.from(n.values())}function pt(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n]!==s[n])return!1;return!0}function la(t,s){const n=Date.now();return t.map(r=>{const a=s[r.tabKey];return a&&n-a<5e3?{...r,messages:[],title:""}:r})}function da(t,s){const n=[],r=t.sessionId||t.instanceId;n.push({key:t.id,ref:s[t.id]}),r&&n.push({key:r,ref:s[r]});for(const a of t.childSessions||[]){const i=a.id||a.providerType,c=`${t.id}:${i}`;n.push({key:c,ref:s[c]}),n.push({key:a.id,ref:s[a.id]})}return n}function ua(t,s){if(t.length!==s.length)return!1;for(let n=0;n<t.length;n+=1)if(t[n].key!==s[n].key||t[n].ref!==s[n].ref)return!1;return!0}function xa({ides:t,connectionStates:s,localUserMessages:n,clearedTabs:r,hiddenTabs:a}){const i=o.useRef([]),c=o.useRef([]),x=o.useRef([]),l=o.useRef([]),p=o.useMemo(()=>{const m=ca(t);return pt(i.current,m)?i.current:(i.current=m,m)},[t]),u=o.useMemo(()=>Fs(t),[t]),b=o.useRef(new Map),g=o.useMemo(()=>{var T;const m=new Map,N=[];for(const j of p){const k=j.daemonId||((T=j.id)==null?void 0:T.split(":")[0])||j.id,v=s[k]||"new",y=j.daemonId&&u[j.daemonId]||void 0,_=da(j,n),P=b.current.get(j.id);if(P&&P.ide===j&&P.connectionState===v&&P.machineName===y&&ua(P.localRefs,_)){m.set(j.id,P),N.push(...P.conversations);continue}const W=Hs(j,n,{machineName:y,connectionState:v}),M={ide:j,connectionState:v,machineName:y,localRefs:_,conversations:W};m.set(j.id,M),N.push(...W)}return b.current=m,N},[p,n,s,u]),d=o.useMemo(()=>{const m=la(g,r);return pt(c.current,m)?c.current:(c.current=m,m)},[g,r]),h=o.useMemo(()=>{const m=new Map;for(const N of d)N.sessionId&&m.set(N.sessionId,N),m.set(N.ideId,N),m.set(N.tabKey,N),m.set(N.ideType,N),m.set(N.agentType,N);return m},[d]),w=o.useCallback(m=>{if(m)return h.get(m)},[h]),S=o.useMemo(()=>{const m=d.filter(N=>!a.has(N.tabKey));return pt(x.current,m)?x.current:(x.current=m,m)},[d,a]),f=o.useMemo(()=>{const m=S.map(N=>N.tabKey);return pt(l.current,m)?l.current:(l.current=m,m)},[S]);return{chatIdes:p,conversations:d,visibleConversations:S,visibleTabKeys:f,resolveConversationByTarget:w}}function sn({ides:t,sendDaemonCommand:s,setToasts:n,setLocalUserMessages:r,resolveConversationByTarget:a}){o.useEffect(()=>{Pe.setIdes(t)},[t]),o.useEffect(()=>{Pe.setResolveAction((i,c,x)=>{s(i,c,x).catch(()=>{})})},[s]),o.useEffect(()=>{const i=Pe.onToast(l=>{n(u=>u.some(g=>g.message===l.message&&l.timestamp-g.timestamp<3e3)?u:[...u.slice(-4),{id:l.id,message:l.message,type:l.type,timestamp:l.timestamp,targetKey:l.targetKey,actions:l.actions}]);const p=l.duration||5e3;setTimeout(()=>n(u=>u.filter(b=>b.id!==l.id)),p)}),c=Pe.onSystemMessage((l,p)=>{r(u=>({...u,[l]:[...u[l]||[],p]}))}),x=Pe.onClearSystemMessage((l,p)=>{r(u=>{var b;return(b=u[l])!=null&&b.length?{...u,[l]:u[l].filter(g=>{var d;return!(g.role==="system"&&((d=g._localId)!=null&&d.startsWith(p)))})}:u})});return()=>{i(),c(),x()}},[n,r]),o.useEffect(()=>{const i=Os.on("status_event",c=>Pe.handleRawEvent(c,"ws"));return()=>{i()}},[]),o.useEffect(()=>{var c;const i=x=>{const l=x.data;if((l==null?void 0:l.type)!=="notification_action"||l.action!=="approve"||!(l.ideId||l.targetSessionId||l.targetKey))return;const p=l.targetSessionId||l.targetKey||l.ideId,u=a(p),b=(u==null?void 0:u.ideId)||l.ideId;b&&s(b,"resolve_action",{action:"approve",button:"Approve",...(u==null?void 0:u.sessionId)&&{targetSessionId:u.sessionId},...l.targetSessionId&&{targetSessionId:l.targetSessionId}}).catch(g=>console.error("[SW Action] approve failed:",g))};return(c=navigator.serviceWorker)==null||c.addEventListener("message",i),()=>{var x;return(x=navigator.serviceWorker)==null?void 0:x.removeEventListener("message",i)}},[a,s])}const pa="adhdev_dashboardLayout_v1",Qe={splitGroups:"adhdev_splitGroups",focusedGroup:"adhdev_focusedGroup",groupActiveTabs:"adhdev_groupActiveTabs",groupTabOrders:"adhdev_groupTabOrders",splitSizes:"adhdev_splitSizes"},et={groupAssignments:[],focusedGroup:0,groupActiveTabIds:{},groupTabOrders:{},groupSizes:[]};function tt(t,s){try{const n=localStorage.getItem(t);return n?JSON.parse(n):s}catch{return s}}function ha(t){try{return localStorage.getItem(t)}catch{return null}}function ma(t){return t<768?"mobile":t<1280?"desktop-narrow":"desktop-wide"}function nn(t){return`${pa}:${t}`}function fa(){const t=ha(Qe.focusedGroup),s=tt(Qe.splitGroups,[]),n=tt(Qe.groupActiveTabs,{}),r=tt(Qe.groupTabOrders,{}),a=tt(Qe.splitSizes,[]);return t!==null||s.length>0||Object.keys(n).length>0||Object.keys(r).length>0||a.length>0?{groupAssignments:s,focusedGroup:t&&parseInt(t,10)||0,groupActiveTabIds:n,groupTabOrders:r,groupSizes:a}:null}function ga(t){const s=nn(t),n=tt(s,null);return n||fa()}function ba(t,s){try{const n=s.groupAssignments.length===0&&s.focusedGroup===0&&Object.keys(s.groupActiveTabIds).length===0&&Object.keys(s.groupTabOrders).length===0&&s.groupSizes.length===0,r=nn(t);if(n){localStorage.removeItem(r);return}localStorage.setItem(r,JSON.stringify(s))}catch{}}function ya(){return{groupAssignments:[...et.groupAssignments],focusedGroup:et.focusedGroup,groupActiveTabIds:{...et.groupActiveTabIds},groupTabOrders:{...et.groupTabOrders},groupSizes:[...et.groupSizes]}}function ja(){const[t]=o.useState(()=>ma(typeof window<"u"?window.innerWidth:1280)),[s,n]=o.useState(()=>new Map),[r,a]=o.useState(0),[i,c]=o.useState({}),[x,l]=o.useState({}),[p,u]=o.useState([]),[b,g]=o.useState(()=>typeof window<"u"&&window.innerWidth<768),[d,h]=o.useState(!1),w=o.useCallback(()=>{if(d)return;const S=ga(t)??ya();n(new Map(S.groupAssignments)),a(S.focusedGroup),c(S.groupActiveTabIds),l(S.groupTabOrders),u(S.groupSizes),h(!0)},[d,t]);return o.useEffect(()=>{d&&ba(t,{groupAssignments:[...s.entries()],focusedGroup:r,groupActiveTabIds:i,groupTabOrders:x,groupSizes:p})},[d,t,s,r,i,x,p]),o.useEffect(()=>{const S=window.matchMedia("(max-width: 767px)"),f=m=>g(m.matches);return S.addEventListener("change",f),()=>S.removeEventListener("change",f)},[]),{groupAssignments:s,setGroupAssignments:n,focusedGroup:r,setFocusedGroup:a,groupActiveTabIds:i,setGroupActiveTabIds:c,groupTabOrders:x,setGroupTabOrders:l,groupSizes:p,setGroupSizes:u,isMobile:b,hasHydratedStoredLayout:d,hydrateStoredLayout:w}}function va({urlActiveTab:t,conversations:s,resolveConversationByTarget:n,normalizedGroupAssignments:r,hasHydratedStoredLayout:a,hydrateStoredLayout:i,setGroupActiveTabIds:c,setFocusedGroup:x,setSearchParams:l,historyModalOpen:p,activeConv:u,isRefreshingHistory:b,ides:g,handleRefreshHistory:d,isSplitMode:h,splitTabRelative:w,numGroups:S,clearAllSplits:f}){const m=o.useRef(!1),N=o.useRef(!1),T=o.useRef(null),j=o.useRef(!1);o.useEffect(()=>{if(!t||m.current||s.length===0)return;if(!a){i();return}const k=n(t);if(!k)return;const v=r.get(k.tabKey)??0;c(y=>({...y,[v]:k.tabKey})),x(v),m.current=!0,N.current=!0,T.current!=null&&(window.clearTimeout(T.current),T.current=null),l(y=>{const _=new URLSearchParams(y);return _.delete("activeTab"),_},{replace:!0})},[t,s,n,r,a,i,c,x,l]),o.useEffect(()=>{if(!(N.current||a)&&s.length!==0){if(!t){i(),N.current=!0;return}if(m.current){N.current=!0;return}if(T.current==null)return T.current=window.setTimeout(()=>{T.current=null,!(N.current||a)&&(i(),N.current=!0)},1500),()=>{T.current!=null&&(window.clearTimeout(T.current),T.current=null)}}},[t,s.length,a,i]),o.useEffect(()=>{if(!p){j.current=!1;return}if(!u||j.current||b)return;const k=g.find(v=>v.id===u.ideId);k&&(!k.chats||k.chats.length===0)&&(j.current=!0,d())},[p,u,b,g,d]),o.useEffect(()=>{const k=v=>{if(v.ctrlKey&&v.key==="\\"){if(v.preventDefault(),h)f();else{const y=s[1];y&&w(y.tabKey,0,"right")}return}v.ctrlKey&&(v.key==="["||v.key==="]")&&h&&(v.preventDefault(),x(y=>v.key==="]"?Math.min(y+1,S-1):Math.max(y-1,0)))};return window.addEventListener("keydown",k),()=>window.removeEventListener("keydown",k)},[h,s,w,S,f,x]),o.useEffect(()=>{if(!u)return;let k=null,v=0,y=-1,_=0;const P=()=>{k=null;const W=Array.from(document.querySelectorAll("[data-chat-scroll]")).filter(E=>E.offsetParent!==null);if(W.length===0){v<18&&(v+=1,k=requestAnimationFrame(P));return}let M=0;for(const E of W)E.scrollTop=E.scrollHeight,M+=E.scrollHeight;M===y?_+=1:(_=0,y=M),v+=1,!(_>=2||v>=18)&&(k=requestAnimationFrame(P))};return k=requestAnimationFrame(P),()=>{k!=null&&cancelAnimationFrame(k)}},[u==null?void 0:u.tabKey])}function _e(t){if(!t)return{};const s=t.sessionId?{targetSessionId:t.sessionId}:{};return je(t)||fe(t)?{...s,agentType:t.agentType||t.ideType}:t.streamSource==="agent-stream"?{...s,agentType:t.agentType}:s}function kt(t){return t&&(t.ideId||t.daemonId)||""}function ht(t,s){t(n=>[...n,{id:Date.now(),message:s,type:"warning",timestamp:Date.now()}])}function wa({sendDaemonCommand:t,activeConv:s,updateIdeChats:n,setToasts:r,setLocalUserMessages:a,setClearedTabs:i}){const[c,x]=o.useState(!1),[l,p]=o.useState(!1),u=o.useCallback(async h=>{try{await t("standalone","launch_ide",{ideType:h,enableCdp:!0})}catch(w){console.error("Launch failed",w)}},[t]),b=o.useCallback(async(h,w)=>{try{const S=h||(s==null?void 0:s.daemonId)||"",f=await t(S,"switch_chat",{id:w,sessionId:w,..._e(s)}),m=f==null?void 0:f.result;if((f==null?void 0:f.success)===!0||m==="switched"||m==="switched-by-title")return;m===!1||m==="not_found"?ht(r,"⚠️ Session tab not found — try refreshing history"):typeof m=="string"&&m.startsWith("error:")?ht(r,`⚠️ Switch error: ${m}`):ht(r,"⚠️ Session switch failed")}catch(S){console.error("Switch failed",S),ht(r,`❌ Switch failed: ${S.message||"connection error"}`)}},[s,t,r]),g=o.useCallback(async()=>{if(!(!s||c)){x(!0);try{const h=kt(s);await t(h,"new_chat",{..._e(s)}),i(w=>({...w,[s.tabKey]:Date.now()})),a(w=>({...w,[s.tabKey]:[]}))}catch(h){console.error("New chat failed",h)}finally{x(!1)}}},[s,c,t,i,a]),d=o.useCallback(async()=>{var h;if(!(!s||l)){p(!0);try{const w=kt(s),S=await t(w,"list_chats",{forceExpand:!0,..._e(s)}),f=(S==null?void 0:S.chats)||((h=S==null?void 0:S.result)==null?void 0:h.chats);S!=null&&S.success&&Array.isArray(f)&&n(s.ideId,f)}catch(w){console.error("Refresh history failed",w)}finally{p(!1)}}},[s,l,t,n]);return{isCreatingChat:c,isRefreshingHistory:l,handleLaunchIde:u,handleSwitchSession:b,handleNewChat:g,handleRefreshHistory:d}}function Na(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 ka(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(a=>s[Number(a)]===t[Number(a)])}function mt(t,s){const n=new Set(s),r=s.length>0?[0]:[];for(const[c,x]of t)!n.has(c)||x<=0||r.includes(x)||r.push(x);r.sort((c,x)=>c-x);const a={};r.forEach((c,x)=>{a[c]=x}),r.length===0&&(a[0]=0);const i=new Map;for(const[c,x]of t){if(!n.has(c)||x<=0)continue;const l=a[x];typeof l=="number"&&l>0&&i.set(c,l)}return{assignments:i,groupCount:Math.max(1,r.length),mapping:a,usedGroups:r}}function cs(t,s){const n={};for(const[r,a]of Object.entries(t)){const i=s[Number(r)];typeof i=="number"&&(n[i]=a)}return n}function Sa(t,s,n){if(s.length===0)return 0;if(typeof n[t]=="number")return n[t];const r=[...s].reverse().find(a=>a<t)??s[0];return n[r]??0}function Ca(t,s,n){if(s.length<=1)return[];const r=s.map(c=>t[c]).filter(c=>Number.isFinite(c)),a=r.length===s.length?r:Array(n).fill(100/n),i=a.reduce((c,x)=>c+x,0);return i>0?a.map(c=>c/i*100):Array(n).fill(100/n)}function ls(t,s){const n={};for(const[r,a]of Object.entries(t)){const i=Number(r);n[i>=s?i+1:i]=a}return n}function ds(t){return Array(t).fill(100/t)}function Ia({groupAssignments:t,setGroupAssignments:s,setFocusedGroup:n,setGroupActiveTabIds:r,setGroupTabOrders:a,groupSizes:i,setGroupSizes:c,isMobile:x,visibleConversations:l,visibleTabKeys:p}){const u=o.useRef(null),b=o.useMemo(()=>mt(t,p),[t,p]),g=b.assignments,d=o.useMemo(()=>x?1:b.groupCount,[b.groupCount,x]),h=d>1,w=o.useCallback((j,k)=>{s(v=>{const y=new Map(mt(v,p).assignments);return k===0?y.delete(j):y.set(j,k),y}),r(v=>({...v,[k]:j})),n(k)},[s,p,r,n]),S=o.useCallback(j=>{s(k=>{const v=mt(k,p).assignments,y=new Map;for(const[_,P]of v)P!==j&&(P>j?y.set(_,P-1):y.set(_,P));return y}),c(k=>{if(k.length<=1)return[];const v=[...k];v.splice(j,1);const y=v.reduce((_,P)=>_+P,0);return y>0?v.map(_=>_/y*100):[]}),n(0)},[s,p,c,n]),f=o.useCallback((j,k)=>{k.preventDefault();const v=u.current;if(!v)return;const y=k.clientX,_=v.offsetWidth,P=i.length===d?[...i]:ds(d),W=E=>{const O=(E.clientX-y)/_*100,C=[...P];C[j]=Math.max(15,P[j]+O),C[j+1]=Math.max(15,P[j+1]-O),c(C)},M=()=>{document.removeEventListener("mousemove",W),document.removeEventListener("mouseup",M),document.body.style.cursor="",document.body.style.userSelect=""};document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",W),document.addEventListener("mouseup",M)},[i,d,c]),m=o.useCallback((j,k,v)=>{if(d>=4)return;const y=v==="left"?k:k+1;s(_=>{const P=mt(_,p).assignments,W=new Map;for(const M of l){const E=P.get(M.tabKey)??0,L=E>=y?E+1:E;L>0&&W.set(M.tabKey,L)}return y>0&&W.set(j,y),W}),c(_=>{const P=_.length===d?[..._]:ds(d),W=P[k]??100/d,M=Math.max(15,W/2),E=Math.max(15,W/2),L=[...P];L[k]=M,L.splice(y,0,E);const O=L.reduce((C,V)=>C+V,0);return L.map(C=>C/O*100)}),r(_=>{const P=ls(_,y);return P[y]=j,P}),a(_=>{const P=ls(_,y);return P[y]=[j],P}),n(y)},[d,s,p,l,c,r,a,n]);o.useEffect(()=>{Na(t,g)||s(g)},[t,g,s]),o.useEffect(()=>{const{mapping:j,usedGroups:k}=b;r(v=>{const y=cs(v,j);return is(v,y)?v:y}),a(v=>{const y=cs(v,j);return is(v,y)?v:y}),n(v=>{const y=x?0:Sa(v,k,j);return v===y?v:y}),c(v=>{const y=x?[]:Ca(v,k,b.groupCount);return ka(v,y)?v:y})},[b,x,r,a,n,c]);const N=o.useMemo(()=>{const j=Array.from({length:d},()=>[]);for(const k of l){const v=g.get(k.tabKey)??0,y=Math.min(v,d-1);j[y].push(k)}return j},[l,g,d]),T=o.useCallback(()=>{s(new Map),n(0)},[s,n]);return{containerRef:u,normalizedGroupAssignments:g,numGroups:d,isSplitMode:h,groupedConvs:N,moveTabToGroup:w,closeGroup:S,handleResizeStart:f,splitTabRelative:m,clearAllSplits:T}}function Ma({ides:t,sendDaemonCommand:s}){const n="0.7.31",r=o.useMemo(()=>t.filter(p=>{if(p.type!=="adhdev-daemon")return!1;const u=p.version||p.daemonVersion||null;return!u||!n?!1:u!==n}),[n,t]),[a,i]=o.useState(!1),[c,x]=o.useState({}),l=o.useCallback(async p=>{var u,b;x(g=>({...g,[p]:"upgrading"}));try{const g=await s(p,"daemon_upgrade",{});(u=g==null?void 0:g.result)!=null&&u.upgraded||(b=g==null?void 0:g.result)!=null&&b.success?x(d=>({...d,[p]:"done"})):x(d=>({...d,[p]:"error"}))}catch{x(g=>({...g,[p]:"error"}))}},[s]);return{versionMismatchDaemons:r,appVersion:n,versionBannerDismissed:a,setVersionBannerDismissed:i,upgradingDaemons:c,handleBannerUpgrade:l}}function rn({sendDaemonCommand:t,activeConv:s,setLocalUserMessages:n,setActionLogs:r,isStandalone:a}){const[i,c]=o.useState(!1),[x,l]=o.useState(!1),p=o.useRef(!1),u=o.useCallback(async h=>{if(!s)return;const w=h.trim();if(!w||p.current)return;const S=s.tabKey;p.current=!0,l(!0);const f=`${Date.now()}-${Math.random().toString(36).slice(2,8)}`,m={role:"user",content:w,timestamp:Date.now(),_localId:f};n(N=>({...N,[S]:[...N[S]||[],m]}));try{const N=kt(s);if(!N)return;await t(N,"send_chat",{message:w,text:w,..._e(s)}),setTimeout(()=>{const T=Date.now()-6e4;n(j=>{const k=j[S];if(!k)return j;const v=k.filter(y=>y.timestamp>T);return v.length===k.length?j:{...j,[S]:v}})},6e4)}catch(N){console.error("Send failed",N),n(T=>({...T,[S]:(T[S]||[]).filter(j=>j._localId!==f)}))}finally{p.current=!1,l(!1)}},[s,t,n]),b=o.useCallback(async()=>{if(s)try{if(a){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(h){console.error("Relaunch failed",h)}},[s,a,t]),g=o.useCallback(async h=>{if(s){r(w=>[...w,{ideId:s.tabKey,text:`🖱️ **${h}** clicked`,timestamp:Date.now()}]);try{const S=(s.modalButtons||[]).indexOf(h),f=h.replace(/[⌥⏎⇧⌫⌘⌃]/g,"").trim().toLowerCase(),m=/^(run|approve|accept|yes|allow|always|proceed|save)/.test(f),N=kt(s);if(!N)return;(await t(N,"resolve_action",{button:h,action:m?"approve":"reject",...S>=0&&{buttonIndex:S},..._e(s)})).success||r(j=>[...j,{ideId:s.tabKey,text:`⚠️ **${h}** failed — button not found`,timestamp:Date.now()}])}catch(w){console.error("[ModalButton] Error:",w),r(S=>[...S,{ideId:s.tabKey,text:`❌ **${h}** error`,timestamp:Date.now()}])}}},[s,t,r]),d=o.useCallback(async()=>{if(!(!s||i)){c(!0);try{await t(s.ideId,"focus_session",{agentType:s.agentType,...s.sessionId&&{targetSessionId:s.sessionId}})}catch(h){console.error("Focus agent failed",h)}finally{c(!1)}}},[s,i,t]);return{isSendingChat:x,isFocusingAgent:i,handleSendChat:u,handleRelaunch:b,handleModalButton:g,handleFocusAgent:d}}function At(t,s){return!!(t<4&&s&&window.innerWidth>=768)}function Ta({conversations:t,numGroups:s,onMoveTab:n,onReceiveTab:r,onOwnTabDrop:a,onClearPreviewOrder:i}){const c=o.useRef(0),[x,l]=o.useState(!1),[p,u]=o.useState(null),b=o.useCallback(()=>{c.current=0,l(!1),u(null)},[]);o.useEffect(()=>(window.addEventListener("dragend",b),window.addEventListener("drop",b),()=>{window.removeEventListener("dragend",b),window.removeEventListener("drop",b)}),[b]);const g=o.useCallback(S=>{S.dataTransfer.types.includes("text/tab-key")&&(c.current+=1,l(!0))},[]),d=o.useCallback(S=>{if(!S.dataTransfer.types.includes("text/tab-key"))return;if(S.preventDefault(),!At(s,n)){u("merge");return}const f=S.currentTarget.getBoundingClientRect(),m=S.clientX-f.left,N=f.width/3;m<N?u("split-left"):m>N*2?u("split-right"):u("merge")},[s,n]),h=o.useCallback(()=>{c.current-=1,!(c.current>0)&&(c.current=0,l(!1),u(null))},[]),w=o.useCallback(S=>{c.current=0,l(!1);const f=S.dataTransfer.getData("text/tab-key"),m=f?t.some(T=>T.tabKey===f):!1,N=p;if(u(null),i(),!!f){if(S.preventDefault(),N==="split-left"&&At(s,n)){n==null||n(f,"split-left");return}if(N==="split-right"&&At(s,n)){n==null||n(f,"split-right");return}if(m){a(f);return}r==null||r(f)}},[t,p,s,n,r,a,i]);return{dragOver:x,dropAction:p,resetDragState:b,handleDragEnter:g,handleDragOver:d,handleDragLeave:h,handleDrop:w}}function Ea(t,s){const n=new Set(s.map(i=>i.tabKey)),r=t.filter(i=>n.has(i)),a=s.filter(i=>!t.includes(i.tabKey)).map(i=>i.tabKey);return[...r,...a]}function Aa({conversations:t,initialActiveTabId:s,initialTabOrder:n,onActiveTabChange:r,onTabOrderChange:a}){const[i,c]=o.useState(s??null),[x,l]=o.useState(n??[]),[p,u]=o.useState(null),b=o.useRef(null),g=o.useRef(null),d=o.useRef(r),h=o.useRef(a);o.useEffect(()=>{d.current=r},[r]),o.useEffect(()=>{h.current=a},[a]),o.useEffect(()=>{s&&s!==i&&c(s)},[s,i]),o.useEffect(()=>{l(v=>{const y=Ea(v,t);return y.length===v.length&&y.every((_,P)=>_===v[P])?v:y})},[t]);const w=o.useMemo(()=>{const v=p??x;if(v.length===0)return t;const y=new Map(v.map((_,P)=>[_,P]));return[...t].sort((_,P)=>{const W=y.get(_.tabKey)??999,M=y.get(P.tabKey)??999;return W-M})},[t,p,x]);o.useEffect(()=>{var y,_;if(w.length===0){i!==null&&(c(null),(y=d.current)==null||y.call(d,null));return}if(i&&w.some(P=>P.tabKey===i))return;const v=w[0].tabKey;v!==i&&(c(v),(_=d.current)==null||_.call(d,v))},[w,i]);const S=o.useMemo(()=>w.find(v=>v.tabKey===i),[w,i]),f=o.useCallback(v=>{var y;c(v),(y=d.current)==null||y.call(d,v)},[]),m=o.useCallback((v,y,_)=>{l(P=>{var L;const W=P.filter(O=>O!==v),M=W.indexOf(y);if(M<0)return P;const E=_==="left"?M:M+1;return W.splice(E,0,v),(L=h.current)==null||L.call(h,W),W}),u(null)},[]),N=o.useCallback((v,y,_)=>{const W=(x.length>0?x:t.map(L=>L.tabKey)).filter(L=>L!==v),M=W.indexOf(y);if(M<0)return;const E=_==="left"?M:M+1;W.splice(E,0,v),b.current=W,u(W)},[x,t]),T=o.useCallback(()=>{var y;const v=b.current;v&&(l(v),(y=h.current)==null||y.call(h,v))},[]),j=o.useCallback(()=>{b.current=null,u(null)},[]),k=o.useCallback(v=>{l(y=>{var P;const _=y.filter(W=>W!==v);return _.push(v),(P=h.current)==null||P.call(h,_),_})},[]);return{activeTabId:i,activeConv:S,sortedConversations:w,previewOrderRef:b,draggingTabRef:g,selectTab:f,handleTabReorder:m,updatePreviewOrder:N,commitPreviewOrder:T,clearPreviewOrder:j,moveTabToEnd:k,setDraggingTabKey:v=>{g.current=v}}}const Ra=o.memo(function({activeConv:s,clearToken:n,isCli:r,ideEntry:a,screenshotUrl:i,clearScreenshot:c,terminalRef:x,handleModalButton:l,handleRelaunch:p,handleSendChat:u,isSendingChat:b,handleFocusAgent:g,isFocusingAgent:d,actionLogs:h,userName:w}){const S=o.useCallback(()=>{c()},[c]);return e.jsxs(e.Fragment,{children:[e.jsx($s,{activeConv:s,onModalButton:l}),e.jsx("div",{className:"desktop-only px-3 pt-1 pb-2",children:!r&&s.transport!=="acp"&&i?e.jsx(sr,{screenshotUrl:i,mode:"preview",onDismiss:S}):!r&&s.transport!=="acp"&&s.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(Ft,{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:p,children:"Relaunch with CDP"})]}):null}),r?e.jsx(yr,{activeConv:s,clearToken:n,terminalRef:x,handleSendChat:u,isSendingChat:b}):e.jsx(Bs,{activeConv:s,ideEntry:a,handleSendChat:u,isSendingChat:b,handleFocusAgent:g,isFocusingAgent:d,actionLogs:h,userName:w})]})},(t,s)=>t.activeConv===s.activeConv&&t.isCli===s.isCli&&t.ideEntry===s.ideEntry&&t.screenshotUrl===s.screenshotUrl&&t.terminalRef===s.terminalRef&&t.handleModalButton===s.handleModalButton&&t.handleRelaunch===s.handleRelaunch&&t.handleSendChat===s.handleSendChat&&t.isSendingChat===s.isSendingChat&&t.handleFocusAgent===s.handleFocusAgent&&t.isFocusingAgent===s.isFocusingAgent&&t.actionLogs===s.actionLogs&&t.userName===s.userName);function _a({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 Rt={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 La(){return typeof navigator>"u"?"unix":navigator.userAgent.toLowerCase().includes("win")?"windows":"unix"}function $a(){const[t,s]=o.useState("unix"),[n,r]=o.useState("powershell"),[a,i]=o.useState(!1),c=t==="unix"?"unix":n;o.useEffect(()=>{s(La())},[]);const x=o.useCallback(()=>{navigator.clipboard.writeText(Rt[c].cmd).catch(()=>{}),i(!0),setTimeout(()=>i(!1),2e3)},[c]);return e.jsxs("div",{className:"text-left bg-bg-secondary border border-border-subtle rounded-xl p-4 font-mono text-[13px] shadow-lg w-full mx-auto leading-relaxed relative select-all",children:[e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="unix"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("unix"),children:"🍎🐧 macOS / Linux"}),e.jsx("button",{className:`text-[10px] px-2.5 py-1 rounded-md font-bold transition-all cursor-pointer ${t==="windows"?"bg-accent/15 text-accent border border-accent/25":"bg-transparent text-text-muted border border-transparent hover:text-text-secondary"}`,onClick:()=>s("windows"),children:"🪟 Windows"})]}),t==="windows"&&e.jsxs("div",{className:"flex gap-1 mb-3 font-sans",children:[e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="powershell"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("powershell"),children:"⚡ PowerShell"}),e.jsx("button",{className:`text-[9px] px-2 py-0.5 rounded font-semibold cursor-pointer transition-all ${n==="cmd"?"bg-accent/10 text-accent":"text-text-muted hover:text-text-secondary"}`,onClick:()=>r("cmd"),children:">_ CMD"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-accent cursor-pointer group",onClick:x,title:"Click to copy",children:[e.jsx("span",{className:"text-text-muted select-none",children:Rt[c].prompt}),e.jsx("span",{className:"flex-1 break-all",children:Rt[c].cmd}),e.jsx("span",{className:"text-[9px] font-sans text-text-muted opacity-0 group-hover:opacity-100 transition-opacity shrink-0 select-none",children:a?"✓":"📋"})]}),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 Pa({conversationsCount:t,isSplitMode:s,isStandalone:n,detectedIdes:r,handleLaunchIde:a}){return t===0&&!s&&r&&a?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($a,{}),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(i=>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:()=>a(i.type),children:[e.jsx(As,{size:14,className:"opacity-70"})," Launch ",i.name]},i.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 an="adhdev-tab-shortcuts";function Da(){try{return JSON.parse(localStorage.getItem(an)||"{}")}catch{return{}}}function Ba({sortedTabKeys:t,onFocus:s,onSelectTab:n}){const r=typeof navigator<"u"&&/Mac|iPhone|iPad/.test(navigator.userAgent),[a,i]=o.useState(()=>Da()),[c,x]=o.useState(null),l=o.useCallback(u=>{const b=[];return u.metaKey&&b.push(r?"⌘":"Meta"),u.ctrlKey&&b.push("Ctrl"),u.altKey&&b.push(r?"⌥":"Alt"),u.shiftKey&&b.push(r?"⇧":"Shift"),["Control","Alt","Shift","Meta"].includes(u.key)?null:(b.push(u.key.length===1?u.key.toUpperCase():u.key),b.join("+"))},[r]),p=o.useCallback(u=>{i(u);try{localStorage.setItem(an,JSON.stringify(u))}catch{}},[]);return o.useEffect(()=>{if(!c)return;const u=b=>{if(b.preventDefault(),b.stopPropagation(),b.key==="Escape"){x(null);return}const g=l(b);if(!g)return;const d={...a};for(const[h,w]of Object.entries(d))w===g&&delete d[h];d[c]=g,p(d),x(null)};return window.addEventListener("keydown",u,!0),()=>window.removeEventListener("keydown",u,!0)},[c,a,p,l]),o.useEffect(()=>{const u=b=>{if(!(!b.ctrlKey&&!b.metaKey&&!b.altKey)){for(const[g,d]of Object.entries(a))if(t.includes(g)&&l(b)===d){b.preventDefault(),s(),n(g);return}}};return window.addEventListener("keydown",u),()=>window.removeEventListener("keydown",u)},[a,t,s,n,l]),{isMac:r,tabShortcuts:a,shortcutListening:c,setShortcutListening:x,saveShortcuts:p}}const Wa=o.memo(function({conv:s,isActive:n,isDraggedTab:r,shortcut:a,conversationKeys:i,draggingTabRef:c,onFocus:x,onSelectTab:l,onConversationActivated:p,onPreviewReorder:u,onReorderTab:b,onCommitPreviewOrder:g,onClearPreviewOrder:d,onDragStateReset:h,onDragTabKeyChange:w,onReceiveTab:S,onOpenContextMenu:f,longPressTimer:m}){const N=s.status==="generating"?"agent-tab-generating":s.status==="waiting_approval"?"agent-tab-waiting":"",T=s.connectionState==="failed"||s.connectionState==="closed",j=o.useCallback(E=>{c.current=s.tabKey,w(s.tabKey),E.dataTransfer.setData("text/tab-key",s.tabKey),E.dataTransfer.effectAllowed="move"},[s.tabKey,c,w]),k=o.useCallback(()=>{c.current=null,w(null),g(),d(),h()},[c,w,g,d,h]),v=o.useCallback(E=>{const L=c.current;if(!(!L||L===s.tabKey)&&E.dataTransfer.types.includes("text/tab-key")){E.preventDefault(),E.stopPropagation();const O=E.currentTarget.getBoundingClientRect(),C=E.clientX<O.left+O.width/2?"left":"right";u(L,s.tabKey,C)}},[s.tabKey,c,u]),y=o.useCallback(E=>{E.preventDefault(),E.stopPropagation();const L=E.dataTransfer.getData("text/tab-key");if(L&&L!==s.tabKey){const O=E.currentTarget.getBoundingClientRect(),C=E.clientX<O.left+O.width/2?"left":"right";i.includes(L)?b(L,s.tabKey,C):S&&S(L)}d()},[s.tabKey,i,b,S,d]),_=o.useCallback(E=>{E.stopPropagation(),x(),l(s.tabKey),p(s)},[s,p,x,l]),P=o.useCallback(E=>{E.preventDefault(),f(E.clientX,E.clientY,s.tabKey)},[s.tabKey,f]),W=o.useCallback(E=>{const L=E.touches[0];m.current=setTimeout(()=>{f(L.clientX,L.clientY,s.tabKey)},600)},[s.tabKey,m,f]),M=o.useCallback(()=>{m.current&&clearTimeout(m.current)},[m]);return e.jsxs("div",{"data-tabkey":s.tabKey,className:`${N} shrink-0 px-2.5 py-1.5 rounded-t-lg cursor-pointer flex items-center gap-2 relative`,draggable:!0,onDragStart:j,onDragEnd:k,onDragOver:v,onDrop:y,onClick:_,onContextMenu:P,onTouchStart:W,onTouchEnd:M,onTouchMove:M,style:{background:n?"var(--bg-primary)":"var(--bg-glass)",borderTop:n?"1px solid var(--border-subtle)":"1px solid transparent",borderLeft:n?"1px solid var(--border-subtle)":"1px solid transparent",borderRight:n?"1px solid var(--border-subtle)":"1px solid transparent",opacity:r?.4:T?n?.6:.3:n?1:.65,transition:"transform 0.2s ease, opacity 0.15s ease"},children:[s.status==="generating"?e.jsx("div",{className:"tab-spinner"}):s.status==="waiting_approval"?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400",children:"▲"}):T?e.jsx("span",{className:"text-[8px] px-[5px] py-px text-yellow-400 animate-pulse",children:"○"}):s.connectionState==="connecting"||s.connectionState==="new"?e.jsx("div",{className:"tab-connecting-spinner"}):s.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:s.displayPrimary,children:s.displayPrimary}),e.jsx("div",{className:"text-[8px] opacity-50 flex gap-1 items-center",children:T?e.jsx("span",{className:"text-yellow-400 opacity-100",children:"Reconnecting…"}):s.connectionState==="connecting"||s.connectionState==="new"?e.jsxs("span",{className:"text-blue-400 opacity-100",children:["Connecting",e.jsx("span",{className:"connecting-dots"})]}):e.jsxs(e.Fragment,{children:[s.displaySecondary,s.machineName&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"opacity-40",children:"·"}),e.jsxs("span",{className:"opacity-70",children:["🖥 ",s.machineName]})]})]})})]}),a&&e.jsx("span",{className:"text-[9px] opacity-50 font-mono ml-0.5 shrink-0 bg-bg-secondary px-1 rounded",title:`Ctrl+${a}`,children:a})]})},(t,s)=>t.conv===s.conv&&t.isActive===s.isActive&&t.isDraggedTab===s.isDraggedTab&&t.shortcut===s.shortcut&&t.conversationKeys===s.conversationKeys);function Oa({conversations:t,activeTabId:s,groupIndex:n,numGroups:r,draggingTabRef:a,onFocus:i,onSelectTab:c,onConversationActivated:x,onPreviewReorder:l,onReorderTab:p,onCommitPreviewOrder:u,onClearPreviewOrder:b,onDragStateReset:g,onDragTabKeyChange:d,onMoveTab:h,onReceiveTab:w,onHideTab:S}){const[f,m]=o.useState(null),N=o.useRef(null),T=o.useRef(null),j=o.useMemo(()=>t.map(M=>M.tabKey),[t]);it("PaneGroupTabBar",{groupIndex:n,activeTabId:s,tabCount:t.length,ctxMenuTab:(f==null?void 0:f.tabKey)||null});const{isMac:k,tabShortcuts:v,shortcutListening:y,setShortcutListening:_,saveShortcuts:P}=Ba({sortedTabKeys:t.map(M=>M.tabKey),onFocus:i,onSelectTab:c});o.useEffect(()=>{if(!f)return;const M=E=>{const L=document.querySelector("[data-pane-context-menu]");L&&L.contains(E.target)||m(null)};return window.addEventListener("mousedown",M,!0),()=>window.removeEventListener("mousedown",M,!0)},[f]),o.useEffect(()=>{const M=T.current;if(!M)return;const E=L=>{Math.abs(L.deltaY)>Math.abs(L.deltaX)&&(L.preventDefault(),M.scrollLeft+=L.deltaY)};return M.addEventListener("wheel",E,{passive:!1}),()=>M.removeEventListener("wheel",E)},[]);const W=o.useCallback((M,E,L)=>{m({x:M,y:E,tabKey:L})},[]);return 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:T,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(M=>e.jsx(Wa,{conv:M,isActive:s===M.tabKey,isDraggedTab:a.current===M.tabKey,shortcut:v[M.tabKey],conversationKeys:j,draggingTabRef:a,onFocus:i,onSelectTab:c,onConversationActivated:x,onPreviewReorder:l,onReorderTab:p,onCommitPreviewOrder:u,onClearPreviewOrder:b,onDragStateReset:g,onDragTabKeyChange:d,onReceiveTab:w,onOpenContextMenu:W,longPressTimer:N},M.tabKey)),t.length===0&&e.jsx("div",{className:"p-2 text-xs opacity-40",children:"No tabs in this group"})]})}),f&&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:f.x,top:f.y},children:[h&&n>0&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{h(f.tabKey,"left"),m(null)},children:"← Move to Left Group"}),h&&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:()=>{h(f.tabKey,"right"),m(null)},children:"Move to Right Group →"}),h&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{h(f.tabKey,"split-left"),m(null)},children:"⇤ Split Left"}),h&&r<4&&e.jsx("button",{className:"w-full text-left px-3 py-1.5 text-xs hover:bg-bg-secondary transition-colors ",onClick:()=>{h(f.tabKey,"split-right"),m(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:M=>{M.stopPropagation(),_(f.tabKey),m(null)},children:["⌨ ",v[f.tabKey]?`Change shortcut (${v[f.tabKey]})`:"Set shortcut"]}),v[f.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 M={...v};delete M[f.tabKey],P(M),m(null)},children:"✕ Remove shortcut"}),S&&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:()=>{S(f.tabKey),m(null)},children:"🚫 Hide from Dashboard"})]}),!h&&!S&&e.jsx("div",{className:"px-3 py-1.5 text-[11px] text-text-muted opacity-50 italic",children:"No actions available"})]}),y&&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:()=>_(null),children:e.jsxs("div",{className:"bg-bg-primary border border-border-subtle rounded-xl px-8 py-6 text-center shadow-xl",onClick:M=>M.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 Ka({conversations:t,ides:s,clearedTabs:n,actionLogs:r,screenshotMap:a,setScreenshotMap:i,sendDaemonCommand:c,setLocalUserMessages:x,setActionLogs:l,isStandalone:p,userName:u,groupIndex:b,onFocus:g,isSplitMode:d,numGroups:h,onMoveTab:w,onReceiveTab:S,style:f,detectedIdes:m,handleLaunchIde:N,onActiveTabChange:T,initialActiveTabId:j,initialTabOrder:k,onTabOrderChange:v,onHideTab:y}){const{sendCommand:_}=De(),P=o.useRef(null),{activeTabId:W,activeConv:M,sortedConversations:E,draggingTabRef:L,selectTab:O,handleTabReorder:C,updatePreviewOrder:V,commitPreviewOrder:Q,clearPreviewOrder:Z,moveTabToEnd:G,setDraggingTabKey:te}=Aa({conversations:t,initialActiveTabId:j,initialTabOrder:k,onActiveTabChange:T,onTabOrderChange:v}),Y=rn({sendDaemonCommand:c,activeConv:M,setLocalUserMessages:x,setActionLogs:l,isStandalone:p}),{dragOver:se,dropAction:ee,resetDragState:ie,handleDragEnter:B,handleDragOver:$,handleDragLeave:A,handleDrop:R}=Ta({conversations:t,numGroups:h,onMoveTab:w,onReceiveTab:S,onOwnTabDrop:G,onClearPreviewOrder:Z}),D=M&&je(M)&&!fe(M),H=o.useMemo(()=>M?s.find(re=>re.id===M.ideId):void 0,[s,M]),U=M?a[M.ideId]:void 0,ae=o.useCallback(()=>{if(!M||!(M.ideId in a))return;const re={...a};delete re[M.ideId],i(re)},[M,a,i]),de=o.useMemo(()=>M?r.filter(re=>re.ideId===M.tabKey):[],[r,M]);it("PaneGroup",{groupIndex:b,conversationCount:t.length,activeTabId:W,dragOver:se});const ce=o.useCallback(re=>{re.streamSource==="agent-stream"&&re.agentType&&_(re.ideId,"focus_session",{agentType:re.agentType,...re.sessionId&&{targetSessionId:re.sessionId}}).catch(()=>{})},[_]);return e.jsxs("div",{className:"flex flex-col min-h-0 min-w-0 flex-1 overflow-hidden",onClick:g,style:{...f,outline:se?"2px dashed var(--accent-primary)":"none",outlineOffset:"-2px",transition:"outline 0.15s ease"},children:[e.jsx(Oa,{conversations:E,activeTabId:W,groupIndex:b,numGroups:h,draggingTabRef:L,onFocus:g,onSelectTab:O,onConversationActivated:ce,onPreviewReorder:V,onReorderTab:C,onCommitPreviewOrder:Q,onClearPreviewOrder:Z,onDragStateReset:ie,onDragTabKeyChange:te,onMoveTab:w,onReceiveTab:S,onHideTab:y}),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden relative",onDragEnter:B,onDragOver:$,onDragLeave:A,onDrop:R,children:[se&&e.jsx(_a,{dropAction:ee,canSplit:!!(h<4&&w)}),M?e.jsx(Ra,{activeConv:M,clearToken:n[M.tabKey]||0,isCli:!!D,ideEntry:H,screenshotUrl:U,clearScreenshot:ae,terminalRef:P,handleModalButton:Y.handleModalButton,handleRelaunch:Y.handleRelaunch,handleSendChat:Y.handleSendChat,isSendingChat:Y.isSendingChat,handleFocusAgent:Y.handleFocusAgent,isFocusingAgent:Y.isFocusingAgent,actionLogs:de,userName:u}):e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center",children:e.jsx(Pa,{conversationsCount:t.length,isSplitMode:d,isStandalone:p,detectedIdes:m,handleLaunchIde:N})})]})]})}function za({containerRef:t,isSplitMode:s,numGroups:n,groupSizes:r,groupedConvs:a,clearedTabs:i,ides:c,actionLogs:x,screenshotMap:l,setScreenshotMap:p,sendDaemonCommand:u,setLocalUserMessages:b,setActionLogs:g,isStandalone:d,userName:h,setFocusedGroup:w,moveTabToGroup:S,splitTabRelative:f,closeGroup:m,handleResizeStart:N,detectedIdes:T,handleLaunchIde:j,groupActiveTabIds:k,setGroupActiveTabIds:v,groupTabOrders:y,setGroupTabOrders:_,toggleHiddenTab:P}){return e.jsx("div",{ref:t,className:`flex-1 min-h-0 flex ${s?"flex-row":"flex-col"} overflow-hidden`,children:a.map((W,M)=>{const E=s&&r.length===n?`${r[M]}%`:void 0;return e.jsxs(bn.Fragment,{children:[s&&M>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:L=>N(M-1,L),onDoubleClick:()=>m(M),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(Ka,{style:s?{flexBasis:E??`${100/n}%`,flexGrow:E?0:1,flexShrink:E?0:1}:void 0,conversations:W,clearedTabs:i,ides:c,actionLogs:x,screenshotMap:l,setScreenshotMap:p,sendDaemonCommand:u,setLocalUserMessages:b,setActionLogs:g,isStandalone:d,userName:h,groupIndex:M,onFocus:()=>w(M),isSplitMode:s,numGroups:n,onMoveTab:(L,O)=>{O==="left"&&M>0?S(L,M-1):O==="right"&&M<n-1?S(L,M+1):O==="split-left"&&n<4?f(L,M,"left"):O==="split-right"&&n<4&&f(L,M,"right")},onReceiveTab:L=>S(L,M),detectedIdes:M===0?T:void 0,handleLaunchIde:M===0?j:void 0,onActiveTabChange:L=>v(O=>(O[M]??null)===(L??null)?O:{...O,[M]:L}),initialActiveTabId:k[M],initialTabOrder:y[M],onTabOrderChange:L=>_(O=>{const C=O[M]||[];return C.length===L.length&&C.every((V,Q)=>V===L[Q])?O:{...O,[M]:L}}),onHideTab:P})]},M)})})}function Fa({daemons:t,targetVersion:s,upgradingDaemons:n,onUpgrade:r,onDismiss:a}){return t.length===0?null:e.jsxs("div",{className:"flex items-center gap-2.5 px-4 py-2 border-b text-xs text-text-secondary shrink-0 flex-wrap",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",borderColor:"color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:[e.jsx("span",{className:"text-sm shrink-0 mt-0.5",style:{color:"var(--status-warning)"},children:e.jsx(Ms,{size:14})}),e.jsxs("span",{className:"flex-1 flex items-center gap-2 flex-wrap min-w-0",children:[e.jsxs("span",{children:["Update available",s?e.jsxs(e.Fragment,{children:[": ",e.jsxs("strong",{children:["v",s]})]}):null]}),t.map(i=>{const c=Xe(i,{fallbackId:i.id}),x=n[i.id],l=i.version||i.daemonVersion||"unknown";return e.jsxs("span",{className:"inline-flex items-center gap-1.5 px-2 py-0.5 rounded-md",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 15%, transparent)"},children:[e.jsx("span",{className:"font-medium text-text-primary",children:c}),e.jsxs("span",{className:"text-[10px] text-text-muted",children:["v",l]}),x==="upgrading"?e.jsx("span",{className:"text-[10px] animate-pulse",style:{color:"var(--status-warning)"},children:"upgrading…"}):x==="done"?e.jsx("span",{className:"text-[10px] text-green-400",children:"✓ restarting"}):x==="error"?e.jsx("button",{className:"text-[10px] text-red-400 hover:text-red-300 underline cursor-pointer",onClick:()=>r(i.id),children:"retry"}):e.jsx("button",{className:"text-[10px] font-semibold cursor-pointer px-1.5 py-px rounded transition-colors",style:{color:"var(--status-warning)",background:"color-mix(in srgb, var(--status-warning) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},onClick:()=>r(i.id),children:"Upgrade"})]},i.id)})]}),e.jsx("button",{className:"text-text-muted hover:text-text-primary transition-colors text-sm px-1 shrink-0",onClick:a,title:"Dismiss",children:"✕"})]})}function Ha({activeConv:t,onCancel:s,onStopNow:n,onSaveAndStop:r}){const a=t.agentName||t.ideType||"CLI";return e.jsxs("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center",children:[e.jsx("div",{onClick:s,className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),e.jsxs("div",{role:"dialog","aria-modal":"true",className:"card fade-in relative w-[92%] max-w-[420px] flex flex-col overflow-hidden rounded-[18px] shadow-[0_20px_40px_rgba(0,0,0,0.4)]",children:[e.jsxs("div",{className:"px-6 py-5 border-b border-border-subtle bg-[var(--surface-primary)]",children:[e.jsxs("h3",{className:"m-0 text-lg font-extrabold",children:["Stop ",a,"?"]}),e.jsx("div",{className:"mt-1 text-sm text-text-muted",children:"The CLI runtime will stop. Choose whether to stop immediately or ask the provider to save and exit first."})]}),e.jsxs("div",{className:"px-6 py-5 bg-bg-primary flex flex-col gap-3",children:[e.jsx("button",{onClick:r,className:"btn btn-primary w-full justify-center",children:"Save and stop"}),e.jsx("button",{onClick:n,className:"btn btn-secondary w-full justify-center text-red-400 border-red-500/25 hover:bg-red-500/10",children:"Stop now"}),e.jsx("button",{onClick:s,className:"btn btn-secondary w-full justify-center",children:"Cancel"})]})]})]})}const _t=[{icon:"🦦",title:"Welcome to ADHDev",desc:"Monitor and control your AI coding agents from anywhere — web, mobile, or CLI.",visual:"🎉"},{icon:"💬",title:"Real-time chat",desc:"See what your AI agent is doing in real-time. Send messages, approve or reject actions — all from your browser or phone.",visual:"📱"},{icon:"🖥️",title:"Remote desktop",desc:"View and control your IDE screen via P2P connection. Click, type, scroll — just like being there.",visual:"🖱️"},{icon:"🚀",title:"Get started",desc:"Install the daemon and link it to your dashboard. It connects automatically.",code:"npm install -g @adhdev/daemon-standalone && adhdev-standalone"}];function Ua({onClose:t}){const[s,n]=o.useState(0),r=_t[s],a=s===_t.length-1;return e.jsxs("div",{className:"onboarding-overlay",style:{position:"fixed",inset:0,zIndex:9999,background:"rgba(0,0,0,0.65)",backdropFilter:"blur(6px)",display:"flex",alignItems:"center",justifyContent:"center",animation:"fadeIn 0.3s ease-out"},onClick:i=>{i.target===i.currentTarget&&t()},children:[e.jsxs("div",{style:{background:"var(--bg-secondary, #1a1a2e)",border:"1px solid var(--border-subtle, #333)",borderRadius:"1.25rem",width:"min(440px, 92vw)",padding:"2.5rem 2rem 2rem",position:"relative",animation:"slideUp 0.3s ease-out"},children:[e.jsx("button",{onClick:t,style:{position:"absolute",top:12,right:16,background:"transparent",border:"none",color:"var(--text-muted)",fontSize:"1.2rem",cursor:"pointer"},children:"✕"}),e.jsx("div",{style:{display:"flex",justifyContent:"center",gap:6,marginBottom:"1.5rem"},children:_t.map((i,c)=>e.jsx("div",{style:{width:c===s?24:8,height:8,borderRadius:4,background:c===s?"var(--accent, #7c3aed)":"var(--border-subtle, #444)",transition:"all 0.3s ease"}},c))}),e.jsx("div",{style:{textAlign:"center",fontSize:"3rem",marginBottom:"1rem"},children:r.visual||r.icon}),e.jsxs("div",{style:{textAlign:"center"},children:[e.jsxs("h2",{style:{fontSize:"1.35rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",justifyContent:"center",gap:8},children:[e.jsx("span",{children:r.icon})," ",r.title]}),e.jsx("p",{style:{fontSize:"0.9rem",color:"var(--text-secondary)",lineHeight:1.6,marginBottom:"1.25rem"},children:r.desc}),r.code&&e.jsxs("div",{style:{background:"var(--bg-primary, #111)",border:"1px solid var(--border-subtle, #333)",borderRadius:"0.5rem",padding:"0.75rem 1rem",fontFamily:"monospace",fontSize:"0.8rem",color:"var(--accent, #a78bfa)",textAlign:"left",overflowX:"auto",marginBottom:"0.5rem"},children:[e.jsx("span",{style:{color:"var(--text-muted)",marginRight:8},children:"$"}),r.code]}),a&&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:()=>a?t():n(i=>i+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:a?"Get Started →":"Next →"})]})]}),e.jsx("style",{children:`
54
- @keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
55
- @keyframes slideUp { from { opacity: 0; transform: translateY(20px) } to { opacity: 1; transform: translateY(0) } }
56
- `})]})}function Va(){const{sendCommand:t}=De(),[s,n]=gs(),r=s.get("activeTab"),a=Ct(),{updateIdeChats:i,screenshotMap:c,setScreenshotMap:x}=a,l=a.ides||[],[p,u]=o.useState(()=>{try{return!localStorage.getItem("adhdev_onboarding_v1")}catch{return!1}}),b=a.toasts||[],g=a.setToasts||(()=>{}),d=a.wsStatus||"connected",h=a.isConnected??!0,w=a.connectionStates||{},S=a.showReconnected||!1,{groupAssignments:f,setGroupAssignments:m,focusedGroup:N,setFocusedGroup:T,groupActiveTabIds:j,setGroupActiveTabIds:k,groupTabOrders:v,setGroupTabOrders:y,groupSizes:_,setGroupSizes:P,isMobile:W,hasHydratedStoredLayout:M,hydrateStoredLayout:E}=ja(),[L,O]=o.useState(!1),[C,V]=o.useState(!1),[Q,Z]=o.useState([]),[G,te]=o.useState({}),[Y,se]=o.useState({});it("Dashboard",{ideCount:l.length,toastCount:b.length,focusedGroup:N,groupCount:Object.keys(f).length,localMessageTabs:Object.keys(G).length,actionLogCount:Q.length});const ee=l.find(be=>be.type==="adhdev-daemon"),ie=(ee==null?void 0:ee.detectedIdes)||[],B=!!ee,{hiddenTabs:$,toggleTab:A}=en(),{chatIdes:R,conversations:D,visibleConversations:H,visibleTabKeys:U,resolveConversationByTarget:ae}=xa({ides:l,connectionStates:w,localUserMessages:G,clearedTabs:Y,hiddenTabs:$}),{containerRef:de,normalizedGroupAssignments:ce,numGroups:re,isSplitMode:K,groupedConvs:X,moveTabToGroup:F,closeGroup:I,handleResizeStart:q,splitTabRelative:z,clearAllSplits:ne}=Ia({groupAssignments:f,setGroupAssignments:m,setFocusedGroup:T,setGroupActiveTabIds:k,setGroupTabOrders:y,groupSizes:_,setGroupSizes:P,isMobile:W,visibleConversations:H,visibleTabKeys:U}),J=o.useMemo(()=>{var ve,Ue;const be=j[N];if(be){const lt=D.find(dn=>dn.tabKey===be);if(lt)return lt}return((ve=X[N])==null?void 0:ve[0])||((Ue=X[0])==null?void 0:Ue[0])},[j,N,D,X]);tn({visibleConversations:H,clearedTabs:Y,setClearedTabs:se,setActionLogs:Z}),sn({ides:l,sendDaemonCommand:t,setToasts:g,setLocalUserMessages:te,resolveConversationByTarget:ae});const{isCreatingChat:ge,isRefreshingHistory:oe,handleLaunchIde:Te,handleSwitchSession:Se,handleNewChat:Ce,handleRefreshHistory:He}=wa({sendDaemonCommand:t,activeConv:J,updateIdeChats:i,setToasts:g,setLocalUserMessages:te,setClearedTabs:se});va({urlActiveTab:r,conversations:D,resolveConversationByTarget:ae,normalizedGroupAssignments:ce,hasHydratedStoredLayout:M,hydrateStoredLayout:E,setGroupActiveTabIds:k,setFocusedGroup:T,setSearchParams:n,historyModalOpen:L,activeConv:J,isRefreshingHistory:oe,ides:l,handleRefreshHistory:He,isSplitMode:K,splitTabRelative:z,numGroups:re,clearAllSplits:ne});const $e=o.useCallback(async be=>{if(!J||!je(J)||fe(J))return;const ve=J.ideType||J.agentType||"",Ue=J.ideId||J.daemonId||"";try{await t(Ue,"stop_cli",{cliType:ve,targetSessionId:J.sessionId,mode:be})}catch(lt){console.error("Stop CLI failed:",lt)}},[J,t]),It=o.useCallback(async()=>{var ve;if(!J||!je(J)||fe(J))return;if((ve=J.resume)!=null&&ve.supported){V(!0);return}const be=J.ideType||J.agentType||"CLI";window.confirm(`Stop ${be}?
57
- This will terminate the CLI process.`)&&await $e("hard")},[J,$e]),Mt=o.useCallback(()=>{!J||!je(J)||fe(J)||!J.sessionId||window.dispatchEvent(new CustomEvent("adhdev:fit-cli-terminal",{detail:{sessionId:J.sessionId}}))},[J]),{versionMismatchDaemons:ct,appVersion:Ge,versionBannerDismissed:Tt,setVersionBannerDismissed:on,upgradingDaemons:cn,handleBannerUpgrade:ln}=Ma({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(jr,{wsStatus:d,showReconnected:S}),!Tt&&e.jsx(Fa,{daemons:ct,targetVersion:Ge,upgradingDaemons:cn,onUpgrade:ln,onDismiss:()=>on(!0)}),e.jsx(vr,{activeConv:J,agentCount:R.length,wsStatus:d,isConnected:h,onOpenHistory:()=>O(!0),onFitCli:Mt,onStopCli:It}),e.jsx(za,{containerRef:de,isSplitMode:K,numGroups:re,groupSizes:_,groupedConvs:X,clearedTabs:Y,ides:l,actionLogs:Q,screenshotMap:c,setScreenshotMap:x,sendDaemonCommand:t,setLocalUserMessages:te,setActionLogs:Z,isStandalone:B,userName:a.userName,focusedGroup:N,setFocusedGroup:T,moveTabToGroup:F,splitTabRelative:z,closeGroup:I,handleResizeStart:q,detectedIdes:ie,handleLaunchIde:Te,groupActiveTabIds:j,setGroupActiveTabIds:k,groupTabOrders:v,setGroupTabOrders:y,toggleHiddenTab:A}),L&&J&&e.jsx(Ks,{activeConv:J,ides:l,isCreatingChat:ge,isRefreshingHistory:oe,onClose:()=>O(!1),onNewChat:Ce,onSwitchSession:Se,onRefreshHistory:He}),C&&J&&je(J)&&!fe(J)&&e.jsx(Ha,{activeConv:J,onCancel:()=>V(!1),onStopNow:async()=>{V(!1),await $e("hard")},onSaveAndStop:async()=>{V(!1),await $e("save")}}),e.jsx("style",{children:`
58
- body { overflow: hidden; overscroll-behavior: none; }
59
- `}),e.jsx(zs,{toasts:b,onDismiss:be=>g(ve=>ve.filter(Ue=>Ue.id!==be)),onClickToast:be=>{if(be.targetKey){const ve=ae(be.targetKey);ve&&T(ce.get(ve.tabKey)??0)}}}),p&&e.jsx(Ua,{onClose:()=>{try{localStorage.setItem("adhdev_onboarding_v1","done")}catch{}u(!1)}})]})}function qa({hasExtensions:t,ideName:s,activeChatTab:n,extensionTabs:r,onSelectTab:a}){return t?e.jsxs("div",{className:"ide-chat-tabs",children:[e.jsx("button",{className:`ide-chat-tab ${n==="native"?"active":""}`,onClick:()=>a("native"),children:s}),r.map(i=>{const c=n===i.tabKey,x=i.status==="waiting_approval",l=i.status==="generating";return e.jsxs("button",{className:`ide-chat-tab ${c?"active":""}`,onClick:()=>a(i.tabKey),children:[e.jsx("span",{style:{display:"inline-block",width:6,height:6,borderRadius:"50%",marginRight:5,background:x?"var(--status-warning)":l?"var(--accent-primary)":"#64748b",boxShadow:l?"0 0 6px var(--accent-primary)":"none"}}),i.title,x&&e.jsx("span",{className:"ide-ext-badge",style:{background:"color-mix(in srgb, var(--status-warning) 13%, transparent)",color:"var(--status-warning)",marginLeft:4},children:"!"})]},i.tabKey)})]}):null}function Ya({ideName:t,workspaceName:s,connState:n,machineName:r,viewMode:a,onChangeView:i,onOpenHistory:c,headerActions:x,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(qe,{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(p=>e.jsx("button",{className:"btn btn-secondary btn-sm",style:{border:a===p?"1px solid var(--accent-primary)":"none",background:a===p?"rgba(99,102,241,0.12)":"var(--bg-secondary)",padding:"6px 10px",color:a===p?"var(--accent-primary)":void 0},onClick:()=>i(p),children:p==="chat"?e.jsx(qe,{size:14}):p==="split"?"⊞":e.jsx(Le,{size:14})},p)),e.jsx("button",{className:"btn btn-secondary btn-sm flex items-center justify-center shrink-0",onClick:c,title:"Chat History",children:e.jsx(Is,{size:14})}),x,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 Xa({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 Ga({ideId:t,activeConv:s,historyModalOpen:n,chats:r,sendDaemonCommand:a,updateIdeChats:i,pushToast:c}){const[x,l]=o.useState(!1),[p,u]=o.useState(!1),[b,g]=o.useState(!1),d=o.useRef(!1),h=o.useCallback(async m=>{const N=m.trim();if(!(!N||!t||b||!s)){g(!0);try{await a(t,"send_chat",{message:N,text:N,waitForResponse:!0,..._e(s)})}catch(T){console.error("[IDE] Send failed:",T)}finally{g(!1)}}},[t,b,a,s]),w=o.useCallback(async()=>{var m;if(!(!t||p||!s)){u(!0);try{const N=await a(t,"list_chats",{forceExpand:!0,..._e(s)}),T=(N==null?void 0:N.chats)||((m=N==null?void 0:N.result)==null?void 0:m.chats);N!=null&&N.success&&Array.isArray(T)&&i(t,T)}catch(N){console.error("[IDE] Refresh history failed:",N),c("히스토리 새로고침에 실패했습니다.","warning")}finally{u(!1)}}},[t,p,a,s,i,c]),S=o.useCallback(async(m,N)=>{if(!(!t||!s))try{const T=await a(t,"switch_chat",{id:N,sessionId:N,..._e(s)}),j=T==null?void 0:T.result;if((T==null?void 0:T.success)===!0||j==="switched"||j==="switched-by-title")return;j===!1||j==="not_found"?c("세션 탭을 찾지 못했습니다. 히스토리를 새로고침해 보세요.","warning"):typeof j=="string"&&j.startsWith("error:")?c(`세션 전환 오류: ${j}`,"warning"):c("세션 전환에 실패했습니다.","warning")}catch(T){console.error("[IDE] Switch session failed:",T),c(`세션 전환 실패: ${(T==null?void 0:T.message)||"connection error"}`,"warning")}},[t,a,s,c]),f=o.useCallback(async()=>{if(!(!t||x||!s)){l(!0);try{await a(t,"new_chat",{..._e(s)})}catch(m){console.error("[IDE] New chat failed:",m),c("새 채팅 생성에 실패했습니다.","warning")}finally{l(!1)}}},[t,x,a,s,c]);return o.useEffect(()=>{if(!n){d.current=!1;return}d.current||p||(!r||r.length===0)&&(d.current=!0,w())},[n,r,p,w]),{isSendingChat:b,isCreatingChat:x,isRefreshingHistory:p,handleSendAgent:h,handleRefreshHistory:w,handleSwitchSession:S,handleNewChat:f}}function Ja({ideData:t,allIdes:s,connectionStates:n,localUserMessages:r,ideName:a}){const[i,c]=o.useState("native"),x=o.useMemo(()=>Fs(s),[s]),l=o.useMemo(()=>{var w;if(!t)return[];const h=t.daemonId||((w=t.id)==null?void 0:w.split(":")[0])||t.id;return Hs(t,r,{machineName:t.daemonId&&x[t.daemonId]||void 0,connectionState:n[h]||"new"})},[t,r,x,n]),p=o.useMemo(()=>l.find(h=>h.streamSource==="native"),[l]),u=o.useMemo(()=>l.filter(h=>h.streamSource==="agent-stream"),[l]);o.useEffect(()=>{var h;i!=="native"&&(u.some(w=>w.tabKey===i)||c(((h=u[0])==null?void 0:h.tabKey)||"native"))},[i,u]),o.useEffect(()=>{i==="native"&&(p||u[0]&&c(u[0].tabKey))},[i,p,u]);const b=o.useMemo(()=>i==="native"&&p?p:u.find(h=>h.tabKey===i)||p||u[0],[i,p,u]),g=o.useMemo(()=>u.map(h=>({tabKey:h.tabKey,title:h.title||h.agentName||a,status:h.status})),[u,a]),d=o.useCallback(h=>{if(h)return l.find(w=>w.sessionId===h||w.ideId===h||w.tabKey===h||w.ideType===h||w.agentType===h)},[l]);return{activeChatTab:i,setActiveChatTab:c,activeConv:b,conversations:l,extensionTabs:g,hasExtensions:g.length>0,resolveConversationByTarget:d}}function Za({doId:t,ideId:s,ideType:n,connState:r,viewMode:a,instanceId:i}){const[c,x]=o.useState(null),[l,p]=o.useState(null),u=o.useMemo(()=>{if(!s)return n;const g=s.split(":");return g.length>=3&&g[1]==="ide"?g.slice(2).join(":"):n},[s,n]);o.useEffect(()=>t?ue.onScreenshot("ide-page",(d,h)=>{if(d!==t)return;const w=new FileReader;w.onload=()=>x(w.result),w.readAsDataURL(h)}):void 0,[t]),o.useEffect(()=>{r!=="connected"&&x(null)},[r]),o.useEffect(()=>{var d;return t?((d=ue.onStatus)==null?void 0:d.call(ue,(h,w)=>{h===t&&w!=null&&w.screenshotUsage&&p(w.screenshotUsage)}))||(()=>{}):void 0},[t]),o.useEffect(()=>{x(null)},[t,s,u]),o.useEffect(()=>{const g=t?ue.get(t):null;if(!(!g||r!=="connected"))return a!=="chat"&&u?g.startScreenshots(u):g.stopScreenshots(u),()=>{g.stopScreenshots(u)}},[a,r,u,t]);const b=o.useCallback(async(g,d)=>{const h=t?ue.get(t):null;return!h||r!=="connected"?(console.warn("[RemoteInput] P2P not connected"),{success:!1,error:"P2P not connected"}):h.sendInput(g,d,i||u)},[t,r,i,u]);return{connScreenshot:c,screenshotUsage:l,handleRemoteAction:b}}function Qa(){const[t,s]=o.useState([]),n=o.useCallback(a=>{s(i=>i.filter(c=>c.id!==a))},[]),r=o.useCallback((a,i="warning")=>{const c=Date.now()+Math.floor(Math.random()*1e3);s(x=>[...x,{id:c,message:a,type:i}]),window.setTimeout(()=>{s(x=>x.filter(l=>l.id!==c))},5e3)},[]);return{toasts:t,setToasts:s,dismissToast:n,pushToast:r}}function eo({renderHeaderActions:t}={}){var re;const{id:s}=bs(),n=ot(),r=Ct(),a=r.ides||[],i=r.updateIdeChats||(()=>{}),c=r.connectionStates||{},{sendCommand:x}=De(),l=o.useMemo(()=>Us(s||"").daemonId,[s]),p=o.useMemo(()=>a.find(K=>K.id===s),[a,s]),u=(p==null?void 0:p.type)||void 0,b=u?u.charAt(0).toUpperCase()+u.slice(1):"IDE",g=r.isConnected??!0,d=c[l]||(g?"connected":"new"),h=((re=r.connectionTransports)==null?void 0:re[l])||"unknown",w=o.useMemo(()=>a.find(K=>K.id===l||K.daemonId===l),[a,l]),S=w?Xe(w,{fallbackId:l}):"",f=(p==null?void 0:p.workspace)||"",[m]=gs(),N=typeof window<"u"&&window.innerWidth<=768,T=m.get("view")||(N?"chat":"split"),[j,k]=o.useState(T),[v,y]=o.useState(!1),{toasts:_,setToasts:P,dismissToast:W,pushToast:M}=Qa(),[E,L]=o.useState([]),[O,C]=o.useState({}),[V,Q]=o.useState({}),{activeChatTab:Z,setActiveChatTab:G,activeConv:te,conversations:Y,extensionTabs:se,hasExtensions:ee,resolveConversationByTarget:ie}=Ja({ideData:p,allIdes:a,connectionStates:c,localUserMessages:O,ideName:b});tn({visibleConversations:Y,clearedTabs:V,setClearedTabs:Q,setActionLogs:L});const{connScreenshot:B,screenshotUsage:$,handleRemoteAction:A}=Za({doId:l,ideId:s||"",ideType:u,connState:d,viewMode:j,instanceId:p==null?void 0:p.instanceId}),R=!!a.find(K=>K.type==="adhdev-daemon"),D=rn({sendDaemonCommand:x,activeConv:te,setLocalUserMessages:C,setActionLogs:L,isStandalone:R}),{isCreatingChat:H,isRefreshingHistory:U,handleRefreshHistory:ae,handleSwitchSession:de,handleNewChat:ce}=Ga({ideId:s||"",activeConv:te,historyModalOpen:v,chats:p==null?void 0:p.chats,sendDaemonCommand:x,updateIdeChats:i,pushToast:M});return sn({ides:a,sendDaemonCommand:x,setToasts:P,setLocalUserMessages:C,resolveConversationByTarget:ie}),s?te?e.jsxs("div",{className:"ide-page",children:[e.jsx(Ya,{ideName:b,workspaceName:f,connState:d,machineName:S,viewMode:j,onChangeView:k,onOpenHistory:()=>y(!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 ${j==="chat"?"full":""} ${j==="remote"?"hidden":""}`,children:[e.jsx(qa,{hasExtensions:ee,ideName:b,activeChatTab:Z,extensionTabs:se,onSelectTab:K=>{G(K);const X=Y.find(F=>F.tabKey===K);(X==null?void 0:X.streamSource)==="agent-stream"&&x(X.ideId,"focus_session",{agentType:X.agentType,...X.sessionId&&{targetSessionId:X.sessionId}}).catch(()=>{})}}),e.jsx($s,{activeConv:te,onModalButton:D.handleModalButton}),e.jsx(Bs,{activeConv:te,ideEntry:a.find(K=>K.id===te.ideId),handleSendChat:D.handleSendChat,isSendingChat:D.isSendingChat,handleFocusAgent:D.handleFocusAgent,isFocusingAgent:D.isFocusingAgent,actionLogs:E,userName:r.userName})]}),e.jsx("div",{className:`ide-remote-panel ${j==="remote"?"full":""} ${j==="chat"?"hidden":""}`,children:e.jsx(tr,{addLog:()=>{},connState:d,connScreenshot:B,screenshotUsage:$,transportType:h,onAction:A})})]}),e.jsx(Xa,{toasts:_,onDismiss:W}),v&&e.jsx(Ks,{activeConv:te,ides:a,isCreatingChat:H,isRefreshingHistory:U,onClose:()=>y(!1),onNewChat:ce,onSwitchSession:de,onRefreshHistory:ae})]}):e.jsx("div",{className:"ide-empty",children:"IDE session not available"}):e.jsx("div",{className:"ide-empty",children:"No IDE selected"})}function to({machineId:t,registeredMachineId:s,sendDaemonCommand:n,onNicknameSynced:r,logsEndRef:a}){const[i,c]=o.useState([]),[x,l]=o.useState(null),[p,u]=o.useState(null),[b,g]=o.useState(!1),[d,h]=o.useState(!1),[w,S]=o.useState(!1),[f,m]=o.useState([]),[N,T]=o.useState([]),[j,k]=o.useState(null),[v,y]=o.useState(!1),[_,P]=o.useState(""),W=o.useRef(null),M=o.useCallback(A=>{W.current=A},[]),E=o.useCallback((A,R,D=!1)=>{c(H=>[...H.slice(-100),{timestamp:Date.now(),level:A,message:R}]),setTimeout(()=>{var H;return(H=a.current)==null?void 0:H.scrollIntoView({behavior:"smooth"})},100),D&&Pe.showToast(R,A==="error"||A==="warn"?"warning":"success")},[a]),L=o.useCallback(async(A,R)=>{var D;if(!t||x)return!1;l(A),E("info",`Launching ${pe(A)}${R!=null&&R.workspace?` in ${R.workspace}`:""}...`);try{const H={ideType:A,enableCdp:!0};(D=R==null?void 0:R.workspace)!=null&&D.trim()?H.workspace=R.workspace.trim():R!=null&&R.useDefaultWorkspace&&(H.useDefaultWorkspace=!0);const U=await n(t,"launch_ide",H);return E(U!=null&&U.success?"info":"error",U!=null&&U.success?`${pe(A)} launched`:`Failed: ${U==null?void 0:U.error}`,!0),!!(U!=null&&U.success)}catch(H){return E("error",`Launch error: ${H.message}`,!0),!1}finally{l(null)}},[t,x,E,n]),O=o.useCallback(async A=>{if(!t)return{success:!1};const{cliType:R,dir:D,workspaceId:H,useDefaultWorkspace:U,useHome:ae,argsStr:de,model:ce}=A;if(!R)return E("warn","Select a CLI or ACP provider first",!0),{success:!1};const re=de?de.split(/\s+/).filter(Boolean):void 0,K=(D==null?void 0:D.trim())||(H?"(saved id)":U?"(default workspace)":ae?"(home)":"");E("info",`Launching ${R}${K?` in ${K}`:""}${ce?` (model: ${ce})`:""}...`),u(R);try{const X={cliType:R,cliArgs:re,initialModel:ce||void 0};D!=null&&D.trim()?X.dir=D.trim():H?X.workspaceId=H:U?X.useDefaultWorkspace=!0:ae&&(X.useHome=!0);const F=await n(t,"launch_cli",X),I=(F==null?void 0:F.result)||F;return F!=null&&F.success?(E("info",`${R} launched`,!0),(I==null?void 0:I.launchSource)==="home"?E("info","📂 Running in home directory (explicit choice)"):(I==null?void 0:I.launchSource)==="defaultWorkspace"&&E("info","📂 Using default workspace (explicit choice)"),{success:!0,sessionId:I==null?void 0:I.sessionId}):(E("error",`Failed: ${(F==null?void 0:F.error)||(I==null?void 0:I.error)}`,!0),(F==null?void 0:F.code)==="WORKSPACE_LAUNCH_CONTEXT_REQUIRED"&&k({cliType:R,argsStr:de,model:ce}),{success:!1,sessionId:I==null?void 0:I.sessionId})}catch(X){return E("error",`Launch error: ${X.message}`,!0),{success:!1}}finally{u(null)}},[t,E,n]),C=o.useCallback(async(A,R,D,H)=>t?A?R.trim()?O({cliType:A,dir:R,argsStr:D,model:H}):(k({cliType:A,argsStr:D,model:H}),{success:!1}):(E("warn","Select a provider",!0),{success:!1}):{success:!1},[t,E,O]),V=o.useCallback(async(A,R,D)=>{if(t&&window.confirm(`Stop ${A}?
60
- This will terminate the process.`))try{const H=await n(t,"stop_cli",{cliType:A,dir:R,targetSessionId:D});H!=null&&H.success?E("info",`${A} stopped`,!0):E("error",`Stop failed: ${(H==null?void 0:H.error)||"Unknown error"}`,!0)}catch(H){E("error",`Stop failed: ${H.message}`,!0)}},[t,E,n]),Q=o.useCallback(async A=>{try{await n(A.daemonId,"restart_ide",{ideType:A.type}),E("info",`${pe(A.type)} restart initiated`,!0)}catch(R){E("error",`Restart failed: ${R.message}`,!0)}},[E,n]),Z=o.useCallback(async A=>{if(window.confirm(`Stop ${pe(A.type)}?
61
- This will disconnect CDP and optionally kill the process.`))try{const R=await n(A.daemonId,"stop_ide",{ideType:A.type,killProcess:!0});R!=null&&R.success?E("info",`${pe(A.type)} stopped`,!0):E("error",`Stop failed: ${(R==null?void 0:R.error)||"Unknown error"}`,!0)}catch(R){E("error",`Stop failed: ${R.message}`,!0)}},[E,n]),G=o.useCallback(async()=>{if(t)try{const A=await n(t,"detect_ides",{});E("info",`Found ${((A==null?void 0:A.result)||[]).length} IDE(s)`,!0)}catch(A){E("error",`Detection failed: ${A.message}`,!0)}},[t,E,n]),te=o.useCallback(async()=>{if(t){g(!0);try{const A=await n(t,"get_recent_workspaces",{});A!=null&&A.success&&Array.isArray(A==null?void 0:A.result)&&T(A.result)}catch(A){E("error",`Failed: ${A.message}`)}finally{g(!1)}}},[t,E,n]),Y=o.useCallback(async A=>{if(!(!t||!A.trim())){h(!0);try{const R=await n(t,"workspace_add",{path:A.trim()});R!=null&&R.success?E("info",`Workspace added: ${A.trim()}`):E("error",(R==null?void 0:R.error)||"workspace_add failed")}catch(R){E("error",R.message)}finally{h(!1)}return!0}},[t,E,n]),se=o.useCallback(async A=>{if(!(!t||!window.confirm("Remove this workspace from the list?"))){h(!0);try{const R=await n(t,"workspace_remove",{id:A});R!=null&&R.success?E("info","Workspace removed",!0):E("error",(R==null?void 0:R.error)||"workspace_remove failed",!0)}catch(R){E("error",R.message,!0)}finally{h(!1)}}},[t,E,n]),ee=o.useCallback(async A=>{var R;if(t){h(!0);try{const D=await n(t,"workspace_set_default",A===null?{clear:!0}:{id:A});if(D!=null&&D.success){E("info",A?"Default workspace updated":"Default workspace cleared",!0);const H=typeof D.defaultWorkspacePath=="string"?D.defaultWorkspacePath:"";H&&((R=W.current)==null||R.call(W,H))}else E("error",(D==null?void 0:D.error)||"workspace_set_default failed",!0)}catch(D){E("error",D.message,!0)}finally{h(!1)}}},[t,E,n]),ie=o.useCallback(async A=>{var D;if(!t||!A.trim())return;const R=A.trim();h(!0);try{const H=await n(t,"workspace_set_default",{path:R});H!=null&&H.success?(E("info","Default workspace set from history"),(D=W.current)==null||D.call(W,R)):E("error",(H==null?void 0:H.error)||"Could not set default (path missing on disk?)")}catch(H){E("error",H.message)}finally{h(!1)}},[t,E,n]),B=o.useCallback(async()=>{var A;if(t){S(!0);try{const R=await n(t,"get_cli_history",{}),D=(R==null?void 0:R.history)??((A=R==null?void 0:R.result)==null?void 0:A.history);R!=null&&R.success&&Array.isArray(D)&&m(D)}catch{}S(!1)}},[t,n]),$=o.useCallback(async()=>{if(t)try{if(await n(t,"set_machine_nickname",{nickname:_}),r)try{await r({machineRuntimeId:t,registeredMachineId:s,nickname:_})}catch(A){E("warn",`Live nickname updated, but account sync failed: ${A.message}`)}E("info",`Nickname set to "${_||"(cleared)"}"`),y(!1)}catch(A){E("error",`Failed: ${A.message}`)}},[t,_,s,E,r,n]);return{logs:i,launchingIde:x,launchingAgentType:p,loadingWorkspaces:b,workspaceBusy:d,loadingHistory:w,cliHistory:f,recentWorkspaces:N,launchPick:j,setLaunchPick:k,editingNickname:v,setEditingNickname:y,nicknameInput:_,setNicknameInput:P,addLog:E,handleLaunchIde:L,runLaunchCliCore:O,handleLaunchCli:C,handleStopCli:V,handleRestartIde:Q,handleStopIde:Z,handleDetectIdes:G,handleLoadRecentWorkspaces:te,handleWorkspaceAdd:Y,handleWorkspaceRemove:se,handleWorkspaceSetDefault:ee,handleWorkspaceResumePath:ie,loadCliHistory:B,handleSaveNickname:$,setOnDefaultWorkspaceChanged:M}}function so(t){const s=Math.floor((Date.now()-t)/1e3);return s<45?"just now":s<3600?`${Math.floor(s/60)}m ago`:s<86400?`${Math.floor(s/3600)}h ago`:`${Math.floor(s/86400)}d ago`}function no({machine:t,ideSessions:s,cliSessions:n,acpSessions:r,actions:a,isDashboardHidden:i,onToggleDashboardVisibility:c}){const{workspaceBusy:x,handleWorkspaceAdd:l,handleWorkspaceRemove:p,handleWorkspaceSetDefault:u}=a,[b,g]=o.useState(""),d=t.availableMem??t.freeMem,h=t.totalMem>0?Math.min(100,Math.max(0,Math.round((t.totalMem-d)/t.totalMem*100))):0,w=t.loadavg[0]||0,S=[...t.workspaceActivity||[]].sort((m,N)=>N.lastUsedAt-m.lastUsedAt).slice(0,5),f=[...s.map(m=>({id:m.id,label:`IDE · ${m.type}`,workspace:m.workspace||""})),...n.map(m=>({id:m.id,label:`CLI · ${m.cliName}`,workspace:m.workspace||""})),...r.map(m=>({id:m.id,label:`ACP · ${m.acpName}`,workspace:m.workspace||""}))].filter(m=>i==null?void 0:i(m.id));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(dt,{icon:e.jsx(Es,{size:16}),label:"Uptime",value:ir(t.uptime)}),e.jsx(dt,{icon:e.jsx(Le,{size:16}),label:"IDEs",value:`${s.length}`}),e.jsx(dt,{icon:e.jsx(Ht,{size:16}),label:"CLIs",value:`${n.length}`}),e.jsx(dt,{icon:e.jsx(Rs,{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(Jt,{value:Math.min(Math.round(w/t.cpus*100),100),max:100,label:"CPU Load",color:"#8b5cf6",detail:`${w.toFixed(2)} avg / ${t.cpus} cores`}),e.jsx(Jt,{value:h,max:100,label:"Memory",color:"#3b82f6",detail:`${Qt(t.totalMem-d)} / ${Qt(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:x,value:t.defaultWorkspaceId||"",onChange:m=>void u(m.target.value===""?null:m.target.value),children:[e.jsx("option",{value:"",children:"(none)"}),(t.workspaces||[]).map(m=>e.jsx("option",{value:m.id,children:m.label||m.path},m.id))]}),t.defaultWorkspacePath&&e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate max-w-[min(100%,360px)]",title:t.defaultWorkspacePath,children:t.defaultWorkspacePath})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-end",children:[e.jsx("input",{className:"flex-1 min-w-[200px] text-xs bg-bg-primary border border-border-subtle rounded-lg px-2.5 py-1.5",placeholder:"Add workspace path…",value:b,disabled:x,onChange:m=>g(m.target.value),onKeyDown:m=>m.key==="Enter"&&void(async()=>{await l(b)&&g("")})()}),e.jsx("button",{type:"button",className:"machine-btn text-xs px-3 py-1.5",disabled:x,onClick:async()=>{await l(b)&&g("")},children:"Add"})]}),(t.workspaces||[]).length>0&&e.jsx("ul",{className:"mt-3 space-y-1.5 max-h-40 overflow-y-auto",children:(t.workspaces||[]).map(m=>e.jsxs("li",{className:"flex items-start gap-2 text-[11px] text-text-muted rounded-lg border border-border-subtle bg-bg-primary px-2.5 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[m.id===t.defaultWorkspaceId&&e.jsx("span",{className:"text-[10px]",children:"⭐"}),e.jsx("span",{className:"font-medium text-text-primary truncate",children:Dt(m.path,m.label)})]}),e.jsx("div",{className:"font-mono truncate text-[10px]",title:m.path,children:m.path})]}),e.jsx("button",{type:"button",className:"text-[10px] text-red-400/90 hover:underline shrink-0",disabled:x,onClick:()=>void p(m.id),children:"Remove"})]},m.id))}),S.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("div",{className:"text-[10px] text-text-muted uppercase tracking-wide font-semibold mb-2",children:"Recent activity"}),e.jsx("div",{className:"space-y-1.5",children:S.map(m=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px] rounded-lg border border-border-subtle bg-bg-primary px-2.5 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-text-primary truncate",children:Dt(m.path)}),e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:m.path,children:m.path})]}),e.jsxs("span",{className:"text-[10px] text-text-muted shrink-0",children:[m.kind?`${m.kind} · `:"",so(m.lastUsedAt)]})]},`${m.path}:${m.lastUsedAt}`))})]})]}),f.length>0&&c&&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:"Hidden From Dashboard"}),e.jsx("div",{className:"flex flex-col gap-2",children:f.map(m=>e.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-border-subtle bg-bg-primary px-3 py-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-[12px] font-medium text-text-primary truncate",children:m.label}),m.workspace&&e.jsx("div",{className:"text-[10px] text-text-muted font-mono truncate",title:m.workspace,children:m.workspace})]}),e.jsx("button",{type:"button",className:"machine-btn text-[11px] px-2.5 py-1 text-zinc-300 border-zinc-500/30",onClick:()=>c(m.id),children:"Show"})]},m.id))})]})]})}function ro(t){return t?t.ownerType==="user"?"you control":"agent controls":"view only"}const ao={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 Lt({category:t,machine:s,machineId:n,providers:r,managedEntries:a,getIcon:i,actions:c,sendDaemonCommand:x,isDashboardHidden:l,onToggleDashboardVisibility:p}){const u=ot(),{handleLaunchIde:b,handleLaunchCli:g,handleStopCli:d,handleRestartIde:h,handleStopIde:w,handleDetectIdes:S,cliHistory:f,loadingHistory:m,loadCliHistory:N,launchingIde:T,launchingAgentType:j}=c,[k,v]=o.useState(null),y=o.useCallback(I=>{I&&u({pathname:"/",search:`?activeTab=${encodeURIComponent(I)}`})},[u]),_=ao[t],P=t==="ide",W=t==="acp",M=r.filter(I=>I.category===t),E=new Map(M.map(I=>[I.type,I.displayName||I.type])),[L,O]=o.useState(""),[C,V]=o.useState(""),[Q,Z]=o.useState(""),[G,te]=o.useState(s.defaultWorkspaceId||""),[Y,se]=o.useState(""),[ee,ie]=o.useState([]),B=ee.filter(I=>!a.some(q=>q.type===I&&ye(q.status)!=="stopped")),$=o.useRef({});o.useEffect(()=>{!L&&M.length>0&&O(M[0].type)},[L,M.length]),o.useEffect(()=>{s.defaultWorkspaceId&&!G&&te(s.defaultWorkspaceId)},[s.defaultWorkspaceId]);const A=(()=>{if(G==="__custom__")return Y.trim();if(!G)return"";const I=(s.workspaces||[]).find(q=>q.id===G);return(I==null?void 0:I.path)||""})(),R=o.useCallback(I=>{const q=$.current[I];q&&(clearTimeout(q),delete $.current[I]),ie(z=>z.filter(ne=>ne!==I))},[]),D=o.useCallback(I=>{if(!I)return;ie(z=>z.includes(I)?z:[...z,I]);const q=$.current[I];q&&clearTimeout(q),$.current[I]=setTimeout(()=>{ie(z=>z.filter(ne=>ne!==I)),delete $.current[I]},2e4)},[]);o.useEffect(()=>{for(const I of a)ye(I.status)!=="stopped"&&R(I.type)},[a,R]),o.useEffect(()=>()=>{Object.values($.current).forEach(clearTimeout),$.current={}},[]);const[H,U]=o.useState({}),[ae,de]=o.useState(null);o.useEffect(()=>{if(!P||!n||!x)return;(async()=>{try{const q=await x(n,"get_ide_extensions",{}),z=(q==null?void 0:q.result)||q;z!=null&&z.success&&(z!=null&&z.ideExtensions)&&U(z.ideExtensions)}catch{}})()},[P,n,x]);const ce=I=>P?pe(I.type):t==="cli"?I.cliName:I.acpName,re=P?s.detectedIdes||[]:[],K=()=>{(async()=>{if(P){await b(L,A?{workspace:A}:void 0)&&D(L);return}const I=await g(L,A,C||void 0,W&&Q||void 0);I.success&&(D(L),I.sessionId&&y(I.sessionId))})()},X=I=>{P?w(I):d(I.type,I.workspace,I.id)},F=e.jsxs("div",{className:"mb-3",children:[e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:G,onChange:I=>{te(I.target.value),I.target.value!=="__custom__"&&se("")},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(I=>e.jsxs("option",{value:I.id,children:[I.id===s.defaultWorkspaceId?"⭐ ":"",Dt(I.path,I.label)]},I.id)),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]}):e.jsxs(e.Fragment,{children:[e.jsx("option",{value:"",children:"(no workspaces saved — add in Overview tab)"}),e.jsx("option",{value:"__custom__",children:"✏️ Custom path…"})]})}),G==="__custom__"&&e.jsx("input",{type:"text",placeholder:"Enter absolute path…",value:Y,onChange:I=>se(I.target.value),className:"machine-input flex-1 min-w-[200px]",autoFocus:!0})]}),e.jsx("div",{className:"mt-1.5 text-[10px] text-text-muted",children:G==="__custom__"?A?e.jsx("span",{className:"font-mono truncate block",title:A,children:A}):"Enter an absolute path to launch there.":A?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"font-medium text-text-secondary",children:G===s.defaultWorkspaceId?"Default workspace":"Selected workspace"}),e.jsx("span",{className:"font-mono truncate block",title:A,children:A})]}):"No workspace selected. This launches in the home directory."})]});return e.jsxs("div",{children:[e.jsxs("div",{className:`px-5 py-4 rounded-xl mb-5 bg-bg-secondary border ${_.accent}`,children:[e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Launch ",_.label]}),F,P?e.jsx(e.Fragment,{children:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[re.map(I=>{const q=a.find(ge=>(ge.type||"").toLowerCase()===(I.type||"").toLowerCase()&&ye(ge.status)!=="stopped"),z=I.running||!!q,ne=!!q&&q.cdpConnected,J=ee.includes(I.type||I.id||"");return e.jsxs("button",{onClick:()=>{if(ne&&q){u(`/ide/${q.id}`);return}J||(async()=>await b(I.type||I.id||"",A?{workspace:A}:void 0)&&D(I.type||I.id||""))()},disabled:!!T||J,className:`machine-btn-primary flex items-center gap-1.5 ${z?"!border-green-500/30":""}`,style:{opacity:T&&T!==I.type?.4:1},children:[e.jsx("span",{children:i(I.type)}),z&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 shadow-[0_0_4px_rgba(34,197,94,0.4)]"}),J?`⏳ Waiting for ${I.name||pe(I.type)}...`:ne?`Open ${I.name||pe(I.type)}`:T===I.type?"⏳ Launching...":`▶ ${I.name||pe(I.type)}`,z&&ne&&e.jsx("span",{className:"text-[9px] text-green-400 font-normal",children:"running"})]},I.type)}),re.length===0&&e.jsxs("div",{className:"text-xs text-text-muted italic",children:["No IDEs detected.",e.jsxs("button",{onClick:S,className:"machine-btn ml-2 flex items-center gap-1",children:[e.jsx(Pn,{size:12})," Scan"]})]})]})}):e.jsxs("div",{className:"flex gap-2 items-center flex-wrap",children:[e.jsx("select",{value:L,onChange:I=>O(I.target.value),className:"machine-input",children:M.length>0?M.map(I=>e.jsxs("option",{value:I.type,children:[I.icon," ",I.displayName]},I.type)):e.jsxs("option",{value:"",disabled:!0,children:["No ",t.toUpperCase()," providers available"]})}),W&&e.jsx("input",{type:"text",placeholder:"Model (default)",value:Q,onChange:I=>Z(I.target.value),className:"machine-input min-w-[120px]"}),e.jsx("input",{type:"text",placeholder:"Args (optional)",value:C,onChange:I=>V(I.target.value),className:"machine-input min-w-[120px]"}),e.jsx("button",{onClick:K,disabled:!!j,className:"machine-btn-primary",children:j===L?"⏳ Launching...":"▶ Launch"})]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-2.5",children:["Running (",a.length+ee.filter(I=>!a.some(q=>q.type===I&&ye(q.status)!=="stopped")).length,")"]}),a.length===0&&B.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 ",_.plural," running"]}):e.jsxs("div",{className:"flex flex-col gap-2.5 mb-5",children:[B.map(I=>e.jsx("div",{className:"px-4.5 py-3.5 rounded-xl bg-bg-secondary",style:{border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)"},children:e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"text-lg",children:i(I)}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-[13px] text-text-primary",children:P?pe(I):E.get(I)||I}),e.jsx("div",{className:"text-[11px] text-text-muted",children:j===I?"Launching process...":"Waiting for process and session to register..."})]})]}),e.jsx("span",{className:"px-2 py-0.5 rounded-md text-[10px] font-semibold",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:"var(--status-warning)"},children:"starting"})]})},`pending:${I}`)),a.map(I=>{const q=P?I:null,z=W?I:null,ne=!P&&!W?I:null,J=ye(I.status),ge=(l==null?void 0:l(I.id))??!1;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:i(I.type)}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-semibold text-[13px] text-text-primary",children:[ce(I),(q==null?void 0:q.version)&&e.jsxs("span",{className:"text-[10px] text-text-muted ml-1.5",children:["v",q.version]})]}),e.jsxs("div",{className:"text-[11px] text-text-muted flex gap-2",children:[e.jsx("span",{children:I.workspace||"—"}),(z==null?void 0:z.currentModel)&&e.jsxs("span",{className:"text-cyan-500",children:["🤖 ",z.currentModel]}),(z==null?void 0:z.currentPlan)&&e.jsxs("span",{style:{color:"var(--status-warning)"},children:["📋 ",z.currentPlan]})]}),ne&&(ne.runtimeKey||ne.runtimeWriteOwner)&&e.jsxs("div",{className:"text-[10px] text-text-muted flex gap-2 mt-0.5 flex-wrap",children:[ne.runtimeKey&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-text-secondary",children:"Local terminal:"}),e.jsxs("span",{className:"font-mono text-text-secondary",children:["adhdev attach ",ne.runtimeKey]}),e.jsx("button",{type:"button",className:"machine-btn text-[9px] px-1.5 py-px",onClick:()=>{var oe;(oe=navigator.clipboard)==null||oe.writeText(`adhdev attach ${ne.runtimeKey}`),v(ne.runtimeKey||null),window.setTimeout(()=>{v(Te=>Te===ne.runtimeKey?null:Te)},1200)},children:k===ne.runtimeKey?"Copied":"Copy"})]}),ne.runtimeWriteOwner&&e.jsx("span",{style:{color:ne.runtimeWriteOwner.ownerType==="user"?"var(--status-warning)":void 0},className:ne.runtimeWriteOwner.ownerType!=="user"?"text-violet-400":"",children:ro(ne.runtimeWriteOwner)})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[p&&e.jsx("button",{onClick:()=>p(I.id),className:`machine-btn ${ge?"text-zinc-300 border-zinc-500/30":"text-violet-400 border-violet-500/30"}`,title:ge?"Show on Dashboard":"Hide from Dashboard",children:ge?"Show":"Hide"}),e.jsx("span",{className:`px-2 py-0.5 rounded-md text-[10px] font-semibold ${J==="stopped"?"bg-red-500/[0.08] text-red-500":J==="generating"?"bg-orange-500/[0.08] text-orange-400":"bg-green-500/[0.08] text-green-500"}`,children:J}),P&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{onClick:()=>u(`/ide/${I.id}`),className:"machine-btn flex items-center gap-1",children:[e.jsx(Le,{size:13})," Control"]}),e.jsx("button",{onClick:()=>h(I),className:"machine-btn",style:{color:"var(--status-warning)",borderColor:"color-mix(in srgb, var(--status-warning) 30%, transparent)"},children:"↻"})]}),W&&e.jsx("button",{onClick:()=>u(`/ide/${I.id}`),className:"machine-btn",title:"View chat",children:e.jsx(qe,{size:14})}),ne&&J!=="stopped"&&e.jsxs("button",{onClick:()=>y(I.id),className:"machine-btn flex items-center gap-1",title:"Open terminal in dashboard",children:[e.jsx(Le,{size:13})," Open"]}),J==="stopped"?e.jsx("button",{onClick:()=>{(async()=>{if(P){await b(I.type,I.workspace?{workspace:I.workspace}:void 0)&&D(I.type);return}const oe=await g(I.type,I.workspace);oe.success&&(D(I.type),oe.sessionId&&y(oe.sessionId))})()},disabled:ee.includes(I.type),className:"machine-btn text-green-500 border-green-500/30",children:ee.includes(I.type)?"⏳":"▶"}):e.jsx("button",{onClick:()=>X(I),className:"machine-btn text-red-500 border-red-500/30",children:"■"})]})]}),q&&q.aiAgents.length>0&&e.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:q.aiAgents.map(oe=>e.jsxs("span",{className:`px-2 py-0.5 rounded-md text-[10px] ${Ps(oe.status)?"bg-orange-500/[0.08] text-orange-400":"bg-indigo-500/[0.06] text-indigo-400"}`,children:[oe.name," · ",ye(oe.status)]},oe.id))}),q&&(H[q.type]||[]).length>0&&x&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-border-subtle",children:[e.jsx("div",{className:"text-[10px] text-text-muted font-semibold uppercase tracking-wider mb-1.5",children:"Extensions"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:(H[q.type]||[]).map(oe=>e.jsxs("button",{disabled:ae===`${q.type}.${oe.type}`,onClick:async()=>{const Te=`${q.type}.${oe.type}`;de(Te);try{await x(n,"set_ide_extension",{ideType:q.type,extensionType:oe.type,enabled:!oe.enabled}),U(Se=>({...Se,[q.type]:(Se[q.type]||[]).map(Ce=>Ce.type===oe.type?{...Ce,enabled:!Ce.enabled}:Ce)}))}catch(Se){console.error("Extension toggle failed:",Se)}finally{de(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 ${oe.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 ${oe.enabled?"bg-violet-400 shadow-[0_0_4px_rgba(139,92,246,0.4)]":"bg-zinc-600"}`}),oe.name,e.jsx("span",{className:"text-[9px] font-normal",children:oe.enabled?"ON":"OFF"})]},oe.type))})]})]},I.id)})]}),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider",children:"History"}),e.jsx("button",{onClick:N,disabled:m,className:"machine-btn",children:m?"⏳":"↻ Load"})]}),(()=>{const I=new Set(M.map(z=>z.type)),q=f.filter(z=>(z.category||"cli")!==t?!1:t==="ide"?!0:I.has(z.cliType));return q.length>0?e.jsx("div",{className:"flex flex-col gap-1 max-h-[200px] overflow-y-auto",children:q.map((z,ne)=>{var J,ge;return e.jsxs("div",{onClick:()=>{O(z.cliType),(z.workspace||z.dir)&&(te("__custom__"),se(z.workspace||z.dir)),V((z.cliArgs||[]).join(" ")),Z(z.model||""),P&&(async()=>await b(z.cliType,z.workspace?{workspace:z.workspace}:void 0)&&D(z.cliType))()},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:i(z.cliType)}),e.jsx("span",{children:((J=z.workspace||z.dir)==null?void 0:J.split("/").filter(Boolean).pop())||z.cliType||"root"}),z.model&&e.jsxs("span",{className:"text-cyan-500 text-[10px]",children:["model=",z.model]}),z.newWindow&&e.jsx("span",{className:"text-text-muted text-[10px]",children:"new window"}),((ge=z.cliArgs)==null?void 0:ge.length)>0&&e.jsx("span",{className:"text-text-muted text-[10px]",children:z.cliArgs.join(" ")})]}),e.jsx("span",{className:"text-text-muted text-[10px]",children:z.timestamp?new Date(z.timestamp).toLocaleDateString():""})]},ne)})}):e.jsxs("div",{className:"text-[11px] text-text-muted italic mb-2",children:["No ",_.label," launch history yet."]})})()]})]})}const us=["openPanel","sendMessage","readChat","newSession","listSessions","switchSession","resolveAction","listModels","setModel","listModes","setMode","focusEditor"],oo=[{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 io({machineId:t,provider:s,sendDaemonCommand:n,onClose:r}){const[a,i]=o.useState("config"),[c,x]=o.useState("codex-cli"),[l,p]=o.useState([]),[u,b]=o.useState(""),[g,d]=o.useState([]),[h,w]=o.useState(""),S=o.useRef(null),f=o.useRef(null),m=y=>{p(_=>_.includes(y)?_.filter(P=>P!==y):[..._,y])},N=()=>p([...us]),T=()=>p([]);o.useEffect(()=>{var y;(y=S.current)==null||y.scrollIntoView({behavior:"smooth"})},[g]),o.useEffect(()=>()=>{f.current&&clearInterval(f.current)},[]);const j=o.useCallback(()=>{f.current&&clearInterval(f.current),f.current=setInterval(async()=>{try{const y=await n(t,"provider_auto_fix_status",{providerType:s.type});(y==null?void 0:y.running)===!1&&a==="running"&&(i("done"),d(_=>[..._,`
62
- ✅ Auto-fix completed!`]),f.current&&clearInterval(f.current))}catch{}},3e3)},[t,s.type,n,a]),k=async()=>{if(l.length!==0){i("running"),d(["🚀 Starting auto-fix...",`Agent: ${c}`,`Scripts: ${l.join(", ")}`,u?`💬 Comment: ${u}`:"",""]),w("");try{const y=await n(t,"provider_auto_fix",{providerType:s.type,functions:l,agent:c,...u?{comment:u}:{}});y!=null&&y.success&&(y!=null&&y.started||y!=null&&y.running)?(d(_=>[..._,"✅ Agent started. Monitoring progress..."]),j()):(i("error"),w((y==null?void 0:y.error)||"Failed to start auto-fix"))}catch(y){i("error"),w((y==null?void 0:y.message)||"Connection failed")}}},v=async()=>{try{await n(t,"provider_auto_fix_cancel",{providerType:s.type}),d(y=>[...y,`
63
- ⚠️ Auto-fix cancelled.`]),i("done"),f.current&&clearInterval(f.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:y=>y.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:[a==="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:oo.map(y=>e.jsxs("button",{onClick:()=>x(y.value),className:"flex-1 px-3 py-2 rounded-lg border text-left transition-all",style:{borderColor:c===y.value?y.color+"66":"var(--border-subtle)",background:c===y.value?y.color+"0d":"transparent"},children:[e.jsx("div",{className:"text-[12px] font-semibold",style:{color:c===y.value?y.color:"var(--text-primary)"},children:y.label}),e.jsx("div",{className:"text-[10px] text-text-muted",children:y.desc})]},y.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:T,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(y=>e.jsxs("button",{onClick:()=>m(y),className:"px-2.5 py-1.5 rounded-md border text-[11px] font-medium text-left transition-all",style:{borderColor:l.includes(y)?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:l.includes(y)?"rgba(139,92,246,0.08)":"transparent",color:l.includes(y)?"#a78bfa":"var(--text-secondary)"},children:[l.includes(y)?"☑ ":"☐ ",y]},y))})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:["Additional Instructions ",e.jsx("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),e.jsx("textarea",{value:u,onChange:y=>b(y.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"})]})]}),(a==="running"||a==="done"||a==="error")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mb-1.5 block",children:"Agent Output"}),e.jsxs("div",{className:"rounded-lg border border-border-subtle bg-[#0d0d0d] p-3 font-mono text-[11px] leading-relaxed text-text-secondary overflow-y-auto",style:{maxHeight:320,minHeight:200},children:[g.map((y,_)=>e.jsx("div",{className:y.startsWith("✅")?"text-green-400":"",style:y.startsWith("❌")||y.startsWith("⚠")?{color:"var(--status-warning)"}:void 0,children:y},_)),a==="running"&&e.jsx("div",{className:"text-violet-400 animate-pulse mt-1",children:"● Running..."}),e.jsx("div",{ref:S})]}),h&&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:h})]})]}),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:[a==="config"&&l.length>0&&`${l.length} script(s) selected`,a==="running"&&"Agent is generating...",a==="done"&&"Run `adhdev provider verify` to validate"]}),e.jsxs("div",{className:"flex gap-2",children:[a==="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"})]}),a==="running"&&e.jsx("button",{onClick:v,className:"machine-btn text-red-400 border-red-500/30",children:"⬛ Cancel"}),(a==="done"||a==="error")&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{i("config"),d([]),w("")},className:"machine-btn",children:"← Back"}),e.jsx("button",{onClick:r,className:"machine-btn",children:"Close"})]})]})]})]})})}function co({machineId:t,providers:s,sendDaemonCommand:n,onClose:r,onCreated:a}){var j;const i=s.filter(k=>k.category==="ide"),[c,x]=o.useState(((j=i[0])==null?void 0:j.type)||""),[l,p]=o.useState(""),[u,b]=o.useState(""),[g,d]=o.useState(!1),[h,w]=o.useState(""),[S,f]=o.useState(!1),m=k=>{const v=k.toLowerCase().replace(/[^a-z0-9-]/g,"");p(v),(!u||u===N(l))&&b(N(v))},N=k=>k.split("-").map(v=>v.charAt(0).toUpperCase()+v.slice(1)).join(" "),T=async()=>{if(!(!l||!u||!c)){d(!0),w("");try{const k=await n(t,"provider_clone",{type:l,name:u,category:"ide",location:"user",cloneFrom:c});k!=null&&k.success||k!=null&&k.created?(f(!0),a==null||a(l)):w((k==null?void 0:k.error)||"Failed to create provider")}catch(k){w((k==null?void 0:k.message)||"Connection failed")}d(!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:S?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:i.map(k=>e.jsxs("button",{onClick:()=>x(k.type),className:"px-2.5 py-2 rounded-lg border text-center transition-all",style:{borderColor:c===k.type?"rgba(139,92,246,0.4)":"var(--border-subtle)",background:c===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:c===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=>m(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:u,onChange:k=>b(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"})]}),h&&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:h})]})}),e.jsx("div",{className:"px-5 py-3.5 border-t border-border-subtle flex justify-end gap-2",children:S?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:T,disabled:!l||!u||g,className:"machine-btn",style:{background:l&&u?"rgba(34,197,94,0.12)":void 0,borderColor:l&&u?"rgba(34,197,94,0.3)":void 0,color:l&&u?"#86efac":void 0,opacity:!l||!u||g?.4:1},children:g?"⏳ Creating...":"✨ Create Provider"})]})})]})})}function lo({machineId:t,providers:s,sendDaemonCommand:n}){const[r,a]=o.useState([]),[i,c]=o.useState(!1),[x,l]=o.useState(null),[p,u]=o.useState("all"),[b,g]=o.useState(null),[d,h]=o.useState(!1),w=o.useCallback(async()=>{var f;if(t){c(!0);try{const m=await n(t,"get_provider_settings",{}),N=(m==null?void 0:m.result)||m;if(m!=null&&m.success&&(N!=null&&N.settings)){const T=[];for(const[j,k]of Object.entries(N.settings)){const v=s.find(y=>y.type===j);T.push({type:j,displayName:(v==null?void 0:v.displayName)||j,icon:(v==null?void 0:v.icon)||"",category:(v==null?void 0:v.category)||"unknown",schema:k,values:((f=N.values)==null?void 0:f[j])||{}})}T.sort((j,k)=>j.category.localeCompare(k.category)||j.displayName.localeCompare(k.displayName)),a(T)}}catch{}c(!1)}},[t,s,n]);o.useEffect(()=>{r.length===0&&w()},[]);const S=async(f,m,N)=>{l(`${f}.${m}`),a(T=>T.map(j=>j.type===f?{...j,values:{...j.values,[m]:N}}:j));try{const T=await n(t,"set_provider_setting",{providerType:f,key:m,value:N});T!=null&&T.success||w()}catch{w()}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(f=>e.jsx("button",{onClick:()=>u(f),className:`machine-btn text-[10px] px-2 py-0.5 ${p===f?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:f.toUpperCase()},f))]}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{onClick:()=>h(!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:w,disabled:i,className:"machine-btn",children:i?"⏳ Loading...":"↻ Refresh"})]})]}),p!=="all"&&r.filter(f=>f.category===p).length>1&&(()=>{const f=r.filter(j=>j.category===p),m=new Map;for(const j of f)for(const k of j.schema){if(k.type!=="boolean")continue;const v=m.get(k.key),y=!!(j.values[k.key]??k.default);v?(v.onCount+=y?1:0,v.total+=1):m.set(k.key,{label:k.label||k.key,onCount:y?1:0,total:1})}const N=[...m.entries()].filter(([,j])=>j.total===f.length);if(N.length===0)return null;const T=async(j,k)=>{for(const v of f)await S(v.type,j,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 ",p.toUpperCase()," providers (",f.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(([j,k])=>{const v=k.onCount===k.total,y=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 T(j,!0),disabled:v,className:`machine-btn text-[9px] px-1.5 py-px ${v?"opacity-40":"text-green-400 border-green-500/30"}`,children:"All ON"}),e.jsx("button",{onClick:()=>void T(j,!1),disabled:y,className:`machine-btn text-[9px] px-1.5 py-px ${y?"opacity-40":"text-red-400 border-red-500/30"}`,children:"All OFF"})]},j)})})]})})(),i&&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(f=>p==="all"||f.category===p).map(f=>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:f.icon}),e.jsx("span",{className:"font-semibold text-[13px] text-text-primary",children:f.displayName}),e.jsx("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:f.category==="acp"?"rgba(139,92,246,0.08)":f.category==="cli"?"rgba(59,130,246,0.08)":f.category==="ide"?"rgba(34,197,94,0.08)":"color-mix(in srgb, var(--status-warning) 8%, transparent)",color:f.category==="acp"?"#a78bfa":f.category==="cli"?"#60a5fa":f.category==="ide"?"#86efac":"var(--status-warning)"},children:f.category}),f.category==="ide"&&e.jsx("button",{onClick:()=>g(s.find(m=>m.type===f.type)||{type:f.type,displayName:f.displayName,icon:f.icon,category:f.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:f.schema.map(m=>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:[m.label||m.key,x===`${f.type}.${m.key}`&&e.jsx("span",{className:"ml-1.5 text-[9px] text-violet-500",children:"saving..."})]}),m.description&&e.jsx("div",{className:"text-[10px] text-text-muted mt-px",children:m.description})]}),e.jsx("div",{className:"shrink-0",children:m.type==="boolean"?e.jsx("button",{onClick:()=>S(f.type,m.key,!(f.values[m.key]??m.default)),className:"w-10 h-[22px] rounded-[11px] border-none relative cursor-pointer transition-colors duration-200",style:{background:f.values[m.key]??m.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:f.values[m.key]??m.default?21:3}})}):m.type==="number"?e.jsx("input",{type:"number",value:f.values[m.key]??m.default??0,min:m.min,max:m.max,onChange:N=>{const T=parseInt(N.target.value)||0;m.min!==void 0&&T<m.min||m.max!==void 0&&T>m.max||S(f.type,m.key,T)},className:"machine-input w-20 text-center text-[11px]"}):m.type==="select"&&m.options?e.jsx("select",{value:f.values[m.key]??m.default??"",onChange:N=>S(f.type,m.key,N.target.value),className:"machine-input text-[11px]",children:m.options.map(N=>e.jsx("option",{value:N,children:N},N))}):e.jsx("input",{type:"text",value:f.values[m.key]??m.default??"",onBlur:N=>S(f.type,m.key,N.target.value),className:"machine-input w-[120px] text-[11px]"})})]},m.key))})]},f.type))}),b&&e.jsx(io,{machineId:t,provider:b,sendDaemonCommand:n,onClose:()=>g(null)}),d&&e.jsx(co,{machineId:t,providers:s,sendDaemonCommand:n,onClose:()=>h(!1),onCreated:()=>{h(!1),w()}})]})}function uo({machineId:t,sendDaemonCommand:s}){const[n,r]=o.useState([]),[a,i]=o.useState(0),[c,x]=o.useState(!0),[l,p]=o.useState("debug"),u=o.useRef(null),b=o.useRef(!1);return o.useEffect(()=>{if(!t||!c)return;const g=async()=>{try{const h=await s(t,"get_logs",{count:200,minLevel:l,since:a}),w=(h==null?void 0:h.result)||h;if(h!=null&&h.success&&Array.isArray(w==null?void 0:w.logs)&&w.logs.length>0){r(f=>[...f,...w.logs.map(N=>({timestamp:N.ts,level:N.level,message:`[${N.category}] ${N.message}`}))].slice(-300));const S=Math.max(...w.logs.map(f=>f.ts));i(S)}}catch{}};g();const d=setInterval(g,3e3);return()=>clearInterval(d)},[t,c,a,l,s]),o.useEffect(()=>{if(c&&n.length>0){const g=b.current?"smooth":"instant";setTimeout(()=>{var d;(d=u.current)==null||d.scrollIntoView({behavior:g}),b.current=!0},50)}},[n.length,c]),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-3",children:[e.jsxs("div",{className:"flex gap-1 items-center",children:[e.jsx("span",{className:"text-[11px] text-text-muted font-semibold uppercase tracking-wider mr-2",children:"Level"}),["debug","info","warn","error"].map(g=>e.jsx("button",{onClick:()=>{p(g),r([]),i(0)},className:`machine-btn text-[10px] px-2 py-0.5 ${l===g?"bg-violet-500/15 border-violet-500/40 text-violet-400":""}`,children:g.toUpperCase()},g))]}),e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsxs("span",{className:"text-[10px] text-text-muted",children:[n.length," entries"]}),e.jsx("button",{onClick:()=>x(!c),className:`machine-btn ${c?"text-green-500 border-green-500/30":""}`,children:c?"⏸ Pause":"▶ Resume"}),e.jsx("button",{onClick:()=>{r([]),i(0)},className:"machine-btn",children:"Clear"})]})]}),e.jsxs("div",{className:"bg-bg-secondary border border-border-subtle rounded-xl p-3 min-h-[200px] max-h-[500px] overflow-y-auto font-mono text-[11px] leading-relaxed",children:[n.length===0&&e.jsx("div",{className:"p-10 text-center text-text-muted",children:"Loading daemon logs..."}),n.map((g,d)=>e.jsxs("div",{className:"flex gap-2 py-px",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"var(--status-warning)":g.level==="debug"?"#64748b":"#94a3b8"},children:[e.jsx("span",{className:"text-text-muted min-w-[75px] shrink-0",children:new Date(g.timestamp).toLocaleTimeString()}),e.jsx("span",{className:"font-semibold min-w-[32px] shrink-0 text-[9px]",style:{color:g.level==="error"?"#ef4444":g.level==="warn"?"var(--status-warning)":g.level==="debug"?"#475569":"#8b5cf6"},children:g.level==="error"?"ERR":g.level==="warn"?"WRN":g.level==="debug"?"DBG":"INF"}),e.jsx("span",{children:g.message})]},d)),e.jsx("div",{ref:u})]})]})}function xo({machine:t,launchPick:s,actions:n}){const{runLaunchCliCore:r,setLaunchPick:a}=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(i=>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:()=>{a(null),r({cliType:s.cliType,workspaceId:i.id,argsStr:s.argsStr,model:s.model})},children:[e.jsx("span",{className:"font-medium text-text-primary block truncate",children:i.label||i.path}),e.jsx("span",{className:"text-[10px] text-text-muted font-mono truncate block",children:i.path})]},i.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:()=>{a(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:()=>{a(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:()=>a(null),children:"Cancel"})]})]})})}function po({onNicknameSynced:t}={}){var v,y,_,P,W,M,E,L,O;const{id:s}=bs(),n=ot(),{sendCommand:r}=De(),a=Ct(),i=a.ides||[],c=a.initialLoaded??!0,{isHidden:x,toggleTab:l}=en(),p=i.find(C=>C.id===s&&C.daemonMode),[u,b]=o.useState("overview"),g=o.useRef(null),d=to({machineId:s,registeredMachineId:(p==null?void 0:p.machineId)||null,sendDaemonCommand:r,onNicknameSynced:t,logsEndRef:g});o.useEffect(()=>Pe.onToast(V=>{a.setToasts(Z=>{if(Z.some(Y=>Y.message===V.message&&V.timestamp-Y.timestamp<3e3))return Z;const te={id:V.id,message:V.message,type:V.type,timestamp:V.timestamp,targetKey:V.targetKey,actions:V.actions};return[...Z.slice(-4),te]});const Q=V.duration||5e3;setTimeout(()=>a.setToasts(Z=>Z.filter(G=>G.id!==V.id)),Q)}),[a]);const h=((p==null?void 0:p.availableProviders)||[]).map(C=>({type:C.type,displayName:C.displayName,icon:C.icon,category:C.category})),w={};for(const C of h)w[C.type]=C.icon;const S=C=>w[C]||"",f=p?{id:p.id,hostname:Ds(p,{fallbackId:p.id}),platform:((v=p.machine)==null?void 0:v.platform)||"unknown",arch:((y=p.machine)==null?void 0:y.arch)||"",cpus:((_=p.machine)==null?void 0:_.cpus)||0,totalMem:((P=p.machine)==null?void 0:P.totalMem)||0,freeMem:((W=p.machine)==null?void 0:W.freeMem)||0,availableMem:(M=p.machine)==null?void 0:M.availableMem,loadavg:((E=p.machine)==null?void 0:E.loadavg)||[],uptime:((L=p.machine)==null?void 0:L.uptime)||0,release:((O=p.machine)==null?void 0:O.release)||"",cdpConnected:!!p.cdpConnected,machineNickname:p.machineNickname||null,p2p:p.p2p||{available:!1,state:"unavailable",peers:0,screenshotActive:!1},detectedIdes:p.detectedIdes||[],workspaces:p.workspaces||[],defaultWorkspaceId:p.defaultWorkspaceId??p.activeWorkspaceId??null,defaultWorkspacePath:p.defaultWorkspacePath??p.activeWorkspacePath??null,workspaceActivity:p.workspaceActivity||[]}:null,m=i.filter(C=>C.daemonId===s&&!C.daemonMode).filter(C=>!es(C)&&!ts(C)).map(C=>({id:C.id,type:C.type,version:C.version||"",instanceId:C.instanceId||"",status:C.status,workspace:C.workspace||null,terminals:C.terminals||0,aiAgents:pr(C.aiAgents||C.agents||[]),activeChat:C.activeChat||null,chats:C.chats||[],childSessions:C.childSessions||[],cdpConnected:C.cdpConnected||!1,daemonId:s})),N=i.filter(C=>C.daemonId===s&&es(C)).map(C=>({id:C.id,type:C.type,cliName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,daemonId:s})),T=i.filter(C=>C.daemonId===s&&ts(C)).map(C=>({id:C.id,type:C.type,acpName:C.cliName||C.type,status:C.status,workspace:C.workspace||"",activeChat:C.activeChat||null,currentModel:C.currentModel,currentPlan:C.currentPlan,daemonId:s}));if(!f)return c?e.jsxs("div",{className:"p-10 text-center text-text-muted",children:[e.jsx("h2",{className:"text-text-primary",children:"Machine not found"}),e.jsx("p",{className:"mt-3",children:"The machine may be offline or not yet connected."}),e.jsx("button",{onClick:()=>n("/machines"),className:"machine-btn-back",children:"← Back to Burrows"})]}):e.jsx("div",{className:"p-10 text-center text-text-muted",children:e.jsx("p",{children:"⏳ Loading machine..."})});const j=Xe(p,{fallbackId:f.id}),k=[{id:"overview",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Dn,{size:14})," Overview"]})},{id:"ides",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Le,{size:14})," IDEs"]}),count:m.length},{id:"clis",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Ye,{size:14})," CLIs"]}),count:N.length},{id:"acps",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(Rs,{size:14})," ACP Agents"]}),count:T.length},{id:"providers",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(zt,{size:14})," Providers"]})},{id:"logs",label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx($n,{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:[d.editingNickname?e.jsxs("div",{className:"flex gap-1.5 items-center",children:[e.jsx("input",{autoFocus:!0,value:d.nicknameInput,onChange:C=>d.setNicknameInput(C.target.value),onKeyDown:C=>{C.key==="Enter"&&d.handleSaveNickname(),C.key==="Escape"&&d.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:d.handleSaveNickname,className:"machine-btn text-green-500 border-green-500/30 shrink-0",children:"✓"}),e.jsx("button",{onClick:()=>d.setEditingNickname(!1),className:"machine-btn shrink-0",children:"✕"})]}):e.jsx("h1",{className:"header-title cursor-pointer truncate",onClick:()=>{d.setEditingNickname(!0),d.setNicknameInput(f.machineNickname||"")},title:"Click to set nickname",children:j}),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:[f.platform," · ",f.arch," · ",f.cpus," cores"]}),(p==null?void 0:p.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",p.version]}),(p==null?void 0:p.versionMismatch)&&e.jsxs("button",{className:"px-1.5 py-px rounded text-[9px] font-semibold cursor-pointer transition-colors shrink-0",style:{background:"color-mix(in srgb, var(--status-warning) 8%, transparent)",border:"1px solid color-mix(in srgb, var(--status-warning) 20%, transparent)",color:"var(--status-warning)"},onClick:async()=>{try{await r(s,"daemon_upgrade",{})}catch{}},children:["🔄 Update to v",p.serverVersion]}),f.p2p.available&&e.jsxs("span",{className:"px-1.5 py-px rounded text-[9px] font-semibold",style:{background:f.p2p.state==="connected"?"rgba(34,197,94,0.08)":"rgba(234,179,8,0.08)",color:f.p2p.state==="connected"?"#22c55e":"#eab308"},children:["P2P ",f.p2p.state==="connected"?`● ${f.p2p.peers}`:"○"]}),f.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 ●"}),f.machineNickname&&e.jsxs("span",{className:"text-text-muted opacity-80 shrink-0",children:["(",f.hostname,")"]})]})]})]})}),e.jsx("div",{className:"machine-tabs w-full overflow-x-auto overflow-y-hidden pb-1 -mb-1 mt-2",children:k.map(C=>e.jsxs("button",{onClick:()=>b(C.id),className:`machine-tab shrink-0${u===C.id?" active":""}`,children:[C.label,C.count!==void 0&&e.jsx("span",{className:"tab-count",children:C.count})]},C.id))})]}),e.jsxs("div",{className:"page-content",children:[u==="overview"&&e.jsx(no,{machine:f,ideSessions:m,cliSessions:N,acpSessions:T,actions:d,isDashboardHidden:x,onToggleDashboardVisibility:l}),u==="ides"&&e.jsx(Lt,{category:"ide",machine:f,machineId:s,providers:h,managedEntries:m,getIcon:S,actions:d,isDashboardHidden:x,onToggleDashboardVisibility:l,sendDaemonCommand:r}),u==="clis"&&e.jsx(Lt,{category:"cli",machine:f,machineId:s,providers:h,managedEntries:N,getIcon:S,actions:d,isDashboardHidden:x,onToggleDashboardVisibility:l}),u==="acps"&&e.jsx(Lt,{category:"acp",machine:f,machineId:s,providers:h,managedEntries:T,getIcon:S,actions:d,isDashboardHidden:x,onToggleDashboardVisibility:l}),u==="providers"&&e.jsx(lo,{machineId:s,providers:h,sendDaemonCommand:r}),u==="logs"&&e.jsx(uo,{machineId:s,sendDaemonCommand:r})]}),d.launchPick&&f&&e.jsx(xo,{machine:f,launchPick:d.launchPick,actions:d}),e.jsx(zs,{toasts:a.toasts||[],onDismiss:C=>a.setToasts(V=>V.filter(Q=>Q.id!==C)),onClickToast:C=>{C.targetKey}}),e.jsx("style",{children:`
64
- @keyframes toast-in {
65
- from { opacity: 0; transform: translateX(40px); }
66
- to { opacity: 1; transform: translateX(0); }
67
- }
68
- `})]})}function ho(){const[t,s]=o.useState({ide:[],cli:[],ext:[],acp:[]}),[n,r]=o.useState(!0);o.useEffect(()=>{fetch("https://raw.githubusercontent.com/vilmire/adhdev-providers/main/registry.json").then(c=>c.json()).then(c=>{const x=[],l=[],p=[],u=[];Object.values(c.providers||{}).forEach(g=>{const d={name:g.name||"Unknown",status:g.status||"Stable",details:g.details||"Community Provider"};g.category==="ide"?x.push(d):g.category==="cli"?l.push(d):g.category==="extension"?p.push(d):g.category==="acp"&&u.push(d)});const b=(g,d)=>{const h={Stable:1,Beta:2,WIP:3},w=h[g.status]||99,S=h[d.status]||99;return w!==S?w-S:g.name.localeCompare(d.name)};s({ide:x.sort(b),cli:l.sort(b),ext:p.sort(b),acp:u.sort(b)})}).catch(c=>console.error("Failed to load capabilities:",c)).finally(()=>r(!1))},[]);const a=c=>c==="Stable"?e.jsxs("div",{className:"flex items-center gap-1.5 text-success",children:[e.jsx(Cs,{className:"w-4 h-4"})," ",e.jsx("span",{children:"Stable"})]}):c==="Beta"?e.jsxs("div",{className:"flex items-center gap-1.5 text-warning",children:[e.jsx(Ft,{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(Es,{className:"w-4 h-4"})," ",e.jsx("span",{children:c})]}),i=c=>e.jsx("div",{className:"bg-bg-card border border-border-subtle rounded-xl overflow-hidden",children:e.jsxs("table",{className:"w-full text-left border-collapse",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-bg-secondary border-b border-border-subtle text-xs uppercase text-text-muted font-medium tracking-wider",children:[e.jsx("th",{className:"py-3 px-4 w-1/3",children:"Target"}),e.jsx("th",{className:"py-3 px-4 w-1/4",children:"Status"}),e.jsx("th",{className:"py-3 px-4",children:"Details"})]})}),e.jsx("tbody",{className:"divide-y divide-border-subtle text-sm",children:c.map((x,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:x.name}),e.jsx("td",{className:"py-3 px-4",children:a(x.status)}),e.jsx("td",{className:"py-3 px-4 text-text-muted",children:x.details})]},l))})]})});return n?e.jsx(wt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(vt,{}),widthClassName:"max-w-5xl",children:e.jsx(Ut,{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(wt,{title:"Capabilities",subtitle:"Provider registry coverage for IDEs, CLI agents, extensions, and ACPs",icon:e.jsx(vt,{}),widthClassName:"max-w-5xl",contentClassName:"animate-fade-in",children:[e.jsx(me,{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(me,{title:"IDE support",icon:e.jsx(Le,{className:"w-4 h-4"}),description:"Desktop editors and IDE surfaces with registry-backed providers.",children:i(t.ide)}),e.jsx(me,{title:"Standalone CLI agents",icon:e.jsx(Ht,{className:"w-4 h-4"}),description:"CLI-first agents that can participate in the standalone dashboard.",children:i(t.cli)}),e.jsx(me,{title:"AI extensions",icon:e.jsx(Ye,{className:"w-4 h-4"}),description:"IDE extensions and companion integrations available in the registry.",children:i(t.ext)}),e.jsx(me,{title:`ACP agents (${t.acp.length} loaded)`,icon:e.jsx(Ye,{className:"w-4 h-4"}),description:"ACP-backed providers discovered through the same shared registry.",children:i(t.acp)})]})}class mo{constructor(){xe(this,"adapters",new Map);xe(this,"states",new Map);xe(this,"ptyCallbacks",new Set);xe(this,"runtimeListeners",new Map);xe(this,"screenshotCallbacks",new Map);xe(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,a){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,r){r!=null&&r.scrollback?this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:0,text:typeof n=="string"?n:"",truncated:!1}):typeof n=="string"&&n&&this.emitRuntimeEvent(s,{type:"session_output",sessionId:s,data:n}),this.ptyCallbacks.forEach(a=>a(s,n,r))}emitRuntimeSnapshot(s,n,r=0,a=!1){this.emitRuntimeEvent(s,{type:"runtime_snapshot",sessionId:s,seq:r,text:n,truncated:a})}onRuntimeEvent(s,n){const r=this.runtimeListeners.get(s)||new Set;return r.add(n),this.runtimeListeners.set(s,r),()=>{const a=this.runtimeListeners.get(s);a&&(a.delete(n),a.size===0&&this.runtimeListeners.delete(s))}}async requestRuntimeSnapshot(s,n){if(!n)return;const r=await fetch(`/api/v1/runtime/${encodeURIComponent(n)}/snapshot`);if(!r.ok)return;const a=await r.json();this.emitRuntimeEvent(n,{type:"runtime_snapshot",sessionId:n,seq:typeof a.seq=="number"?a.seq:0,text:typeof a.text=="string"?a.text:"",truncated:!!a.truncated})}emitRuntimeEvent(s,n){var r;(r=this.runtimeListeners.get(s))==null||r.forEach(a=>a(n))}}const Ae=new mo;function fo(){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=fo(),ps=3e3,go=3e4;let Re=null,bo=0;const St=new Map;let We=null,rt=null;function yo(t){return t==="connected"?"connected":t}async function jt(t,s,n){const r=Ir(t,n||{}),a=Re;if(a&&a.readyState===WebSocket.OPEN){const c=`req_${++bo}_${Date.now()}`;return new Promise((x,l)=>{const p=setTimeout(()=>{St.delete(c),l(new Error(`WS command timeout: ${s}`))},3e4);St.set(c,{resolve:u=>{clearTimeout(p),x(u)},reject:u=>{clearTimeout(p),l(u)}}),a.send(JSON.stringify({type:"command",requestId:c,data:{type:s,payload:r.payload}}))})}const i=await fetch("/api/v1/command",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({type:s,payload:r.payload})});if(!i.ok)throw new Error(`HTTP ${i.status}`);return i.json()}class jo{constructor(s){xe(this,"daemonId");xe(this,"screenshotIdeType",null);this.daemonId=s}get hasCommandChannel(){return(Re==null?void 0:Re.readyState)===WebSocket.OPEN}get connectionState(){return(Re==null?void 0:Re.readyState)===WebSocket.OPEN?"connected":"disconnected"}async sendCommand(s,n){return jt(this.daemonId,s,n)}async sendInput(s,n){return jt(this.daemonId,"cdp_remote_action",{action:s,params:n,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}})}startScreenshots(s){this.screenshotIdeType=s||null,We&&(clearInterval(We),We=null);const n=async()=>{if(this.hasCommandChannel)try{const r=await jt(this.daemonId,"screenshot",{width:1280,...this.screenshotIdeType&&{targetSessionId:this.screenshotIdeType}});if(r!=null&&r.success&&(r!=null&&r.base64)){const a=await fetch(`data:image/jpeg;base64,${r.base64}`).then(i=>i.blob());Ae.emitScreenshot(this.daemonId,a)}}catch{}};n(),We=setInterval(n,2e3)}stopScreenshots(s){We&&(clearInterval(We),We=null)}}let ke=null;function vo(t){return(!ke||ke.daemonId!==t)&&(ke=new jo(t)),ke}function wo({children:t}){const s=o.useRef(Yt()),n=Yt();s.current=n;const{setUserName:r}=at(),a=o.useRef(r);a.current=r;const[,i]=o.useState("disconnected"),c=o.useCallback((g,d)=>{i(g),rt==null||rt(g,d)},[]),x=o.useRef(null),l=o.useRef(),p=o.useRef(ps),u=o.useRef(!0),b=o.useRef(!1);return o.useEffect(()=>{u.current=!0,b.current=!1;function g(){var w,S;if(!u.current||((w=x.current)==null?void 0:w.readyState)===WebSocket.OPEN||((S=x.current)==null?void 0:S.readyState)===WebSocket.CONNECTING)return;c("connecting"),console.log(`[Standalone WS] Connecting to ${xs}...`);let h;try{h=new WebSocket(xs)}catch(f){console.error("[Standalone WS] Failed to create WebSocket:",f),d();return}x.current=h,h.onopen=()=>{if(!u.current){h.close();return}c("connected"),p.current=ps,console.log("[Standalone WS] Connected")},Re=h,h.onmessage=f=>{var m;try{const N=JSON.parse(f.data);if((N.type==="command_result"||N.type==="error")&&N.requestId){const T=St.get(N.requestId);T&&(St.delete(N.requestId),N.type==="error"?T.reject(new Error(((m=N.data)==null?void 0:m.message)||"Command failed")):T.resolve(N.data));return}if(N.type==="pty_output"){Ae.emitPtyOutput(N.cliId,N.data);return}if(N.type==="runtime_snapshot"){Ae.emitRuntimeSnapshot(N.sessionId,typeof N.text=="string"?N.text:"",typeof N.seq=="number"?N.seq:0,!!N.truncated);return}if(N.type==="status"||N.type==="initial_state"){const T=N.data;if(!T)return;const{injectEntries:j,markLoaded:k}=s.current,v=T.id||"standalone",y=vo(v);Ae.register(v,y),Ae.setState(v,"connected"),c("connected",v),Ae.emitStatus(v,T);const _=Cr(T,{daemonId:v});_.length>0&&j(_),k(),T.userName&&a.current&&a.current(T.userName)}}catch(N){console.error("[Standalone WS] Parse error:",N)}},h.onclose=()=>{u.current&&(ke==null||ke.stopScreenshots(),ke&&Ae.setState(ke.daemonId,"disconnected"),c("disconnected"),x.current=null,d())},h.onerror=f=>{b.current||!u.current||console.warn("[Standalone WS] Error, will reconnect:",f)}}function d(){if(!u.current)return;clearTimeout(l.current);const h=p.current;console.log(`[Standalone WS] Reconnecting in ${h}ms...`),l.current=setTimeout(()=>{p.current=Math.min(p.current*1.5,go),g()},h)}return g(),()=>{u.current=!1,b.current=!0,clearTimeout(l.current),x.current&&(x.current.onerror=null,x.current.onclose=null,x.current.close(),x.current=null,Re=null),ke&&(ke.stopScreenshots(),Ae.unregister(ke.daemonId))}},[]),e.jsx(e.Fragment,{children:t})}function No({children:t}){const[s,n]=o.useState("disconnected"),[r,a]=o.useState(null);o.useEffect(()=>(rt=(c,x)=>{n(c),x&&a(x)},()=>{rt=null}),[]);const i=o.useMemo(()=>{const c=s==="connected",x=yo(s),l={};return r&&(l[r]=x),l.standalone=x,{wsStatus:s,isConnected:c,connectionStates:l}},[s,r]);return e.jsx(Cn,{connectionOverrides:i,children:e.jsx(wo,{children:t})})}const ko=[{id:"dashboard",path:"/dashboard",icon:e.jsx(Ns,{}),label:"Dashboard"},{id:"machine",path:"/machines",icon:e.jsx(ks,{}),label:"Burrow"},{id:"settings",path:"/settings",icon:e.jsx(zt,{}),label:"Settings"}];function So({children:t}){const s=ot(),n=yn(),[r,a]=o.useState(!1),[i,c]=o.useState(()=>{try{return localStorage.getItem("sidebar-collapsed")==="1"}catch{return!1}}),x=u=>{s(u),a(!1)},l=()=>{c(u=>{const b=!u;try{localStorage.setItem("sidebar-collapsed",b?"1":"0")}catch{}return b})},p=u=>`nav-item${n.pathname.startsWith(u)?" active":""} cursor-pointer ${i?"justify-center py-2.5 px-0":""}`;return e.jsxs("div",{className:`app-layout${r?" mobile-menu-open":""}${i?" sidebar-collapsed":""}`,children:[e.jsxs("button",{type:"button",className:"mobile-menu-btn","aria-label":"Open menu",onClick:()=>a(!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:()=>a(!1),onKeyDown:u=>u.key==="Escape"&&a(!1)}),e.jsxs("aside",{className:`sidebar ${r?"sidebar-open":""}`,children:[e.jsxs("div",{className:"sidebar-header",children:[e.jsxs("div",{className:`sidebar-logo ${i?"justify-center gap-0":""}`,children:[e.jsx("img",{src:"/otter-logo.png",alt:"ADHDev",className:"w-7 h-7"}),!i&&e.jsx("span",{children:"ADHDev"})]}),e.jsx("button",{type:"button",className:"sidebar-close-btn","aria-label":"Close menu",onClick:()=>a(!1),children:"✕"})]}),e.jsx("nav",{className:"sidebar-nav",children:ko.map(u=>e.jsxs("div",{className:p(u.path),id:`nav-${u.id}`,onClick:()=>x(u.path),title:i?u.label:void 0,children:[e.jsx("span",{className:"nav-icon",children:u.icon}),!i&&u.label]},u.id))}),e.jsxs("div",{className:"border-t border-border-subtle pt-4 mt-2",children:[e.jsxs("div",{className:`nav-item cursor-pointer ${i?"justify-center py-2.5 px-0":""}`,id:"nav-docs",onClick:()=>window.open("https://docs.adhf.dev","_blank"),title:i?"Docs":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(vt,{})}),!i&&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":""} ${i?"justify-center py-2.5 px-0":""}`,id:"nav-about",onClick:()=>s("/about"),title:i?"About":void 0,children:[e.jsx("span",{className:"nav-icon",children:e.jsx(Ss,{})}),!i&&"About"]}),!i&&e.jsxs("div",{className:"px-3 py-2 text-xs text-text-muted",children:["Selfhost v","0.7.31"]}),e.jsxs("div",{className:`nav-item cursor-pointer ${i?"justify-center py-2.5 px-0":"mt-1"}`,onClick:l,title:i?"Expand sidebar":"Collapse sidebar",children:[e.jsx("span",{className:"nav-icon text-base",children:i?"›":"‹"}),!i&&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 Co=[{icon:e.jsx(ks,{size:16}),title:"Local-first runtime",desc:"Everything stays on your machine and the browser only connects over localhost."},{icon:e.jsx(qe,{size:16}),title:"Agent chat relay",desc:"Read and respond to AI conversations in real time across connected IDEs."},{icon:e.jsx(Ts,{size:16}),title:"Live screenshots",desc:"View your IDE directly in the browser through the local screenshot stream."},{icon:e.jsx(Le,{size:16}),title:"Remote control",desc:"Click, type, and steer your IDE sessions without switching windows."},{icon:e.jsx(Ye,{size:16}),title:"Multi-IDE support",desc:"Monitor VS Code, Cursor, Windsurf, and extension-based agents in one place."},{icon:e.jsx(vt,{size:16}),title:"CLI and ACP coverage",desc:"Track standalone CLI agents and ACP-backed workflows alongside IDE sessions."}],Io=[{icon:e.jsx(As,{size:16}),title:"Access from anywhere",desc:"Reach your burrows from another laptop or phone without opening local ports."},{icon:e.jsx(Ns,{size:16}),title:"Low-latency P2P stream",desc:"Cloud adds the WebRTC path for faster screenshots and remote control."},{icon:e.jsx(_s,{size:16}),title:"Mobile notifications",desc:"Get approval prompts and activity updates when you are away from your desk."},{icon:e.jsx(Ln,{size:16}),title:"REST API access",desc:"Integrate with Slack, CI, or internal tools using API keys and service routes."},{icon:e.jsx(Rn,{size:16}),title:"Team workspace",desc:"Share burrows, activity views, and policies across a team workspace."},{icon:e.jsx(Cs,{size:16}),title:"Enterprise controls",desc:"SSO, RBAC, audit logs, and managed policy features for production teams."}],Mo=[{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 To(){return e.jsxs(wt,{icon:e.jsx(Ss,{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.31"]}),children:[e.jsx(me,{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(me,{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:Co.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(me,{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:Vs.map(t=>`${t.icon} ${t.name}`)},{label:"Extensions",items:Ys.map(t=>`${t.icon} ${t.name}`)},{label:"CLI agents",items:qs.map(t=>`${t.icon} ${t.name}`)}].map(t=>e.jsxs("div",{className:"rounded-xl border border-border-subtle bg-bg-glass px-4 py-4",children:[e.jsx("div",{className:"text-[10px] font-bold tracking-wider text-text-muted mb-3 uppercase",children:t.label}),e.jsx("div",{className:"flex flex-col gap-1.5",children:t.items.map(s=>e.jsx("div",{className:"rounded-md border border-border-subtle bg-bg-card px-2.5 py-1.5 text-[12px] text-text-secondary",children:s},s))})]},t.label))})}),e.jsx(me,{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:Io.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(me,{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:Mo.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(Ut,{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(Fn,{size:14,className:"mr-1"}),"Discord ↗"]})]})})]})}function Eo(){const{ides:t}=at(),s=t.find(b=>b.type==="adhdev-daemon"),n=(s==null?void 0:s.detectedIdes)||[],{sendCommand:r}=De(),{userName:a}=at(),[i,c]=o.useState(a||"");o.useEffect(()=>{a!==void 0&&c(a)},[a]);const x=b=>{const g=b.target.value.trim();s!=null&&s.id&&g!==a&&r(s.id,"set_user_name",{userName:g}).catch(console.error)},[l,p]=o.useState(()=>{try{return localStorage.getItem("adhdev_sound")!=="0"}catch{return!0}}),u=b=>{p(b);try{localStorage.setItem("adhdev_sound",b?"1":"0")}catch{}};return e.jsxs(wt,{icon:e.jsx(zt,{className:"text-text-primary"}),title:"Settings",subtitle:"Local daemon configuration, appearance, and on-device preferences",widthClassName:"max-w-5xl",children:[e.jsx(zr,{variant:"info",children:"Standalone settings stay on this machine. The browser only talks to your local daemon over localhost."}),e.jsx(me,{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.31"]}),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(me,{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(b=>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 ${b.running?"bg-green-400":"bg-text-muted/30"}`}),e.jsx("span",{className:"text-sm font-medium",children:b.name})]}),e.jsx("span",{className:"text-[11px] text-text-muted font-mono",children:b.type})]},b.type))})}),e.jsx(me,{title:"Machine",description:"The local burrow exposed by your standalone daemon.",children:e.jsx(Gr,{ides:t,emptyMessage:"Daemon not connected. Run 'adhdev-standalone' to start."})}),e.jsx(me,{title:"Appearance",description:"Match the rest of the dashboard with a single place for mode and theme.",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(ea,{})]}),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, accent, and chat palette for the standalone UI."}),e.jsx(oa,{})]})]})}),e.jsx(me,{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(Xr,{}),e.jsx(Oe,{label:e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx(zn,{size:15})," Sound Effects"]}),description:"Play a sound when agent completes or needs approval",checked:l,onChange:u})]})}),e.jsx(me,{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(_n,{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:i,onChange:b=>c(b.target.value),onBlur:x,onKeyDown:b=>{b.key==="Enter"&&b.currentTarget.blur()}})]})})})]})}qr();ra();const Ao=vs({baseUrl:""});function hs(){const{ides:t}=at(),s=t.find(n=>{var r;return n.daemonMode||((r=n.id)==null?void 0:r.startsWith("standalone"))});return s?e.jsx(ft,{to:`/machines/${s.id}`,replace:!0}):t.length>0?e.jsx(ft,{to:`/machines/${t[0].id}`,replace:!0}):e.jsx(ft,{to:"/dashboard",replace:!0})}function Ro(){return e.jsx(jn,{future:{v7_startTransition:!0,v7_relativeSplatPath:!0},children:e.jsx(Tn,{client:Ao,children:e.jsx(No,{children:e.jsx(An,{value:{sendCommand:jt,sendData:()=>!1},children:e.jsx(So,{children:e.jsxs(vn,{children:[e.jsx(Ee,{path:"/dashboard",element:e.jsx(Va,{})}),e.jsx(Ee,{path:"/ide/:id",element:e.jsx(eo,{})}),e.jsx(Ee,{path:"/machine",element:e.jsx(hs,{})}),e.jsx(Ee,{path:"/machines/:id",element:e.jsx(po,{})}),e.jsx(Ee,{path:"/machines",element:e.jsx(hs,{})}),e.jsx(Ee,{path:"/capabilities",element:e.jsx(ho,{})}),e.jsx(Ee,{path:"/about",element:e.jsx(To,{})}),e.jsx(Ee,{path:"/settings",element:e.jsx(Eo,{})}),e.jsx(Ee,{path:"*",element:e.jsx(ft,{to:"/dashboard",replace:!0})})]})})})})})})}br({connectionManager:Ae});wn(document.getElementById("root")).render(e.jsx(o.StrictMode,{children:e.jsx(Ro,{})}));